mirror of
https://gitlab.com/apparmor/apparmor
synced 2025-09-02 15:25:27 +00:00
parser: Clean up file entry processing
Removes an unnecessary variable, simplifies and unifies some of the loop logic, and removes commented out code. Signed-off-by: Tyler Hicks <tyhicks@canonical.com> Acked-by: Steve Beattie <steve@nxnw.org>
This commit is contained in:
@@ -76,14 +76,13 @@ static int file_comp(const void *c1, const void *c2)
|
|||||||
|
|
||||||
static int process_file_entries(struct codomain *cod)
|
static int process_file_entries(struct codomain *cod)
|
||||||
{
|
{
|
||||||
int n, count;
|
struct cod_entry *cur, *next;
|
||||||
struct cod_entry *flist, *cur, *next;
|
|
||||||
struct cod_entry **table;
|
struct cod_entry **table;
|
||||||
|
int n, count = 0;
|
||||||
|
|
||||||
for (flist = cod->entries, n = 0; flist; flist = flist->next)
|
for (cur = cod->entries; cur; cur = cur->next)
|
||||||
n++;
|
count++;
|
||||||
|
|
||||||
count = n;
|
|
||||||
if (count < 2)
|
if (count < 2)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
@@ -93,12 +92,8 @@ static int process_file_entries(struct codomain *cod)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
n = 0;
|
for (cur = cod->entries, n = 0; cur; cur = cur->next, n++)
|
||||||
for (flist = cod->entries; flist; flist = flist->next) {
|
table[n] = cur;
|
||||||
table[n] = flist;
|
|
||||||
n++;
|
|
||||||
}
|
|
||||||
|
|
||||||
qsort(table, count, sizeof(struct cod_entry *), file_comp);
|
qsort(table, count, sizeof(struct cod_entry *), file_comp);
|
||||||
table[count] = NULL;
|
table[count] = NULL;
|
||||||
for (n = 0; n < count; n++)
|
for (n = 0; n < count; n++)
|
||||||
@@ -107,26 +102,24 @@ static int process_file_entries(struct codomain *cod)
|
|||||||
free(table);
|
free(table);
|
||||||
|
|
||||||
/* walk the sorted table merging similar entries */
|
/* walk the sorted table merging similar entries */
|
||||||
for (cur = cod->entries, next = cur->next; next != NULL; next = cur->next) {
|
for (cur = cod->entries, next = cur->next; next; next = cur->next) {
|
||||||
if (file_comp(&cur, &next) == 0) {
|
if (file_comp(&cur, &next) != 0) {
|
||||||
/* check for merged x consistency */
|
|
||||||
if (!is_merged_x_consistent(cur->mode, next->mode)) {
|
|
||||||
PERROR(_("profile %s: has merged rule %s with "
|
|
||||||
"conflicting x modifiers\n"),
|
|
||||||
cod->name, cur->name);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
//if (next->audit)
|
|
||||||
//fprintf(stderr, "warning: merging rule 0x%x %s\n", next->audit, next->name);
|
|
||||||
cur->mode |= next->mode;
|
|
||||||
cur->audit |= next->audit;
|
|
||||||
cur->next = next->next;
|
|
||||||
|
|
||||||
next->next = NULL;
|
|
||||||
free_cod_entries(next);
|
|
||||||
} else {
|
|
||||||
cur = next;
|
cur = next;
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* check for merged x consistency */
|
||||||
|
if (!is_merged_x_consistent(cur->mode, next->mode)) {
|
||||||
|
PERROR(_("profile %s: has merged rule %s with conflicting x modifiers\n"),
|
||||||
|
cod->name, cur->name);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
cur->mode |= next->mode;
|
||||||
|
cur->audit |= next->audit;
|
||||||
|
cur->next = next->next;
|
||||||
|
|
||||||
|
next->next = NULL;
|
||||||
|
free_cod_entries(next);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
Reference in New Issue
Block a user