The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Data Structures | Macros | Typedefs | Functions | Variables
rlm_sql_sqlite.c File Reference

SQLite driver. More...

#include <freeradius-devel/server/base.h>
#include <freeradius-devel/util/debug.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sqlite3.h>
#include "rlm_sql.h"
#include "rlm_sql_trunk.h"
#include "config.h"
+ Include dependency graph for rlm_sql_sqlite.c:

Go to the source code of this file.

Data Structures

struct  rlm_sql_sqlite_conn_t
 
struct  rlm_sql_sqlite_t
 

Macros

#define BOOTSTRAP_MAX   (1048576 * 10)
 
#define LOG_PREFIX   "sql - sqlite"
 
#define SQLITE_OPEN_NOMUTEX   0
 

Typedefs

typedef sqlite_int64 sqlite3_int64
 

Functions

static void _sql_connection_close (UNUSED fr_event_list_t *el, void *h, UNUSED void *uctx)
 
static void _sql_greatest (sqlite3_context *ctx, int num_values, sqlite3_value **values)
 
 CC_NO_UBSAN (function)
 
static int mod_instantiate (module_inst_ctx_t const *mctx)
 
static int mod_load (void)
 
static int sql_affected_rows (fr_sql_query_t *query_ctx, UNUSED rlm_sql_config_t const *config)
 
static sql_rcode_t sql_check_error (sqlite3 *db, int status)
 Determine if an error occurred, and what type of error it was. More...
 
static size_t sql_error (UNUSED TALLOC_CTX *ctx, sql_log_entry_t out[], NDEBUG_UNUSED size_t outlen, fr_sql_query_t *query_ctx)
 Retrieves any errors associated with the query context. More...
 
static sql_rcode_t sql_error_to_rcode (int status)
 Convert an sqlite status code to an sql_rcode_t. More...
 
static unlang_action_t sql_fetch_row (rlm_rcode_t *p_result, UNUSED int *priority, UNUSED request_t *request, void *uctx)
 
static sql_rcode_t sql_fields (char const **out[], fr_sql_query_t *query_ctx, UNUSED rlm_sql_config_t const *config)
 
static sql_rcode_t sql_finish_query (fr_sql_query_t *query_ctx, rlm_sql_config_t const *config)
 
static sql_rcode_t sql_free_result (fr_sql_query_t *query_ctx, UNUSED rlm_sql_config_t const *config)
 
static int sql_loadfile (TALLOC_CTX *ctx, sqlite3 *db, char const *filename)
 
static void sql_print_error (sqlite3 *db, int status, char const *fmt,...))
 Print an error to the global debug log. More...
 
static void sql_request_complete (UNUSED request_t *request, void *preq, UNUSED void *rctx, UNUSED void *uctx)
 
static SQL_QUERY_RESUME void sql_request_fail (UNUSED request_t *request, void *preq, UNUSED void *rctx, UNUSED trunk_request_state_t state, UNUSED void *uctx)
 

Variables

static const conf_parser_t driver_config []
 
rlm_sql_driver_t rlm_sql_sqlite
 

Detailed Description

SQLite driver.

Id
51cd8ff821b7cf12459aa663f263f9b9039355c4

Definition in file rlm_sql_sqlite.c.


Data Structure Documentation

◆ rlm_sql_sqlite_conn_t

struct rlm_sql_sqlite_conn_t

Definition at line 53 of file rlm_sql_sqlite.c.

Data Fields
int col_count
sqlite3 * db
sqlite3_stmt * statement

◆ rlm_sql_sqlite_t

struct rlm_sql_sqlite_t

Definition at line 59 of file rlm_sql_sqlite.c.

Data Fields
bool bootstrap
char const * filename

Macro Definition Documentation

◆ BOOTSTRAP_MAX

#define BOOTSTRAP_MAX   (1048576 * 10)

Definition at line 40 of file rlm_sql_sqlite.c.

◆ LOG_PREFIX

#define LOG_PREFIX   "sql - sqlite"

Definition at line 27 of file rlm_sql_sqlite.c.

◆ SQLITE_OPEN_NOMUTEX

#define SQLITE_OPEN_NOMUTEX   0

Definition at line 46 of file rlm_sql_sqlite.c.

Typedef Documentation

◆ sqlite3_int64

typedef sqlite_int64 sqlite3_int64

Definition at line 50 of file rlm_sql_sqlite.c.

Function Documentation

◆ _sql_connection_close()

static void _sql_connection_close ( UNUSED fr_event_list_t el,
void *  h,
UNUSED void *  uctx 
)
static

Definition at line 422 of file rlm_sql_sqlite.c.

◆ _sql_greatest()

static void _sql_greatest ( sqlite3_context *  ctx,
int  num_values,
sqlite3_value **  values 
)
static

Definition at line 357 of file rlm_sql_sqlite.c.

+ Here is the caller graph for this function:

◆ CC_NO_UBSAN()

CC_NO_UBSAN ( function  )

Definition at line 372 of file rlm_sql_sqlite.c.

+ Here is the call graph for this function:

◆ mod_instantiate()

static int mod_instantiate ( module_inst_ctx_t const *  mctx)
static

Definition at line 665 of file rlm_sql_sqlite.c.

+ Here is the call graph for this function:

◆ mod_load()

static int mod_load ( void  )
static

Definition at line 784 of file rlm_sql_sqlite.c.

◆ sql_affected_rows()

static int sql_affected_rows ( fr_sql_query_t query_ctx,
UNUSED rlm_sql_config_t const *  config 
)
static

Definition at line 597 of file rlm_sql_sqlite.c.

◆ sql_check_error()

static sql_rcode_t sql_check_error ( sqlite3 *  db,
int  status 
)
static

Determine if an error occurred, and what type of error it was.

Parameters
dbhandle to extract error from (may be NULL).
statusto check (if unused, set to SQLITE_OK).
Returns
  • RLM_SQL_OK - If no errors found.
  • RLM_SQL_ERROR - If a known, non-fatal, error occurred.
  • RLM_SQL_ALT_QUERY - If a constraints violation occurred.
  • RLM_SQL_RECONNECT - Anything else. We assume the connection can no longer be used.

Definition at line 125 of file rlm_sql_sqlite.c.

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

◆ sql_error()

static size_t sql_error ( UNUSED TALLOC_CTX *  ctx,
sql_log_entry_t  out[],
NDEBUG_UNUSED size_t  outlen,
fr_sql_query_t query_ctx 
)
static

Retrieves any errors associated with the query context.

Note
Caller will free any memory allocated in ctx.
Parameters
ctxto allocate temporary error buffers in.
outArray of sql_log_entrys to fill.
outlenLength of out array.
query_ctxQuery context to retrieve error for.
configrlm_sql config.
Returns
number of errors written to the sql_log_entry_t array.

Definition at line 575 of file rlm_sql_sqlite.c.

+ Here is the call graph for this function:

◆ sql_error_to_rcode()

static sql_rcode_t sql_error_to_rcode ( int  status)
static

Convert an sqlite status code to an sql_rcode_t.

Parameters
statusto convert.
Returns
  • RLM_SQL_OK - If no errors found.
  • RLM_SQL_ERROR - If a known, non-fatal, error occurred.
  • RLM_SQL_ALT_QUERY - If a constraints violation occurred.
  • RLM_SQL_RECONNECT - Anything else, we assume the connection can no longer be used.

Definition at line 78 of file rlm_sql_sqlite.c.

+ Here is the caller graph for this function:

◆ sql_fetch_row()

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

Definition at line 454 of file rlm_sql_sqlite.c.

+ Here is the call graph for this function:

◆ sql_fields()

static sql_rcode_t sql_fields ( char const **  out[],
fr_sql_query_t query_ctx,
UNUSED rlm_sql_config_t const *  config 
)
static

Definition at line 436 of file rlm_sql_sqlite.c.

+ Here is the call graph for this function:

◆ sql_finish_query()

static sql_rcode_t sql_finish_query ( fr_sql_query_t query_ctx,
rlm_sql_config_t const *  config 
)
static

Definition at line 592 of file rlm_sql_sqlite.c.

+ Here is the call graph for this function:

◆ sql_free_result()

static sql_rcode_t sql_free_result ( fr_sql_query_t query_ctx,
UNUSED rlm_sql_config_t const *  config 
)
static

Definition at line 542 of file rlm_sql_sqlite.c.

+ Here is the caller graph for this function:

◆ sql_loadfile()

static int sql_loadfile ( TALLOC_CTX *  ctx,
sqlite3 *  db,
char const *  filename 
)
static

Definition at line 228 of file rlm_sql_sqlite.c.

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

◆ sql_print_error()

static void sql_print_error ( sqlite3 *  db,
int  status,
char const *  fmt,
  ... 
)
static

Print an error to the global debug log.

If status does not indicate success, write an error to the global error log.

Note
The error code will be appended to the fmt string in the format ": code 0x<hex> (<int>)[: <string>]".
Parameters
dbhandle to extract error from (may be NULL).
statusto check (if unused, set to SQLITE_OK).
fmtto prepend.
...arguments to fmt.

Definition at line 173 of file rlm_sql_sqlite.c.

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

◆ sql_request_complete()

static void sql_request_complete ( UNUSED request_t request,
void *  preq,
UNUSED void *  rctx,
UNUSED void *  uctx 
)
static

Definition at line 658 of file rlm_sql_sqlite.c.

+ Here is the call graph for this function:

◆ sql_request_fail()

static SQL_QUERY_RESUME void sql_request_fail ( UNUSED request_t request,
void *  preq,
UNUSED void *  rctx,
UNUSED trunk_request_state_t  state,
UNUSED void *  uctx 
)
static

Definition at line 649 of file rlm_sql_sqlite.c.

Variable Documentation

◆ driver_config

const conf_parser_t driver_config[]
static
Initial value:
= {
}
#define CONF_PARSER_TERMINATOR
Definition: cf_parse.h:627
#define FR_CONF_OFFSET_FLAGS(_name, _flags, _struct, _field)
conf_parser_t which parses a single CONF_PAIR, writing the result to a field in a struct
Definition: cf_parse.h:256
@ CONF_FLAG_REQUIRED
Error out if no matching CONF_PAIR is found, and no dflt value is set.
Definition: cf_parse.h:405
@ CONF_FLAG_FILE_OUTPUT
File matching value must exist, and must be writable.
Definition: cf_parse.h:413

Definition at line 64 of file rlm_sql_sqlite.c.

◆ rlm_sql_sqlite

rlm_sql_driver_t rlm_sql_sqlite
Initial value:
= {
.common = {
.name = "sql_sqlite",
.inst_size = sizeof(rlm_sql_sqlite_t),
.onload = mod_load,
},
.sql_query_resume = sql_query_resume,
.sql_select_query_resume = sql_query_resume,
.sql_affected_rows = sql_affected_rows,
.sql_fetch_row = sql_fetch_row,
.sql_fields = sql_fields,
.sql_free_result = sql_free_result,
.sql_error = sql_error,
.sql_finish_query = sql_finish_query,
.sql_finish_select_query = sql_finish_query,
.uses_trunks = true,
.trunk_io_funcs = {
.connection_alloc = sql_trunk_connection_alloc,
.request_mux = sql_trunk_request_mux,
.request_complete = sql_request_complete,
.request_fail = sql_request_fail
}
}
#define MODULE_MAGIC_INIT
Stop people using different module/library/server versions together.
Definition: dl_module.h:63
static const conf_parser_t config[]
Definition: base.c:183
static int instantiate(module_inst_ctx_t const *mctx)
Definition: rlm_rest.c:1302
#define RLM_SQL_RCODE_FLAGS_ALT_QUERY
Can distinguish between other errors and those.
Definition: rlm_sql.h:172
static void sql_request_complete(UNUSED request_t *request, void *preq, UNUSED void *rctx, UNUSED void *uctx)
static size_t sql_error(UNUSED TALLOC_CTX *ctx, sql_log_entry_t out[], NDEBUG_UNUSED size_t outlen, fr_sql_query_t *query_ctx)
Retrieves any errors associated with the query context.
static int mod_load(void)
static sql_rcode_t sql_fields(char const **out[], fr_sql_query_t *query_ctx, UNUSED rlm_sql_config_t const *config)
static unlang_action_t sql_fetch_row(rlm_rcode_t *p_result, UNUSED int *priority, UNUSED request_t *request, void *uctx)
static const conf_parser_t driver_config[]
static SQL_QUERY_RESUME void sql_request_fail(UNUSED request_t *request, void *preq, UNUSED void *rctx, UNUSED trunk_request_state_t state, UNUSED void *uctx)
static sql_rcode_t sql_finish_query(fr_sql_query_t *query_ctx, rlm_sql_config_t const *config)
static sql_rcode_t sql_free_result(fr_sql_query_t *query_ctx, UNUSED rlm_sql_config_t const *config)
static int sql_affected_rows(fr_sql_query_t *query_ctx, UNUSED rlm_sql_config_t const *config)
static int mod_instantiate(module_inst_ctx_t const *mctx)

Definition at line 797 of file rlm_sql_sqlite.c.