From: Alan T. DeKok Date: Fri, 24 Feb 2017 16:49:41 +0000 (-0500) Subject: mod_conn_create should not be global X-Git-Tag: release_3_0_13~14 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ba2fcf623a468c73d216cda0a77eff5d42597d7c;p=thirdparty%2Ffreeradius-server.git mod_conn_create should not be global --- diff --git a/src/modules/rlm_sql/rlm_sql.c b/src/modules/rlm_sql/rlm_sql.c index f60753d5b4f..60502461e2d 100644 --- a/src/modules/rlm_sql/rlm_sql.c +++ b/src/modules/rlm_sql/rlm_sql.c @@ -919,6 +919,50 @@ static int mod_bootstrap(CONF_SECTION *conf, void *instance) } +static void *mod_conn_create(TALLOC_CTX *ctx, void *instance) +{ + int rcode; + rlm_sql_t *inst = instance; + rlm_sql_handle_t *handle; + + /* + * Connections cannot be alloced from the inst or + * pool contexts due to threading issues. + */ + handle = talloc_zero(ctx, rlm_sql_handle_t); + if (!handle) return NULL; + + handle->log_ctx = talloc_pool(handle, 2048); + if (!handle->log_ctx) { + talloc_free(handle); + return NULL; + } + + /* + * Handle requires a pointer to the SQL inst so the + * destructor has access to the module configuration. + */ + handle->inst = inst; + + rcode = (inst->module->sql_socket_init)(handle, inst->config); + if (rcode != 0) { + fail: + /* + * Destroy any half opened connections. + */ + talloc_free(handle); + return NULL; + } + + if (inst->config->connect_query) { + if (rlm_sql_select_query(inst, NULL, &handle, inst->config->connect_query) != RLM_SQL_OK) goto fail; + (inst->module->sql_finish_select_query)(handle, inst->config); + } + + return handle; +} + + static int mod_instantiate(CONF_SECTION *conf, void *instance) { rlm_sql_t *inst = instance; diff --git a/src/modules/rlm_sql/rlm_sql.h b/src/modules/rlm_sql/rlm_sql.h index a241353a4d7..eba8a902da4 100644 --- a/src/modules/rlm_sql/rlm_sql.h +++ b/src/modules/rlm_sql/rlm_sql.h @@ -242,7 +242,6 @@ typedef struct sql_grouplist { struct sql_grouplist *next; } rlm_sql_grouplist_t; -void *mod_conn_create(TALLOC_CTX *ctx, void *instance); int sql_fr_pair_list_afrom_str(TALLOC_CTX *ctx, REQUEST *request, VALUE_PAIR **first_pair, rlm_sql_row_t row); int sql_read_realms(rlm_sql_handle_t *handle); int sql_getvpdata(TALLOC_CTX *ctx, rlm_sql_t *inst, REQUEST *request, rlm_sql_handle_t **handle, VALUE_PAIR **pair, char const *query); diff --git a/src/modules/rlm_sql/sql.c b/src/modules/rlm_sql/sql.c index 51ba11d979c..05d0bc24564 100644 --- a/src/modules/rlm_sql/sql.c +++ b/src/modules/rlm_sql/sql.c @@ -54,49 +54,6 @@ const FR_NAME_NUMBER sql_rcode_table[] = { }; -void *mod_conn_create(TALLOC_CTX *ctx, void *instance) -{ - int rcode; - rlm_sql_t *inst = instance; - rlm_sql_handle_t *handle; - - /* - * Connections cannot be alloced from the inst or - * pool contexts due to threading issues. - */ - handle = talloc_zero(ctx, rlm_sql_handle_t); - if (!handle) return NULL; - - handle->log_ctx = talloc_pool(handle, 2048); - if (!handle->log_ctx) { - talloc_free(handle); - return NULL; - } - - /* - * Handle requires a pointer to the SQL inst so the - * destructor has access to the module configuration. - */ - handle->inst = inst; - - rcode = (inst->module->sql_socket_init)(handle, inst->config); - if (rcode != 0) { - fail: - /* - * Destroy any half opened connections. - */ - talloc_free(handle); - return NULL; - } - - if (inst->config->connect_query) { - if (rlm_sql_select_query(inst, NULL, &handle, inst->config->connect_query) != RLM_SQL_OK) goto fail; - (inst->module->sql_finish_select_query)(handle, inst->config); - } - - return handle; -} - /************************************************************************* * * Function: sql_fr_pair_list_afrom_str