From patchwork Tue Nov 15 19:45:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Lautrbach X-Patchwork-Id: 13044097 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EAE50C43219 for ; Tue, 15 Nov 2022 19:47:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229941AbiKOTrG (ORCPT ); Tue, 15 Nov 2022 14:47:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44190 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231560AbiKOTrC (ORCPT ); Tue, 15 Nov 2022 14:47:02 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB2C711C15 for ; Tue, 15 Nov 2022 11:46:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668541560; 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=/hhVm+1kQrr6wMDW9q/3qFYlNPpyRaBGpD06r8nbebA=; b=DoceKzdfQJkSdbb72tf9E5Ylvjo/Q3ux3E9CG6gi53v5hJ5yG54/IetQMQlR/bC2MBRkWN /NEHgbwE5qj1RcnPKS4MPy9Pn141B2uUV0fna5KNWZvCFyiaIk05N1CDRFsNVZUZQ9l68F QaP3LbT35SoQDGXAfB0EVughmdE3z9A= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-640-q8FM_wW1NgWNxvPK71tfbg-1; Tue, 15 Nov 2022 14:45:58 -0500 X-MC-Unique: q8FM_wW1NgWNxvPK71tfbg-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 123DF185A78B for ; Tue, 15 Nov 2022 19:45:58 +0000 (UTC) Received: from localhost.localdomain (ovpn-195-4.brq.redhat.com [10.40.195.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 62BAA112131E; Tue, 15 Nov 2022 19:45:57 +0000 (UTC) From: Petr Lautrbach To: selinux@vger.kernel.org Cc: Petr Lautrbach Subject: [PATCH v2 1/3] python/sepolicy: Fix sepolicy manpage -w ... Date: Tue, 15 Nov 2022 20:45:50 +0100 Message-Id: <20221115194552.338640-1-plautrba@redhat.com> MIME-Version: 1.0 Content-type: text/plain X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org From: Petr Lautrbach Commit 7494bb1298b3 ("sepolicy: generate man pages in parallel") improved sepolicy performance but broke `sepolicy manpage -w ...` as it didn't collect data about domains and roles from ManPage() and so HTMLManPages() generated only empty page. This is fixed now, domains and roles are being collected and used for HTML pages. Signed-off-by: Petr Lautrbach Acked-by: James Carter --- python/sepolicy/sepolicy.py | 13 +++++++++++-- python/sepolicy/sepolicy/manpage.py | 12 +++++------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/python/sepolicy/sepolicy.py b/python/sepolicy/sepolicy.py index 733d40484709..2ca02ee9a0cf 100755 --- a/python/sepolicy/sepolicy.py +++ b/python/sepolicy/sepolicy.py @@ -332,9 +332,10 @@ def manpage_work(domain, path, root, source_files, web): from sepolicy.manpage import ManPage m = ManPage(domain, path, root, source_files, web) print(m.get_man_page_path()) + return (m.manpage_domains, m.manpage_roles) def manpage(args): - from sepolicy.manpage import HTMLManPages, manpage_domains, manpage_roles, gen_domains + from sepolicy.manpage import HTMLManPages, gen_domains path = args.path if not args.policy and args.root != "/": @@ -347,9 +348,17 @@ def manpage(args): else: test_domains = args.domain + manpage_domains = set() + manpage_roles = set() p = Pool() + async_results = [] for domain in test_domains: - p.apply_async(manpage_work, [domain, path, args.root, args.source_files, args.web]) + async_results.append(p.apply_async(manpage_work, [domain, path, args.root, args.source_files, args.web])) + results = map(lambda x: x.get(), async_results) + for result in results: + manpage_domains.update(set(result[0])) + manpage_roles.update(set(result[1])) + p.close() p.join() diff --git a/python/sepolicy/sepolicy/manpage.py b/python/sepolicy/sepolicy/manpage.py index 3e61e333193f..de72cb6cda5f 100755 --- a/python/sepolicy/sepolicy/manpage.py +++ b/python/sepolicy/sepolicy/manpage.py @@ -21,7 +21,7 @@ # 02111-1307 USA # # -__all__ = ['ManPage', 'HTMLManPages', 'manpage_domains', 'manpage_roles', 'gen_domains'] +__all__ = ['ManPage', 'HTMLManPages', 'gen_domains'] import string import selinux @@ -147,10 +147,6 @@ def _gen_types(): def prettyprint(f, trim): return " ".join(f[:-len(trim)].split("_")) -# for HTML man pages -manpage_domains = [] -manpage_roles = [] - fedora_releases = ["Fedora17", "Fedora18"] rhel_releases = ["RHEL6", "RHEL7"] @@ -408,6 +404,8 @@ class ManPage: """ modules_dict = None enabled_str = ["Disabled", "Enabled"] + manpage_domains = [] + manpage_roles = [] def __init__(self, domainname, path="/tmp", root="/", source_files=False, html=False): self.html = html @@ -453,10 +451,10 @@ class ManPage: if self.domainname + "_r" in self.all_roles: self.__gen_user_man_page() if self.html: - manpage_roles.append(self.man_page_path) + self.manpage_roles.append(self.man_page_path) else: if self.html: - manpage_domains.append(self.man_page_path) + self.manpage_domains.append(self.man_page_path) self.__gen_man_page() self.fd.close() From patchwork Tue Nov 15 19:45:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Lautrbach X-Patchwork-Id: 13044096 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 73AA5C4332F for ; Tue, 15 Nov 2022 19:47:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229560AbiKOTrF (ORCPT ); Tue, 15 Nov 2022 14:47:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44196 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231561AbiKOTrC (ORCPT ); Tue, 15 Nov 2022 14:47:02 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DFEE21EACA for ; Tue, 15 Nov 2022 11:46:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668541563; 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: in-reply-to:in-reply-to:references:references; bh=tWfK2vrcZVoLhJl4x6kP8BCC8iuXsvYkZigzHV7I0QQ=; b=DyqAJaAyDgyPMyGqnvocgEdlBA2kVBaBD5Y9Wc3MUdnMkoYnJav8CR36GKWNp0L/NICZmR lnXPTu+0+cGH1e8G24cUxfJXvxdveg6P0DusK6hcTKc5NpgI/hnuF9MFRYrQUlxHa8l2jT 4cqizPpmuGctkdvNX4azz5u+CkdMV9o= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-56-cRo8Unh0MryAFq43Yk96ew-1; Tue, 15 Nov 2022 14:46:01 -0500 X-MC-Unique: cRo8Unh0MryAFq43Yk96ew-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6BA5929AA2FD for ; Tue, 15 Nov 2022 19:46:01 +0000 (UTC) Received: from localhost.localdomain (ovpn-195-4.brq.redhat.com [10.40.195.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id C6521112131E; Tue, 15 Nov 2022 19:46:00 +0000 (UTC) From: Petr Lautrbach To: selinux@vger.kernel.org Cc: Petr Lautrbach Subject: [PATCH v2 2/3] python/sepolicy: Use distro module to get os version Date: Tue, 15 Nov 2022 20:45:51 +0100 Message-Id: <20221115194552.338640-2-plautrba@redhat.com> In-Reply-To: <20221115194552.338640-1-plautrba@redhat.com> References: <20221115194552.338640-1-plautrba@redhat.com> MIME-Version: 1.0 Content-type: text/plain X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org From: Petr Lautrbach distro module uses /etc/os-release file which contains operating system identification data, see os-release(5). Given that the mechanism doesn't use `rpm` it should be possible to generate man pages on other distributions. Signed-off-by: Petr Lautrbach --- python/sepolicy/sepolicy/__init__.py | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/python/sepolicy/sepolicy/__init__.py b/python/sepolicy/sepolicy/__init__.py index 9c3caa05b80b..baa4c8e62e97 100644 --- a/python/sepolicy/sepolicy/__init__.py +++ b/python/sepolicy/sepolicy/__init__.py @@ -1226,27 +1226,14 @@ def boolean_desc(boolean): def get_os_version(): - os_version = "" - pkg_name = "selinux-policy" + system_release = "" try: - try: - from commands import getstatusoutput - except ImportError: - from subprocess import getstatusoutput - rc, output = getstatusoutput("rpm -q '%s'" % pkg_name) - if rc == 0: - os_version = output.split(".")[-2] - except: - os_version = "" - - if os_version[0:2] == "fc": - os_version = "Fedora" + os_version[2:] - elif os_version[0:2] == "el": - os_version = "RHEL" + os_version[2:] - else: - os_version = "" + import distro + system_release = distro.name(pretty=True) + except IOError: + system_release = "Misc" - return os_version + return system_release def reinit(): From patchwork Tue Nov 15 19:45:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Lautrbach X-Patchwork-Id: 13044095 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DD70AC433FE for ; Tue, 15 Nov 2022 19:47:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231481AbiKOTrF (ORCPT ); Tue, 15 Nov 2022 14:47:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44216 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231565AbiKOTrC (ORCPT ); Tue, 15 Nov 2022 14:47:02 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 006A6275CB for ; Tue, 15 Nov 2022 11:46:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668541567; 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: in-reply-to:in-reply-to:references:references; bh=qhDfbDMAjXx4S0RSzOev93uPtHrFWE4bSkmNZDl1fno=; b=Bm5FfRmOEFg8z98/pNJgZ3JHQGSvkIQPWgfNzzLwzsZBcj50qgFd/DH/iD6DGz9KGJNUc3 HXK4bZcvw2/CZx5lMWqB45Q2/OoTu0ORCBDpMKecNqzfjh9HS4FxmMvNL5Lz/dViceQLA2 YxgySo9bnA5FpUeTF7RaG4HhNeTis7M= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-94-KPxmc7OKNBqFvjPgNoWNnw-1; Tue, 15 Nov 2022 14:46:05 -0500 X-MC-Unique: KPxmc7OKNBqFvjPgNoWNnw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6E4F485A5A6 for ; Tue, 15 Nov 2022 19:46:05 +0000 (UTC) Received: from localhost.localdomain (ovpn-195-4.brq.redhat.com [10.40.195.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id C787E112131E; Tue, 15 Nov 2022 19:46:04 +0000 (UTC) From: Petr Lautrbach To: selinux@vger.kernel.org Cc: Petr Lautrbach Subject: [PATCH v2 3/3] python/sepolicy: Simplify generation of man pages Date: Tue, 15 Nov 2022 20:45:52 +0100 Message-Id: <20221115194552.338640-3-plautrba@redhat.com> In-Reply-To: <20221115194552.338640-1-plautrba@redhat.com> References: <20221115194552.338640-1-plautrba@redhat.com> MIME-Version: 1.0 Content-type: text/plain X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org From: Petr Lautrbach And do not hardcode Fedora and RHEL versions. Signed-off-by: Petr Lautrbach --- python/sepolicy/sepolicy/manpage.py | 71 ++++------------------------- 1 file changed, 8 insertions(+), 63 deletions(-) diff --git a/python/sepolicy/sepolicy/manpage.py b/python/sepolicy/sepolicy/manpage.py index de72cb6cda5f..d9973170f3c3 100755 --- a/python/sepolicy/sepolicy/manpage.py +++ b/python/sepolicy/sepolicy/manpage.py @@ -147,9 +147,6 @@ def _gen_types(): def prettyprint(f, trim): return " ".join(f[:-len(trim)].split("_")) -fedora_releases = ["Fedora17", "Fedora18"] -rhel_releases = ["RHEL6", "RHEL7"] - def get_alphabet_manpages(manpage_list): alphabet_manpages = dict.fromkeys(string.ascii_letters, []) @@ -180,7 +177,7 @@ def convert_manpage_to_html(html_manpage, manpage): class HTMLManPages: """ - Generate a HHTML Manpages on an given SELinux domains + Generate a HTML Manpages on an given SELinux domains """ def __init__(self, manpage_roles, manpage_domains, path, os_version): @@ -188,18 +185,12 @@ class HTMLManPages: self.manpage_domains = get_alphabet_manpages(manpage_domains) self.os_version = os_version self.old_path = path + "/" - self.new_path = self.old_path + self.os_version + "/" - - if self.os_version in fedora_releases or self.os_version in rhel_releases: - self.__gen_html_manpages() - else: - print("SELinux HTML man pages can not be generated for this %s" % os_version) - exit(1) + self.new_path = self.old_path + self.__gen_html_manpages() def __gen_html_manpages(self): self._write_html_manpage() self._gen_index() - self._gen_body() self._gen_css() def _write_html_manpage(self): @@ -217,67 +208,21 @@ class HTMLManPages: convert_manpage_to_html((self.new_path + r.rsplit("_selinux", 1)[0] + ".html"), self.old_path + r) def _gen_index(self): - index = self.old_path + "index.html" - fd = open(index, 'w') - fd.write(""" - - - - SELinux man pages online - - -

SELinux man pages

-

-Fedora or Red Hat Enterprise Linux Man Pages. -

-
-

Fedora

- - -
-
-
-""")
-        for f in fedora_releases:
-            fd.write("""
-%s - SELinux man pages for %s """ % (f, f, f, f))
-
-        fd.write("""
-
-
-

RHEL

- - -
-
-
-""")
-        for r in rhel_releases:
-            fd.write("""
-%s - SELinux man pages for %s """ % (r, r, r, r))
-
-        fd.write("""
-
- """) - fd.close() - print("%s has been created" % index) - - def _gen_body(self): - html = self.new_path + self.os_version + ".html" + html = self.new_path + "index.html" fd = open(html, 'w') fd.write(""" - - Linux man-pages online for Fedora18 + + SELinux man pages online -

SELinux man pages for Fedora18

+

SELinux man pages for %s


SELinux roles

-""") +""" % self.os_version) for letter in self.manpage_roles: if len(self.manpage_roles[letter]): fd.write("""