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

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