policydb.h 21 KB

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