From: Arran Cudbard-Bell Date: Sun, 1 Jun 2025 19:52:07 +0000 (-0600) Subject: More p_result fixes X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ac7b00ce0c47dc14a54afd6ba91f661dc4b31d8d;p=thirdparty%2Ffreeradius-server.git More p_result fixes --- diff --git a/src/modules/rlm_sql/rlm_sql.c b/src/modules/rlm_sql/rlm_sql.c index 72f3847b74..2c915cfefb 100644 --- a/src/modules/rlm_sql/rlm_sql.c +++ b/src/modules/rlm_sql/rlm_sql.c @@ -592,7 +592,13 @@ static xlat_action_t sql_xlat(TALLOC_CTX *ctx, fr_dcursor_t *out, thread->trunk, arg->vb_strvalue, SQL_QUERY_SELECT)); 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; + + if (unlang_function_push(/* discard, sql_xlat_select_resume just uses query_ctx->rcode */ NULL, + request, + inst->select, + NULL, + NULL, 0, + UNLANG_SUB_FRAME, query_ctx) == UNLANG_ACTION_FAIL) return XLAT_ACTION_FAIL; return XLAT_ACTION_PUSH_UNLANG; } @@ -621,7 +627,12 @@ static xlat_action_t sql_fetch_xlat(UNUSED TALLOC_CTX *ctx, UNUSED fr_dcursor_t thread->trunk, arg->vb_strvalue, SQL_QUERY_SELECT)); 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; + if (unlang_function_push(/* discard, sql_xlat_select_resume just uses query_ctx->rcode */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; } @@ -892,7 +903,13 @@ static unlang_action_t mod_map_proc(unlang_result_t *p_result, map_ctx_t const * thread->trunk, query_head->vb_strvalue, SQL_QUERY_SELECT); if (unlang_map_yield(request, mod_map_resume, NULL, 0, query_ctx) != UNLANG_ACTION_YIELD) RETURN_UNLANG_FAIL; - return unlang_function_push(NULL, request, inst->select, NULL, NULL, 0, UNLANG_SUB_FRAME, query_ctx); + return unlang_function_push(/* discard, mod_map_resume just uses query_ctx->rcode */ NULL, + request, + inst->select, + NULL, + NULL, + 0, UNLANG_SUB_FRAME, + query_ctx); } /** xlat escape function for drivers which do not provide their own @@ -1080,7 +1097,7 @@ static unlang_action_t sql_get_grouplist_resume(unlang_result_t *p_result, reque RETURN_UNLANG_OK; } -static unlang_action_t sql_get_grouplist(sql_group_ctx_t *group_ctx, trunk_t *trunk, request_t *request) +static unlang_action_t sql_get_grouplist(unlang_result_t *p_result, sql_group_ctx_t *group_ctx, trunk_t *trunk, request_t *request) { rlm_sql_t const *inst = group_ctx->inst; @@ -1091,8 +1108,20 @@ static unlang_action_t sql_get_grouplist(sql_group_ctx_t *group_ctx, trunk_t *tr MEM(group_ctx->query_ctx = fr_sql_query_alloc(group_ctx, inst, request, trunk, 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); + if (unlang_function_push(/* sql_get_grouplist_resume translates the query_ctx->rocde into a module rcode */p_result, + request, + NULL, + sql_get_grouplist_resume, + NULL, + 0, UNLANG_SUB_FRAME, + group_ctx) < 0) return UNLANG_ACTION_FAIL; + + return unlang_function_push(/* discard, sql_get_grouplist_resume translates rcodes */NULL, + request, + inst->select, + NULL, + NULL, 0, + UNLANG_SUB_FRAME, group_ctx->query_ctx); } typedef struct { @@ -1154,7 +1183,7 @@ 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) { + if (sql_get_grouplist(NULL, xlat_ctx->group_ctx, thread->trunk, request) != UNLANG_ACTION_PUSHED_CHILD) { return XLAT_ACTION_FAIL; } @@ -1299,7 +1328,7 @@ static unlang_action_t CC_HINT(nonnull) mod_autz_group_resume(unlang_result_t * .query = query, }; - if (sql_get_grouplist(autz_ctx->group_ctx, autz_ctx->trunk, request) == UNLANG_ACTION_PUSHED_CHILD) { + if (sql_get_grouplist(p_result, autz_ctx->group_ctx, autz_ctx->trunk, request) == UNLANG_ACTION_PUSHED_CHILD) { autz_ctx->status = SQL_AUTZ_GROUP_MEMB_RESUME; return UNLANG_ACTION_PUSHED_CHILD; } @@ -1362,7 +1391,7 @@ static unlang_action_t CC_HINT(nonnull) mod_autz_group_resume(unlang_result_t * }; if (unlang_module_yield(request, mod_autz_group_resume, NULL, 0, mctx->rctx) == UNLANG_ACTION_FAIL) RETURN_UNLANG_FAIL; - if (sql_get_map_list(request, map_ctx, autz_ctx->trunk) == UNLANG_ACTION_PUSHED_CHILD) { + if (sql_get_map_list(p_result, 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; } @@ -1418,7 +1447,7 @@ static unlang_action_t CC_HINT(nonnull) mod_autz_group_resume(unlang_result_t * }; if (unlang_module_yield(request, mod_autz_group_resume, NULL, 0, mctx->rctx) == UNLANG_ACTION_FAIL) RETURN_UNLANG_FAIL; - if (sql_get_map_list(request, map_ctx, autz_ctx->trunk) == UNLANG_ACTION_PUSHED_CHILD) { + if (sql_get_map_list(p_result, 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; } @@ -1532,7 +1561,7 @@ static unlang_action_t CC_HINT(nonnull) mod_authorize_resume(unlang_result_t *p_ }; if (unlang_module_yield(request, mod_authorize_resume, NULL, 0, autz_ctx) == UNLANG_ACTION_FAIL) RETURN_UNLANG_FAIL; - if (sql_get_map_list(request, map_ctx, autz_ctx->trunk) == UNLANG_ACTION_PUSHED_CHILD){ + if (sql_get_map_list(p_result, request, map_ctx, autz_ctx->trunk) == UNLANG_ACTION_PUSHED_CHILD){ autz_ctx->status = SQL_AUTZ_CHECK_RESUME; return UNLANG_ACTION_PUSHED_CHILD; } @@ -1574,7 +1603,7 @@ static unlang_action_t CC_HINT(nonnull) mod_authorize_resume(unlang_result_t *p_ }; if (unlang_module_yield(request, mod_authorize_resume, NULL, 0, autz_ctx) == UNLANG_ACTION_FAIL) RETURN_UNLANG_FAIL; - if (sql_get_map_list(request, map_ctx, autz_ctx->trunk) == UNLANG_ACTION_PUSHED_CHILD){ + if (sql_get_map_list(p_result, request, map_ctx, autz_ctx->trunk) == UNLANG_ACTION_PUSHED_CHILD){ autz_ctx->status = SQL_AUTZ_REPLY_RESUME; return UNLANG_ACTION_PUSHED_CHILD; } @@ -1847,7 +1876,13 @@ static unlang_action_t mod_sql_redundant_resume(unlang_result_t *p_result, modul 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); + return unlang_function_push(/* discard, mod_sql_redundant_query_resume uses query_ctx->rcode*/ NULL, + request, + inst->query, + NULL, + NULL, + 0, UNLANG_SUB_FRAME, + redundant_ctx->query_ctx); } /** Generic module call for failing between a bunch of queries. diff --git a/src/modules/rlm_sql/rlm_sql.h b/src/modules/rlm_sql/rlm_sql.h index 09e63c495e..b830779d68 100644 --- a/src/modules/rlm_sql/rlm_sql.h +++ b/src/modules/rlm_sql/rlm_sql.h @@ -248,7 +248,7 @@ struct sql_inst { module_instance_t const *mi; //!< Module instance data for thread lookups. }; -unlang_action_t sql_get_map_list(request_t *request, fr_sql_map_ctx_t *map_ctx, trunk_t *trunk); +unlang_action_t sql_get_map_list(unlang_result_t *p_result, request_t *request, fr_sql_map_ctx_t *map_ctx, trunk_t *trunk); void rlm_sql_query_log(rlm_sql_t const *inst, char const *filename, char const *query) CC_HINT(nonnull); unlang_action_t rlm_sql_trunk_query(unlang_result_t *p_result, request_t *request, void *uctx); unlang_action_t rlm_sql_fetch_row(unlang_result_t *p_result, request_t *request, void *uctx); diff --git a/src/modules/rlm_sql/sql.c b/src/modules/rlm_sql/sql.c index 88e493f8f8..b883b80ba8 100644 --- a/src/modules/rlm_sql/sql.c +++ b/src/modules/rlm_sql/sql.c @@ -268,7 +268,8 @@ unlang_action_t rlm_sql_trunk_query(unlang_result_t *p_result, request_t *reques * state of the trunk request to reapable - so in that case don't * yield (in sql_trunk_query_start) */ - if (unlang_function_push(NULL, request, + if (unlang_function_push(/* allow the caller of rlm_sql_trunk_query to get at the rcode */p_result, + request, query_ctx->treq->state == TRUNK_REQUEST_STATE_REAPABLE ? NULL : sql_trunk_query_start, query_ctx->type == SQL_QUERY_SELECT ? @@ -340,7 +341,7 @@ static unlang_action_t sql_get_map_list_resume(unlang_result_t *p_result, reques /** Submit the query to get any user / group check or reply pairs * */ -unlang_action_t sql_get_map_list(request_t *request, fr_sql_map_ctx_t *map_ctx, trunk_t *trunk) +unlang_action_t sql_get_map_list(unlang_result_t *p_result, request_t *request, fr_sql_map_ctx_t *map_ctx, trunk_t *trunk) { rlm_sql_t const *inst = map_ctx->inst; @@ -349,9 +350,21 @@ unlang_action_t sql_get_map_list(request_t *request, fr_sql_map_ctx_t *map_ctx, MEM(map_ctx->query_ctx = fr_sql_query_alloc(map_ctx->ctx, inst, request, trunk, map_ctx->query->vb_strvalue, SQL_QUERY_SELECT)); - if (unlang_function_push(NULL, request, NULL, sql_get_map_list_resume, NULL, 0, UNLANG_SUB_FRAME, map_ctx) < 0) return UNLANG_ACTION_FAIL; - - return unlang_function_push(NULL, request, inst->select, NULL, NULL, 0, UNLANG_SUB_FRAME, map_ctx->query_ctx); + if (unlang_function_push(p_result, + request, + NULL, + sql_get_map_list_resume, + NULL, 0, + UNLANG_SUB_FRAME, + map_ctx) < 0) return UNLANG_ACTION_FAIL; + + return unlang_function_push(/* discard, sql_get_map_list_resume uses query_ctx->rcode */ NULL, + request, + inst->select, + NULL, + NULL, 0, + UNLANG_SUB_FRAME, + map_ctx->query_ctx); } /* diff --git a/src/modules/rlm_sqlippool/rlm_sqlippool.c b/src/modules/rlm_sqlippool/rlm_sqlippool.c index 93a821f3a2..37880e1c3d 100644 --- a/src/modules/rlm_sqlippool/rlm_sqlippool.c +++ b/src/modules/rlm_sqlippool/rlm_sqlippool.c @@ -233,7 +233,7 @@ static int sqlippool_alloc_ctx_free(ippool_alloc_ctx_t *to_free) query_ctx->type = _type; \ query_ctx->status = SQL_QUERY_PREPARED; \ alloc_ctx->query = query; \ - return unlang_function_push(NULL, request, sql->_function, NULL, NULL, 0, UNLANG_SUB_FRAME, query_ctx); \ + return unlang_function_push(p_result, request, sql->_function, NULL, NULL, 0, UNLANG_SUB_FRAME, query_ctx); \ } while (0) /** Resume function called after each IP allocation query is expanded @@ -532,7 +532,13 @@ static unlang_action_t CC_HINT(nonnull) mod_alloc(unlang_result_t *p_result, mod if ((env->begin.type == FR_TYPE_STRING) && env->begin.vb_length) { alloc_ctx->query_ctx->query_str = env->begin.vb_strvalue; - return unlang_function_push(NULL, request, sql->query, NULL, NULL, 0, UNLANG_SUB_FRAME, alloc_ctx->query_ctx); + return unlang_function_push(/* mod_alloc_resume looks at frame result */ p_result, + request, + sql->query, + NULL, + NULL, 0, + UNLANG_SUB_FRAME, + alloc_ctx->query_ctx); } return UNLANG_ACTION_PUSHED_CHILD; @@ -589,7 +595,13 @@ static unlang_action_t mod_common_free_resume(unlang_result_t *p_result, module_ common_ctx->query_ctx->query_str = common_ctx->env->update.vb_strvalue; query_ctx->status = SQL_QUERY_PREPARED; - return unlang_function_push(NULL, request, sql->query, NULL, NULL, 0, UNLANG_SUB_FRAME, query_ctx); + return unlang_function_push(/* mod_common_update_resume uses frame rcode */p_result, + request, + sql->query, + NULL, + NULL, 0, + UNLANG_SUB_FRAME, + query_ctx); } /** Common function used by module methods which perform an optional "free" then "update" @@ -628,7 +640,13 @@ static unlang_action_t CC_HINT(nonnull) mod_common(unlang_result_t *p_result, mo talloc_free(common_ctx); RETURN_UNLANG_FAIL; } - return unlang_function_push(NULL, request, sql->query, NULL, NULL, 0, UNLANG_SUB_FRAME, common_ctx->query_ctx); + return unlang_function_push(/* mod_common_free_resume looks at frame result */ NULL, + request, + sql->query, + NULL, + NULL, 0, + UNLANG_SUB_FRAME, + common_ctx->query_ctx); } common_ctx->query_ctx->query_str = env->update.vb_strvalue; @@ -637,7 +655,13 @@ static unlang_action_t CC_HINT(nonnull) mod_common(unlang_result_t *p_result, mo talloc_free(common_ctx); RETURN_UNLANG_FAIL; } - return unlang_function_push(NULL, request, sql->query, NULL, NULL, 0, UNLANG_SUB_FRAME, common_ctx->query_ctx); + return unlang_function_push(/* mod_common_update_resume looks at frame result */ p_result, + request, + sql->query, + NULL, + NULL, 0, + UNLANG_SUB_FRAME, + common_ctx->query_ctx); } /** Call SQL module box_escape_func to escape tainted values