policydb.h revision 255e72915d4cbddceb435e13d81601755714e9f3
1 2/* Author : Stephen Smalley, <sds@epoch.ncsc.mil> */ 3 4/* 5 * Updated: Joshua Brindle <jbrindle@tresys.com> 6 * Karl MacMillan <kmacmillan@tresys.com> 7 * Jason Tang <jtang@tresys.com> 8 * 9 * Module support 10 * 11 * Updated: Trusted Computer Solutions, Inc. <dgoeddel@trustedcs.com> 12 * 13 * Support for enhanced MLS infrastructure. 14 * 15 * Updated: Frank Mayer <mayerf@tresys.com> and Karl MacMillan <kmacmillan@tresys.com> 16 * 17 * Added conditional policy language extensions 18 * 19 * Updated: Red Hat, Inc. James Morris <jmorris@redhat.com> 20 * 21 * Fine-grained netlink support 22 * IPv6 support 23 * Code cleanup 24 * 25 * Copyright (C) 2004-2005 Trusted Computer Solutions, Inc. 26 * Copyright (C) 2003 - 2004 Tresys Technology, LLC 27 * Copyright (C) 2003 - 2004 Red Hat, Inc. 28 * 29 * This library is free software; you can redistribute it and/or 30 * modify it under the terms of the GNU Lesser General Public 31 * License as published by the Free Software Foundation; either 32 * version 2.1 of the License, or (at your option) any later version. 33 * 34 * This library is distributed in the hope that it will be useful, 35 * but WITHOUT ANY WARRANTY; without even the implied warranty of 36 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 37 * Lesser General Public License for more details. 38 * 39 * You should have received a copy of the GNU Lesser General Public 40 * License along with this library; if not, write to the Free Software 41 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 42 */ 43 44/* FLASK */ 45 46/* 47 * A policy database (policydb) specifies the 48 * configuration data for the security policy. 49 */ 50 51#ifndef _SEPOL_POLICYDB_POLICYDB_H_ 52#define _SEPOL_POLICYDB_POLICYDB_H_ 53 54#include <stdio.h> 55#include <stddef.h> 56 57#include <sepol/policydb.h> 58 59#include <sepol/policydb/flask_types.h> 60#include <sepol/policydb/symtab.h> 61#include <sepol/policydb/avtab.h> 62#include <sepol/policydb/context.h> 63#include <sepol/policydb/constraint.h> 64#include <sepol/policydb/sidtab.h> 65 66#define ERRMSG_LEN 1024 67 68#define POLICYDB_SUCCESS 0 69#define POLICYDB_ERROR -1 70#define POLICYDB_UNSUPPORTED -2 71 72/* 73 * A datum type is defined for each kind of symbol 74 * in the configuration data: individual permissions, 75 * common prefixes for access vectors, classes, 76 * users, roles, types, sensitivities, categories, etc. 77 */ 78 79/* type set preserves data needed by modules such as *, ~ and attributes */ 80typedef struct type_set { 81 ebitmap_t types; 82 ebitmap_t negset; 83#define TYPE_STAR 1 84#define TYPE_COMP 2 85 uint32_t flags; 86} type_set_t; 87 88typedef struct role_set { 89 ebitmap_t roles; 90#define ROLE_STAR 1 91#define ROLE_COMP 2 92 uint32_t flags; 93} role_set_t; 94 95/* Permission attributes */ 96typedef struct perm_datum { 97 symtab_datum_t s; 98} perm_datum_t; 99 100/* Attributes of a common prefix for access vectors */ 101typedef struct common_datum { 102 symtab_datum_t s; 103 symtab_t permissions; /* common permissions */ 104} common_datum_t; 105 106/* Class attributes */ 107typedef struct class_datum { 108 symtab_datum_t s; 109 char *comkey; /* common name */ 110 common_datum_t *comdatum; /* common datum */ 111 symtab_t permissions; /* class-specific permission symbol table */ 112 constraint_node_t *constraints; /* constraints on class permissions */ 113 constraint_node_t *validatetrans; /* special transition rules */ 114} class_datum_t; 115 116/* Role attributes */ 117typedef struct role_datum { 118 symtab_datum_t s; 119 ebitmap_t dominates; /* set of roles dominated by this role */ 120 type_set_t types; /* set of authorized types for role */ 121 ebitmap_t cache; /* This is an expanded set used for context validation during parsing */ 122 uint32_t bounds; /* bounds role, if exist */ 123#define ROLE_ROLE 0 /* regular role in kernel policies */ 124#define ROLE_ATTRIB 1 /* attribute */ 125 uint32_t flavor; 126 ebitmap_t roles; /* roles with this attribute */ 127} role_datum_t; 128 129typedef struct role_trans { 130 uint32_t role; /* current role */ 131 uint32_t type; /* program executable type, or new object type */ 132 uint32_t tclass; /* process class, or new object class */ 133 uint32_t new_role; /* new role */ 134 struct role_trans *next; 135} role_trans_t; 136 137typedef struct role_allow { 138 uint32_t role; /* current role */ 139 uint32_t new_role; /* new role */ 140 struct role_allow *next; 141} role_allow_t; 142 143/* filename_trans rules */ 144typedef struct filename_trans { 145 uint32_t stype; 146 uint32_t ttype; 147 uint32_t tclass; 148 char *name; 149 uint32_t otype; 150 struct filename_trans *next; 151} filename_trans_t; 152 153/* Type attributes */ 154typedef struct type_datum { 155 symtab_datum_t s; 156 uint32_t primary; /* primary name? can be set to primary value if below is TYPE_ */ 157#define TYPE_TYPE 0 /* regular type or alias in kernel policies */ 158#define TYPE_ATTRIB 1 /* attribute */ 159#define TYPE_ALIAS 2 /* alias in modular policy */ 160 uint32_t flavor; 161 ebitmap_t types; /* types with this attribute */ 162#define TYPE_FLAGS_PERMISSIVE 0x01 163 uint32_t flags; 164 uint32_t bounds; /* bounds type, if exist */ 165} type_datum_t; 166 167/* 168 * Properties of type_datum 169 * available on the policy version >= (MOD_)POLICYDB_VERSION_BOUNDARY 170 */ 171#define TYPEDATUM_PROPERTY_PRIMARY 0x0001 172#define TYPEDATUM_PROPERTY_ATTRIBUTE 0x0002 173#define TYPEDATUM_PROPERTY_ALIAS 0x0004 /* userspace only */ 174#define TYPEDATUM_PROPERTY_PERMISSIVE 0x0008 /* userspace only */ 175 176/* User attributes */ 177typedef struct user_datum { 178 symtab_datum_t s; 179 role_set_t roles; /* set of authorized roles for user */ 180 mls_semantic_range_t range; /* MLS range (min. - max.) for user */ 181 mls_semantic_level_t dfltlevel; /* default login MLS level for user */ 182 ebitmap_t cache; /* This is an expanded set used for context validation during parsing */ 183 mls_range_t exp_range; /* expanded range used for validation */ 184 mls_level_t exp_dfltlevel; /* expanded range used for validation */ 185 uint32_t bounds; /* bounds user, if exist */ 186} user_datum_t; 187 188/* Sensitivity attributes */ 189typedef struct level_datum { 190 mls_level_t *level; /* sensitivity and associated categories */ 191 unsigned char isalias; /* is this sensitivity an alias for another? */ 192 unsigned char defined; 193} level_datum_t; 194 195/* Category attributes */ 196typedef struct cat_datum { 197 symtab_datum_t s; 198 unsigned char isalias; /* is this category an alias for another? */ 199} cat_datum_t; 200 201typedef struct range_trans { 202 uint32_t source_type; 203 uint32_t target_type; 204 uint32_t target_class; 205 mls_range_t target_range; 206 struct range_trans *next; 207} range_trans_t; 208 209/* Boolean data type */ 210typedef struct cond_bool_datum { 211 symtab_datum_t s; 212 int state; 213} cond_bool_datum_t; 214 215struct cond_node; 216 217typedef struct cond_node cond_list_t; 218struct cond_av_list; 219 220typedef struct class_perm_node { 221 uint32_t class; 222 uint32_t data; /* permissions or new type */ 223 struct class_perm_node *next; 224} class_perm_node_t; 225 226typedef struct avrule { 227/* these typedefs are almost exactly the same as those in avtab.h - they are 228 * here because of the need to include neverallow and dontaudit messages */ 229#define AVRULE_ALLOWED 1 230#define AVRULE_AUDITALLOW 2 231#define AVRULE_AUDITDENY 4 232#define AVRULE_DONTAUDIT 8 233#define AVRULE_NEVERALLOW 128 234#define AVRULE_AV (AVRULE_ALLOWED | AVRULE_AUDITALLOW | AVRULE_AUDITDENY | AVRULE_DONTAUDIT | AVRULE_NEVERALLOW) 235#define AVRULE_TRANSITION 16 236#define AVRULE_MEMBER 32 237#define AVRULE_CHANGE 64 238#define AVRULE_TYPE (AVRULE_TRANSITION | AVRULE_MEMBER | AVRULE_CHANGE) 239 uint32_t specified; 240#define RULE_SELF 1 241 uint32_t flags; 242 type_set_t stypes; 243 type_set_t ttypes; 244 class_perm_node_t *perms; 245 unsigned long line; /* line number from policy.conf where 246 * this rule originated */ 247 struct avrule *next; 248} avrule_t; 249 250typedef struct role_trans_rule { 251 role_set_t roles; /* current role */ 252 type_set_t types; /* program executable type, or new object type */ 253 ebitmap_t classes; /* process class, or new object class */ 254 uint32_t new_role; /* new role */ 255 struct role_trans_rule *next; 256} role_trans_rule_t; 257 258typedef struct role_allow_rule { 259 role_set_t roles; /* current role */ 260 role_set_t new_roles; /* new roles */ 261 struct role_allow_rule *next; 262} role_allow_rule_t; 263 264typedef struct filename_trans_rule { 265 type_set_t stypes; 266 type_set_t ttypes; 267 uint32_t tclass; 268 char *name; 269 uint32_t otype; /* new type */ 270 struct filename_trans_rule *next; 271} filename_trans_rule_t; 272 273typedef struct range_trans_rule { 274 type_set_t stypes; 275 type_set_t ttypes; 276 ebitmap_t tclasses; 277 mls_semantic_range_t trange; 278 struct range_trans_rule *next; 279} range_trans_rule_t; 280 281/* 282 * The configuration data includes security contexts for 283 * initial SIDs, unlabeled file systems, TCP and UDP port numbers, 284 * network interfaces, and nodes. This structure stores the 285 * relevant data for one such entry. Entries of the same kind 286 * (e.g. all initial SIDs) are linked together into a list. 287 */ 288typedef struct ocontext { 289 union { 290 char *name; /* name of initial SID, fs, netif, fstype, path */ 291 struct { 292 uint8_t protocol; 293 uint16_t low_port; 294 uint16_t high_port; 295 } port; /* TCP or UDP port information */ 296 struct { 297 uint32_t addr; /* network order */ 298 uint32_t mask; /* network order */ 299 } node; /* node information */ 300 struct { 301 uint32_t addr[4]; /* network order */ 302 uint32_t mask[4]; /* network order */ 303 } node6; /* IPv6 node information */ 304 uint32_t device; 305 uint16_t pirq; 306 struct { 307 uint32_t low_iomem; 308 uint32_t high_iomem; 309 } iomem; 310 struct { 311 uint32_t low_ioport; 312 uint32_t high_ioport; 313 } ioport; 314 } u; 315 union { 316 uint32_t sclass; /* security class for genfs */ 317 uint32_t behavior; /* labeling behavior for fs_use */ 318 } v; 319 context_struct_t context[2]; /* security context(s) */ 320 sepol_security_id_t sid[2]; /* SID(s) */ 321 struct ocontext *next; 322} ocontext_t; 323 324typedef struct genfs { 325 char *fstype; 326 struct ocontext *head; 327 struct genfs *next; 328} genfs_t; 329 330/* symbol table array indices */ 331#define SYM_COMMONS 0 332#define SYM_CLASSES 1 333#define SYM_ROLES 2 334#define SYM_TYPES 3 335#define SYM_USERS 4 336#define SYM_BOOLS 5 337#define SYM_LEVELS 6 338#define SYM_CATS 7 339#define SYM_NUM 8 340 341/* object context array indices */ 342#define OCON_ISID 0 /* initial SIDs */ 343#define OCON_FS 1 /* unlabeled file systems */ 344#define OCON_PORT 2 /* TCP and UDP port numbers */ 345#define OCON_NETIF 3 /* network interfaces */ 346#define OCON_NODE 4 /* nodes */ 347#define OCON_FSUSE 5 /* fs_use */ 348#define OCON_NODE6 6 /* IPv6 nodes */ 349#define OCON_GENFS 7 /* needed for ocontext_supported */ 350 351/* object context array indices for Xen */ 352#define OCON_XEN_ISID 0 /* initial SIDs */ 353#define OCON_XEN_PIRQ 1 /* physical irqs */ 354#define OCON_XEN_IOPORT 2 /* io ports */ 355#define OCON_XEN_IOMEM 3 /* io memory */ 356#define OCON_XEN_PCIDEVICE 4 /* pci devices */ 357 358/* OCON_NUM needs to be the largest index in any platform's ocontext array */ 359#define OCON_NUM 7 360 361/* section: module information */ 362 363/* scope_index_t holds all of the symbols that are in scope in a 364 * particular situation. The bitmaps are indices (and thus must 365 * subtract one) into the global policydb->scope array. */ 366typedef struct scope_index { 367 ebitmap_t scope[SYM_NUM]; 368#define p_classes_scope scope[SYM_CLASSES] 369#define p_roles_scope scope[SYM_ROLES] 370#define p_types_scope scope[SYM_TYPES] 371#define p_users_scope scope[SYM_USERS] 372#define p_bools_scope scope[SYM_BOOLS] 373#define p_sens_scope scope[SYM_LEVELS] 374#define p_cat_scope scope[SYM_CATS] 375 376 /* this array maps from class->value to the permissions within 377 * scope. if bit (perm->value - 1) is set in map 378 * class_perms_map[class->value - 1] then that permission is 379 * enabled for this class within this decl. */ 380 ebitmap_t *class_perms_map; 381 /* total number of classes in class_perms_map array */ 382 uint32_t class_perms_len; 383} scope_index_t; 384 385/* a list of declarations for a particular avrule_decl */ 386 387/* These two structs declare a block of policy that has TE and RBAC 388 * statements and declarations. The root block (the global policy) 389 * can never have an ELSE branch. */ 390typedef struct avrule_decl { 391 uint32_t decl_id; 392 uint32_t enabled; /* whether this block is enabled */ 393 394 cond_list_t *cond_list; 395 avrule_t *avrules; 396 role_trans_rule_t *role_tr_rules; 397 role_allow_rule_t *role_allow_rules; 398 range_trans_rule_t *range_tr_rules; 399 scope_index_t required; /* symbols needed to activate this block */ 400 scope_index_t declared; /* symbols declared within this block */ 401 402 /* type transition rules with a 'name' component */ 403 filename_trans_rule_t *filename_trans_rules; 404 405 /* for additive statements (type attribute, roles, and users) */ 406 symtab_t symtab[SYM_NUM]; 407 408 /* In a linked module this will contain the name of the module 409 * from which this avrule_decl originated. */ 410 char *module_name; 411 412 struct avrule_decl *next; 413} avrule_decl_t; 414 415typedef struct avrule_block { 416 avrule_decl_t *branch_list; 417 avrule_decl_t *enabled; /* pointer to which branch is enabled. this is 418 used in linking and never written to disk */ 419#define AVRULE_OPTIONAL 1 420 uint32_t flags; /* any flags for this block, currently just optional */ 421 struct avrule_block *next; 422} avrule_block_t; 423 424/* Every identifier has its own scope datum. The datum describes if 425 * the item is to be included into the final policy during 426 * expansion. */ 427typedef struct scope_datum { 428/* Required for this decl */ 429#define SCOPE_REQ 1 430/* Declared in this decl */ 431#define SCOPE_DECL 2 432 uint32_t scope; 433 uint32_t *decl_ids; 434 uint32_t decl_ids_len; 435 /* decl_ids is a list of avrule_decl's that declare/require 436 * this symbol. If scope==SCOPE_DECL then this is a list of 437 * declarations. If the symbol may only be declared once 438 * (types, bools) then decl_ids_len will be exactly 1. For 439 * implicitly declared things (roles, users) then decl_ids_len 440 * will be at least 1. */ 441} scope_datum_t; 442 443/* The policy database */ 444typedef struct policydb { 445#define POLICY_KERN SEPOL_POLICY_KERN 446#define POLICY_BASE SEPOL_POLICY_BASE 447#define POLICY_MOD SEPOL_POLICY_MOD 448 uint32_t policy_type; 449 char *name; 450 char *version; 451 int target_platform; 452 453 /* Set when the policydb is modified such that writing is unsupported */ 454 int unsupported_format; 455 456 /* Whether this policydb is mls, should always be set */ 457 int mls; 458 459 /* symbol tables */ 460 symtab_t symtab[SYM_NUM]; 461#define p_commons symtab[SYM_COMMONS] 462#define p_classes symtab[SYM_CLASSES] 463#define p_roles symtab[SYM_ROLES] 464#define p_types symtab[SYM_TYPES] 465#define p_users symtab[SYM_USERS] 466#define p_bools symtab[SYM_BOOLS] 467#define p_levels symtab[SYM_LEVELS] 468#define p_cats symtab[SYM_CATS] 469 470 /* symbol names indexed by (value - 1) */ 471 char **sym_val_to_name[SYM_NUM]; 472#define p_common_val_to_name sym_val_to_name[SYM_COMMONS] 473#define p_class_val_to_name sym_val_to_name[SYM_CLASSES] 474#define p_role_val_to_name sym_val_to_name[SYM_ROLES] 475#define p_type_val_to_name sym_val_to_name[SYM_TYPES] 476#define p_user_val_to_name sym_val_to_name[SYM_USERS] 477#define p_bool_val_to_name sym_val_to_name[SYM_BOOLS] 478#define p_sens_val_to_name sym_val_to_name[SYM_LEVELS] 479#define p_cat_val_to_name sym_val_to_name[SYM_CATS] 480 481 /* class, role, and user attributes indexed by (value - 1) */ 482 class_datum_t **class_val_to_struct; 483 role_datum_t **role_val_to_struct; 484 user_datum_t **user_val_to_struct; 485 type_datum_t **type_val_to_struct; 486 487 /* module stuff section -- used in parsing and for modules */ 488 489 /* keep track of the scope for every identifier. these are 490 * hash tables, where the key is the identifier name and value 491 * a scope_datum_t. as a convenience, one may use the 492 * p_*_macros (cf. struct scope_index_t declaration). */ 493 symtab_t scope[SYM_NUM]; 494 495 /* module rule storage */ 496 avrule_block_t *global; 497 /* avrule_decl index used for link/expand */ 498 avrule_decl_t **decl_val_to_struct; 499 500 /* compiled storage of rules - use for the kernel policy */ 501 502 /* type enforcement access vectors and transitions */ 503 avtab_t te_avtab; 504 505 /* bools indexed by (value - 1) */ 506 cond_bool_datum_t **bool_val_to_struct; 507 /* type enforcement conditional access vectors and transitions */ 508 avtab_t te_cond_avtab; 509 /* linked list indexing te_cond_avtab by conditional */ 510 cond_list_t *cond_list; 511 512 /* role transitions */ 513 role_trans_t *role_tr; 514 515 /* type transition rules with a 'name' component */ 516 filename_trans_t *filename_trans; 517 518 /* role allows */ 519 role_allow_t *role_allow; 520 521 /* security contexts of initial SIDs, unlabeled file systems, 522 TCP or UDP port numbers, network interfaces and nodes */ 523 ocontext_t *ocontexts[OCON_NUM]; 524 525 /* security contexts for files in filesystems that cannot support 526 a persistent label mapping or use another 527 fixed labeling behavior. */ 528 genfs_t *genfs; 529 530 /* range transitions */ 531 range_trans_t *range_tr; 532 533 ebitmap_t *type_attr_map; 534 535 ebitmap_t *attr_type_map; /* not saved in the binary policy */ 536 537 ebitmap_t policycaps; 538 539 /* this bitmap is referenced by type NOT the typical type-1 used in other 540 bitmaps. Someday the 0 bit may be used for global permissive */ 541 ebitmap_t permissive_map; 542 543 unsigned policyvers; 544 545 unsigned handle_unknown; 546} policydb_t; 547 548struct sepol_policydb { 549 struct policydb p; 550}; 551 552extern int policydb_init(policydb_t * p); 553 554extern int policydb_from_image(sepol_handle_t * handle, 555 void *data, size_t len, policydb_t * policydb); 556 557extern int policydb_to_image(sepol_handle_t * handle, 558 policydb_t * policydb, void **newdata, 559 size_t * newlen); 560 561extern int policydb_index_classes(policydb_t * p); 562 563extern int policydb_index_bools(policydb_t * p); 564 565extern int policydb_index_others(sepol_handle_t * handle, policydb_t * p, 566 unsigned int verbose); 567 568extern int policydb_reindex_users(policydb_t * p); 569 570extern void policydb_destroy(policydb_t * p); 571 572extern int policydb_load_isids(policydb_t * p, sidtab_t * s); 573 574/* Deprecated */ 575extern int policydb_context_isvalid(const policydb_t * p, 576 const context_struct_t * c); 577 578extern void symtabs_destroy(symtab_t * symtab); 579extern int scope_destroy(hashtab_key_t key, hashtab_datum_t datum, void *p); 580typedef void (*hashtab_destroy_func_t) (hashtab_key_t k, hashtab_datum_t d, 581 void *args); 582extern hashtab_destroy_func_t get_symtab_destroy_func(int sym_num); 583 584extern void class_perm_node_init(class_perm_node_t * x); 585extern void type_set_init(type_set_t * x); 586extern void type_set_destroy(type_set_t * x); 587extern int type_set_cpy(type_set_t * dst, type_set_t * src); 588extern int type_set_or_eq(type_set_t * dst, type_set_t * other); 589extern void role_set_init(role_set_t * x); 590extern void role_set_destroy(role_set_t * x); 591extern void avrule_init(avrule_t * x); 592extern void avrule_destroy(avrule_t * x); 593extern void avrule_list_destroy(avrule_t * x); 594extern void role_trans_rule_init(role_trans_rule_t * x); 595extern void role_trans_rule_list_destroy(role_trans_rule_t * x); 596extern void filename_trans_rule_init(filename_trans_rule_t * x); 597extern void filename_trans_rule_list_destroy(filename_trans_rule_t * x); 598 599extern void role_datum_init(role_datum_t * x); 600extern void role_datum_destroy(role_datum_t * x); 601extern void role_allow_rule_init(role_allow_rule_t * x); 602extern void role_allow_rule_destroy(role_allow_rule_t * x); 603extern void role_allow_rule_list_destroy(role_allow_rule_t * x); 604extern void range_trans_rule_init(range_trans_rule_t *x); 605extern void range_trans_rule_destroy(range_trans_rule_t *x); 606extern void range_trans_rule_list_destroy(range_trans_rule_t *x); 607extern void type_datum_init(type_datum_t * x); 608extern void type_datum_destroy(type_datum_t * x); 609extern void user_datum_init(user_datum_t * x); 610extern void user_datum_destroy(user_datum_t * x); 611extern void level_datum_init(level_datum_t * x); 612extern void level_datum_destroy(level_datum_t * x); 613extern void cat_datum_init(cat_datum_t * x); 614extern void cat_datum_destroy(cat_datum_t * x); 615 616extern int check_assertions(sepol_handle_t * handle, 617 policydb_t * p, avrule_t * avrules); 618 619extern int symtab_insert(policydb_t * x, uint32_t sym, 620 hashtab_key_t key, hashtab_datum_t datum, 621 uint32_t scope, uint32_t avrule_decl_id, 622 uint32_t * value); 623 624/* A policy "file" may be a memory region referenced by a (data, len) pair 625 or a file referenced by a FILE pointer. */ 626typedef struct policy_file { 627#define PF_USE_MEMORY 0 628#define PF_USE_STDIO 1 629#define PF_LEN 2 /* total up length in len field */ 630 unsigned type; 631 char *data; 632 size_t len; 633 size_t size; 634 FILE *fp; 635 struct sepol_handle *handle; 636} policy_file_t; 637 638struct sepol_policy_file { 639 struct policy_file pf; 640}; 641 642extern void policy_file_init(policy_file_t * x); 643 644extern int policydb_read(policydb_t * p, struct policy_file *fp, 645 unsigned int verbose); 646extern int avrule_read_list(policydb_t * p, avrule_t ** avrules, 647 struct policy_file *fp); 648 649extern int policydb_write(struct policydb *p, struct policy_file *pf); 650extern int policydb_set_target_platform(policydb_t *p, int platform); 651 652#define PERM_SYMTAB_SIZE 32 653 654/* Identify specific policy version changes */ 655#define POLICYDB_VERSION_BASE 15 656#define POLICYDB_VERSION_BOOL 16 657#define POLICYDB_VERSION_IPV6 17 658#define POLICYDB_VERSION_NLCLASS 18 659#define POLICYDB_VERSION_VALIDATETRANS 19 660#define POLICYDB_VERSION_MLS 19 661#define POLICYDB_VERSION_AVTAB 20 662#define POLICYDB_VERSION_RANGETRANS 21 663#define POLICYDB_VERSION_POLCAP 22 664#define POLICYDB_VERSION_PERMISSIVE 23 665#define POLICYDB_VERSION_BOUNDARY 24 666#define POLICYDB_VERSION_FILENAME_TRANS 25 667#define POLICYDB_VERSION_ROLETRANS 26 668 669/* Range of policy versions we understand*/ 670#define POLICYDB_VERSION_MIN POLICYDB_VERSION_BASE 671#define POLICYDB_VERSION_MAX POLICYDB_VERSION_ROLETRANS 672 673/* Module versions and specific changes*/ 674#define MOD_POLICYDB_VERSION_BASE 4 675#define MOD_POLICYDB_VERSION_VALIDATETRANS 5 676#define MOD_POLICYDB_VERSION_MLS 5 677#define MOD_POLICYDB_VERSION_RANGETRANS 6 678#define MOD_POLICYDB_VERSION_MLS_USERS 6 679#define MOD_POLICYDB_VERSION_POLCAP 7 680#define MOD_POLICYDB_VERSION_PERMISSIVE 8 681#define MOD_POLICYDB_VERSION_BOUNDARY 9 682#define MOD_POLICYDB_VERSION_BOUNDARY_ALIAS 10 683#define MOD_POLICYDB_VERSION_FILENAME_TRANS 11 684#define MOD_POLICYDB_VERSION_ROLETRANS 12 685#define MOD_POLICYDB_VERSION_ROLEATTRIB 13 686 687#define MOD_POLICYDB_VERSION_MIN MOD_POLICYDB_VERSION_BASE 688#define MOD_POLICYDB_VERSION_MAX MOD_POLICYDB_VERSION_ROLEATTRIB 689 690#define POLICYDB_CONFIG_MLS 1 691 692/* macros to check policy feature */ 693 694/* TODO: add other features here */ 695 696#define policydb_has_boundary_feature(p) \ 697 (((p)->policy_type == POLICY_KERN \ 698 && p->policyvers >= POLICYDB_VERSION_BOUNDARY) || \ 699 ((p)->policy_type != POLICY_KERN \ 700 && p->policyvers >= MOD_POLICYDB_VERSION_BOUNDARY)) 701 702/* the config flags related to unknown classes/perms are bits 2 and 3 */ 703#define DENY_UNKNOWN SEPOL_DENY_UNKNOWN 704#define REJECT_UNKNOWN SEPOL_REJECT_UNKNOWN 705#define ALLOW_UNKNOWN SEPOL_ALLOW_UNKNOWN 706 707#define POLICYDB_CONFIG_UNKNOWN_MASK (DENY_UNKNOWN | REJECT_UNKNOWN | ALLOW_UNKNOWN) 708 709#define OBJECT_R "object_r" 710#define OBJECT_R_VAL 1 711 712#define POLICYDB_MAGIC SELINUX_MAGIC 713#define POLICYDB_STRING "SE Linux" 714#define POLICYDB_XEN_STRING "XenFlask" 715#define POLICYDB_STRING_MAX_LENGTH 32 716#define POLICYDB_MOD_MAGIC SELINUX_MOD_MAGIC 717#define POLICYDB_MOD_STRING "SE Linux Module" 718#define SEPOL_TARGET_SELINUX 0 719#define SEPOL_TARGET_XEN 1 720 721 722#endif /* _POLICYDB_H_ */ 723 724/* FLASK */ 725