mirror of
https://gitlab.com/apparmor/apparmor
synced 2025-08-22 18:17:09 +00:00
Make value_list generic so it can be reused.
value_list can be reused by conditionals and list values, so pull it out and abstract it some more. Signed-off-by: John Johansen <john.johansen@canonical.com> Acked-by: Kees Cook <kees@ubuntu.com>
This commit is contained in:
parent
e087db57b2
commit
b8f36df713
@ -49,6 +49,12 @@ struct cod_pattern {
|
|||||||
char *regex; // posix regex
|
char *regex; // posix regex
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct value_list {
|
||||||
|
char *value;
|
||||||
|
|
||||||
|
struct value_list *next;
|
||||||
|
};
|
||||||
|
|
||||||
struct cod_entry {
|
struct cod_entry {
|
||||||
char *namespace;
|
char *namespace;
|
||||||
char *name;
|
char *name;
|
||||||
@ -275,6 +281,9 @@ extern struct var_string *split_out_var(char *string);
|
|||||||
extern void free_var_string(struct var_string *var);
|
extern void free_var_string(struct var_string *var);
|
||||||
|
|
||||||
/* parser_misc.c */
|
/* parser_misc.c */
|
||||||
|
extern struct value_list *new_value_list(char *value);
|
||||||
|
extern void free_value_list(struct value_list *list);
|
||||||
|
extern void print_value_list(struct value_list *list);
|
||||||
extern char *processid(char *string, int len);
|
extern char *processid(char *string, int len);
|
||||||
extern char *processquoted(char *string, int len);
|
extern char *processquoted(char *string, int len);
|
||||||
extern char *processunquoted(char *string, int len);
|
extern char *processunquoted(char *string, int len);
|
||||||
|
@ -939,6 +939,41 @@ void debug_cod_list(struct codomain *cod)
|
|||||||
dump_policy_hats(cod);
|
dump_policy_hats(cod);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct value_list *new_value_list(char *value)
|
||||||
|
{
|
||||||
|
struct value_list *val = calloc(1, sizeof(struct value_list));
|
||||||
|
if (val)
|
||||||
|
val->value = value;
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
|
void free_value_list(struct value_list *list)
|
||||||
|
{
|
||||||
|
struct value_list *next;
|
||||||
|
|
||||||
|
while (list) {
|
||||||
|
next = list->next;
|
||||||
|
if (list->value)
|
||||||
|
free(list->value);
|
||||||
|
free(list);
|
||||||
|
list = next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void print_value_list(struct value_list *list)
|
||||||
|
{
|
||||||
|
struct value_list *entry;
|
||||||
|
|
||||||
|
if (!list)
|
||||||
|
return;
|
||||||
|
|
||||||
|
fprintf(stderr, "%s", list->value);
|
||||||
|
list = list->next;
|
||||||
|
list_for_each(list, entry) {
|
||||||
|
fprintf(stderr, ", %s", entry->value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef UNIT_TEST
|
#ifdef UNIT_TEST
|
||||||
int test_str_to_boolean(void)
|
int test_str_to_boolean(void)
|
||||||
{
|
{
|
||||||
|
@ -64,14 +64,8 @@
|
|||||||
|
|
||||||
#define CAP_TO_MASK(x) (1ull << (x))
|
#define CAP_TO_MASK(x) (1ull << (x))
|
||||||
|
|
||||||
struct value_list {
|
|
||||||
char *value;
|
|
||||||
struct value_list *next;
|
|
||||||
};
|
|
||||||
|
|
||||||
int parser_token = 0;
|
int parser_token = 0;
|
||||||
|
|
||||||
void free_value_list(struct value_list *list);
|
|
||||||
struct cod_entry *do_file_rule(char *namespace, char *id, int mode,
|
struct cod_entry *do_file_rule(char *namespace, char *id, int mode,
|
||||||
char *link_id, char *nt);
|
char *link_id, char *nt);
|
||||||
|
|
||||||
@ -377,26 +371,23 @@ varassign: TOK_BOOL_VAR TOK_EQUALS TOK_VALUE
|
|||||||
|
|
||||||
valuelist: TOK_VALUE
|
valuelist: TOK_VALUE
|
||||||
{
|
{
|
||||||
struct value_list *new = calloc(1, sizeof(struct value_list));
|
struct value_list *val = new_value_list($1);
|
||||||
if (!new)
|
if (!val)
|
||||||
yyerror(_("Memory allocation error."));
|
yyerror(_("Memory allocation error."));
|
||||||
PDEBUG("Matched: value (%s)\n", $1);
|
PDEBUG("Matched: value (%s)\n", $1);
|
||||||
|
|
||||||
new->value = $1;
|
$$ = val;
|
||||||
new->next = NULL;
|
|
||||||
$$ = new;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
valuelist: valuelist TOK_VALUE
|
valuelist: valuelist TOK_VALUE
|
||||||
{
|
{
|
||||||
struct value_list *new = calloc(1, sizeof(struct value_list));
|
struct value_list *val = new_value_list($2);
|
||||||
if (!new)
|
if (!val)
|
||||||
yyerror(_("Memory allocation error."));
|
yyerror(_("Memory allocation error."));
|
||||||
PDEBUG("Matched: value list\n");
|
PDEBUG("Matched: value list\n");
|
||||||
|
|
||||||
new->value = $2;
|
val->next = $1;
|
||||||
new->next = $1;
|
$$ = val;
|
||||||
$$ = new;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
flags: { /* nothing */
|
flags: { /* nothing */
|
||||||
@ -1114,19 +1105,6 @@ void yyerror(char *msg, ...)
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void free_value_list(struct value_list *list)
|
|
||||||
{
|
|
||||||
struct value_list *next;
|
|
||||||
|
|
||||||
while (list) {
|
|
||||||
next = list->next;
|
|
||||||
if (list->value)
|
|
||||||
free(list->value);
|
|
||||||
free(list);
|
|
||||||
list = next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct cod_entry *do_file_rule(char *namespace, char *id, int mode,
|
struct cod_entry *do_file_rule(char *namespace, char *id, int mode,
|
||||||
char *link_id, char *nt)
|
char *link_id, char *nt)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user