The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Macros | Functions | Variables
tmpl_eval.c File Reference

fr_pair_t template functions More...

#include <freeradius-devel/server/exec.h>
#include <freeradius-devel/server/exec_legacy.h>
#include <freeradius-devel/server/tmpl.h>
#include <freeradius-devel/server/tmpl_dcursor.h>
#include <freeradius-devel/server/client.h>
#include <freeradius-devel/unlang/call.h>
#include <freeradius-devel/util/dlist.h>
#include <freeradius-devel/util/proto.h>
#include <freeradius-devel/util/value.h>
#include <freeradius-devel/util/edit.h>
#include <freeradius-devel/util/token.h>
#include <freeradius-devel/util/types.h>
#include <talloc.h>
+ Include dependency graph for tmpl_eval.c:

Go to the source code of this file.

Macros

#define _TMPL_PRIVATE   1
 

Functions

ssize_t _tmpl_to_atype (TALLOC_CTX *ctx, void *out, request_t *request, tmpl_t const *vpt, xlat_escape_legacy_t escape, void const *escape_ctx, fr_type_t dst_type)
 Expand a template to a string, allocing a new buffer to hold the string. More...
 
ssize_t _tmpl_to_type (void *out, uint8_t *buff, size_t bufflen, request_t *request, tmpl_t const *vpt, xlat_escape_legacy_t escape, void const *escape_ctx, fr_type_t dst_type)
 Expand a tmpl_t to a string writing the result to a buffer. More...
 
 if (!vpt->rules.escape.func &&vpt->rules.escape.safe_for)
 
 if ((!did_concat &&tmpl_escape_pre_concat(vpt))||tmpl_escape_post_concat(vpt))
 
int pair_append_by_tmpl_parent (TALLOC_CTX *ctx, fr_pair_t **out, fr_pair_list_t *list, tmpl_t const *vpt, bool skip_list)
 Allocate and insert a leaf vp from a tmpl_t, building the parent vps if needed. More...
 
int tmpl_copy_pair_children (TALLOC_CTX *ctx, fr_pair_list_t *out, request_t *request, tmpl_t const *vpt)
 Copy children of pairs matching a tmpl_t in the current request_t. More...
 
int tmpl_copy_pairs (TALLOC_CTX *ctx, fr_pair_list_t *out, request_t *request, tmpl_t const *vpt)
 Copy pairs matching a tmpl_t in the current request_t. More...
 
int tmpl_eval (TALLOC_CTX *ctx, fr_value_box_list_t *out, request_t *request, tmpl_t const *vpt)
 Gets the value of a tmpl. More...
 
int tmpl_eval_cast_in_place (fr_value_box_list_t *list, request_t *request, tmpl_t const *vpt)
 Casts a value or list of values according to the tmpl. More...
 
static void * tmpl_eval_escape_uctx_alloc (request_t *request, tmpl_escape_t const *escape)
 Allocate a uctx for an escaping function. More...
 
static void tmpl_eval_escape_uctx_free (tmpl_escape_t const *escape, void *uctx)
 Free a uctx for an escaping function. More...
 
int tmpl_eval_pair (TALLOC_CTX *ctx, fr_value_box_list_t *out, request_t *request, tmpl_t const *vpt)
 Gets the value of a real or virtual attribute. More...
 
fr_type_t tmpl_expanded_type (tmpl_t const *vpt)
 Return the native data type of the expression. More...
 
int tmpl_find_or_add_vp (fr_pair_t **out, request_t *request, tmpl_t const *vpt)
 Returns the first VP matching a tmpl_t, or if no VPs match, creates a new one. More...
 
int tmpl_find_vp (fr_pair_t **out, request_t *request, tmpl_t const *vpt)
 Returns the first VP matching a tmpl_t. More...
 
void tmpl_global_free (void)
 
int tmpl_global_init (void)
 
TALLOC_CTX * tmpl_list_ctx (request_t *request, fr_dict_attr_t const *list)
 Return the correct TALLOC_CTX to alloc fr_pair_t in, for a list. More...
 
fr_pair_list_ttmpl_list_head (request_t *request, fr_dict_attr_t const *list)
 Resolve attribute fr_pair_list_t value to an attribute list. More...
 
fr_packet_ttmpl_packet_ptr (request_t *request, fr_dict_attr_t const *list)
 Resolve a list to the fr_packet_t holding the HEAD pointer for a fr_pair_t list. More...
 
int tmpl_request_ptr (request_t **context, FR_DLIST_HEAD(tmpl_request_list) const *rql)
 Resolve a tmpl_request_ref_t to a request_t. More...
 
int tmpl_value_list_insert_tail (fr_value_box_list_t *list, fr_value_box_t *box, tmpl_t const *vpt)
 Insert a value-box to a list, with casting. More...
 
 VALUE_BOX_LIST_VERIFY (list)
 

Variables

static fr_dict_t const * dict_freeradius
 
static fr_dict_t const * dict_radius
 
goto success
 
fr_dict_attr_t const * tmpl_attr_unspec
 Placeholder attribute for uses of unspecified attribute references. More...
 
fr_dict_autoload_t tmpl_dict []
 

Detailed Description

fr_pair_t template functions

Id
c34ce3a43289c510402048a04e4453367cf5b014

Definition in file tmpl_eval.c.

Macro Definition Documentation

◆ _TMPL_PRIVATE

#define _TMPL_PRIVATE   1

Definition at line 29 of file tmpl_eval.c.

Function Documentation

◆ _tmpl_to_atype()

ssize_t _tmpl_to_atype ( TALLOC_CTX *  ctx,
void *  out,
request_t request,
tmpl_t const *  vpt,
xlat_escape_legacy_t  escape,
void const *  escape_ctx,
fr_type_t  dst_type 
)

Expand a template to a string, allocing a new buffer to hold the string.

The intended use of tmpl_expand and tmpl_aexpand is for modules to easily convert a tmpl_t provided by the conf parser, into a usable value. The value returned should be raw and undoctored for FR_TYPE_STRING and FR_TYPE_OCTETS types, and the printable (string) version of the data for all others.

This function will always duplicate values, whereas tmpl_expand may return a pointer to an existing buffer.

Note
This function is used where raw string values are needed, which may mean the string returned may be binary data or contain unprintable chars. fr_snprint or fr_asprint should be used before using these values in debug statements. is_printable can be used to check if the string only contains printable chars.
The type (char or uint8_t) can be obtained with talloc_get_type, and may be used as a hint as to how to process or print the data.
Parameters
ctxto allocate new buffer in.
outWhere to write pointer to the new buffer.
requestCurrent request.
vptto expand. Must be one of the following types:
escapexlat escape function (only used for TMPL_TYPE_XLAT_UNRESOLVED_* types).
escape_ctxxlat escape function data (only used for TMPL_TYPE_XLAT_UNRESOLVED_* types).
dst_typeFR_TYPE_* matching out pointer.
See also
tmpl_aexpand.
Returns
  • -1 on failure.
  • The length of data written to buff, or pointed to by out.

Definition at line 561 of file tmpl_eval.c.

+ Here is the call graph for this function:

◆ _tmpl_to_type()

ssize_t _tmpl_to_type ( void *  out,
uint8_t buff,
size_t  bufflen,
request_t request,
tmpl_t const *  vpt,
xlat_escape_legacy_t  escape,
void const *  escape_ctx,
fr_type_t  dst_type 
)

Expand a tmpl_t to a string writing the result to a buffer.

The intended use of tmpl_expand and tmpl_aexpand is for modules to easily convert a tmpl_t provided by the conf parser, into a usable value. The value returned should be raw and undoctored for FR_TYPE_STRING and FR_TYPE_OCTETS types, and the printable (string) version of the data for all others.

Depending what arguments are passed, either copies the value to buff, or writes a pointer to a string buffer to out. This allows the most efficient access to the value resolved by the tmpl_t, avoiding unnecessary string copies.

Note
This function is used where raw string values are needed, which may mean the string returned may be binary data or contain unprintable chars. fr_snprint or fr_asprint should be used before using these values in debug statements. is_printable can be used to check if the string only contains printable chars.
Parameters
[out]outWhere to write a pointer to the string buffer. On return may point to buff if buff was used to store the value. Otherwise will point to a fr_value_box_t buffer, or the name of the template. Must not be NULL.
[out]buffExpansion buffer, may be NULL except for the following types:
[in]bufflenLength of expansion buffer. Must be >= 2.
[in]requestCurrent request.
[in]vptto expand. Must be one of the following types:
[in]escapexlat escape function (only used for xlat types).
[in]escape_ctxxlat escape function data.
dst_typeFR_TYPE_* matching out pointer.
See also
tmpl_expand.
Returns
  • -1 on failure.
  • The length of data written out.

Definition at line 282 of file tmpl_eval.c.

+ Here is the call graph for this function:

◆ if() [1/2]

if ( !vpt->rules.escape.func &&vpt->rules.escape.  safe_for)

Definition at line 1444 of file tmpl_eval.c.

+ Here is the call graph for this function:

◆ if() [2/2]

Definition at line 1428 of file tmpl_eval.c.

+ Here is the call graph for this function:

◆ pair_append_by_tmpl_parent()

int pair_append_by_tmpl_parent ( TALLOC_CTX *  ctx,
fr_pair_t **  out,
fr_pair_list_t list,
tmpl_t const *  vpt,
bool  skip_list 
)

Allocate and insert a leaf vp from a tmpl_t, building the parent vps if needed.

This is the simple case - just add a vp at the first place where the parents exist, or create the parents, with no attempt to handle filters.

It is functionally equivalent to fr_pair_append_by_da_parent() but uses a tmpl_t to build the nested structure rather than a fr_dict_attr_t.

Parameters
[in]ctxto allocate new pair(s) in
[out]outLeaf pair we allocated.
[in]listto insert into.
[in]vpttmpl representing the attribute to add.
[in]skip_listskip list attr ref at the head of the tmpl.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 972 of file tmpl_eval.c.

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

◆ tmpl_copy_pair_children()

int tmpl_copy_pair_children ( TALLOC_CTX *  ctx,
fr_pair_list_t out,
request_t request,
tmpl_t const *  vpt 
)

Copy children of pairs matching a tmpl_t in the current request_t.

Parameters
ctxto allocate new fr_pair_t in.
outWhere to write the copied fr_pair_t (s).
requestThe current request_t.
vptspecifying the fr_pair_t type or list to copy. Must be one of the following types:
Returns
  • -1 if no matching fr_pair_t could be found.
  • -2 if list could not be found (doesn't exist in current request_t).
  • -3 if context could not be found (no parent request_t available).
  • -4 on memory allocation error.

Definition at line 839 of file tmpl_eval.c.

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

◆ tmpl_copy_pairs()

int tmpl_copy_pairs ( TALLOC_CTX *  ctx,
fr_pair_list_t out,
request_t request,
tmpl_t const *  vpt 
)

Copy pairs matching a tmpl_t in the current request_t.

Parameters
ctxto allocate new fr_pair_t in.
outWhere to write the copied fr_pair_t (s).
requestThe current request_t.
vptspecifying the fr_pair_t type or list to copy. Must be one of the following types:
Returns
  • -1 if no matching fr_pair_t could be found.
  • -2 if list could not be found (doesn't exist in current request_t).
  • -3 if context could not be found (no parent request_t available).
  • -4 on memory allocation error.

Definition at line 796 of file tmpl_eval.c.

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

◆ tmpl_eval()

int tmpl_eval ( TALLOC_CTX *  ctx,
fr_value_box_list_t *  out,
request_t request,
tmpl_t const *  vpt 
)

Gets the value of a tmpl.

The result is returned "raw". The caller must do any escaping it desires.

Parameters
[in]ctxto allocate boxed value, and buffers in.
[out]outWhere to write the boxed value.
[in]requestThe current request.
[in]vptRepresenting the tmpl
Returns
  • <0 we failed getting a value for the tmpl
  • 0 we successfully evaluated the tmpl

Definition at line 1216 of file tmpl_eval.c.

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

◆ tmpl_eval_cast_in_place()

int tmpl_eval_cast_in_place ( fr_value_box_list_t *  list,
request_t request,
tmpl_t const *  vpt 
)

Casts a value or list of values according to the tmpl.

Parameters
[in,out]listWhere to write the boxed value.
[in]requestThe current request.
[in]vptRepresenting the attribute.
Returns
  • <0 the cast failed
  • 0 we successfully evaluated the tmpl

Definition at line 1344 of file tmpl_eval.c.

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

◆ tmpl_eval_escape_uctx_alloc()

static void* tmpl_eval_escape_uctx_alloc ( request_t request,
tmpl_escape_t const *  escape 
)
inlinestatic

Allocate a uctx for an escaping function.

Parameters
[in]requestThe current request.
[in]escapeDescribing how to escape tmpl data.
Returns
the uctx to pass to the escape function.

Definition at line 1288 of file tmpl_eval.c.

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

◆ tmpl_eval_escape_uctx_free()

static void tmpl_eval_escape_uctx_free ( tmpl_escape_t const *  escape,
void *  uctx 
)
inlinestatic

Free a uctx for an escaping function.

Parameters
[in]escapeDescribing how to escape tmpl data.
[in]uctxThe uctx to free.

Definition at line 1319 of file tmpl_eval.c.

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

◆ tmpl_eval_pair()

int tmpl_eval_pair ( TALLOC_CTX *  ctx,
fr_value_box_list_t *  out,
request_t request,
tmpl_t const *  vpt 
)

Gets the value of a real or virtual attribute.

Parameters
[in]ctxto allocate boxed value, and buffers in.
[out]outWhere to write the boxed value.
[in]requestThe current request.
[in]vptRepresenting the attribute.
Returns
  • <0 we failed getting a value for the attribute.
  • 0 we successfully evaluated the tmpl

Definition at line 1075 of file tmpl_eval.c.

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

◆ tmpl_expanded_type()

fr_type_t tmpl_expanded_type ( tmpl_t const *  vpt)

Return the native data type of the expression.

Parameters
[in]vptto determine the type of.
Returns
  • FR_TYPE_NULL if the type of the tmpl_t can't be determined.
  • The data type we'd expect the tmpl_t to produce at runtime when expanded.

Definition at line 207 of file tmpl_eval.c.

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

◆ tmpl_find_or_add_vp()

int tmpl_find_or_add_vp ( fr_pair_t **  out,
request_t request,
tmpl_t const *  vpt 
)

Returns the first VP matching a tmpl_t, or if no VPs match, creates a new one.

Parameters
[out]outwhere to write the retrieved or created vp.
[in]requestThe current request_t.
[in]vptspecifying the fr_pair_t type to retrieve or create. Must be TMPL_TYPE_ATTR.
Returns
  • 1 on success a pair was created.
  • 0 on success a pair was found.
  • -1 if a new fr_pair_t couldn't be found or created.
  • -2 if list could not be found (doesn't exist in current request_t).
  • -3 if context could not be found (no parent request_t available).

Definition at line 916 of file tmpl_eval.c.

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

◆ tmpl_find_vp()

int tmpl_find_vp ( fr_pair_t **  out,
request_t request,
tmpl_t const *  vpt 
)

Returns the first VP matching a tmpl_t.

Parameters
[out]outwhere to write the retrieved vp.
[in]requestThe current request_t.
[in]vptspecifying the fr_pair_t type to find. Must be one of the following types:
Returns
  • 0 on success (found matching fr_pair_t).
  • -1 if no matching fr_pair_t could be found.
  • -2 if list could not be found (doesn't exist in current request_t).
  • -3 if context could not be found (no parent request_t available).

Definition at line 887 of file tmpl_eval.c.

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

◆ tmpl_global_free()

void tmpl_global_free ( void  )

Definition at line 1471 of file tmpl_eval.c.

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

◆ tmpl_global_init()

int tmpl_global_init ( void  )

Definition at line 1453 of file tmpl_eval.c.

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

◆ tmpl_list_ctx()

TALLOC_CTX* tmpl_list_ctx ( request_t request,
fr_dict_attr_t const *  list 
)

Return the correct TALLOC_CTX to alloc fr_pair_t in, for a list.

Allocating new fr_pair_t in the context of a request_t is usually wrong. fr_pair_t should be allocated in the context of a fr_packet_t, so that if the fr_packet_t is freed before the request_t, the associated fr_pair_t lists are freed too.

Parameters
[in]requestcontaining the target lists.
[in]listfr_pair_list_t value to resolve to TALLOC_CTX.
Returns
  • TALLOC_CTX on success.
  • NULL on failure.
See also
tmpl_pair_list

Definition at line 114 of file tmpl_eval.c.

+ Here is the caller graph for this function:

◆ tmpl_list_head()

fr_pair_list_t* tmpl_list_head ( request_t request,
fr_dict_attr_t const *  list 
)

Resolve attribute fr_pair_list_t value to an attribute list.

The value returned is a pointer to the pointer of the HEAD of a fr_pair_t list in the request_t. If the head of the list changes, the pointer will still be valid.

Parameters
[in]requestcontaining the target lists.
[in]listfr_pair_list_t value to resolve to fr_pair_t list. Will be NULL if list name couldn't be resolved.
Returns
a pointer to the HEAD of a list in the request_t.
See also
tmpl_dcursor_init

Definition at line 74 of file tmpl_eval.c.

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

◆ tmpl_packet_ptr()

fr_packet_t* tmpl_packet_ptr ( request_t request,
fr_dict_attr_t const *  list 
)

Resolve a list to the fr_packet_t holding the HEAD pointer for a fr_pair_t list.

Returns a pointer to the fr_packet_t that holds the HEAD pointer of a given list, for the current request_t.

Parameters
[in]requestTo resolve list in.
[in]listfr_pair_list_t value to resolve to fr_packet_t.
Returns
See also
tmpl_pair_list

Definition at line 144 of file tmpl_eval.c.

◆ tmpl_request_ptr()

int tmpl_request_ptr ( request_t **  context,
FR_DLIST_HEAD(tmpl_request_list) const *  rql 
)

Resolve a tmpl_request_ref_t to a request_t.

Sometimes request_t structs may be chained to each other, as is the case when internally proxying EAP. This function resolves a tmpl_request_ref_t to a request_t higher in the chain than the current request_t.

See also
tmpl_pair_list
Parameters
[in,out]contextrequest_t to start resolving from, and where to write a pointer to the resolved request_t back to.
[in]rqllist of request qualifiers to follow.
Returns
  • 0 if request is valid in this context.
  • -1 if request is not valid in this context.

Definition at line 167 of file tmpl_eval.c.

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

◆ tmpl_value_list_insert_tail()

int tmpl_value_list_insert_tail ( fr_value_box_list_t *  list,
fr_value_box_t box,
tmpl_t const *  vpt 
)

Insert a value-box to a list, with casting.

Parameters
listto append to
boxbox to cast / append
vpttmpl with cast.
Returns
  • <0 for "cast failed"
  • 0 for success

Definition at line 1050 of file tmpl_eval.c.

+ Here is the call graph for this function:

◆ VALUE_BOX_LIST_VERIFY()

VALUE_BOX_LIST_VERIFY ( list  )
+ Here is the caller graph for this function:

Variable Documentation

◆ dict_freeradius

fr_dict_t const* dict_freeradius
static

Definition at line 46 of file tmpl_eval.c.

◆ dict_radius

fr_dict_t const* dict_radius
static

Definition at line 47 of file tmpl_eval.c.

◆ success

goto success

Definition at line 1450 of file tmpl_eval.c.

◆ tmpl_attr_unspec

fr_dict_attr_t const * tmpl_attr_unspec

Placeholder attribute for uses of unspecified attribute references.

Definition at line 59 of file tmpl_eval.c.

◆ tmpl_dict

fr_dict_autoload_t tmpl_dict
Initial value:
= {
{ .out = &dict_freeradius, .proto = "freeradius" },
{ .out = &dict_radius, .proto = "radius" },
{ NULL }
}
static fr_dict_t const * dict_freeradius
Definition: tmpl_eval.c:46
static fr_dict_t const * dict_radius
Definition: tmpl_eval.c:47

Definition at line 50 of file tmpl_eval.c.