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

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