From: Alan T. DeKok Date: Mon, 7 May 2018 15:34:00 +0000 (-0400) Subject: add dictionary directory to fr_dict_autoload() X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=1793054089003e243f9e7678201623f7fc2cd728;p=thirdparty%2Ffreeradius-server.git add dictionary directory to fr_dict_autoload() --- diff --git a/src/include/dict.h b/src/include/dict.h index 101f050f766..1afe0d0f565 100644 --- a/src/include/dict.h +++ b/src/include/dict.h @@ -351,7 +351,7 @@ int fr_dict_read(fr_dict_t *dict, char const *dir, char const *filename); */ int fr_dict_attr_autoload(fr_dict_attr_autoload_t const *to_load); -int fr_dict_autoload(fr_dict_autoload_t const *to_load); +int fr_dict_autoload(char const *dir, fr_dict_autoload_t const *to_load); void fr_dict_autofree(fr_dict_autoload_t const *to_free); /** @} */ diff --git a/src/lib/util/dict.c b/src/lib/util/dict.c index 0fb8ab4e1c6..30703094b78 100644 --- a/src/lib/util/dict.c +++ b/src/lib/util/dict.c @@ -5281,33 +5281,34 @@ int fr_dict_attr_autoload(fr_dict_attr_autoload_t const *to_load) /** Process a dict_autoload element to load a protocol * + * @param[in] dir directory where the dictionaries are stored. * @param[in] to_load dictionary definition. * @return * - 0 on success. * - -1 on failure. */ -int fr_dict_autoload(fr_dict_autoload_t const *to_load) +int fr_dict_autoload(char const *dir, fr_dict_autoload_t const *to_load) { fr_dict_t *dict = NULL; fr_dict_autoload_t const *p; + char const *my_dir; for (p = to_load; p->out; p++) { + my_dir = dir; + if (unlikely(!p->out)) { fr_strerror_printf("autoload missing parameter out"); return -1; } - if (unlikely(!p->base_dir)) { - fr_strerror_printf("autoload missing parameter base_dir"); - return 0; /* Change to -1 later */ - } + if (p->base_dir) my_dir = p->base_dir; if (unlikely(!p->proto)) { fr_strerror_printf("autoload missing parameter proto"); return -1; } - if (fr_dict_protocol_afrom_file(NULL, &dict, p->base_dir, p->proto) < 0) return -1; + if (fr_dict_protocol_afrom_file(NULL, &dict, my_dir, p->proto) < 0) return -1; if (p->out) *(p->out) = dict; } diff --git a/src/main/mainconfig.c b/src/main/mainconfig.c index ecda8d760c5..38c0c82a9e8 100644 --- a/src/main/mainconfig.c +++ b/src/main/mainconfig.c @@ -274,7 +274,7 @@ static int _module_dict_autoload(dl_t const *module, void *symbol, UNUSED void * { DEBUG("Loading dictionary %s", module->name); - if (fr_dict_autoload((fr_dict_autoload_t const *)symbol) < 0) { + if (fr_dict_autoload(main_config.dictionary_dir, (fr_dict_autoload_t const *)symbol) < 0) { ERROR("Failed loading dictionary: %s", fr_strerror()); return -1; } diff --git a/src/main/module.c b/src/main/module.c index c4826287f55..31252cb4087 100644 --- a/src/main/module.c +++ b/src/main/module.c @@ -954,7 +954,7 @@ static int virtual_module_bootstrap(CONF_SECTION *modules, CONF_SECTION *vm_cs) #if 0 static int _module_dict_autoload(dl_t const *module, void *symbol, UNUSED void *user_ctx) { - if (fr_dict_autoload((fr_dict_autoload_t *)symbol) < 0) { + if (fr_dict_autoload(main_config.dictionary_dir, (fr_dict_autoload_t *)symbol) < 0) { ERROR("Failed loading dictionary: %s", fr_strerror()); return -1; } diff --git a/src/modules/rlm_eap/lib/base/eap_base.c b/src/modules/rlm_eap/lib/base/eap_base.c index 76d42f0a7dd..3a1d3e334c4 100644 --- a/src/modules/rlm_eap/lib/base/eap_base.c +++ b/src/modules/rlm_eap/lib/base/eap_base.c @@ -423,7 +423,7 @@ rlm_rcode_t eap_virtual_server(REQUEST *request, REQUEST *fake, */ int eap_base_init(void) { - if (fr_dict_autoload(eap_base_dict) < 0) return -1; + if (fr_dict_autoload(main_config.dictionary_dir, eap_base_dict) < 0) return -1; if (fr_dict_attr_autoload(eap_base_dict_attr) < 0) return -1; return 0;