From patchwork Fri Nov 13 11:52:09 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Lautrbach X-Patchwork-Id: 7610991 Return-Path: X-Original-To: patchwork-selinux@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id D99FD9F1C2 for ; Fri, 13 Nov 2015 11:55:05 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 15DFE205DE for ; Fri, 13 Nov 2015 11:55:05 +0000 (UTC) Received: from emvm-gh1-uea09.nsa.gov (emvm-gh1-uea09.nsa.gov [63.239.67.10]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CD21F2054A for ; Fri, 13 Nov 2015 11:55:03 +0000 (UTC) X-TM-IMSS-Message-ID: <1c8a93eb00030c38@nsa.gov> Received: from tarius.tycho.ncsc.mil ([144.51.242.1]) by nsa.gov ([63.239.67.10]) with ESMTP (TREND IMSS SMTP Service 7.1) id 1c8a93eb00030c38 ; Fri, 13 Nov 2015 06:54:43 -0500 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 tADBqYO3023647; Fri, 13 Nov 2015 06:52:44 -0500 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 tADBqWGU251554 for ; Fri, 13 Nov 2015 06:52:32 -0500 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 tADBqWT0023644 for ; Fri, 13 Nov 2015 06:52:32 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A1B5AABEzkVWnBy3hNFeGQEBAg8BAQEBg15vrxoBjQ2EBAkXAoV3gURMAQEBAQEBEgEBAQEBCAsJCSGFYoEeM4guwV6GVIolghQMQYExBY0biS2FHYgKgiSMQ41egi1dgV5xhT0BAQE X-IPAS-Result: A1B5AABEzkVWnBy3hNFeGQEBAg8BAQEBg15vrxoBjQ2EBAkXAoV3gURMAQEBAQEBEgEBAQEBCAsJCSGFYoEeM4guwV6GVIolghQMQYExBY0biS2FHYgKgiSMQ41egi1dgV5xhT0BAQE X-IronPort-AV: E=Sophos;i="5.20,287,1444708800"; d="scan'208";a="4929851" Received: from emvm-gh1-uea09.nsa.gov ([63.239.67.10]) by goalie.tycho.ncsc.mil with ESMTP; 13 Nov 2015 06:52:23 -0500 X-TM-IMSS-Message-ID: <1c89b1c700030c26@nsa.gov> Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by nsa.gov ([63.239.67.10]) with ESMTP (TREND IMSS SMTP Service 7.1; TLSv1/SSLv3 ADH-AES256-SHA (256/256)) id 1c89b1c700030c26 ; Fri, 13 Nov 2015 06:53:45 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (Postfix) with ESMTPS id 83F22A14E2 for ; Fri, 13 Nov 2015 11:52:21 +0000 (UTC) Received: from hulk.com (ovpn-204-119.brq.redhat.com [10.40.204.119]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id tADBqJBn023388; Fri, 13 Nov 2015 06:52:20 -0500 From: Petr Lautrbach To: selinux@tycho.nsa.gov Subject: [PATCH] sepolgen: Use key function in sort() Date: Fri, 13 Nov 2015 12:52:09 +0100 Message-Id: <1447415529-7588-1-git-send-email-plautrba@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-TM-AS-MML: disable 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-Spam-Status: No, score=-7.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In Py3.0, the cmp parameter in sort() function was removed and key keyword is available since Py2.4. Fixes: # cat avc.log | audit2allow -R Traceback (most recent call last): File "/usr/bin/audit2allow", line 363, in app.main() File "/usr/bin/audit2allow", line 351, in main self.__output() File "/usr/bin/audit2allow", line 308, in __output g.set_gen_refpol(ifs, perm_maps) File "/usr/lib64/python3.4/site-packages/sepolgen/policygen.py", line 101, in set_gen_refpol self.ifgen = InterfaceGenerator(if_set, perm_maps) File "/usr/lib64/python3.4/site-packages/sepolgen/policygen.py", line 353, in __init__ self.hack_check_ifs(ifs) File "/usr/lib64/python3.4/site-packages/sepolgen/policygen.py", line 365, in hack_check_ifs params.sort(param_comp) TypeError: must use keyword argument for key function Signed-off-by: Petr Lautrbach --- sepolgen/src/sepolgen/policygen.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/sepolgen/src/sepolgen/policygen.py b/sepolgen/src/sepolgen/policygen.py index 4438a11..34c8401 100644 --- a/sepolgen/src/sepolgen/policygen.py +++ b/sepolgen/src/sepolgen/policygen.py @@ -36,8 +36,6 @@ from . import access from . import interfaces from . import matching from . import util -if util.PY3: - from .util import cmp # Constants for the level of explanation from the generation # routines NO_EXPLANATION = 0 @@ -278,15 +276,12 @@ def explain_access(av, ml=None, verbosity=SHORT_EXPLANATION): explain_interfaces() return s -def param_comp(a, b): - return cmp(b.num, a.num) - def call_interface(interface, av): params = [] args = [] params.extend(interface.params.values()) - params.sort(param_comp) + params.sort(key=lambda param: param.num, reverse=True) ifcall = refpolicy.InterfaceCall() ifcall.ifname = interface.name @@ -321,7 +316,7 @@ class InterfaceGenerator: for x in ifs.interfaces.values(): params = [] params.extend(x.params.values()) - params.sort(param_comp) + params.sort(key=lambda param: param.num, reverse=True) for i in range(len(params)): # Check that the paramater position matches # the number (e.g., $1 is the first arg). This