The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Macros | Functions | Variables
map.c File Reference
#include <freeradius-devel/server/exec.h>
#include <freeradius-devel/server/exec_legacy.h>
#include <freeradius-devel/server/map.h>
#include <freeradius-devel/server/paircmp.h>
#include <freeradius-devel/server/tmpl.h>
#include <freeradius-devel/server/tmpl_dcursor.h>
#include <freeradius-devel/unlang/interpret.h>
#include <freeradius-devel/util/debug.h>
#include <freeradius-devel/util/base16.h>
#include <freeradius-devel/util/pair_legacy.h>
#include <freeradius-devel/util/misc.h>
#include <freeradius-devel/protocol/radius/rfc2865.h>
#include <freeradius-devel/protocol/freeradius/freeradius.internal.h>
#include <ctype.h>
+ Include dependency graph for map.c:

Go to the source code of this file.

Macros

#define DEBUG_OVERWRITE(_old, _new)
 

Functions

static int _map_afrom_cs (TALLOC_CTX *ctx, map_list_t *out, map_t *parent, CONF_SECTION *cs, tmpl_rules_t const *lhs_rules, tmpl_rules_t const *rhs_rules, map_validate_t validate, void *uctx, unsigned int max, bool update, bool edit)
 
static int _map_list_afrom_cs (TALLOC_CTX *ctx, map_list_t *out, map_t *parent, CONF_SECTION *cs, tmpl_rules_t const *t_rules, map_validate_t validate, void *uctx, unsigned int max)
 
int map_afrom_attr_str (TALLOC_CTX *ctx, map_t **out, char const *vp_str, tmpl_rules_t const *lhs_rules, tmpl_rules_t const *rhs_rules)
 Convert a value pair string to valuepair map. More...
 
int map_afrom_cp (TALLOC_CTX *ctx, map_t **out, map_t *parent, CONF_PAIR *cp, tmpl_rules_t const *lhs_rules, tmpl_rules_t const *input_rhs_rules, bool edit)
 Convert CONFIG_PAIR (which may contain refs) to map_t. More...
 
int map_afrom_cs (TALLOC_CTX *ctx, map_list_t *out, CONF_SECTION *cs, tmpl_rules_t const *lhs_rules, tmpl_rules_t const *rhs_rules, map_validate_t validate, void *uctx, unsigned int max)
 Convert a config section into an attribute map. More...
 
int map_afrom_cs_edit (TALLOC_CTX *ctx, map_list_t *out, CONF_SECTION *cs, tmpl_rules_t const *lhs_rules, tmpl_rules_t const *rhs_rules, map_validate_t validate, void *uctx, unsigned int max)
 Convert a config section into an attribute map for editing. More...
 
int map_afrom_fields (TALLOC_CTX *ctx, map_t **out, map_t **parent_p, request_t *request, char const *lhs, char const *op_str, char const *rhs, tmpl_rules_t const *lhs_rules, tmpl_rules_t const *rhs_rules)
 Convert a fr_pair_t into a map. More...
 
ssize_t map_afrom_substr (TALLOC_CTX *ctx, map_t **out, map_t **parent_p, fr_sbuff_t *in, fr_table_num_sorted_t const *op_table, size_t op_table_len, tmpl_rules_t const *lhs_rules, tmpl_rules_t const *rhs_rules, fr_sbuff_parse_rules_t const *p_rules)
 Parse sbuff into (which may contain refs) to map_t. More...
 
int map_afrom_value_box (TALLOC_CTX *ctx, map_t **out, char const *lhs, fr_token_t lhs_quote, tmpl_rules_t const *lhs_rules, fr_token_t op, fr_value_box_t *rhs, bool steal_rhs_buffs)
 Convert a value box to a map. More...
 
int map_afrom_vp (TALLOC_CTX *ctx, map_t **out, fr_pair_t *vp, tmpl_rules_t const *rules)
 Convert a fr_pair_t into a map. More...
 
static map_tmap_alloc (TALLOC_CTX *ctx, map_t *parent)
 
void map_debug_log (request_t *request, map_t const *map, fr_pair_t const *vp)
 
static int map_exec_to_vp (TALLOC_CTX *ctx, fr_pair_list_t *out, request_t *request, map_t const *map)
 Process map which has exec as a src. More...
 
int map_list_afrom_cs (TALLOC_CTX *ctx, map_list_t *out, CONF_SECTION *cs, tmpl_rules_t const *t_rules, map_validate_t validate, void *uctx, unsigned int max)
 Convert a config section into a list of { a, b, c, d, ... More...
 
ssize_t map_print (fr_sbuff_t *out, map_t const *map)
 Print a map to a string. More...
 
int map_to_request (request_t *request, map_t const *map, radius_map_getvalue_t func, void *ctx)
 Convert map_t to fr_pair_t (s) and add them to a request_t. More...
 
int map_to_vp (TALLOC_CTX *ctx, fr_pair_list_t *out, request_t *request, map_t const *map, UNUSED void *uctx)
 Convert a map to a fr_pair_t. More...
 
static int map_value_afrom_cp (TALLOC_CTX *ctx, map_t **out, map_t *parent, CONF_PAIR *cp, tmpl_rules_t const *t_rules)
 Convert CONFIG_PAIR (which may contain refs) to map_t. More...
 

Variables

static fr_table_num_sorted_t const cond_quote_table []
 
static size_t cond_quote_table_len = NUM_ELEMENTS(cond_quote_table)
 
fr_table_num_sorted_t const map_assignment_op_table []
 
size_t map_assignment_op_table_len = NUM_ELEMENTS(map_assignment_op_table)
 
fr_sbuff_parse_rules_t const map_parse_rules_bareword_quoted
 
fr_sbuff_parse_rules_t const * map_parse_rules_quoted [T_TOKEN_LAST]
 

Macro Definition Documentation

◆ DEBUG_OVERWRITE

#define DEBUG_OVERWRITE (   _old,
  _new 
)
Value:
do {\
char *our_old; \
char *our_new; \
fr_pair_aprint_value_quoted(request, &our_old, _old, T_DOUBLE_QUOTED_STRING); \
fr_pair_aprint_value_quoted(request, &our_new, _new, T_DOUBLE_QUOTED_STRING); \
RINDENT(); \
RDEBUG3("--> overwriting %s with %s", our_old, our_new); \
REXDENT(); \
talloc_free(our_old); \
talloc_free(our_new); \
} \
} while (0)
#define RDEBUG_ENABLED3
True if request debug level 1-3 messages are enabled.
Definition: log.h:335
@ T_DOUBLE_QUOTED_STRING
Definition: token.h:121

Definition at line 1749 of file map.c.

Function Documentation

◆ _map_afrom_cs()

static int _map_afrom_cs ( TALLOC_CTX *  ctx,
map_list_t *  out,
map_t parent,
CONF_SECTION cs,
tmpl_rules_t const *  lhs_rules,
tmpl_rules_t const *  rhs_rules,
map_validate_t  validate,
void *  uctx,
unsigned int  max,
bool  update,
bool  edit 
)
static

Definition at line 750 of file map.c.

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

◆ _map_list_afrom_cs()

static int _map_list_afrom_cs ( TALLOC_CTX *  ctx,
map_list_t *  out,
map_t parent,
CONF_SECTION cs,
tmpl_rules_t const *  t_rules,
map_validate_t  validate,
void *  uctx,
unsigned int  max 
)
static

Definition at line 1165 of file map.c.

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

◆ map_afrom_attr_str()

int map_afrom_attr_str ( TALLOC_CTX *  ctx,
map_t **  out,
char const *  vp_str,
tmpl_rules_t const *  lhs_rules,
tmpl_rules_t const *  rhs_rules 
)

Convert a value pair string to valuepair map.

Takes a valuepair string with list and request qualifiers and converts it into a map_t.

Attribute string is in the format (where

<qu> 

is a quotation char ['"]):

  [<list>.][<qu>]<attribute>[<qu>] <op> [<qu>]<value>[<qu>]
Parameters
[in]ctxwhere to allocate the map.
[out]outWhere to write the new map.
[in]vp_strstring to parse.
[in]lhs_rulesrules for parsing LHS attribute references.
[in]rhs_rulesrules for parsing RHS attribute references.
Returns
  • 0 on success.
  • < 0 on error.

Definition at line 1319 of file map.c.

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

◆ map_afrom_cp()

int map_afrom_cp ( TALLOC_CTX *  ctx,
map_t **  out,
map_t parent,
CONF_PAIR cp,
tmpl_rules_t const *  lhs_rules,
tmpl_rules_t const *  input_rhs_rules,
bool  edit 
)

Convert CONFIG_PAIR (which may contain refs) to map_t.

Treats the left operand as an attribute reference

<request>.<list>.<attribute>

Treatment of left operand depends on quotation, barewords are treated as attribute references, double quoted values are treated as expandable strings, single quoted values are treated as literal strings.

Return must be freed with talloc_free

Parameters
[in]ctxfor talloc.
[in]outWhere to write the pointer to the new map_t.
[in]parentthe parent map
[in]cpto convert to map.
[in]lhs_rulesrules for parsing LHS attribute references.
[in]input_rhs_rulesrules for parsing RHS attribute references.
[in]edittreat the map as an edit
Returns
  • map_t if successful.
  • NULL on error.

Definition at line 109 of file map.c.

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

◆ map_afrom_cs()

int map_afrom_cs ( TALLOC_CTX *  ctx,
map_list_t *  out,
CONF_SECTION cs,
tmpl_rules_t const *  lhs_rules,
tmpl_rules_t const *  rhs_rules,
map_validate_t  validate,
void *  uctx,
unsigned int  max 
)

Convert a config section into an attribute map.

For "update" sections, Uses 'name2' of section to set default request and lists.

Parameters
[in]ctxfor talloc.
[out]outWhere to store the allocated map.
[in]csthe update section
[in]lhs_rulesrules for parsing LHS attribute references.
[in]rhs_rulesrules for parsing RHS attribute references.
[in]validatemap using this callback (may be NULL).
[in]uctxto pass to callback.
[in]maxnumber of mappings to process.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 1014 of file map.c.

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

◆ map_afrom_cs_edit()

int map_afrom_cs_edit ( TALLOC_CTX *  ctx,
map_list_t *  out,
CONF_SECTION cs,
tmpl_rules_t const *  lhs_rules,
tmpl_rules_t const *  rhs_rules,
map_validate_t  validate,
void *  uctx,
unsigned int  max 
)

Convert a config section into an attribute map for editing.

Parameters
[in]ctxfor talloc.
[out]outWhere to store the allocated map.
[in]csthe update section
[in]lhs_rulesrules for parsing LHS attribute references.
[in]rhs_rulesrules for parsing RHS attribute references.
[in]validatemap using this callback (may be NULL).
[in]uctxto pass to callback.
[in]maxnumber of mappings to process.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 1045 of file map.c.

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

◆ map_afrom_fields()

int map_afrom_fields ( TALLOC_CTX *  ctx,
map_t **  out,
map_t **  parent_p,
request_t request,
char const *  lhs,
char const *  op_str,
char const *  rhs,
tmpl_rules_t const *  lhs_rules,
tmpl_rules_t const *  rhs_rules 
)

Convert a fr_pair_t into a map.

Parameters
[in]ctxwhere to allocate the map.
[out]outWhere to write the new map (must be freed with talloc_free()).
[in,out]parent_pthe parent map, updated for relative maps
[in]requestthe request
[in]lhsof map
[in]op_stroperator for map
[in]rhsof map
[in]lhs_rulesfor parsing the LHS
[in]rhs_rulesfor parsing the RHS
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 2439 of file map.c.

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

◆ map_afrom_substr()

ssize_t map_afrom_substr ( TALLOC_CTX *  ctx,
map_t **  out,
map_t **  parent_p,
fr_sbuff_t in,
fr_table_num_sorted_t const *  op_table,
size_t  op_table_len,
tmpl_rules_t const *  lhs_rules,
tmpl_rules_t const *  rhs_rules,
fr_sbuff_parse_rules_t const *  p_rules 
)

Parse sbuff into (which may contain refs) to map_t.

This function uses the legacy operator meanings. The maps created here should only be used with radius_legacy_map_cmp() and radius_legacy_map_apply()

The left operand MUST be an attribute reference

<request>.<list>.<attribute>

The op_table should be #cond_cmp_op_table for check items, and map_assignment_op_table for reply items.

Return must be freed with talloc_free

Parameters
[in]ctxfor talloc.
[in]outWhere to write the pointer to the new map_t.
[in,out]parent_pthe parent map, updated for relative maps
[in]inthe data to parse for creating the map.
[in]op_tablefor lhs OP rhs
[in]op_table_lenlength of op_table
[in]lhs_rulesrules for parsing LHS attribute references.
[in]rhs_rulesrules for parsing RHS attribute references.
[in]p_rulesa list of terminals which will stop string parsing.
Returns
  • >0 on success.
  • <=0 on error.

Definition at line 427 of file map.c.

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

◆ map_afrom_value_box()

int map_afrom_value_box ( TALLOC_CTX *  ctx,
map_t **  out,
char const *  lhs,
fr_token_t  lhs_quote,
tmpl_rules_t const *  lhs_rules,
fr_token_t  op,
fr_value_box_t rhs,
bool  steal_rhs_buffs 
)

Convert a value box to a map.

This is mainly used in IO modules, where another function is used to convert between the foreign value type and internal values, and the destination attribute is provided as a string.

Parameters
[in]ctxfor talloc
[out]outWhere to store the head of the map.
[in]lhsof the operation
[in]lhs_quotetype of the LHS string
[in]lhs_rulesrules that control parsing of the LHS string.
[in]opthe operation to perform
[in]rhsof the operation
[in]steal_rhs_buffsWhether we attempt to save allocs by stealing the buffers from the rhs fr_value_box_t.
Returns
  • map_t if successful.
  • NULL on error.

Definition at line 1269 of file map.c.

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

◆ map_afrom_vp()

int map_afrom_vp ( TALLOC_CTX *  ctx,
map_t **  out,
fr_pair_t vp,
tmpl_rules_t const *  rules 
)

Convert a fr_pair_t into a map.

Parameters
[in]ctxwhere to allocate the map.
[out]outWhere to write the new map (must be freed with talloc_free()).
[in]vpto convert.
[in]rulesto insert attributes into.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 1350 of file map.c.

+ Here is the call graph for this function:

◆ map_alloc()

static map_t* map_alloc ( TALLOC_CTX *  ctx,
map_t parent 
)
inlinestatic

Definition at line 72 of file map.c.

+ Here is the caller graph for this function:

◆ map_debug_log()

void map_debug_log ( request_t request,
map_t const *  map,
fr_pair_t const *  vp 
)

Definition at line 2350 of file map.c.

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

◆ map_exec_to_vp()

static int map_exec_to_vp ( TALLOC_CTX *  ctx,
fr_pair_list_t out,
request_t request,
map_t const *  map 
)
static

Process map which has exec as a src.

Evaluate maps which specify exec as a src. This may be used by various sorts of update sections, and so has been broken out into it's own function.

Parameters
[in,out]ctxto allocate new fr_pair_t (s) in.
[out]outWhere to write the fr_pair_t (s).
[in]requeststructure (used only for talloc).
[in]mapthe map. The LHS (dst) must be TMPL_TYPE_ATTR. The RHS (src) must be TMPL_TYPE_EXEC.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 1415 of file map.c.

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

◆ map_list_afrom_cs()

int map_list_afrom_cs ( TALLOC_CTX *  ctx,
map_list_t *  out,
CONF_SECTION cs,
tmpl_rules_t const *  t_rules,
map_validate_t  validate,
void *  uctx,
unsigned int  max 
)

Convert a config section into a list of { a, b, c, d, ...

}

Parameters
[in]ctxfor talloc.
[out]outWhere to store the allocated map.
[in]csthe update section
[in]t_rulesrules for parsing the data.
[in]validatemap using this callback (may be NULL).
[in]uctxto pass to callback.
[in]maxnumber of mappings to process.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 1238 of file map.c.

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

◆ map_print()

ssize_t map_print ( fr_sbuff_t out,
map_t const *  map 
)

Print a map to a string.

Parameters
[out]outBuffer to write string to.
[in]mapto print.
Returns
  • The number of bytes written to the out buffer.
  • A number >= outlen if truncation has occurred.

Definition at line 2295 of file map.c.

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

◆ map_to_request()

int map_to_request ( request_t request,
map_t const *  map,
radius_map_getvalue_t  func,
void *  ctx 
)

Convert map_t to fr_pair_t (s) and add them to a request_t.

Takes a single map_t, resolves request and list identifiers to pointers in the current request, then attempts to retrieve module specific value(s) using callback, and adds the resulting values to the correct request/list.

Parameters
requestThe current request.
mapspecifying destination attribute and location and src identifier.
functo retrieve module specific values and convert them to fr_pair_t.
ctxto be passed to func.
Returns
  • -1 if the operation failed.
  • -2 in the source attribute wasn't valid.
  • 0 on success.

Definition at line 1781 of file map.c.

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

◆ map_to_vp()

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

Convert a map to a fr_pair_t.

Parameters
[in,out]ctxto allocate fr_pair_t (s) in.
[out]outWhere to write the fr_pair_t (s), which may be NULL if not found
[in]requestThe current request.
[in]mapthe map. The LHS (dst) has to be TMPL_TYPE_ATTR.
[in]uctxunused.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 1487 of file map.c.

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

◆ map_value_afrom_cp()

static int map_value_afrom_cp ( TALLOC_CTX *  ctx,
map_t **  out,
map_t parent,
CONF_PAIR cp,
tmpl_rules_t const *  t_rules 
)
static

Convert CONFIG_PAIR (which may contain refs) to map_t.

Treats the CONFIG_PAIR name as a value.

Treatment of left operand depends on quotation, barewords are treated as attribute , double quoted values are treated as expandable strings, single quoted values are treated as literal strings.

Return must be freed with talloc_free

Parameters
[in]ctxfor talloc.
[in]outWhere to write the pointer to the new map_t.
[in]parentthe parent map
[in]cpto convert to map.
[in]t_rulesrules for parsing name
Returns
  • map_t if successful.
  • NULL on error.

Definition at line 1076 of file map.c.

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

Variable Documentation

◆ cond_quote_table

fr_table_num_sorted_t const cond_quote_table[]
static
Initial value:
= {
}
#define L(_str)
Helper for initialising arrays of string literals.
Definition: build.h:207
@ T_SINGLE_QUOTED_STRING
Definition: token.h:122
@ T_BACK_QUOTED_STRING
Definition: token.h:123
@ T_SOLIDUS_QUOTED_STRING
Definition: token.h:124

Definition at line 50 of file map.c.

◆ cond_quote_table_len

size_t cond_quote_table_len = NUM_ELEMENTS(cond_quote_table)
static

Definition at line 56 of file map.c.

◆ map_assignment_op_table

fr_table_num_sorted_t const map_assignment_op_table[]
Initial value:
= {
{ L("!*"), T_OP_CMP_FALSE },
{ L("!="), T_OP_NE },
{ L("!~"), T_OP_REG_NE },
{ L("+="), T_OP_ADD_EQ },
{ L("-="), T_OP_SUB_EQ },
{ L(":="), T_OP_SET },
{ L("<"), T_OP_LT },
{ L("<="), T_OP_LE },
{ L("="), T_OP_EQ },
{ L("=*"), T_OP_CMP_TRUE },
{ L("=="), T_OP_CMP_EQ },
{ L("=~"), T_OP_REG_EQ },
{ L(">"), T_OP_GT },
{ L(">="), T_OP_GE }
}
@ T_OP_SUB_EQ
Definition: token.h:70
@ T_OP_CMP_TRUE
Definition: token.h:104
@ T_OP_EQ
Definition: token.h:83
@ T_OP_SET
Definition: token.h:84
@ T_OP_NE
Definition: token.h:97
@ T_OP_ADD_EQ
Definition: token.h:69
@ T_OP_CMP_FALSE
Definition: token.h:105
@ T_OP_REG_EQ
Definition: token.h:102
@ T_OP_CMP_EQ
Definition: token.h:106
@ T_OP_LE
Definition: token.h:100
@ T_OP_GE
Definition: token.h:98
@ T_OP_GT
Definition: token.h:99
@ T_OP_LT
Definition: token.h:101
@ T_OP_REG_NE
Definition: token.h:103

Definition at line 329 of file map.c.

◆ map_assignment_op_table_len

size_t map_assignment_op_table_len = NUM_ELEMENTS(map_assignment_op_table)

Definition at line 345 of file map.c.

◆ map_parse_rules_bareword_quoted

fr_sbuff_parse_rules_t const map_parse_rules_bareword_quoted

Definition at line 347 of file map.c.

◆ map_parse_rules_quoted

fr_sbuff_parse_rules_t const* map_parse_rules_quoted[T_TOKEN_LAST]
Initial value:
= {
}
fr_sbuff_parse_rules_t const map_parse_rules_bareword_quoted
Definition: map.c:347
@ T_BARE_WORD
Definition: token.h:120
fr_sbuff_parse_rules_t const value_parse_rules_solidus_quoted
Definition: value.c:559
fr_sbuff_parse_rules_t const value_parse_rules_single_quoted
Definition: value.c:553
fr_sbuff_parse_rules_t const value_parse_rules_backtick_quoted
Definition: value.c:565
fr_sbuff_parse_rules_t const value_parse_rules_double_quoted
Definition: value.c:547

Definition at line 391 of file map.c.