The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Macros | Functions | Variables
sql.c File Reference
#include <freeradius-devel/server/base.h>
#include <freeradius-devel/util/debug.h>
#include <sys/file.h>
#include <sys/stat.h>
#include <ctype.h>
#include "rlm_sql.h"
+ Include dependency graph for sql.c:

Go to the source code of this file.

Macros

#define LOG_PREFIX   inst->name
 

Functions

fr_sql_query_tfr_sql_query_alloc (TALLOC_CTX *ctx, rlm_sql_t const *inst, request_t *request, rlm_sql_handle_t *handle, trunk_t *trunk, char const *query_str, fr_sql_query_type_t type)
 Allocate an sql query structure. More...
 
static int fr_sql_query_free (fr_sql_query_t *to_free)
 Automatically run the correct finish function when freeing an SQL query. More...
 
unlang_action_t rlm_sql_fetch_row (rlm_rcode_t *p_result, UNUSED int *priority, request_t *request, void *uctx)
 Call the driver's sql_fetch_row function. More...
 
void rlm_sql_print_error (rlm_sql_t const *inst, request_t *request, fr_sql_query_t *query_ctx, bool force_debug)
 Retrieve any errors from the SQL driver. More...
 
unlang_action_t rlm_sql_query (rlm_rcode_t *p_result, UNUSED int *priority, request_t *request, void *uctx)
 Call the driver's sql_query method, reconnecting if necessary. More...
 
void rlm_sql_query_log (rlm_sql_t const *inst, char const *filename, char const *query)
 
unlang_action_t rlm_sql_select_query (rlm_rcode_t *p_result, UNUSED int *priority, request_t *request, void *uctx)
 Call the driver's sql_select_query method, reconnecting if necessary. More...
 
unlang_action_t rlm_sql_trunk_query (rlm_rcode_t *p_result, UNUSED int *priority, request_t *request, void *uctx)
 Submit an SQL query using a trunk connection. More...
 
unlang_action_t sql_get_map_list (request_t *request, fr_sql_map_ctx_t *map_ctx, rlm_sql_handle_t **handle, trunk_t *trunk)
 Submit the query to get any user / group check or reply pairs. More...
 
static unlang_action_t sql_get_map_list_resume (rlm_rcode_t *p_result, UNUSED int *priority, request_t *request, void *uctx)
 Process the results of an SQL query to produce a map list. More...
 
void * sql_mod_conn_create (TALLOC_CTX *ctx, void *instance, fr_time_delta_t timeout)
 
static void sql_trunk_query_cancel (UNUSED request_t *request, UNUSED fr_signal_t action, void *uctx)
 Cancel an SQL query submitted on a trunk. More...
 
static unlang_action_t sql_trunk_query_start (UNUSED rlm_rcode_t *p_result, UNUSED int *priority, UNUSED request_t *request, UNUSED void *uctx)
 Yield processing after submitting a trunk request. More...
 

Variables

fr_table_num_sorted_t const sql_rcode_description_table []
 
size_t sql_rcode_description_table_len = NUM_ELEMENTS(sql_rcode_description_table)
 
fr_table_num_sorted_t const sql_rcode_table []
 
size_t sql_rcode_table_len = NUM_ELEMENTS(sql_rcode_table)
 

Macro Definition Documentation

◆ LOG_PREFIX

#define LOG_PREFIX   inst->name

Definition at line 29 of file sql.c.

Function Documentation

◆ fr_sql_query_alloc()

fr_sql_query_t* fr_sql_query_alloc ( TALLOC_CTX *  ctx,
rlm_sql_t const *  inst,
request_t request,
rlm_sql_handle_t handle,
trunk_t trunk,
char const *  query_str,
fr_sql_query_type_t  type 
)

Allocate an sql query structure.

Definition at line 413 of file sql.c.

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

◆ fr_sql_query_free()

static int fr_sql_query_free ( fr_sql_query_t to_free)
static

Automatically run the correct finish function when freeing an SQL query.

And mark any associated trunk request as complete.

Definition at line 397 of file sql.c.

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

◆ rlm_sql_fetch_row()

unlang_action_t rlm_sql_fetch_row ( rlm_rcode_t p_result,
UNUSED int *  priority,
request_t request,
void *  uctx 
)

Call the driver's sql_fetch_row function.

Calls the driver's sql_fetch_row logging any errors. On success, will write row data to uctx->row.

The rcode within the query context is updated to

Parameters
p_resultResult of current module call.
priorityUnused.
requestCurrent request.
uctxquery context containing query to execute.
Returns
an unlang_action_t.

Definition at line 308 of file sql.c.

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

◆ rlm_sql_print_error()

void rlm_sql_print_error ( rlm_sql_t const *  inst,
request_t request,
fr_sql_query_t query_ctx,
bool  force_debug 
)

Retrieve any errors from the SQL driver.

Retrieves errors from the driver from the last operation and writes them to to request/global log, in the ERROR, WARN, INFO and DEBUG categories.

Parameters
instInstance of rlm_sql.
requestCurrent request, may be NULL.
query_ctxQuery context to retrieve errors for.
force_debugForce all errors to be logged as debug messages.

Definition at line 352 of file sql.c.

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

◆ rlm_sql_query()

unlang_action_t rlm_sql_query ( rlm_rcode_t p_result,
UNUSED int *  priority,
request_t request,
void *  uctx 
)

Call the driver's sql_query method, reconnecting if necessary.

Note
Caller must call (inst->driver->sql_finish_query)(handle, &inst->config); after they're done with the result.

The rcode within the query context is updated to

Parameters
p_resultResult of current module call.
priorityUnused.
requestCurrent request.
uctxquery context containing query to execute.
Returns
an unlang_action_t.

Definition at line 447 of file sql.c.

+ Here is the call graph for this function:

◆ rlm_sql_query_log()

void rlm_sql_query_log ( rlm_sql_t const *  inst,
char const *  filename,
char const *  query 
)

Definition at line 774 of file sql.c.

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

◆ rlm_sql_select_query()

unlang_action_t rlm_sql_select_query ( rlm_rcode_t p_result,
UNUSED int *  priority,
request_t request,
void *  uctx 
)

Call the driver's sql_select_query method, reconnecting if necessary.

Note
Caller must call (inst->driver->sql_finish_select_query)(handle, &inst->config); after they're done with the result.

The rcode within the query context is updated to

Parameters
p_resultResult of current module call.
priorityUnused.
requestCurrent request.
uctxquery context containing query to execute.
Returns
an unlang_action_t.

Definition at line 646 of file sql.c.

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

◆ rlm_sql_trunk_query()

unlang_action_t rlm_sql_trunk_query ( rlm_rcode_t p_result,
UNUSED int *  priority,
request_t request,
void *  uctx 
)

Submit an SQL query using a trunk connection.

Parameters
p_resultResult of current module call.
priorityUnused.
requestCurrent request.
uctxquery context containing query to execute.
Returns
an unlang_action_t.

Definition at line 572 of file sql.c.

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

◆ sql_get_map_list()

unlang_action_t sql_get_map_list ( request_t request,
fr_sql_map_ctx_t map_ctx,
rlm_sql_handle_t **  handle,
trunk_t trunk 
)

Submit the query to get any user / group check or reply pairs.

Definition at line 756 of file sql.c.

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

◆ sql_get_map_list_resume()

static unlang_action_t sql_get_map_list_resume ( rlm_rcode_t p_result,
UNUSED int *  priority,
request_t request,
void *  uctx 
)
static

Process the results of an SQL query to produce a map list.

Definition at line 709 of file sql.c.

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

◆ sql_mod_conn_create()

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

Definition at line 65 of file sql.c.

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

◆ sql_trunk_query_cancel()

static void sql_trunk_query_cancel ( UNUSED request_t request,
UNUSED fr_signal_t  action,
void *  uctx 
)
static

Cancel an SQL query submitted on a trunk.

Definition at line 547 of file sql.c.

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

◆ sql_trunk_query_start()

static unlang_action_t sql_trunk_query_start ( UNUSED rlm_rcode_t p_result,
UNUSED int *  priority,
UNUSED request_t request,
UNUSED void *  uctx 
)
static

Yield processing after submitting a trunk request.

Definition at line 539 of file sql.c.

+ Here is the caller graph for this function:

Variable Documentation

◆ sql_rcode_description_table

fr_table_num_sorted_t const sql_rcode_description_table[]
Initial value:
= {
{ L("need alt query"), RLM_SQL_ALT_QUERY },
{ L("no connection"), RLM_SQL_RECONNECT },
{ L("no more rows"), RLM_SQL_NO_MORE_ROWS },
{ L("query invalid"), RLM_SQL_QUERY_INVALID },
{ L("server error"), RLM_SQL_ERROR },
{ L("success"), RLM_SQL_OK }
}
#define L(_str)
Helper for initialising arrays of string literals.
Definition: build.h:207
@ RLM_SQL_QUERY_INVALID
Query syntax error.
Definition: rlm_sql.h:45
@ RLM_SQL_ALT_QUERY
Key constraint violation, use an alternative query.
Definition: rlm_sql.h:49
@ RLM_SQL_RECONNECT
Stale connection, should reconnect.
Definition: rlm_sql.h:48
@ RLM_SQL_ERROR
General connection/server error.
Definition: rlm_sql.h:46
@ RLM_SQL_OK
Success.
Definition: rlm_sql.h:47
@ RLM_SQL_NO_MORE_ROWS
No more rows available.
Definition: rlm_sql.h:50

Definition at line 45 of file sql.c.

◆ sql_rcode_description_table_len

size_t sql_rcode_description_table_len = NUM_ELEMENTS(sql_rcode_description_table)

Definition at line 53 of file sql.c.

◆ sql_rcode_table

fr_table_num_sorted_t const sql_rcode_table[]
Initial value:
= {
{ L("alternate"), RLM_SQL_ALT_QUERY },
{ L("empty"), RLM_SQL_NO_MORE_ROWS },
{ L("error"), RLM_SQL_ERROR },
{ L("invalid"), RLM_SQL_QUERY_INVALID },
{ L("ok"), RLM_SQL_OK },
{ L("reconnect"), RLM_SQL_RECONNECT }
}

Definition at line 55 of file sql.c.

◆ sql_rcode_table_len

size_t sql_rcode_table_len = NUM_ELEMENTS(sql_rcode_table)

Definition at line 63 of file sql.c.