blob: fa9140067401a4ecbdf756487193014eeafcc4c7 [file] [log] [blame]
Joshua Brindle13cd4c82008-08-19 15:30:36 -04001/* Author : Joshua Brindle <jbrindle@tresys.com>
2 * Karl MacMillan <kmacmillan@tresys.com>
3 * Jason Tang <jtang@tresys.com>
4 * Added support for binary policy modules
5 *
6 * Copyright (C) 2004 - 2005 Tresys Technology, LLC
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, version 2.
10 */
11
12#ifndef MODULE_COMPILER_H
13#define MODULE_COMPILER_H
14
15#include <sepol/policydb/hashtab.h>
16
17/* Called when checkpolicy begins to parse a policy -- either at the
18 * very beginning for a kernel/base policy, or after the module header
19 * for policy modules. Initialize the memory structures within.
20 * Return 0 on success, -1 on error. */
21int define_policy(int pass, int module_header_given);
22
23/* Declare a symbol declaration to the current avrule_decl. Check
24 * that insertion is allowed here and that the symbol does not already
25 * exist. Returns 0 on success, 1 if symbol was already there (caller
26 * needs to free() the datum), -1 if declarations not allowed, -2 for
27 * duplicate declarations, -3 for all else.
28 */
29int declare_symbol(uint32_t symbol_type,
30 hashtab_key_t key, hashtab_datum_t datum,
31 uint32_t * dest_value, uint32_t * datum_value);
32
33role_datum_t *declare_role(void);
34type_datum_t *declare_type(unsigned char primary, unsigned char isattr);
35user_datum_t *declare_user(void);
36
37type_datum_t *get_local_type(char *id, uint32_t value, unsigned char isattr);
38
39/* Add a symbol to the current avrule_block's require section. Note
40 * that a module may not both declare and require the same symbol.
41 * Returns 0 on success, -1 on error. */
42int require_symbol(uint32_t symbol_type,
43 hashtab_key_t key, hashtab_datum_t datum,
44 uint32_t * dest_value, uint32_t * datum_value);
45
46/* Enable a permission for a class within the current avrule_decl.
47 * Return 0 on success, -1 if out of memory. */
48int add_perm_to_class(uint32_t perm_value, uint32_t class_value);
49
50/* Functions called from REQUIRE blocks. Add the first symbol on the
51 * id_queue to this avrule_decl's scope if not already there.
52 * c.f. require_symbol(). */
53int require_class(int pass);
54int require_role(int pass);
55int require_type(int pass);
56int require_attribute(int pass);
57int require_user(int pass);
58int require_bool(int pass);
59int require_sens(int pass);
60int require_cat(int pass);
61
62/* Check if an identifier is within the scope of the current
63 * declaration or any of its parents. Return 1 if it is, 0 if not.
64 * If the identifier is not known at all then return 1 (truth). */
65int is_id_in_scope(uint32_t symbol_type, hashtab_key_t id);
66
67/* Check if a particular permission is within the scope of the current
68 * declaration or any of its parents. Return 1 if it is, 0 if not.
69 * If the identifier is not known at all then return 1 (truth). */
70int is_perm_in_scope(hashtab_key_t perm_id, hashtab_key_t class_id);
71
72/* Search the current avrules block for a conditional with the same
73 * expression as 'cond'. If the conditional does not exist then
74 * create one. Either way, return the conditional. */
75cond_list_t *get_current_cond_list(cond_list_t * cond);
76
77/* Append rule to the current avrule_block. */
78void append_cond_list(cond_list_t * cond);
79void append_avrule(avrule_t * avrule);
80void append_role_trans(role_trans_rule_t * role_tr_rules);
81void append_role_allow(role_allow_rule_t * role_allow_rules);
82void append_range_trans(range_trans_rule_t * range_tr_rules);
83
84/* Create a new optional block and add it to the global policy.
85 * During the second pass resolve the block's requirements. Return 0
86 * on success, -1 on error.
87 */
88int begin_optional(int pass);
89int end_optional(int pass);
90
91/* ELSE blocks are similar to normal blocks with the following two
92 * limitations:
93 * - no declarations are allowed within else branches
94 * - no REQUIRES are allowed; the else branch inherits the parent's
95 * requirements
96 */
97int begin_optional_else(int pass);
98
99/* Called whenever existing an avrule block. Check that the block had
100 * a non-empty REQUIRE section. If so pop the block off of the scop
101 * stack and return 0. If not then send an error to yyerror and
102 * return -1. */
103int end_avrule_block(int pass);
104
105#endif