From patchwork Tue Aug 2 13:40:28 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Lautrbach X-Patchwork-Id: 9257433 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4091C6077C for ; Tue, 2 Aug 2016 13:44:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 31BCF28534 for ; Tue, 2 Aug 2016 13:44:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2625328536; Tue, 2 Aug 2016 13:44:30 +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=-1.9 required=2.0 tests=BAYES_00 autolearn=ham version=3.3.1 Received: from emsm-gh1-uea10.nsa.gov (emsm-gh1-uea10.nsa.gov [8.44.101.8]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 25F5928534 for ; Tue, 2 Aug 2016 13:44:28 +0000 (UTC) Received: from unknown (HELO tarius.tycho.ncsc.mil) ([144.51.242.1]) by emsm-gh1-uea10.nsa.gov with ESMTP; 02 Aug 2016 13:44:06 +0000 Received: from prometheus.infosec.tycho.ncsc.mil (prometheus [192.168.25.40]) by tarius.tycho.ncsc.mil (8.14.4/8.14.4) with ESMTP id u72DehY9021865; Tue, 2 Aug 2016 09:41:50 -0400 Received: from tarius.tycho.ncsc.mil (tarius.infosec.tycho.ncsc.mil [144.51.242.1]) by prometheus.infosec.tycho.ncsc.mil (8.15.2/8.15.2) with ESMTP id u72DeeG4214197 for ; Tue, 2 Aug 2016 09:40:40 -0400 Received: from goalie.tycho.ncsc.mil (goalie [144.51.242.250]) by tarius.tycho.ncsc.mil (8.14.4/8.14.4) with ESMTP id u72Dee68021862 for ; Tue, 2 Aug 2016 09:40:40 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A1DNAABjnaBXhxy3hNFdHQGEeaYGggIBjxGEDBSGCYE9TAEBAQEBARMBAQEKCwkJGYYNSQGBB4gxwFaGKolVAYUSBZkzi3iDBwKPOwKQJ4IVYoFZOjKGVA0XgR8BAQE X-IPAS-Result: A1DNAABjnaBXhxy3hNFdHQGEeaYGggIBjxGEDBSGCYE9TAEBAQEBARMBAQEKCwkJGYYNSQGBB4gxwFaGKolVAYUSBZkzi3iDBwKPOwKQJ4IVYoFZOjKGVA0XgR8BAQE X-IronPort-AV: E=Sophos;i="5.28,460,1464667200"; d="scan'208";a="5617586" Received: from emsm-gh1-uea11.corp.nsa.gov (HELO emsm-gh1-uea11.nsa.gov) ([10.208.41.37]) by goalie.tycho.ncsc.mil with ESMTP; 02 Aug 2016 09:40:38 -0400 Received: from mx1.redhat.com ([209.132.183.28]) by emsm-gh1-uea11.nsa.gov with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 02 Aug 2016 13:40:37 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 29A7F61E66 for ; Tue, 2 Aug 2016 13:40:36 +0000 (UTC) Received: from rhel-at-redhat.localdomain.com ([10.40.2.167]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u72DeYfG031066; Tue, 2 Aug 2016 09:40:35 -0400 From: Petr Lautrbach To: selinux@tycho.nsa.gov Subject: [PATCH] policycoreutils: Don't use subprocess.getstatusoutput() in Python 2 code Date: Tue, 2 Aug 2016 15:40:28 +0200 Message-Id: <1470145228-21229-1-git-send-email-plautrba@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 02 Aug 2016 13:40:36 +0000 (UTC) X-BeenThere: selinux@tycho.nsa.gov X-Mailman-Version: 2.1.20 Precedence: list List-Id: "Security-Enhanced Linux \(SELinux\) mailing list" List-Post: List-Help: MIME-Version: 1.0 Errors-To: selinux-bounces@tycho.nsa.gov Sender: "Selinux" X-Virus-Scanned: ClamAV using ClamSMTP The commit 7574a50f tried to improve compatibility with Python 3. It changed the code to use subprocess.getstatusoutput() instead of commands.getstatusoutput(). Unfortunately subprocess.getstatusoutput() is not available in Python 2. This patch changes how getstatusoutput() is imported so the code works on Python 2 and Python 3. Fixes: $ chcat -d something Traceback (most recent call last): File "/usr/bin/chcat", line 432, in sys.exit(chcat_replace(["s0"], cmds, login_ind)) File "/usr/bin/chcat", line 271, in chcat_replace rc = subprocess.getstatusoutput(cmd) AttributeError: 'module' object has no attribute 'getstatusoutput' Signed-off-by: Petr Lautrbach --- policycoreutils/sandbox/start | 8 +++++--- policycoreutils/scripts/chcat | 17 ++++++++++------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/policycoreutils/sandbox/start b/policycoreutils/sandbox/start index fc406e1..7f83532 100644 --- a/policycoreutils/sandbox/start +++ b/policycoreutils/sandbox/start @@ -1,10 +1,12 @@ #! /usr/bin/python -Es -import gtk -import subprocess +try: + from subprocess import getstatusoutput +except ImportError: + from commands import getstatusoutput import sys rc = [-1, ''] try: - rc = subprocess.getstatusoutput(sys.argv[1]) + rc = getstatusoutput(sys.argv[1]) except: pass if rc[0] == 0: diff --git a/policycoreutils/scripts/chcat b/policycoreutils/scripts/chcat index 267390e..f33a0ea 100755 --- a/policycoreutils/scripts/chcat +++ b/policycoreutils/scripts/chcat @@ -22,7 +22,10 @@ # 02111-1307 USA # # -import subprocess +try: + from subprocess import getstatusoutput +except ImportError: + from commands import getstatusoutput import sys import os import pwd @@ -92,7 +95,7 @@ def chcat_user_add(newcat, users): cmd = "semanage login -a -r %s -s %s %s" % (new_serange, user[0], u) else: cmd = "semanage login -m -r %s -s %s %s" % (new_serange, user[0], u) - rc = subprocess.getstatusoutput(cmd) + rc = getstatusoutput(cmd) if rc[0] != 0: print(rc[1]) errors += 1 @@ -131,7 +134,7 @@ def chcat_add(orig, newcat, objects, login_ind): else: cat_string = cat cmd = 'chcon -l %s:%s %s' % (sensitivity, cat_string, f) - rc = subprocess.getstatusoutput(cmd) + rc = getstatusoutput(cmd) if rc[0] != 0: print(rc[1]) errors += 1 @@ -172,7 +175,7 @@ def chcat_user_remove(newcat, users): cmd = "semanage login -a -r %s -s %s %s" % (new_serange, user[0], u) else: cmd = "semanage login -m -r %s -s %s %s" % (new_serange, user[0], u) - rc = subprocess.getstatusoutput(cmd) + rc = getstatusoutput(cmd) if rc[0] != 0: print(rc[1]) errors += 1 @@ -217,7 +220,7 @@ def chcat_remove(orig, newcat, objects, login_ind): cmd = 'chcon -l %s %s' % (sensitivity, f) else: cmd = 'chcon -l %s:%s %s' % (sensitivity, cat, f) - rc = subprocess.getstatusoutput(cmd) + rc = getstatusoutput(cmd) if rc[0] != 0: print(rc[1]) errors += 1 @@ -245,7 +248,7 @@ def chcat_user_replace(newcat, users): cmd = "semanage login -a -r %s -s %s %s" % (new_serange, user[0], u) else: cmd = "semanage login -m -r %s -s %s %s" % (new_serange, user[0], u) - rc = subprocess.getstatusoutput(cmd) + rc = getstatusoutput(cmd) if rc[0] != 0: print(rc[1]) errors += 1 @@ -268,7 +271,7 @@ def chcat_replace(newcat, objects, login_ind): for f in objects: cmd = "%s %s" % (cmd, f) - rc = subprocess.getstatusoutput(cmd) + rc = getstatusoutput(cmd) if rc[0] != 0: print(rc[1]) errors += 1