*/
sql_set_user(inst, request, NULL);
- handle = sql_get_socket(inst);
+ handle = fr_connection_get(inst->pool);
if (!handle) {
return 0;
}
(inst->module->sql_finish_select_query)(handle, inst->config);
finish:
- sql_release_socket(inst, handle);
+ fr_connection_release(inst->pool, handle);
return ret;
}
DEBUG("rlm_sql (%s) in generate_sql_clients: query is %s",
inst->config->xlat_name, inst->config->client_query);
- handle = sql_get_socket(inst);
+ handle = fr_connection_get(inst->pool);
if (!handle) {
return -1;
}
}
(inst->module->sql_finish_select_query)(handle, inst->config);
- sql_release_socket(inst, handle);
+ fr_connection_release(inst->pool, handle);
return 0;
}
/*
* Get a socket for this lookup
*/
- handle = sql_get_socket(inst);
+ handle = fr_connection_get(inst->pool);
if (!handle) {
return 1;
}
*/
if (sql_get_grouplist(inst, &handle, request, &head) < 0) {
REDEBUG("Error getting group membership");
- sql_release_socket(inst, handle);
+ fr_connection_release(inst->pool, handle);
return 1;
}
RDEBUG("sql_groupcmp finished: User is a member of group %s",
check->vp_strvalue);
talloc_free(head);
- sql_release_socket(inst, handle);
+ fr_connection_release(inst->pool, handle);
return 0;
}
}
/* Free the grouplist */
talloc_free(head);
- sql_release_socket(inst, handle);
+ fr_connection_release(inst->pool, handle);
RDEBUG("sql_groupcmp finished: User is NOT a member of group %s", check->vp_strvalue);
{
rlm_sql_t *inst = instance;
- if (inst->config) {
- if (inst->pool) sql_poolfree(inst);
- }
+ if (inst->config) if (inst->pool) fr_connection_pool_delete(inst->pool);
if (inst->handle) {
#if 0
* Export these methods, too. This avoids RTDL_GLOBAL.
*/
inst->sql_set_user = sql_set_user;
- inst->sql_get_socket = sql_get_socket;
- inst->sql_release_socket = sql_release_socket;
inst->sql_escape_func = sql_escape_func;
inst->sql_query = rlm_sql_query;
inst->sql_select_query = rlm_sql_select_query;
*/
INFO("rlm_sql (%s): Attempting to connect to database \"%s\"", inst->config->xlat_name, inst->config->sql_db);
- if (sql_socket_pool_init(inst) < 0) return -1;
+ inst->pool = fr_connection_pool_module_init(inst->cs, inst, mod_conn_create, NULL, NULL);
+ if (!inst->pool) return -1;
if (inst->config->groupmemb_query &&
inst->config->groupmemb_query[0]) {
* After this point use goto error or goto release to cleanup socket temporary pairlists and
* temporary attributes.
*/
- handle = sql_get_socket(inst);
+ handle = fr_connection_get(inst->pool);
if (!handle) {
rcode = RLM_MODULE_FAIL;
goto error;
rcode = RLM_MODULE_NOTFOUND;
}
- sql_release_socket(inst, handle);
+ fr_connection_release(inst->pool, handle);
sql_unset_user(inst, request);
return rcode;
pairfree(&reply_tmp);
sql_unset_user(inst, request);
- sql_release_socket(inst, handle);
+ fr_connection_release(inst->pool, handle);
return rcode;
}
RDEBUG2("Using query template '%s'", attr);
- handle = sql_get_socket(inst);
+ handle = fr_connection_get(inst->pool);
if (!handle) {
rcode = RLM_MODULE_FAIL;
*
* If we get RLM_SQL_RECONNECT it means all connections in the pool
* were exhausted, and we couldn't create a new connection,
- * so we do not need to call sql_release_socket.
+ * so we do not need to call fr_connection_release.
*/
sql_ret = rlm_sql_query(&handle, inst, expanded);
TALLOC_FREE(expanded);
finish:
talloc_free(expanded);
- sql_release_socket(inst, handle);
+ fr_connection_release(inst->pool, handle);
sql_unset_user(inst, request);
return rcode;
}
/* initialize the sql socket */
- handle = sql_get_socket(inst);
+ handle = fr_connection_get(inst->pool);
if (!handle) {
talloc_free(expanded);
sql_unset_user(inst, request);
finish:
(inst->module->sql_finish_select_query)(handle, inst->config);
- sql_release_socket(inst, handle);
+ fr_connection_release(inst->pool, handle);
talloc_free(expanded);
sql_unset_user(inst, request);
rlm_sql_module_t *module;
int (*sql_set_user)(rlm_sql_t *inst, REQUEST *request, char const *username);
- rlm_sql_handle_t *(*sql_get_socket)(rlm_sql_t *inst);
- int (*sql_release_socket)(rlm_sql_t *inst, rlm_sql_handle_t *handle);
size_t (*sql_escape_func)(REQUEST *, char *out, size_t outlen, char const *in, void *arg);
sql_rcode_t (*sql_query)(rlm_sql_handle_t **handle, rlm_sql_t *inst, char const *query);
sql_rcode_t (*sql_select_query)(rlm_sql_handle_t **handle, rlm_sql_t *inst, char const *query);
struct sql_grouplist *next;
} rlm_sql_grouplist_t;
-int sql_socket_pool_init(rlm_sql_t *inst);
-void sql_poolfree(rlm_sql_t *inst);
-int sql_close_socket(rlm_sql_t *inst, rlm_sql_handle_t *handle);
-rlm_sql_handle_t *sql_get_socket(rlm_sql_t *inst);
-int sql_release_socket(rlm_sql_t *inst, rlm_sql_handle_t *handle);
+void *mod_conn_create(TALLOC_CTX *ctx, void *instance);
int sql_userparse(TALLOC_CTX *ctx, 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, rlm_sql_handle_t **handle, VALUE_PAIR **pair, char const *query);
#ifdef HAVE_PTHREAD_H
#endif
-static int _sql_conn_free(rlm_sql_handle_t *conn)
+static int _mod_conn_free(rlm_sql_handle_t *conn)
{
rlm_sql_t *inst = conn->inst;
return 0;
}
-static void *mod_conn_create(TALLOC_CTX *ctx, void *instance)
+void *mod_conn_create(TALLOC_CTX *ctx, void *instance)
{
int rcode;
rlm_sql_t *inst = instance;
* Then we call our destructor to trigger an modules.sql.close
* event, then all the memory is freed.
*/
- talloc_set_destructor(handle, _sql_conn_free);
+ talloc_set_destructor(handle, _mod_conn_free);
rcode = (inst->module->sql_socket_init)(handle, inst->config);
if (rcode != 0) {
/*************************************************************************
*
- * Function: sql_socket_pool_init
- *
- * Purpose: Connect to the sql server, if possible
- *
- *************************************************************************/
-int sql_socket_pool_init(rlm_sql_t * inst)
-{
- inst->pool = fr_connection_pool_module_init(inst->cs, inst, mod_conn_create, NULL, NULL);
- if (!inst->pool) return -1;
-
- return 1;
-}
-
-/*************************************************************************
- *
- * Function: sql_poolfree
- *
- * Purpose: Clean up and free sql pool
- *
- *************************************************************************/
-void sql_poolfree(rlm_sql_t * inst)
-{
- fr_connection_pool_delete(inst->pool);
-}
-
-
-/*************************************************************************
- *
- * Function: sql_get_socket
- *
- * Purpose: Return a SQL handle from the connection pool
- *
- *************************************************************************/
-rlm_sql_handle_t * sql_get_socket(rlm_sql_t * inst)
-{
- return fr_connection_get(inst->pool);
-}
-
-/*************************************************************************
- *
- * Function: sql_release_socket
- *
- * Purpose: Frees a SQL handle back to the connection pool
- *
- *************************************************************************/
-int sql_release_socket(rlm_sql_t * inst, rlm_sql_handle_t * handle)
-{
- fr_connection_release(inst->pool, handle);
- return 0;
-}
-
-
-/*************************************************************************
- *
* Function: sql_userparse
*
* Purpose: Read entries from the database and fill VALUE_PAIR structures
typedef struct rlm_sqlhpwippool_t {
char const *myname; //!< Name of this instance
- rlm_sql_t *sqlinst;
+ rlm_sql_t *sql_inst;
rlm_sql_module_t *db;
#ifdef HAVE_PTHREAD_D
pthread_mutex_t mutex; //!< Used "with" sync_after
{
char query[MAX_QUERY_LEN];
vsnprintf(query, MAX_QUERY_LEN, fmt, ap);
- if (rlm_sql_query(&sqlsock, data->sqlinst, query)) {
+ if (rlm_sql_query(&sqlsock, data->sql_inst, query)) {
nvp_log(__LINE__, data, L_ERR, "nvp_vquery(): query from line %u: %s",
- line, (char const *)(data->db->sql_error)(sqlsock, data->sqlinst->config));
+ line, (char const *)(data->db->sql_error)(sqlsock, data->sql_inst->config));
return 0;
}
/* handy wrapper around data->db->sql_finish_query() */
static int nvp_finish(rlm_sqlhpwippool_t *data, rlm_sql_handle_t *sqlsock)
{
- return (data->db->sql_finish_query)(sqlsock, data->sqlinst->config);
+ return (data->db->sql_finish_query)(sqlsock, data->sql_inst->config);
}
/* executes query and fetches first row
}
va_end(ap);
- if ((data->db->sql_store_result)(sqlsock, data->sqlinst->config)) {
+ if ((data->db->sql_store_result)(sqlsock, data->sql_inst->config)) {
nvp_log(__LINE__, data, L_ERR,
"nvp_select(): error while saving results of query from line %u",
line);
return 0;
}
- if ((data->db->sql_num_rows)(sqlsock, data->sqlinst->config) < 1) {
+ if ((data->db->sql_num_rows)(sqlsock, data->sql_inst->config) < 1) {
nvp_log(__LINE__, data, L_DBG,
"nvp_select(): no results in query from line %u", line);
return -1;
}
- if ((data->db->sql_fetch_row)(sqlsock, data->sqlinst->config)) {
+ if ((data->db->sql_fetch_row)(sqlsock, data->sql_inst->config)) {
nvp_log(__LINE__, data, L_ERR, "nvp_select(): couldn't fetch row "
"from results of query from line %u",
line);
static int nvp_select_finish(rlm_sqlhpwippool_t *data, rlm_sql_handle_t *sqlsock)
{
- return ((data->db->sql_free_result)(sqlsock, data->sqlinst->config) ||
+ return ((data->db->sql_free_result)(sqlsock, data->sql_inst->config) ||
nvp_finish(data, sqlsock));
}
rlm_sql_handle_t *sqlsock;
/* initialize the SQL socket */
- sqlsock = sql_get_socket(data->sqlinst);
+ sqlsock = fr_connection_get(data->sql_inst->pool);
if (!sqlsock) {
nvp_log(__LINE__, data, L_ERR, "nvp_cleanup(): error while "
"requesting new SQL connection");
/* free IPs of closed sessions */
if (!nvp_freeclosed(data, sqlsock)) {
- sql_release_socket(data->sqlinst, sqlsock);
+ fr_connection_release(data->sql_inst->pool, sqlsock);
return 0;
}
"`ips`.`rsv_until` != 0" /* no acct pkt received yet */
")",
data->db_name)) {
- sql_release_socket(data->sqlinst, sqlsock);
+ fr_connection_release(data->sql_inst->pool, sqlsock);
return 0;
}
else {
/* count number of free IP addresses in IP pools */
if (!nvp_syncfree(data, sqlsock)) {
- sql_release_socket(data->sqlinst, sqlsock);
+ fr_connection_release(data->sql_inst->pool, sqlsock);
return 0;
}
- sql_release_socket(data->sqlinst, sqlsock);
+ fr_connection_release(data->sql_inst->pool, sqlsock);
return 1;
}
static int mod_instantiate(CONF_SECTION *conf, void *instance)
{
rlm_sqlhpwippool_t *inst = instance;
- module_instance_t *sqlinst;
+ module_instance_t *sql_inst;
/* save my name */
inst->myname = cf_section_name2(conf);
inst->sincesync = 0;
- sqlinst = find_module_instance(cf_section_find("modules"), (inst->sql_module_instance), true);
- if (!sqlinst) {
+ sql_inst = find_module_instance(cf_section_find("modules"), (inst->sql_module_instance), true);
+ if (!sql_inst) {
nvp_log(__LINE__, inst, L_ERR,
"mod_instantiate(): cannot find module instance "
"named \"%s\"",
}
/* check if the given instance is really a rlm_sql instance */
- if (strcmp(sqlinst->entry->name, "rlm_sql") != 0) {
+ if (strcmp(sql_inst->entry->name, "rlm_sql") != 0) {
nvp_log(__LINE__, inst, L_ERR,
"mod_instantiate(): given instance (%s) is not "
"an instance of the rlm_sql module",
}
/* save pointers to useful "objects" */
- inst->sqlinst = (rlm_sql_t *) sqlinst->insthandle;
- inst->db = (rlm_sql_module_t *) inst->sqlinst->module;
+ inst->sql_inst = (rlm_sql_t *) sql_inst->insthandle;
+ inst->db = (rlm_sql_module_t *) inst->sql_inst->module;
return ((nvp_cleanup(inst)) ? 0 : -1);
}
}
/* get our database connection */
- sqlsock = sql_get_socket(inst->sqlinst);
+ sqlsock = fr_connection_get(inst->sql_inst->pool);
if (!sqlsock) {
nvp_log(__LINE__, inst, L_ERR,
"mod_post_auth(): error while requesting an SQL socket");
if (nvp_select(__LINE__, inst, sqlsock, "SELECT CONNECTION_ID()") < 1) {
nvp_log(__LINE__, inst, L_ERR, "mod_post_auth(): WTF ;-)!");
nvp_select_finish(inst, sqlsock);
- sql_release_socket(inst->sqlinst, sqlsock);
+ fr_connection_release(inst->sql_inst->pool, sqlsock);
return RLM_MODULE_FAIL;
}
if (!r) {
nvp_log(__LINE__, inst, L_ERR,
"mod_post_auth(): synchronization failed");
- sql_release_socket(inst->sqlinst, sqlsock);
+ fr_connection_release(inst->sql_inst->pool, sqlsock);
return RLM_MODULE_FAIL;
}
}
goto end_gid; /* exit the main loop */
case 0:
- sql_release_socket(inst->sqlinst, sqlsock);
+ fr_connection_release(inst->sql_inst->pool, sqlsock);
return RLM_MODULE_FAIL;
}
goto end_prio; /* select next gid */
case 0:
- sql_release_socket(inst->sqlinst, sqlsock);
+ fr_connection_release(inst->sql_inst->pool, sqlsock);
return RLM_MODULE_FAIL;
}
goto end_pid; /* select next prio */
case 0:
- sql_release_socket(inst->sqlinst, sqlsock);
+ fr_connection_release(inst->sql_inst->pool, sqlsock);
return RLM_MODULE_FAIL;
}
"ORDER BY RAND() "
"LIMIT 1",
inst->db_name, pid, connid, inst->free_after, ip_start, ip_stop)) {
- sql_release_socket(inst->sqlinst, sqlsock);
+ fr_connection_release(inst->sql_inst->pool, sqlsock);
return RLM_MODULE_FAIL;
}
else {
continue; /* select next pid */
case 0:
- sql_release_socket(inst->sqlinst, sqlsock);
+ fr_connection_release(inst->sql_inst->pool, sqlsock);
return RLM_MODULE_FAIL;
}
"`pid` = %lu "
"LIMIT 1",
inst->db_name, pid)) {
- sql_release_socket(inst->sqlinst, sqlsock);
+ fr_connection_release(inst->sql_inst->pool, sqlsock);
return RLM_MODULE_FAIL;
}
else {
end_gid:
/* release SQL socket */
- sql_release_socket(inst->sqlinst, sqlsock);
+ fr_connection_release(inst->sql_inst->pool, sqlsock);
/* no free IP address found */
if (!ip.s_addr) {
}
/* connect to database */
- sqlsock = sql_get_socket(inst->sqlinst);
+ sqlsock = fr_connection_get(inst->sql_inst->pool);
if (!sqlsock) {
nvp_log(__LINE__, inst, L_ERR,
"mod_accounting(): couldn't connect to database");
vp = pairfind(request->packet->vps, PW_FRAMED_IP_ADDRESS, 0, TAG_ANY);
if (!vp) {
nvp_log(__LINE__, inst, L_ERR, "mod_accounting(): no framed IP");
- sql_release_socket(inst->sqlinst, sqlsock);
+ fr_connection_release(inst->sql_inst->pool, sqlsock);
return RLM_MODULE_FAIL;
}
"`rsv_by` = '%s' "
"WHERE `ip` = %lu",
inst->db_name, sessid, framedip)) {
- sql_release_socket(inst->sqlinst, sqlsock);
+ fr_connection_release(inst->sql_inst->pool, sqlsock);
return RLM_MODULE_FAIL;
}
nvp_finish(inst, sqlsock);
"`ips`.`rsv_by` = '%s' AND "
"`ips`.`ip` BETWEEN `ip_pools`.`ip_start` AND `ip_pools`.`ip_stop`",
inst->db_name, inst->free_after, sessid)) {
- sql_release_socket(inst->sqlinst, sqlsock);
+ fr_connection_release(inst->sql_inst->pool, sqlsock);
return RLM_MODULE_FAIL;
}
nvp_finish(inst, sqlsock);
vp = pairfind(request->packet->vps, PW_NAS_IP_ADDRESS, 0, TAG_ANY);
if (!vp) {
nvp_log(__LINE__, inst, L_ERR, "mod_accounting(): no NAS IP");
- sql_release_socket(inst->sqlinst, sqlsock);
+ fr_connection_release(inst->sql_inst->pool, sqlsock);
return RLM_MODULE_FAIL;
}
"`radacct`.`nasipaddress` = '%s' AND "
"`ips`.`rsv_by` = `radacct`.`acctuniqueid`",
inst->db_name, inst->free_after, nasipstr)) {
- sql_release_socket(inst->sqlinst, sqlsock);
+ fr_connection_release(inst->sql_inst->pool, sqlsock);
return RLM_MODULE_FAIL;
}
nvp_finish(inst, sqlsock);
break;
}
- sql_release_socket(inst->sqlinst, sqlsock);
+ fr_connection_release(inst->sql_inst->pool, sqlsock);
return RLM_MODULE_OK;
}
*/
static int mod_instantiate(CONF_SECTION *conf, void *instance)
{
- module_instance_t *sqlinst;
+ module_instance_t *sql_inst;
rlm_sqlippool_t *inst = instance;
char const *pool_name = NULL;
} else {
inst->pool_name = talloc_typed_strdup(inst, "ippool");
}
- sqlinst = find_module_instance(cf_section_find("modules"),
+ sql_inst = find_module_instance(cf_section_find("modules"),
inst->sql_instance_name, true);
- if (!sqlinst) {
+ if (!sql_inst) {
cf_log_err_cs(conf, "failed to find sql instance named %s",
inst->sql_instance_name);
return -1;
inst->framed_ip_address = PW_FRAMED_IPV6_PREFIX;
}
- if (strcmp(sqlinst->entry->name, "rlm_sql") != 0) {
+ if (strcmp(sql_inst->entry->name, "rlm_sql") != 0) {
cf_log_err_cs(conf, "Module \"%s\""
" is not an instance of the rlm_sql module",
inst->sql_instance_name);
return -1;
}
- inst->sql_inst = (rlm_sql_t *) sqlinst->insthandle;
+ inst->sql_inst = (rlm_sql_t *) sql_inst->insthandle;
return 0;
}
return do_logging(request, inst->log_nopool, RLM_MODULE_NOOP);
}
- handle = inst->sql_inst->sql_get_socket(inst->sql_inst);
+ handle = fr_connection_get(inst->sql_inst->pool);
if (!handle) {
REDEBUG("cannot get sql connection");
return RLM_MODULE_FAIL;
inst->pool_check, handle, inst, request,
(char *) NULL, 0);
- inst->sql_inst->sql_release_socket(inst->sql_inst, handle);
+ fr_connection_release(inst->sql_inst->pool, handle);
if (allocation_len) {
}
- inst->sql_inst->sql_release_socket(inst->sql_inst, handle);
+ fr_connection_release(inst->sql_inst->pool, handle);
RDEBUG("IP address could not be allocated");
return do_logging(request, inst->log_failed, RLM_MODULE_NOOP);
DO(allocate_commit);
RDEBUG("Invalid IP number [%s] returned from instbase query.", allocation);
- inst->sql_inst->sql_release_socket(inst->sql_inst, handle);
+ fr_connection_release(inst->sql_inst->pool, handle);
return do_logging(request, inst->log_failed, RLM_MODULE_NOOP);
}
DO(allocate_commit);
- inst->sql_inst->sql_release_socket(inst->sql_inst, handle);
+ fr_connection_release(inst->sql_inst->pool, handle);
return do_logging(request, inst->log_success, RLM_MODULE_OK);
}
return RLM_MODULE_NOOP;
}
- handle = inst->sql_inst->sql_get_socket(inst->sql_inst);
+ handle = fr_connection_get(inst->sql_inst->pool);
if (!handle) {
RDEBUG("Cannot allocate sql connection");
return RLM_MODULE_FAIL;
break;
}
- inst->sql_inst->sql_release_socket(inst->sql_inst, handle);
+ fr_connection_release(inst->sql_inst->pool, handle);
return rcode;
}