From: Alan T. DeKok Date: Wed, 28 Jan 2026 21:43:29 +0000 (-0500) Subject: distinguish "load main config" from "load random config file" X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8ff1d7f254616570c7f62fddd348f843a1849961;p=thirdparty%2Ffreeradius-server.git distinguish "load main config" from "load random config file" 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. --- diff --git a/src/bin/unit_test_map.c b/src/bin/unit_test_map.c index 6f174ca8183..f4674ffb57c 100644 --- a/src/bin/unit_test_map.c +++ b/src/bin/unit_test_map.c @@ -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; } diff --git a/src/lib/server/cf_file.c b/src/lib/server/cf_file.c index f25f9be2b3e..fa705728d26 100644 --- a/src/lib/server/cf_file.c +++ b/src/lib/server/cf_file.c @@ -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)); diff --git a/src/lib/server/cf_file.h b/src/lib/server/cf_file.h index 6253120b2d3..9499851cff2 100644 --- a/src/lib/server/cf_file.h +++ b/src/lib/server/cf_file.h @@ -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); diff --git a/src/lib/server/client.c b/src/lib/server/client.c index a5fcaaf6c53..d1eac20cbd8 100644 --- a/src/lib/server/client.c +++ b/src/lib/server/client.c @@ -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; } diff --git a/src/lib/server/main_config.c b/src/lib/server/main_config.c index ed4bf1ddeb9..ef44add6be7 100644 --- a/src/lib/server/main_config.c +++ b/src/lib/server/main_config.c @@ -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; } diff --git a/src/listen/control/radmin.c b/src/listen/control/radmin.c index 12926f661ef..8c4b407e374 100644 --- a/src/listen/control/radmin.c +++ b/src/listen/control/radmin.c @@ -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); diff --git a/src/modules/rlm_redis_ippool/rlm_redis_ippool_tool.c b/src/modules/rlm_redis_ippool/rlm_redis_ippool_tool.c index b49be5f3f3d..efc8d4fd876 100644 --- a/src/modules/rlm_redis_ippool/rlm_redis_ippool_tool.c +++ b/src/modules/rlm_redis_ippool/rlm_redis_ippool_tool.c @@ -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); }