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

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