From: Nick Porter Date: Tue, 2 May 2023 16:56:52 +0000 (+0100) Subject: Switch mod_map to return unlang_action_t X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2c3f8cbae5971138306cfa33d9b13c2e32f89dc4;p=thirdparty%2Ffreeradius-server.git Switch mod_map to return unlang_action_t In preparation for async mod_map_proc in relevant modules --- diff --git a/src/bin/unit_test_module.c b/src/bin/unit_test_module.c index 4e426fdeeaa..6e2d9de3ea7 100644 --- a/src/bin/unit_test_module.c +++ b/src/bin/unit_test_module.c @@ -513,10 +513,11 @@ static int map_proc_verify(CONF_SECTION *cs, UNUSED void *mod_inst, UNUSED void return 0; } -static rlm_rcode_t mod_map_proc(UNUSED void *mod_inst, UNUSED void *proc_inst, UNUSED request_t *request, - UNUSED fr_value_box_list_t *src, UNUSED map_list_t const *maps) +static unlang_action_t mod_map_proc(rlm_rcode_t *p_result, UNUSED void *mod_inst, UNUSED void *proc_inst, + UNUSED request_t *request, UNUSED fr_value_box_list_t *src, + UNUSED map_list_t const *maps) { - return RLM_MODULE_FAIL; + RETURN_MODULE_FAIL; } static request_t *request_clone(request_t *old, int number, CONF_SECTION *server_cs) diff --git a/src/lib/server/map_proc.c b/src/lib/server/map_proc.c index fed7e7f91db..8e19454006e 100644 --- a/src/lib/server/map_proc.c +++ b/src/lib/server/map_proc.c @@ -192,14 +192,16 @@ map_proc_inst_t *map_proc_instantiate(TALLOC_CTX *ctx, map_proc_t const *proc, * Evaluate the map processor src template, then call a map processor function to do * something with the expanded src template and map the result to attributes in the request. * + * @param[out] p_result Result code of evaluating the map. * @param[in] request The current request. * @param[in] inst of a map processor. * @param[in,out] result Result of expanding the map input. May be consumed * by the map processor. + * @return one of UNLANG_ACTION_* */ -rlm_rcode_t map_proc(request_t *request, map_proc_inst_t const *inst, fr_value_box_list_t *result) +unlang_action_t map_proc(rlm_rcode_t *p_result, request_t *request, map_proc_inst_t const *inst, fr_value_box_list_t *result) { - return inst->proc->evaluate(inst->proc->mod_inst, inst->data, request, result, inst->maps); + return inst->proc->evaluate(p_result, inst->proc->mod_inst, inst->data, request, result, inst->maps); } /** Free all map_processors unregistering them diff --git a/src/lib/server/map_proc.h b/src/lib/server/map_proc.h index bce2804745e..62f1bf2e0dc 100644 --- a/src/lib/server/map_proc.h +++ b/src/lib/server/map_proc.h @@ -47,19 +47,20 @@ extern "C" { /** Function to evaluate the src string and map the result to server attributes * + * @param[out] p_result Result of applying the map: + * - #RLM_MODULE_NOOP - If no data available for given src, or no mappings matched available data. + * - #RLM_MODULE_UPDATED - If new pairs were added to the request. + * - #RLM_MODULE_FAIL - If an error occurred performing the mapping. * @param[in] mod_inst Instance of the module that registered the map_proc. * @param[in] proc_inst Map proc data created by #map_proc_instantiate_t. * @param[in] request The current request. * @param[in,out] result Input data for the map processor. May be consumed by the * map processor. * @param[in] maps Head of the list of maps to process. - * @return - * - #RLM_MODULE_NOOP - If no data available for given src, or no mappings matched available data. - * - #RLM_MODULE_UPDATED - If new pairs were added to the request. - * - #RLM_MODULE_FAIL - If an error occurred performing the mapping. + * @return one of UNLANG_ACTION_* */ -typedef rlm_rcode_t (*map_proc_func_t)(void *mod_inst, void *proc_inst, request_t *request, - fr_value_box_list_t *result, map_list_t const *maps); +typedef unlang_action_t (*map_proc_func_t)(rlm_rcode_t *p_result, void *mod_inst, void *proc_inst, request_t *request, + fr_value_box_list_t *result, map_list_t const *maps); /** Allocate new instance data for a map processor * @@ -85,7 +86,7 @@ int map_proc_register(void *mod_inst, char const *name, map_proc_inst_t *map_proc_instantiate(TALLOC_CTX *ctx, map_proc_t const *proc, CONF_SECTION *cs, tmpl_t const *src, map_list_t const *maps); -rlm_rcode_t map_proc(request_t *request, map_proc_inst_t const *inst, fr_value_box_list_t *src); +unlang_action_t map_proc(rlm_rcode_t *p_result, request_t *request, map_proc_inst_t const *inst, fr_value_box_list_t *src); #ifdef __cplusplus } diff --git a/src/lib/unlang/map.c b/src/lib/unlang/map.c index 1602c3da38e..640de57957d 100644 --- a/src/lib/unlang/map.c +++ b/src/lib/unlang/map.c @@ -291,6 +291,7 @@ static unlang_action_t map_proc_apply(rlm_rcode_t *p_result, request_t *request, map_proc_inst_t *inst = gext->proc_inst; unlang_frame_state_map_proc_t *map_proc_state = talloc_get_type_abort(frame->state, unlang_frame_state_map_proc_t); + unlang_action_t ret; RDEBUG2("MAP %s \"%pM\"", inst->proc->name, &map_proc_state->src_result); @@ -298,10 +299,10 @@ static unlang_action_t map_proc_apply(rlm_rcode_t *p_result, request_t *request, * FIXME - We don't yet support async LHS/RHS expansions for map procs */ VALUE_BOX_LIST_VERIFY(&map_proc_state->src_result); - *p_result = map_proc(request, gext->proc_inst, &map_proc_state->src_result); + ret = map_proc(p_result, request, gext->proc_inst, &map_proc_state->src_result); VALUE_BOX_LIST_VERIFY(&map_proc_state->src_result); - return UNLANG_ACTION_CALCULATE_RESULT; + return ret; } static unlang_action_t unlang_map_state_init(rlm_rcode_t *p_result, request_t *request, unlang_stack_frame_t *frame) diff --git a/src/modules/rlm_client/rlm_client.c b/src/modules/rlm_client/rlm_client.c index 6d559421e43..247efbfbf68 100644 --- a/src/modules/rlm_client/rlm_client.c +++ b/src/modules/rlm_client/rlm_client.c @@ -104,19 +104,20 @@ static int _map_proc_client_get_vp(TALLOC_CTX *ctx, fr_pair_list_t *out, request /** Map multiple attributes from a client into the request * + * @param[out] p_result Result of applying the map: + * - #RLM_MODULE_NOOP no rows were returned. + * - #RLM_MODULE_UPDATED if one or more #fr_pair_t were added to the #request_t. + * - #RLM_MODULE_FAIL if an error occurred. * @param[in] mod_inst NULL. * @param[in] proc_inst NULL. * @param[in] request The current request. * @param[in] client_override If NULL, use the current client, else use the client matching * the ip given. * @param[in] maps Head of the map list. - * @return - * - #RLM_MODULE_NOOP no rows were returned. - * - #RLM_MODULE_UPDATED if one or more #fr_pair_t were added to the #request_t. - * - #RLM_MODULE_FAIL if an error occurred. + * @return UNLANG_ACTION_CALCULATE_RESULT */ -static rlm_rcode_t map_proc_client(UNUSED void *mod_inst, UNUSED void *proc_inst, request_t *request, - fr_value_box_list_t *client_override, map_list_t const *maps) +static unlang_action_t map_proc_client(rlm_rcode_t *p_result, UNUSED void *mod_inst, UNUSED void *proc_inst, + request_t *request, fr_value_box_list_t *client_override, map_list_t const *maps) { rlm_rcode_t rcode = RLM_MODULE_OK; map_t const *map = NULL; @@ -137,7 +138,7 @@ static rlm_rcode_t map_proc_client(UNUSED void *mod_inst, UNUSED void *proc_inst FR_VALUE_BOX_LIST_FREE, true, SIZE_MAX) < 0) { REDEBUG("Failed concatenating input data"); - return RLM_MODULE_FAIL; + RETURN_MODULE_FAIL; } client_str = client_override_head->vb_strvalue; @@ -172,7 +173,7 @@ static rlm_rcode_t map_proc_client(UNUSED void *mod_inst, UNUSED void *proc_inst client = client_from_request(request); if (!client) { REDEBUG("No client associated with this request"); - return RLM_MODULE_FAIL; + RETURN_MODULE_FAIL; } } uctx.cs = client->cs; @@ -212,7 +213,7 @@ static rlm_rcode_t map_proc_client(UNUSED void *mod_inst, UNUSED void *proc_inst REXDENT(); finish: - return rcode; + RETURN_MODULE_RCODE(rcode); } static xlat_arg_parser_t const xlat_client_args[] = { diff --git a/src/modules/rlm_csv/rlm_csv.c b/src/modules/rlm_csv/rlm_csv.c index c1c5c8f7779..fa487d683a6 100644 --- a/src/modules/rlm_csv/rlm_csv.c +++ b/src/modules/rlm_csv/rlm_csv.c @@ -31,8 +31,8 @@ RCSID("$Id$") #include -static rlm_rcode_t mod_map_proc(void *mod_inst, UNUSED void *proc_inst, request_t *request, - fr_value_box_list_t *key, map_list_t const *maps); +static unlang_action_t mod_map_proc(rlm_rcode_t *p_result, void *mod_inst, UNUSED void *proc_inst, request_t *request, + fr_value_box_list_t *key, map_list_t const *maps); /* * Define a structure for our module configuration. @@ -965,25 +965,26 @@ finish: /** Perform a search and map the result of the search to server attributes * +* @param[out] p_result Result of applying map: + * - #RLM_MODULE_NOOP no rows were returned. + * - #RLM_MODULE_UPDATED if one or more #fr_pair_t were added to the #request_t. + * - #RLM_MODULE_FAIL if an error occurred. * @param[in] mod_inst #rlm_csv_t. * @param[in] proc_inst mapping map entries to field numbers. * @param[in,out] request The current request. * @param[in] key key to look for * @param[in] maps Head of the map list. - * @return - * - #RLM_MODULE_NOOP no rows were returned. - * - #RLM_MODULE_UPDATED if one or more #fr_pair_t were added to the #request_t. - * - #RLM_MODULE_FAIL if an error occurred. + * @return UNLANG_ACTION_CALCULATE_RESULT */ -static rlm_rcode_t mod_map_proc(void *mod_inst, UNUSED void *proc_inst, request_t *request, - fr_value_box_list_t *key, map_list_t const *maps) +static unlang_action_t mod_map_proc(rlm_rcode_t *p_result, void *mod_inst, UNUSED void *proc_inst, request_t *request, + fr_value_box_list_t *key, map_list_t const *maps) { rlm_csv_t *inst = talloc_get_type_abort(mod_inst, rlm_csv_t); fr_value_box_t *key_head = fr_value_box_list_head(key); if (!key_head) { REDEBUG("CSV key cannot be (null)"); - return RLM_MODULE_FAIL; + RETURN_MODULE_FAIL; } if ((inst->key_data_type == FR_TYPE_OCTETS) || (inst->key_data_type == FR_TYPE_STRING)) { @@ -992,11 +993,11 @@ static rlm_rcode_t mod_map_proc(void *mod_inst, UNUSED void *proc_inst, request_ FR_VALUE_BOX_LIST_FREE, true, SIZE_MAX) < 0) { REDEBUG("Failed parsing key"); - return RLM_MODULE_FAIL; + RETURN_MODULE_FAIL; } } - return mod_map_apply(inst, request, key_head, maps); + RETURN_MODULE_RCODE(mod_map_apply(inst, request, key_head, maps)); } diff --git a/src/modules/rlm_json/rlm_json.c b/src/modules/rlm_json/rlm_json.c index d21d867e609..93772b681f4 100644 --- a/src/modules/rlm_json/rlm_json.c +++ b/src/modules/rlm_json/rlm_json.c @@ -412,18 +412,19 @@ static int _json_map_proc_get_value(TALLOC_CTX *ctx, fr_pair_list_t *out, reques /** Parses a JSON string, and executes jpath queries against it to map values to attributes * + * @param p_result Result of applying map: + * - #RLM_MODULE_NOOP no rows were returned or columns matched. + * - #RLM_MODULE_UPDATED if one or more #fr_pair_t were added to the #request_t. + * - #RLM_MODULE_FAIL if a fault occurred. * @param mod_inst unused. * @param proc_inst cached jpath sequences. * @param request The current request. * @param json JSON string to parse. * @param maps Head of the map list. - * @return - * - #RLM_MODULE_NOOP no rows were returned or columns matched. - * - #RLM_MODULE_UPDATED if one or more #fr_pair_t were added to the #request_t. - * - #RLM_MODULE_FAIL if a fault occurred. + * @return UNLANG_ACTION_CALCULATE_RESULT */ -static rlm_rcode_t mod_map_proc(UNUSED void *mod_inst, void *proc_inst, request_t *request, - fr_value_box_list_t *json, map_list_t const *maps) +static unlang_action_t mod_map_proc(rlm_rcode_t *p_result, UNUSED void *mod_inst, void *proc_inst, request_t *request, + fr_value_box_list_t *json, map_list_t const *maps) { rlm_rcode_t rcode = RLM_MODULE_UPDATED; struct json_tokener *tok; @@ -438,7 +439,7 @@ static rlm_rcode_t mod_map_proc(UNUSED void *mod_inst, void *proc_inst, request_ if (!json_head) { REDEBUG("JSON map input cannot be (null)"); - return RLM_MODULE_FAIL; + RETURN_MODULE_FAIL; } if (fr_value_box_list_concat_in_place(request, @@ -446,13 +447,13 @@ static rlm_rcode_t mod_map_proc(UNUSED void *mod_inst, void *proc_inst, request_ FR_VALUE_BOX_LIST_FREE, true, SIZE_MAX) < 0) { REDEBUG("Failed concatenating input"); - return RLM_MODULE_FAIL; + RETURN_MODULE_FAIL; } json_str = json_head->vb_strvalue; if ((talloc_array_length(json_str) - 1) == 0) { REDEBUG("JSON map input length must be > 0"); - return RLM_MODULE_FAIL; + RETURN_MODULE_FAIL; } tok = json_tokener_new(); @@ -519,7 +520,7 @@ finish: json_object_put(to_eval.root); json_tokener_free(tok); - return rcode; + RETURN_MODULE_RCODE(rcode); } static int mod_bootstrap(module_inst_ctx_t const *mctx) diff --git a/src/modules/rlm_ldap/rlm_ldap.c b/src/modules/rlm_ldap/rlm_ldap.c index 029bf2a176b..094ad3a0b41 100644 --- a/src/modules/rlm_ldap/rlm_ldap.c +++ b/src/modules/rlm_ldap/rlm_ldap.c @@ -648,18 +648,19 @@ static int ldap_map_verify(CONF_SECTION *cs, UNUSED void *mod_inst, UNUSED void * @todo For xlat expansions we need to parse the raw URL first, and then apply * different escape functions to the different parts. * + * @param[out] p_result Result of map expansion: + * - #RLM_MODULE_NOOP no rows were returned. + * - #RLM_MODULE_UPDATED if one or more #fr_pair_t were added to the #request_t. + * - #RLM_MODULE_FAIL if an error occurred. * @param[in] mod_inst #rlm_ldap_t * @param[in] proc_inst unused. * @param[in,out] request The current request. * @param[in] url LDAP url specifying base DN and filter. * @param[in] maps Head of the map list. - * @return - * - #RLM_MODULE_NOOP no rows were returned. - * - #RLM_MODULE_UPDATED if one or more #fr_pair_t were added to the #request_t. - * - #RLM_MODULE_FAIL if an error occurred. + * @return UNLANG_ACTION_CALCULATE_RESULT */ -static rlm_rcode_t mod_map_proc(void *mod_inst, UNUSED void *proc_inst, request_t *request, - fr_value_box_list_t *url, map_list_t const *maps) +static unlang_action_t mod_map_proc(rlm_rcode_t *p_result, void *mod_inst, UNUSED void *proc_inst, request_t *request, + fr_value_box_list_t *url, map_list_t const *maps) { rlm_rcode_t rcode = RLM_MODULE_UPDATED; rlm_ldap_t *inst = talloc_get_type_abort(mod_inst, rlm_ldap_t); @@ -683,7 +684,7 @@ static rlm_rcode_t mod_map_proc(void *mod_inst, UNUSED void *proc_inst, request_ */ if (!url_head) { REDEBUG("LDAP URL cannot be (null)"); - return RLM_MODULE_FAIL; + RETURN_MODULE_FAIL; } if (fr_value_box_list_concat_in_place(request, @@ -691,18 +692,18 @@ static rlm_rcode_t mod_map_proc(void *mod_inst, UNUSED void *proc_inst, request_ FR_VALUE_BOX_LIST_FREE, true, SIZE_MAX) < 0) { REDEBUG("Failed concatenating input"); - return RLM_MODULE_FAIL; + RETURN_MODULE_FAIL; } url_str = url_head->vb_strvalue; if (!ldap_is_ldap_url(url_str)) { REDEBUG("Map query string does not look like a valid LDAP URI"); - return RLM_MODULE_FAIL; + RETURN_MODULE_FAIL; } if (ldap_url_parse(url_str, &ldap_url)){ REDEBUG("Parsing LDAP URL failed"); - return RLM_MODULE_FAIL; + RETURN_MODULE_FAIL; } /* @@ -814,7 +815,7 @@ free_expanded: free_urldesc: ldap_free_urldesc(ldap_url); - return rcode; + RETURN_MODULE_RCODE(rcode); } /** Perform LDAP-Group comparison checking diff --git a/src/modules/rlm_sql/rlm_sql.c b/src/modules/rlm_sql/rlm_sql.c index a20a7370764..865dd9d8ceb 100644 --- a/src/modules/rlm_sql/rlm_sql.c +++ b/src/modules/rlm_sql/rlm_sql.c @@ -370,18 +370,19 @@ static int sql_map_verify(CONF_SECTION *cs, UNUSED void *mod_inst, UNUSED void * /** Executes a SELECT query and maps the result to server attributes * + * @param p_result Result of map expansion: + * - #RLM_MODULE_NOOP no rows were returned or columns matched. + * - #RLM_MODULE_UPDATED if one or more #fr_pair_t were added to the #request_t. + * - #RLM_MODULE_FAIL if a fault occurred. * @param mod_inst #rlm_sql_t instance. * @param proc_inst Instance data for this specific mod_proc call (unused). * @param request The current request. * @param query string to execute. * @param maps Head of the map list. - * @return - * - #RLM_MODULE_NOOP no rows were returned or columns matched. - * - #RLM_MODULE_UPDATED if one or more #fr_pair_t were added to the #request_t. - * - #RLM_MODULE_FAIL if a fault occurred. + * @return UNLANG_ACTION_CALCULATE_RESULT */ -static rlm_rcode_t mod_map_proc(void *mod_inst, UNUSED void *proc_inst, request_t *request, - fr_value_box_list_t *query, map_list_t const *maps) +static unlang_action_t mod_map_proc(rlm_rcode_t *p_result, void *mod_inst, UNUSED void *proc_inst, request_t *request, + fr_value_box_list_t *query, map_list_t const *maps) { rlm_sql_t *inst = talloc_get_type_abort(mod_inst, rlm_sql_t); rlm_sql_handle_t *handle = NULL; @@ -412,7 +413,7 @@ static rlm_rcode_t mod_map_proc(void *mod_inst, UNUSED void *proc_inst, request_ if (!query_head) { REDEBUG("Query cannot be (null)"); - return RLM_MODULE_FAIL; + RETURN_MODULE_FAIL; } if (fr_value_box_list_concat_in_place(request, @@ -420,7 +421,7 @@ static rlm_rcode_t mod_map_proc(void *mod_inst, UNUSED void *proc_inst, request_ FR_VALUE_BOX_LIST_FREE, true, SIZE_MAX) < 0) { RPEDEBUG("Failed concatenating input string"); - return RLM_MODULE_FAIL; + RETURN_MODULE_FAIL; } query_str = query_head->vb_strvalue; @@ -435,7 +436,7 @@ static rlm_rcode_t mod_map_proc(void *mod_inst, UNUSED void *proc_inst, request_ handle = fr_pool_connection_get(inst->pool, request); /* connection pool should produce error */ if (!handle) { - rcode = RLM_MODULE_FAIL; + RETURN_MODULE_FAIL; goto finish; } @@ -547,7 +548,7 @@ finish: talloc_free(fields); fr_pool_connection_release(inst->pool, request, handle); - return rcode; + RETURN_MODULE_RCODE(rcode); }