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

Convert internal format configuration values into native C types. More...

#include <string.h>
#include <freeradius-devel/server/cf_file.h>
#include <freeradius-devel/server/cf_parse.h>
#include <freeradius-devel/server/cf_priv.h>
#include <freeradius-devel/server/log.h>
#include <freeradius-devel/server/tmpl.h>
#include <freeradius-devel/server/virtual_servers.h>
#include <freeradius-devel/util/debug.h>
#include <freeradius-devel/util/inet.h>
#include <freeradius-devel/util/misc.h>
#include <freeradius-devel/util/perm.h>
#include <freeradius-devel/util/types.h>
+ Include dependency graph for cf_parse.c:

Go to the source code of this file.

Macros

#define PAIR_SPACE(_cs)   ((_cs->depth + 1) * 2)
 
#define SECTION_SPACE(_cs)   (_cs->depth * 2)
 

Functions

int _cf_section_rule_push (CONF_SECTION *cs, conf_parser_t const *rule, char const *filename, int lineno)
 Add a single rule to a CONF_SECTION. More...
 
int _cf_section_rules_push (CONF_SECTION *cs, conf_parser_t const *rules, char const *filename, int lineno)
 Add an array of parse rules to a CONF_SECTION. More...
 
void cf_pair_debug (CONF_SECTION const *cs, CONF_PAIR *cp, conf_parser_t const *rule)
 
static int cf_pair_default (CONF_PAIR **out, void *parent, CONF_SECTION *cs, conf_parser_t const *rule)
 Allocate a pair using the dflt value and quotation. More...
 
int cf_pair_parse (TALLOC_CTX *ctx, CONF_SECTION *cs, char const *name, unsigned int type, void *data, char const *dflt, fr_token_t dflt_quote)
 Parses a CONF_PAIR into a C data type, with a default value. More...
 
static int cf_pair_parse_internal (TALLOC_CTX *ctx, void *out, void *base, CONF_SECTION *cs, conf_parser_t const *rule)
 Parses a CONF_PAIR into a C data type, with a default value. More...
 
int cf_pair_parse_value (TALLOC_CTX *ctx, void *out, UNUSED void *base, CONF_ITEM *ci, conf_parser_t const *rule)
 Parses a CONF_PAIR into a C data type. More...
 
int cf_pair_to_value_box (TALLOC_CTX *ctx, fr_value_box_t *out, CONF_PAIR *cp, conf_parser_t const *rule)
 Parses a CONF_PAIR into a boxed value. More...
 
static int cf_pair_unescape (CONF_PAIR *cp, conf_parser_t const *rule)
 
int cf_parse_gid (TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, UNUSED conf_parser_t const *rule)
 Generic function for resolving GID strings to uid_t values. More...
 
static int cf_parse_tmpl_pass2 (UNUSED CONF_SECTION *cs, tmpl_t **out, CONF_PAIR *cp, fr_type_t type, bool attribute, fr_dict_t const *dict_def)
 
int cf_parse_uid (TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, UNUSED conf_parser_t const *rule)
 Generic function for resolving UID strings to uid_t values. More...
 
int cf_section_parse (TALLOC_CTX *ctx, void *base, CONF_SECTION *cs)
 Parse a configuration section into user-supplied variables. More...
 
static int cf_section_parse_init (CONF_SECTION *cs, void *base, conf_parser_t const *rule)
 Pre-allocate a config section structure to allow defaults to be set. More...
 
int cf_section_parse_pass2 (void *base, CONF_SECTION *cs)
 Fixup xlat expansions and attributes. More...
 
static void cf_section_parse_warn (CONF_SECTION *cs)
 
static int cf_subsection_parse (TALLOC_CTX *ctx, void *out, void *base, CONF_SECTION *cs, conf_parser_t const *rule)
 Parse a subsection. More...
 
int cf_table_parse_int (UNUSED TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, conf_parser_t const *rule)
 Generic function for parsing conf pair values as int. More...
 
int cf_table_parse_int32 (UNUSED TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, conf_parser_t const *rule)
 Generic function for parsing conf pair values as int32_t (FR_TYPE_INT32) More...
 
int cf_table_parse_uint32 (UNUSED TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, conf_parser_t const *rule)
 Generic function for parsing conf pair values as int32_t (FR_TYPE_UINT32) More...
 

Variables

static conf_parser_t conf_term = CONF_PARSER_TERMINATOR
 
static char const parse_spaces [] = " "
 

Detailed Description

Convert internal format configuration values into native C types.

Id
c603b47cdaef84dbfccae514da694cafdc2b82a4

Definition in file cf_parse.c.

Macro Definition Documentation

◆ PAIR_SPACE

#define PAIR_SPACE (   _cs)    ((_cs->depth + 1) * 2)

Definition at line 46 of file cf_parse.c.

◆ SECTION_SPACE

#define SECTION_SPACE (   _cs)    (_cs->depth * 2)

Definition at line 47 of file cf_parse.c.

Function Documentation

◆ _cf_section_rule_push()

int _cf_section_rule_push ( CONF_SECTION cs,
conf_parser_t const *  rule,
char const *  filename,
int  lineno 
)

Add a single rule to a CONF_SECTION.

Parameters
[in]csto add rules to.
[in]ruleto add.
[in]filenamewhere the rule was pushed.
[in]linenowhere the rule was pushed.
Returns
  • 0 on success.
  • -1 if the rules added conflict.

Definition at line 1351 of file cf_parse.c.

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

◆ _cf_section_rules_push()

int _cf_section_rules_push ( CONF_SECTION cs,
conf_parser_t const *  rules,
char const *  filename,
int  lineno 
)

Add an array of parse rules to a CONF_SECTION.

Parameters
[in]csto add rules to.
[in]rulesto add. Last element should have NULL name field.
[in]filenamewhere the rule was pushed.
[in]linenowhere the rule was pushed.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 1448 of file cf_parse.c.

+ Here is the call graph for this function:

◆ cf_pair_debug()

void cf_pair_debug ( CONF_SECTION const *  cs,
CONF_PAIR cp,
conf_parser_t const *  rule 
)

Definition at line 49 of file cf_parse.c.

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

◆ cf_pair_default()

static int cf_pair_default ( CONF_PAIR **  out,
void *  parent,
CONF_SECTION cs,
conf_parser_t const *  rule 
)
static

Allocate a pair using the dflt value and quotation.

The pair created by this function should fed to cf_pair_parse for parsing.

Parameters
[out]outWhere to write the CONF_PAIR we created with the default value.
[in]parentbeing populated.
[in]csto parent the CONF_PAIR from.
[in]ruleto use to create the default.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 296 of file cf_parse.c.

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

◆ cf_pair_parse()

int cf_pair_parse ( TALLOC_CTX *  ctx,
CONF_SECTION cs,
char const *  name,
unsigned int  type,
void *  data,
char const *  dflt,
fr_token_t  dflt_quote 
)

Parses a CONF_PAIR into a C data type, with a default value.

Takes fields from a conf_parser_t struct and uses them to parse the string value of a CONF_PAIR into a C data type matching the type argument.

The format of the types are the same as fr_value_box_t types.

Note
The dflt value will only be used if no matching CONF_PAIR is found. Empty strings will not result in the dflt value being used.

fr_type_t to data type mappings

fr_type_t Data type Dynamically allocated
FR_TYPE_BOOL bool No
FR_TYPE_UINT32 uint32_t No
FR_TYPE_UINT16 uint16_t No
FR_TYPE_UINT64 uint64_t No
FR_TYPE_INT32 int32_t No
FR_TYPE_STRING char const * Yes
FR_TYPE_IPV4_ADDR fr_ipaddr_t No
FR_TYPE_IPV4_PREFIX fr_ipaddr_t No
FR_TYPE_IPV6_ADDR fr_ipaddr_t No
FR_TYPE_IPV6_PREFIX fr_ipaddr_t No
FR_TYPE_COMBO_IP_ADDR fr_ipaddr_t No
FR_TYPE_COMBO_IP_PREFIX fr_ipaddr_t No
FR_TYPE_TIME_DELTA fr_time_delta_t No
Parameters
[in]ctxTo allocate arrays and values in.
[in]csto search for matching CONF_PAIR in.
[in]nameof CONF_PAIR to search for.
[in]typeData type to parse CONF_PAIR value as. Should be one of the following data types, and one or more of the following flag types or'd together:

Definition at line 700 of file cf_parse.c.

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

◆ cf_pair_parse_internal()

static int cf_pair_parse_internal ( TALLOC_CTX *  ctx,
void *  out,
void *  base,
CONF_SECTION cs,
conf_parser_t const *  rule 
)
static

Parses a CONF_PAIR into a C data type, with a default value.

Parameters
[in]ctxTo allocate arrays and values in.
[out]outWhere to write the result. Must not be NULL unless rule->runc is provided.
[in]baseaddress of the structure out points into. May be NULL in the case of manual parsing.
[in]csto search for matching CONF_PAIR in.
[in]ruleto parse CONF_PAIR with.
Returns
  • 1 if default value was used, or if there was no CONF_PAIR or dflt.
  • 0 on success.
  • -1 on error.
  • -2 if deprecated.

Definition at line 440 of file cf_parse.c.

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

◆ cf_pair_parse_value()

int cf_pair_parse_value ( TALLOC_CTX *  ctx,
void *  out,
UNUSED void *  base,
CONF_ITEM ci,
conf_parser_t const *  rule 
)

Parses a CONF_PAIR into a C data type.

Return the value of a CONF_PAIR.

See also
cf_pair_value
Parameters
[in]ctxto allocate any dynamic buffers in.
[out]outWhere to write the parsed value.
[in]baseaddress of the structure out points into. May be NULL in the case of manual parsing.
[in]cito parse.
[in]ruleto parse to. May contain flags.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 171 of file cf_parse.c.

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

◆ cf_pair_to_value_box()

int cf_pair_to_value_box ( TALLOC_CTX *  ctx,
fr_value_box_t out,
CONF_PAIR cp,
conf_parser_t const *  rule 
)

Parses a CONF_PAIR into a boxed value.

Return the value of a CONF_PAIR.

See also
cf_pair_value
Parameters
[in]ctxto allocate any dynamic buffers in.
[out]outWhere to write the parsed value.
[in]cpto parse.
[in]ruleto parse to. May contain flags.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 126 of file cf_parse.c.

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

◆ cf_pair_unescape()

static int cf_pair_unescape ( CONF_PAIR cp,
conf_parser_t const *  rule 
)
static

Definition at line 352 of file cf_parse.c.

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

◆ cf_parse_gid()

int cf_parse_gid ( TALLOC_CTX *  ctx,
void *  out,
UNUSED void *  parent,
CONF_ITEM ci,
UNUSED conf_parser_t const *  rule 
)

Generic function for resolving GID strings to uid_t values.

Type should be FR_TYPE_VOID, struct field should be a gid_t.

Definition at line 1541 of file cf_parse.c.

+ Here is the call graph for this function:

◆ cf_parse_tmpl_pass2()

static int cf_parse_tmpl_pass2 ( UNUSED CONF_SECTION cs,
tmpl_t **  out,
CONF_PAIR cp,
fr_type_t  type,
bool  attribute,
fr_dict_t const *  dict_def 
)
static

Definition at line 1097 of file cf_parse.c.

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

◆ cf_parse_uid()

int cf_parse_uid ( TALLOC_CTX *  ctx,
void *  out,
UNUSED void *  parent,
CONF_ITEM ci,
UNUSED conf_parser_t const *  rule 
)

Generic function for resolving UID strings to uid_t values.

Type should be FR_TYPE_VOID, struct field should be a uid_t.

Definition at line 1526 of file cf_parse.c.

+ Here is the call graph for this function:

◆ cf_section_parse()

int cf_section_parse ( TALLOC_CTX *  ctx,
void *  base,
CONF_SECTION cs 
)

Parse a configuration section into user-supplied variables.

Parameters
[in]ctxto allocate any strings, or additional structures in. Usually the same as base, unless base is a nested struct.
[out]basepointer to a struct to fill with data.
[in]csto parse.
Returns
  • 0 on success.
  • -1 on general error.
  • -2 if a deprecated CONF_ITEM was found.

Definition at line 985 of file cf_parse.c.

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

◆ cf_section_parse_init()

static int cf_section_parse_init ( CONF_SECTION cs,
void *  base,
conf_parser_t const *  rule 
)
static

Pre-allocate a config section structure to allow defaults to be set.

Parameters
csThe parent subsection.
basepointer or variable.
rulethat may have defaults in this config section.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 722 of file cf_parse.c.

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

◆ cf_section_parse_pass2()

int cf_section_parse_pass2 ( void *  base,
CONF_SECTION cs 
)

Fixup xlat expansions and attributes.

Parameters
[out]basestart of structure to write tmpl_t s to.
[in]csCONF_SECTION to fixup.
Returns
  • 0 on success.
  • -1 on failure (parse errors etc...).

Definition at line 1163 of file cf_parse.c.

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

◆ cf_section_parse_warn()

static void cf_section_parse_warn ( CONF_SECTION cs)
static

Definition at line 811 of file cf_parse.c.

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

◆ cf_subsection_parse()

static int cf_subsection_parse ( TALLOC_CTX *  ctx,
void *  out,
void *  base,
CONF_SECTION cs,
conf_parser_t const *  rule 
)
static

Parse a subsection.

Note
Turns out using nested structures (instead of pointers) for subsections, was actually a pretty bad design decision, and will need to be fixed at some future point. For now we have a horrible hack where only multi-subsections get an array of structures of the appropriate size.
Parameters
[in]ctxto allocate any additional structures under.
[out]outpointer to a struct/pointer to fill with data.
[in]baseaddress of the structure out points into. May be NULL in the case of manual parsing.
[in]csto parse.
[in]ruleto parse the subcs with.
Returns
  • 0 on success.
  • -1 on general error.
  • -2 if a deprecated CONF_ITEM was found.

Definition at line 855 of file cf_parse.c.

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

◆ cf_table_parse_int()

int cf_table_parse_int ( UNUSED TALLOC_CTX *  ctx,
void *  out,
UNUSED void *  parent,
CONF_ITEM ci,
conf_parser_t const *  rule 
)

Generic function for parsing conf pair values as int.

Note
This should be used for enum types as c99 6.4.4.3 states that the enumeration constants are of type int.

Definition at line 1474 of file cf_parse.c.

+ Here is the call graph for this function:

◆ cf_table_parse_int32()

int cf_table_parse_int32 ( UNUSED TALLOC_CTX *  ctx,
void *  out,
UNUSED void *  parent,
CONF_ITEM ci,
conf_parser_t const *  rule 
)

Generic function for parsing conf pair values as int32_t (FR_TYPE_INT32)

Definition at line 1490 of file cf_parse.c.

+ Here is the call graph for this function:

◆ cf_table_parse_uint32()

int cf_table_parse_uint32 ( UNUSED TALLOC_CTX *  ctx,
void *  out,
UNUSED void *  parent,
CONF_ITEM ci,
conf_parser_t const *  rule 
)

Generic function for parsing conf pair values as int32_t (FR_TYPE_UINT32)

Definition at line 1506 of file cf_parse.c.

+ Here is the call graph for this function:

Variable Documentation

◆ conf_term

Definition at line 43 of file cf_parse.c.

◆ parse_spaces

char const parse_spaces[] = " "
static

Definition at line 44 of file cf_parse.c.