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 v2 3/3] python/semanage module: Fix handling of -a/-e/-d/-r options
Date: Sun, 17 Feb 2019 21:42:52 +0100	[thread overview]
Message-ID: <CAJfZ7=nsFTKC4upjKETSDC0bgmYCvQZg5tTte_KcTH8Kxe5ucA@mail.gmail.com> (raw)
In-Reply-To: <20190215160025.9810-3-plautrba@redhat.com>

On Fri, Feb 15, 2019 at 5:00 PM Petr Lautrbach <plautrba@redhat.com> wrote:
>
> Previous code traceback-ed when one of the mentioned option was used without
> any argument as this state was not handled by the argument parser.
>
> action='store' stores arguments as a list while the original
> action='store_const' used str therefore it's needed to convert list to str
> before it's sent to moduleRecords class.
>
> Fixes:
> ^_^ semanage module -a
> Traceback (most recent call last):
>   File "/usr/sbin/semanage", line 963, in <module>
>     do_parser()
>   File "/usr/sbin/semanage", line 942, in do_parser
>     args.func(args)
>   File "/usr/sbin/semanage", line 608, in handleModule
>     OBJECT.add(args.module_name, args.priority)
>   File "/usr/lib/python3.7/site-packages/seobject.py", line 402, in add
>     if not os.path.exists(file):
>   File "/usr/lib64/python3.7/genericpath.py", line 19, in exists
>     os.stat(path)
> TypeError: stat: path should be string, bytes, os.PathLike or integer, not NoneType
>
> Signed-off-by: Petr Lautrbach <plautrba@redhat.com>

For the three patches: Acked-by: Nicolas Iooss <nicolas.iooss@m4x.org>

> ---
>  python/semanage/semanage | 25 ++++++++++++-------------
>  1 file changed, 12 insertions(+), 13 deletions(-)
>
> diff --git a/python/semanage/semanage b/python/semanage/semanage
> index 18191c13..d6d68248 100644
> --- a/python/semanage/semanage
> +++ b/python/semanage/semanage
> @@ -609,14 +609,14 @@ def setupInterfaceParser(subparsers):
>
>  def handleModule(args):
>      OBJECT = seobject.moduleRecords(args)
> -    if args.action == "add":
> -        OBJECT.add(args.module_name, args.priority)
> -    if args.action == "enable":
> -        OBJECT.set_enabled(args.module_name, True)
> -    if args.action == "disable":
> -        OBJECT.set_enabled(args.module_name, False)
> -    if args.action == "remove":
> -        OBJECT.delete(args.module_name, args.priority)
> +    if args.action_add:
> +        OBJECT.add(args.action_add[0], args.priority)
> +    if args.action_enable:
> +        OBJECT.set_enabled(" ".join(args.action_enable), True)
> +    if args.action_disable:
> +        OBJECT.set_enabled(" ".join(args.action_disable), False)
> +    if args.action_remove:
> +        OBJECT.delete(" ".join(args.action_remove), args.priority)
>      if args.action == "deleteall":
>          OBJECT.deleteall()
>      if args.action == "list":
> @@ -635,14 +635,13 @@ def setupModuleParser(subparsers):
>      parser_add_priority(moduleParser, "module")
>
>      mgroup = moduleParser.add_mutually_exclusive_group(required=True)
> -    parser_add_add(mgroup, "module")
>      parser_add_list(mgroup, "module")
>      parser_add_extract(mgroup, "module")
>      parser_add_deleteall(mgroup, "module")
> -    mgroup.add_argument('-r', '--remove', dest='action', action='store_const', const='remove', help=_("Remove a module"))
> -    mgroup.add_argument('-d', '--disable', dest='action', action='store_const', const='disable', help=_("Disable a module"))
> -    mgroup.add_argument('-e', '--enable', dest='action', action='store_const', const='enable', help=_("Enable a module"))
> -    moduleParser.add_argument('module_name', nargs='?', default=None, help=_('Name of the module to act on'))
> +    mgroup.add_argument('-a', '--add', dest='action_add', action='store', nargs=1, metavar='module_name', help=_("Add a module"))
> +    mgroup.add_argument('-r', '--remove', dest='action_remove', action='store', nargs='+', metavar='module_name', help=_("Remove a module"))
> +    mgroup.add_argument('-d', '--disable', dest='action_disable', action='store', nargs='+', metavar='module_name', help=_("Disable a module"))
> +    mgroup.add_argument('-e', '--enable', dest='action_enable', action='store', nargs='+', metavar='module_name', help=_("Enable a module"))
>      moduleParser.set_defaults(func=handleModule)
>
>
> --
> 2.20.1
>


  reply	other threads:[~2019-02-17 20:43 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-06 19:43 [PATCH 1/2] python/semanage module: Fix handling of -a/-e/-d/-r options Petr Lautrbach
2019-02-06 19:43 ` [PATCH 2/2] python/semanage: Use standard argparse.error() method in handlePermissive Petr Lautrbach
2019-02-07 21:47   ` Nicolas Iooss
2019-02-10 16:51     ` Nicolas Iooss
2019-02-07 21:46 ` [PATCH 1/2] python/semanage module: Fix handling of -a/-e/-d/-r options Nicolas Iooss
2019-02-15 14:28   ` Petr Lautrbach
2019-02-15 16:00     ` [PATCH v2 1/3] python/semanage: Drop python shebang from seobject.py Petr Lautrbach
2019-02-15 16:00       ` [PATCH v2 2/3] python/semanage: Update semanage to use python3 Petr Lautrbach
2019-02-15 16:00       ` [PATCH v2 3/3] python/semanage module: Fix handling of -a/-e/-d/-r options Petr Lautrbach
2019-02-17 20:42         ` Nicolas Iooss [this message]
2019-02-19 22:07           ` Nicolas Iooss
2019-02-17 20:41     ` [PATCH 1/2] " 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=nsFTKC4upjKETSDC0bgmYCvQZg5tTte_KcTH8Kxe5ucA@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).