2
0
mirror of https://gitlab.com/apparmor/apparmor synced 2025-08-31 14:25:52 +00:00

parser: finish basic infrastructure for rule merging

Currently only file rules get merged. Finish adding basic support
for rule merging and make the default the behavior to dedup
merge rules that are exact matches.

Signed-off-by: John Johansen <john.johansen@canonical.com>
This commit is contained in:
John Johansen
2023-07-03 23:52:57 -07:00
parent dbca8ebb89
commit 7d9958890f
8 changed files with 220 additions and 44 deletions

View File

@@ -72,7 +72,7 @@ static int process_file_entries(Profile *prof)
table = (struct cod_entry **) malloc(sizeof(struct cod_entry *) * (count + 1));
if (!table) {
PERROR(_("Couldn't merge entries. Out of Memory\n"));
return ENOMEM;
return -ENOMEM;
}
for (cur = prof->entries, n = 0; cur; cur = cur->next, n++)
@@ -84,6 +84,7 @@ static int process_file_entries(Profile *prof)
prof->entries = table[0];
free(table);
count = 0;
/* walk the sorted table merging similar entries */
for (cur = prof->entries, next = cur->next; next; next = cur->next) {
if (file_comp(&cur, &next) != 0) {
@@ -102,12 +103,20 @@ static int process_file_entries(Profile *prof)
next->next = NULL;
free_cod_entries(next);
count++;
}
return 0;
return count;
}
int profile_merge_rules(Profile *prof)
{
return process_file_entries(prof);
int res, tmp = process_file_entries(prof);
if (tmp < 0)
return -tmp;
res = prof->merge_rules();
if (res < 0)
return -res;
// TODO: output message eliminated rules res + tmp;
return 0;
}