From: Alan T. DeKok Date: Tue, 9 Nov 2021 20:35:55 +0000 (-0500) Subject: be a bit more forgiving around registering xlats X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9f2c36dfdcae62944f82689d1297d5df4c992307;p=thirdparty%2Ffreeradius-server.git be a bit more forgiving around registering xlats for module instances like "foo { ... }" versus "foo bar { ... }". if the xlat is already registered, don't do anything. If it isn't registered, then register it --- diff --git a/src/modules/rlm_client/rlm_client.c b/src/modules/rlm_client/rlm_client.c index 1fd00e54a3..b18443cd39 100644 --- a/src/modules/rlm_client/rlm_client.c +++ b/src/modules/rlm_client/rlm_client.c @@ -358,9 +358,12 @@ static unlang_action_t CC_HINT(nonnull) mod_authorize(rlm_rcode_t *p_result, UNU * that must be referenced in later calls, store a handle to it * in *instance otherwise put a null pointer there. */ -static int mod_bootstrap(void *instance, UNUSED CONF_SECTION *conf) +static int mod_bootstrap(void *instance, CONF_SECTION *conf) { xlat_t *xlat; + + if (cf_section_name2(conf)) return 0; + xlat = xlat_register(instance, "client", xlat_client, false); xlat_func_args(xlat, xlat_client_args); map_proc_register(instance, "client", map_proc_client, NULL, 0); diff --git a/src/modules/rlm_dict/rlm_dict.c b/src/modules/rlm_dict/rlm_dict.c index 8068855397..abe7e0cb9e 100644 --- a/src/modules/rlm_dict/rlm_dict.c +++ b/src/modules/rlm_dict/rlm_dict.c @@ -225,9 +225,15 @@ static xlat_action_t xlat_attr_num(TALLOC_CTX *ctx, fr_dcursor_t *out, request_t * that must be referenced in later calls, store a handle to it * in *instance otherwise put a null pointer there. */ -static int mod_bootstrap(void *instance, UNUSED CONF_SECTION *conf) +static int mod_bootstrap(void *instance, CONF_SECTION *conf) { xlat_t *xlat; + + /* + * Only register these xlats for the first instance of the dictionary module. + */ + if (cf_section_name2(conf) != NULL) return 0; + xlat = xlat_register(instance, "attr_by_num", xlat_dict_attr_by_num, false); xlat_func_args(xlat, xlat_dict_attr_by_num_args); xlat = xlat_register(instance, "attr_by_oid", xlat_dict_attr_by_oid, false); diff --git a/src/modules/rlm_json/rlm_json.c b/src/modules/rlm_json/rlm_json.c index 6254e6fbbe..9562153ab4 100644 --- a/src/modules/rlm_json/rlm_json.c +++ b/src/modules/rlm_json/rlm_json.c @@ -561,9 +561,9 @@ static int mod_bootstrap(void *instance, CONF_SECTION *conf) if (!inst->name) inst->name = cf_section_name1(conf); xlat = xlat_register(instance, "jsonquote", json_quote_xlat, false); - xlat_func_mono(xlat, &json_quote_xlat_arg); + if (xlat) xlat_func_mono(xlat, &json_quote_xlat_arg); xlat = xlat_register(instance, "jpathvalidate", jpath_validate_xlat, false); - xlat_func_mono(xlat, &jpath_validate_xlat_arg); + if (xlat) xlat_func_mono(xlat, &jpath_validate_xlat_arg); name = talloc_asprintf(inst, "%s_encode", inst->name); xlat = xlat_register(instance, name, json_encode_xlat, false); diff --git a/src/modules/rlm_ldap/rlm_ldap.c b/src/modules/rlm_ldap/rlm_ldap.c index 42cbd667b7..0a9c5096a4 100644 --- a/src/modules/rlm_ldap/rlm_ldap.c +++ b/src/modules/rlm_ldap/rlm_ldap.c @@ -1881,10 +1881,12 @@ static int mod_bootstrap(void *instance, CONF_SECTION *conf) xlat = xlat_register(NULL, inst->name, ldap_xlat, false); xlat_func_mono(xlat, &ldap_xlat_arg); xlat_async_thread_instantiate_set(xlat, mod_xlat_thread_instantiate, ldap_xlat_thread_inst_t, NULL, inst); + xlat = xlat_register(NULL, "ldap_escape", ldap_escape_xlat, false); - xlat_func_mono(xlat, &ldap_escape_xlat_arg); + if (xlat) xlat_func_mono(xlat, &ldap_escape_xlat_arg); xlat = xlat_register(NULL, "ldap_unescape", ldap_unescape_xlat, false); - xlat_func_mono(xlat, &ldap_escape_xlat_arg); + if (xlat) xlat_func_mono(xlat, &ldap_escape_xlat_arg); + map_proc_register(inst, inst->name, mod_map_proc, ldap_map_verify, 0); return 0; diff --git a/src/modules/rlm_unpack/rlm_unpack.c b/src/modules/rlm_unpack/rlm_unpack.c index 89a554eb4d..992a8cfda7 100644 --- a/src/modules/rlm_unpack/rlm_unpack.c +++ b/src/modules/rlm_unpack/rlm_unpack.c @@ -149,10 +149,8 @@ static int mod_bootstrap(UNUSED void *instance, CONF_SECTION *conf) { xlat_t *xlat; - if (cf_section_name2(conf)) return 0; - xlat = xlat_register(NULL, "unpack", unpack_xlat, false); - xlat_func_args(xlat, unpack_xlat_args); + if (xlat) xlat_func_args(xlat, unpack_xlat_args); return 0; } diff --git a/src/modules/rlm_yubikey/rlm_yubikey.c b/src/modules/rlm_yubikey/rlm_yubikey.c index 1fd12eb443..39e51e795a 100644 --- a/src/modules/rlm_yubikey/rlm_yubikey.c +++ b/src/modules/rlm_yubikey/rlm_yubikey.c @@ -198,10 +198,8 @@ static int mod_bootstrap(void *instance, CONF_SECTION *conf) } #endif - if (cf_section_name2(conf)) return 0; - xlat = xlat_register(inst, "modhextohex", modhex_to_hex_xlat, false); - xlat_func_mono(xlat, &modhex_to_hex_xlat_arg); + if (xlat) xlat_func_mono(xlat, &modhex_to_hex_xlat_arg); return 0; }