From: Arran Cudbard-Bell Date: Wed, 15 May 2024 21:50:10 +0000 (-0600) Subject: Remove more module-list specific lookup functions X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=529973c4d714d7d4c3f19acafc75b36980dff1c8;p=thirdparty%2Ffreeradius-server.git Remove more module-list specific lookup functions rlm_sql_ippool and rlm_sql_counter won't work with dynamic modules... but that's OK, because the way they depend on other modules is stupid, and needs to be fixed anyway. --- diff --git a/src/lib/server/module.c b/src/lib/server/module.c index f67f5eb9a1f..9b1f2d5f17f 100644 --- a/src/lib/server/module.c +++ b/src/lib/server/module.c @@ -467,9 +467,9 @@ static int mlg_thread_init(UNUSED TALLOC_CTX **ctx, UNUSED module_list_t const * * * @param[in] mi Module instance to get the thread-specific data for. */ -static module_thread_instance_t *mlg_thread_data_get(module_instance_t *mi) +static module_thread_instance_t *mlg_thread_data_get(module_instance_t const *mi) { - mlg_module_instance_t *mlg_mi = (mlg_module_instance_t *)talloc_get_type_abort(mi, module_instance_t); + mlg_module_instance_t const *mlg_mi = (mlg_module_instance_t const *)talloc_get_type_abort_const(mi, module_instance_t); module_thread_instance_t *ti; fr_assert_msg(mlg_mi->inst_idx <= talloc_array_length(mlg_thread_inst_list), @@ -535,9 +535,9 @@ static void mltl_mlg_data_del(module_instance_t *mi) if (mltl_mi->ti) module_thread_detach(mltl_mi->ti); } -static module_thread_instance_t *mltl_thread_data_get(module_instance_t *mi) +static module_thread_instance_t *mltl_thread_data_get(module_instance_t const *mi) { - mltl_module_instance_t *mltl_mi = (mltl_module_instance_t *)talloc_get_type_abort(mi, module_instance_t); + mltl_module_instance_t const *mltl_mi = (mltl_module_instance_t *)talloc_get_type_abort_const(mi, module_instance_t); return mltl_mi->ti; } diff --git a/src/lib/server/module.h b/src/lib/server/module.h index ed05320fdd6..05380981aa4 100644 --- a/src/lib/server/module.h +++ b/src/lib/server/module.h @@ -327,7 +327,7 @@ struct module_thread_instance_s { * - NULL if no data exists. * - Pointer to the data on success. */ -typedef module_thread_instance_t *(*module_list_thread_data_get_t)(module_instance_t *mi); +typedef module_thread_instance_t *(*module_list_thread_data_get_t)(module_instance_t const *mi); /** A list of modules * @@ -436,7 +436,7 @@ module_instance_t *module_instance_by_data(module_list_t const *ml, void const * * - NULL if module has no thread instance data. */ static inline CC_HINT(warn_unused_result) CC_HINT(always_inline) -module_thread_instance_t *module_thread(module_instance_t *mi) +module_thread_instance_t *module_thread(module_instance_t const *mi) { return mi->ml->thread_data_get(mi); } diff --git a/src/lib/server/module_rlm.c b/src/lib/server/module_rlm.c index 2d67bde3f31..647463dfc9a 100644 --- a/src/lib/server/module_rlm.c +++ b/src/lib/server/module_rlm.c @@ -474,7 +474,7 @@ module_instance_t *module_rlm_by_name_and_method(module_method_t *method, call_e * Module names are allowed to contain '.' * so we search for the bare module name first. */ - mi = module_instance_by_name(rlm_modules_static, NULL, name); + mi = module_rlm_static_by_name(NULL, name); if (mi) { virtual_server_method_t const *allowed_list; @@ -793,12 +793,7 @@ CONF_SECTION *module_rlm_by_name_virtual(char const *asked_name) return inst->cs; } -module_thread_instance_t *module_rlm_thread_by_data(void const *data) -{ - return module_thread_by_data(rlm_modules_static, data); -} - -module_instance_t *module_rlm_by_name(module_instance_t const *parent, char const *asked_name) +module_instance_t *module_rlm_static_by_name(module_instance_t const *parent, char const *asked_name) { return module_instance_by_name(rlm_modules_static, parent, asked_name); } diff --git a/src/lib/server/module_rlm.h b/src/lib/server/module_rlm.h index 7332ea3e2f3..2df0749ef3d 100644 --- a/src/lib/server/module_rlm.h +++ b/src/lib/server/module_rlm.h @@ -94,9 +94,7 @@ module_instance_t *module_rlm_by_name_and_method(module_method_t *method, call_e char const **name1, char const **name2, char const *asked_name); -module_thread_instance_t *module_rlm_thread_by_data(void const *data); - -module_instance_t *module_rlm_by_name(module_instance_t const *parent, char const *asked_name); +module_instance_t *module_rlm_static_by_name(module_instance_t const *parent, char const *asked_name); CONF_SECTION *module_rlm_by_name_virtual(char const *asked_name); diff --git a/src/lib/unlang/xlat_inst.c b/src/lib/unlang/xlat_inst.c index fd05d2a9aaa..33bcef8cf38 100644 --- a/src/lib/unlang/xlat_inst.c +++ b/src/lib/unlang/xlat_inst.c @@ -158,7 +158,7 @@ static xlat_thread_inst_t *xlat_thread_inst_alloc(TALLOC_CTX *ctx, fr_event_list module_ctx_t *mctx; mctx = module_ctx_from_inst(xt, call->func->mctx); - mctx->thread = module_rlm_thread_by_data(mctx->mi->data)->data; + mctx->thread = module_thread(mctx->mi)->data; xt->mctx = mctx; } diff --git a/src/modules/rlm_ldap/rlm_ldap.c b/src/modules/rlm_ldap/rlm_ldap.c index e551bc559e6..562074731ea 100644 --- a/src/modules/rlm_ldap/rlm_ldap.c +++ b/src/modules/rlm_ldap/rlm_ldap.c @@ -1286,7 +1286,7 @@ static unlang_action_t mod_map_proc(rlm_rcode_t *p_result, void const *mod_inst, fr_value_box_list_t *url, map_list_t const *maps) { rlm_ldap_t const *inst = talloc_get_type_abort_const(mod_inst, rlm_ldap_t); - fr_ldap_thread_t *thread = talloc_get_type_abort(module_rlm_thread_by_data(inst)->data, fr_ldap_thread_t); + fr_ldap_thread_t *thread = talloc_get_type_abort(module_thread(inst->mi)->data, fr_ldap_thread_t); LDAPURLDesc *ldap_url; int ldap_url_ret; @@ -1428,7 +1428,7 @@ static unlang_action_t mod_authenticate_resume(rlm_rcode_t *p_result, UNUSED int static unlang_action_t CC_HINT(nonnull) mod_authenticate(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request) { rlm_ldap_t const *inst = talloc_get_type_abort_const(mctx->mi->data, rlm_ldap_t); - fr_ldap_thread_t *thread = talloc_get_type_abort(module_rlm_thread_by_data(inst)->data, fr_ldap_thread_t); + fr_ldap_thread_t *thread = talloc_get_type_abort(module_thread(inst->mi), fr_ldap_thread_t); ldap_auth_ctx_t *auth_ctx; ldap_auth_call_env_t *call_env = talloc_get_type_abort(mctx->env_data, ldap_auth_call_env_t); @@ -1616,7 +1616,7 @@ static unlang_action_t mod_authorize_resume(rlm_rcode_t *p_result, UNUSED int *p if (inst->edir && inst->edir_autz) { fr_pair_t *password = fr_pair_find_by_da(&request->control_pairs, NULL, attr_cleartext_password); - fr_ldap_thread_t *thread = talloc_get_type_abort(module_rlm_thread_by_data(inst)->data, + fr_ldap_thread_t *thread = talloc_get_type_abort(module_thread(inst->mi)->data, fr_ldap_thread_t); if (!password) { @@ -1808,7 +1808,7 @@ static int autz_ctx_free(ldap_autz_ctx_t *autz_ctx) static unlang_action_t CC_HINT(nonnull) mod_authorize(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request) { rlm_ldap_t const *inst = talloc_get_type_abort_const(mctx->mi->data, rlm_ldap_t); - fr_ldap_thread_t *thread = talloc_get_type_abort(module_rlm_thread_by_data(inst)->data, fr_ldap_thread_t); + fr_ldap_thread_t *thread = talloc_get_type_abort(module_thread(inst->mi)->data, fr_ldap_thread_t); ldap_autz_ctx_t *autz_ctx; fr_ldap_map_exp_t *expanded; ldap_autz_call_env_t *call_env = talloc_get_type_abort(mctx->env_data, ldap_autz_call_env_t); @@ -1965,7 +1965,7 @@ static unlang_action_t user_modify(rlm_rcode_t *p_result, rlm_ldap_t const *inst ldap_acct_section_t *section, ldap_usermod_call_env_t *call_env) { rlm_rcode_t rcode = RLM_MODULE_FAIL; - fr_ldap_thread_t *thread = talloc_get_type_abort(module_rlm_thread_by_data(inst)->data, fr_ldap_thread_t); + fr_ldap_thread_t *thread = talloc_get_type_abort(module_thread(inst->mi)->data, fr_ldap_thread_t); ldap_user_modify_ctx_t *usermod_ctx = NULL; int total = 0, last_pass = 0; @@ -2400,6 +2400,7 @@ static int mod_instantiate(module_inst_ctx_t const *mctx) rlm_ldap_t *inst = talloc_get_type_abort(mctx->mi->data, rlm_ldap_t); CONF_SECTION *conf = mctx->mi->conf; + inst->mi = mctx->mi; /* Cached for IO callbacks */ inst->group.da = boot->group_da; inst->group.cache_da = boot->cache_da; diff --git a/src/modules/rlm_ldap/rlm_ldap.h b/src/modules/rlm_ldap/rlm_ldap.h index 0ae07cc940c..1440e74eb77 100644 --- a/src/modules/rlm_ldap/rlm_ldap.h +++ b/src/modules/rlm_ldap/rlm_ldap.h @@ -127,6 +127,8 @@ typedef struct { fr_ldap_config_t handle_config; //!< Connection configuration instance. fr_trunk_conf_t trunk_conf; //!< Trunk configuration fr_trunk_conf_t bind_trunk_conf; //!< Trunk configuration for trunk used for bind auths + + module_instance_t const *mi; //!< Module instance data for thread lookups. } rlm_ldap_t; /** Call environment used in LDAP authorization diff --git a/src/modules/rlm_sqlcounter/rlm_sqlcounter.c b/src/modules/rlm_sqlcounter/rlm_sqlcounter.c index 77cc598f9ba..c9162239e97 100644 --- a/src/modules/rlm_sqlcounter/rlm_sqlcounter.c +++ b/src/modules/rlm_sqlcounter/rlm_sqlcounter.c @@ -508,7 +508,7 @@ static int mod_instantiate(module_inst_ctx_t const *mctx) module_instance_t const *sql_inst; fr_assert(inst->query && *inst->query); - sql_inst = module_rlm_by_name(NULL, inst->sql_name); + sql_inst = module_rlm_static_by_name(NULL, inst->sql_name); if (!sql_inst) { cf_log_err(conf, "Module \"%s\" not found", inst->sql_name); return -1; diff --git a/src/modules/rlm_sqlippool/rlm_sqlippool.c b/src/modules/rlm_sqlippool/rlm_sqlippool.c index 82a682bdee6..8f1f526cf47 100644 --- a/src/modules/rlm_sqlippool/rlm_sqlippool.c +++ b/src/modules/rlm_sqlippool/rlm_sqlippool.c @@ -241,7 +241,7 @@ static int mod_instantiate(module_inst_ctx_t const *mctx) inst->name = talloc_asprintf(inst, "%s - %s", mctx->mi->name, inst->sql_name); - sql = module_rlm_by_name(NULL, inst->sql_name); + sql = module_rlm_static_by_name(NULL, inst->sql_name); if (!sql) { cf_log_err(conf, "failed to find sql instance named %s", inst->sql_name); @@ -598,7 +598,7 @@ static int call_env_parse(TALLOC_CTX *ctx, void *out, tmpl_rules_t const *t_rule /* * Lookup the sql module instance. */ - sql_inst = module_rlm_by_name(NULL, inst->sql_name); + sql_inst = module_rlm_static_by_name(NULL, inst->sql_name); if (!sql_inst) return -1; sql = talloc_get_type_abort(sql_inst->data, rlm_sql_t);