Blame SOURCES/0001-Support-old-boolean-names-in-policy-queries.patch

437d0a
From 97bd46865e12246c00517d1e07aabca530a305ac Mon Sep 17 00:00:00 2001
437d0a
From: Vit Mojzis <vmojzis@redhat.com>
437d0a
Date: Wed, 17 Jun 2020 13:34:19 +0200
437d0a
Subject: [PATCH] Support old boolean names in policy queries
437d0a
437d0a
Translate old boolean names based on /etc/selinux/*/booleans.subs_dist
437d0a
file. The translation is only attempted when "policy" was not specified
437d0a
to avoid influencing queries of policies from other systems.
437d0a
437d0a
Signed-off-by: Vit Mojzis <vmojzis@redhat.com>
437d0a
---
437d0a
 seinfo                        |  6 +++++-
437d0a
 sesearch                      |  7 ++++++-
437d0a
 setools/policyrep/selinux.pxd |  1 +
437d0a
 setools/policyrep/util.pxi    | 22 ++++++++++++++++++++++
437d0a
 4 files changed, 34 insertions(+), 2 deletions(-)
437d0a
437d0a
diff --git a/seinfo b/seinfo
437d0a
index d2caf7c..bc33e12 100755
437d0a
--- a/seinfo
437d0a
+++ b/seinfo
437d0a
@@ -125,7 +125,11 @@ try:
437d0a
     if args.boolquery or args.all:
437d0a
         q = setools.BoolQuery(p)
437d0a
         if isinstance(args.boolquery, str):
437d0a
-            q.name = args.boolquery
437d0a
+            if args.policy:
437d0a
+                q.name = args.boolquery
437d0a
+            else:
437d0a
+                # try to find substitutions for old boolean names
437d0a
+                q.name = setools.policyrep.lookup_boolean_name_sub(args.boolquery)
437d0a
 
437d0a
         components.append(("Booleans", q, lambda x: x.statement()))
437d0a
 
437d0a
diff --git a/sesearch b/sesearch
437d0a
index c4b1d38..733f3d3 100755
437d0a
--- a/sesearch
437d0a
+++ b/sesearch
437d0a
@@ -189,7 +189,12 @@ try:
437d0a
             if args.boolean_regex:
437d0a
                 q.boolean = args.boolean
437d0a
             else:
437d0a
-                q.boolean = args.boolean.split(",")
437d0a
+                if args.policy:
437d0a
+                    q.boolean = args.boolean.split(",")
437d0a
+                else:
437d0a
+                    # try to find substitutions for old boolean names
437d0a
+                    q.boolean = map(setools.policyrep.lookup_boolean_name_sub,
437d0a
+                                    args.boolean.split(","))
437d0a
 
437d0a
         for r in sorted(q.results()):
437d0a
             print(r)
437d0a
diff --git a/setools/policyrep/selinux.pxd b/setools/policyrep/selinux.pxd
437d0a
index a2e8af0..1686831 100644
437d0a
--- a/setools/policyrep/selinux.pxd
437d0a
+++ b/setools/policyrep/selinux.pxd
437d0a
@@ -24,3 +24,4 @@ cdef extern from "<selinux/selinux.h>":
437d0a
     bint selinuxfs_exists()
437d0a
     const char* selinux_current_policy_path()
437d0a
     const char* selinux_binary_policy_path()
437d0a
+    char* selinux_boolean_sub(const char *boolean_name);
437d0a
diff --git a/setools/policyrep/util.pxi b/setools/policyrep/util.pxi
437d0a
index 40f21a7..abc7be8 100644
437d0a
--- a/setools/policyrep/util.pxi
437d0a
+++ b/setools/policyrep/util.pxi
437d0a
@@ -230,3 +230,25 @@ cdef flatten_list(input_list):
437d0a
             ret.append(i)
437d0a
 
437d0a
     return ret
437d0a
+
437d0a
+
437d0a
+def lookup_boolean_name_sub(name):
437d0a
+    """
437d0a
+    Read the /etc/selinux/TYPE/booleans.subs_dist file looking
437d0a
+    for a record with 'name'.
437d0a
+    Return the translated name if a corresponding substitution exists,
437d0a
+    otherwise return the original name.
437d0a
+    """
437d0a
+    cdef:
437d0a
+        char *_name = selinux.selinux_boolean_sub(name)
437d0a
+        str new_name = name
437d0a
+
437d0a
+    if _name == NULL:
437d0a
+        raise MemoryError
437d0a
+    # cast "char *" to "str" and free
437d0a
+    try:
437d0a
+        new_name = _name
437d0a
+    finally:
437d0a
+        free(_name)
437d0a
+
437d0a
+    return new_name
437d0a
-- 
437d0a
2.25.4
437d0a