libsepol/cil: Add function to determine if a subtree has a declaration

Create the function cil_tree_subtree_has_decl() that returns CIL_TRUE
if the subtree has a declaration in it and CIL_FALSE otherwise.

Signed-off-by: James Carter <jwcart2@gmail.com>
This commit is contained in:
James Carter 2021-06-24 15:58:14 -04:00 committed by Nicolas Iooss
parent 37863b0b14
commit 20271849d5
No known key found for this signature in database
GPG Key ID: C191415F340DAAA0
2 changed files with 18 additions and 0 deletions

View File

@ -136,6 +136,22 @@ __attribute__((format (printf, 3, 4))) void cil_tree_log(struct cil_tree_node *n
cil_log(lvl,"\n");
}
int cil_tree_subtree_has_decl(struct cil_tree_node *node)
{
while (node) {
if (node->flavor >= CIL_MIN_DECLARATIVE) {
return CIL_TRUE;
}
if (node->cl_head != NULL) {
if (cil_tree_subtree_has_decl(node->cl_head))
return CIL_TRUE;
}
node = node->next;
}
return CIL_FALSE;
}
int cil_tree_init(struct cil_tree **tree)
{
struct cil_tree *new_tree = cil_malloc(sizeof(*new_tree));

View File

@ -54,6 +54,8 @@ struct cil_tree_node *cil_tree_get_next_path(struct cil_tree_node *node, char **
char *cil_tree_get_cil_path(struct cil_tree_node *node);
__attribute__((format (printf, 3, 4))) void cil_tree_log(struct cil_tree_node *node, enum cil_log_level lvl, const char* msg, ...);
int cil_tree_subtree_has_decl(struct cil_tree_node *node);
int cil_tree_init(struct cil_tree **tree);
void cil_tree_destroy(struct cil_tree **tree);
void cil_tree_subtree_destroy(struct cil_tree_node *node);