]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
manually pull over changes from v3
authorAlan T. DeKok <aland@freeradius.org>
Mon, 4 Mar 2019 21:46:37 +0000 (16:46 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Mon, 4 Mar 2019 21:46:37 +0000 (16:46 -0500)
src/modules/rlm_sqlippool/rlm_sqlippool.c

index 3f321f77884ca97a16b685d1e5c6d78230f52595..8ede6e13f64b90c043a7a965cf97bfc1458e793a 100644 (file)
@@ -296,6 +296,11 @@ static int sqlippool_command(char const *fmt, rlm_sql_handle_t **handle,
         */
        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)
         */
@@ -331,7 +336,7 @@ static int sqlippool_command(char const *fmt, rlm_sql_handle_t **handle,
  * 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];
@@ -351,18 +356,18 @@ static int CC_HINT(nonnull (1, 3, 4, 5)) sqlippool_query1(char *out, int outlen,
        /*
         *      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;
        }
@@ -385,8 +390,9 @@ static int CC_HINT(nonnull (1, 3, 4, 5)) sqlippool_query1(char *out, int outlen,
 
        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;
 }
@@ -526,8 +532,9 @@ static rlm_rcode_t CC_HINT(nonnull) mod_post_auth(void *instance, UNUSED void *t
        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...
@@ -545,8 +552,9 @@ static rlm_rcode_t CC_HINT(nonnull) mod_post_auth(void *instance, UNUSED void *t
                         *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);