selinux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nicolas Iooss <nicolas.iooss@m4x.org>
To: Petr Lautrbach <plautrba@redhat.com>
Cc: selinux@vger.kernel.org
Subject: Re: [PATCH 1/4] python/semanage: move valid_types initialisations to class constructors
Date: Thu, 20 Dec 2018 23:34:53 +0100	[thread overview]
Message-ID: <CAJfZ7=nuM-z=P8n-V+C7GT+mWWYv59rGre-kxky2-mpRw-2Rmg@mail.gmail.com> (raw)
In-Reply-To: <20181220151420.30878-2-plautrba@redhat.com>

On Thu, Dec 20, 2018 at 4:14 PM Petr Lautrbach <plautrba@redhat.com> wrote:
>
> Based on idea from Nicolas Iooss <nicolas.iooss@m4x.org>
>
> Fixes:
> $ sudo semanage
> Traceback (most recent call last):
>   File "/usr/sbin/semanage", line 28, in <module>
>     import seobject
>   File "/usr/lib/python3.7/site-packages/seobject.py", line 1045, in <module>
>     class portRecords(semanageRecords):
>   File "/usr/lib/python3.7/site-packages/seobject.py", line 1047, in portRecords
>     valid_types = list(list(sepolicy.info(sepolicy.ATTRIBUTE, "port_type"))[0]["types"])
>   File "/usr/lib/python3.7/site-packages/sepolicy/__init__.py", line 203, in <genexpr>
>     return ({
>   File "/usr/lib64/python3.7/site-packages/setools/typeattrquery.py", line 65, in results
>     for attr in self.policy.typeattributes():
> AttributeError: 'NoneType' object has no attribute 'typeattributes'
>
> https://github.com/SELinuxProject/selinux/issues/81
>
> Signed-off-by: Petr Lautrbach <plautrba@redhat.com>

Why are classes ibpkeyRecords and ibendportRecords not covered by the
changes from this patch?

Nicolas

> ---
>  python/semanage/seobject.py | 33 ++++++++++++++++++++-------------
>  1 file changed, 20 insertions(+), 13 deletions(-)
>
> diff --git a/python/semanage/seobject.py b/python/semanage/seobject.py
> index efec0a55..2b43b65c 100644
> --- a/python/semanage/seobject.py
> +++ b/python/semanage/seobject.py
> @@ -1043,13 +1043,15 @@ class seluserRecords(semanageRecords):
>
>
>  class portRecords(semanageRecords):
> -    try:
> -        valid_types = list(list(sepolicy.info(sepolicy.ATTRIBUTE, "port_type"))[0]["types"])
> -    except RuntimeError:
> -        valid_types = []
> +
> +    valid_types = []
>
>      def __init__(self, args = None):
>          semanageRecords.__init__(self, args)
> +        try:
> +            self.valid_types = list(list(sepolicy.info(sepolicy.ATTRIBUTE, "port_type"))[0]["types"])
> +        except RuntimeError:
> +            pass
>
>      def __genkey(self, port, proto):
>          if proto == "tcp":
> @@ -1823,14 +1825,16 @@ class ibendportRecords(semanageRecords):
>              print(rec)
>
>  class nodeRecords(semanageRecords):
> -    try:
> -        valid_types = list(list(sepolicy.info(sepolicy.ATTRIBUTE, "node_type"))[0]["types"])
> -    except RuntimeError:
> -        valid_types = []
> +
> +    valid_types = []
>
>      def __init__(self, args = None):
>          semanageRecords.__init__(self, args)
>          self.protocol = ["ipv4", "ipv6"]
> +        try:
> +            self.valid_types = list(list(sepolicy.info(sepolicy.ATTRIBUTE, "node_type"))[0]["types"])
> +        except RuntimeError:
> +            pass
>
>      def validate(self, addr, mask, protocol):
>          newaddr = addr
> @@ -2264,14 +2268,17 @@ class interfaceRecords(semanageRecords):
>
>
>  class fcontextRecords(semanageRecords):
> -    try:
> -        valid_types = list(list(sepolicy.info(sepolicy.ATTRIBUTE, "file_type"))[0]["types"])
> -        valid_types += list(list(sepolicy.info(sepolicy.ATTRIBUTE, "device_node"))[0]["types"])
> -    except RuntimeError:
> -        valid_types = []
> +
> +    valid_types = []
>
>      def __init__(self, args = None):
>          semanageRecords.__init__(self, args)
> +        try:
> +            self.valid_types = list(list(sepolicy.info(sepolicy.ATTRIBUTE, "file_type"))[0]["types"])
> +            self.valid_types += list(list(sepolicy.info(sepolicy.ATTRIBUTE, "device_node"))[0]["types"])
> +        except RuntimeError:
> +            pass
> +
>          self.equiv = {}
>          self.equiv_dist = {}
>          self.equal_ind = False
> --
> 2.20.1
>


  reply	other threads:[~2018-12-20 22:35 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-20 15:14 Fix semanage in envinronment without default policy or when -S <store> is used Petr Lautrbach
2018-12-20 15:14 ` [PATCH 1/4] python/semanage: move valid_types initialisations to class constructors Petr Lautrbach
2018-12-20 22:34   ` Nicolas Iooss [this message]
2019-01-02 13:14     ` Petr Lautrbach
2018-12-20 15:14 ` [PATCH 2/4] python/semanage: import sepolicy only when it's needed Petr Lautrbach
2018-12-20 15:14 ` [PATCH 3/4] python/sepolicy: Add sepolicy.load_store_policy(store) Petr Lautrbach
2018-12-20 21:55   ` Nicolas Iooss
2019-01-02 14:13     ` Petr Lautrbach
2018-12-20 15:14 ` [PATCH 4/4] python/semanage: Load a store policy and set the store SELinux policy root Petr Lautrbach
2019-01-03 12:03 ` [PATCH v2 1/5] python/semanage: move valid_types initialisations to class constructors Petr Lautrbach
2019-01-03 12:03   ` [PATCH v2 2/5] python/semanage: import sepolicy only when it's needed Petr Lautrbach
2019-01-03 12:03   ` [PATCH v2 3/5] python/sepolicy: Add sepolicy.load_store_policy(store) Petr Lautrbach
2019-01-03 12:03   ` [PATCH v2 4/5] python/semanage: Load a store policy and set the store SELinux policy root Petr Lautrbach
2019-01-03 12:03   ` [PATCH v2 5/5] python/sepolicy: Make policy files sorting more robust Petr Lautrbach
2019-01-05 14:43     ` Nicolas Iooss

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAJfZ7=nuM-z=P8n-V+C7GT+mWWYv59rGre-kxky2-mpRw-2Rmg@mail.gmail.com' \
    --to=nicolas.iooss@m4x.org \
    --cc=plautrba@redhat.com \
    --cc=selinux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).