]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
rlm_couchbase: Fix several issues (#4517)
authorJorge Pereira <jpereira@users.noreply.github.com>
Thu, 19 May 2022 23:00:49 +0000 (20:00 -0300)
committerGitHub <noreply@github.com>
Thu, 19 May 2022 23:00:49 +0000 (18:00 -0500)
src/modules/rlm_couchbase/mod.c
src/modules/rlm_couchbase/mod.h
src/modules/rlm_couchbase/rlm_couchbase.c

index 1d1642219bf458d10ac87cae2e2e86fa3f12d137..75a49512d549fa79a0cdbc5951757089fe7b2a01 100644 (file)
@@ -57,12 +57,11 @@ static int _mod_conn_free(rlm_couchbase_handle_t *chandle)
  *
  * Release the underlying mod_build_api_opts() objects
  *
- * @param  instance The module instance.
+ * @param  inst    The module instance.
  * @return 0.
  */
-int mod_free_api_opts(void *instance)
+int mod_free_api_opts(rlm_couchbase_t *inst)
 {
-       rlm_couchbase_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_couchbase_t);       /* our module instance */
        couchbase_opts_t *opts = inst->api_opts;
 
        if (!opts) return 0;
@@ -70,11 +69,11 @@ int mod_free_api_opts(void *instance)
        DEBUG("Releasing the couchbase api options");
 
        for (; opts != NULL; opts = opts->next) {
-               if (opts->key) talloc_free(opts->key);
-               if (opts->val) talloc_free(opts->val);
+               TALLOC_FREE(opts->key);
+               TALLOC_FREE(opts->val);
        }
 
-       talloc_free(opts);
+       TALLOC_FREE(opts);
 
        /* return */
        return 0;
@@ -86,14 +85,13 @@ int mod_free_api_opts(void *instance)
  * as a couchbase_opts_t object (key/value list).
  *
  * @param  conf     Configuration list.
- * @param  instance The module instance.
+ * @param  inst     The module instance.
  * @return
  *      - 0 on success.
  *     - -1 on failure.
  */
-int mod_build_api_opts(CONF_SECTION *conf, void *instance)
+int mod_build_api_opts(CONF_SECTION *conf, rlm_couchbase_t *inst)
 {
-       rlm_couchbase_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_couchbase_t);       /* our module instance */
        CONF_SECTION *cs;                       /* module config list */
        CONF_ITEM *ci;                          /* config item */
        CONF_PAIR *cp;                          /* config pair */
@@ -155,7 +153,7 @@ int mod_build_api_opts(CONF_SECTION *conf, void *instance)
  */
 void *mod_conn_create(TALLOC_CTX *ctx, void *instance, fr_time_delta_t timeout)
 {
-       rlm_couchbase_t const *inst = talloc_get_type_abort_const(instance, rlm_couchbase_t);           /* module instance pointer */
+       rlm_couchbase_t *inst = talloc_get_type_abort(instance, rlm_couchbase_t); /* module instance pointer */
        rlm_couchbase_handle_t *chandle = NULL;           /* connection handle pointer */
        cookie_t *cookie = NULL;                          /* couchbase cookie */
        lcb_t cb_inst;                                    /* couchbase connection instance */
@@ -201,15 +199,15 @@ void *mod_conn_create(TALLOC_CTX *ctx, void *instance, fr_time_delta_t timeout)
  * a cluster statistics report.  Mark the connection as failed if the request
  * returns anything other than success.
  *
- * @param  instance The module instance (currently unused).
- * @param  handle   The connection handle.
+ * @param  opaque       The module instance (currently unused).
+ * @param  connection   The connection handle.
  * @return
  *     - 0 on success (alive).
  *     - -1 on failure (unavailable).
  */
-int mod_conn_alive(UNUSED void *instance, void *handle)
+int mod_conn_alive(UNUSED void *opaque, void *connection)
 {
-       rlm_couchbase_handle_t *chandle = handle;   /* connection handle pointer */
+       rlm_couchbase_handle_t *chandle = connection;   /* connection handle pointer */
        lcb_t cb_inst = chandle->handle;            /* couchbase instance */
        lcb_error_t cb_error = LCB_SUCCESS;         /* couchbase error status */
 
@@ -231,14 +229,13 @@ int mod_conn_alive(UNUSED void *instance, void *handle)
  * used to lookup and map attributes for all incoming accounting requests.
  *
  * @param  conf     Configuration list.
- * @param  instance The module instance.
+ * @param  inst     The module instance.
  * @return
  *      - 0 on success.
  *     - -1 on failure.
  */
-int mod_build_attribute_element_map(CONF_SECTION *conf, void *instance)
+int mod_build_attribute_element_map(CONF_SECTION *conf, rlm_couchbase_t *inst)
 {
-       rlm_couchbase_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_couchbase_t);   /* our module instance */
        CONF_SECTION *cs;                   /* module config list */
        CONF_ITEM *ci;                      /* config item */
        CONF_PAIR *cp;                      /* conig pair */
@@ -484,8 +481,10 @@ int mod_json_object_to_map(TALLOC_CTX *ctx, fr_dcursor_t *out, request_t *reques
                        if (map_afrom_value_box(ctx, &map,
                                                attr_name, T_BARE_WORD,
                                                &(tmpl_rules_t){
-                                                       .dict_def = request->dict,
-                                                       .list_def = list,
+                                                       .attr = {
+                                                               .dict_def = request->dict,
+                                                               .list_def = list
+                                                       }
                                                },
                                                op,
                                                &tmp, true) < 0) {
@@ -629,7 +628,7 @@ int mod_ensure_start_timestamp(json_object *json, fr_pair_list_t *vps)
        /* get current event timestamp */
        if ((vp = fr_pair_find_by_da_idx(vps, attr_event_timestamp, 0)) != NULL) {
                /* get seconds value from attribute */
-               ts = fr_time_to_sec(vp->vp_date);
+               ts = fr_unix_time_to_sec(vp->vp_date);
        } else {
                /* debugging */
                DEBUG("failed to find event timestamp in current request");
index 2359620adba427c5cbe384de7ad8a94efc01e8dd..72fb139c558c9ec524ca09b7ff8f841379f9bf58 100644 (file)
@@ -74,11 +74,11 @@ typedef struct {
 } rlm_couchbase_handle_t;
 
 /* define functions */
-void *mod_conn_create(TALLOC_CTX *ctx, void *instance, fr_time_delta_t timeout);
+void *mod_conn_create(TALLOC_CTX *ctx, UNUSED void *instance, fr_time_delta_t timeout);
 
-int mod_conn_alive(UNUSED void *instance, void *handle);
+int mod_conn_alive(void *opaque, void *connection);
 
-int mod_build_attribute_element_map(CONF_SECTION *conf, void *instance);
+int mod_build_attribute_element_map(CONF_SECTION *conf, rlm_couchbase_t *inst);
 
 int mod_attribute_to_element(const char *name, json_object *map, void *buf);
 
@@ -92,7 +92,7 @@ int mod_client_map_section(CONF_SECTION *client, CONF_SECTION const *map, json_o
 
 int mod_load_client_documents(rlm_couchbase_t *inst, CONF_SECTION *tmpl, CONF_SECTION *map);
 
-int mod_build_api_opts(CONF_SECTION *conf, void *instance);
+int mod_build_api_opts(CONF_SECTION *conf, rlm_couchbase_t *inst);
 
-int mod_free_api_opts(void *instance);
+int mod_free_api_opts(rlm_couchbase_t *inst);
 
index 9abf2451518d78da91fdb719382e779ad77bd646..813d02b20310fb38a5dfc1abb7ba80b4c6b62d55 100644 (file)
@@ -26,7 +26,7 @@
 
 RCSID("$Id$")
 
-#define LOG_PREFIX inst->name
+#define LOG_PREFIX "couchbase - "
 
 #include <freeradius-devel/server/base.h>
 #include <freeradius-devel/server/map.h>
@@ -149,11 +149,10 @@ static unlang_action_t mod_authorize(rlm_rcode_t *p_result, module_ctx_t const *
                TALLOC_CTX      *pool = talloc_pool(request, 1024);     /* We need to do lots of allocs */
                fr_dcursor_t    maps;
                map_t           *map = NULL;
-               map_list_t      map_head;
+               fr_dlist_head_t map_head;
                vp_list_mod_t   *vlm;
                fr_dlist_head_t vlm_head;
 
-               map_list_init(&map_head);
                fr_dcursor_init(&maps, &map_head);
 
                /*
@@ -419,10 +418,10 @@ finish:
  *
  * Detach the module instance and free any allocated resources.
  *
- * @param  instance The module instance.
+ * @param  mctx The module instance.
  * @return Returns 0 (success) in all conditions.
  */
-static int mod_detach(void *instance)
+static int mod_detach(module_detach_ctx_t const *mctx)
 {
        rlm_couchbase_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_couchbase_t);
 
@@ -437,8 +436,7 @@ static int mod_detach(void *instance)
  *
  * Intialize the module and create the initial Couchbase connection pool.
  *
- * @param  conf     The module configuration.
- * @param  instance The module instance.
+ * @param  mctx     The module instance.
  * @return
  *     - 0 on success.
  *     - -1 on failure.
@@ -446,6 +444,7 @@ static int mod_detach(void *instance)
 static int mod_instantiate(module_inst_ctx_t const *mctx)
 {
        rlm_couchbase_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_couchbase_t);   /* our module instance */
+       CONF_SECTION    *conf = mctx->inst->conf;
 
        {
                char *server, *p;
@@ -556,7 +555,7 @@ module_rlm_t rlm_couchbase = {
                .onload         = mod_load,
                .instantiate    = mod_instantiate,
                .detach         = mod_detach
-       }
+       },
        .methods = {
                [MOD_AUTHORIZE]         = mod_authorize,
                [MOD_ACCOUNTING]        = mod_accounting,