From: Jorge Pereira Date: Thu, 19 May 2022 23:00:49 +0000 (-0300) Subject: rlm_couchbase: Fix several issues (#4517) X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d0fd918ff5aab3c9d0961ecfe243cb1a25bdd0d3;p=thirdparty%2Ffreeradius-server.git rlm_couchbase: Fix several issues (#4517) --- diff --git a/src/modules/rlm_couchbase/mod.c b/src/modules/rlm_couchbase/mod.c index 1d1642219bf..75a49512d54 100644 --- a/src/modules/rlm_couchbase/mod.c +++ b/src/modules/rlm_couchbase/mod.c @@ -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"); diff --git a/src/modules/rlm_couchbase/mod.h b/src/modules/rlm_couchbase/mod.h index 2359620adba..72fb139c558 100644 --- a/src/modules/rlm_couchbase/mod.h +++ b/src/modules/rlm_couchbase/mod.h @@ -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); diff --git a/src/modules/rlm_couchbase/rlm_couchbase.c b/src/modules/rlm_couchbase/rlm_couchbase.c index 9abf2451518..813d02b2031 100644 --- a/src/modules/rlm_couchbase/rlm_couchbase.c +++ b/src/modules/rlm_couchbase/rlm_couchbase.c @@ -26,7 +26,7 @@ RCSID("$Id$") -#define LOG_PREFIX inst->name +#define LOG_PREFIX "couchbase - " #include #include @@ -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,