Skip to contentSkip to conversation

Create secil2tree to write CIL AST

PATCH In review James Carter 2 participants 6 messages Apr 21, 2021 – Apr 22, 2021 SELinux security module

lore
Share & tools
lore
#0 lore raw

v3 cover Create secil2tree to write CIL AST

For debugging purposes it would be useful to be able to write out the CIL AST at various points in the build process.

This patch set creates secil2tree which can write the CIL parse tree, the CIL AST after the build phase, or the CIL AST after the resolve phase (with names fully-qualified).

Within CIL the function cil_print_tree() has existed from early in CIL's development, but it was not exported in libsepol and there was no way to use it except by adding a call to it where you wanted to print out the CIL AST and then recompiling everything. It also used cil_log() as its output, so other messages could be mixed in with the output. This patch set moves all of this code to its own file, updates it, renames it as cil_write_ast(), and adds libsepol functions that can be used to call it after each one of the phases mentioned above.

Both the parse and build CIL AST are valid CIL policies that can be compiled with secilc, but the resolve CIL AST is not always a valid CIL policy. The biggest problem is that fully-qualified names can contain dots and CIL does not allow dots in declaration names. There are other problems as well. It would be nice to get to the point where the output for all of the trees are valid CIL, but that is a goal for the future.

v3:
- -use "-ast-phase=<phase>" in the usage message and man pages instead of "-ast-phase <phase>"

v2:
- Remove whitespace errors in cil_write_ast.h
- Use "const char*" instead of just "char*" when dealing with string literals to satisfy clang.

James Carter (3):
libsepol/cil: Create functions to write the CIL AST libsepol/cil: Add functions to make use of cil_write_ast()
secilc: Create the new program called secil2tree to write out CIL AST

 libsepol/cil/include/cil/cil.h   |    3 +
 libsepol/cil/src/cil.c           |   92 ++
 libsepol/cil/src/cil_tree.c      | 1471 ----------------------------
 libsepol/cil/src/cil_tree.h      |    2 -
 libsepol/cil/src/cil_write_ast.c | 1573 ++++++++++++++++++++++++++++++
 libsepol/cil/src/cil_write_ast.h |   46 +
 libsepol/src/libsepol.map.in     |    3 +
 secilc/.gitignore                |    2 +
 secilc/Makefile                  |   20 +-
 secilc/secil2tree.8.xml          |   81 ++
 secilc/secil2tree.c              |  206 ++++
 11 files changed, 2024 insertions(+), 1475 deletions(-)
 create mode 100644 libsepol/cil/src/cil_write_ast.c
 create mode 100644 libsepol/cil/src/cil_write_ast.h
 create mode 100644 secilc/secil2tree.8.xml
 create mode 100644 secilc/secil2tree.c
Signature · 1 line
2.26.3
#1 lore raw

PATCH v3 1/3 libsepol/cil: Create functions to write the CIL AST

The function cil_print_tree() has existed in cil_tree.c since the beginning of the development of CIL and secilc. Unfortunately, it used cil_log() at log level CIL_INFO to print out the AST and has suffered greatly from bit rot.

Move the functions to write the CIL AST to cil_write_ast.c, update the functions, and write the AST to the FILE pointer passed in as an argument.

The function cil_write_ast() supports writing the CIL AST at three different phases of the compiling a CIL policy. After parsing has been done and the parse tree has been created, after the CIL AST has been built, and after the CIL AST has been resolved.

---
 libsepol/cil/src/cil_tree.c      | 1471 ----------------------------
 libsepol/cil/src/cil_tree.h      |    2 -
 libsepol/cil/src/cil_write_ast.c | 1573 ++++++++++++++++++++++++++++++
 libsepol/cil/src/cil_write_ast.h |   46 +
 4 files changed, 1619 insertions(+), 1473 deletions(-)
 create mode 100644 libsepol/cil/src/cil_write_ast.c
 create mode 100644 libsepol/cil/src/cil_write_ast.h
libsepol/cil/src/cil_tree.c +0 -1471
index 3da972e9..067268eb 100644
@@ -41,15 +41,6 @@
 #include "cil_parser.h"
 #include "cil_strpool.h"
 
-void cil_tree_print_perms_list(struct cil_tree_node *current_perm);
-void cil_tree_print_classperms(struct cil_classperms *cp);
-void cil_tree_print_level(struct cil_level *level);
-void cil_tree_print_levelrange(struct cil_levelrange *lvlrange);
-void cil_tree_print_context(struct cil_context *context);
-void cil_tree_print_expr_tree(struct cil_tree_node *expr_root);
-void cil_tree_print_constrain(struct cil_constrain *cons);
-void cil_tree_print_node(struct cil_tree_node *node);
-
 __attribute__((noreturn)) __attribute__((format (printf, 1, 2))) void cil_tree_error(const char* msg, ...)
 {
 	va_list ap;
@@ -328,1465 +319,3 @@ int cil_tree_walk(struct cil_tree_node *node,
 
 	return SEPOL_OK;
 }
-
-
-/* Copied from cil_policy.c, but changed to prefix -- Need to refactor */
-static int cil_expr_to_string(struct cil_list *expr, char **out)
-{
-	int rc = SEPOL_ERR;
-	struct cil_list_item *curr;
-	char *stack[COND_EXPR_MAXDEPTH] = {};
-	int pos = 0;
-
-	cil_list_for_each(curr, expr) {
-		if (pos >= COND_EXPR_MAXDEPTH) {
-			rc = SEPOL_ERR;
-			goto exit;
-		}
-		switch (curr->flavor) {
-		case CIL_LIST:
-			rc = cil_expr_to_string(curr->data, &stack[pos]);
-			if (rc != SEPOL_OK) {
-				goto exit;
-			}
-			pos++;
-			break;
-		case CIL_STRING:
-			stack[pos] = curr->data;
-			pos++;
-			break;
-		case CIL_DATUM:
-			stack[pos] = ((struct cil_symtab_datum *)curr->data)->name;
-			pos++;
-			break;
-		case CIL_OP: {
-			int len;
-			char *expr_str;
-			enum cil_flavor op_flavor = *((enum cil_flavor *)curr->data);
-			char *op_str = NULL;
-
-			if (pos == 0) {
-				rc = SEPOL_ERR;
-				goto exit;
-			}
-			switch (op_flavor) {
-			case CIL_AND:
-				op_str = CIL_KEY_AND;
-				break;
-			case CIL_OR:
-				op_str = CIL_KEY_OR;
-				break;
-			case CIL_NOT:
-				op_str = CIL_KEY_NOT;
-				break;
-			case CIL_ALL:
-				op_str = CIL_KEY_ALL;
-				break;
-			case CIL_EQ:
-				op_str = CIL_KEY_EQ;
-				break;
-			case CIL_NEQ:
-				op_str = CIL_KEY_NEQ;
-				break;
-			case CIL_XOR:
-				op_str = CIL_KEY_XOR;
-				break;
-			case CIL_RANGE:
-				op_str = CIL_KEY_RANGE;
-				break;
-			case CIL_CONS_DOM:
-				op_str = CIL_KEY_CONS_DOM;
-				break;
-			case CIL_CONS_DOMBY:
-				op_str = CIL_KEY_CONS_DOMBY;
-				break;
-			case CIL_CONS_INCOMP:
-				op_str = CIL_KEY_CONS_INCOMP;
-				break;
-			default:
-				cil_log(CIL_ERR, "Unknown operator in expression\n");
-				goto exit;
-				break;
-			}
-			if (op_flavor == CIL_NOT) {
-				len = strlen(stack[pos-1]) + strlen(op_str) + 4;
-				expr_str = cil_malloc(len);
-				snprintf(expr_str, len, "(%s %s)", op_str, stack[pos-1]);
-				free(stack[pos-1]);
-				stack[pos-1] = NULL;
-				pos--;
-			} else {
-				if (pos < 2) {
-					rc = SEPOL_ERR;
-					goto exit;
-				}
-				len = strlen(stack[pos-1]) + strlen(stack[pos-2]) + strlen(op_str) + 5;
-				expr_str = cil_malloc(len);
-				snprintf(expr_str, len, "(%s %s %s)", op_str, stack[pos-1], stack[pos-2]);
-				free(stack[pos-2]);
-				free(stack[pos-1]);
-				stack[pos-2] = NULL;
-				stack[pos-1] = NULL;
-				pos -= 2;
-			}
-			stack[pos] = expr_str;
-			pos++;
-			break;
-		}
-		case CIL_CONS_OPERAND: {
-			enum cil_flavor operand_flavor = *((enum cil_flavor *)curr->data);
-			char *operand_str = NULL;
-			switch (operand_flavor) {
-			case CIL_CONS_U1:
-				operand_str = CIL_KEY_CONS_U1;
-				break;
-			case CIL_CONS_U2:
-				operand_str = CIL_KEY_CONS_U2;
-				break;
-			case CIL_CONS_U3:
-				operand_str = CIL_KEY_CONS_U3;
-				break;
-			case CIL_CONS_T1:
-				operand_str = CIL_KEY_CONS_T1;
-				break;
-			case CIL_CONS_T2:
-				operand_str = CIL_KEY_CONS_T2;
-				break;
-			case CIL_CONS_T3:
-				operand_str = CIL_KEY_CONS_T3;
-				break;
-			case CIL_CONS_R1:
-				operand_str = CIL_KEY_CONS_R1;
-				break;
-			case CIL_CONS_R2:
-				operand_str = CIL_KEY_CONS_R2;
-				break;
-			case CIL_CONS_R3:
-				operand_str = CIL_KEY_CONS_R3;
-				break;
-			case CIL_CONS_L1:
-				operand_str = CIL_KEY_CONS_L1;
-				break;
-			case CIL_CONS_L2:
-				operand_str = CIL_KEY_CONS_L2;
-				break;
-			case CIL_CONS_H1:
-				operand_str = CIL_KEY_CONS_H1;
-				break;
-			case CIL_CONS_H2:
-				operand_str = CIL_KEY_CONS_H2;
-				break;
-			default:
-				cil_log(CIL_ERR, "Unknown operand in expression\n");
-				goto exit;
-				break;
-			}
-			stack[pos] = operand_str;
-			pos++;
-			break;
-		}
-		default:
-			cil_log(CIL_ERR, "Unknown flavor in expression\n");
-			goto exit;
-			break;
-		}
-	}
-
-	*out = stack[0];
-
-	return SEPOL_OK;
-
-exit:
-	return rc;
-}
-
-void cil_tree_print_expr(struct cil_list *datum_expr, struct cil_list *str_expr)
-{
-	char *expr_str;
-	int rc;
-
-	cil_log(CIL_INFO, "(");
-
-	if (datum_expr != NULL) {
-		rc = cil_expr_to_string(datum_expr, &expr_str);
-	} else {
-		rc = cil_expr_to_string(str_expr, &expr_str);
-	}
-	if (rc != SEPOL_OK) {
-		cil_log(CIL_INFO, "ERROR)");
-		return;
-	}
-	cil_log(CIL_INFO, "%s)", expr_str);
-	free(expr_str);
-}
-
-void cil_tree_print_perms_list(struct cil_tree_node *current_perm)
-{
-	while (current_perm != NULL) {
-		if (current_perm->flavor == CIL_PERM) {
-			cil_log(CIL_INFO, " %s", ((struct cil_perm *)current_perm->data)->datum.name);
-		} else if (current_perm->flavor == CIL_MAP_PERM) {
-			cil_log(CIL_INFO, " %s", ((struct cil_perm*)current_perm->data)->datum.name);
-		} else {
-			cil_log(CIL_INFO, "\n\n perms list contained unexpected data type: %d\n", current_perm->flavor);
-			break;
-		}
-		current_perm = current_perm->next;	
-	}
-}
-
-void cil_tree_print_cats(struct cil_cats *cats)
-{
-	cil_tree_print_expr(cats->datum_expr, cats->str_expr);
-}
-
-void cil_tree_print_perm_strs(struct cil_list *perm_strs)
-{
-	struct cil_list_item *curr;
-
-	if (perm_strs == NULL) {
-		return;
-	}
-
-	cil_log(CIL_INFO, " (");
-
-	cil_list_for_each(curr, perm_strs) {
-		cil_log(CIL_INFO, " %s", (char*)curr->data);
-	}
-
-	cil_log(CIL_INFO, " )");
-}
-
-
-void cil_tree_print_classperms(struct cil_classperms *cp)
-{
-	if (cp == NULL) {
-		return;
-	}
-
-	cil_log(CIL_INFO, " class: %s", cp->class_str);
-	cil_log(CIL_INFO, ", perm_strs:");
-	cil_tree_print_perm_strs(cp->perm_strs);
-}
-
-void cil_tree_print_classperms_set(struct cil_classperms_set *cp_set)
-{
-	if (cp_set == NULL) {
-		return;
-	}
-
-	cil_log(CIL_INFO, " %s", cp_set->set_str);
-}
-
-void cil_tree_print_classperms_list(struct cil_list *cp_list)
-{
-	struct cil_list_item *i;
-
-	if (cp_list == NULL) {
-		return;
-	}
-
-	cil_list_for_each(i, cp_list) {
-		if (i->flavor == CIL_CLASSPERMS) {
-			cil_tree_print_classperms(i->data);
-		} else {
-			cil_tree_print_classperms_set(i->data);
-		}
-	}
-}
-
-void cil_tree_print_level(struct cil_level *level)
-{
-	if (level->sens != NULL) {
-		cil_log(CIL_INFO, " %s", level->sens->datum.name);
-	} else if (level->sens_str != NULL) {
-		cil_log(CIL_INFO, " %s", level->sens_str);
-	}
-
-	cil_tree_print_cats(level->cats);
-
-	return;
-}
-
-void cil_tree_print_levelrange(struct cil_levelrange *lvlrange)
-{
-	cil_log(CIL_INFO, " (");
-	if (lvlrange->low != NULL) {
-		cil_log(CIL_INFO, " (");
-		cil_tree_print_level(lvlrange->low);
-		cil_log(CIL_INFO, " )");
-	} else if (lvlrange->low_str != NULL) {
-		cil_log(CIL_INFO, " %s", lvlrange->low_str);
-	}
-
-	if (lvlrange->high != NULL) {
-		cil_log(CIL_INFO, " (");
-		cil_tree_print_level(lvlrange->high);
-		cil_log(CIL_INFO, " )");
-	} else if (lvlrange->high_str != NULL) {
-		cil_log(CIL_INFO, " %s", lvlrange->high_str);
-	}
-	cil_log(CIL_INFO, " )");
-}
-
-void cil_tree_print_context(struct cil_context *context)
-{
-	cil_log(CIL_INFO, " (");
-	if (context->user != NULL) {
-		cil_log(CIL_INFO, " %s", context->user->datum.name);
-	} else if (context->user_str != NULL) {
-		cil_log(CIL_INFO, " %s", context->user_str);
-	}
-
-	if (context->role != NULL) {
-		cil_log(CIL_INFO, " %s", context->role->datum.name);
-	} else if (context->role_str != NULL) {
-		cil_log(CIL_INFO, " %s", context->role_str);
-	}
-
-	if (context->type != NULL) {
-		cil_log(CIL_INFO, " %s", ((struct cil_symtab_datum *)context->type)->name);
-	} else if (context->type_str != NULL) {
-		cil_log(CIL_INFO, " %s", context->type_str);
-	}
-
-	if (context->range != NULL) {
-		cil_tree_print_levelrange(context->range);
-	} else if (context->range_str != NULL) {
-		cil_log(CIL_INFO, " %s", context->range_str);
-	}
-
-	cil_log(CIL_INFO, " )");
-
-	return;
-}
-
-void cil_tree_print_constrain(struct cil_constrain *cons)
-{
-	cil_tree_print_classperms_list(cons->classperms);
-
-	cil_tree_print_expr(cons->datum_expr, cons->str_expr);
-
-	cil_log(CIL_INFO, "\n");
-}
-
-void cil_tree_print_node(struct cil_tree_node *node)
-{
-	if (node->data == NULL) {
-		cil_log(CIL_INFO, "FLAVOR: %d", node->flavor);
-		return;
-	} else {
-		switch( node->flavor ) {
-		case CIL_BLOCK: {
-			struct cil_block *block = node->data;
-			cil_log(CIL_INFO, "BLOCK: %s\n", block->datum.name);
-			return;
-		}
-		case CIL_BLOCKINHERIT: {
-			struct cil_blockinherit *inherit = node->data;
-			cil_log(CIL_INFO, "BLOCKINHERIT: %s\n", inherit->block_str);
-			return;
-		}
-		case CIL_BLOCKABSTRACT: {
-			struct cil_blockabstract *abstract = node->data;
-			cil_log(CIL_INFO, "BLOCKABSTRACT: %s\n", abstract->block_str);
-			return;
-		}
-		case CIL_IN: {
-			struct cil_in *in = node->data;
-			cil_log(CIL_INFO, "IN: %s\n", in->block_str);
-			return;
-		}
-		case CIL_USER: {
-			struct cil_user *user = node->data;
-			cil_log(CIL_INFO, "USER: %s\n", user->datum.name);
-			return;
-		}
-		case CIL_TYPE: {
-			struct cil_type *type = node->data;
-			cil_log(CIL_INFO, "TYPE: %s\n", type->datum.name);
-			return;
-		}
-		case CIL_EXPANDTYPEATTRIBUTE: {
-			struct cil_expandtypeattribute *attr = node->data;
-
-			cil_log(CIL_INFO, "(EXPANDTYPEATTRIBUTE ");
-			cil_tree_print_expr(attr->attr_datums, attr->attr_strs);
-			cil_log(CIL_INFO, "%s)\n",attr->expand ?
-					CIL_KEY_CONDTRUE : CIL_KEY_CONDFALSE);
-
-			return;
-		}
-		case CIL_TYPEATTRIBUTESET: {
-			struct cil_typeattributeset *attr = node->data;
-
-			cil_log(CIL_INFO, "(TYPEATTRIBUTESET %s ", attr->attr_str);
-
-			cil_tree_print_expr(attr->datum_expr, attr->str_expr);
-
-			cil_log(CIL_INFO, "\n");
-			return;
-		}
-		case CIL_TYPEATTRIBUTE: {
-			struct cil_typeattribute *attr = node->data;
-			cil_log(CIL_INFO, "TYPEATTRIBUTE: %s\n", attr->datum.name);
-			return;
-		}
-		case CIL_ROLE: {
-			struct cil_role *role = node->data;
-			cil_log(CIL_INFO, "ROLE: %s\n", role->datum.name);
-			return;
-		}
-		case CIL_USERROLE: {
-			struct cil_userrole *userrole = node->data;
-			cil_log(CIL_INFO, "USERROLE:");
-			struct cil_symtab_datum *datum = NULL;
-
-			if (userrole->user != NULL) {
-				datum = userrole->user;
-				cil_log(CIL_INFO, " %s", datum->name);
-			} else if (userrole->user_str != NULL) {
-				cil_log(CIL_INFO, " %s", userrole->user_str);
-			}
-
-			if (userrole->role != NULL) {
-				datum = userrole->role;
-				cil_log(CIL_INFO, " %s", datum->name);
-			} else if (userrole->role_str != NULL) {
-				cil_log(CIL_INFO, " %s", userrole->role_str);
-			}
-
-			cil_log(CIL_INFO, "\n");
-			return;
-		}
-		case CIL_USERLEVEL: {
-			struct cil_userlevel *usrlvl = node->data;
-			cil_log(CIL_INFO, "USERLEVEL:");
-
-			if (usrlvl->user_str != NULL) {
-				cil_log(CIL_INFO, " %s", usrlvl->user_str);
-			}
-
-			if (usrlvl->level != NULL) {
-				cil_log(CIL_INFO, " (");
-				cil_tree_print_level(usrlvl->level);
-				cil_log(CIL_INFO, " )");
-			} else if (usrlvl->level_str != NULL) {
-				cil_log(CIL_INFO, " %s", usrlvl->level_str);
-			}
-
-			cil_log(CIL_INFO, "\n");
-			return;
-		}
-		case CIL_USERRANGE: {
-			struct cil_userrange *userrange = node->data;
-			cil_log(CIL_INFO, "USERRANGE:");
-
-			if (userrange->user_str != NULL) {
-				cil_log(CIL_INFO, " %s", userrange->user_str);
-			}
-
-			if (userrange->range != NULL) {
-				cil_log(CIL_INFO, " (");
-				cil_tree_print_levelrange(userrange->range);
-				cil_log(CIL_INFO, " )");
-			} else if (userrange->range_str != NULL) {
-				cil_log(CIL_INFO, " %s", userrange->range_str);
-			}
-
-			cil_log(CIL_INFO, "\n");
-			return;
-		}
-		case CIL_USERBOUNDS: {
-			struct cil_bounds *bnds = node->data;
-			cil_log(CIL_INFO, "USERBOUNDS: user: %s, bounds: %s\n", bnds->parent_str, bnds->child_str);
-			return;
-		}
-		case CIL_ROLETYPE: {
-			struct cil_roletype *roletype = node->data;
-			struct cil_symtab_datum *datum = NULL;
-			cil_log(CIL_INFO, "ROLETYPE:");
-
-			if (roletype->role != NULL) {
-				datum = roletype->role;
-				cil_log(CIL_INFO, " %s", datum->name);
-			} else if (roletype->role_str != NULL) {
-				cil_log(CIL_INFO, " %s", roletype->role_str);
-			}
-
-			if (roletype->type != NULL) {
-				datum = roletype->type;
-				cil_log(CIL_INFO, " %s", datum->name);
-			} else if (roletype->type_str != NULL) {
-				cil_log(CIL_INFO, " %s", roletype->type_str);
-			}
-
-			cil_log(CIL_INFO, "\n");
-			return;
-		}
-		case CIL_ROLETRANSITION: {
-			struct cil_roletransition *roletrans = node->data;
-			cil_log(CIL_INFO, "ROLETRANSITION:");
-
-			if (roletrans->src != NULL) {
-				cil_log(CIL_INFO, " %s", roletrans->src->datum.name);
-			} else {
-				cil_log(CIL_INFO, " %s", roletrans->src_str);
-			}
-
-			if (roletrans->tgt != NULL) {
-				cil_log(CIL_INFO, " %s", ((struct cil_symtab_datum *)roletrans->tgt)->name);
-			} else {
-				cil_log(CIL_INFO, " %s", roletrans->tgt_str);
-			}
-				
-			if (roletrans->obj != NULL) {
-				cil_log(CIL_INFO, " %s", roletrans->obj->datum.name);
-			} else {
-				cil_log(CIL_INFO, " %s", roletrans->obj_str);
-			}
-
-			if (roletrans->result != NULL) {
-				cil_log(CIL_INFO, " %s\n", roletrans->result->datum.name);
-			} else {
-				cil_log(CIL_INFO, " %s\n", roletrans->result_str);
-			}
-
-			return;
-		}
-		case CIL_ROLEALLOW: {
-			struct cil_roleallow *roleallow = node->data;
-			cil_log(CIL_INFO, "ROLEALLOW:");
-
-			if (roleallow->src != NULL) {
-				cil_log(CIL_INFO, " %s", ((struct cil_symtab_datum*)roleallow->src)->name);
-			} else {
-				cil_log(CIL_INFO, " %s", roleallow->src_str);
-			}
-
-			if (roleallow->tgt != NULL) {
-				cil_log(CIL_INFO, " %s", ((struct cil_symtab_datum*)roleallow->tgt)->name);
-			} else {
-				cil_log(CIL_INFO, " %s", roleallow->tgt_str);
-			}
-
-			cil_log(CIL_INFO, "\n");
-			return;
-		}
-		case CIL_ROLEATTRIBUTESET: {
-			struct cil_roleattributeset *attr = node->data;
-
-			cil_log(CIL_INFO, "(ROLEATTRIBUTESET %s ", attr->attr_str);
-
-			cil_tree_print_expr(attr->datum_expr, attr->str_expr);
-
-			cil_log(CIL_INFO, "\n");
-			return;
-		}
-		case CIL_ROLEATTRIBUTE: {
-			struct cil_roleattribute *attr = node->data;
-			cil_log(CIL_INFO, "ROLEATTRIBUTE: %s\n", attr->datum.name);
-			return;
-		}
-		case CIL_USERATTRIBUTESET: {
-			struct cil_userattributeset *attr = node->data;
-
-			cil_log(CIL_INFO, "(USERATTRIBUTESET %s ", attr->attr_str);
-
-			cil_tree_print_expr(attr->datum_expr, attr->str_expr);
-
-			cil_log(CIL_INFO, "\n");
-			return;
-		}
-		case CIL_USERATTRIBUTE: {
-			struct cil_userattribute *attr = node->data;
-			cil_log(CIL_INFO, "USERATTRIBUTE: %s\n", attr->datum.name);
-			return;
-		}
-		case CIL_ROLEBOUNDS: {
-			struct cil_bounds *bnds = node->data;
-			cil_log(CIL_INFO, "ROLEBOUNDS: role: %s, bounds: %s\n", bnds->parent_str, bnds->child_str);
-			return;
-		}
-		case CIL_CLASS: {
-			struct cil_class *cls = node->data;
-			cil_log(CIL_INFO, "CLASS: %s ", cls->datum.name);
-				
-			if (cls->common != NULL) {
-				cil_log(CIL_INFO, "inherits: %s ", cls->common->datum.name);
-			}
-			cil_log(CIL_INFO, "(");
-	
-			cil_tree_print_perms_list(node->cl_head);
-	
-			cil_log(CIL_INFO, " )");
-			return;
-		}
-		case CIL_CLASSORDER: {
-			struct cil_classorder *classorder = node->data;
-			struct cil_list_item *class;
-
-			if (classorder->class_list_str == NULL) {
-				cil_log(CIL_INFO, "CLASSORDER: ()\n");
-				return;
-			}
-
-			cil_log(CIL_INFO, "CLASSORDER: (");
-			cil_list_for_each(class, classorder->class_list_str) {
-				cil_log(CIL_INFO, " %s", (char*)class->data);
-			}
-			cil_log(CIL_INFO, " )\n");
-			return;
-		}
-		case CIL_COMMON: {
-			struct cil_class *common = node->data;
-			cil_log(CIL_INFO, "COMMON: %s (", common->datum.name);
-		
-			cil_tree_print_perms_list(node->cl_head);
-	
-			cil_log(CIL_INFO, " )");
-			return;
-		}
-		case CIL_CLASSCOMMON: {
-			struct cil_classcommon *clscom = node->data;
-
-			cil_log(CIL_INFO, "CLASSCOMMON: class: %s, common: %s\n", clscom->class_str, clscom->common_str);
-
-			return;
-		}
-		case CIL_CLASSPERMISSION: {
-			struct cil_classpermission *cp = node->data;
-
-			cil_log(CIL_INFO, "CLASSPERMISSION: %s", cp->datum.name);
-
-			cil_log(CIL_INFO, "\n");
-
-			return;
-		}
-		case CIL_CLASSPERMISSIONSET: {
-			struct cil_classpermissionset *cps = node->data;
-
-			cil_log(CIL_INFO, "CLASSPERMISSIONSET: %s", cps->set_str);
-
-			cil_tree_print_classperms_list(cps->classperms);
-
-			cil_log(CIL_INFO, "\n");
-
-			return;
-		}
-		case CIL_MAP_CLASS: {
-			struct cil_class *cm = node->data;
-			cil_log(CIL_INFO, "MAP_CLASS: %s", cm->datum.name);
-
-			cil_log(CIL_INFO, " (");
-			cil_tree_print_perms_list(node->cl_head);
-			cil_log(CIL_INFO, " )\n");
-
-			return;
-		}
-		case CIL_MAP_PERM: {
-			struct cil_perm *cmp = node->data;
-
-			cil_log(CIL_INFO, "MAP_PERM: %s", cmp->datum.name);
-
-			if (cmp->classperms == NULL) {
-				cil_log(CIL_INFO, " perms: ()");
-				return;
-			}
-
-			cil_log(CIL_INFO, " kernel class perms: (");
-
-			cil_tree_print_classperms_list(cmp->classperms);
-
-			cil_log(CIL_INFO, " )\n");
-
-			return;
-		}
-		case CIL_CLASSMAPPING: {
-			struct cil_classmapping *mapping = node->data;
-
-			cil_log(CIL_INFO, "CLASSMAPPING: map class: %s, map perm: %s,", mapping->map_class_str, mapping->map_perm_str);
-
-			cil_log(CIL_INFO, " (");
-
-			cil_tree_print_classperms_list(mapping->classperms);
-
-			cil_log(CIL_INFO, " )\n");
-			return;
-		}
-		case CIL_BOOL: {
-			struct cil_bool *boolean = node->data;
-			cil_log(CIL_INFO, "BOOL: %s, value: %d\n", boolean->datum.name, boolean->value);
-			return;
-		}
-		case CIL_TUNABLE: {
-			struct cil_tunable *tunable = node->data;
-			cil_log(CIL_INFO, "TUNABLE: %s, value: %d\n", tunable->datum.name, tunable->value);
-			return;
-		}
-		case CIL_BOOLEANIF: {
-			struct cil_booleanif *bif = node->data;
-
-			cil_log(CIL_INFO, "(BOOLEANIF ");
-
-			cil_tree_print_expr(bif->datum_expr, bif->str_expr);
-
-			cil_log(CIL_INFO, " )\n");
-			return;
-		}
-		case CIL_TUNABLEIF: {
-			struct cil_tunableif *tif = node->data;
-
-			cil_log(CIL_INFO, "(TUNABLEIF ");
-
-			cil_tree_print_expr(tif->datum_expr, tif->str_expr);
-
-			cil_log(CIL_INFO, " )\n");
-			return;
-		}
-		case CIL_CONDBLOCK: {
-			struct cil_condblock *cb = node->data;
-			if (cb->flavor == CIL_CONDTRUE) {
-				cil_log(CIL_INFO, "true\n");
-			} else if (cb->flavor == CIL_CONDFALSE) {
-				cil_log(CIL_INFO, "false\n");
-			}
-			return;
-		}
-		case CIL_ALL:
-			cil_log(CIL_INFO, "all");
-			return;
-		case CIL_AND:
-			cil_log(CIL_INFO, "&&");
-			return;
-		case CIL_OR:
-			cil_log(CIL_INFO, "|| ");
-			return;
-		case CIL_NOT:
-			cil_log(CIL_INFO, "!");
-			return;
-		case CIL_EQ:
-			cil_log(CIL_INFO, "==");
-			return;
-		case CIL_NEQ:
-			cil_log(CIL_INFO, "!=");
-			return;
-		case CIL_TYPEALIAS: {
-			struct cil_alias *alias = node->data;
-			cil_log(CIL_INFO, "TYPEALIAS: %s\n", alias->datum.name);
-			return;
-		}
-		case CIL_TYPEALIASACTUAL: {
-			struct cil_aliasactual *aliasactual = node->data;
-			cil_log(CIL_INFO, "TYPEALIASACTUAL: type: %s, alias: %s\n", aliasactual->alias_str, aliasactual->actual_str);
-			return;
-		}
-		case CIL_TYPEBOUNDS: {
-			struct cil_bounds *bnds = node->data;
-			cil_log(CIL_INFO, "TYPEBOUNDS: type: %s, bounds: %s\n", bnds->parent_str, bnds->child_str);
-			return;
-		}
-		case CIL_TYPEPERMISSIVE: {
-			struct cil_typepermissive *typeperm = node->data;
-
-			if (typeperm->type != NULL) {
-				cil_log(CIL_INFO, "TYPEPERMISSIVE: %s\n", ((struct cil_symtab_datum *)typeperm->type)->name);
-			} else {
-				cil_log(CIL_INFO, "TYPEPERMISSIVE: %s\n", typeperm->type_str);
-			}
-
-			return;
-		}
-		case CIL_NAMETYPETRANSITION: {
-			struct cil_nametypetransition *nametypetrans = node->data;
-			cil_log(CIL_INFO, "TYPETRANSITION:");
-
-			if (nametypetrans->src != NULL) {
-				cil_log(CIL_INFO, " %s", ((struct cil_symtab_datum *)nametypetrans->src)->name);
-			} else {
-				cil_log(CIL_INFO, " %s", nametypetrans->src_str);
-			}
-
-			if (nametypetrans->tgt != NULL) {
-				cil_log(CIL_INFO, " %s", ((struct cil_symtab_datum *)nametypetrans->tgt)->name);
-			} else {
-				cil_log(CIL_INFO, " %s", nametypetrans->tgt_str);
-			}
-
-			if (nametypetrans->obj != NULL) {
-				cil_log(CIL_INFO, " %s", nametypetrans->obj->datum.name);
-			} else {
-				cil_log(CIL_INFO, " %s", nametypetrans->obj_str);
-			}
-
-			cil_log(CIL_INFO, " %s\n", nametypetrans->name_str);
-
-			if (nametypetrans->result != NULL) {
-				cil_log(CIL_INFO, " %s", ((struct cil_symtab_datum *)nametypetrans->result)->name);
-			} else {
-				cil_log(CIL_INFO, " %s", nametypetrans->result_str);
-			}
-
-			return;
-		}
-		case CIL_RANGETRANSITION: {
-			struct cil_rangetransition *rangetrans = node->data;
-			cil_log(CIL_INFO, "RANGETRANSITION:");
-
-			if (rangetrans->src != NULL) {
-				cil_log(CIL_INFO, " %s", ((struct cil_symtab_datum *)rangetrans->src)->name);
-			} else {
-				cil_log(CIL_INFO, " %s", rangetrans->src_str);
-			}
-
-			if (rangetrans->exec != NULL) {
-				cil_log(CIL_INFO, " %s", ((struct cil_symtab_datum *)rangetrans->exec)->name);
-			} else {
-				cil_log(CIL_INFO, " %s", rangetrans->exec_str);
-			}
-
-			if (rangetrans->obj != NULL) {
-				cil_log(CIL_INFO, " %s", rangetrans->obj->datum.name);
-			} else {
-				cil_log(CIL_INFO, " %s", rangetrans->obj_str);
-			}
-
-			if (rangetrans->range != NULL) {
-				cil_log(CIL_INFO, " (");
-				cil_tree_print_levelrange(rangetrans->range);
-				cil_log(CIL_INFO, " )");
-			} else {
-				cil_log(CIL_INFO, " %s", rangetrans->range_str);
-			}
-
-			cil_log(CIL_INFO, "\n");
-			return;
-		}
-		case CIL_AVRULE: {
-			struct cil_avrule *rule = node->data;
-			switch (rule->rule_kind) {
-			case CIL_AVRULE_ALLOWED:
-				cil_log(CIL_INFO, "ALLOW:");
-				break;
-			case CIL_AVRULE_AUDITALLOW:
-				cil_log(CIL_INFO, "AUDITALLOW:");
-				break;
-			case CIL_AVRULE_DONTAUDIT:
-				cil_log(CIL_INFO, "DONTAUDIT:");
-				break;
-			case CIL_AVRULE_NEVERALLOW:
-				cil_log(CIL_INFO, "NEVERALLOW:");
-				break;
-			}
-
-			if (rule->src != NULL) {
-				cil_log(CIL_INFO, " %s", ((struct cil_symtab_datum*)rule->src)->name);
-			} else {
-				cil_log(CIL_INFO, " %s", rule->src_str);
-			}
-
-			if (rule->tgt != NULL) {
-				cil_log(CIL_INFO, " %s", ((struct cil_symtab_datum*)rule->tgt)->name);
-			} else {
-				cil_log(CIL_INFO, " %s", rule->tgt_str);
-			}
-
-			cil_tree_print_classperms_list(rule->perms.classperms);
-
-			cil_log(CIL_INFO, "\n");
-
-			return;
-		}
-		case CIL_TYPE_RULE: {
-			struct cil_type_rule *rule = node->data;
-			switch (rule->rule_kind) {
-			case CIL_TYPE_TRANSITION:
-				cil_log(CIL_INFO, "TYPETRANSITION:");
-				break;
-			case CIL_TYPE_MEMBER:
-				cil_log(CIL_INFO, "TYPEMEMBER:");
-				break;
-			case CIL_TYPE_CHANGE:
-				cil_log(CIL_INFO, "TYPECHANGE:");
-				break;
-			}
-
-			if (rule->src != NULL) {
-				cil_log(CIL_INFO, " %s", ((struct cil_symtab_datum *)rule->src)->name);
-			} else {
-				cil_log(CIL_INFO, " %s", rule->src_str);
-			}
-
-			if (rule->tgt != NULL) {
-				cil_log(CIL_INFO, " %s", ((struct cil_symtab_datum *)rule->tgt)->name);
-			} else {
-				cil_log(CIL_INFO, " %s", rule->tgt_str);
-			}
-
-			if (rule->obj != NULL) {
-				cil_log(CIL_INFO, " %s", rule->obj->datum.name);
-			} else {
-				cil_log(CIL_INFO, " %s", rule->obj_str);
-			}
-
-			if (rule->result != NULL) {
-				cil_log(CIL_INFO, " %s\n", ((struct cil_symtab_datum *)rule->result)->name);
-			} else {
-				cil_log(CIL_INFO, " %s\n", rule->result_str);
-			}
-
-			return;
-		}
-		case CIL_SENS: {
-			struct cil_sens *sens = node->data;
-			cil_log(CIL_INFO, "SENSITIVITY: %s\n", sens->datum.name);
-			return;
-		}
-		case CIL_SENSALIAS: {
-			struct cil_alias *alias = node->data;
-			cil_log(CIL_INFO, "SENSITIVITYALIAS: %s\n", alias->datum.name);
-			return;
-		}
-		case CIL_SENSALIASACTUAL: {
-			struct cil_aliasactual *aliasactual = node->data;
-			cil_log(CIL_INFO, "SENSITIVITYALIAS: alias: %s, sensitivity: %s\n", aliasactual->alias_str, aliasactual->actual_str);
-
-			return;
-		}
-		case CIL_CAT: {
-			struct cil_cat *cat = node->data;
-			cil_log(CIL_INFO, "CATEGORY: %s\n", cat->datum.name);
-			return;
-		}
-		case CIL_CATALIAS: {
-			struct cil_alias *alias = node->data;
-			cil_log(CIL_INFO, "CATEGORYALIAS: %s\n", alias->datum.name);
-			return;
-		}
-		case CIL_CATALIASACTUAL: {
-			struct cil_aliasactual *aliasactual = node->data;
-			cil_log(CIL_INFO, "CATEGORYALIAS: alias %s, category: %s\n", aliasactual->alias_str, aliasactual->actual_str);
-			return;
-		}
-		case CIL_CATSET: {
-			struct cil_catset *catset = node->data;
-
-			cil_log(CIL_INFO, "CATSET: %s ",catset->datum.name);
-
-			cil_tree_print_cats(catset->cats);
-
-			return;
-		}
-		case CIL_CATORDER: {
-			struct cil_catorder *catorder = node->data;
-			struct cil_list_item *cat;
-
-			if (catorder->cat_list_str == NULL) {
-				cil_log(CIL_INFO, "CATORDER: ()\n");
-				return;
-			}
-
-			cil_log(CIL_INFO, "CATORDER: (");
-			cil_list_for_each(cat, catorder->cat_list_str) {
-				cil_log(CIL_INFO, " %s", (char*)cat->data);
-			}
-			cil_log(CIL_INFO, " )\n");
-			return;
-		}
-		case CIL_SENSCAT: {
-			struct cil_senscat *senscat = node->data;
-
-			cil_log(CIL_INFO, "SENSCAT: sens:");
-
-			if (senscat->sens_str != NULL) {
-				cil_log(CIL_INFO, " %s ", senscat->sens_str);
-			} else {
-				cil_log(CIL_INFO, " [processed]");
-			}
-
-			cil_tree_print_cats(senscat->cats);
-
-			return;
-		}
-		case CIL_SENSITIVITYORDER: {
-			struct cil_sensorder *sensorder = node->data;
-			struct cil_list_item *sens;
-
-			cil_log(CIL_INFO, "SENSITIVITYORDER: (");
-
-			if (sensorder->sens_list_str != NULL) {
-				cil_list_for_each(sens, sensorder->sens_list_str) {
-					if (sens->flavor == CIL_LIST) {
-						struct cil_list_item *sub;
-						cil_log(CIL_INFO, " (");
-						cil_list_for_each(sub, (struct cil_list*)sens->data) {
-							cil_log(CIL_INFO, " %s", (char*)sub->data);
-						}
-						cil_log(CIL_INFO, " )");
-					} else {
-						cil_log(CIL_INFO, " %s", (char*)sens->data);
-					}
-				}
-			}
-
-			cil_log(CIL_INFO, " )\n");
-			return;
-		}
-		case CIL_LEVEL: {
-			struct cil_level *level = node->data;
-			cil_log(CIL_INFO, "LEVEL %s:", level->datum.name); 
-			cil_tree_print_level(level);
-			cil_log(CIL_INFO, "\n");
-			return;
-		}
-		case CIL_LEVELRANGE: {
-			struct cil_levelrange *lvlrange = node->data;
-			cil_log(CIL_INFO, "LEVELRANGE %s:", lvlrange->datum.name);
-			cil_tree_print_levelrange(lvlrange);
-			cil_log(CIL_INFO, "\n");
-			return;
-		}
-		case CIL_CONSTRAIN: {
-			struct cil_constrain *cons = node->data;
-			cil_log(CIL_INFO, "CONSTRAIN: (");
-			cil_tree_print_constrain(cons);
-			return;
-		}
-		case CIL_MLSCONSTRAIN: {
-			struct cil_constrain *cons = node->data;
-			cil_log(CIL_INFO, "MLSCONSTRAIN: (");
-			cil_tree_print_constrain(cons);
-			return;
-		}
-		case CIL_VALIDATETRANS: {
-			struct cil_validatetrans *vt = node->data;
-
-			cil_log(CIL_INFO, "(VALIDATETRANS ");
-
-			if (vt->class != NULL) {
-				cil_log(CIL_INFO, "%s ", vt->class->datum.name);
-			} else if (vt->class_str != NULL) {
-				cil_log(CIL_INFO, "%s ", vt->class_str);
-			}
-
-			cil_tree_print_expr(vt->datum_expr, vt->str_expr);
-
-			cil_log(CIL_INFO, ")\n");
-			return;
-		}
-		case CIL_MLSVALIDATETRANS: {
-			struct cil_validatetrans *vt = node->data;
-
-			cil_log(CIL_INFO, "(MLSVALIDATETRANS ");
-
-			if (vt->class != NULL) {
-				cil_log(CIL_INFO, "%s ", vt->class->datum.name);
-			} else if (vt->class_str != NULL) {
-				cil_log(CIL_INFO, "%s ", vt->class_str);
-			}
-
-			cil_tree_print_expr(vt->datum_expr, vt->str_expr);
-
-			cil_log(CIL_INFO, ")\n");
-			return;
-		}
-		case CIL_CONTEXT: {
-			struct cil_context *context = node->data;
-			cil_log(CIL_INFO, "CONTEXT %s:", context->datum.name);
-			cil_tree_print_context(context);
-			cil_log(CIL_INFO, "\n");
-			return;
-		}
-		case CIL_FILECON: {
-			struct cil_filecon *filecon = node->data;
-			cil_log(CIL_INFO, "FILECON:");
-			cil_log(CIL_INFO, " %s %d", filecon->path_str, filecon->type);
-
-			if (filecon->context != NULL) {
-				cil_tree_print_context(filecon->context);
-			} else if (filecon->context_str != NULL) {
-				cil_log(CIL_INFO, " %s", filecon->context_str);
-			}
-
-			cil_log(CIL_INFO, "\n");
-			return;
-
-		}
-		case CIL_IBPKEYCON: {
-			struct cil_ibpkeycon *ibpkeycon = node->data;
-
-			cil_log(CIL_INFO, "IBPKEYCON: %s", ibpkeycon->subnet_prefix_str);
-			cil_log(CIL_INFO, " (%d %d) ", ibpkeycon->pkey_low, ibpkeycon->pkey_high);
-
-			if (ibpkeycon->context)
-				cil_tree_print_context(ibpkeycon->context);
-			else if (ibpkeycon->context_str)
-				cil_log(CIL_INFO, " %s", ibpkeycon->context_str);
-
-			cil_log(CIL_INFO, "\n");
-			return;
-		}
-		case CIL_PORTCON: {
-			struct cil_portcon *portcon = node->data;
-			cil_log(CIL_INFO, "PORTCON:");
-			if (portcon->proto == CIL_PROTOCOL_UDP) {
-				cil_log(CIL_INFO, " udp");
-			} else if (portcon->proto == CIL_PROTOCOL_TCP) {
-				cil_log(CIL_INFO, " tcp");
-			} else if (portcon->proto == CIL_PROTOCOL_DCCP) {
-				cil_log(CIL_INFO, " dccp");
-			} else if (portcon->proto == CIL_PROTOCOL_SCTP) {
-				cil_log(CIL_INFO, " sctp");
-			}
-			cil_log(CIL_INFO, " (%d %d)", portcon->port_low, portcon->port_high);
-
-			if (portcon->context != NULL) {
-				cil_tree_print_context(portcon->context);
-			} else if (portcon->context_str != NULL) {
-				cil_log(CIL_INFO, " %s", portcon->context_str);
-			}
-
-			cil_log(CIL_INFO, "\n");
-			return;
-		}
-		case CIL_NODECON: {
-			struct cil_nodecon *nodecon = node->data;
-			char buf[256];
-				
-			cil_log(CIL_INFO, "NODECON:");
-				
-			if (nodecon->addr) {
-				inet_ntop(nodecon->addr->family, &nodecon->addr->ip, buf, 256);
-				cil_log(CIL_INFO, " %s", buf);
-			}  else {
-				cil_log(CIL_INFO, " %s", nodecon->addr_str);
-			}
-
-			if (nodecon->mask) {
-				inet_ntop(nodecon->mask->family, &nodecon->mask->ip, buf, 256);
-				cil_log(CIL_INFO, " %s", buf);
-			} else {
-				cil_log(CIL_INFO, " %s", nodecon->mask_str);
-			}
-				
-			if (nodecon->context != NULL) {
-				cil_tree_print_context(nodecon->context);
-			} else if (nodecon->context_str != NULL) {
-				cil_log(CIL_INFO, " %s", nodecon->context_str);
-			}
-
-			cil_log(CIL_INFO, "\n");
-			return;
-		}
-		case CIL_GENFSCON: {
-			struct cil_genfscon *genfscon = node->data;
-			cil_log(CIL_INFO, "GENFSCON:");
-			cil_log(CIL_INFO, " %s %s", genfscon->fs_str, genfscon->path_str);
-
-			if (genfscon->context != NULL) {
-				cil_tree_print_context(genfscon->context);
-			} else if (genfscon->context_str != NULL) {
-				cil_log(CIL_INFO, " %s", genfscon->context_str);
-			}
-
-			cil_log(CIL_INFO, "\n");
-			return;
-		}
-		case CIL_NETIFCON: {
-			struct cil_netifcon *netifcon = node->data;
-			cil_log(CIL_INFO, "NETIFCON %s", netifcon->interface_str);
-
-			if (netifcon->if_context != NULL) {
-				cil_tree_print_context(netifcon->if_context);
-			} else if (netifcon->if_context_str != NULL) {
-				cil_log(CIL_INFO, " %s", netifcon->if_context_str);
-			}
-
-			if (netifcon->packet_context != NULL) {
-				cil_tree_print_context(netifcon->packet_context);
-			} else if (netifcon->packet_context_str != NULL) {
-				cil_log(CIL_INFO, " %s", netifcon->packet_context_str);
-			}
-
-			cil_log(CIL_INFO, "\n");
-			return;
-		}
-		case CIL_IBENDPORTCON: {
-			struct cil_ibendportcon *ibendportcon = node->data;
-
-			cil_log(CIL_INFO, "IBENDPORTCON: %s %u ", ibendportcon->dev_name_str, ibendportcon->port);
-
-			if (ibendportcon->context)
-				cil_tree_print_context(ibendportcon->context);
-			else if (ibendportcon->context_str)
-				cil_log(CIL_INFO, " %s", ibendportcon->context_str);
-
-			cil_log(CIL_INFO, "\n");
-			return;
-		}
-		case CIL_PIRQCON: {
-			struct cil_pirqcon *pirqcon = node->data;
-
-			cil_log(CIL_INFO, "PIRQCON %d", pirqcon->pirq);
-			if (pirqcon->context != NULL) {
-				cil_tree_print_context(pirqcon->context);
-			} else {
-				cil_log(CIL_INFO, " %s", pirqcon->context_str);
-			}
-
-			cil_log(CIL_INFO, "\n");
-			return;
-		}
-		case CIL_IOMEMCON: {
-			struct cil_iomemcon *iomemcon = node->data;
-
-			cil_log(CIL_INFO, "IOMEMCON ( %"PRId64" %"PRId64" )", iomemcon->iomem_low, iomemcon->iomem_high);
-			if (iomemcon->context != NULL) {
-				cil_tree_print_context(iomemcon->context);
-			} else {
-				cil_log(CIL_INFO, " %s", iomemcon->context_str);
-			}
-
-			cil_log(CIL_INFO, "\n");
-			return;
-		}
-		case CIL_IOPORTCON: {
-			struct cil_ioportcon *ioportcon = node->data;
-
-			cil_log(CIL_INFO, "IOPORTCON ( %d %d )", ioportcon->ioport_low, ioportcon->ioport_high);
-			if (ioportcon->context != NULL) {
-				cil_tree_print_context(ioportcon->context);
-			} else {
-				cil_log(CIL_INFO, " %s", ioportcon->context_str);
-			}
-
-			cil_log(CIL_INFO, "\n");
-			return;
-		}
-		case CIL_PCIDEVICECON: {
-			struct cil_pcidevicecon *pcidevicecon = node->data;
-
-			cil_log(CIL_INFO, "PCIDEVICECON %d", pcidevicecon->dev);
-			if (pcidevicecon->context != NULL) {
-				cil_tree_print_context(pcidevicecon->context);
-			} else {
-				cil_log(CIL_INFO, " %s", pcidevicecon->context_str);
-			}
-
-			cil_log(CIL_INFO, "\n");
-			return;
-		}
-		case CIL_DEVICETREECON: {
-			struct cil_devicetreecon *devicetreecon = node->data;
-
-			cil_log(CIL_INFO, "DEVICETREECON %s", devicetreecon->path);
-			if (devicetreecon->context != NULL) {
-				cil_tree_print_context(devicetreecon->context);
-			} else {
-				cil_log(CIL_INFO, " %s", devicetreecon->context_str);
-			}
-
-			cil_log(CIL_INFO, "\n");
-			return;
-		}
-		case CIL_FSUSE: {
-			struct cil_fsuse *fsuse = node->data;
-			cil_log(CIL_INFO, "FSUSE: ");
-
-			if (fsuse->type == CIL_FSUSE_XATTR) {
-				cil_log(CIL_INFO, "xattr ");
-			} else if (fsuse->type == CIL_FSUSE_TASK) {
-				cil_log(CIL_INFO, "task ");
-			} else if (fsuse->type == CIL_FSUSE_TRANS) {
-				cil_log(CIL_INFO, "trans ");
-			} else {
-				cil_log(CIL_INFO, "unknown ");
-			}
-
-			cil_log(CIL_INFO, "%s ", fsuse->fs_str);
-
-			if (fsuse->context != NULL) {
-				cil_tree_print_context(fsuse->context);
-			} else {
-				cil_log(CIL_INFO, " %s", fsuse->context_str);
-			}
-
-			cil_log(CIL_INFO, "\n");
-			return;
-		}
-		case CIL_SID: {
-			struct cil_sid *sid = node->data;
-			cil_log(CIL_INFO, "SID: %s\n", sid->datum.name);
-			return;
-		}
-		case CIL_SIDCONTEXT: {
-			struct cil_sidcontext *sidcon = node->data;
-			cil_log(CIL_INFO, "SIDCONTEXT: %s", sidcon->sid_str);
-
-			if (sidcon->context != NULL) {
-				cil_tree_print_context(sidcon->context);
-			} else {
-				cil_log(CIL_INFO, " %s", sidcon->context_str);
-			}
-
-			cil_log(CIL_INFO, "\n");
-			return;
-		}
-		case CIL_SIDORDER: {
-			struct cil_sidorder *sidorder = node->data;
-			struct cil_list_item *sid;
-
-			if (sidorder->sid_list_str == NULL) {
-				cil_log(CIL_INFO, "SIDORDER: ()\n");
-				return;
-			}
-
-			cil_log(CIL_INFO, "SIDORDER: (");
-			cil_list_for_each(sid, sidorder->sid_list_str) {
-				cil_log(CIL_INFO, " %s", (char*)sid->data);
-			}
-			cil_log(CIL_INFO, " )\n");
-			return;
-		}
-		case CIL_POLICYCAP: {
-			struct cil_policycap *polcap = node->data;
-			cil_log(CIL_INFO, "POLICYCAP: %s\n", polcap->datum.name);
-			return;
-		}
-		case CIL_MACRO: {
-			struct cil_macro *macro = node->data;
-			cil_log(CIL_INFO, "MACRO %s:", macro->datum.name);
-
-			if (macro->params != NULL && macro->params->head != NULL) {
-				struct cil_list_item *curr_param;
-				cil_log(CIL_INFO, " parameters: (");
-				cil_list_for_each(curr_param, macro->params) {
-					cil_log(CIL_INFO, " flavor: %d, string: %s;", ((struct cil_param*)curr_param->data)->flavor, ((struct cil_param*)curr_param->data)->str);
-
-				}
-				cil_log(CIL_INFO, " )");
-			}
-			cil_log(CIL_INFO, "\n");
-
-			return;
-		}
-		case CIL_CALL: {
-			struct cil_call *call = node->data;
-			cil_log(CIL_INFO, "CALL: macro name:");
-
-			if (call->macro != NULL) {
-				cil_log(CIL_INFO, " %s", call->macro->datum.name);
-			} else {
-				cil_log(CIL_INFO, " %s", call->macro_str);
-			}
-
-			if (call->args != NULL) {
-				cil_log(CIL_INFO, ", args: ( ");
-				struct cil_list_item *item;
-				cil_list_for_each(item, call->args) {
-					struct cil_symtab_datum *datum = ((struct cil_args*)item->data)->arg;
-					if (datum != NULL) {
-						if (datum->nodes != NULL && datum->nodes->head != NULL) {
-							cil_tree_print_node(NODE(datum));
-						}
-					} else if (((struct cil_args*)item->data)->arg_str != NULL) {
-						switch (item->flavor) {
-						case CIL_TYPE: cil_log(CIL_INFO, "type:"); break;
-						case CIL_USER: cil_log(CIL_INFO, "user:"); break;
-						case CIL_ROLE: cil_log(CIL_INFO, "role:"); break;
-						case CIL_SENS: cil_log(CIL_INFO, "sensitivity:"); break;
-						case CIL_CAT: cil_log(CIL_INFO, "category:"); break;
-						case CIL_CATSET: cil_log(CIL_INFO, "categoryset:"); break;
-						case CIL_LEVEL: cil_log(CIL_INFO, "level:"); break;
-						case CIL_CLASS: cil_log(CIL_INFO, "class:"); break;
-						default: break;
-						}
-						cil_log(CIL_INFO, "%s ", ((struct cil_args*)item->data)->arg_str);
-					}
-				}
-				cil_log(CIL_INFO, ")");
-			}
-
-			cil_log(CIL_INFO, "\n");
-			return;
-		}	
-		case CIL_OPTIONAL: {
-			struct cil_optional *optional = node->data;
-			cil_log(CIL_INFO, "OPTIONAL: %s\n", optional->datum.name);
-			return;
-		}
-		case CIL_IPADDR: {
-			struct cil_ipaddr *ipaddr = node->data;
-			char buf[256];
-
-			inet_ntop(ipaddr->family, &ipaddr->ip, buf, 256);
-			cil_log(CIL_INFO, "IPADDR %s: %s\n", ipaddr->datum.name, buf);
-
-			break;
-		}
-		default : {
-			cil_log(CIL_INFO, "CIL FLAVOR: %d\n", node->flavor);
-			return;
-		}
-		}
-	}
-}
-
-void cil_tree_print(struct cil_tree_node *tree, uint32_t depth)
-{
-	struct cil_tree_node *current = NULL;
-	current = tree;
-	uint32_t x = 0;
-
-	if (current != NULL) {
-		if (current->cl_head == NULL) {
-			if (current->flavor == CIL_NODE) {
-				if (current->parent->cl_head == current) {
-					cil_log(CIL_INFO, "%s", (char*)current->data);
-				} else {
-					cil_log(CIL_INFO, " %s", (char*)current->data);
-				}
-			} else if (current->flavor != CIL_PERM) {
-				for (x = 0; x<depth; x++) {
-					cil_log(CIL_INFO, "\t");
-				}
-				cil_tree_print_node(current);
-			}
-		} else {
-			if (current->parent != NULL) {
-				cil_log(CIL_INFO, "\n");
-				for (x = 0; x<depth; x++) {
-					cil_log(CIL_INFO, "\t");
-				}
-				cil_log(CIL_INFO, "(");
-
-				if (current->flavor != CIL_NODE) {
-					cil_tree_print_node(current);
-				}
-			}
-			cil_tree_print(current->cl_head, depth + 1);
-		}
-
-		if (current->next == NULL) {
-			if ((current->parent != NULL) && (current->parent->cl_tail == current) && (current->parent->parent != NULL)) {
-				if (current->flavor == CIL_PERM) {
-					cil_log(CIL_INFO, ")\n");
-				} else if (current->flavor != CIL_NODE) {
-					for (x = 0; x<depth-1; x++) {
-						cil_log(CIL_INFO, "\t");
-					}
-					cil_log(CIL_INFO, ")\n");
-				} else {
-					cil_log(CIL_INFO, ")");
-				}
-			}
-
-			if ((current->parent != NULL) && (current->parent->parent == NULL))
-				cil_log(CIL_INFO, "\n\n");
-		} else {
-			cil_tree_print(current->next, depth);
-		}
-	} else {
-		cil_log(CIL_INFO, "Tree is NULL\n");
-	}
-}
libsepol/cil/src/cil_tree.h +0 -2
index aeded560..bac9f1e4 100644
@@ -62,8 +62,6 @@ void cil_tree_children_destroy(struct cil_tree_node *node);
 void cil_tree_node_init(struct cil_tree_node **node);
 void cil_tree_node_destroy(struct cil_tree_node **node);
 
-void cil_tree_print(struct cil_tree_node *tree, uint32_t depth);
-
 //finished values
 #define CIL_TREE_SKIP_NOTHING	0
 #define CIL_TREE_SKIP_NEXT	1
libsepol/cil/src/cil_write_ast.c new file +1573 -0

1,512 lines not on this page · raw message

libsepol/cil/src/cil_write_ast.h new file +46 -0

46 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.26.3

Part of the diff is not shown here. View the raw message.

#2 lore raw

PATCH v3 2/3 libsepol/cil: Add functions to make use of cil_write_ast()

In reply to James Carter

Add the functions cil_write_parse_ast(), cil_write_build_ast(), and cil_write_resolve_ast() that can be used outside of libsepol.

These functions take a FILE pointer and CIL db, do the CIL build through the desired phase, and then call cil_write_ast() to write the CIL AST at that point.

---
 libsepol/cil/include/cil/cil.h |  3 ++
 libsepol/cil/src/cil.c         | 92 ++++++++++++++++++++++++++++++++++
 libsepol/src/libsepol.map.in   |  3 ++
 3 files changed, 98 insertions(+)
libsepol/cil/include/cil/cil.h +3 -0
index e6f4503e..92fac6e1 100644
@@ -60,6 +60,9 @@ extern void cil_set_attrs_expand_size(struct cil_db *db, unsigned attrs_expand_s
 extern void cil_set_target_platform(cil_db_t *db, int target_platform);
 extern void cil_set_policy_version(cil_db_t *db, int policy_version);
 extern void cil_write_policy_conf(FILE *out, struct cil_db *db);
+extern int cil_write_parse_ast(FILE *out, cil_db_t *db);
+extern int cil_write_build_ast(FILE *out, cil_db_t *db);
+extern int cil_write_resolve_ast(FILE *out, cil_db_t *db);
 
 enum cil_log_level {
 	CIL_ERR = 1,
libsepol/cil/src/cil.c +92 -0

104 lines not on this page · raw message

libsepol/src/libsepol.map.in +3 -0
index eb572125..2e503bd1 100644
@@ -269,4 +269,7 @@ LIBSEPOL_1.1 {
 LIBSEPOL_3.0 {
   global:
 	sepol_policydb_optimize;
+	cil_write_parse_ast;
+	cil_write_build_ast;
+	cil_write_resolve_ast;
 } LIBSEPOL_1.1;
Signature · 1 line
2.26.3
#3 lore raw

PATCH v3 3/3 secilc: Create the new program called secil2tree to write out CIL AST

In reply to James Carter

secil2tree is the SELinux CIL AST writer. It calls the cil functions cil_write_parse_ast(), cil_write_build_ast(), or cil_write_resolve_ast() to write out the parse tree, the CIL AST after the build phase, or the CIL AST after the resolve phase.

---
 secilc/.gitignore       |   2 +
 secilc/Makefile         |  20 +++-
 secilc/secil2tree.8.xml |  81 ++++++++++++++++
 secilc/secil2tree.c     | 206 ++++++++++++++++++++++++++++++++++++++++
 4 files changed, 307 insertions(+), 2 deletions(-)
 create mode 100644 secilc/secil2tree.8.xml
 create mode 100644 secilc/secil2tree.c
secilc/.gitignore +2 -0
index 164523b0..d2a3daf1 100644
@@ -2,6 +2,8 @@ secilc
 secilc.8
 secil2conf
 secil2conf.8
+secil2tree
+secil2tree.8
 policy.*
 file_contexts
 docs/html
secilc/Makefile +18 -2
index d4a1c35a..94be0481 100644
@@ -10,8 +10,13 @@ SECIL2CONF = secil2conf
 SECIL2CONF_SRCS := secil2conf.c
 SECIL2CONF_OBJS := $(patsubst %.c,%.o,$(SECIL2CONF_SRCS))
 
+SECIL2TREE = secil2tree
+SECIL2TREE_SRCS := secil2tree.c
+SECIL2TREE_OBJS := $(patsubst %.c,%.o,$(SECIL2TREE_SRCS))
+
 SECILC_MANPAGE = secilc.8
 SECIL2CONF_MANPAGE = secil2conf.8
+SECIL2TREE_MANPAGE = secil2tree.8
 XMLTO = xmlto
 DIFF = diff
 
@@ -23,7 +28,7 @@ CFLAGS ?= -Wall -Wshadow -Wextra -Wundef -Wmissing-format-attribute -Wcast-align
 override CFLAGS += -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64
 override LDLIBS += -lsepol
 
-all: $(SECILC) $(SECIL2CONF) man
+all: $(SECILC) $(SECIL2CONF) $(SECIL2TREE) man
 
 $(SECILC): $(SECILC_OBJS)
 	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS)
@@ -37,7 +42,10 @@ test: $(SECILC)
 $(SECIL2CONF): $(SECIL2CONF_OBJS)
 	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS)
 
-man: $(SECILC_MANPAGE) $(SECIL2CONF_MANPAGE)
+$(SECIL2TREE): $(SECIL2TREE_OBJS)
+	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS)
+
+man: $(SECILC_MANPAGE) $(SECIL2CONF_MANPAGE) $(SECIL2TREE_MANPAGE)
 
 $(SECILC_MANPAGE): $(SECILC_MANPAGE).xml
 	$(XMLTO) man $(SECILC_MANPAGE).xml
@@ -45,13 +53,18 @@ $(SECILC_MANPAGE): $(SECILC_MANPAGE).xml
 $(SECIL2CONF_MANPAGE): $(SECIL2CONF_MANPAGE).xml
 	$(XMLTO) man $(SECIL2CONF_MANPAGE).xml
 
+$(SECIL2TREE_MANPAGE): $(SECIL2TREE_MANPAGE).xml
+	$(XMLTO) man $(SECIL2TREE_MANPAGE).xml
+
 install: all man
 	-mkdir -p $(DESTDIR)$(BINDIR)
 	-mkdir -p $(DESTDIR)$(MANDIR)/man8
 	install -m 755 $(SECILC) $(DESTDIR)$(BINDIR)
 	install -m 755 $(SECIL2CONF) $(DESTDIR)$(BINDIR)
+	install -m 755 $(SECIL2TREE) $(DESTDIR)$(BINDIR)
 	install -m 644 $(SECILC_MANPAGE) $(DESTDIR)$(MANDIR)/man8
 	install -m 644 $(SECIL2CONF_MANPAGE) $(DESTDIR)$(MANDIR)/man8
+	install -m 644 $(SECIL2TREE_MANPAGE) $(DESTDIR)$(MANDIR)/man8
 
 doc:
 	$(MAKE) -C docs
@@ -61,10 +74,13 @@ clean:
 	rm -f $(SECILC_OBJS)
 	rm -f $(SECIL2CONF)
 	rm -f $(SECIL2CONF_OBJS)
+	rm -f $(SECIL2TREE)
+	rm -f $(SECIL2TREE_OBJS)
 	rm -f policy.*
 	rm -f file_contexts
 	rm -f $(SECILC_MANPAGE)
 	rm -f $(SECIL2CONF_MANPAGE)
+	rm -f $(SECIL2TREE_MANPAGE)
 	rm -f opt-actual.cil
 	rm -f opt-actual.bin
 	$(MAKE) -C docs clean
secilc/secil2tree.8.xml new file +81 -0

81 lines not on this page · raw message

secilc/secil2tree.c new file +206 -0

206 lines not on this page · raw message

Signature · 1 line
2.26.3
Acked-by on the v3 series
#4 lore raw
In reply to James Carter
Quoted 55 lines · James Carter

For debugging purposes it would be useful to be able to write out the CIL AST at various points in the build process.

This patch set creates secil2tree which can write the CIL parse tree, the CIL AST after the build phase, or the CIL AST after the resolve phase (with names fully-qualified).

Within CIL the function cil_print_tree() has existed from early in CIL's development, but it was not exported in libsepol and there was no way to use it except by adding a call to it where you wanted to print out the CIL AST and then recompiling everything. It also used cil_log() as its output, so other messages could be mixed in with the output. This patch set moves all of this code to its own file, updates it, renames it as cil_write_ast(), and adds libsepol functions that can be used to call it after each one of the phases mentioned above.

Both the parse and build CIL AST are valid CIL policies that can be compiled with secilc, but the resolve CIL AST is not always a valid CIL policy. The biggest problem is that fully-qualified names can contain dots and CIL does not allow dots in declaration names. There are other problems as well. It would be nice to get to the point where the output for all of the trees are valid CIL, but that is a goal for the future.

v3:
- -use "-ast-phase=<phase>" in the usage message and man pages instead of "-ast-phase <phase>"

v2:
- Remove whitespace errors in cil_write_ast.h
- Use "const char*" instead of just "char*" when dealing with string literals to satisfy clang.

James Carter (3):
libsepol/cil: Create functions to write the CIL AST libsepol/cil: Add functions to make use of cil_write_ast()
secilc: Create the new program called secil2tree to write out CIL AST

 libsepol/cil/include/cil/cil.h   |    3 +
 libsepol/cil/src/cil.c           |   92 ++
 libsepol/cil/src/cil_tree.c      | 1471 ----------------------------
 libsepol/cil/src/cil_tree.h      |    2 -
 libsepol/cil/src/cil_write_ast.c | 1573 ++++++++++++++++++++++++++++++
 libsepol/cil/src/cil_write_ast.h |   46 +
 libsepol/src/libsepol.map.in     |    3 +
 secilc/.gitignore                |    2 +
 secilc/Makefile                  |   20 +-
 secilc/secil2tree.8.xml          |   81 ++
 secilc/secil2tree.c              |  206 ++++
 11 files changed, 2024 insertions(+), 1475 deletions(-)
 create mode 100644 libsepol/cil/src/cil_write_ast.c
 create mode 100644 libsepol/cil/src/cil_write_ast.h
 create mode 100644 secilc/secil2tree.8.xml
 create mode 100644 secilc/secil2tree.c
Quoted 3 lines

--
2.26.3

I indeed missed the v2, sorry for this.
These patches look good to me, thanks!

#5 lore raw
Quoted 57 lines · Nicolas Iooss
Quoted 55 lines · James Carter

For debugging purposes it would be useful to be able to write out the CIL AST at various points in the build process.

This patch set creates secil2tree which can write the CIL parse tree, the CIL AST after the build phase, or the CIL AST after the resolve phase (with names fully-qualified).

Within CIL the function cil_print_tree() has existed from early in CIL's development, but it was not exported in libsepol and there was no way to use it except by adding a call to it where you wanted to print out the CIL AST and then recompiling everything. It also used cil_log() as its output, so other messages could be mixed in with the output. This patch set moves all of this code to its own file, updates it, renames it as cil_write_ast(), and adds libsepol functions that can be used to call it after each one of the phases mentioned above.

Both the parse and build CIL AST are valid CIL policies that can be compiled with secilc, but the resolve CIL AST is not always a valid CIL policy. The biggest problem is that fully-qualified names can contain dots and CIL does not allow dots in declaration names. There are other problems as well. It would be nice to get to the point where the output for all of the trees are valid CIL, but that is a goal for the future.

v3:
- -use "-ast-phase=<phase>" in the usage message and man pages instead of "-ast-phase <phase>"

v2:
- Remove whitespace errors in cil_write_ast.h
- Use "const char*" instead of just "char*" when dealing with string literals to satisfy clang.

James Carter (3):
libsepol/cil: Create functions to write the CIL AST libsepol/cil: Add functions to make use of cil_write_ast()
secilc: Create the new program called secil2tree to write out CIL AST

 libsepol/cil/include/cil/cil.h   |    3 +
 libsepol/cil/src/cil.c           |   92 ++
 libsepol/cil/src/cil_tree.c      | 1471 ----------------------------
 libsepol/cil/src/cil_tree.h      |    2 -
 libsepol/cil/src/cil_write_ast.c | 1573 ++++++++++++++++++++++++++++++
 libsepol/cil/src/cil_write_ast.h |   46 +
 libsepol/src/libsepol.map.in     |    3 +
 secilc/.gitignore                |    2 +
 secilc/Makefile                  |   20 +-
 secilc/secil2tree.8.xml          |   81 ++
 secilc/secil2tree.c              |  206 ++++
 11 files changed, 2024 insertions(+), 1475 deletions(-)
 create mode 100644 libsepol/cil/src/cil_write_ast.c
 create mode 100644 libsepol/cil/src/cil_write_ast.h
 create mode 100644 secilc/secil2tree.8.xml
 create mode 100644 secilc/secil2tree.c
Quoted 8 lines
Quoted 3 lines

--
2.26.3

I indeed missed the v2, sorry for this.
These patches look good to me, thanks!

... and merged. Thanks again!

Nicolas