28RCSID(
"$Id: a25cb00f2919c50c33b40f4b17080451cd62c80c $")
30#include <freeradius-devel/server/base.h>
31#include <freeradius-devel/server/map.h>
32#include <freeradius-devel/unlang/tmpl.h>
33#include <freeradius-devel/unlang/map.h>
60#define MAP_CTX(_mod_inst, _map_inst, _rctx) &(map_ctx_t){ .moi = _mod_inst, .mpi = _map_inst, .rctx = _rctx }
163 fr_value_box_list_init(&map_proc_state->
src_result);
178 request,
inst->src, NULL, NULL) < 0) {
179 REDEBUG(
"Failed expanding map src");
183 fr_value_box_list_insert_head(&map_proc_state->
src_result, src_result);
244 quoted_str = talloc_array(g,
char, quoted_len);
268 switch (map->
lhs->type) {
275 cf_log_err(map->
ci,
"Left side of map must be an attribute "
276 "or an xlat (that expands to an attribute), not a %s",
281 switch (map->
rhs->type) {
291 cf_log_err(map->
ci,
"Right side of map must be an attribute, literal, xlat or exec, got type %s",
297 cf_log_err(map->
ci,
"Invalid operator \"%s\" in map section. "
298 "Only assignment or filter operators are allowed",
316 char const *tmpl_str;
336 cf_log_err(cs,
"'map' sections require a 'modules' section");
342 cf_log_err(cs,
"Failed to find map processor '%s'", name2);
367 &
FR_SBUFF_IN(tmpl_str, talloc_array_length(tmpl_str) - 1),
394 cf_log_err(cs,
"Invalid third argument for map");
402 map_list_init(&gext->
map);
404 if (rcode < 0)
return NULL;
405 if (map_list_empty(&gext->
map)) {
406 cf_log_err(cs,
"'map' sections cannot be empty");
417 cf_log_err(cs,
"Failed instantiating map function '%s'", name2);
451 .unlang_name =
"unlang_map_t",
454 .frame_state_type =
"unlang_frame_state_map_proc_t",
unlang_action_t
Returned by unlang_op_t calls, determine the next action of the interpreter.
@ UNLANG_ACTION_PUSHED_CHILD
unlang_t pushed a new child onto the stack, execute it instead of continuing.
@ UNLANG_ACTION_STOP_PROCESSING
Break out of processing the current request (unwind).
@ UNLANG_ACTION_CALCULATE_RESULT
Calculate a new section rlm_rcode_t value.
@ UNLANG_ACTION_YIELD
Temporarily pause execution until an event occurs.
#define RULES_VERIFY(_cs, _rules)
Common header for all CONF_* types.
A section grouping multiple CONF_PAIR.
fr_token_t cf_section_argv_quote(CONF_SECTION const *cs, int argc)
Return the quoting for one of the variadic arguments.
char const * cf_section_name2(CONF_SECTION const *cs)
Return the second identifier of a CONF_SECTION.
CONF_SECTION * cf_section_find(CONF_SECTION const *cs, char const *name1, char const *name2)
Find a CONF_SECTION with name1 and optionally name2.
CONF_SECTION * cf_item_to_section(CONF_ITEM const *ci)
Cast a CONF_ITEM to a CONF_SECTION.
char const * cf_section_argv(CONF_SECTION const *cs, int argc)
Return variadic argument at the specified index.
#define cf_log_err(_cf, _fmt,...)
#define cf_log_perr(_cf, _fmt,...)
bool pass2_fixup_map_rhs(unlang_group_t *g, tmpl_rules_t const *rules)
unlang_group_t * unlang_group_allocate(unlang_t *parent, CONF_SECTION *cs, unlang_type_t type)
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.
static TALLOC_CTX * unlang_ctx
void unlang_register(unlang_op_t *op)
Register an operation with the interpreter.
map_proc_func_t resume
resumption handler
unlang_action_t unlang_map_yield(request_t *request, map_proc_func_t resume, unlang_map_signal_t signal, fr_signal_t sigmask, void *rctx)
Yield a request back to the interpreter from within a module.
static int fixup_map_cb(map_t *map, UNUSED void *ctx)
Validate and fixup a map that's part of an map section.
static unlang_t * unlang_compile_map(unlang_t *parent, unlang_compile_ctx_t *unlang_ctx, CONF_ITEM const *ci)
fr_signal_t sigmask
Signals to block.
static int compile_map_name(unlang_group_t *g)
void unlang_map_init(void)
static unlang_action_t map_proc_resume(unlang_result_t *p_result, request_t *request, UNUSED unlang_stack_frame_t *frame)
void * rctx
for resume / signal
static unlang_action_t map_proc_apply(unlang_result_t *p_result, request_t *request, unlang_stack_frame_t *frame)
static unlang_action_t unlang_map_state_init(unlang_result_t *p_result, request_t *request, unlang_stack_frame_t *frame)
unlang_map_signal_t signal
for signal handlers
#define MAP_CTX(_mod_inst, _map_inst, _rctx)
Wrapper to create a map_ctx_t as a compound literal.
fr_value_box_list_t src_result
Result of expanding the map source.
map and unlang integration.
static char * stack[MAX_STACK]
map_proc_inst_t * proc_inst
static unlang_map_t * unlang_group_to_map(unlang_group_t *g)
Cast a group structure to the map keyword extension.
map_list_t map
Head of the map list.
map_proc_t * map_proc_find(char const *name)
Find a map processor by name.
map_proc_inst_t * map_proc_instantiate(TALLOC_CTX *ctx, map_proc_t const *proc, CONF_SECTION *cs, tmpl_t const *src, map_list_t const *maps)
Create a new map proc instance.
fr_value_box_safe_for_t map_proc_literals_safe_for(map_proc_t const *proc)
unlang_action_t(* map_proc_func_t)(unlang_result_t *p_result, map_ctx_t const *mpctx, request_t *request, fr_value_box_list_t *result, map_list_t const *maps)
Function to evaluate the src string and map the result to server attributes.
Map processor registration.
size_t fr_snprint(char *out, size_t outlen, char const *in, ssize_t inlen, char quote)
Escape any non printable or non-UTF8 characters in the input string.
size_t fr_snprint_len(char const *in, ssize_t inlen, char quote)
Find the length of the buffer required to fully escape a string with fr_prints.
#define RETURN_UNLANG_FAIL
#define REQUEST_VERIFY(_x)
#define FR_SBUFF_IN(_start, _len_or_end)
static char const * tmpl_type_to_str(tmpl_type_t type)
Return a static string containing the type name.
fr_value_box_safe_for_t literals_safe_for
safe_for value assigned to literal values in xlats, execs, and data.
@ TMPL_TYPE_REGEX_UNCOMPILED
Regex where compilation is possible but hasn't been performed yet.
@ TMPL_TYPE_ATTR_UNRESOLVED
An attribute reference that we couldn't resolve but looked valid.
@ TMPL_TYPE_ATTR
Reference to one or more attributes.
@ TMPL_TYPE_XLAT
Pre-parsed xlat expansion.
@ TMPL_TYPE_EXEC
Callout to an external script or program.
@ TMPL_TYPE_REGEX_XLAT_UNRESOLVED
A regular expression with unresolved xlat functions or attribute references.
@ TMPL_TYPE_DATA
Value in native boxed format.
@ TMPL_TYPE_REGEX
Compiled (and possibly JIT'd) regular expression.
@ TMPL_TYPE_DATA_UNRESOLVED
Unparsed literal string.
@ TMPL_TYPE_XLAT_UNRESOLVED
A xlat expansion with unresolved xlat functions or attribute references.
@ TMPL_TYPE_REGEX_XLAT
A regex containing xlat expansions.
@ TMPL_TYPE_EXEC_UNRESOLVED
An exec with unresolved xlat function or attribute references.
ssize_t tmpl_afrom_substr(TALLOC_CTX *ctx, tmpl_t **out, fr_sbuff_t *in, fr_token_t quote, fr_sbuff_parse_rules_t const *p_rules, tmpl_rules_t const *t_rules))
Convert an arbitrary string into a tmpl_t.
tmpl_attr_rules_t attr
Rules/data for parsing attribute references.
#define tmpl_aexpand(_ctx, _out, _request, _vpt, _escape, _escape_ctx)
Expand a tmpl to a C type, allocing a new buffer to hold the string.
Optional arguments passed to vp_tmpl functions.
fr_signal_t
Signals that can be generated/processed by request signal handlers.
eap_aka_sim_process_conf_t * inst
fr_aka_sim_id_type_t type
eap_type_t type
The preferred EAP-Type of this instance of the EAP-SIM/AKA/AKA' state machine.
fr_token_t op
The operator that controls insertion of the dst attribute.
tmpl_t * lhs
Typically describes the attribute to add, modify or compare.
tmpl_t * rhs
Typically describes a literal value or a src attribute to copy or compare.
CONF_ITEM * ci
Config item that the map was created from.
uint8_t disallow_rhs_resolve
map RHS is NOT immediately resolved in the context of the LHS.
#define fr_table_str_by_value(_table, _number, _def)
Convert an integer to a string.
char * talloc_typed_asprintf(TALLOC_CTX *ctx, char const *fmt,...)
Call talloc vasprintf, setting the type on the new chunk correctly.
int unlang_tmpl_push(TALLOC_CTX *ctx, unlang_result_t *p_result, fr_value_box_list_t *out, request_t *request, tmpl_t const *tmpl, unlang_tmpl_args_t *args, bool top_frame)
Push a tmpl onto the stack for evaluation.
const bool fr_assignment_op[T_TOKEN_LAST]
fr_table_num_ordered_t const fr_tokens_table[]
const bool fr_comparison_op[T_TOKEN_LAST]
void(* unlang_map_signal_t)(map_ctx_t const *mpctx, request_t *request, fr_signal_t action)
A callback when the request gets a fr_signal_t.
int unlang_xlat_push(TALLOC_CTX *ctx, unlang_result_t *p_result, fr_value_box_list_t *out, request_t *request, xlat_exp_head_t const *xlat, bool top_frame)
Push a pre-compiled xlat onto the stack for evaluation.
char const * debug_name
Printed in log messages when the node is executed.
void * state
Stack frame specialisations.
static unlang_t * unlang_group_to_generic(unlang_group_t const *p)
static unlang_group_t * unlang_generic_to_group(unlang_t const *p)
char const * name
Unknown...
@ UNLANG_TYPE_MAP
Mapping section (like #UNLANG_TYPE_UPDATE, but uses values from a map_proc_t call).
static void frame_repeat(unlang_stack_frame_t *frame, unlang_process_t process)
Mark the current stack frame up for repeat, and set a new process function.
unlang_t const * instruction
The unlang node we're evaluating.
@ UNLANG_OP_FLAG_RCODE_SET
Set request->rcode to the result of this operation.
static void repeatable_set(unlang_stack_frame_t *frame)
unlang_process_t process
function to call for interpreting this stack frame
Generic representation of a grouping.
A node in a graph of unlang_op_t (s) that we execute.
Our interpreter stack, as distinct from the C stack.
An unlang stack associated with a request.
#define VALUE_BOX_LIST_VERIFY(_x)