/usr/include/apol/avrule-query.h is in libapol-dev 3.3.8+20151215-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 | /**
* @file
*
* Routines to query access vector rules of a policy. These are
* allow, neverallow, auditallow, and dontaudit rules.
*
* @author Jeremy A. Mowery jmowery@tresys.com
* @author 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
*/
#ifndef APOL_AVRULE_QUERY_H
#define APOL_AVRULE_QUERY_H
#ifdef __cplusplus
extern "C"
{
#endif
#include "policy.h"
#include "vector.h"
#include <qpol/policy.h>
typedef struct apol_avrule_query apol_avrule_query_t;
/**
* Execute a query against all access vector rules within the policy.
*
* @param p Policy within which to look up avrules.
* @param a Structure containing parameters for query. If this is
* NULL then return all avrules.
* @param v Reference to a vector of qpol_avrule_t. The vector will
* be allocated by this function. The caller must call
* apol_vector_destroy() afterwards. This will be set to NULL upon no
* results or upon error.
*
* @return 0 on success (including none found), negative on error.
*/
extern int apol_avrule_get_by_query(const apol_policy_t * p, const apol_avrule_query_t * a, apol_vector_t ** v);
/**
* Execute a query against all syntactic access vector rules within
* the policy. If the policy has line numbers, then the returned list
*
* @param p Policy within which to look up avrules. The policy must
* be capable of having syntactic rules.
* @param a Structure containing parameters for query. If this is
* NULL then return all avrules.
* @param v Reference to a vector of qpol_syn_avrule_t. The vector
* will be allocated by this function. The caller must call
* apol_vector_destroy() afterwards. This will be set to NULL upon no
* results or upon error.
*
* @return 0 on success (including none found), negative on error.
*/
extern int apol_syn_avrule_get_by_query(const apol_policy_t * p, const apol_avrule_query_t * a, apol_vector_t ** v);
/**
* Allocate and return a new avrule query structure. All fields are
* initialized, such that running this blank query results in
* returning all avrules within the policy. The caller must call
* apol_avrule_query_destroy() upon the return value afterwards.
*
* @return An initialized avrule query structure, or NULL upon error.
*/
extern apol_avrule_query_t *apol_avrule_query_create(void);
/**
* Deallocate all memory associated with the referenced avrule query,
* and then set it to NULL. This function does nothing if the query
* is already NULL.
*
* @param a Reference to a avrule query structure to destroy.
*/
extern void apol_avrule_query_destroy(apol_avrule_query_t ** a);
/**
* Set an avrule query to search only certain access vector rules
* within the policy. This is a bitmap; use the constants in
* libqpol/avrule_query.h (QPOL_RULE_ALLOW, etc.) to give the rule
* selections.
*
* @param p Policy handler, to report errors.
* @param a AV rule query to set.
* @param rules Bitmap to indicate which rules to search, or 0 to
* search all rules.
*
* @return Always 0.
*/
extern int apol_avrule_query_set_rules(const apol_policy_t * p, apol_avrule_query_t * a, unsigned int rules);
/**
* Set an avrule query to return rules whose source symbol matches
* symbol. Symbol may be a type or attribute; if it is an alias then
* the query will convert it to its primary prior to searching. If
* is_indirect is non-zero then the search will be done indirectly.
* If the symbol is a type, then the query matches rules with one of
* the type's attributes. If the symbol is an attribute, then it
* matches rule with any of the attribute's types.
*
* @param p Policy handler, to report errors.
* @param a AV rule query to set.
* @param symbol Limit query to rules with this symbol as their
* source, or NULL to unset this field.
* @param is_indirect If non-zero, perform indirect matching.
*
* @return 0 on success, negative on error.
*/
extern int apol_avrule_query_set_source(const apol_policy_t * p, apol_avrule_query_t * a, const char *symbol,
int is_indirect);
/**
* Set an avrule query to return rules whose source symbol is matched as a type
* or an attribute. The symbol will match both types and attributes by default.
* @see apol_avrule_query_set_source() to set the symbol to match.
*
* @param p Policy handler, to report errors.
* @param a AV rule query to set.
* @param component Bit-wise or'ed set of APOL_QUERY_SYMBOL_IS_TYPE
* and APOL_QUERY_SYMBOL_IS_ATTRIBUTE indicating the type of component
* to match.
*
* @return 0 on success, negative on error.
*/
extern int apol_avrule_query_set_source_component(const apol_policy_t * p, apol_avrule_query_t * a, unsigned int component);
/**
* Set an avrule query to return rules whose target symbol matches
* symbol. Symbol may be a type or attribute; if it is an alias then
* the query will convert it to its primary prior to searching. If
* is_indirect is non-zero then the search will be done indirectly.
* If the symbol is a type, then the query matches rules with one of
* the type's attributes. If the symbol is an attribute, then it
* matches rule with any of the attribute's types.
*
* @param p Policy handler, to report errors.
* @param a AV rule query to set.
* @param symbol Limit query to rules with this symbol as their
* target, or NULL to unset this field.
* @param is_indirect If non-zero, perform indirect matching.
*
* @return 0 on success, negative on error.
*/
extern int apol_avrule_query_set_target(const apol_policy_t * p, apol_avrule_query_t * a, const char *symbol,
int is_indirect);
/**
* Set an avrule query to return rules whose target symbol is matched as a type
* or an attribute. The symbol will match both types and attributes by default.
* @see apol_avrule_query_set_target() to set the symbol to match.
*
* @param p Policy handler, to report errors.
* @param a AV rule query to set.
* @param component Bit-wise or'ed set of APOL_QUERY_SYMBOL_IS_TYPE
* and APOL_QUERY_SYMBOL_IS_ATTRIBUTE indicating the type of component
* to match.
*
* @return 0 on success, negative on error.
*/
extern int apol_avrule_query_set_target_component(const apol_policy_t * p, apol_avrule_query_t * a, unsigned int component);
/**
* Set an avrule query to return rules with this object (non-common)
* class. If more than one class are appended to the query, the
* rule's class must be one of those appended. (I.e., the rule's
* class must be a member of the query's classes.) Pass a NULL to
* clear all classes. Note that this performs straight string
* comparison, ignoring the regex flag.
*
* @param p Policy handler, to report errors.
* @param a AV rule query to set.
* @param obj_class Name of object class to add to search set, or NULL
* to clear all classes.
*
* @return 0 on success, negative on error.
*/
extern int apol_avrule_query_append_class(const apol_policy_t * p, apol_avrule_query_t * a, const char *obj_class);
/**
* Set an avrule query to return rules with this permission. By
* default, if more than one permission are appended to the query, at
* least one of the rule's permissions must be one of those appended;
* that is, the intersection of query's and rule's permissions must be
* non-empty. (This behavior can be changed.) Pass a NULL to clear
* all permissions. Note that this performs a straight string
* comparison, ignoring the regex flag.
*
* @param p Policy handler, to report errors.
* @param a AV rule query to set.
* @param perm Name of permission to add to search set, or NULL to
* clear all permissions.
*
* @return 0 on success, negative on error.
*
* @see apol_avrule_query_set_all_perms()
*/
extern int apol_avrule_query_append_perm(const apol_policy_t * p, apol_avrule_query_t * a, const char *perm);
/**
* Set an avrule query to return rules that are in conditionals and
* whose conditional uses a particular boolean variable.
* Unconditional rules will not be returned.
*
* @param p Policy handler, to report errors.
* @param a AV rule query to set.
* @param bool_name Name of boolean that conditional must contain. If
* NULL then search all rules.
*
* @return 0 on success, negative on error.
*/
extern int apol_avrule_query_set_bool(const apol_policy_t * p, apol_avrule_query_t * a, const char *bool_name);
/**
* Set an avrule query to search only enabled rules within the policy.
* These include rules that are unconditional and those within enabled
* conditionals.
*
* @param p Policy handler, to report errors.
* @param a AV rule query to set.
* @param is_enabled Non-zero to search only enabled rules, 0 to
* search all rules.
*
* @return Always 0.
*/
extern int apol_avrule_query_set_enabled(const apol_policy_t * p, apol_avrule_query_t * a, int is_enabled);
/**
* Normally, if more than one permission are added to the query then
* all returned rules will have <em>at least one</em> of those
* permissions. If the all_perms flag is set, then returned rules
* will have <em>all</em> of the given permissions. This flag does
* nothing if no permissions are given.
*
* <em>Note:</em> If calling apol_syn_avrule_get_by_query(), the
* returned results may not be what is expected. For a given
* source-target-class triplet, all of the associated permissions are
* unioned together prior to executing the avrule query. Although a
* given syntactic AV rule might not have all of the matched
* permissions, the union of the rules' permissions will them. For
* example, consider these two allow rules:
*
*<pre>allow A B : C p1;
*allow A B : C p2;</pre>
*
* If the avrule query has both permissions p1 and p2 and the
* all_perms flag is set, then both of these syntactic rules will be
* returned by apol_syn_avrule_get_by_query().
*
* @param p Policy handler, to report errors.
* @param a AV rule query to set.
* @param all_perms Non-zero to match all permissions, zero to match
* any permission.
*
* @return Always 0.
*
* @see apol_avrule_query_append_perm()
*/
extern int apol_avrule_query_set_all_perms(const apol_policy_t * p, apol_avrule_query_t * a, int all_perms);
/**
* Set an avrule query to treat the source symbol as any. That is,
* use the same symbol for either source or target of a rule. This
* flag does nothing if the source symbol is not set.
*
* @param p Policy handler, to report errors.
* @param a AV rule query to set.
* @param is_any Non-zero to use source symbol for any field, 0 to
* keep source as only source.
*
* @return Always 0.
*/
extern int apol_avrule_query_set_source_any(const apol_policy_t * p, apol_avrule_query_t * a, int is_any);
/**
* Set an avrule query to use regular expression searching for source
* and target types/attributes. Strings will be treated as regexes
* instead of literals. Matching will occur against the type name or
* any of its aliases.
*
* @param p Policy handler, to report errors.
* @param a AV rule query to set.
* @param is_regex Non-zero to enable regex searching, 0 to disable.
*
* @return Always 0.
*/
extern int apol_avrule_query_set_regex(const apol_policy_t * p, apol_avrule_query_t * a, int is_regex);
/**
* Given a single avrule, return a newly allocated vector of
* qpol_syn_avrule_t pointers (relative to the given policy) which
* comprise that rule. The vector will be sorted by line numbers if
* the policy has line numbers. If the given perms vector is non-NULL
* and non-empty, then only return syntactic rules with at least one
* permission listed within the perms vector.
*
* @param p Policy from which to obtain syntactic rules.
* @param rule AV rule to convert.
* @param perms If non-NULL and non-empty, a list of permission
* strings. Returned syn avrules will have at least one permission in
* common with this list.
*
* @return A newly allocated vector of syn_avrule_t pointers. The
* caller is responsible for calling apol_vector_destroy() afterwards.
*/
extern apol_vector_t *apol_avrule_to_syn_avrules(const apol_policy_t * p, const qpol_avrule_t * rule,
const apol_vector_t * perms);
/**
* Given a vector of avrules (qpol_avrule_t pointers), return a newly
* allocated vector of qpol_syn_avrule_t pointers (relative to the
* given policy) which comprise all of those rules. The returned
* vector will be sorted by line numbers if the policy has line
* numbers. Also, it will not have any duplicate syntactic rules. If
* the given perms vector is non-NULL and non-empty, then only return
* syntactic rules with at least one permission listed within the
* perms vector.
*
* @param p Policy from which to obtain syntactic rules.
* @param rules Vector of AV rules to convert.
* @param perms If non-NULL and non-empty, a list of permission
* strings. Returned syn avrules will have at least one permission in
* common with this list.
*
* @return A newly allocated vector of syn_avrule_t pointers. The
* caller is responsible for calling apol_vector_destroy() afterwards.
*/
extern apol_vector_t *apol_avrule_list_to_syn_avrules(const apol_policy_t * p, const apol_vector_t * rules,
const apol_vector_t * perms);
/**
* Render an avrule to a string.
*
* @param policy Policy handler, to report errors.
* @param rule The rule to render.
*
* @return a newly malloc()'d string representation of the rule, or NULL on
* failure; if the call fails, errno will be set. The caller is responsible
* for calling free() on the returned string.
*/
extern char *apol_avrule_render(const apol_policy_t * policy, const qpol_avrule_t * rule);
/**
* Render a syntactic avrule to a string.
*
* @param policy Policy handler to report errors.
* @param rule The rule to render.
*
* @return a newly malloc()'d string representation of the rule, or NULL on
* failure; if the call fails, errno will be set. The caller is responsible
* for calling free() on the returned string.
*/
extern char *apol_syn_avrule_render(const apol_policy_t * policy, const qpol_syn_avrule_t * rule);
#ifdef __cplusplus
}
#endif
#endif
|