mirror of
https://gitlab.com/apparmor/apparmor
synced 2025-09-02 15:25:27 +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:
@@ -53,6 +53,8 @@ struct cod_entry {
|
|||||||
int audit; /* audit flags for mode */
|
int audit; /* audit flags for mode */
|
||||||
int deny; /* TRUE or FALSE */
|
int deny; /* TRUE or FALSE */
|
||||||
|
|
||||||
|
int alias_ignore; /* ignore for alias processing */
|
||||||
|
|
||||||
int subset;
|
int subset;
|
||||||
|
|
||||||
pattern_t pattern_type;
|
pattern_t pattern_type;
|
||||||
|
@@ -97,15 +97,16 @@ static char *do_alias(struct alias_rule *alias, const char *target)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
sprintf(new, "%s%s", alias->to, target + strlen(alias->from));
|
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;
|
return new;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct codomain *target_cod;
|
||||||
static struct cod_entry *target_list;
|
static struct cod_entry *target_list;
|
||||||
static void process_entries(const void *nodep, VISIT value, int __unused level)
|
static void process_entries(const void *nodep, VISIT value, int __unused level)
|
||||||
{
|
{
|
||||||
struct alias_rule **t = (struct alias_rule **) nodep;
|
struct alias_rule **t = (struct alias_rule **) nodep;
|
||||||
struct cod_entry *entry;
|
struct cod_entry *entry, *dup = NULL;
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
if (value == preorder || value == endorder)
|
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);
|
len = strlen((*t)->from);
|
||||||
|
|
||||||
list_for_each(target_list, entry) {
|
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;
|
continue;
|
||||||
if (entry->name && strncmp((*t)->from, entry->name, len) == 0) {
|
if (entry->name && strncmp((*t)->from, entry->name, len) == 0) {
|
||||||
char *new = do_alias(*t, entry->name);
|
char *new = do_alias(*t, entry->name);
|
||||||
if (!new)
|
if (!new)
|
||||||
return;
|
return;
|
||||||
free(entry->name);
|
dup = copy_cod_entry(entry);
|
||||||
entry->name = new;
|
free(dup->name);
|
||||||
|
dup->name = new;
|
||||||
}
|
}
|
||||||
if (entry->link_name &&
|
if (entry->link_name &&
|
||||||
strncmp((*t)->from, entry->link_name, len) == 0) {
|
strncmp((*t)->from, entry->link_name, len) == 0) {
|
||||||
char *new = do_alias(*t, entry->link_name);
|
char *new = do_alias(*t, entry->link_name);
|
||||||
if (!new)
|
if (!new)
|
||||||
return;
|
return;
|
||||||
free(entry->link_name);
|
if (!dup)
|
||||||
entry->link_name = new;
|
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) {
|
if (cod->entries) {
|
||||||
target_list = cod->entries;
|
target_list = cod->entries;
|
||||||
|
target_cod = cod;
|
||||||
twalk(alias_table, process_entries);
|
twalk(alias_table, process_entries);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -686,6 +686,7 @@ struct cod_entry *copy_cod_entry(struct cod_entry *orig)
|
|||||||
entry->name = strdup(orig->name);
|
entry->name = strdup(orig->name);
|
||||||
entry->link_name = orig->link_name ? strdup(orig->link_name) : NULL;
|
entry->link_name = orig->link_name ? strdup(orig->link_name) : NULL;
|
||||||
entry->mode = orig->mode;
|
entry->mode = orig->mode;
|
||||||
|
entry->audit = orig->audit;
|
||||||
entry->deny = orig->deny;
|
entry->deny = orig->deny;
|
||||||
|
|
||||||
/* XXX - need to create copies of the patterns, too */
|
/* XXX - need to create copies of the patterns, too */
|
||||||
|
Reference in New Issue
Block a user