2
0
mirror of https://gitlab.com/apparmor/apparmor synced 2025-08-30 05:47:59 +00:00

parser: Refactor rule accumulation to use some helper functions

Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <steve@nxnw.org>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
This commit is contained in:
John Johansen 2014-09-03 14:24:37 -07:00 committed by Steve Beattie
parent 73c74d044d
commit ee7bf1dc28
2 changed files with 18 additions and 9 deletions

View File

@ -76,6 +76,21 @@ void aare_reset_matchflags(void)
#undef RESET_FLAGS #undef RESET_FLAGS
} }
void aare_rules::add_to_rules(Node *tree, Node *perms)
{
if (reverse)
flip_tree(tree);
if (root)
root = new AltNode(root, new CatNode(tree, perms));
else
root = new CatNode(tree, perms);
}
static Node *cat_with_null_seperator(Node *l, Node *r)
{
return new CatNode(new CatNode(l, new CharNode(0)), r);
}
bool aare_rules::add_rule_vec(int deny, uint32_t perms, uint32_t audit, bool aare_rules::add_rule_vec(int deny, uint32_t perms, uint32_t audit,
int count, const char **rulev, dfaflags_t flags) int count, const char **rulev, dfaflags_t flags)
{ {
@ -89,13 +104,9 @@ bool aare_rules::add_rule_vec(int deny, uint32_t perms, uint32_t audit,
return false; return false;
for (int i = 1; i < count; i++) { for (int i = 1; i < count; i++) {
Node *subtree = NULL; Node *subtree = NULL;
Node *node = new CharNode(0);
if (!node)
return false;
tree = new CatNode(tree, node);
if (regex_parse(&subtree, rulev[i])) if (regex_parse(&subtree, rulev[i]))
return false; return false;
tree = new CatNode(tree, subtree); tree = cat_with_null_seperator(tree, subtree);
} }
/* /*
@ -200,10 +211,7 @@ bool aare_rules::add_rule_vec(int deny, uint32_t perms, uint32_t audit,
cerr << "\n\n"; cerr << "\n\n";
} }
if (root) add_to_rules(tree, accept);
root = new AltNode(root, new CatNode(tree, accept));
else
root = new CatNode(tree, accept);
rule_count++; rule_count++;

View File

@ -28,6 +28,7 @@
class aare_rules { class aare_rules {
Node *root; Node *root;
void add_to_rules(Node *tree, Node *perms);
public: public:
int reverse; int reverse;
int rule_count; int rule_count;