The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
cf_file.c File Reference

Read the radiusd.conf file. More...

#include <freeradius-devel/server/cf_file.h>
#include <freeradius-devel/server/cf_priv.h>
#include <freeradius-devel/server/log.h>
#include <freeradius-devel/server/tmpl.h>
#include <freeradius-devel/server/util.h>
#include <freeradius-devel/server/virtual_servers.h>
#include <freeradius-devel/util/debug.h>
#include <freeradius-devel/util/file.h>
#include <freeradius-devel/util/misc.h>
#include <freeradius-devel/util/perm.h>
#include <freeradius-devel/util/syserror.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <ctype.h>
#include <fcntl.h>
#include <freeradius-devel/server/main_config.h>
+ Include dependency graph for cf_file.c:

Go to the source code of this file.

Data Structures

struct  cf_file_heap_t
 
struct  cf_stack_frame_t
 
union  cf_stack_frame_t.__unnamed61__
 
struct  cf_stack_frame_t.__unnamed61__.__unnamed63__
 
struct  cf_stack_t
 

Macros

#define MAX_STACK   (32)
 
#define RULES_VERIFY(_cs, _rules)   if (cf_tmpl_rules_verify(_cs, _rules) < 0) return NULL
 

Typedefs

typedef struct cf_file_heap_t cf_file_heap_t
 
typedef CONF_ITEM *(* cf_process_func_t) (cf_stack_t *)
 
typedef enum conf_property CONF_PROPERTY
 

Enumerations

enum  cf_stack_file_t { CF_STACK_FILE = 0 }
 
enum  conf_property {
  CONF_PROPERTY_INVALID = 0 ,
  CONF_PROPERTY_NAME ,
  CONF_PROPERTY_INSTANCE
}
 

Functions

static int8_t _inode_cmp (void const *one, void const *two)
 
static int add_pair (CONF_SECTION *parent, char const *attr, char const *value, fr_token_t name1_token, fr_token_t op_token, fr_token_t value_token, char *buff, char const *filename, int lineno)
 
static int add_section_pair (CONF_SECTION **parent, char const **attr, char const *dot, char *buffer, size_t buffer_len, char const *filename, int lineno)
 
char const * cf_expand_variables (char const *cf, int lineno, CONF_SECTION *outer_cs, char *output, size_t outsize, char const *input, ssize_t inlen, bool *soft_fail)
 
bool cf_file_check (CONF_PAIR *cp, bool check_perms)
 Do some checks on the file as an "input" file. More...
 
void cf_file_check_user (uid_t uid, gid_t gid)
 Set the euid/egid used when performing file checks. More...
 
static int cf_file_fill (cf_stack_t *stack)
 
void cf_file_free (CONF_SECTION *cs)
 
static int cf_file_include (cf_stack_t *stack)
 
static int cf_file_open (CONF_SECTION *cs, char const *filename, bool from_dir, FILE **fp_p)
 
int cf_file_read (CONF_SECTION *cs, char const *filename)
 
static int cf_get_token (CONF_SECTION *parent, char const **ptr_p, fr_token_t *token, char *buffer, size_t buflen, char const *filename, int lineno)
 
static char const * cf_local_file (char const *base, char const *filename, char *buffer, size_t bufsize)
 
static int cf_pair_write (FILE *fp, CONF_PAIR *cp)
 
CONF_ITEMcf_reference_item (CONF_SECTION const *parent_cs, CONF_SECTION const *outer_cs, char const *ptr)
 
int cf_section_pass2 (CONF_SECTION *cs)
 
int cf_section_write (FILE *fp, CONF_SECTION *cs, int depth)
 
static void cf_stack_cleanup (cf_stack_t *stack)
 
static ssize_t cf_string_write (FILE *fp, char const *string, size_t len, fr_token_t t)
 
static bool cf_template_merge (CONF_SECTION *cs, CONF_SECTION const *template)
 
static int cf_tmpl_rules_verify (CONF_SECTION *cs, tmpl_rules_t const *rules)
 
static int8_t filename_cmp (void const *one, void const *two)
 
static ssize_t fr_skip_condition (char const *start, char const *end, bool const terminal[static UINT8_MAX+1], bool *eol)
 Skip a conditional expression. More...
 
static ssize_t fr_skip_xlat (char const *start, char const *end)
 Skip an xlat expression. More...
 
static int frame_readdir (cf_stack_t *stack)
 
static int parse_input (cf_stack_t *stack)
 
static CONF_ITEMprocess_catch (cf_stack_t *stack)
 
static CONF_ITEMprocess_if (cf_stack_t *stack)
 
static int process_include (cf_stack_t *stack, CONF_SECTION *parent, char const *ptr, bool required, bool relative)
 
static CONF_ITEMprocess_map (cf_stack_t *stack)
 
static CONF_ITEMprocess_subrequest (cf_stack_t *stack)
 
static int process_template (cf_stack_t *stack)
 

Variables

bool check_config = false
 
static gid_t conf_check_gid = (gid_t)-1
 
static uid_t conf_check_uid = (uid_t)-1
 
static fr_table_num_sorted_t const conf_property_name []
 
static size_t conf_property_name_len = NUM_ELEMENTS(conf_property_name)
 
static char const parse_tabs [] = " "
 
static const bool terminal_end_line [UINT8_MAX+1]
 
static const bool terminal_end_section [UINT8_MAX+1]
 
static fr_table_ptr_sorted_t unlang_keywords []
 
static int unlang_keywords_len = NUM_ELEMENTS(unlang_keywords)
 

Detailed Description

Read the radiusd.conf file.

Id
51d54f65af2e25c1aca5cafe83b6238b1ac5eaef
Note
Yep I should learn to use lex & yacc, or at least write a decent parser. I know how to do that, really :) mique.nosp@m.ls@c.nosp@m.istro.nosp@m.n.nl

Definition in file cf_file.c.


Data Structure Documentation

◆ cf_file_heap_t

struct cf_file_heap_t

Definition at line 869 of file cf_file.c.

Data Fields
char const * filename
fr_heap_index_t heap_id

◆ cf_stack_frame_t

struct cf_stack_frame_t

Definition at line 93 of file cf_file.c.

+ Collaboration diagram for cf_stack_frame_t:
Data Fields
union cf_stack_frame_t __unnamed__
int braces
CONF_SECTION * current sub-section we're reading
char const * filename filename we're reading
bool from_dir this file was read from $include foo/
int lineno line in that filename
CONF_SECTION * parent which started this file
bool require_edits are we required to do edits?
CONF_SECTION * special map / update section
cf_stack_file_t type

◆ cf_stack_frame_t.__unnamed61__

union cf_stack_frame_t.__unnamed61__

Definition at line 99 of file cf_file.c.

Data Fields
__unnamed61__ __unnamed__

◆ cf_stack_frame_t.__unnamed61__.__unnamed63__

struct cf_stack_frame_t.__unnamed61__.__unnamed63__

Definition at line 100 of file cf_file.c.

Data Fields
FILE * fp FP we're reading.

◆ cf_stack_t

struct cf_stack_t

Definition at line 136 of file cf_file.c.

+ Collaboration diagram for cf_stack_t:
Data Fields
char ** buff buffers for reading / parsing
size_t bufsize size of the buffers
int depth stack depth
char * fill where we start filling the buffer from
cf_stack_frame_t frame[MAX_STACK] stack frames
char const * ptr current parse pointer

Macro Definition Documentation

◆ MAX_STACK

#define MAX_STACK   (32)

Definition at line 92 of file cf_file.c.

◆ RULES_VERIFY

#define RULES_VERIFY (   _cs,
  _rules 
)    if (cf_tmpl_rules_verify(_cs, _rules) < 0) return NULL

Definition at line 164 of file cf_file.c.

Typedef Documentation

◆ cf_file_heap_t

◆ cf_process_func_t

typedef CONF_ITEM*(* cf_process_func_t) (cf_stack_t *)

Definition at line 2138 of file cf_file.c.

◆ CONF_PROPERTY

Enumeration Type Documentation

◆ cf_stack_file_t

Enumerator
CF_STACK_FILE 

Definition at line 82 of file cf_file.c.

◆ conf_property

Enumerator
CONF_PROPERTY_INVALID 
CONF_PROPERTY_NAME 
CONF_PROPERTY_INSTANCE 

Definition at line 70 of file cf_file.c.

Function Documentation

◆ _inode_cmp()

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

Definition at line 540 of file cf_file.c.

+ Here is the caller graph for this function:

◆ add_pair()

static int add_pair ( CONF_SECTION parent,
char const *  attr,
char const *  value,
fr_token_t  name1_token,
fr_token_t  op_token,
fr_token_t  value_token,
char *  buff,
char const *  filename,
int  lineno 
)
static

Definition at line 2055 of file cf_file.c.

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

◆ add_section_pair()

static int add_section_pair ( CONF_SECTION **  parent,
char const **  attr,
char const *  dot,
char *  buffer,
size_t  buffer_len,
char const *  filename,
int  lineno 
)
static

Definition at line 1992 of file cf_file.c.

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

◆ cf_expand_variables()

char const* cf_expand_variables ( char const *  cf,
int  lineno,
CONF_SECTION outer_cs,
char *  output,
size_t  outsize,
char const *  input,
ssize_t  inlen,
bool soft_fail 
)

Definition at line 174 of file cf_file.c.

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

◆ cf_file_check()

bool cf_file_check ( CONF_PAIR cp,
bool  check_perms 
)

Do some checks on the file as an "input" file.

i.e. one read by a module.

Note
Must be called with super user privileges.
Parameters
cpcurrently being processed.
check_permsIf true - will return false if file is world readable, or not readable by the unprivileged user/group.
Returns
  • true if permissions are OK, or the file exists.
  • false if the file does not exist or the permissions are incorrect.

Definition at line 658 of file cf_file.c.

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

◆ cf_file_check_user()

void cf_file_check_user ( uid_t  uid,
gid_t  gid 
)

Set the euid/egid used when performing file checks.

Sets the euid, and egid used when cf_file_check is called to check permissions on conf items of type CONF_FLAG_FILE_INPUT

Note
This is probably only useful for the freeradius daemon itself.
Parameters
uidto set, (uid_t)-1 to use current euid.
gidto set, (gid_t)-1 to use current egid.

Definition at line 3084 of file cf_file.c.

◆ cf_file_fill()

static int cf_file_fill ( cf_stack_t stack)
static

Definition at line 2692 of file cf_file.c.

+ Here is the caller graph for this function:

◆ cf_file_free()

void cf_file_free ( CONF_SECTION cs)

Definition at line 3069 of file cf_file.c.

+ Here is the call graph for this function:

◆ cf_file_include()

static int cf_file_include ( cf_stack_t stack)
static

Definition at line 2796 of file cf_file.c.

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

◆ cf_file_open()

static int cf_file_open ( CONF_SECTION cs,
char const *  filename,
bool  from_dir,
FILE **  fp_p 
)
static

Definition at line 549 of file cf_file.c.

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

◆ cf_file_read()

int cf_file_read ( CONF_SECTION cs,
char const *  filename 
)

Definition at line 3010 of file cf_file.c.

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

◆ cf_get_token()

static int cf_get_token ( CONF_SECTION parent,
char const **  ptr_p,
fr_token_t token,
char *  buffer,
size_t  buflen,
char const *  filename,
int  lineno 
)
static

Definition at line 820 of file cf_file.c.

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

◆ cf_local_file()

static char const* cf_local_file ( char const *  base,
char const *  filename,
char *  buffer,
size_t  bufsize 
)
static

Definition at line 791 of file cf_file.c.

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

◆ cf_pair_write()

static int cf_pair_write ( FILE *  fp,
CONF_PAIR cp 
)
static

Definition at line 3125 of file cf_file.c.

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

◆ cf_reference_item()

CONF_ITEM* cf_reference_item ( CONF_SECTION const *  parent_cs,
CONF_SECTION const *  outer_cs,
char const *  ptr 
)

Definition at line 3206 of file cf_file.c.

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

◆ cf_section_pass2()

int cf_section_pass2 ( CONF_SECTION cs)

Definition at line 757 of file cf_file.c.

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

◆ cf_section_write()

int cf_section_write ( FILE *  fp,
CONF_SECTION cs,
int  depth 
)

Definition at line 3141 of file cf_file.c.

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

◆ cf_stack_cleanup()

static void cf_stack_cleanup ( cf_stack_t stack)
static

Definition at line 2976 of file cf_file.c.

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

◆ cf_string_write()

static ssize_t cf_string_write ( FILE *  fp,
char const *  string,
size_t  len,
fr_token_t  t 
)
static

Definition at line 3092 of file cf_file.c.

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

◆ cf_template_merge()

static bool cf_template_merge ( CONF_SECTION cs,
CONF_SECTION const *  template 
)
static

Definition at line 464 of file cf_file.c.

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

◆ cf_tmpl_rules_verify()

static int cf_tmpl_rules_verify ( CONF_SECTION cs,
tmpl_rules_t const *  rules 
)
inlinestatic

Definition at line 146 of file cf_file.c.

+ Here is the call graph for this function:

◆ filename_cmp()

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

Definition at line 874 of file cf_file.c.

+ Here is the caller graph for this function:

◆ fr_skip_condition()

static ssize_t fr_skip_condition ( char const *  start,
char const *  end,
bool const  terminal[static UINT8_MAX+1],
bool eol 
)
static

Skip a conditional expression.

This is a simple "peek ahead" parser which tries to not be wrong. It may accept some things which will later parse as invalid (e.g. unknown attributes, etc.) But it also rejects all malformed expressions.

It's used as a quick hack because the full parser isn't always available.

Parameters
[in]startstart of the condition.
[in]endend of the string (or NULL for zero-terminated strings)
[in]terminalterminal character(s)
[out]eoldid the parse error happen at eol?
Returns
>0 length of the string which was parsed. *eol is false. <=0 on error, *eol may be set.

Definition at line 1372 of file cf_file.c.

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

◆ fr_skip_xlat()

static ssize_t fr_skip_xlat ( char const *  start,
char const *  end 
)
static

Skip an xlat expression.

This is a simple "peek ahead" parser which tries to not be wrong. It may accept some things which will later parse as invalid (e.g. unknown attributes, etc.) But it also rejects all malformed expressions.

It's used as a quick hack because the full parser isn't always available.

Parameters
[in]startstart of the expression, MUST point to the "%{" or "%("
[in]endend of the string (or NULL for zero-terminated strings)
Returns
>0 length of the string which was parsed <=0 on error

Definition at line 1220 of file cf_file.c.

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

◆ frame_readdir()

static int frame_readdir ( cf_stack_t stack)
static

Definition at line 2655 of file cf_file.c.

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

◆ parse_input()

static int parse_input ( cf_stack_t stack)
static

Definition at line 2140 of file cf_file.c.

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

◆ process_catch()

static CONF_ITEM* process_catch ( cf_stack_t stack)
static

Definition at line 1900 of file cf_file.c.

+ Here is the call graph for this function:

◆ process_if()

static CONF_ITEM* process_if ( cf_stack_t stack)
static

Definition at line 1521 of file cf_file.c.

+ Here is the call graph for this function:

◆ process_include()

static int process_include ( cf_stack_t stack,
CONF_SECTION parent,
char const *  ptr,
bool  required,
bool  relative 
)
static

Definition at line 885 of file cf_file.c.

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

◆ process_map()

static CONF_ITEM* process_map ( cf_stack_t stack)
static

Definition at line 1686 of file cf_file.c.

+ Here is the call graph for this function:

◆ process_subrequest()

static CONF_ITEM* process_subrequest ( cf_stack_t stack)
static

Definition at line 1774 of file cf_file.c.

+ Here is the call graph for this function:

◆ process_template()

static int process_template ( cf_stack_t stack)
static

Definition at line 1149 of file cf_file.c.

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

Variable Documentation

◆ check_config

bool check_config = false

Definition at line 66 of file cf_file.c.

◆ conf_check_gid

gid_t conf_check_gid = (gid_t)-1
static

Definition at line 68 of file cf_file.c.

◆ conf_check_uid

uid_t conf_check_uid = (uid_t)-1
static

Definition at line 67 of file cf_file.c.

◆ conf_property_name

fr_table_num_sorted_t const conf_property_name[]
static
Initial value:
= {
{ L("instance"), CONF_PROPERTY_INSTANCE },
{ L("name"), CONF_PROPERTY_NAME }
}
#define L(_str)
Helper for initialising arrays of string literals.
Definition: build.h:207
@ CONF_PROPERTY_NAME
Definition: cf_file.c:72
@ CONF_PROPERTY_INSTANCE
Definition: cf_file.c:73

Definition at line 76 of file cf_file.c.

◆ conf_property_name_len

size_t conf_property_name_len = NUM_ELEMENTS(conf_property_name)
static

Definition at line 80 of file cf_file.c.

◆ parse_tabs

char const parse_tabs[] = " "
static

Definition at line 3090 of file cf_file.c.

◆ terminal_end_line

const bool terminal_end_line[UINT8_MAX+1]
static
Initial value:
= {
[0] = true,
['\r'] = true,
['\n'] = true,
['#'] = true,
[','] = true,
[';'] = true,
['}'] = true,
}

Definition at line 1344 of file cf_file.c.

◆ terminal_end_section

const bool terminal_end_section[UINT8_MAX+1]
static
Initial value:
= {
['{'] = true,
}

Definition at line 1340 of file cf_file.c.

◆ unlang_keywords

fr_table_ptr_sorted_t unlang_keywords[]
static
Initial value:
= {
{ L("catch"), (void *) process_catch },
{ L("elsif"), (void *) process_if },
{ L("if"), (void *) process_if },
{ L("map"), (void *) process_map },
{ L("subrequest"), (void *) process_subrequest }
}
static CONF_ITEM * process_map(cf_stack_t *stack)
Definition: cf_file.c:1686
static CONF_ITEM * process_catch(cf_stack_t *stack)
Definition: cf_file.c:1900
static CONF_ITEM * process_subrequest(cf_stack_t *stack)
Definition: cf_file.c:1774
static CONF_ITEM * process_if(cf_stack_t *stack)
Definition: cf_file.c:1521

Definition at line 2129 of file cf_file.c.

◆ unlang_keywords_len

int unlang_keywords_len = NUM_ELEMENTS(unlang_keywords)
static

Definition at line 2136 of file cf_file.c.