mirror of
https://gitlab.com/apparmor/apparmor
synced 2025-08-29 05:17:59 +00: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
@ -62,6 +62,7 @@ struct value_list {
|
|||||||
|
|
||||||
struct cond_entry {
|
struct cond_entry {
|
||||||
char *name;
|
char *name;
|
||||||
|
int eq; /* where equals was used in specifying list */
|
||||||
struct value_list *vals;
|
struct value_list *vals;
|
||||||
|
|
||||||
struct cond_entry *next;
|
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 struct value_list *dup_value_list(struct value_list *list);
|
||||||
extern void free_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 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 free_cond_entry(struct cond_entry *ent);
|
||||||
extern void print_cond_entry(struct cond_entry *ent);
|
extern void print_cond_entry(struct cond_entry *ent);
|
||||||
extern char *processid(char *string, int len);
|
extern char *processid(char *string, int len);
|
||||||
|
@ -280,6 +280,18 @@ LT_EQUAL <=
|
|||||||
yy_push_state(EXTCOND_MODE);
|
yy_push_state(EXTCOND_MODE);
|
||||||
return TOK_CONDID;
|
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>{
|
<SUB_ID>{
|
||||||
@ -384,6 +396,11 @@ LT_EQUAL <=
|
|||||||
return TOK_OPENPAREN;
|
return TOK_OPENPAREN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
in {
|
||||||
|
DUMP_PREPROCESS;
|
||||||
|
return TOK_IN;
|
||||||
|
}
|
||||||
|
|
||||||
[^\n] {
|
[^\n] {
|
||||||
DUMP_PREPROCESS;
|
DUMP_PREPROCESS;
|
||||||
/* Something we didn't expect */
|
/* Something we didn't expect */
|
||||||
|
@ -84,6 +84,7 @@ static struct keyword_table keyword_table[] = {
|
|||||||
{"umount", TOK_UMOUNT},
|
{"umount", TOK_UMOUNT},
|
||||||
{"unmount", TOK_UMOUNT},
|
{"unmount", TOK_UMOUNT},
|
||||||
{"pivot_root", TOK_PIVOTROOT},
|
{"pivot_root", TOK_PIVOTROOT},
|
||||||
|
{"in", TOK_IN},
|
||||||
/* terminate */
|
/* terminate */
|
||||||
{NULL, 0}
|
{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));
|
struct cond_entry *ent = calloc(1, sizeof(struct cond_entry));
|
||||||
if (ent) {
|
if (ent) {
|
||||||
ent->name = name;
|
ent->name = name;
|
||||||
ent->vals = list;
|
ent->vals = list;
|
||||||
|
ent->eq = eq;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ent;
|
return ent;
|
||||||
|
@ -121,6 +121,7 @@ void add_local_entry(struct codomain *cod);
|
|||||||
%token TOK_REMOUNT
|
%token TOK_REMOUNT
|
||||||
%token TOK_UMOUNT
|
%token TOK_UMOUNT
|
||||||
%token TOK_PIVOTROOT
|
%token TOK_PIVOTROOT
|
||||||
|
%token TOK_IN
|
||||||
|
|
||||||
/* rlimits */
|
/* rlimits */
|
||||||
%token TOK_RLIMIT
|
%token TOK_RLIMIT
|
||||||
@ -1068,7 +1069,7 @@ cond: TOK_CONDID TOK_EQUALS TOK_VALUE
|
|||||||
struct value_list *value = new_value_list($3);
|
struct value_list *value = new_value_list($3);
|
||||||
if (!value)
|
if (!value)
|
||||||
yyerror(_("Memory allocation error."));
|
yyerror(_("Memory allocation error."));
|
||||||
ent = new_cond_entry($1, value);
|
ent = new_cond_entry($1, 1, value);
|
||||||
if (!ent) {
|
if (!ent) {
|
||||||
free_value_list(value);
|
free_value_list(value);
|
||||||
yyerror(_("Memory allocation error."));
|
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
|
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)
|
if (!ent)
|
||||||
yyerror(_("Memory allocation error."));
|
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…
x
Reference in New Issue
Block a user