*/
if (!fmt || !*fmt) return 0;
+ /*
+ * No handle? That's an error.
+ */
+ if (!handle || !*handle) return -1;
+
/*
* @todo this needs to die (should just be done in xlat expansion)
*/
* Query the database expecting a single result row
*/
static int CC_HINT(nonnull (1, 3, 4, 5)) sqlippool_query1(char *out, int outlen, char const *fmt,
- rlm_sql_handle_t *handle, rlm_sqlippool_t *data,
+ rlm_sql_handle_t **handle, rlm_sqlippool_t *data,
REQUEST *request, char *param, int param_len)
{
char query[MAX_QUERY_LEN];
/*
* Do an xlat on the provided string
*/
- if (xlat_aeval(request, &expanded, request, query, data->sql_inst->sql_escape_func, handle) < 0) {
+ if (xlat_aeval(request, &expanded, request, query, data->sql_inst->sql_escape_func, *handle) < 0) {
return 0;
}
- retval = data->sql_inst->sql_select_query(data->sql_inst, request, &handle, expanded);
+ retval = data->sql_inst->sql_select_query(data->sql_inst, request, handle, expanded);
talloc_free(expanded);
- if (retval != 0){
+ if ((retval != 0) || !*handle) {
REDEBUG("database query error on '%s'", query);
return 0;
}
- if (data->sql_inst->sql_fetch_row(&row, data->sql_inst, request, &handle) < 0) {
+ if (data->sql_inst->sql_fetch_row(&row, data->sql_inst, request, handle) < 0) {
REDEBUG("Failed fetching query result");
goto finish;
}
strcpy(out, row[0]);
retval = rlen;
+
finish:
- (data->sql_inst->driver->sql_finish_select_query)(handle, data->sql_inst->config);
+ (data->sql_inst->driver->sql_finish_select_query)(*handle, data->sql_inst->config);
return retval;
}
DO_PART(allocate_begin);
allocation_len = sqlippool_query1(allocation, sizeof(allocation),
- inst->allocate_find, handle,
+ inst->allocate_find, &handle,
inst, request, (char *) NULL, 0);
+ if (!handle) return RLM_MODULE_FAIL;
/*
* Nothing found...
*Let's check if the pool exists at all
*/
allocation_len = sqlippool_query1(allocation, sizeof(allocation),
- inst->pool_check, handle, inst, request,
+ inst->pool_check, &handle, inst, request,
(char *) NULL, 0);
+ if (!handle) return RLM_MODULE_FAIL;
fr_pool_connection_release(inst->sql_inst->pool, request, handle);