mlsrule_query.c File Reference


Detailed Description

Implementation for the public interface for searching and iterating over range transition rules.

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 mlsrule_query.c.

#include "iterator_internal.h"
#include <qpol/iterator.h>
#include <qpol/policy.h>
#include <qpol/mlsrule_query.h>
#include <sepol/policydb/policydb.h>
#include <sepol/policydb/avtab.h>
#include <sepol/policydb/util.h>
#include <stdlib.h>
#include "qpol_internal.h"

Go to the source code of this file.


Classes

struct  range_trans_state

Typedefs

typedef range_trans_state range_trans_state_t

Functions

int range_trans_state_end (const qpol_iterator_t *iter)
void * range_trans_state_get_cur (const qpol_iterator_t *iter)
int range_trans_state_next (qpol_iterator_t *iter)
size_t range_trans_state_size (const qpol_iterator_t *iter)
int qpol_policy_get_range_trans_iter (const qpol_policy_t *policy, qpol_iterator_t **iter)
 Get an iterator over all range transition rules in a policy.
int qpol_range_trans_get_source_type (const qpol_policy_t *policy, const qpol_range_trans_t *rule, const qpol_type_t **source)
 Get the source type from a range transition rule.
int qpol_range_trans_get_target_type (const qpol_policy_t *policy, const qpol_range_trans_t *rule, const qpol_type_t **target)
 Get the target type from a range transition rule.
int qpol_range_trans_get_target_class (const qpol_policy_t *policy, const qpol_range_trans_t *rule, const qpol_class_t **target)
 Get the target class from a range transition rule.
int qpol_range_trans_get_range (const qpol_policy_t *policy, const qpol_range_trans_t *rule, const qpol_mls_range_t **range)
 Get the range from a range transition rule.

Typedef Documentation

typedef struct range_trans_state range_trans_state_t
 

Referenced by qpol_policy_get_range_trans_iter(), range_trans_state_end(), range_trans_state_get_cur(), range_trans_state_next(), and range_trans_state_size().


Function Documentation

int range_trans_state_end const qpol_iterator_t iter  )  [static]
 

Definition at line 43 of file mlsrule_query.c.

References range_trans_state::cur, qpol_iterator_state(), qpol_iterator_t, and range_trans_state_t.

Referenced by qpol_policy_get_range_trans_iter(), and range_trans_state_next().

00044 {
00045         range_trans_state_t *rs = NULL;
00046 
00047         if (!iter || !(rs = qpol_iterator_state(iter))) {
00048                 errno = EINVAL;
00049                 return STATUS_ERR;
00050         }
00051 
00052         return rs->cur ? 0 : 1;
00053 }

void* range_trans_state_get_cur const qpol_iterator_t iter  )  [static]
 

Definition at line 55 of file mlsrule_query.c.

References range_trans_state::cur, qpol_iterator_state(), qpol_iterator_t, and range_trans_state_t.

Referenced by qpol_policy_get_range_trans_iter().

00056 {
00057         range_trans_state_t *rs = NULL;
00058 
00059         if (!iter || !(rs = qpol_iterator_state(iter))) {
00060                 errno = EINVAL;
00061                 return NULL;
00062         }
00063 
00064         return rs->cur;
00065 }

int range_trans_state_next qpol_iterator_t iter  )  [static]
 

Definition at line 67 of file mlsrule_query.c.

References range_trans_state::cur, qpol_iterator_state(), qpol_iterator_t, range_trans_state_end(), and range_trans_state_t.

Referenced by qpol_policy_get_range_trans_iter().

00068 {
00069         range_trans_state_t *rs = NULL;
00070 
00071         if (!iter || !(rs = qpol_iterator_state(iter))) {
00072                 errno = EINVAL;
00073                 return STATUS_ERR;
00074         }
00075 
00076         if (range_trans_state_end(iter)) {
00077                 errno = EINVAL;
00078                 return STATUS_ERR;
00079         }
00080 
00081         rs->cur = rs->cur->next;
00082 
00083         return STATUS_SUCCESS;
00084 }

size_t range_trans_state_size const qpol_iterator_t iter  )  [static]
 

Definition at line 86 of file mlsrule_query.c.

References range_trans_state::head, qpol_iterator_state(), qpol_iterator_t, and range_trans_state_t.

Referenced by qpol_policy_get_range_trans_iter().

00087 {
00088         range_trans_state_t *rs = NULL;
00089         size_t count = 0;
00090         range_trans_t *tmp = NULL;
00091 
00092         if (!iter || !(rs = qpol_iterator_state(iter))) {
00093                 errno = EINVAL;
00094                 return 0;
00095         }
00096 
00097         for (tmp = rs->head; tmp; tmp = tmp->next)
00098                 count++;
00099 
00100         return count;
00101 }

int qpol_policy_get_range_trans_iter const qpol_policy_t policy,
qpol_iterator_t **  iter
 

Get an iterator over all range transition rules in a policy.

Parameters:
policy Policy from which to get the range transitions.
iter Iterator over items of type qpol_range_trans_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 unmodifed. 0 on success and < 0 on failure; if the call fails, errno will be set and *iter will be NULL.

Definition at line 103 of file mlsrule_query.c.

References range_trans_state::cur, ERR, range_trans_state::head, qpol_policy::p, qpol_iterator_create(), qpol_iterator_t, qpol_policy_t, range_trans_state_end(), range_trans_state_get_cur(), range_trans_state_next(), range_trans_state_size(), and range_trans_state_t.

Referenced by apol_range_trans_get_by_query(), infer_policy_version(), print_stats(), and range_trans_get_items().

00104 {
00105         policydb_t *db = NULL;
00106         range_trans_state_t *rs = NULL;
00107         int error = 0;
00108 
00109         if (iter)
00110                 *iter = NULL;
00111 
00112         if (!policy || !iter) {
00113                 ERR(policy, "%s", strerror(EINVAL));
00114                 errno = EINVAL;
00115                 return STATUS_ERR;
00116         }
00117 
00118         db = &policy->p->p;
00119 
00120         rs = calloc(1, sizeof(range_trans_state_t));
00121         if (!rs) {
00122                 error = errno;
00123                 ERR(policy, "%s", strerror(error));
00124                 errno = error;
00125                 return STATUS_ERR;
00126         }
00127 
00128         if (qpol_iterator_create(policy, (void *)rs, range_trans_state_get_cur,
00129                                  range_trans_state_next, range_trans_state_end, range_trans_state_size, free, iter)) {
00130                 error = errno;
00131                 free(rs);
00132                 errno = error;
00133                 return STATUS_ERR;
00134         }
00135 
00136         rs->head = rs->cur = db->range_tr;
00137         return STATUS_SUCCESS;
00138 }

int qpol_range_trans_get_source_type const qpol_policy_t policy,
const qpol_range_trans_t rule,
const qpol_type_t **  source
 

Get the source type from a range transition rule.

Parameters:
policy Policy from which the rule comes.
rule The rule from which to get the source type.
source Pointer in which to store the source type. The caller should not free this pointer. 0 on success and < 0 on failure; if the call fails, errno will be set and *source will be NULL.

Definition at line 140 of file mlsrule_query.c.

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

Referenced by apol_range_trans_get_by_query(), apol_range_trans_render(), imp_range_trans_run(), and range_trans_get_items().

00141 {
00142         policydb_t *db = NULL;
00143         range_trans_t *rt = NULL;
00144 
00145         if (source) {
00146                 *source = NULL;
00147         }
00148 
00149         if (!policy || !rule || !source) {
00150                 errno = EINVAL;
00151                 ERR(policy, "%s", strerror(EINVAL));
00152                 return STATUS_ERR;
00153         }
00154 
00155         db = &policy->p->p;
00156         rt = (range_trans_t *) rule;
00157 
00158         *source = (qpol_type_t *) db->type_val_to_struct[rt->source_type - 1];
00159 
00160         return STATUS_SUCCESS;
00161 }

int qpol_range_trans_get_target_type const qpol_policy_t policy,
const qpol_range_trans_t rule,
const qpol_type_t **  target
 

Get the target type from a range transition rule.

Parameters:
policy Policy from which the rule comes.
rule The rule from which to get the target type.
target Pointer in which to store the target type. The caller should not free this pointer. 0 on success and < 0 on failure; if the call fails, errno will be set and *target will be NULL.

Definition at line 163 of file mlsrule_query.c.

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

Referenced by apol_range_trans_get_by_query(), apol_range_trans_render(), imp_range_trans_run(), and range_trans_get_items().

00164 {
00165         policydb_t *db = NULL;
00166         range_trans_t *rt = NULL;
00167 
00168         if (target) {
00169                 *target = NULL;
00170         }
00171 
00172         if (!policy || !rule || !target) {
00173                 ERR(policy, "%s", strerror(EINVAL));
00174                 errno = EINVAL;
00175                 return STATUS_ERR;
00176         }
00177 
00178         db = &policy->p->p;
00179         rt = (range_trans_t *) rule;
00180 
00181         *target = (qpol_type_t *) db->type_val_to_struct[rt->target_type - 1];
00182 
00183         return STATUS_SUCCESS;
00184 }

int qpol_range_trans_get_target_class const qpol_policy_t policy,
const qpol_range_trans_t rule,
const qpol_class_t **  target
 

Get the target class from a range transition rule.

Parameters:
policy Policy from which the rule comes.
rule The rule from which to get the target class.
target Pointer in which to store the target class. The caller should not free this pointer. 0 on success and < 0 on failure; if the call fails, errno will be set and *target will be NULL.

Definition at line 186 of file mlsrule_query.c.

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

Referenced by apol_range_trans_get_by_query(), apol_range_trans_render(), infer_policy_version(), policy_21_range_trans_either(), policy_21_range_trans_lnk_file(), policy_21_range_trans_process(), and range_trans_get_items().

00187 {
00188         policydb_t *db = NULL;
00189         range_trans_t *rt = NULL;
00190 
00191         if (target) {
00192                 *target = NULL;
00193         }
00194 
00195         if (!policy || !rule || !target) {
00196                 ERR(policy, "%s", strerror(EINVAL));
00197                 errno = EINVAL;
00198                 return STATUS_ERR;
00199         }
00200 
00201         db = &policy->p->p;
00202         rt = (range_trans_t *) rule;
00203 
00204         *target = (qpol_class_t *) db->class_val_to_struct[rt->target_class - 1];
00205 
00206         return STATUS_SUCCESS;
00207 }

int qpol_range_trans_get_range const qpol_policy_t policy,
const qpol_range_trans_t rule,
const qpol_mls_range_t **  range
 

Get the range from a range transition rule.

Parameters:
policy Policy from which the rule comes.
rule The rule from which to get the range.
range Pointer in which to store the range. The caller should not free this pointer. 0 on success and < 0 on failure; if the call fails, errno will be set and *range will be NULL.

Definition at line 209 of file mlsrule_query.c.

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

Referenced by apol_range_trans_get_by_query(), apol_range_trans_render(), imp_range_trans_run(), and range_trans_get_items().

00210 {
00211         policydb_t *db = NULL;
00212         range_trans_t *rt = NULL;
00213 
00214         if (range) {
00215                 *range = NULL;
00216         }
00217 
00218         if (!policy || !rule || !range) {
00219                 ERR(policy, "%s", strerror(EINVAL));
00220                 errno = EINVAL;
00221                 return STATUS_ERR;
00222         }
00223 
00224         db = &policy->p->p;
00225         rt = (range_trans_t *) rule;
00226 
00227         *range = (qpol_mls_range_t *) & rt->target_range;
00228 
00229         return STATUS_SUCCESS;
00230 }