selinux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Vit Mojzis <vmojzis@redhat.com>
To: selinux@vger.kernel.org
Subject: Re: [PATCH 2/3] python/sepolicy: Stop rejecting aliases in sepolicy commands
Date: Mon, 22 Oct 2018 17:40:01 +0200	[thread overview]
Message-ID: <20181022154003.19309-1-vmojzis@redhat.com> (raw)
In-Reply-To: <CAJfZ7=nSsAKJ=MB6HiZ3mDE3kVa4Yx8imkVDsq-ngC-2O8Vfpg@mail.gmail.com>

On 21. 10. 18 11:20, Nicolas Iooss wrote:> On Sun, Oct 21, 2018 at 11:10 AM Nicolas Iooss <nicolas.iooss@m4x.org> wrote:
>>
>> On Tue, Oct 16, 2018 at 12:05 PM Vit Mojzis <vmojzis@redhat.com> wrote:
>>>
>>> Fix CheckDomain and CheckPortType classes to properly deal with aliases.
>>>
>>> Resolves:
>>>     https://bugzilla.redhat.com/show_bug.cgi?id=1600009
>>>
>>> Signed-off-by: Vit Mojzis <vmojzis@redhat.com>
>>> ---
>>>   python/sepolicy/sepolicy.py          |  8 +++-----
>>>   python/sepolicy/sepolicy/__init__.py | 10 +++++++++-
>>>   2 files changed, 12 insertions(+), 6 deletions(-)
>>>
>> [...]
>>> diff --git a/python/sepolicy/sepolicy/__init__.py b/python/sepolicy/sepolicy/__init__.py
>>> index 8484b28c..0da3917b 100644
>>> --- a/python/sepolicy/sepolicy/__init__.py
>>> +++ b/python/sepolicy/sepolicy/__init__.py
>>> @@ -447,6 +447,14 @@ def get_file_types(setype):
>>>       return mpaths
>>>
>>>
>>> +# determine if entered type is an alias
>>> +# and return corresponding type name
>>> +def get_real_type_name(name):
>>> +    try:
>>> +        return next(info(TYPE, name))["name"]
>>> +    except (RuntimeError, StopIteration):
>>> +        return None
>>> +
>>
>> When I first read the function comment, I did not understand whether
>> the returned value was a kind of SELinux type (like something which
>> would say "a file type", "a port type") or the SELinux type which is
>> aliased. It is the second interpretation which is implemented.
>> Moreover, this comment seems to be better in a function docstring. I
>> suggest changing this into the following:
>>
>> def get_real_type_name(name):
>>      """Return the real name of a type:
>>
>>      * If 'name' refers to a type, return the same name.
>>      * If 'name' refers to a type alias, return the corresponding name.
>>      * Otherwise return None.
>>      """
>>
>> What do you think of this suggestion?
>>
>> Moreover, when is RuntimeError triggered, in the exception that are caught?

Catching RuntimeError ensures compatibility with setools3, which
triggers this exception instead of returning empty list.

> 
> Also, if name is empty, sepolicy.info(TYPE, name) returns all
> available types, so get_real_type_name("") returns the first type in
> the list of types defined in the policy. I saw that your patches use
> "if setype and sepolicy.get_real_type_name(setype) not in
> self.valid_types" in many places (which looks good). To increase the
> robustness of the Python code, I would also add a test in
> get_real_type_name as well, like:
> 
>      if not name:
>          return None

Good point, thank you.

> 
> Nicolas
> 



  reply	other threads:[~2018-10-22 15:40 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-16 10:05 Fix alias handling in sepolicy and semanage Vit Mojzis
2018-10-16 10:05 ` [PATCH 1/3] python/sepolicy: Fix "info" to search aliases as well Vit Mojzis
2018-10-16 10:05 ` [PATCH 2/3] python/sepolicy: Stop rejecting aliases in sepolicy commands Vit Mojzis
2018-10-21  9:10   ` Nicolas Iooss
2018-10-21  9:20     ` Nicolas Iooss
2018-10-22 15:40       ` Vit Mojzis [this message]
2018-10-22 15:43       ` Vit Mojzis
2018-10-22 17:53         ` Nicolas Iooss
2018-10-23 19:23           ` Nicolas Iooss
2018-10-30 15:26             ` Vit Mojzis
2018-10-30 15:26               ` [PATCH] python: replace aliases with corresponding type names Vit Mojzis
2018-11-05 20:51                 ` Nicolas Iooss
2018-11-09  8:53                   ` Vit Mojzis
2018-11-11 20:48                     ` Nicolas Iooss
2018-10-16 10:05 ` [PATCH 3/3] python/semanage: Stop rejecting aliases in semanage commands Vit Mojzis

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=20181022154003.19309-1-vmojzis@redhat.com \
    --to=vmojzis@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).