Re: [PATCH v2] python/sepolgen: allow any policy statement in if(n)def

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Jan 22, 2021 at 5:32 PM Ondrej Mosnacek <omosnace@xxxxxxxxxx> wrote:
> On Fri, Jan 22, 2021 at 4:29 PM Vit Mojzis <vmojzis@xxxxxxxxxx> 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@xxxxxxxxxx>
> > ---
> > 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@xxxxxxxxxx>

Merged:
https://github.com/SELinuxProject/selinux/commit/e12f71e82f523513c249dbe5a2e35c1916370992

-- 
Ondrej Mosnacek
Software Engineer, Platform Security - SELinux kernel
Red Hat, Inc.




[Index of Archives]     [Selinux Refpolicy]     [Linux SGX]     [Fedora Users]     [Fedora Desktop]     [Yosemite Photos]     [Yosemite Camping]     [Yosemite Campsites]     [KDE Users]     [Gnome Users]

  Powered by Linux