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

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