From patchwork Fri Feb 15 16:00:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Lautrbach X-Patchwork-Id: 10815141 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1248413A4 for ; Fri, 15 Feb 2019 16:00:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 010792F9DC for ; Fri, 15 Feb 2019 16:00:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E93972F9E7; Fri, 15 Feb 2019 16:00:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 967D72F9E0 for ; Fri, 15 Feb 2019 16:00:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391023AbfBOQAd (ORCPT ); Fri, 15 Feb 2019 11:00:33 -0500 Received: from mx1.redhat.com ([209.132.183.28]:33002 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390625AbfBOQAd (ORCPT ); Fri, 15 Feb 2019 11:00:33 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E94BF13982C for ; Fri, 15 Feb 2019 16:00:32 +0000 (UTC) Received: from workstation.redhat.com (unknown [10.40.205.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 194595C3FD; Fri, 15 Feb 2019 16:00:31 +0000 (UTC) From: Petr Lautrbach To: selinux@vger.kernel.org Cc: Petr Lautrbach Subject: [PATCH v2 1/3] python/semanage: Drop python shebang from seobject.py Date: Fri, 15 Feb 2019 17:00:23 +0100 Message-Id: <20190215160025.9810-1-plautrba@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 15 Feb 2019 16:00:33 +0000 (UTC) Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP seobject.py is not supposed to be used as entrypoint therefore the shebang is unnecessary. It also doesn't need execute bits. Signed-off-by: Petr Lautrbach --- python/semanage/Makefile | 2 +- python/semanage/seobject.py | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/python/semanage/Makefile b/python/semanage/Makefile index 2e262ef8..37065268 100644 --- a/python/semanage/Makefile +++ b/python/semanage/Makefile @@ -27,7 +27,7 @@ install: all fi ; \ done test -d $(DESTDIR)/$(PACKAGEDIR) || install -m 755 -d $(DESTDIR)/$(PACKAGEDIR) - install -m 755 seobject.py $(DESTDIR)/$(PACKAGEDIR) + install -m 644 seobject.py $(DESTDIR)/$(PACKAGEDIR) -mkdir -p $(DESTDIR)$(BASHCOMPLETIONDIR) install -m 644 $(BASHCOMPLETIONS) $(DESTDIR)$(BASHCOMPLETIONDIR)/semanage diff --git a/python/semanage/seobject.py b/python/semanage/seobject.py index b31a90c1..13fdf531 100644 --- a/python/semanage/seobject.py +++ b/python/semanage/seobject.py @@ -1,4 +1,3 @@ -#! /usr/bin/python -Es # Copyright (C) 2005-2013 Red Hat # see file 'COPYING' for use and warranty information # From patchwork Fri Feb 15 16:00:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Lautrbach X-Patchwork-Id: 10815145 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9581913A4 for ; Fri, 15 Feb 2019 16:00:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 85D392F9D3 for ; Fri, 15 Feb 2019 16:00:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7A9AA2F9E0; Fri, 15 Feb 2019 16:00:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 296892F9D3 for ; Fri, 15 Feb 2019 16:00:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390625AbfBOQAk (ORCPT ); Fri, 15 Feb 2019 11:00:40 -0500 Received: from mx1.redhat.com ([209.132.183.28]:44544 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389873AbfBOQAk (ORCPT ); Fri, 15 Feb 2019 11:00:40 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8D820C794C for ; Fri, 15 Feb 2019 16:00:40 +0000 (UTC) Received: from workstation.redhat.com (unknown [10.40.205.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id A577217AF9; Fri, 15 Feb 2019 16:00:39 +0000 (UTC) From: Petr Lautrbach To: selinux@vger.kernel.org Cc: Petr Lautrbach Subject: [PATCH v2 2/3] python/semanage: Update semanage to use python3 Date: Fri, 15 Feb 2019 17:00:24 +0100 Message-Id: <20190215160025.9810-2-plautrba@redhat.com> In-Reply-To: <20190215160025.9810-1-plautrba@redhat.com> References: <20190215160025.9810-1-plautrba@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 15 Feb 2019 16:00:40 +0000 (UTC) Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP semanage uses seobject which uses setools which is python 3 only. Signed-off-by: Petr Lautrbach --- python/semanage/semanage | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/semanage/semanage b/python/semanage/semanage index 4b544bfc..18191c13 100644 --- a/python/semanage/semanage +++ b/python/semanage/semanage @@ -1,4 +1,4 @@ -#! /usr/bin/python -Es +#! /usr/bin/python3 -Es # Copyright (C) 2012-2013 Red Hat # AUTHOR: Miroslav Grepl # AUTHOR: David Quigley From patchwork Fri Feb 15 16:00:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Lautrbach X-Patchwork-Id: 10815147 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1C3ED6C2 for ; Fri, 15 Feb 2019 16:00:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0BB952F9CB for ; Fri, 15 Feb 2019 16:00:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F41852F9E0; Fri, 15 Feb 2019 16:00:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8BA5C2F9CB for ; Fri, 15 Feb 2019 16:00:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390989AbfBOQAt (ORCPT ); Fri, 15 Feb 2019 11:00:49 -0500 Received: from mx1.redhat.com ([209.132.183.28]:49388 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389873AbfBOQAt (ORCPT ); Fri, 15 Feb 2019 11:00:49 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 52EFCAD89E for ; Fri, 15 Feb 2019 16:00:48 +0000 (UTC) Received: from workstation.redhat.com (unknown [10.40.205.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 630525C21E; Fri, 15 Feb 2019 16:00:47 +0000 (UTC) From: Petr Lautrbach To: selinux@vger.kernel.org Cc: Petr Lautrbach Subject: [PATCH v2 3/3] python/semanage module: Fix handling of -a/-e/-d/-r options Date: Fri, 15 Feb 2019 17:00:25 +0100 Message-Id: <20190215160025.9810-3-plautrba@redhat.com> In-Reply-To: <20190215160025.9810-1-plautrba@redhat.com> References: <20190215160025.9810-1-plautrba@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Fri, 15 Feb 2019 16:00:48 +0000 (UTC) Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 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 --- 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)