1/*
2 * Copyright 2011 Tresys Technology, LLC. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 *
7 *    1. Redistributions of source code must retain the above copyright notice,
8 *       this list of conditions and the following disclaimer.
9 *
10 *    2. Redistributions in binary form must reproduce the above copyright notice,
11 *       this list of conditions and the following disclaimer in the documentation
12 *       and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY TRESYS TECHNOLOGY, LLC ``AS IS'' AND ANY EXPRESS
15 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
16 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
17 * EVENT SHALL TRESYS TECHNOLOGY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
18 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
19 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
21 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
22 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
23 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 *
25 * The views and conclusions contained in the software and documentation are those
26 * of the authors and should not be interpreted as representing official policies,
27 * either expressed or implied, of Tresys Technology, LLC.
28 */
29
30#ifndef CIL_BUILD_AST_H_
31#define CIL_BUILD_AST_H_
32
33#include <stdint.h>
34
35#include "cil_internal.h"
36#include "cil_flavor.h"
37#include "cil_tree.h"
38#include "cil_list.h"
39
40int cil_gen_node(struct cil_db *db, struct cil_tree_node *ast_node, struct cil_symtab_datum *datum, hashtab_key_t key, enum cil_sym_index sflavor, enum cil_flavor nflavor);
41int cil_parse_to_list(struct cil_tree_node *parse_cl_head, struct cil_list *ast_cl, enum cil_flavor flavor);
42
43int cil_gen_block(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node, uint16_t is_abstract);
44void cil_destroy_block(struct cil_block *block);
45int cil_gen_blockinherit(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
46void cil_destroy_blockinherit(struct cil_blockinherit *inherit);
47int cil_gen_blockabstract(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
48void cil_destroy_blockabstract(struct cil_blockabstract *abstract);
49int cil_gen_in(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
50void cil_destroy_in(struct cil_in *in);
51int cil_gen_class(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
52void cil_destroy_class(struct cil_class *class);
53int cil_gen_classorder(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
54void cil_destroy_classorder(struct cil_classorder *classorder);
55int cil_gen_perm(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node, enum cil_flavor flavor, unsigned int *num_perms);
56void cil_destroy_perm(struct cil_perm *perm);
57int cil_gen_perm_nodes(struct cil_db *db, struct cil_tree_node *current_perm, struct cil_tree_node *ast_node, enum cil_flavor flavor, unsigned int *num_perms);
58int cil_fill_perms(struct cil_tree_node *start_perm, struct cil_list **perm_strs);
59int cil_fill_classperms(struct cil_tree_node *parse_current, struct cil_classperms **cp);
60void cil_destroy_classperms(struct cil_classperms *cp);
61void cil_fill_classperms_set(struct cil_tree_node *parse_current, struct cil_classperms_set **cp_set);
62void cil_destroy_classperms_set(struct cil_classperms_set *cp_set);
63int cil_fill_classperms_list(struct cil_tree_node *parse_current, struct cil_list **expr_list);
64void cil_destroy_classperms_list(struct cil_list **cp_list);
65int cil_gen_classpermission(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
66void cil_destroy_classpermission(struct cil_classpermission *cp);
67int cil_gen_classpermissionset(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
68void cil_destroy_classpermissionset(struct cil_classpermissionset *cps);
69int cil_gen_map_class(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
70int cil_gen_classmapping(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
71void cil_destroy_classmapping(struct cil_classmapping *mapping);
72int cil_gen_common(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
73int cil_gen_classcommon(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
74void cil_destroy_classcommon(struct cil_classcommon *clscom);
75int cil_gen_sid(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
76void cil_destroy_sid(struct cil_sid *sid);
77int cil_gen_sidcontext(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
78void cil_destroy_sidcontext(struct cil_sidcontext *sidcon);
79int cil_gen_sidorder(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
80void cil_destroy_sidorder(struct cil_sidorder *sidorder);
81int cil_gen_user(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
82void cil_destroy_user(struct cil_user *user);
83int cil_gen_userlevel(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
84void cil_destroy_userlevel(struct cil_userlevel *usrlvl);
85int cil_gen_userrange(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
86void cil_destroy_userrange(struct cil_userrange *userrange);
87int cil_gen_userbounds(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
88int cil_gen_userprefix(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
89void cil_destroy_userprefix(struct cil_userprefix *userprefix);
90int cil_gen_selinuxuser(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
91int cil_gen_selinuxuserdefault(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
92void cil_destroy_selinuxuser(struct cil_selinuxuser *selinuxuser);
93int cil_gen_role(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
94void cil_destroy_role(struct cil_role *role);
95int cil_gen_roletype(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
96void cil_destroy_roletype(struct cil_roletype *roletype);
97int cil_gen_userrole(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
98void cil_destroy_userrole(struct cil_userrole *userrole);
99int cil_gen_roletransition(struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
100void cil_destroy_roletransition(struct cil_roletransition *roletrans);
101int cil_gen_roleallow(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
102void cil_destroy_roleallow(struct cil_roleallow *roleallow);
103int cil_gen_roleattribute(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
104void cil_destroy_roleattribute(struct cil_roleattribute *role);
105int cil_gen_roleattributeset(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
106void cil_destroy_roleattributeset(struct cil_roleattributeset *attrset);
107int cil_gen_rolebounds(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
108int cil_gen_avrule(struct cil_tree_node *parse_current, struct cil_tree_node *ast_node, uint32_t rule_kind);
109void cil_destroy_avrule(struct cil_avrule *rule);
110int cil_gen_type_rule(struct cil_tree_node *parse_current, struct cil_tree_node *ast_node, uint32_t rule_kind);
111void cil_destroy_type_rule(struct cil_type_rule *rule);
112int cil_gen_type(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
113void cil_destroy_type(struct cil_type *type);
114int cil_gen_typeattribute(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
115void cil_destroy_typeattribute(struct cil_typeattribute *type);
116int cil_gen_bool(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node, int tunableif);
117void cil_destroy_bool(struct cil_bool *boolean);
118int cil_gen_tunable(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
119void cil_destroy_tunable(struct cil_tunable *tunable);
120int cil_gen_constrain_expr(struct cil_tree_node *current, enum cil_flavor flavor, struct cil_list **stack);
121int cil_gen_expr(struct cil_tree_node *current, enum cil_flavor flavor, struct cil_list **stack);
122int cil_gen_boolif(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node, int tunable_if);
123void cil_destroy_boolif(struct cil_booleanif *bif);
124int cil_gen_tunif(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
125void cil_destroy_tunif(struct cil_tunableif *tif);
126int cil_gen_condblock(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node, enum cil_flavor flavor);
127void cil_destroy_condblock(struct cil_condblock *cb);
128int cil_gen_alias(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node, enum cil_flavor flavor);
129void cil_destroy_alias(struct cil_alias *alias);
130int cil_gen_aliasactual(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node, enum cil_flavor flavor);
131void cil_destroy_aliasactual(struct cil_aliasactual *aliasactual);
132int cil_gen_typeattributeset(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
133void cil_destroy_typeattributeset(struct cil_typeattributeset *attrtypes);
134int cil_gen_typebounds(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
135int cil_gen_typepermissive(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
136void cil_destroy_typepermissive(struct cil_typepermissive *typeperm);
137int cil_gen_typetransition(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
138void cil_destroy_name(struct cil_name *name);
139void cil_destroy_typetransition(struct cil_nametypetransition *nametypetrans);
140int cil_gen_rangetransition(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
141void cil_destroy_rangetransition(struct cil_rangetransition *rangetrans);
142int cil_gen_sensitivity(struct cil_db *idb, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
143void cil_destroy_sensitivity(struct cil_sens *sens);
144int cil_gen_category(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
145void cil_destroy_category(struct cil_cat *cat);
146int cil_set_to_list(struct cil_tree_node *parse_current, struct cil_list *ast_cl);
147void cil_destroy_catset(struct cil_catset *catset);
148int cil_gen_catorder(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
149void cil_destroy_catorder(struct cil_catorder *catorder);
150int cil_gen_sensitivityorder(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
151void cil_destroy_sensitivityorder(struct cil_sensorder *sensorder);
152int cil_gen_senscat(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
153void cil_destroy_senscat(struct cil_senscat *senscat);
154int cil_gen_level(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
155void cil_destroy_level(struct cil_level *level);
156int cil_fill_levelrange(struct cil_tree_node *low, struct cil_levelrange *lvlrange);
157int cil_gen_levelrange(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
158void cil_destroy_levelrange(struct cil_levelrange *lvlrange);
159void cil_destroy_constrain_node(struct cil_tree_node *cons_node);
160int cil_gen_constrain(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node, enum cil_flavor flavor);
161void cil_destroy_constrain(struct cil_constrain *cons);
162int cil_gen_validatetrans(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node, enum cil_flavor flavor);
163void cil_destroy_validatetrans(struct cil_validatetrans *validtrans);
164int cil_fill_context(struct cil_tree_node *user_node, struct cil_context *context);
165int cil_gen_context(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
166void cil_destroy_context(struct cil_context *context);
167int cil_gen_filecon(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
168void cil_destroy_filecon(struct cil_filecon *filecon);
169int cil_gen_portcon(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
170void cil_destroy_portcon(struct cil_portcon *portcon);
171int cil_gen_nodecon(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
172void cil_destroy_nodecon(struct cil_nodecon *nodecon);
173int cil_gen_genfscon(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
174void cil_destroy_genfscon(struct cil_genfscon *genfscon);
175int cil_gen_netifcon(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
176void cil_destroy_netifcon(struct cil_netifcon *netifcon);
177int cil_gen_pirqcon(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
178void cil_destroy_pirqcon(struct cil_pirqcon *pirqcon);
179int cil_gen_iomemcon(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
180void cil_destroy_iomemcon(struct cil_iomemcon *iomemcon);
181int cil_gen_ioportcon(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
182void cil_destroy_ioportcon(struct cil_ioportcon *ioportcon);
183int cil_gen_pcidevicecon(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
184void cil_destroy_pcidevicecon(struct cil_pcidevicecon *pcidevicecon);
185int cil_gen_devicetreecon(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
186void cil_destroy_devicetreecon(struct cil_devicetreecon *devicetreecon);
187int cil_gen_fsuse(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
188void cil_destroy_fsuse(struct cil_fsuse *fsuse);
189void cil_destroy_param(struct cil_param *param);
190int cil_gen_macro(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
191void cil_destroy_macro(struct cil_macro *macro);
192int cil_gen_call(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
193void cil_destroy_call(struct cil_call *call);
194void cil_destroy_args(struct cil_args *args);
195int cil_gen_optional(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
196void cil_destroy_optional(struct cil_optional *optional);
197int cil_gen_policycap(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
198void cil_destroy_policycap(struct cil_policycap *polcap);
199int cil_gen_ipaddr(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
200void cil_destroy_ipaddr(struct cil_ipaddr *ipaddr);
201int cil_gen_bounds(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node, enum cil_flavor flavor);
202void cil_destroy_bounds(struct cil_bounds *bounds);
203int cil_gen_default(struct cil_tree_node *parse_current, struct cil_tree_node *ast_node, enum cil_flavor flavor);
204void cil_destroy_default(struct cil_default *def);
205int cil_gen_handleunknown(struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
206void cil_destroy_handleunknown(struct cil_handleunknown *unk);
207int cil_gen_mls(struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
208void cil_destroy_mls(struct cil_mls *mls);
209int cil_gen_defaultrange(struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
210void cil_destroy_defaultrange(struct cil_defaultrange *def);
211
212int cil_fill_cats(struct cil_tree_node *curr, struct cil_cats **cats);
213void cil_destroy_cats(struct cil_cats *cats);
214int cil_fill_context(struct cil_tree_node *user_node, struct cil_context *context);
215int cil_fill_integer(struct cil_tree_node *int_node, uint32_t *integer);
216int cil_fill_integer64(struct cil_tree_node *int_node, uint64_t *integer);
217int cil_fill_ipaddr(struct cil_tree_node *addr_node, struct cil_ipaddr *addr);
218int cil_fill_level(struct cil_tree_node *sens, struct cil_level *level);
219
220int cil_build_ast(struct cil_db *db, struct cil_tree_node *parse_tree, struct cil_tree_node *ast);
221
222#endif /* CIL_BUILD_AST_H_ */
223