Skip to content

Commit

Permalink
Read custom dictionary _AFTER_ bootstrap has completed
Browse files Browse the repository at this point in the history
  • Loading branch information
arr2036 committed Oct 24, 2024
1 parent ba883a6 commit 428caa8
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/bin/radiusd.c
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,7 @@ int main(int argc, char *argv[])
*/
if (unlang_global_init() < 0) EXIT_WITH_FAILURE;

if (server_init(config->root_cs) < 0) EXIT_WITH_FAILURE;
if (server_init(config->root_cs, config->raddb_dir, fr_dict_unconst(fr_dict_internal())) < 0) EXIT_WITH_FAILURE;

/*
* Everything seems to have loaded OK, exit gracefully.
Expand Down
2 changes: 1 addition & 1 deletion src/bin/unit_test_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,7 @@ int main(int argc, char *argv[])
client_add(NULL, client);
}

if (server_init(config->root_cs) < 0) EXIT_WITH_FAILURE;
if (server_init(config->root_cs, config->raddb_dir, dict) < 0) EXIT_WITH_FAILURE;

vs = virtual_server_find("default");
if (!vs) {
Expand Down
25 changes: 23 additions & 2 deletions src/lib/server/base.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,22 @@ RCSID("$Id$")
#include <freeradius-devel/server/password.h>
#include <freeradius-devel/server/packet.h>
#include <freeradius-devel/unlang/xlat.h>
#include <freeradius-devel/util/dict.h>

extern bool tmpl_require_enum_prefix;

/** Initialize src/lib/server/
*
* This is just so that the callers don't need to call a million functions.
*
* @param cs The root configuration section.
* @param[in] cs The root configuration section.
* @param[in] dict_dir The path to the raddb directory.
* @param[in] dict the main dictionary, usually the internal dictionary.
* @return
* - 0 on success.
* - -1 on failure.
*/
int server_init(CONF_SECTION *cs)
int server_init(CONF_SECTION *cs, char const *dict_dir, fr_dict_t *dict)
{
/*
* Initialize the dictionary attributes needed by the tmpl code.
Expand Down Expand Up @@ -86,6 +89,24 @@ int server_init(CONF_SECTION *cs)
*/
if (xlat_protocols_register() < 0) return -1;

/*
* Load in the custom dictionary. We do this after the listeners
* have loaded their relevant dictionaries, and after the modules
* have created any attributes they need to, so that we can define
* additional protocol attributes, and add
*/
switch (fr_dict_read(dict, dict_dir, FR_DICTIONARY_FILE)) {
case -1:
PERROR("Error reading custom dictionary");
return -1;
case 0:
DEBUG2("Including dictionary file \"%s/%s\"", dict_dir, FR_DICTIONARY_FILE);
break;

default:
break;
}

/*
* And then load the virtual servers.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/lib/server/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,5 @@ RCSIDH(base_h, "$Id$")

#include <freeradius-devel/util/base.h>

int server_init(CONF_SECTION *cs);
int server_init(CONF_SECTION *cs, char const *dict_dir, fr_dict_t *dict);
void server_free(void);
19 changes: 0 additions & 19 deletions src/lib/server/main_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -1109,25 +1109,6 @@ int main_config_init(main_config_t *config)
goto failure;
}

#define DICT_READ_OPTIONAL(_d, _n) \
do {\
switch (fr_dict_read(config->dict, _d, _n)) {\
case -1:\
PERROR("Error reading dictionary \"%s/%s\"", _d, _n);\
goto failure;\
case 0:\
DEBUG2("Including dictionary file \"%s/%s\"", _d,_n);\
break;\
default:\
break;\
}\
} while (0)

/*
* It's OK if this one doesn't exist.
*/
DICT_READ_OPTIONAL(config->raddb_dir, FR_DICTIONARY_FILE);

/*
* Special-case things. If the output is a TTY, AND
* we're debugging, colourise things. This flag also
Expand Down
3 changes: 0 additions & 3 deletions src/tests/digest/config/dictionary
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
PROTOCOL RADIUS 1
BEGIN-PROTOCOL RADIUS

ATTRIBUTE Vendor-Specific 26 vsa


VENDOR TEST 32000

BEGIN-VENDOR TEST
Expand Down

0 comments on commit 428caa8

Please sign in to comment.