From: Alan T. DeKok Date: Mon, 4 Nov 2019 22:11:31 +0000 (-0500) Subject: move dlopen() to load by protocol X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8ac616d54bdf2e3249dc60ceca8c9cf6eb0a3445;p=thirdparty%2Ffreeradius-server.git move dlopen() to load by protocol --- diff --git a/src/lib/util/dict_priv.h b/src/lib/util/dict_priv.h index 3c12777f53b..90757f01118 100644 --- a/src/lib/util/dict_priv.h +++ b/src/lib/util/dict_priv.h @@ -100,7 +100,9 @@ extern TALLOC_CTX *dict_ctx; extern fr_table_num_ordered_t const date_precision_table[]; extern size_t date_precision_table_len; -fr_dict_t *dict_alloc(TALLOC_CTX *ctx, char const *name); +fr_dict_t *dict_alloc(TALLOC_CTX *ctx); + +int dict_dlopen(fr_dict_t *dict, char const *name); /** Initialise fields in a dictionary attribute structure * diff --git a/src/lib/util/dict_tokenize.c b/src/lib/util/dict_tokenize.c index 7c7f2bbc6ba..3aabb7ffc8e 100644 --- a/src/lib/util/dict_tokenize.c +++ b/src/lib/util/dict_tokenize.c @@ -1236,7 +1236,17 @@ static int dict_read_process_protocol(char **argv, int argc) return 0; } - dict = dict_alloc(NULL, argv[0]); + dict = dict_alloc(NULL); + + /* + * Try to load protocol-specific validation routines. + * Some protocols don't need them, so it's OK if the + * validation routines don't exist. + */ + if (dict_dlopen(dict, argv[0]) < 0) { + talloc_free(dict); + return -1; + } /* * Set the root attribute with the protocol name @@ -2240,7 +2250,7 @@ int fr_dict_internal_afrom_file(fr_dict_t **out, char const *dict_subdir) memcpy(&tmp, &dict_dir_default, sizeof(tmp)); dict_path = dict_subdir ? talloc_asprintf(NULL, "%s%c%s", dict_dir_default, FR_DIR_SEP, dict_subdir) : tmp; - dict = dict_alloc(dict_ctx, NULL); + dict = dict_alloc(dict_ctx); if (!dict) { error: if (!fr_dict_internal) talloc_free(dict); diff --git a/src/lib/util/dict_util.c b/src/lib/util/dict_util.c index 4359496f9e9..8e74371bb4f 100644 --- a/src/lib/util/dict_util.c +++ b/src/lib/util/dict_util.c @@ -2153,7 +2153,7 @@ fr_dict_enum_t *fr_dict_enum_by_alias(fr_dict_attr_t const *da, char const *alia return fr_hash_table_finddata(dict->values_by_alias, &find); } -static int dict_dlopen(fr_dict_t *dict, char const *name) +int dict_dlopen(fr_dict_t *dict, char const *name) { char *module_name; char *p, *q; @@ -2208,11 +2208,10 @@ static int _dict_free(fr_dict_t *dict) /** Allocate a new dictionary * * @param[in] ctx to allocate dictionary in. - * @param[in] name the name of the protocol * @return * - NULL on memory allocation error. */ -fr_dict_t *dict_alloc(TALLOC_CTX *ctx, char const *name) +fr_dict_t *dict_alloc(TALLOC_CTX *ctx) { fr_dict_t *dict; @@ -2273,11 +2272,11 @@ fr_dict_t *dict_alloc(TALLOC_CTX *ctx, char const *name) dict->values_by_da = fr_hash_table_create(dict, dict_enum_value_hash, dict_enum_value_cmp, hash_pool_free); if (!dict->values_by_da) goto error; - if (dict_dlopen(dict, name) < 0) goto error; - /* - * Try to load libfreeradius-NAME + * Set default type size and length. */ + dict->default_type_size = 1; + dict->default_type_length = 1; return dict; }