The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Macros | Functions
mod.c File Reference

Utility functions used in the module. More...

#include <freeradius-devel/json/base.h>
#include <freeradius-devel/server/base.h>
#include <freeradius-devel/server/map.h>
#include "mod.h"
#include "couchbase.h"
+ Include dependency graph for mod.c:

Go to the source code of this file.

Macros

#define LOG_PREFIX   "couchbase"
 

Functions

static int _get_client_value (char **out, CONF_PAIR const *cp, void *data)
 Handle client value processing for client_map_section() More...
 
static int _mod_conn_free (rlm_couchbase_handle_t *chandle)
 Delete a connection pool handle and free related resources. More...
 
int mod_attribute_to_element (const char *name, json_object *map, void *buf)
 Map attributes to JSON element names. More...
 
int mod_build_api_opts (CONF_SECTION *conf, rlm_couchbase_t *inst)
 Build a couchbase_opts_t structure from the configuration "couchbase_api" list. More...
 
int mod_build_attribute_element_map (CONF_SECTION *conf, rlm_couchbase_t *inst)
 Build a JSON object map from the configuration "map" list. More...
 
int mod_conn_alive (UNUSED void *opaque, void *connection)
 Check the health of a connection handle. More...
 
void * mod_conn_create (TALLOC_CTX *ctx, void *instance, fr_time_delta_t timeout)
 Create a new connection pool handle. More...
 
int mod_ensure_start_timestamp (json_object *json, fr_pair_list_t *vps)
 Ensure accounting documents always contain a valid timestamp. More...
 
int mod_free_api_opts (rlm_couchbase_t *inst)
 Delete a object built by mod_build_api_opts() More...
 
int mod_json_object_to_map (TALLOC_CTX *ctx, fr_dcursor_t *out, request_t *request, json_object *json, fr_dict_attr_t const *list)
 Build value pairs from the passed JSON object and add to the request. More...
 
int mod_load_client_documents (rlm_couchbase_t *inst, CONF_SECTION *tmpl, CONF_SECTION *map)
 Load client entries from Couchbase client documents on startup. More...
 
json_object * mod_value_pair_to_json_object (request_t *request, fr_pair_t *vp)
 Convert value pairs to json objects. More...
 

Detailed Description

Utility functions used in the module.

Id
35f236aab2b414ba45eca78ecf0cf48db8c27768
Author
Aaron Hurt (ahurt.nosp@m.@anb.nosp@m.cs.co.nosp@m.m)

Definition in file mod.c.

Macro Definition Documentation

◆ LOG_PREFIX

#define LOG_PREFIX   "couchbase"

Definition at line 28 of file mod.c.

Function Documentation

◆ _get_client_value()

static int _get_client_value ( char **  out,
CONF_PAIR const *  cp,
void *  data 
)
static

Handle client value processing for client_map_section()

Parameters
outCharacter output
cpConfiguration pair
dataThe client data
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 674 of file mod.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _mod_conn_free()

static int _mod_conn_free ( rlm_couchbase_handle_t chandle)
static

Delete a connection pool handle and free related resources.

Destroys the underlying Couchbase connection handle freeing any related resources and closes the socket connection.

Parameters
chandleThe connection handle to destroy.
Returns
0.

Definition at line 45 of file mod.c.

+ Here is the caller graph for this function:

◆ mod_attribute_to_element()

int mod_attribute_to_element ( const char *  name,
json_object *  map,
void *  buf 
)

Map attributes to JSON element names.

Attempt to map the passed attribute name to the configured JSON element name using the JSON object map mod_build_attribute_element_map().

Parameters
nameThe character name of the requested attribute.
mapThe JSON object map to use for the lookup.
bufThe buffer where the given element will be stored if found.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 311 of file mod.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mod_build_api_opts()

int mod_build_api_opts ( CONF_SECTION conf,
rlm_couchbase_t inst 
)

Build a couchbase_opts_t structure from the configuration "couchbase_api" list.

Parse the "couchbase_api" list from the module configuration file and store this as a couchbase_opts_t object (key/value list).

Parameters
confConfiguration list.
instThe module instance.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 93 of file mod.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mod_build_attribute_element_map()

int mod_build_attribute_element_map ( CONF_SECTION conf,
rlm_couchbase_t inst 
)

Build a JSON object map from the configuration "map" list.

Parse the "map" list from the module configuration file and store this as a JSON object (key/value list) in the module instance. This map will be used to lookup and map attributes for all incoming accounting requests.

Parameters
confConfiguration list.
instThe module instance.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 237 of file mod.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mod_conn_alive()

int mod_conn_alive ( UNUSED void *  opaque,
void *  connection 
)

Check the health of a connection handle.

Attempt to determine the state of the Couchbase connection by requesting a cluster statistics report. Mark the connection as failed if the request returns anything other than success.

Parameters
opaqueThe module instance (currently unused).
connectionThe connection handle.
Returns
  • 0 on success (alive).
  • -1 on failure (unavailable).

Definition at line 208 of file mod.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mod_conn_create()

void* mod_conn_create ( TALLOC_CTX *  ctx,
void *  instance,
fr_time_delta_t  timeout 
)

Create a new connection pool handle.

Create a new connection to Couchbase within the pool and initialize information associated with the connection instance.

Parameters
ctxThe connection parent context.
instanceThe module instance.
timeoutMaximum time to establish the connection.
Returns
  • New connection handle.
  • NULL on error.

Definition at line 154 of file mod.c.

+ Here is the call graph for this function:

◆ mod_ensure_start_timestamp()

int mod_ensure_start_timestamp ( json_object *  json,
fr_pair_list_t vps 
)

Ensure accounting documents always contain a valid timestamp.

Inspect the given JSON object representation of an accounting document fetched from Couchbase and ensuse it contains a valid (non NULL) timestamp value.

Parameters
jsonJSON object representation of an accounting document.
vpsThe value pairs associated with the current accounting request.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 604 of file mod.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mod_free_api_opts()

int mod_free_api_opts ( rlm_couchbase_t inst)

Delete a object built by mod_build_api_opts()

Release the underlying mod_build_api_opts() objects

Parameters
instThe module instance.
Returns
0.

Definition at line 63 of file mod.c.

+ Here is the caller graph for this function:

◆ mod_json_object_to_map()

int mod_json_object_to_map ( TALLOC_CTX *  ctx,
fr_dcursor_t out,
request_t request,
json_object *  json,
fr_dict_attr_t const *  list 
)

Build value pairs from the passed JSON object and add to the request.

Parse the passed JSON object and create value pairs that will be injected into the given request for authorization.

Example JSON document structure:

{
"docType": "raduser",
"userName": "test",
"control": {
"SHA-Password": {
"value": "a94a8fe5ccb19ba61c4c0873d391e987982fbbd3",
"op": ":="
}
},
"reply": {
"Reply-Message": {
"value": "Hidey Ho!",
"op": "="
}
}
}
Parameters
[in]ctxto allocate maps in.
[in]outCursor to append maps to.
[in]requestThe request to which the generated pairs should be added.
[in]jsonThe JSON object representation of the user document.
[in]listThe pair list fr_request_attr_control or fr_request_attr_reply
Returns
  • 1 if no section found.
  • 0 on success.
  • <0 on error.

Definition at line 373 of file mod.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mod_load_client_documents()

int mod_load_client_documents ( rlm_couchbase_t inst,
CONF_SECTION tmpl,
CONF_SECTION map 
)

Load client entries from Couchbase client documents on startup.

This function executes the view defined in the module configuration and loops through all returned rows. The view is called with "stale=false" to ensure the most accurate data available when the view is called. This will force an index rebuild on this design document in Couchbase. However, since this function is only run once at server startup this should not be a concern.

Parameters
instThe module instance.
tmplDefault values for new clients.
mapThe client attribute configuration list.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 706 of file mod.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mod_value_pair_to_json_object()

json_object* mod_value_pair_to_json_object ( request_t request,
fr_pair_t vp 
)

Convert value pairs to json objects.

Take the passed value pair and convert it to a json-c JSON object..

Parameters
requestThe request object.
vpThe value pair to convert.
Returns
A JSON object.

Definition at line 510 of file mod.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function: