diff mbox series

python/sepolgen: allow any policy statement in ifndef

Message ID 20210111211405.2215410-1-vmojzis@redhat.com (mailing list archive)
State Superseded
Headers show
Series python/sepolgen: allow any policy statement in ifndef | expand

Commit Message

Vit Mojzis Jan. 11, 2021, 9:14 p.m. UTC
"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 "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>
---
 python/sepolgen/src/sepolgen/refparser.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Ondrej Mosnacek Jan. 19, 2021, 1:55 p.m. UTC | #1
On Mon, Jan 11, 2021 at 10:16 PM Vit Mojzis <vmojzis@redhat.com> wrote:
> "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 "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>
> ---
>  python/sepolgen/src/sepolgen/refparser.py | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/python/sepolgen/src/sepolgen/refparser.py b/python/sepolgen/src/sepolgen/refparser.py
> index 9f850990..3c69904a 100644
> --- a/python/sepolgen/src/sepolgen/refparser.py
> +++ b/python/sepolgen/src/sepolgen/refparser.py
> @@ -434,7 +434,7 @@ 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
> +             | IFNDEF OPAREN TICK IDENTIFIER SQUOTE COMMA TICK statement SQUOTE CPAREN optional_semi
>               | IFDEF OPAREN TICK IDENTIFIER SQUOTE COMMA TICK interface_stmts SQUOTE COMMA TICK interface_stmts SQUOTE CPAREN optional_semi

IMHO we should be consistent and allow any statements also in ifdefs
(i.e. make an equivalent change in the line before and after).

>      '''
>      x = refpolicy.IfDef(p[4])
> --
> 2.29.2
>
diff mbox series

Patch

diff --git a/python/sepolgen/src/sepolgen/refparser.py b/python/sepolgen/src/sepolgen/refparser.py
index 9f850990..3c69904a 100644
--- a/python/sepolgen/src/sepolgen/refparser.py
+++ b/python/sepolgen/src/sepolgen/refparser.py
@@ -434,7 +434,7 @@  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
+             | IFNDEF OPAREN TICK IDENTIFIER SQUOTE COMMA TICK statement SQUOTE CPAREN optional_semi
              | IFDEF OPAREN TICK IDENTIFIER SQUOTE COMMA TICK interface_stmts SQUOTE COMMA TICK interface_stmts SQUOTE CPAREN optional_semi
     '''
     x = refpolicy.IfDef(p[4])