2
0
mirror of https://gitlab.com/apparmor/apparmor synced 2025-08-31 06:16:03 +00:00

Fix alias to keep old rule and add new one instead of updating old rule.

Alias was broken because it when an alias was made the old path was completely
removed and there was no way to specify it.  Update it so aliases just add
an new duplicate rule instead.
This commit is contained in:
John Johansen
2010-02-12 13:46:55 -08:00
parent 94b2a345f2
commit eafddd3cea
3 changed files with 25 additions and 7 deletions

View File

@@ -97,15 +97,16 @@ static char *do_alias(struct alias_rule *alias, const char *target)
return NULL;
}
sprintf(new, "%s%s", alias->to, target + strlen(alias->from));
//fprintf(stderr, "replaced alias: from: %s, to: %s, name: %s\n %s\n", alias->from, alias->to, target, new);
/*fprintf(stderr, "replaced alias: from: %s, to: %s, name: %s\n %s\n", alias->from, alias->to, target, new);*/
return new;
}
static struct codomain *target_cod;
static struct cod_entry *target_list;
static void process_entries(const void *nodep, VISIT value, int __unused level)
{
struct alias_rule **t = (struct alias_rule **) nodep;
struct cod_entry *entry;
struct cod_entry *entry, *dup = NULL;
int len;
if (value == preorder || value == endorder)
@@ -114,22 +115,35 @@ static void process_entries(const void *nodep, VISIT value, int __unused level)
len = strlen((*t)->from);
list_for_each(target_list, entry) {
if (entry->mode & (AA_SHARED_PERMS & AA_PTRACE_PERMS))
if (entry->mode & (AA_SHARED_PERMS & AA_PTRACE_PERMS) ||
entry->alias_ignore)
continue;
if (entry->name && strncmp((*t)->from, entry->name, len) == 0) {
char *new = do_alias(*t, entry->name);
if (!new)
return;
free(entry->name);
entry->name = new;
dup = copy_cod_entry(entry);
free(dup->name);
dup->name = new;
}
if (entry->link_name &&
strncmp((*t)->from, entry->link_name, len) == 0) {
char *new = do_alias(*t, entry->link_name);
if (!new)
return;
free(entry->link_name);
entry->link_name = new;
if (!dup)
dup = copy_cod_entry(entry);
free(dup->link_name);
dup->link_name = new;
}
if (dup) {
dup->alias_ignore = 1;
/* adds to the front of the list, list iteratition
* will skip it
*/
entry->next = dup;
dup = NULL;
}
}
}
@@ -162,6 +176,7 @@ void replace_aliases(struct codomain *cod)
if (cod->entries) {
target_list = cod->entries;
target_cod = cod;
twalk(alias_table, process_entries);
}
}