xref: /aosp_15_r20/system/sepolicy/tools/sepolicy-check.c (revision e4a36f4174b17bbab9dc043f4a65dc8d87377290)
1*e4a36f41SAndroid Build Coastguard Worker #include <getopt.h>
2*e4a36f41SAndroid Build Coastguard Worker #include <unistd.h>
3*e4a36f41SAndroid Build Coastguard Worker #include <stdlib.h>
4*e4a36f41SAndroid Build Coastguard Worker #include <sys/mman.h>
5*e4a36f41SAndroid Build Coastguard Worker #include <sys/types.h>
6*e4a36f41SAndroid Build Coastguard Worker #include <sys/stat.h>
7*e4a36f41SAndroid Build Coastguard Worker #include <fcntl.h>
8*e4a36f41SAndroid Build Coastguard Worker #include <stdio.h>
9*e4a36f41SAndroid Build Coastguard Worker #include <sepol/policydb/policydb.h>
10*e4a36f41SAndroid Build Coastguard Worker #include <sepol/policydb/services.h>
11*e4a36f41SAndroid Build Coastguard Worker #include <sepol/policydb/expand.h>
12*e4a36f41SAndroid Build Coastguard Worker 
13*e4a36f41SAndroid Build Coastguard Worker #define EQUALS 0
14*e4a36f41SAndroid Build Coastguard Worker #define NOT 1
15*e4a36f41SAndroid Build Coastguard Worker #define ANY 2
16*e4a36f41SAndroid Build Coastguard Worker 
usage(char * arg0)17*e4a36f41SAndroid Build Coastguard Worker void usage(char *arg0) {
18*e4a36f41SAndroid Build Coastguard Worker 	fprintf(stderr, "%s -s <source> -t <target> -c <class> -p <perm> -P <policy file>\n", arg0);
19*e4a36f41SAndroid Build Coastguard Worker 	exit(1);
20*e4a36f41SAndroid Build Coastguard Worker }
21*e4a36f41SAndroid Build Coastguard Worker 
cmalloc(size_t s)22*e4a36f41SAndroid Build Coastguard Worker void *cmalloc(size_t s) {
23*e4a36f41SAndroid Build Coastguard Worker 	void *t = malloc(s);
24*e4a36f41SAndroid Build Coastguard Worker 	if (t == NULL) {
25*e4a36f41SAndroid Build Coastguard Worker 		fprintf(stderr, "Out of memory\n");
26*e4a36f41SAndroid Build Coastguard Worker 		exit(1);
27*e4a36f41SAndroid Build Coastguard Worker 	}
28*e4a36f41SAndroid Build Coastguard Worker 	return t;
29*e4a36f41SAndroid Build Coastguard Worker }
30*e4a36f41SAndroid Build Coastguard Worker 
parse_ops(char ** arg)31*e4a36f41SAndroid Build Coastguard Worker int parse_ops(char **arg) {
32*e4a36f41SAndroid Build Coastguard Worker 	switch (*arg[0]) {
33*e4a36f41SAndroid Build Coastguard Worker 		case '-':
34*e4a36f41SAndroid Build Coastguard Worker 			*arg = *arg + 1;
35*e4a36f41SAndroid Build Coastguard Worker 			return NOT;
36*e4a36f41SAndroid Build Coastguard Worker 		case '*':
37*e4a36f41SAndroid Build Coastguard Worker 			return ANY;
38*e4a36f41SAndroid Build Coastguard Worker 		default:
39*e4a36f41SAndroid Build Coastguard Worker 			return EQUALS;
40*e4a36f41SAndroid Build Coastguard Worker 	}
41*e4a36f41SAndroid Build Coastguard Worker }
42*e4a36f41SAndroid Build Coastguard Worker 
check(int op,uint16_t arg1,uint16_t arg2)43*e4a36f41SAndroid Build Coastguard Worker int check(int op, uint16_t arg1, uint16_t arg2) {
44*e4a36f41SAndroid Build Coastguard Worker 	switch (op) {
45*e4a36f41SAndroid Build Coastguard Worker 		case EQUALS:
46*e4a36f41SAndroid Build Coastguard Worker 			return arg1 == arg2;
47*e4a36f41SAndroid Build Coastguard Worker 		case NOT:
48*e4a36f41SAndroid Build Coastguard Worker 			return arg1 != arg2;
49*e4a36f41SAndroid Build Coastguard Worker 		case ANY:
50*e4a36f41SAndroid Build Coastguard Worker 			return 1;
51*e4a36f41SAndroid Build Coastguard Worker 		default:
52*e4a36f41SAndroid Build Coastguard Worker 			fprintf(stderr, "Bad op while checking!");
53*e4a36f41SAndroid Build Coastguard Worker 			return 2;
54*e4a36f41SAndroid Build Coastguard Worker 	}
55*e4a36f41SAndroid Build Coastguard Worker }
56*e4a36f41SAndroid Build Coastguard Worker 
check_perm(avtab_ptr_t current,perm_datum_t * perm)57*e4a36f41SAndroid Build Coastguard Worker int check_perm(avtab_ptr_t current, perm_datum_t *perm) {
58*e4a36f41SAndroid Build Coastguard Worker 	uint16_t perm_bitmask = 1U << (perm->s.value - 1);
59*e4a36f41SAndroid Build Coastguard Worker 	return (current->datum.data & perm_bitmask) != 0;
60*e4a36f41SAndroid Build Coastguard Worker }
61*e4a36f41SAndroid Build Coastguard Worker 
62*e4a36f41SAndroid Build Coastguard Worker 
expand_and_check(int s_op,uint32_t source_type,int t_op,uint32_t target_type,int c_op,uint32_t target_class,perm_datum_t * perm,policydb_t * policy,avtab_t * avtab)63*e4a36f41SAndroid Build Coastguard Worker int expand_and_check(int s_op, uint32_t source_type,
64*e4a36f41SAndroid Build Coastguard Worker 		     int t_op, uint32_t target_type,
65*e4a36f41SAndroid Build Coastguard Worker 		     int c_op, uint32_t target_class,
66*e4a36f41SAndroid Build Coastguard Worker 		     perm_datum_t *perm, policydb_t *policy, avtab_t *avtab) {
67*e4a36f41SAndroid Build Coastguard Worker 	avtab_t exp_avtab;
68*e4a36f41SAndroid Build Coastguard Worker 	avtab_ptr_t cur;
69*e4a36f41SAndroid Build Coastguard Worker 	unsigned int i;
70*e4a36f41SAndroid Build Coastguard Worker 	int match;
71*e4a36f41SAndroid Build Coastguard Worker 
72*e4a36f41SAndroid Build Coastguard Worker 	if (avtab_init(&exp_avtab)) {
73*e4a36f41SAndroid Build Coastguard Worker 		fputs("out of memory\n", stderr);
74*e4a36f41SAndroid Build Coastguard Worker 		return -1;
75*e4a36f41SAndroid Build Coastguard Worker 	}
76*e4a36f41SAndroid Build Coastguard Worker 
77*e4a36f41SAndroid Build Coastguard Worker 	if (expand_avtab(policy, avtab, &exp_avtab)) {
78*e4a36f41SAndroid Build Coastguard Worker 		fputs("out of memory\n", stderr);
79*e4a36f41SAndroid Build Coastguard Worker 		avtab_destroy(&exp_avtab);
80*e4a36f41SAndroid Build Coastguard Worker 		return -1;
81*e4a36f41SAndroid Build Coastguard Worker 	}
82*e4a36f41SAndroid Build Coastguard Worker 
83*e4a36f41SAndroid Build Coastguard Worker 	for (i = 0; i < exp_avtab.nslot; i++) {
84*e4a36f41SAndroid Build Coastguard Worker 		for (cur = exp_avtab.htable[i]; cur; cur = cur->next) {
85*e4a36f41SAndroid Build Coastguard Worker 			match = 1;
86*e4a36f41SAndroid Build Coastguard Worker 			match &= check(s_op, source_type, cur->key.source_type);
87*e4a36f41SAndroid Build Coastguard Worker 			match &= check(t_op, target_type, cur->key.target_type);
88*e4a36f41SAndroid Build Coastguard Worker 			match &= check(c_op, target_class, cur->key.target_class);
89*e4a36f41SAndroid Build Coastguard Worker 			match &= check_perm(cur, perm);
90*e4a36f41SAndroid Build Coastguard Worker 			if (match) {
91*e4a36f41SAndroid Build Coastguard Worker 				avtab_destroy(&exp_avtab);
92*e4a36f41SAndroid Build Coastguard Worker 				return 1;
93*e4a36f41SAndroid Build Coastguard Worker 			}
94*e4a36f41SAndroid Build Coastguard Worker 		}
95*e4a36f41SAndroid Build Coastguard Worker 	}
96*e4a36f41SAndroid Build Coastguard Worker 
97*e4a36f41SAndroid Build Coastguard Worker 	avtab_destroy(&exp_avtab);
98*e4a36f41SAndroid Build Coastguard Worker 	return 0;
99*e4a36f41SAndroid Build Coastguard Worker }
100*e4a36f41SAndroid Build Coastguard Worker 
101*e4a36f41SAndroid Build Coastguard Worker /*
102*e4a36f41SAndroid Build Coastguard Worker  * Checks to see if a rule matching the given arguments already exists.
103*e4a36f41SAndroid Build Coastguard Worker  *
104*e4a36f41SAndroid Build Coastguard Worker  * The format for the arguments is as follows:
105*e4a36f41SAndroid Build Coastguard Worker  *
106*e4a36f41SAndroid Build Coastguard Worker  * - A bare string is treated as a literal and will be matched by equality.
107*e4a36f41SAndroid Build Coastguard Worker  * - A string starting with "-" will be matched by inequality.
108*e4a36f41SAndroid Build Coastguard Worker  * - A string starting with "*" will be treated as a wildcard.
109*e4a36f41SAndroid Build Coastguard Worker  *
110*e4a36f41SAndroid Build Coastguard Worker  * The return codes for this function are as follows:
111*e4a36f41SAndroid Build Coastguard Worker  *
112*e4a36f41SAndroid Build Coastguard Worker  * - 0 indicates a successful return without a match
113*e4a36f41SAndroid Build Coastguard Worker  * - 1 indicates a successful return with a match
114*e4a36f41SAndroid Build Coastguard Worker  * - -1 indicates an error
115*e4a36f41SAndroid Build Coastguard Worker  */
check_rule(char * s,char * t,char * c,char * p,policydb_t * policy)116*e4a36f41SAndroid Build Coastguard Worker int check_rule(char *s, char *t, char *c, char *p, policydb_t *policy) {
117*e4a36f41SAndroid Build Coastguard Worker 	type_datum_t *src = NULL;
118*e4a36f41SAndroid Build Coastguard Worker 	type_datum_t *tgt = NULL;
119*e4a36f41SAndroid Build Coastguard Worker 	class_datum_t *cls = NULL;
120*e4a36f41SAndroid Build Coastguard Worker 	perm_datum_t *perm = NULL;
121*e4a36f41SAndroid Build Coastguard Worker 	int s_op = parse_ops(&s);
122*e4a36f41SAndroid Build Coastguard Worker 	int t_op = parse_ops(&t);
123*e4a36f41SAndroid Build Coastguard Worker 	int c_op = parse_ops(&c);
124*e4a36f41SAndroid Build Coastguard Worker 	int p_op = parse_ops(&p);
125*e4a36f41SAndroid Build Coastguard Worker 	avtab_key_t key;
126*e4a36f41SAndroid Build Coastguard Worker 	int match;
127*e4a36f41SAndroid Build Coastguard Worker 
128*e4a36f41SAndroid Build Coastguard Worker 	key.source_type = key.target_type = key.target_class = 0;
129*e4a36f41SAndroid Build Coastguard Worker 
130*e4a36f41SAndroid Build Coastguard Worker 	if (s_op != ANY) {
131*e4a36f41SAndroid Build Coastguard Worker 		src = hashtab_search(policy->p_types.table, s);
132*e4a36f41SAndroid Build Coastguard Worker 		if (src == NULL) {
133*e4a36f41SAndroid Build Coastguard Worker 			fprintf(stderr, "source type %s does not exist\n", s);
134*e4a36f41SAndroid Build Coastguard Worker 			return -1;
135*e4a36f41SAndroid Build Coastguard Worker 		}
136*e4a36f41SAndroid Build Coastguard Worker 	}
137*e4a36f41SAndroid Build Coastguard Worker 	if (t_op != ANY) {
138*e4a36f41SAndroid Build Coastguard Worker 		tgt = hashtab_search(policy->p_types.table, t);
139*e4a36f41SAndroid Build Coastguard Worker 		if (tgt == NULL) {
140*e4a36f41SAndroid Build Coastguard Worker 			fprintf(stderr, "target type %s does not exist\n", t);
141*e4a36f41SAndroid Build Coastguard Worker 			return -1;
142*e4a36f41SAndroid Build Coastguard Worker 		}
143*e4a36f41SAndroid Build Coastguard Worker 	}
144*e4a36f41SAndroid Build Coastguard Worker 	if (c_op != ANY) {
145*e4a36f41SAndroid Build Coastguard Worker 		cls = hashtab_search(policy->p_classes.table, c);
146*e4a36f41SAndroid Build Coastguard Worker 		if (cls == NULL) {
147*e4a36f41SAndroid Build Coastguard Worker 			fprintf(stderr, "class %s does not exist\n", c);
148*e4a36f41SAndroid Build Coastguard Worker 			return -1;
149*e4a36f41SAndroid Build Coastguard Worker 		}
150*e4a36f41SAndroid Build Coastguard Worker 	}
151*e4a36f41SAndroid Build Coastguard Worker 	if (p_op != ANY) {
152*e4a36f41SAndroid Build Coastguard Worker 		perm = hashtab_search(cls->permissions.table, p);
153*e4a36f41SAndroid Build Coastguard Worker 		if (perm == NULL) {
154*e4a36f41SAndroid Build Coastguard Worker 			if (cls->comdatum == NULL) {
155*e4a36f41SAndroid Build Coastguard Worker 				fprintf(stderr, "perm %s does not exist in class %s\n", p, c);
156*e4a36f41SAndroid Build Coastguard Worker 				return -1;
157*e4a36f41SAndroid Build Coastguard Worker 			}
158*e4a36f41SAndroid Build Coastguard Worker 			perm = hashtab_search(cls->comdatum->permissions.table, p);
159*e4a36f41SAndroid Build Coastguard Worker 			if (perm == NULL) {
160*e4a36f41SAndroid Build Coastguard Worker 				fprintf(stderr, "perm %s does not exist in class %s\n", p, c);
161*e4a36f41SAndroid Build Coastguard Worker 				return -1;
162*e4a36f41SAndroid Build Coastguard Worker 			}
163*e4a36f41SAndroid Build Coastguard Worker 		}
164*e4a36f41SAndroid Build Coastguard Worker 	}
165*e4a36f41SAndroid Build Coastguard Worker 
166*e4a36f41SAndroid Build Coastguard Worker 	if (s_op != ANY)
167*e4a36f41SAndroid Build Coastguard Worker 		key.source_type = src->s.value;
168*e4a36f41SAndroid Build Coastguard Worker 	if (t_op != ANY)
169*e4a36f41SAndroid Build Coastguard Worker 		key.target_type = tgt->s.value;
170*e4a36f41SAndroid Build Coastguard Worker 	if (c_op != ANY)
171*e4a36f41SAndroid Build Coastguard Worker 		key.target_class = cls->s.value;
172*e4a36f41SAndroid Build Coastguard Worker 
173*e4a36f41SAndroid Build Coastguard Worker 	/* Check unconditional rules after attribute expansion. */
174*e4a36f41SAndroid Build Coastguard Worker 	match = expand_and_check(s_op, key.source_type,
175*e4a36f41SAndroid Build Coastguard Worker 				 t_op, key.target_type,
176*e4a36f41SAndroid Build Coastguard Worker 				 c_op, key.target_class,
177*e4a36f41SAndroid Build Coastguard Worker 				 perm, policy, &policy->te_avtab);
178*e4a36f41SAndroid Build Coastguard Worker 	if (match)
179*e4a36f41SAndroid Build Coastguard Worker 		return match;
180*e4a36f41SAndroid Build Coastguard Worker 
181*e4a36f41SAndroid Build Coastguard Worker 	/* Check conditional rules after attribute expansion. */
182*e4a36f41SAndroid Build Coastguard Worker 	return expand_and_check(s_op, key.source_type,
183*e4a36f41SAndroid Build Coastguard Worker 				t_op, key.target_type,
184*e4a36f41SAndroid Build Coastguard Worker 				c_op, key.target_class,
185*e4a36f41SAndroid Build Coastguard Worker 				perm, policy, &policy->te_cond_avtab);
186*e4a36f41SAndroid Build Coastguard Worker }
187*e4a36f41SAndroid Build Coastguard Worker 
load_policy(char * filename,policydb_t * policydb,struct policy_file * pf)188*e4a36f41SAndroid Build Coastguard Worker int load_policy(char *filename, policydb_t *policydb, struct policy_file *pf) {
189*e4a36f41SAndroid Build Coastguard Worker 	int fd;
190*e4a36f41SAndroid Build Coastguard Worker 	struct stat sb;
191*e4a36f41SAndroid Build Coastguard Worker 	void *map;
192*e4a36f41SAndroid Build Coastguard Worker 	int ret;
193*e4a36f41SAndroid Build Coastguard Worker 
194*e4a36f41SAndroid Build Coastguard Worker 	fd = open(filename, O_RDONLY);
195*e4a36f41SAndroid Build Coastguard Worker 	if (fd < 0) {
196*e4a36f41SAndroid Build Coastguard Worker 		fprintf(stderr, "Can't open '%s':  %s\n", filename, strerror(errno));
197*e4a36f41SAndroid Build Coastguard Worker 		return 1;
198*e4a36f41SAndroid Build Coastguard Worker 	}
199*e4a36f41SAndroid Build Coastguard Worker 	if (fstat(fd, &sb) < 0) {
200*e4a36f41SAndroid Build Coastguard Worker 		fprintf(stderr, "Can't stat '%s':  %s\n", filename, strerror(errno));
201*e4a36f41SAndroid Build Coastguard Worker 		close(fd);
202*e4a36f41SAndroid Build Coastguard Worker 		return 1;
203*e4a36f41SAndroid Build Coastguard Worker 	}
204*e4a36f41SAndroid Build Coastguard Worker 	map = mmap(NULL, sb.st_size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
205*e4a36f41SAndroid Build Coastguard Worker 	if (map == MAP_FAILED) {
206*e4a36f41SAndroid Build Coastguard Worker 		fprintf(stderr, "Can't mmap '%s':  %s\n", filename, strerror(errno));
207*e4a36f41SAndroid Build Coastguard Worker 		close(fd);
208*e4a36f41SAndroid Build Coastguard Worker 		return 1;
209*e4a36f41SAndroid Build Coastguard Worker 	}
210*e4a36f41SAndroid Build Coastguard Worker 
211*e4a36f41SAndroid Build Coastguard Worker 	policy_file_init(pf);
212*e4a36f41SAndroid Build Coastguard Worker 	pf->type = PF_USE_MEMORY;
213*e4a36f41SAndroid Build Coastguard Worker 	pf->data = map;
214*e4a36f41SAndroid Build Coastguard Worker 	pf->len = sb.st_size;
215*e4a36f41SAndroid Build Coastguard Worker 	if (policydb_init(policydb)) {
216*e4a36f41SAndroid Build Coastguard Worker 		fprintf(stderr, "Could not initialize policydb!\n");
217*e4a36f41SAndroid Build Coastguard Worker 		close(fd);
218*e4a36f41SAndroid Build Coastguard Worker 		munmap(map, sb.st_size);
219*e4a36f41SAndroid Build Coastguard Worker 		return 1;
220*e4a36f41SAndroid Build Coastguard Worker 	}
221*e4a36f41SAndroid Build Coastguard Worker 	ret = policydb_read(policydb, pf, 0);
222*e4a36f41SAndroid Build Coastguard Worker 	if (ret) {
223*e4a36f41SAndroid Build Coastguard Worker 		fprintf(stderr, "error(s) encountered while parsing configuration\n");
224*e4a36f41SAndroid Build Coastguard Worker 		close(fd);
225*e4a36f41SAndroid Build Coastguard Worker 		munmap(map, sb.st_size);
226*e4a36f41SAndroid Build Coastguard Worker 		return 1;
227*e4a36f41SAndroid Build Coastguard Worker 	}
228*e4a36f41SAndroid Build Coastguard Worker 
229*e4a36f41SAndroid Build Coastguard Worker 	return 0;
230*e4a36f41SAndroid Build Coastguard Worker }
231*e4a36f41SAndroid Build Coastguard Worker 
232*e4a36f41SAndroid Build Coastguard Worker 
main(int argc,char ** argv)233*e4a36f41SAndroid Build Coastguard Worker int main(int argc, char **argv)
234*e4a36f41SAndroid Build Coastguard Worker {
235*e4a36f41SAndroid Build Coastguard Worker 	char *policy = NULL, *source = NULL, *target = NULL, *class = NULL, *perm = NULL;
236*e4a36f41SAndroid Build Coastguard Worker 	policydb_t policydb;
237*e4a36f41SAndroid Build Coastguard Worker 	struct policy_file pf;
238*e4a36f41SAndroid Build Coastguard Worker 	sidtab_t sidtab;
239*e4a36f41SAndroid Build Coastguard Worker 	char ch;
240*e4a36f41SAndroid Build Coastguard Worker 	int match = 1;
241*e4a36f41SAndroid Build Coastguard Worker 
242*e4a36f41SAndroid Build Coastguard Worker 	struct option long_options[] = {
243*e4a36f41SAndroid Build Coastguard Worker 			{"source", required_argument, NULL, 's'},
244*e4a36f41SAndroid Build Coastguard Worker 			{"target", required_argument, NULL, 't'},
245*e4a36f41SAndroid Build Coastguard Worker 			{"class", required_argument, NULL, 'c'},
246*e4a36f41SAndroid Build Coastguard Worker 			{"perm", required_argument, NULL, 'p'},
247*e4a36f41SAndroid Build Coastguard Worker 			{"policy", required_argument, NULL, 'P'},
248*e4a36f41SAndroid Build Coastguard Worker 			{NULL, 0, NULL, 0}
249*e4a36f41SAndroid Build Coastguard Worker 	};
250*e4a36f41SAndroid Build Coastguard Worker 
251*e4a36f41SAndroid Build Coastguard Worker 	while ((ch = getopt_long(argc, argv, "s:t:c:p:P:", long_options, NULL)) != -1) {
252*e4a36f41SAndroid Build Coastguard Worker 		switch (ch) {
253*e4a36f41SAndroid Build Coastguard Worker 			case 's':
254*e4a36f41SAndroid Build Coastguard Worker 				source = optarg;
255*e4a36f41SAndroid Build Coastguard Worker 				break;
256*e4a36f41SAndroid Build Coastguard Worker 			case 't':
257*e4a36f41SAndroid Build Coastguard Worker 				target = optarg;
258*e4a36f41SAndroid Build Coastguard Worker 				break;
259*e4a36f41SAndroid Build Coastguard Worker 			case 'c':
260*e4a36f41SAndroid Build Coastguard Worker 				class = optarg;
261*e4a36f41SAndroid Build Coastguard Worker 				break;
262*e4a36f41SAndroid Build Coastguard Worker 			case 'p':
263*e4a36f41SAndroid Build Coastguard Worker 				perm = optarg;
264*e4a36f41SAndroid Build Coastguard Worker 				break;
265*e4a36f41SAndroid Build Coastguard Worker 			case 'P':
266*e4a36f41SAndroid Build Coastguard Worker 				policy = optarg;
267*e4a36f41SAndroid Build Coastguard Worker 				break;
268*e4a36f41SAndroid Build Coastguard Worker 			default:
269*e4a36f41SAndroid Build Coastguard Worker 				usage(argv[0]);
270*e4a36f41SAndroid Build Coastguard Worker 		}
271*e4a36f41SAndroid Build Coastguard Worker 	}
272*e4a36f41SAndroid Build Coastguard Worker 
273*e4a36f41SAndroid Build Coastguard Worker 	if (!source || !target || !class || !perm || !policy)
274*e4a36f41SAndroid Build Coastguard Worker 		usage(argv[0]);
275*e4a36f41SAndroid Build Coastguard Worker 
276*e4a36f41SAndroid Build Coastguard Worker 	sepol_set_policydb(&policydb);
277*e4a36f41SAndroid Build Coastguard Worker 	sepol_set_sidtab(&sidtab);
278*e4a36f41SAndroid Build Coastguard Worker 
279*e4a36f41SAndroid Build Coastguard Worker 	if (load_policy(policy, &policydb, &pf))
280*e4a36f41SAndroid Build Coastguard Worker 		goto out;
281*e4a36f41SAndroid Build Coastguard Worker 
282*e4a36f41SAndroid Build Coastguard Worker 	match = check_rule(source, target, class, perm, &policydb);
283*e4a36f41SAndroid Build Coastguard Worker 	if (match < 0) {
284*e4a36f41SAndroid Build Coastguard Worker 		fprintf(stderr, "Error checking rules!\n");
285*e4a36f41SAndroid Build Coastguard Worker 		goto out;
286*e4a36f41SAndroid Build Coastguard Worker 	} else if (match > 0) {
287*e4a36f41SAndroid Build Coastguard Worker 		printf("Match found!\n");
288*e4a36f41SAndroid Build Coastguard Worker 		goto out;
289*e4a36f41SAndroid Build Coastguard Worker 	}
290*e4a36f41SAndroid Build Coastguard Worker 
291*e4a36f41SAndroid Build Coastguard Worker 	match = 0;
292*e4a36f41SAndroid Build Coastguard Worker 
293*e4a36f41SAndroid Build Coastguard Worker out:
294*e4a36f41SAndroid Build Coastguard Worker 	policydb_destroy(&policydb);
295*e4a36f41SAndroid Build Coastguard Worker 	return match;
296*e4a36f41SAndroid Build Coastguard Worker }
297