The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
rlm_sql.c File Reference

Implements FreeTDS rlm_sql driver. More...

#include <freeradius-devel/server/base.h>
#include <freeradius-devel/server/exfile.h>
#include <freeradius-devel/server/map_proc.h>
#include <freeradius-devel/server/module_rlm.h>
#include <freeradius-devel/server/pairmove.h>
#include <freeradius-devel/util/debug.h>
#include <freeradius-devel/util/dict.h>
#include <freeradius-devel/util/table.h>
#include <freeradius-devel/unlang/function.h>
#include <freeradius-devel/unlang/xlat_func.h>
#include <sys/stat.h>
#include "rlm_sql.h"
+ Include dependency graph for rlm_sql.c:

Go to the source code of this file.

Data Structures

struct  rlm_sql_boot_t
 
struct  rlm_sql_grouplist_s
 
struct  sql_autz_call_env_t
 
struct  sql_autz_ctx_t
 Context for SQL authorization. More...
 
struct  sql_group_ctx_t
 Context for group membership query evaluation. More...
 
struct  sql_group_xlat_call_env_t
 
struct  sql_group_xlat_ctx_t
 
struct  sql_map_ctx_t
 Context for SQL maps. More...
 
struct  sql_redundant_call_env_t
 
struct  sql_redundant_ctx_t
 Context for tracking redundant SQL query sets. More...
 
struct  sql_xlat_call_env_t
 

Macros

#define LOG_PREFIX   mctx->mi->name
 
#define MAX_SQL_FIELD_INDEX   (64)
 
#define QUERY_ESCAPE
 
#define SQL_AUTZ_STAGE_GROUP   0x20
 
#define SQL_AUTZ_STAGE_PROFILE   0x40
 
#define SQL_SAFE_FOR   (fr_value_box_safe_for_t)inst->driver
 
#define sql_unset_user(_i, _r)   fr_pair_delete_by_da(&_r->request_pairs, _i->sql_user)
 

Typedefs

typedef struct rlm_sql_grouplist_s rlm_sql_grouplist_t
 

Enumerations

enum  sql_autz_status_t {
  SQL_AUTZ_CHECK = 0x12 ,
  SQL_AUTZ_CHECK_RESUME = 0x13 ,
  SQL_AUTZ_REPLY = 0x14 ,
  SQL_AUTZ_REPLY_RESUME = 0x15 ,
  SQL_AUTZ_GROUP_MEMB = 0x20 ,
  SQL_AUTZ_GROUP_MEMB_RESUME = 0x21 ,
  SQL_AUTZ_GROUP_CHECK = 0x22 ,
  SQL_AUTZ_GROUP_CHECK_RESUME = 0x23 ,
  SQL_AUTZ_GROUP_REPLY = 0x24 ,
  SQL_AUTZ_GROUP_REPLY_RESUME = 0x25 ,
  SQL_AUTZ_PROFILE_START = 0x40 ,
  SQL_AUTZ_PROFILE_CHECK = 0x42 ,
  SQL_AUTZ_PROFILE_CHECK_RESUME = 0x43 ,
  SQL_AUTZ_PROFILE_REPLY = 0x44 ,
  SQL_AUTZ_PROFILE_REPLY_RESUME = 0x45
}
 Status of the authorization process. More...
 

Functions

static int _sql_escape_uxtx_free (void *uctx)
 
static int _sql_map_proc_get_value (TALLOC_CTX *ctx, fr_pair_list_t *out, request_t *request, map_t const *map, void *uctx)
 Converts a string value into a fr_pair_t.
 
static int call_env_parse (TALLOC_CTX *ctx, void *out, tmpl_rules_t const *t_rules, CONF_ITEM *ci, call_env_ctx_t const *cec, UNUSED call_env_parser_t const *rule)
 Custom parser for sql call env queries.
 
static int check_map_process (request_t *request, map_list_t *check_map, map_list_t *reply_map)
 Process a "check" map.
 
static sql_fall_through_t fall_through (map_list_t *maps)
 
static int logfile_call_env_parse (TALLOC_CTX *ctx, call_env_parsed_head_t *out, tmpl_rules_t const *t_rules, CONF_ITEM *cc, call_env_ctx_t const *cec, call_env_parser_t const *rule)
 
static int logfile_call_env_parse (TALLOC_CTX *ctx, call_env_parsed_head_t *out, tmpl_rules_t const *t_rules, CONF_ITEM *ci, call_env_ctx_t const *cec, UNUSED call_env_parser_t const *rule)
 
static unlang_action_t mod_authorize (rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request)
 Start of module authorize method.
 
static unlang_action_t mod_authorize_resume (rlm_rcode_t *p_result, int *priority, request_t *request, void *uctx)
 Resume function called after authorization check / reply tmpl expansion.
 
static unlang_action_t mod_autz_group_resume (rlm_rcode_t *p_result, UNUSED int *priority, request_t *request, void *uctx)
 Resume function called after authorization group / profile expansion of check / reply query tmpl.
 
static int mod_bootstrap (module_inst_ctx_t const *mctx)
 
static int mod_detach (module_detach_ctx_t const *mctx)
 
static int mod_instantiate (module_inst_ctx_t const *mctx)
 
static unlang_action_t mod_map_proc (rlm_rcode_t *p_result, void const *mod_inst, UNUSED void *proc_inst, request_t *request, fr_value_box_list_t *query, map_list_t const *maps)
 Executes a SELECT query and maps the result to server attributes.
 
static unlang_action_t mod_map_resume (rlm_rcode_t *p_result, UNUSED int *priority, request_t *request, void *uctx)
 Process the results of an SQL map query.
 
static unlang_action_t mod_sql_redundant (rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request)
 Generic module call for failing between a bunch of queries.
 
static unlang_action_t mod_sql_redundant_query_resume (rlm_rcode_t *p_result, UNUSED int *priority, request_t *request, void *uctx)
 Resume function called after executing an SQL query in a redundant list of queries.
 
static unlang_action_t mod_sql_redundant_resume (rlm_rcode_t *p_result, UNUSED int *priority, request_t *request, void *uctx)
 Resume function called after expansion of next query in a redundant list of queries.
 
static int mod_thread_detach (module_thread_inst_ctx_t const *mctx)
 
static int mod_thread_instantiate (module_thread_inst_ctx_t const *mctx)
 Initialise thread specific data structure.
 
static int query_call_env_parse (TALLOC_CTX *ctx, call_env_parsed_head_t *out, tmpl_rules_t const *t_rules, CONF_ITEM *cc, call_env_ctx_t const *cec, call_env_parser_t const *rule)
 
static int query_call_env_parse (TALLOC_CTX *ctx, call_env_parsed_head_t *out, tmpl_rules_t const *t_rules, CONF_ITEM *ci, call_env_ctx_t const *cec, UNUSED call_env_parser_t const *rule)
 
static int sql_autz_ctx_free (sql_autz_ctx_t *to_free)
 
static int sql_box_escape (fr_value_box_t *vb, void *uctx)
 
static ssize_t sql_escape_func (request_t *, char *out, size_t outlen, char const *in, void *arg)
 
static ssize_t sql_escape_func (UNUSED request_t *request, char *out, size_t outlen, char const *in, void *arg)
 xlat escape function for drivers which do not provide their own
 
static void * sql_escape_uctx_alloc (UNUSED request_t *request, void const *uctx)
 
static xlat_action_t sql_escape_xlat (UNUSED TALLOC_CTX *ctx, fr_dcursor_t *out, xlat_ctx_t const *xctx, request_t *request, fr_value_box_list_t *in)
 Escape a value to make it SQL safe.
 
static xlat_action_t sql_fetch_xlat (UNUSED TALLOC_CTX *ctx, UNUSED fr_dcursor_t *out, xlat_ctx_t const *xctx, request_t *request, fr_value_box_list_t *in)
 Execute an arbitrary SQL query, expecting results to be returned.
 
static unlang_action_t sql_get_grouplist (sql_group_ctx_t *group_ctx, trunk_t *trunk, request_t *request)
 
static unlang_action_t sql_get_grouplist_resume (rlm_rcode_t *p_result, UNUSED int *priority, request_t *request, void *uctx)
 
static xlat_action_t sql_group_xlat (UNUSED TALLOC_CTX *ctx, UNUSED fr_dcursor_t *out, xlat_ctx_t const *xctx, request_t *request, UNUSED fr_value_box_list_t *in)
 Check if the user is a member of a particular group.
 
static xlat_action_t sql_group_xlat_query_resume (TALLOC_CTX *ctx, fr_dcursor_t *out, xlat_ctx_t const *xctx, UNUSED request_t *request, fr_value_box_list_t *in)
 Compare list of groups returned from SQL query to xlat argument.
 
static xlat_action_t sql_group_xlat_resume (UNUSED TALLOC_CTX *ctx, UNUSED fr_dcursor_t *out, xlat_ctx_t const *xctx, request_t *request, UNUSED fr_value_box_list_t *in)
 Run SQL query for group membership to return list of groups.
 
static int sql_map_verify (CONF_SECTION *cs, UNUSED void const *mod_inst, UNUSED void *proc_inst, tmpl_t const *src, UNUSED map_list_t const *maps)
 
static xlat_action_t sql_modify_xlat (TALLOC_CTX *ctx, fr_dcursor_t *out, xlat_ctx_t const *xctx, request_t *request, fr_value_box_list_t *in)
 Execute an arbitrary SQL query, returning the number of rows affected.
 
static int sql_redundant_ctx_free (sql_redundant_ctx_t *to_free)
 Tidy up when freeing an SQL redundant context.
 
static void sql_set_user (rlm_sql_t const *inst, request_t *request, fr_value_box_t *user)
 
static xlat_action_t sql_xlat (TALLOC_CTX *ctx, fr_dcursor_t *out, xlat_ctx_t const *xctx, request_t *request, fr_value_box_list_t *in)
 Execute an arbitrary SQL query.
 
static int sql_xlat_escape (request_t *request, fr_value_box_t *vb, void *uctx)
 Escape a tainted VB used as an xlat argument.
 
static xlat_action_t sql_xlat_query_resume (TALLOC_CTX *ctx, fr_dcursor_t *out, xlat_ctx_t const *xctx, request_t *request, UNUSED fr_value_box_list_t *in)
 
static xlat_action_t sql_xlat_select_resume (TALLOC_CTX *ctx, fr_dcursor_t *out, xlat_ctx_t const *xctx, request_t *request, UNUSED fr_value_box_list_t *in)
 
static int submodule_parse (TALLOC_CTX *ctx, void *out, void *parent, CONF_ITEM *ci, conf_parser_t const *rule)
 

Variables

static const call_env_method_t accounting_method_env
 
static fr_dict_attr_t const * attr_expr_bool_enum
 
static fr_dict_attr_t const * attr_fall_through
 
static fr_dict_attr_t const * attr_sql_user_name
 
static fr_dict_attr_t const * attr_user_profile
 
static const call_env_method_t authorize_method_env
 
static fr_dict_t const * dict_freeradius
 
static const call_env_method_t group_xlat_method_env
 
static const conf_parser_t module_config []
 
module_rlm_t rlm_sql
 
fr_dict_autoload_t rlm_sql_dict []
 
fr_dict_attr_autoload_t rlm_sql_dict_attr []
 
static const call_env_method_t send_method_env
 
static const call_env_method_t xlat_method_env
 

Detailed Description

Implements FreeTDS rlm_sql driver.

Implements SQL 'users' file, and SQL accounting.

Id
ed4de9c4164a97ec5ccf853635b3da01252391f2
Id
7af78654e40e5b40632e33eba7229b47291a4261

Definition in file rlm_sql.c.


Data Structure Documentation

◆ rlm_sql_boot_t

struct rlm_sql_boot_t

Definition at line 53 of file rlm_sql.c.

+ Collaboration diagram for rlm_sql_boot_t:
Data Fields
fr_dict_attr_t const * group_da

◆ rlm_sql_grouplist_s

struct rlm_sql_grouplist_s

Definition at line 1050 of file rlm_sql.c.

+ Collaboration diagram for rlm_sql_grouplist_s:
Data Fields
char * name
rlm_sql_grouplist_t * next

◆ sql_autz_call_env_t

struct sql_autz_call_env_t

Definition at line 108 of file rlm_sql.c.

+ Collaboration diagram for sql_autz_call_env_t:
Data Fields
tmpl_t * check_query Tmpl to expand to form authorize_check_query.
tmpl_t * group_check_query Tmpl to expand to form authorize_group_check_query.
tmpl_t * group_reply_query Tmpl to expand to form authorize_group_reply_query.
tmpl_t * membership_query Tmpl to expand to form group_membership_query.
tmpl_t * reply_query Tmpl to expand to form authorize_reply_query.
fr_value_box_t user Expansion of the sql_user_name.

◆ sql_autz_ctx_t

struct sql_autz_ctx_t

Context for SQL authorization.

Definition at line 179 of file rlm_sql.c.

+ Collaboration diagram for sql_autz_ctx_t:
Data Fields
sql_autz_call_env_t * call_env Call environment data.
map_list_t check_tmp List to store check items before processing.
rlm_sql_grouplist_t * group Current group being processed.
sql_group_ctx_t * group_ctx Context used for retrieving user group membership.
rlm_sql_t const * inst Module instance.
fr_sql_map_ctx_t * map_ctx Context used for retrieving attribute value pairs as a map list.
fr_pair_t * profile Current profile being processed.
fr_value_box_list_t query Where expanded query tmpls will be written.
rlm_rcode_t rcode Module return code.
map_list_t reply_tmp List to store reply items before processing.
request_t * request Request being processed.
fr_pair_t * sql_group Pair to update with group being processed.
sql_autz_status_t status Current status of the authorization.
trunk_t * trunk Trunk connection for current authorization.
bool user_found Has the user been found anywhere?

◆ sql_group_ctx_t

struct sql_group_ctx_t

Context for group membership query evaluation.

Definition at line 169 of file rlm_sql.c.

+ Collaboration diagram for sql_group_ctx_t:
Data Fields
rlm_sql_grouplist_t * groups List of groups retrieved.
rlm_sql_t const * inst Module instance.
int num_groups How many groups have been retrieved.
fr_value_box_t * query Query string used for evaluating group membership.
fr_sql_query_t * query_ctx Query context.

◆ sql_group_xlat_call_env_t

struct sql_group_xlat_call_env_t

Definition at line 245 of file rlm_sql.c.

+ Collaboration diagram for sql_group_xlat_call_env_t:
Data Fields
tmpl_t * membership_query
fr_value_box_t user

◆ sql_group_xlat_ctx_t

struct sql_group_xlat_ctx_t

Definition at line 1110 of file rlm_sql.c.

+ Collaboration diagram for sql_group_xlat_ctx_t:
Data Fields
sql_group_ctx_t * group_ctx
fr_value_box_list_t query

◆ sql_map_ctx_t

struct sql_map_ctx_t

Context for SQL maps.

Definition at line 200 of file rlm_sql.c.

+ Collaboration diagram for sql_map_ctx_t:
Data Fields
rlm_sql_t const * inst
map_list_t const * maps
fr_sql_query_t * query_ctx

◆ sql_redundant_call_env_t

struct sql_redundant_call_env_t

Definition at line 206 of file rlm_sql.c.

+ Collaboration diagram for sql_redundant_call_env_t:
Data Fields
fr_value_box_t filename File name to write SQL logs to.
tmpl_t ** query Array of tmpls for list of queries to run.
fr_value_box_t user Expansion of sql_user_name.

◆ sql_redundant_ctx_t

struct sql_redundant_ctx_t

Context for tracking redundant SQL query sets.

Definition at line 234 of file rlm_sql.c.

+ Collaboration diagram for sql_redundant_ctx_t:
Data Fields
sql_redundant_call_env_t * call_env Call environment data.
rlm_sql_t const * inst Module instance.
fr_value_box_list_t query Where expanded query tmpl will be written.
fr_sql_query_t * query_ctx Query context for current query.
size_t query_no Current query number.
fr_value_box_t * query_vb Current query string.
request_t * request Request being processed.
trunk_t * trunk Trunk connection for queries.

◆ sql_xlat_call_env_t

struct sql_xlat_call_env_t

Definition at line 123 of file rlm_sql.c.

+ Collaboration diagram for sql_xlat_call_env_t:
Data Fields
fr_value_box_t filename

Macro Definition Documentation

◆ LOG_PREFIX

#define LOG_PREFIX   mctx->mi->name

Definition at line 30 of file rlm_sql.c.

◆ MAX_SQL_FIELD_INDEX

#define MAX_SQL_FIELD_INDEX   (64)

Definition at line 713 of file rlm_sql.c.

◆ QUERY_ESCAPE

#define QUERY_ESCAPE
Value:
.pair.escape = { \
.uctx = { .func = { .alloc = sql_escape_uctx_alloc }, .type = TMPL_ESCAPE_UCTX_ALLOC_FUNC }, \
}, .pair.func = call_env_parse
static int call_env_parse(TALLOC_CTX *ctx, void *out, tmpl_rules_t const *t_rules, CONF_ITEM *ci, call_env_ctx_t const *cec, UNUSED call_env_parser_t const *rule)
Custom parser for sql call env queries.
Definition rlm_sql.c:2347
static void * sql_escape_uctx_alloc(UNUSED request_t *request, void const *uctx)
Definition rlm_sql.c:282
@ TMPL_ESCAPE_UCTX_ALLOC_FUNC
A new uctx of the specified size and type is allocated and pre-populated by memcpying uctx....
Definition tmpl_escape.h:35
@ TMPL_ESCAPE_PRE_CONCAT
Pre-concatenation escaping is useful for DSLs where elements of the expansion are static,...
Definition tmpl_escape.h:61

Definition at line 2372 of file rlm_sql.c.

◆ SQL_AUTZ_STAGE_GROUP

#define SQL_AUTZ_STAGE_GROUP   0x20

Definition at line 164 of file rlm_sql.c.

◆ SQL_AUTZ_STAGE_PROFILE

#define SQL_AUTZ_STAGE_PROFILE   0x40

Definition at line 165 of file rlm_sql.c.

◆ SQL_SAFE_FOR

#define SQL_SAFE_FOR   (fr_value_box_safe_for_t)inst->driver

Definition at line 47 of file rlm_sql.c.

◆ sql_unset_user

#define sql_unset_user (   _i,
  _r 
)    fr_pair_delete_by_da(&_r->request_pairs, _i->sql_user)

Definition at line 1047 of file rlm_sql.c.

Typedef Documentation

◆ rlm_sql_grouplist_t

Definition at line 142 of file rlm_sql.c.

Enumeration Type Documentation

◆ sql_autz_status_t

Status of the authorization process.

Enumerator
SQL_AUTZ_CHECK 

Running user check query.

SQL_AUTZ_CHECK_RESUME 

Completed user check query.

SQL_AUTZ_REPLY 

Running user reply query.

SQL_AUTZ_REPLY_RESUME 

Completed user reply query.

SQL_AUTZ_GROUP_MEMB 

Running group membership query.

SQL_AUTZ_GROUP_MEMB_RESUME 

Completed group membership query.

SQL_AUTZ_GROUP_CHECK 

Running group check query.

SQL_AUTZ_GROUP_CHECK_RESUME 

Completed group check query.

SQL_AUTZ_GROUP_REPLY 

Running group reply query.

SQL_AUTZ_GROUP_REPLY_RESUME 

Completed group reply query.

SQL_AUTZ_PROFILE_START 

Starting processing user profiles.

SQL_AUTZ_PROFILE_CHECK 

Running profile check query.

SQL_AUTZ_PROFILE_CHECK_RESUME 

Completed profile check query.

SQL_AUTZ_PROFILE_REPLY 

Running profile reply query.

SQL_AUTZ_PROFILE_REPLY_RESUME 

Completed profile reply query.

Definition at line 146 of file rlm_sql.c.

Function Documentation

◆ _sql_escape_uxtx_free()

static int _sql_escape_uxtx_free ( void *  uctx)
static

Definition at line 273 of file rlm_sql.c.

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

◆ _sql_map_proc_get_value()

static int _sql_map_proc_get_value ( TALLOC_CTX *  ctx,
fr_pair_list_t out,
request_t request,
map_t const *  map,
void *  uctx 
)
static

Converts a string value into a fr_pair_t.

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

Definition at line 676 of file rlm_sql.c.

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

◆ call_env_parse()

static int call_env_parse ( TALLOC_CTX *  ctx,
void *  out,
tmpl_rules_t const *  t_rules,
CONF_ITEM ci,
call_env_ctx_t const *  cec,
UNUSED call_env_parser_t const *  rule 
)
static

Custom parser for sql call env queries.

Needed as the escape function needs to reference the correct SQL driver

Definition at line 2347 of file rlm_sql.c.

+ Here is the call graph for this function:

◆ check_map_process()

static int check_map_process ( request_t request,
map_list_t *  check_map,
map_list_t *  reply_map 
)
static

Process a "check" map.

Any entries using an assignment operator will be moved to the reply map for later merging into the request.

Parameters
requestCurrent request.
check_mapto process.
reply_mapwhere any assignment entries will be moved.
Returns
  • 0 if all the check entries pass.
  • -1 if the checks fail.

Definition at line 1221 of file rlm_sql.c.

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

◆ fall_through()

static sql_fall_through_t fall_through ( map_list_t *  maps)
static

Definition at line 300 of file rlm_sql.c.

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

◆ logfile_call_env_parse() [1/2]

static int logfile_call_env_parse ( TALLOC_CTX *  ctx,
call_env_parsed_head_t *  out,
tmpl_rules_t const *  t_rules,
CONF_ITEM cc,
call_env_ctx_t const *  cec,
call_env_parser_t const *  rule 
)
static

◆ logfile_call_env_parse() [2/2]

static int logfile_call_env_parse ( TALLOC_CTX *  ctx,
call_env_parsed_head_t *  out,
tmpl_rules_t const *  t_rules,
CONF_ITEM ci,
call_env_ctx_t const *  cec,
UNUSED call_env_parser_t const *  rule 
)
static

Definition at line 1902 of file rlm_sql.c.

+ Here is the call graph for this function:

◆ mod_authorize()

static unlang_action_t mod_authorize ( rlm_rcode_t p_result,
module_ctx_t const *  mctx,
request_t request 
)
static

Start of module authorize method.

Pushes the tmpl relating to the first required query for evaluation

Definition at line 1671 of file rlm_sql.c.

+ Here is the call graph for this function:

◆ mod_authorize_resume()

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

Resume function called after authorization check / reply tmpl expansion.

Parameters
p_resultResult of current authorization.
priorityUnused.
requestCurrent request.
uctxCurrent authorization context.
Returns
one of the RLM_MODULE_* values.

Definition at line 1516 of file rlm_sql.c.

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

◆ mod_autz_group_resume()

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

Resume function called after authorization group / profile expansion of check / reply query tmpl.

Groups and profiles are treated almost identically except:

  • groups are read from an SQL query
  • profiles are read from &control.User-Profile
  • if cache_groups is set, groups populate &control.SQL-Group

Profiles are handled after groups, and will not happend if the last group resulted in Fall-Through = no

Before each query is run, &request.SQL-Group is populated with the value of the group being evaluated.

Parameters
p_resultResult of current authorization.
priorityUnused.
requestCurrent request.
uctxCurrent authorization context.
Returns
one of the RLM_MODULE_* values.

Definition at line 1286 of file rlm_sql.c.

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

◆ mod_bootstrap()

static int mod_bootstrap ( module_inst_ctx_t const *  mctx)
static

Definition at line 2170 of file rlm_sql.c.

+ Here is the call graph for this function:

◆ mod_detach()

static int mod_detach ( module_detach_ctx_t const *  mctx)
static

Definition at line 2062 of file rlm_sql.c.

◆ mod_instantiate()

static int mod_instantiate ( module_inst_ctx_t const *  mctx)
static

Definition at line 2079 of file rlm_sql.c.

+ Here is the call graph for this function:

◆ mod_map_proc()

static unlang_action_t mod_map_proc ( rlm_rcode_t p_result,
void const *  mod_inst,
UNUSED void *  proc_inst,
request_t request,
fr_value_box_list_t *  query,
map_list_t const *  maps 
)
static

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

Parameters
p_resultResult of map expansion:
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
UNLANG_ACTION_CALCULATE_RESULT

Definition at line 863 of file rlm_sql.c.

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

◆ mod_map_resume()

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

Process the results of an SQL map query.

Parameters
[out]p_resultResult of applying the map.
[in]priorityUnused.
[in]requestCurrent request.
[in]uctxMap context.
Returns
One of UNLANG_ACTION_*

Definition at line 723 of file rlm_sql.c.

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

◆ mod_sql_redundant()

static unlang_action_t mod_sql_redundant ( rlm_rcode_t p_result,
module_ctx_t const *  mctx,
request_t request 
)
static

Generic module call for failing between a bunch of queries.

Used for accounting and send module calls

Definition at line 1866 of file rlm_sql.c.

+ Here is the call graph for this function:

◆ mod_sql_redundant_query_resume()

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

Resume function called after executing an SQL query in a redundant list of queries.

Parameters
p_resultResult of current module call.
priorityUnused.
requestCurrent request.
uctxCurrent redundant sql context.
Returns
one of the RLM_MODULE_* values.

Definition at line 1759 of file rlm_sql.c.

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

◆ mod_sql_redundant_resume()

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

Resume function called after expansion of next query in a redundant list of queries.

Parameters
p_resultResult of current module call.
priorityUnused.
requestCurrent request.
uctxCurrent redundant sql context.
Returns
one of the RLM_MODULE_* values.

Definition at line 1840 of file rlm_sql.c.

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

◆ mod_thread_detach()

static int mod_thread_detach ( module_thread_inst_ctx_t const *  mctx)
static

Definition at line 2333 of file rlm_sql.c.

◆ mod_thread_instantiate()

static int mod_thread_instantiate ( module_thread_inst_ctx_t const *  mctx)
static

Initialise thread specific data structure.

Definition at line 2314 of file rlm_sql.c.

+ Here is the call graph for this function:

◆ query_call_env_parse() [1/2]

static int query_call_env_parse ( TALLOC_CTX *  ctx,
call_env_parsed_head_t *  out,
tmpl_rules_t const *  t_rules,
CONF_ITEM cc,
call_env_ctx_t const *  cec,
call_env_parser_t const *  rule 
)
static

◆ query_call_env_parse() [2/2]

static int query_call_env_parse ( TALLOC_CTX *  ctx,
call_env_parsed_head_t *  out,
tmpl_rules_t const *  t_rules,
CONF_ITEM ci,
call_env_ctx_t const *  cec,
UNUSED call_env_parser_t const *  rule 
)
static

Definition at line 1980 of file rlm_sql.c.

+ Here is the call graph for this function:

◆ sql_autz_ctx_free()

static int sql_autz_ctx_free ( sql_autz_ctx_t to_free)
static

Definition at line 1259 of file rlm_sql.c.

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

◆ sql_box_escape()

static int sql_box_escape ( fr_value_box_t vb,
void *  uctx 
)
static

Definition at line 417 of file rlm_sql.c.

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

◆ sql_escape_func() [1/2]

static ssize_t sql_escape_func ( request_t ,
char *  out,
size_t  outlen,
char const *  in,
void *  arg 
)
static
+ Here is the caller graph for this function:

◆ sql_escape_func() [2/2]

static ssize_t sql_escape_func ( UNUSED request_t 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 912 of file rlm_sql.c.

+ Here is the call graph for this function:

◆ sql_escape_uctx_alloc()

static void * sql_escape_uctx_alloc ( UNUSED request_t request,
void const *  uctx 
)
static

Definition at line 282 of file rlm_sql.c.

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

◆ sql_get_grouplist()

static unlang_action_t sql_get_grouplist ( sql_group_ctx_t group_ctx,
trunk_t trunk,
request_t request 
)
static

Definition at line 1094 of file rlm_sql.c.

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

◆ sql_get_grouplist_resume()

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

Definition at line 1055 of file rlm_sql.c.

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

◆ sql_group_xlat_query_resume()

static xlat_action_t sql_group_xlat_query_resume ( TALLOC_CTX *  ctx,
fr_dcursor_t out,
xlat_ctx_t const *  xctx,
UNUSED request_t request,
fr_value_box_list_t *  in 
)
static

Compare list of groups returned from SQL query to xlat argument.

Called after the SQL query has completed and group list has been built.

Definition at line 1119 of file rlm_sql.c.

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

◆ sql_group_xlat_resume()

static xlat_action_t sql_group_xlat_resume ( UNUSED TALLOC_CTX *  ctx,
UNUSED fr_dcursor_t out,
xlat_ctx_t const *  xctx,
request_t request,
UNUSED fr_value_box_list_t *  in 
)
static

Run SQL query for group membership to return list of groups.

Called after group membership query tmpl is expanded

Definition at line 1149 of file rlm_sql.c.

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

◆ sql_map_verify()

static int sql_map_verify ( CONF_SECTION cs,
UNUSED void const *  mod_inst,
UNUSED void *  proc_inst,
tmpl_t const *  src,
UNUSED map_list_t const *  maps 
)
static

Definition at line 701 of file rlm_sql.c.

+ Here is the caller graph for this function:

◆ sql_redundant_ctx_free()

static int sql_redundant_ctx_free ( sql_redundant_ctx_t to_free)
static

Tidy up when freeing an SQL redundant context.

Release the connection handle and unset the SQL-User attribute.

Definition at line 1741 of file rlm_sql.c.

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

◆ sql_set_user()

static void sql_set_user ( rlm_sql_t const *  inst,
request_t request,
fr_value_box_t user 
)
static

Definition at line 1025 of file rlm_sql.c.

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

◆ sql_xlat_escape()

static int sql_xlat_escape ( request_t request,
fr_value_box_t vb,
void *  uctx 
)
static

Escape a tainted VB used as an xlat argument.

Definition at line 339 of file rlm_sql.c.

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

◆ sql_xlat_query_resume()

static xlat_action_t sql_xlat_query_resume ( TALLOC_CTX *  ctx,
fr_dcursor_t out,
xlat_ctx_t const *  xctx,
request_t request,
UNUSED fr_value_box_list_t *  in 
)
static

Definition at line 447 of file rlm_sql.c.

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

◆ sql_xlat_select_resume()

static xlat_action_t sql_xlat_select_resume ( TALLOC_CTX *  ctx,
fr_dcursor_t out,
xlat_ctx_t const *  xctx,
request_t request,
UNUSED fr_value_box_list_t *  in 
)
static

Definition at line 488 of file rlm_sql.c.

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

◆ submodule_parse()

static int submodule_parse ( TALLOC_CTX *  ctx,
void *  out,
void *  parent,
CONF_ITEM ci,
conf_parser_t const *  rule 
)
static

Definition at line 259 of file rlm_sql.c.

+ Here is the call graph for this function:

Variable Documentation

◆ accounting_method_env

const call_env_method_t accounting_method_env
static
Initial value:
= {
.env = (call_env_parser_t[]) {
}
}
#define CALL_ENV_TERMINATOR
Definition call_env.h:231
#define FR_CALL_ENV_METHOD_OUT(_inst)
Helper macro for populating the size/type fields of a call_env_method_t from the output structure typ...
Definition call_env.h:235
@ CALL_ENV_FLAG_CONCAT
If the tmpl produced multiple boxes they should be concatenated.
Definition call_env.h:76
@ CALL_ENV_FLAG_SUBSECTION
This is a subsection.
Definition call_env.h:87
#define FR_CALL_ENV_SUBSECTION_FUNC(_name, _name2, _flags, _func)
Specify a call_env_parser_t which parses a subsection using a callback function.
Definition call_env.h:407
#define FR_CALL_ENV_OFFSET(_name, _cast_type, _flags, _struct, _field)
Specify a call_env_parser_t which writes out runtime results to the specified field.
Definition call_env.h:335
Per method call config.
Definition call_env.h:175
#define CF_IDENT_ANY
Definition cf_util.h:78
@ FR_TYPE_STRING
String of printable characters.
static int logfile_call_env_parse(TALLOC_CTX *ctx, call_env_parsed_head_t *out, tmpl_rules_t const *t_rules, CONF_ITEM *cc, call_env_ctx_t const *cec, call_env_parser_t const *rule)
static int query_call_env_parse(TALLOC_CTX *ctx, call_env_parsed_head_t *out, tmpl_rules_t const *t_rules, CONF_ITEM *cc, call_env_ctx_t const *cec, call_env_parser_t const *rule)

Definition at line 212 of file rlm_sql.c.

◆ attr_expr_bool_enum

fr_dict_attr_t const* attr_expr_bool_enum
static

Definition at line 97 of file rlm_sql.c.

◆ attr_fall_through

fr_dict_attr_t const* attr_fall_through
static

Definition at line 94 of file rlm_sql.c.

◆ attr_sql_user_name

fr_dict_attr_t const* attr_sql_user_name
static

Definition at line 95 of file rlm_sql.c.

◆ attr_user_profile

fr_dict_attr_t const* attr_user_profile
static

Definition at line 96 of file rlm_sql.c.

◆ authorize_method_env

const call_env_method_t authorize_method_env
static
Initial value:
= {
.env = (call_env_parser_t[]) {
}
}
@ CALL_ENV_FLAG_PARSE_ONLY
The result of parsing will not be evaluated at runtime.
Definition call_env.h:85
#define FR_CALL_ENV_PARSE_ONLY_OFFSET(_name, _cast_type, _flags, _struct, _parse_field)
Specify a call_env_parser_t which writes out the result of the parsing phase to the field specified.
Definition call_env.h:384
#define QUERY_ESCAPE
Definition rlm_sql.c:2372

Definition at line 2377 of file rlm_sql.c.

◆ dict_freeradius

fr_dict_t const* dict_freeradius
static

Definition at line 86 of file rlm_sql.c.

◆ group_xlat_method_env

const call_env_method_t group_xlat_method_env
static

◆ module_config

const conf_parser_t module_config[]
static
Initial value:
= {
{ FR_CONF_OFFSET_TYPE_FLAGS("driver", FR_TYPE_VOID, 0, rlm_sql_t, driver_submodule), .dflt = "null",
.func = submodule_parse },
{ FR_CONF_OFFSET("server", rlm_sql_config_t, sql_server), .dflt = "" },
{ FR_CONF_OFFSET("port", rlm_sql_config_t, sql_port), .dflt = "0" },
{ FR_CONF_OFFSET("login", rlm_sql_config_t, sql_login), .dflt = "" },
{ FR_CONF_OFFSET_FLAGS("password", CONF_FLAG_SECRET, rlm_sql_config_t, sql_password), .dflt = "" },
{ FR_CONF_OFFSET("radius_db", rlm_sql_config_t, sql_db), .dflt = "radius" },
{ FR_CONF_OFFSET("read_groups", rlm_sql_config_t, read_groups), .dflt = "yes" },
{ FR_CONF_OFFSET("group_attribute", rlm_sql_config_t, group_attribute) },
{ FR_CONF_OFFSET("cache_groups", rlm_sql_config_t, cache_groups) },
{ FR_CONF_OFFSET("read_profiles", rlm_sql_config_t, read_profiles), .dflt = "yes" },
{ FR_CONF_OFFSET("open_query", rlm_sql_config_t, connect_query) },
{ FR_CONF_OFFSET("safe_characters", rlm_sql_config_t, allowed_chars), .dflt = "@abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-_: /" },
{ FR_CONF_OFFSET("query_timeout", rlm_sql_config_t, query_timeout), .dflt = "5" },
}
#define CONF_PARSER_TERMINATOR
Definition cf_parse.h:642
#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_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
#define FR_CONF_OFFSET_SUBSECTION(_name, _flags, _struct, _field, _subcs)
conf_parser_t which populates a sub-struct using a CONF_SECTION
Definition cf_parse.h:297
@ CONF_FLAG_SECRET
Only print value if debug level >= 3.
Definition cf_parse.h:422
#define FR_CONF_OFFSET_TYPE_FLAGS(_name, _type, _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:241
@ FR_TYPE_VOID
User data.
static int submodule_parse(TALLOC_CTX *ctx, void *out, void *parent, CONF_ITEM *ci, conf_parser_t const *rule)
Definition rlm_sql.c:259
conf_parser_t const trunk_config[]
Config parser definitions to populate a trunk_conf_t.
Definition trunk.c:315

Definition at line 57 of file rlm_sql.c.

◆ rlm_sql

module_rlm_t rlm_sql
Initial value:
= {
.common = {
.name = "sql",
.boot_size = sizeof(rlm_sql_boot_t),
.boot_type = "rlm_sql_boot_t",
.inst_size = sizeof(rlm_sql_t),
.config = module_config,
.bootstrap = mod_bootstrap,
.instantiate = mod_instantiate,
.detach = mod_detach,
.thread_inst_size = sizeof(rlm_sql_thread_t),
},
.method_group = {
.bindings = (module_method_binding_t[]){
{ .section = SECTION_NAME("accounting", CF_IDENT_ANY), .method = mod_sql_redundant, .method_env = &accounting_method_env },
{ .section = SECTION_NAME("authorize", CF_IDENT_ANY), .method = mod_authorize, .method_env = &authorize_method_env },
{ .section = SECTION_NAME("recv", CF_IDENT_ANY), .method = mod_authorize, .method_env = &authorize_method_env },
{ .section = SECTION_NAME("send", CF_IDENT_ANY), .method = mod_sql_redundant, .method_env = &send_method_env },
}
}
}
#define MODULE_MAGIC_INIT
Stop people using different module/library/server versions together.
Definition dl_module.h:63
static void thread_detach(UNUSED void *uctx)
Explicitly cleanup module/xlat resources.
Definition radiusd.c:149
static int thread_instantiate(TALLOC_CTX *ctx, fr_event_list_t *el, UNUSED void *uctx)
Create module and xlat per-thread instances.
Definition radiusd.c:132
static int mod_detach(module_detach_ctx_t const *mctx)
Definition rlm_sql.c:2062
static const call_env_method_t authorize_method_env
Definition rlm_sql.c:2377
static unlang_action_t mod_sql_redundant(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request)
Generic module call for failing between a bunch of queries.
Definition rlm_sql.c:1866
static int mod_bootstrap(module_inst_ctx_t const *mctx)
Definition rlm_sql.c:2170
static unlang_action_t mod_authorize(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request)
Start of module authorize method.
Definition rlm_sql.c:1671
static int mod_thread_instantiate(module_thread_inst_ctx_t const *mctx)
Initialise thread specific data structure.
Definition rlm_sql.c:2314
static const call_env_method_t accounting_method_env
Definition rlm_sql.c:212
static const conf_parser_t module_config[]
Definition rlm_sql.c:57
static const call_env_method_t send_method_env
Definition rlm_sql.c:222
static int mod_thread_detach(module_thread_inst_ctx_t const *mctx)
Definition rlm_sql.c:2333
static int mod_instantiate(module_inst_ctx_t const *mctx)
Definition rlm_sql.c:2079
#define SECTION_NAME(_name1, _name2)
Define a section name consisting of a verb and a noun.
Definition section.h:40
#define MODULE_BINDING_TERMINATOR
Terminate a module binding list.
Definition module.h:151
Named methods exported by a module.
Definition module.h:173

Definition at line 2391 of file rlm_sql.c.

◆ rlm_sql_dict

fr_dict_autoload_t rlm_sql_dict
Initial value:
= {
{ .out = &dict_freeradius, .proto = "freeradius" },
{ NULL }
}
static fr_dict_t const * dict_freeradius
Definition rlm_sql.c:86

Definition at line 89 of file rlm_sql.c.

◆ rlm_sql_dict_attr

fr_dict_attr_autoload_t rlm_sql_dict_attr
Initial value:
= {
{ .out = &attr_fall_through, .name = "Fall-Through", .type = FR_TYPE_BOOL, .dict = &dict_freeradius },
{ .out = &attr_sql_user_name, .name = "SQL-User-Name", .type = FR_TYPE_STRING, .dict = &dict_freeradius },
{ .out = &attr_user_profile, .name = "User-Profile", .type = FR_TYPE_STRING, .dict = &dict_freeradius },
{ .out = &attr_expr_bool_enum, .name = "Expr-Bool-Enum", .type = FR_TYPE_BOOL, .dict = &dict_freeradius },
{ NULL }
}
@ FR_TYPE_BOOL
A truth value.
static fr_dict_attr_t const * attr_sql_user_name
Definition rlm_sql.c:95
static fr_dict_attr_t const * attr_fall_through
Definition rlm_sql.c:94
static fr_dict_attr_t const * attr_expr_bool_enum
Definition rlm_sql.c:97
static fr_dict_attr_t const * attr_user_profile
Definition rlm_sql.c:96

Definition at line 100 of file rlm_sql.c.

◆ send_method_env

const call_env_method_t send_method_env
static

◆ xlat_method_env

const call_env_method_t xlat_method_env
static
Initial value:
= {
.env = (call_env_parser_t[]) {
.pair.escape = {
},
},
}
}
int rad_filename_box_make_safe(fr_value_box_t *vb, UNUSED void *uxtc)
Definition util.c:167
uintptr_t fr_value_box_safe_for_t
Escaping that's been applied to a value box.
Definition value.h:155

Definition at line 127 of file rlm_sql.c.