Message ID | 20210122152552.405237-1-vmojzis@redhat.com (mailing list archive) |
---|---|
State | Accepted |
Delegated to: | Ondrej Mosnáček |
Headers | show |
Series | [v2] python/sepolgen: allow any policy statement in if(n)def | expand |
On Fri, Jan 22, 2021 at 4:29 PM Vit Mojzis <vmojzis@redhat.com> wrote: > "ifdef/ifndef" statements can be used to conditionally define > an interface, but this syntax is not recognised by sepolgen-ifgen. > Fix sepolgen-ifgen to allow any policy statement inside an > "fidef/ifndef" statement. > > Fixes: > $ cat <<EOF > i.if > ifndef(`apache_manage_pid_files',` > interface(`apache_manage_pid_files',` > manage_files_pattern($1, httpd_var_run_t, httpd_var_run_t) > ') > ') > > #sepolgen-ifgen --interface=i.if > i.if: Syntax error on line 2 interface [type=INTERFACE] > i.if: Syntax error on line 4 ' [type=SQUOTE] > > Signed-off-by: Vit Mojzis <vmojzis@redhat.com> > --- > Thanks. Fixed. And I replaced "statement" with "statements" to allow > multiple statements (as was possible with interface_stmts). > I'm not all that sure about the last line since I didn't manage to find > it's meaning (but I assume IF-THEN-ELSE). Yes, the third argument is basically an optional 'else' branch: https://www.gnu.org/software/m4/manual/m4-1.4.15/html_node/Ifdef.html > > python/sepolgen/src/sepolgen/refparser.py | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/python/sepolgen/src/sepolgen/refparser.py b/python/sepolgen/src/sepolgen/refparser.py > index 9f850990..e611637f 100644 > --- a/python/sepolgen/src/sepolgen/refparser.py > +++ b/python/sepolgen/src/sepolgen/refparser.py > @@ -433,9 +433,9 @@ def p_ifelse(p): > > > def p_ifdef(p): > - '''ifdef : IFDEF OPAREN TICK IDENTIFIER SQUOTE COMMA TICK interface_stmts SQUOTE CPAREN optional_semi > - | IFNDEF OPAREN TICK IDENTIFIER SQUOTE COMMA TICK interface_stmts SQUOTE CPAREN optional_semi > - | IFDEF OPAREN TICK IDENTIFIER SQUOTE COMMA TICK interface_stmts SQUOTE COMMA TICK interface_stmts SQUOTE CPAREN optional_semi > + '''ifdef : IFDEF OPAREN TICK IDENTIFIER SQUOTE COMMA TICK statements SQUOTE CPAREN optional_semi > + | IFNDEF OPAREN TICK IDENTIFIER SQUOTE COMMA TICK statements SQUOTE CPAREN optional_semi > + | IFDEF OPAREN TICK IDENTIFIER SQUOTE COMMA TICK statements SQUOTE COMMA TICK statements SQUOTE CPAREN optional_semi > ''' > x = refpolicy.IfDef(p[4]) > if p[1] == 'ifdef': > -- > 2.29.2 > Acked-by: Ondrej Mosnacek <omosnace@redhat.com> -- Ondrej Mosnacek Software Engineer, Platform Security - SELinux kernel Red Hat, Inc.
On Fri, Jan 22, 2021 at 5:32 PM Ondrej Mosnacek <omosnace@redhat.com> wrote: > On Fri, Jan 22, 2021 at 4:29 PM Vit Mojzis <vmojzis@redhat.com> wrote: > > "ifdef/ifndef" statements can be used to conditionally define > > an interface, but this syntax is not recognised by sepolgen-ifgen. > > Fix sepolgen-ifgen to allow any policy statement inside an > > "fidef/ifndef" statement. > > > > Fixes: > > $ cat <<EOF > i.if > > ifndef(`apache_manage_pid_files',` > > interface(`apache_manage_pid_files',` > > manage_files_pattern($1, httpd_var_run_t, httpd_var_run_t) > > ') > > ') > > > > #sepolgen-ifgen --interface=i.if > > i.if: Syntax error on line 2 interface [type=INTERFACE] > > i.if: Syntax error on line 4 ' [type=SQUOTE] > > > > Signed-off-by: Vit Mojzis <vmojzis@redhat.com> > > --- > > Thanks. Fixed. And I replaced "statement" with "statements" to allow > > multiple statements (as was possible with interface_stmts). > > I'm not all that sure about the last line since I didn't manage to find > > it's meaning (but I assume IF-THEN-ELSE). > > Yes, the third argument is basically an optional 'else' branch: > https://www.gnu.org/software/m4/manual/m4-1.4.15/html_node/Ifdef.html > > > > > python/sepolgen/src/sepolgen/refparser.py | 6 +++--- > > 1 file changed, 3 insertions(+), 3 deletions(-) > > > > diff --git a/python/sepolgen/src/sepolgen/refparser.py b/python/sepolgen/src/sepolgen/refparser.py > > index 9f850990..e611637f 100644 > > --- a/python/sepolgen/src/sepolgen/refparser.py > > +++ b/python/sepolgen/src/sepolgen/refparser.py > > @@ -433,9 +433,9 @@ def p_ifelse(p): > > > > > > def p_ifdef(p): > > - '''ifdef : IFDEF OPAREN TICK IDENTIFIER SQUOTE COMMA TICK interface_stmts SQUOTE CPAREN optional_semi > > - | IFNDEF OPAREN TICK IDENTIFIER SQUOTE COMMA TICK interface_stmts SQUOTE CPAREN optional_semi > > - | IFDEF OPAREN TICK IDENTIFIER SQUOTE COMMA TICK interface_stmts SQUOTE COMMA TICK interface_stmts SQUOTE CPAREN optional_semi > > + '''ifdef : IFDEF OPAREN TICK IDENTIFIER SQUOTE COMMA TICK statements SQUOTE CPAREN optional_semi > > + | IFNDEF OPAREN TICK IDENTIFIER SQUOTE COMMA TICK statements SQUOTE CPAREN optional_semi > > + | IFDEF OPAREN TICK IDENTIFIER SQUOTE COMMA TICK statements SQUOTE COMMA TICK statements SQUOTE CPAREN optional_semi > > ''' > > x = refpolicy.IfDef(p[4]) > > if p[1] == 'ifdef': > > -- > > 2.29.2 > > > > Acked-by: Ondrej Mosnacek <omosnace@redhat.com> Merged: https://github.com/SELinuxProject/selinux/commit/e12f71e82f523513c249dbe5a2e35c1916370992
diff --git a/python/sepolgen/src/sepolgen/refparser.py b/python/sepolgen/src/sepolgen/refparser.py index 9f850990..e611637f 100644 --- a/python/sepolgen/src/sepolgen/refparser.py +++ b/python/sepolgen/src/sepolgen/refparser.py @@ -433,9 +433,9 @@ def p_ifelse(p): def p_ifdef(p): - '''ifdef : IFDEF OPAREN TICK IDENTIFIER SQUOTE COMMA TICK interface_stmts SQUOTE CPAREN optional_semi - | IFNDEF OPAREN TICK IDENTIFIER SQUOTE COMMA TICK interface_stmts SQUOTE CPAREN optional_semi - | IFDEF OPAREN TICK IDENTIFIER SQUOTE COMMA TICK interface_stmts SQUOTE COMMA TICK interface_stmts SQUOTE CPAREN optional_semi + '''ifdef : IFDEF OPAREN TICK IDENTIFIER SQUOTE COMMA TICK statements SQUOTE CPAREN optional_semi + | IFNDEF OPAREN TICK IDENTIFIER SQUOTE COMMA TICK statements SQUOTE CPAREN optional_semi + | IFDEF OPAREN TICK IDENTIFIER SQUOTE COMMA TICK statements SQUOTE COMMA TICK statements SQUOTE CPAREN optional_semi ''' x = refpolicy.IfDef(p[4]) if p[1] == 'ifdef':
"ifdef/ifndef" statements can be used to conditionally define an interface, but this syntax is not recognised by sepolgen-ifgen. Fix sepolgen-ifgen to allow any policy statement inside an "fidef/ifndef" statement. Fixes: $ cat <<EOF > i.if ifndef(`apache_manage_pid_files',` interface(`apache_manage_pid_files',` manage_files_pattern($1, httpd_var_run_t, httpd_var_run_t) ') ') #sepolgen-ifgen --interface=i.if i.if: Syntax error on line 2 interface [type=INTERFACE] i.if: Syntax error on line 4 ' [type=SQUOTE] Signed-off-by: Vit Mojzis <vmojzis@redhat.com> --- Thanks. Fixed. And I replaced "statement" with "statements" to allow multiple statements (as was possible with interface_stmts). I'm not all that sure about the last line since I didn't manage to find it's meaning (but I assume IF-THEN-ELSE). python/sepolgen/src/sepolgen/refparser.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)