diff --git a/parser/parser.h b/parser/parser.h index 5081c3634..5b02a79d8 100644 --- a/parser/parser.h +++ b/parser/parser.h @@ -77,9 +77,15 @@ struct aa_rlimits { rlim_t limits[RLIMIT_NLIMITS]; }; +struct alt_name { + char *name; + struct alt_name *next; +}; + struct codomain { char *namespace; char *name; /* codomain name */ + struct alt_name *altnames; void *xmatch; size_t xmatch_size; int xmatch_len; diff --git a/parser/parser_alias.c b/parser/parser_alias.c index 1f4ebd7aa..7c821f869 100644 --- a/parser/parser_alias.c +++ b/parser/parser_alias.c @@ -161,11 +161,17 @@ static void process_name(const void *nodep, VISIT value, int __unused level) len = strlen((*t)->from); if (cod->name && strncmp((*t)->from, cod->name, len) == 0) { + struct alt_name *alt; char *new = do_alias(*t, cod->name); if (!new) return; - free(cod->name); - cod->name = new; + /* aliases create alternate names */ + alt = calloc(1, sizeof(struct alt_name)); + if (!alt) + return; + alt->name = new; + alt->next = cod->altnames; + cod->altnames = alt; } } diff --git a/parser/parser_regex.c b/parser/parser_regex.c index 993204130..0235618d0 100644 --- a/parser/parser_regex.c +++ b/parser/parser_regex.c @@ -509,7 +509,7 @@ static int process_profile_name_xmatch(struct codomain *cod) if (ptype == ePatternInvalid) { PERROR(_("%s: Invalid profile name '%s' - bad regular expression\n"), progname, name); return FALSE; - } else if (ptype == ePatternBasic) { + } else if (ptype == ePatternBasic && !cod->altnames) { /* no regex so do not set xmatch */ cod->xmatch = NULL; cod->xmatch_len = 0; @@ -523,6 +523,18 @@ static int process_profile_name_xmatch(struct codomain *cod) aare_delete_ruleset(rule); return FALSE; } + if (cod->altnames) { + struct alt_name *alt; + list_for_each(cod->altnames, alt) { + int len; + convert_aaregex_to_pcre(alt->name, 0, tbuf, + PATH_MAX + 3, &len); + if (!aare_add_rule(rule, tbuf, 0, AA_MAY_EXEC, 0)) { + aare_delete_ruleset(rule); + return FALSE; + } + } + } cod->xmatch = aare_create_dfa(rule, &cod->xmatch_size, dfaflags); aare_delete_ruleset(rule);