]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
distinguish "load main config" from "load random config file" developer/alandekok master
authorAlan T. DeKok <aland@freeradius.org>
Wed, 28 Jan 2026 21:43:29 +0000 (16:43 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Wed, 28 Jan 2026 22:00:18 +0000 (17:00 -0500)
and ensure that we add a top-level "raddbdir", just in case some
configuration doesn't have the horrible mapping

raddbdir = foo
confdir = ${raddbdir}

Now that raddbdir is gone, we want to ensure that pre-4.0.0 configs
still work.

src/bin/unit_test_map.c
src/lib/server/cf_file.c
src/lib/server/cf_file.h
src/lib/server/client.c
src/lib/server/main_config.c
src/listen/control/radmin.c
src/modules/rlm_redis_ippool/rlm_redis_ippool_tool.c

index 6f174ca81835937bf2f51aaa571cc3d1828e4114..f4674ffb57cdb2c1af452d1fdd15c2778f1a545f 100644 (file)
@@ -97,7 +97,7 @@ static int process_file(char const *filename)
        config->root_cs = cf_section_alloc(config, NULL, "main", NULL);
        cf_section_set_unlang(config->root_cs);
 
-       if ((cf_file_read(config->root_cs, filename) < 0) || (cf_section_pass2(config->root_cs) < 0)) {
+       if ((cf_file_read(config->root_cs, filename, true) < 0) || (cf_section_pass2(config->root_cs) < 0)) {
                fprintf(stderr, "unit_test_map: Failed parsing %s\n", filename);
                return EXIT_FAILURE;
        }
index f25f9be2b3e1e1f3a2fa5d1a12462a25417825d6..fa705728d26a55e354c6464f98b35ff77eb1622d 100644 (file)
@@ -3563,20 +3563,35 @@ static void cf_stack_cleanup(cf_stack_t *stack)
 /*
  *     Bootstrap a config file.
  */
-int cf_file_read(CONF_SECTION *cs, char const *filename)
+int cf_file_read(CONF_SECTION *cs, char const *filename, bool root)
 {
        int             i;
-       char            *p;
-       CONF_PAIR       *cp;
        fr_rb_tree_t    *tree;
        cf_stack_t      stack;
        cf_stack_frame_t        *frame;
 
-       cp = cf_pair_alloc(cs, "confdir", filename, T_OP_EQ, T_BARE_WORD, T_SINGLE_QUOTED_STRING);
-       if (!cp) return -1;
+       /*
+        *      Only add the default config directory if we're loading a top-level configuration file.
+        */
+       if (root) {
+               char      *p;
+               CONF_PAIR *cp;
+
+               /*
+                *      For compatibility, this goes first.  And we don't care if there are too many '/'.
+                */
+               cp = cf_pair_alloc(cs, "raddbdir", filename, T_OP_EQ, T_BARE_WORD, T_SINGLE_QUOTED_STRING);
+               if (!cp) return -1;
 
-       p = strrchr(cp->value, FR_DIR_SEP);
-       if (p) *p = '\0';
+               /*
+                *      This goes second, and we try to be nice about too many '/'.
+                */
+               cp = cf_pair_alloc(cs, "confdir", filename, T_OP_EQ, T_BARE_WORD, T_SINGLE_QUOTED_STRING);
+               if (!cp) return -1;
+
+               p = strrchr(cp->value, FR_DIR_SEP);
+               if (p) *p = '\0';
+       }
 
        MEM(tree = fr_rb_inline_talloc_alloc(cs, cf_file_t, node, _inode_cmp, NULL));
 
index 6253120b2d3966a1c3efa25fe3819986867d44e5..9499851cff2261e3b46636f13ff683de9bffe0af 100644 (file)
@@ -53,7 +53,7 @@ typedef enum {
 /*
  *     Config file parsing
  */
-int                    cf_file_read(CONF_SECTION *cs, char const *file);
+int                    cf_file_read(CONF_SECTION *cs, char const *file, bool root);
 int                    cf_section_pass2(CONF_SECTION *cs);
 void                   cf_file_free(CONF_SECTION *cs);
 
index a5fcaaf6c537fb0fa1a44909112d5d545895fe48..d1eac20cbd8e08a1a7811ae1e95fbd7085153fbc 100644 (file)
@@ -1069,7 +1069,7 @@ fr_client_t *client_read(char const *filename, CONF_SECTION *server_cs, bool che
        cs = cf_section_alloc(NULL, NULL, "main", NULL);
        if (!cs) return NULL;
 
-       if ((cf_file_read(cs, filename) < 0) || (cf_section_pass2(cs) < 0)) {
+       if ((cf_file_read(cs, filename, false) < 0) || (cf_section_pass2(cs) < 0)) {
                talloc_free(cs);
                return NULL;
        }
index ed4bf1ddeb961e22495818c039685523fe2c9460..ef44add6be73920d22cb02edf99ea739a994ca7c 100644 (file)
@@ -1116,7 +1116,7 @@ int main_config_init(main_config_t *config)
 
        /* Read the configuration file */
        snprintf(buffer, sizeof(buffer), "%.200s/%.50s.conf", config->confdir, config->name);
-       if (cf_file_read(cs, buffer) < 0) {
+       if (cf_file_read(cs, buffer, true) < 0) {
                ERROR("Error reading or parsing %s", buffer);
                goto failure;
        }
index 12926f661ef87bfffc59f3e17abbd32333c48fdc..8c4b407e374fd94c8245e8756d0506f0c8bffb60 100644 (file)
@@ -992,7 +992,7 @@ int main(int argc, char **argv)
                cs = cf_section_alloc(autofree, NULL, "main", NULL);
                if (!cs) fr_exit_now(EXIT_FAILURE);
 
-               if ((cf_file_read(cs, io_buffer) < 0) || (cf_section_pass2(cs) < 0)) {
+               if ((cf_file_read(cs, io_buffer, true) < 0) || (cf_section_pass2(cs) < 0)) {
                        fprintf(stderr, "%s: Errors reading or parsing %s\n", progname, io_buffer);
                error:
                        fr_exit_now(EXIT_FAILURE);
index b49be5f3f3df9e76fd6c60eb9359dad8460aa79b..efc8d4fd876e5c819a1cdaeb405a497c4bda5cbf 100644 (file)
@@ -1595,7 +1595,7 @@ do { \
        /*
         *      Read configuration files if necessary.
         */
-       if (filename && (cf_file_read(conf->cs, filename) < 0 || (cf_section_pass2(conf->cs) < 0))) {
+       if (filename && (cf_file_read(conf->cs, filename, true) < 0 || (cf_section_pass2(conf->cs) < 0))) {
                fr_exit_now(EXIT_FAILURE);
        }