Blame SOURCES/0003-semanage-Fix-parsing-of-ignoredirs-758.patch

d2e6db
From aca3def462ab141c3991a2d27c44341b809cf970 Mon Sep 17 00:00:00 2001
d2e6db
From: rwmjones <rjones@redhat.com>
d2e6db
Date: Thu, 6 Oct 2022 12:15:56 +0100
d2e6db
Subject: [PATCH 3/3] semanage: Fix parsing of ignoredirs (#758)
d2e6db
d2e6db
From /etc/selinux/semanage.conf from a RHEL 9.1 system, this line
d2e6db
caused problems:
d2e6db
d2e6db
  ignoredirs=/root;/bin;/boot;/dev;/etc [...]
d2e6db
d2e6db
Parse this as a list of modified Rx.fspath, generating a tree like:
d2e6db
d2e6db
  /files/etc/selinux/semanage.conf/ignoredirs/1 = /root
d2e6db
  /files/etc/selinux/semanage.conf/ignoredirs/2 = /bin
d2e6db
  /files/etc/selinux/semanage.conf/ignoredirs/3 = /dev
d2e6db
  /files/etc/selinux/semanage.conf/ignoredirs/4 = /etc
d2e6db
  [...]
d2e6db
d2e6db
Also this adds the RHEL 9 file as another test case and adjusts the
d2e6db
output of the existing test case.
d2e6db
d2e6db
Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=2077120
d2e6db
Signed-off-by: Richard W.M. Jones <rjones@redhat.com>
d2e6db
d2e6db
Signed-off-by: Richard W.M. Jones <rjones@redhat.com>
d2e6db
(cherry picked from commit a3ba6e2d32b95507e2474a219e788ac3d54bc4a1)
d2e6db
---
d2e6db
 lenses/semanage.aug                  |  7 +++-
d2e6db
 lenses/tests/test_semanage.aug       |  4 +-
d2e6db
 tests/root/etc/selinux/semanage.conf | 60 ++++++++++++++++++++++++++++
d2e6db
 tests/xpath.tests                    |  1 +
d2e6db
 4 files changed, 70 insertions(+), 2 deletions(-)
d2e6db
 create mode 100644 tests/root/etc/selinux/semanage.conf
d2e6db
d2e6db
diff --git a/lenses/semanage.aug b/lenses/semanage.aug
d2e6db
index 46f93b32..edd97131 100644
d2e6db
--- a/lenses/semanage.aug
d2e6db
+++ b/lenses/semanage.aug
d2e6db
@@ -23,7 +23,12 @@ let sep = IniFile.sep "=" "="
d2e6db
 let empty = IniFile.empty
d2e6db
 let eol = IniFile.eol
d2e6db
 
d2e6db
-let entry = IniFile.entry IniFile.entry_re sep comment
d2e6db
+let list_keys = "ignoredirs"
d2e6db
+let scl = del ";" ";"
d2e6db
+let fspath = /[^ \t\n;#]+/ (* Rx.fspath without ; or # *)
d2e6db
+
d2e6db
+let entry = IniFile.entry_list list_keys sep fspath scl comment
d2e6db
+          | IniFile.entry (IniFile.entry_re - list_keys) sep comment
d2e6db
           | empty
d2e6db
 
d2e6db
 let title = IniFile.title_label "@group" (IniFile.record_re - /^end$/)
d2e6db
diff --git a/lenses/tests/test_semanage.aug b/lenses/tests/test_semanage.aug
d2e6db
index a6ceaca0..f76b95f3 100644
d2e6db
--- a/lenses/tests/test_semanage.aug
d2e6db
+++ b/lenses/tests/test_semanage.aug
d2e6db
@@ -68,7 +68,9 @@ test Semanage.lns get conf =
d2e6db
    { "usepasswd" = "False" }
d2e6db
    { "bzip-small" = "true" }
d2e6db
    { "bzip-blocksize" = "5" }
d2e6db
-   { "ignoredirs" = "/root" }
d2e6db
+   { "ignoredirs"
d2e6db
+     { "1" = "/root" }
d2e6db
+   }
d2e6db
    { }
d2e6db
    { "@group" = "sefcontext_compile"
d2e6db
      { "path" = "/usr/sbin/sefcontext_compile" }
d2e6db
diff --git a/tests/root/etc/selinux/semanage.conf b/tests/root/etc/selinux/semanage.conf
d2e6db
new file mode 100644
d2e6db
index 00000000..406f16f1
d2e6db
--- /dev/null
d2e6db
+++ b/tests/root/etc/selinux/semanage.conf
d2e6db
@@ -0,0 +1,60 @@
d2e6db
+# Authors: Jason Tang <jtang@tresys.com>
d2e6db
+#
d2e6db
+# Copyright (C) 2004-2005 Tresys Technology, LLC
d2e6db
+#
d2e6db
+#  This library is free software; you can redistribute it and/or
d2e6db
+#  modify it under the terms of the GNU Lesser General Public
d2e6db
+#  License as published by the Free Software Foundation; either
d2e6db
+#  version 2.1 of the License, or (at your option) any later version.
d2e6db
+#
d2e6db
+#  This library is distributed in the hope that it will be useful,
d2e6db
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
d2e6db
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
d2e6db
+#  Lesser General Public License for more details.
d2e6db
+#
d2e6db
+#  You should have received a copy of the GNU Lesser General Public
d2e6db
+#  License along with this library; if not, write to the Free Software
d2e6db
+#  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
d2e6db
+#
d2e6db
+# Specify how libsemanage will interact with a SELinux policy manager.
d2e6db
+# The four options are:
d2e6db
+#
d2e6db
+#  "source"     - libsemanage manipulates a source SELinux policy
d2e6db
+#  "direct"     - libsemanage will write directly to a module store.
d2e6db
+#  /foo/bar     - Write by way of a policy management server, whose
d2e6db
+#                 named socket is at /foo/bar.  The path must begin
d2e6db
+#                 with a '/'.
d2e6db
+#  foo.com:4242 - Establish a TCP connection to a remote policy
d2e6db
+#                 management server at foo.com.  If there is a colon
d2e6db
+#                 then the remainder is interpreted as a port number;
d2e6db
+#                 otherwise default to port 4242.
d2e6db
+module-store = direct
d2e6db
+
d2e6db
+# When generating the final linked and expanded policy, by default
d2e6db
+# semanage will set the policy version to POLICYDB_VERSION_MAX, as
d2e6db
+# given in <sepol/policydb.h>.  Change this setting if a different
d2e6db
+# version is necessary.
d2e6db
+#policy-version = 19
d2e6db
+
d2e6db
+# expand-check check neverallow rules when executing all semanage
d2e6db
+# commands. There might be a penalty in execution time if this
d2e6db
+# option is enabled.
d2e6db
+expand-check=0
d2e6db
+
d2e6db
+# usepasswd check tells semanage to scan all pass word records for home directories
d2e6db
+# and setup the labeling correctly. If this is turned off, SELinux will label only /home
d2e6db
+# and home directories of users with SELinux login mappings defined, see
d2e6db
+# semanage login -l for the list of such users.
d2e6db
+# If you want to use a different home directory, you will need to use semanage fcontext command.
d2e6db
+# For example, if you had home dirs in /althome directory you would have to execute
d2e6db
+# semanage fcontext -a -e /home /althome
d2e6db
+usepasswd=False
d2e6db
+bzip-small=true
d2e6db
+bzip-blocksize=5
d2e6db
+ignoredirs=/root;/bin;/boot;/dev;/etc;/lib;/lib64;/proc;/run;/sbin;/sys;/tmp;/usr;/var
d2e6db
+optimize-policy=true
d2e6db
+
d2e6db
+[sefcontext_compile]
d2e6db
+path = /usr/sbin/sefcontext_compile
d2e6db
+args = -r $@
d2e6db
+[end]
d2e6db
diff --git a/tests/xpath.tests b/tests/xpath.tests
d2e6db
index 4278e433..71c998b8 100644
d2e6db
--- a/tests/xpath.tests
d2e6db
+++ b/tests/xpath.tests
d2e6db
@@ -109,6 +109,7 @@ test descendant-or-self /files/descendant-or-self :: 4
d2e6db
      /files/etc/ssh/ssh_config/Host/SendEnv[1]/4 = LC_TIME
d2e6db
      /files/etc/ssh/ssh_config/Host/SendEnv[2]/4 = LC_TELEPHONE
d2e6db
      /files/etc/aliases/4
d2e6db
+     /files/etc/selinux/semanage.conf/ignoredirs/4 = /dev
d2e6db
      /files/etc/fstab/4
d2e6db
      /files/etc/pam.d/login/4
d2e6db
      /files/etc/pam.d/newrole/4
d2e6db
-- 
d2e6db
2.31.1
d2e6db