]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
add and use chdir option
authorAlan T. DeKok <aland@freeradius.org>
Tue, 23 Sep 2025 11:29:36 +0000 (07:29 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Tue, 23 Sep 2025 15:11:57 +0000 (11:11 -0400)
so that the server will do a chdir after suid_down_permanent

raddb/radiusd.conf.in
src/bin/radiusd.c
src/lib/server/main_config.c
src/lib/server/main_config.h

index 380ea39052e2559231a5679ae4dda6a8da70c8cc..5ae0020be14271e49c728fed5bd5bede85517d4f 100644 (file)
@@ -540,6 +540,17 @@ security {
 #      user = radius
 #      group = radius
 
+       #
+       #  After the server has changed to the final user/group, it
+       #  can also set the current working directory.  While not
+       #  necessary, changing the working directory means that the
+       #  server does not have any dangling paths.
+       #
+       #  The directory here should either be "/", or ${confdir}
+       #
+#      chdir = ${confdir}
+
+
        #
        #  allow_core_dumps:: Core dumps are a bad thing.
        #
index 5791a74abf4000af7e3864e7a9a8c0a219638e7d..234710471b8e3336d4068af65c9ddf54a69f7baf 100644 (file)
@@ -881,6 +881,17 @@ int main(int argc, char *argv[])
         */
        rad_suid_down_permanent();
 
+       /*
+        *      Move the current working directory to a place where it
+        *      can't hurt anything.
+        */
+       if (main_config->chdir_is_set) {
+               if (chdir(main_config->chdir) < 0) {
+                       ERROR("Failed changing working to %s: %s", main_config->chdir, fr_syserror(errno));
+                       EXIT_WITH_FAILURE;
+               }
+       }
+
        DUMP_CAPABILITIES("post-suid-down");
 
        /*
index df29ef603a4afdce6287a38fce8a14cad0b6f2de..02c3c829f7ec0873af33af841ae2a9fbe1d1c61c 100644 (file)
@@ -274,6 +274,8 @@ static const conf_parser_t security_config[] = {
        { FR_CONF_OFFSET_IS_SET("openssl_fips_mode", FR_TYPE_BOOL, 0, main_config_t, openssl_fips_mode), .dflt = "no" },
 #endif
 
+       { FR_CONF_OFFSET_IS_SET("chdir", FR_TYPE_STRING, 0, main_config_t, chdir), },
+
        CONF_PARSER_TERMINATOR
 };
 
index e42850eadd441a5e911b84d748e87f464a1ebb6e..73be934fa2d79e352537b3cac1f32fc6e9c749fc 100644 (file)
@@ -102,6 +102,9 @@ struct main_config_s {
        bool            gid_is_set;
 #endif
 
+       char const      *chdir;                         //!< where to chdir() to when we start.
+       bool            chdir_is_set;
+
 #ifdef ENABLE_OPENSSL_VERSION_CHECK
        char const      *allow_vulnerable_openssl;      //!< The CVE number of the last security issue acknowledged.
 #endif