• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2011 Tresys Technology, LLC. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  *    1. Redistributions of source code must retain the above copyright notice,
8  *       this list of conditions and the following disclaimer.
9  *
10  *    2. Redistributions in binary form must reproduce the above copyright notice,
11  *       this list of conditions and the following disclaimer in the documentation
12  *       and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY TRESYS TECHNOLOGY, LLC ``AS IS'' AND ANY EXPRESS
15  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
16  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
17  * EVENT SHALL TRESYS TECHNOLOGY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
18  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
19  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
21  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
22  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
23  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  *
25  * The views and conclusions contained in the software and documentation are those
26  * of the authors and should not be interpreted as representing official policies,
27  * either expressed or implied, of Tresys Technology, LLC.
28  */
29 
30 #include "CuTest.h"
31 #include "CilTest.h"
32 
33 #include "../../src/cil_internal.h"
34 #include "../../src/cil_copy_ast.h"
35 #include "../../src/cil_build_ast.h"
36 #include "../../src/cil_resolve_ast.h"
37 
38 #define CIL_TEST_SYM_SIZE	1
39 
40 int __cil_copy_node_helper(struct cil_tree_node *orig, uint32_t *finished, void *extra_args);
41 
42 struct cil_args_copy {
43 	struct cil_tree_node *dest;
44 	struct cil_db *db;
45 };
46 
gen_copy_args(struct cil_tree_node * node,struct cil_db * db)47 struct cil_args_copy *gen_copy_args(struct cil_tree_node *node, struct cil_db *db)
48 {
49 	struct cil_args_copy *args = cil_malloc(sizeof(*args));
50 	args->dest = node;
51 	args->db = db;
52 
53 	return args;
54 }
55 
test_cil_copy_list(CuTest * tc)56 void test_cil_copy_list(CuTest *tc) {
57 	char *line[] = {"(", "foo1", "foo2", ")", NULL};
58 
59 	struct cil_tree *test_tree;
60 	struct cil_list *cil_l;
61 
62 	gen_test_tree(&test_tree, line);
63 	cil_list_init(&cil_l);
64 
65 	cil_set_to_list(test_tree->root->cl_head, cil_l, 1);
66 
67 	struct cil_list *copy_list;
68 	cil_list_init(&copy_list);
69 
70 	int rc =cil_copy_list(cil_l, &copy_list);
71 	CuAssertIntEquals(tc, rc, SEPOL_OK);
72 	CuAssertStrEquals(tc, copy_list->head->data, cil_l->head->data);
73 	CuAssertStrEquals(tc, copy_list->head->next->data, cil_l->head->next->data);
74 	CuAssertIntEquals(tc, copy_list->head->flavor, cil_l->head->flavor);
75 	CuAssertIntEquals(tc, copy_list->head->next->flavor, cil_l->head->next->flavor);
76 }
77 
test_cil_copy_list_sublist(CuTest * tc)78 void test_cil_copy_list_sublist(CuTest *tc) {
79 	char *line[] = {"(", "foo1", "foo2", "(", "foo3", ")", ")", NULL};
80 
81 	struct cil_tree *test_tree;
82 	struct cil_list *cil_l;
83 
84 	gen_test_tree(&test_tree, line);
85 	cil_list_init(&cil_l);
86 
87 	cil_set_to_list(test_tree->root->cl_head, cil_l, 1);
88 
89 	struct cil_list *copy_list;
90 	cil_list_init(&copy_list);
91 
92 	int rc = cil_copy_list(cil_l, &copy_list);
93 	CuAssertIntEquals(tc, rc, SEPOL_OK);
94 	CuAssertStrEquals(tc, copy_list->head->data, cil_l->head->data);
95 	CuAssertStrEquals(tc, copy_list->head->next->data, cil_l->head->next->data);
96 	CuAssertStrEquals(tc, ((struct cil_list *)copy_list->head->next->next->data)->head->data, ((struct cil_list *)cil_l->head->next->next->data)->head->data);
97 	CuAssertIntEquals(tc, copy_list->head->flavor, cil_l->head->flavor);
98 	CuAssertIntEquals(tc, copy_list->head->next->flavor, cil_l->head->next->flavor);
99 	CuAssertIntEquals(tc, ((struct cil_list *)copy_list->head->next->next->data)->head->flavor, ((struct cil_list *)cil_l->head->next->next->data)->head->flavor);
100 }
101 
test_cil_copy_list_sublist_extra(CuTest * tc)102 void test_cil_copy_list_sublist_extra(CuTest *tc) {
103 	char *line[] = {"(", "foo1", "foo2", "(", "foo3", ")", "foo4", ")", NULL};
104 
105 	struct cil_tree *test_tree;
106 	struct cil_list *cil_l;
107 
108 	gen_test_tree(&test_tree, line);
109 	cil_list_init(&cil_l);
110 
111 	cil_set_to_list(test_tree->root->cl_head, cil_l, 1);
112 
113 	struct cil_list *copy_list;
114 	cil_list_init(&copy_list);
115 
116 	int rc = cil_copy_list(cil_l, &copy_list);
117 	CuAssertIntEquals(tc, rc, SEPOL_OK);
118 	CuAssertStrEquals(tc, copy_list->head->data, cil_l->head->data);
119 	CuAssertStrEquals(tc, copy_list->head->next->data, cil_l->head->next->data);
120 	CuAssertStrEquals(tc, ((struct cil_list *)copy_list->head->next->next->data)->head->data, ((struct cil_list *)cil_l->head->next->next->data)->head->data);
121 	CuAssertStrEquals(tc, copy_list->head->next->next->next->data, cil_l->head->next->next->next->data);
122 	CuAssertIntEquals(tc, copy_list->head->flavor, cil_l->head->flavor);
123 	CuAssertIntEquals(tc, copy_list->head->next->flavor, cil_l->head->next->flavor);
124 	CuAssertIntEquals(tc, ((struct cil_list *)copy_list->head->next->next->data)->head->flavor, ((struct cil_list *)cil_l->head->next->next->data)->head->flavor);
125 	CuAssertIntEquals(tc, copy_list->head->next->next->next->flavor, cil_l->head->next->next->next->flavor);
126 }
127 
test_cil_copy_list_orignull_neg(CuTest * tc)128 void test_cil_copy_list_orignull_neg(CuTest *tc) {
129 	char *line[] = {"(", "foo1", "foo2", ")", NULL};
130 
131 	struct cil_tree *test_tree;
132 	struct cil_list *cil_l = NULL;
133 
134 	gen_test_tree(&test_tree, line);
135 
136 	struct cil_list *copy_list;
137 	cil_list_init(&copy_list);
138 
139 	int rc = cil_copy_list(cil_l, &copy_list);
140 	CuAssertIntEquals(tc, rc, SEPOL_ERR);
141 	CuAssertPtrEquals(tc, copy_list->head, NULL);
142 }
143 
test_cil_copy_block(CuTest * tc)144 void test_cil_copy_block(CuTest *tc) {
145 	char *line[] = {"(", "block", "a", "(", "type", "log", ")", ")", NULL};
146 
147 	struct cil_tree *test_tree;
148 	gen_test_tree(&test_tree, line);
149 
150 	struct cil_tree_node *test_ast_node;
151 	cil_tree_node_init(&test_ast_node);
152 
153 	struct cil_db *test_db;
154 	cil_db_init(&test_db);
155 
156 	test_ast_node->parent = test_db->ast->root;
157 	test_ast_node->line = 1;
158 
159 	cil_gen_block(test_db, test_tree->root->cl_head->cl_head, test_ast_node, 0);
160 
161 	struct cil_tree_node *test_copy;
162 	cil_tree_node_init(&test_copy);
163 
164 	symtab_t sym;
165 	symtab_init(&sym, cil_sym_sizes[CIL_SYM_ARRAY_BLOCK][CIL_SYM_BLOCKS]);
166 
167 	int rc = cil_copy_block(test_db, test_ast_node->data, &test_copy->data, &sym);
168 	CuAssertIntEquals(tc, rc, SEPOL_OK);
169 }
170 
test_cil_copy_perm(CuTest * tc)171 void test_cil_copy_perm(CuTest *tc) {
172 	char *line[] = {"(", "class", "foo", "(", "read", "write", "open", ")", ")", NULL};
173 
174 	struct cil_tree *test_tree;
175 	gen_test_tree(&test_tree, line);
176 
177 	struct cil_tree_node *test_ast_node;
178 	cil_tree_node_init(&test_ast_node);
179 
180 	struct cil_db *test_db;
181 	cil_db_init(&test_db);
182 
183 	struct cil_class *new_node;
184 	cil_class_init(&new_node);
185 
186 	struct cil_tree_node *new_tree_node;
187 	cil_tree_node_init(&new_tree_node);
188 	new_tree_node->data = new_node;
189 	new_tree_node->flavor = CIL_CLASS;
190 
191 	test_ast_node->parent = new_tree_node;
192 	test_ast_node->line = 1;
193 
194 	struct cil_tree_node *test_copy;
195 	cil_tree_node_init(&test_copy);
196 
197 	symtab_t sym;
198 	symtab_init(&sym, CIL_CLASS_SYM_SIZE);
199 
200 	cil_gen_perm(test_db, test_tree->root->cl_head->cl_head->next->next->cl_head, test_ast_node);
201 	int rc = cil_copy_perm(test_db, test_ast_node->data, &test_copy->data, &sym);
202 	CuAssertIntEquals(tc, rc, SEPOL_OK);
203 	cil_gen_perm(test_db, test_tree->root->cl_head->cl_head->next->next->cl_head->next, test_ast_node);
204 	rc = cil_copy_perm(test_db, test_ast_node->data, &test_copy->data, &sym);
205 	CuAssertIntEquals(tc, rc, SEPOL_OK);
206 	cil_gen_perm(test_db, test_tree->root->cl_head->cl_head->next->next->cl_head->next->next, test_ast_node);
207 	rc = cil_copy_perm(test_db, test_ast_node->data, &test_copy->data, &sym);
208 	CuAssertIntEquals(tc, rc, SEPOL_OK);
209 
210 }
211 
test_cil_copy_class(CuTest * tc)212 void test_cil_copy_class(CuTest *tc) {
213 	char *line[] = {"(", "class", "file", "(", "read", "write", "open", ")", ")", NULL};
214 
215 	struct cil_tree *test_tree;
216 	gen_test_tree(&test_tree, line);
217 
218 	struct cil_tree_node *test_ast_node;
219 	cil_tree_node_init(&test_ast_node);
220 
221 	struct cil_db *test_db;
222 	cil_db_init(&test_db);
223 
224 	test_ast_node->parent = test_db->ast->root;
225 	test_ast_node->line = 1;
226 
227 	cil_gen_class(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
228 
229 	struct cil_tree_node *test_copy;
230 	cil_tree_node_init(&test_copy);
231 
232 	symtab_t sym;
233 	symtab_init(&sym, CIL_CLASS_SYM_SIZE);
234 
235 	int rc = cil_copy_class(test_db, test_ast_node->data, &test_copy->data, &sym);
236 	CuAssertIntEquals(tc, rc, SEPOL_OK);
237 }
238 
test_cil_copy_common(CuTest * tc)239 void test_cil_copy_common(CuTest *tc) {
240 	char *line[] = {"(", "common", "test", "(", "read", "write", ")", ")", NULL};
241 
242 	struct cil_tree *test_tree;
243 	gen_test_tree(&test_tree, line);
244 
245 	struct cil_tree_node *test_ast_node;
246 	cil_tree_node_init(&test_ast_node);
247 
248 	struct cil_db *test_db;
249 	cil_db_init(&test_db);
250 
251 	test_ast_node->parent = test_db->ast->root;
252 	test_ast_node->line = 1;
253 
254 	cil_gen_common(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
255 
256 	struct cil_tree_node *test_copy;
257 	cil_tree_node_init(&test_copy);
258 
259 	symtab_t sym;
260 	symtab_init(&sym, CIL_CLASS_SYM_SIZE);
261 
262 	int rc = cil_copy_common(test_db, test_ast_node->data, &test_copy->data, &sym);
263 	CuAssertIntEquals(tc, rc, SEPOL_OK);
264 }
265 
test_cil_copy_classcommon(CuTest * tc)266 void test_cil_copy_classcommon(CuTest *tc) {
267 	char *line[] = {"(", "classcommon", "file", "file", NULL};
268 
269         struct cil_tree *test_tree;
270         gen_test_tree(&test_tree, line);
271 
272         struct cil_tree_node *test_ast_node;
273         cil_tree_node_init(&test_ast_node);
274 
275         struct cil_db *test_db;
276         cil_db_init(&test_db);
277 
278         char *test_key = test_tree->root->cl_head->cl_head->next->data;
279         struct cil_class *test_cls;
280 	cil_class_init(&test_cls);
281 
282         test_ast_node->parent = test_db->ast->root;
283         test_ast_node->line = 1;
284 
285         cil_symtab_insert(&test_db->symtab[CIL_SYM_CLASSES], (hashtab_key_t)test_key, (struct cil_symtab_datum*)test_cls, test_ast_node);
286 
287         test_ast_node->data = test_cls;
288         test_ast_node->flavor = CIL_CLASS;
289 
290         cil_gen_classcommon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
291 
292 	struct cil_classcommon *test_copy;
293 	cil_classcommon_init(&test_copy);
294 
295 	symtab_t sym;
296 	symtab_init(&sym, CIL_CLASS_SYM_SIZE);
297 
298 	int rc = cil_copy_classcommon(test_db, test_ast_node->data, (void**)&test_copy, &sym);
299 	CuAssertIntEquals(tc, rc, SEPOL_OK);
300 	CuAssertStrEquals(tc, ((struct cil_classcommon *)test_ast_node->data)->class_str, test_copy->class_str);
301 	CuAssertStrEquals(tc, ((struct cil_classcommon *)test_ast_node->data)->common_str, test_copy->common_str);
302 }
303 
test_cil_copy_sid(CuTest * tc)304 void test_cil_copy_sid(CuTest *tc) {
305 	char *line[] = {"(", "sid", "test", ")", NULL};
306 
307 	struct cil_tree *test_tree;
308 	gen_test_tree(&test_tree, line);
309 
310 	struct cil_tree_node *test_ast_node;
311 	cil_tree_node_init(&test_ast_node);
312 
313 	struct cil_db *test_db;
314 	cil_db_init(&test_db);
315 
316 	test_ast_node->parent = test_db->ast->root;
317 	test_ast_node->line = 1;
318 
319 	cil_gen_sid(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
320 
321 	struct cil_tree_node *test_copy;
322 	cil_tree_node_init(&test_copy);
323 
324 	symtab_t sym;
325 	symtab_init(&sym, CIL_TEST_SYM_SIZE);
326 
327 	int rc = cil_copy_sid(test_db, test_ast_node->data, &test_copy->data, &sym);
328 	CuAssertIntEquals(tc, rc, SEPOL_OK);
329 }
330 
test_cil_copy_sidcontext(CuTest * tc)331 void test_cil_copy_sidcontext(CuTest *tc) {
332 	char *line[] = {"(", "sidcontext", "test", "(", "blah_u", "blah_r", "blah_t", "(", "low", "high", ")", ")", ")", NULL};
333 
334 	struct cil_tree *test_tree;
335 	gen_test_tree(&test_tree, line);
336 
337 	struct cil_tree_node *test_ast_node;
338 	cil_tree_node_init(&test_ast_node);
339 
340 	struct cil_db *test_db;
341 	cil_db_init(&test_db);
342 
343 	test_ast_node->parent = test_db->ast->root;
344 	test_ast_node->line = 1;
345 
346 	cil_gen_sidcontext(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
347 
348 	struct cil_tree_node *test_copy;
349 	cil_tree_node_init(&test_copy);
350 
351 	symtab_t sym;
352 	symtab_init(&sym, CIL_TEST_SYM_SIZE);
353 
354 	int rc = cil_copy_sidcontext(test_db, test_ast_node->data, &test_copy->data, &sym);
355 	CuAssertIntEquals(tc, rc, SEPOL_OK);
356 	CuAssertStrEquals(tc, ((struct cil_user *)test_copy->data)->datum.name,
357 		((struct cil_user *)test_ast_node->data)->datum.name);
358 }
359 
test_cil_copy_user(CuTest * tc)360 void test_cil_copy_user(CuTest *tc) {
361 	char *line[] = {"(", "user", "sysadm", ")", NULL};
362 
363 	struct cil_tree *test_tree;
364 	gen_test_tree(&test_tree, line);
365 
366 	struct cil_tree_node *test_ast_node;
367 	cil_tree_node_init(&test_ast_node);
368 
369 	struct cil_db *test_db;
370 	cil_db_init(&test_db);
371 
372 	test_ast_node->parent = test_db->ast->root;
373 	test_ast_node->line = 1;
374 
375 	cil_gen_user(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
376 
377 	struct cil_tree_node *test_copy;
378 	cil_tree_node_init(&test_copy);
379 
380 	symtab_t sym;
381 	symtab_init(&sym, CIL_TEST_SYM_SIZE);
382 
383 	int rc = cil_copy_user(test_db, test_ast_node->data, &test_copy->data, &sym);
384 	CuAssertIntEquals(tc, rc, SEPOL_OK);
385 }
386 
test_cil_copy_role(CuTest * tc)387 void test_cil_copy_role(CuTest *tc) {
388 	char *line[] = {"(", "role", "role_r", ")", NULL};
389 
390 	struct cil_tree *test_tree;
391 	gen_test_tree(&test_tree, line);
392 
393 	struct cil_tree_node *test_ast_node;
394 	cil_tree_node_init(&test_ast_node);
395 
396 	struct cil_db *test_db;
397 	cil_db_init(&test_db);
398 
399 	test_ast_node->parent = test_db->ast->root;
400 	test_ast_node->line = 1;
401 
402 	cil_gen_role(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
403 
404 	struct cil_tree_node *test_copy;
405 	cil_tree_node_init(&test_copy);
406 
407 	symtab_t sym;
408 	symtab_init(&sym, CIL_TEST_SYM_SIZE);
409 
410 	int rc = cil_copy_role(test_db, test_ast_node->data, &test_copy->data, &sym);
411 	CuAssertIntEquals(tc, rc, SEPOL_OK);
412 }
413 
test_cil_copy_userrole(CuTest * tc)414 void test_cil_copy_userrole(CuTest *tc) {
415 	char *line[] = {"(", "userrole", "staff_u", "staff_r", ")", NULL};
416 
417 	struct cil_tree *test_tree;
418 	gen_test_tree(&test_tree, line);
419 
420 	struct cil_tree_node *test_ast_node;
421 	cil_tree_node_init(&test_ast_node);
422 
423 	struct cil_db *test_db;
424 	cil_db_init(&test_db);
425 
426 	test_ast_node->parent = test_db->ast->root;
427 	test_ast_node->line = 1;
428 
429 	cil_gen_userrole(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
430 
431 	struct cil_userrole *test_copy;
432 	cil_userrole_init(&test_copy);
433 
434 	symtab_t sym;
435 	symtab_init(&sym, CIL_TEST_SYM_SIZE);
436 
437 	int rc = cil_copy_userrole(test_db, test_ast_node->data, (void**)&test_copy, &sym);
438 	CuAssertIntEquals(tc, rc, SEPOL_OK);
439 	CuAssertStrEquals(tc, ((struct cil_userrole *)test_ast_node->data)->user_str, test_copy->user_str);
440 	CuAssertStrEquals(tc, ((struct cil_userrole *)test_ast_node->data)->role_str, test_copy->role_str);
441 }
442 
test_cil_copy_type(CuTest * tc)443 void test_cil_copy_type(CuTest *tc) {
444 	char *line[] = {"(", "type", "test", ")", NULL};
445 
446 	struct cil_tree *test_tree;
447 	gen_test_tree(&test_tree, line);
448 
449 	struct cil_tree_node *test_ast_node;
450 	cil_tree_node_init(&test_ast_node);
451 
452 	struct cil_db *test_db;
453 	cil_db_init(&test_db);
454 
455 	test_ast_node->parent = test_db->ast->root;
456 	test_ast_node->line = 1;
457 
458 	cil_gen_type(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
459 
460 	struct cil_tree_node *test_copy;
461 	cil_tree_node_init(&test_copy);
462 
463 	symtab_t sym;
464 	symtab_init(&sym, CIL_TEST_SYM_SIZE);
465 
466 	int rc = cil_copy_type(test_db, test_ast_node->data, &test_copy->data, &sym);
467 	CuAssertIntEquals(tc, rc, SEPOL_OK);
468 }
469 
test_cil_copy_typealias(CuTest * tc)470 void test_cil_copy_typealias(CuTest *tc) {
471 	char *line[] = {"(", "typealias", ".test.type", "type_t", ")", "(", "type", "test", ")", NULL};
472 
473 	struct cil_tree *test_tree;
474 	gen_test_tree(&test_tree, line);
475 
476 	struct cil_tree_node *test_ast_node;
477 	cil_tree_node_init(&test_ast_node);
478 
479 	struct cil_db *test_db;
480 	cil_db_init(&test_db);
481 
482 	test_ast_node->parent = test_db->ast->root;
483 	test_ast_node->line = 1;
484 
485 	cil_gen_typealias(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
486 
487 	struct cil_tree_node *test_copy;
488 	cil_tree_node_init(&test_copy);
489 
490 	symtab_t sym;
491 	symtab_init(&sym, CIL_TEST_SYM_SIZE);
492 
493 	int rc = cil_copy_typealias(test_db, test_ast_node->data, &test_copy->data, &sym);
494 	CuAssertIntEquals(tc, rc, SEPOL_OK);
495 }
496 
test_cil_copy_typeattribute(CuTest * tc)497 void test_cil_copy_typeattribute(CuTest *tc) {
498 	char *line[] = {"(", "typettribute", "type_t", ")", NULL};
499 
500 	struct cil_tree *test_tree;
501 	gen_test_tree(&test_tree, line);
502 
503 	struct cil_tree_node *test_ast_node;
504 	cil_tree_node_init(&test_ast_node);
505 
506 	struct cil_db *test_db;
507 	cil_db_init(&test_db);
508 
509 	test_ast_node->parent = test_db->ast->root;
510 	test_ast_node->line = 1;
511 
512 	cil_gen_typeattribute(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
513 
514 	struct cil_tree_node *test_copy;
515 	cil_tree_node_init(&test_copy);
516 
517 	symtab_t sym;
518 	symtab_init(&sym, CIL_TEST_SYM_SIZE);
519 
520 	int rc = cil_copy_typeattribute(test_db, test_ast_node->data, &test_copy->data, &sym);
521 	CuAssertIntEquals(tc, rc, SEPOL_OK);
522 }
523 
test_cil_copy_bool(CuTest * tc)524 void test_cil_copy_bool(CuTest *tc) {
525 	char *line[] = {"(", "boolean", "foo", "true", ")", NULL};
526 
527 	struct cil_tree *test_tree;
528 	gen_test_tree(&test_tree, line);
529 
530 	struct cil_tree_node *test_ast_node;
531 	cil_tree_node_init(&test_ast_node);
532 
533 	struct cil_db *test_db;
534 	cil_db_init(&test_db);
535 
536 	test_ast_node->parent = test_db->ast->root;
537 	test_ast_node->line = 1;
538 
539 	cil_gen_bool(test_db, test_tree->root->cl_head->cl_head, test_ast_node, CIL_BOOL);
540 
541 	struct cil_tree_node *test_copy;
542 	cil_tree_node_init(&test_copy);
543 
544 	symtab_t sym;
545 	symtab_init(&sym, CIL_TEST_SYM_SIZE);
546 
547 	int rc = cil_copy_bool(test_db, test_ast_node->data, &test_copy->data, &sym);
548 	CuAssertIntEquals(tc, rc, SEPOL_OK);
549 	CuAssertIntEquals(tc, ((struct cil_bool *)test_copy->data)->value,
550 		((struct cil_bool *)test_ast_node->data)->value);
551 }
552 
test_cil_copy_type_rule(CuTest * tc)553 void test_cil_copy_type_rule(CuTest *tc) {
554 	char *line[] = {"(", "typetransition", "foo", "bar", "file", "foobar", ")", NULL};
555 
556 	struct cil_tree *test_tree;
557 	gen_test_tree(&test_tree, line);
558 
559 	struct cil_tree_node *test_ast_node;
560 	cil_tree_node_init(&test_ast_node);
561 
562 	struct cil_db *test_db;
563 	cil_db_init(&test_db);
564 
565 	test_ast_node->parent = test_db->ast->root;
566 	test_ast_node->line = 1;
567 
568 	cil_gen_type_rule(test_tree->root->cl_head->cl_head, test_ast_node, CIL_TYPE_TRANSITION);
569 
570 	struct cil_type_rule *test_copy;
571 	cil_type_rule_init(&test_copy);
572 
573 	symtab_t sym;
574 	symtab_init(&sym, CIL_TEST_SYM_SIZE);
575 
576 	int rc = cil_copy_type_rule(test_db, test_ast_node->data, (void**)&test_copy, &sym);
577 	CuAssertIntEquals(tc, rc, SEPOL_OK);
578 	CuAssertIntEquals(tc, ((struct cil_type_rule *)test_ast_node->data)->rule_kind, test_copy->rule_kind);
579 	CuAssertStrEquals(tc, ((struct cil_type_rule *)test_ast_node->data)->src_str, test_copy->src_str);
580 	CuAssertStrEquals(tc, ((struct cil_type_rule *)test_ast_node->data)->tgt_str, test_copy->tgt_str);
581 	CuAssertStrEquals(tc, ((struct cil_type_rule *)test_ast_node->data)->obj_str, test_copy->obj_str);
582 }
583 
test_cil_copy_avrule(CuTest * tc)584 void test_cil_copy_avrule(CuTest *tc) {
585 	char *line[] = {"(", "allow", "test", "foo", "(", "bar", "(", "read", "write", ")", ")", ")", NULL};
586 
587 	struct cil_tree *test_tree;
588 	gen_test_tree(&test_tree, line);
589 
590 	struct cil_tree_node *test_ast_node;
591 	cil_tree_node_init(&test_ast_node);
592 
593 	struct cil_db *test_db;
594 	cil_db_init(&test_db);
595 
596 	test_ast_node->parent = test_db->ast->root;
597 	test_ast_node->line = 1;
598 
599 	struct cil_tree_node *test_current;
600 	test_current = test_tree->root->cl_head->cl_head;
601 
602 	cil_gen_avrule(test_current, test_ast_node, CIL_AVRULE_ALLOWED);
603 
604 	struct cil_avrule *test_copy;
605 	cil_avrule_init(&test_copy);
606 
607 	symtab_t sym;
608 	symtab_init(&sym, CIL_TEST_SYM_SIZE);
609 
610 	int rc = cil_copy_avrule(test_db, test_ast_node->data, (void**)&test_copy, &sym);
611 	CuAssertIntEquals(tc, rc, SEPOL_OK);
612 	CuAssertIntEquals(tc, ((struct cil_avrule *)test_ast_node->data)->rule_kind, test_copy->rule_kind);
613 	CuAssertStrEquals(tc, ((struct cil_avrule *)test_ast_node->data)->src_str, test_copy->src_str);
614 	CuAssertStrEquals(tc, ((struct cil_avrule *)test_ast_node->data)->tgt_str, test_copy->tgt_str);
615 	CuAssertStrEquals(tc, ((struct cil_avrule *)test_ast_node->data)->classpermset->class_str, test_copy->classpermset->class_str);
616 	CuAssertIntEquals(tc, ((struct cil_avrule *)test_ast_node->data)->classpermset->permset->perms_list_str->head->flavor, test_copy->classpermset->permset->perms_list_str->head->flavor);
617 	CuAssertStrEquals(tc, (char*)((struct cil_avrule *)test_ast_node->data)->classpermset->permset->perms_list_str->head->data, (char*)test_copy->classpermset->permset->perms_list_str->head->data);
618 	CuAssertIntEquals(tc, ((struct cil_avrule *)test_ast_node->data)->classpermset->permset->perms_list_str->head->next->flavor, test_copy->classpermset->permset->perms_list_str->head->next->flavor);
619 	CuAssertStrEquals(tc, (char*)((struct cil_avrule *)test_ast_node->data)->classpermset->permset->perms_list_str->head->next->data, (char*)test_copy->classpermset->permset->perms_list_str->head->next->data);
620 }
621 
test_cil_copy_sens(CuTest * tc)622 void test_cil_copy_sens(CuTest *tc) {
623 	char *line[] = {"(", "sensitivity", "s0", ")", NULL};
624 
625 	struct cil_tree *test_tree;
626 	gen_test_tree(&test_tree, line);
627 
628 	struct cil_db *test_db;
629 	cil_db_init(&test_db);
630 
631 	struct cil_tree_node *test_ast_node;
632 	cil_tree_node_init(&test_ast_node);
633 
634 	test_ast_node->parent = test_db->ast->root;
635 	test_ast_node->line = 1;
636 
637 	cil_gen_sensitivity(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
638 
639 	struct cil_tree_node *test_copy;
640 	cil_tree_node_init(&test_copy);
641 
642 	symtab_t sym;
643 	symtab_init(&sym, CIL_TEST_SYM_SIZE);
644 
645 	int rc = cil_copy_sens(test_db, test_ast_node->data, &test_copy->data, &sym);
646 	CuAssertIntEquals(tc, rc, SEPOL_OK);
647 }
648 
test_cil_copy_sensalias(CuTest * tc)649 void test_cil_copy_sensalias(CuTest *tc) {
650 	char *line[] = {"(", "sensitivityalias", "s0", "alias", ")", NULL};
651 
652 	struct cil_tree *test_tree;
653 	gen_test_tree(&test_tree, line);
654 
655 	struct cil_db *test_db;
656 	cil_db_init(&test_db);
657 
658 	struct cil_tree_node *test_ast_node;
659 	cil_tree_node_init(&test_ast_node);
660 
661 	test_ast_node->parent = test_db->ast->root;
662 	test_ast_node->line = 1;
663 
664 	cil_gen_sensalias(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
665 
666 	struct cil_tree_node *test_copy;
667 	cil_tree_node_init(&test_copy);
668 
669 	symtab_t sym;
670 	symtab_init(&sym, CIL_TEST_SYM_SIZE);
671 
672 	int rc = cil_copy_sensalias(test_db, test_ast_node->data, &test_copy->data, &sym);
673 	CuAssertIntEquals(tc, rc, SEPOL_OK);
674 	CuAssertStrEquals(tc, ((struct cil_sensalias *)test_copy->data)->sens_str,
675 		((struct cil_sensalias *)test_ast_node->data)->sens_str);
676 }
677 
test_cil_copy_cat(CuTest * tc)678 void test_cil_copy_cat(CuTest *tc) {
679 	char *line[] = {"(", "category", "c0", ")", NULL};
680 
681 	struct cil_tree *test_tree;
682 	gen_test_tree(&test_tree, line);
683 
684 	struct cil_db *test_db;
685 	cil_db_init(&test_db);
686 
687 	struct cil_tree_node *test_ast_node;
688 	cil_tree_node_init(&test_ast_node);
689 
690 	test_ast_node->parent = test_db->ast->root;
691 	test_ast_node->line = 1;
692 
693 	cil_gen_category(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
694 
695 	struct cil_tree_node *test_copy;
696 	cil_tree_node_init(&test_copy);
697 
698 	symtab_t sym;
699 	symtab_init(&sym, CIL_TEST_SYM_SIZE);
700 
701 	int rc = cil_copy_cat(test_db, test_ast_node->data, &test_copy->data, &sym);
702 	CuAssertIntEquals(tc, rc, SEPOL_OK);
703 }
704 
test_cil_copy_catalias(CuTest * tc)705 void test_cil_copy_catalias(CuTest *tc) {
706 	char *line[] = {"(", "categoryalias", "c0", "red", ")", NULL};
707 
708 	struct cil_tree *test_tree;
709 	gen_test_tree(&test_tree, line);
710 
711 	struct cil_db *test_db;
712 	cil_db_init(&test_db);
713 
714 	struct cil_tree_node *test_ast_node;
715 	cil_tree_node_init(&test_ast_node);
716 
717 	test_ast_node->parent = test_db->ast->root;
718 	test_ast_node->line = 1;
719 
720 	cil_gen_catalias(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
721 
722 	struct cil_tree_node *test_copy;
723 	cil_tree_node_init(&test_copy);
724 
725 	symtab_t sym;
726 	symtab_init(&sym, CIL_TEST_SYM_SIZE);
727 
728 	int rc = cil_copy_catalias(test_db, test_ast_node->data, &test_copy->data, &sym);
729 	CuAssertIntEquals(tc, rc, SEPOL_OK);
730 	CuAssertStrEquals(tc, ((struct cil_catalias *)test_copy->data)->cat_str,
731 		((struct cil_catalias *)test_ast_node->data)->cat_str);
732 }
733 
test_cil_copy_senscat(CuTest * tc)734 void test_cil_copy_senscat(CuTest *tc) {
735 	char *line[] = {"(", "sensitivity", "s0", ")",
736                         "(", "sensitivity", "s1", ")",
737                         "(", "dominance", "(", "s0", "s1", ")", ")",
738 			"(", "category", "c0", ")",
739 			"(", "category", "c255", ")",
740 			"(", "categoryorder", "(", "c0", "c255", ")", ")",
741 			"(", "sensitivitycategory", "s1", "(", "c0", "c255", ")", ")", NULL};
742 
743         struct cil_tree *test_tree;
744         gen_test_tree(&test_tree, line);
745 
746         struct cil_tree_node *test_ast_node;
747         cil_tree_node_init(&test_ast_node);
748 
749         struct cil_db *test_db;
750         cil_db_init(&test_db);
751 
752         test_ast_node->parent = test_db->ast->root;
753         test_ast_node->line = 1;
754 
755         cil_gen_senscat(test_db, test_tree->root->cl_head->next->next->next->next->next->next->cl_head, test_ast_node);
756 
757 	struct cil_senscat *test_copy;
758 	cil_senscat_init(&test_copy);
759 
760 	symtab_t sym;
761 	symtab_init(&sym, CIL_TEST_SYM_SIZE);
762 
763 	int rc = cil_copy_senscat(test_db, test_ast_node->data, (void**)&test_copy, &sym);
764 	CuAssertIntEquals(tc, rc, SEPOL_OK);
765 	CuAssertStrEquals(tc, ((struct cil_senscat *)test_ast_node->data)->sens_str, test_copy->sens_str);
766 	CuAssertStrEquals(tc, (char*)((struct cil_senscat *)test_ast_node->data)->catset->cat_list_str->head->data,
767 	                      (char*)test_copy->catset->cat_list_str->head->data);
768 	CuAssertStrEquals(tc, (char*)((struct cil_senscat *)test_ast_node->data)->catset->cat_list_str->head->next->data,
769 	                      (char*)test_copy->catset->cat_list_str->head->next->data);
770 }
771 
test_cil_copy_catorder(CuTest * tc)772 void test_cil_copy_catorder(CuTest *tc) {
773 	char *line[] = {"(", "category", "c0", ")",
774 			"(", "category", "c255", ")",
775 			"(", "categoryorder", "(", "c0", "c255", ")", ")", NULL};
776 
777 	struct cil_tree *test_tree;
778 	gen_test_tree(&test_tree, line);
779 
780 	struct cil_db *test_db;
781 	cil_db_init(&test_db);
782 
783 	struct cil_tree_node *test_ast_node;
784 	cil_tree_node_init(&test_ast_node);
785 
786 	test_ast_node->parent = test_db->ast->root;
787 	test_ast_node->line = 1;
788 
789 	cil_gen_catorder(test_db, test_tree->root->cl_head->next->next->cl_head, test_ast_node);
790 
791 	struct cil_catorder *test_copy;
792 	cil_catorder_init(&test_copy);
793 
794 	symtab_t sym;
795 	symtab_init(&sym, CIL_TEST_SYM_SIZE);
796 
797 	int rc = cil_copy_catorder(test_db, test_ast_node->data, (void**)&test_copy, &sym);
798 	CuAssertIntEquals(tc, rc, SEPOL_OK);
799 	CuAssertStrEquals(tc, (char*)((struct cil_catorder *)test_ast_node->data)->cat_list_str->head->data, (char*)test_copy->cat_list_str->head->data);
800 	CuAssertStrEquals(tc, (char*)((struct cil_catorder *)test_ast_node->data)->cat_list_str->head->next->data, (char*)test_copy->cat_list_str->head->next->data);
801 }
802 
test_cil_copy_dominance(CuTest * tc)803 void test_cil_copy_dominance(CuTest *tc) {
804         char *line[] = {"(", "sensitivity", "s0", ")",
805                         "(", "sensitivity", "s1", ")",
806                         "(", "sensitivity", "s2", ")",
807                         "(", "dominance", "(", "s0", "s1", ")", ")", NULL};
808 
809         struct cil_tree *test_tree;
810         gen_test_tree(&test_tree, line);
811 
812         struct cil_tree_node *test_ast_node;
813         cil_tree_node_init(&test_ast_node);
814 
815         struct cil_db *test_db;
816         cil_db_init(&test_db);
817 
818         test_ast_node->parent = test_db->ast->root;
819         test_ast_node->line = 1;
820 
821         cil_gen_dominance(test_db, test_tree->root->cl_head->next->next->next->cl_head, test_ast_node);
822 
823 	struct cil_sens_dominates *test_copy;
824 	cil_sens_dominates_init(&test_copy);
825 
826 	symtab_t sym;
827 	symtab_init(&sym, CIL_TEST_SYM_SIZE);
828 
829 	int rc = cil_copy_dominance(test_db, test_ast_node->data, (void**)&test_copy, &sym);
830 	CuAssertIntEquals(tc, rc, SEPOL_OK);
831 	CuAssertStrEquals(tc, (char*)((struct cil_sens_dominates *)test_ast_node->data)->sens_list_str->head->data, (char*)test_copy->sens_list_str->head->data);
832 	CuAssertStrEquals(tc, (char*)((struct cil_sens_dominates *)test_ast_node->data)->sens_list_str->head->next->data, (char*)test_copy->sens_list_str->head->next->data);
833 }
834 
test_cil_copy_level(CuTest * tc)835 void test_cil_copy_level(CuTest *tc) {
836 	char *line[] = {"(", "level", "low", "(", "s0", "(", "c1", ")", ")", ")", NULL};
837 
838         struct cil_tree *test_tree;
839         gen_test_tree(&test_tree, line);
840 
841         struct cil_tree_node *test_ast_node;
842         cil_tree_node_init(&test_ast_node);
843 
844         struct cil_db *test_db;
845         cil_db_init(&test_db);
846 
847         test_ast_node->parent = test_db->ast->root;
848         test_ast_node->line = 1;
849 
850         cil_gen_level(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
851 
852 	struct cil_tree_node *test_copy;
853 	cil_tree_node_init(&test_copy);
854 
855 	symtab_t sym;
856 	symtab_init(&sym, CIL_TEST_SYM_SIZE);
857 
858 	int rc = cil_copy_level(test_db, test_ast_node->data, &test_copy->data, &sym);
859 	CuAssertIntEquals(tc, rc, SEPOL_OK);
860 }
861 
test_cil_copy_fill_level(CuTest * tc)862 void test_cil_copy_fill_level(CuTest *tc) {
863 	char *line[] = {"(", "level", "low", "(", "s0", "(", "c1", ")", ")", ")", NULL};
864 
865         struct cil_tree *test_tree;
866         gen_test_tree(&test_tree, line);
867 
868         struct cil_tree_node *test_ast_node;
869         cil_tree_node_init(&test_ast_node);
870 
871         struct cil_db *test_db;
872         cil_db_init(&test_db);
873 
874         test_ast_node->parent = test_db->ast->root;
875         test_ast_node->line = 1;
876 
877         cil_gen_level(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
878 
879 	struct cil_tree_node *test_copy;
880 	cil_tree_node_init(&test_copy);
881 	cil_level_init((struct cil_level**)&test_copy->data);
882 
883 	symtab_t sym;
884 	symtab_init(&sym, CIL_TEST_SYM_SIZE);
885 
886 	int rc = cil_copy_fill_level((struct cil_level*)test_ast_node->data, (struct cil_level*)test_copy->data);
887 	CuAssertIntEquals(tc, rc, SEPOL_OK);
888 	CuAssertStrEquals(tc, ((struct cil_level *)test_copy->data)->sens_str,
889 		((struct cil_level *)test_ast_node->data)->sens_str);
890 }
891 
test_cil_copy_context(CuTest * tc)892 void test_cil_copy_context(CuTest *tc) {
893 	char *line[] = {"(", "context", "packet_default", "(", "system_u", "object_r", "etc_t", "(", "low", "high", ")", ")", ")", NULL};
894 
895         struct cil_tree *test_tree;
896         gen_test_tree(&test_tree, line);
897 
898         struct cil_tree_node *test_ast_node;
899         cil_tree_node_init(&test_ast_node);
900 
901         struct cil_db *test_db;
902         cil_db_init(&test_db);
903 
904         test_ast_node->parent = test_db->ast->root;
905         test_ast_node->line = 1;
906 
907 	cil_gen_context(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
908 
909 	struct cil_tree_node *test_copy;
910 	cil_tree_node_init(&test_copy);
911 
912 	symtab_t sym;
913 	symtab_init(&sym, CIL_TEST_SYM_SIZE);
914 
915 	int rc = cil_copy_context(test_db, test_ast_node->data, &test_copy->data, &sym);
916 	CuAssertIntEquals(tc, rc, SEPOL_OK);
917 }
918 
test_cil_copy_netifcon(CuTest * tc)919 void test_cil_copy_netifcon(CuTest *tc) {
920 	char *line[] = {"(", "netifcon", "eth0", "if_default", "packet_default", ")", NULL};
921 
922         struct cil_tree *test_tree;
923         gen_test_tree(&test_tree, line);
924 
925         struct cil_tree_node *test_ast_node;
926         cil_tree_node_init(&test_ast_node);
927 
928         struct cil_db *test_db;
929         cil_db_init(&test_db);
930 
931         test_ast_node->parent = test_db->ast->root;
932         test_ast_node->line = 1;
933 
934         cil_gen_netifcon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
935 
936 	struct cil_netifcon *test_copy;
937 
938 	symtab_t sym;
939 	symtab_init(&sym, CIL_TEST_SYM_SIZE);
940 
941 	int rc = cil_copy_netifcon(test_db, test_ast_node->data, (void**)&test_copy, &sym);
942 	CuAssertIntEquals(tc, rc, SEPOL_OK);
943 	CuAssertStrEquals(tc, test_copy->interface_str,
944 		((struct cil_netifcon *)test_ast_node->data)->interface_str);
945 	CuAssertStrEquals(tc, test_copy->if_context_str,
946 		((struct cil_netifcon *)test_ast_node->data)->if_context_str);
947 	CuAssertStrEquals(tc, test_copy->packet_context_str,
948 		((struct cil_netifcon *)test_ast_node->data)->packet_context_str);
949 }
950 
test_cil_copy_netifcon_nested(CuTest * tc)951 void test_cil_copy_netifcon_nested(CuTest *tc) {
952 	char *line[] = {"(", "netifcon", "eth1",
953 			"(", "system_u", "object_r", "netif_t", "(", "low", "high", ")", ")",
954 			"(", "system_u", "object_r", "netif_t", "(", "low", "high", ")", ")", ")", NULL};
955 
956         struct cil_tree *test_tree;
957         gen_test_tree(&test_tree, line);
958 
959         struct cil_tree_node *test_ast_node;
960         cil_tree_node_init(&test_ast_node);
961 
962         struct cil_db *test_db;
963         cil_db_init(&test_db);
964 
965         test_ast_node->parent = test_db->ast->root;
966         test_ast_node->line = 1;
967 
968         cil_gen_netifcon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
969 
970 	struct cil_netifcon *test_copy;
971 
972 	symtab_t sym;
973 	symtab_init(&sym, CIL_TEST_SYM_SIZE);
974 
975 	int rc = cil_copy_netifcon(test_db, test_ast_node->data, (void**)&test_copy, &sym);
976 	CuAssertIntEquals(tc, rc, SEPOL_OK);
977 	CuAssertStrEquals(tc, test_copy->interface_str,
978 		((struct cil_netifcon *)test_ast_node->data)->interface_str);
979 	CuAssertStrEquals(tc, test_copy->if_context_str,
980 		((struct cil_netifcon *)test_ast_node->data)->if_context_str);
981 	CuAssertStrEquals(tc, test_copy->packet_context_str,
982 		((struct cil_netifcon *)test_ast_node->data)->packet_context_str);
983 	CuAssertStrEquals(tc, test_copy->packet_context->user_str,
984 		((struct cil_netifcon *)test_ast_node->data)->packet_context->user_str);
985 	CuAssertStrEquals(tc, test_copy->packet_context->role_str,
986 		((struct cil_netifcon *)test_ast_node->data)->packet_context->role_str);
987 	CuAssertStrEquals(tc, test_copy->packet_context->type_str,
988 		((struct cil_netifcon *)test_ast_node->data)->packet_context->type_str);
989 	CuAssertStrEquals(tc, test_copy->packet_context->range_str,
990 		((struct cil_netifcon *)test_ast_node->data)->packet_context->range_str);
991 }
992 
test_cil_copy_fill_context(CuTest * tc)993 void test_cil_copy_fill_context(CuTest *tc) {
994 	char *line[] = {"(", "context", "packet_default", "(", "system_u", "object_r", "etc_t", "range", ")", ")", NULL};
995 
996         struct cil_tree *test_tree;
997         gen_test_tree(&test_tree, line);
998 
999         struct cil_tree_node *test_ast_node;
1000         cil_tree_node_init(&test_ast_node);
1001 
1002         struct cil_db *test_db;
1003         cil_db_init(&test_db);
1004 
1005         test_ast_node->parent = test_db->ast->root;
1006         test_ast_node->line = 1;
1007 
1008 	cil_gen_context(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
1009 
1010 	struct cil_tree_node *test_copy;
1011 	cil_tree_node_init(&test_copy);
1012 	cil_context_init((struct cil_context**)&test_copy->data);
1013 
1014 	symtab_t sym;
1015 	symtab_init(&sym, CIL_TEST_SYM_SIZE);
1016 
1017 	int rc = cil_copy_fill_context((struct cil_context*)test_ast_node->data, (struct cil_context*)test_copy->data);
1018 	CuAssertIntEquals(tc, rc, SEPOL_OK);
1019 	CuAssertStrEquals(tc, ((struct cil_context *)test_copy->data)->user_str,
1020 		((struct cil_context *)test_ast_node->data)->user_str);
1021 	CuAssertStrEquals(tc, ((struct cil_context *)test_copy->data)->role_str,
1022 		((struct cil_context *)test_ast_node->data)->role_str);
1023 	CuAssertStrEquals(tc, ((struct cil_context *)test_copy->data)->type_str,
1024 		((struct cil_context *)test_ast_node->data)->type_str);
1025 	CuAssertStrEquals(tc, ((struct cil_context *)test_copy->data)->range_str,
1026 		((struct cil_context *)test_ast_node->data)->range_str);
1027 }
1028 
test_cil_copy_fill_context_anonrange(CuTest * tc)1029 void test_cil_copy_fill_context_anonrange(CuTest *tc) {
1030 	char *line[] = {"(", "context", "packet_default", "(", "system_u", "object_r", "etc_t", "(", "low", "high", ")", ")", ")", NULL};
1031 
1032         struct cil_tree *test_tree;
1033         gen_test_tree(&test_tree, line);
1034 
1035         struct cil_tree_node *test_ast_node;
1036         cil_tree_node_init(&test_ast_node);
1037 
1038         struct cil_db *test_db;
1039         cil_db_init(&test_db);
1040 
1041         test_ast_node->parent = test_db->ast->root;
1042         test_ast_node->line = 1;
1043 
1044 	cil_gen_context(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
1045 
1046 	struct cil_tree_node *test_copy;
1047 	cil_tree_node_init(&test_copy);
1048 	cil_context_init((struct cil_context**)&test_copy->data);
1049 
1050 	symtab_t sym;
1051 	symtab_init(&sym, CIL_TEST_SYM_SIZE);
1052 
1053 	int rc = cil_copy_fill_context((struct cil_context*)test_ast_node->data, (struct cil_context*)test_copy->data);
1054 	CuAssertIntEquals(tc, rc, SEPOL_OK);
1055 	CuAssertStrEquals(tc, ((struct cil_context *)test_copy->data)->user_str,
1056 		((struct cil_context *)test_ast_node->data)->user_str);
1057 	CuAssertStrEquals(tc, ((struct cil_context *)test_copy->data)->role_str,
1058 		((struct cil_context *)test_ast_node->data)->role_str);
1059 	CuAssertStrEquals(tc, ((struct cil_context *)test_copy->data)->type_str,
1060 		((struct cil_context *)test_ast_node->data)->type_str);
1061 	CuAssertStrEquals(tc, ((struct cil_context *)test_copy->data)->range_str,
1062 		((struct cil_context *)test_ast_node->data)->range_str);
1063 }
1064 
test_cil_copy_call(CuTest * tc)1065 void test_cil_copy_call(CuTest *tc) {
1066 	char *line[] = {"(", "call", "mm", "(", "foo", ")", ")", NULL};
1067 
1068         struct cil_tree *test_tree;
1069         gen_test_tree(&test_tree, line);
1070 
1071         struct cil_tree_node *test_ast_node;
1072         cil_tree_node_init(&test_ast_node);
1073 
1074         struct cil_db *test_db;
1075         cil_db_init(&test_db);
1076 
1077         test_ast_node->parent = test_db->ast->root;
1078         test_ast_node->line = 1;
1079 
1080         cil_gen_call(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
1081 
1082 	struct cil_call *test_copy;
1083 
1084 	symtab_t sym;
1085 	symtab_init(&sym, CIL_TEST_SYM_SIZE);
1086 
1087 	int rc = cil_copy_call(test_db, test_ast_node->data, (void**)&test_copy, &sym);
1088 	CuAssertIntEquals(tc, rc, SEPOL_OK);
1089 	CuAssertStrEquals(tc, test_copy->macro_str, ((struct cil_call *)test_ast_node->data)->macro_str);
1090 }
1091 
test_cil_copy_optional(CuTest * tc)1092 void test_cil_copy_optional(CuTest *tc) {
1093 	char *line[] = {"(", "optional", "opt", "(", "allow", "foo", "bar", "(", "file", "(", "read", ")", ")", ")", ")", NULL};
1094 
1095         struct cil_tree *test_tree;
1096         gen_test_tree(&test_tree, line);
1097 
1098         struct cil_tree_node *test_ast_node;
1099         cil_tree_node_init(&test_ast_node);
1100 
1101         struct cil_db *test_db;
1102         cil_db_init(&test_db);
1103 
1104         test_ast_node->parent = test_db->ast->root;
1105         test_ast_node->line = 1;
1106 
1107         cil_gen_optional(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
1108 
1109 	struct cil_tree_node *test_copy;
1110 	cil_tree_node_init(&test_copy);
1111 
1112 	symtab_t sym;
1113 	symtab_init(&sym, CIL_TEST_SYM_SIZE);
1114 
1115 	int rc = cil_copy_optional(test_db, test_ast_node->data, &test_copy->data, &sym);
1116 	CuAssertIntEquals(tc, rc, SEPOL_OK);
1117 }
1118 
test_cil_copy_nodecon(CuTest * tc)1119 void test_cil_copy_nodecon(CuTest *tc) {
1120 	char *line[] = {"(", "nodecon", "ipaddr", "ipaddr", "con", ")", NULL};
1121 
1122         struct cil_tree *test_tree;
1123         gen_test_tree(&test_tree, line);
1124 
1125         struct cil_tree_node *test_ast_node;
1126         cil_tree_node_init(&test_ast_node);
1127 
1128         struct cil_db *test_db;
1129         cil_db_init(&test_db);
1130 
1131         test_ast_node->parent = test_db->ast->root;
1132         test_ast_node->line = 1;
1133 
1134         cil_gen_nodecon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
1135 
1136 	struct cil_nodecon *test_copy;
1137 
1138 	symtab_t sym;
1139 	symtab_init(&sym, CIL_TEST_SYM_SIZE);
1140 
1141 	int rc = cil_copy_nodecon(test_db, test_ast_node->data, (void**)&test_copy, &sym);
1142 	CuAssertIntEquals(tc, rc, SEPOL_OK);
1143 	CuAssertStrEquals(tc, test_copy->addr_str,
1144 		((struct cil_nodecon *)test_ast_node->data)->addr_str);
1145 	CuAssertStrEquals(tc, test_copy->mask_str,
1146 		((struct cil_nodecon *)test_ast_node->data)->mask_str);
1147 	CuAssertStrEquals(tc, test_copy->context_str,
1148 		((struct cil_nodecon *)test_ast_node->data)->context_str);
1149 }
1150 
test_cil_copy_nodecon_anon(CuTest * tc)1151 void test_cil_copy_nodecon_anon(CuTest *tc) {
1152 	char *line[] = {"(", "nodecon", "(", "192.168.1.1", ")", "(", "192.168.1.1", ")", "(", "user", "role", "type", "(", "low", "high", ")", ")", ")", NULL};
1153 
1154         struct cil_tree *test_tree;
1155         gen_test_tree(&test_tree, line);
1156 
1157         struct cil_tree_node *test_ast_node;
1158         cil_tree_node_init(&test_ast_node);
1159 
1160         struct cil_db *test_db;
1161         cil_db_init(&test_db);
1162 
1163         test_ast_node->parent = test_db->ast->root;
1164         test_ast_node->line = 1;
1165 
1166         cil_gen_nodecon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
1167 
1168 	struct cil_nodecon *test_copy;
1169 
1170 	symtab_t sym;
1171 	symtab_init(&sym, CIL_TEST_SYM_SIZE);
1172 
1173 	int rc = cil_copy_nodecon(test_db, test_ast_node->data, (void**)&test_copy, &sym);
1174 	CuAssertIntEquals(tc, rc, SEPOL_OK);
1175 	CuAssertStrEquals(tc, test_copy->addr_str,
1176 		((struct cil_nodecon *)test_ast_node->data)->addr_str);
1177 	CuAssertStrEquals(tc, test_copy->mask_str,
1178 		((struct cil_nodecon *)test_ast_node->data)->mask_str);
1179 	CuAssertStrEquals(tc, test_copy->context_str,
1180 		((struct cil_nodecon *)test_ast_node->data)->context_str);
1181 }
1182 
test_cil_copy_fill_ipaddr(CuTest * tc)1183 void test_cil_copy_fill_ipaddr(CuTest *tc) {
1184 	char *line[] = {"(", "ipaddr", "ip", "192.168.1.1", ")", NULL};
1185 
1186         struct cil_tree *test_tree;
1187         gen_test_tree(&test_tree, line);
1188 
1189         struct cil_tree_node *test_ast_node;
1190         cil_tree_node_init(&test_ast_node);
1191 
1192         struct cil_db *test_db;
1193         cil_db_init(&test_db);
1194 
1195         test_ast_node->parent = test_db->ast->root;
1196         test_ast_node->line = 1;
1197 
1198         cil_gen_ipaddr(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
1199 
1200 	symtab_t sym;
1201 	symtab_init(&sym, CIL_TEST_SYM_SIZE);
1202 
1203 	struct cil_ipaddr *new;
1204 	cil_ipaddr_init(&new);
1205 	struct cil_ipaddr *old;
1206 	cil_ipaddr_init(&new);
1207 
1208 	old = (struct cil_ipaddr*)test_ast_node->data;
1209 	int rc = cil_copy_fill_ipaddr(old, new);
1210 	CuAssertIntEquals(tc, rc, SEPOL_OK);
1211 
1212 	CuAssertIntEquals(tc, old->family, new->family);
1213 }
1214 
test_cil_copy_ipaddr(CuTest * tc)1215 void test_cil_copy_ipaddr(CuTest *tc) {
1216 	char *line[] = {"(", "ipaddr", "ip", "192.168.1.1", ")", NULL};
1217 
1218         struct cil_tree *test_tree;
1219         gen_test_tree(&test_tree, line);
1220 
1221         struct cil_tree_node *test_ast_node;
1222         cil_tree_node_init(&test_ast_node);
1223 
1224         struct cil_db *test_db;
1225         cil_db_init(&test_db);
1226 
1227         test_ast_node->parent = test_db->ast->root;
1228         test_ast_node->line = 1;
1229 
1230         cil_gen_ipaddr(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
1231 
1232 	struct cil_tree_node *test_copy;
1233 	cil_tree_node_init(&test_copy);
1234 
1235 	symtab_t sym;
1236 	symtab_init(&sym, CIL_TEST_SYM_SIZE);
1237 
1238 	int rc = cil_copy_ipaddr(test_db, test_ast_node->data, &test_copy->data, &sym);
1239 	CuAssertIntEquals(tc, rc, SEPOL_OK);
1240 }
1241 
test_cil_copy_conditional(CuTest * tc)1242 void test_cil_copy_conditional(CuTest *tc) {
1243 	char *line[] = {"(", "booleanif", "(", "and", "foo", "bar", ")",
1244 			"(", "true",
1245 			"(", "allow", "foo", "bar", "(", "file", "(", "read", ")", ")", ")", ")", ")", NULL};
1246 
1247 	struct cil_tree *test_tree;
1248 	gen_test_tree(&test_tree, line);
1249 
1250 	struct cil_tree_node *test_ast_node;
1251 	cil_tree_node_init(&test_ast_node);
1252 
1253 	struct cil_db *test_db;
1254 	cil_db_init(&test_db);
1255 
1256 	test_ast_node->parent = test_db->ast->root;
1257 	test_ast_node->line = 1;
1258 
1259 	cil_gen_boolif(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
1260 
1261 	struct cil_list_item *curr_old;
1262 	curr_old = ((struct cil_booleanif*)test_ast_node->data)->expr_stack->head;
1263 
1264 	struct cil_conditional *cond_new;
1265 
1266 	symtab_t sym;
1267 	symtab_init(&sym, CIL_TEST_SYM_SIZE);
1268 
1269 	int rc = cil_copy_conditional(test_db, curr_old->data, (void**)&cond_new, &sym);
1270 	CuAssertIntEquals(tc, rc, SEPOL_OK);
1271 
1272 	CuAssertStrEquals(tc, ((struct cil_conditional*)curr_old->data)->str, cond_new->str);
1273 	CuAssertIntEquals(tc, ((struct cil_conditional*)curr_old->data)->flavor, cond_new->flavor);
1274 }
1275 
test_cil_copy_boolif(CuTest * tc)1276 void test_cil_copy_boolif(CuTest *tc) {
1277 	char *line[] = {"(", "booleanif", "(", "and", "foo", "bar", ")",
1278 			"(", "true",
1279 			"(", "allow", "foo", "bar", "(", "file", "(", "read", ")", ")", ")", ")", ")", NULL};
1280 
1281 	struct cil_tree *test_tree;
1282 	gen_test_tree(&test_tree, line);
1283 
1284 	struct cil_tree_node *test_ast_node;
1285 	cil_tree_node_init(&test_ast_node);
1286 
1287 	struct cil_db *test_db;
1288 	cil_db_init(&test_db);
1289 
1290 	test_ast_node->parent = test_db->ast->root;
1291 	test_ast_node->line = 1;
1292 
1293 	cil_gen_boolif(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
1294 
1295 	struct cil_booleanif *test_copy;
1296 
1297 	symtab_t sym;
1298 	symtab_init(&sym, CIL_TEST_SYM_SIZE);
1299 
1300 	int rc = cil_copy_boolif(test_db, test_ast_node->data, (void**)&test_copy, &sym);
1301 	CuAssertIntEquals(tc, rc, SEPOL_OK);
1302 }
1303 
test_cil_copy_constrain(CuTest * tc)1304 void test_cil_copy_constrain(CuTest *tc) {
1305 	char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "eq", "l2", "h2", ")", ")", NULL};
1306 
1307         struct cil_tree *test_tree;
1308         gen_test_tree(&test_tree, line);
1309 
1310         struct cil_tree_node *test_ast_node;
1311         cil_tree_node_init(&test_ast_node);
1312 
1313         struct cil_db *test_db;
1314         cil_db_init(&test_db);
1315 
1316         test_ast_node->parent = test_db->ast->root;
1317         test_ast_node->line = 1;
1318 
1319         cil_gen_constrain(test_db, test_tree->root->cl_head->cl_head, test_ast_node, CIL_MLSCONSTRAIN);
1320 
1321 	struct cil_constrain *test_copy;
1322 
1323 	symtab_t sym;
1324 	symtab_init(&sym, CIL_TEST_SYM_SIZE);
1325 
1326 	int rc = cil_copy_constrain(test_db, test_ast_node->data, (void**)&test_copy, &sym);
1327 	CuAssertIntEquals(tc, rc, SEPOL_OK);
1328 	CuAssertStrEquals(tc, ((struct cil_constrain*)test_copy)->classpermset->class_str, ((struct cil_constrain *)test_ast_node->data)->classpermset->class_str);
1329 }
1330 /*
1331 void test_cil_copy_ast(CuTest *tc) {
1332 	char *line[] = {"(", "mlsconstrain", "(", "file", "dir", ")", "(", "create", "relabelto", ")", "(", "eq", "l2", "h2", ")", ")", NULL};
1333 
1334         struct cil_tree *test_tree;
1335         gen_test_tree(&test_tree, line);
1336 
1337         struct cil_tree_node *test_ast_node;
1338         cil_tree_node_init(&test_ast_node);
1339 
1340         struct cil_db *test_db;
1341         cil_db_init(&test_db);
1342 
1343         test_ast_node->parent = test_db->ast->root;
1344         test_ast_node->line = 1;
1345 
1346         cil_gen_constrain(test_db, test_tree->root->cl_head->cl_head, test_ast_node, CIL_MLSCONSTRAIN);
1347 
1348 	struct cil_tree_node *test_current;
1349 	test_current = test_tree->root->cl_head->cl_head;
1350 
1351 	struct cil_constrain *test_copy;
1352 	cil_constrain_init(&test_copy);
1353 	cil_list_init(&test_copy->expr);
1354 
1355 	int rc = cil_copy_ast(((struct cil_constrain *)test_ast_node->data)->expr, test_copy->expr);
1356 	CuAssertIntEquals(tc, rc, SEPOL_OK);
1357 }
1358 
1359 void test_cil_copy_ast_neg(CuTest *tc) {
1360 	char *line[] = {"(", "mlsconstrain", ")", NULL};
1361 
1362         struct cil_tree *test_tree;
1363         gen_test_tree(&test_tree, line);
1364 
1365         struct cil_tree_node *test_ast_node;
1366         cil_tree_node_init(&test_ast_node);
1367 
1368         struct cil_db *test_db;
1369         cil_db_init(&test_db);
1370 
1371         test_ast_node->parent = test_db->ast->root;
1372         test_ast_node->line = 1;
1373 
1374         cil_gen_constrain(test_db, test_tree->root->cl_head->cl_head, test_ast_node, CIL_MLSCONSTRAIN);
1375 
1376 	struct cil_tree_node *test_current;
1377 	test_current = test_tree->root->cl_head->cl_head;
1378 
1379 	struct cil_constrain *test_copy;
1380 	cil_constrain_init(&test_copy);
1381 	cil_list_init(&test_copy->expr);
1382 
1383 	int rc = cil_copy_ast(((struct cil_constrain *)test_ast_node->data)->expr, test_copy->expr);
1384 	CuAssertIntEquals(tc, rc, SEPOL_ERR);
1385 }
1386 */
1387 /* node_helper functions */
1388 
test_cil_copy_node_helper_block(CuTest * tc)1389 void test_cil_copy_node_helper_block(CuTest *tc) {
1390 	char *line[] = {"(", "block", "a", "(", "type", "log", ")", ")", NULL};
1391 
1392 	struct cil_tree *test_tree;
1393 	gen_test_tree(&test_tree, line);
1394 
1395 	struct cil_db *test_db;
1396 	cil_db_init(&test_db);
1397 
1398 	struct cil_db *test_db2;
1399 	cil_db_init(&test_db2);
1400 
1401 	uint32_t finished = 0;
1402 
1403 	struct cil_args_copy *extra_args = gen_copy_args(test_db2->ast->root, test_db2);
1404 
1405 	cil_build_ast(test_db, test_tree->root, test_db->ast->root);
1406 
1407 	int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
1408 	CuAssertIntEquals(tc, finished, 0);
1409 	CuAssertIntEquals(tc, SEPOL_OK, rc);
1410 }
1411 
test_cil_copy_node_helper_block_merge(CuTest * tc)1412 void test_cil_copy_node_helper_block_merge(CuTest *tc) {
1413 	char *line[] = {"(", "block", "a", "(", "type", "log", ")", ")", NULL};
1414 
1415 	struct cil_tree *test_tree;
1416 	gen_test_tree(&test_tree, line);
1417 
1418 	struct cil_db *test_db;
1419 	cil_db_init(&test_db);
1420 
1421 	uint32_t finished = 0;
1422 
1423 	struct cil_args_copy *extra_args = gen_copy_args(test_db->ast->root, test_db);
1424 
1425 	cil_build_ast(test_db, test_tree->root, test_db->ast->root);
1426 
1427 	int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
1428 	CuAssertIntEquals(tc, finished, 0);
1429 	CuAssertIntEquals(tc, SEPOL_OK, rc);
1430 }
1431 
test_cil_copy_node_helper_perm(CuTest * tc)1432 void test_cil_copy_node_helper_perm(CuTest *tc) {
1433 	char *line[] = {"(", "class", "foo", "(", "read", "write", "open", ")", ")", NULL};
1434 
1435 	struct cil_tree *test_tree;
1436 	gen_test_tree(&test_tree, line);
1437 
1438 	struct cil_db *test_db;
1439 	cil_db_init(&test_db);
1440 
1441 	struct cil_db *test_db2;
1442 	cil_db_init(&test_db2);
1443 
1444 	uint32_t finished = 0;
1445 
1446 	struct cil_class *test_class;
1447 	cil_class_init(&test_class);
1448 
1449 	struct cil_tree_node *parent_node;
1450 	cil_tree_node_init(&parent_node);
1451 	parent_node->flavor = CIL_CLASS;
1452 	parent_node->data = test_class;
1453 	struct cil_tree_node *root;
1454 	cil_tree_node_init(&root);
1455 	root->flavor = CIL_ROOT;
1456 	parent_node->parent = root;
1457 
1458 	struct cil_args_copy *extra_args = gen_copy_args(parent_node, test_db2);
1459 
1460 	cil_build_ast(test_db, test_tree->root, test_db->ast->root);
1461 
1462 	int rc = __cil_copy_node_helper(test_db->ast->root->cl_head->cl_head, &finished, extra_args);
1463 	CuAssertIntEquals(tc, finished, 0);
1464 	CuAssertIntEquals(tc, SEPOL_OK, rc);
1465 }
1466 
test_cil_copy_node_helper_perm_neg(CuTest * tc)1467 void test_cil_copy_node_helper_perm_neg(CuTest *tc) {
1468 	char *line[] = {"(", "class", "foo", "(", "read", "write", "open", ")", ")", NULL};
1469 
1470 	struct cil_tree *test_tree;
1471 	gen_test_tree(&test_tree, line);
1472 
1473 	struct cil_db *test_db;
1474 	cil_db_init(&test_db);
1475 
1476 	uint32_t finished = 0;
1477 
1478 	struct cil_args_copy *extra_args = gen_copy_args(test_db->ast->root, test_db);
1479 
1480 	cil_build_ast(test_db, test_tree->root, test_db->ast->root);
1481 
1482 	int rc = __cil_copy_node_helper(test_db->ast->root->cl_head->cl_head, &finished, extra_args);
1483 	CuAssertIntEquals(tc, finished, 0);
1484 	CuAssertIntEquals(tc, SEPOL_ERR, rc);
1485 }
1486 
test_cil_copy_node_helper_class(CuTest * tc)1487 void test_cil_copy_node_helper_class(CuTest *tc) {
1488 	char *line[] = {"(", "class", "file", "(", "read", "write", "open", ")", ")", NULL};
1489 
1490 	struct cil_tree *test_tree;
1491 	gen_test_tree(&test_tree, line);
1492 
1493 	struct cil_db *test_db;
1494 	cil_db_init(&test_db);
1495 
1496 	struct cil_db *test_db2;
1497 	cil_db_init(&test_db2);
1498 
1499 	uint32_t finished = 0;
1500 
1501 	struct cil_args_copy *extra_args = gen_copy_args(test_db2->ast->root, test_db2);
1502 
1503 	cil_build_ast(test_db, test_tree->root, test_db->ast->root);
1504 
1505 	int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
1506 	CuAssertIntEquals(tc, finished, 0);
1507 	CuAssertIntEquals(tc, SEPOL_OK, rc);
1508 }
1509 
test_cil_copy_node_helper_class_dup_neg(CuTest * tc)1510 void test_cil_copy_node_helper_class_dup_neg(CuTest *tc) {
1511 	char *line[] = {"(", "class", "test", "(", "read", "write", ")", ")", NULL};
1512 
1513 	struct cil_tree *test_tree;
1514 	gen_test_tree(&test_tree, line);
1515 
1516 	struct cil_db *test_db;
1517 	cil_db_init(&test_db);
1518 
1519 	uint32_t finished = 0;
1520 
1521 	struct cil_args_copy *extra_args = gen_copy_args(test_db->ast->root, test_db);
1522 
1523 	cil_build_ast(test_db, test_tree->root, test_db->ast->root);
1524 
1525 	int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
1526 	CuAssertIntEquals(tc, finished, 0);
1527 	CuAssertIntEquals(tc, SEPOL_ERR, rc);
1528 }
1529 
test_cil_copy_node_helper_common(CuTest * tc)1530 void test_cil_copy_node_helper_common(CuTest *tc) {
1531 	char *line[] = {"(", "common", "test", "(", "read", "write", ")", ")", NULL};
1532 
1533 	struct cil_tree *test_tree;
1534 	gen_test_tree(&test_tree, line);
1535 
1536 	struct cil_db *test_db;
1537 	cil_db_init(&test_db);
1538 
1539 	struct cil_db *test_db2;
1540 	cil_db_init(&test_db2);
1541 
1542 	uint32_t finished = 0;
1543 
1544 	struct cil_args_copy *extra_args = gen_copy_args(test_db2->ast->root, test_db2);
1545 
1546 	cil_build_ast(test_db, test_tree->root, test_db->ast->root);
1547 
1548 	int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
1549 	CuAssertIntEquals(tc, finished, 0);
1550 	CuAssertIntEquals(tc, SEPOL_OK, rc);
1551 }
1552 
test_cil_copy_node_helper_common_dup_neg(CuTest * tc)1553 void test_cil_copy_node_helper_common_dup_neg(CuTest *tc) {
1554 	char *line[] = {"(", "class", "file", "(", "read", "write", "open", ")", ")", NULL};
1555 
1556 	struct cil_tree *test_tree;
1557 	gen_test_tree(&test_tree, line);
1558 
1559 	struct cil_db *test_db;
1560 	cil_db_init(&test_db);
1561 
1562 	uint32_t finished = 0;
1563 
1564 	struct cil_args_copy *extra_args = gen_copy_args(test_db->ast->root, test_db);
1565 
1566 	cil_build_ast(test_db, test_tree->root, test_db->ast->root);
1567 
1568 	int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
1569 	CuAssertIntEquals(tc, finished, 0);
1570 	CuAssertIntEquals(tc, SEPOL_ERR, rc);
1571 }
1572 
test_cil_copy_node_helper_classcommon(CuTest * tc)1573 void test_cil_copy_node_helper_classcommon(CuTest *tc) {
1574 	char *line[] = {"(", "classcommon", "file", "file", NULL};
1575 
1576 	struct cil_tree *test_tree;
1577 	gen_test_tree(&test_tree, line);
1578 
1579 	struct cil_db *test_db;
1580 	cil_db_init(&test_db);
1581 
1582 	struct cil_db *test_db2;
1583 	cil_db_init(&test_db2);
1584 
1585 	uint32_t finished = 0;
1586 
1587 	struct cil_args_copy *extra_args = gen_copy_args(test_db2->ast->root, test_db2);
1588 
1589 	cil_build_ast(test_db, test_tree->root, test_db->ast->root);
1590 
1591 	int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
1592 	CuAssertIntEquals(tc, finished, 0);
1593 	CuAssertIntEquals(tc, SEPOL_OK, rc);
1594 }
1595 
test_cil_copy_node_helper_sid(CuTest * tc)1596 void test_cil_copy_node_helper_sid(CuTest *tc) {
1597 	char *line[] = {"(", "sid", "test", ")", NULL};
1598 
1599 	struct cil_tree *test_tree;
1600 	gen_test_tree(&test_tree, line);
1601 
1602 	struct cil_db *test_db;
1603 	cil_db_init(&test_db);
1604 
1605 	struct cil_db *test_db2;
1606 	cil_db_init(&test_db2);
1607 
1608 	uint32_t finished = 0;
1609 
1610 	struct cil_args_copy *extra_args = gen_copy_args(test_db2->ast->root, test_db2);
1611 
1612 	cil_build_ast(test_db, test_tree->root, test_db->ast->root);
1613 
1614 	int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
1615 	CuAssertIntEquals(tc, finished, 0);
1616 	CuAssertIntEquals(tc, SEPOL_OK, rc);
1617 }
1618 
test_cil_copy_node_helper_sid_merge(CuTest * tc)1619 void test_cil_copy_node_helper_sid_merge(CuTest *tc) {
1620 	char *line[] = {"(", "sid", "test", ")", NULL};
1621 
1622 	struct cil_tree *test_tree;
1623 	gen_test_tree(&test_tree, line);
1624 
1625 	struct cil_db *test_db;
1626 	cil_db_init(&test_db);
1627 
1628 	uint32_t finished = 0;
1629 
1630 	struct cil_args_copy *extra_args = gen_copy_args(test_db->ast->root, test_db);
1631 
1632 	cil_build_ast(test_db, test_tree->root, test_db->ast->root);
1633 
1634 	int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
1635 	CuAssertIntEquals(tc, finished, 0);
1636 	CuAssertIntEquals(tc, SEPOL_OK, rc);
1637 }
1638 
test_cil_copy_node_helper_sidcontext(CuTest * tc)1639 void test_cil_copy_node_helper_sidcontext(CuTest *tc) {
1640 	char *line[] = {"(", "sidcontext", "test", "(", "blah_u", "blah_r", "blah_t", "(", "low", "high", ")", ")", ")", NULL};
1641 
1642 	struct cil_tree *test_tree;
1643 	gen_test_tree(&test_tree, line);
1644 
1645 	struct cil_db *test_db;
1646 	cil_db_init(&test_db);
1647 
1648 	struct cil_db *test_db2;
1649 	cil_db_init(&test_db2);
1650 
1651 	uint32_t finished = 0;
1652 
1653 	struct cil_args_copy *extra_args = gen_copy_args(test_db2->ast->root, test_db2);
1654 
1655 	cil_build_ast(test_db, test_tree->root, test_db->ast->root);
1656 
1657 	int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
1658 	CuAssertIntEquals(tc, finished, 0);
1659 	CuAssertIntEquals(tc, SEPOL_OK, rc);
1660 }
1661 
test_cil_copy_node_helper_user(CuTest * tc)1662 void test_cil_copy_node_helper_user(CuTest *tc) {
1663 	char *line[] = {"(", "user", "sysadm", ")", NULL};
1664 
1665 	struct cil_tree *test_tree;
1666 	gen_test_tree(&test_tree, line);
1667 
1668 	struct cil_db *test_db;
1669 	cil_db_init(&test_db);
1670 
1671 	struct cil_db *test_db2;
1672 	cil_db_init(&test_db2);
1673 
1674 	uint32_t finished = 0;
1675 
1676 	struct cil_args_copy *extra_args = gen_copy_args(test_db2->ast->root, test_db2);
1677 
1678 	cil_build_ast(test_db, test_tree->root, test_db->ast->root);
1679 
1680 	int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
1681 	CuAssertIntEquals(tc, finished, 0);
1682 	CuAssertIntEquals(tc, SEPOL_OK, rc);
1683 }
1684 
test_cil_copy_node_helper_user_merge(CuTest * tc)1685 void test_cil_copy_node_helper_user_merge(CuTest *tc) {
1686 	char *line[] = {"(", "user", "sysadm", ")", NULL};
1687 
1688 	struct cil_tree *test_tree;
1689 	gen_test_tree(&test_tree, line);
1690 
1691 	struct cil_db *test_db;
1692 	cil_db_init(&test_db);
1693 
1694 	uint32_t finished = 0;
1695 
1696 	struct cil_args_copy *extra_args = gen_copy_args(test_db->ast->root, test_db);
1697 
1698 	cil_build_ast(test_db, test_tree->root, test_db->ast->root);
1699 
1700 	int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
1701 	CuAssertIntEquals(tc, finished, 0);
1702 	CuAssertIntEquals(tc, SEPOL_OK, rc);
1703 }
1704 
test_cil_copy_node_helper_role(CuTest * tc)1705 void test_cil_copy_node_helper_role(CuTest *tc) {
1706 	char *line[] = {"(", "role", "role_r", ")", NULL};
1707 
1708 	struct cil_tree *test_tree;
1709 	gen_test_tree(&test_tree, line);
1710 
1711 	struct cil_db *test_db;
1712 	cil_db_init(&test_db);
1713 
1714 	struct cil_db *test_db2;
1715 	cil_db_init(&test_db2);
1716 
1717 	uint32_t finished = 0;
1718 
1719 	struct cil_args_copy *extra_args = gen_copy_args(test_db2->ast->root, test_db2);
1720 
1721 	cil_build_ast(test_db, test_tree->root, test_db->ast->root);
1722 
1723 	int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
1724 	CuAssertIntEquals(tc, finished, 0);
1725 	CuAssertIntEquals(tc, SEPOL_OK, rc);
1726 }
1727 
test_cil_copy_node_helper_role_merge(CuTest * tc)1728 void test_cil_copy_node_helper_role_merge(CuTest *tc) {
1729 	char *line[] = {"(", "role", "role_r", ")", NULL};
1730 
1731 	struct cil_tree *test_tree;
1732 	gen_test_tree(&test_tree, line);
1733 
1734 	struct cil_db *test_db;
1735 	cil_db_init(&test_db);
1736 
1737 	uint32_t finished = 0;
1738 
1739 	struct cil_args_copy *extra_args = gen_copy_args(test_db->ast->root, test_db);
1740 
1741 	cil_build_ast(test_db, test_tree->root, test_db->ast->root);
1742 
1743 	int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
1744 	CuAssertIntEquals(tc, finished, 0);
1745 	CuAssertIntEquals(tc, SEPOL_OK, rc);
1746 }
1747 
test_cil_copy_node_helper_userrole(CuTest * tc)1748 void test_cil_copy_node_helper_userrole(CuTest *tc) {
1749 	char *line[] = {"(", "userrole", "staff_u", "staff_r", ")", NULL};
1750 
1751 	struct cil_tree *test_tree;
1752 	gen_test_tree(&test_tree, line);
1753 
1754 	struct cil_db *test_db;
1755 	cil_db_init(&test_db);
1756 
1757 	struct cil_db *test_db2;
1758 	cil_db_init(&test_db2);
1759 
1760 	uint32_t finished = 0;
1761 
1762 	struct cil_args_copy *extra_args = gen_copy_args(test_db2->ast->root, test_db2);
1763 
1764 	cil_build_ast(test_db, test_tree->root, test_db->ast->root);
1765 
1766 	int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
1767 	CuAssertIntEquals(tc, finished, 0);
1768 	CuAssertIntEquals(tc, SEPOL_OK, rc);
1769 }
1770 
test_cil_copy_node_helper_type(CuTest * tc)1771 void test_cil_copy_node_helper_type(CuTest *tc) {
1772 	char *line[] = {"(", "type", "type_t", ")", NULL};
1773 
1774 	struct cil_tree *test_tree;
1775 	gen_test_tree(&test_tree, line);
1776 
1777 	struct cil_db *test_db;
1778 	cil_db_init(&test_db);
1779 
1780 	struct cil_db *test_db2;
1781 	cil_db_init(&test_db2);
1782 
1783 	uint32_t finished = 0;
1784 
1785 	struct cil_args_copy *extra_args = gen_copy_args(test_db2->ast->root, test_db2);
1786 
1787 	cil_build_ast(test_db, test_tree->root, test_db->ast->root);
1788 
1789 	int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
1790 	CuAssertIntEquals(tc, finished, 0);
1791 	CuAssertIntEquals(tc, SEPOL_OK, rc);
1792 }
1793 
test_cil_copy_node_helper_type_merge(CuTest * tc)1794 void test_cil_copy_node_helper_type_merge(CuTest *tc) {
1795 	char *line[] = {"(", "type", "type_t", ")", NULL};
1796 
1797 	struct cil_tree *test_tree;
1798 	gen_test_tree(&test_tree, line);
1799 
1800 	struct cil_db *test_db;
1801 	cil_db_init(&test_db);
1802 
1803 	uint32_t finished = 0;
1804 
1805 	struct cil_args_copy *extra_args = gen_copy_args(test_db->ast->root, test_db);
1806 
1807 	cil_build_ast(test_db, test_tree->root, test_db->ast->root);
1808 
1809 	int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
1810 	CuAssertIntEquals(tc, finished, 0);
1811 	CuAssertIntEquals(tc, SEPOL_OK, rc);
1812 }
1813 
test_cil_copy_node_helper_typeattribute(CuTest * tc)1814 void test_cil_copy_node_helper_typeattribute(CuTest *tc) {
1815 	char *line[] = {"(", "typeattribute", "bar", ")", NULL};
1816 
1817 	struct cil_tree *test_tree;
1818 	gen_test_tree(&test_tree, line);
1819 
1820 	struct cil_db *test_db;
1821 	cil_db_init(&test_db);
1822 
1823 	struct cil_db *test_db2;
1824 	cil_db_init(&test_db2);
1825 
1826 	uint32_t finished = 0;
1827 
1828 	struct cil_args_copy *extra_args = gen_copy_args(test_db2->ast->root, test_db2);
1829 
1830 	cil_build_ast(test_db, test_tree->root, test_db->ast->root);
1831 
1832 	int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
1833 	CuAssertIntEquals(tc, finished, 0);
1834 	CuAssertIntEquals(tc, SEPOL_OK, rc);
1835 }
1836 
test_cil_copy_node_helper_typeattribute_merge(CuTest * tc)1837 void test_cil_copy_node_helper_typeattribute_merge(CuTest *tc) {
1838 	char *line[] = {"(", "typeattribute", "bar", ")", NULL};
1839 
1840 	struct cil_tree *test_tree;
1841 	gen_test_tree(&test_tree, line);
1842 
1843 	struct cil_db *test_db;
1844 	cil_db_init(&test_db);
1845 
1846 	uint32_t finished = 0;
1847 
1848 	struct cil_args_copy *extra_args = gen_copy_args(test_db->ast->root, test_db);
1849 
1850 	cil_build_ast(test_db, test_tree->root, test_db->ast->root);
1851 
1852 	int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
1853 	CuAssertIntEquals(tc, finished, 0);
1854 	CuAssertIntEquals(tc, SEPOL_OK, rc);
1855 }
1856 
test_cil_copy_node_helper_typealias(CuTest * tc)1857 void test_cil_copy_node_helper_typealias(CuTest *tc) {
1858 	char *line[] = {"(", "typealias", ".test.type", "type_t", ")", "(", "type", "test", ")", NULL};
1859 
1860 	struct cil_tree *test_tree;
1861 	gen_test_tree(&test_tree, line);
1862 
1863 	struct cil_db *test_db;
1864 	cil_db_init(&test_db);
1865 
1866 	struct cil_db *test_db2;
1867 	cil_db_init(&test_db2);
1868 
1869 	uint32_t finished = 0;
1870 
1871 	struct cil_args_copy *extra_args = gen_copy_args(test_db2->ast->root, test_db2);
1872 
1873 	cil_build_ast(test_db, test_tree->root, test_db->ast->root);
1874 
1875 	int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
1876 	CuAssertIntEquals(tc, finished, 0);
1877 	CuAssertIntEquals(tc, SEPOL_OK, rc);
1878 }
1879 
test_cil_copy_node_helper_typealias_dup_neg(CuTest * tc)1880 void test_cil_copy_node_helper_typealias_dup_neg(CuTest *tc) {
1881 	char *line[] = {"(", "typealias", ".test.type", "type_t", ")", "(", "type", "test", ")", NULL};
1882 
1883 	struct cil_tree *test_tree;
1884 	gen_test_tree(&test_tree, line);
1885 
1886 	struct cil_db *test_db;
1887 	cil_db_init(&test_db);
1888 
1889 	uint32_t finished = 0;
1890 
1891 	struct cil_args_copy *extra_args = gen_copy_args(test_db->ast->root, test_db);
1892 
1893 	cil_build_ast(test_db, test_tree->root, test_db->ast->root);
1894 
1895 	int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
1896 	CuAssertIntEquals(tc, finished, 0);
1897 	CuAssertIntEquals(tc, SEPOL_ERR, rc);
1898 }
1899 
test_cil_copy_node_helper_bool(CuTest * tc)1900 void test_cil_copy_node_helper_bool(CuTest *tc) {
1901 	char *line[] = {"(", "boolean", "foo", "true", ")", NULL};
1902 
1903 	struct cil_tree *test_tree;
1904 	gen_test_tree(&test_tree, line);
1905 
1906 	struct cil_db *test_db;
1907 	cil_db_init(&test_db);
1908 
1909 	struct cil_db *test_db2;
1910 	cil_db_init(&test_db2);
1911 
1912 	uint32_t finished = 0;
1913 
1914 	struct cil_args_copy *extra_args = gen_copy_args(test_db2->ast->root, test_db2);
1915 
1916 	cil_build_ast(test_db, test_tree->root, test_db->ast->root);
1917 
1918 	int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
1919 	CuAssertIntEquals(tc, finished, 0);
1920 	CuAssertIntEquals(tc, SEPOL_OK, rc);
1921 }
1922 
test_cil_copy_node_helper_bool_dup_neg(CuTest * tc)1923 void test_cil_copy_node_helper_bool_dup_neg(CuTest *tc) {
1924 	char *line[] = {"(", "boolean", "foo", "true", ")", NULL};
1925 
1926 	struct cil_tree *test_tree;
1927 	gen_test_tree(&test_tree, line);
1928 
1929 	struct cil_db *test_db;
1930 	cil_db_init(&test_db);
1931 
1932 	uint32_t finished = 0;
1933 
1934 	struct cil_args_copy *extra_args = gen_copy_args(test_db->ast->root, test_db);
1935 
1936 	cil_build_ast(test_db, test_tree->root, test_db->ast->root);
1937 
1938 	int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
1939 	CuAssertIntEquals(tc, finished, 0);
1940 	CuAssertIntEquals(tc, SEPOL_ERR, rc);
1941 }
1942 
test_cil_copy_node_helper_avrule(CuTest * tc)1943 void test_cil_copy_node_helper_avrule(CuTest *tc) {
1944 	char *line[] = {"(", "allow", "test", "foo", "(", "file", "(", "read", "write", ")", ")", ")", NULL};
1945 
1946 	struct cil_tree *test_tree;
1947 	gen_test_tree(&test_tree, line);
1948 
1949 	struct cil_db *test_db;
1950 	cil_db_init(&test_db);
1951 
1952 	struct cil_db *test_db2;
1953 	cil_db_init(&test_db2);
1954 
1955 	uint32_t finished = 0;
1956 
1957 	struct cil_args_copy *extra_args = gen_copy_args(test_db2->ast->root, test_db2);
1958 
1959 	cil_build_ast(test_db, test_tree->root, test_db->ast->root);
1960 
1961 	int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
1962 	CuAssertIntEquals(tc, finished, 0);
1963 	CuAssertIntEquals(tc, SEPOL_OK, rc);
1964 }
1965 
test_cil_copy_node_helper_type_rule(CuTest * tc)1966 void test_cil_copy_node_helper_type_rule(CuTest *tc) {
1967 	char *line[] = {"(", "typetransition", "foo", "bar", "file", "foobar", ")", NULL};
1968 
1969 	struct cil_tree *test_tree;
1970 	gen_test_tree(&test_tree, line);
1971 
1972 	struct cil_db *test_db;
1973 	cil_db_init(&test_db);
1974 
1975 	struct cil_db *test_db2;
1976 	cil_db_init(&test_db2);
1977 
1978 	uint32_t finished = 0;
1979 
1980 	struct cil_args_copy *extra_args = gen_copy_args(test_db2->ast->root, test_db2);
1981 
1982 	cil_build_ast(test_db, test_tree->root, test_db->ast->root);
1983 
1984 	int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
1985 	CuAssertIntEquals(tc, finished, 0);
1986 	CuAssertIntEquals(tc, SEPOL_OK, rc);
1987 }
1988 
test_cil_copy_node_helper_sens(CuTest * tc)1989 void test_cil_copy_node_helper_sens(CuTest *tc) {
1990 	char *line[] = {"(", "sensitivity", "s0", ")", NULL};
1991 
1992 	struct cil_tree *test_tree;
1993 	gen_test_tree(&test_tree, line);
1994 
1995 	struct cil_db *test_db;
1996 	cil_db_init(&test_db);
1997 
1998 	struct cil_db *test_db2;
1999 	cil_db_init(&test_db2);
2000 
2001 	uint32_t finished = 0;
2002 
2003 	struct cil_args_copy *extra_args = gen_copy_args(test_db2->ast->root, test_db2);
2004 
2005 	cil_build_ast(test_db, test_tree->root, test_db->ast->root);
2006 
2007 	int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
2008 	CuAssertIntEquals(tc, finished, 0);
2009 	CuAssertIntEquals(tc, SEPOL_OK, rc);
2010 }
2011 
test_cil_copy_node_helper_sens_merge(CuTest * tc)2012 void test_cil_copy_node_helper_sens_merge(CuTest *tc) {
2013 	char *line[] = {"(", "sensitivity", "s0", ")", NULL};
2014 
2015 	struct cil_tree *test_tree;
2016 	gen_test_tree(&test_tree, line);
2017 
2018 	struct cil_db *test_db;
2019 	cil_db_init(&test_db);
2020 
2021 	uint32_t finished = 0;
2022 
2023 	struct cil_args_copy *extra_args = gen_copy_args(test_db->ast->root, test_db);
2024 
2025 	cil_build_ast(test_db, test_tree->root, test_db->ast->root);
2026 
2027 	int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
2028 	CuAssertIntEquals(tc, finished, 0);
2029 	CuAssertIntEquals(tc, SEPOL_OK, rc);
2030 }
2031 
test_cil_copy_node_helper_sensalias(CuTest * tc)2032 void test_cil_copy_node_helper_sensalias(CuTest *tc) {
2033 	char *line[] = {"(", "sensitivityalias", "s0", "alias", ")", NULL};
2034 
2035 	struct cil_tree *test_tree;
2036 	gen_test_tree(&test_tree, line);
2037 
2038 	struct cil_db *test_db;
2039 	cil_db_init(&test_db);
2040 
2041 	struct cil_db *test_db2;
2042 	cil_db_init(&test_db2);
2043 
2044 	uint32_t finished = 0;
2045 
2046 	struct cil_args_copy *extra_args = gen_copy_args(test_db2->ast->root, test_db2);
2047 
2048 	cil_build_ast(test_db, test_tree->root, test_db->ast->root);
2049 
2050 	int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
2051 	CuAssertIntEquals(tc, finished, 0);
2052 	CuAssertIntEquals(tc, SEPOL_OK, rc);
2053 }
2054 
test_cil_copy_node_helper_sensalias_dup_neg(CuTest * tc)2055 void test_cil_copy_node_helper_sensalias_dup_neg(CuTest *tc) {
2056 	char *line[] = {"(", "sensitivityalias", "s0", "alias", ")", NULL};
2057 
2058 	struct cil_tree *test_tree;
2059 	gen_test_tree(&test_tree, line);
2060 
2061 	struct cil_db *test_db;
2062 	cil_db_init(&test_db);
2063 
2064 	uint32_t finished = 0;
2065 
2066 	struct cil_args_copy *extra_args = gen_copy_args(test_db->ast->root, test_db);
2067 
2068 	cil_build_ast(test_db, test_tree->root, test_db->ast->root);
2069 
2070 	int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
2071 	CuAssertIntEquals(tc, finished, 0);
2072 	CuAssertIntEquals(tc, SEPOL_ERR, rc);
2073 }
2074 
test_cil_copy_node_helper_cat(CuTest * tc)2075 void test_cil_copy_node_helper_cat(CuTest *tc) {
2076 	char *line[] = {"(", "category", "c0", ")", NULL};
2077 
2078 	struct cil_tree *test_tree;
2079 	gen_test_tree(&test_tree, line);
2080 
2081 	struct cil_db *test_db;
2082 	cil_db_init(&test_db);
2083 
2084 	struct cil_db *test_db2;
2085 	cil_db_init(&test_db2);
2086 
2087 	uint32_t finished = 0;
2088 
2089 	struct cil_args_copy *extra_args = gen_copy_args(test_db2->ast->root, test_db2);
2090 
2091 	cil_build_ast(test_db, test_tree->root, test_db->ast->root);
2092 
2093 	int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
2094 	CuAssertIntEquals(tc, finished, 0);
2095 	CuAssertIntEquals(tc, SEPOL_OK, rc);
2096 }
2097 
test_cil_copy_node_helper_cat_merge(CuTest * tc)2098 void test_cil_copy_node_helper_cat_merge(CuTest *tc) {
2099 	char *line[] = {"(", "category", "c0", ")", NULL};
2100 
2101 	struct cil_tree *test_tree;
2102 	gen_test_tree(&test_tree, line);
2103 
2104 	struct cil_db *test_db;
2105 	cil_db_init(&test_db);
2106 
2107 	uint32_t finished = 0;
2108 
2109 	struct cil_args_copy *extra_args = gen_copy_args(test_db->ast->root, test_db);
2110 
2111 	cil_build_ast(test_db, test_tree->root, test_db->ast->root);
2112 
2113 	int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
2114 	CuAssertIntEquals(tc, finished, 0);
2115 	CuAssertIntEquals(tc, SEPOL_OK, rc);
2116 }
2117 
test_cil_copy_node_helper_catalias(CuTest * tc)2118 void test_cil_copy_node_helper_catalias(CuTest *tc) {
2119 	char *line[] = {"(", "categoryalias", "c0", "red", ")", NULL};
2120 
2121 	struct cil_tree *test_tree;
2122 	gen_test_tree(&test_tree, line);
2123 
2124 	struct cil_db *test_db;
2125 	cil_db_init(&test_db);
2126 
2127 	struct cil_db *test_db2;
2128 	cil_db_init(&test_db2);
2129 
2130 	uint32_t finished = 0;
2131 
2132 	struct cil_args_copy *extra_args = gen_copy_args(test_db2->ast->root, test_db2);
2133 
2134 	cil_build_ast(test_db, test_tree->root, test_db->ast->root);
2135 
2136 	int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
2137 	CuAssertIntEquals(tc, finished, 0);
2138 	CuAssertIntEquals(tc, SEPOL_OK, rc);
2139 }
2140 
test_cil_copy_node_helper_catalias_dup_neg(CuTest * tc)2141 void test_cil_copy_node_helper_catalias_dup_neg(CuTest *tc) {
2142 	char *line[] = {"(", "categoryalias", "c0", "red", ")", NULL};
2143 
2144 	struct cil_tree *test_tree;
2145 	gen_test_tree(&test_tree, line);
2146 
2147 	struct cil_db *test_db;
2148 	cil_db_init(&test_db);
2149 
2150 	uint32_t finished = 0;
2151 
2152 	struct cil_args_copy *extra_args = gen_copy_args(test_db->ast->root, test_db);
2153 
2154 	cil_build_ast(test_db, test_tree->root, test_db->ast->root);
2155 
2156 	int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
2157 	CuAssertIntEquals(tc, finished, 0);
2158 	CuAssertIntEquals(tc, SEPOL_ERR, rc);
2159 }
2160 
test_cil_copy_node_helper_senscat(CuTest * tc)2161 void test_cil_copy_node_helper_senscat(CuTest *tc) {
2162 	char *line[] = {"(", "sensitivity", "s0", ")",
2163                         "(", "sensitivity", "s1", ")",
2164                         "(", "dominance", "(", "s0", "s1", ")", ")",
2165 			"(", "category", "c0", ")",
2166 			"(", "category", "c255", ")",
2167 			"(", "categoryorder", "(", "c0", "c255", ")", ")",
2168 			"(", "sensitivitycategory", "s1", "(", "c0", "c255", ")", ")", NULL};
2169 
2170 	struct cil_tree *test_tree;
2171 	gen_test_tree(&test_tree, line);
2172 
2173 	struct cil_db *test_db;
2174 	cil_db_init(&test_db);
2175 
2176 	struct cil_db *test_db2;
2177 	cil_db_init(&test_db2);
2178 
2179 	uint32_t finished = 0;
2180 
2181 	struct cil_senscat *test_senscat;
2182 	cil_senscat_init(&test_senscat);
2183 
2184 	struct cil_tree_node *parent_node;
2185 	cil_tree_node_init(&parent_node);
2186 	parent_node->flavor = CIL_SENSCAT;
2187 	parent_node->data = test_senscat;
2188 
2189 	struct cil_args_copy *extra_args = gen_copy_args(parent_node, test_db2);
2190 
2191 	cil_build_ast(test_db, test_tree->root, test_db->ast->root);
2192 
2193 	int rc = __cil_copy_node_helper(test_db->ast->root->cl_head->next->next->next->next->next->next, &finished, extra_args);
2194 	CuAssertIntEquals(tc, finished, 0);
2195 	CuAssertIntEquals(tc, SEPOL_OK, rc);
2196 }
2197 
test_cil_copy_node_helper_catorder(CuTest * tc)2198 void test_cil_copy_node_helper_catorder(CuTest *tc) {
2199 	char *line[] = {"(", "category", "c0", ")",
2200 			"(", "category", "c255", ")",
2201 			"(", "categoryorder", "(", "c0", "c255", ")", ")", NULL};
2202 
2203 	struct cil_tree *test_tree;
2204 	gen_test_tree(&test_tree, line);
2205 
2206 	struct cil_db *test_db;
2207 	cil_db_init(&test_db);
2208 
2209 	struct cil_db *test_db2;
2210 	cil_db_init(&test_db2);
2211 
2212 	uint32_t finished = 0;
2213 
2214 	struct cil_catorder *test_catorder;
2215 	cil_catorder_init(&test_catorder);
2216 
2217 	struct cil_tree_node *parent_node;
2218 	cil_tree_node_init(&parent_node);
2219 	parent_node->flavor = CIL_CATORDER;
2220 	parent_node->data = test_catorder;
2221 
2222 	struct cil_args_copy *extra_args = gen_copy_args(parent_node, test_db2);
2223 
2224 	cil_build_ast(test_db, test_tree->root, test_db->ast->root);
2225 
2226 	int rc = __cil_copy_node_helper(test_db->ast->root->cl_head->next->next, &finished, extra_args);
2227 	CuAssertIntEquals(tc, finished, 0);
2228 	CuAssertIntEquals(tc, SEPOL_OK, rc);
2229 }
2230 
test_cil_copy_node_helper_dominance(CuTest * tc)2231 void test_cil_copy_node_helper_dominance(CuTest *tc) {
2232         char *line[] = {"(", "sensitivity", "s0", ")",
2233                         "(", "sensitivity", "s1", ")",
2234                         "(", "sensitivity", "s2", ")",
2235                         "(", "dominance", "(", "s0", "s1", ")", ")", NULL};
2236 
2237 	struct cil_tree *test_tree;
2238 	gen_test_tree(&test_tree, line);
2239 
2240 	struct cil_db *test_db;
2241 	cil_db_init(&test_db);
2242 
2243 	struct cil_db *test_db2;
2244 	cil_db_init(&test_db2);
2245 
2246 	uint32_t finished = 0;
2247 
2248 	struct cil_sens *test_sens;
2249 	cil_sens_init(&test_sens);
2250 
2251 	struct cil_tree_node *parent_node;
2252 	cil_tree_node_init(&parent_node);
2253 	parent_node->flavor = CIL_SENS;
2254 	parent_node->data = test_sens;
2255 
2256 	struct cil_args_copy *extra_args = gen_copy_args(parent_node, test_db2);
2257 
2258 	cil_build_ast(test_db, test_tree->root, test_db->ast->root);
2259 
2260 	int rc = __cil_copy_node_helper(test_db->ast->root->cl_head->next->next->next, &finished, extra_args);
2261 	CuAssertIntEquals(tc, finished, 0);
2262 	CuAssertIntEquals(tc, SEPOL_OK, rc);
2263 }
2264 
test_cil_copy_node_helper_level(CuTest * tc)2265 void test_cil_copy_node_helper_level(CuTest *tc) {
2266 	char *line[] = {"(", "level", "low", "(", "s0", "(", "c1", ")", ")", ")", NULL};
2267 
2268 	struct cil_tree *test_tree;
2269 	gen_test_tree(&test_tree, line);
2270 
2271 	struct cil_db *test_db;
2272 	cil_db_init(&test_db);
2273 
2274 	struct cil_db *test_db2;
2275 	cil_db_init(&test_db2);
2276 
2277 	uint32_t finished = 0;
2278 
2279 	struct cil_args_copy *extra_args = gen_copy_args(test_db2->ast->root, test_db2);
2280 
2281 	cil_build_ast(test_db, test_tree->root, test_db->ast->root);
2282 
2283 	int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
2284 	CuAssertIntEquals(tc, finished, 0);
2285 	CuAssertIntEquals(tc, SEPOL_OK, rc);
2286 }
2287 
test_cil_copy_node_helper_level_dup_neg(CuTest * tc)2288 void test_cil_copy_node_helper_level_dup_neg(CuTest *tc) {
2289 	char *line[] = {"(", "level", "low", "(", "s0", "(", "c1", ")", ")", ")", NULL};
2290 
2291 	struct cil_tree *test_tree;
2292 	gen_test_tree(&test_tree, line);
2293 
2294 	struct cil_db *test_db;
2295 	cil_db_init(&test_db);
2296 
2297 	uint32_t finished = 0;
2298 
2299 	struct cil_args_copy *extra_args = gen_copy_args(test_db->ast->root, test_db);
2300 
2301 	cil_build_ast(test_db, test_tree->root, test_db->ast->root);
2302 
2303 	int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
2304 	CuAssertIntEquals(tc, finished, 0);
2305 	CuAssertIntEquals(tc, SEPOL_ERR, rc);
2306 }
2307 
test_cil_copy_node_helper_context(CuTest * tc)2308 void test_cil_copy_node_helper_context(CuTest *tc) {
2309 	char *line[] = {"(", "context", "packet_default", "(", "system_u", "object_r", "etc_t", "(", "low", "high", ")", ")", ")", NULL};
2310 
2311 	struct cil_tree *test_tree;
2312 	gen_test_tree(&test_tree, line);
2313 
2314 	struct cil_db *test_db;
2315 	cil_db_init(&test_db);
2316 
2317 	struct cil_db *test_db2;
2318 	cil_db_init(&test_db2);
2319 
2320 	uint32_t finished = 0;
2321 
2322 	struct cil_args_copy *extra_args = gen_copy_args(test_db2->ast->root, test_db2);
2323 
2324 	cil_build_ast(test_db, test_tree->root, test_db->ast->root);
2325 
2326 	int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
2327 	CuAssertIntEquals(tc, finished, 0);
2328 	CuAssertIntEquals(tc, SEPOL_OK, rc);
2329 }
2330 
test_cil_copy_node_helper_context_dup_neg(CuTest * tc)2331 void test_cil_copy_node_helper_context_dup_neg(CuTest *tc) {
2332 	char *line[] = {"(", "context", "packet_default", "(", "system_u", "object_r", "etc_t", "(", "low", "high", ")",  ")", ")", NULL};
2333 
2334 	struct cil_tree *test_tree;
2335 	gen_test_tree(&test_tree, line);
2336 
2337 	struct cil_db *test_db;
2338 	cil_db_init(&test_db);
2339 
2340 	uint32_t finished = 0;
2341 
2342 	struct cil_args_copy *extra_args = gen_copy_args(test_db->ast->root, test_db);
2343 
2344 	cil_build_ast(test_db, test_tree->root, test_db->ast->root);
2345 
2346 	int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
2347 	CuAssertIntEquals(tc, finished, 0);
2348 	CuAssertIntEquals(tc, SEPOL_ERR, rc);
2349 }
2350 
test_cil_copy_node_helper_netifcon(CuTest * tc)2351 void test_cil_copy_node_helper_netifcon(CuTest *tc) {
2352 	char *line[] = {"(", "netifcon", "eth0", "if_default", "packet_default", ")", NULL};
2353 
2354 	struct cil_tree *test_tree;
2355 	gen_test_tree(&test_tree, line);
2356 
2357 	struct cil_db *test_db;
2358 	cil_db_init(&test_db);
2359 
2360 	struct cil_db *test_db2;
2361 	cil_db_init(&test_db2);
2362 
2363 	uint32_t finished = 0;
2364 
2365 	struct cil_args_copy *extra_args = gen_copy_args(test_db2->ast->root, test_db2);
2366 
2367 	cil_build_ast(test_db, test_tree->root, test_db->ast->root);
2368 
2369 	int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
2370 	CuAssertIntEquals(tc, finished, 0);
2371 	CuAssertIntEquals(tc, SEPOL_OK, rc);
2372 }
2373 
test_cil_copy_node_helper_call(CuTest * tc)2374 void test_cil_copy_node_helper_call(CuTest *tc) {
2375 	char *line[] = {"(", "call", "mm", "(", "foo", ")", ")", NULL};
2376 
2377 	struct cil_tree *test_tree;
2378 	gen_test_tree(&test_tree, line);
2379 
2380 	struct cil_db *test_db;
2381 	cil_db_init(&test_db);
2382 
2383 	struct cil_db *test_db2;
2384 	cil_db_init(&test_db2);
2385 
2386 	uint32_t finished = 0;
2387 
2388 	struct cil_args_copy *extra_args = gen_copy_args(test_db2->ast->root, test_db2);
2389 
2390 	cil_build_ast(test_db, test_tree->root, test_db->ast->root);
2391 
2392 	int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
2393 	CuAssertIntEquals(tc, finished, 0);
2394 	CuAssertIntEquals(tc, SEPOL_OK, rc);
2395 }
2396 
test_cil_copy_node_helper_optional(CuTest * tc)2397 void test_cil_copy_node_helper_optional(CuTest *tc) {
2398 	char *line[] = {"(", "optional", "opt", "(", "allow", "foo", "bar", "(", "file", "(", "read", ")", ")", ")", ")", NULL};
2399 
2400 	struct cil_tree *test_tree;
2401 	gen_test_tree(&test_tree, line);
2402 
2403 	struct cil_db *test_db;
2404 	cil_db_init(&test_db);
2405 
2406 	struct cil_db *test_db2;
2407 	cil_db_init(&test_db2);
2408 
2409 	uint32_t finished = 0;
2410 
2411 	struct cil_args_copy *extra_args = gen_copy_args(test_db2->ast->root, test_db2);
2412 
2413 	cil_build_ast(test_db, test_tree->root, test_db->ast->root);
2414 
2415 	int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
2416 	CuAssertIntEquals(tc, finished, 0);
2417 	CuAssertIntEquals(tc, SEPOL_OK, rc);
2418 }
2419 
test_cil_copy_node_helper_optional_merge(CuTest * tc)2420 void test_cil_copy_node_helper_optional_merge(CuTest *tc) {
2421 	char *line[] = {"(", "optional", "opt", "(", "allow", "foo", "bar", "(", "file", "(", "read", ")", ")", ")", ")", NULL};
2422 
2423 	struct cil_tree *test_tree;
2424 	gen_test_tree(&test_tree, line);
2425 
2426 	struct cil_db *test_db;
2427 	cil_db_init(&test_db);
2428 
2429 	uint32_t finished = 0;
2430 
2431 	struct cil_args_copy *extra_args = gen_copy_args(test_db->ast->root, test_db);
2432 
2433 	cil_build_ast(test_db, test_tree->root, test_db->ast->root);
2434 
2435 	int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
2436 	CuAssertIntEquals(tc, finished, 0);
2437 	CuAssertIntEquals(tc, SEPOL_OK, rc);
2438 }
2439 
test_cil_copy_node_helper_ipaddr(CuTest * tc)2440 void test_cil_copy_node_helper_ipaddr(CuTest *tc) {
2441 	char *line[] = {"(", "ipaddr", "ip", "192.168.1.1", ")", NULL};
2442 
2443 	struct cil_tree *test_tree;
2444 	gen_test_tree(&test_tree, line);
2445 
2446 	struct cil_db *test_db;
2447 	cil_db_init(&test_db);
2448 
2449 	struct cil_db *test_db2;
2450 	cil_db_init(&test_db2);
2451 
2452 	uint32_t finished = 0;
2453 
2454 	struct cil_args_copy *extra_args = gen_copy_args(test_db2->ast->root, test_db2);
2455 
2456 	cil_build_ast(test_db, test_tree->root, test_db->ast->root);
2457 
2458 	int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
2459 	CuAssertIntEquals(tc, finished, 0);
2460 	CuAssertIntEquals(tc, SEPOL_OK, rc);
2461 }
2462 
test_cil_copy_node_helper_ipaddr_dup_neg(CuTest * tc)2463 void test_cil_copy_node_helper_ipaddr_dup_neg(CuTest *tc) {
2464 	char *line[] = {"(", "ipaddr", "ip", "192.168.1.1", ")", NULL};
2465 
2466 	struct cil_tree *test_tree;
2467 	gen_test_tree(&test_tree, line);
2468 
2469 	struct cil_db *test_db;
2470 	cil_db_init(&test_db);
2471 
2472 	uint32_t finished = 0;
2473 
2474 	struct cil_args_copy *extra_args = gen_copy_args(test_db->ast->root, test_db);
2475 
2476 	cil_build_ast(test_db, test_tree->root, test_db->ast->root);
2477 
2478 	int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
2479 	CuAssertIntEquals(tc, finished, 0);
2480 	CuAssertIntEquals(tc, SEPOL_ERR, rc);
2481 }
2482 
test_cil_copy_node_helper_boolif(CuTest * tc)2483 void test_cil_copy_node_helper_boolif(CuTest *tc) {
2484 	char *line[] = {"(", "booleanif", "(", "and", "foo", "bar", ")",
2485 			"(", "true",
2486 			"(", "allow", "foo", "bar", "(", "file", "(", "read", ")", ")", ")", ")", ")", NULL};
2487 
2488 	struct cil_tree *test_tree;
2489 	gen_test_tree(&test_tree, line);
2490 
2491 	struct cil_db *test_db;
2492 	cil_db_init(&test_db);
2493 
2494 	struct cil_db *test_db2;
2495 	cil_db_init(&test_db2);
2496 
2497 	uint32_t finished = 0;
2498 
2499 	struct cil_args_copy *extra_args = gen_copy_args(test_db2->ast->root, test_db2);
2500 
2501 	cil_build_ast(test_db, test_tree->root, test_db->ast->root);
2502 
2503 	int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
2504 	CuAssertIntEquals(tc, finished, 0);
2505 	CuAssertIntEquals(tc, SEPOL_OK, rc);
2506 }
2507 
test_cil_copy_node_helper_mlsconstrain(CuTest * tc)2508 void test_cil_copy_node_helper_mlsconstrain(CuTest *tc) {
2509 	char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "eq", "l1", "l2", ")", ")", NULL};
2510 
2511 	struct cil_tree *test_tree;
2512 	gen_test_tree(&test_tree, line);
2513 
2514 	struct cil_db *test_db;
2515 	cil_db_init(&test_db);
2516 
2517 	struct cil_db *test_db2;
2518 	cil_db_init(&test_db2);
2519 
2520 	uint32_t finished = 0;
2521 
2522 	struct cil_args_copy *extra_args = gen_copy_args(test_db2->ast->root, test_db2);
2523 
2524 	cil_build_ast(test_db, test_tree->root, test_db->ast->root);
2525 
2526 	int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
2527 	CuAssertIntEquals(tc, finished, 0);
2528 	CuAssertIntEquals(tc, SEPOL_OK, rc);
2529 }
2530 
test_cil_copy_node_helper_orignull_neg(CuTest * tc)2531 void test_cil_copy_node_helper_orignull_neg(CuTest *tc) {
2532 	char *line[] = {"(", ")", NULL};
2533 
2534 	struct cil_tree *test_tree;
2535 	gen_test_tree(&test_tree, line);
2536 
2537 	struct cil_db *test_db;
2538 	cil_db_init(&test_db);
2539 
2540 	struct cil_db *test_db2;
2541 	cil_db_init(&test_db2);
2542 
2543 	uint32_t finished = 0;
2544 
2545 	struct cil_args_copy *extra_args = gen_copy_args(test_db2->ast->root, test_db2);
2546 
2547 	int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
2548 	CuAssertIntEquals(tc, SEPOL_ERR, rc);
2549 }
2550 
test_cil_copy_node_helper_extraargsnull_neg(CuTest * tc)2551 void test_cil_copy_node_helper_extraargsnull_neg(CuTest *tc) {
2552 	char *line[] = {"(", "mlsconstrain", "(", "file", "dir", ")", "(", "create", "relabelto", ")", "(", "eq", "l1", "l2", ")", ")", NULL};
2553 
2554 	struct cil_tree *test_tree;
2555 	gen_test_tree(&test_tree, line);
2556 
2557 	struct cil_db *test_db;
2558 	cil_db_init(&test_db);
2559 
2560 	struct cil_db *test_db2;
2561 	cil_db_init(&test_db2);
2562 
2563 	struct cil_args_copy *extra_args = NULL;
2564 
2565 	uint32_t finished = 0;
2566 
2567 	cil_build_ast(test_db, test_tree->root, test_db->ast->root);
2568 
2569 	int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
2570 	CuAssertIntEquals(tc, SEPOL_ERR, rc);
2571 }
2572