Blame SOURCES/0005-Issue-4092-systemd-tmpfiles-warnings.patch

51b5b9
From 9c08a053938eb28821fad7d0850c046ef2ed44c4 Mon Sep 17 00:00:00 2001
51b5b9
From: Mark Reynolds <mreynolds@redhat.com>
51b5b9
Date: Wed, 9 Dec 2020 16:16:30 -0500
51b5b9
Subject: [PATCH 05/12] Issue 4092 - systemd-tmpfiles warnings
51b5b9
51b5b9
Bug Description:
51b5b9
51b5b9
systemd-tmpfiles warns about legacy paths in our tmpfiles configs.
51b5b9
Using /var/run also introduces a race condition, see the following
51b5b9
issue https://pagure.io/389-ds-base/issue/47429
51b5b9
51b5b9
Fix Description:
51b5b9
51b5b9
Instead of using @localstatedir@/run use @localrundir@ which was
51b5b9
introduced in #850.
51b5b9
51b5b9
Relates: https://github.com/389ds/389-ds-base/issues/766
51b5b9
Fixes: https://github.com/389ds/389-ds-base/issues/4092
51b5b9
51b5b9
Reviewed by: vashirov & firstyear(Thanks!)
51b5b9
---
51b5b9
 Makefile.am                                  |  4 ++--
51b5b9
 configure.ac                                 | 10 ++++++++--
51b5b9
 dirsrvtests/tests/suites/basic/basic_test.py |  3 ++-
51b5b9
 ldap/admin/src/defaults.inf.in               |  8 ++++----
51b5b9
 ldap/servers/snmp/main.c                     |  8 ++++----
51b5b9
 src/lib389/lib389/__init__.py                |  3 +++
51b5b9
 src/lib389/lib389/instance/options.py        |  7 ++++++-
51b5b9
 src/lib389/lib389/instance/remove.py         | 13 ++++++++-----
51b5b9
 src/lib389/lib389/instance/setup.py          | 10 ++++++++--
51b5b9
 9 files changed, 45 insertions(+), 21 deletions(-)
51b5b9
51b5b9
diff --git a/Makefile.am b/Makefile.am
51b5b9
index 36434cf17..fc5a6a7d1 100644
51b5b9
--- a/Makefile.am
51b5b9
+++ b/Makefile.am
51b5b9
@@ -141,8 +141,8 @@ PATH_DEFINES = -DLOCALSTATEDIR="\"$(localstatedir)\"" -DSYSCONFDIR="\"$(sysconfd
51b5b9
 	-DLIBDIR="\"$(libdir)\"" -DBINDIR="\"$(bindir)\"" \
51b5b9
 	-DDATADIR="\"$(datadir)\"" -DDOCDIR="\"$(docdir)\"" \
51b5b9
 	-DSBINDIR="\"$(sbindir)\"" -DPLUGINDIR="\"$(serverplugindir)\"" \
51b5b9
-	-DTEMPLATEDIR="\"$(sampledatadir)\"" -DSYSTEMSCHEMADIR="\"$(systemschemadir)\""
51b5b9
-
51b5b9
+	-DTEMPLATEDIR="\"$(sampledatadir)\"" -DSYSTEMSCHEMADIR="\"$(systemschemadir)\"" \
51b5b9
+	-DLOCALRUNDIR="\"$(localrundir)\""
51b5b9
 # Now that we have all our defines in place, setup the CPPFLAGS
51b5b9
 
51b5b9
 # These flags are the "must have" for all components
51b5b9
diff --git a/configure.ac b/configure.ac
51b5b9
index 61bf35e4a..9845beb7d 100644
51b5b9
--- a/configure.ac
51b5b9
+++ b/configure.ac
51b5b9
@@ -418,7 +418,14 @@ fi
51b5b9
 
51b5b9
 m4_include(m4/fhs.m4)
51b5b9
 
51b5b9
-localrundir='/run'
51b5b9
+# /run directory path
51b5b9
+AC_ARG_WITH([localrundir],
51b5b9
+            AS_HELP_STRING([--with-localrundir=DIR],
51b5b9
+                           [Runtime data directory]),
51b5b9
+            [localrundir=$with_localrundir],
51b5b9
+            [localrundir="/run"])
51b5b9
+AC_SUBST([localrundir])
51b5b9
+
51b5b9
 cockpitdir=/389-console
51b5b9
 
51b5b9
 # installation paths - by default, we store everything
51b5b9
@@ -899,7 +906,6 @@ AC_SUBST(ldaplib_defs)
51b5b9
 AC_SUBST(ldaptool_bindir)
51b5b9
 AC_SUBST(ldaptool_opts)
51b5b9
 AC_SUBST(plainldif_opts)
51b5b9
-AC_SUBST(localrundir)
51b5b9
 
51b5b9
 AC_SUBST(brand)
51b5b9
 AC_SUBST(capbrand)
51b5b9
diff --git a/dirsrvtests/tests/suites/basic/basic_test.py b/dirsrvtests/tests/suites/basic/basic_test.py
51b5b9
index 41726f073..7e80c443b 100644
51b5b9
--- a/dirsrvtests/tests/suites/basic/basic_test.py
51b5b9
+++ b/dirsrvtests/tests/suites/basic/basic_test.py
51b5b9
@@ -901,7 +901,8 @@ def test_basic_ldapagent(topology_st, import_example_ldif):
51b5b9
     # Remember, this is *forking*
51b5b9
     check_output([os.path.join(topology_st.standalone.get_sbin_dir(), 'ldap-agent'), config_file])
51b5b9
     # First kill any previous agents ....
51b5b9
-    pidpath = os.path.join(var_dir, 'run/ldap-agent.pid')
51b5b9
+    run_dir = topology_st.standalone.get_run_dir()
51b5b9
+    pidpath = os.path.join(run_dir, 'ldap-agent.pid')
51b5b9
     pid = None
51b5b9
     with open(pidpath, 'r') as pf:
51b5b9
         pid = pf.readlines()[0].strip()
51b5b9
diff --git a/ldap/admin/src/defaults.inf.in b/ldap/admin/src/defaults.inf.in
51b5b9
index d5f504591..e02248b89 100644
51b5b9
--- a/ldap/admin/src/defaults.inf.in
51b5b9
+++ b/ldap/admin/src/defaults.inf.in
51b5b9
@@ -35,12 +35,12 @@ sysconf_dir = @sysconfdir@
51b5b9
 initconfig_dir = @initconfigdir@
51b5b9
 config_dir = @instconfigdir@/slapd-{instance_name}
51b5b9
 local_state_dir = @localstatedir@
51b5b9
-run_dir = @localstatedir@/run/dirsrv
51b5b9
+run_dir = @localrundir@
51b5b9
 # This is the expected location of ldapi.
51b5b9
-ldapi = @localstatedir@/run/slapd-{instance_name}.socket
51b5b9
+ldapi = @localrundir@/slapd-{instance_name}.socket
51b5b9
+pid_file = @localrundir@/slapd-{instance_name}.pid
51b5b9
 ldapi_listen = on
51b5b9
 ldapi_autobind = on
51b5b9
-pid_file = @localstatedir@/run/dirsrv/slapd-{instance_name}.pid
51b5b9
 inst_dir = @serverdir@/slapd-{instance_name}
51b5b9
 plugin_dir = @serverplugindir@
51b5b9
 system_schema_dir = @systemschemadir@
51b5b9
@@ -54,7 +54,7 @@ root_dn = cn=Directory Manager
51b5b9
 schema_dir = @instconfigdir@/slapd-{instance_name}/schema
51b5b9
 cert_dir = @instconfigdir@/slapd-{instance_name}
51b5b9
 
51b5b9
-lock_dir = @localstatedir@/lock/dirsrv/slapd-{instance_name}
51b5b9
+lock_dir = @localrundir@/lock/dirsrv/slapd-{instance_name}
51b5b9
 log_dir = @localstatedir@/log/dirsrv/slapd-{instance_name}
51b5b9
 access_log = @localstatedir@/log/dirsrv/slapd-{instance_name}/access
51b5b9
 audit_log = @localstatedir@/log/dirsrv/slapd-{instance_name}/audit
51b5b9
diff --git a/ldap/servers/snmp/main.c b/ldap/servers/snmp/main.c
51b5b9
index 88a4d532a..e6271a8a9 100644
51b5b9
--- a/ldap/servers/snmp/main.c
51b5b9
+++ b/ldap/servers/snmp/main.c
51b5b9
@@ -287,14 +287,14 @@ load_config(char *conf_path)
51b5b9
     }
51b5b9
 
51b5b9
     /* set pidfile path */
51b5b9
-    if ((pidfile = malloc(strlen(LOCALSTATEDIR) + strlen("/run/") +
51b5b9
+    if ((pidfile = malloc(strlen(LOCALRUNDIR) + strlen("/") +
51b5b9
                           strlen(LDAP_AGENT_PIDFILE) + 1)) != NULL) {
51b5b9
-        strncpy(pidfile, LOCALSTATEDIR, strlen(LOCALSTATEDIR) + 1);
51b5b9
+        strncpy(pidfile, LOCALRUNDIR, strlen(LOCALRUNDIR) + 1);
51b5b9
         /* The above will likely not be NULL terminated, but we need to
51b5b9
          * be sure that we're properly NULL terminated for the below
51b5b9
          * strcat() to work properly. */
51b5b9
-        pidfile[strlen(LOCALSTATEDIR)] = (char)0;
51b5b9
-        strcat(pidfile, "/run/");
51b5b9
+        pidfile[strlen(LOCALRUNDIR)] = (char)0;
51b5b9
+        strcat(pidfile, "/");
51b5b9
         strcat(pidfile, LDAP_AGENT_PIDFILE);
51b5b9
     } else {
51b5b9
         printf("ldap-agent: malloc error processing config file\n");
51b5b9
diff --git a/src/lib389/lib389/__init__.py b/src/lib389/lib389/__init__.py
51b5b9
index e0299c5b4..2a0b83913 100644
51b5b9
--- a/src/lib389/lib389/__init__.py
51b5b9
+++ b/src/lib389/lib389/__init__.py
51b5b9
@@ -1709,6 +1709,9 @@ class DirSrv(SimpleLDAPObject, object):
51b5b9
     def get_bin_dir(self):
51b5b9
         return self.ds_paths.bin_dir
51b5b9
 
51b5b9
+    def get_run_dir(self):
51b5b9
+        return self.ds_paths.run_dir
51b5b9
+
51b5b9
     def get_plugin_dir(self):
51b5b9
         return self.ds_paths.plugin_dir
51b5b9
 
51b5b9
diff --git a/src/lib389/lib389/instance/options.py b/src/lib389/lib389/instance/options.py
51b5b9
index 4e083618c..d5b95e6df 100644
51b5b9
--- a/src/lib389/lib389/instance/options.py
51b5b9
+++ b/src/lib389/lib389/instance/options.py
51b5b9
@@ -1,5 +1,5 @@
51b5b9
 # --- BEGIN COPYRIGHT BLOCK ---
51b5b9
-# Copyright (C) 2019 Red Hat, Inc.
51b5b9
+# Copyright (C) 2021 Red Hat, Inc.
51b5b9
 # All rights reserved.
51b5b9
 #
51b5b9
 # License: GPL (version 3 or any later version).
51b5b9
@@ -32,6 +32,7 @@ format_keys = [
51b5b9
     'backup_dir',
51b5b9
     'db_dir',
51b5b9
     'db_home_dir',
51b5b9
+    'ldapi',
51b5b9
     'ldif_dir',
51b5b9
     'lock_dir',
51b5b9
     'log_dir',
51b5b9
@@ -233,6 +234,10 @@ class Slapd2Base(Options2):
51b5b9
         self._helptext['local_state_dir'] = "Sets the location of Directory Server variable data. Only set this parameter in a development environment."
51b5b9
         self._advanced['local_state_dir'] = True
51b5b9
 
51b5b9
+        self._options['ldapi'] = ds_paths.ldapi
51b5b9
+        self._type['ldapi'] = str
51b5b9
+        self._helptext['ldapi'] = "Sets the location of socket interface of the Directory Server."
51b5b9
+
51b5b9
         self._options['lib_dir'] = ds_paths.lib_dir
51b5b9
         self._type['lib_dir'] = str
51b5b9
         self._helptext['lib_dir'] = "Sets the location of Directory Server shared libraries. Only set this parameter in a development environment."
51b5b9
diff --git a/src/lib389/lib389/instance/remove.py b/src/lib389/lib389/instance/remove.py
51b5b9
index d7bb48ce0..1a35ddc07 100644
51b5b9
--- a/src/lib389/lib389/instance/remove.py
51b5b9
+++ b/src/lib389/lib389/instance/remove.py
51b5b9
@@ -78,13 +78,16 @@ def remove_ds_instance(dirsrv, force=False):
51b5b9
 
51b5b9
     _log.debug("Found instance marker at %s! Proceeding to remove ..." % dse_ldif_path)
51b5b9
 
51b5b9
-    # Stop the instance (if running) and now we know it really does exist
51b5b9
-    # and hopefully have permission to access it ...
51b5b9
-    _log.debug("Stopping instance %s" % dirsrv.serverid)
51b5b9
-    dirsrv.stop()
51b5b9
-
51b5b9
     ### ANY NEW REMOVAL ACTION MUST BE BELOW THIS LINE!!!
51b5b9
 
51b5b9
+    # Remove LDAPI socket file
51b5b9
+    ldapi_path = os.path.join(dirsrv.ds_paths.run_dir, "slapd-%s.socket" % dirsrv.serverid)
51b5b9
+    if os.path.exists(ldapi_path):
51b5b9
+        try:
51b5b9
+            os.remove(ldapi_path)
51b5b9
+        except OSError as e:
51b5b9
+            _log.debug(f"Failed to remove LDAPI socket ({ldapi_path})  Error: {str(e)}")
51b5b9
+
51b5b9
     # Remove these paths:
51b5b9
     # for path in ('backup_dir', 'cert_dir', 'config_dir', 'db_dir',
51b5b9
     #             'ldif_dir', 'lock_dir', 'log_dir', 'run_dir'):
51b5b9
diff --git a/src/lib389/lib389/instance/setup.py b/src/lib389/lib389/instance/setup.py
51b5b9
index ab7a2da85..57e7a9fd4 100644
51b5b9
--- a/src/lib389/lib389/instance/setup.py
51b5b9
+++ b/src/lib389/lib389/instance/setup.py
51b5b9
@@ -732,7 +732,10 @@ class SetupDs(object):
51b5b9
                 dse += line.replace('%', '{', 1).replace('%', '}', 1)
51b5b9
 
51b5b9
         with open(os.path.join(slapd['config_dir'], 'dse.ldif'), 'w') as file_dse:
51b5b9
-            ldapi_path = os.path.join(slapd['local_state_dir'], "run/slapd-%s.socket" % slapd['instance_name'])
51b5b9
+            if os.path.exists(os.path.dirname(slapd['ldapi'])):
51b5b9
+                ldapi_path = slapd['ldapi']
51b5b9
+            else:
51b5b9
+                ldapi_path = os.path.join(slapd['run_dir'], "slapd-%s.socket" % slapd['instance_name'])
51b5b9
             dse_fmt = dse.format(
51b5b9
                 schema_dir=slapd['schema_dir'],
51b5b9
                 lock_dir=slapd['lock_dir'],
51b5b9
@@ -902,10 +905,13 @@ class SetupDs(object):
51b5b9
             self.log.info("Perform SELinux labeling ...")
51b5b9
             selinux_paths = ('backup_dir', 'cert_dir', 'config_dir', 'db_dir',
51b5b9
                              'ldif_dir', 'lock_dir', 'log_dir', 'db_home_dir',
51b5b9
-                             'run_dir', 'schema_dir', 'tmp_dir')
51b5b9
+                             'schema_dir', 'tmp_dir')
51b5b9
             for path in selinux_paths:
51b5b9
                 selinux_restorecon(slapd[path])
51b5b9
 
51b5b9
+            # Don't run restorecon on the entire /run directory
51b5b9
+            selinux_restorecon(slapd['run_dir'] + '/dirsrv')
51b5b9
+
51b5b9
             selinux_label_port(slapd['port'])
51b5b9
 
51b5b9
         # Start the server
51b5b9
-- 
51b5b9
2.31.1
51b5b9