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

Implements FreeTDS rlm_sql driver. More...

#include <ctype.h>
#include <freeradius-devel/radiusd.h>
#include <freeradius-devel/modules.h>
#include <freeradius-devel/map_proc.h>
#include <freeradius-devel/token.h>
#include <freeradius-devel/rad_assert.h>
#include <freeradius-devel/exfile.h>
#include <sys/stat.h>
#include "rlm_sql.h"
+ Include dependency graph for rlm_sql.c:

Go to the source code of this file.

Macros

#define MAX_SQL_FIELD_INDEX   (64)
 
#define sql_unset_user(_i, _r)   fr_pair_delete_by_num(&_r->packet->vps, _i->sql_user->vendor, _i->sql_user->attr, TAG_ANY)
 

Functions

static int _sql_map_proc_get_value (TALLOC_CTX *ctx, VALUE_PAIR **out, REQUEST *request, vp_map_t const *map, void *uctx)
 Converts a string value into a VALUE_PAIR. More...
 
static int acct_redundant (rlm_sql_t *inst, REQUEST *request, sql_acct_section_t *section)
 
static sql_fall_through_t fall_through (VALUE_PAIR *vp)
 
static int generate_sql_clients (rlm_sql_t *inst)
 
static rlm_rcode_t mod_accounting (void *instance, REQUEST *request) CC_HINT(nonnull)
 
static rlm_rcode_t mod_authorize (void *instance, REQUEST *request) CC_HINT(nonnull)
 
static int mod_bootstrap (CONF_SECTION *conf, void *instance)
 
static rlm_rcode_t mod_checksimul (void *instance, REQUEST *request) CC_HINT(nonnull)
 
static int mod_detach (void *instance)
 
static int mod_instantiate (CONF_SECTION *conf, void *instance)
 
static rlm_rcode_t mod_map_proc (void *mod_inst, UNUSED void *proc_inst, REQUEST *request, char const *query, vp_map_t const *maps)
 Executes a SELECT query and maps the result to server attributes. More...
 
static rlm_rcode_t mod_post_auth (void *instance, REQUEST *request) CC_HINT(nonnull)
 
static rlm_rcode_t rlm_sql_process_groups (rlm_sql_t *inst, REQUEST *request, rlm_sql_handle_t **handle, sql_fall_through_t *do_fall_through)
 
static size_t sql_escape_for_xlat_func (REQUEST *request, char *out, size_t outlen, char const *in, void *arg)
 Passed as the escape function to map_proc and sql xlat methods. More...
 
static size_t sql_escape_func (REQUEST *, char *out, size_t outlen, char const *in, void *arg)
 
static size_t sql_escape_func (UNUSED REQUEST *request, char *out, size_t outlen, char const *in, void *arg)
 xlat escape function for drivers which do not provide their own More...
 
static int sql_get_grouplist (rlm_sql_t *inst, rlm_sql_handle_t **handle, REQUEST *request, rlm_sql_grouplist_t **phead)
 
static int sql_groupcmp (void *instance, REQUEST *request, UNUSED VALUE_PAIR *request_vp, VALUE_PAIR *check, UNUSED VALUE_PAIR *check_pairs, UNUSED VALUE_PAIR **reply_pairs) CC_HINT(nonnull(1
 
int sql_set_user (rlm_sql_t const *inst, REQUEST *request, char const *username)
 
static ssize_t sql_xlat (char **out, UNUSED size_t outlen, void const *mod_inst, UNUSED void const *xlat_inst, REQUEST *request, char const *fmt)
 Execute an arbitrary SQL query. More...
 

Variables

static const CONF_PARSER acct_config []
 
static const CONF_PARSER module_config []
 
static const CONF_PARSER postauth_config []
 
static const CONF_PARSER query_config []
 
module_t rlm_sql
 
static const CONF_PARSER type_config []
 

Detailed Description

Implements FreeTDS rlm_sql driver.

Implements SQL 'users' file, and SQL accounting.

Id:
2932e61d65e98e34ede0b62bb0ccc1de4028690f
Id:
4748ef6ccf12f9b13ea80124dabefe524a86aa19

Definition in file rlm_sql.c.

Macro Definition Documentation

#define MAX_SQL_FIELD_INDEX   (64)
#define sql_unset_user (   _i,
  _r 
)    fr_pair_delete_by_num(&_r->packet->vps, _i->sql_user->vendor, _i->sql_user->attr, TAG_ANY)

Definition at line 680 of file rlm_sql.c.

Function Documentation

static int _sql_map_proc_get_value ( TALLOC_CTX *  ctx,
VALUE_PAIR **  out,
REQUEST request,
vp_map_t const *  map,
void *  uctx 
)
static

Converts a string value into a VALUE_PAIR.

Parameters
[in,out]ctxto allocate VALUE_PAIR (s).
[out]outwhere to write the resulting VALUE_PAIR.
[in]requestThe current request.
[in]mapto process.
[in]uctxThe value to parse.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 245 of file rlm_sql.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static int acct_redundant ( rlm_sql_t inst,
REQUEST request,
sql_acct_section_t section 
)
static

Definition at line 1457 of file rlm_sql.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static sql_fall_through_t fall_through ( VALUE_PAIR vp)
static

Definition at line 123 of file rlm_sql.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static int generate_sql_clients ( rlm_sql_t inst)
static

Definition at line 414 of file rlm_sql.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static rlm_rcode_t mod_accounting ( void *  instance,
REQUEST request 
)
static

Definition at line 1625 of file rlm_sql.c.

+ Here is the call graph for this function:

static rlm_rcode_t mod_authorize ( void *  instance,
REQUEST request 
)
static

Definition at line 1197 of file rlm_sql.c.

+ Here is the call graph for this function:

static int mod_bootstrap ( CONF_SECTION conf,
void *  instance 
)
static

Definition at line 992 of file rlm_sql.c.

+ Here is the call graph for this function:

static rlm_rcode_t mod_checksimul ( void *  instance,
REQUEST request 
)
static

Definition at line 1648 of file rlm_sql.c.

+ Here is the call graph for this function:

static int mod_detach ( void *  instance)
static

Definition at line 967 of file rlm_sql.c.

+ Here is the call graph for this function:

static int mod_instantiate ( CONF_SECTION conf,
void *  instance 
)
static

Definition at line 1070 of file rlm_sql.c.

+ Here is the call graph for this function:

static rlm_rcode_t mod_map_proc ( void *  mod_inst,
UNUSED void *  proc_inst,
REQUEST request,
char const *  query,
vp_map_t const *  maps 
)
static

Executes a SELECT query and maps the result to server attributes.

Parameters
mod_instrlm_sql_t instance.
proc_instInstance data for this specific mod_proc call (unused).
requestThe current request.
querystring to execute.
mapsHead of the map list.
Returns

Definition at line 284 of file rlm_sql.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static rlm_rcode_t mod_post_auth ( void *  instance,
REQUEST request 
)
static

Definition at line 1845 of file rlm_sql.c.

+ Here is the call graph for this function:

static rlm_rcode_t rlm_sql_process_groups ( rlm_sql_t inst,
REQUEST request,
rlm_sql_handle_t **  handle,
sql_fall_through_t do_fall_through 
)
static

Definition at line 808 of file rlm_sql.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Passed as the escape function to map_proc and sql xlat methods.

The variant reserves a connection for the escape functions to use, and releases it after escaping is complete.

Definition at line 616 of file rlm_sql.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

+ Here is the caller graph for this function:

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

xlat escape function for drivers which do not provide their own

Definition at line 505 of file rlm_sql.c.

+ Here is the call graph for this function:

static int sql_get_grouplist ( rlm_sql_t inst,
rlm_sql_handle_t **  handle,
REQUEST request,
rlm_sql_grouplist_t **  phead 
)
static

Definition at line 682 of file rlm_sql.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static int static int sql_groupcmp ( void *  instance,
REQUEST request,
UNUSED VALUE_PAIR request_vp,
VALUE_PAIR check,
UNUSED VALUE_PAIR check_pairs,
UNUSED VALUE_PAIR **  reply_pairs 
)
static

Definition at line 743 of file rlm_sql.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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:

static ssize_t sql_xlat ( char **  out,
UNUSED size_t  outlen,
void const *  mod_inst,
UNUSED void const *  xlat_inst,
REQUEST request,
char const *  fmt 
)
static

Execute an arbitrary SQL query.

For selects the first value of the first column will be returned, for inserts, updates and deletes the number of rows affected will be returned instead.

Definition at line 143 of file rlm_sql.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Variable Documentation

const CONF_PARSER acct_config[]
static
Initial value:
= {
{ FR_CONF_OFFSET("reference", PW_TYPE_STRING | PW_TYPE_XLAT, rlm_sql_config_t, accounting.reference), .dflt = ".query" },
{ FR_CONF_POINTER("type", PW_TYPE_SUBSECTION, NULL), .dflt = (void const *) type_config },
}
char const * logfile
Keep a log of all SQL queries executed Useful for batch insertion with the NULL drivers.
Definition: rlm_sql.h:121
#define CONF_PARSER_TERMINATOR
Definition: conffile.h:289
static const CONF_PARSER type_config[]
Definition: rlm_sql.c:54
#define PW_TYPE_SUBSECTION
Definition: conffile.h:188
#define PW_TYPE_XLAT
string will be dynamically expanded.
Definition: conffile.h:207
#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 63 of file rlm_sql.c.

const CONF_PARSER module_config[]
static

Definition at line 79 of file rlm_sql.c.

const CONF_PARSER postauth_config[]
static
Initial value:
= {
{ FR_CONF_OFFSET("reference", PW_TYPE_STRING | PW_TYPE_XLAT, rlm_sql_config_t, postauth.reference), .dflt = ".query" },
}
char const * logfile
Keep a log of all SQL queries executed Useful for batch insertion with the NULL drivers.
Definition: rlm_sql.h:121
#define CONF_PARSER_TERMINATOR
Definition: conffile.h:289
#define PW_TYPE_XLAT
string will be dynamically expanded.
Definition: conffile.h:207
#define PW_TYPE_MULTI
CONF_PAIR can have multiple copies.
Definition: conffile.h:210
#define FR_CONF_OFFSET(_n, _t, _s, _f)
Definition: conffile.h:168
String of printable characters.
Definition: radius.h:33

Definition at line 71 of file rlm_sql.c.

const CONF_PARSER query_config[]
static
Initial value:
= {
}
#define CONF_PARSER_TERMINATOR
Definition: conffile.h:289
#define PW_TYPE_XLAT
string will be dynamically expanded.
Definition: conffile.h:207
#define PW_TYPE_MULTI
CONF_PAIR can have multiple copies.
Definition: conffile.h:210
#define FR_CONF_OFFSET(_n, _t, _s, _f)
Definition: conffile.h:168
String of printable characters.
Definition: radius.h:33

Definition at line 45 of file rlm_sql.c.

module_t rlm_sql
Initial value:
= {
.magic = RLM_MODULE_INIT,
.name = "sql",
.inst_size = sizeof(rlm_sql_t),
.config = module_config,
.bootstrap = mod_bootstrap,
.instantiate = mod_instantiate,
.detach = mod_detach,
.methods = {
},
}
7 methods index for postauth section.
Definition: modules.h:48
#define RLM_TYPE_THREAD_SAFE
Module is threadsafe.
Definition: modules.h:75
#define RLM_MODULE_INIT
Definition: modules.h:86
static rlm_rcode_t mod_authorize(void *instance, REQUEST *request) CC_HINT(nonnull)
Definition: rlm_sql.c:1197
static int mod_detach(void *instance)
Definition: rlm_sql.c:967
static int mod_instantiate(CONF_SECTION *conf, void *instance)
Definition: rlm_sql.c:1070
4 methods index for checksimul section.
Definition: modules.h:45
struct sql_inst rlm_sql_t
Definition: rlm_sql.h:150
3 methods index for accounting section.
Definition: modules.h:44
static const CONF_PARSER module_config[]
Definition: rlm_sql.c:79
static rlm_rcode_t mod_checksimul(void *instance, REQUEST *request) CC_HINT(nonnull)
Definition: rlm_sql.c:1648
static int mod_bootstrap(CONF_SECTION *conf, void *instance)
Definition: rlm_sql.c:992
static rlm_rcode_t mod_accounting(void *instance, REQUEST *request) CC_HINT(nonnull)
Definition: rlm_sql.c:1625
1 methods index for authorize section.
Definition: modules.h:42
static rlm_rcode_t mod_post_auth(void *instance, REQUEST *request) CC_HINT(nonnull)
Definition: rlm_sql.c:1845

Definition at line 1863 of file rlm_sql.c.

const CONF_PARSER type_config[]
static
Initial value:
= {
{ FR_CONF_POINTER("accounting-on", PW_TYPE_SUBSECTION, NULL), .dflt = (void const *) query_config },
{ FR_CONF_POINTER("accounting-off", PW_TYPE_SUBSECTION, NULL), .dflt = (void const *) query_config },
{ FR_CONF_POINTER("start", PW_TYPE_SUBSECTION, NULL), .dflt = (void const *) query_config },
{ FR_CONF_POINTER("interim-update", PW_TYPE_SUBSECTION, NULL), .dflt = (void const *) query_config },
{ FR_CONF_POINTER("stop", PW_TYPE_SUBSECTION, NULL), .dflt = (void const *) query_config },
}
#define CONF_PARSER_TERMINATOR
Definition: conffile.h:289
#define PW_TYPE_SUBSECTION
Definition: conffile.h:188
static const CONF_PARSER query_config[]
Definition: rlm_sql.c:45
#define FR_CONF_POINTER(_n, _t, _p)
Definition: conffile.h:172

Definition at line 54 of file rlm_sql.c.