From patchwork Wed Nov 6 10:59:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Lautrbach X-Patchwork-Id: 11230015 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 29D551709 for ; Wed, 6 Nov 2019 10:59:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id EF838217F4 for ; Wed, 6 Nov 2019 10:59:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="DnpCYw4d" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725868AbfKFK7U (ORCPT ); Wed, 6 Nov 2019 05:59:20 -0500 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:24897 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725856AbfKFK7U (ORCPT ); Wed, 6 Nov 2019 05:59:20 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573037959; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=qKMHPiKMUKdHSFlHwTfjJQ1Vq+rHhX1LbBoditmi/zA=; b=DnpCYw4dyaP2+nFSzgTCeR+Flqku9jFNk5TMaUBBFjOadVMDhvgGwQRG5kYgUYb7QHmDnW tw/15/iZ1a5aNA+9FdFbZCSrBCXsV+IMsA+Xg6pkntSp+PNO3x2AzNmODPqBvQ3cri/ugS 7aL2CgCOOG5rvOcpiW8Wis9XE3xuYSg= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-33-t8iwsRUAMg2YU_8g44dmWg-1; Wed, 06 Nov 2019 05:59:15 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EB0B61800D53 for ; Wed, 6 Nov 2019 10:59:14 +0000 (UTC) Received: from workstation.brq.redhat.com (unknown [10.34.245.65]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1913A60852; Wed, 6 Nov 2019 10:59:13 +0000 (UTC) From: Petr Lautrbach To: selinux@vger.kernel.org Cc: Petr Lautrbach Subject: [PATCH] python/sepolicy: Revert "Only invoke RPM on RPM-enabled Linux distributions" Date: Wed, 6 Nov 2019 11:59:07 +0100 Message-Id: <20191106105907.1064568-1-plautrba@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-MC-Unique: t8iwsRUAMg2YU_8g44dmWg-1 X-Mimecast-Spam-Score: 0 Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org Commit 8ad76337d09d4b0080275d74392a258ea4ed0273 ("Only invoke RPM on RPM-enabled Linux distributions") used platform.linux_distribution() function to detect whether the system is rpm based. This function is deprecated since Python 3.5 and it's removed from Python 3.8 - https://bugs.python.org/issue28167 The original problem is already fixed by another commit 671f83b42ba2 ("policycoreutils/sepolicy: Check get_rpm_nvr_list() return value"): $ sepolicy generate --customize -p mypolicy -n testpolicy -d httpd_sys_script_t -w /home Failed to retrieve rpm info for selinux-policy Created the following files: mypolicy/testpolicy.te # Type Enforcement file mypolicy/testpolicy.if # Interface file mypolicy/testpolicy.fc # File Contexts file mypolicy/testpolicy_selinux.spec # Spec file mypolicy/testpolicy.sh # Setup Script Fixes: File "/usr/lib/python3.8/site-packages/sepolicy/generate.py", line 1384, in generate if (platform.linux_distribution(full_distribution_name=0)[0] in ("redhat", "centos", "SuSE", "fedora", "mandrake", "mandriva")): AttributeError: module 'platform' has no attribute 'linux_distribution' Signed-off-by: Petr Lautrbach Acked-by: Stephen Smalley --- python/sepolicy/sepolicy/generate.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/python/sepolicy/sepolicy/generate.py b/python/sepolicy/sepolicy/generate.py index 973edb9d..e8d07e7d 100644 --- a/python/sepolicy/sepolicy/generate.py +++ b/python/sepolicy/sepolicy/generate.py @@ -26,7 +26,6 @@ import re import sepolicy from sepolicy import get_all_types, get_all_attributes, get_all_roles import time -import platform from .templates import executable from .templates import boolean @@ -1178,8 +1177,7 @@ allow %s_t %s_t:%s_socket name_%s; newsh += re.sub("TEMPLATETYPE", self.name, t1) newsh += self.generate_user_sh() - if (platform.linux_distribution(full_distribution_name=0)[0] in ("redhat", "centos", "SuSE", "fedora", "mandrake", "mandriva")): - newsh += re.sub("TEMPLATEFILE", self.file_name, script.rpm) + newsh += re.sub("TEMPLATEFILE", self.file_name, script.rpm) return newsh @@ -1379,7 +1377,6 @@ Warning %s does not exist out += "%s # %s\n" % (self.write_if(out_dir), _("Interface file")) out += "%s # %s\n" % (self.write_fc(out_dir), _("File Contexts file")) if self.type != NEWTYPE: - if (platform.linux_distribution(full_distribution_name=0)[0] in ("redhat", "centos", "SuSE", "fedora", "mandrake", "mandriva")): - out += "%s # %s\n" % (self.write_spec(out_dir), _("Spec file")) + out += "%s # %s\n" % (self.write_spec(out_dir), _("Spec file")) out += "%s # %s\n" % (self.write_sh(out_dir), _("Setup Script")) return out