isid_query.h File Reference


Detailed Description

Defines the public interface for searching and iterating over initial SIDs.

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 isid_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_isid qpol_isid_t

Functions

int qpol_policy_get_isid_by_name (const qpol_policy_t *policy, const char *name, const qpol_isid_t **ocon)
 Get an initial SID statement by name.
int qpol_policy_get_isid_iter (const qpol_policy_t *policy, qpol_iterator_t **iter)
 Get an iterator for the initial SID statements in a policy.
int qpol_isid_get_name (const qpol_policy_t *policy, const qpol_isid_t *ocon, const char **name)
 Get the name from an initial SID statement.
int qpol_isid_get_context (const qpol_policy_t *policy, const qpol_isid_t *ocon, const qpol_context_t **context)
 Get the context from an initial SID statement.

Typedef Documentation

typedef struct qpol_isid qpol_isid_t
 

Definition at line 39 of file isid_query.h.

Referenced by apol_isid_get_by_query(), find_assoc_types_run(), find_netif_types_run(), find_node_types_run(), find_port_types_run(), in_isid_ctx(), print_isids(), and qpol_policy_get_isid_by_name().


Function Documentation

int qpol_policy_get_isid_by_name const qpol_policy_t policy,
const char *  name,
const qpol_isid_t **  ocon
 

Get an initial SID statement by name.

Parameters:
policy The policy from which to get the initial SID statement.
name The name of the initial SID.
ocon Pointer in which to store the initial SID. 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 isid_query.c.

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

Referenced by find_assoc_types_run(), find_netif_types_run(), find_node_types_run(), and find_port_types_run().

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_ISID]; tmp; tmp = tmp->next) {
00053                 if (!strcmp(name, tmp->u.name))
00054                         break;
00055         }
00056 
00057         *ocon = (qpol_isid_t *) tmp;
00058 
00059         if (*ocon == NULL) {
00060                 ERR(policy, "could not find initial SID statement for %s", name);
00061                 errno = ENOENT;
00062                 return STATUS_ERR;
00063         }
00064 
00065         return STATUS_SUCCESS;
00066 }

int qpol_policy_get_isid_iter const qpol_policy_t policy,
qpol_iterator_t **  iter
 

Get an iterator for the initial SID statements in a policy.

Parameters:
policy The policy from which to create the iterator.
iter Iterator over items of type qpol_isid_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 isid_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_isid_get_by_query(), in_isid_ctx(), and print_stats().

00069 {
00070         policydb_t *db = NULL;
00071         ocon_state_t *os = NULL;
00072         int error = 0;
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_ISID];
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         return STATUS_SUCCESS;
00101 }

int qpol_isid_get_name const qpol_policy_t policy,
const qpol_isid_t ocon,
const char **  name
 

Get the name from an initial SID statement.

Parameters:
policy The policy associated with the initial SID.
ocon The initial SID from which to get the name.
name Pointer to the string in which to store the 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 103 of file isid_query.c.

References ERR, and qpol_policy_t.

Referenced by apol_isid_get_by_query(), and print_isids().

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

int qpol_isid_get_context const qpol_policy_t policy,
const qpol_isid_t ocon,
const qpol_context_t **  context
 

Get the context from an initial SID statement.

Parameters:
policy The policy associated with the inital SID.
ocon The initial SID from which to get the 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 122 of file isid_query.c.

References ERR, qpol_context_t, and qpol_policy_t.

Referenced by apol_isid_get_by_query(), find_assoc_types_run(), find_netif_types_run(), find_node_types_run(), find_port_types_run(), in_isid_ctx(), and print_isids().

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