The FreeRADIUS server $Id: a4e7f8c94e8038b7627bcf52356b7ed15955c1d7 $
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/map_proc.h>
#include <freeradius-devel/server/modpriv.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 T(_x)   [T_OP_ ## _x] = true
 
#define UPDATE_CTX2   unlang_compile_ctx_copy(&unlang_ctx2, unlang_ctx)
 

Functions

static bool 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_t * compile_edit_pair (unlang_t *parent, unlang_compile_ctx_t *unlang_ctx, CONF_PAIR *cp)
 Compile one edit pair.
 
static unlang_t * compile_edit_section (unlang_t *parent, unlang_compile_ctx_t *unlang_ctx, CONF_SECTION *cs)
 Compile one edit section.
 
static unlang_t * compile_function (unlang_t *parent, unlang_compile_ctx_t *unlang_ctx, CONF_ITEM *ci, CONF_SECTION *subcs, bool policy)
 
static unlang_t * compile_item (unlang_t *parent, unlang_compile_ctx_t *unlang_ctx, CONF_ITEM *ci)
 
static unlang_t * compile_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_t * compile_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 fr_cmp_ret_t instruction_cmp (void const *one, void const *two)
 
static unlang_op_t * 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 *cs, bool module_retry)
 
unlang_t * unlang_compile_children (unlang_group_t *g, unlang_compile_ctx_t *unlang_ctx_in)
 
unlang_t * unlang_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_t * unlang_compile_section (unlang_t *parent, unlang_compile_ctx_t *unlang_ctx, CONF_SECTION *cs, unlang_type_t type)
 
int unlang_compile_virtual_module (CONF_SECTION *cs, fr_dict_t const *dict)
 Compile an unlang section for a virtual module.
 
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_t * unlang_group_allocate (unlang_t *parent, CONF_SECTION *cs, unlang_type_t type)
 
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)
 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)
 
fr_rb_tree_t * unlang_instruction_tree = NULL
 
uint64_t unlang_number = 1
 
static char const unlang_spaces [] = " "
 

Detailed Description

Functions to convert configuration sections into unlang structures.

Id
72dcc2016ecb7cffcd913a2d9405a7699cf5a734

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:233
Test enumeration values.
Definition dict_test.h:92
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
static fr_cmp_ret_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

◆ T

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

Definition at line 506 of file compile.c.

◆ UPDATE_CTX2

#define UPDATE_CTX2   unlang_compile_ctx_copy(&unlang_ctx2, unlang_ctx)

Definition at line 82 of file compile.c.

Function Documentation

◆ compile_action_pair()

static bool compile_action_pair ( unlang_mod_actions_t *  actions,
CONF_PAIR *  cp 
)
static

Definition at line 940 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 1237 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 765 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 610 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 1649 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 2011 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 1822 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 1001 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 484 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 1564 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 851 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 1240 of file dict_util.c.

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

◆ instruction_cmp()

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

Definition at line 2364 of file compile.c.

+ Here is the caller graph for this function:

◆ name_to_op()

static unlang_op_t * name_to_op ( char const *  name)
static

Definition at line 1907 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 115 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 206 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 87 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 179 of file compile.c.

+ Here is the call 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 2214 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 *  cs,
bool  module_retry 
)

Definition at line 1086 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 1289 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 1197 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 2373 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 2354 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 1600 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 1522 of file compile.c.

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

◆ unlang_compile_virtual_module()

int unlang_compile_virtual_module ( CONF_SECTION *  cs,
fr_dict_t const *  dict 
)

Compile an unlang section for a virtual module.

This is just a wrapper around unlang_compile_section(), as the unlang_compile_ctx isn't public.

Parameters
[in]cscontaining the unlang calls to compile.
[in]dictdictionary to use
Returns
  • 0 on success.
  • -1 on error.

Definition at line 2283 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 1916 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 234 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 529 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 346 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 451 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 1736 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),
}
@ CMP_EQ
a == b
Definition build.h:116
#define T(_x)
Definition compile.c:506

Definition at line 508 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:245
@ RLM_MODULE_INVALID
The module considers the request invalid.
Definition rcode.h:51
@ RLM_MODULE_OK
The module is OK, continue.
Definition rcode.h:49
@ RLM_MODULE_FAIL
Module failed, don't reply.
Definition rcode.h:48
@ RLM_MODULE_DISALLOW
Reject the request (user is locked out).
Definition rcode.h:52
@ RLM_MODULE_REJECT
Immediately reject the request.
Definition rcode.h:47
@ RLM_MODULE_TIMEOUT
Module (or section) timed out.
Definition rcode.h:56
@ RLM_MODULE_NOTFOUND
User not found.
Definition rcode.h:53
@ RLM_MODULE_UPDATED
OK (pairs modified).
Definition rcode.h:55
@ RLM_MODULE_NOT_SET
Error resolving rcode (should not be returned by modules).
Definition rcode.h:45
@ RLM_MODULE_NOOP
Module succeeded without doing anything.
Definition rcode.h:54
@ RLM_MODULE_HANDLED
The module handled the request, so stop.
Definition rcode.h:50

Definition at line 67 of file compile.c.

◆ mod_rcode_table_len

size_t mod_rcode_table_len = NUM_ELEMENTS(mod_rcode_table)

Definition at line 80 of file compile.c.

◆ unlang_instruction_tree

fr_rb_tree_t * unlang_instruction_tree = NULL

Definition at line 63 of file compile.c.

◆ unlang_number

uint64_t unlang_number = 1
extern

Definition at line 55 of file interpret.c.

◆ unlang_spaces

char const unlang_spaces[] = " "
static

Definition at line 85 of file compile.c.