Blame SOURCES/0051-python-sepolicy-add-missing-booleans-to-man-pages.patch

017072
From f3ddbd8220d9646072c9a4c9ed37f2dff998a53c Mon Sep 17 00:00:00 2001
017072
From: Vit Mojzis <vmojzis@redhat.com>
017072
Date: Tue, 10 Jan 2023 11:37:26 +0100
017072
Subject: [PATCH] python/sepolicy: add missing booleans to man pages
017072
017072
get_bools should return a list of booleans that can affect given type,
017072
but it did not handle non trivial conditional statements properly
017072
(returning the whole conditional statement instead of a list of booleans
017072
in the statement).
017072
017072
e.g. for
017072
allow httpd_t spamc_t:process transition; [ httpd_can_check_spam && httpd_can_sendmail ]:True
017072
get_bools used to return [("httpd_can_check_spam && httpd_can_sendmail", False)] instead of
017072
[("httpd_can_check_spam", False), ("httpd_can_sendmail", False)]
017072
017072
- rename "boolean" in sepolicy rule dictionary to "booleans" to suggest
017072
  it can contain multiple values and make sure it is populated correctly
017072
- add "conditional" key to the rule dictionary to accommodate
017072
  get_conditionals, which requires the whole conditional statement
017072
- extend get_bools search to dontaudit rules so that it covers booleans
017072
  like httpd_dontaudit_search_dirs
017072
017072
Note: get_bools uses security_get_boolean_active to get the boolean
017072
      value, but the value is later used to represent the default.
017072
      Not ideal, but I'm not aware of a way to get the actual defaults.
017072
017072
Fixes:
017072
        "sepolicy manpage" generates man pages that are missing booleans
017072
        which are included in non trivial conditional expressions
017072
        e.g. httpd_selinux(8) does not include httpd_can_check_spam,
017072
        httpd_tmp_exec, httpd_unified, or httpd_use_gpg
017072
017072
        This fix, however, also adds some not strictly related booleans
017072
        to some man pages. e.g. use_nfs_home_dirs and
017072
        use_samba_home_dirs are added to httpd_selinux(8)
017072
017072
Signed-off-by: Vit Mojzis <vmojzis@redhat.com>
017072
Acked-by: Jason Zaman <jason@perfinion.com>
017072
---
017072
 python/sepolicy/sepolicy/__init__.py | 21 +++++++++++++--------
017072
 1 file changed, 13 insertions(+), 8 deletions(-)
017072
017072
diff --git a/python/sepolicy/sepolicy/__init__.py b/python/sepolicy/sepolicy/__init__.py
017072
index b6ca57c3..0f51174d 100644
017072
--- a/python/sepolicy/sepolicy/__init__.py
017072
+++ b/python/sepolicy/sepolicy/__init__.py
017072
@@ -324,7 +324,12 @@ def _setools_rule_to_dict(rule):
017072
         pass
017072
 
017072
     try:
017072
-        d['boolean'] = [(str(rule.conditional), enabled)]
017072
+        d['booleans'] = [(str(b), b.state) for b in rule.conditional.booleans]
017072
+    except AttributeError:
017072
+        pass
017072
+
017072
+    try:
017072
+        d['conditional'] = str(rule.conditional)
017072
     except AttributeError:
017072
         pass
017072
 
017072
@@ -426,12 +431,12 @@ def get_conditionals(src, dest, tclass, perm):
017072
                 x['source'] in src_list and
017072
                 x['target'] in dest_list and
017072
                 set(perm).issubset(x[PERMS]) and
017072
-                'boolean' in x,
017072
+                'conditional' in x,
017072
                 get_all_allow_rules()))
017072
 
017072
     try:
017072
         for i in allows:
017072
-            tdict.update({'source': i['source'], 'boolean': i['boolean']})
017072
+            tdict.update({'source': i['source'], 'conditional': (i['conditional'], i['enabled'])})
017072
             if tdict not in tlist:
017072
                 tlist.append(tdict)
017072
                 tdict = {}
017072
@@ -445,10 +450,10 @@ def get_conditionals_format_text(cond):
017072
 
017072
     enabled = False
017072
     for x in cond:
017072
-        if x['boolean'][0][1]:
017072
+        if x['conditional'][1]:
017072
             enabled = True
017072
             break
017072
-    return _("-- Allowed %s [ %s ]") % (enabled, " || ".join(set(map(lambda x: "%s=%d" % (x['boolean'][0][0], x['boolean'][0][1]), cond))))
017072
+    return _("-- Allowed %s [ %s ]") % (enabled, " || ".join(set(map(lambda x: "%s=%d" % (x['conditional'][0], x['conditional'][1]), cond))))
017072
 
017072
 
017072
 def get_types_from_attribute(attribute):
017072
@@ -703,9 +708,9 @@ def get_boolean_rules(setype, boolean):
017072
     boollist = []
017072
     permlist = search([ALLOW], {'source': setype})
017072
     for p in permlist:
017072
-        if "boolean" in p:
017072
+        if "booleans" in p:
017072
             try:
017072
-                for b in p["boolean"]:
017072
+                for b in p["booleans"]:
017072
                     if boolean in b:
017072
                         boollist.append(p)
017072
             except:
017072
@@ -1124,7 +1129,7 @@ def get_bools(setype):
017072
     bools = []
017072
     domainbools = []
017072
     domainname, short_name = gen_short_name(setype)
017072
-    for i in map(lambda x: x['boolean'], filter(lambda x: 'boolean' in x and x['source'] == setype, get_all_allow_rules())):
017072
+    for i in map(lambda x: x['booleans'], filter(lambda x: 'booleans' in x and x['source'] == setype, search([ALLOW, DONTAUDIT]))):
017072
         for b in i:
017072
             if not isinstance(b, tuple):
017072
                 continue
017072
-- 
017072
2.37.3
017072