All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
rlm_sql.h File Reference

Prototypes and functions for the SQL module. More...

#include <freeradius-devel/radiusd.h>
#include <freeradius-devel/connection.h>
#include <freeradius-devel/modpriv.h>
#include <freeradius-devel/exfile.h>
+ Include dependency graph for rlm_sql.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  rlm_sql_handle
 
struct  rlm_sql_module_t
 
struct  sql_acct_section
 
struct  sql_config
 
struct  sql_grouplist
 
struct  sql_inst
 
struct  sql_log_entry
 

Macros

#define MOD_PREFIX   "rlm_sql"
 
#define PW_ITEM_CHECK   0
 
#define PW_ITEM_REPLY   1
 
#define RLM_SQL_RCODE_FLAGS_ALT_QUERY   1
 Can distinguish between other errors and those. More...
 

Typedefs

typedef struct sql_config rlm_sql_config_t
 
typedef struct sql_grouplist rlm_sql_grouplist_t
 
typedef struct rlm_sql_handle rlm_sql_handle_t
 
typedef struct rlm_sql_module_t rlm_sql_module_t
 
typedef char ** rlm_sql_row_t
 
typedef struct sql_inst rlm_sql_t
 
typedef struct sql_acct_section sql_acct_section_t
 
typedef size_t(* sql_error_t )(TALLOC_CTX *ctx, sql_log_entry_t out[], size_t outlen, rlm_sql_handle_t *handle, rlm_sql_config_t *config)
 Retrieve errors from the last query operation. More...
 
typedef struct sql_log_entry sql_log_entry_t
 

Enumerations

enum  sql_fall_through_t {
  FALL_THROUGH_DEFAULT = 0,
  FALL_THROUGH_YES,
  FALL_THROUGH_NO
}
 
enum  sql_rcode_t {
  RLM_SQL_QUERY_INVALID = -3,
  RLM_SQL_ERROR = -2,
  RLM_SQL_OK = 0,
  RLM_SQL_RECONNECT = 1,
  RLM_SQL_ALT_QUERY = 2
}
 

Functions

void * mod_conn_create (TALLOC_CTX *ctx, void *instance, struct timeval const *timeout)
 Create a new connection pool handle. More...
 
void sql_rcode_t sql_rcode_t int rlm_sql_fetch_row (rlm_sql_row_t *out, rlm_sql_t const *inst, REQUEST *request, rlm_sql_handle_t **handle)
 Call the driver's sql_fetch_row function. More...
 
void rlm_sql_print_error (rlm_sql_t const *inst, REQUEST *request, rlm_sql_handle_t *handle, bool force_debug)
 Retrieve any errors from the SQL driver. More...
 
void sql_rcode_t sql_rcode_t rlm_sql_query (rlm_sql_t const *inst, REQUEST *request, rlm_sql_handle_t **handle, char const *query) CC_HINT(nonnull(1
 
void rlm_sql_query_log (rlm_sql_t const *inst, REQUEST *request, sql_acct_section_t *section, char const *query) CC_HINT(nonnull(1
 
void sql_rcode_t rlm_sql_select_query (rlm_sql_t const *inst, REQUEST *request, rlm_sql_handle_t **handle, char const *query) CC_HINT(nonnull(1
 
int sql_dict_init (rlm_sql_handle_t *handle)
 
int sql_fr_pair_list_afrom_str (TALLOC_CTX *ctx, REQUEST *request, VALUE_PAIR **first_pair, rlm_sql_row_t row)
 
int sql_getvpdata (TALLOC_CTX *ctx, rlm_sql_t const *inst, REQUEST *request, rlm_sql_handle_t **handle, VALUE_PAIR **pair, char const *query)
 
int sql_read_clients (rlm_sql_handle_t *handle)
 
int sql_read_realms (rlm_sql_handle_t *handle)
 
int sql_set_user (rlm_sql_t const *inst, REQUEST *request, char const *username)
 

Variables

const FR_NAME_NUMBER sql_rcode_table []
 

Detailed Description

Prototypes and functions for the SQL module.

Id:
13b4a3a66c289a94edb054d77b56aa855577cb3b

Definition in file rlm_sql.h.


Data Structure Documentation

struct rlm_sql_handle

Definition at line 152 of file rlm_sql.h.

+ Collaboration diagram for rlm_sql_handle:
Data Fields
void * conn Database specific connection handle.
rlm_sql_t * inst The rlm_sql instance this connection belongs to.
TALLOC_CTX * log_ctx Talloc pool used to avoid mallocing memory on when log strings need to be copied.
rlm_sql_row_t row Row data from the last query.
struct sql_acct_section

Definition at line 70 of file rlm_sql.h.

+ Collaboration diagram for sql_acct_section:
Data Fields
CONF_SECTION * cs The CONF_SECTION representing the group of queries to process.
char const * logfile
char const ** query
char const * reference Reference string, expanded to point to a group of queries.
bool reference_cp
struct sql_config

Definition at line 83 of file rlm_sql.h.

+ Collaboration diagram for sql_config:
Data Fields
sql_acct_section_t accounting
char const * allowed_chars Chars which done need escaping..
char const * authorize_check_query Query used get check VPs for a user.
char const * authorize_group_check_query Query used get check VPs for a group.
char const * authorize_group_reply_query Query used get reply VPs for a group.
char const * authorize_reply_query Query used get reply VPs for a user.
char const * client_query Query used to get FreeRADIUS client definitions.
char const * connect_query Query executed after establishing new connection.
char const * default_profile Default profile to use if no other profiles were configured.
bool delete_stale_sessions Whether we should use session_zap to create a fake stop packet, to terminate any stale sessions.
bool do_clients Read clients from SQL database.
void * driver Where drivers should write a pointer to their configurations.
char const * group_attribute Name of the group attribute.
char const * groupmemb_query Query to determine group membership.
char const * logfile Keep a log of all SQL queries executed Useful for batch insertion with the NULL drivers.
sql_acct_section_t postauth
uint32_t query_timeout How long to allow queries to run for.
char const * query_user xlat expansion used to specify the user to use as the subject of queries.
bool read_groups Read user groups by default.

If false, Fall-Through = yes is required in the previous reply list to process groups.

bool read_profiles Read user profiles by default.

If false, Fall-Through = yes is required in the previous reply list to process profiles.

char const * simul_count_query Query used get number of active sessions for a user (basic simultaneous use check).
char const * simul_verify_query Query to get active sessions for a user the result is fed to session_zap.
char const * sql_db Database to run queries against.
char const * sql_driver_name SQL driver module name e.g. rlm_sql_sqlite.
char const * sql_login Login credentials to use.
char const * sql_password Login password to use.
uint32_t sql_port Port to connect to.
char const * sql_server Server to connect to.
struct sql_grouplist

Definition at line 241 of file rlm_sql.h.

+ Collaboration diagram for sql_grouplist:
Data Fields
char * name
struct sql_grouplist * next
struct sql_log_entry

Definition at line 61 of file rlm_sql.h.

Data Fields
char const * msg Log message.
log_type_t type Type of log entry L_ERR, L_WARN, L_INFO, L_DBG etc..

Macro Definition Documentation

#define MOD_PREFIX   "rlm_sql"

Definition at line 37 of file rlm_sql.h.

#define PW_ITEM_CHECK   0

Definition at line 39 of file rlm_sql.h.

#define PW_ITEM_REPLY   1

Definition at line 40 of file rlm_sql.h.

#define RLM_SQL_RCODE_FLAGS_ALT_QUERY   1

Can distinguish between other errors and those.

resulting from a unique key violation.

Definition at line 164 of file rlm_sql.h.

Typedef Documentation

typedef struct sql_config rlm_sql_config_t
typedef char** rlm_sql_row_t

Definition at line 59 of file rlm_sql.h.

typedef struct sql_inst rlm_sql_t

Definition at line 150 of file rlm_sql.h.

typedef size_t(* sql_error_t)(TALLOC_CTX *ctx, sql_log_entry_t out[], size_t outlen, rlm_sql_handle_t *handle, rlm_sql_config_t *config)

Retrieve errors from the last query operation.

Note
Buffers allocated in the context provided will be automatically freed. The driver should not free these buffers explicitly.
If the driver uses its own buffers to aggregate messages, they should be cleared on sql_query_finish, and after each call to sql_error, to prevent the same messages being printed multiple times.
Parameters
[in,out]ctxto allocate any buffers required. If static buffers are provided by the driver they need not be strduped, just write the pointer to those buffers to the .msg field of a sql_log_entry_t element.
[out]outa pre-allocated array of log entries to fill. Need not be NULL terminated.
[in]outlenNumber of log entries available for populating. Do not write to index out[outlen] or higher.
[in]handleto retrieve errors from.
[in]configof the SQL instance.
Returns
0 - If no error messages are available. >0 - Number of log entries

Definition at line 187 of file rlm_sql.h.

Enumeration Type Documentation

Enumerator
FALL_THROUGH_DEFAULT 
FALL_THROUGH_YES 
FALL_THROUGH_NO 

Definition at line 52 of file rlm_sql.h.

Enumerator
RLM_SQL_QUERY_INVALID 

Query syntax error.

RLM_SQL_ERROR 

General connection/server error.

RLM_SQL_OK 

Success.

RLM_SQL_RECONNECT 

Stale connection, should reconnect.

RLM_SQL_ALT_QUERY 

Key constraint violation.

Definition at line 44 of file rlm_sql.h.

Function Documentation

void* mod_conn_create ( TALLOC_CTX *  ctx,
void *  instance,
struct timeval const *  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.

Create a new connection pool handle.

Create a new ldap connection and allocate memory for a new rlm_handle_t

Create a new connection pool handle.

Matches the fr_connection_create_t function prototype, is passed to fr_connection_pool_init, and called when a new connection is required by the connection pool API.

Creates an instances of rlm_rest_handle_t, and rlm_rest_curl_context_t which hold the context data required for generating requests and parsing responses.

If instance->connect_uri is not NULL libcurl will attempt to open a TCP socket to the server specified in the URI. This is done so that when the socket is first used, there will already be a cached TCP connection to the REST server associated with the curl handle.

See Also
fr_connection_pool_init
fr_connection_create_t
connection.c

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.

Create a new connection pool handle.

Create a new ldap connection and allocate memory for a new rlm_handle_t

Create a new connection pool handle.

Matches the fr_connection_create_t function prototype, is passed to fr_connection_pool_init, and called when a new connection is required by the connection pool API.

Creates an instances of rlm_rest_handle_t, and rlm_rest_curl_context_t which hold the context data required for generating requests and parsing responses.

If instance->connect_uri is not NULL libcurl will attempt to open a TCP socket to the server specified in the URI. This is done so that when the socket is first used, there will already be a cached TCP connection to the REST server associated with the curl handle.

See Also
fr_connection_pool_init
fr_connection_create_t
connection.c

Definition at line 68 of file mod.c.

+ Here is the call graph for this function:

void sql_rcode_t sql_rcode_t int rlm_sql_fetch_row ( rlm_sql_row_t out,
rlm_sql_t const *  inst,
REQUEST request,
rlm_sql_handle_t **  handle 
)

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 (*handle)->row.

Parameters
outWhere to write row data.
instInstance of rlm_sql_t.
requestThe Current request, may be NULL.
handleHandle to retrieve errors for.
Returns

Definition at line 249 of file sql.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void rlm_sql_print_error ( rlm_sql_t const *  inst,
REQUEST request,
rlm_sql_handle_t handle,
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.
handleHandle to retrieve errors for.
force_debugForce all errors to be logged as debug messages.

Definition at line 280 of file sql.c.

+ Here is the caller graph for this function:

void sql_rcode_t sql_rcode_t rlm_sql_query ( rlm_sql_t const *  inst,
REQUEST request,
rlm_sql_handle_t **  handle,
char const *  query 
)

+ Here is the caller graph for this function:

void rlm_sql_query_log ( rlm_sql_t const *  inst,
REQUEST request,
sql_acct_section_t section,
char const *  query 
)

+ Here is the caller graph for this function:

void sql_rcode_t rlm_sql_select_query ( rlm_sql_t const *  inst,
REQUEST request,
rlm_sql_handle_t **  handle,
char const *  query 
)

+ Here is the caller graph for this function:

int sql_dict_init ( rlm_sql_handle_t handle)
int sql_fr_pair_list_afrom_str ( TALLOC_CTX *  ctx,
REQUEST request,
VALUE_PAIR **  first_pair,
rlm_sql_row_t  row 
)

Definition at line 128 of file sql.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int sql_getvpdata ( TALLOC_CTX *  ctx,
rlm_sql_t const *  inst,
REQUEST request,
rlm_sql_handle_t **  handle,
VALUE_PAIR **  pair,
char const *  query 
)

Definition at line 504 of file sql.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int sql_read_clients ( rlm_sql_handle_t handle)
int sql_read_realms ( rlm_sql_handle_t handle)
int sql_set_user ( rlm_sql_t const *  inst,
REQUEST request,
char const *  username 
)

Definition at line 641 of file rlm_sql.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Variable Documentation

const FR_NAME_NUMBER sql_rcode_table[]

Definition at line 46 of file sql.c.