The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
Macros | Functions | Variables
compile.c File Reference

Functions to convert configuration sections into unlang structures. More...

#include <freeradius-devel/protocol/freeradius/freeradius.internal.h>
#include <freeradius-devel/server/virtual_servers.h>
#include <freeradius-devel/server/cf_file.h>
#include <freeradius-devel/server/main_config.h>
#include <freeradius-devel/server/map_proc.h>
#include <freeradius-devel/server/modpriv.h>
#include <freeradius-devel/server/module_rlm.h>
#include <freeradius-devel/unlang/xlat_priv.h>
#include "call_priv.h"
#include "caller_priv.h"
#include "condition_priv.h"
#include "foreach_priv.h"
#include "load_balance_priv.h"
#include "map_priv.h"
#include "module_priv.h"
#include "parallel_priv.h"
#include "subrequest_priv.h"
#include "switch_priv.h"
#include "edit_priv.h"
#include "timeout_priv.h"
#include "limit_priv.h"
#include "transaction_priv.h"
#include "try_priv.h"
#include "mod_action.h"
+ Include dependency graph for compile.c:

Go to the source code of this file.

Macros

#define CLAMP(_name, _field, _limit)
 
#define debug_braces(_type)   (unlang_ops[_type].flag & UNLANG_OP_FLAG_DEBUG_BRACES)
 
#define T(_x)   [T_OP_ ## _x] = true
 
#define UPDATE_CTX2   unlang_compile_ctx_copy(&unlang_ctx2, unlang_ctx)
 

Functions

static int compile_action_pair (unlang_mod_actions_t *actions, CONF_PAIR *cp)
 
static bool compile_action_subsection (unlang_t *c, CONF_SECTION *cs, CONF_SECTION *subcs)
 
static unlang_tcompile_edit_pair (unlang_t *parent, unlang_compile_ctx_t *unlang_ctx, CONF_PAIR *cp)
 Compile one edit pair.
 
static unlang_tcompile_edit_section (unlang_t *parent, unlang_compile_ctx_t *unlang_ctx, CONF_SECTION *cs)
 Compile one edit section.
 
static unlang_tcompile_function (unlang_t *parent, unlang_compile_ctx_t *unlang_ctx, CONF_ITEM *ci, CONF_SECTION *subcs, bool policy)
 
static unlang_tcompile_item (unlang_t *parent, unlang_compile_ctx_t *unlang_ctx, CONF_ITEM *ci)
 
static unlang_tcompile_module (unlang_t *parent, unlang_compile_ctx_t *unlang_ctx, CONF_ITEM *ci, char const *name)
 
static bool compile_retry_section (unlang_mod_actions_t *actions, CONF_ITEM *ci)
 
static void compile_set_default_actions (unlang_t *c, unlang_compile_ctx_t *unlang_ctx)
 Update a compiled unlang_t with the default actions.
 
static unlang_tcompile_tmpl (unlang_t *parent, unlang_compile_ctx_t *unlang_ctx, CONF_ITEM *ci)
 
static int compile_variable (unlang_t *parent, unlang_compile_ctx_t *unlang_ctx, CONF_PAIR *cp, tmpl_rules_t *t_rules)
 Compile a variable definition.
 
int dict_attr_acopy_children (fr_dict_t *dict, fr_dict_attr_t *dst, fr_dict_attr_t const *src)
 Copy the children of an existing attribute.
 
static int8_t instruction_cmp (void const *one, void const *two)
 
static unlang_op_t const * name_to_op (char const *name)
 
bool pass2_fixup_map (map_t *map, tmpl_rules_t const *rules, fr_dict_attr_t const *parent)
 Fixup ONE map (recursively)
 
bool pass2_fixup_map_rhs (unlang_group_t *g, tmpl_rules_t const *rules)
 
bool pass2_fixup_tmpl (UNUSED TALLOC_CTX *ctx, tmpl_t **vpt_p, CONF_ITEM const *ci, fr_dict_t const *dict)
 
bool pass2_fixup_update (unlang_group_t *g, tmpl_rules_t const *rules)
 
int unlang_compile (virtual_server_t const *vs, CONF_SECTION *cs, unlang_mod_actions_t const *actions, tmpl_rules_t const *rules, void **instruction)
 Compile an unlang section for a virtual server.
 
bool unlang_compile_actions (unlang_mod_actions_t *actions, CONF_SECTION *action_cs, bool module_retry)
 
unlang_tunlang_compile_children (unlang_group_t *g, unlang_compile_ctx_t *unlang_ctx_in)
 
unlang_tunlang_compile_empty (unlang_t *parent, UNUSED unlang_compile_ctx_t *unlang_ctx, CONF_SECTION *cs, unlang_type_t type)
 
void unlang_compile_init (TALLOC_CTX *ctx)
 
bool unlang_compile_is_keyword (const char *name)
 Check if name is an unlang keyword.
 
bool unlang_compile_limit_subsection (CONF_SECTION *cs, char const *name)
 
unlang_tunlang_compile_section (unlang_t *parent, unlang_compile_ctx_t *unlang_ctx, CONF_SECTION *cs, unlang_type_t type)
 
int unlang_define_local_variable (CONF_ITEM *ci, unlang_variable_t *var, tmpl_rules_t *t_rules, fr_type_t type, char const *name, fr_dict_attr_t const *ref)
 
static void unlang_dump (unlang_t *c, int depth)
 
static int unlang_fixup_edit (map_t *map, void *ctx)
 Validate and fixup a map that's part of an edit section.
 
int unlang_fixup_update (map_t *map, void *ctx)
 Validate and fixup a map that's part of an update section.
 
unlang_group_tunlang_group_allocate (unlang_t *parent, CONF_SECTION *cs, unlang_type_t type)
 
void * unlang_thread_instance (unlang_t const *instruction)
 Get the thread-instance data for an instruction.
 
int unlang_thread_instantiate (TALLOC_CTX *ctx)
 Create thread-specific data structures for unlang.
 
static CONF_SECTIONvirtual_module_find_cs (CONF_ITEM *ci, UNUSED char const *real_name, char const *virtual_name, char const *method_name, unlang_compile_ctx_t *unlang_ctx, bool *policy)
 Load a named module from the virtual module list, or from the "policy" subsection.
 

Variables

static const bool edit_list_sub_op [T_TOKEN_LAST]
 
fr_table_num_sorted_t const mod_rcode_table []
 
size_t mod_rcode_table_len = NUM_ELEMENTS(mod_rcode_table)
 
static fr_rb_tree_tunlang_instruction_tree = NULL
 
static unsigned int unlang_number = 1
 
static char const unlang_spaces [] = " "
 
static _Thread_local unlang_thread_tunlang_thread_array
 

Detailed Description

Functions to convert configuration sections into unlang structures.

Id
a81ed2e920a1d312839385cd6f7340c66639bb62

Definition in file compile.c.

Macro Definition Documentation

◆ CLAMP

#define CLAMP (   _name,
  _field,
  _limit 
)
Value:
do { \
if (!fr_time_delta_ispos(actions->retry._field)) { \
cf_log_err(csi, "Invalid value for '" STRINGIFY(_name) " = %s' - value must be positive", \
value); \
return false; \
} \
if (fr_time_delta_cmp(actions->retry._field, fr_time_delta_from_sec(_limit)) > 0) { \
cf_log_err(csi, "Invalid value for '" STRINGIFY(_name) " = %s' - value must be less than " STRINGIFY(_limit) "s", \
value); \
return false; \
} \
} while (0)
#define STRINGIFY(x)
Definition build.h:197
Test enumeration values.
Definition dict_test.h:92
static int8_t fr_time_delta_cmp(fr_time_delta_t a, fr_time_delta_t b)
Compare two fr_time_delta_t values.
Definition time.h:930
static fr_time_delta_t fr_time_delta_from_sec(int64_t sec)
Definition time.h:590
#define fr_time_delta_ispos(_a)
Definition time.h:290

◆ debug_braces

#define debug_braces (   _type)    (unlang_ops[_type].flag & UNLANG_OP_FLAG_DEBUG_BRACES)

Definition at line 843 of file compile.c.

◆ T

#define T (   _x)    [T_OP_ ## _x] = true

Definition at line 502 of file compile.c.

◆ UPDATE_CTX2

#define UPDATE_CTX2   unlang_compile_ctx_copy(&unlang_ctx2, unlang_ctx)

Definition at line 90 of file compile.c.

Function Documentation

◆ compile_action_pair()

static int compile_action_pair ( unlang_mod_actions_t actions,
CONF_PAIR cp 
)
static

Definition at line 938 of file compile.c.

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

◆ compile_action_subsection()

static bool compile_action_subsection ( unlang_t c,
CONF_SECTION cs,
CONF_SECTION subcs 
)
static

Definition at line 1236 of file compile.c.

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

◆ compile_edit_pair()

static unlang_t * compile_edit_pair ( unlang_t parent,
unlang_compile_ctx_t unlang_ctx,
CONF_PAIR cp 
)
static

Compile one edit pair.

Definition at line 763 of file compile.c.

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

◆ compile_edit_section()

static unlang_t * compile_edit_section ( unlang_t parent,
unlang_compile_ctx_t unlang_ctx,
CONF_SECTION cs 
)
static

Compile one edit section.

Definition at line 602 of file compile.c.

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

◆ compile_function()

static unlang_t * compile_function ( unlang_t parent,
unlang_compile_ctx_t unlang_ctx,
CONF_ITEM ci,
CONF_SECTION subcs,
bool  policy 
)
static

Definition at line 1636 of file compile.c.

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

◆ compile_item()

static unlang_t * compile_item ( unlang_t parent,
unlang_compile_ctx_t unlang_ctx,
CONF_ITEM ci 
)
static

Definition at line 1980 of file compile.c.

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

◆ compile_module()

static unlang_t * compile_module ( unlang_t parent,
unlang_compile_ctx_t unlang_ctx,
CONF_ITEM ci,
char const *  name 
)
static

Definition at line 1795 of file compile.c.

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

◆ compile_retry_section()

static bool compile_retry_section ( unlang_mod_actions_t actions,
CONF_ITEM ci 
)
static

Definition at line 999 of file compile.c.

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

◆ compile_set_default_actions()

static void compile_set_default_actions ( unlang_t c,
unlang_compile_ctx_t unlang_ctx 
)
static

Update a compiled unlang_t with the default actions.

Don't over-ride any actions which have been set.

Definition at line 480 of file compile.c.

+ Here is the caller graph for this function:

◆ compile_tmpl()

static unlang_t * compile_tmpl ( unlang_t parent,
unlang_compile_ctx_t unlang_ctx,
CONF_ITEM ci 
)
static

Definition at line 1550 of file compile.c.

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

◆ compile_variable()

static int compile_variable ( unlang_t parent,
unlang_compile_ctx_t unlang_ctx,
CONF_PAIR cp,
tmpl_rules_t t_rules 
)
static

Compile a variable definition.

Definitions which are adjacent to one another are automatically merged into one larger variable definition.

Definition at line 850 of file compile.c.

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

◆ dict_attr_acopy_children()

int dict_attr_acopy_children ( fr_dict_t dict,
fr_dict_attr_t dst,
fr_dict_attr_t const *  src 
)
extern

Copy the children of an existing attribute.

Parameters
[in]dictto allocate the children in
[in]dstwhere to copy the children to
[in]srcwhere to copy the children from
Returns
  • 0 on success
  • <0 on error

Definition at line 1116 of file dict_util.c.

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

◆ instruction_cmp()

static int8_t instruction_cmp ( void const *  one,
void const *  two 
)
static

Definition at line 2276 of file compile.c.

+ Here is the caller graph for this function:

◆ name_to_op()

static unlang_op_t const * name_to_op ( char const *  name)
inlinestatic

Definition at line 1875 of file compile.c.

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

◆ pass2_fixup_map()

bool pass2_fixup_map ( map_t map,
tmpl_rules_t const *  rules,
fr_dict_attr_t const *  parent 
)

Fixup ONE map (recursively)

This function resolves most things. Most notable it CAN leave the RHS unresolved, for use in map sections.

Definition at line 123 of file compile.c.

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

◆ pass2_fixup_map_rhs()

bool pass2_fixup_map_rhs ( unlang_group_t g,
tmpl_rules_t const *  rules 
)

Definition at line 214 of file compile.c.

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

◆ pass2_fixup_tmpl()

bool pass2_fixup_tmpl ( UNUSED TALLOC_CTX *  ctx,
tmpl_t **  vpt_p,
CONF_ITEM const *  ci,
fr_dict_t const *  dict 
)

Definition at line 95 of file compile.c.

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

◆ pass2_fixup_update()

bool pass2_fixup_update ( unlang_group_t g,
tmpl_rules_t const *  rules 
)

Definition at line 187 of file compile.c.

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

◆ unlang_compile()

int unlang_compile ( virtual_server_t const *  vs,
CONF_SECTION cs,
unlang_mod_actions_t const *  actions,
tmpl_rules_t const *  rules,
void **  instruction 
)

Compile an unlang section for a virtual server.

Parameters
[in]vsVirtual server to compile section for.
[in]cscontaining the unlang calls to compile.
[in]actionsActions to use for the unlang section.
[in]rulesRules to use for the unlang section.
[out]instructionPointer to store the compiled unlang section.
Returns
  • 0 on success.
  • -1 on error.

Definition at line 2199 of file compile.c.

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

◆ unlang_compile_actions()

bool unlang_compile_actions ( unlang_mod_actions_t actions,
CONF_SECTION action_cs,
bool  module_retry 
)

Definition at line 1083 of file compile.c.

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

◆ unlang_compile_children()

unlang_t * unlang_compile_children ( unlang_group_t g,
unlang_compile_ctx_t unlang_ctx_in 
)

Definition at line 1288 of file compile.c.

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

◆ unlang_compile_empty()

unlang_t * unlang_compile_empty ( unlang_t parent,
UNUSED unlang_compile_ctx_t unlang_ctx,
CONF_SECTION cs,
unlang_type_t  type 
)

Definition at line 1196 of file compile.c.

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

◆ unlang_compile_init()

void unlang_compile_init ( TALLOC_CTX *  ctx)

Definition at line 2285 of file compile.c.

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

◆ unlang_compile_is_keyword()

bool unlang_compile_is_keyword ( const char *  name)

Check if name is an unlang keyword.

Parameters
[in]nameto check.
Returns
  • true if it is a keyword.
  • false if it's not a keyword.

Definition at line 2266 of file compile.c.

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

◆ unlang_compile_limit_subsection()

bool unlang_compile_limit_subsection ( CONF_SECTION cs,
char const *  name 
)

Definition at line 1586 of file compile.c.

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

◆ unlang_compile_section()

unlang_t * unlang_compile_section ( unlang_t parent,
unlang_compile_ctx_t unlang_ctx,
CONF_SECTION cs,
unlang_type_t  type 
)

Definition at line 1508 of file compile.c.

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

◆ unlang_define_local_variable()

int unlang_define_local_variable ( CONF_ITEM ci,
unlang_variable_t var,
tmpl_rules_t t_rules,
fr_type_t  type,
char const *  name,
fr_dict_attr_t const *  ref 
)

Definition at line 1885 of file compile.c.

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

◆ unlang_dump()

static void unlang_dump ( unlang_t c,
int  depth 
)
static

Definition at line 240 of file compile.c.

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

◆ unlang_fixup_edit()

static int unlang_fixup_edit ( map_t map,
void *  ctx 
)
static

Validate and fixup a map that's part of an edit section.

Parameters
mapto validate.
ctxdata to pass to fixup function (currently unused).
Returns
0 if valid else -1.
Todo:
  • this is only called for CONF_PAIR maps, not for CONF_SECTION. So when we parse nested maps, there's no validation done of the CONF_SECTION. In order to fix this, we need to have map_afrom_cs() call the validation function for the CONF_SECTION before recursing.

Definition at line 525 of file compile.c.

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

◆ unlang_fixup_update()

int unlang_fixup_update ( map_t map,
void *  ctx 
)

Validate and fixup a map that's part of an update section.

Parameters
mapto validate.
ctxdata to pass to fixup function (currently unused).
Returns
  • 0 if valid.
  • -1 not valid.

Definition at line 351 of file compile.c.

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

◆ unlang_group_allocate()

unlang_group_t * unlang_group_allocate ( unlang_t parent,
CONF_SECTION cs,
unlang_type_t  type 
)

Definition at line 447 of file compile.c.

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

◆ unlang_thread_instance()

void * unlang_thread_instance ( unlang_t const *  instruction)

Get the thread-instance data for an instruction.

Parameters
[in]instructionthe instruction to use
Returns
a pointer to thread-local data

Definition at line 2340 of file compile.c.

+ Here is the caller graph for this function:

◆ unlang_thread_instantiate()

int unlang_thread_instantiate ( TALLOC_CTX *  ctx)

Create thread-specific data structures for unlang.

Definition at line 2294 of file compile.c.

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

◆ virtual_module_find_cs()

static CONF_SECTION * virtual_module_find_cs ( CONF_ITEM ci,
UNUSED char const *  real_name,
char const *  virtual_name,
char const *  method_name,
unlang_compile_ctx_t unlang_ctx,
bool policy 
)
static

Load a named module from the virtual module list, or from the "policy" subsection.

If it's "foo.method", look for "foo", and return "method" as the method we wish to use, instead of the input component.

Parameters
[in]ciConfiguration item to check
[in]real_nameComplete name string e.g. foo.authorize.
[in]virtual_nameVirtual module name e.g. foo.
[in]method_nameMethod override (may be NULL) or the method name e.g. authorize.
[in]unlang_ctxUnlang context this call is being compiled in.
[out]policywhether or not this thing was a policy
Returns
the CONF_SECTION specifying the virtual module.

Definition at line 1713 of file compile.c.

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

Variable Documentation

◆ edit_list_sub_op

const bool edit_list_sub_op[T_TOKEN_LAST]
static
Initial value:
= {
T(NE),
T(GE),
T(GT),
T(LE),
T(LT),
T(CMP_EQ),
}
#define T(_x)
Definition compile.c:502

Definition at line 504 of file compile.c.

◆ mod_rcode_table

fr_table_num_sorted_t const mod_rcode_table[]
Initial value:
= {
{ L("..."), RLM_MODULE_NOT_SET },
{ L("disallow"), RLM_MODULE_DISALLOW },
{ L("fail"), RLM_MODULE_FAIL },
{ L("handled"), RLM_MODULE_HANDLED },
{ L("invalid"), RLM_MODULE_INVALID },
{ L("noop"), RLM_MODULE_NOOP },
{ L("notfound"), RLM_MODULE_NOTFOUND },
{ L("ok"), RLM_MODULE_OK },
{ L("reject"), RLM_MODULE_REJECT },
{ L("timeout"), RLM_MODULE_TIMEOUT },
{ L("updated"), RLM_MODULE_UPDATED }
}
#define L(_str)
Helper for initialising arrays of string literals.
Definition build.h:209
@ RLM_MODULE_INVALID
The module considers the request invalid.
Definition rcode.h:47
@ RLM_MODULE_OK
The module is OK, continue.
Definition rcode.h:45
@ RLM_MODULE_FAIL
Module failed, don't reply.
Definition rcode.h:44
@ RLM_MODULE_DISALLOW
Reject the request (user is locked out).
Definition rcode.h:48
@ RLM_MODULE_REJECT
Immediately reject the request.
Definition rcode.h:43
@ RLM_MODULE_TIMEOUT
Module (or section) timed out.
Definition rcode.h:52
@ RLM_MODULE_NOTFOUND
User not found.
Definition rcode.h:49
@ RLM_MODULE_UPDATED
OK (pairs modified).
Definition rcode.h:51
@ RLM_MODULE_NOT_SET
Error resolving rcode (should not be returned by modules).
Definition rcode.h:41
@ RLM_MODULE_NOOP
Module succeeded without doing anything.
Definition rcode.h:50
@ RLM_MODULE_HANDLED
The module handled the request, so stop.
Definition rcode.h:46

Definition at line 75 of file compile.c.

◆ mod_rcode_table_len

size_t mod_rcode_table_len = NUM_ELEMENTS(mod_rcode_table)

Definition at line 88 of file compile.c.

◆ unlang_instruction_tree

fr_rb_tree_t* unlang_instruction_tree = NULL
static

Definition at line 71 of file compile.c.

◆ unlang_number

unsigned int unlang_number = 1
static

Definition at line 57 of file compile.c.

◆ unlang_spaces

char const unlang_spaces[] = " "
static

Definition at line 93 of file compile.c.

◆ unlang_thread_array

_Thread_local unlang_thread_t* unlang_thread_array
static

Definition at line 64 of file compile.c.