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

MySQL driver. More...

#include <freeradius-devel/radiusd.h>
#include <freeradius-devel/rad_assert.h>
#include <sys/stat.h>
#include "config.h"
#include "rlm_sql.h"
+ Include dependency graph for rlm_sql_mysql.c:

Go to the source code of this file.

Data Structures

struct  rlm_sql_mysql_config
 
struct  rlm_sql_mysql_conn
 

Typedefs

typedef struct rlm_sql_mysql_config rlm_sql_mysql_config_t
 
typedef struct rlm_sql_mysql_conn rlm_sql_mysql_conn_t
 

Enumerations

enum  rlm_sql_mysql_warnings {
  SERVER_WARNINGS_AUTO = 0,
  SERVER_WARNINGS_YES,
  SERVER_WARNINGS_NO
}
 

Functions

static int _mod_destructor (UNUSED rlm_sql_mysql_config_t *driver)
 
static int _sql_socket_destructor (rlm_sql_mysql_conn_t *conn)
 
static int mod_instantiate (CONF_SECTION *conf, rlm_sql_config_t *config)
 
static int sql_affected_rows (rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t *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, rlm_sql_handle_t *handle, rlm_sql_config_t *config)
 Retrieves any errors associated with the connection handle. More...
 
static size_t sql_escape_func (UNUSED REQUEST *request, char *out, size_t outlen, char const *in, void *arg)
 
static sql_rcode_t sql_fetch_row (rlm_sql_row_t *out, rlm_sql_handle_t *handle, rlm_sql_config_t *config)
 
static sql_rcode_t sql_fields (char const **out[], rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t *config)
 
static sql_rcode_t sql_finish_query (rlm_sql_handle_t *handle, rlm_sql_config_t *config)
 Finish query. More...
 
static sql_rcode_t sql_free_result (rlm_sql_handle_t *, rlm_sql_config_t *)
 
static sql_rcode_t sql_free_result (rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t *config)
 
static int sql_num_fields (rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t *config)
 
static int sql_num_rows (rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t *config)
 
static sql_rcode_t sql_query (rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t *config, char const *query)
 
static sql_rcode_t sql_select_query (rlm_sql_handle_t *handle, rlm_sql_config_t *config, char const *query)
 
static sql_rcode_t sql_socket_init (rlm_sql_handle_t *handle, rlm_sql_config_t *config, struct timeval const *timeout)
 
static sql_rcode_t sql_store_result (rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t *config)
 
static size_t sql_warnings (TALLOC_CTX *ctx, sql_log_entry_t out[], size_t outlen, rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t *config)
 Retrieves any warnings associated with the last query. More...
 

Variables

static const CONF_PARSER driver_config []
 
static int mysql_instance_count = 0
 
rlm_sql_module_t rlm_sql_mysql
 
static const FR_NAME_NUMBER server_warnings_table []
 
static CONF_PARSER tls_config []
 

Detailed Description

MySQL driver.

Id:
340d22351adbdd015eebfe1c32548ce3854d8c62

Definition in file rlm_sql_mysql.c.


Data Structure Documentation

struct rlm_sql_mysql_config

Definition at line 72 of file rlm_sql_mysql.c.

Data Fields
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.
char const * tls_cipher
char const * tls_private_key_file Private key for the certificate we present to the server.
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.
struct rlm_sql_mysql_conn

Definition at line 65 of file rlm_sql_mysql.c.

Data Fields
MYSQL db
MYSQL_RES * result
rlm_sql_row_t row
MYSQL * sock

Typedef Documentation

Enumeration Type Documentation

Enumerator
SERVER_WARNINGS_AUTO 
SERVER_WARNINGS_YES 
SERVER_WARNINGS_NO 

Definition at line 52 of file rlm_sql_mysql.c.

Function Documentation

static int _mod_destructor ( UNUSED rlm_sql_mysql_config_t driver)
static

Definition at line 119 of file rlm_sql_mysql.c.

+ Here is the caller graph for this function:

static int _sql_socket_destructor ( rlm_sql_mysql_conn_t conn)
static

Definition at line 108 of file rlm_sql_mysql.c.

+ Here is the caller graph for this function:

static int mod_instantiate ( CONF_SECTION conf,
rlm_sql_config_t config 
)
static

Definition at line 126 of file rlm_sql_mysql.c.

+ Here is the call graph for this function:

static int sql_affected_rows ( rlm_sql_handle_t handle,
UNUSED rlm_sql_config_t config 
)
static

Definition at line 706 of file rlm_sql_mysql.c.

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 273 of file rlm_sql_mysql.c.

+ Here is the caller graph for this function:

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

Retrieves any errors associated with the connection handle.

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.
handlerlm_sql connection handle.
configrlm_sql config.
Returns
number of errors written to the sql_log_entry_t array.

Definition at line 590 of file rlm_sql_mysql.c.

+ Here is the call graph for this function:

static size_t sql_escape_func ( UNUSED REQUEST request,
char *  out,
size_t  outlen,
char const *  in,
void *  arg 
)
static

Definition at line 713 of file rlm_sql_mysql.c.

static sql_rcode_t sql_fetch_row ( rlm_sql_row_t out,
rlm_sql_handle_t handle,
rlm_sql_config_t config 
)
static

Definition at line 462 of file rlm_sql_mysql.c.

+ Here is the call graph for this function:

static sql_rcode_t sql_fields ( char const **  out[],
rlm_sql_handle_t handle,
UNUSED rlm_sql_config_t config 
)
static

Definition at line 436 of file rlm_sql_mysql.c.

static sql_rcode_t sql_finish_query ( rlm_sql_handle_t handle,
rlm_sql_config_t 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 660 of file rlm_sql_mysql.c.

+ Here is the call graph for this function:

static sql_rcode_t sql_free_result ( rlm_sql_handle_t ,
rlm_sql_config_t  
)
static

+ Here is the caller graph for this function:

static sql_rcode_t sql_free_result ( rlm_sql_handle_t handle,
UNUSED rlm_sql_config_t config 
)
static

Definition at line 496 of file rlm_sql_mysql.c.

static int sql_num_fields ( rlm_sql_handle_t handle,
UNUSED rlm_sql_config_t config 
)
static

Definition at line 387 of file rlm_sql_mysql.c.

+ Here is the caller graph for this function:

static int sql_num_rows ( rlm_sql_handle_t handle,
UNUSED rlm_sql_config_t config 
)
static

Definition at line 425 of file rlm_sql_mysql.c.

static sql_rcode_t sql_query ( rlm_sql_handle_t handle,
UNUSED rlm_sql_config_t config,
char const *  query 
)
static

Definition at line 337 of file rlm_sql_mysql.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static sql_rcode_t sql_select_query ( rlm_sql_handle_t handle,
rlm_sql_config_t config,
char const *  query 
)
static

Definition at line 402 of file rlm_sql_mysql.c.

+ Here is the call graph for this function:

static sql_rcode_t sql_socket_init ( rlm_sql_handle_t handle,
rlm_sql_config_t config,
struct timeval const *  timeout 
)
static

Definition at line 165 of file rlm_sql_mysql.c.

+ Here is the call graph for this function:

static sql_rcode_t sql_store_result ( rlm_sql_handle_t handle,
UNUSED rlm_sql_config_t config 
)
static

Definition at line 361 of file rlm_sql_mysql.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static size_t sql_warnings ( TALLOC_CTX *  ctx,
sql_log_entry_t  out[],
size_t  outlen,
rlm_sql_handle_t handle,
UNUSED rlm_sql_config_t config 
)
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.
handlerlm_sql connection handle.
configrlm_sql config.
Returns

Definition at line 525 of file rlm_sql_mysql.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Variable Documentation

const CONF_PARSER driver_config[]
static
Initial value:
= {
{ FR_CONF_POINTER("tls", PW_TYPE_SUBSECTION, NULL), .dflt = (void const *) tls_config },
{ FR_CONF_OFFSET("warnings", PW_TYPE_STRING, rlm_sql_mysql_config_t, warnings_str), .dflt = "auto" },
}
#define CONF_PARSER_TERMINATOR
Definition: conffile.h:289
#define PW_TYPE_SUBSECTION
Definition: conffile.h:188
static CONF_PARSER tls_config[]
Definition: rlm_sql_mysql.c:85
#define FR_CONF_OFFSET(_n, _t, _s, _f)
Definition: conffile.h:168
String of printable characters.
Definition: radius.h:33
#define FR_CONF_POINTER(_n, _t, _p)
Definition: conffile.h:172

Definition at line 98 of file rlm_sql_mysql.c.

int mysql_instance_count = 0
static

Definition at line 50 of file rlm_sql_mysql.c.

rlm_sql_module_t rlm_sql_mysql
Initial value:
= {
.name = "rlm_sql_mysql",
.mod_instantiate = mod_instantiate,
.sql_socket_init = sql_socket_init,
.sql_query = sql_query,
.sql_select_query = sql_select_query,
.sql_store_result = sql_store_result,
.sql_num_fields = sql_num_fields,
.sql_num_rows = sql_num_rows,
.sql_affected_rows = sql_affected_rows,
.sql_fields = sql_fields,
.sql_fetch_row = sql_fetch_row,
.sql_free_result = sql_free_result,
.sql_error = sql_error,
.sql_finish_query = sql_finish_query,
.sql_finish_select_query = sql_finish_query,
.sql_escape_func = sql_escape_func
}
static sql_rcode_t sql_fields(char const **out[], rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t *config)
#define RLM_SQL_RCODE_FLAGS_ALT_QUERY
Can distinguish between other errors and those.
Definition: rlm_sql.h:164
static sql_rcode_t sql_finish_query(rlm_sql_handle_t *handle, rlm_sql_config_t *config)
Finish query.
static sql_rcode_t sql_query(rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t *config, char const *query)
static sql_rcode_t sql_free_result(rlm_sql_handle_t *, rlm_sql_config_t *)
static sql_rcode_t sql_store_result(rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t *config)
static sql_rcode_t sql_socket_init(rlm_sql_handle_t *handle, rlm_sql_config_t *config, struct timeval const *timeout)
static int sql_num_fields(rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t *config)
static sql_rcode_t sql_fetch_row(rlm_sql_row_t *out, rlm_sql_handle_t *handle, rlm_sql_config_t *config)
static int sql_num_rows(rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t *config)
static int mod_instantiate(CONF_SECTION *conf, rlm_sql_config_t *config)
static size_t sql_error(TALLOC_CTX *ctx, sql_log_entry_t out[], size_t outlen, rlm_sql_handle_t *handle, rlm_sql_config_t *config)
Retrieves any errors associated with the connection handle.
static sql_rcode_t sql_select_query(rlm_sql_handle_t *handle, rlm_sql_config_t *config, char const *query)
static int sql_affected_rows(rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t *config)
static size_t sql_escape_func(UNUSED REQUEST *request, char *out, size_t outlen, char const *in, void *arg)

Definition at line 731 of file rlm_sql_mysql.c.

const FR_NAME_NUMBER server_warnings_table[]
static
Initial value:

Definition at line 58 of file rlm_sql_mysql.c.

CONF_PARSER tls_config[]
static
Initial value:
= {
{ FR_CONF_OFFSET("certificate_file", PW_TYPE_FILE_INPUT, rlm_sql_mysql_config_t, tls_certificate_file) },
{ FR_CONF_OFFSET("private_key_file", PW_TYPE_FILE_INPUT, rlm_sql_mysql_config_t, tls_private_key_file) },
}
#define PW_TYPE_FILE_INPUT
File matching value must exist, and must be readable.
Definition: conffile.h:204
#define CONF_PARSER_TERMINATOR
Definition: conffile.h:289
#define FR_CONF_OFFSET(_n, _t, _s, _f)
Definition: conffile.h:168
String of printable characters.
Definition: radius.h:33

Definition at line 85 of file rlm_sql_mysql.c.