xref: /aosp_15_r20/external/selinux/libsepol/cil/src/cil.c (revision 2d543d20722ada2425b5bdab9d0d1d29470e7bba)
1*2d543d20SAndroid Build Coastguard Worker /*
2*2d543d20SAndroid Build Coastguard Worker  * Copyright 2011 Tresys Technology, LLC. All rights reserved.
3*2d543d20SAndroid Build Coastguard Worker  *
4*2d543d20SAndroid Build Coastguard Worker  * Redistribution and use in source and binary forms, with or without
5*2d543d20SAndroid Build Coastguard Worker  * modification, are permitted provided that the following conditions are met:
6*2d543d20SAndroid Build Coastguard Worker  *
7*2d543d20SAndroid Build Coastguard Worker  *    1. Redistributions of source code must retain the above copyright notice,
8*2d543d20SAndroid Build Coastguard Worker  *       this list of conditions and the following disclaimer.
9*2d543d20SAndroid Build Coastguard Worker  *
10*2d543d20SAndroid Build Coastguard Worker  *    2. Redistributions in binary form must reproduce the above copyright notice,
11*2d543d20SAndroid Build Coastguard Worker  *       this list of conditions and the following disclaimer in the documentation
12*2d543d20SAndroid Build Coastguard Worker  *       and/or other materials provided with the distribution.
13*2d543d20SAndroid Build Coastguard Worker  *
14*2d543d20SAndroid Build Coastguard Worker  * THIS SOFTWARE IS PROVIDED BY TRESYS TECHNOLOGY, LLC ``AS IS'' AND ANY EXPRESS
15*2d543d20SAndroid Build Coastguard Worker  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
16*2d543d20SAndroid Build Coastguard Worker  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
17*2d543d20SAndroid Build Coastguard Worker  * EVENT SHALL TRESYS TECHNOLOGY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
18*2d543d20SAndroid Build Coastguard Worker  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
19*2d543d20SAndroid Build Coastguard Worker  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20*2d543d20SAndroid Build Coastguard Worker  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
21*2d543d20SAndroid Build Coastguard Worker  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
22*2d543d20SAndroid Build Coastguard Worker  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
23*2d543d20SAndroid Build Coastguard Worker  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24*2d543d20SAndroid Build Coastguard Worker  *
25*2d543d20SAndroid Build Coastguard Worker  * The views and conclusions contained in the software and documentation are those
26*2d543d20SAndroid Build Coastguard Worker  * of the authors and should not be interpreted as representing official policies,
27*2d543d20SAndroid Build Coastguard Worker  * either expressed or implied, of Tresys Technology, LLC.
28*2d543d20SAndroid Build Coastguard Worker  */
29*2d543d20SAndroid Build Coastguard Worker 
30*2d543d20SAndroid Build Coastguard Worker #include <stdlib.h>
31*2d543d20SAndroid Build Coastguard Worker #include <stdio.h>
32*2d543d20SAndroid Build Coastguard Worker 
33*2d543d20SAndroid Build Coastguard Worker #include <sepol/policydb/policydb.h>
34*2d543d20SAndroid Build Coastguard Worker #include <sepol/policydb/symtab.h>
35*2d543d20SAndroid Build Coastguard Worker 
36*2d543d20SAndroid Build Coastguard Worker #include "cil_internal.h"
37*2d543d20SAndroid Build Coastguard Worker #include "cil_flavor.h"
38*2d543d20SAndroid Build Coastguard Worker #include "cil_log.h"
39*2d543d20SAndroid Build Coastguard Worker #include "cil_mem.h"
40*2d543d20SAndroid Build Coastguard Worker #include "cil_tree.h"
41*2d543d20SAndroid Build Coastguard Worker #include "cil_list.h"
42*2d543d20SAndroid Build Coastguard Worker #include "cil_symtab.h"
43*2d543d20SAndroid Build Coastguard Worker #include "cil_build_ast.h"
44*2d543d20SAndroid Build Coastguard Worker 
45*2d543d20SAndroid Build Coastguard Worker #include "cil_parser.h"
46*2d543d20SAndroid Build Coastguard Worker #include "cil_build_ast.h"
47*2d543d20SAndroid Build Coastguard Worker #include "cil_resolve_ast.h"
48*2d543d20SAndroid Build Coastguard Worker #include "cil_fqn.h"
49*2d543d20SAndroid Build Coastguard Worker #include "cil_post.h"
50*2d543d20SAndroid Build Coastguard Worker #include "cil_binary.h"
51*2d543d20SAndroid Build Coastguard Worker #include "cil_policy.h"
52*2d543d20SAndroid Build Coastguard Worker #include "cil_strpool.h"
53*2d543d20SAndroid Build Coastguard Worker #include "cil_write_ast.h"
54*2d543d20SAndroid Build Coastguard Worker 
55*2d543d20SAndroid Build Coastguard Worker const int cil_sym_sizes[CIL_SYM_ARRAY_NUM][CIL_SYM_NUM] = {
56*2d543d20SAndroid Build Coastguard Worker 	{64, 64, 64, 1 << 13, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64},
57*2d543d20SAndroid Build Coastguard Worker 	{8, 8, 8, 32, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
58*2d543d20SAndroid Build Coastguard Worker 	{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
59*2d543d20SAndroid Build Coastguard Worker 	{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
60*2d543d20SAndroid Build Coastguard Worker 	{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
61*2d543d20SAndroid Build Coastguard Worker };
62*2d543d20SAndroid Build Coastguard Worker 
63*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_CONS_T1;
64*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_CONS_T2;
65*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_CONS_T3;
66*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_CONS_R1;
67*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_CONS_R2;
68*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_CONS_R3;
69*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_CONS_U1;
70*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_CONS_U2;
71*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_CONS_U3;
72*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_CONS_L1;
73*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_CONS_L2;
74*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_CONS_H1;
75*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_CONS_H2;
76*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_AND;
77*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_OR;
78*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_NOT;
79*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_EQ;
80*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_NEQ;
81*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_CONS_DOM;
82*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_CONS_DOMBY;
83*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_CONS_INCOMP;
84*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_CONDTRUE;
85*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_CONDFALSE;
86*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_SELF;
87*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_NOTSELF;
88*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_OTHER;
89*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_OBJECT_R;
90*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_STAR;
91*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_TCP;
92*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_UDP;
93*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_DCCP;
94*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_SCTP;
95*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_AUDITALLOW;
96*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_TUNABLEIF;
97*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_ALLOW;
98*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_DONTAUDIT;
99*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_TYPETRANSITION;
100*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_TYPECHANGE;
101*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_CALL;
102*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_TUNABLE;
103*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_XOR;
104*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_ALL;
105*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_RANGE;
106*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_GLOB;
107*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_FILE;
108*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_DIR;
109*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_CHAR;
110*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_BLOCK;
111*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_SOCKET;
112*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_PIPE;
113*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_SYMLINK;
114*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_ANY;
115*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_XATTR;
116*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_TASK;
117*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_TRANS;
118*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_TYPE;
119*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_ROLE;
120*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_USER;
121*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_USERATTRIBUTE;
122*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_USERATTRIBUTESET;
123*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_SENSITIVITY;
124*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_CATEGORY;
125*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_CATSET;
126*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_LEVEL;
127*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_LEVELRANGE;
128*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_CLASS;
129*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_IPADDR;
130*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_MAP_CLASS;
131*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_CLASSPERMISSION;
132*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_BOOL;
133*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_STRING;
134*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_NAME;
135*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_SOURCE;
136*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_TARGET;
137*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_LOW;
138*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_HIGH;
139*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_LOW_HIGH;
140*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_GLBLUB;
141*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_HANDLEUNKNOWN;
142*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_HANDLEUNKNOWN_ALLOW;
143*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_HANDLEUNKNOWN_DENY;
144*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_HANDLEUNKNOWN_REJECT;
145*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_MACRO;
146*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_IN;
147*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_IN_BEFORE;
148*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_IN_AFTER;
149*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_MLS;
150*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_DEFAULTRANGE;
151*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_BLOCKINHERIT;
152*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_BLOCKABSTRACT;
153*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_CLASSORDER;
154*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_CLASSMAPPING;
155*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_CLASSPERMISSIONSET;
156*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_COMMON;
157*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_CLASSCOMMON;
158*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_SID;
159*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_SIDCONTEXT;
160*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_SIDORDER;
161*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_USERLEVEL;
162*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_USERRANGE;
163*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_USERBOUNDS;
164*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_USERPREFIX;
165*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_SELINUXUSER;
166*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_SELINUXUSERDEFAULT;
167*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_TYPEATTRIBUTE;
168*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_TYPEATTRIBUTESET;
169*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_EXPANDTYPEATTRIBUTE;
170*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_TYPEALIAS;
171*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_TYPEALIASACTUAL;
172*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_TYPEBOUNDS;
173*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_TYPEPERMISSIVE;
174*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_RANGETRANSITION;
175*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_USERROLE;
176*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_ROLETYPE;
177*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_ROLETRANSITION;
178*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_ROLEALLOW;
179*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_ROLEATTRIBUTE;
180*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_ROLEATTRIBUTESET;
181*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_ROLEBOUNDS;
182*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_BOOLEANIF;
183*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_NEVERALLOW;
184*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_TYPEMEMBER;
185*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_SENSALIAS;
186*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_SENSALIASACTUAL;
187*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_CATALIAS;
188*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_CATALIASACTUAL;
189*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_CATORDER;
190*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_SENSITIVITYORDER;
191*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_SENSCAT;
192*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_CONSTRAIN;
193*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_MLSCONSTRAIN;
194*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_VALIDATETRANS;
195*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_MLSVALIDATETRANS;
196*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_CONTEXT;
197*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_FILECON;
198*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_IBPKEYCON;
199*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_IBENDPORTCON;
200*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_PORTCON;
201*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_NODECON;
202*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_GENFSCON;
203*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_NETIFCON;
204*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_PIRQCON;
205*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_IOMEMCON;
206*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_IOPORTCON;
207*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_PCIDEVICECON;
208*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_DEVICETREECON;
209*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_FSUSE;
210*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_POLICYCAP;
211*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_OPTIONAL;
212*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_DEFAULTUSER;
213*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_DEFAULTROLE;
214*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_DEFAULTTYPE;
215*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_ROOT;
216*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_NODE;
217*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_PERM;
218*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_ALLOWX;
219*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_AUDITALLOWX;
220*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_DONTAUDITX;
221*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_NEVERALLOWX;
222*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_PERMISSIONX;
223*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_IOCTL;
224*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_NLMSG;
225*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_UNORDERED;
226*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_SRC_INFO;
227*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_SRC_CIL;
228*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_SRC_HLL_LMS;
229*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_SRC_HLL_LMX;
230*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_SRC_HLL_LME;
231*2d543d20SAndroid Build Coastguard Worker char *CIL_KEY_DENY_RULE;
232*2d543d20SAndroid Build Coastguard Worker 
cil_init_keys(void)233*2d543d20SAndroid Build Coastguard Worker static void cil_init_keys(void)
234*2d543d20SAndroid Build Coastguard Worker {
235*2d543d20SAndroid Build Coastguard Worker 	/* Initialize CIL Keys into strpool */
236*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_CONS_T1 = cil_strpool_add("t1");
237*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_CONS_T2 = cil_strpool_add("t2");
238*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_CONS_T3 = cil_strpool_add("t3");
239*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_CONS_R1 = cil_strpool_add("r1");
240*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_CONS_R2 = cil_strpool_add("r2");
241*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_CONS_R3 = cil_strpool_add("r3");
242*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_CONS_U1 = cil_strpool_add("u1");
243*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_CONS_U2 = cil_strpool_add("u2");
244*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_CONS_U3 = cil_strpool_add("u3");
245*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_CONS_L1 = cil_strpool_add("l1");
246*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_CONS_L2 = cil_strpool_add("l2");
247*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_CONS_H1 = cil_strpool_add("h1");
248*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_CONS_H2 = cil_strpool_add("h2");
249*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_AND = cil_strpool_add("and");
250*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_OR = cil_strpool_add("or");
251*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_NOT = cil_strpool_add("not");
252*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_EQ = cil_strpool_add("eq");
253*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_NEQ = cil_strpool_add("neq");
254*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_CONS_DOM = cil_strpool_add("dom");
255*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_CONS_DOMBY = cil_strpool_add("domby");
256*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_CONS_INCOMP = cil_strpool_add("incomp");
257*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_CONDTRUE = cil_strpool_add("true");
258*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_CONDFALSE = cil_strpool_add("false");
259*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_SELF = cil_strpool_add("self");
260*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_NOTSELF = cil_strpool_add("notself");
261*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_OTHER = cil_strpool_add("other");
262*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_OBJECT_R = cil_strpool_add("object_r");
263*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_STAR = cil_strpool_add("*");
264*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_UDP = cil_strpool_add("udp");
265*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_TCP = cil_strpool_add("tcp");
266*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_DCCP = cil_strpool_add("dccp");
267*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_SCTP = cil_strpool_add("sctp");
268*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_AUDITALLOW = cil_strpool_add("auditallow");
269*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_TUNABLEIF = cil_strpool_add("tunableif");
270*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_ALLOW = cil_strpool_add("allow");
271*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_DONTAUDIT = cil_strpool_add("dontaudit");
272*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_TYPETRANSITION = cil_strpool_add("typetransition");
273*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_TYPECHANGE = cil_strpool_add("typechange");
274*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_CALL = cil_strpool_add("call");
275*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_TUNABLE = cil_strpool_add("tunable");
276*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_XOR = cil_strpool_add("xor");
277*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_ALL = cil_strpool_add("all");
278*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_RANGE = cil_strpool_add("range");
279*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_TYPE = cil_strpool_add("type");
280*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_ROLE = cil_strpool_add("role");
281*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_USER = cil_strpool_add("user");
282*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_USERATTRIBUTE = cil_strpool_add("userattribute");
283*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_USERATTRIBUTESET = cil_strpool_add("userattributeset");
284*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_SENSITIVITY = cil_strpool_add("sensitivity");
285*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_CATEGORY = cil_strpool_add("category");
286*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_CATSET = cil_strpool_add("categoryset");
287*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_LEVEL = cil_strpool_add("level");
288*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_LEVELRANGE = cil_strpool_add("levelrange");
289*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_CLASS = cil_strpool_add("class");
290*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_IPADDR = cil_strpool_add("ipaddr");
291*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_MAP_CLASS = cil_strpool_add("classmap");
292*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_CLASSPERMISSION = cil_strpool_add("classpermission");
293*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_BOOL = cil_strpool_add("boolean");
294*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_STRING = cil_strpool_add("string");
295*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_NAME = cil_strpool_add("name");
296*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_HANDLEUNKNOWN = cil_strpool_add("handleunknown");
297*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_HANDLEUNKNOWN_ALLOW = cil_strpool_add("allow");
298*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_HANDLEUNKNOWN_DENY = cil_strpool_add("deny");
299*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_HANDLEUNKNOWN_REJECT = cil_strpool_add("reject");
300*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_BLOCKINHERIT = cil_strpool_add("blockinherit");
301*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_BLOCKABSTRACT = cil_strpool_add("blockabstract");
302*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_CLASSORDER = cil_strpool_add("classorder");
303*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_CLASSMAPPING = cil_strpool_add("classmapping");
304*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_CLASSPERMISSIONSET = cil_strpool_add("classpermissionset");
305*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_COMMON = cil_strpool_add("common");
306*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_CLASSCOMMON = cil_strpool_add("classcommon");
307*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_SID = cil_strpool_add("sid");
308*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_SIDCONTEXT = cil_strpool_add("sidcontext");
309*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_SIDORDER = cil_strpool_add("sidorder");
310*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_USERLEVEL = cil_strpool_add("userlevel");
311*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_USERRANGE = cil_strpool_add("userrange");
312*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_USERBOUNDS = cil_strpool_add("userbounds");
313*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_USERPREFIX = cil_strpool_add("userprefix");
314*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_SELINUXUSER = cil_strpool_add("selinuxuser");
315*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_SELINUXUSERDEFAULT = cil_strpool_add("selinuxuserdefault");
316*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_TYPEATTRIBUTE = cil_strpool_add("typeattribute");
317*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_TYPEATTRIBUTESET = cil_strpool_add("typeattributeset");
318*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_EXPANDTYPEATTRIBUTE = cil_strpool_add("expandtypeattribute");
319*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_TYPEALIAS = cil_strpool_add("typealias");
320*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_TYPEALIASACTUAL = cil_strpool_add("typealiasactual");
321*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_TYPEBOUNDS = cil_strpool_add("typebounds");
322*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_TYPEPERMISSIVE = cil_strpool_add("typepermissive");
323*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_RANGETRANSITION = cil_strpool_add("rangetransition");
324*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_USERROLE = cil_strpool_add("userrole");
325*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_ROLETYPE = cil_strpool_add("roletype");
326*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_ROLETRANSITION = cil_strpool_add("roletransition");
327*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_ROLEALLOW = cil_strpool_add("roleallow");
328*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_ROLEATTRIBUTE = cil_strpool_add("roleattribute");
329*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_ROLEATTRIBUTESET = cil_strpool_add("roleattributeset");
330*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_ROLEBOUNDS = cil_strpool_add("rolebounds");
331*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_BOOLEANIF = cil_strpool_add("booleanif");
332*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_NEVERALLOW = cil_strpool_add("neverallow");
333*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_TYPEMEMBER = cil_strpool_add("typemember");
334*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_SENSALIAS = cil_strpool_add("sensitivityalias");
335*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_SENSALIASACTUAL = cil_strpool_add("sensitivityaliasactual");
336*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_CATALIAS = cil_strpool_add("categoryalias");
337*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_CATALIASACTUAL = cil_strpool_add("categoryaliasactual");
338*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_CATORDER = cil_strpool_add("categoryorder");
339*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_SENSITIVITYORDER = cil_strpool_add("sensitivityorder");
340*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_SENSCAT = cil_strpool_add("sensitivitycategory");
341*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_CONSTRAIN = cil_strpool_add("constrain");
342*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_MLSCONSTRAIN = cil_strpool_add("mlsconstrain");
343*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_VALIDATETRANS = cil_strpool_add("validatetrans");
344*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_MLSVALIDATETRANS = cil_strpool_add("mlsvalidatetrans");
345*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_CONTEXT = cil_strpool_add("context");
346*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_FILECON = cil_strpool_add("filecon");
347*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_IBPKEYCON = cil_strpool_add("ibpkeycon");
348*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_IBENDPORTCON = cil_strpool_add("ibendportcon");
349*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_PORTCON = cil_strpool_add("portcon");
350*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_NODECON = cil_strpool_add("nodecon");
351*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_GENFSCON = cil_strpool_add("genfscon");
352*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_NETIFCON = cil_strpool_add("netifcon");
353*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_PIRQCON = cil_strpool_add("pirqcon");
354*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_IOMEMCON = cil_strpool_add("iomemcon");
355*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_IOPORTCON = cil_strpool_add("ioportcon");
356*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_PCIDEVICECON = cil_strpool_add("pcidevicecon");
357*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_DEVICETREECON = cil_strpool_add("devicetreecon");
358*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_FSUSE = cil_strpool_add("fsuse");
359*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_POLICYCAP = cil_strpool_add("policycap");
360*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_OPTIONAL = cil_strpool_add("optional");
361*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_DEFAULTUSER = cil_strpool_add("defaultuser");
362*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_DEFAULTROLE = cil_strpool_add("defaultrole");
363*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_DEFAULTTYPE = cil_strpool_add("defaulttype");
364*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_MACRO = cil_strpool_add("macro");
365*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_IN = cil_strpool_add("in");
366*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_IN_BEFORE = cil_strpool_add("before");
367*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_IN_AFTER = cil_strpool_add("after");
368*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_MLS = cil_strpool_add("mls");
369*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_DEFAULTRANGE = cil_strpool_add("defaultrange");
370*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_GLOB = cil_strpool_add("*");
371*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_FILE = cil_strpool_add("file");
372*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_DIR = cil_strpool_add("dir");
373*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_CHAR = cil_strpool_add("char");
374*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_BLOCK = cil_strpool_add("block");
375*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_SOCKET = cil_strpool_add("socket");
376*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_PIPE = cil_strpool_add("pipe");
377*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_SYMLINK = cil_strpool_add("symlink");
378*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_ANY = cil_strpool_add("any");
379*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_XATTR = cil_strpool_add("xattr");
380*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_TASK = cil_strpool_add("task");
381*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_TRANS = cil_strpool_add("trans");
382*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_SOURCE = cil_strpool_add("source");
383*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_TARGET = cil_strpool_add("target");
384*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_LOW = cil_strpool_add("low");
385*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_HIGH = cil_strpool_add("high");
386*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_LOW_HIGH = cil_strpool_add("low-high");
387*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_GLBLUB = cil_strpool_add("glblub");
388*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_ROOT = cil_strpool_add("<root>");
389*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_NODE = cil_strpool_add("<node>");
390*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_PERM = cil_strpool_add("perm");
391*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_ALLOWX = cil_strpool_add("allowx");
392*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_AUDITALLOWX = cil_strpool_add("auditallowx");
393*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_DONTAUDITX = cil_strpool_add("dontauditx");
394*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_NEVERALLOWX = cil_strpool_add("neverallowx");
395*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_PERMISSIONX = cil_strpool_add("permissionx");
396*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_IOCTL = cil_strpool_add("ioctl");
397*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_NLMSG = cil_strpool_add("nlmsg");
398*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_UNORDERED = cil_strpool_add("unordered");
399*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_SRC_INFO = cil_strpool_add("<src_info>");
400*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_SRC_CIL = cil_strpool_add("cil");
401*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_SRC_HLL_LMS = cil_strpool_add("lms");
402*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_SRC_HLL_LMX = cil_strpool_add("lmx");
403*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_SRC_HLL_LME = cil_strpool_add("lme");
404*2d543d20SAndroid Build Coastguard Worker 	CIL_KEY_DENY_RULE = cil_strpool_add("deny");
405*2d543d20SAndroid Build Coastguard Worker }
406*2d543d20SAndroid Build Coastguard Worker 
cil_db_init(struct cil_db ** db)407*2d543d20SAndroid Build Coastguard Worker void cil_db_init(struct cil_db **db)
408*2d543d20SAndroid Build Coastguard Worker {
409*2d543d20SAndroid Build Coastguard Worker 	*db = cil_malloc(sizeof(**db));
410*2d543d20SAndroid Build Coastguard Worker 
411*2d543d20SAndroid Build Coastguard Worker 	cil_strpool_init();
412*2d543d20SAndroid Build Coastguard Worker 	cil_init_keys();
413*2d543d20SAndroid Build Coastguard Worker 
414*2d543d20SAndroid Build Coastguard Worker 	cil_tree_init(&(*db)->parse);
415*2d543d20SAndroid Build Coastguard Worker 	cil_tree_init(&(*db)->ast);
416*2d543d20SAndroid Build Coastguard Worker 	cil_root_init((struct cil_root **)&(*db)->ast->root->data);
417*2d543d20SAndroid Build Coastguard Worker 	(*db)->sidorder = NULL;
418*2d543d20SAndroid Build Coastguard Worker 	(*db)->classorder = NULL;
419*2d543d20SAndroid Build Coastguard Worker 	(*db)->catorder = NULL;
420*2d543d20SAndroid Build Coastguard Worker 	(*db)->sensitivityorder = NULL;
421*2d543d20SAndroid Build Coastguard Worker 	cil_sort_init(&(*db)->netifcon);
422*2d543d20SAndroid Build Coastguard Worker 	cil_sort_init(&(*db)->genfscon);
423*2d543d20SAndroid Build Coastguard Worker 	cil_sort_init(&(*db)->filecon);
424*2d543d20SAndroid Build Coastguard Worker 	cil_sort_init(&(*db)->nodecon);
425*2d543d20SAndroid Build Coastguard Worker 	cil_sort_init(&(*db)->ibpkeycon);
426*2d543d20SAndroid Build Coastguard Worker 	cil_sort_init(&(*db)->ibendportcon);
427*2d543d20SAndroid Build Coastguard Worker 	cil_sort_init(&(*db)->portcon);
428*2d543d20SAndroid Build Coastguard Worker 	cil_sort_init(&(*db)->pirqcon);
429*2d543d20SAndroid Build Coastguard Worker 	cil_sort_init(&(*db)->iomemcon);
430*2d543d20SAndroid Build Coastguard Worker 	cil_sort_init(&(*db)->ioportcon);
431*2d543d20SAndroid Build Coastguard Worker 	cil_sort_init(&(*db)->pcidevicecon);
432*2d543d20SAndroid Build Coastguard Worker 	cil_sort_init(&(*db)->devicetreecon);
433*2d543d20SAndroid Build Coastguard Worker 	cil_sort_init(&(*db)->fsuse);
434*2d543d20SAndroid Build Coastguard Worker 	cil_list_init(&(*db)->userprefixes, CIL_LIST_ITEM);
435*2d543d20SAndroid Build Coastguard Worker 	cil_list_init(&(*db)->selinuxusers, CIL_LIST_ITEM);
436*2d543d20SAndroid Build Coastguard Worker 	cil_list_init(&(*db)->declared_strings, CIL_LIST_ITEM);
437*2d543d20SAndroid Build Coastguard Worker 
438*2d543d20SAndroid Build Coastguard Worker 	cil_type_init(&(*db)->selftype);
439*2d543d20SAndroid Build Coastguard Worker 	(*db)->selftype->datum.name = CIL_KEY_SELF;
440*2d543d20SAndroid Build Coastguard Worker 	(*db)->selftype->datum.fqn = CIL_KEY_SELF;
441*2d543d20SAndroid Build Coastguard Worker 	cil_type_init(&(*db)->notselftype);
442*2d543d20SAndroid Build Coastguard Worker 	(*db)->notselftype->datum.name = CIL_KEY_NOTSELF;
443*2d543d20SAndroid Build Coastguard Worker 	(*db)->notselftype->datum.fqn = CIL_KEY_NOTSELF;
444*2d543d20SAndroid Build Coastguard Worker 	cil_type_init(&(*db)->othertype);
445*2d543d20SAndroid Build Coastguard Worker 	(*db)->othertype->datum.name = CIL_KEY_OTHER;
446*2d543d20SAndroid Build Coastguard Worker 	(*db)->othertype->datum.fqn = CIL_KEY_OTHER;
447*2d543d20SAndroid Build Coastguard Worker 	(*db)->num_types_and_attrs = 0;
448*2d543d20SAndroid Build Coastguard Worker 	(*db)->num_classes = 0;
449*2d543d20SAndroid Build Coastguard Worker 	(*db)->num_types = 0;
450*2d543d20SAndroid Build Coastguard Worker 	(*db)->num_roles = 0;
451*2d543d20SAndroid Build Coastguard Worker 	(*db)->num_users = 0;
452*2d543d20SAndroid Build Coastguard Worker 	(*db)->num_cats = 0;
453*2d543d20SAndroid Build Coastguard Worker 	(*db)->val_to_type = NULL;
454*2d543d20SAndroid Build Coastguard Worker 	(*db)->val_to_role = NULL;
455*2d543d20SAndroid Build Coastguard Worker 	(*db)->val_to_user = NULL;
456*2d543d20SAndroid Build Coastguard Worker 
457*2d543d20SAndroid Build Coastguard Worker 	(*db)->disable_dontaudit = CIL_FALSE;
458*2d543d20SAndroid Build Coastguard Worker 	(*db)->disable_neverallow = CIL_FALSE;
459*2d543d20SAndroid Build Coastguard Worker 	(*db)->attrs_expand_generated = CIL_FALSE;
460*2d543d20SAndroid Build Coastguard Worker 	(*db)->attrs_expand_size = 1;
461*2d543d20SAndroid Build Coastguard Worker 	(*db)->preserve_tunables = CIL_FALSE;
462*2d543d20SAndroid Build Coastguard Worker 	(*db)->handle_unknown = -1;
463*2d543d20SAndroid Build Coastguard Worker 	(*db)->mls = -1;
464*2d543d20SAndroid Build Coastguard Worker 	(*db)->multiple_decls = CIL_FALSE;
465*2d543d20SAndroid Build Coastguard Worker 	(*db)->qualified_names = CIL_FALSE;
466*2d543d20SAndroid Build Coastguard Worker 	(*db)->target_platform = SEPOL_TARGET_SELINUX;
467*2d543d20SAndroid Build Coastguard Worker 	(*db)->policy_version = POLICYDB_VERSION_MAX;
468*2d543d20SAndroid Build Coastguard Worker }
469*2d543d20SAndroid Build Coastguard Worker 
cil_declared_strings_list_destroy(struct cil_list ** strings)470*2d543d20SAndroid Build Coastguard Worker static void cil_declared_strings_list_destroy(struct cil_list **strings)
471*2d543d20SAndroid Build Coastguard Worker {
472*2d543d20SAndroid Build Coastguard Worker 	struct cil_list_item *i;
473*2d543d20SAndroid Build Coastguard Worker 
474*2d543d20SAndroid Build Coastguard Worker 	cil_list_for_each(i, *strings) {
475*2d543d20SAndroid Build Coastguard Worker 		struct cil_symtab_datum *d = i->data;
476*2d543d20SAndroid Build Coastguard Worker 		cil_symtab_datum_destroy(d);
477*2d543d20SAndroid Build Coastguard Worker 		free(d);
478*2d543d20SAndroid Build Coastguard Worker 	}
479*2d543d20SAndroid Build Coastguard Worker 	cil_list_destroy(strings, CIL_FALSE);
480*2d543d20SAndroid Build Coastguard Worker }
481*2d543d20SAndroid Build Coastguard Worker 
cil_db_destroy(struct cil_db ** db)482*2d543d20SAndroid Build Coastguard Worker void cil_db_destroy(struct cil_db **db)
483*2d543d20SAndroid Build Coastguard Worker {
484*2d543d20SAndroid Build Coastguard Worker 	if (db == NULL || *db == NULL) {
485*2d543d20SAndroid Build Coastguard Worker 		return;
486*2d543d20SAndroid Build Coastguard Worker 	}
487*2d543d20SAndroid Build Coastguard Worker 
488*2d543d20SAndroid Build Coastguard Worker 	cil_tree_destroy(&(*db)->parse);
489*2d543d20SAndroid Build Coastguard Worker 	cil_tree_destroy(&(*db)->ast);
490*2d543d20SAndroid Build Coastguard Worker 	cil_list_destroy(&(*db)->sidorder, CIL_FALSE);
491*2d543d20SAndroid Build Coastguard Worker 	cil_list_destroy(&(*db)->classorder, CIL_FALSE);
492*2d543d20SAndroid Build Coastguard Worker 	cil_list_destroy(&(*db)->catorder, CIL_FALSE);
493*2d543d20SAndroid Build Coastguard Worker 	cil_list_destroy(&(*db)->sensitivityorder, CIL_FALSE);
494*2d543d20SAndroid Build Coastguard Worker 	cil_sort_destroy(&(*db)->netifcon);
495*2d543d20SAndroid Build Coastguard Worker 	cil_sort_destroy(&(*db)->genfscon);
496*2d543d20SAndroid Build Coastguard Worker 	cil_sort_destroy(&(*db)->filecon);
497*2d543d20SAndroid Build Coastguard Worker 	cil_sort_destroy(&(*db)->nodecon);
498*2d543d20SAndroid Build Coastguard Worker 	cil_sort_destroy(&(*db)->ibpkeycon);
499*2d543d20SAndroid Build Coastguard Worker 	cil_sort_destroy(&(*db)->ibendportcon);
500*2d543d20SAndroid Build Coastguard Worker 	cil_sort_destroy(&(*db)->portcon);
501*2d543d20SAndroid Build Coastguard Worker 	cil_sort_destroy(&(*db)->pirqcon);
502*2d543d20SAndroid Build Coastguard Worker 	cil_sort_destroy(&(*db)->iomemcon);
503*2d543d20SAndroid Build Coastguard Worker 	cil_sort_destroy(&(*db)->ioportcon);
504*2d543d20SAndroid Build Coastguard Worker 	cil_sort_destroy(&(*db)->pcidevicecon);
505*2d543d20SAndroid Build Coastguard Worker 	cil_sort_destroy(&(*db)->devicetreecon);
506*2d543d20SAndroid Build Coastguard Worker 	cil_sort_destroy(&(*db)->fsuse);
507*2d543d20SAndroid Build Coastguard Worker 	cil_list_destroy(&(*db)->userprefixes, CIL_FALSE);
508*2d543d20SAndroid Build Coastguard Worker 	cil_list_destroy(&(*db)->selinuxusers, CIL_FALSE);
509*2d543d20SAndroid Build Coastguard Worker 
510*2d543d20SAndroid Build Coastguard Worker 	cil_declared_strings_list_destroy(&(*db)->declared_strings);
511*2d543d20SAndroid Build Coastguard Worker 
512*2d543d20SAndroid Build Coastguard Worker 	cil_destroy_type((*db)->selftype);
513*2d543d20SAndroid Build Coastguard Worker 	cil_destroy_type((*db)->notselftype);
514*2d543d20SAndroid Build Coastguard Worker 	cil_destroy_type((*db)->othertype);
515*2d543d20SAndroid Build Coastguard Worker 
516*2d543d20SAndroid Build Coastguard Worker 	cil_strpool_destroy();
517*2d543d20SAndroid Build Coastguard Worker 	free((*db)->val_to_type);
518*2d543d20SAndroid Build Coastguard Worker 	free((*db)->val_to_role);
519*2d543d20SAndroid Build Coastguard Worker 	free((*db)->val_to_user);
520*2d543d20SAndroid Build Coastguard Worker 
521*2d543d20SAndroid Build Coastguard Worker 	free(*db);
522*2d543d20SAndroid Build Coastguard Worker 	*db = NULL;
523*2d543d20SAndroid Build Coastguard Worker }
524*2d543d20SAndroid Build Coastguard Worker 
cil_root_init(struct cil_root ** root)525*2d543d20SAndroid Build Coastguard Worker void cil_root_init(struct cil_root **root)
526*2d543d20SAndroid Build Coastguard Worker {
527*2d543d20SAndroid Build Coastguard Worker 	struct cil_root *r = cil_malloc(sizeof(*r));
528*2d543d20SAndroid Build Coastguard Worker 	cil_symtab_array_init(r->symtab, cil_sym_sizes[CIL_SYM_ARRAY_ROOT]);
529*2d543d20SAndroid Build Coastguard Worker 
530*2d543d20SAndroid Build Coastguard Worker 	*root = r;
531*2d543d20SAndroid Build Coastguard Worker }
532*2d543d20SAndroid Build Coastguard Worker 
cil_root_destroy(struct cil_root * root)533*2d543d20SAndroid Build Coastguard Worker void cil_root_destroy(struct cil_root *root)
534*2d543d20SAndroid Build Coastguard Worker {
535*2d543d20SAndroid Build Coastguard Worker 	if (root == NULL) {
536*2d543d20SAndroid Build Coastguard Worker 		return;
537*2d543d20SAndroid Build Coastguard Worker 	}
538*2d543d20SAndroid Build Coastguard Worker 	cil_symtab_array_destroy(root->symtab);
539*2d543d20SAndroid Build Coastguard Worker 	free(root);
540*2d543d20SAndroid Build Coastguard Worker }
541*2d543d20SAndroid Build Coastguard Worker 
cil_add_file(cil_db_t * db,const char * name,const char * data,size_t size)542*2d543d20SAndroid Build Coastguard Worker int cil_add_file(cil_db_t *db, const char *name, const char *data, size_t size)
543*2d543d20SAndroid Build Coastguard Worker {
544*2d543d20SAndroid Build Coastguard Worker 	char *buffer = NULL;
545*2d543d20SAndroid Build Coastguard Worker 	int rc;
546*2d543d20SAndroid Build Coastguard Worker 
547*2d543d20SAndroid Build Coastguard Worker 	cil_log(CIL_INFO, "Parsing %s\n", name);
548*2d543d20SAndroid Build Coastguard Worker 
549*2d543d20SAndroid Build Coastguard Worker 	buffer = cil_malloc(size + 2);
550*2d543d20SAndroid Build Coastguard Worker 	memcpy(buffer, data, size);
551*2d543d20SAndroid Build Coastguard Worker 	memset(buffer + size, 0, 2);
552*2d543d20SAndroid Build Coastguard Worker 
553*2d543d20SAndroid Build Coastguard Worker 	rc = cil_parser(name, buffer, size + 2, &db->parse);
554*2d543d20SAndroid Build Coastguard Worker 	if (rc != SEPOL_OK) {
555*2d543d20SAndroid Build Coastguard Worker 		cil_log(CIL_INFO, "Failed to parse %s\n", name);
556*2d543d20SAndroid Build Coastguard Worker 		goto exit;
557*2d543d20SAndroid Build Coastguard Worker 	}
558*2d543d20SAndroid Build Coastguard Worker 
559*2d543d20SAndroid Build Coastguard Worker 	free(buffer);
560*2d543d20SAndroid Build Coastguard Worker 	buffer = NULL;
561*2d543d20SAndroid Build Coastguard Worker 
562*2d543d20SAndroid Build Coastguard Worker 	rc = SEPOL_OK;
563*2d543d20SAndroid Build Coastguard Worker 
564*2d543d20SAndroid Build Coastguard Worker exit:
565*2d543d20SAndroid Build Coastguard Worker 	free(buffer);
566*2d543d20SAndroid Build Coastguard Worker 
567*2d543d20SAndroid Build Coastguard Worker 	return rc;
568*2d543d20SAndroid Build Coastguard Worker }
569*2d543d20SAndroid Build Coastguard Worker 
cil_compile(struct cil_db * db)570*2d543d20SAndroid Build Coastguard Worker int cil_compile(struct cil_db *db)
571*2d543d20SAndroid Build Coastguard Worker {
572*2d543d20SAndroid Build Coastguard Worker 	int rc = SEPOL_ERR;
573*2d543d20SAndroid Build Coastguard Worker 
574*2d543d20SAndroid Build Coastguard Worker 	if (db == NULL) {
575*2d543d20SAndroid Build Coastguard Worker 		goto exit;
576*2d543d20SAndroid Build Coastguard Worker 	}
577*2d543d20SAndroid Build Coastguard Worker 
578*2d543d20SAndroid Build Coastguard Worker 	cil_log(CIL_INFO, "Building AST from Parse Tree\n");
579*2d543d20SAndroid Build Coastguard Worker 	rc = cil_build_ast(db, db->parse->root, db->ast->root);
580*2d543d20SAndroid Build Coastguard Worker 	if (rc != SEPOL_OK) {
581*2d543d20SAndroid Build Coastguard Worker 		cil_log(CIL_ERR, "Failed to build AST\n");
582*2d543d20SAndroid Build Coastguard Worker 		goto exit;
583*2d543d20SAndroid Build Coastguard Worker 	}
584*2d543d20SAndroid Build Coastguard Worker 
585*2d543d20SAndroid Build Coastguard Worker 	cil_log(CIL_INFO, "Destroying Parse Tree\n");
586*2d543d20SAndroid Build Coastguard Worker 	cil_tree_destroy(&db->parse);
587*2d543d20SAndroid Build Coastguard Worker 
588*2d543d20SAndroid Build Coastguard Worker 	cil_log(CIL_INFO, "Resolving AST\n");
589*2d543d20SAndroid Build Coastguard Worker 	rc = cil_resolve_ast(db, db->ast->root);
590*2d543d20SAndroid Build Coastguard Worker 	if (rc != SEPOL_OK) {
591*2d543d20SAndroid Build Coastguard Worker 		cil_log(CIL_ERR, "Failed to resolve AST\n");
592*2d543d20SAndroid Build Coastguard Worker 		goto exit;
593*2d543d20SAndroid Build Coastguard Worker 	}
594*2d543d20SAndroid Build Coastguard Worker 
595*2d543d20SAndroid Build Coastguard Worker 	cil_log(CIL_INFO, "Qualifying Names\n");
596*2d543d20SAndroid Build Coastguard Worker 	rc = cil_fqn_qualify(db->ast->root);
597*2d543d20SAndroid Build Coastguard Worker 	if (rc != SEPOL_OK) {
598*2d543d20SAndroid Build Coastguard Worker 		cil_log(CIL_ERR, "Failed to qualify names\n");
599*2d543d20SAndroid Build Coastguard Worker 		goto exit;
600*2d543d20SAndroid Build Coastguard Worker 	}
601*2d543d20SAndroid Build Coastguard Worker 
602*2d543d20SAndroid Build Coastguard Worker 	cil_log(CIL_INFO, "Compile post process\n");
603*2d543d20SAndroid Build Coastguard Worker 	rc = cil_post_process(db);
604*2d543d20SAndroid Build Coastguard Worker 	if (rc != SEPOL_OK ) {
605*2d543d20SAndroid Build Coastguard Worker 		cil_log(CIL_ERR, "Post process failed\n");
606*2d543d20SAndroid Build Coastguard Worker 		goto exit;
607*2d543d20SAndroid Build Coastguard Worker 	}
608*2d543d20SAndroid Build Coastguard Worker 
609*2d543d20SAndroid Build Coastguard Worker exit:
610*2d543d20SAndroid Build Coastguard Worker 
611*2d543d20SAndroid Build Coastguard Worker 	return rc;
612*2d543d20SAndroid Build Coastguard Worker }
613*2d543d20SAndroid Build Coastguard Worker 
cil_write_parse_ast(FILE * out,cil_db_t * db)614*2d543d20SAndroid Build Coastguard Worker int cil_write_parse_ast(FILE *out, cil_db_t *db)
615*2d543d20SAndroid Build Coastguard Worker {
616*2d543d20SAndroid Build Coastguard Worker 	int rc = SEPOL_ERR;
617*2d543d20SAndroid Build Coastguard Worker 
618*2d543d20SAndroid Build Coastguard Worker 	if (db == NULL) {
619*2d543d20SAndroid Build Coastguard Worker 		goto exit;
620*2d543d20SAndroid Build Coastguard Worker 	}
621*2d543d20SAndroid Build Coastguard Worker 
622*2d543d20SAndroid Build Coastguard Worker 	cil_log(CIL_INFO, "Writing Parse AST\n");
623*2d543d20SAndroid Build Coastguard Worker 	rc = cil_write_ast(out, CIL_WRITE_AST_PHASE_PARSE, db->parse->root);
624*2d543d20SAndroid Build Coastguard Worker 	if (rc != SEPOL_OK) {
625*2d543d20SAndroid Build Coastguard Worker 		cil_log(CIL_ERR, "Failed to write parse ast\n");
626*2d543d20SAndroid Build Coastguard Worker 		goto exit;
627*2d543d20SAndroid Build Coastguard Worker 	}
628*2d543d20SAndroid Build Coastguard Worker 
629*2d543d20SAndroid Build Coastguard Worker exit:
630*2d543d20SAndroid Build Coastguard Worker 	return rc;
631*2d543d20SAndroid Build Coastguard Worker }
632*2d543d20SAndroid Build Coastguard Worker 
cil_write_build_ast(FILE * out,cil_db_t * db)633*2d543d20SAndroid Build Coastguard Worker int cil_write_build_ast(FILE *out, cil_db_t *db)
634*2d543d20SAndroid Build Coastguard Worker {
635*2d543d20SAndroid Build Coastguard Worker 	int rc = SEPOL_ERR;
636*2d543d20SAndroid Build Coastguard Worker 
637*2d543d20SAndroid Build Coastguard Worker 	if (db == NULL) {
638*2d543d20SAndroid Build Coastguard Worker 		goto exit;
639*2d543d20SAndroid Build Coastguard Worker 	}
640*2d543d20SAndroid Build Coastguard Worker 
641*2d543d20SAndroid Build Coastguard Worker 	cil_log(CIL_INFO, "Building AST from Parse Tree\n");
642*2d543d20SAndroid Build Coastguard Worker 	rc = cil_build_ast(db, db->parse->root, db->ast->root);
643*2d543d20SAndroid Build Coastguard Worker 	if (rc != SEPOL_OK) {
644*2d543d20SAndroid Build Coastguard Worker 		cil_log(CIL_ERR, "Failed to build ast\n");
645*2d543d20SAndroid Build Coastguard Worker 		goto exit;
646*2d543d20SAndroid Build Coastguard Worker 	}
647*2d543d20SAndroid Build Coastguard Worker 
648*2d543d20SAndroid Build Coastguard Worker 	cil_log(CIL_INFO, "Destroying Parse Tree\n");
649*2d543d20SAndroid Build Coastguard Worker 	cil_tree_destroy(&db->parse);
650*2d543d20SAndroid Build Coastguard Worker 
651*2d543d20SAndroid Build Coastguard Worker 	cil_log(CIL_INFO, "Writing Build AST\n");
652*2d543d20SAndroid Build Coastguard Worker 	rc = cil_write_ast(out, CIL_WRITE_AST_PHASE_BUILD, db->ast->root);
653*2d543d20SAndroid Build Coastguard Worker 	if (rc != SEPOL_OK) {
654*2d543d20SAndroid Build Coastguard Worker 		cil_log(CIL_ERR, "Failed to write build ast\n");
655*2d543d20SAndroid Build Coastguard Worker 		goto exit;
656*2d543d20SAndroid Build Coastguard Worker 	}
657*2d543d20SAndroid Build Coastguard Worker 
658*2d543d20SAndroid Build Coastguard Worker exit:
659*2d543d20SAndroid Build Coastguard Worker 	return rc;
660*2d543d20SAndroid Build Coastguard Worker }
661*2d543d20SAndroid Build Coastguard Worker 
cil_write_resolve_ast(FILE * out,cil_db_t * db)662*2d543d20SAndroid Build Coastguard Worker int cil_write_resolve_ast(FILE *out, cil_db_t *db)
663*2d543d20SAndroid Build Coastguard Worker {
664*2d543d20SAndroid Build Coastguard Worker 	int rc = SEPOL_ERR;
665*2d543d20SAndroid Build Coastguard Worker 
666*2d543d20SAndroid Build Coastguard Worker 	if (db == NULL) {
667*2d543d20SAndroid Build Coastguard Worker 		goto exit;
668*2d543d20SAndroid Build Coastguard Worker 	}
669*2d543d20SAndroid Build Coastguard Worker 
670*2d543d20SAndroid Build Coastguard Worker 	cil_log(CIL_INFO, "Building AST from Parse Tree\n");
671*2d543d20SAndroid Build Coastguard Worker 	rc = cil_build_ast(db, db->parse->root, db->ast->root);
672*2d543d20SAndroid Build Coastguard Worker 	if (rc != SEPOL_OK) {
673*2d543d20SAndroid Build Coastguard Worker 		cil_log(CIL_ERR, "Failed to build ast\n");
674*2d543d20SAndroid Build Coastguard Worker 		goto exit;
675*2d543d20SAndroid Build Coastguard Worker 	}
676*2d543d20SAndroid Build Coastguard Worker 
677*2d543d20SAndroid Build Coastguard Worker 	cil_log(CIL_INFO, "Destroying Parse Tree\n");
678*2d543d20SAndroid Build Coastguard Worker 	cil_tree_destroy(&db->parse);
679*2d543d20SAndroid Build Coastguard Worker 
680*2d543d20SAndroid Build Coastguard Worker 	cil_log(CIL_INFO, "Resolving AST\n");
681*2d543d20SAndroid Build Coastguard Worker 	rc = cil_resolve_ast(db, db->ast->root);
682*2d543d20SAndroid Build Coastguard Worker 	if (rc != SEPOL_OK) {
683*2d543d20SAndroid Build Coastguard Worker 		cil_log(CIL_ERR, "Failed to resolve ast\n");
684*2d543d20SAndroid Build Coastguard Worker 		goto exit;
685*2d543d20SAndroid Build Coastguard Worker 	}
686*2d543d20SAndroid Build Coastguard Worker 
687*2d543d20SAndroid Build Coastguard Worker 	cil_log(CIL_INFO, "Qualifying Names\n");
688*2d543d20SAndroid Build Coastguard Worker 	rc = cil_fqn_qualify(db->ast->root);
689*2d543d20SAndroid Build Coastguard Worker 	if (rc != SEPOL_OK) {
690*2d543d20SAndroid Build Coastguard Worker 		cil_log(CIL_ERR, "Failed to qualify names\n");
691*2d543d20SAndroid Build Coastguard Worker 		goto exit;
692*2d543d20SAndroid Build Coastguard Worker 	}
693*2d543d20SAndroid Build Coastguard Worker 
694*2d543d20SAndroid Build Coastguard Worker 	cil_log(CIL_INFO, "Writing Resolve AST\n");
695*2d543d20SAndroid Build Coastguard Worker 	rc = cil_write_ast(out, CIL_WRITE_AST_PHASE_RESOLVE, db->ast->root);
696*2d543d20SAndroid Build Coastguard Worker 	if (rc != SEPOL_OK) {
697*2d543d20SAndroid Build Coastguard Worker 		cil_log(CIL_ERR, "Failed to write resolve ast\n");
698*2d543d20SAndroid Build Coastguard Worker 		goto exit;
699*2d543d20SAndroid Build Coastguard Worker 	}
700*2d543d20SAndroid Build Coastguard Worker 
701*2d543d20SAndroid Build Coastguard Worker exit:
702*2d543d20SAndroid Build Coastguard Worker 	return rc;
703*2d543d20SAndroid Build Coastguard Worker }
704*2d543d20SAndroid Build Coastguard Worker 
cil_write_post_ast(FILE * out,cil_db_t * db)705*2d543d20SAndroid Build Coastguard Worker int cil_write_post_ast(FILE *out, cil_db_t *db)
706*2d543d20SAndroid Build Coastguard Worker {
707*2d543d20SAndroid Build Coastguard Worker 	int rc = SEPOL_ERR;
708*2d543d20SAndroid Build Coastguard Worker 
709*2d543d20SAndroid Build Coastguard Worker 	if (db == NULL) {
710*2d543d20SAndroid Build Coastguard Worker 		goto exit;
711*2d543d20SAndroid Build Coastguard Worker 	}
712*2d543d20SAndroid Build Coastguard Worker 
713*2d543d20SAndroid Build Coastguard Worker 	cil_log(CIL_INFO, "Building AST from Parse Tree\n");
714*2d543d20SAndroid Build Coastguard Worker 	rc = cil_build_ast(db, db->parse->root, db->ast->root);
715*2d543d20SAndroid Build Coastguard Worker 	if (rc != SEPOL_OK) {
716*2d543d20SAndroid Build Coastguard Worker 		cil_log(CIL_ERR, "Failed to build ast\n");
717*2d543d20SAndroid Build Coastguard Worker 		goto exit;
718*2d543d20SAndroid Build Coastguard Worker 	}
719*2d543d20SAndroid Build Coastguard Worker 
720*2d543d20SAndroid Build Coastguard Worker 	cil_log(CIL_INFO, "Destroying Parse Tree\n");
721*2d543d20SAndroid Build Coastguard Worker 	cil_tree_destroy(&db->parse);
722*2d543d20SAndroid Build Coastguard Worker 
723*2d543d20SAndroid Build Coastguard Worker 	cil_log(CIL_INFO, "Resolving AST\n");
724*2d543d20SAndroid Build Coastguard Worker 	rc = cil_resolve_ast(db, db->ast->root);
725*2d543d20SAndroid Build Coastguard Worker 	if (rc != SEPOL_OK) {
726*2d543d20SAndroid Build Coastguard Worker 		cil_log(CIL_ERR, "Failed to resolve ast\n");
727*2d543d20SAndroid Build Coastguard Worker 		goto exit;
728*2d543d20SAndroid Build Coastguard Worker 	}
729*2d543d20SAndroid Build Coastguard Worker 
730*2d543d20SAndroid Build Coastguard Worker 	cil_log(CIL_INFO, "Qualifying Names\n");
731*2d543d20SAndroid Build Coastguard Worker 	rc = cil_fqn_qualify(db->ast->root);
732*2d543d20SAndroid Build Coastguard Worker 	if (rc != SEPOL_OK) {
733*2d543d20SAndroid Build Coastguard Worker 		cil_log(CIL_ERR, "Failed to qualify names\n");
734*2d543d20SAndroid Build Coastguard Worker 		goto exit;
735*2d543d20SAndroid Build Coastguard Worker 	}
736*2d543d20SAndroid Build Coastguard Worker 
737*2d543d20SAndroid Build Coastguard Worker 	cil_log(CIL_INFO, "Compile post process\n");
738*2d543d20SAndroid Build Coastguard Worker 	rc = cil_post_process(db);
739*2d543d20SAndroid Build Coastguard Worker 	if (rc != SEPOL_OK ) {
740*2d543d20SAndroid Build Coastguard Worker 		cil_log(CIL_ERR, "Post process failed\n");
741*2d543d20SAndroid Build Coastguard Worker 		goto exit;
742*2d543d20SAndroid Build Coastguard Worker 	}
743*2d543d20SAndroid Build Coastguard Worker 
744*2d543d20SAndroid Build Coastguard Worker 	cil_log(CIL_INFO, "Writing Post AST\n");
745*2d543d20SAndroid Build Coastguard Worker 	rc = cil_write_ast(out, CIL_WRITE_AST_PHASE_POST, db->ast->root);
746*2d543d20SAndroid Build Coastguard Worker 	if (rc != SEPOL_OK) {
747*2d543d20SAndroid Build Coastguard Worker 		cil_log(CIL_ERR, "Failed to write post ast\n");
748*2d543d20SAndroid Build Coastguard Worker 		goto exit;
749*2d543d20SAndroid Build Coastguard Worker 	}
750*2d543d20SAndroid Build Coastguard Worker 
751*2d543d20SAndroid Build Coastguard Worker exit:
752*2d543d20SAndroid Build Coastguard Worker 	return rc;
753*2d543d20SAndroid Build Coastguard Worker }
754*2d543d20SAndroid Build Coastguard Worker 
cil_build_policydb(cil_db_t * db,sepol_policydb_t ** sepol_db)755*2d543d20SAndroid Build Coastguard Worker int cil_build_policydb(cil_db_t *db, sepol_policydb_t **sepol_db)
756*2d543d20SAndroid Build Coastguard Worker {
757*2d543d20SAndroid Build Coastguard Worker 	int rc;
758*2d543d20SAndroid Build Coastguard Worker 
759*2d543d20SAndroid Build Coastguard Worker 	cil_log(CIL_INFO, "Building policy binary\n");
760*2d543d20SAndroid Build Coastguard Worker 	rc = cil_binary_create(db, sepol_db);
761*2d543d20SAndroid Build Coastguard Worker 	if (rc != SEPOL_OK) {
762*2d543d20SAndroid Build Coastguard Worker 		cil_log(CIL_ERR, "Failed to generate binary\n");
763*2d543d20SAndroid Build Coastguard Worker 		goto exit;
764*2d543d20SAndroid Build Coastguard Worker 	}
765*2d543d20SAndroid Build Coastguard Worker 
766*2d543d20SAndroid Build Coastguard Worker exit:
767*2d543d20SAndroid Build Coastguard Worker 	return rc;
768*2d543d20SAndroid Build Coastguard Worker }
769*2d543d20SAndroid Build Coastguard Worker 
cil_write_policy_conf(FILE * out,struct cil_db * db)770*2d543d20SAndroid Build Coastguard Worker void cil_write_policy_conf(FILE *out, struct cil_db *db)
771*2d543d20SAndroid Build Coastguard Worker {
772*2d543d20SAndroid Build Coastguard Worker 	cil_log(CIL_INFO, "Writing policy.conf file\n");
773*2d543d20SAndroid Build Coastguard Worker 	cil_gen_policy(out, db);
774*2d543d20SAndroid Build Coastguard Worker }
775*2d543d20SAndroid Build Coastguard Worker 
cil_destroy_data(void ** data,enum cil_flavor flavor)776*2d543d20SAndroid Build Coastguard Worker void cil_destroy_data(void **data, enum cil_flavor flavor)
777*2d543d20SAndroid Build Coastguard Worker {
778*2d543d20SAndroid Build Coastguard Worker 	if (*data == NULL) {
779*2d543d20SAndroid Build Coastguard Worker 		return;
780*2d543d20SAndroid Build Coastguard Worker 	}
781*2d543d20SAndroid Build Coastguard Worker 
782*2d543d20SAndroid Build Coastguard Worker 	switch(flavor) {
783*2d543d20SAndroid Build Coastguard Worker 	case CIL_NONE:
784*2d543d20SAndroid Build Coastguard Worker 		break;
785*2d543d20SAndroid Build Coastguard Worker 	case CIL_ROOT:
786*2d543d20SAndroid Build Coastguard Worker 		cil_root_destroy(*data);
787*2d543d20SAndroid Build Coastguard Worker 		break;
788*2d543d20SAndroid Build Coastguard Worker 	case CIL_NODE:
789*2d543d20SAndroid Build Coastguard Worker 		break;
790*2d543d20SAndroid Build Coastguard Worker 	case CIL_STRING:
791*2d543d20SAndroid Build Coastguard Worker 		break;
792*2d543d20SAndroid Build Coastguard Worker 	case CIL_DATUM:
793*2d543d20SAndroid Build Coastguard Worker 		break;
794*2d543d20SAndroid Build Coastguard Worker 	case CIL_LIST:
795*2d543d20SAndroid Build Coastguard Worker 		cil_list_destroy(*data, CIL_FALSE);
796*2d543d20SAndroid Build Coastguard Worker 		break;
797*2d543d20SAndroid Build Coastguard Worker 	case CIL_LIST_ITEM:
798*2d543d20SAndroid Build Coastguard Worker 		break;
799*2d543d20SAndroid Build Coastguard Worker 	case CIL_PARAM:
800*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_param(*data);
801*2d543d20SAndroid Build Coastguard Worker 		break;
802*2d543d20SAndroid Build Coastguard Worker 	case CIL_ARGS:
803*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_args(*data);
804*2d543d20SAndroid Build Coastguard Worker 		break;
805*2d543d20SAndroid Build Coastguard Worker 	case CIL_BLOCK:
806*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_block(*data);
807*2d543d20SAndroid Build Coastguard Worker 		break;
808*2d543d20SAndroid Build Coastguard Worker 	case CIL_BLOCKINHERIT:
809*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_blockinherit(*data);
810*2d543d20SAndroid Build Coastguard Worker 		break;
811*2d543d20SAndroid Build Coastguard Worker 	case CIL_BLOCKABSTRACT:
812*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_blockabstract(*data);
813*2d543d20SAndroid Build Coastguard Worker 		break;
814*2d543d20SAndroid Build Coastguard Worker 	case CIL_IN:
815*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_in(*data);
816*2d543d20SAndroid Build Coastguard Worker 		break;
817*2d543d20SAndroid Build Coastguard Worker 	case CIL_MACRO:
818*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_macro(*data);
819*2d543d20SAndroid Build Coastguard Worker 		break;
820*2d543d20SAndroid Build Coastguard Worker 	case CIL_CALL:
821*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_call(*data);
822*2d543d20SAndroid Build Coastguard Worker 		break;
823*2d543d20SAndroid Build Coastguard Worker 	case CIL_OPTIONAL:
824*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_optional(*data);
825*2d543d20SAndroid Build Coastguard Worker 		break;
826*2d543d20SAndroid Build Coastguard Worker 	case CIL_BOOL:
827*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_bool(*data);
828*2d543d20SAndroid Build Coastguard Worker 		break;
829*2d543d20SAndroid Build Coastguard Worker 	case CIL_BOOLEANIF:
830*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_boolif(*data);
831*2d543d20SAndroid Build Coastguard Worker 		break;
832*2d543d20SAndroid Build Coastguard Worker 	case CIL_TUNABLE:
833*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_tunable(*data);
834*2d543d20SAndroid Build Coastguard Worker 		break;
835*2d543d20SAndroid Build Coastguard Worker 	case CIL_TUNABLEIF:
836*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_tunif(*data);
837*2d543d20SAndroid Build Coastguard Worker 		break;
838*2d543d20SAndroid Build Coastguard Worker 	case CIL_CONDBLOCK:
839*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_condblock(*data);
840*2d543d20SAndroid Build Coastguard Worker 		break;
841*2d543d20SAndroid Build Coastguard Worker 	case CIL_CONDTRUE:
842*2d543d20SAndroid Build Coastguard Worker 		break;
843*2d543d20SAndroid Build Coastguard Worker 	case CIL_CONDFALSE:
844*2d543d20SAndroid Build Coastguard Worker 		break;
845*2d543d20SAndroid Build Coastguard Worker 	case CIL_PERM:
846*2d543d20SAndroid Build Coastguard Worker 	case CIL_MAP_PERM:
847*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_perm(*data);
848*2d543d20SAndroid Build Coastguard Worker 		break;
849*2d543d20SAndroid Build Coastguard Worker 	case CIL_COMMON:
850*2d543d20SAndroid Build Coastguard Worker 	case CIL_CLASS:
851*2d543d20SAndroid Build Coastguard Worker 	case CIL_MAP_CLASS:
852*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_class(*data);
853*2d543d20SAndroid Build Coastguard Worker 		break;
854*2d543d20SAndroid Build Coastguard Worker 	case CIL_CLASSORDER:
855*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_ordered(*data);
856*2d543d20SAndroid Build Coastguard Worker 		break;
857*2d543d20SAndroid Build Coastguard Worker 	case CIL_CLASSPERMISSION:
858*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_classpermission(*data);
859*2d543d20SAndroid Build Coastguard Worker 		break;
860*2d543d20SAndroid Build Coastguard Worker 	case CIL_CLASSCOMMON:
861*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_classcommon(*data);
862*2d543d20SAndroid Build Coastguard Worker 		break;
863*2d543d20SAndroid Build Coastguard Worker 	case CIL_CLASSMAPPING:
864*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_classmapping(*data);
865*2d543d20SAndroid Build Coastguard Worker 		break;
866*2d543d20SAndroid Build Coastguard Worker 	case CIL_CLASSPERMS:
867*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_classperms(*data);
868*2d543d20SAndroid Build Coastguard Worker 		break;
869*2d543d20SAndroid Build Coastguard Worker 	case CIL_CLASSPERMS_SET:
870*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_classperms_set(*data);
871*2d543d20SAndroid Build Coastguard Worker 		break;
872*2d543d20SAndroid Build Coastguard Worker 	case CIL_CLASSPERMISSIONSET:
873*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_classpermissionset(*data);
874*2d543d20SAndroid Build Coastguard Worker 		break;
875*2d543d20SAndroid Build Coastguard Worker 	case CIL_USER:
876*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_user(*data);
877*2d543d20SAndroid Build Coastguard Worker 		break;
878*2d543d20SAndroid Build Coastguard Worker 	case CIL_USERATTRIBUTE:
879*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_userattribute(*data);
880*2d543d20SAndroid Build Coastguard Worker 		break;
881*2d543d20SAndroid Build Coastguard Worker 	case CIL_USERATTRIBUTESET:
882*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_userattributeset(*data);
883*2d543d20SAndroid Build Coastguard Worker 		break;
884*2d543d20SAndroid Build Coastguard Worker 	case CIL_USERPREFIX:
885*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_userprefix(*data);
886*2d543d20SAndroid Build Coastguard Worker 		break;
887*2d543d20SAndroid Build Coastguard Worker 	case CIL_USERROLE:
888*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_userrole(*data);
889*2d543d20SAndroid Build Coastguard Worker 		break;
890*2d543d20SAndroid Build Coastguard Worker 	case CIL_USERLEVEL:
891*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_userlevel(*data);
892*2d543d20SAndroid Build Coastguard Worker 		break;
893*2d543d20SAndroid Build Coastguard Worker 	case CIL_USERRANGE:
894*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_userrange(*data);
895*2d543d20SAndroid Build Coastguard Worker 		break;
896*2d543d20SAndroid Build Coastguard Worker 	case CIL_USERBOUNDS:
897*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_bounds(*data);
898*2d543d20SAndroid Build Coastguard Worker 		break;
899*2d543d20SAndroid Build Coastguard Worker 	case CIL_SELINUXUSER:
900*2d543d20SAndroid Build Coastguard Worker 	case CIL_SELINUXUSERDEFAULT:
901*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_selinuxuser(*data);
902*2d543d20SAndroid Build Coastguard Worker 		break;
903*2d543d20SAndroid Build Coastguard Worker 	case CIL_ROLE:
904*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_role(*data);
905*2d543d20SAndroid Build Coastguard Worker 		break;
906*2d543d20SAndroid Build Coastguard Worker 	case CIL_ROLEATTRIBUTE:
907*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_roleattribute(*data);
908*2d543d20SAndroid Build Coastguard Worker 		break;
909*2d543d20SAndroid Build Coastguard Worker 	case CIL_ROLEATTRIBUTESET:
910*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_roleattributeset(*data);
911*2d543d20SAndroid Build Coastguard Worker 		break;
912*2d543d20SAndroid Build Coastguard Worker 	case CIL_ROLETYPE:
913*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_roletype(*data);
914*2d543d20SAndroid Build Coastguard Worker 		break;
915*2d543d20SAndroid Build Coastguard Worker 	case CIL_ROLEBOUNDS:
916*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_bounds(*data);
917*2d543d20SAndroid Build Coastguard Worker 		break;
918*2d543d20SAndroid Build Coastguard Worker 	case CIL_TYPE:
919*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_type(*data);
920*2d543d20SAndroid Build Coastguard Worker 		break;
921*2d543d20SAndroid Build Coastguard Worker 	case CIL_TYPEATTRIBUTE:
922*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_typeattribute(*data);
923*2d543d20SAndroid Build Coastguard Worker 		break;
924*2d543d20SAndroid Build Coastguard Worker 	case CIL_TYPEALIAS:
925*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_alias(*data);
926*2d543d20SAndroid Build Coastguard Worker 		break;
927*2d543d20SAndroid Build Coastguard Worker 	case CIL_TYPEATTRIBUTESET:
928*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_typeattributeset(*data);
929*2d543d20SAndroid Build Coastguard Worker 		break;
930*2d543d20SAndroid Build Coastguard Worker 	case CIL_EXPANDTYPEATTRIBUTE:
931*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_expandtypeattribute(*data);
932*2d543d20SAndroid Build Coastguard Worker 		break;
933*2d543d20SAndroid Build Coastguard Worker 	case CIL_TYPEALIASACTUAL:
934*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_aliasactual(*data);
935*2d543d20SAndroid Build Coastguard Worker 		break;
936*2d543d20SAndroid Build Coastguard Worker 	case CIL_TYPEBOUNDS:
937*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_bounds(*data);
938*2d543d20SAndroid Build Coastguard Worker 		break;
939*2d543d20SAndroid Build Coastguard Worker 	case CIL_TYPEPERMISSIVE:
940*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_typepermissive(*data);
941*2d543d20SAndroid Build Coastguard Worker 		break;
942*2d543d20SAndroid Build Coastguard Worker 	case CIL_SENS:
943*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_sensitivity(*data);
944*2d543d20SAndroid Build Coastguard Worker 		break;
945*2d543d20SAndroid Build Coastguard Worker 	case CIL_SENSALIAS:
946*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_alias(*data);
947*2d543d20SAndroid Build Coastguard Worker 		break;
948*2d543d20SAndroid Build Coastguard Worker 	case CIL_SENSALIASACTUAL:
949*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_aliasactual(*data);
950*2d543d20SAndroid Build Coastguard Worker 		break;
951*2d543d20SAndroid Build Coastguard Worker 	case CIL_SENSITIVITYORDER:
952*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_ordered(*data);
953*2d543d20SAndroid Build Coastguard Worker 		break;
954*2d543d20SAndroid Build Coastguard Worker 	case CIL_SENSCAT:
955*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_senscat(*data);
956*2d543d20SAndroid Build Coastguard Worker 		break;
957*2d543d20SAndroid Build Coastguard Worker 	case CIL_CAT:
958*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_category(*data);
959*2d543d20SAndroid Build Coastguard Worker 		break;
960*2d543d20SAndroid Build Coastguard Worker 	case CIL_CATSET:
961*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_catset(*data);
962*2d543d20SAndroid Build Coastguard Worker 		break;
963*2d543d20SAndroid Build Coastguard Worker 	case CIL_CATALIAS:
964*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_alias(*data);
965*2d543d20SAndroid Build Coastguard Worker 		break;
966*2d543d20SAndroid Build Coastguard Worker 	case CIL_CATALIASACTUAL:
967*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_aliasactual(*data);
968*2d543d20SAndroid Build Coastguard Worker 		break;
969*2d543d20SAndroid Build Coastguard Worker 	case CIL_CATORDER:
970*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_ordered(*data);
971*2d543d20SAndroid Build Coastguard Worker 		break;
972*2d543d20SAndroid Build Coastguard Worker 	case CIL_LEVEL:
973*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_level(*data);
974*2d543d20SAndroid Build Coastguard Worker 		break;
975*2d543d20SAndroid Build Coastguard Worker 	case CIL_LEVELRANGE:
976*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_levelrange(*data);
977*2d543d20SAndroid Build Coastguard Worker 		break;
978*2d543d20SAndroid Build Coastguard Worker 	case CIL_SID:
979*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_sid(*data);
980*2d543d20SAndroid Build Coastguard Worker 		break;
981*2d543d20SAndroid Build Coastguard Worker 	case CIL_SIDORDER:
982*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_ordered(*data);
983*2d543d20SAndroid Build Coastguard Worker 		break;
984*2d543d20SAndroid Build Coastguard Worker 	case CIL_ROLEALLOW:
985*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_roleallow(*data);
986*2d543d20SAndroid Build Coastguard Worker 		break;
987*2d543d20SAndroid Build Coastguard Worker 	case CIL_AVRULE:
988*2d543d20SAndroid Build Coastguard Worker 	case CIL_AVRULEX:
989*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_avrule(*data);
990*2d543d20SAndroid Build Coastguard Worker 		break;
991*2d543d20SAndroid Build Coastguard Worker 	case CIL_PERMISSIONX:
992*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_permissionx(*data);
993*2d543d20SAndroid Build Coastguard Worker 		break;
994*2d543d20SAndroid Build Coastguard Worker 	case CIL_DENY_RULE:
995*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_deny_rule(*data);
996*2d543d20SAndroid Build Coastguard Worker 		break;
997*2d543d20SAndroid Build Coastguard Worker 	case CIL_ROLETRANSITION:
998*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_roletransition(*data);
999*2d543d20SAndroid Build Coastguard Worker 		break;
1000*2d543d20SAndroid Build Coastguard Worker 	case CIL_TYPE_RULE:
1001*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_type_rule(*data);
1002*2d543d20SAndroid Build Coastguard Worker 		break;
1003*2d543d20SAndroid Build Coastguard Worker 	case CIL_NAMETYPETRANSITION:
1004*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_typetransition(*data);
1005*2d543d20SAndroid Build Coastguard Worker 		break;
1006*2d543d20SAndroid Build Coastguard Worker 	case CIL_RANGETRANSITION:
1007*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_rangetransition(*data);
1008*2d543d20SAndroid Build Coastguard Worker 		break;
1009*2d543d20SAndroid Build Coastguard Worker 	case CIL_CONSTRAIN:
1010*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_constrain(*data);
1011*2d543d20SAndroid Build Coastguard Worker 		break;
1012*2d543d20SAndroid Build Coastguard Worker 	case CIL_MLSCONSTRAIN:
1013*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_constrain(*data);
1014*2d543d20SAndroid Build Coastguard Worker 		break;
1015*2d543d20SAndroid Build Coastguard Worker 	case CIL_VALIDATETRANS:
1016*2d543d20SAndroid Build Coastguard Worker 	case CIL_MLSVALIDATETRANS:
1017*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_validatetrans(*data);
1018*2d543d20SAndroid Build Coastguard Worker 		break;
1019*2d543d20SAndroid Build Coastguard Worker 	case CIL_CONTEXT:
1020*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_context(*data);
1021*2d543d20SAndroid Build Coastguard Worker 		break;
1022*2d543d20SAndroid Build Coastguard Worker 	case CIL_IPADDR:
1023*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_ipaddr(*data);
1024*2d543d20SAndroid Build Coastguard Worker 		break;
1025*2d543d20SAndroid Build Coastguard Worker 	case CIL_DECLARED_STRING:
1026*2d543d20SAndroid Build Coastguard Worker 		break;
1027*2d543d20SAndroid Build Coastguard Worker 	case CIL_SIDCONTEXT:
1028*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_sidcontext(*data);
1029*2d543d20SAndroid Build Coastguard Worker 		break;
1030*2d543d20SAndroid Build Coastguard Worker 	case CIL_FSUSE:
1031*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_fsuse(*data);
1032*2d543d20SAndroid Build Coastguard Worker 		break;
1033*2d543d20SAndroid Build Coastguard Worker 	case CIL_FILECON:
1034*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_filecon(*data);
1035*2d543d20SAndroid Build Coastguard Worker 		break;
1036*2d543d20SAndroid Build Coastguard Worker 	case CIL_IBPKEYCON:
1037*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_ibpkeycon(*data);
1038*2d543d20SAndroid Build Coastguard Worker 		break;
1039*2d543d20SAndroid Build Coastguard Worker 	case CIL_PORTCON:
1040*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_portcon(*data);
1041*2d543d20SAndroid Build Coastguard Worker 		break;
1042*2d543d20SAndroid Build Coastguard Worker 	case CIL_IBENDPORTCON:
1043*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_ibendportcon(*data);
1044*2d543d20SAndroid Build Coastguard Worker 		break;
1045*2d543d20SAndroid Build Coastguard Worker 	case CIL_NODECON:
1046*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_nodecon(*data);
1047*2d543d20SAndroid Build Coastguard Worker 		break;
1048*2d543d20SAndroid Build Coastguard Worker 	case CIL_GENFSCON:
1049*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_genfscon(*data);
1050*2d543d20SAndroid Build Coastguard Worker 		break;
1051*2d543d20SAndroid Build Coastguard Worker 	case CIL_NETIFCON:
1052*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_netifcon(*data);
1053*2d543d20SAndroid Build Coastguard Worker 		break;
1054*2d543d20SAndroid Build Coastguard Worker 	case CIL_PIRQCON:
1055*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_pirqcon(*data);
1056*2d543d20SAndroid Build Coastguard Worker 		break;
1057*2d543d20SAndroid Build Coastguard Worker 	case CIL_IOMEMCON:
1058*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_iomemcon(*data);
1059*2d543d20SAndroid Build Coastguard Worker 		break;
1060*2d543d20SAndroid Build Coastguard Worker 	case CIL_IOPORTCON:
1061*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_ioportcon(*data);
1062*2d543d20SAndroid Build Coastguard Worker 		break;
1063*2d543d20SAndroid Build Coastguard Worker 	case CIL_PCIDEVICECON:
1064*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_pcidevicecon(*data);
1065*2d543d20SAndroid Build Coastguard Worker 		break;
1066*2d543d20SAndroid Build Coastguard Worker 	case CIL_DEVICETREECON:
1067*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_devicetreecon(*data);
1068*2d543d20SAndroid Build Coastguard Worker 		break;
1069*2d543d20SAndroid Build Coastguard Worker 	case CIL_POLICYCAP:
1070*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_policycap(*data);
1071*2d543d20SAndroid Build Coastguard Worker 		break;
1072*2d543d20SAndroid Build Coastguard Worker 	case CIL_DEFAULTUSER:
1073*2d543d20SAndroid Build Coastguard Worker 	case CIL_DEFAULTROLE:
1074*2d543d20SAndroid Build Coastguard Worker 	case CIL_DEFAULTTYPE:
1075*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_default(*data);
1076*2d543d20SAndroid Build Coastguard Worker 		break;
1077*2d543d20SAndroid Build Coastguard Worker 	case CIL_DEFAULTRANGE:
1078*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_defaultrange(*data);
1079*2d543d20SAndroid Build Coastguard Worker 		break;
1080*2d543d20SAndroid Build Coastguard Worker 	case CIL_HANDLEUNKNOWN:
1081*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_handleunknown(*data);
1082*2d543d20SAndroid Build Coastguard Worker 		break;
1083*2d543d20SAndroid Build Coastguard Worker 	case CIL_MLS:
1084*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_mls(*data);
1085*2d543d20SAndroid Build Coastguard Worker 		break;
1086*2d543d20SAndroid Build Coastguard Worker 	case CIL_SRC_INFO:
1087*2d543d20SAndroid Build Coastguard Worker 		cil_destroy_src_info(*data);
1088*2d543d20SAndroid Build Coastguard Worker 		break;
1089*2d543d20SAndroid Build Coastguard Worker 	case CIL_OP:
1090*2d543d20SAndroid Build Coastguard Worker 	case CIL_CONS_OPERAND:
1091*2d543d20SAndroid Build Coastguard Worker 		break;
1092*2d543d20SAndroid Build Coastguard Worker 	default:
1093*2d543d20SAndroid Build Coastguard Worker 		cil_log(CIL_INFO, "Unknown data flavor: %d\n", flavor);
1094*2d543d20SAndroid Build Coastguard Worker 		break;
1095*2d543d20SAndroid Build Coastguard Worker 	}
1096*2d543d20SAndroid Build Coastguard Worker 
1097*2d543d20SAndroid Build Coastguard Worker 	*data = NULL;
1098*2d543d20SAndroid Build Coastguard Worker }
1099*2d543d20SAndroid Build Coastguard Worker 
cil_flavor_to_symtab_index(enum cil_flavor flavor,enum cil_sym_index * sym_index)1100*2d543d20SAndroid Build Coastguard Worker int cil_flavor_to_symtab_index(enum cil_flavor flavor, enum cil_sym_index *sym_index)
1101*2d543d20SAndroid Build Coastguard Worker {
1102*2d543d20SAndroid Build Coastguard Worker 	if (flavor < CIL_MIN_DECLARATIVE) {
1103*2d543d20SAndroid Build Coastguard Worker 		return SEPOL_ERR;
1104*2d543d20SAndroid Build Coastguard Worker 	}
1105*2d543d20SAndroid Build Coastguard Worker 
1106*2d543d20SAndroid Build Coastguard Worker 	switch(flavor) {
1107*2d543d20SAndroid Build Coastguard Worker 	case CIL_BLOCK:
1108*2d543d20SAndroid Build Coastguard Worker 		*sym_index = CIL_SYM_BLOCKS;
1109*2d543d20SAndroid Build Coastguard Worker 		break;
1110*2d543d20SAndroid Build Coastguard Worker 	case CIL_MACRO:
1111*2d543d20SAndroid Build Coastguard Worker 		*sym_index = CIL_SYM_BLOCKS;
1112*2d543d20SAndroid Build Coastguard Worker 		break;
1113*2d543d20SAndroid Build Coastguard Worker 	case CIL_OPTIONAL:
1114*2d543d20SAndroid Build Coastguard Worker 		*sym_index = CIL_SYM_BLOCKS;
1115*2d543d20SAndroid Build Coastguard Worker 		break;
1116*2d543d20SAndroid Build Coastguard Worker 	case CIL_BOOL:
1117*2d543d20SAndroid Build Coastguard Worker 		*sym_index = CIL_SYM_BOOLS;
1118*2d543d20SAndroid Build Coastguard Worker 		break;
1119*2d543d20SAndroid Build Coastguard Worker 	case CIL_TUNABLE:
1120*2d543d20SAndroid Build Coastguard Worker 		*sym_index = CIL_SYM_TUNABLES;
1121*2d543d20SAndroid Build Coastguard Worker 		break;
1122*2d543d20SAndroid Build Coastguard Worker 	case CIL_PERM:
1123*2d543d20SAndroid Build Coastguard Worker 	case CIL_MAP_PERM:
1124*2d543d20SAndroid Build Coastguard Worker 		*sym_index = CIL_SYM_PERMS;
1125*2d543d20SAndroid Build Coastguard Worker 		break;
1126*2d543d20SAndroid Build Coastguard Worker 	case CIL_COMMON:
1127*2d543d20SAndroid Build Coastguard Worker 		*sym_index = CIL_SYM_COMMONS;
1128*2d543d20SAndroid Build Coastguard Worker 		break;
1129*2d543d20SAndroid Build Coastguard Worker 	case CIL_CLASS:
1130*2d543d20SAndroid Build Coastguard Worker 	case CIL_MAP_CLASS:
1131*2d543d20SAndroid Build Coastguard Worker 		*sym_index = CIL_SYM_CLASSES;
1132*2d543d20SAndroid Build Coastguard Worker 		break;
1133*2d543d20SAndroid Build Coastguard Worker 	case CIL_CLASSPERMISSION:
1134*2d543d20SAndroid Build Coastguard Worker 	case CIL_CLASSPERMISSIONSET:
1135*2d543d20SAndroid Build Coastguard Worker 		*sym_index = CIL_SYM_CLASSPERMSETS;
1136*2d543d20SAndroid Build Coastguard Worker 		break;
1137*2d543d20SAndroid Build Coastguard Worker 	case CIL_USER:
1138*2d543d20SAndroid Build Coastguard Worker 	case CIL_USERATTRIBUTE:
1139*2d543d20SAndroid Build Coastguard Worker 		*sym_index = CIL_SYM_USERS;
1140*2d543d20SAndroid Build Coastguard Worker 		break;
1141*2d543d20SAndroid Build Coastguard Worker 	case CIL_ROLE:
1142*2d543d20SAndroid Build Coastguard Worker 	case CIL_ROLEATTRIBUTE:
1143*2d543d20SAndroid Build Coastguard Worker 		*sym_index = CIL_SYM_ROLES;
1144*2d543d20SAndroid Build Coastguard Worker 		break;
1145*2d543d20SAndroid Build Coastguard Worker 	case CIL_TYPE:
1146*2d543d20SAndroid Build Coastguard Worker 	case CIL_TYPEALIAS:
1147*2d543d20SAndroid Build Coastguard Worker 	case CIL_TYPEATTRIBUTE:
1148*2d543d20SAndroid Build Coastguard Worker 		*sym_index = CIL_SYM_TYPES;
1149*2d543d20SAndroid Build Coastguard Worker 		break;
1150*2d543d20SAndroid Build Coastguard Worker 	case CIL_SENS:
1151*2d543d20SAndroid Build Coastguard Worker 	case CIL_SENSALIAS:
1152*2d543d20SAndroid Build Coastguard Worker 		*sym_index = CIL_SYM_SENS;
1153*2d543d20SAndroid Build Coastguard Worker 		break;
1154*2d543d20SAndroid Build Coastguard Worker 	case CIL_CAT:
1155*2d543d20SAndroid Build Coastguard Worker 	case CIL_CATSET:
1156*2d543d20SAndroid Build Coastguard Worker 	case CIL_CATALIAS:
1157*2d543d20SAndroid Build Coastguard Worker 		*sym_index = CIL_SYM_CATS;
1158*2d543d20SAndroid Build Coastguard Worker 		break;
1159*2d543d20SAndroid Build Coastguard Worker 	case CIL_LEVEL:
1160*2d543d20SAndroid Build Coastguard Worker 		*sym_index = CIL_SYM_LEVELS;
1161*2d543d20SAndroid Build Coastguard Worker 		break;
1162*2d543d20SAndroid Build Coastguard Worker 	case CIL_LEVELRANGE:
1163*2d543d20SAndroid Build Coastguard Worker 		*sym_index = CIL_SYM_LEVELRANGES;
1164*2d543d20SAndroid Build Coastguard Worker 		break;
1165*2d543d20SAndroid Build Coastguard Worker 	case CIL_SID:
1166*2d543d20SAndroid Build Coastguard Worker 		*sym_index = CIL_SYM_SIDS;
1167*2d543d20SAndroid Build Coastguard Worker 		break;
1168*2d543d20SAndroid Build Coastguard Worker 	case CIL_DECLARED_STRING:
1169*2d543d20SAndroid Build Coastguard Worker 		*sym_index = CIL_SYM_STRINGS;
1170*2d543d20SAndroid Build Coastguard Worker 		break;
1171*2d543d20SAndroid Build Coastguard Worker 	case CIL_CONTEXT:
1172*2d543d20SAndroid Build Coastguard Worker 		*sym_index = CIL_SYM_CONTEXTS;
1173*2d543d20SAndroid Build Coastguard Worker 		break;
1174*2d543d20SAndroid Build Coastguard Worker 	case CIL_IPADDR:
1175*2d543d20SAndroid Build Coastguard Worker 		*sym_index = CIL_SYM_IPADDRS;
1176*2d543d20SAndroid Build Coastguard Worker 		break;
1177*2d543d20SAndroid Build Coastguard Worker 	case CIL_POLICYCAP:
1178*2d543d20SAndroid Build Coastguard Worker 		*sym_index = CIL_SYM_POLICYCAPS;
1179*2d543d20SAndroid Build Coastguard Worker 		break;
1180*2d543d20SAndroid Build Coastguard Worker 	case CIL_PERMISSIONX:
1181*2d543d20SAndroid Build Coastguard Worker 		*sym_index = CIL_SYM_PERMX;
1182*2d543d20SAndroid Build Coastguard Worker 		break;
1183*2d543d20SAndroid Build Coastguard Worker 	default:
1184*2d543d20SAndroid Build Coastguard Worker 		*sym_index = CIL_SYM_UNKNOWN;
1185*2d543d20SAndroid Build Coastguard Worker 		cil_log(CIL_INFO, "Failed to find flavor: %d\n", flavor);
1186*2d543d20SAndroid Build Coastguard Worker 		return SEPOL_ERR;
1187*2d543d20SAndroid Build Coastguard Worker 	}
1188*2d543d20SAndroid Build Coastguard Worker 
1189*2d543d20SAndroid Build Coastguard Worker 	return SEPOL_OK;
1190*2d543d20SAndroid Build Coastguard Worker }
1191*2d543d20SAndroid Build Coastguard Worker 
cil_node_to_string(struct cil_tree_node * node)1192*2d543d20SAndroid Build Coastguard Worker const char * cil_node_to_string(struct cil_tree_node *node)
1193*2d543d20SAndroid Build Coastguard Worker {
1194*2d543d20SAndroid Build Coastguard Worker 	switch (node->flavor) {
1195*2d543d20SAndroid Build Coastguard Worker 	case CIL_NONE:
1196*2d543d20SAndroid Build Coastguard Worker 		return "<none>";
1197*2d543d20SAndroid Build Coastguard Worker 	case CIL_ROOT:
1198*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_ROOT;
1199*2d543d20SAndroid Build Coastguard Worker 	case CIL_NODE:
1200*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_NODE;
1201*2d543d20SAndroid Build Coastguard Worker 	case CIL_STRING:
1202*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_STRING;
1203*2d543d20SAndroid Build Coastguard Worker 	case CIL_DATUM:
1204*2d543d20SAndroid Build Coastguard Worker 		return "<datum>";
1205*2d543d20SAndroid Build Coastguard Worker 	case CIL_LIST:
1206*2d543d20SAndroid Build Coastguard Worker 		return "<list>";
1207*2d543d20SAndroid Build Coastguard Worker 	case CIL_LIST_ITEM:
1208*2d543d20SAndroid Build Coastguard Worker 		return "<list_item>";
1209*2d543d20SAndroid Build Coastguard Worker 	case CIL_PARAM:
1210*2d543d20SAndroid Build Coastguard Worker 		return "<param>";
1211*2d543d20SAndroid Build Coastguard Worker 	case CIL_ARGS:
1212*2d543d20SAndroid Build Coastguard Worker 		return "<args>";
1213*2d543d20SAndroid Build Coastguard Worker 	case CIL_BLOCK:
1214*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_BLOCK;
1215*2d543d20SAndroid Build Coastguard Worker 	case CIL_BLOCKINHERIT:
1216*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_BLOCKINHERIT;
1217*2d543d20SAndroid Build Coastguard Worker 	case CIL_BLOCKABSTRACT:
1218*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_BLOCKABSTRACT;
1219*2d543d20SAndroid Build Coastguard Worker 	case CIL_IN:
1220*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_IN;
1221*2d543d20SAndroid Build Coastguard Worker 	case CIL_MACRO:
1222*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_MACRO;
1223*2d543d20SAndroid Build Coastguard Worker 	case CIL_CALL:
1224*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_CALL;
1225*2d543d20SAndroid Build Coastguard Worker 	case CIL_OPTIONAL:
1226*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_OPTIONAL;
1227*2d543d20SAndroid Build Coastguard Worker 	case CIL_BOOL:
1228*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_BOOL;
1229*2d543d20SAndroid Build Coastguard Worker 	case CIL_BOOLEANIF:
1230*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_BOOLEANIF;
1231*2d543d20SAndroid Build Coastguard Worker 	case CIL_TUNABLE:
1232*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_TUNABLE;
1233*2d543d20SAndroid Build Coastguard Worker 	case CIL_TUNABLEIF:
1234*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_TUNABLEIF;
1235*2d543d20SAndroid Build Coastguard Worker 	case CIL_CONDBLOCK:
1236*2d543d20SAndroid Build Coastguard Worker 		switch (((struct cil_condblock*)node->data)->flavor) {
1237*2d543d20SAndroid Build Coastguard Worker 		case CIL_CONDTRUE:
1238*2d543d20SAndroid Build Coastguard Worker 			return CIL_KEY_CONDTRUE;
1239*2d543d20SAndroid Build Coastguard Worker 		case CIL_CONDFALSE:
1240*2d543d20SAndroid Build Coastguard Worker 			return CIL_KEY_CONDFALSE;
1241*2d543d20SAndroid Build Coastguard Worker 		default:
1242*2d543d20SAndroid Build Coastguard Worker 			break;
1243*2d543d20SAndroid Build Coastguard Worker 		}
1244*2d543d20SAndroid Build Coastguard Worker 		break;
1245*2d543d20SAndroid Build Coastguard Worker 	case CIL_CONDTRUE:
1246*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_CONDTRUE;
1247*2d543d20SAndroid Build Coastguard Worker 	case CIL_CONDFALSE:
1248*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_CONDFALSE;
1249*2d543d20SAndroid Build Coastguard Worker 	case CIL_PERM:
1250*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_PERM;
1251*2d543d20SAndroid Build Coastguard Worker 	case CIL_COMMON:
1252*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_COMMON;
1253*2d543d20SAndroid Build Coastguard Worker 	case CIL_CLASS:
1254*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_CLASS;
1255*2d543d20SAndroid Build Coastguard Worker 	case CIL_CLASSORDER:
1256*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_CLASSORDER;
1257*2d543d20SAndroid Build Coastguard Worker 	case CIL_MAP_CLASS:
1258*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_MAP_CLASS;
1259*2d543d20SAndroid Build Coastguard Worker 	case CIL_CLASSPERMISSION:
1260*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_CLASSPERMISSION;
1261*2d543d20SAndroid Build Coastguard Worker 	case CIL_CLASSCOMMON:
1262*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_CLASSCOMMON;
1263*2d543d20SAndroid Build Coastguard Worker 	case CIL_CLASSMAPPING:
1264*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_CLASSMAPPING;
1265*2d543d20SAndroid Build Coastguard Worker 	case CIL_CLASSPERMISSIONSET:
1266*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_CLASSPERMISSIONSET;
1267*2d543d20SAndroid Build Coastguard Worker 	case CIL_USER:
1268*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_USER;
1269*2d543d20SAndroid Build Coastguard Worker 	case CIL_USERATTRIBUTE:
1270*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_USERATTRIBUTE;
1271*2d543d20SAndroid Build Coastguard Worker 	case CIL_USERATTRIBUTESET:
1272*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_USERATTRIBUTESET;
1273*2d543d20SAndroid Build Coastguard Worker 	case CIL_USERPREFIX:
1274*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_USERPREFIX;
1275*2d543d20SAndroid Build Coastguard Worker 	case CIL_USERROLE:
1276*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_USERROLE;
1277*2d543d20SAndroid Build Coastguard Worker 	case CIL_USERLEVEL:
1278*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_USERLEVEL;
1279*2d543d20SAndroid Build Coastguard Worker 	case CIL_USERRANGE:
1280*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_USERRANGE;
1281*2d543d20SAndroid Build Coastguard Worker 	case CIL_USERBOUNDS:
1282*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_USERBOUNDS;
1283*2d543d20SAndroid Build Coastguard Worker 	case CIL_SELINUXUSER:
1284*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_SELINUXUSER;
1285*2d543d20SAndroid Build Coastguard Worker 	case CIL_SELINUXUSERDEFAULT:
1286*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_SELINUXUSERDEFAULT;
1287*2d543d20SAndroid Build Coastguard Worker 	case CIL_ROLE:
1288*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_ROLE;
1289*2d543d20SAndroid Build Coastguard Worker 	case CIL_ROLEATTRIBUTE:
1290*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_ROLEATTRIBUTE;
1291*2d543d20SAndroid Build Coastguard Worker 	case CIL_ROLEATTRIBUTESET:
1292*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_ROLEATTRIBUTESET;
1293*2d543d20SAndroid Build Coastguard Worker 	case CIL_ROLETYPE:
1294*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_ROLETYPE;
1295*2d543d20SAndroid Build Coastguard Worker 	case CIL_ROLEBOUNDS:
1296*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_ROLEBOUNDS;
1297*2d543d20SAndroid Build Coastguard Worker 	case CIL_TYPE:
1298*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_TYPE;
1299*2d543d20SAndroid Build Coastguard Worker 	case CIL_TYPEATTRIBUTE:
1300*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_TYPEATTRIBUTE;
1301*2d543d20SAndroid Build Coastguard Worker 	case CIL_TYPEALIAS:
1302*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_TYPEALIAS;
1303*2d543d20SAndroid Build Coastguard Worker 	case CIL_TYPEATTRIBUTESET:
1304*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_TYPEATTRIBUTESET;
1305*2d543d20SAndroid Build Coastguard Worker 	case CIL_EXPANDTYPEATTRIBUTE:
1306*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_EXPANDTYPEATTRIBUTE;
1307*2d543d20SAndroid Build Coastguard Worker 	case CIL_TYPEALIASACTUAL:
1308*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_TYPEALIASACTUAL;
1309*2d543d20SAndroid Build Coastguard Worker 	case CIL_TYPEBOUNDS:
1310*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_TYPEBOUNDS;
1311*2d543d20SAndroid Build Coastguard Worker 	case CIL_TYPEPERMISSIVE:
1312*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_TYPEPERMISSIVE;
1313*2d543d20SAndroid Build Coastguard Worker 	case CIL_SENS:
1314*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_SENSITIVITY;
1315*2d543d20SAndroid Build Coastguard Worker 	case CIL_SENSALIAS:
1316*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_SENSALIAS;
1317*2d543d20SAndroid Build Coastguard Worker 	case CIL_SENSALIASACTUAL:
1318*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_SENSALIASACTUAL;
1319*2d543d20SAndroid Build Coastguard Worker 	case CIL_SENSITIVITYORDER:
1320*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_SENSITIVITYORDER;
1321*2d543d20SAndroid Build Coastguard Worker 	case CIL_SENSCAT:
1322*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_SENSCAT;
1323*2d543d20SAndroid Build Coastguard Worker 	case CIL_CAT:
1324*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_CATEGORY;
1325*2d543d20SAndroid Build Coastguard Worker 	case CIL_CATSET:
1326*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_CATSET;
1327*2d543d20SAndroid Build Coastguard Worker 	case CIL_CATALIAS:
1328*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_CATALIAS;
1329*2d543d20SAndroid Build Coastguard Worker 	case CIL_CATALIASACTUAL:
1330*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_CATALIASACTUAL;
1331*2d543d20SAndroid Build Coastguard Worker 	case CIL_CATORDER:
1332*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_CATORDER;
1333*2d543d20SAndroid Build Coastguard Worker 	case CIL_LEVEL:
1334*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_LEVEL;
1335*2d543d20SAndroid Build Coastguard Worker 	case CIL_LEVELRANGE:
1336*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_LEVELRANGE;
1337*2d543d20SAndroid Build Coastguard Worker 	case CIL_SID:
1338*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_SID;
1339*2d543d20SAndroid Build Coastguard Worker 	case CIL_SIDORDER:
1340*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_SIDORDER;
1341*2d543d20SAndroid Build Coastguard Worker 	case CIL_ROLEALLOW:
1342*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_ROLEALLOW;
1343*2d543d20SAndroid Build Coastguard Worker 	case CIL_AVRULE:
1344*2d543d20SAndroid Build Coastguard Worker 		switch (((struct cil_avrule *)node->data)->rule_kind) {
1345*2d543d20SAndroid Build Coastguard Worker 		case CIL_AVRULE_ALLOWED:
1346*2d543d20SAndroid Build Coastguard Worker 			return CIL_KEY_ALLOW;
1347*2d543d20SAndroid Build Coastguard Worker 		case CIL_AVRULE_AUDITALLOW:
1348*2d543d20SAndroid Build Coastguard Worker 			return CIL_KEY_AUDITALLOW;
1349*2d543d20SAndroid Build Coastguard Worker 		case CIL_AVRULE_DONTAUDIT:
1350*2d543d20SAndroid Build Coastguard Worker 			return CIL_KEY_DONTAUDIT;
1351*2d543d20SAndroid Build Coastguard Worker 		case CIL_AVRULE_NEVERALLOW:
1352*2d543d20SAndroid Build Coastguard Worker 			return CIL_KEY_NEVERALLOW;
1353*2d543d20SAndroid Build Coastguard Worker 		default:
1354*2d543d20SAndroid Build Coastguard Worker 			break;
1355*2d543d20SAndroid Build Coastguard Worker 		}
1356*2d543d20SAndroid Build Coastguard Worker 		break;
1357*2d543d20SAndroid Build Coastguard Worker 	case CIL_AVRULEX:
1358*2d543d20SAndroid Build Coastguard Worker 		switch (((struct cil_avrule *)node->data)->rule_kind) {
1359*2d543d20SAndroid Build Coastguard Worker 		case CIL_AVRULE_ALLOWED:
1360*2d543d20SAndroid Build Coastguard Worker 			return CIL_KEY_ALLOWX;
1361*2d543d20SAndroid Build Coastguard Worker 		case CIL_AVRULE_AUDITALLOW:
1362*2d543d20SAndroid Build Coastguard Worker 			return CIL_KEY_AUDITALLOWX;
1363*2d543d20SAndroid Build Coastguard Worker 		case CIL_AVRULE_DONTAUDIT:
1364*2d543d20SAndroid Build Coastguard Worker 			return CIL_KEY_DONTAUDITX;
1365*2d543d20SAndroid Build Coastguard Worker 		case CIL_AVRULE_NEVERALLOW:
1366*2d543d20SAndroid Build Coastguard Worker 			return CIL_KEY_NEVERALLOWX;
1367*2d543d20SAndroid Build Coastguard Worker 		default:
1368*2d543d20SAndroid Build Coastguard Worker 			break;
1369*2d543d20SAndroid Build Coastguard Worker 		}
1370*2d543d20SAndroid Build Coastguard Worker 		break;
1371*2d543d20SAndroid Build Coastguard Worker 	case CIL_PERMISSIONX:
1372*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_PERMISSIONX;
1373*2d543d20SAndroid Build Coastguard Worker 	case CIL_DENY_RULE:
1374*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_DENY_RULE;
1375*2d543d20SAndroid Build Coastguard Worker 	case CIL_ROLETRANSITION:
1376*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_ROLETRANSITION;
1377*2d543d20SAndroid Build Coastguard Worker 	case CIL_TYPE_RULE:
1378*2d543d20SAndroid Build Coastguard Worker 		switch (((struct cil_type_rule *)node->data)->rule_kind) {
1379*2d543d20SAndroid Build Coastguard Worker 		case CIL_TYPE_TRANSITION:
1380*2d543d20SAndroid Build Coastguard Worker 			return CIL_KEY_TYPETRANSITION;
1381*2d543d20SAndroid Build Coastguard Worker 		case CIL_TYPE_MEMBER:
1382*2d543d20SAndroid Build Coastguard Worker 			return CIL_KEY_TYPEMEMBER;
1383*2d543d20SAndroid Build Coastguard Worker 		case CIL_TYPE_CHANGE:
1384*2d543d20SAndroid Build Coastguard Worker 			return CIL_KEY_TYPECHANGE;
1385*2d543d20SAndroid Build Coastguard Worker 		default:
1386*2d543d20SAndroid Build Coastguard Worker 			break;
1387*2d543d20SAndroid Build Coastguard Worker 		}
1388*2d543d20SAndroid Build Coastguard Worker 		break;
1389*2d543d20SAndroid Build Coastguard Worker 	case CIL_NAMETYPETRANSITION:
1390*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_TYPETRANSITION;
1391*2d543d20SAndroid Build Coastguard Worker 	case CIL_RANGETRANSITION:
1392*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_RANGETRANSITION;
1393*2d543d20SAndroid Build Coastguard Worker 	case CIL_CONSTRAIN:
1394*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_CONSTRAIN;
1395*2d543d20SAndroid Build Coastguard Worker 	case CIL_MLSCONSTRAIN:
1396*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_MLSCONSTRAIN;
1397*2d543d20SAndroid Build Coastguard Worker 	case CIL_VALIDATETRANS:
1398*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_VALIDATETRANS;
1399*2d543d20SAndroid Build Coastguard Worker 	case CIL_MLSVALIDATETRANS:
1400*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_MLSVALIDATETRANS;
1401*2d543d20SAndroid Build Coastguard Worker 	case CIL_CONTEXT:
1402*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_CONTEXT;
1403*2d543d20SAndroid Build Coastguard Worker 	case CIL_IPADDR:
1404*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_IPADDR;
1405*2d543d20SAndroid Build Coastguard Worker 	case CIL_SIDCONTEXT:
1406*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_SIDCONTEXT;
1407*2d543d20SAndroid Build Coastguard Worker 	case CIL_FSUSE:
1408*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_FSUSE;
1409*2d543d20SAndroid Build Coastguard Worker 	case CIL_FILECON:
1410*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_FILECON;
1411*2d543d20SAndroid Build Coastguard Worker 	case CIL_IBPKEYCON:
1412*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_IBPKEYCON;
1413*2d543d20SAndroid Build Coastguard Worker 	case CIL_IBENDPORTCON:
1414*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_IBENDPORTCON;
1415*2d543d20SAndroid Build Coastguard Worker 	case CIL_PORTCON:
1416*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_PORTCON;
1417*2d543d20SAndroid Build Coastguard Worker 	case CIL_NODECON:
1418*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_NODECON;
1419*2d543d20SAndroid Build Coastguard Worker 	case CIL_GENFSCON:
1420*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_GENFSCON;
1421*2d543d20SAndroid Build Coastguard Worker 	case CIL_NETIFCON:
1422*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_NETIFCON;
1423*2d543d20SAndroid Build Coastguard Worker 	case CIL_PIRQCON:
1424*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_PIRQCON;
1425*2d543d20SAndroid Build Coastguard Worker 	case CIL_IOMEMCON:
1426*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_IOMEMCON;
1427*2d543d20SAndroid Build Coastguard Worker 	case CIL_IOPORTCON:
1428*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_IOPORTCON;
1429*2d543d20SAndroid Build Coastguard Worker 	case CIL_PCIDEVICECON:
1430*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_PCIDEVICECON;
1431*2d543d20SAndroid Build Coastguard Worker 	case CIL_DEVICETREECON:
1432*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_DEVICETREECON;
1433*2d543d20SAndroid Build Coastguard Worker 	case CIL_POLICYCAP:
1434*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_POLICYCAP;
1435*2d543d20SAndroid Build Coastguard Worker 	case CIL_DEFAULTUSER:
1436*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_DEFAULTUSER;
1437*2d543d20SAndroid Build Coastguard Worker 	case CIL_DEFAULTROLE:
1438*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_DEFAULTROLE;
1439*2d543d20SAndroid Build Coastguard Worker 	case CIL_DEFAULTTYPE:
1440*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_DEFAULTTYPE;
1441*2d543d20SAndroid Build Coastguard Worker 	case CIL_DEFAULTRANGE:
1442*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_DEFAULTRANGE;
1443*2d543d20SAndroid Build Coastguard Worker 	case CIL_HANDLEUNKNOWN:
1444*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_HANDLEUNKNOWN;
1445*2d543d20SAndroid Build Coastguard Worker 	case CIL_MLS:
1446*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_MLS;
1447*2d543d20SAndroid Build Coastguard Worker 	case CIL_SRC_INFO:
1448*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_SRC_INFO;
1449*2d543d20SAndroid Build Coastguard Worker 	case CIL_ALL:
1450*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_ALL;
1451*2d543d20SAndroid Build Coastguard Worker 	case CIL_RANGE:
1452*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_RANGE;
1453*2d543d20SAndroid Build Coastguard Worker 	case CIL_AND:
1454*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_AND;
1455*2d543d20SAndroid Build Coastguard Worker 	case CIL_OR:
1456*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_OR;
1457*2d543d20SAndroid Build Coastguard Worker 	case CIL_XOR:
1458*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_XOR;
1459*2d543d20SAndroid Build Coastguard Worker 	case CIL_NOT:
1460*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_NOT;
1461*2d543d20SAndroid Build Coastguard Worker 	case CIL_EQ:
1462*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_EQ;
1463*2d543d20SAndroid Build Coastguard Worker 	case CIL_NEQ:
1464*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_NEQ;
1465*2d543d20SAndroid Build Coastguard Worker 	case CIL_CONS_DOM:
1466*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_CONS_DOM;
1467*2d543d20SAndroid Build Coastguard Worker 	case CIL_CONS_DOMBY:
1468*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_CONS_DOMBY;
1469*2d543d20SAndroid Build Coastguard Worker 	case CIL_CONS_INCOMP:
1470*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_CONS_INCOMP;
1471*2d543d20SAndroid Build Coastguard Worker 	case CIL_CONS_U1:
1472*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_CONS_U1;
1473*2d543d20SAndroid Build Coastguard Worker 	case CIL_CONS_U2:
1474*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_CONS_U2;
1475*2d543d20SAndroid Build Coastguard Worker 	case CIL_CONS_U3:
1476*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_CONS_U3;
1477*2d543d20SAndroid Build Coastguard Worker 	case CIL_CONS_T1:
1478*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_CONS_T1;
1479*2d543d20SAndroid Build Coastguard Worker 	case CIL_CONS_T2:
1480*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_CONS_T2;
1481*2d543d20SAndroid Build Coastguard Worker 	case CIL_CONS_T3:
1482*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_CONS_T3;
1483*2d543d20SAndroid Build Coastguard Worker 	case CIL_CONS_R1:
1484*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_CONS_R1;
1485*2d543d20SAndroid Build Coastguard Worker 	case CIL_CONS_R2:
1486*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_CONS_R2;
1487*2d543d20SAndroid Build Coastguard Worker 	case CIL_CONS_R3:
1488*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_CONS_R3;
1489*2d543d20SAndroid Build Coastguard Worker 	case CIL_CONS_L1:
1490*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_CONS_L1;
1491*2d543d20SAndroid Build Coastguard Worker 	case CIL_CONS_L2:
1492*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_CONS_L2;
1493*2d543d20SAndroid Build Coastguard Worker 	case CIL_CONS_H1:
1494*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_CONS_H1;
1495*2d543d20SAndroid Build Coastguard Worker 	case CIL_CONS_H2:
1496*2d543d20SAndroid Build Coastguard Worker 		return CIL_KEY_CONS_H2;
1497*2d543d20SAndroid Build Coastguard Worker 
1498*2d543d20SAndroid Build Coastguard Worker 	default:
1499*2d543d20SAndroid Build Coastguard Worker 		break;
1500*2d543d20SAndroid Build Coastguard Worker 	}
1501*2d543d20SAndroid Build Coastguard Worker 
1502*2d543d20SAndroid Build Coastguard Worker 	return "<unknown>";
1503*2d543d20SAndroid Build Coastguard Worker }
1504*2d543d20SAndroid Build Coastguard Worker 
cil_userprefixes_to_string(struct cil_db * db,char ** out,size_t * size)1505*2d543d20SAndroid Build Coastguard Worker int cil_userprefixes_to_string(struct cil_db *db, char **out, size_t *size)
1506*2d543d20SAndroid Build Coastguard Worker {
1507*2d543d20SAndroid Build Coastguard Worker 	int rc = SEPOL_ERR;
1508*2d543d20SAndroid Build Coastguard Worker 	size_t str_len = 0;
1509*2d543d20SAndroid Build Coastguard Worker 	int buf_pos = 0;
1510*2d543d20SAndroid Build Coastguard Worker 	char *str_tmp = NULL;
1511*2d543d20SAndroid Build Coastguard Worker 	struct cil_list_item *curr;
1512*2d543d20SAndroid Build Coastguard Worker 	struct cil_userprefix *userprefix = NULL;
1513*2d543d20SAndroid Build Coastguard Worker 	struct cil_user *user = NULL;
1514*2d543d20SAndroid Build Coastguard Worker 
1515*2d543d20SAndroid Build Coastguard Worker 	*out = NULL;
1516*2d543d20SAndroid Build Coastguard Worker 
1517*2d543d20SAndroid Build Coastguard Worker 	if (db->userprefixes->head == NULL) {
1518*2d543d20SAndroid Build Coastguard Worker 		rc = SEPOL_OK;
1519*2d543d20SAndroid Build Coastguard Worker 		*size = 0;
1520*2d543d20SAndroid Build Coastguard Worker 		goto exit;
1521*2d543d20SAndroid Build Coastguard Worker 	}
1522*2d543d20SAndroid Build Coastguard Worker 
1523*2d543d20SAndroid Build Coastguard Worker 	cil_list_for_each(curr, db->userprefixes) {
1524*2d543d20SAndroid Build Coastguard Worker 		userprefix = curr->data;
1525*2d543d20SAndroid Build Coastguard Worker 		user = userprefix->user;
1526*2d543d20SAndroid Build Coastguard Worker 		str_len += strlen("user ") + strlen(user->datum.fqn) + strlen(" prefix ") + strlen(userprefix->prefix_str) + 2;
1527*2d543d20SAndroid Build Coastguard Worker 	}
1528*2d543d20SAndroid Build Coastguard Worker 
1529*2d543d20SAndroid Build Coastguard Worker 	*size = str_len * sizeof(char);
1530*2d543d20SAndroid Build Coastguard Worker 	str_len++;
1531*2d543d20SAndroid Build Coastguard Worker 	str_tmp = cil_malloc(str_len * sizeof(char));
1532*2d543d20SAndroid Build Coastguard Worker 	*out = str_tmp;
1533*2d543d20SAndroid Build Coastguard Worker 
1534*2d543d20SAndroid Build Coastguard Worker 	cil_list_for_each(curr, db->userprefixes) {
1535*2d543d20SAndroid Build Coastguard Worker 		userprefix = curr->data;
1536*2d543d20SAndroid Build Coastguard Worker 		user = userprefix->user;
1537*2d543d20SAndroid Build Coastguard Worker 
1538*2d543d20SAndroid Build Coastguard Worker 		buf_pos = snprintf(str_tmp, str_len, "user %s prefix %s;\n", user->datum.fqn,
1539*2d543d20SAndroid Build Coastguard Worker 									userprefix->prefix_str);
1540*2d543d20SAndroid Build Coastguard Worker 		if (buf_pos < 0) {
1541*2d543d20SAndroid Build Coastguard Worker 			free(str_tmp);
1542*2d543d20SAndroid Build Coastguard Worker 			*size = 0;
1543*2d543d20SAndroid Build Coastguard Worker 			*out = NULL;
1544*2d543d20SAndroid Build Coastguard Worker 			goto exit;
1545*2d543d20SAndroid Build Coastguard Worker 		}
1546*2d543d20SAndroid Build Coastguard Worker 		str_len -= buf_pos;
1547*2d543d20SAndroid Build Coastguard Worker 		str_tmp += buf_pos;
1548*2d543d20SAndroid Build Coastguard Worker 	}
1549*2d543d20SAndroid Build Coastguard Worker 
1550*2d543d20SAndroid Build Coastguard Worker 	rc = SEPOL_OK;
1551*2d543d20SAndroid Build Coastguard Worker exit:
1552*2d543d20SAndroid Build Coastguard Worker 	return rc;
1553*2d543d20SAndroid Build Coastguard Worker 
1554*2d543d20SAndroid Build Coastguard Worker }
1555*2d543d20SAndroid Build Coastguard Worker 
cil_cats_to_ebitmap(struct cil_cats * cats,struct ebitmap * cats_ebitmap)1556*2d543d20SAndroid Build Coastguard Worker static int cil_cats_to_ebitmap(struct cil_cats *cats, struct ebitmap* cats_ebitmap)
1557*2d543d20SAndroid Build Coastguard Worker {
1558*2d543d20SAndroid Build Coastguard Worker 	int rc = SEPOL_ERR;
1559*2d543d20SAndroid Build Coastguard Worker 	struct cil_list_item *i;
1560*2d543d20SAndroid Build Coastguard Worker 	struct cil_list_item *j;
1561*2d543d20SAndroid Build Coastguard Worker 	struct cil_cat* cat;
1562*2d543d20SAndroid Build Coastguard Worker 	struct cil_catset *cs;
1563*2d543d20SAndroid Build Coastguard Worker 	struct cil_tree_node *node;
1564*2d543d20SAndroid Build Coastguard Worker 
1565*2d543d20SAndroid Build Coastguard Worker 	if (cats == NULL) {
1566*2d543d20SAndroid Build Coastguard Worker 		rc = SEPOL_OK;
1567*2d543d20SAndroid Build Coastguard Worker 		goto exit;
1568*2d543d20SAndroid Build Coastguard Worker 	}
1569*2d543d20SAndroid Build Coastguard Worker 
1570*2d543d20SAndroid Build Coastguard Worker 	cil_list_for_each(i, cats->datum_expr) {
1571*2d543d20SAndroid Build Coastguard Worker 		node = NODE(i->data);
1572*2d543d20SAndroid Build Coastguard Worker 		if (node->flavor == CIL_CATSET) {
1573*2d543d20SAndroid Build Coastguard Worker 			cs = (struct cil_catset*)i->data;
1574*2d543d20SAndroid Build Coastguard Worker 			cil_list_for_each(j, cs->cats->datum_expr) {
1575*2d543d20SAndroid Build Coastguard Worker 				cat = (struct cil_cat*)j->data;
1576*2d543d20SAndroid Build Coastguard Worker 				rc = ebitmap_set_bit(cats_ebitmap, cat->value, 1);
1577*2d543d20SAndroid Build Coastguard Worker 				if (rc != SEPOL_OK) {
1578*2d543d20SAndroid Build Coastguard Worker 					goto exit;
1579*2d543d20SAndroid Build Coastguard Worker 				}
1580*2d543d20SAndroid Build Coastguard Worker 			}
1581*2d543d20SAndroid Build Coastguard Worker 		} else {
1582*2d543d20SAndroid Build Coastguard Worker 			cat = (struct cil_cat*)i->data;
1583*2d543d20SAndroid Build Coastguard Worker 			rc = ebitmap_set_bit(cats_ebitmap, cat->value, 1);
1584*2d543d20SAndroid Build Coastguard Worker 			if (rc != SEPOL_OK) {
1585*2d543d20SAndroid Build Coastguard Worker 				goto exit;
1586*2d543d20SAndroid Build Coastguard Worker 			}
1587*2d543d20SAndroid Build Coastguard Worker 		}
1588*2d543d20SAndroid Build Coastguard Worker 	}
1589*2d543d20SAndroid Build Coastguard Worker 
1590*2d543d20SAndroid Build Coastguard Worker 	return SEPOL_OK;
1591*2d543d20SAndroid Build Coastguard Worker 
1592*2d543d20SAndroid Build Coastguard Worker exit:
1593*2d543d20SAndroid Build Coastguard Worker 	return rc;
1594*2d543d20SAndroid Build Coastguard Worker }
1595*2d543d20SAndroid Build Coastguard Worker 
cil_level_equals(struct cil_level * low,struct cil_level * high)1596*2d543d20SAndroid Build Coastguard Worker static int cil_level_equals(struct cil_level *low, struct cil_level *high)
1597*2d543d20SAndroid Build Coastguard Worker {
1598*2d543d20SAndroid Build Coastguard Worker 	int rc;
1599*2d543d20SAndroid Build Coastguard Worker 	struct ebitmap elow;
1600*2d543d20SAndroid Build Coastguard Worker 	struct ebitmap ehigh;
1601*2d543d20SAndroid Build Coastguard Worker 
1602*2d543d20SAndroid Build Coastguard Worker 	if (strcmp(low->sens->datum.fqn, high->sens->datum.fqn)) {
1603*2d543d20SAndroid Build Coastguard Worker 		rc = 0;
1604*2d543d20SAndroid Build Coastguard Worker 		goto exit;
1605*2d543d20SAndroid Build Coastguard Worker 	}
1606*2d543d20SAndroid Build Coastguard Worker 
1607*2d543d20SAndroid Build Coastguard Worker 	ebitmap_init(&elow);
1608*2d543d20SAndroid Build Coastguard Worker 	ebitmap_init(&ehigh);
1609*2d543d20SAndroid Build Coastguard Worker 
1610*2d543d20SAndroid Build Coastguard Worker 	rc = cil_cats_to_ebitmap(low->cats, &elow);
1611*2d543d20SAndroid Build Coastguard Worker 	if (rc != SEPOL_OK) {
1612*2d543d20SAndroid Build Coastguard Worker 		goto exit;
1613*2d543d20SAndroid Build Coastguard Worker 	}
1614*2d543d20SAndroid Build Coastguard Worker 
1615*2d543d20SAndroid Build Coastguard Worker 	rc = cil_cats_to_ebitmap(high->cats, &ehigh);
1616*2d543d20SAndroid Build Coastguard Worker 	if (rc != SEPOL_OK) {
1617*2d543d20SAndroid Build Coastguard Worker 		goto exit;
1618*2d543d20SAndroid Build Coastguard Worker 	}
1619*2d543d20SAndroid Build Coastguard Worker 
1620*2d543d20SAndroid Build Coastguard Worker 	rc = ebitmap_cmp(&elow, &ehigh);
1621*2d543d20SAndroid Build Coastguard Worker 	ebitmap_destroy(&elow);
1622*2d543d20SAndroid Build Coastguard Worker 	ebitmap_destroy(&ehigh);
1623*2d543d20SAndroid Build Coastguard Worker 
1624*2d543d20SAndroid Build Coastguard Worker exit:
1625*2d543d20SAndroid Build Coastguard Worker 	return rc;
1626*2d543d20SAndroid Build Coastguard Worker }
1627*2d543d20SAndroid Build Coastguard Worker 
__cil_level_strlen(struct cil_level * lvl)1628*2d543d20SAndroid Build Coastguard Worker static int __cil_level_strlen(struct cil_level *lvl)
1629*2d543d20SAndroid Build Coastguard Worker {
1630*2d543d20SAndroid Build Coastguard Worker 	struct cil_list_item *item;
1631*2d543d20SAndroid Build Coastguard Worker 	struct cil_cats *cats = lvl->cats;
1632*2d543d20SAndroid Build Coastguard Worker 	int str_len = 0;
1633*2d543d20SAndroid Build Coastguard Worker 	char *str1 = NULL;
1634*2d543d20SAndroid Build Coastguard Worker 	char *str2 = NULL;
1635*2d543d20SAndroid Build Coastguard Worker 	int first = -1;
1636*2d543d20SAndroid Build Coastguard Worker 	int last = -1;
1637*2d543d20SAndroid Build Coastguard Worker 
1638*2d543d20SAndroid Build Coastguard Worker 	str_len += strlen(lvl->sens->datum.fqn);
1639*2d543d20SAndroid Build Coastguard Worker 
1640*2d543d20SAndroid Build Coastguard Worker 	if (cats && cats->datum_expr != NULL) {
1641*2d543d20SAndroid Build Coastguard Worker 		str_len++; /* initial ":" */
1642*2d543d20SAndroid Build Coastguard Worker 		cil_list_for_each(item, cats->datum_expr) {
1643*2d543d20SAndroid Build Coastguard Worker 			struct cil_cat *cat = item->data;
1644*2d543d20SAndroid Build Coastguard Worker 			if (first == -1) {
1645*2d543d20SAndroid Build Coastguard Worker 				str1 = cat->datum.fqn;
1646*2d543d20SAndroid Build Coastguard Worker 				first = cat->value;
1647*2d543d20SAndroid Build Coastguard Worker 				last = first;
1648*2d543d20SAndroid Build Coastguard Worker 			} else if (cat->value == last + 1) {
1649*2d543d20SAndroid Build Coastguard Worker 				last++;
1650*2d543d20SAndroid Build Coastguard Worker 				str2 = cat->datum.fqn;
1651*2d543d20SAndroid Build Coastguard Worker 			} else {
1652*2d543d20SAndroid Build Coastguard Worker 				if (first == last) {
1653*2d543d20SAndroid Build Coastguard Worker 					str_len += strlen(str1) + strlen(cat->datum.fqn) + 1;
1654*2d543d20SAndroid Build Coastguard Worker 				} else if (last == first + 1) {
1655*2d543d20SAndroid Build Coastguard Worker 					str_len += strlen(str1) + strlen(str2) + strlen(cat->datum.fqn) + 2;
1656*2d543d20SAndroid Build Coastguard Worker 				} else {
1657*2d543d20SAndroid Build Coastguard Worker 					str_len += strlen(str1) + strlen(str2) + strlen(cat->datum.fqn) + 2;
1658*2d543d20SAndroid Build Coastguard Worker 				}
1659*2d543d20SAndroid Build Coastguard Worker 				first = -1;
1660*2d543d20SAndroid Build Coastguard Worker 				last = -1;
1661*2d543d20SAndroid Build Coastguard Worker 				if (item->next != NULL) {
1662*2d543d20SAndroid Build Coastguard Worker 					str_len++; /* space for "," after */
1663*2d543d20SAndroid Build Coastguard Worker 				}
1664*2d543d20SAndroid Build Coastguard Worker 			}
1665*2d543d20SAndroid Build Coastguard Worker 		}
1666*2d543d20SAndroid Build Coastguard Worker 		if (first != -1) {
1667*2d543d20SAndroid Build Coastguard Worker 			if (first == last) {
1668*2d543d20SAndroid Build Coastguard Worker 				str_len += strlen(str1);
1669*2d543d20SAndroid Build Coastguard Worker 			} else if (last == first + 1) {
1670*2d543d20SAndroid Build Coastguard Worker 				str_len += strlen(str1) + strlen(str2) + 1;
1671*2d543d20SAndroid Build Coastguard Worker 			} else {
1672*2d543d20SAndroid Build Coastguard Worker 				str_len += strlen(str1) + strlen(str2) + 1;
1673*2d543d20SAndroid Build Coastguard Worker 			}
1674*2d543d20SAndroid Build Coastguard Worker 		}
1675*2d543d20SAndroid Build Coastguard Worker 	}
1676*2d543d20SAndroid Build Coastguard Worker 
1677*2d543d20SAndroid Build Coastguard Worker 	return str_len;
1678*2d543d20SAndroid Build Coastguard Worker }
1679*2d543d20SAndroid Build Coastguard Worker 
__cil_level_to_string(struct cil_level * lvl,char * out)1680*2d543d20SAndroid Build Coastguard Worker static int __cil_level_to_string(struct cil_level *lvl, char *out)
1681*2d543d20SAndroid Build Coastguard Worker {
1682*2d543d20SAndroid Build Coastguard Worker 	struct cil_list_item *item;
1683*2d543d20SAndroid Build Coastguard Worker 	struct cil_cats *cats = lvl->cats;
1684*2d543d20SAndroid Build Coastguard Worker 	int buf_pos = 0;
1685*2d543d20SAndroid Build Coastguard Worker 	char *str_tmp = out;
1686*2d543d20SAndroid Build Coastguard Worker 	char *str1 = NULL;
1687*2d543d20SAndroid Build Coastguard Worker 	char *str2 = NULL;
1688*2d543d20SAndroid Build Coastguard Worker 	int first = -1;
1689*2d543d20SAndroid Build Coastguard Worker 	int last = -1;
1690*2d543d20SAndroid Build Coastguard Worker 
1691*2d543d20SAndroid Build Coastguard Worker 	buf_pos = sprintf(str_tmp, "%s", lvl->sens->datum.fqn);
1692*2d543d20SAndroid Build Coastguard Worker 	str_tmp += buf_pos;
1693*2d543d20SAndroid Build Coastguard Worker 
1694*2d543d20SAndroid Build Coastguard Worker 	if (cats && cats->datum_expr != NULL) {
1695*2d543d20SAndroid Build Coastguard Worker 		buf_pos = sprintf(str_tmp, ":");
1696*2d543d20SAndroid Build Coastguard Worker 		str_tmp += buf_pos;
1697*2d543d20SAndroid Build Coastguard Worker 
1698*2d543d20SAndroid Build Coastguard Worker 		cil_list_for_each(item, cats->datum_expr) {
1699*2d543d20SAndroid Build Coastguard Worker 			struct cil_cat *cat = item->data;
1700*2d543d20SAndroid Build Coastguard Worker 			if (first == -1) {
1701*2d543d20SAndroid Build Coastguard Worker 				str1 = cat->datum.fqn;
1702*2d543d20SAndroid Build Coastguard Worker 				first = cat->value;
1703*2d543d20SAndroid Build Coastguard Worker 				last = first;
1704*2d543d20SAndroid Build Coastguard Worker 			} else if (cat->value == last + 1) {
1705*2d543d20SAndroid Build Coastguard Worker 				last++;
1706*2d543d20SAndroid Build Coastguard Worker 				str2 = cat->datum.fqn;
1707*2d543d20SAndroid Build Coastguard Worker 			} else {
1708*2d543d20SAndroid Build Coastguard Worker 				if (first == last) {
1709*2d543d20SAndroid Build Coastguard Worker 					buf_pos = sprintf(str_tmp, "%s,%s", str1, cat->datum.fqn);
1710*2d543d20SAndroid Build Coastguard Worker 					str_tmp += buf_pos;
1711*2d543d20SAndroid Build Coastguard Worker 				} else if (last == first + 1) {
1712*2d543d20SAndroid Build Coastguard Worker 					buf_pos = sprintf(str_tmp, "%s,%s,%s", str1, str2, cat->datum.fqn);
1713*2d543d20SAndroid Build Coastguard Worker 					str_tmp += buf_pos;
1714*2d543d20SAndroid Build Coastguard Worker 				} else {
1715*2d543d20SAndroid Build Coastguard Worker 					buf_pos = sprintf(str_tmp, "%s.%s,%s",str1, str2, cat->datum.fqn);
1716*2d543d20SAndroid Build Coastguard Worker 					str_tmp += buf_pos;
1717*2d543d20SAndroid Build Coastguard Worker 				}
1718*2d543d20SAndroid Build Coastguard Worker 				first = -1;
1719*2d543d20SAndroid Build Coastguard Worker 				last = -1;
1720*2d543d20SAndroid Build Coastguard Worker 				if (item->next != NULL) {
1721*2d543d20SAndroid Build Coastguard Worker 					buf_pos = sprintf(str_tmp, ",");
1722*2d543d20SAndroid Build Coastguard Worker 					str_tmp += buf_pos;
1723*2d543d20SAndroid Build Coastguard Worker 				}
1724*2d543d20SAndroid Build Coastguard Worker 			}
1725*2d543d20SAndroid Build Coastguard Worker 		}
1726*2d543d20SAndroid Build Coastguard Worker 		if (first != -1) {
1727*2d543d20SAndroid Build Coastguard Worker 			if (first == last) {
1728*2d543d20SAndroid Build Coastguard Worker 				buf_pos = sprintf(str_tmp, "%s", str1);
1729*2d543d20SAndroid Build Coastguard Worker 				str_tmp += buf_pos;
1730*2d543d20SAndroid Build Coastguard Worker 			} else if (last == first + 1) {
1731*2d543d20SAndroid Build Coastguard Worker 				buf_pos = sprintf(str_tmp, "%s,%s", str1, str2);
1732*2d543d20SAndroid Build Coastguard Worker 				str_tmp += buf_pos;
1733*2d543d20SAndroid Build Coastguard Worker 			} else {
1734*2d543d20SAndroid Build Coastguard Worker 				buf_pos = sprintf(str_tmp, "%s.%s",str1, str2);
1735*2d543d20SAndroid Build Coastguard Worker 				str_tmp += buf_pos;
1736*2d543d20SAndroid Build Coastguard Worker 			}
1737*2d543d20SAndroid Build Coastguard Worker 		}
1738*2d543d20SAndroid Build Coastguard Worker 	}
1739*2d543d20SAndroid Build Coastguard Worker 
1740*2d543d20SAndroid Build Coastguard Worker 	return str_tmp - out;
1741*2d543d20SAndroid Build Coastguard Worker }
1742*2d543d20SAndroid Build Coastguard Worker 
cil_selinuxusers_to_string(struct cil_db * db,char ** out,size_t * size)1743*2d543d20SAndroid Build Coastguard Worker int cil_selinuxusers_to_string(struct cil_db *db, char **out, size_t *size)
1744*2d543d20SAndroid Build Coastguard Worker {
1745*2d543d20SAndroid Build Coastguard Worker 	size_t str_len = 0;
1746*2d543d20SAndroid Build Coastguard Worker 	int buf_pos = 0;
1747*2d543d20SAndroid Build Coastguard Worker 	char *str_tmp = NULL;
1748*2d543d20SAndroid Build Coastguard Worker 	struct cil_list_item *curr;
1749*2d543d20SAndroid Build Coastguard Worker 
1750*2d543d20SAndroid Build Coastguard Worker 	if (db->selinuxusers->head == NULL) {
1751*2d543d20SAndroid Build Coastguard Worker 		*size = 0;
1752*2d543d20SAndroid Build Coastguard Worker 		*out = NULL;
1753*2d543d20SAndroid Build Coastguard Worker 		return SEPOL_OK;
1754*2d543d20SAndroid Build Coastguard Worker 	}
1755*2d543d20SAndroid Build Coastguard Worker 
1756*2d543d20SAndroid Build Coastguard Worker 	cil_list_for_each(curr, db->selinuxusers) {
1757*2d543d20SAndroid Build Coastguard Worker 		struct cil_selinuxuser *selinuxuser = curr->data;
1758*2d543d20SAndroid Build Coastguard Worker 		struct cil_user *user = selinuxuser->user;
1759*2d543d20SAndroid Build Coastguard Worker 
1760*2d543d20SAndroid Build Coastguard Worker 		str_len += strlen(selinuxuser->name_str) + strlen(user->datum.fqn) + 1;
1761*2d543d20SAndroid Build Coastguard Worker 
1762*2d543d20SAndroid Build Coastguard Worker 		if (db->mls == CIL_TRUE) {
1763*2d543d20SAndroid Build Coastguard Worker 			struct cil_levelrange *range = selinuxuser->range;
1764*2d543d20SAndroid Build Coastguard Worker 			str_len += __cil_level_strlen(range->low) + __cil_level_strlen(range->high) + 2;
1765*2d543d20SAndroid Build Coastguard Worker 		}
1766*2d543d20SAndroid Build Coastguard Worker 
1767*2d543d20SAndroid Build Coastguard Worker 		str_len++;
1768*2d543d20SAndroid Build Coastguard Worker 	}
1769*2d543d20SAndroid Build Coastguard Worker 
1770*2d543d20SAndroid Build Coastguard Worker 	*size = str_len * sizeof(char);
1771*2d543d20SAndroid Build Coastguard Worker 	str_tmp = cil_malloc(*size+1);
1772*2d543d20SAndroid Build Coastguard Worker 	*out = str_tmp;
1773*2d543d20SAndroid Build Coastguard Worker 
1774*2d543d20SAndroid Build Coastguard Worker 	for(curr = db->selinuxusers->head; curr != NULL; curr = curr->next) {
1775*2d543d20SAndroid Build Coastguard Worker 		struct cil_selinuxuser *selinuxuser = curr->data;
1776*2d543d20SAndroid Build Coastguard Worker 		struct cil_user *user = selinuxuser->user;
1777*2d543d20SAndroid Build Coastguard Worker 
1778*2d543d20SAndroid Build Coastguard Worker 		buf_pos = sprintf(str_tmp, "%s:%s", selinuxuser->name_str, user->datum.fqn);
1779*2d543d20SAndroid Build Coastguard Worker 		str_tmp += buf_pos;
1780*2d543d20SAndroid Build Coastguard Worker 
1781*2d543d20SAndroid Build Coastguard Worker 		if (db->mls == CIL_TRUE) {
1782*2d543d20SAndroid Build Coastguard Worker 			struct cil_levelrange *range = selinuxuser->range;
1783*2d543d20SAndroid Build Coastguard Worker 			buf_pos = sprintf(str_tmp, ":");
1784*2d543d20SAndroid Build Coastguard Worker 			str_tmp += buf_pos;
1785*2d543d20SAndroid Build Coastguard Worker 			buf_pos = __cil_level_to_string(range->low, str_tmp);
1786*2d543d20SAndroid Build Coastguard Worker 			str_tmp += buf_pos;
1787*2d543d20SAndroid Build Coastguard Worker 			buf_pos = sprintf(str_tmp, "-");
1788*2d543d20SAndroid Build Coastguard Worker 			str_tmp += buf_pos;
1789*2d543d20SAndroid Build Coastguard Worker 			buf_pos = __cil_level_to_string(range->high, str_tmp);
1790*2d543d20SAndroid Build Coastguard Worker 			str_tmp += buf_pos;
1791*2d543d20SAndroid Build Coastguard Worker 		}
1792*2d543d20SAndroid Build Coastguard Worker 
1793*2d543d20SAndroid Build Coastguard Worker 		buf_pos = sprintf(str_tmp, "\n");
1794*2d543d20SAndroid Build Coastguard Worker 		str_tmp += buf_pos;
1795*2d543d20SAndroid Build Coastguard Worker 	}
1796*2d543d20SAndroid Build Coastguard Worker 
1797*2d543d20SAndroid Build Coastguard Worker 	return SEPOL_OK;
1798*2d543d20SAndroid Build Coastguard Worker }
1799*2d543d20SAndroid Build Coastguard Worker 
cil_filecons_to_string(struct cil_db * db,char ** out,size_t * size)1800*2d543d20SAndroid Build Coastguard Worker int cil_filecons_to_string(struct cil_db *db, char **out, size_t *size)
1801*2d543d20SAndroid Build Coastguard Worker {
1802*2d543d20SAndroid Build Coastguard Worker 	uint32_t i = 0;
1803*2d543d20SAndroid Build Coastguard Worker 	int buf_pos = 0;
1804*2d543d20SAndroid Build Coastguard Worker 	size_t str_len = 0;
1805*2d543d20SAndroid Build Coastguard Worker 	char *str_tmp = NULL;
1806*2d543d20SAndroid Build Coastguard Worker 	struct cil_sort *filecons = db->filecon;
1807*2d543d20SAndroid Build Coastguard Worker 
1808*2d543d20SAndroid Build Coastguard Worker 	for (i = 0; i < filecons->count; i++) {
1809*2d543d20SAndroid Build Coastguard Worker 		struct cil_filecon *filecon = filecons->array[i];
1810*2d543d20SAndroid Build Coastguard Worker 		struct cil_context *ctx = filecon->context;
1811*2d543d20SAndroid Build Coastguard Worker 		char *path_str = filecon->path ? DATUM(filecon->path)->fqn : filecon->path_str;
1812*2d543d20SAndroid Build Coastguard Worker 		str_len += strlen(path_str);
1813*2d543d20SAndroid Build Coastguard Worker 
1814*2d543d20SAndroid Build Coastguard Worker 		if (filecon->type != CIL_FILECON_ANY) {
1815*2d543d20SAndroid Build Coastguard Worker 			/* If a type is specified,
1816*2d543d20SAndroid Build Coastguard Worker 			   +2 for type string, +1 for tab */
1817*2d543d20SAndroid Build Coastguard Worker 			str_len += 3;
1818*2d543d20SAndroid Build Coastguard Worker 		}
1819*2d543d20SAndroid Build Coastguard Worker 
1820*2d543d20SAndroid Build Coastguard Worker 		if (ctx != NULL) {
1821*2d543d20SAndroid Build Coastguard Worker 			struct cil_user *user = ctx->user;
1822*2d543d20SAndroid Build Coastguard Worker 			struct cil_role *role = ctx->role;
1823*2d543d20SAndroid Build Coastguard Worker 			struct cil_type *type = ctx->type;
1824*2d543d20SAndroid Build Coastguard Worker 
1825*2d543d20SAndroid Build Coastguard Worker 			str_len += (strlen(user->datum.fqn) + strlen(role->datum.fqn) + strlen(type->datum.fqn) + 3);
1826*2d543d20SAndroid Build Coastguard Worker 
1827*2d543d20SAndroid Build Coastguard Worker 			if (db->mls == CIL_TRUE) {
1828*2d543d20SAndroid Build Coastguard Worker 				struct cil_levelrange *range = ctx->range;
1829*2d543d20SAndroid Build Coastguard Worker 				if (cil_level_equals(range->low, range->high)) {
1830*2d543d20SAndroid Build Coastguard Worker 					str_len += __cil_level_strlen(range->low) + 1;
1831*2d543d20SAndroid Build Coastguard Worker 				} else {
1832*2d543d20SAndroid Build Coastguard Worker 					str_len += __cil_level_strlen(range->low) + __cil_level_strlen(range->high) + 2;
1833*2d543d20SAndroid Build Coastguard Worker 				}
1834*2d543d20SAndroid Build Coastguard Worker 			}
1835*2d543d20SAndroid Build Coastguard Worker 		} else {
1836*2d543d20SAndroid Build Coastguard Worker 			str_len += strlen("\t<<none>>");
1837*2d543d20SAndroid Build Coastguard Worker 		}
1838*2d543d20SAndroid Build Coastguard Worker 
1839*2d543d20SAndroid Build Coastguard Worker 		str_len++;
1840*2d543d20SAndroid Build Coastguard Worker 	}
1841*2d543d20SAndroid Build Coastguard Worker 
1842*2d543d20SAndroid Build Coastguard Worker 	*size = str_len * sizeof(char);
1843*2d543d20SAndroid Build Coastguard Worker 	str_tmp = cil_malloc(*size+1);
1844*2d543d20SAndroid Build Coastguard Worker 	*out = str_tmp;
1845*2d543d20SAndroid Build Coastguard Worker 
1846*2d543d20SAndroid Build Coastguard Worker 	for (i = 0; i < filecons->count; i++) {
1847*2d543d20SAndroid Build Coastguard Worker 		struct cil_filecon *filecon = filecons->array[i];
1848*2d543d20SAndroid Build Coastguard Worker 		struct cil_context *ctx = filecon->context;
1849*2d543d20SAndroid Build Coastguard Worker 		const char *str_type = NULL;
1850*2d543d20SAndroid Build Coastguard Worker 		char *path_str = filecon->path ? DATUM(filecon->path)->fqn : filecon->path_str;
1851*2d543d20SAndroid Build Coastguard Worker 		buf_pos = sprintf(str_tmp, "%s", path_str);
1852*2d543d20SAndroid Build Coastguard Worker 		str_tmp += buf_pos;
1853*2d543d20SAndroid Build Coastguard Worker 
1854*2d543d20SAndroid Build Coastguard Worker 		switch(filecon->type) {
1855*2d543d20SAndroid Build Coastguard Worker 		case CIL_FILECON_ANY:
1856*2d543d20SAndroid Build Coastguard Worker 			str_type = "";
1857*2d543d20SAndroid Build Coastguard Worker 			break;
1858*2d543d20SAndroid Build Coastguard Worker 		case CIL_FILECON_FILE:
1859*2d543d20SAndroid Build Coastguard Worker 			str_type = "\t--";
1860*2d543d20SAndroid Build Coastguard Worker 			break;
1861*2d543d20SAndroid Build Coastguard Worker 		case CIL_FILECON_DIR:
1862*2d543d20SAndroid Build Coastguard Worker 			str_type = "\t-d";
1863*2d543d20SAndroid Build Coastguard Worker 			break;
1864*2d543d20SAndroid Build Coastguard Worker 		case CIL_FILECON_CHAR:
1865*2d543d20SAndroid Build Coastguard Worker 			str_type = "\t-c";
1866*2d543d20SAndroid Build Coastguard Worker 			break;
1867*2d543d20SAndroid Build Coastguard Worker 		case CIL_FILECON_BLOCK:
1868*2d543d20SAndroid Build Coastguard Worker 			str_type = "\t-b";
1869*2d543d20SAndroid Build Coastguard Worker 			break;
1870*2d543d20SAndroid Build Coastguard Worker 		case CIL_FILECON_SOCKET:
1871*2d543d20SAndroid Build Coastguard Worker 			str_type = "\t-s";
1872*2d543d20SAndroid Build Coastguard Worker 			break;
1873*2d543d20SAndroid Build Coastguard Worker 		case CIL_FILECON_PIPE:
1874*2d543d20SAndroid Build Coastguard Worker 			str_type = "\t-p";
1875*2d543d20SAndroid Build Coastguard Worker 			break;
1876*2d543d20SAndroid Build Coastguard Worker 		case CIL_FILECON_SYMLINK:
1877*2d543d20SAndroid Build Coastguard Worker 			str_type = "\t-l";
1878*2d543d20SAndroid Build Coastguard Worker 			break;
1879*2d543d20SAndroid Build Coastguard Worker 		default:
1880*2d543d20SAndroid Build Coastguard Worker 			str_type = "";
1881*2d543d20SAndroid Build Coastguard Worker 			break;
1882*2d543d20SAndroid Build Coastguard Worker 		}
1883*2d543d20SAndroid Build Coastguard Worker 		buf_pos = sprintf(str_tmp, "%s", str_type);
1884*2d543d20SAndroid Build Coastguard Worker 		str_tmp += buf_pos;
1885*2d543d20SAndroid Build Coastguard Worker 
1886*2d543d20SAndroid Build Coastguard Worker 		if (ctx != NULL) {
1887*2d543d20SAndroid Build Coastguard Worker 			struct cil_user *user = ctx->user;
1888*2d543d20SAndroid Build Coastguard Worker 			struct cil_role *role = ctx->role;
1889*2d543d20SAndroid Build Coastguard Worker 			struct cil_type *type = ctx->type;
1890*2d543d20SAndroid Build Coastguard Worker 
1891*2d543d20SAndroid Build Coastguard Worker 			buf_pos = sprintf(str_tmp, "\t%s:%s:%s", user->datum.fqn, role->datum.fqn,
1892*2d543d20SAndroid Build Coastguard Worker 							  type->datum.fqn);
1893*2d543d20SAndroid Build Coastguard Worker 			str_tmp += buf_pos;
1894*2d543d20SAndroid Build Coastguard Worker 
1895*2d543d20SAndroid Build Coastguard Worker 			if (db->mls == CIL_TRUE) {
1896*2d543d20SAndroid Build Coastguard Worker 				struct cil_levelrange *range = ctx->range;
1897*2d543d20SAndroid Build Coastguard Worker 				buf_pos = sprintf(str_tmp, ":");
1898*2d543d20SAndroid Build Coastguard Worker 				str_tmp += buf_pos;
1899*2d543d20SAndroid Build Coastguard Worker 				buf_pos = __cil_level_to_string(range->low, str_tmp);
1900*2d543d20SAndroid Build Coastguard Worker 				str_tmp += buf_pos;
1901*2d543d20SAndroid Build Coastguard Worker 
1902*2d543d20SAndroid Build Coastguard Worker 				if (!cil_level_equals(range->low, range->high)) {
1903*2d543d20SAndroid Build Coastguard Worker 					buf_pos = sprintf(str_tmp, "-");
1904*2d543d20SAndroid Build Coastguard Worker 					str_tmp += buf_pos;
1905*2d543d20SAndroid Build Coastguard Worker 					buf_pos = __cil_level_to_string(range->high, str_tmp);
1906*2d543d20SAndroid Build Coastguard Worker 					str_tmp += buf_pos;
1907*2d543d20SAndroid Build Coastguard Worker 				}
1908*2d543d20SAndroid Build Coastguard Worker 			}
1909*2d543d20SAndroid Build Coastguard Worker 		} else {
1910*2d543d20SAndroid Build Coastguard Worker 			buf_pos = sprintf(str_tmp, "\t<<none>>");
1911*2d543d20SAndroid Build Coastguard Worker 			str_tmp += buf_pos;
1912*2d543d20SAndroid Build Coastguard Worker 		}
1913*2d543d20SAndroid Build Coastguard Worker 
1914*2d543d20SAndroid Build Coastguard Worker 		buf_pos = sprintf(str_tmp, "\n");
1915*2d543d20SAndroid Build Coastguard Worker 		str_tmp += buf_pos;
1916*2d543d20SAndroid Build Coastguard Worker 	}
1917*2d543d20SAndroid Build Coastguard Worker 
1918*2d543d20SAndroid Build Coastguard Worker 	return SEPOL_OK;
1919*2d543d20SAndroid Build Coastguard Worker }
1920*2d543d20SAndroid Build Coastguard Worker 
cil_set_disable_dontaudit(struct cil_db * db,int disable_dontaudit)1921*2d543d20SAndroid Build Coastguard Worker void cil_set_disable_dontaudit(struct cil_db *db, int disable_dontaudit)
1922*2d543d20SAndroid Build Coastguard Worker {
1923*2d543d20SAndroid Build Coastguard Worker 	db->disable_dontaudit = disable_dontaudit;
1924*2d543d20SAndroid Build Coastguard Worker }
1925*2d543d20SAndroid Build Coastguard Worker 
cil_set_disable_neverallow(struct cil_db * db,int disable_neverallow)1926*2d543d20SAndroid Build Coastguard Worker void cil_set_disable_neverallow(struct cil_db *db, int disable_neverallow)
1927*2d543d20SAndroid Build Coastguard Worker {
1928*2d543d20SAndroid Build Coastguard Worker 	db->disable_neverallow = disable_neverallow;
1929*2d543d20SAndroid Build Coastguard Worker }
1930*2d543d20SAndroid Build Coastguard Worker 
cil_set_attrs_expand_generated(struct cil_db * db,int attrs_expand_generated)1931*2d543d20SAndroid Build Coastguard Worker void cil_set_attrs_expand_generated(struct cil_db *db, int attrs_expand_generated)
1932*2d543d20SAndroid Build Coastguard Worker {
1933*2d543d20SAndroid Build Coastguard Worker 	db->attrs_expand_generated = attrs_expand_generated;
1934*2d543d20SAndroid Build Coastguard Worker }
1935*2d543d20SAndroid Build Coastguard Worker 
cil_set_attrs_expand_size(struct cil_db * db,unsigned attrs_expand_size)1936*2d543d20SAndroid Build Coastguard Worker void cil_set_attrs_expand_size(struct cil_db *db, unsigned attrs_expand_size)
1937*2d543d20SAndroid Build Coastguard Worker {
1938*2d543d20SAndroid Build Coastguard Worker 	db->attrs_expand_size = attrs_expand_size;
1939*2d543d20SAndroid Build Coastguard Worker }
1940*2d543d20SAndroid Build Coastguard Worker 
cil_set_preserve_tunables(struct cil_db * db,int preserve_tunables)1941*2d543d20SAndroid Build Coastguard Worker void cil_set_preserve_tunables(struct cil_db *db, int preserve_tunables)
1942*2d543d20SAndroid Build Coastguard Worker {
1943*2d543d20SAndroid Build Coastguard Worker 	db->preserve_tunables = preserve_tunables;
1944*2d543d20SAndroid Build Coastguard Worker }
1945*2d543d20SAndroid Build Coastguard Worker 
cil_set_handle_unknown(struct cil_db * db,int handle_unknown)1946*2d543d20SAndroid Build Coastguard Worker int cil_set_handle_unknown(struct cil_db *db, int handle_unknown)
1947*2d543d20SAndroid Build Coastguard Worker {
1948*2d543d20SAndroid Build Coastguard Worker 	int rc = 0;
1949*2d543d20SAndroid Build Coastguard Worker 
1950*2d543d20SAndroid Build Coastguard Worker 	switch (handle_unknown) {
1951*2d543d20SAndroid Build Coastguard Worker 		case SEPOL_DENY_UNKNOWN:
1952*2d543d20SAndroid Build Coastguard Worker 		case SEPOL_REJECT_UNKNOWN:
1953*2d543d20SAndroid Build Coastguard Worker 		case SEPOL_ALLOW_UNKNOWN:
1954*2d543d20SAndroid Build Coastguard Worker 			db->handle_unknown = handle_unknown;
1955*2d543d20SAndroid Build Coastguard Worker 			break;
1956*2d543d20SAndroid Build Coastguard Worker 		default:
1957*2d543d20SAndroid Build Coastguard Worker 			cil_log(CIL_ERR, "Unknown value for handle-unknown: %i\n", handle_unknown);
1958*2d543d20SAndroid Build Coastguard Worker 			rc = -1;
1959*2d543d20SAndroid Build Coastguard Worker 	}
1960*2d543d20SAndroid Build Coastguard Worker 
1961*2d543d20SAndroid Build Coastguard Worker 	return rc;
1962*2d543d20SAndroid Build Coastguard Worker }
1963*2d543d20SAndroid Build Coastguard Worker 
cil_set_mls(struct cil_db * db,int mls)1964*2d543d20SAndroid Build Coastguard Worker void cil_set_mls(struct cil_db *db, int mls)
1965*2d543d20SAndroid Build Coastguard Worker {
1966*2d543d20SAndroid Build Coastguard Worker 	db->mls = mls;
1967*2d543d20SAndroid Build Coastguard Worker }
1968*2d543d20SAndroid Build Coastguard Worker 
cil_set_multiple_decls(struct cil_db * db,int multiple_decls)1969*2d543d20SAndroid Build Coastguard Worker void cil_set_multiple_decls(struct cil_db *db, int multiple_decls)
1970*2d543d20SAndroid Build Coastguard Worker {
1971*2d543d20SAndroid Build Coastguard Worker 	db->multiple_decls = multiple_decls;
1972*2d543d20SAndroid Build Coastguard Worker }
1973*2d543d20SAndroid Build Coastguard Worker 
cil_set_qualified_names(struct cil_db * db,int qualified_names)1974*2d543d20SAndroid Build Coastguard Worker void cil_set_qualified_names(struct cil_db *db, int qualified_names)
1975*2d543d20SAndroid Build Coastguard Worker {
1976*2d543d20SAndroid Build Coastguard Worker 	db->qualified_names = qualified_names;
1977*2d543d20SAndroid Build Coastguard Worker }
1978*2d543d20SAndroid Build Coastguard Worker 
cil_set_target_platform(struct cil_db * db,int target_platform)1979*2d543d20SAndroid Build Coastguard Worker void cil_set_target_platform(struct cil_db *db, int target_platform)
1980*2d543d20SAndroid Build Coastguard Worker {
1981*2d543d20SAndroid Build Coastguard Worker 	db->target_platform = target_platform;
1982*2d543d20SAndroid Build Coastguard Worker }
1983*2d543d20SAndroid Build Coastguard Worker 
cil_set_policy_version(struct cil_db * db,int policy_version)1984*2d543d20SAndroid Build Coastguard Worker void cil_set_policy_version(struct cil_db *db, int policy_version)
1985*2d543d20SAndroid Build Coastguard Worker {
1986*2d543d20SAndroid Build Coastguard Worker 	db->policy_version = policy_version;
1987*2d543d20SAndroid Build Coastguard Worker }
1988*2d543d20SAndroid Build Coastguard Worker 
cil_symtab_array_init(symtab_t symtab[],const int symtab_sizes[CIL_SYM_NUM])1989*2d543d20SAndroid Build Coastguard Worker void cil_symtab_array_init(symtab_t symtab[], const int symtab_sizes[CIL_SYM_NUM])
1990*2d543d20SAndroid Build Coastguard Worker {
1991*2d543d20SAndroid Build Coastguard Worker 	uint32_t i = 0;
1992*2d543d20SAndroid Build Coastguard Worker 	for (i = 0; i < CIL_SYM_NUM; i++) {
1993*2d543d20SAndroid Build Coastguard Worker 		cil_symtab_init(&symtab[i], symtab_sizes[i]);
1994*2d543d20SAndroid Build Coastguard Worker 	}
1995*2d543d20SAndroid Build Coastguard Worker }
1996*2d543d20SAndroid Build Coastguard Worker 
cil_symtab_array_destroy(symtab_t symtab[])1997*2d543d20SAndroid Build Coastguard Worker void cil_symtab_array_destroy(symtab_t symtab[])
1998*2d543d20SAndroid Build Coastguard Worker {
1999*2d543d20SAndroid Build Coastguard Worker 	int i = 0;
2000*2d543d20SAndroid Build Coastguard Worker 	for (i = 0; i < CIL_SYM_NUM; i++) {
2001*2d543d20SAndroid Build Coastguard Worker 		cil_symtab_destroy(&symtab[i]);
2002*2d543d20SAndroid Build Coastguard Worker 	}
2003*2d543d20SAndroid Build Coastguard Worker }
2004*2d543d20SAndroid Build Coastguard Worker 
cil_destroy_ast_symtabs(struct cil_tree_node * current)2005*2d543d20SAndroid Build Coastguard Worker void cil_destroy_ast_symtabs(struct cil_tree_node *current)
2006*2d543d20SAndroid Build Coastguard Worker {
2007*2d543d20SAndroid Build Coastguard Worker 	while (current) {
2008*2d543d20SAndroid Build Coastguard Worker 		switch (current->flavor) {
2009*2d543d20SAndroid Build Coastguard Worker 		case CIL_BLOCK:
2010*2d543d20SAndroid Build Coastguard Worker 			cil_symtab_array_destroy(((struct cil_block*)current->data)->symtab);
2011*2d543d20SAndroid Build Coastguard Worker 			break;
2012*2d543d20SAndroid Build Coastguard Worker 		case CIL_IN:
2013*2d543d20SAndroid Build Coastguard Worker 			cil_symtab_array_destroy(((struct cil_in*)current->data)->symtab);
2014*2d543d20SAndroid Build Coastguard Worker 			break;
2015*2d543d20SAndroid Build Coastguard Worker 		case CIL_CLASS:
2016*2d543d20SAndroid Build Coastguard Worker 		case CIL_COMMON:
2017*2d543d20SAndroid Build Coastguard Worker 		case CIL_MAP_CLASS:
2018*2d543d20SAndroid Build Coastguard Worker 			cil_symtab_destroy(&((struct cil_class*)current->data)->perms);
2019*2d543d20SAndroid Build Coastguard Worker 			break;
2020*2d543d20SAndroid Build Coastguard Worker 		case CIL_MACRO:
2021*2d543d20SAndroid Build Coastguard Worker 			cil_symtab_array_destroy(((struct cil_macro*)current->data)->symtab);
2022*2d543d20SAndroid Build Coastguard Worker 			break;
2023*2d543d20SAndroid Build Coastguard Worker 		case CIL_CONDBLOCK:
2024*2d543d20SAndroid Build Coastguard Worker 			cil_symtab_array_destroy(((struct cil_condblock*)current->data)->symtab);
2025*2d543d20SAndroid Build Coastguard Worker 			break;
2026*2d543d20SAndroid Build Coastguard Worker 		default:
2027*2d543d20SAndroid Build Coastguard Worker 			break;
2028*2d543d20SAndroid Build Coastguard Worker 		}
2029*2d543d20SAndroid Build Coastguard Worker 
2030*2d543d20SAndroid Build Coastguard Worker 		if (current->cl_head) {
2031*2d543d20SAndroid Build Coastguard Worker 			cil_destroy_ast_symtabs(current->cl_head);
2032*2d543d20SAndroid Build Coastguard Worker 		}
2033*2d543d20SAndroid Build Coastguard Worker 
2034*2d543d20SAndroid Build Coastguard Worker 		current = current->next;
2035*2d543d20SAndroid Build Coastguard Worker 	}
2036*2d543d20SAndroid Build Coastguard Worker }
2037*2d543d20SAndroid Build Coastguard Worker 
cil_get_symtab(struct cil_tree_node * ast_node,symtab_t ** symtab,enum cil_sym_index sym_index)2038*2d543d20SAndroid Build Coastguard Worker int cil_get_symtab(struct cil_tree_node *ast_node, symtab_t **symtab, enum cil_sym_index sym_index)
2039*2d543d20SAndroid Build Coastguard Worker {
2040*2d543d20SAndroid Build Coastguard Worker 	struct cil_tree_node *node = ast_node;
2041*2d543d20SAndroid Build Coastguard Worker 	*symtab = NULL;
2042*2d543d20SAndroid Build Coastguard Worker 
2043*2d543d20SAndroid Build Coastguard Worker 	if (sym_index == CIL_SYM_PERMS) {
2044*2d543d20SAndroid Build Coastguard Worker 		/* Class statements are not blocks, so the passed node should be the class */
2045*2d543d20SAndroid Build Coastguard Worker 		if (node->flavor == CIL_CLASS || node->flavor == CIL_MAP_CLASS ||
2046*2d543d20SAndroid Build Coastguard Worker 			node->flavor == CIL_COMMON) {
2047*2d543d20SAndroid Build Coastguard Worker 			*symtab = &((struct cil_class*)node->data)->perms;
2048*2d543d20SAndroid Build Coastguard Worker 			return SEPOL_OK;
2049*2d543d20SAndroid Build Coastguard Worker 		}
2050*2d543d20SAndroid Build Coastguard Worker 		goto exit;
2051*2d543d20SAndroid Build Coastguard Worker 	}
2052*2d543d20SAndroid Build Coastguard Worker 
2053*2d543d20SAndroid Build Coastguard Worker 	if (sym_index < CIL_SYM_BLOCKS || sym_index >= CIL_SYM_NUM) {
2054*2d543d20SAndroid Build Coastguard Worker 		cil_log(CIL_ERR, "Invalid symtab type\n");
2055*2d543d20SAndroid Build Coastguard Worker 		goto exit;
2056*2d543d20SAndroid Build Coastguard Worker 	}
2057*2d543d20SAndroid Build Coastguard Worker 
2058*2d543d20SAndroid Build Coastguard Worker 	while (node != NULL && *symtab == NULL) {
2059*2d543d20SAndroid Build Coastguard Worker 		switch (node->flavor) {
2060*2d543d20SAndroid Build Coastguard Worker 		case CIL_ROOT:
2061*2d543d20SAndroid Build Coastguard Worker 			*symtab = &((struct cil_root *)node->data)->symtab[sym_index];
2062*2d543d20SAndroid Build Coastguard Worker 			break;
2063*2d543d20SAndroid Build Coastguard Worker 		case CIL_BLOCK:
2064*2d543d20SAndroid Build Coastguard Worker 			*symtab = &((struct cil_block*)node->data)->symtab[sym_index];
2065*2d543d20SAndroid Build Coastguard Worker 			break;
2066*2d543d20SAndroid Build Coastguard Worker 		case CIL_MACRO:
2067*2d543d20SAndroid Build Coastguard Worker 			*symtab = &((struct cil_macro*)node->data)->symtab[sym_index];
2068*2d543d20SAndroid Build Coastguard Worker 			break;
2069*2d543d20SAndroid Build Coastguard Worker 		case CIL_IN:
2070*2d543d20SAndroid Build Coastguard Worker 			/* In blocks only exist before resolving the AST */
2071*2d543d20SAndroid Build Coastguard Worker 			*symtab = &((struct cil_in*)node->data)->symtab[sym_index];
2072*2d543d20SAndroid Build Coastguard Worker 			break;
2073*2d543d20SAndroid Build Coastguard Worker 		case CIL_CONDBLOCK: {
2074*2d543d20SAndroid Build Coastguard Worker 			if (node->parent->flavor == CIL_TUNABLEIF) {
2075*2d543d20SAndroid Build Coastguard Worker 				/* Cond blocks only exist before resolving the AST */
2076*2d543d20SAndroid Build Coastguard Worker 				*symtab = &((struct cil_condblock*)node->data)->symtab[sym_index];
2077*2d543d20SAndroid Build Coastguard Worker 			} else if (node->parent->flavor == CIL_BOOLEANIF) {
2078*2d543d20SAndroid Build Coastguard Worker 				node = node->parent->parent;
2079*2d543d20SAndroid Build Coastguard Worker 			}
2080*2d543d20SAndroid Build Coastguard Worker 			break;
2081*2d543d20SAndroid Build Coastguard Worker 		}
2082*2d543d20SAndroid Build Coastguard Worker 		default:
2083*2d543d20SAndroid Build Coastguard Worker 			node = node->parent;
2084*2d543d20SAndroid Build Coastguard Worker 		}
2085*2d543d20SAndroid Build Coastguard Worker 	}
2086*2d543d20SAndroid Build Coastguard Worker 
2087*2d543d20SAndroid Build Coastguard Worker 	if (*symtab == NULL) {
2088*2d543d20SAndroid Build Coastguard Worker 		goto exit;
2089*2d543d20SAndroid Build Coastguard Worker 	}
2090*2d543d20SAndroid Build Coastguard Worker 
2091*2d543d20SAndroid Build Coastguard Worker 	return SEPOL_OK;
2092*2d543d20SAndroid Build Coastguard Worker 
2093*2d543d20SAndroid Build Coastguard Worker exit:
2094*2d543d20SAndroid Build Coastguard Worker 	cil_tree_log(ast_node, CIL_ERR, "Failed to get symtab from node");
2095*2d543d20SAndroid Build Coastguard Worker 	return SEPOL_ERR;
2096*2d543d20SAndroid Build Coastguard Worker }
2097*2d543d20SAndroid Build Coastguard Worker 
cil_string_to_uint32(const char * string,uint32_t * value,int base)2098*2d543d20SAndroid Build Coastguard Worker int cil_string_to_uint32(const char *string, uint32_t *value, int base)
2099*2d543d20SAndroid Build Coastguard Worker {
2100*2d543d20SAndroid Build Coastguard Worker 	unsigned long val;
2101*2d543d20SAndroid Build Coastguard Worker 	char *end = NULL;
2102*2d543d20SAndroid Build Coastguard Worker 	int rc = SEPOL_ERR;
2103*2d543d20SAndroid Build Coastguard Worker 
2104*2d543d20SAndroid Build Coastguard Worker 	if (string == NULL || value  == NULL) {
2105*2d543d20SAndroid Build Coastguard Worker 		goto exit;
2106*2d543d20SAndroid Build Coastguard Worker 	}
2107*2d543d20SAndroid Build Coastguard Worker 
2108*2d543d20SAndroid Build Coastguard Worker 	errno = 0;
2109*2d543d20SAndroid Build Coastguard Worker 	val = strtoul(string, &end, base);
2110*2d543d20SAndroid Build Coastguard Worker 	if (errno != 0 || end == string || *end != '\0') {
2111*2d543d20SAndroid Build Coastguard Worker 		rc = SEPOL_ERR;
2112*2d543d20SAndroid Build Coastguard Worker 		goto exit;
2113*2d543d20SAndroid Build Coastguard Worker 	}
2114*2d543d20SAndroid Build Coastguard Worker 
2115*2d543d20SAndroid Build Coastguard Worker 	/* Ensure that the value fits a 32-bit integer without triggering -Wtype-limits */
2116*2d543d20SAndroid Build Coastguard Worker #if ULONG_MAX > UINT32_MAX
2117*2d543d20SAndroid Build Coastguard Worker 	if (val > UINT32_MAX) {
2118*2d543d20SAndroid Build Coastguard Worker 		rc = SEPOL_ERR;
2119*2d543d20SAndroid Build Coastguard Worker 		goto exit;
2120*2d543d20SAndroid Build Coastguard Worker 	}
2121*2d543d20SAndroid Build Coastguard Worker #endif
2122*2d543d20SAndroid Build Coastguard Worker 
2123*2d543d20SAndroid Build Coastguard Worker 	*value = val;
2124*2d543d20SAndroid Build Coastguard Worker 
2125*2d543d20SAndroid Build Coastguard Worker 	return SEPOL_OK;
2126*2d543d20SAndroid Build Coastguard Worker 
2127*2d543d20SAndroid Build Coastguard Worker exit:
2128*2d543d20SAndroid Build Coastguard Worker 	cil_log(CIL_ERR, "Failed to create uint32_t from string\n");
2129*2d543d20SAndroid Build Coastguard Worker 	return rc;
2130*2d543d20SAndroid Build Coastguard Worker }
2131*2d543d20SAndroid Build Coastguard Worker 
cil_string_to_uint64(const char * string,uint64_t * value,int base)2132*2d543d20SAndroid Build Coastguard Worker int cil_string_to_uint64(const char *string, uint64_t *value, int base)
2133*2d543d20SAndroid Build Coastguard Worker {
2134*2d543d20SAndroid Build Coastguard Worker 	char *end = NULL;
2135*2d543d20SAndroid Build Coastguard Worker 	int rc = SEPOL_ERR;
2136*2d543d20SAndroid Build Coastguard Worker 
2137*2d543d20SAndroid Build Coastguard Worker 	if (string == NULL || value  == NULL) {
2138*2d543d20SAndroid Build Coastguard Worker 		goto exit;
2139*2d543d20SAndroid Build Coastguard Worker 	}
2140*2d543d20SAndroid Build Coastguard Worker 
2141*2d543d20SAndroid Build Coastguard Worker 	errno = 0;
2142*2d543d20SAndroid Build Coastguard Worker 	*value = strtoull(string, &end, base);
2143*2d543d20SAndroid Build Coastguard Worker 	if (errno != 0 || end == string || *end != '\0') {
2144*2d543d20SAndroid Build Coastguard Worker 		rc = SEPOL_ERR;
2145*2d543d20SAndroid Build Coastguard Worker 		goto exit;
2146*2d543d20SAndroid Build Coastguard Worker 	}
2147*2d543d20SAndroid Build Coastguard Worker 
2148*2d543d20SAndroid Build Coastguard Worker 	return SEPOL_OK;
2149*2d543d20SAndroid Build Coastguard Worker 
2150*2d543d20SAndroid Build Coastguard Worker exit:
2151*2d543d20SAndroid Build Coastguard Worker 	cil_log(CIL_ERR, "Failed to create uint64_t from string\n");
2152*2d543d20SAndroid Build Coastguard Worker 	return rc;
2153*2d543d20SAndroid Build Coastguard Worker }
2154*2d543d20SAndroid Build Coastguard Worker 
cil_sort_init(struct cil_sort ** sort)2155*2d543d20SAndroid Build Coastguard Worker void cil_sort_init(struct cil_sort **sort)
2156*2d543d20SAndroid Build Coastguard Worker {
2157*2d543d20SAndroid Build Coastguard Worker 	*sort = cil_malloc(sizeof(**sort));
2158*2d543d20SAndroid Build Coastguard Worker 
2159*2d543d20SAndroid Build Coastguard Worker 	(*sort)->flavor = CIL_NONE;
2160*2d543d20SAndroid Build Coastguard Worker 	(*sort)->count = 0;
2161*2d543d20SAndroid Build Coastguard Worker 	(*sort)->index = 0;
2162*2d543d20SAndroid Build Coastguard Worker 	(*sort)->array = NULL;
2163*2d543d20SAndroid Build Coastguard Worker }
2164*2d543d20SAndroid Build Coastguard Worker 
cil_sort_destroy(struct cil_sort ** sort)2165*2d543d20SAndroid Build Coastguard Worker void cil_sort_destroy(struct cil_sort **sort)
2166*2d543d20SAndroid Build Coastguard Worker {
2167*2d543d20SAndroid Build Coastguard Worker 	(*sort)->flavor = CIL_NONE;
2168*2d543d20SAndroid Build Coastguard Worker 	(*sort)->count = 0;
2169*2d543d20SAndroid Build Coastguard Worker 	(*sort)->index = 0;
2170*2d543d20SAndroid Build Coastguard Worker 	if ((*sort)->array != NULL) {
2171*2d543d20SAndroid Build Coastguard Worker 		free((*sort)->array);
2172*2d543d20SAndroid Build Coastguard Worker 	}
2173*2d543d20SAndroid Build Coastguard Worker 	(*sort)->array = NULL;
2174*2d543d20SAndroid Build Coastguard Worker 
2175*2d543d20SAndroid Build Coastguard Worker 	free(*sort);
2176*2d543d20SAndroid Build Coastguard Worker 	*sort = NULL;
2177*2d543d20SAndroid Build Coastguard Worker }
2178*2d543d20SAndroid Build Coastguard Worker 
cil_ordered_init(struct cil_ordered ** ordered)2179*2d543d20SAndroid Build Coastguard Worker void cil_ordered_init(struct cil_ordered **ordered)
2180*2d543d20SAndroid Build Coastguard Worker {
2181*2d543d20SAndroid Build Coastguard Worker 	*ordered = cil_malloc(sizeof(**ordered));
2182*2d543d20SAndroid Build Coastguard Worker 	(*ordered)->merged = CIL_FALSE;
2183*2d543d20SAndroid Build Coastguard Worker 	(*ordered)->strs = NULL;
2184*2d543d20SAndroid Build Coastguard Worker 	(*ordered)->datums = NULL;
2185*2d543d20SAndroid Build Coastguard Worker }
2186*2d543d20SAndroid Build Coastguard Worker 
cil_netifcon_init(struct cil_netifcon ** netifcon)2187*2d543d20SAndroid Build Coastguard Worker void cil_netifcon_init(struct cil_netifcon **netifcon)
2188*2d543d20SAndroid Build Coastguard Worker {
2189*2d543d20SAndroid Build Coastguard Worker 	*netifcon = cil_malloc(sizeof(**netifcon));
2190*2d543d20SAndroid Build Coastguard Worker 
2191*2d543d20SAndroid Build Coastguard Worker 	(*netifcon)->interface_str = NULL;
2192*2d543d20SAndroid Build Coastguard Worker 	(*netifcon)->if_context_str = NULL;
2193*2d543d20SAndroid Build Coastguard Worker 	(*netifcon)->if_context = NULL;
2194*2d543d20SAndroid Build Coastguard Worker 	(*netifcon)->packet_context_str = NULL;
2195*2d543d20SAndroid Build Coastguard Worker 	(*netifcon)->packet_context = NULL;
2196*2d543d20SAndroid Build Coastguard Worker 	(*netifcon)->context_str = NULL;
2197*2d543d20SAndroid Build Coastguard Worker }
2198*2d543d20SAndroid Build Coastguard Worker 
cil_ibendportcon_init(struct cil_ibendportcon ** ibendportcon)2199*2d543d20SAndroid Build Coastguard Worker void cil_ibendportcon_init(struct cil_ibendportcon **ibendportcon)
2200*2d543d20SAndroid Build Coastguard Worker {
2201*2d543d20SAndroid Build Coastguard Worker 	*ibendportcon = cil_malloc(sizeof(**ibendportcon));
2202*2d543d20SAndroid Build Coastguard Worker 
2203*2d543d20SAndroid Build Coastguard Worker 	(*ibendportcon)->dev_name_str = NULL;
2204*2d543d20SAndroid Build Coastguard Worker 	(*ibendportcon)->port = 0;
2205*2d543d20SAndroid Build Coastguard Worker 	(*ibendportcon)->context_str = NULL;
2206*2d543d20SAndroid Build Coastguard Worker 	(*ibendportcon)->context = NULL;
2207*2d543d20SAndroid Build Coastguard Worker }
2208*2d543d20SAndroid Build Coastguard Worker 
cil_context_init(struct cil_context ** context)2209*2d543d20SAndroid Build Coastguard Worker void cil_context_init(struct cil_context **context)
2210*2d543d20SAndroid Build Coastguard Worker {
2211*2d543d20SAndroid Build Coastguard Worker 	*context = cil_malloc(sizeof(**context));
2212*2d543d20SAndroid Build Coastguard Worker 
2213*2d543d20SAndroid Build Coastguard Worker 	cil_symtab_datum_init(&(*context)->datum);
2214*2d543d20SAndroid Build Coastguard Worker 	(*context)->user_str = NULL;
2215*2d543d20SAndroid Build Coastguard Worker 	(*context)->user = NULL;
2216*2d543d20SAndroid Build Coastguard Worker 	(*context)->role_str = NULL;
2217*2d543d20SAndroid Build Coastguard Worker 	(*context)->role = NULL;
2218*2d543d20SAndroid Build Coastguard Worker 	(*context)->type_str = NULL;
2219*2d543d20SAndroid Build Coastguard Worker 	(*context)->type = NULL;
2220*2d543d20SAndroid Build Coastguard Worker 	(*context)->range_str = NULL;
2221*2d543d20SAndroid Build Coastguard Worker 	(*context)->range = NULL;
2222*2d543d20SAndroid Build Coastguard Worker }
2223*2d543d20SAndroid Build Coastguard Worker 
cil_level_init(struct cil_level ** level)2224*2d543d20SAndroid Build Coastguard Worker void cil_level_init(struct cil_level **level)
2225*2d543d20SAndroid Build Coastguard Worker {
2226*2d543d20SAndroid Build Coastguard Worker 	*level = cil_malloc(sizeof(**level));
2227*2d543d20SAndroid Build Coastguard Worker 
2228*2d543d20SAndroid Build Coastguard Worker 	cil_symtab_datum_init(&(*level)->datum);
2229*2d543d20SAndroid Build Coastguard Worker 	(*level)->sens_str = NULL;
2230*2d543d20SAndroid Build Coastguard Worker 	(*level)->sens = NULL;
2231*2d543d20SAndroid Build Coastguard Worker 	(*level)->cats = NULL;
2232*2d543d20SAndroid Build Coastguard Worker }
2233*2d543d20SAndroid Build Coastguard Worker 
cil_levelrange_init(struct cil_levelrange ** range)2234*2d543d20SAndroid Build Coastguard Worker void cil_levelrange_init(struct cil_levelrange **range)
2235*2d543d20SAndroid Build Coastguard Worker {
2236*2d543d20SAndroid Build Coastguard Worker 	*range = cil_malloc(sizeof(**range));
2237*2d543d20SAndroid Build Coastguard Worker 
2238*2d543d20SAndroid Build Coastguard Worker 	cil_symtab_datum_init(&(*range)->datum);
2239*2d543d20SAndroid Build Coastguard Worker 	(*range)->low_str = NULL;
2240*2d543d20SAndroid Build Coastguard Worker 	(*range)->low = NULL;
2241*2d543d20SAndroid Build Coastguard Worker 	(*range)->high_str = NULL;
2242*2d543d20SAndroid Build Coastguard Worker 	(*range)->high = NULL;
2243*2d543d20SAndroid Build Coastguard Worker }
2244*2d543d20SAndroid Build Coastguard Worker 
cil_sens_init(struct cil_sens ** sens)2245*2d543d20SAndroid Build Coastguard Worker void cil_sens_init(struct cil_sens **sens)
2246*2d543d20SAndroid Build Coastguard Worker {
2247*2d543d20SAndroid Build Coastguard Worker 	*sens = cil_malloc(sizeof(**sens));
2248*2d543d20SAndroid Build Coastguard Worker 
2249*2d543d20SAndroid Build Coastguard Worker 	cil_symtab_datum_init(&(*sens)->datum);
2250*2d543d20SAndroid Build Coastguard Worker 
2251*2d543d20SAndroid Build Coastguard Worker 	(*sens)->cats_list = NULL;
2252*2d543d20SAndroid Build Coastguard Worker 
2253*2d543d20SAndroid Build Coastguard Worker 	(*sens)->ordered = CIL_FALSE;
2254*2d543d20SAndroid Build Coastguard Worker }
2255*2d543d20SAndroid Build Coastguard Worker 
cil_block_init(struct cil_block ** block)2256*2d543d20SAndroid Build Coastguard Worker void cil_block_init(struct cil_block **block)
2257*2d543d20SAndroid Build Coastguard Worker {
2258*2d543d20SAndroid Build Coastguard Worker 	*block = cil_malloc(sizeof(**block));
2259*2d543d20SAndroid Build Coastguard Worker 
2260*2d543d20SAndroid Build Coastguard Worker 	cil_symtab_datum_init(&(*block)->datum);
2261*2d543d20SAndroid Build Coastguard Worker 
2262*2d543d20SAndroid Build Coastguard Worker 	cil_symtab_array_init((*block)->symtab, cil_sym_sizes[CIL_SYM_ARRAY_BLOCK]);
2263*2d543d20SAndroid Build Coastguard Worker 
2264*2d543d20SAndroid Build Coastguard Worker 	(*block)->is_abstract = CIL_FALSE;
2265*2d543d20SAndroid Build Coastguard Worker 
2266*2d543d20SAndroid Build Coastguard Worker 	(*block)->bi_nodes = NULL;
2267*2d543d20SAndroid Build Coastguard Worker }
2268*2d543d20SAndroid Build Coastguard Worker 
cil_blockinherit_init(struct cil_blockinherit ** inherit)2269*2d543d20SAndroid Build Coastguard Worker void cil_blockinherit_init(struct cil_blockinherit **inherit)
2270*2d543d20SAndroid Build Coastguard Worker {
2271*2d543d20SAndroid Build Coastguard Worker 	*inherit = cil_malloc(sizeof(**inherit));
2272*2d543d20SAndroid Build Coastguard Worker 	(*inherit)->block_str = NULL;
2273*2d543d20SAndroid Build Coastguard Worker 	(*inherit)->block = NULL;
2274*2d543d20SAndroid Build Coastguard Worker }
2275*2d543d20SAndroid Build Coastguard Worker 
cil_blockabstract_init(struct cil_blockabstract ** abstract)2276*2d543d20SAndroid Build Coastguard Worker void cil_blockabstract_init(struct cil_blockabstract **abstract)
2277*2d543d20SAndroid Build Coastguard Worker {
2278*2d543d20SAndroid Build Coastguard Worker 	*abstract = cil_malloc(sizeof(**abstract));
2279*2d543d20SAndroid Build Coastguard Worker 	(*abstract)->block_str = NULL;
2280*2d543d20SAndroid Build Coastguard Worker 	(*abstract)->block = NULL;
2281*2d543d20SAndroid Build Coastguard Worker }
2282*2d543d20SAndroid Build Coastguard Worker 
cil_in_init(struct cil_in ** in)2283*2d543d20SAndroid Build Coastguard Worker void cil_in_init(struct cil_in **in)
2284*2d543d20SAndroid Build Coastguard Worker {
2285*2d543d20SAndroid Build Coastguard Worker 	*in = cil_malloc(sizeof(**in));
2286*2d543d20SAndroid Build Coastguard Worker 
2287*2d543d20SAndroid Build Coastguard Worker 	cil_symtab_array_init((*in)->symtab, cil_sym_sizes[CIL_SYM_ARRAY_IN]);
2288*2d543d20SAndroid Build Coastguard Worker 	(*in)->is_after = CIL_FALSE;
2289*2d543d20SAndroid Build Coastguard Worker 	(*in)->block_str = NULL;
2290*2d543d20SAndroid Build Coastguard Worker 	(*in)->block = NULL;
2291*2d543d20SAndroid Build Coastguard Worker }
2292*2d543d20SAndroid Build Coastguard Worker 
cil_class_init(struct cil_class ** class)2293*2d543d20SAndroid Build Coastguard Worker void cil_class_init(struct cil_class **class)
2294*2d543d20SAndroid Build Coastguard Worker {
2295*2d543d20SAndroid Build Coastguard Worker 	*class = cil_malloc(sizeof(**class));
2296*2d543d20SAndroid Build Coastguard Worker 
2297*2d543d20SAndroid Build Coastguard Worker 	cil_symtab_datum_init(&(*class)->datum);
2298*2d543d20SAndroid Build Coastguard Worker 
2299*2d543d20SAndroid Build Coastguard Worker 	cil_symtab_init(&(*class)->perms, CIL_CLASS_SYM_SIZE);
2300*2d543d20SAndroid Build Coastguard Worker 
2301*2d543d20SAndroid Build Coastguard Worker 	(*class)->num_perms = 0;
2302*2d543d20SAndroid Build Coastguard Worker 	(*class)->common = NULL;
2303*2d543d20SAndroid Build Coastguard Worker 	(*class)->ordered = CIL_FALSE;
2304*2d543d20SAndroid Build Coastguard Worker }
2305*2d543d20SAndroid Build Coastguard Worker 
cil_classcommon_init(struct cil_classcommon ** classcommon)2306*2d543d20SAndroid Build Coastguard Worker void cil_classcommon_init(struct cil_classcommon **classcommon)
2307*2d543d20SAndroid Build Coastguard Worker {
2308*2d543d20SAndroid Build Coastguard Worker 	*classcommon = cil_malloc(sizeof(**classcommon));
2309*2d543d20SAndroid Build Coastguard Worker 
2310*2d543d20SAndroid Build Coastguard Worker 	(*classcommon)->class_str = NULL;
2311*2d543d20SAndroid Build Coastguard Worker 	(*classcommon)->class = NULL;
2312*2d543d20SAndroid Build Coastguard Worker 	(*classcommon)->common_str = NULL;
2313*2d543d20SAndroid Build Coastguard Worker 	(*classcommon)->common = NULL;
2314*2d543d20SAndroid Build Coastguard Worker }
2315*2d543d20SAndroid Build Coastguard Worker 
cil_sid_init(struct cil_sid ** sid)2316*2d543d20SAndroid Build Coastguard Worker void cil_sid_init(struct cil_sid **sid)
2317*2d543d20SAndroid Build Coastguard Worker {
2318*2d543d20SAndroid Build Coastguard Worker 	*sid = cil_malloc(sizeof(**sid));
2319*2d543d20SAndroid Build Coastguard Worker 
2320*2d543d20SAndroid Build Coastguard Worker 	cil_symtab_datum_init(&(*sid)->datum);
2321*2d543d20SAndroid Build Coastguard Worker 
2322*2d543d20SAndroid Build Coastguard Worker 	(*sid)->ordered = CIL_FALSE;
2323*2d543d20SAndroid Build Coastguard Worker 	(*sid)->context = NULL;
2324*2d543d20SAndroid Build Coastguard Worker }
2325*2d543d20SAndroid Build Coastguard Worker 
cil_sidcontext_init(struct cil_sidcontext ** sidcontext)2326*2d543d20SAndroid Build Coastguard Worker void cil_sidcontext_init(struct cil_sidcontext **sidcontext)
2327*2d543d20SAndroid Build Coastguard Worker {
2328*2d543d20SAndroid Build Coastguard Worker 	*sidcontext = cil_malloc(sizeof(**sidcontext));
2329*2d543d20SAndroid Build Coastguard Worker 
2330*2d543d20SAndroid Build Coastguard Worker 	(*sidcontext)->sid_str = NULL;
2331*2d543d20SAndroid Build Coastguard Worker 	(*sidcontext)->sid = NULL;
2332*2d543d20SAndroid Build Coastguard Worker 	(*sidcontext)->context_str = NULL;
2333*2d543d20SAndroid Build Coastguard Worker 	(*sidcontext)->context = NULL;
2334*2d543d20SAndroid Build Coastguard Worker }
2335*2d543d20SAndroid Build Coastguard Worker 
cil_userrole_init(struct cil_userrole ** userrole)2336*2d543d20SAndroid Build Coastguard Worker void cil_userrole_init(struct cil_userrole **userrole)
2337*2d543d20SAndroid Build Coastguard Worker {
2338*2d543d20SAndroid Build Coastguard Worker 	*userrole = cil_malloc(sizeof(**userrole));
2339*2d543d20SAndroid Build Coastguard Worker 
2340*2d543d20SAndroid Build Coastguard Worker 	(*userrole)->user_str = NULL;
2341*2d543d20SAndroid Build Coastguard Worker 	(*userrole)->user = NULL;
2342*2d543d20SAndroid Build Coastguard Worker 	(*userrole)->role_str = NULL;
2343*2d543d20SAndroid Build Coastguard Worker 	(*userrole)->role = NULL;
2344*2d543d20SAndroid Build Coastguard Worker }
2345*2d543d20SAndroid Build Coastguard Worker 
cil_userprefix_init(struct cil_userprefix ** userprefix)2346*2d543d20SAndroid Build Coastguard Worker void cil_userprefix_init(struct cil_userprefix **userprefix)
2347*2d543d20SAndroid Build Coastguard Worker {
2348*2d543d20SAndroid Build Coastguard Worker 	*userprefix = cil_malloc(sizeof(**userprefix));
2349*2d543d20SAndroid Build Coastguard Worker 
2350*2d543d20SAndroid Build Coastguard Worker 	(*userprefix)->user_str = NULL;
2351*2d543d20SAndroid Build Coastguard Worker 	(*userprefix)->user = NULL;
2352*2d543d20SAndroid Build Coastguard Worker 	(*userprefix)->prefix_str = NULL;
2353*2d543d20SAndroid Build Coastguard Worker }
2354*2d543d20SAndroid Build Coastguard Worker 
cil_selinuxuser_init(struct cil_selinuxuser ** selinuxuser)2355*2d543d20SAndroid Build Coastguard Worker void cil_selinuxuser_init(struct cil_selinuxuser **selinuxuser)
2356*2d543d20SAndroid Build Coastguard Worker {
2357*2d543d20SAndroid Build Coastguard Worker 	*selinuxuser = cil_malloc(sizeof(**selinuxuser));
2358*2d543d20SAndroid Build Coastguard Worker 
2359*2d543d20SAndroid Build Coastguard Worker 	(*selinuxuser)->name_str = NULL;
2360*2d543d20SAndroid Build Coastguard Worker 	(*selinuxuser)->user_str = NULL;
2361*2d543d20SAndroid Build Coastguard Worker 	(*selinuxuser)->user = NULL;
2362*2d543d20SAndroid Build Coastguard Worker 	(*selinuxuser)->range_str = NULL;
2363*2d543d20SAndroid Build Coastguard Worker 	(*selinuxuser)->range = NULL;
2364*2d543d20SAndroid Build Coastguard Worker }
2365*2d543d20SAndroid Build Coastguard Worker 
cil_roletype_init(struct cil_roletype ** roletype)2366*2d543d20SAndroid Build Coastguard Worker void cil_roletype_init(struct cil_roletype **roletype)
2367*2d543d20SAndroid Build Coastguard Worker {
2368*2d543d20SAndroid Build Coastguard Worker 	*roletype = cil_malloc(sizeof(**roletype));
2369*2d543d20SAndroid Build Coastguard Worker 
2370*2d543d20SAndroid Build Coastguard Worker 	(*roletype)->role_str = NULL;
2371*2d543d20SAndroid Build Coastguard Worker 	(*roletype)->role = NULL;
2372*2d543d20SAndroid Build Coastguard Worker 	(*roletype)->type_str = NULL;
2373*2d543d20SAndroid Build Coastguard Worker 	(*roletype)->type = NULL;
2374*2d543d20SAndroid Build Coastguard Worker }
2375*2d543d20SAndroid Build Coastguard Worker 
cil_roleattribute_init(struct cil_roleattribute ** attr)2376*2d543d20SAndroid Build Coastguard Worker void cil_roleattribute_init(struct cil_roleattribute **attr)
2377*2d543d20SAndroid Build Coastguard Worker {
2378*2d543d20SAndroid Build Coastguard Worker 	*attr = cil_malloc(sizeof(**attr));
2379*2d543d20SAndroid Build Coastguard Worker 
2380*2d543d20SAndroid Build Coastguard Worker 	cil_symtab_datum_init(&(*attr)->datum);
2381*2d543d20SAndroid Build Coastguard Worker 
2382*2d543d20SAndroid Build Coastguard Worker 	(*attr)->expr_list = NULL;
2383*2d543d20SAndroid Build Coastguard Worker 	(*attr)->roles = NULL;
2384*2d543d20SAndroid Build Coastguard Worker }
2385*2d543d20SAndroid Build Coastguard Worker 
cil_roleattributeset_init(struct cil_roleattributeset ** attrset)2386*2d543d20SAndroid Build Coastguard Worker void cil_roleattributeset_init(struct cil_roleattributeset **attrset)
2387*2d543d20SAndroid Build Coastguard Worker {
2388*2d543d20SAndroid Build Coastguard Worker 	*attrset = cil_malloc(sizeof(**attrset));
2389*2d543d20SAndroid Build Coastguard Worker 
2390*2d543d20SAndroid Build Coastguard Worker 	(*attrset)->attr_str = NULL;
2391*2d543d20SAndroid Build Coastguard Worker 	(*attrset)->attr = NULL;
2392*2d543d20SAndroid Build Coastguard Worker 	(*attrset)->str_expr = NULL;
2393*2d543d20SAndroid Build Coastguard Worker 	(*attrset)->datum_expr = NULL;
2394*2d543d20SAndroid Build Coastguard Worker }
2395*2d543d20SAndroid Build Coastguard Worker 
cil_typeattribute_init(struct cil_typeattribute ** attr)2396*2d543d20SAndroid Build Coastguard Worker void cil_typeattribute_init(struct cil_typeattribute **attr)
2397*2d543d20SAndroid Build Coastguard Worker {
2398*2d543d20SAndroid Build Coastguard Worker 	*attr = cil_malloc(sizeof(**attr));
2399*2d543d20SAndroid Build Coastguard Worker 
2400*2d543d20SAndroid Build Coastguard Worker 	cil_symtab_datum_init(&(*attr)->datum);
2401*2d543d20SAndroid Build Coastguard Worker 
2402*2d543d20SAndroid Build Coastguard Worker 	(*attr)->expr_list = NULL;
2403*2d543d20SAndroid Build Coastguard Worker 	(*attr)->types = NULL;
2404*2d543d20SAndroid Build Coastguard Worker 	(*attr)->used = CIL_FALSE;
2405*2d543d20SAndroid Build Coastguard Worker 	(*attr)->keep = CIL_FALSE;
2406*2d543d20SAndroid Build Coastguard Worker }
2407*2d543d20SAndroid Build Coastguard Worker 
cil_typeattributeset_init(struct cil_typeattributeset ** attrset)2408*2d543d20SAndroid Build Coastguard Worker void cil_typeattributeset_init(struct cil_typeattributeset **attrset)
2409*2d543d20SAndroid Build Coastguard Worker {
2410*2d543d20SAndroid Build Coastguard Worker 	*attrset = cil_malloc(sizeof(**attrset));
2411*2d543d20SAndroid Build Coastguard Worker 
2412*2d543d20SAndroid Build Coastguard Worker 	(*attrset)->attr_str = NULL;
2413*2d543d20SAndroid Build Coastguard Worker 	(*attrset)->attr = NULL;
2414*2d543d20SAndroid Build Coastguard Worker 	(*attrset)->str_expr = NULL;
2415*2d543d20SAndroid Build Coastguard Worker 	(*attrset)->datum_expr = NULL;
2416*2d543d20SAndroid Build Coastguard Worker }
2417*2d543d20SAndroid Build Coastguard Worker 
cil_expandtypeattribute_init(struct cil_expandtypeattribute ** expandattr)2418*2d543d20SAndroid Build Coastguard Worker void cil_expandtypeattribute_init(struct cil_expandtypeattribute **expandattr)
2419*2d543d20SAndroid Build Coastguard Worker {
2420*2d543d20SAndroid Build Coastguard Worker 	*expandattr = cil_malloc(sizeof(**expandattr));
2421*2d543d20SAndroid Build Coastguard Worker 
2422*2d543d20SAndroid Build Coastguard Worker 	(*expandattr)->attr_strs = NULL;
2423*2d543d20SAndroid Build Coastguard Worker 	(*expandattr)->attr_datums = NULL;
2424*2d543d20SAndroid Build Coastguard Worker 	(*expandattr)->expand = 0;
2425*2d543d20SAndroid Build Coastguard Worker }
2426*2d543d20SAndroid Build Coastguard Worker 
cil_alias_init(struct cil_alias ** alias)2427*2d543d20SAndroid Build Coastguard Worker void cil_alias_init(struct cil_alias **alias)
2428*2d543d20SAndroid Build Coastguard Worker {
2429*2d543d20SAndroid Build Coastguard Worker 	*alias = cil_malloc(sizeof(**alias));
2430*2d543d20SAndroid Build Coastguard Worker 
2431*2d543d20SAndroid Build Coastguard Worker 	(*alias)->actual = NULL;
2432*2d543d20SAndroid Build Coastguard Worker 
2433*2d543d20SAndroid Build Coastguard Worker 	cil_symtab_datum_init(&(*alias)->datum);
2434*2d543d20SAndroid Build Coastguard Worker }
2435*2d543d20SAndroid Build Coastguard Worker 
cil_aliasactual_init(struct cil_aliasactual ** aliasactual)2436*2d543d20SAndroid Build Coastguard Worker void cil_aliasactual_init(struct cil_aliasactual **aliasactual)
2437*2d543d20SAndroid Build Coastguard Worker {
2438*2d543d20SAndroid Build Coastguard Worker 	*aliasactual = cil_malloc(sizeof(**aliasactual));
2439*2d543d20SAndroid Build Coastguard Worker 
2440*2d543d20SAndroid Build Coastguard Worker 	(*aliasactual)->alias_str = NULL;
2441*2d543d20SAndroid Build Coastguard Worker 	(*aliasactual)->alias = NULL;
2442*2d543d20SAndroid Build Coastguard Worker 	(*aliasactual)->actual_str = NULL;
2443*2d543d20SAndroid Build Coastguard Worker 	(*aliasactual)->actual = NULL;
2444*2d543d20SAndroid Build Coastguard Worker }
2445*2d543d20SAndroid Build Coastguard Worker 
cil_typepermissive_init(struct cil_typepermissive ** typeperm)2446*2d543d20SAndroid Build Coastguard Worker void cil_typepermissive_init(struct cil_typepermissive **typeperm)
2447*2d543d20SAndroid Build Coastguard Worker {
2448*2d543d20SAndroid Build Coastguard Worker 	*typeperm = cil_malloc(sizeof(**typeperm));
2449*2d543d20SAndroid Build Coastguard Worker 
2450*2d543d20SAndroid Build Coastguard Worker 	(*typeperm)->type_str = NULL;
2451*2d543d20SAndroid Build Coastguard Worker 	(*typeperm)->type = NULL;
2452*2d543d20SAndroid Build Coastguard Worker }
2453*2d543d20SAndroid Build Coastguard Worker 
cil_nametypetransition_init(struct cil_nametypetransition ** nametypetrans)2454*2d543d20SAndroid Build Coastguard Worker void cil_nametypetransition_init(struct cil_nametypetransition **nametypetrans)
2455*2d543d20SAndroid Build Coastguard Worker {
2456*2d543d20SAndroid Build Coastguard Worker 	*nametypetrans = cil_malloc(sizeof(**nametypetrans));
2457*2d543d20SAndroid Build Coastguard Worker 
2458*2d543d20SAndroid Build Coastguard Worker 	(*nametypetrans)->src_str = NULL;
2459*2d543d20SAndroid Build Coastguard Worker 	(*nametypetrans)->src = NULL;
2460*2d543d20SAndroid Build Coastguard Worker 	(*nametypetrans)->tgt_str = NULL;
2461*2d543d20SAndroid Build Coastguard Worker 	(*nametypetrans)->tgt = NULL;
2462*2d543d20SAndroid Build Coastguard Worker 	(*nametypetrans)->obj_str = NULL;
2463*2d543d20SAndroid Build Coastguard Worker 	(*nametypetrans)->obj = NULL;
2464*2d543d20SAndroid Build Coastguard Worker 	(*nametypetrans)->name_str = NULL;
2465*2d543d20SAndroid Build Coastguard Worker 	(*nametypetrans)->name = NULL;
2466*2d543d20SAndroid Build Coastguard Worker 	(*nametypetrans)->result_str = NULL;
2467*2d543d20SAndroid Build Coastguard Worker 	(*nametypetrans)->result = NULL;
2468*2d543d20SAndroid Build Coastguard Worker }
2469*2d543d20SAndroid Build Coastguard Worker 
cil_rangetransition_init(struct cil_rangetransition ** rangetrans)2470*2d543d20SAndroid Build Coastguard Worker void cil_rangetransition_init(struct cil_rangetransition **rangetrans)
2471*2d543d20SAndroid Build Coastguard Worker {
2472*2d543d20SAndroid Build Coastguard Worker         *rangetrans = cil_malloc(sizeof(**rangetrans));
2473*2d543d20SAndroid Build Coastguard Worker 
2474*2d543d20SAndroid Build Coastguard Worker 	(*rangetrans)->src_str = NULL;
2475*2d543d20SAndroid Build Coastguard Worker 	(*rangetrans)->src = NULL;
2476*2d543d20SAndroid Build Coastguard Worker 	(*rangetrans)->exec_str = NULL;
2477*2d543d20SAndroid Build Coastguard Worker 	(*rangetrans)->exec = NULL;
2478*2d543d20SAndroid Build Coastguard Worker 	(*rangetrans)->obj_str = NULL;
2479*2d543d20SAndroid Build Coastguard Worker 	(*rangetrans)->obj = NULL;
2480*2d543d20SAndroid Build Coastguard Worker 	(*rangetrans)->range_str = NULL;
2481*2d543d20SAndroid Build Coastguard Worker 	(*rangetrans)->range = NULL;
2482*2d543d20SAndroid Build Coastguard Worker }
2483*2d543d20SAndroid Build Coastguard Worker 
cil_bool_init(struct cil_bool ** cilbool)2484*2d543d20SAndroid Build Coastguard Worker void cil_bool_init(struct cil_bool **cilbool)
2485*2d543d20SAndroid Build Coastguard Worker {
2486*2d543d20SAndroid Build Coastguard Worker 	*cilbool = cil_malloc(sizeof(**cilbool));
2487*2d543d20SAndroid Build Coastguard Worker 
2488*2d543d20SAndroid Build Coastguard Worker 	cil_symtab_datum_init(&(*cilbool)->datum);
2489*2d543d20SAndroid Build Coastguard Worker 	(*cilbool)->value = 0;
2490*2d543d20SAndroid Build Coastguard Worker }
2491*2d543d20SAndroid Build Coastguard Worker 
cil_tunable_init(struct cil_tunable ** ciltun)2492*2d543d20SAndroid Build Coastguard Worker void cil_tunable_init(struct cil_tunable **ciltun)
2493*2d543d20SAndroid Build Coastguard Worker {
2494*2d543d20SAndroid Build Coastguard Worker 	*ciltun = cil_malloc(sizeof(**ciltun));
2495*2d543d20SAndroid Build Coastguard Worker 
2496*2d543d20SAndroid Build Coastguard Worker 	cil_symtab_datum_init(&(*ciltun)->datum);
2497*2d543d20SAndroid Build Coastguard Worker 	(*ciltun)->value = 0;
2498*2d543d20SAndroid Build Coastguard Worker }
2499*2d543d20SAndroid Build Coastguard Worker 
cil_condblock_init(struct cil_condblock ** cb)2500*2d543d20SAndroid Build Coastguard Worker void cil_condblock_init(struct cil_condblock **cb)
2501*2d543d20SAndroid Build Coastguard Worker {
2502*2d543d20SAndroid Build Coastguard Worker 	*cb = cil_malloc(sizeof(**cb));
2503*2d543d20SAndroid Build Coastguard Worker 
2504*2d543d20SAndroid Build Coastguard Worker 	(*cb)->flavor = CIL_NONE;
2505*2d543d20SAndroid Build Coastguard Worker 	cil_symtab_array_init((*cb)->symtab, cil_sym_sizes[CIL_SYM_ARRAY_CONDBLOCK]);
2506*2d543d20SAndroid Build Coastguard Worker }
2507*2d543d20SAndroid Build Coastguard Worker 
cil_boolif_init(struct cil_booleanif ** bif)2508*2d543d20SAndroid Build Coastguard Worker void cil_boolif_init(struct cil_booleanif **bif)
2509*2d543d20SAndroid Build Coastguard Worker {
2510*2d543d20SAndroid Build Coastguard Worker 	*bif = cil_malloc(sizeof(**bif));
2511*2d543d20SAndroid Build Coastguard Worker 
2512*2d543d20SAndroid Build Coastguard Worker 	(*bif)->str_expr = NULL;
2513*2d543d20SAndroid Build Coastguard Worker 	(*bif)->datum_expr = NULL;
2514*2d543d20SAndroid Build Coastguard Worker }
2515*2d543d20SAndroid Build Coastguard Worker 
cil_tunif_init(struct cil_tunableif ** tif)2516*2d543d20SAndroid Build Coastguard Worker void cil_tunif_init(struct cil_tunableif **tif)
2517*2d543d20SAndroid Build Coastguard Worker {
2518*2d543d20SAndroid Build Coastguard Worker 	*tif = cil_malloc(sizeof(**tif));
2519*2d543d20SAndroid Build Coastguard Worker 
2520*2d543d20SAndroid Build Coastguard Worker 	(*tif)->str_expr = NULL;
2521*2d543d20SAndroid Build Coastguard Worker 	(*tif)->datum_expr = NULL;
2522*2d543d20SAndroid Build Coastguard Worker }
2523*2d543d20SAndroid Build Coastguard Worker 
cil_avrule_init(struct cil_avrule ** avrule)2524*2d543d20SAndroid Build Coastguard Worker void cil_avrule_init(struct cil_avrule **avrule)
2525*2d543d20SAndroid Build Coastguard Worker {
2526*2d543d20SAndroid Build Coastguard Worker 	*avrule = cil_malloc(sizeof(**avrule));
2527*2d543d20SAndroid Build Coastguard Worker 
2528*2d543d20SAndroid Build Coastguard Worker 	(*avrule)->is_extended = 0;
2529*2d543d20SAndroid Build Coastguard Worker 	(*avrule)->rule_kind = CIL_NONE;
2530*2d543d20SAndroid Build Coastguard Worker 	(*avrule)->src_str = NULL;
2531*2d543d20SAndroid Build Coastguard Worker 	(*avrule)->src = NULL;
2532*2d543d20SAndroid Build Coastguard Worker 	(*avrule)->tgt_str = NULL;
2533*2d543d20SAndroid Build Coastguard Worker 	(*avrule)->tgt = NULL;
2534*2d543d20SAndroid Build Coastguard Worker 	memset(&((*avrule)->perms), 0, sizeof((*avrule)->perms));
2535*2d543d20SAndroid Build Coastguard Worker }
2536*2d543d20SAndroid Build Coastguard Worker 
cil_permissionx_init(struct cil_permissionx ** permx)2537*2d543d20SAndroid Build Coastguard Worker void cil_permissionx_init(struct cil_permissionx **permx)
2538*2d543d20SAndroid Build Coastguard Worker {
2539*2d543d20SAndroid Build Coastguard Worker 	*permx = cil_malloc(sizeof(**permx));
2540*2d543d20SAndroid Build Coastguard Worker 
2541*2d543d20SAndroid Build Coastguard Worker 	cil_symtab_datum_init(&(*permx)->datum);
2542*2d543d20SAndroid Build Coastguard Worker 	(*permx)->kind = CIL_NONE;
2543*2d543d20SAndroid Build Coastguard Worker 	(*permx)->obj_str = NULL;
2544*2d543d20SAndroid Build Coastguard Worker 	(*permx)->obj = NULL;
2545*2d543d20SAndroid Build Coastguard Worker 	(*permx)->expr_str = NULL;
2546*2d543d20SAndroid Build Coastguard Worker 	(*permx)->perms = NULL;
2547*2d543d20SAndroid Build Coastguard Worker }
2548*2d543d20SAndroid Build Coastguard Worker 
cil_deny_rule_init(struct cil_deny_rule ** rule)2549*2d543d20SAndroid Build Coastguard Worker void cil_deny_rule_init(struct cil_deny_rule **rule)
2550*2d543d20SAndroid Build Coastguard Worker {
2551*2d543d20SAndroid Build Coastguard Worker 	*rule = cil_malloc(sizeof(**rule));
2552*2d543d20SAndroid Build Coastguard Worker 
2553*2d543d20SAndroid Build Coastguard Worker 	(*rule)->src_str = NULL;
2554*2d543d20SAndroid Build Coastguard Worker 	(*rule)->src = NULL;
2555*2d543d20SAndroid Build Coastguard Worker 	(*rule)->tgt_str = NULL;
2556*2d543d20SAndroid Build Coastguard Worker 	(*rule)->tgt = NULL;
2557*2d543d20SAndroid Build Coastguard Worker 	(*rule)->classperms = NULL;
2558*2d543d20SAndroid Build Coastguard Worker }
2559*2d543d20SAndroid Build Coastguard Worker 
cil_type_rule_init(struct cil_type_rule ** type_rule)2560*2d543d20SAndroid Build Coastguard Worker void cil_type_rule_init(struct cil_type_rule **type_rule)
2561*2d543d20SAndroid Build Coastguard Worker {
2562*2d543d20SAndroid Build Coastguard Worker 	*type_rule = cil_malloc(sizeof(**type_rule));
2563*2d543d20SAndroid Build Coastguard Worker 
2564*2d543d20SAndroid Build Coastguard Worker 	(*type_rule)->rule_kind = CIL_NONE;
2565*2d543d20SAndroid Build Coastguard Worker 	(*type_rule)->src_str = NULL;
2566*2d543d20SAndroid Build Coastguard Worker 	(*type_rule)->src = NULL;
2567*2d543d20SAndroid Build Coastguard Worker 	(*type_rule)->tgt_str = NULL;
2568*2d543d20SAndroid Build Coastguard Worker 	(*type_rule)->tgt = NULL;
2569*2d543d20SAndroid Build Coastguard Worker 	(*type_rule)->obj_str = NULL;
2570*2d543d20SAndroid Build Coastguard Worker 	(*type_rule)->obj = NULL;
2571*2d543d20SAndroid Build Coastguard Worker 	(*type_rule)->result_str = NULL;
2572*2d543d20SAndroid Build Coastguard Worker 	(*type_rule)->result = NULL;
2573*2d543d20SAndroid Build Coastguard Worker }
2574*2d543d20SAndroid Build Coastguard Worker 
cil_roletransition_init(struct cil_roletransition ** role_trans)2575*2d543d20SAndroid Build Coastguard Worker void cil_roletransition_init(struct cil_roletransition **role_trans)
2576*2d543d20SAndroid Build Coastguard Worker {
2577*2d543d20SAndroid Build Coastguard Worker 	*role_trans = cil_malloc(sizeof(**role_trans));
2578*2d543d20SAndroid Build Coastguard Worker 
2579*2d543d20SAndroid Build Coastguard Worker 	(*role_trans)->src_str = NULL;
2580*2d543d20SAndroid Build Coastguard Worker 	(*role_trans)->src = NULL;
2581*2d543d20SAndroid Build Coastguard Worker 	(*role_trans)->tgt_str = NULL;
2582*2d543d20SAndroid Build Coastguard Worker 	(*role_trans)->tgt = NULL;
2583*2d543d20SAndroid Build Coastguard Worker 	(*role_trans)->obj_str = NULL;
2584*2d543d20SAndroid Build Coastguard Worker 	(*role_trans)->obj = NULL;
2585*2d543d20SAndroid Build Coastguard Worker 	(*role_trans)->result_str = NULL;
2586*2d543d20SAndroid Build Coastguard Worker 	(*role_trans)->result = NULL;
2587*2d543d20SAndroid Build Coastguard Worker }
2588*2d543d20SAndroid Build Coastguard Worker 
cil_roleallow_init(struct cil_roleallow ** roleallow)2589*2d543d20SAndroid Build Coastguard Worker void cil_roleallow_init(struct cil_roleallow **roleallow)
2590*2d543d20SAndroid Build Coastguard Worker {
2591*2d543d20SAndroid Build Coastguard Worker 	*roleallow = cil_malloc(sizeof(**roleallow));
2592*2d543d20SAndroid Build Coastguard Worker 
2593*2d543d20SAndroid Build Coastguard Worker 	(*roleallow)->src_str = NULL;
2594*2d543d20SAndroid Build Coastguard Worker 	(*roleallow)->src = NULL;
2595*2d543d20SAndroid Build Coastguard Worker 	(*roleallow)->tgt_str = NULL;
2596*2d543d20SAndroid Build Coastguard Worker 	(*roleallow)->tgt = NULL;
2597*2d543d20SAndroid Build Coastguard Worker }
2598*2d543d20SAndroid Build Coastguard Worker 
cil_catset_init(struct cil_catset ** catset)2599*2d543d20SAndroid Build Coastguard Worker void cil_catset_init(struct cil_catset **catset)
2600*2d543d20SAndroid Build Coastguard Worker {
2601*2d543d20SAndroid Build Coastguard Worker 	*catset = cil_malloc(sizeof(**catset));
2602*2d543d20SAndroid Build Coastguard Worker 
2603*2d543d20SAndroid Build Coastguard Worker 	cil_symtab_datum_init(&(*catset)->datum);
2604*2d543d20SAndroid Build Coastguard Worker 	(*catset)->cats = NULL;
2605*2d543d20SAndroid Build Coastguard Worker }
2606*2d543d20SAndroid Build Coastguard Worker 
cil_senscat_init(struct cil_senscat ** senscat)2607*2d543d20SAndroid Build Coastguard Worker void cil_senscat_init(struct cil_senscat **senscat)
2608*2d543d20SAndroid Build Coastguard Worker {
2609*2d543d20SAndroid Build Coastguard Worker 	*senscat = cil_malloc(sizeof(**senscat));
2610*2d543d20SAndroid Build Coastguard Worker 
2611*2d543d20SAndroid Build Coastguard Worker 	(*senscat)->sens_str = NULL;
2612*2d543d20SAndroid Build Coastguard Worker 	(*senscat)->sens = NULL;
2613*2d543d20SAndroid Build Coastguard Worker 	(*senscat)->cats = NULL;
2614*2d543d20SAndroid Build Coastguard Worker }
2615*2d543d20SAndroid Build Coastguard Worker 
cil_cats_init(struct cil_cats ** cats)2616*2d543d20SAndroid Build Coastguard Worker void cil_cats_init(struct cil_cats **cats)
2617*2d543d20SAndroid Build Coastguard Worker {
2618*2d543d20SAndroid Build Coastguard Worker 	*cats = cil_malloc(sizeof(**cats));
2619*2d543d20SAndroid Build Coastguard Worker 
2620*2d543d20SAndroid Build Coastguard Worker 	(*cats)->evaluated = CIL_FALSE;
2621*2d543d20SAndroid Build Coastguard Worker 	(*cats)->str_expr = NULL;
2622*2d543d20SAndroid Build Coastguard Worker 	(*cats)->datum_expr = NULL;
2623*2d543d20SAndroid Build Coastguard Worker }
2624*2d543d20SAndroid Build Coastguard Worker 
cil_filecon_init(struct cil_filecon ** filecon)2625*2d543d20SAndroid Build Coastguard Worker void cil_filecon_init(struct cil_filecon **filecon)
2626*2d543d20SAndroid Build Coastguard Worker {
2627*2d543d20SAndroid Build Coastguard Worker 	*filecon = cil_malloc(sizeof(**filecon));
2628*2d543d20SAndroid Build Coastguard Worker 
2629*2d543d20SAndroid Build Coastguard Worker 	(*filecon)->path_str = NULL;
2630*2d543d20SAndroid Build Coastguard Worker 	(*filecon)->type = CIL_FILECON_ANY;
2631*2d543d20SAndroid Build Coastguard Worker 	(*filecon)->context_str = NULL;
2632*2d543d20SAndroid Build Coastguard Worker 	(*filecon)->context = NULL;
2633*2d543d20SAndroid Build Coastguard Worker }
2634*2d543d20SAndroid Build Coastguard Worker 
cil_ibpkeycon_init(struct cil_ibpkeycon ** ibpkeycon)2635*2d543d20SAndroid Build Coastguard Worker void cil_ibpkeycon_init(struct cil_ibpkeycon **ibpkeycon)
2636*2d543d20SAndroid Build Coastguard Worker {
2637*2d543d20SAndroid Build Coastguard Worker 	*ibpkeycon = cil_malloc(sizeof(**ibpkeycon));
2638*2d543d20SAndroid Build Coastguard Worker 
2639*2d543d20SAndroid Build Coastguard Worker 	(*ibpkeycon)->subnet_prefix_str = NULL;
2640*2d543d20SAndroid Build Coastguard Worker 	(*ibpkeycon)->pkey_low = 0;
2641*2d543d20SAndroid Build Coastguard Worker 	(*ibpkeycon)->pkey_high = 0;
2642*2d543d20SAndroid Build Coastguard Worker 	(*ibpkeycon)->context_str = NULL;
2643*2d543d20SAndroid Build Coastguard Worker 	(*ibpkeycon)->context = NULL;
2644*2d543d20SAndroid Build Coastguard Worker }
2645*2d543d20SAndroid Build Coastguard Worker 
cil_portcon_init(struct cil_portcon ** portcon)2646*2d543d20SAndroid Build Coastguard Worker void cil_portcon_init(struct cil_portcon **portcon)
2647*2d543d20SAndroid Build Coastguard Worker {
2648*2d543d20SAndroid Build Coastguard Worker 	*portcon = cil_malloc(sizeof(**portcon));
2649*2d543d20SAndroid Build Coastguard Worker 	(*portcon)->proto = 0;
2650*2d543d20SAndroid Build Coastguard Worker 	(*portcon)->port_low = 0;
2651*2d543d20SAndroid Build Coastguard Worker 	(*portcon)->port_high = 0;
2652*2d543d20SAndroid Build Coastguard Worker 	(*portcon)->context_str = NULL;
2653*2d543d20SAndroid Build Coastguard Worker 	(*portcon)->context = NULL;
2654*2d543d20SAndroid Build Coastguard Worker }
2655*2d543d20SAndroid Build Coastguard Worker 
cil_nodecon_init(struct cil_nodecon ** nodecon)2656*2d543d20SAndroid Build Coastguard Worker void cil_nodecon_init(struct cil_nodecon **nodecon)
2657*2d543d20SAndroid Build Coastguard Worker {
2658*2d543d20SAndroid Build Coastguard Worker 	*nodecon = cil_malloc(sizeof(**nodecon));
2659*2d543d20SAndroid Build Coastguard Worker 
2660*2d543d20SAndroid Build Coastguard Worker 	(*nodecon)->addr_str = NULL;
2661*2d543d20SAndroid Build Coastguard Worker 	(*nodecon)->addr = NULL;
2662*2d543d20SAndroid Build Coastguard Worker 	(*nodecon)->mask_str = NULL;
2663*2d543d20SAndroid Build Coastguard Worker 	(*nodecon)->mask = NULL;
2664*2d543d20SAndroid Build Coastguard Worker 	(*nodecon)->context_str = NULL;
2665*2d543d20SAndroid Build Coastguard Worker 	(*nodecon)->context = NULL;
2666*2d543d20SAndroid Build Coastguard Worker }
2667*2d543d20SAndroid Build Coastguard Worker 
cil_genfscon_init(struct cil_genfscon ** genfscon)2668*2d543d20SAndroid Build Coastguard Worker void cil_genfscon_init(struct cil_genfscon **genfscon)
2669*2d543d20SAndroid Build Coastguard Worker {
2670*2d543d20SAndroid Build Coastguard Worker 	*genfscon = cil_malloc(sizeof(**genfscon));
2671*2d543d20SAndroid Build Coastguard Worker 
2672*2d543d20SAndroid Build Coastguard Worker 	(*genfscon)->fs_str = NULL;
2673*2d543d20SAndroid Build Coastguard Worker 	(*genfscon)->path_str = NULL;
2674*2d543d20SAndroid Build Coastguard Worker 	(*genfscon)->file_type = CIL_FILECON_ANY;
2675*2d543d20SAndroid Build Coastguard Worker 	(*genfscon)->context_str = NULL;
2676*2d543d20SAndroid Build Coastguard Worker 	(*genfscon)->context = NULL;
2677*2d543d20SAndroid Build Coastguard Worker }
2678*2d543d20SAndroid Build Coastguard Worker 
cil_pirqcon_init(struct cil_pirqcon ** pirqcon)2679*2d543d20SAndroid Build Coastguard Worker void cil_pirqcon_init(struct cil_pirqcon **pirqcon)
2680*2d543d20SAndroid Build Coastguard Worker {
2681*2d543d20SAndroid Build Coastguard Worker 	*pirqcon = cil_malloc(sizeof(**pirqcon));
2682*2d543d20SAndroid Build Coastguard Worker 
2683*2d543d20SAndroid Build Coastguard Worker 	(*pirqcon)->pirq = 0;
2684*2d543d20SAndroid Build Coastguard Worker 	(*pirqcon)->context_str = NULL;
2685*2d543d20SAndroid Build Coastguard Worker 	(*pirqcon)->context = NULL;
2686*2d543d20SAndroid Build Coastguard Worker }
2687*2d543d20SAndroid Build Coastguard Worker 
cil_iomemcon_init(struct cil_iomemcon ** iomemcon)2688*2d543d20SAndroid Build Coastguard Worker void cil_iomemcon_init(struct cil_iomemcon **iomemcon)
2689*2d543d20SAndroid Build Coastguard Worker {
2690*2d543d20SAndroid Build Coastguard Worker 	*iomemcon = cil_malloc(sizeof(**iomemcon));
2691*2d543d20SAndroid Build Coastguard Worker 
2692*2d543d20SAndroid Build Coastguard Worker 	(*iomemcon)->iomem_low = 0;
2693*2d543d20SAndroid Build Coastguard Worker 	(*iomemcon)->iomem_high = 0;
2694*2d543d20SAndroid Build Coastguard Worker 	(*iomemcon)->context_str = NULL;
2695*2d543d20SAndroid Build Coastguard Worker 	(*iomemcon)->context = NULL;
2696*2d543d20SAndroid Build Coastguard Worker }
2697*2d543d20SAndroid Build Coastguard Worker 
cil_ioportcon_init(struct cil_ioportcon ** ioportcon)2698*2d543d20SAndroid Build Coastguard Worker void cil_ioportcon_init(struct cil_ioportcon **ioportcon)
2699*2d543d20SAndroid Build Coastguard Worker {
2700*2d543d20SAndroid Build Coastguard Worker 	*ioportcon = cil_malloc(sizeof(**ioportcon));
2701*2d543d20SAndroid Build Coastguard Worker 
2702*2d543d20SAndroid Build Coastguard Worker 	(*ioportcon)->context_str = NULL;
2703*2d543d20SAndroid Build Coastguard Worker 	(*ioportcon)->context = NULL;
2704*2d543d20SAndroid Build Coastguard Worker }
2705*2d543d20SAndroid Build Coastguard Worker 
cil_pcidevicecon_init(struct cil_pcidevicecon ** pcidevicecon)2706*2d543d20SAndroid Build Coastguard Worker void cil_pcidevicecon_init(struct cil_pcidevicecon **pcidevicecon)
2707*2d543d20SAndroid Build Coastguard Worker {
2708*2d543d20SAndroid Build Coastguard Worker 	*pcidevicecon = cil_malloc(sizeof(**pcidevicecon));
2709*2d543d20SAndroid Build Coastguard Worker 
2710*2d543d20SAndroid Build Coastguard Worker 	(*pcidevicecon)->dev = 0;
2711*2d543d20SAndroid Build Coastguard Worker 	(*pcidevicecon)->context_str = NULL;
2712*2d543d20SAndroid Build Coastguard Worker 	(*pcidevicecon)->context = NULL;
2713*2d543d20SAndroid Build Coastguard Worker }
2714*2d543d20SAndroid Build Coastguard Worker 
cil_devicetreecon_init(struct cil_devicetreecon ** dtcon)2715*2d543d20SAndroid Build Coastguard Worker void cil_devicetreecon_init(struct cil_devicetreecon **dtcon)
2716*2d543d20SAndroid Build Coastguard Worker {
2717*2d543d20SAndroid Build Coastguard Worker 	*dtcon = cil_malloc(sizeof(**dtcon));
2718*2d543d20SAndroid Build Coastguard Worker 
2719*2d543d20SAndroid Build Coastguard Worker 	(*dtcon)->path = NULL;
2720*2d543d20SAndroid Build Coastguard Worker 	(*dtcon)->context_str = NULL;
2721*2d543d20SAndroid Build Coastguard Worker 	(*dtcon)->context = NULL;
2722*2d543d20SAndroid Build Coastguard Worker }
2723*2d543d20SAndroid Build Coastguard Worker 
cil_fsuse_init(struct cil_fsuse ** fsuse)2724*2d543d20SAndroid Build Coastguard Worker void cil_fsuse_init(struct cil_fsuse **fsuse)
2725*2d543d20SAndroid Build Coastguard Worker {
2726*2d543d20SAndroid Build Coastguard Worker 	*fsuse = cil_malloc(sizeof(**fsuse));
2727*2d543d20SAndroid Build Coastguard Worker 
2728*2d543d20SAndroid Build Coastguard Worker 	(*fsuse)->type = 0;
2729*2d543d20SAndroid Build Coastguard Worker 	(*fsuse)->fs_str = NULL;
2730*2d543d20SAndroid Build Coastguard Worker 	(*fsuse)->context_str = NULL;
2731*2d543d20SAndroid Build Coastguard Worker 	(*fsuse)->context = NULL;
2732*2d543d20SAndroid Build Coastguard Worker }
2733*2d543d20SAndroid Build Coastguard Worker 
cil_constrain_init(struct cil_constrain ** constrain)2734*2d543d20SAndroid Build Coastguard Worker void cil_constrain_init(struct cil_constrain **constrain)
2735*2d543d20SAndroid Build Coastguard Worker {
2736*2d543d20SAndroid Build Coastguard Worker 	*constrain = cil_malloc(sizeof(**constrain));
2737*2d543d20SAndroid Build Coastguard Worker 
2738*2d543d20SAndroid Build Coastguard Worker 	(*constrain)->classperms = NULL;
2739*2d543d20SAndroid Build Coastguard Worker 	(*constrain)->str_expr = NULL;
2740*2d543d20SAndroid Build Coastguard Worker 	(*constrain)->datum_expr = NULL;
2741*2d543d20SAndroid Build Coastguard Worker }
2742*2d543d20SAndroid Build Coastguard Worker 
cil_validatetrans_init(struct cil_validatetrans ** validtrans)2743*2d543d20SAndroid Build Coastguard Worker void cil_validatetrans_init(struct cil_validatetrans **validtrans)
2744*2d543d20SAndroid Build Coastguard Worker {
2745*2d543d20SAndroid Build Coastguard Worker 	*validtrans = cil_malloc(sizeof(**validtrans));
2746*2d543d20SAndroid Build Coastguard Worker 
2747*2d543d20SAndroid Build Coastguard Worker 	(*validtrans)->class_str = NULL;
2748*2d543d20SAndroid Build Coastguard Worker 	(*validtrans)->class = NULL;
2749*2d543d20SAndroid Build Coastguard Worker 	(*validtrans)->str_expr = NULL;
2750*2d543d20SAndroid Build Coastguard Worker 	(*validtrans)->datum_expr = NULL;
2751*2d543d20SAndroid Build Coastguard Worker }
2752*2d543d20SAndroid Build Coastguard Worker 
cil_ipaddr_init(struct cil_ipaddr ** ipaddr)2753*2d543d20SAndroid Build Coastguard Worker void cil_ipaddr_init(struct cil_ipaddr **ipaddr)
2754*2d543d20SAndroid Build Coastguard Worker {
2755*2d543d20SAndroid Build Coastguard Worker 	*ipaddr = cil_malloc(sizeof(**ipaddr));
2756*2d543d20SAndroid Build Coastguard Worker 
2757*2d543d20SAndroid Build Coastguard Worker 	cil_symtab_datum_init(&(*ipaddr)->datum);
2758*2d543d20SAndroid Build Coastguard Worker 	memset(&(*ipaddr)->ip, 0, sizeof((*ipaddr)->ip));
2759*2d543d20SAndroid Build Coastguard Worker }
2760*2d543d20SAndroid Build Coastguard Worker 
cil_perm_init(struct cil_perm ** perm)2761*2d543d20SAndroid Build Coastguard Worker void cil_perm_init(struct cil_perm **perm)
2762*2d543d20SAndroid Build Coastguard Worker {
2763*2d543d20SAndroid Build Coastguard Worker 	*perm = cil_malloc(sizeof(**perm));
2764*2d543d20SAndroid Build Coastguard Worker 
2765*2d543d20SAndroid Build Coastguard Worker 	cil_symtab_datum_init(&(*perm)->datum);
2766*2d543d20SAndroid Build Coastguard Worker 	(*perm)->value = 0;
2767*2d543d20SAndroid Build Coastguard Worker 	(*perm)->classperms = NULL;
2768*2d543d20SAndroid Build Coastguard Worker }
2769*2d543d20SAndroid Build Coastguard Worker 
cil_classpermission_init(struct cil_classpermission ** cp)2770*2d543d20SAndroid Build Coastguard Worker void cil_classpermission_init(struct cil_classpermission **cp)
2771*2d543d20SAndroid Build Coastguard Worker {
2772*2d543d20SAndroid Build Coastguard Worker 	*cp = cil_malloc(sizeof(**cp));
2773*2d543d20SAndroid Build Coastguard Worker 
2774*2d543d20SAndroid Build Coastguard Worker 	cil_symtab_datum_init(&(*cp)->datum);
2775*2d543d20SAndroid Build Coastguard Worker 	(*cp)->classperms = NULL;
2776*2d543d20SAndroid Build Coastguard Worker }
2777*2d543d20SAndroid Build Coastguard Worker 
cil_classpermissionset_init(struct cil_classpermissionset ** cps)2778*2d543d20SAndroid Build Coastguard Worker void cil_classpermissionset_init(struct cil_classpermissionset **cps)
2779*2d543d20SAndroid Build Coastguard Worker {
2780*2d543d20SAndroid Build Coastguard Worker 	*cps = cil_malloc(sizeof(**cps));
2781*2d543d20SAndroid Build Coastguard Worker 
2782*2d543d20SAndroid Build Coastguard Worker 	(*cps)->set_str = NULL;
2783*2d543d20SAndroid Build Coastguard Worker 	(*cps)->set = NULL;
2784*2d543d20SAndroid Build Coastguard Worker 	(*cps)->classperms = NULL;
2785*2d543d20SAndroid Build Coastguard Worker }
2786*2d543d20SAndroid Build Coastguard Worker 
cil_classperms_set_init(struct cil_classperms_set ** cp_set)2787*2d543d20SAndroid Build Coastguard Worker void cil_classperms_set_init(struct cil_classperms_set **cp_set)
2788*2d543d20SAndroid Build Coastguard Worker {
2789*2d543d20SAndroid Build Coastguard Worker 	*cp_set = cil_malloc(sizeof(**cp_set));
2790*2d543d20SAndroid Build Coastguard Worker 	(*cp_set)->set_str = NULL;
2791*2d543d20SAndroid Build Coastguard Worker 	(*cp_set)->set = NULL;
2792*2d543d20SAndroid Build Coastguard Worker }
2793*2d543d20SAndroid Build Coastguard Worker 
cil_classperms_init(struct cil_classperms ** cp)2794*2d543d20SAndroid Build Coastguard Worker void cil_classperms_init(struct cil_classperms **cp)
2795*2d543d20SAndroid Build Coastguard Worker {
2796*2d543d20SAndroid Build Coastguard Worker 	*cp = cil_malloc(sizeof(**cp));
2797*2d543d20SAndroid Build Coastguard Worker 	(*cp)->class_str = NULL;
2798*2d543d20SAndroid Build Coastguard Worker 	(*cp)->class = NULL;
2799*2d543d20SAndroid Build Coastguard Worker 	(*cp)->perm_strs = NULL;
2800*2d543d20SAndroid Build Coastguard Worker 	(*cp)->perms = NULL;
2801*2d543d20SAndroid Build Coastguard Worker }
2802*2d543d20SAndroid Build Coastguard Worker 
cil_classmapping_init(struct cil_classmapping ** mapping)2803*2d543d20SAndroid Build Coastguard Worker void cil_classmapping_init(struct cil_classmapping **mapping)
2804*2d543d20SAndroid Build Coastguard Worker {
2805*2d543d20SAndroid Build Coastguard Worker 	*mapping = cil_malloc(sizeof(**mapping));
2806*2d543d20SAndroid Build Coastguard Worker 
2807*2d543d20SAndroid Build Coastguard Worker 	(*mapping)->map_class_str = NULL;
2808*2d543d20SAndroid Build Coastguard Worker 	(*mapping)->map_class = NULL;
2809*2d543d20SAndroid Build Coastguard Worker 	(*mapping)->map_perm_str = NULL;
2810*2d543d20SAndroid Build Coastguard Worker 	(*mapping)->map_perm = NULL;
2811*2d543d20SAndroid Build Coastguard Worker 	(*mapping)->classperms = NULL;
2812*2d543d20SAndroid Build Coastguard Worker }
2813*2d543d20SAndroid Build Coastguard Worker 
cil_user_init(struct cil_user ** user)2814*2d543d20SAndroid Build Coastguard Worker void cil_user_init(struct cil_user **user)
2815*2d543d20SAndroid Build Coastguard Worker {
2816*2d543d20SAndroid Build Coastguard Worker 	*user = cil_malloc(sizeof(**user));
2817*2d543d20SAndroid Build Coastguard Worker 
2818*2d543d20SAndroid Build Coastguard Worker 	cil_symtab_datum_init(&(*user)->datum);
2819*2d543d20SAndroid Build Coastguard Worker 	(*user)->bounds = NULL;
2820*2d543d20SAndroid Build Coastguard Worker 	(*user)->roles = NULL;
2821*2d543d20SAndroid Build Coastguard Worker 	(*user)->dftlevel = NULL;
2822*2d543d20SAndroid Build Coastguard Worker 	(*user)->range = NULL;
2823*2d543d20SAndroid Build Coastguard Worker 	(*user)->value = 0;
2824*2d543d20SAndroid Build Coastguard Worker }
2825*2d543d20SAndroid Build Coastguard Worker 
cil_userattribute_init(struct cil_userattribute ** attr)2826*2d543d20SAndroid Build Coastguard Worker void cil_userattribute_init(struct cil_userattribute **attr)
2827*2d543d20SAndroid Build Coastguard Worker {
2828*2d543d20SAndroid Build Coastguard Worker 	*attr = cil_malloc(sizeof(**attr));
2829*2d543d20SAndroid Build Coastguard Worker 
2830*2d543d20SAndroid Build Coastguard Worker 	cil_symtab_datum_init(&(*attr)->datum);
2831*2d543d20SAndroid Build Coastguard Worker 
2832*2d543d20SAndroid Build Coastguard Worker 	(*attr)->expr_list = NULL;
2833*2d543d20SAndroid Build Coastguard Worker 	(*attr)->users = NULL;
2834*2d543d20SAndroid Build Coastguard Worker }
2835*2d543d20SAndroid Build Coastguard Worker 
cil_userattributeset_init(struct cil_userattributeset ** attrset)2836*2d543d20SAndroid Build Coastguard Worker void cil_userattributeset_init(struct cil_userattributeset **attrset)
2837*2d543d20SAndroid Build Coastguard Worker {
2838*2d543d20SAndroid Build Coastguard Worker 	*attrset = cil_malloc(sizeof(**attrset));
2839*2d543d20SAndroid Build Coastguard Worker 
2840*2d543d20SAndroid Build Coastguard Worker 	(*attrset)->attr_str = NULL;
2841*2d543d20SAndroid Build Coastguard Worker 	(*attrset)->attr = NULL;
2842*2d543d20SAndroid Build Coastguard Worker 	(*attrset)->str_expr = NULL;
2843*2d543d20SAndroid Build Coastguard Worker 	(*attrset)->datum_expr = NULL;
2844*2d543d20SAndroid Build Coastguard Worker }
2845*2d543d20SAndroid Build Coastguard Worker 
cil_userlevel_init(struct cil_userlevel ** usrlvl)2846*2d543d20SAndroid Build Coastguard Worker void cil_userlevel_init(struct cil_userlevel **usrlvl)
2847*2d543d20SAndroid Build Coastguard Worker {
2848*2d543d20SAndroid Build Coastguard Worker 	*usrlvl = cil_malloc(sizeof(**usrlvl));
2849*2d543d20SAndroid Build Coastguard Worker 
2850*2d543d20SAndroid Build Coastguard Worker 	(*usrlvl)->user_str = NULL;
2851*2d543d20SAndroid Build Coastguard Worker 	(*usrlvl)->user = NULL;
2852*2d543d20SAndroid Build Coastguard Worker 	(*usrlvl)->level_str = NULL;
2853*2d543d20SAndroid Build Coastguard Worker 	(*usrlvl)->level = NULL;
2854*2d543d20SAndroid Build Coastguard Worker }
2855*2d543d20SAndroid Build Coastguard Worker 
cil_userrange_init(struct cil_userrange ** userrange)2856*2d543d20SAndroid Build Coastguard Worker void cil_userrange_init(struct cil_userrange **userrange)
2857*2d543d20SAndroid Build Coastguard Worker {
2858*2d543d20SAndroid Build Coastguard Worker 	*userrange = cil_malloc(sizeof(**userrange));
2859*2d543d20SAndroid Build Coastguard Worker 
2860*2d543d20SAndroid Build Coastguard Worker 	(*userrange)->user_str = NULL;
2861*2d543d20SAndroid Build Coastguard Worker 	(*userrange)->user = NULL;
2862*2d543d20SAndroid Build Coastguard Worker 	(*userrange)->range_str = NULL;
2863*2d543d20SAndroid Build Coastguard Worker 	(*userrange)->range = NULL;
2864*2d543d20SAndroid Build Coastguard Worker }
2865*2d543d20SAndroid Build Coastguard Worker 
cil_role_init(struct cil_role ** role)2866*2d543d20SAndroid Build Coastguard Worker void cil_role_init(struct cil_role **role)
2867*2d543d20SAndroid Build Coastguard Worker {
2868*2d543d20SAndroid Build Coastguard Worker 	*role = cil_malloc(sizeof(**role));
2869*2d543d20SAndroid Build Coastguard Worker 
2870*2d543d20SAndroid Build Coastguard Worker 	cil_symtab_datum_init(&(*role)->datum);
2871*2d543d20SAndroid Build Coastguard Worker 	(*role)->bounds = NULL;
2872*2d543d20SAndroid Build Coastguard Worker 	(*role)->types = NULL;
2873*2d543d20SAndroid Build Coastguard Worker 	(*role)->value = 0;
2874*2d543d20SAndroid Build Coastguard Worker }
2875*2d543d20SAndroid Build Coastguard Worker 
cil_type_init(struct cil_type ** type)2876*2d543d20SAndroid Build Coastguard Worker void cil_type_init(struct cil_type **type)
2877*2d543d20SAndroid Build Coastguard Worker {
2878*2d543d20SAndroid Build Coastguard Worker 	*type = cil_malloc(sizeof(**type));
2879*2d543d20SAndroid Build Coastguard Worker 
2880*2d543d20SAndroid Build Coastguard Worker 	cil_symtab_datum_init(&(*type)->datum);
2881*2d543d20SAndroid Build Coastguard Worker 	(*type)->bounds = NULL;
2882*2d543d20SAndroid Build Coastguard Worker 	(*type)->value = 0;
2883*2d543d20SAndroid Build Coastguard Worker }
2884*2d543d20SAndroid Build Coastguard Worker 
cil_cat_init(struct cil_cat ** cat)2885*2d543d20SAndroid Build Coastguard Worker void cil_cat_init(struct cil_cat **cat)
2886*2d543d20SAndroid Build Coastguard Worker {
2887*2d543d20SAndroid Build Coastguard Worker 	*cat = cil_malloc(sizeof(**cat));
2888*2d543d20SAndroid Build Coastguard Worker 
2889*2d543d20SAndroid Build Coastguard Worker 	cil_symtab_datum_init(&(*cat)->datum);
2890*2d543d20SAndroid Build Coastguard Worker 	(*cat)->ordered = CIL_FALSE;
2891*2d543d20SAndroid Build Coastguard Worker 	(*cat)->value = 0;
2892*2d543d20SAndroid Build Coastguard Worker }
2893*2d543d20SAndroid Build Coastguard Worker 
cil_args_init(struct cil_args ** args)2894*2d543d20SAndroid Build Coastguard Worker void cil_args_init(struct cil_args **args)
2895*2d543d20SAndroid Build Coastguard Worker {
2896*2d543d20SAndroid Build Coastguard Worker 	*args = cil_malloc(sizeof(**args));
2897*2d543d20SAndroid Build Coastguard Worker 	(*args)->arg_str = NULL;
2898*2d543d20SAndroid Build Coastguard Worker 	(*args)->arg = NULL;
2899*2d543d20SAndroid Build Coastguard Worker 	(*args)->param_str = NULL;
2900*2d543d20SAndroid Build Coastguard Worker 	(*args)->flavor = CIL_NONE;
2901*2d543d20SAndroid Build Coastguard Worker }
2902*2d543d20SAndroid Build Coastguard Worker 
cil_call_init(struct cil_call ** call)2903*2d543d20SAndroid Build Coastguard Worker void cil_call_init(struct cil_call **call)
2904*2d543d20SAndroid Build Coastguard Worker {
2905*2d543d20SAndroid Build Coastguard Worker 	*call = cil_malloc(sizeof(**call));
2906*2d543d20SAndroid Build Coastguard Worker 
2907*2d543d20SAndroid Build Coastguard Worker 	(*call)->macro_str = NULL;
2908*2d543d20SAndroid Build Coastguard Worker 	(*call)->macro = NULL;
2909*2d543d20SAndroid Build Coastguard Worker 	(*call)->args_tree = NULL;
2910*2d543d20SAndroid Build Coastguard Worker 	(*call)->args = NULL;
2911*2d543d20SAndroid Build Coastguard Worker 	(*call)->copied = 0;
2912*2d543d20SAndroid Build Coastguard Worker }
2913*2d543d20SAndroid Build Coastguard Worker 
cil_optional_init(struct cil_optional ** optional)2914*2d543d20SAndroid Build Coastguard Worker void cil_optional_init(struct cil_optional **optional)
2915*2d543d20SAndroid Build Coastguard Worker {
2916*2d543d20SAndroid Build Coastguard Worker 	*optional = cil_malloc(sizeof(**optional));
2917*2d543d20SAndroid Build Coastguard Worker 	cil_symtab_datum_init(&(*optional)->datum);
2918*2d543d20SAndroid Build Coastguard Worker }
2919*2d543d20SAndroid Build Coastguard Worker 
cil_param_init(struct cil_param ** param)2920*2d543d20SAndroid Build Coastguard Worker void cil_param_init(struct cil_param **param)
2921*2d543d20SAndroid Build Coastguard Worker {
2922*2d543d20SAndroid Build Coastguard Worker 	*param = cil_malloc(sizeof(**param));
2923*2d543d20SAndroid Build Coastguard Worker 
2924*2d543d20SAndroid Build Coastguard Worker 	(*param)->str = NULL;
2925*2d543d20SAndroid Build Coastguard Worker 	(*param)->flavor = CIL_NONE;
2926*2d543d20SAndroid Build Coastguard Worker }
2927*2d543d20SAndroid Build Coastguard Worker 
cil_macro_init(struct cil_macro ** macro)2928*2d543d20SAndroid Build Coastguard Worker void cil_macro_init(struct cil_macro **macro)
2929*2d543d20SAndroid Build Coastguard Worker {
2930*2d543d20SAndroid Build Coastguard Worker 	*macro = cil_malloc(sizeof(**macro));
2931*2d543d20SAndroid Build Coastguard Worker 
2932*2d543d20SAndroid Build Coastguard Worker 	cil_symtab_datum_init(&(*macro)->datum);
2933*2d543d20SAndroid Build Coastguard Worker 	cil_symtab_array_init((*macro)->symtab, cil_sym_sizes[CIL_SYM_ARRAY_MACRO]);
2934*2d543d20SAndroid Build Coastguard Worker 	(*macro)->params = NULL;
2935*2d543d20SAndroid Build Coastguard Worker }
2936*2d543d20SAndroid Build Coastguard Worker 
cil_policycap_init(struct cil_policycap ** policycap)2937*2d543d20SAndroid Build Coastguard Worker void cil_policycap_init(struct cil_policycap **policycap)
2938*2d543d20SAndroid Build Coastguard Worker {
2939*2d543d20SAndroid Build Coastguard Worker 	*policycap = cil_malloc(sizeof(**policycap));
2940*2d543d20SAndroid Build Coastguard Worker 
2941*2d543d20SAndroid Build Coastguard Worker 	cil_symtab_datum_init(&(*policycap)->datum);
2942*2d543d20SAndroid Build Coastguard Worker }
2943*2d543d20SAndroid Build Coastguard Worker 
cil_bounds_init(struct cil_bounds ** bounds)2944*2d543d20SAndroid Build Coastguard Worker void cil_bounds_init(struct cil_bounds **bounds)
2945*2d543d20SAndroid Build Coastguard Worker {
2946*2d543d20SAndroid Build Coastguard Worker 	*bounds = cil_malloc(sizeof(**bounds));
2947*2d543d20SAndroid Build Coastguard Worker 
2948*2d543d20SAndroid Build Coastguard Worker 	(*bounds)->parent_str = NULL;
2949*2d543d20SAndroid Build Coastguard Worker 	(*bounds)->parent = NULL;
2950*2d543d20SAndroid Build Coastguard Worker 	(*bounds)->child_str = NULL;
2951*2d543d20SAndroid Build Coastguard Worker 	(*bounds)->child = NULL;
2952*2d543d20SAndroid Build Coastguard Worker }
2953*2d543d20SAndroid Build Coastguard Worker 
cil_default_init(struct cil_default ** def)2954*2d543d20SAndroid Build Coastguard Worker void cil_default_init(struct cil_default **def)
2955*2d543d20SAndroid Build Coastguard Worker {
2956*2d543d20SAndroid Build Coastguard Worker 	*def = cil_malloc(sizeof(**def));
2957*2d543d20SAndroid Build Coastguard Worker 
2958*2d543d20SAndroid Build Coastguard Worker 	(*def)->flavor = CIL_NONE;
2959*2d543d20SAndroid Build Coastguard Worker 	(*def)->class_strs = NULL;
2960*2d543d20SAndroid Build Coastguard Worker 	(*def)->class_datums = NULL;
2961*2d543d20SAndroid Build Coastguard Worker }
2962*2d543d20SAndroid Build Coastguard Worker 
cil_defaultrange_init(struct cil_defaultrange ** def)2963*2d543d20SAndroid Build Coastguard Worker void cil_defaultrange_init(struct cil_defaultrange **def)
2964*2d543d20SAndroid Build Coastguard Worker {
2965*2d543d20SAndroid Build Coastguard Worker 	*def = cil_malloc(sizeof(**def));
2966*2d543d20SAndroid Build Coastguard Worker 
2967*2d543d20SAndroid Build Coastguard Worker 	(*def)->class_strs = NULL;
2968*2d543d20SAndroid Build Coastguard Worker 	(*def)->class_datums = NULL;
2969*2d543d20SAndroid Build Coastguard Worker }
2970*2d543d20SAndroid Build Coastguard Worker 
cil_handleunknown_init(struct cil_handleunknown ** unk)2971*2d543d20SAndroid Build Coastguard Worker void cil_handleunknown_init(struct cil_handleunknown **unk)
2972*2d543d20SAndroid Build Coastguard Worker {
2973*2d543d20SAndroid Build Coastguard Worker 	*unk = cil_malloc(sizeof(**unk));
2974*2d543d20SAndroid Build Coastguard Worker }
2975*2d543d20SAndroid Build Coastguard Worker 
cil_mls_init(struct cil_mls ** mls)2976*2d543d20SAndroid Build Coastguard Worker void cil_mls_init(struct cil_mls **mls)
2977*2d543d20SAndroid Build Coastguard Worker {
2978*2d543d20SAndroid Build Coastguard Worker 	*mls = cil_malloc(sizeof(**mls));
2979*2d543d20SAndroid Build Coastguard Worker 	(*mls)->value = 0;
2980*2d543d20SAndroid Build Coastguard Worker }
2981*2d543d20SAndroid Build Coastguard Worker 
cil_src_info_init(struct cil_src_info ** info)2982*2d543d20SAndroid Build Coastguard Worker void cil_src_info_init(struct cil_src_info **info)
2983*2d543d20SAndroid Build Coastguard Worker {
2984*2d543d20SAndroid Build Coastguard Worker 	*info = cil_malloc(sizeof(**info));
2985*2d543d20SAndroid Build Coastguard Worker 	(*info)->kind = NULL;
2986*2d543d20SAndroid Build Coastguard Worker 	(*info)->hll_line = 0;
2987*2d543d20SAndroid Build Coastguard Worker 	(*info)->path = NULL;
2988*2d543d20SAndroid Build Coastguard Worker }
2989