The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Data Structures | Macros | Typedefs | Functions | Variables
map.h File Reference

Structures and prototypes for maps. More...

#include <freeradius-devel/server/cf_util.h>
#include <freeradius-devel/server/tmpl.h>
#include <freeradius-devel/util/dlist.h>
+ Include dependency graph for map.h:

Go to the source code of this file.

Data Structures

struct  map_s
 Value pair map. More...
 
struct  vp_list_mod_s
 A list modification. More...
 

Macros

#define MAP_LHS_TERMINALS
 Single character tokens used as terminals for the LHS operand. More...
 
#define MAP_VERIFY(_x)   fr_assert((_x)->lhs)
 

Typedefs

typedef struct map_s map_t
 
typedef int(* map_validate_t) (map_t *map, void *ctx)
 
typedef int(* radius_map_getvalue_t) (TALLOC_CTX *ctx, fr_pair_list_t *out, request_t *request, map_t const *map, void *uctx)
 
typedef struct vp_list_mod_s vp_list_mod_t
 

Functions

typedef FR_DLIST_HEAD (map_list) map_list_t
 Given these are used in so many places, it's more friendly to have a proper type. More...
 
int map_afrom_attr_str (TALLOC_CTX *ctx, map_t **out, char const *raw, 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 *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, 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_type, 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...
 
void map_debug_log (request_t *request, map_t const *map, fr_pair_t const *vp))
 
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...
 
int map_list_mod_apply (request_t *request, vp_list_mod_t const *vlm)
 Apply the output of map_to_list_mod to a request. More...
 
ssize_t map_print (fr_sbuff_t *out, map_t const *map)
 Print a map to a string. More...
 
int map_to_list_mod (TALLOC_CTX *ctx, vp_list_mod_t **out, request_t *request, map_t const *map, fr_value_box_list_t *lhs_result, fr_value_box_list_t *rhs_result)
 Evaluate a map creating a new map with TMPL_TYPE_ATTR LHS and TMPL_TYPE_DATA RHS. 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, void *uctx))
 

Variables

fr_table_num_sorted_t const map_assignment_op_table []
 
size_t map_assignment_op_table_len
 
fr_sbuff_parse_rules_t const map_parse_rules_bareword_quoted
 
fr_sbuff_parse_rules_t const * map_parse_rules_quoted [T_TOKEN_LAST]
 

Detailed Description

Structures and prototypes for maps.

Id
cb19772b01ddb2110203d35c80118ac2c86d2d9e

Definition in file map.h.


Data Structure Documentation

◆ vp_list_mod_s

struct vp_list_mod_s

A list modification.

Definition at line 99 of file map.h.

+ Collaboration diagram for vp_list_mod_s:
Data Fields
fr_dlist_t entry Entry into dlist.
map_t const * map Original map describing the change to be made.
map_list_t mod New map containing the destination (LHS) and values (RHS).

Macro Definition Documentation

◆ MAP_LHS_TERMINALS

#define MAP_LHS_TERMINALS
Value:
['-'] = true, \
[':'] = true, \
['+'] = true, \
['<'] = true, \
['='] = true, \
['>'] = true, \
['~'] = true

Single character tokens used as terminals for the LHS operand.

Definition at line 51 of file map.h.

◆ MAP_VERIFY

#define MAP_VERIFY (   _x)    fr_assert((_x)->lhs)

Definition at line 108 of file map.h.

Typedef Documentation

◆ map_t

typedef struct map_s map_t

Definition at line 1 of file map.h.

◆ map_validate_t

typedef int(* map_validate_t) (map_t *map, void *ctx)

Definition at line 116 of file map.h.

◆ radius_map_getvalue_t

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

Definition at line 117 of file map.h.

◆ vp_list_mod_t

typedef struct vp_list_mod_s vp_list_mod_t

Definition at line 1 of file map.h.

Function Documentation

◆ FR_DLIST_HEAD()

typedef FR_DLIST_HEAD ( map_list  )

Given these are used in so many places, it's more friendly to have a proper type.

◆ 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_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_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_list_mod_apply()

int map_list_mod_apply ( request_t request,
vp_list_mod_t const *  vlm 
)

Apply the output of map_to_list_mod to a request.

Parameters
requestto modify.
vlmVP List Modification to apply.

Definition at line 922 of file map_async.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_list_mod()

int map_to_list_mod ( TALLOC_CTX *  ctx,
vp_list_mod_t **  out,
request_t request,
map_t const *  original,
fr_value_box_list_t *  lhs_result,
fr_value_box_list_t *  rhs_result 
)

Evaluate a map creating a new map with TMPL_TYPE_ATTR LHS and TMPL_TYPE_DATA RHS.

This function creates maps for consumption by map_to_request.

Parameters
[in,out]ctxto allocate modification maps in.
[out]outWhere to write the fr_pair_t (s), which may be NULL if not found
[in]requestThe current request.
[in]originalthe map. The LHS (dst) has to be TMPL_TYPE_ATTR.
[in]lhs_resultof previous stack based rhs evaluation. Must be provided for rhs types:
  • TMPL_TYPE_XLAT
  • TMPL_TYPE_EXEC (in future)
[in]rhs_resultof previous stack based rhs evaluation. Must be provided for rhs types:
  • TMPL_TYPE_XLAT
  • TMPL_TYPE_EXEC (in future) Once this function returns result will be invalidated even if this function errors.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 251 of file map_async.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,
void *  uctx 
)

Variable Documentation

◆ map_assignment_op_table

fr_table_num_sorted_t const map_assignment_op_table[]
extern

Definition at line 329 of file map.c.

◆ map_assignment_op_table_len

size_t map_assignment_op_table_len
extern

Definition at line 345 of file map.c.

◆ map_parse_rules_bareword_quoted

fr_sbuff_parse_rules_t const map_parse_rules_bareword_quoted
extern

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]
extern

Definition at line 391 of file map.c.