From 20271849d5e16fd3a3dd9c0db7d19fae18cf1f4c Mon Sep 17 00:00:00 2001 From: James Carter Date: Thu, 24 Jun 2021 15:58:14 -0400 Subject: [PATCH] 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 --- libsepol/cil/src/cil_tree.c | 16 ++++++++++++++++ libsepol/cil/src/cil_tree.h | 2 ++ 2 files changed, 18 insertions(+) diff --git a/libsepol/cil/src/cil_tree.c b/libsepol/cil/src/cil_tree.c index 067268eb..4cf8dcc8 100644 --- a/libsepol/cil/src/cil_tree.c +++ b/libsepol/cil/src/cil_tree.c @@ -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)); diff --git a/libsepol/cil/src/cil_tree.h b/libsepol/cil/src/cil_tree.h index bac9f1e4..f4d22071 100644 --- a/libsepol/cil/src/cil_tree.h +++ b/libsepol/cil/src/cil_tree.h @@ -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);