]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Remove useless calls to unlang_function_push and just use unlang_module_yield
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Sat, 31 May 2025 19:26:30 +0000 (13:26 -0600)
committerNick Porter <nick@portercomputing.co.uk>
Wed, 18 Jun 2025 12:53:02 +0000 (13:53 +0100)
Adding new stack frames is expensive, and there's no need to do this as we can just mutate the module's frame

src/modules/rlm_mschap/rlm_mschap.c
src/modules/rlm_sql/rlm_sql.c
src/modules/rlm_sqlcounter/rlm_sqlcounter.c
src/modules/rlm_sqlippool/rlm_sqlippool.c

index 9b7217719bab19af28a6368e53bca66b84758176..dc54db09f7f6876c0529df9050ba34c76e398d47 100644 (file)
@@ -1911,9 +1911,9 @@ static unlang_action_t CC_HINT(nonnull) mschap_process_v2_response(rlm_rcode_t *
 /** Complete mschap authentication after any tmpls have been expanded.
  *
  */
-static unlang_action_t mod_authenticate_resume(unlang_result_t *p_result, request_t *request, void *uctx)
+static unlang_action_t mod_authenticate_resume(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request)
 {
-       mschap_auth_ctx_t       *auth_ctx = talloc_get_type_abort(uctx, mschap_auth_ctx_t);
+       mschap_auth_ctx_t       *auth_ctx = talloc_get_type_abort(mctx->rctx, mschap_auth_ctx_t);
        mschap_auth_call_env_t  *env_data = talloc_get_type_abort(auth_ctx->env_data, mschap_auth_call_env_t);
        rlm_mschap_t const      *inst = talloc_get_type_abort_const(auth_ctx->inst, rlm_mschap_t);
        fr_pair_t               *challenge = NULL;
@@ -1931,11 +1931,11 @@ static unlang_action_t mod_authenticate_resume(unlang_result_t *p_result, reques
                 */
                if (!auth_ctx->nt_password) {
                        REDEBUG("Missing Password.NT - required for change password request");
-                       RETURN_UNLANG_FAIL;
+                       RETURN_MODULE_FAIL;
                }
                if (!env_data->chap_nt_enc_pw) {
                        REDEBUG("chap_nt_enc_pw option is not set - required for change password request");
-                       RETURN_UNLANG_INVALID;
+                       RETURN_MODULE_INVALID;
                }
 
                mschap_process_cpw_request(&rcode, inst, request, auth_ctx);
@@ -2052,22 +2052,7 @@ static unlang_action_t mod_authenticate_resume(unlang_result_t *p_result, reques
        } /* else we weren't asked to use MPPE */
 
 finish:
-       RETURN_UNLANG_RCODE(rcode);
-}
-
-/** When changing passwords using the ntlm_auth helper, evaluate the domain tmpl
- *
- */
-static unlang_action_t mod_authenticate_domain_tmpl_push(unlang_result_t *p_result, request_t *request, void *uctx)
-{
-       mschap_auth_ctx_t       *auth_ctx = talloc_get_type_abort(uctx, mschap_auth_ctx_t);
-       mschap_auth_call_env_t  *env_data = talloc_get_type_abort(auth_ctx->env_data, mschap_auth_call_env_t);
-
-       fr_value_box_list_init(&auth_ctx->cpw_ctx->cpw_domain);
-       if (unlang_tmpl_push(auth_ctx, &auth_ctx->cpw_ctx->cpw_domain, request,
-                            env_data->ntlm_cpw_domain, NULL) < 0) RETURN_UNLANG_FAIL;
-
-       return UNLANG_ACTION_PUSHED_CHILD;
+       RETURN_MODULE_RCODE(rcode);
 }
 
 #ifdef WITH_TLS
@@ -2318,8 +2303,10 @@ static unlang_action_t CC_HINT(nonnull) mod_authenticate(rlm_rcode_t *p_result,
                case AUTH_INTERNAL:
 #ifdef WITH_TLS
                        if (mschap_new_pass_decrypt(request, auth_ctx) < 0) RETURN_MODULE_FAIL;
-                       if (unlang_function_push(NULL, request, NULL,  mod_authenticate_resume, NULL, 0,
-                                                UNLANG_SUB_FRAME, auth_ctx) < 0) RETURN_MODULE_FAIL;
+
+                       if (unlang_module_yield(request, mod_authenticate_resume, NULL, 0, auth_ctx) != UNLANG_ACTION_YIELD) {
+                               RETURN_MODULE_FAIL;
+                       }
 
                        fr_value_box_list_init(&auth_ctx->cpw_ctx->local_cpw_result);
                        if (unlang_tmpl_push(auth_ctx, &auth_ctx->cpw_ctx->local_cpw_result, request,
@@ -2336,11 +2323,27 @@ static unlang_action_t CC_HINT(nonnull) mod_authenticate(rlm_rcode_t *p_result,
                                RETURN_MODULE_FAIL;
                        }
 
-                       if (unlang_function_push(NULL, request, env_data->ntlm_cpw_domain ? mod_authenticate_domain_tmpl_push : NULL,
-                                                mod_authenticate_resume, NULL, 0,
-                                                UNLANG_SUB_FRAME, auth_ctx) < 0) RETURN_MODULE_FAIL;
+                       /*
+                        *      Run the resumption function where we're done with:
+                        */
+                       if (unlang_module_yield(request, mod_authenticate_resume, NULL, 0, auth_ctx) != UNLANG_ACTION_YIELD) {
+                               RETURN_MODULE_FAIL;
+                       };
+
+                       /*
+                        *      a) Expanding the domain, if specified
+                        */
+                       if (env_data->ntlm_cpw_domain) {
+                               fr_value_box_list_init(&auth_ctx->cpw_ctx->cpw_domain);
+                               if (unlang_tmpl_push(auth_ctx, &auth_ctx->cpw_ctx->cpw_domain, request,
+                                               env_data->ntlm_cpw_domain, NULL) < 0) RETURN_MODULE_FAIL;
+                       }
 
                        fr_value_box_list_init(&auth_ctx->cpw_ctx->cpw_user);
+
+                       /*
+                        *      b) Expanding the username
+                        */
                        if (unlang_tmpl_push(auth_ctx, &auth_ctx->cpw_ctx->cpw_user, request,
                                             env_data->ntlm_cpw_username, NULL) < 0) RETURN_MODULE_FAIL;
                        break;
@@ -2349,7 +2352,15 @@ static unlang_action_t CC_HINT(nonnull) mod_authenticate(rlm_rcode_t *p_result,
                return UNLANG_ACTION_PUSHED_CHILD;
        }
 
-       return unlang_function_push(NULL, request, mod_authenticate_resume, NULL, NULL, 0, UNLANG_SUB_FRAME, 0);
+       /*
+        *      Not doing password change, just jump straight to the resumption function...
+        */
+       {
+               module_ctx_t our_mctx = *mctx;
+               our_mctx.rctx = auth_ctx;
+
+               return mod_authenticate_resume(p_result, &our_mctx, request);
+       }
 }
 
 /*
index 8e93a78abffd3ae79668a08ab01cee208af5b8d3..5fece5bccaa6a35d702c396a66100da9bdeca3fc 100644 (file)
@@ -34,12 +34,16 @@ RCSID("$Id$")
 #include <freeradius-devel/server/map_proc.h>
 #include <freeradius-devel/server/module_rlm.h>
 #include <freeradius-devel/server/pairmove.h>
+#include <freeradius-devel/server/rcode.h>
 #include <freeradius-devel/util/debug.h>
 #include <freeradius-devel/util/dict.h>
 #include <freeradius-devel/util/skip.h>
 #include <freeradius-devel/util/table.h>
+#include <freeradius-devel/unlang/action.h>
 #include <freeradius-devel/unlang/function.h>
 #include <freeradius-devel/unlang/xlat_func.h>
+#include <freeradius-devel/unlang/module.h>
+#include <freeradius-devel/unlang/map.h>
 
 #include <sys/stat.h>
 
@@ -589,7 +593,6 @@ static xlat_action_t sql_xlat(TALLOC_CTX *ctx, fr_dcursor_t *out,
 
        unlang_xlat_yield(request, sql_xlat_select_resume, NULL, 0, query_ctx);
        if (unlang_function_push(NULL, request, inst->select, NULL, NULL, 0, UNLANG_SUB_FRAME, query_ctx) != UNLANG_ACTION_PUSHED_CHILD) return XLAT_ACTION_FAIL;
-
        return XLAT_ACTION_PUSH_UNLANG;
 }
 
@@ -619,7 +622,6 @@ static xlat_action_t sql_fetch_xlat(UNUSED TALLOC_CTX *ctx, UNUSED fr_dcursor_t
 
        unlang_xlat_yield(request, sql_xlat_select_resume, NULL, 0, query_ctx);
        if (unlang_function_push(NULL, request, inst->select, NULL, NULL, 0, UNLANG_SUB_FRAME, query_ctx) != UNLANG_ACTION_PUSHED_CHILD) return XLAT_ACTION_FAIL;
-
        return XLAT_ACTION_PUSH_UNLANG;
 }
 
@@ -1090,7 +1092,6 @@ static unlang_action_t sql_get_grouplist(sql_group_ctx_t *group_ctx, trunk_t *tr
                                                      group_ctx->query->vb_strvalue, SQL_QUERY_SELECT));
 
        if (unlang_function_push(NULL, request, NULL, sql_get_grouplist_resume, NULL, 0, UNLANG_SUB_FRAME, group_ctx) < 0) return UNLANG_ACTION_FAIL;
-
        return unlang_function_push(NULL, request, inst->select, NULL, NULL, 0, UNLANG_SUB_FRAME, group_ctx->query_ctx);
 }
 
@@ -1153,8 +1154,9 @@ static xlat_action_t sql_group_xlat_resume(UNUSED TALLOC_CTX *ctx, UNUSED fr_dcu
 
        if (unlang_xlat_yield(request, sql_group_xlat_query_resume, NULL, 0, xlat_ctx) != XLAT_ACTION_YIELD) return XLAT_ACTION_FAIL;
 
-       if (sql_get_grouplist(xlat_ctx->group_ctx, thread->trunk, request) != UNLANG_ACTION_PUSHED_CHILD)
-                       return XLAT_ACTION_FAIL;
+       if (sql_get_grouplist(xlat_ctx->group_ctx, thread->trunk, request) != UNLANG_ACTION_PUSHED_CHILD) {
+               return XLAT_ACTION_FAIL;
+       }
 
        return XLAT_ACTION_PUSH_UNLANG;
 }
@@ -1265,13 +1267,13 @@ static int sql_autz_ctx_free(sql_autz_ctx_t *to_free)
  * Before each query is run, &request.SQL-Group is populated with the value of the group being evaluated.
  *
  * @param p_result     Result of current authorization.
- * @param request      Current request.
- * @param uctx         Current authorization context.
+ * @param mctx         Current request.
+ * @param request      Current authorization context.
  * @return one of the RLM_MODULE_* values.
  */
-static unlang_action_t mod_autz_group_resume(unlang_result_t *p_result, request_t *request, void *uctx)
+static unlang_action_t CC_HINT(nonnull)  mod_autz_group_resume(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request)
 {
-       sql_autz_ctx_t          *autz_ctx = talloc_get_type_abort(uctx, sql_autz_ctx_t);
+       sql_autz_ctx_t          *autz_ctx = talloc_get_type_abort(mctx->rctx, sql_autz_ctx_t);
        sql_autz_call_env_t     *call_env = autz_ctx->call_env;
        sql_group_ctx_t         *group_ctx = autz_ctx->group_ctx;
        fr_sql_map_ctx_t        *map_ctx = autz_ctx->map_ctx;
@@ -1280,7 +1282,7 @@ static unlang_action_t mod_autz_group_resume(unlang_result_t *p_result, request_
        sql_fall_through_t      do_fall_through = FALL_THROUGH_DEFAULT;
        fr_pair_t               *vp;
 
-       switch (p_result->rcode) {
+       switch (*p_result) {
        case RLM_MODULE_USER_SECTION_REJECT:
                return UNLANG_ACTION_CALCULATE_RESULT;
 
@@ -1290,7 +1292,7 @@ static unlang_action_t mod_autz_group_resume(unlang_result_t *p_result, request_
 
        switch(autz_ctx->status) {
        case SQL_AUTZ_GROUP_MEMB:
-               if (unlang_function_repeat_set(request, mod_autz_group_resume) < 0) RETURN_UNLANG_FAIL;
+               if (unlang_module_yield(request, mod_autz_group_resume, NULL, 0, mctx->rctx) != UNLANG_ACTION_YIELD) RETURN_MODULE_FAIL;
                MEM(autz_ctx->group_ctx = talloc(autz_ctx, sql_group_ctx_t));
                *autz_ctx->group_ctx = (sql_group_ctx_t) {
                        .inst = inst,
@@ -1339,9 +1341,9 @@ static unlang_action_t mod_autz_group_resume(unlang_result_t *p_result, request_
                }
 
                if (call_env->group_check_query) {
-                       if (unlang_function_repeat_set(request, mod_autz_group_resume) < 0) RETURN_UNLANG_FAIL;
+                       if (unlang_module_yield(request, mod_autz_group_resume, NULL, 0, mctx->rctx) != UNLANG_ACTION_YIELD) RETURN_MODULE_FAIL;
                        if (unlang_tmpl_push(autz_ctx, &autz_ctx->query, request,
-                                            call_env->group_check_query, NULL) < 0) RETURN_UNLANG_FAIL;
+                                            call_env->group_check_query, NULL) < 0) RETURN_MODULE_FAIL;
                        return UNLANG_ACTION_PUSHED_CHILD;
                }
 
@@ -1359,7 +1361,7 @@ static unlang_action_t mod_autz_group_resume(unlang_result_t *p_result, request_
                        .query = query,
                };
 
-               if (unlang_function_repeat_set(request, mod_autz_group_resume) < 0) RETURN_UNLANG_FAIL;
+               if (unlang_module_yield(request, mod_autz_group_resume, NULL, 0, mctx->rctx) != UNLANG_ACTION_YIELD) RETURN_MODULE_FAIL;
                if (sql_get_map_list(request, map_ctx, autz_ctx->trunk) == UNLANG_ACTION_PUSHED_CHILD) {
                        autz_ctx->status = autz_ctx->status & SQL_AUTZ_STAGE_GROUP ? SQL_AUTZ_GROUP_CHECK_RESUME : SQL_AUTZ_PROFILE_CHECK_RESUME;
                        return UNLANG_ACTION_PUSHED_CHILD;
@@ -1393,9 +1395,9 @@ static unlang_action_t mod_autz_group_resume(unlang_result_t *p_result, request_
 
                if (call_env->group_reply_query) {
                group_reply_push:
-                       if (unlang_function_repeat_set(request, mod_autz_group_resume) < 0) RETURN_UNLANG_FAIL;
+                       if (unlang_module_yield(request, mod_autz_group_resume, NULL, 0, mctx->rctx) != UNLANG_ACTION_YIELD) RETURN_MODULE_FAIL;
                        if (unlang_tmpl_push(autz_ctx, &autz_ctx->query, request,
-                                            call_env->group_reply_query, NULL) < 0) RETURN_UNLANG_FAIL;
+                                            call_env->group_reply_query, NULL) < 0) RETURN_MODULE_FAIL;
                        autz_ctx->status = autz_ctx->status & SQL_AUTZ_STAGE_GROUP ? SQL_AUTZ_GROUP_REPLY : SQL_AUTZ_PROFILE_REPLY;
                        return UNLANG_ACTION_PUSHED_CHILD;
                }
@@ -1415,7 +1417,7 @@ static unlang_action_t mod_autz_group_resume(unlang_result_t *p_result, request_
                        .expand_rhs = true,
                };
 
-               if (unlang_function_repeat_set(request, mod_autz_group_resume) < 0) RETURN_UNLANG_FAIL;
+               if (unlang_module_yield(request, mod_autz_group_resume, NULL, 0, mctx->rctx) != UNLANG_ACTION_YIELD) RETURN_MODULE_FAIL;
                if (sql_get_map_list(request, map_ctx, autz_ctx->trunk) == UNLANG_ACTION_PUSHED_CHILD) {
                        autz_ctx->status = autz_ctx->status & SQL_AUTZ_STAGE_GROUP ? SQL_AUTZ_GROUP_REPLY_RESUME : SQL_AUTZ_PROFILE_REPLY_RESUME;
                        return UNLANG_ACTION_PUSHED_CHILD;
@@ -1450,7 +1452,7 @@ static unlang_action_t mod_autz_group_resume(unlang_result_t *p_result, request_
                if (radius_legacy_map_list_apply(request, &autz_ctx->reply_tmp, NULL) < 0) {
                        RPEDEBUG("Failed applying reply item");
                        REXDENT();
-                       RETURN_UNLANG_FAIL;
+                       RETURN_MODULE_FAIL;
                }
                REXDENT();
                map_list_talloc_free(&autz_ctx->reply_tmp);
@@ -1487,21 +1489,21 @@ static unlang_action_t mod_autz_group_resume(unlang_result_t *p_result, request_
                }
        }
 
-       if (!autz_ctx->user_found) RETURN_UNLANG_NOTFOUND;
+       if (!autz_ctx->user_found) RETURN_MODULE_NOTFOUND;
 
-       RETURN_UNLANG_RCODE(autz_ctx->rcode);
+       RETURN_MODULE_RCODE(autz_ctx->rcode);
 }
 
 /** Resume function called after authorization check / reply tmpl expansion
  *
  * @param p_result     Result of current authorization.
+ * @param mctx         Module call ctx.
  * @param request      Current request.
- * @param uctx         Current authorization context.
  * @return one of the RLM_MODULE_* values.
  */
-static unlang_action_t mod_authorize_resume(unlang_result_t *p_result, request_t *request, void *uctx)
+static unlang_action_t CC_HINT(nonnull) mod_authorize_resume(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request)
 {
-       sql_autz_ctx_t          *autz_ctx = talloc_get_type_abort(uctx, sql_autz_ctx_t);
+       sql_autz_ctx_t          *autz_ctx = talloc_get_type_abort(mctx->rctx, sql_autz_ctx_t);
        sql_autz_call_env_t     *call_env = autz_ctx->call_env;
        rlm_sql_t const         *inst = autz_ctx->inst;
        fr_value_box_t          *query = fr_value_box_list_pop_head(&autz_ctx->query);
@@ -1511,7 +1513,7 @@ static unlang_action_t mod_authorize_resume(unlang_result_t *p_result, request_t
        /*
         *      If a previous async call returned one of the "failure" results just return.
         */
-       switch (p_result->rcode) {
+       switch (*p_result) {
        case RLM_MODULE_USER_SECTION_REJECT:
                return UNLANG_ACTION_CALCULATE_RESULT;
 
@@ -1529,7 +1531,7 @@ static unlang_action_t mod_authorize_resume(unlang_result_t *p_result, request_t
                        .query = query,
                };
 
-               if (unlang_function_repeat_set(request, mod_authorize_resume) < 0) RETURN_UNLANG_FAIL;
+               if (unlang_module_yield(request, mod_authorize_resume, NULL, 0, autz_ctx) != UNLANG_ACTION_YIELD) RETURN_MODULE_FAIL;
                if (sql_get_map_list(request, map_ctx, autz_ctx->trunk) == UNLANG_ACTION_PUSHED_CHILD){
                        autz_ctx->status = SQL_AUTZ_CHECK_RESUME;
                        return UNLANG_ACTION_PUSHED_CHILD;
@@ -1556,8 +1558,8 @@ static unlang_action_t mod_authorize_resume(unlang_result_t *p_result, request_t
 
                if (!call_env->reply_query) goto skip_reply;
 
-               if (unlang_function_repeat_set(request, mod_authorize_resume) < 0) RETURN_UNLANG_FAIL;
-               if (unlang_tmpl_push(autz_ctx, &autz_ctx->query, request, call_env->reply_query, NULL) < 0) RETURN_UNLANG_FAIL;
+               if (unlang_module_yield(request, mod_authorize_resume, NULL, 0, autz_ctx) != UNLANG_ACTION_YIELD) RETURN_MODULE_FAIL;
+               if (unlang_tmpl_push(autz_ctx, &autz_ctx->query, request, call_env->reply_query, NULL) < 0) RETURN_MODULE_FAIL;
                autz_ctx->status = SQL_AUTZ_REPLY;
                return UNLANG_ACTION_PUSHED_CHILD;
 
@@ -1571,7 +1573,7 @@ static unlang_action_t mod_authorize_resume(unlang_result_t *p_result, request_t
                        .expand_rhs = true,
                };
 
-               if (unlang_function_repeat_set(request, mod_authorize_resume) < 0) RETURN_UNLANG_FAIL;
+               if (unlang_module_yield(request, mod_authorize_resume, NULL, 0, autz_ctx) != UNLANG_ACTION_YIELD) RETURN_MODULE_FAIL;
                if (sql_get_map_list(request, map_ctx, autz_ctx->trunk) == UNLANG_ACTION_PUSHED_CHILD){
                        autz_ctx->status = SQL_AUTZ_REPLY_RESUME;
                        return UNLANG_ACTION_PUSHED_CHILD;
@@ -1596,7 +1598,7 @@ static unlang_action_t mod_authorize_resume(unlang_result_t *p_result, request_t
                        if (radius_legacy_map_list_apply(request, &autz_ctx->reply_tmp, NULL) < 0) {
                                RPEDEBUG("Failed applying item");
                                REXDENT();
-                               RETURN_UNLANG_FAIL;
+                               RETURN_MODULE_FAIL;
                        }
                        REXDENT();
 
@@ -1618,9 +1620,9 @@ static unlang_action_t mod_authorize_resume(unlang_result_t *p_result, request_t
                                break;
                        }
 
-                       if (unlang_function_repeat_set(request, mod_autz_group_resume) < 0) RETURN_UNLANG_FAIL;
+                       if (unlang_module_yield(request, mod_autz_group_resume, NULL, 0, autz_ctx) != UNLANG_ACTION_YIELD) RETURN_MODULE_FAIL;
                        if (unlang_tmpl_push(autz_ctx, &autz_ctx->query, request,
-                                            call_env->membership_query, NULL) < 0) RETURN_UNLANG_FAIL;
+                                            call_env->membership_query, NULL) < 0) RETURN_MODULE_FAIL;
                        autz_ctx->status = SQL_AUTZ_GROUP_MEMB;
                        return UNLANG_ACTION_PUSHED_CHILD;
                }
@@ -1639,16 +1641,16 @@ static unlang_action_t mod_authorize_resume(unlang_result_t *p_result, request_t
 
                        MEM(pair_update_request(&autz_ctx->sql_group, inst->group_da) >= 0);
                        autz_ctx->status = SQL_AUTZ_PROFILE_START;
-                       return mod_autz_group_resume(p_result, request, autz_ctx);
+                       return mod_autz_group_resume(p_result, mctx, request);
                }
                break;
 
        default:
-               fr_assert(0);
+               fr_assert_msg(0, "Invalid status %d in mod_authorize_resume", autz_ctx->status);
        }
 
-       if (!autz_ctx->user_found) RETURN_UNLANG_NOTFOUND;
-       RETURN_UNLANG_RCODE(autz_ctx->rcode);
+       if (!autz_ctx->user_found) RETURN_MODULE_NOTFOUND;
+       RETURN_MODULE_RCODE(autz_ctx->rcode);
 }
 
 /** Start of module authorize method
@@ -1688,9 +1690,9 @@ static unlang_action_t CC_HINT(nonnull) mod_authorize(rlm_rcode_t *p_result, mod
        MEM(autz_ctx->map_ctx = talloc_zero(autz_ctx, fr_sql_map_ctx_t));
        talloc_set_destructor(autz_ctx, sql_autz_ctx_free);
 
-       if (unlang_function_push(NULL, request, NULL,
-                                (call_env->check_query || call_env->reply_query) ? mod_authorize_resume : mod_autz_group_resume,
-                                NULL, 0, UNLANG_SUB_FRAME, autz_ctx) < 0) {
+       if (unlang_module_yield(request,
+                               (call_env->check_query || call_env->reply_query) ? mod_authorize_resume : mod_autz_group_resume,
+                               NULL, 0, autz_ctx) != UNLANG_ACTION_YIELD) {
        error:
                talloc_free(autz_ctx);
                RETURN_MODULE_FAIL;
@@ -1845,7 +1847,6 @@ static unlang_action_t mod_sql_redundant_resume(rlm_rcode_t *p_result, module_ct
                                                          redundant_ctx->query_vb->vb_strvalue, SQL_QUERY_OTHER));
 
        unlang_module_yield(request, mod_sql_redundant_query_resume, NULL, 0, redundant_ctx);
-
        return unlang_function_push(NULL, request, inst->query, NULL, NULL, 0, UNLANG_SUB_FRAME, redundant_ctx->query_ctx);
 }
 
index acd381390e68dddf3a076d06aa87cf270fe73a7a..12409230d3c580260ee41d25f71cdd8d32dd7ea0 100644 (file)
@@ -32,7 +32,8 @@ RCSID("$Id$")
 #include <freeradius-devel/util/debug.h>
 #include <freeradius-devel/util/dict.h>
 #include <freeradius-devel/unlang/function.h>
-
+#include <freeradius-devel/unlang/action.h>
+#include <freeradius-devel/unlang/module.h>
 #include <ctype.h>
 
 /*
@@ -263,9 +264,9 @@ typedef struct {
  * Otherwise, optionally populate a reply attribute with the value of `limit` - `counter` and return RLM_MODULE_UPDATED.
  * If no reply attribute is set, return RLM_MODULE_OK.
  */
-static unlang_action_t mod_authorize_resume(unlang_result_t *p_result, request_t *request, void *uctx)
+static unlang_action_t mod_authorize_resume(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request)
 {
-       sqlcounter_rctx_t       *rctx = talloc_get_type_abort(uctx, sqlcounter_rctx_t);
+       sqlcounter_rctx_t       *rctx = talloc_get_type_abort(mctx->rctx, sqlcounter_rctx_t);
        rlm_sqlcounter_t        *inst = rctx->inst;
        sqlcounter_call_env_t   *env = rctx->env;
        fr_value_box_t          *sql_result = fr_value_box_list_pop_head(&rctx->result);
@@ -302,7 +303,7 @@ static unlang_action_t mod_authorize_resume(unlang_result_t *p_result, request_t
                REDEBUG2("Rejecting user, %s value (%" PRIu64 ") is less than counter value (%" PRIu64 ")",
                         inst->limit_attr->name, limit->vp_uint64, counter);
 
-               RETURN_UNLANG_REJECT;
+               RETURN_MODULE_REJECT;
        }
 
        res = limit->vp_uint64 - counter;
@@ -352,28 +353,28 @@ static unlang_action_t mod_authorize_resume(unlang_result_t *p_result, request_t
                        if (fr_value_box_cmp(&vb, &existing) == 1) {
                                RDEBUG2("Leaving existing %s value of %pV" , env->reply_attr->name,
                                        &vp->data);
-                               RETURN_UNLANG_OK;
+                               RETURN_MODULE_OK;
                        }
                }
                        break;
 
                case -1:        /* alloc failed */
                        REDEBUG("Error allocating attribute %s", env->reply_attr->name);
-                       RETURN_UNLANG_FAIL;
+                       RETURN_MODULE_FAIL;
 
                default:        /* request or list unavailable */
                        RDEBUG2("List or request context not available for %s, skipping...", env->reply_attr->name);
-                       RETURN_UNLANG_OK;
+                       RETURN_MODULE_OK;
                }
 
                fr_value_box_cast(vp, &vp->data, vp->data.type, NULL, &vb);
 
                RDEBUG2("%pP", vp);
 
-               RETURN_UNLANG_UPDATED;
+               RETURN_MODULE_UPDATED;
        }
 
-       RETURN_UNLANG_OK;
+       RETURN_MODULE_OK;
 }
 
 /** Check the value of a `counter` retrieved from an SQL query with a `limit`
@@ -429,7 +430,7 @@ static unlang_action_t CC_HINT(nonnull) mod_authorize(rlm_rcode_t *p_result, mod
                .limit = limit
        };
 
-       if (unlang_function_push(NULL, request, NULL, mod_authorize_resume, NULL, 0, UNLANG_SUB_FRAME, rctx) < 0) {
+       if (unlang_module_yield(request, mod_authorize_resume, NULL, 0, rctx) != UNLANG_ACTION_YIELD) {
        error:
                talloc_free(rctx);
                RETURN_MODULE_FAIL;
index 8456ffb347ff2745ac7bfa9df67275a712e3f732..fbce05e3b4183613339ccaa273e0a6b13081b170 100644 (file)
@@ -31,6 +31,8 @@ RCSID("$Id$")
 #include <freeradius-devel/util/debug.h>
 #include <freeradius-devel/radius/radius.h>
 #include <freeradius-devel/unlang/function.h>
+#include <freeradius-devel/unlang/action.h>
+#include <freeradius-devel/unlang/module.h>
 
 #include <ctype.h>
 
@@ -223,7 +225,7 @@ static int sqlippool_alloc_ctx_free(ippool_alloc_ctx_t *to_free)
        return 0;
 }
 
-#define REPEAT_MOD_ALLOC_RESUME if (unlang_function_repeat_set(request, mod_alloc_resume) < 0) RETURN_UNLANG_FAIL
+#define REPEAT_MOD_ALLOC_RESUME if (unlang_module_yield(request, mod_alloc_resume, NULL, 0, mctx->rctx) < 0) RETURN_MODULE_FAIL
 #define SUBMIT_QUERY(_query_str, _new_status, _type, _function) do { \
        alloc_ctx->status = _new_status; \
        REPEAT_MOD_ALLOC_RESUME; \
@@ -241,13 +243,13 @@ static int sqlippool_alloc_ctx_free(ippool_alloc_ctx_t *to_free)
  * Following the final (successful) query, the destination attribute is populated.
  *
  * @param p_result     Result of IP allocation.
+ * @param mctx         Current allocation context.
  * @param request      Current request.
- * @param uctx         Current allocation context.
  * @return One of the UNLANG_ACTION_* values.
  */
-static unlang_action_t mod_alloc_resume(unlang_result_t *p_result, request_t *request, void *uctx)
+static unlang_action_t mod_alloc_resume(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request)
 {
-       ippool_alloc_ctx_t      *alloc_ctx = talloc_get_type_abort(uctx, ippool_alloc_ctx_t);
+       ippool_alloc_ctx_t      *alloc_ctx = talloc_get_type_abort(mctx->rctx, ippool_alloc_ctx_t);
        ippool_alloc_call_env_t *env = alloc_ctx->env;
        int                     allocation_len = 0;
        char                    allocation[FR_MAX_STRING_LEN];
@@ -258,7 +260,7 @@ static unlang_action_t mod_alloc_resume(unlang_result_t *p_result, request_t *re
        /*
         *      If a previous async call returned one of the "failure" results just return.
         */
-       switch (p_result->rcode) {
+       switch (*p_result) {
        case RLM_MODULE_USER_SECTION_REJECT:
                return UNLANG_ACTION_CALCULATE_RESULT;
 
@@ -284,7 +286,7 @@ static unlang_action_t mod_alloc_resume(unlang_result_t *p_result, request_t *re
                        if (unlang_tmpl_push(alloc_ctx, &alloc_ctx->values, request, env->existing, NULL) < 0) {
                        error:
                                talloc_free(alloc_ctx);
-                               RETURN_UNLANG_FAIL;
+                               RETURN_MODULE_FAIL;
                        }
                        return UNLANG_ACTION_PUSHED_CHILD;
                }
@@ -367,7 +369,7 @@ static unlang_action_t mod_alloc_resume(unlang_result_t *p_result, request_t *re
                }
        no_address:
                RWDEBUG("IP address could not be allocated");
-               RETURN_UNLANG_NOOP;
+               RETURN_MODULE_NOOP;
 
        case IPPOOL_ALLOC_MAKE_PAIR:
        {
@@ -432,7 +434,7 @@ static unlang_action_t mod_alloc_resume(unlang_result_t *p_result, request_t *re
                         *      NOTFOUND
                         */
                        RWDEBUG("Pool \"%pV\" appears to be full", &env->pool_name);
-                       RETURN_UNLANG_NOTFOUND;
+                       RETURN_MODULE_NOTFOUND;
                }
 
                /*
@@ -443,7 +445,7 @@ static unlang_action_t mod_alloc_resume(unlang_result_t *p_result, request_t *re
                 */
                RWDEBUG("IP address could not be allocated as no pool exists with the name \"%pV\"",
                        &env->pool_name);
-               RETURN_UNLANG_NOOP;
+               RETURN_MODULE_NOOP;
 
        case IPPOOL_ALLOC_UPDATE:
                if (query && query->vb_length) SUBMIT_QUERY(query->vb_strvalue, IPPOOL_ALLOC_UPDATE_RUN, SQL_QUERY_OTHER, query);
@@ -464,7 +466,7 @@ static unlang_action_t mod_alloc_resume(unlang_result_t *p_result, request_t *re
        {
                rlm_rcode_t     rcode = alloc_ctx->rcode;
                talloc_free(alloc_ctx);
-               RETURN_UNLANG_RCODE(rcode);
+               RETURN_MODULE_RCODE(rcode);
        }
        }
 
@@ -472,7 +474,7 @@ static unlang_action_t mod_alloc_resume(unlang_result_t *p_result, request_t *re
         *      All return paths are handled within the switch statement.
         */
        fr_assert(0);
-       RETURN_UNLANG_FAIL;
+       RETURN_MODULE_FAIL;
 }
 
 /** Initiate the allocation of an IP address from the pool.
@@ -523,7 +525,7 @@ static unlang_action_t CC_HINT(nonnull) mod_alloc(rlm_rcode_t *p_result, module_
        MEM(alloc_ctx->query_ctx = sql->query_alloc(alloc_ctx, sql, request, thread->trunk, "", SQL_QUERY_OTHER));
 
        fr_value_box_list_init(&alloc_ctx->values);
-       if (unlang_function_push(NULL, request, NULL, mod_alloc_resume, NULL, 0, UNLANG_SUB_FRAME, alloc_ctx) < 0 ) {
+       if (unlikely(unlang_module_yield(request, mod_alloc_resume, NULL, 0, alloc_ctx) != UNLANG_ACTION_YIELD)) {
                talloc_free(alloc_ctx);
                RETURN_MODULE_FAIL;
        }
@@ -538,14 +540,14 @@ static unlang_action_t CC_HINT(nonnull) mod_alloc(rlm_rcode_t *p_result, module_
 
 /** Resume function called after mod_common "update" query has completed
  */
-static unlang_action_t mod_common_update_resume(unlang_result_t *p_result, UNUSED request_t *request, void *uctx)
+static unlang_action_t mod_common_update_resume(rlm_rcode_t *p_result, module_ctx_t const *mctx, UNUSED request_t *request)
 {
-       ippool_common_ctx_t     *common_ctx = talloc_get_type_abort(uctx, ippool_common_ctx_t);
+       ippool_common_ctx_t     *common_ctx = talloc_get_type_abort(mctx->rctx, ippool_common_ctx_t);
        fr_sql_query_t          *query_ctx = common_ctx->query_ctx;
        rlm_sql_t const         *sql = common_ctx->sql;
        int                     affected = 0;
 
-       switch (p_result->rcode) {
+       switch (*p_result) {
        case RLM_MODULE_USER_SECTION_REJECT:
                return UNLANG_ACTION_CALCULATE_RESULT;
 
@@ -557,32 +559,32 @@ static unlang_action_t mod_common_update_resume(unlang_result_t *p_result, UNUSE
 
        talloc_free(common_ctx);
 
-       if (affected > 0) RETURN_UNLANG_UPDATED;
-       RETURN_UNLANG_NOTFOUND;
+       if (affected > 0) RETURN_MODULE_UPDATED;
+       RETURN_MODULE_NOTFOUND;
 }
 
 /** Resume function called after mod_common "free" query has completed
  */
-static unlang_action_t mod_common_free_resume(unlang_result_t *p_result, request_t *request, void *uctx)
+static unlang_action_t mod_common_free_resume(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request)
 {
-       ippool_common_ctx_t     *common_ctx = talloc_get_type_abort(uctx, ippool_common_ctx_t);
+       ippool_common_ctx_t     *common_ctx = talloc_get_type_abort(mctx->rctx, ippool_common_ctx_t);
        fr_sql_query_t          *query_ctx = common_ctx->query_ctx;
        rlm_sql_t const         *sql = common_ctx->sql;
 
-       switch (p_result->rcode) {
+       switch (*p_result) {
        case RLM_MODULE_USER_SECTION_REJECT:
                return UNLANG_ACTION_CALCULATE_RESULT;
 
        default:
                break;
        }
-       if (common_ctx->env->update.type != FR_TYPE_STRING) RETURN_UNLANG_NOOP;
+       if (common_ctx->env->update.type != FR_TYPE_STRING) RETURN_MODULE_NOOP;
 
        sql->driver->sql_finish_query(query_ctx, &sql->config);
 
-       if (unlang_function_push(NULL, request, NULL, mod_common_update_resume, NULL, 0, UNLANG_SUB_FRAME, common_ctx) < 0) {
+       if (unlikely(unlang_module_yield(request, mod_common_update_resume, NULL, 0, common_ctx) != UNLANG_ACTION_YIELD)) {
                talloc_free(common_ctx);
-               RETURN_UNLANG_FAIL;
+               RETURN_MODULE_FAIL;
        }
 
        common_ctx->query_ctx->query_str = common_ctx->env->update.vb_strvalue;
@@ -622,7 +624,7 @@ static unlang_action_t CC_HINT(nonnull) mod_common(rlm_rcode_t *p_result, module
         */
        if (env->free.type == FR_TYPE_STRING) {
                common_ctx->query_ctx->query_str = env->free.vb_strvalue;
-               if (unlang_function_push(NULL, request, NULL, mod_common_free_resume, NULL, 0, UNLANG_SUB_FRAME, common_ctx) < 0) {
+               if (unlikely(unlang_module_yield(request, mod_common_free_resume, NULL, 0, common_ctx) != UNLANG_ACTION_YIELD)) {
                        talloc_free(common_ctx);
                        RETURN_MODULE_FAIL;
                }
@@ -630,7 +632,8 @@ static unlang_action_t CC_HINT(nonnull) mod_common(rlm_rcode_t *p_result, module
        }
 
        common_ctx->query_ctx->query_str = env->update.vb_strvalue;
-       if (unlang_function_push(NULL, request, NULL, mod_common_update_resume, NULL, 0, UNLANG_SUB_FRAME, common_ctx) < 0) {
+
+       if (unlikely(unlang_module_yield(request, mod_common_update_resume, NULL, 0, common_ctx) != UNLANG_ACTION_YIELD)) {
                talloc_free(common_ctx);
                RETURN_MODULE_FAIL;
        }