From 543202555995864e1b02d690daa26067e81c2fab Mon Sep 17 00:00:00 2001 From: Viktor Ashirov Date: Aug 11 2020 19:42:52 +0000 Subject: Issue 51039 - systemd-tmpfiles warnings Bug Description: systemd-tmpfiles warns about legacy paths in our tmpfiles configs. Using /var/run also introduces a race condition, see the following issue https://pagure.io/389-ds-base/issue/47429 Fix Description: Instead of using @localstatedir@/run use @localrundir@ which was introduced in #47513. Relates: https://pagure.io/389-ds-base/issue/47429 Fixes: https://pagure.io/389-ds-base/issue/51039 Reviewed by: mreynolds, firstyear, tbordaz (Thanks!) --- diff --git a/Makefile.am b/Makefile.am index 3f21645..0e3c931 100644 --- a/Makefile.am +++ b/Makefile.am @@ -141,7 +141,8 @@ PATH_DEFINES = -DLOCALSTATEDIR="\"$(localstatedir)\"" -DSYSCONFDIR="\"$(sysconfd -DLIBDIR="\"$(libdir)\"" -DBINDIR="\"$(bindir)\"" \ -DDATADIR="\"$(datadir)\"" -DDOCDIR="\"$(docdir)\"" \ -DSBINDIR="\"$(sbindir)\"" -DPLUGINDIR="\"$(serverplugindir)\"" \ - -DTEMPLATEDIR="\"$(sampledatadir)\"" -DSYSTEMSCHEMADIR="\"$(systemschemadir)\"" + -DTEMPLATEDIR="\"$(sampledatadir)\"" -DSYSTEMSCHEMADIR="\"$(systemschemadir)\"" \ + -DLOCALRUNDIR="\"$(localrundir)\"" # Now that we have all our defines in place, setup the CPPFLAGS diff --git a/configure.ac b/configure.ac index 4843a82..99a647e 100644 --- a/configure.ac +++ b/configure.ac @@ -427,7 +427,14 @@ fi m4_include(m4/fhs.m4) -localrundir='/run' +# /run directory path +AC_ARG_WITH([localrundir], + AS_HELP_STRING([--with-localrundir=DIR], + [Runtime data directory]), + [localrundir=$with_localrundir], + [localrundir="/run"]) +AC_SUBST([localrundir]) + cockpitdir=/389-console # installation paths - by default, we store everything @@ -908,7 +915,6 @@ AC_SUBST(ldaplib_defs) AC_SUBST(ldaptool_bindir) AC_SUBST(ldaptool_opts) AC_SUBST(plainldif_opts) -AC_SUBST(localrundir) AC_SUBST(brand) AC_SUBST(capbrand) diff --git a/dirsrvtests/tests/suites/basic/basic_test.py b/dirsrvtests/tests/suites/basic/basic_test.py index 878cef7..9982ca5 100644 --- a/dirsrvtests/tests/suites/basic/basic_test.py +++ b/dirsrvtests/tests/suites/basic/basic_test.py @@ -835,7 +835,6 @@ def test_basic_ldapagent(topology_st, import_example_ldif): """ log.info('Running test_basic_ldapagent...') - var_dir = topology_st.standalone.get_local_state_dir() config_file = os.path.join(topology_st.standalone.get_sysconf_dir(), 'dirsrv/config/agent.conf') @@ -849,7 +848,8 @@ def test_basic_ldapagent(topology_st, import_example_ldif): # Remember, this is *forking* check_output([os.path.join(topology_st.standalone.get_sbin_dir(), 'ldap-agent'), config_file]) # First kill any previous agents .... - pidpath = os.path.join(var_dir, 'run/ldap-agent.pid') + run_dir = topology_st.standalone.get_run_dir() + pidpath = os.path.join(run_dir, 'ldap-agent.pid') pid = None with open(pidpath, 'r') as pf: pid = pf.readlines()[0].strip() diff --git a/ldap/admin/src/defaults.inf.in b/ldap/admin/src/defaults.inf.in index 2f630f9..df966e5 100644 --- a/ldap/admin/src/defaults.inf.in +++ b/ldap/admin/src/defaults.inf.in @@ -35,10 +35,10 @@ sysconf_dir = @sysconfdir@ initconfig_dir = @initconfigdir@ config_dir = @instconfigdir@/slapd-{instance_name} local_state_dir = @localstatedir@ -run_dir = @localstatedir@/run/dirsrv +run_dir = @localrundir@ # This is the expected location of ldapi. -ldapi = @localstatedir@/run/slapd-{instance_name}.socket -pid_file = @localstatedir@/run/dirsrv/slapd-{instance_name}.pid +ldapi = @localrundir@/slapd-{instance_name}.socket +pid_file = @localrundir@/slapd-{instance_name}.pid inst_dir = @serverdir@/slapd-{instance_name} plugin_dir = @serverplugindir@ system_schema_dir = @systemschemadir@ @@ -52,7 +52,7 @@ root_dn = cn=Directory Manager schema_dir = @instconfigdir@/slapd-{instance_name}/schema cert_dir = @instconfigdir@/slapd-{instance_name} -lock_dir = @localstatedir@/lock/dirsrv/slapd-{instance_name} +lock_dir = @localrundir@/lock/dirsrv/slapd-{instance_name} log_dir = @localstatedir@/log/dirsrv/slapd-{instance_name} access_log = @localstatedir@/log/dirsrv/slapd-{instance_name}/access audit_log = @localstatedir@/log/dirsrv/slapd-{instance_name}/audit diff --git a/ldap/servers/snmp/main.c b/ldap/servers/snmp/main.c index 4b672ea..e5beb3c 100644 --- a/ldap/servers/snmp/main.c +++ b/ldap/servers/snmp/main.c @@ -286,14 +286,14 @@ load_config(char *conf_path) } /* set pidfile path */ - if ((pidfile = malloc(strlen(LOCALSTATEDIR) + strlen("/run/") + + if ((pidfile = malloc(strlen(LOCALRUNDIR) + strlen("/") + strlen(LDAP_AGENT_PIDFILE) + 1)) != NULL) { - strncpy(pidfile, LOCALSTATEDIR, strlen(LOCALSTATEDIR) + 1); + strncpy(pidfile, LOCALRUNDIR, strlen(LOCALRUNDIR) + 1); /* The above will likely not be NULL terminated, but we need to * be sure that we're properly NULL terminated for the below * strcat() to work properly. */ - pidfile[strlen(LOCALSTATEDIR)] = (char)0; - strcat(pidfile, "/run/"); + pidfile[strlen(LOCALRUNDIR)] = (char)0; + strcat(pidfile, "/"); strcat(pidfile, LDAP_AGENT_PIDFILE); } else { printf("ldap-agent: malloc error processing config file\n"); diff --git a/src/lib389/lib389/__init__.py b/src/lib389/lib389/__init__.py index c3dc6f2..56cb10e 100644 --- a/src/lib389/lib389/__init__.py +++ b/src/lib389/lib389/__init__.py @@ -1695,6 +1695,9 @@ class DirSrv(SimpleLDAPObject, object): def get_bin_dir(self): return self.ds_paths.bin_dir + def get_run_dir(self): + return self.ds_paths.run_dir + def get_plugin_dir(self): return self.ds_paths.plugin_dir diff --git a/src/lib389/lib389/instance/options.py b/src/lib389/lib389/instance/options.py index fd60d43..699f836 100644 --- a/src/lib389/lib389/instance/options.py +++ b/src/lib389/lib389/instance/options.py @@ -25,6 +25,7 @@ format_keys = [ 'sysconf_dir', 'data_dir', 'local_state_dir', + 'ldapi', 'lib_dir', 'cert_dir', 'config_dir', @@ -216,6 +217,10 @@ class Slapd2Base(Options2): self._type['local_state_dir'] = str self._helptext['local_state_dir'] = "Sets the location of Directory Server variable data. Only set this parameter in a development environment." + self._options['ldapi'] = ds_paths.ldapi + self._type['ldapi'] = str + self._helptext['ldapi'] = "Sets the location of socket interface of the Directory Server." + self._options['lib_dir'] = ds_paths.lib_dir self._type['lib_dir'] = str self._helptext['lib_dir'] = "Sets the location of Directory Server shared libraries. Only set this parameter in a development environment." diff --git a/src/lib389/lib389/instance/setup.py b/src/lib389/lib389/instance/setup.py index 418b71b..bf97bf1 100644 --- a/src/lib389/lib389/instance/setup.py +++ b/src/lib389/lib389/instance/setup.py @@ -966,7 +966,10 @@ class SetupDs(object): raise ValueError("Suffix RDN '{}' in '{}' is not supported. Supported RDN's are: 'c', 'cn', 'dc', 'o', and 'ou'".format(suffix_rdn_attr, backend['nsslapd-suffix'])) # Initialise ldapi socket information. IPA expects this .... - ldapi_path = os.path.join(slapd['local_state_dir'], "run/slapd-%s.socket" % slapd['instance_name']) + if os.path.exists(os.path.dirname(slapd['ldapi'])): + ldapi_path = slapd['ldapi'] + else: + ldapi_path = os.path.join(slapd['run_dir'], "slapd-%s.socket" % slapd['instance_name']) ds_instance.config.set('nsslapd-ldapifilepath', ldapi_path) ds_instance.config.set('nsslapd-ldapilisten', 'on') ds_instance.config.set('nsslapd-ldapiautobind', 'on')