]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Remove handle from fr_sql_query_t
authorNick Porter <nick@portercomputing.co.uk>
Tue, 26 Nov 2024 13:25:32 +0000 (13:25 +0000)
committerNick Porter <nick@portercomputing.co.uk>
Wed, 27 Nov 2024 08:05:01 +0000 (08:05 +0000)
src/modules/rlm_sql/drivers/rlm_sql_db2/rlm_sql_db2.c
src/modules/rlm_sql/rlm_sql.c
src/modules/rlm_sql/rlm_sql.h
src/modules/rlm_sql/sql.c
src/modules/rlm_sqlippool/rlm_sqlippool.c

index 89fd331ba88fc7373442ab617b9b18fbe886f6b4..809d3162fb7c500f8a8afd9db4bd2c7a1d46d329 100644 (file)
@@ -240,9 +240,8 @@ static unlang_action_t sql_fetch_row(rlm_rcode_t *p_result, UNUSED int *priority
 
 static sql_rcode_t sql_free_result(fr_sql_query_t *query_ctx, UNUSED rlm_sql_config_t const *config)
 {
-       rlm_sql_db2_conn_t *conn;
+       rlm_sql_db2_conn_t      *conn = talloc_get_type_abort(query_ctx->tconn->conn->h, rlm_sql_db2_conn_t);
 
-       conn = query_ctx->handle->conn;
        TALLOC_FREE(query_ctx->row);
        SQLFreeHandle(SQL_HANDLE_STMT, conn->stmt);
 
index 4ba0227df01a8da310ccfb773a560f059caa7d2a..cb8889114274e1138e88b7c1d8984201b3169bfe 100644 (file)
@@ -562,7 +562,6 @@ static xlat_action_t sql_xlat(TALLOC_CTX *ctx, fr_dcursor_t *out,
                              request_t *request, fr_value_box_list_t *in)
 {
        sql_xlat_call_env_t     *call_env = talloc_get_type_abort(xctx->env_data, sql_xlat_call_env_t);
-       rlm_sql_handle_t        *handle = NULL;
        rlm_sql_t const         *inst = talloc_get_type_abort(xctx->mctx->mi->data, rlm_sql_t);
        rlm_sql_thread_t        *thread = talloc_get_type_abort(xctx->mctx->thread, rlm_sql_thread_t);
        char const              *p;
@@ -589,7 +588,7 @@ static xlat_action_t sql_xlat(TALLOC_CTX *ctx, fr_dcursor_t *out,
        if ((strncasecmp(p, "insert", 6) == 0) ||
            (strncasecmp(p, "update", 6) == 0) ||
            (strncasecmp(p, "delete", 6) == 0)) {
-               MEM(query_ctx = fr_sql_query_alloc(unlang_interpret_frame_talloc_ctx(request), inst, request, handle,
+               MEM(query_ctx = fr_sql_query_alloc(unlang_interpret_frame_talloc_ctx(request), inst, request,
                                                   thread->trunk, arg->vb_strvalue, SQL_QUERY_OTHER));
 
                unlang_xlat_yield(request, sql_xlat_query_resume, NULL, 0, query_ctx);
@@ -599,7 +598,7 @@ static xlat_action_t sql_xlat(TALLOC_CTX *ctx, fr_dcursor_t *out,
                return sql_xlat_query_resume(ctx, out, &(xlat_ctx_t){.rctx = query_ctx, .inst = inst}, request, in);
        } /* else it's a SELECT statement */
 
-       MEM(query_ctx = fr_sql_query_alloc(unlang_interpret_frame_talloc_ctx(request), inst, request, handle,
+       MEM(query_ctx = fr_sql_query_alloc(unlang_interpret_frame_talloc_ctx(request), inst, request,
                                           thread->trunk, arg->vb_strvalue, SQL_QUERY_SELECT));
 
        unlang_xlat_yield(request, sql_xlat_select_resume, NULL, 0, query_ctx);
@@ -620,7 +619,6 @@ static xlat_action_t sql_fetch_xlat(UNUSED TALLOC_CTX *ctx, UNUSED fr_dcursor_t
                                    request_t *request, fr_value_box_list_t *in)
 {
        sql_xlat_call_env_t     *call_env = talloc_get_type_abort(xctx->env_data, sql_xlat_call_env_t);
-       rlm_sql_handle_t        *handle = NULL;
        rlm_sql_t const         *inst = talloc_get_type_abort(xctx->mctx->mi->data, rlm_sql_t);
        rlm_sql_thread_t        *thread = talloc_get_type_abort(xctx->mctx->thread, rlm_sql_thread_t);
        fr_value_box_t          *arg = fr_value_box_list_head(in);
@@ -630,7 +628,7 @@ static xlat_action_t sql_fetch_xlat(UNUSED TALLOC_CTX *ctx, UNUSED fr_dcursor_t
                rlm_sql_query_log(inst, call_env->filename.vb_strvalue, arg->vb_strvalue);
        }
 
-       MEM(query_ctx = fr_sql_query_alloc(unlang_interpret_frame_talloc_ctx(request), inst, request, handle,
+       MEM(query_ctx = fr_sql_query_alloc(unlang_interpret_frame_talloc_ctx(request), inst, request,
                                           thread->trunk, arg->vb_strvalue, SQL_QUERY_SELECT));
 
        unlang_xlat_yield(request, sql_xlat_select_resume, NULL, 0, query_ctx);
@@ -651,7 +649,6 @@ static xlat_action_t sql_modify_xlat(TALLOC_CTX *ctx, fr_dcursor_t *out, xlat_ct
                                     request_t *request, fr_value_box_list_t *in)
 {
        sql_xlat_call_env_t     *call_env = talloc_get_type_abort(xctx->env_data, sql_xlat_call_env_t);
-       rlm_sql_handle_t        *handle = NULL;
        rlm_sql_t const         *inst = talloc_get_type_abort(xctx->mctx->mi->data, rlm_sql_t);
        rlm_sql_thread_t        *thread = talloc_get_type_abort(xctx->mctx->thread, rlm_sql_thread_t);
        fr_value_box_t          *arg = fr_value_box_list_head(in);
@@ -662,7 +659,7 @@ static xlat_action_t sql_modify_xlat(TALLOC_CTX *ctx, fr_dcursor_t *out, xlat_ct
                rlm_sql_query_log(inst, call_env->filename.vb_strvalue, arg->vb_strvalue);
        }
 
-       MEM(query_ctx = fr_sql_query_alloc(unlang_interpret_frame_talloc_ctx(request), inst, request, handle,
+       MEM(query_ctx = fr_sql_query_alloc(unlang_interpret_frame_talloc_ctx(request), inst, request,
                                           thread->trunk, arg->vb_strvalue, SQL_QUERY_OTHER));
 
        unlang_xlat_yield(request, sql_xlat_query_resume, NULL, 0, query_ctx);
@@ -735,7 +732,6 @@ static unlang_action_t mod_map_resume(rlm_rcode_t *p_result, UNUSED int *priorit
        fr_sql_query_t          *query_ctx = map_ctx->query_ctx;
        map_list_t const        *maps = map_ctx->maps;
        rlm_sql_t const         *inst = map_ctx->inst;
-       rlm_sql_handle_t        *handle = query_ctx->handle;
        map_t const             *map;
        rlm_rcode_t             rcode = RLM_MODULE_UPDATED;
        sql_rcode_t             ret;
@@ -853,7 +849,6 @@ static unlang_action_t mod_map_resume(rlm_rcode_t *p_result, UNUSED int *priorit
 finish:
        talloc_free(fields);
        talloc_free(map_ctx);
-       if (handle) fr_pool_connection_release(inst->pool, request, handle);
 
        RETURN_MODULE_RCODE(rcode);
 }
@@ -876,7 +871,6 @@ static unlang_action_t mod_map_proc(rlm_rcode_t *p_result, void const *mod_inst,
 {
        rlm_sql_t const         *inst = talloc_get_type_abort_const(mod_inst, rlm_sql_t);
        rlm_sql_thread_t        *thread = talloc_get_type_abort(module_thread(inst->mi)->data, rlm_sql_thread_t);
-       rlm_sql_handle_t        *handle = NULL;
        fr_value_box_t          *query_head = fr_value_box_list_head(query);
        sql_map_ctx_t           *map_ctx;
        fr_value_box_t          *vb = NULL;
@@ -909,7 +903,7 @@ static unlang_action_t mod_map_proc(rlm_rcode_t *p_result, void const *mod_inst,
                .maps = maps,
        };
 
-       MEM(map_ctx->query_ctx = fr_sql_query_alloc(map_ctx, inst, request, handle,
+       MEM(map_ctx->query_ctx = fr_sql_query_alloc(map_ctx, inst, request,
                                                    thread->trunk, query_head->vb_strvalue, SQL_QUERY_SELECT));
 
        if (unlang_function_push(request, NULL, mod_map_resume, NULL, 0,
@@ -1103,7 +1097,7 @@ static unlang_action_t sql_get_grouplist_resume(rlm_rcode_t *p_result, UNUSED in
        RETURN_MODULE_OK;
 }
 
-static unlang_action_t sql_get_grouplist(sql_group_ctx_t *group_ctx, rlm_sql_handle_t **handle, trunk_t *trunk, request_t *request)
+static unlang_action_t sql_get_grouplist(sql_group_ctx_t *group_ctx, trunk_t *trunk, request_t *request)
 {
        rlm_sql_t const         *inst = group_ctx->inst;
 
@@ -1111,7 +1105,7 @@ static unlang_action_t sql_get_grouplist(sql_group_ctx_t *group_ctx, rlm_sql_han
 
        if (!group_ctx->query || (group_ctx->query->vb_length == 0)) return UNLANG_ACTION_CALCULATE_RESULT;
 
-       MEM(group_ctx->query_ctx = fr_sql_query_alloc(group_ctx, inst, request, *handle, trunk,
+       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(request, NULL, sql_get_grouplist_resume, NULL, 0, UNLANG_SUB_FRAME, group_ctx) < 0) return UNLANG_ACTION_FAIL;
@@ -1182,7 +1176,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, &xlat_ctx->handle, thread->trunk, request) != UNLANG_ACTION_PUSHED_CHILD)
+       if (sql_get_grouplist(xlat_ctx->group_ctx, thread->trunk, request) != UNLANG_ACTION_PUSHED_CHILD)
                        return XLAT_ACTION_FAIL;
 
        return XLAT_ACTION_PUSH_UNLANG;
@@ -1328,7 +1322,7 @@ static unlang_action_t mod_autz_group_resume(rlm_rcode_t *p_result, UNUSED int *
                        .query = query,
                };
 
-               if (sql_get_grouplist(autz_ctx->group_ctx, &autz_ctx->handle, autz_ctx->trunk, request) == UNLANG_ACTION_PUSHED_CHILD) {
+               if (sql_get_grouplist(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;
                }
@@ -1391,7 +1385,7 @@ static unlang_action_t mod_autz_group_resume(rlm_rcode_t *p_result, UNUSED int *
                };
 
                if (unlang_function_repeat_set(request, mod_autz_group_resume) < 0) RETURN_MODULE_FAIL;
-               if (sql_get_map_list(request, map_ctx, &autz_ctx->handle, autz_ctx->trunk) == UNLANG_ACTION_PUSHED_CHILD) {
+               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;
                }
@@ -1446,7 +1440,7 @@ static unlang_action_t mod_autz_group_resume(rlm_rcode_t *p_result, UNUSED int *
                };
 
                if (unlang_function_repeat_set(request, mod_autz_group_resume) < 0) RETURN_MODULE_FAIL;
-               if (sql_get_map_list(request, map_ctx, &autz_ctx->handle, autz_ctx->trunk) == UNLANG_ACTION_PUSHED_CHILD) {
+               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;
                }
@@ -1561,7 +1555,7 @@ static unlang_action_t mod_authorize_resume(rlm_rcode_t *p_result, int *priority
                };
 
                if (unlang_function_repeat_set(request, mod_authorize_resume) < 0) RETURN_MODULE_FAIL;
-               if (sql_get_map_list(request, map_ctx, &autz_ctx->handle, autz_ctx->trunk) == UNLANG_ACTION_PUSHED_CHILD){
+               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;
                }
@@ -1602,7 +1596,7 @@ static unlang_action_t mod_authorize_resume(rlm_rcode_t *p_result, int *priority
                };
 
                if (unlang_function_repeat_set(request, mod_authorize_resume) < 0) RETURN_MODULE_FAIL;
-               if (sql_get_map_list(request, map_ctx, &autz_ctx->handle, autz_ctx->trunk) == UNLANG_ACTION_PUSHED_CHILD){
+               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;
                }
@@ -1871,8 +1865,7 @@ static unlang_action_t mod_sql_redundant_resume(rlm_rcode_t *p_result, UNUSED in
                rlm_sql_query_log(inst, call_env->filename.vb_strvalue, redundant_ctx->query_vb->vb_strvalue);
        }
 
-       MEM(redundant_ctx->query_ctx = fr_sql_query_alloc(redundant_ctx, inst, request,
-                                                         redundant_ctx->handle, redundant_ctx->trunk,
+       MEM(redundant_ctx->query_ctx = fr_sql_query_alloc(redundant_ctx, inst, request, redundant_ctx->trunk,
                                                          redundant_ctx->query_vb->vb_strvalue, SQL_QUERY_OTHER));
 
        if (unlang_function_repeat_set(request, mod_sql_redundant_query_resume) < 0) RETURN_MODULE_FAIL;
index fb5e21d036a245579c93a2df389ff5f56299feb7..7358ba6938f9610e6bb758dd8fb41bfbe5d59376 100644 (file)
@@ -137,7 +137,6 @@ typedef enum {
 typedef struct {
        rlm_sql_t const         *inst;                          //!< Module instance for this query.
        request_t               *request;                       //!< Request this query relates to.
-       rlm_sql_handle_t        *handle;                        //!< Connection handle this query is being run on.
        trunk_t                 *trunk;                         //!< Trunk this query is being run on.
        trunk_connection_t      *tconn;                         //!< Trunk connection this query is being run on.
        trunk_request_t         *treq;                          //!< Trunk request for this query.
@@ -250,7 +249,7 @@ struct sql_inst {
        unlang_function_t       query;
        unlang_function_t       select;
        unlang_function_t       fetch_row;
-       fr_sql_query_t          *(*query_alloc)(TALLOC_CTX *ctx, rlm_sql_t const *inst, request_t *request, rlm_sql_handle_t *handle, trunk_t *trunk, char const *query_str, fr_sql_query_type_t type);
+       fr_sql_query_t          *(*query_alloc)(TALLOC_CTX *ctx, rlm_sql_t const *inst, request_t *request, trunk_t *trunk, char const *query_str, fr_sql_query_type_t type);
 
        char const              *name;                  //!< Module instance name.
        fr_dict_attr_t const    *group_da;              //!< Group dictionary attribute.
@@ -258,14 +257,14 @@ struct sql_inst {
 };
 
 void           *sql_mod_conn_create(TALLOC_CTX *ctx, void *instance, fr_time_delta_t timeout);
-unlang_action_t        sql_get_map_list(request_t *request, fr_sql_map_ctx_t *map_ctx, rlm_sql_handle_t **handle, trunk_t *trunk);
+unlang_action_t        sql_get_map_list(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_select_query(rlm_rcode_t *p_result, UNUSED int *priority, request_t *request, void *uctx);
 unlang_action_t        rlm_sql_query(rlm_rcode_t *p_result, int *priority, request_t *request, void *uctx);
 unlang_action_t rlm_sql_trunk_query(rlm_rcode_t *p_result, UNUSED int *priority, request_t *request, void *uctx);
 unlang_action_t rlm_sql_fetch_row(rlm_rcode_t *p_result, UNUSED int *priority, request_t *request, void *uctx);
 void           rlm_sql_print_error(rlm_sql_t const *inst, request_t *request, fr_sql_query_t *query_ctx, bool force_debug);
-fr_sql_query_t *fr_sql_query_alloc(TALLOC_CTX *ctx, rlm_sql_t const *inst, request_t *request, rlm_sql_handle_t *handle, trunk_t *trunk, char const *query_str, fr_sql_query_type_t type);
+fr_sql_query_t *fr_sql_query_alloc(TALLOC_CTX *ctx, rlm_sql_t const *inst, request_t *request, trunk_t *trunk, char const *query_str, fr_sql_query_type_t type);
 
 /*
  *     sql_state.c
index 7a665ed27b22484e509c0e9dbecc4f7579dae4f0..370d7840158507f8f2062d303681c64be06f7c37 100644 (file)
@@ -409,14 +409,13 @@ static int fr_sql_query_free(fr_sql_query_t *to_free)
 /** Allocate an sql query structure
  *
  */
-fr_sql_query_t *fr_sql_query_alloc(TALLOC_CTX *ctx, rlm_sql_t const *inst, request_t *request, rlm_sql_handle_t *handle,
+fr_sql_query_t *fr_sql_query_alloc(TALLOC_CTX *ctx, rlm_sql_t const *inst, request_t *request,
                                   trunk_t *trunk, char const *query_str, fr_sql_query_type_t type)
 {
        fr_sql_query_t  *query;
        MEM(query = talloc(ctx, fr_sql_query_t));
        *query = (fr_sql_query_t) {
                .inst = inst,
-               .handle = handle,
                .request = request,
                .trunk = trunk,
                .query_str = query_str,
@@ -449,9 +448,6 @@ unlang_action_t rlm_sql_query(rlm_rcode_t *p_result, UNUSED int *priority, reque
        rlm_sql_t const *inst = query_ctx->inst;
        int             i, count;
 
-       /* Caller should check they have a valid handle */
-       fr_assert(query_ctx->handle);
-
        /* There's no query to run, return an error */
        if (query_ctx->query_str[0] == '\0') {
                if (request) REDEBUG("Zero length query");
@@ -481,11 +477,7 @@ unlang_action_t rlm_sql_query(rlm_rcode_t *p_result, UNUSED int *priority, reque
                 *      sockets in the pool and fail to establish a *new* connection.
                 */
                case RLM_SQL_RECONNECT:
-                       query_ctx->handle = fr_pool_connection_reconnect(inst->pool, request, query_ctx->handle);
-                       /* Reconnection failed */
-                       if (!query_ctx->handle) RETURN_MODULE_FAIL;
-                       /* Reconnection succeeded, try again with the new handle */
-                       continue;
+                       RETURN_MODULE_FAIL;
 
                /*
                 *      These are bad and should make rlm_sql return invalid
@@ -648,9 +640,6 @@ unlang_action_t rlm_sql_select_query(rlm_rcode_t *p_result, UNUSED int *priority
        rlm_sql_t const *inst = query_ctx->inst;
        int i, count;
 
-       /* Caller should check they have a valid handle */
-       fr_assert(query_ctx->handle);
-
        /* There's no query to run, return an error */
        if (query_ctx->query_str[0] == '\0') {
                if (request) REDEBUG("Zero length query");
@@ -680,11 +669,7 @@ unlang_action_t rlm_sql_select_query(rlm_rcode_t *p_result, UNUSED int *priority
                 *      sockets in the pool and fail to establish a *new* connection.
                 */
                case RLM_SQL_RECONNECT:
-                       query_ctx->handle = fr_pool_connection_reconnect(inst->pool, request, query_ctx->handle);
-                       /* Reconnection failed */
-                       if (!query_ctx->handle) RETURN_MODULE_FAIL;
-                       /* Reconnection succeeded, try again with the new handle */
-                       continue;
+                       RETURN_MODULE_FAIL;
 
                case RLM_SQL_QUERY_INVALID:
                case RLM_SQL_ERROR:
@@ -752,14 +737,13 @@ static unlang_action_t sql_get_map_list_resume(rlm_rcode_t *p_result, UNUSED int
 /** 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, rlm_sql_handle_t **handle,
-                                trunk_t *trunk)
+unlang_action_t sql_get_map_list(request_t *request, fr_sql_map_ctx_t *map_ctx, trunk_t *trunk)
 {
        rlm_sql_t const *inst = map_ctx->inst;
 
        fr_assert(request);
 
-       MEM(map_ctx->query_ctx = fr_sql_query_alloc(map_ctx->ctx, inst, request, *handle, trunk,
+       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(request, NULL, sql_get_map_list_resume, NULL, 0, UNLANG_SUB_FRAME, map_ctx) < 0) return UNLANG_ACTION_FAIL;
index b741c3f202933286d3c90c21d98d032dad80c8a6..c60a634ccf5b17ebff8d47ef85bf3b7832e64cd7 100644 (file)
@@ -530,7 +530,7 @@ static unlang_action_t CC_HINT(nonnull) mod_alloc(rlm_rcode_t *p_result, module_
         *      Since they typically form an SQL transaction, they all need to be on the same
         *      connection, and use the same trunk request if using trunks.
         */
-       MEM(alloc_ctx->query_ctx = sql->query_alloc(alloc_ctx, sql, request, handle, thread->trunk, "", SQL_QUERY_OTHER));
+       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(request, NULL, mod_alloc_resume, NULL, 0, UNLANG_SUB_FRAME, alloc_ctx) < 0 ) {
@@ -634,7 +634,7 @@ static unlang_action_t CC_HINT(nonnull) mod_common(rlm_rcode_t *p_result, module
        };
        talloc_set_destructor(common_ctx, sqlippool_common_ctx_free);
 
-       MEM(common_ctx->query_ctx = sql->query_alloc(common_ctx, sql, request, handle, thread->trunk, "", SQL_QUERY_OTHER));
+       MEM(common_ctx->query_ctx = sql->query_alloc(common_ctx, sql, request, thread->trunk, "", SQL_QUERY_OTHER));
 
        /*
         *  An optional query which can be used to tidy up before updates