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

MySQL driver. More...

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

Go to the source code of this file.

Data Structures

struct  rlm_sql_mysql_conn_t
 
struct  rlm_sql_mysql_t
 

Macros

#define LOG_PREFIX   log_prefix
 
#define LOG_PREFIX   "rlm_sql_mysql"
 
#define LOG_PREFIX   log_prefix
 

Enumerations

enum  rlm_sql_mysql_warnings {
  SERVER_WARNINGS_AUTO = 0 ,
  SERVER_WARNINGS_YES ,
  SERVER_WARNINGS_NO
}
 

Functions

static void _sql_connect_io_notify (fr_event_list_t *el, int fd, UNUSED int flags, void *uctx)
 Callback for I/O events in response to mysql_real_connect_start() More...
 
static void _sql_connect_query_run (connection_t *conn, UNUSED connection_state_t prev, UNUSED connection_state_t state, void *uctx)
 
static void _sql_connection_close (fr_event_list_t *el, void *h, UNUSED void *uctx)
 
 CC_NO_UBSAN (function)
 
static int mod_instantiate (module_inst_ctx_t const *mctx)
 
static int mod_load (void)
 
static void mod_unload (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 (MYSQL *server, int client_errno)
 Analyse the last error that occurred on the socket, and determine an action. More...
 
static size_t sql_error (TALLOC_CTX *ctx, sql_log_entry_t out[], size_t outlen, fr_sql_query_t *query_ctx)
 Retrieves any errors associated with the query context. More...
 
static void * sql_escape_arg_alloc (TALLOC_CTX *ctx, fr_event_list_t *el, void *uctx)
 Allocate the argument used for the SQL escape function. More...
 
static void sql_escape_arg_free (void *uctx)
 
static ssize_t sql_escape_func (request_t *request, char *out, size_t outlen, char const *in, void *arg)
 
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)
 Finish query. More...
 
static sql_rcode_t sql_free_result (fr_sql_query_t *, rlm_sql_config_t const *)
 
static sql_rcode_t sql_free_result (fr_sql_query_t *query_ctx, UNUSED rlm_sql_config_t const *config)
 
static int sql_num_rows (fr_sql_query_t *query_ctx, UNUSED rlm_sql_config_t const *config)
 
SQL_QUERY_FAIL static SQL_QUERY_RESUME unlang_action_t sql_select_query_resume (rlm_rcode_t *p_result, UNUSED int *priority, UNUSED request_t *request, void *uctx)
 
static sql_rcode_t sql_store_result (rlm_sql_mysql_conn_t *conn, UNUSED rlm_sql_config_t const *config)
 
static size_t sql_warnings (TALLOC_CTX *ctx, sql_log_entry_t out[], size_t outlen, rlm_sql_mysql_conn_t *conn)
 Retrieves any warnings associated with the last query. More...
 

Variables

static const conf_parser_t driver_config []
 
rlm_sql_driver_t rlm_sql_mysql
 
static fr_table_num_sorted_t const server_warnings_table []
 
static size_t server_warnings_table_len = NUM_ELEMENTS(server_warnings_table)
 
static conf_parser_t tls_config []
 

Detailed Description

MySQL driver.

Id
3920a7af012a0bf141e30ff305369e4b7aaf7b6b

Definition in file rlm_sql_mysql.c.


Data Structure Documentation

◆ rlm_sql_mysql_conn_t

struct rlm_sql_mysql_conn_t

Definition at line 68 of file rlm_sql_mysql.c.

+ Collaboration diagram for rlm_sql_mysql_conn_t:
Data Fields
connection_t * conn Generic connection structure for this connection.
MYSQL db Structure representing connection details.
int fd fd for this connection's I/O events.
fr_sql_query_t * query_ctx Current query running on this connection.
MYSQL_RES * result Result from most recent query.
MYSQL * sock Connection details as returned by connection init functions.
int status returned by the most recent non-blocking function call.

◆ rlm_sql_mysql_t

struct rlm_sql_mysql_t

Definition at line 78 of file rlm_sql_mysql.c.

Data Fields
char const * character_set Character set to use on connections.
char const * tls_ca_file Path to the CA used to validate the server's certificate.
char const * tls_ca_path Directory containing CAs that may be used to validate the servers certificate.
char const * tls_certificate_file Public certificate we present to the server.
bool tls_check_cert Verify there's a trust relationship between the server's cert and one of the CAs we have configured.
bool tls_check_cert_cn Verify that the CN in the server cert matches the host we passed to mysql_real_connect().
char const * tls_cipher Colon separated list of TLS ciphers for TLS <= 1.2.
char const * tls_crl_file Public certificate we present to the server.
char const * tls_crl_path Private key for the certificate we present to the server.
char const * tls_private_key_file Private key for the certificate we present to the server.
bool tls_required Require that the connection is encrypted.
rlm_sql_mysql_warnings warnings mysql_warning_count() doesn't appear to work with NDB cluster
char const * warnings_str Whether we always query the server for additional warnings.

Macro Definition Documentation

◆ LOG_PREFIX [1/3]

#define LOG_PREFIX   log_prefix

Definition at line 881 of file rlm_sql_mysql.c.

◆ LOG_PREFIX [2/3]

#define LOG_PREFIX   "rlm_sql_mysql"

Definition at line 881 of file rlm_sql_mysql.c.

◆ LOG_PREFIX [3/3]

#define LOG_PREFIX   log_prefix

Definition at line 881 of file rlm_sql_mysql.c.

Enumeration Type Documentation

◆ rlm_sql_mysql_warnings

Enumerator
SERVER_WARNINGS_AUTO 
SERVER_WARNINGS_YES 
SERVER_WARNINGS_NO 

Definition at line 55 of file rlm_sql_mysql.c.

Function Documentation

◆ _sql_connect_io_notify()

static void _sql_connect_io_notify ( fr_event_list_t el,
int  fd,
UNUSED int  flags,
void *  uctx 
)
static

Callback for I/O events in response to mysql_real_connect_start()

Definition at line 192 of file rlm_sql_mysql.c.

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

◆ _sql_connect_query_run()

static void _sql_connect_query_run ( connection_t conn,
UNUSED connection_state_t  prev,
UNUSED connection_state_t  state,
void *  uctx 
)
static

Definition at line 227 of file rlm_sql_mysql.c.

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

◆ _sql_connection_close()

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

Definition at line 389 of file rlm_sql_mysql.c.

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

◆ CC_NO_UBSAN()

CC_NO_UBSAN ( function  )

Definition at line 259 of file rlm_sql_mysql.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 140 of file rlm_sql_mysql.c.

◆ mod_load()

static int mod_load ( void  )
static

Definition at line 176 of file rlm_sql_mysql.c.

◆ mod_unload()

static void mod_unload ( void  )
static

Definition at line 171 of file rlm_sql_mysql.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 843 of file rlm_sql_mysql.c.

◆ sql_check_error()

static sql_rcode_t sql_check_error ( MYSQL *  server,
int  client_errno 
)
static

Analyse the last error that occurred on the socket, and determine an action.

Parameters
serverSocket from which to extract the server error. May be NULL.
client_errnoError from the client.
Returns
an action for rlm_sql_t to take.

Definition at line 408 of file rlm_sql_mysql.c.

+ Here is the caller graph for this function:

◆ sql_error()

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

Retrieves any errors associated with the query context.

Note
Caller should free any memory allocated in ctx (talloc_free_children()).
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 701 of file rlm_sql_mysql.c.

+ Here is the call graph for this function:

◆ sql_escape_arg_alloc()

static void* sql_escape_arg_alloc ( TALLOC_CTX *  ctx,
fr_event_list_t el,
void *  uctx 
)
static

Allocate the argument used for the SQL escape function.

In this case, a dedicated connection to allow the escape function to have access to server side parameters, though no packets ever flow after the connection is made.

Definition at line 1110 of file rlm_sql_mysql.c.

+ Here is the call graph for this function:

◆ sql_escape_arg_free()

static void sql_escape_arg_free ( void *  uctx)
static

Definition at line 1133 of file rlm_sql_mysql.c.

+ Here is the call graph for this function:

◆ sql_escape_func()

static ssize_t sql_escape_func ( request_t request,
char *  out,
size_t  outlen,
char const *  in,
void *  arg 
)
static

Definition at line 850 of file rlm_sql_mysql.c.

◆ 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 539 of file rlm_sql_mysql.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 508 of file rlm_sql_mysql.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

Finish query.

As a single SQL statement may return multiple results sets, (for example stored procedures) it is necessary to check whether more results exist and process them in turn if so.

Definition at line 777 of file rlm_sql_mysql.c.

+ Here is the call graph for this function:

◆ sql_free_result() [1/2]

static sql_rcode_t sql_free_result ( fr_sql_query_t ,
rlm_sql_config_t const *   
)
static
+ Here is the caller graph for this function:

◆ sql_free_result() [2/2]

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

Definition at line 607 of file rlm_sql_mysql.c.

◆ sql_num_rows()

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

Definition at line 499 of file rlm_sql_mysql.c.

◆ sql_select_query_resume()

SQL_QUERY_FAIL static SQL_QUERY_RESUME unlang_action_t sql_select_query_resume ( rlm_rcode_t p_result,
UNUSED int *  priority,
UNUSED request_t request,
void *  uctx 
)
static

Definition at line 1084 of file rlm_sql_mysql.c.

+ Here is the call graph for this function:

◆ sql_store_result()

static sql_rcode_t sql_store_result ( rlm_sql_mysql_conn_t conn,
UNUSED rlm_sql_config_t const *  config 
)
static

Definition at line 479 of file rlm_sql_mysql.c.

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

◆ sql_warnings()

static size_t sql_warnings ( TALLOC_CTX *  ctx,
sql_log_entry_t  out[],
size_t  outlen,
rlm_sql_mysql_conn_t conn 
)
static

Retrieves any warnings associated with the last query.

MySQL stores a limited number of warnings associated with the last query executed. These can be very useful in diagnosing issues, or in some cases working around bugs in MySQL which causes it to return the wrong error.

Note
Caller should free any memory allocated in ctx (talloc_free_children()).
Parameters
ctxto allocate temporary error buffers in.
outArray of sql_log_entrys to fill.
outlenLength of out array.
connMySQL connection the query was run on.
configrlm_sql config.
Returns

Definition at line 637 of file rlm_sql_mysql.c.

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

Variable Documentation

◆ driver_config

const conf_parser_t driver_config[]
static
Initial value:
= {
{ FR_CONF_POINTER("tls", 0, CONF_FLAG_SUBSECTION, NULL), .subcs = (void const *) tls_config },
{ FR_CONF_OFFSET("warnings", rlm_sql_mysql_t, warnings_str), .dflt = "auto" },
{ FR_CONF_OFFSET("character_set", rlm_sql_mysql_t, character_set) },
}
#define CONF_PARSER_TERMINATOR
Definition: cf_parse.h:627
#define FR_CONF_OFFSET(_name, _struct, _field)
conf_parser_t which parses a single CONF_PAIR, writing the result to a field in a struct
Definition: cf_parse.h:268
#define FR_CONF_POINTER(_name, _type, _flags, _res_p)
conf_parser_t which parses a single CONF_PAIR producing a single global result
Definition: cf_parse.h:310
@ CONF_FLAG_SUBSECTION
Instead of putting the information into a configuration structure, the configuration file routines MA...
Definition: cf_parse.h:399
static conf_parser_t tls_config[]

Definition at line 129 of file rlm_sql_mysql.c.

◆ rlm_sql_mysql

rlm_sql_driver_t rlm_sql_mysql

Definition at line 1141 of file rlm_sql_mysql.c.

◆ server_warnings_table

fr_table_num_sorted_t const server_warnings_table[]
static
Initial value:
= {
{ L("auto"), SERVER_WARNINGS_AUTO },
{ L("no"), SERVER_WARNINGS_NO },
{ L("yes"), SERVER_WARNINGS_YES }
}
#define L(_str)
Helper for initialising arrays of string literals.
Definition: build.h:207
@ SERVER_WARNINGS_AUTO
Definition: rlm_sql_mysql.c:56
@ SERVER_WARNINGS_NO
Definition: rlm_sql_mysql.c:58
@ SERVER_WARNINGS_YES
Definition: rlm_sql_mysql.c:57

Definition at line 61 of file rlm_sql_mysql.c.

◆ server_warnings_table_len

size_t server_warnings_table_len = NUM_ELEMENTS(server_warnings_table)
static

Definition at line 66 of file rlm_sql_mysql.c.

◆ tls_config

conf_parser_t tls_config[]
static
Initial value:
= {
{ FR_CONF_OFFSET_FLAGS("certificate_file", CONF_FLAG_FILE_INPUT, rlm_sql_mysql_t, tls_certificate_file) },
{ FR_CONF_OFFSET_FLAGS("private_key_file", CONF_FLAG_FILE_INPUT, rlm_sql_mysql_t, tls_private_key_file) },
{ FR_CONF_OFFSET("cipher", rlm_sql_mysql_t, tls_cipher) },
{ FR_CONF_OFFSET("tls_required", rlm_sql_mysql_t, tls_required) },
{ FR_CONF_OFFSET("check_cert", rlm_sql_mysql_t, tls_check_cert) },
{ FR_CONF_OFFSET("check_cert_cn", rlm_sql_mysql_t, tls_check_cert_cn) },
}
#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_FILE_INPUT
File matching value must exist, and must be readable.
Definition: cf_parse.h:411

Definition at line 103 of file rlm_sql_mysql.c.