mirror of
https://gitlab.com/apparmor/apparmor.git
synced 2025-03-04 08:24:42 +01:00
Update the parser to support the 'in' keyword for value lists
Bug #959560 Part 1/3 of fix Signed-off-by: John Johansen <john.johansen@canonical.com>
This commit is contained in:
parent
c1722cdfdb
commit
3356dc4edd
8 changed files with 63 additions and 4 deletions
|
@ -62,6 +62,7 @@ struct value_list {
|
|||
|
||||
struct cond_entry {
|
||||
char *name;
|
||||
int eq; /* where equals was used in specifying list */
|
||||
struct value_list *vals;
|
||||
|
||||
struct cond_entry *next;
|
||||
|
@ -316,7 +317,7 @@ extern struct value_list *new_value_list(char *value);
|
|||
extern struct value_list *dup_value_list(struct value_list *list);
|
||||
extern void free_value_list(struct value_list *list);
|
||||
extern void print_value_list(struct value_list *list);
|
||||
extern struct cond_entry *new_cond_entry(char *name, struct value_list *list);
|
||||
extern struct cond_entry *new_cond_entry(char *name, int eq, struct value_list *list);
|
||||
extern void free_cond_entry(struct cond_entry *ent);
|
||||
extern void print_cond_entry(struct cond_entry *ent);
|
||||
extern char *processid(char *string, int len);
|
||||
|
|
|
@ -280,6 +280,18 @@ LT_EQUAL <=
|
|||
yy_push_state(EXTCOND_MODE);
|
||||
return TOK_CONDID;
|
||||
}
|
||||
{VARIABLE_NAME}/{WS}+in{WS}*\( {
|
||||
/* we match to 'in' in the lexer so that
|
||||
* we can switch scanner state. By the time
|
||||
* the parser see the 'in' it may be to late
|
||||
* as bison may have requested the next
|
||||
* token from the scanner
|
||||
*/
|
||||
PDEBUG("conditional %s=\n", yytext);
|
||||
yylval.id = processid(yytext, yyleng);
|
||||
yy_push_state(EXTCOND_MODE);
|
||||
return TOK_CONDID;
|
||||
}
|
||||
}
|
||||
|
||||
<SUB_ID>{
|
||||
|
@ -384,6 +396,11 @@ LT_EQUAL <=
|
|||
return TOK_OPENPAREN;
|
||||
}
|
||||
|
||||
in {
|
||||
DUMP_PREPROCESS;
|
||||
return TOK_IN;
|
||||
}
|
||||
|
||||
[^\n] {
|
||||
DUMP_PREPROCESS;
|
||||
/* Something we didn't expect */
|
||||
|
|
|
@ -84,6 +84,7 @@ static struct keyword_table keyword_table[] = {
|
|||
{"umount", TOK_UMOUNT},
|
||||
{"unmount", TOK_UMOUNT},
|
||||
{"pivot_root", TOK_PIVOTROOT},
|
||||
{"in", TOK_IN},
|
||||
/* terminate */
|
||||
{NULL, 0}
|
||||
};
|
||||
|
@ -1025,12 +1026,13 @@ void print_value_list(struct value_list *list)
|
|||
}
|
||||
}
|
||||
|
||||
struct cond_entry *new_cond_entry(char *name, struct value_list *list)
|
||||
struct cond_entry *new_cond_entry(char *name, int eq, struct value_list *list)
|
||||
{
|
||||
struct cond_entry *ent = calloc(1, sizeof(struct cond_entry));
|
||||
if (ent) {
|
||||
ent->name = name;
|
||||
ent->vals = list;
|
||||
ent->eq = eq;
|
||||
}
|
||||
|
||||
return ent;
|
||||
|
|
|
@ -121,6 +121,7 @@ void add_local_entry(struct codomain *cod);
|
|||
%token TOK_REMOUNT
|
||||
%token TOK_UMOUNT
|
||||
%token TOK_PIVOTROOT
|
||||
%token TOK_IN
|
||||
|
||||
/* rlimits */
|
||||
%token TOK_RLIMIT
|
||||
|
@ -1068,7 +1069,7 @@ cond: TOK_CONDID TOK_EQUALS TOK_VALUE
|
|||
struct value_list *value = new_value_list($3);
|
||||
if (!value)
|
||||
yyerror(_("Memory allocation error."));
|
||||
ent = new_cond_entry($1, value);
|
||||
ent = new_cond_entry($1, 1, value);
|
||||
if (!ent) {
|
||||
free_value_list(value);
|
||||
yyerror(_("Memory allocation error."));
|
||||
|
@ -1078,7 +1079,17 @@ cond: TOK_CONDID TOK_EQUALS TOK_VALUE
|
|||
|
||||
cond: TOK_CONDID TOK_EQUALS TOK_OPENPAREN valuelist TOK_CLOSEPAREN
|
||||
{
|
||||
struct cond_entry *ent = new_cond_entry($1, $4);
|
||||
struct cond_entry *ent = new_cond_entry($1, 1, $4);
|
||||
|
||||
if (!ent)
|
||||
yyerror(_("Memory allocation error."));
|
||||
$$ = ent;
|
||||
}
|
||||
|
||||
|
||||
cond: TOK_CONDID TOK_IN TOK_OPENPAREN valuelist TOK_CLOSEPAREN
|
||||
{
|
||||
struct cond_entry *ent = new_cond_entry($1, 0, $4);
|
||||
|
||||
if (!ent)
|
||||
yyerror(_("Memory allocation error."));
|
||||
|
|
7
parser/tst/simple_tests/mount/in_1.sd
Normal file
7
parser/tst/simple_tests/mount/in_1.sd
Normal file
|
@ -0,0 +1,7 @@
|
|||
#
|
||||
#=Description basic mount rule
|
||||
#=EXRESULT PASS
|
||||
#
|
||||
/usr/bin/foo {
|
||||
mount options in (rw) -> /foo,
|
||||
}
|
7
parser/tst/simple_tests/mount/in_2.sd
Normal file
7
parser/tst/simple_tests/mount/in_2.sd
Normal file
|
@ -0,0 +1,7 @@
|
|||
#
|
||||
#=Description basic mount rule
|
||||
#=EXRESULT PASS
|
||||
#
|
||||
/usr/bin/foo {
|
||||
mount options in (rw, ro) -> /foo,
|
||||
}
|
7
parser/tst/simple_tests/mount/in_3.sd
Normal file
7
parser/tst/simple_tests/mount/in_3.sd
Normal file
|
@ -0,0 +1,7 @@
|
|||
#
|
||||
#=Description basic mount rule
|
||||
#=EXRESULT PASS
|
||||
#
|
||||
/usr/bin/foo {
|
||||
mount options in (rw ro) -> /foo,
|
||||
}
|
7
parser/tst/simple_tests/mount/in_4.sd
Normal file
7
parser/tst/simple_tests/mount/in_4.sd
Normal file
|
@ -0,0 +1,7 @@
|
|||
#
|
||||
#=Description basic mount rule
|
||||
#=EXRESULT PASS
|
||||
#
|
||||
/usr/bin/foo {
|
||||
mount options in (rw ro) fstype=procfs -> /foo,
|
||||
}
|
Loading…
Add table
Reference in a new issue