xref: /aosp_15_r20/external/selinux/checkpolicy/policy_parse.y (revision 2d543d20722ada2425b5bdab9d0d1d29470e7bba)
1*2d543d20SAndroid Build Coastguard Worker 
2*2d543d20SAndroid Build Coastguard Worker /*
3*2d543d20SAndroid Build Coastguard Worker  * Author : Stephen Smalley, <[email protected]>
4*2d543d20SAndroid Build Coastguard Worker  */
5*2d543d20SAndroid Build Coastguard Worker 
6*2d543d20SAndroid Build Coastguard Worker /*
7*2d543d20SAndroid Build Coastguard Worker  * Updated: Trusted Computer Solutions, Inc. <[email protected]>
8*2d543d20SAndroid Build Coastguard Worker  *
9*2d543d20SAndroid Build Coastguard Worker  *	Support for enhanced MLS infrastructure.
10*2d543d20SAndroid Build Coastguard Worker  *
11*2d543d20SAndroid Build Coastguard Worker  * Updated: David Caplan, <[email protected]>
12*2d543d20SAndroid Build Coastguard Worker  *
13*2d543d20SAndroid Build Coastguard Worker  * 	Added conditional policy language extensions
14*2d543d20SAndroid Build Coastguard Worker  *
15*2d543d20SAndroid Build Coastguard Worker  * Updated: Joshua Brindle <[email protected]>
16*2d543d20SAndroid Build Coastguard Worker  *	    Karl MacMillan <[email protected]>
17*2d543d20SAndroid Build Coastguard Worker  *          Jason Tang     <[email protected]>
18*2d543d20SAndroid Build Coastguard Worker  *
19*2d543d20SAndroid Build Coastguard Worker  *	Added support for binary policy modules
20*2d543d20SAndroid Build Coastguard Worker  *
21*2d543d20SAndroid Build Coastguard Worker  * Copyright (C) 2004-2005 Trusted Computer Solutions, Inc.
22*2d543d20SAndroid Build Coastguard Worker  * Copyright (C) 2003 - 2008 Tresys Technology, LLC
23*2d543d20SAndroid Build Coastguard Worker  * Copyright (C) 2007 Red Hat Inc.
24*2d543d20SAndroid Build Coastguard Worker  * Copyright (C) 2017 Mellanox Technologies Inc.
25*2d543d20SAndroid Build Coastguard Worker  *	This program is free software; you can redistribute it and/or modify
26*2d543d20SAndroid Build Coastguard Worker  *  	it under the terms of the GNU General Public License as published by
27*2d543d20SAndroid Build Coastguard Worker  *	the Free Software Foundation, version 2.
28*2d543d20SAndroid Build Coastguard Worker  */
29*2d543d20SAndroid Build Coastguard Worker 
30*2d543d20SAndroid Build Coastguard Worker /* FLASK */
31*2d543d20SAndroid Build Coastguard Worker 
32*2d543d20SAndroid Build Coastguard Worker %{
33*2d543d20SAndroid Build Coastguard Worker #include <sys/types.h>
34*2d543d20SAndroid Build Coastguard Worker #include <assert.h>
35*2d543d20SAndroid Build Coastguard Worker #include <stdarg.h>
36*2d543d20SAndroid Build Coastguard Worker #include <stdint.h>
37*2d543d20SAndroid Build Coastguard Worker #include <stdio.h>
38*2d543d20SAndroid Build Coastguard Worker #include <stdlib.h>
39*2d543d20SAndroid Build Coastguard Worker #include <string.h>
40*2d543d20SAndroid Build Coastguard Worker #include <sys/socket.h>
41*2d543d20SAndroid Build Coastguard Worker #include <netinet/in.h>
42*2d543d20SAndroid Build Coastguard Worker #include <arpa/inet.h>
43*2d543d20SAndroid Build Coastguard Worker #include <stdlib.h>
44*2d543d20SAndroid Build Coastguard Worker 
45*2d543d20SAndroid Build Coastguard Worker #include <sepol/policydb/expand.h>
46*2d543d20SAndroid Build Coastguard Worker #include <sepol/policydb/policydb.h>
47*2d543d20SAndroid Build Coastguard Worker #include <sepol/policydb/services.h>
48*2d543d20SAndroid Build Coastguard Worker #include <sepol/policydb/conditional.h>
49*2d543d20SAndroid Build Coastguard Worker #include <sepol/policydb/hierarchy.h>
50*2d543d20SAndroid Build Coastguard Worker #include <sepol/policydb/polcaps.h>
51*2d543d20SAndroid Build Coastguard Worker #include "queue.h"
52*2d543d20SAndroid Build Coastguard Worker #include "module_compiler.h"
53*2d543d20SAndroid Build Coastguard Worker #include "policy_define.h"
54*2d543d20SAndroid Build Coastguard Worker 
55*2d543d20SAndroid Build Coastguard Worker extern policydb_t *policydbp;
56*2d543d20SAndroid Build Coastguard Worker extern unsigned int pass;
57*2d543d20SAndroid Build Coastguard Worker 
58*2d543d20SAndroid Build Coastguard Worker extern char yytext[];
59*2d543d20SAndroid Build Coastguard Worker extern int yylex(void);
60*2d543d20SAndroid Build Coastguard Worker extern int yywarn(const char *msg);
61*2d543d20SAndroid Build Coastguard Worker extern int yyerror(const char *msg);
62*2d543d20SAndroid Build Coastguard Worker 
63*2d543d20SAndroid Build Coastguard Worker typedef int (* require_func_t)(int pass);
64*2d543d20SAndroid Build Coastguard Worker 
65*2d543d20SAndroid Build Coastguard Worker %}
66*2d543d20SAndroid Build Coastguard Worker 
67*2d543d20SAndroid Build Coastguard Worker %union {
68*2d543d20SAndroid Build Coastguard Worker 	unsigned int val;
69*2d543d20SAndroid Build Coastguard Worker 	uint64_t val64;
70*2d543d20SAndroid Build Coastguard Worker 	uintptr_t valptr;
71*2d543d20SAndroid Build Coastguard Worker 	void *ptr;
72*2d543d20SAndroid Build Coastguard Worker         require_func_t require_func;
73*2d543d20SAndroid Build Coastguard Worker }
74*2d543d20SAndroid Build Coastguard Worker 
75*2d543d20SAndroid Build Coastguard Worker %type <ptr> cond_expr cond_expr_prim cond_pol_list cond_else
76*2d543d20SAndroid Build Coastguard Worker %type <ptr> cond_allow_def cond_auditallow_def cond_auditdeny_def cond_dontaudit_def
77*2d543d20SAndroid Build Coastguard Worker %type <ptr> cond_transition_def cond_te_avtab_def cond_rule_def
78*2d543d20SAndroid Build Coastguard Worker %type <valptr> cexpr cexpr_prim op role_mls_op
79*2d543d20SAndroid Build Coastguard Worker %type <val> ipv4_addr_def number
80*2d543d20SAndroid Build Coastguard Worker %type <val64> number64
81*2d543d20SAndroid Build Coastguard Worker %type <require_func> require_decl_def
82*2d543d20SAndroid Build Coastguard Worker 
83*2d543d20SAndroid Build Coastguard Worker %token PATH
84*2d543d20SAndroid Build Coastguard Worker %token QPATH
85*2d543d20SAndroid Build Coastguard Worker %token FILENAME
86*2d543d20SAndroid Build Coastguard Worker %token COMMON
87*2d543d20SAndroid Build Coastguard Worker %token CLASS
88*2d543d20SAndroid Build Coastguard Worker %token CONSTRAIN
89*2d543d20SAndroid Build Coastguard Worker %token VALIDATETRANS
90*2d543d20SAndroid Build Coastguard Worker %token INHERITS
91*2d543d20SAndroid Build Coastguard Worker %token SID
92*2d543d20SAndroid Build Coastguard Worker %token ROLE
93*2d543d20SAndroid Build Coastguard Worker %token ROLEATTRIBUTE
94*2d543d20SAndroid Build Coastguard Worker %token ATTRIBUTE_ROLE
95*2d543d20SAndroid Build Coastguard Worker %token ROLES
96*2d543d20SAndroid Build Coastguard Worker %token TYPEALIAS
97*2d543d20SAndroid Build Coastguard Worker %token TYPEATTRIBUTE
98*2d543d20SAndroid Build Coastguard Worker %token TYPEBOUNDS
99*2d543d20SAndroid Build Coastguard Worker %token TYPE
100*2d543d20SAndroid Build Coastguard Worker %token TYPES
101*2d543d20SAndroid Build Coastguard Worker %token ALIAS
102*2d543d20SAndroid Build Coastguard Worker %token ATTRIBUTE
103*2d543d20SAndroid Build Coastguard Worker %token EXPANDATTRIBUTE
104*2d543d20SAndroid Build Coastguard Worker %token BOOL
105*2d543d20SAndroid Build Coastguard Worker %token TUNABLE
106*2d543d20SAndroid Build Coastguard Worker %token IF
107*2d543d20SAndroid Build Coastguard Worker %token ELSE
108*2d543d20SAndroid Build Coastguard Worker %token TYPE_TRANSITION
109*2d543d20SAndroid Build Coastguard Worker %token TYPE_MEMBER
110*2d543d20SAndroid Build Coastguard Worker %token TYPE_CHANGE
111*2d543d20SAndroid Build Coastguard Worker %token ROLE_TRANSITION
112*2d543d20SAndroid Build Coastguard Worker %token RANGE_TRANSITION
113*2d543d20SAndroid Build Coastguard Worker %token SENSITIVITY
114*2d543d20SAndroid Build Coastguard Worker %token DOMINANCE
115*2d543d20SAndroid Build Coastguard Worker %token DOM DOMBY INCOMP
116*2d543d20SAndroid Build Coastguard Worker %token CATEGORY
117*2d543d20SAndroid Build Coastguard Worker %token LEVEL
118*2d543d20SAndroid Build Coastguard Worker %token RANGE
119*2d543d20SAndroid Build Coastguard Worker %token MLSCONSTRAIN
120*2d543d20SAndroid Build Coastguard Worker %token MLSVALIDATETRANS
121*2d543d20SAndroid Build Coastguard Worker %token USER
122*2d543d20SAndroid Build Coastguard Worker %token NEVERALLOW
123*2d543d20SAndroid Build Coastguard Worker %token ALLOW
124*2d543d20SAndroid Build Coastguard Worker %token AUDITALLOW
125*2d543d20SAndroid Build Coastguard Worker %token AUDITDENY
126*2d543d20SAndroid Build Coastguard Worker %token DONTAUDIT
127*2d543d20SAndroid Build Coastguard Worker %token ALLOWXPERM
128*2d543d20SAndroid Build Coastguard Worker %token AUDITALLOWXPERM
129*2d543d20SAndroid Build Coastguard Worker %token DONTAUDITXPERM
130*2d543d20SAndroid Build Coastguard Worker %token NEVERALLOWXPERM
131*2d543d20SAndroid Build Coastguard Worker %token SOURCE
132*2d543d20SAndroid Build Coastguard Worker %token TARGET
133*2d543d20SAndroid Build Coastguard Worker %token SAMEUSER
134*2d543d20SAndroid Build Coastguard Worker %token FSCON PORTCON NETIFCON NODECON
135*2d543d20SAndroid Build Coastguard Worker %token IBPKEYCON
136*2d543d20SAndroid Build Coastguard Worker %token IBENDPORTCON
137*2d543d20SAndroid Build Coastguard Worker %token PIRQCON IOMEMCON IOPORTCON PCIDEVICECON DEVICETREECON
138*2d543d20SAndroid Build Coastguard Worker %token FSUSEXATTR FSUSETASK FSUSETRANS
139*2d543d20SAndroid Build Coastguard Worker %token GENFSCON
140*2d543d20SAndroid Build Coastguard Worker %token U1 U2 U3 R1 R2 R3 T1 T2 T3 L1 L2 H1 H2
141*2d543d20SAndroid Build Coastguard Worker %token NOT AND OR XOR
142*2d543d20SAndroid Build Coastguard Worker %token CTRUE CFALSE
143*2d543d20SAndroid Build Coastguard Worker %token IDENTIFIER
144*2d543d20SAndroid Build Coastguard Worker %token NUMBER
145*2d543d20SAndroid Build Coastguard Worker %token EQUALS
146*2d543d20SAndroid Build Coastguard Worker %token NOTEQUAL
147*2d543d20SAndroid Build Coastguard Worker %token IPV4_ADDR
148*2d543d20SAndroid Build Coastguard Worker %token IPV4_CIDR
149*2d543d20SAndroid Build Coastguard Worker %token IPV6_ADDR
150*2d543d20SAndroid Build Coastguard Worker %token IPV6_CIDR
151*2d543d20SAndroid Build Coastguard Worker %token MODULE VERSION_IDENTIFIER REQUIRE OPTIONAL
152*2d543d20SAndroid Build Coastguard Worker %token POLICYCAP
153*2d543d20SAndroid Build Coastguard Worker %token PERMISSIVE
154*2d543d20SAndroid Build Coastguard Worker %token FILESYSTEM
155*2d543d20SAndroid Build Coastguard Worker %token DEFAULT_USER DEFAULT_ROLE DEFAULT_TYPE DEFAULT_RANGE
156*2d543d20SAndroid Build Coastguard Worker %token LOW_HIGH LOW HIGH GLBLUB
157*2d543d20SAndroid Build Coastguard Worker %token INVALID_CHAR
158*2d543d20SAndroid Build Coastguard Worker 
159*2d543d20SAndroid Build Coastguard Worker %left OR
160*2d543d20SAndroid Build Coastguard Worker %left XOR
161*2d543d20SAndroid Build Coastguard Worker %left AND
162*2d543d20SAndroid Build Coastguard Worker %right NOT
163*2d543d20SAndroid Build Coastguard Worker %left EQUALS NOTEQUAL
164*2d543d20SAndroid Build Coastguard Worker %%
165*2d543d20SAndroid Build Coastguard Worker policy			: base_policy
166*2d543d20SAndroid Build Coastguard Worker                         | module_policy
167*2d543d20SAndroid Build Coastguard Worker                         ;
168*2d543d20SAndroid Build Coastguard Worker base_policy             : { if (define_policy(pass, 0) == -1) YYABORT; }
169*2d543d20SAndroid Build Coastguard Worker                           classes initial_sids access_vectors
170*2d543d20SAndroid Build Coastguard Worker                           { if (pass == 1) { if (policydb_index_classes(policydbp)) YYABORT; }
171*2d543d20SAndroid Build Coastguard Worker                             else if (pass == 2) { if (policydb_index_others(NULL, policydbp, 0)) YYABORT; }}
172*2d543d20SAndroid Build Coastguard Worker 			  opt_default_rules opt_mls te_rbac users opt_constraints
173*2d543d20SAndroid Build Coastguard Worker                          { if (pass == 1) { if (policydb_index_bools(policydbp)) YYABORT; }
174*2d543d20SAndroid Build Coastguard Worker 			   else if (pass == 2) { if (policydb_index_others(NULL, policydbp, 0)) YYABORT; }}
175*2d543d20SAndroid Build Coastguard Worker 			  initial_sid_contexts opt_fs_contexts opt_fs_uses opt_genfs_contexts net_contexts opt_dev_contexts opt_ibpkey_contexts opt_ibendport_contexts
176*2d543d20SAndroid Build Coastguard Worker 			;
177*2d543d20SAndroid Build Coastguard Worker classes			: class_def
178*2d543d20SAndroid Build Coastguard Worker 			| classes class_def
179*2d543d20SAndroid Build Coastguard Worker 			;
180*2d543d20SAndroid Build Coastguard Worker class_def		: CLASS identifier
181*2d543d20SAndroid Build Coastguard Worker 			{if (define_class()) YYABORT;}
182*2d543d20SAndroid Build Coastguard Worker 			;
183*2d543d20SAndroid Build Coastguard Worker initial_sids 		: initial_sid_def
184*2d543d20SAndroid Build Coastguard Worker 			| initial_sids initial_sid_def
185*2d543d20SAndroid Build Coastguard Worker 			;
186*2d543d20SAndroid Build Coastguard Worker initial_sid_def		: SID identifier
187*2d543d20SAndroid Build Coastguard Worker                         {if (define_initial_sid()) YYABORT;}
188*2d543d20SAndroid Build Coastguard Worker 			;
189*2d543d20SAndroid Build Coastguard Worker access_vectors		: opt_common_perms av_perms
190*2d543d20SAndroid Build Coastguard Worker 			;
191*2d543d20SAndroid Build Coastguard Worker opt_common_perms        : common_perms
192*2d543d20SAndroid Build Coastguard Worker                         |
193*2d543d20SAndroid Build Coastguard Worker                         ;
194*2d543d20SAndroid Build Coastguard Worker common_perms		: common_perms_def
195*2d543d20SAndroid Build Coastguard Worker 			| common_perms common_perms_def
196*2d543d20SAndroid Build Coastguard Worker 			;
197*2d543d20SAndroid Build Coastguard Worker common_perms_def	: COMMON identifier '{' identifier_list '}'
198*2d543d20SAndroid Build Coastguard Worker 			{if (define_common_perms()) YYABORT;}
199*2d543d20SAndroid Build Coastguard Worker 			;
200*2d543d20SAndroid Build Coastguard Worker av_perms		: av_perms_def
201*2d543d20SAndroid Build Coastguard Worker 			| av_perms av_perms_def
202*2d543d20SAndroid Build Coastguard Worker 			;
203*2d543d20SAndroid Build Coastguard Worker av_perms_def		: CLASS identifier '{' identifier_list '}'
204*2d543d20SAndroid Build Coastguard Worker 			{if (define_av_perms(FALSE)) YYABORT;}
205*2d543d20SAndroid Build Coastguard Worker                         | CLASS identifier INHERITS identifier
206*2d543d20SAndroid Build Coastguard Worker 			{if (define_av_perms(TRUE)) YYABORT;}
207*2d543d20SAndroid Build Coastguard Worker                         | CLASS identifier INHERITS identifier '{' identifier_list '}'
208*2d543d20SAndroid Build Coastguard Worker 			{if (define_av_perms(TRUE)) YYABORT;}
209*2d543d20SAndroid Build Coastguard Worker 			;
210*2d543d20SAndroid Build Coastguard Worker opt_default_rules	: default_rules
211*2d543d20SAndroid Build Coastguard Worker 			|
212*2d543d20SAndroid Build Coastguard Worker 			;
213*2d543d20SAndroid Build Coastguard Worker default_rules		: default_user_def
214*2d543d20SAndroid Build Coastguard Worker 			| default_role_def
215*2d543d20SAndroid Build Coastguard Worker 			| default_type_def
216*2d543d20SAndroid Build Coastguard Worker 			| default_range_def
217*2d543d20SAndroid Build Coastguard Worker 			| default_rules default_user_def
218*2d543d20SAndroid Build Coastguard Worker 			| default_rules default_role_def
219*2d543d20SAndroid Build Coastguard Worker 			| default_rules default_type_def
220*2d543d20SAndroid Build Coastguard Worker 			| default_rules default_range_def
221*2d543d20SAndroid Build Coastguard Worker 			;
222*2d543d20SAndroid Build Coastguard Worker default_user_def	: DEFAULT_USER names SOURCE ';'
223*2d543d20SAndroid Build Coastguard Worker 			{if (define_default_user(DEFAULT_SOURCE)) YYABORT; }
224*2d543d20SAndroid Build Coastguard Worker 			| DEFAULT_USER names TARGET ';'
225*2d543d20SAndroid Build Coastguard Worker 			{if (define_default_user(DEFAULT_TARGET)) YYABORT; }
226*2d543d20SAndroid Build Coastguard Worker 			;
227*2d543d20SAndroid Build Coastguard Worker default_role_def	: DEFAULT_ROLE names SOURCE ';'
228*2d543d20SAndroid Build Coastguard Worker 			{if (define_default_role(DEFAULT_SOURCE)) YYABORT; }
229*2d543d20SAndroid Build Coastguard Worker 			| DEFAULT_ROLE names TARGET ';'
230*2d543d20SAndroid Build Coastguard Worker 			{if (define_default_role(DEFAULT_TARGET)) YYABORT; }
231*2d543d20SAndroid Build Coastguard Worker 			;
232*2d543d20SAndroid Build Coastguard Worker default_type_def	: DEFAULT_TYPE names SOURCE ';'
233*2d543d20SAndroid Build Coastguard Worker 			{if (define_default_type(DEFAULT_SOURCE)) YYABORT;; }
234*2d543d20SAndroid Build Coastguard Worker 			| DEFAULT_TYPE names TARGET ';'
235*2d543d20SAndroid Build Coastguard Worker 			{if (define_default_type(DEFAULT_TARGET)) YYABORT; }
236*2d543d20SAndroid Build Coastguard Worker 			;
237*2d543d20SAndroid Build Coastguard Worker default_range_def	: DEFAULT_RANGE names SOURCE LOW ';'
238*2d543d20SAndroid Build Coastguard Worker 			{if (define_default_range(DEFAULT_SOURCE_LOW)) YYABORT; }
239*2d543d20SAndroid Build Coastguard Worker 			| DEFAULT_RANGE names SOURCE HIGH ';'
240*2d543d20SAndroid Build Coastguard Worker 			{if (define_default_range(DEFAULT_SOURCE_HIGH)) YYABORT; }
241*2d543d20SAndroid Build Coastguard Worker 			| DEFAULT_RANGE names SOURCE LOW_HIGH ';'
242*2d543d20SAndroid Build Coastguard Worker 			{if (define_default_range(DEFAULT_SOURCE_LOW_HIGH)) YYABORT; }
243*2d543d20SAndroid Build Coastguard Worker 			| DEFAULT_RANGE names TARGET LOW ';'
244*2d543d20SAndroid Build Coastguard Worker 			{if (define_default_range(DEFAULT_TARGET_LOW)) YYABORT; }
245*2d543d20SAndroid Build Coastguard Worker 			| DEFAULT_RANGE names TARGET HIGH ';'
246*2d543d20SAndroid Build Coastguard Worker 			{if (define_default_range(DEFAULT_TARGET_HIGH)) YYABORT; }
247*2d543d20SAndroid Build Coastguard Worker 			| DEFAULT_RANGE names TARGET LOW_HIGH ';'
248*2d543d20SAndroid Build Coastguard Worker 			{if (define_default_range(DEFAULT_TARGET_LOW_HIGH)) YYABORT; }
249*2d543d20SAndroid Build Coastguard Worker 			| DEFAULT_RANGE names GLBLUB';'
250*2d543d20SAndroid Build Coastguard Worker 			{if (define_default_range(DEFAULT_GLBLUB)) YYABORT; }
251*2d543d20SAndroid Build Coastguard Worker 			;
252*2d543d20SAndroid Build Coastguard Worker opt_mls			: mls
253*2d543d20SAndroid Build Coastguard Worker                         |
254*2d543d20SAndroid Build Coastguard Worker 			;
255*2d543d20SAndroid Build Coastguard Worker mls			: sensitivities dominance opt_categories levels mlspolicy
256*2d543d20SAndroid Build Coastguard Worker 			;
257*2d543d20SAndroid Build Coastguard Worker sensitivities	 	: sensitivity_def
258*2d543d20SAndroid Build Coastguard Worker 			| sensitivities sensitivity_def
259*2d543d20SAndroid Build Coastguard Worker 			;
260*2d543d20SAndroid Build Coastguard Worker sensitivity_def		: SENSITIVITY identifier alias_def ';'
261*2d543d20SAndroid Build Coastguard Worker 			{if (define_sens()) YYABORT;}
262*2d543d20SAndroid Build Coastguard Worker 			| SENSITIVITY identifier ';'
263*2d543d20SAndroid Build Coastguard Worker 			{if (define_sens()) YYABORT;}
264*2d543d20SAndroid Build Coastguard Worker 	                ;
265*2d543d20SAndroid Build Coastguard Worker alias_def		: ALIAS names
266*2d543d20SAndroid Build Coastguard Worker 			;
267*2d543d20SAndroid Build Coastguard Worker dominance		: DOMINANCE identifier
268*2d543d20SAndroid Build Coastguard Worker 			{if (define_dominance()) YYABORT;}
269*2d543d20SAndroid Build Coastguard Worker                         | DOMINANCE '{' identifier_list '}'
270*2d543d20SAndroid Build Coastguard Worker 			{if (define_dominance()) YYABORT;}
271*2d543d20SAndroid Build Coastguard Worker 			;
272*2d543d20SAndroid Build Coastguard Worker opt_categories          : categories
273*2d543d20SAndroid Build Coastguard Worker                         |
274*2d543d20SAndroid Build Coastguard Worker                         ;
275*2d543d20SAndroid Build Coastguard Worker categories 		: category_def
276*2d543d20SAndroid Build Coastguard Worker 			| categories category_def
277*2d543d20SAndroid Build Coastguard Worker 			;
278*2d543d20SAndroid Build Coastguard Worker category_def		: CATEGORY identifier alias_def ';'
279*2d543d20SAndroid Build Coastguard Worker 			{if (define_category()) YYABORT;}
280*2d543d20SAndroid Build Coastguard Worker 			| CATEGORY identifier ';'
281*2d543d20SAndroid Build Coastguard Worker 			{if (define_category()) YYABORT;}
282*2d543d20SAndroid Build Coastguard Worker 			;
283*2d543d20SAndroid Build Coastguard Worker levels	 		: level_def
284*2d543d20SAndroid Build Coastguard Worker 			| levels level_def
285*2d543d20SAndroid Build Coastguard Worker 			;
286*2d543d20SAndroid Build Coastguard Worker level_def		: LEVEL identifier ':' id_comma_list ';'
287*2d543d20SAndroid Build Coastguard Worker 			{if (define_level()) YYABORT;}
288*2d543d20SAndroid Build Coastguard Worker 			| LEVEL identifier ';'
289*2d543d20SAndroid Build Coastguard Worker 			{if (define_level()) YYABORT;}
290*2d543d20SAndroid Build Coastguard Worker 			;
291*2d543d20SAndroid Build Coastguard Worker mlspolicy		: mlspolicy_decl
292*2d543d20SAndroid Build Coastguard Worker 			| mlspolicy mlspolicy_decl
293*2d543d20SAndroid Build Coastguard Worker 			;
294*2d543d20SAndroid Build Coastguard Worker mlspolicy_decl		: mlsconstraint_def
295*2d543d20SAndroid Build Coastguard Worker 			| mlsvalidatetrans_def
296*2d543d20SAndroid Build Coastguard Worker 			;
297*2d543d20SAndroid Build Coastguard Worker mlsconstraint_def	: MLSCONSTRAIN names names cexpr ';'
298*2d543d20SAndroid Build Coastguard Worker 			{ if (define_constraint((constraint_expr_t*)$4)) YYABORT; }
299*2d543d20SAndroid Build Coastguard Worker 			;
300*2d543d20SAndroid Build Coastguard Worker mlsvalidatetrans_def	: MLSVALIDATETRANS names cexpr ';'
301*2d543d20SAndroid Build Coastguard Worker 			{ if (define_validatetrans((constraint_expr_t*)$3)) YYABORT; }
302*2d543d20SAndroid Build Coastguard Worker 			;
303*2d543d20SAndroid Build Coastguard Worker te_rbac			: te_rbac_decl
304*2d543d20SAndroid Build Coastguard Worker 			| te_rbac te_rbac_decl
305*2d543d20SAndroid Build Coastguard Worker 			;
306*2d543d20SAndroid Build Coastguard Worker te_rbac_decl		: te_decl
307*2d543d20SAndroid Build Coastguard Worker 			| rbac_decl
308*2d543d20SAndroid Build Coastguard Worker                         | cond_stmt_def
309*2d543d20SAndroid Build Coastguard Worker 			| optional_block
310*2d543d20SAndroid Build Coastguard Worker 			| policycap_def
311*2d543d20SAndroid Build Coastguard Worker 			| ';'
312*2d543d20SAndroid Build Coastguard Worker                         ;
313*2d543d20SAndroid Build Coastguard Worker rbac_decl		: attribute_role_def
314*2d543d20SAndroid Build Coastguard Worker 			| role_type_def
315*2d543d20SAndroid Build Coastguard Worker                         | role_trans_def
316*2d543d20SAndroid Build Coastguard Worker  			| role_allow_def
317*2d543d20SAndroid Build Coastguard Worker 			| roleattribute_def
318*2d543d20SAndroid Build Coastguard Worker 			| role_attr_def
319*2d543d20SAndroid Build Coastguard Worker 			;
320*2d543d20SAndroid Build Coastguard Worker te_decl			: attribute_def
321*2d543d20SAndroid Build Coastguard Worker                         | expandattribute_def
322*2d543d20SAndroid Build Coastguard Worker                         | type_def
323*2d543d20SAndroid Build Coastguard Worker                         | typealias_def
324*2d543d20SAndroid Build Coastguard Worker                         | typeattribute_def
325*2d543d20SAndroid Build Coastguard Worker                         | typebounds_def
326*2d543d20SAndroid Build Coastguard Worker                         | bool_def
327*2d543d20SAndroid Build Coastguard Worker 			| tunable_def
328*2d543d20SAndroid Build Coastguard Worker                         | transition_def
329*2d543d20SAndroid Build Coastguard Worker                         | range_trans_def
330*2d543d20SAndroid Build Coastguard Worker                         | te_avtab_def
331*2d543d20SAndroid Build Coastguard Worker 			| permissive_def
332*2d543d20SAndroid Build Coastguard Worker 			;
333*2d543d20SAndroid Build Coastguard Worker attribute_def           : ATTRIBUTE identifier ';'
334*2d543d20SAndroid Build Coastguard Worker                         { if (define_attrib()) YYABORT;}
335*2d543d20SAndroid Build Coastguard Worker                         ;
336*2d543d20SAndroid Build Coastguard Worker expandattribute_def     : EXPANDATTRIBUTE names bool_val ';'
337*2d543d20SAndroid Build Coastguard Worker                         { if (expand_attrib()) YYABORT;}
338*2d543d20SAndroid Build Coastguard Worker                         ;
339*2d543d20SAndroid Build Coastguard Worker type_def		: TYPE identifier alias_def opt_attr_list ';'
340*2d543d20SAndroid Build Coastguard Worker                         {if (define_type(1)) YYABORT;}
341*2d543d20SAndroid Build Coastguard Worker 	                | TYPE identifier opt_attr_list ';'
342*2d543d20SAndroid Build Coastguard Worker                         {if (define_type(0)) YYABORT;}
343*2d543d20SAndroid Build Coastguard Worker     			;
344*2d543d20SAndroid Build Coastguard Worker typealias_def           : TYPEALIAS identifier alias_def ';'
345*2d543d20SAndroid Build Coastguard Worker 			{if (define_typealias()) YYABORT;}
346*2d543d20SAndroid Build Coastguard Worker 			;
347*2d543d20SAndroid Build Coastguard Worker typeattribute_def	: TYPEATTRIBUTE identifier id_comma_list ';'
348*2d543d20SAndroid Build Coastguard Worker 			{if (define_typeattribute()) YYABORT;}
349*2d543d20SAndroid Build Coastguard Worker 			;
350*2d543d20SAndroid Build Coastguard Worker typebounds_def          : TYPEBOUNDS identifier id_comma_list ';'
351*2d543d20SAndroid Build Coastguard Worker                         {if (define_typebounds()) YYABORT;}
352*2d543d20SAndroid Build Coastguard Worker                         ;
353*2d543d20SAndroid Build Coastguard Worker opt_attr_list           : ',' id_comma_list
354*2d543d20SAndroid Build Coastguard Worker 			|
355*2d543d20SAndroid Build Coastguard Worker 			;
356*2d543d20SAndroid Build Coastguard Worker bool_def                : BOOL identifier bool_val ';'
357*2d543d20SAndroid Build Coastguard Worker                         { if (define_bool_tunable(0)) YYABORT; }
358*2d543d20SAndroid Build Coastguard Worker                         ;
359*2d543d20SAndroid Build Coastguard Worker tunable_def		: TUNABLE identifier bool_val ';'
360*2d543d20SAndroid Build Coastguard Worker 			{ if (define_bool_tunable(1)) YYABORT; }
361*2d543d20SAndroid Build Coastguard Worker 			;
362*2d543d20SAndroid Build Coastguard Worker bool_val                : CTRUE
363*2d543d20SAndroid Build Coastguard Worker 			{ if (insert_id("T",0)) YYABORT; }
364*2d543d20SAndroid Build Coastguard Worker                         | CFALSE
365*2d543d20SAndroid Build Coastguard Worker 			{ if (insert_id("F",0)) YYABORT; }
366*2d543d20SAndroid Build Coastguard Worker                         ;
367*2d543d20SAndroid Build Coastguard Worker cond_stmt_def           : IF cond_expr '{' cond_pol_list '}' cond_else
368*2d543d20SAndroid Build Coastguard Worker                         { if (pass == 2) { if (define_conditional((cond_expr_t*)$2, (avrule_t*)$4, (avrule_t*)$6) < 0) YYABORT;  }}
369*2d543d20SAndroid Build Coastguard Worker                         ;
370*2d543d20SAndroid Build Coastguard Worker cond_else		: ELSE '{' cond_pol_list '}'
371*2d543d20SAndroid Build Coastguard Worker 			{ $$ = $3; }
372*2d543d20SAndroid Build Coastguard Worker 			| /* empty */
373*2d543d20SAndroid Build Coastguard Worker 			{ $$ = NULL; }
374*2d543d20SAndroid Build Coastguard Worker 			;
375*2d543d20SAndroid Build Coastguard Worker cond_expr               : '(' cond_expr ')'
376*2d543d20SAndroid Build Coastguard Worker 			{ $$ = $2;}
377*2d543d20SAndroid Build Coastguard Worker 			| NOT cond_expr
378*2d543d20SAndroid Build Coastguard Worker 			{ $$ = define_cond_expr(COND_NOT, $2, 0);
379*2d543d20SAndroid Build Coastguard Worker 			  if ($$ == 0) YYABORT; }
380*2d543d20SAndroid Build Coastguard Worker 			| cond_expr AND cond_expr
381*2d543d20SAndroid Build Coastguard Worker 			{ $$ = define_cond_expr(COND_AND, $1, $3);
382*2d543d20SAndroid Build Coastguard Worker 			  if ($$ == 0) YYABORT; }
383*2d543d20SAndroid Build Coastguard Worker 			| cond_expr OR cond_expr
384*2d543d20SAndroid Build Coastguard Worker 			{ $$ = define_cond_expr(COND_OR, $1, $3);
385*2d543d20SAndroid Build Coastguard Worker 			  if ($$ == 0) YYABORT; }
386*2d543d20SAndroid Build Coastguard Worker 			| cond_expr XOR cond_expr
387*2d543d20SAndroid Build Coastguard Worker 			{ $$ = define_cond_expr(COND_XOR, $1, $3);
388*2d543d20SAndroid Build Coastguard Worker 			  if ($$ == 0) YYABORT; }
389*2d543d20SAndroid Build Coastguard Worker 			| cond_expr EQUALS cond_expr
390*2d543d20SAndroid Build Coastguard Worker 			{ $$ = define_cond_expr(COND_EQ, $1, $3);
391*2d543d20SAndroid Build Coastguard Worker 			  if ($$ == 0) YYABORT; }
392*2d543d20SAndroid Build Coastguard Worker 			| cond_expr NOTEQUAL cond_expr
393*2d543d20SAndroid Build Coastguard Worker 			{ $$ = define_cond_expr(COND_NEQ, $1, $3);
394*2d543d20SAndroid Build Coastguard Worker 			  if ($$ == 0) YYABORT; }
395*2d543d20SAndroid Build Coastguard Worker 			| cond_expr_prim
396*2d543d20SAndroid Build Coastguard Worker 			{ $$ = $1; }
397*2d543d20SAndroid Build Coastguard Worker 			;
398*2d543d20SAndroid Build Coastguard Worker cond_expr_prim          : identifier
399*2d543d20SAndroid Build Coastguard Worker                         { $$ = define_cond_expr(COND_BOOL,0, 0);
400*2d543d20SAndroid Build Coastguard Worker 			  if ($$ == COND_ERR) YYABORT; }
401*2d543d20SAndroid Build Coastguard Worker                         ;
402*2d543d20SAndroid Build Coastguard Worker cond_pol_list           : cond_pol_list cond_rule_def
403*2d543d20SAndroid Build Coastguard Worker                         { $$ = define_cond_pol_list((avrule_t *)$1, (avrule_t *)$2); }
404*2d543d20SAndroid Build Coastguard Worker 			| /* empty */
405*2d543d20SAndroid Build Coastguard Worker 			{ $$ = NULL; }
406*2d543d20SAndroid Build Coastguard Worker 			;
407*2d543d20SAndroid Build Coastguard Worker cond_rule_def           : cond_transition_def
408*2d543d20SAndroid Build Coastguard Worker                         { $$ = $1; }
409*2d543d20SAndroid Build Coastguard Worker                         | cond_te_avtab_def
410*2d543d20SAndroid Build Coastguard Worker                         { $$ = $1; }
411*2d543d20SAndroid Build Coastguard Worker 			| require_block
412*2d543d20SAndroid Build Coastguard Worker 			{ $$ = NULL; }
413*2d543d20SAndroid Build Coastguard Worker                         ;
414*2d543d20SAndroid Build Coastguard Worker cond_transition_def	: TYPE_TRANSITION names names ':' names identifier filename ';'
415*2d543d20SAndroid Build Coastguard Worker                         { $$ = define_cond_filename_trans() ;
416*2d543d20SAndroid Build Coastguard Worker                           if ($$ == COND_ERR) YYABORT;}
417*2d543d20SAndroid Build Coastguard Worker 			| TYPE_TRANSITION names names ':' names identifier ';'
418*2d543d20SAndroid Build Coastguard Worker                         { $$ = define_cond_compute_type(AVRULE_TRANSITION) ;
419*2d543d20SAndroid Build Coastguard Worker                           if ($$ == COND_ERR) YYABORT;}
420*2d543d20SAndroid Build Coastguard Worker                         | TYPE_MEMBER names names ':' names identifier ';'
421*2d543d20SAndroid Build Coastguard Worker                         { $$ = define_cond_compute_type(AVRULE_MEMBER) ;
422*2d543d20SAndroid Build Coastguard Worker                           if ($$ ==  COND_ERR) YYABORT;}
423*2d543d20SAndroid Build Coastguard Worker                         | TYPE_CHANGE names names ':' names identifier ';'
424*2d543d20SAndroid Build Coastguard Worker                         { $$ = define_cond_compute_type(AVRULE_CHANGE) ;
425*2d543d20SAndroid Build Coastguard Worker                           if ($$ == COND_ERR) YYABORT;}
426*2d543d20SAndroid Build Coastguard Worker     			;
427*2d543d20SAndroid Build Coastguard Worker cond_te_avtab_def	: cond_allow_def
428*2d543d20SAndroid Build Coastguard Worker                           { $$ = $1; }
429*2d543d20SAndroid Build Coastguard Worker 			| cond_auditallow_def
430*2d543d20SAndroid Build Coastguard Worker 			  { $$ = $1; }
431*2d543d20SAndroid Build Coastguard Worker 			| cond_auditdeny_def
432*2d543d20SAndroid Build Coastguard Worker 			  { $$ = $1; }
433*2d543d20SAndroid Build Coastguard Worker 			| cond_dontaudit_def
434*2d543d20SAndroid Build Coastguard Worker 			  { $$ = $1; }
435*2d543d20SAndroid Build Coastguard Worker 			;
436*2d543d20SAndroid Build Coastguard Worker cond_allow_def		: ALLOW names names ':' names names  ';'
437*2d543d20SAndroid Build Coastguard Worker 			{ $$ = define_cond_te_avtab(AVRULE_ALLOWED) ;
438*2d543d20SAndroid Build Coastguard Worker                           if ($$ == COND_ERR) YYABORT; }
439*2d543d20SAndroid Build Coastguard Worker 		        ;
440*2d543d20SAndroid Build Coastguard Worker cond_auditallow_def	: AUDITALLOW names names ':' names names ';'
441*2d543d20SAndroid Build Coastguard Worker 			{ $$ = define_cond_te_avtab(AVRULE_AUDITALLOW) ;
442*2d543d20SAndroid Build Coastguard Worker                           if ($$ == COND_ERR) YYABORT; }
443*2d543d20SAndroid Build Coastguard Worker 		        ;
444*2d543d20SAndroid Build Coastguard Worker cond_auditdeny_def	: AUDITDENY names names ':' names names ';'
445*2d543d20SAndroid Build Coastguard Worker 			{ $$ = define_cond_te_avtab(AVRULE_AUDITDENY) ;
446*2d543d20SAndroid Build Coastguard Worker                           if ($$ == COND_ERR) YYABORT; }
447*2d543d20SAndroid Build Coastguard Worker 		        ;
448*2d543d20SAndroid Build Coastguard Worker cond_dontaudit_def	: DONTAUDIT names names ':' names names ';'
449*2d543d20SAndroid Build Coastguard Worker 			{ $$ = define_cond_te_avtab(AVRULE_DONTAUDIT);
450*2d543d20SAndroid Build Coastguard Worker                           if ($$ == COND_ERR) YYABORT; }
451*2d543d20SAndroid Build Coastguard Worker 		        ;
452*2d543d20SAndroid Build Coastguard Worker 			;
453*2d543d20SAndroid Build Coastguard Worker transition_def		: TYPE_TRANSITION  names names ':' names identifier filename ';'
454*2d543d20SAndroid Build Coastguard Worker 			{if (define_filename_trans()) YYABORT; }
455*2d543d20SAndroid Build Coastguard Worker 			| TYPE_TRANSITION names names ':' names identifier ';'
456*2d543d20SAndroid Build Coastguard Worker                         {if (define_compute_type(AVRULE_TRANSITION)) YYABORT;}
457*2d543d20SAndroid Build Coastguard Worker                         | TYPE_MEMBER names names ':' names identifier ';'
458*2d543d20SAndroid Build Coastguard Worker                         {if (define_compute_type(AVRULE_MEMBER)) YYABORT;}
459*2d543d20SAndroid Build Coastguard Worker                         | TYPE_CHANGE names names ':' names identifier ';'
460*2d543d20SAndroid Build Coastguard Worker                         {if (define_compute_type(AVRULE_CHANGE)) YYABORT;}
461*2d543d20SAndroid Build Coastguard Worker     			;
462*2d543d20SAndroid Build Coastguard Worker range_trans_def		: RANGE_TRANSITION names names mls_range_def ';'
463*2d543d20SAndroid Build Coastguard Worker 			{ if (define_range_trans(0)) YYABORT; }
464*2d543d20SAndroid Build Coastguard Worker 			| RANGE_TRANSITION names names ':' names mls_range_def ';'
465*2d543d20SAndroid Build Coastguard Worker 			{ if (define_range_trans(1)) YYABORT; }
466*2d543d20SAndroid Build Coastguard Worker 			;
467*2d543d20SAndroid Build Coastguard Worker te_avtab_def		: allow_def
468*2d543d20SAndroid Build Coastguard Worker 			| auditallow_def
469*2d543d20SAndroid Build Coastguard Worker 			| auditdeny_def
470*2d543d20SAndroid Build Coastguard Worker 			| dontaudit_def
471*2d543d20SAndroid Build Coastguard Worker 			| neverallow_def
472*2d543d20SAndroid Build Coastguard Worker 			| xperm_allow_def
473*2d543d20SAndroid Build Coastguard Worker 			| xperm_auditallow_def
474*2d543d20SAndroid Build Coastguard Worker 			| xperm_dontaudit_def
475*2d543d20SAndroid Build Coastguard Worker 			| xperm_neverallow_def
476*2d543d20SAndroid Build Coastguard Worker 			;
477*2d543d20SAndroid Build Coastguard Worker allow_def		: ALLOW names names ':' names names  ';'
478*2d543d20SAndroid Build Coastguard Worker 			{if (define_te_avtab(AVRULE_ALLOWED)) YYABORT; }
479*2d543d20SAndroid Build Coastguard Worker 		        ;
480*2d543d20SAndroid Build Coastguard Worker auditallow_def		: AUDITALLOW names names ':' names names ';'
481*2d543d20SAndroid Build Coastguard Worker 			{if (define_te_avtab(AVRULE_AUDITALLOW)) YYABORT; }
482*2d543d20SAndroid Build Coastguard Worker 		        ;
483*2d543d20SAndroid Build Coastguard Worker auditdeny_def		: AUDITDENY names names ':' names names ';'
484*2d543d20SAndroid Build Coastguard Worker 			{if (define_te_avtab(AVRULE_AUDITDENY)) YYABORT; }
485*2d543d20SAndroid Build Coastguard Worker 		        ;
486*2d543d20SAndroid Build Coastguard Worker dontaudit_def		: DONTAUDIT names names ':' names names ';'
487*2d543d20SAndroid Build Coastguard Worker 			{if (define_te_avtab(AVRULE_DONTAUDIT)) YYABORT; }
488*2d543d20SAndroid Build Coastguard Worker 		        ;
489*2d543d20SAndroid Build Coastguard Worker neverallow_def		: NEVERALLOW names names ':' names names  ';'
490*2d543d20SAndroid Build Coastguard Worker 			{if (define_te_avtab(AVRULE_NEVERALLOW)) YYABORT; }
491*2d543d20SAndroid Build Coastguard Worker 		        ;
492*2d543d20SAndroid Build Coastguard Worker xperm_allow_def		: ALLOWXPERM names names ':' names identifier xperms ';'
493*2d543d20SAndroid Build Coastguard Worker 			{if (define_te_avtab_extended_perms(AVRULE_XPERMS_ALLOWED)) YYABORT; }
494*2d543d20SAndroid Build Coastguard Worker 		        ;
495*2d543d20SAndroid Build Coastguard Worker xperm_auditallow_def	: AUDITALLOWXPERM names names ':' names identifier xperms ';'
496*2d543d20SAndroid Build Coastguard Worker 			{if (define_te_avtab_extended_perms(AVRULE_XPERMS_AUDITALLOW)) YYABORT; }
497*2d543d20SAndroid Build Coastguard Worker 		        ;
498*2d543d20SAndroid Build Coastguard Worker xperm_dontaudit_def	: DONTAUDITXPERM names names ':' names identifier xperms ';'
499*2d543d20SAndroid Build Coastguard Worker 			{if (define_te_avtab_extended_perms(AVRULE_XPERMS_DONTAUDIT)) YYABORT; }
500*2d543d20SAndroid Build Coastguard Worker 		        ;
501*2d543d20SAndroid Build Coastguard Worker xperm_neverallow_def	: NEVERALLOWXPERM names names ':' names identifier xperms ';'
502*2d543d20SAndroid Build Coastguard Worker 			{if (define_te_avtab_extended_perms(AVRULE_XPERMS_NEVERALLOW)) YYABORT; }
503*2d543d20SAndroid Build Coastguard Worker 		        ;
504*2d543d20SAndroid Build Coastguard Worker attribute_role_def	: ATTRIBUTE_ROLE identifier ';'
505*2d543d20SAndroid Build Coastguard Worker 			{if (define_attrib_role()) YYABORT; }
506*2d543d20SAndroid Build Coastguard Worker 		        ;
507*2d543d20SAndroid Build Coastguard Worker role_type_def		: ROLE identifier TYPES names ';'
508*2d543d20SAndroid Build Coastguard Worker 			{if (define_role_types()) YYABORT;}
509*2d543d20SAndroid Build Coastguard Worker 			;
510*2d543d20SAndroid Build Coastguard Worker role_attr_def		: ROLE identifier opt_attr_list ';'
511*2d543d20SAndroid Build Coastguard Worker 			{if (define_role_attr()) YYABORT;}
512*2d543d20SAndroid Build Coastguard Worker                         ;
513*2d543d20SAndroid Build Coastguard Worker role_trans_def		: ROLE_TRANSITION names names identifier ';'
514*2d543d20SAndroid Build Coastguard Worker 			{if (define_role_trans(0)) YYABORT; }
515*2d543d20SAndroid Build Coastguard Worker 			| ROLE_TRANSITION names names ':' names identifier ';'
516*2d543d20SAndroid Build Coastguard Worker 			{if (define_role_trans(1)) YYABORT;}
517*2d543d20SAndroid Build Coastguard Worker 			;
518*2d543d20SAndroid Build Coastguard Worker role_allow_def		: ALLOW names names ';'
519*2d543d20SAndroid Build Coastguard Worker 			{if (define_role_allow()) YYABORT; }
520*2d543d20SAndroid Build Coastguard Worker 			;
521*2d543d20SAndroid Build Coastguard Worker roleattribute_def	: ROLEATTRIBUTE identifier id_comma_list ';'
522*2d543d20SAndroid Build Coastguard Worker 			{if (define_roleattribute()) YYABORT;}
523*2d543d20SAndroid Build Coastguard Worker 			;
524*2d543d20SAndroid Build Coastguard Worker opt_constraints         : constraints
525*2d543d20SAndroid Build Coastguard Worker                         |
526*2d543d20SAndroid Build Coastguard Worker                         ;
527*2d543d20SAndroid Build Coastguard Worker constraints		: constraint_decl
528*2d543d20SAndroid Build Coastguard Worker 			| constraints constraint_decl
529*2d543d20SAndroid Build Coastguard Worker 			;
530*2d543d20SAndroid Build Coastguard Worker constraint_decl		: constraint_def
531*2d543d20SAndroid Build Coastguard Worker 			| validatetrans_def
532*2d543d20SAndroid Build Coastguard Worker 			;
533*2d543d20SAndroid Build Coastguard Worker constraint_def		: CONSTRAIN names names cexpr ';'
534*2d543d20SAndroid Build Coastguard Worker 			{ if (define_constraint((constraint_expr_t*)$4)) YYABORT; }
535*2d543d20SAndroid Build Coastguard Worker 			;
536*2d543d20SAndroid Build Coastguard Worker validatetrans_def	: VALIDATETRANS names cexpr ';'
537*2d543d20SAndroid Build Coastguard Worker 			{ if (define_validatetrans((constraint_expr_t*)$3)) YYABORT; }
538*2d543d20SAndroid Build Coastguard Worker 			;
539*2d543d20SAndroid Build Coastguard Worker cexpr			: '(' cexpr ')'
540*2d543d20SAndroid Build Coastguard Worker 			{ $$ = $2; }
541*2d543d20SAndroid Build Coastguard Worker 			| NOT cexpr
542*2d543d20SAndroid Build Coastguard Worker 			{ $$ = define_cexpr(CEXPR_NOT, $2, 0);
543*2d543d20SAndroid Build Coastguard Worker 			  if ($$ == 0) YYABORT; }
544*2d543d20SAndroid Build Coastguard Worker 			| cexpr AND cexpr
545*2d543d20SAndroid Build Coastguard Worker 			{ $$ = define_cexpr(CEXPR_AND, $1, $3);
546*2d543d20SAndroid Build Coastguard Worker 			  if ($$ == 0) YYABORT; }
547*2d543d20SAndroid Build Coastguard Worker 			| cexpr OR cexpr
548*2d543d20SAndroid Build Coastguard Worker 			{ $$ = define_cexpr(CEXPR_OR, $1, $3);
549*2d543d20SAndroid Build Coastguard Worker 			  if ($$ == 0) YYABORT; }
550*2d543d20SAndroid Build Coastguard Worker 			| cexpr_prim
551*2d543d20SAndroid Build Coastguard Worker 			{ $$ = $1; }
552*2d543d20SAndroid Build Coastguard Worker 			;
553*2d543d20SAndroid Build Coastguard Worker cexpr_prim		: U1 op U2
554*2d543d20SAndroid Build Coastguard Worker 			{ $$ = define_cexpr(CEXPR_ATTR, CEXPR_USER, $2);
555*2d543d20SAndroid Build Coastguard Worker 			  if ($$ == 0) YYABORT; }
556*2d543d20SAndroid Build Coastguard Worker 			| R1 role_mls_op R2
557*2d543d20SAndroid Build Coastguard Worker 			{ $$ = define_cexpr(CEXPR_ATTR, CEXPR_ROLE, $2);
558*2d543d20SAndroid Build Coastguard Worker 			  if ($$ == 0) YYABORT; }
559*2d543d20SAndroid Build Coastguard Worker 			| T1 op T2
560*2d543d20SAndroid Build Coastguard Worker 			{ $$ = define_cexpr(CEXPR_ATTR, CEXPR_TYPE, $2);
561*2d543d20SAndroid Build Coastguard Worker 			  if ($$ == 0) YYABORT; }
562*2d543d20SAndroid Build Coastguard Worker 			| U1 op { if (insert_separator(1)) YYABORT; } names_push
563*2d543d20SAndroid Build Coastguard Worker 			{ $$ = define_cexpr(CEXPR_NAMES, CEXPR_USER, $2);
564*2d543d20SAndroid Build Coastguard Worker 			  if ($$ == 0) YYABORT; }
565*2d543d20SAndroid Build Coastguard Worker 			| U2 op { if (insert_separator(1)) YYABORT; } names_push
566*2d543d20SAndroid Build Coastguard Worker 			{ $$ = define_cexpr(CEXPR_NAMES, (CEXPR_USER | CEXPR_TARGET), $2);
567*2d543d20SAndroid Build Coastguard Worker 			  if ($$ == 0) YYABORT; }
568*2d543d20SAndroid Build Coastguard Worker 			| U3 op { if (insert_separator(1)) YYABORT; } names_push
569*2d543d20SAndroid Build Coastguard Worker 			{ $$ = define_cexpr(CEXPR_NAMES, (CEXPR_USER | CEXPR_XTARGET), $2);
570*2d543d20SAndroid Build Coastguard Worker 			  if ($$ == 0) YYABORT; }
571*2d543d20SAndroid Build Coastguard Worker 			| R1 op { if (insert_separator(1)) YYABORT; } names_push
572*2d543d20SAndroid Build Coastguard Worker 			{ $$ = define_cexpr(CEXPR_NAMES, CEXPR_ROLE, $2);
573*2d543d20SAndroid Build Coastguard Worker 			  if ($$ == 0) YYABORT; }
574*2d543d20SAndroid Build Coastguard Worker 			| R2 op { if (insert_separator(1)) YYABORT; } names_push
575*2d543d20SAndroid Build Coastguard Worker 			{ $$ = define_cexpr(CEXPR_NAMES, (CEXPR_ROLE | CEXPR_TARGET), $2);
576*2d543d20SAndroid Build Coastguard Worker 			  if ($$ == 0) YYABORT; }
577*2d543d20SAndroid Build Coastguard Worker 			| R3 op { if (insert_separator(1)) YYABORT; } names_push
578*2d543d20SAndroid Build Coastguard Worker 			{ $$ = define_cexpr(CEXPR_NAMES, (CEXPR_ROLE | CEXPR_XTARGET), $2);
579*2d543d20SAndroid Build Coastguard Worker 			  if ($$ == 0) YYABORT; }
580*2d543d20SAndroid Build Coastguard Worker 			| T1 op { if (insert_separator(1)) YYABORT; } names_push
581*2d543d20SAndroid Build Coastguard Worker 			{ $$ = define_cexpr(CEXPR_NAMES, CEXPR_TYPE, $2);
582*2d543d20SAndroid Build Coastguard Worker 			  if ($$ == 0) YYABORT; }
583*2d543d20SAndroid Build Coastguard Worker 			| T2 op { if (insert_separator(1)) YYABORT; } names_push
584*2d543d20SAndroid Build Coastguard Worker 			{ $$ = define_cexpr(CEXPR_NAMES, (CEXPR_TYPE | CEXPR_TARGET), $2);
585*2d543d20SAndroid Build Coastguard Worker 			  if ($$ == 0) YYABORT; }
586*2d543d20SAndroid Build Coastguard Worker 			| T3 op { if (insert_separator(1)) YYABORT; } names_push
587*2d543d20SAndroid Build Coastguard Worker 			{ $$ = define_cexpr(CEXPR_NAMES, (CEXPR_TYPE | CEXPR_XTARGET), $2);
588*2d543d20SAndroid Build Coastguard Worker 			  if ($$ == 0) YYABORT; }
589*2d543d20SAndroid Build Coastguard Worker 			| SAMEUSER
590*2d543d20SAndroid Build Coastguard Worker 			{ $$ = define_cexpr(CEXPR_ATTR, CEXPR_USER, CEXPR_EQ);
591*2d543d20SAndroid Build Coastguard Worker 			  if ($$ == 0) YYABORT; }
592*2d543d20SAndroid Build Coastguard Worker 			| SOURCE ROLE { if (insert_separator(1)) YYABORT; } names_push
593*2d543d20SAndroid Build Coastguard Worker 			{ $$ = define_cexpr(CEXPR_NAMES, CEXPR_ROLE, CEXPR_EQ);
594*2d543d20SAndroid Build Coastguard Worker 			  if ($$ == 0) YYABORT; }
595*2d543d20SAndroid Build Coastguard Worker 			| TARGET ROLE { if (insert_separator(1)) YYABORT; } names_push
596*2d543d20SAndroid Build Coastguard Worker 			{ $$ = define_cexpr(CEXPR_NAMES, (CEXPR_ROLE | CEXPR_TARGET), CEXPR_EQ);
597*2d543d20SAndroid Build Coastguard Worker 			  if ($$ == 0) YYABORT; }
598*2d543d20SAndroid Build Coastguard Worker 			| ROLE role_mls_op
599*2d543d20SAndroid Build Coastguard Worker 			{ $$ = define_cexpr(CEXPR_ATTR, CEXPR_ROLE, $2);
600*2d543d20SAndroid Build Coastguard Worker 			  if ($$ == 0) YYABORT; }
601*2d543d20SAndroid Build Coastguard Worker 			| SOURCE TYPE { if (insert_separator(1)) YYABORT; } names_push
602*2d543d20SAndroid Build Coastguard Worker 			{ $$ = define_cexpr(CEXPR_NAMES, CEXPR_TYPE, CEXPR_EQ);
603*2d543d20SAndroid Build Coastguard Worker 			  if ($$ == 0) YYABORT; }
604*2d543d20SAndroid Build Coastguard Worker 			| TARGET TYPE { if (insert_separator(1)) YYABORT; } names_push
605*2d543d20SAndroid Build Coastguard Worker 			{ $$ = define_cexpr(CEXPR_NAMES, (CEXPR_TYPE | CEXPR_TARGET), CEXPR_EQ);
606*2d543d20SAndroid Build Coastguard Worker 			  if ($$ == 0) YYABORT; }
607*2d543d20SAndroid Build Coastguard Worker 			| L1 role_mls_op L2
608*2d543d20SAndroid Build Coastguard Worker 			{ $$ = define_cexpr(CEXPR_ATTR, CEXPR_L1L2, $2);
609*2d543d20SAndroid Build Coastguard Worker 			  if ($$ == 0) YYABORT; }
610*2d543d20SAndroid Build Coastguard Worker 			| L1 role_mls_op H2
611*2d543d20SAndroid Build Coastguard Worker 			{ $$ = define_cexpr(CEXPR_ATTR, CEXPR_L1H2, $2);
612*2d543d20SAndroid Build Coastguard Worker 			  if ($$ == 0) YYABORT; }
613*2d543d20SAndroid Build Coastguard Worker 			| H1 role_mls_op L2
614*2d543d20SAndroid Build Coastguard Worker 			{ $$ = define_cexpr(CEXPR_ATTR, CEXPR_H1L2, $2);
615*2d543d20SAndroid Build Coastguard Worker 			  if ($$ == 0) YYABORT; }
616*2d543d20SAndroid Build Coastguard Worker 			| H1 role_mls_op H2
617*2d543d20SAndroid Build Coastguard Worker 			{ $$ = define_cexpr(CEXPR_ATTR, CEXPR_H1H2, $2);
618*2d543d20SAndroid Build Coastguard Worker 			  if ($$ == 0) YYABORT; }
619*2d543d20SAndroid Build Coastguard Worker 			| L1 role_mls_op H1
620*2d543d20SAndroid Build Coastguard Worker 			{ $$ = define_cexpr(CEXPR_ATTR, CEXPR_L1H1, $2);
621*2d543d20SAndroid Build Coastguard Worker 			  if ($$ == 0) YYABORT; }
622*2d543d20SAndroid Build Coastguard Worker 			| L2 role_mls_op H2
623*2d543d20SAndroid Build Coastguard Worker 			{ $$ = define_cexpr(CEXPR_ATTR, CEXPR_L2H2, $2);
624*2d543d20SAndroid Build Coastguard Worker 			  if ($$ == 0) YYABORT; }
625*2d543d20SAndroid Build Coastguard Worker 			;
626*2d543d20SAndroid Build Coastguard Worker op			: EQUALS
627*2d543d20SAndroid Build Coastguard Worker 			{ $$ = CEXPR_EQ; }
628*2d543d20SAndroid Build Coastguard Worker 			| NOTEQUAL
629*2d543d20SAndroid Build Coastguard Worker 			{ $$ = CEXPR_NEQ; }
630*2d543d20SAndroid Build Coastguard Worker 			;
631*2d543d20SAndroid Build Coastguard Worker role_mls_op		: op
632*2d543d20SAndroid Build Coastguard Worker 			{ $$ = $1; }
633*2d543d20SAndroid Build Coastguard Worker 			| DOM
634*2d543d20SAndroid Build Coastguard Worker 			{ $$ = CEXPR_DOM; }
635*2d543d20SAndroid Build Coastguard Worker 			| DOMBY
636*2d543d20SAndroid Build Coastguard Worker 			{ $$ = CEXPR_DOMBY; }
637*2d543d20SAndroid Build Coastguard Worker 			| INCOMP
638*2d543d20SAndroid Build Coastguard Worker 			{ $$ = CEXPR_INCOMP; }
639*2d543d20SAndroid Build Coastguard Worker 			;
640*2d543d20SAndroid Build Coastguard Worker users			: user_def
641*2d543d20SAndroid Build Coastguard Worker 			| users user_def
642*2d543d20SAndroid Build Coastguard Worker 			;
643*2d543d20SAndroid Build Coastguard Worker user_def		: USER identifier ROLES names opt_mls_user ';'
644*2d543d20SAndroid Build Coastguard Worker 	                {if (define_user()) YYABORT;}
645*2d543d20SAndroid Build Coastguard Worker 			;
646*2d543d20SAndroid Build Coastguard Worker opt_mls_user		: LEVEL mls_level_def RANGE mls_range_def
647*2d543d20SAndroid Build Coastguard Worker 			|
648*2d543d20SAndroid Build Coastguard Worker 			;
649*2d543d20SAndroid Build Coastguard Worker initial_sid_contexts	: initial_sid_context_def
650*2d543d20SAndroid Build Coastguard Worker 			| initial_sid_contexts initial_sid_context_def
651*2d543d20SAndroid Build Coastguard Worker 			;
652*2d543d20SAndroid Build Coastguard Worker initial_sid_context_def	: SID identifier security_context_def
653*2d543d20SAndroid Build Coastguard Worker 			{if (define_initial_sid_context()) YYABORT;}
654*2d543d20SAndroid Build Coastguard Worker 			;
655*2d543d20SAndroid Build Coastguard Worker opt_dev_contexts	: dev_contexts |
656*2d543d20SAndroid Build Coastguard Worker 			;
657*2d543d20SAndroid Build Coastguard Worker dev_contexts		: dev_context_def
658*2d543d20SAndroid Build Coastguard Worker 			| dev_contexts dev_context_def
659*2d543d20SAndroid Build Coastguard Worker 			;
660*2d543d20SAndroid Build Coastguard Worker dev_context_def		: pirq_context_def |
661*2d543d20SAndroid Build Coastguard Worker 			  iomem_context_def |
662*2d543d20SAndroid Build Coastguard Worker 			  ioport_context_def |
663*2d543d20SAndroid Build Coastguard Worker 			  pci_context_def |
664*2d543d20SAndroid Build Coastguard Worker 			  dtree_context_def
665*2d543d20SAndroid Build Coastguard Worker 			;
666*2d543d20SAndroid Build Coastguard Worker pirq_context_def 	: PIRQCON number security_context_def
667*2d543d20SAndroid Build Coastguard Worker 		        {if (define_pirq_context($2)) YYABORT;}
668*2d543d20SAndroid Build Coastguard Worker 		        ;
669*2d543d20SAndroid Build Coastguard Worker iomem_context_def	: IOMEMCON number64 security_context_def
670*2d543d20SAndroid Build Coastguard Worker 		        {if (define_iomem_context($2,$2)) YYABORT;}
671*2d543d20SAndroid Build Coastguard Worker 		        | IOMEMCON number64 '-' number64 security_context_def
672*2d543d20SAndroid Build Coastguard Worker 		        {if (define_iomem_context($2,$4)) YYABORT;}
673*2d543d20SAndroid Build Coastguard Worker 		        ;
674*2d543d20SAndroid Build Coastguard Worker ioport_context_def	: IOPORTCON number security_context_def
675*2d543d20SAndroid Build Coastguard Worker 			{if (define_ioport_context($2,$2)) YYABORT;}
676*2d543d20SAndroid Build Coastguard Worker 			| IOPORTCON number '-' number security_context_def
677*2d543d20SAndroid Build Coastguard Worker 			{if (define_ioport_context($2,$4)) YYABORT;}
678*2d543d20SAndroid Build Coastguard Worker 			;
679*2d543d20SAndroid Build Coastguard Worker pci_context_def  	: PCIDEVICECON number security_context_def
680*2d543d20SAndroid Build Coastguard Worker 		        {if (define_pcidevice_context($2)) YYABORT;}
681*2d543d20SAndroid Build Coastguard Worker 		        ;
682*2d543d20SAndroid Build Coastguard Worker dtree_context_def	: DEVICETREECON path security_context_def
683*2d543d20SAndroid Build Coastguard Worker 		        {if (define_devicetree_context()) YYABORT;}
684*2d543d20SAndroid Build Coastguard Worker 		        ;
685*2d543d20SAndroid Build Coastguard Worker opt_fs_contexts         : fs_contexts
686*2d543d20SAndroid Build Coastguard Worker                         |
687*2d543d20SAndroid Build Coastguard Worker                         ;
688*2d543d20SAndroid Build Coastguard Worker fs_contexts		: fs_context_def
689*2d543d20SAndroid Build Coastguard Worker 			| fs_contexts fs_context_def
690*2d543d20SAndroid Build Coastguard Worker 			;
691*2d543d20SAndroid Build Coastguard Worker fs_context_def		: FSCON number number security_context_def security_context_def
692*2d543d20SAndroid Build Coastguard Worker 			{if (define_fs_context($2,$3)) YYABORT;}
693*2d543d20SAndroid Build Coastguard Worker 			;
694*2d543d20SAndroid Build Coastguard Worker net_contexts		: opt_port_contexts opt_netif_contexts opt_node_contexts
695*2d543d20SAndroid Build Coastguard Worker 			;
696*2d543d20SAndroid Build Coastguard Worker opt_port_contexts       : port_contexts
697*2d543d20SAndroid Build Coastguard Worker                         |
698*2d543d20SAndroid Build Coastguard Worker                         ;
699*2d543d20SAndroid Build Coastguard Worker port_contexts		: port_context_def
700*2d543d20SAndroid Build Coastguard Worker 			| port_contexts port_context_def
701*2d543d20SAndroid Build Coastguard Worker 			;
702*2d543d20SAndroid Build Coastguard Worker port_context_def	: PORTCON identifier number security_context_def
703*2d543d20SAndroid Build Coastguard Worker 			{if (define_port_context($3,$3)) YYABORT;}
704*2d543d20SAndroid Build Coastguard Worker 			| PORTCON identifier number '-' number security_context_def
705*2d543d20SAndroid Build Coastguard Worker 			{if (define_port_context($3,$5)) YYABORT;}
706*2d543d20SAndroid Build Coastguard Worker 			;
707*2d543d20SAndroid Build Coastguard Worker opt_ibpkey_contexts     : ibpkey_contexts
708*2d543d20SAndroid Build Coastguard Worker                         |
709*2d543d20SAndroid Build Coastguard Worker                         ;
710*2d543d20SAndroid Build Coastguard Worker ibpkey_contexts		: ibpkey_context_def
711*2d543d20SAndroid Build Coastguard Worker 			| ibpkey_contexts ibpkey_context_def
712*2d543d20SAndroid Build Coastguard Worker 			;
713*2d543d20SAndroid Build Coastguard Worker ibpkey_context_def	: IBPKEYCON ipv6_addr number security_context_def
714*2d543d20SAndroid Build Coastguard Worker 			{if (define_ibpkey_context($3,$3)) YYABORT;}
715*2d543d20SAndroid Build Coastguard Worker 			| IBPKEYCON ipv6_addr number '-' number security_context_def
716*2d543d20SAndroid Build Coastguard Worker 			{if (define_ibpkey_context($3,$5)) YYABORT;}
717*2d543d20SAndroid Build Coastguard Worker 			;
718*2d543d20SAndroid Build Coastguard Worker opt_ibendport_contexts	: ibendport_contexts
719*2d543d20SAndroid Build Coastguard Worker 			|
720*2d543d20SAndroid Build Coastguard Worker 			;
721*2d543d20SAndroid Build Coastguard Worker ibendport_contexts	: ibendport_context_def
722*2d543d20SAndroid Build Coastguard Worker                         | ibendport_contexts ibendport_context_def
723*2d543d20SAndroid Build Coastguard Worker                         ;
724*2d543d20SAndroid Build Coastguard Worker ibendport_context_def	: IBENDPORTCON identifier number security_context_def
725*2d543d20SAndroid Build Coastguard Worker                         {if (define_ibendport_context($3)) YYABORT;}
726*2d543d20SAndroid Build Coastguard Worker                         ;
727*2d543d20SAndroid Build Coastguard Worker opt_netif_contexts      : netif_contexts
728*2d543d20SAndroid Build Coastguard Worker                         |
729*2d543d20SAndroid Build Coastguard Worker                         ;
730*2d543d20SAndroid Build Coastguard Worker netif_contexts		: netif_context_def
731*2d543d20SAndroid Build Coastguard Worker 			| netif_contexts netif_context_def
732*2d543d20SAndroid Build Coastguard Worker 			;
733*2d543d20SAndroid Build Coastguard Worker netif_context_def	: NETIFCON identifier security_context_def security_context_def
734*2d543d20SAndroid Build Coastguard Worker 			{if (define_netif_context()) YYABORT;}
735*2d543d20SAndroid Build Coastguard Worker 			;
736*2d543d20SAndroid Build Coastguard Worker opt_node_contexts       : node_contexts
737*2d543d20SAndroid Build Coastguard Worker                         |
738*2d543d20SAndroid Build Coastguard Worker                         ;
739*2d543d20SAndroid Build Coastguard Worker node_contexts		: node_context_def
740*2d543d20SAndroid Build Coastguard Worker 			| node_contexts node_context_def
741*2d543d20SAndroid Build Coastguard Worker 			;
742*2d543d20SAndroid Build Coastguard Worker node_context_def	: NODECON ipv4_addr_def ipv4_addr_def security_context_def
743*2d543d20SAndroid Build Coastguard Worker 			{if (define_ipv4_node_context()) YYABORT;}
744*2d543d20SAndroid Build Coastguard Worker 			| NODECON ipv4_cidr_def security_context_def
745*2d543d20SAndroid Build Coastguard Worker 			{if (define_ipv4_cidr_node_context()) YYABORT;}
746*2d543d20SAndroid Build Coastguard Worker 			| NODECON ipv6_addr ipv6_addr security_context_def
747*2d543d20SAndroid Build Coastguard Worker 			{if (define_ipv6_node_context()) YYABORT;}
748*2d543d20SAndroid Build Coastguard Worker 			| NODECON ipv6_cidr security_context_def
749*2d543d20SAndroid Build Coastguard Worker 			{if (define_ipv6_cidr_node_context()) YYABORT;}
750*2d543d20SAndroid Build Coastguard Worker 			;
751*2d543d20SAndroid Build Coastguard Worker opt_fs_uses             : fs_uses
752*2d543d20SAndroid Build Coastguard Worker                         |
753*2d543d20SAndroid Build Coastguard Worker                         ;
754*2d543d20SAndroid Build Coastguard Worker fs_uses                 : fs_use_def
755*2d543d20SAndroid Build Coastguard Worker                         | fs_uses fs_use_def
756*2d543d20SAndroid Build Coastguard Worker                         ;
757*2d543d20SAndroid Build Coastguard Worker fs_use_def              : FSUSEXATTR filesystem security_context_def ';'
758*2d543d20SAndroid Build Coastguard Worker                         {if (define_fs_use(SECURITY_FS_USE_XATTR)) YYABORT;}
759*2d543d20SAndroid Build Coastguard Worker                         | FSUSETASK identifier security_context_def ';'
760*2d543d20SAndroid Build Coastguard Worker                         {if (define_fs_use(SECURITY_FS_USE_TASK)) YYABORT;}
761*2d543d20SAndroid Build Coastguard Worker                         | FSUSETRANS identifier security_context_def ';'
762*2d543d20SAndroid Build Coastguard Worker                         {if (define_fs_use(SECURITY_FS_USE_TRANS)) YYABORT;}
763*2d543d20SAndroid Build Coastguard Worker                         ;
764*2d543d20SAndroid Build Coastguard Worker opt_genfs_contexts      : genfs_contexts
765*2d543d20SAndroid Build Coastguard Worker                         |
766*2d543d20SAndroid Build Coastguard Worker                         ;
767*2d543d20SAndroid Build Coastguard Worker genfs_contexts          : genfs_context_def
768*2d543d20SAndroid Build Coastguard Worker                         | genfs_contexts genfs_context_def
769*2d543d20SAndroid Build Coastguard Worker                         ;
770*2d543d20SAndroid Build Coastguard Worker genfs_context_def	: GENFSCON filesystem path '-' identifier security_context_def
771*2d543d20SAndroid Build Coastguard Worker 			{if (define_genfs_context(1)) YYABORT;}
772*2d543d20SAndroid Build Coastguard Worker 			| GENFSCON filesystem path '-' '-' {insert_id("-", 0);} security_context_def
773*2d543d20SAndroid Build Coastguard Worker 			{if (define_genfs_context(1)) YYABORT;}
774*2d543d20SAndroid Build Coastguard Worker                         | GENFSCON filesystem path security_context_def
775*2d543d20SAndroid Build Coastguard Worker 			{if (define_genfs_context(0)) YYABORT;}
776*2d543d20SAndroid Build Coastguard Worker 			;
777*2d543d20SAndroid Build Coastguard Worker ipv4_addr_def		: IPV4_ADDR
778*2d543d20SAndroid Build Coastguard Worker 			{ if (insert_id(yytext,0)) YYABORT; }
779*2d543d20SAndroid Build Coastguard Worker 			;
780*2d543d20SAndroid Build Coastguard Worker ipv4_cidr_def		: IPV4_CIDR
781*2d543d20SAndroid Build Coastguard Worker 			{ if (insert_id(yytext,0)) YYABORT; }
782*2d543d20SAndroid Build Coastguard Worker 			;
783*2d543d20SAndroid Build Coastguard Worker xperms		: xperm
784*2d543d20SAndroid Build Coastguard Worker 			{ if (insert_separator(0)) YYABORT; }
785*2d543d20SAndroid Build Coastguard Worker 			| nested_xperm_set
786*2d543d20SAndroid Build Coastguard Worker 			{ if (insert_separator(0)) YYABORT; }
787*2d543d20SAndroid Build Coastguard Worker 			| tilde xperm
788*2d543d20SAndroid Build Coastguard Worker                         { if (insert_id("~", 0)) YYABORT; }
789*2d543d20SAndroid Build Coastguard Worker 			| tilde nested_xperm_set
790*2d543d20SAndroid Build Coastguard Worker 			{ if (insert_id("~", 0)) YYABORT;
791*2d543d20SAndroid Build Coastguard Worker 			  if (insert_separator(0)) YYABORT; }
792*2d543d20SAndroid Build Coastguard Worker 			;
793*2d543d20SAndroid Build Coastguard Worker nested_xperm_set	: '{' nested_xperm_list '}'
794*2d543d20SAndroid Build Coastguard Worker 			;
795*2d543d20SAndroid Build Coastguard Worker nested_xperm_list	: nested_xperm_element
796*2d543d20SAndroid Build Coastguard Worker 			| nested_xperm_list nested_xperm_element
797*2d543d20SAndroid Build Coastguard Worker 			;
798*2d543d20SAndroid Build Coastguard Worker nested_xperm_element: xperm '-' { if (insert_id("-", 0)) YYABORT; } xperm
799*2d543d20SAndroid Build Coastguard Worker 			| xperm
800*2d543d20SAndroid Build Coastguard Worker 			| nested_xperm_set
801*2d543d20SAndroid Build Coastguard Worker 			;
802*2d543d20SAndroid Build Coastguard Worker xperm		: number
803*2d543d20SAndroid Build Coastguard Worker                         { if (insert_id(yytext,0)) YYABORT; }
804*2d543d20SAndroid Build Coastguard Worker 			;
805*2d543d20SAndroid Build Coastguard Worker security_context_def	: identifier ':' identifier ':' identifier opt_mls_range_def
806*2d543d20SAndroid Build Coastguard Worker 	                ;
807*2d543d20SAndroid Build Coastguard Worker opt_mls_range_def	: ':' mls_range_def
808*2d543d20SAndroid Build Coastguard Worker 			|
809*2d543d20SAndroid Build Coastguard Worker 			;
810*2d543d20SAndroid Build Coastguard Worker mls_range_def		: mls_level_def '-' mls_level_def
811*2d543d20SAndroid Build Coastguard Worker 			{if (insert_separator(0)) YYABORT;}
812*2d543d20SAndroid Build Coastguard Worker 	                | mls_level_def
813*2d543d20SAndroid Build Coastguard Worker 			{if (insert_separator(0)) YYABORT;}
814*2d543d20SAndroid Build Coastguard Worker 	                ;
815*2d543d20SAndroid Build Coastguard Worker mls_level_def		: identifier ':' id_comma_list
816*2d543d20SAndroid Build Coastguard Worker 			{if (insert_separator(0)) YYABORT;}
817*2d543d20SAndroid Build Coastguard Worker 	                | identifier
818*2d543d20SAndroid Build Coastguard Worker 			{if (insert_separator(0)) YYABORT;}
819*2d543d20SAndroid Build Coastguard Worker 	                ;
820*2d543d20SAndroid Build Coastguard Worker id_comma_list           : identifier
821*2d543d20SAndroid Build Coastguard Worker 			| id_comma_list ',' identifier
822*2d543d20SAndroid Build Coastguard Worker 			;
823*2d543d20SAndroid Build Coastguard Worker tilde			: '~'
824*2d543d20SAndroid Build Coastguard Worker 			;
825*2d543d20SAndroid Build Coastguard Worker asterisk		: '*'
826*2d543d20SAndroid Build Coastguard Worker 			;
827*2d543d20SAndroid Build Coastguard Worker names           	: identifier
828*2d543d20SAndroid Build Coastguard Worker 			{ if (insert_separator(0)) YYABORT; }
829*2d543d20SAndroid Build Coastguard Worker 			| nested_id_set
830*2d543d20SAndroid Build Coastguard Worker 			{ if (insert_separator(0)) YYABORT; }
831*2d543d20SAndroid Build Coastguard Worker 			| asterisk
832*2d543d20SAndroid Build Coastguard Worker                         { if (insert_id("*", 0)) YYABORT;
833*2d543d20SAndroid Build Coastguard Worker 			  if (insert_separator(0)) YYABORT; }
834*2d543d20SAndroid Build Coastguard Worker 			| tilde identifier
835*2d543d20SAndroid Build Coastguard Worker                         { if (insert_id("~", 0)) YYABORT;
836*2d543d20SAndroid Build Coastguard Worker 			  if (insert_separator(0)) YYABORT; }
837*2d543d20SAndroid Build Coastguard Worker 			| tilde nested_id_set
838*2d543d20SAndroid Build Coastguard Worker 			{ if (insert_id("~", 0)) YYABORT;
839*2d543d20SAndroid Build Coastguard Worker 			  if (insert_separator(0)) YYABORT; }
840*2d543d20SAndroid Build Coastguard Worker                         | identifier '-' { if (insert_id("-", 0)) YYABORT; } identifier
841*2d543d20SAndroid Build Coastguard Worker 			{ if (insert_separator(0)) YYABORT; }
842*2d543d20SAndroid Build Coastguard Worker 			;
843*2d543d20SAndroid Build Coastguard Worker tilde_push              : tilde
844*2d543d20SAndroid Build Coastguard Worker                         { if (insert_id("~", 1)) YYABORT; }
845*2d543d20SAndroid Build Coastguard Worker 			;
846*2d543d20SAndroid Build Coastguard Worker asterisk_push           : asterisk
847*2d543d20SAndroid Build Coastguard Worker                         { if (insert_id("*", 1)) YYABORT; }
848*2d543d20SAndroid Build Coastguard Worker 			;
849*2d543d20SAndroid Build Coastguard Worker names_push		: identifier_push
850*2d543d20SAndroid Build Coastguard Worker 			| '{' identifier_list_push '}'
851*2d543d20SAndroid Build Coastguard Worker 			| asterisk_push
852*2d543d20SAndroid Build Coastguard Worker 			| tilde_push identifier_push
853*2d543d20SAndroid Build Coastguard Worker 			| tilde_push '{' identifier_list_push '}'
854*2d543d20SAndroid Build Coastguard Worker 			;
855*2d543d20SAndroid Build Coastguard Worker identifier_list_push	: identifier_push
856*2d543d20SAndroid Build Coastguard Worker 			| identifier_list_push identifier_push
857*2d543d20SAndroid Build Coastguard Worker 			;
858*2d543d20SAndroid Build Coastguard Worker identifier_push		: IDENTIFIER
859*2d543d20SAndroid Build Coastguard Worker 			{ if (insert_id(yytext, 1)) YYABORT; }
860*2d543d20SAndroid Build Coastguard Worker 			;
861*2d543d20SAndroid Build Coastguard Worker identifier_list		: identifier
862*2d543d20SAndroid Build Coastguard Worker 			| identifier_list identifier
863*2d543d20SAndroid Build Coastguard Worker 			;
864*2d543d20SAndroid Build Coastguard Worker nested_id_set           : '{' nested_id_list '}'
865*2d543d20SAndroid Build Coastguard Worker                         ;
866*2d543d20SAndroid Build Coastguard Worker nested_id_list          : nested_id_element | nested_id_list nested_id_element
867*2d543d20SAndroid Build Coastguard Worker                         ;
868*2d543d20SAndroid Build Coastguard Worker nested_id_element       : identifier | '-' { if (insert_id("-", 0)) YYABORT; } identifier | nested_id_set
869*2d543d20SAndroid Build Coastguard Worker                         ;
870*2d543d20SAndroid Build Coastguard Worker identifier		: IDENTIFIER
871*2d543d20SAndroid Build Coastguard Worker 			{ if (insert_id(yytext,0)) YYABORT; }
872*2d543d20SAndroid Build Coastguard Worker 			;
873*2d543d20SAndroid Build Coastguard Worker filesystem		: FILESYSTEM
874*2d543d20SAndroid Build Coastguard Worker                         { if (insert_id(yytext,0)) YYABORT; }
875*2d543d20SAndroid Build Coastguard Worker                         | IDENTIFIER
876*2d543d20SAndroid Build Coastguard Worker 			{ if (insert_id(yytext,0)) YYABORT; }
877*2d543d20SAndroid Build Coastguard Worker                         ;
878*2d543d20SAndroid Build Coastguard Worker path     		: PATH
879*2d543d20SAndroid Build Coastguard Worker 			{ if (insert_id(yytext,0)) YYABORT; }
880*2d543d20SAndroid Build Coastguard Worker 			| QPATH
881*2d543d20SAndroid Build Coastguard Worker 			{ yytext[strlen(yytext) - 1] = '\0'; if (insert_id(yytext + 1,0)) YYABORT; }
882*2d543d20SAndroid Build Coastguard Worker 			;
883*2d543d20SAndroid Build Coastguard Worker filename		: FILENAME
884*2d543d20SAndroid Build Coastguard Worker 			{ yytext[strlen(yytext) - 1] = '\0'; if (insert_id(yytext + 1,0)) YYABORT; }
885*2d543d20SAndroid Build Coastguard Worker 			;
886*2d543d20SAndroid Build Coastguard Worker number			: NUMBER
887*2d543d20SAndroid Build Coastguard Worker 			{ unsigned long x;
888*2d543d20SAndroid Build Coastguard Worker 			  errno = 0;
889*2d543d20SAndroid Build Coastguard Worker 			  x = strtoul(yytext, NULL, 0);
890*2d543d20SAndroid Build Coastguard Worker 			  if (errno)
891*2d543d20SAndroid Build Coastguard Worker 			      YYABORT;
892*2d543d20SAndroid Build Coastguard Worker #if ULONG_MAX > UINT_MAX
893*2d543d20SAndroid Build Coastguard Worker 			  if (x > UINT_MAX)
894*2d543d20SAndroid Build Coastguard Worker 			      YYABORT;
895*2d543d20SAndroid Build Coastguard Worker #endif
896*2d543d20SAndroid Build Coastguard Worker 			  $$ = (unsigned int) x;
897*2d543d20SAndroid Build Coastguard Worker 			}
898*2d543d20SAndroid Build Coastguard Worker 			;
899*2d543d20SAndroid Build Coastguard Worker number64		: NUMBER
900*2d543d20SAndroid Build Coastguard Worker 			{ unsigned long long x;
901*2d543d20SAndroid Build Coastguard Worker 			  errno = 0;
902*2d543d20SAndroid Build Coastguard Worker 			  x = strtoull(yytext, NULL, 0);
903*2d543d20SAndroid Build Coastguard Worker 			  if (errno)
904*2d543d20SAndroid Build Coastguard Worker 			      YYABORT;
905*2d543d20SAndroid Build Coastguard Worker 			  $$ = (uint64_t) x;
906*2d543d20SAndroid Build Coastguard Worker 			}
907*2d543d20SAndroid Build Coastguard Worker 			;
908*2d543d20SAndroid Build Coastguard Worker ipv6_addr		: IPV6_ADDR
909*2d543d20SAndroid Build Coastguard Worker 			{ if (insert_id(yytext,0)) YYABORT; }
910*2d543d20SAndroid Build Coastguard Worker 			;
911*2d543d20SAndroid Build Coastguard Worker ipv6_cidr		: IPV6_CIDR
912*2d543d20SAndroid Build Coastguard Worker 			{ if (insert_id(yytext,0)) YYABORT; }
913*2d543d20SAndroid Build Coastguard Worker 			;
914*2d543d20SAndroid Build Coastguard Worker policycap_def		: POLICYCAP identifier ';'
915*2d543d20SAndroid Build Coastguard Worker 			{if (define_polcap()) YYABORT;}
916*2d543d20SAndroid Build Coastguard Worker 			;
917*2d543d20SAndroid Build Coastguard Worker permissive_def		: PERMISSIVE identifier ';'
918*2d543d20SAndroid Build Coastguard Worker 			{if (define_permissive()) YYABORT;}
919*2d543d20SAndroid Build Coastguard Worker 
920*2d543d20SAndroid Build Coastguard Worker /*********** module grammar below ***********/
921*2d543d20SAndroid Build Coastguard Worker 
922*2d543d20SAndroid Build Coastguard Worker module_policy           : module_def avrules_block
923*2d543d20SAndroid Build Coastguard Worker                         { if (end_avrule_block(pass) == -1) YYABORT;
924*2d543d20SAndroid Build Coastguard Worker                           if (policydb_index_others(NULL, policydbp, 0)) YYABORT;
925*2d543d20SAndroid Build Coastguard Worker                         }
926*2d543d20SAndroid Build Coastguard Worker                         ;
927*2d543d20SAndroid Build Coastguard Worker module_def              : MODULE identifier version_identifier ';'
928*2d543d20SAndroid Build Coastguard Worker                         { if (define_policy(pass, 1) == -1) YYABORT; }
929*2d543d20SAndroid Build Coastguard Worker                         ;
930*2d543d20SAndroid Build Coastguard Worker version_identifier      : VERSION_IDENTIFIER
931*2d543d20SAndroid Build Coastguard Worker                         { if (insert_id(yytext,0)) YYABORT; }
932*2d543d20SAndroid Build Coastguard Worker 			| number
933*2d543d20SAndroid Build Coastguard Worker                         { if (insert_id(yytext,0)) YYABORT; }
934*2d543d20SAndroid Build Coastguard Worker                         | ipv4_addr_def /* version can look like ipv4 address */
935*2d543d20SAndroid Build Coastguard Worker                         ;
936*2d543d20SAndroid Build Coastguard Worker avrules_block           : avrule_decls avrule_user_defs
937*2d543d20SAndroid Build Coastguard Worker                         ;
938*2d543d20SAndroid Build Coastguard Worker avrule_decls            : avrule_decls avrule_decl
939*2d543d20SAndroid Build Coastguard Worker                         | avrule_decl
940*2d543d20SAndroid Build Coastguard Worker                         ;
941*2d543d20SAndroid Build Coastguard Worker avrule_decl             : rbac_decl
942*2d543d20SAndroid Build Coastguard Worker                         | te_decl
943*2d543d20SAndroid Build Coastguard Worker                         | cond_stmt_def
944*2d543d20SAndroid Build Coastguard Worker                         | require_block
945*2d543d20SAndroid Build Coastguard Worker                         | optional_block
946*2d543d20SAndroid Build Coastguard Worker                         | ';'
947*2d543d20SAndroid Build Coastguard Worker                         ;
948*2d543d20SAndroid Build Coastguard Worker require_block           : REQUIRE '{' require_list '}'
949*2d543d20SAndroid Build Coastguard Worker                         ;
950*2d543d20SAndroid Build Coastguard Worker require_list            : require_list require_decl
951*2d543d20SAndroid Build Coastguard Worker                         | require_decl
952*2d543d20SAndroid Build Coastguard Worker                         ;
953*2d543d20SAndroid Build Coastguard Worker require_decl            : require_class ';'
954*2d543d20SAndroid Build Coastguard Worker                         | require_decl_def require_id_list ';'
955*2d543d20SAndroid Build Coastguard Worker                         ;
956*2d543d20SAndroid Build Coastguard Worker require_class           : CLASS identifier names
957*2d543d20SAndroid Build Coastguard Worker                         { if (require_class(pass)) YYABORT; }
958*2d543d20SAndroid Build Coastguard Worker                         ;
959*2d543d20SAndroid Build Coastguard Worker require_decl_def        : ROLE        { $$ = require_role; }
960*2d543d20SAndroid Build Coastguard Worker                         | TYPE        { $$ = require_type; }
961*2d543d20SAndroid Build Coastguard Worker                         | ATTRIBUTE   { $$ = require_attribute; }
962*2d543d20SAndroid Build Coastguard Worker                         | ATTRIBUTE_ROLE   { $$ = require_attribute_role; }
963*2d543d20SAndroid Build Coastguard Worker                         | USER        { $$ = require_user; }
964*2d543d20SAndroid Build Coastguard Worker                         | BOOL        { $$ = require_bool; }
965*2d543d20SAndroid Build Coastguard Worker 			| TUNABLE     { $$ = require_tunable; }
966*2d543d20SAndroid Build Coastguard Worker                         | SENSITIVITY { $$ = require_sens; }
967*2d543d20SAndroid Build Coastguard Worker                         | CATEGORY    { $$ = require_cat; }
968*2d543d20SAndroid Build Coastguard Worker                         ;
969*2d543d20SAndroid Build Coastguard Worker require_id_list         : identifier
970*2d543d20SAndroid Build Coastguard Worker                         { if ($<require_func>0 (pass)) YYABORT; }
971*2d543d20SAndroid Build Coastguard Worker                         | require_id_list ',' identifier
972*2d543d20SAndroid Build Coastguard Worker                         { if ($<require_func>0 (pass)) YYABORT; }
973*2d543d20SAndroid Build Coastguard Worker                         ;
974*2d543d20SAndroid Build Coastguard Worker optional_block          : optional_decl '{' avrules_block '}'
975*2d543d20SAndroid Build Coastguard Worker                         { if (end_avrule_block(pass) == -1) YYABORT; }
976*2d543d20SAndroid Build Coastguard Worker                           optional_else
977*2d543d20SAndroid Build Coastguard Worker                         { if (end_optional(pass) == -1) YYABORT; }
978*2d543d20SAndroid Build Coastguard Worker                         ;
979*2d543d20SAndroid Build Coastguard Worker optional_else           : else_decl '{' avrules_block '}'
980*2d543d20SAndroid Build Coastguard Worker                         { if (end_avrule_block(pass) == -1) YYABORT; }
981*2d543d20SAndroid Build Coastguard Worker                         | /* empty */
982*2d543d20SAndroid Build Coastguard Worker                         ;
983*2d543d20SAndroid Build Coastguard Worker optional_decl           : OPTIONAL
984*2d543d20SAndroid Build Coastguard Worker                         { if (begin_optional(pass) == -1) YYABORT; }
985*2d543d20SAndroid Build Coastguard Worker                         ;
986*2d543d20SAndroid Build Coastguard Worker else_decl               : ELSE
987*2d543d20SAndroid Build Coastguard Worker                         { if (begin_optional_else(pass) == -1) YYABORT; }
988*2d543d20SAndroid Build Coastguard Worker                         ;
989*2d543d20SAndroid Build Coastguard Worker avrule_user_defs        : user_def avrule_user_defs
990*2d543d20SAndroid Build Coastguard Worker                         | /* empty */
991*2d543d20SAndroid Build Coastguard Worker                         ;
992