Blame SOURCES/0014-Issue-5127-run-restorecon-on-dev-shm-at-server-start.patch

9f2552
From 03ca5111a8de602ecef9ad33206ba593b242d0df Mon Sep 17 00:00:00 2001
9f2552
From: Mark Reynolds <mreynolds@redhat.com>
9f2552
Date: Fri, 21 Jan 2022 10:15:35 -0500
9f2552
Subject: [PATCH 1/2] Issue 5127 - run restorecon on /dev/shm at server startup
9f2552
9f2552
Description:
9f2552
9f2552
Update the systemd service file to execute a script that runs
9f2552
restorecon on the DB home directory.  This addresses issues with
9f2552
backup/restore, reboot, and FS restore issues that can happen when
9f2552
/dev/shm is missing or created outside of dscreate.
9f2552
9f2552
relates: https://github.com/389ds/389-ds-base/issues/5127
9f2552
9f2552
Reviewed by: progier & viktor (Thanks!!)
9f2552
---
9f2552
 Makefile.am                          |  2 +-
9f2552
 rpm/389-ds-base.spec.in              |  1 +
9f2552
 wrappers/ds_selinux_restorecon.sh.in | 33 ++++++++++++++++++++++++++++
9f2552
 wrappers/systemd.template.service.in |  1 +
9f2552
 4 files changed, 36 insertions(+), 1 deletion(-)
9f2552
 create mode 100644 wrappers/ds_selinux_restorecon.sh.in
9f2552
9f2552
diff --git a/Makefile.am b/Makefile.am
9f2552
index fc5a6a7d1..d6ad273c3 100644
9f2552
--- a/Makefile.am
9f2552
+++ b/Makefile.am
9f2552
@@ -775,7 +775,7 @@ libexec_SCRIPTS += ldap/admin/src/scripts/ds_selinux_enabled \
9f2552
 	ldap/admin/src/scripts/ds_selinux_port_query
9f2552
 endif
9f2552
 if SYSTEMD
9f2552
-libexec_SCRIPTS += wrappers/ds_systemd_ask_password_acl
9f2552
+libexec_SCRIPTS += wrappers/ds_systemd_ask_password_acl wrappers/ds_selinux_restorecon.sh
9f2552
 endif
9f2552
 
9f2552
 install-data-hook:
9f2552
diff --git a/rpm/389-ds-base.spec.in b/rpm/389-ds-base.spec.in
9f2552
index d80de8422..6c0d95abd 100644
9f2552
--- a/rpm/389-ds-base.spec.in
9f2552
+++ b/rpm/389-ds-base.spec.in
9f2552
@@ -623,6 +623,7 @@ exit 0
9f2552
 %{_sbindir}/ns-slapd
9f2552
 %{_mandir}/man8/ns-slapd.8.gz
9f2552
 %{_libexecdir}/%{pkgname}/ds_systemd_ask_password_acl
9f2552
+%{_libexecdir}/%{pkgname}/ds_selinux_restorecon.sh
9f2552
 %{_mandir}/man5/99user.ldif.5.gz
9f2552
 %{_mandir}/man5/certmap.conf.5.gz
9f2552
 %{_mandir}/man5/slapd-collations.conf.5.gz
9f2552
diff --git a/wrappers/ds_selinux_restorecon.sh.in b/wrappers/ds_selinux_restorecon.sh.in
9f2552
new file mode 100644
9f2552
index 000000000..063347de3
9f2552
--- /dev/null
9f2552
+++ b/wrappers/ds_selinux_restorecon.sh.in
9f2552
@@ -0,0 +1,33 @@
9f2552
+#!/bin/sh
9f2552
+# BEGIN COPYRIGHT BLOCK
9f2552
+# Copyright (C) 2022 Red Hat, Inc.
9f2552
+#
9f2552
+# All rights reserved.
9f2552
+#
9f2552
+# License: GPL (version 3 or any later version).
9f2552
+# See LICENSE for details.
9f2552
+# END COPYRIGHT BLOCK
9f2552
+
9f2552
+# Make sure we have the path to the dse.ldif
9f2552
+if [ -z $1 ]
9f2552
+then
9f2552
+    echo "usage: ${0} /etc/dirsrv/slapd-<instance>/dse.ldif"
9f2552
+    exit 0
9f2552
+fi
9f2552
+
9f2552
+if ! command -v restorecon &> /dev/null
9f2552
+then
9f2552
+    # restorecon is not available
9f2552
+    exit 0
9f2552
+fi
9f2552
+
9f2552
+# Grep the db_home_dir out of the config file
9f2552
+DS_HOME_DIR=`grep 'nsslapd-db-home-directory: ' $1 | awk '{print $2}'`
9f2552
+if [ -z "$DS_HOME_DIR" ]
9f2552
+then
9f2552
+    # No DB home set, that's ok
9f2552
+    exit 0
9f2552
+fi
9f2552
+
9f2552
+# Now run restorecon
9f2552
+restorecon ${DS_HOME_DIR}
9f2552
diff --git a/wrappers/systemd.template.service.in b/wrappers/systemd.template.service.in
9f2552
index a8c21a9be..4485e0ec0 100644
9f2552
--- a/wrappers/systemd.template.service.in
9f2552
+++ b/wrappers/systemd.template.service.in
9f2552
@@ -14,6 +14,7 @@ EnvironmentFile=-@initconfigdir@/@package_name@
9f2552
 EnvironmentFile=-@initconfigdir@/@package_name@-%i
9f2552
 PIDFile=/run/@package_name@/slapd-%i.pid
9f2552
 ExecStartPre=@libexecdir@/ds_systemd_ask_password_acl @instconfigdir@/slapd-%i/dse.ldif
9f2552
+ExecStartPre=@libexecdir@/ds_selinux_restorecon.sh @instconfigdir@/slapd-%i/dse.ldif
9f2552
 ExecStart=@sbindir@/ns-slapd -D @instconfigdir@/slapd-%i -i /run/@package_name@/slapd-%i.pid
9f2552
 PrivateTmp=on
9f2552
 
9f2552
-- 
9f2552
2.31.1
9f2552