netifcon_query.h File Reference


Detailed Description

Defines the public interface for searching and iterating over netifcon statements.

Author:
Kevin Carr kcarr@tresys.com

Jeremy A. Mowery jmowery@tresys.com

Jason Tang jtang@tresys.com

Copyright (C) 2006-2007 Tresys Technology, LLC

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

Definition in file netifcon_query.h.

#include <stddef.h>
#include <stdint.h>
#include <qpol/iterator.h>
#include <qpol/policy.h>

Go to the source code of this file.


Typedefs

typedef qpol_netifcon qpol_netifcon_t

Functions

int qpol_policy_get_netifcon_by_name (const qpol_policy_t *policy, const char *name, const qpol_netifcon_t **ocon)
 Get a netifcon statement by interface name.
int qpol_policy_get_netifcon_iter (const qpol_policy_t *policy, qpol_iterator_t **iter)
 Get an iterator for the netifcon statements in a policy.
int qpol_netifcon_get_name (const qpol_policy_t *policy, const qpol_netifcon_t *ocon, const char **name)
 Get the name of the interface from a netifcon statement.
int qpol_netifcon_get_msg_con (const qpol_policy_t *policy, const qpol_netifcon_t *ocon, const qpol_context_t **context)
 Get the message context from a netifcon statement.
int qpol_netifcon_get_if_con (const qpol_policy_t *policy, const qpol_netifcon_t *ocon, const qpol_context_t **context)
 Get the interface context from a netifcon statement.

Typedef Documentation

typedef struct qpol_netifcon qpol_netifcon_t
 

Definition at line 39 of file netifcon_query.h.

Referenced by apol_netifcon_get_by_query(), find_netif_types_run(), print_netifcon(), and qpol_policy_get_netifcon_by_name().


Function Documentation

int qpol_policy_get_netifcon_by_name const qpol_policy_t policy,
const char *  name,
const qpol_netifcon_t **  ocon
 

Get a netifcon statement by interface name.

Parameters:
policy The policy from which to get the netifcon statement.
name The name of the interface.
ocon Pointer in which to store the statement returned. The caller should not free this pointer.
Returns:
0 on success and < 0 on failure; if the call fails, errno will be set and *ocon will be NULL.

Definition at line 37 of file netifcon_query.c.

References ERR, qpol_policy::p, qpol_netifcon_t, and qpol_policy_t.

Referenced by print_netifcon().

00038 {
00039         ocontext_t *tmp = NULL;
00040         policydb_t *db = NULL;
00041 
00042         if (ocon != NULL)
00043                 *ocon = NULL;
00044 
00045         if (policy == NULL || name == NULL || ocon == NULL) {
00046                 ERR(policy, "%s", strerror(EINVAL));
00047                 errno = EINVAL;
00048                 return STATUS_ERR;
00049         }
00050 
00051         db = &policy->p->p;
00052         for (tmp = db->ocontexts[OCON_NETIF]; tmp; tmp = tmp->next) {
00053                 if (!strcmp(name, tmp->u.name))
00054                         break;
00055         }
00056 
00057         *ocon = (qpol_netifcon_t *) tmp;
00058 
00059         if (*ocon == NULL) {
00060                 ERR(policy, "could not find netifcon statement for %s", name);
00061                 errno = ENOENT;
00062                 return STATUS_ERR;
00063         }
00064 
00065         return STATUS_SUCCESS;
00066 }

int qpol_policy_get_netifcon_iter const qpol_policy_t policy,
qpol_iterator_t **  iter
 

Get an iterator for the netifcon statements in a policy.

Parameters:
policy The policy from which to create the iterator.
iter Iterator over items of type qpol_netifcon_t returned. The caller is responsible for calling qpol_iterator_destroy to free memory used by this iterator. It is important to note that this iterator is only valid as long as the policy is unmodified.
Returns:
0 on success and < 0 on failure; if the call fails, errno will be set and *iter will be NULL.

Definition at line 68 of file netifcon_query.c.

References ocon_state::cur, ERR, ocon_state::head, ocon_state_end(), ocon_state_get_cur(), ocon_state_next(), ocon_state_size(), ocon_state_t, qpol_policy::p, qpol_iterator_create(), qpol_iterator_t, and qpol_policy_t.

Referenced by apol_netifcon_get_by_query(), print_netifcon(), and print_stats().

00069 {
00070         policydb_t *db = NULL;
00071         int error = 0;
00072         ocon_state_t *os = NULL;
00073 
00074         if (iter != NULL)
00075                 *iter = NULL;
00076 
00077         if (policy == NULL || iter == NULL) {
00078                 ERR(policy, "%s", strerror(EINVAL));
00079                 errno = EINVAL;
00080                 return STATUS_ERR;
00081         }
00082 
00083         db = &policy->p->p;
00084 
00085         os = calloc(1, sizeof(ocon_state_t));
00086         if (os == NULL) {
00087                 error = errno;
00088                 ERR(policy, "%s", strerror(ENOMEM));
00089                 errno = error;
00090                 return STATUS_ERR;
00091         }
00092 
00093         os->head = os->cur = db->ocontexts[OCON_NETIF];
00094 
00095         if (qpol_iterator_create(policy, (void *)os, ocon_state_get_cur,
00096                                  ocon_state_next, ocon_state_end, ocon_state_size, free, iter)) {
00097                 free(os);
00098                 return STATUS_ERR;
00099         }
00100 
00101         return STATUS_SUCCESS;
00102 }

int qpol_netifcon_get_name const qpol_policy_t policy,
const qpol_netifcon_t ocon,
const char **  name
 

Get the name of the interface from a netifcon statement.

Parameters:
policy The policy associated wiht the netifcon statement.
ocon The netifcon statement from which to get the name.
name Pointer in which to store the interface name. The caller should not free this string.
Returns:
0 on success and < 0 on failure; if the call fails, errno will be set and *name will be NULL.

Definition at line 104 of file netifcon_query.c.

References ERR, and qpol_policy_t.

Referenced by apol_netifcon_get_by_query(), and apol_netifcon_render().

00105 {
00106         ocontext_t *internal_ocon = NULL;
00107 
00108         if (name != NULL)
00109                 *name = NULL;
00110 
00111         if (policy == NULL || ocon == NULL || name == NULL) {
00112                 ERR(policy, "%s", strerror(EINVAL));
00113                 errno = EINVAL;
00114                 return STATUS_ERR;
00115         }
00116 
00117         internal_ocon = (ocontext_t *) ocon;
00118         *name = internal_ocon->u.name;
00119 
00120         return STATUS_SUCCESS;
00121 }

int qpol_netifcon_get_msg_con const qpol_policy_t policy,
const qpol_netifcon_t ocon,
const qpol_context_t **  context
 

Get the message context from a netifcon statement.

Parameters:
policy The policy associated with the netifcon statement.
ocon The netifcon statement from which to get the message context. context Pointer in which to store the context. The caller should not free this pointer.
Returns:
0 on success and < 0 on failure; if the call fails, errno will be set and *context will be NULL.

Definition at line 123 of file netifcon_query.c.

References ERR, qpol_context_t, and qpol_policy_t.

Referenced by apol_netifcon_get_by_query(), apol_netifcon_render(), and find_netif_types_run().

00124 {
00125         ocontext_t *internal_ocon = NULL;
00126 
00127         if (context != NULL)
00128                 *context = NULL;
00129 
00130         if (policy == NULL || ocon == NULL || context == NULL) {
00131                 ERR(policy, "%s", strerror(EINVAL));
00132                 errno = EINVAL;
00133                 return STATUS_ERR;
00134         }
00135 
00136         internal_ocon = (ocontext_t *) ocon;
00137         *context = (qpol_context_t *) & (internal_ocon->context[1]);
00138 
00139         return STATUS_SUCCESS;
00140 }

int qpol_netifcon_get_if_con const qpol_policy_t policy,
const qpol_netifcon_t ocon,
const qpol_context_t **  context
 

Get the interface context from a netifcon statement.

Parameters:
policy The policy associated with the netifcon statement.
ocon The netifcon statement from which to get the interface context. context Pointer in which to store the context. The caller should not free this pointer.
Returns:
0 on success and < 0 on failure; if the call fails, errno will be set and *context will be NULL.

Definition at line 142 of file netifcon_query.c.

References ERR, qpol_context_t, and qpol_policy_t.

Referenced by apol_netifcon_get_by_query(), apol_netifcon_render(), and find_netif_types_run().

00143 {
00144         ocontext_t *internal_ocon = NULL;
00145 
00146         if (context != NULL)
00147                 *context = NULL;
00148 
00149         if (policy == NULL || ocon == NULL || context == NULL) {
00150                 ERR(policy, "%s", strerror(EINVAL));
00151                 errno = EINVAL;
00152                 return STATUS_ERR;
00153         }
00154 
00155         internal_ocon = (ocontext_t *) ocon;
00156         *context = (qpol_context_t *) & (internal_ocon->context[0]);
00157 
00158         return STATUS_SUCCESS;
00159 }