The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
cf_priv.h
Go to the documentation of this file.
1 #pragma once
2 /*
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation; either version 2 of the License, or
6  * (at your option) any later version.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
16  */
17 
18 /**
19  * $Id: 3746f12944f929e147bcb19aa352981c0894113e $
20  *
21  * @file cf_priv.h
22  * @brief Private data structures and types for cf_*.c
23  *
24  * @copyright 2017 The FreeRADIUS server project
25  */
26 RCSIDH(cf_priv_h, "$Id: 3746f12944f929e147bcb19aa352981c0894113e $")
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 #include <stdint.h>
33 #include <sys/stat.h>
34 
35 #include <freeradius-devel/server/cf_parse.h>
36 #include <freeradius-devel/util/rb.h>
37 #include <freeradius-devel/util/dlist.h>
38 
39 typedef enum conf_type {
45 
46 /** Common header for all CONF_* types
47  *
48  */
49 struct cf_item {
50  fr_rb_node_t ident1_node; //!< Entry in the ident1 tree.
51  fr_rb_node_t ident2_node; //!< Entry in the ident2 tree.
52 
53  fr_dlist_t entry; //!< Entry in dlist
54  fr_dlist_head_t children; //!< The head of the ordered list of children.
55 
56  CONF_ITEM *parent; //!< Parent
57 
58  fr_rb_tree_t *ident1; //!< Tree to store the first identifier (name1 || type || attr).
59  fr_rb_tree_t *ident2; //!< Tree to store the second identifier (name2 || name).
60 
61  CONF_ITEM_TYPE type; //!< Whether the config item is a config_pair, conf_section or cf_data.
62 
63  int lineno; //!< The line number the config item began on.
64  char const *filename; //!< The file the config item was parsed from.
65 };
66 
67 /** Configuration AVP similar to a fr_pair_t
68  *
69  */
70 struct cf_pair {
71  CONF_ITEM item; //!< Common set of fields.
72 
73  char const *attr; //!< Attribute name
74  char const *value; //!< Attribute value
75 
76  fr_token_t op; //!< Operator e.g. =, :=
77  fr_token_t lhs_quote; //!< Name quoting style T_(DOUBLE|SINGLE|BACK)_QUOTE_STRING or T_BARE_WORD.
78  fr_token_t rhs_quote; //!< Value Quoting style T_(DOUBLE|SINGLE|BACK)_QUOTE_STRING or T_BARE_WORD.
79 
80  bool pass2; //!< do expansion in pass2.
81  bool parsed; //!< Was this item used during parsing?
82  bool printed; //!< Was this item printed already in debug mode?
83  bool referenced; //!< Was this item referenced in the config?
84 };
85 
86 typedef enum {
87  CF_UNLANG_NONE = 0, //!< no unlang
88  CF_UNLANG_ALLOW, //!< allow unlang in this section
89  CF_UNLANG_SERVER, //!< this section is a virtual server, allow unlang 2 down
90  CF_UNLANG_POLICY, //!< this section is a policy, allow unlang 2 down
91  CF_UNLANG_MODULES, //!< this section is in "modules", allow unlang 2 down
92  CF_UNLANG_EDIT, //!< only edit commands
93  CF_UNLANG_ASSIGNMENT, //!< only assignments inside of map / update
94  CF_UNLANG_DICTIONARY, //!< only local variable definitions
95  CF_UNLANG_CAN_HAVE_UPDATE, //!< can have "update"
96 } cf_unlang_t;
97 
98 /** A section grouping multiple #CONF_PAIR
99  *
100  */
101 struct cf_section {
102  CONF_ITEM item; //!< Common set of fields.
103 
104  char const *name1; //!< First name token. Given ``foo bar {}`` would be ``foo``.
105  char const *name2; //!< Second name token. Given ``foo bar {}`` would be ``bar``.
106 
107  fr_token_t name2_quote; //!< The type of quoting around name2.
108 
109  int argc; //!< number of additional arguments
110  char const **argv; //!< additional arguments
112 
113  void *base;
114  int depth;
116  bool allow_locals; //!< allow local variables
117 
118  CONF_SECTION *template;
119 };
120 
121 /** Internal data that is associated with a configuration section
122  *
123  */
124 struct cf_data {
125  CONF_ITEM item; //!< Common set of fields.
126 
127  char const *type; //!< C type of data being stored.
128  char const *name; //!< Additional qualification of type.
129 
130  void const *data; //!< User data.
131  bool is_talloced; //!< If true we can do extra checks.
132  bool free; //!< If true, free data with talloc if parent node is freed.
133 };
134 
135 typedef struct {
137  char const *filename; //!< name of the file
138  CONF_SECTION *cs; //!< CONF_SECTION associated with the file
139  struct stat buf; //!< stat about the file
140  bool from_dir; //!< was read from a directory
141 } cf_file_t;
142 
143 /** Iterate over the contents of a list
144  *
145  * @param[in] _ci to iterate over.
146  * @param[in] _iter Name of iteration variable.
147  * Will be declared in the scope of the loop.
148  */
149 #define cf_item_foreach(_ci, _iter) \
150  for (CONF_ITEM *_iter = fr_dlist_head(&(_ci)->children); _iter; _iter = fr_dlist_next(&(_ci)->children, _iter))
151 
152 /** Iterate over the contents of a list
153  *
154  * @param[in] _ci to iterate over.
155  * @param[in] _iter Name of iteration variable.
156  * Will be declared in the scope of the loop.
157  * @param[in] _prev previous pointer
158  */
159 #define cf_item_foreach_next(_ci, _iter, _prev) \
160  for (CONF_ITEM *_iter = fr_dlist_next(&(_ci)->children, _prev); _iter; _iter = fr_dlist_next(&(_ci)->children, _iter))
161 
162 /** Iterate over the contents of a list in reverse order
163  *
164  * @param[in] _ci to iterate over.
165  * @param[in] _iter Name of iteration variable.
166  * Will be declared in the scope of the loop.
167  * @param[in] _prev previous pointer
168  */
169 #define cf_item_foreach_prev(_ci, _iter, _prev) \
170  for (CONF_ITEM *_iter = fr_dlist_prev(&(_ci)->children, _prev); _iter; _iter = fr_dlist_prev(&(_ci)->children, _iter))
171 
172 /** Check if the CONF_ITEM has no children.
173  *
174  * Which is the common use-case
175  *
176  * @param[in] ci to check
177  * @return true/false
178  */
179 static inline CC_HINT(nonnull) bool cf_item_has_no_children(CONF_ITEM const *ci)
180 {
181  return fr_dlist_empty(&ci->children);
182 }
183 
184 #ifdef __cplusplus
185 }
186 #endif
#define RCSIDH(h, id)
Definition: build.h:482
fr_rb_node_t ident2_node
Entry in the ident2 tree.
Definition: cf_priv.h:51
bool printed
Was this item printed already in debug mode?
Definition: cf_priv.h:82
CONF_ITEM item
Common set of fields.
Definition: cf_priv.h:102
CONF_ITEM * parent
Parent.
Definition: cf_priv.h:56
fr_token_t name2_quote
The type of quoting around name2.
Definition: cf_priv.h:107
bool from_dir
was read from a directory
Definition: cf_priv.h:140
void * base
Definition: cf_priv.h:113
char const * name2
Second name token. Given foo bar {} would be bar.
Definition: cf_priv.h:105
bool allow_locals
allow local variables
Definition: cf_priv.h:116
int argc
number of additional arguments
Definition: cf_priv.h:109
char const * attr
Attribute name.
Definition: cf_priv.h:73
char const * name
Additional qualification of type.
Definition: cf_priv.h:128
fr_rb_tree_t * ident2
Tree to store the second identifier (name2 || name).
Definition: cf_priv.h:59
fr_token_t rhs_quote
Value Quoting style T_(DOUBLE|SINGLE|BACK)_QUOTE_STRING or T_BARE_WORD.
Definition: cf_priv.h:78
int depth
Definition: cf_priv.h:114
char const * value
Attribute value.
Definition: cf_priv.h:74
cf_unlang_t unlang
Definition: cf_priv.h:115
char const * name1
First name token. Given foo bar {} would be foo.
Definition: cf_priv.h:104
void const * data
User data.
Definition: cf_priv.h:130
static bool cf_item_has_no_children(CONF_ITEM const *ci)
Check if the CONF_ITEM has no children.
Definition: cf_priv.h:179
cf_unlang_t
Definition: cf_priv.h:86
@ CF_UNLANG_MODULES
this section is in "modules", allow unlang 2 down
Definition: cf_priv.h:91
@ CF_UNLANG_NONE
no unlang
Definition: cf_priv.h:87
@ CF_UNLANG_CAN_HAVE_UPDATE
can have "update"
Definition: cf_priv.h:95
@ CF_UNLANG_ALLOW
allow unlang in this section
Definition: cf_priv.h:88
@ CF_UNLANG_POLICY
this section is a policy, allow unlang 2 down
Definition: cf_priv.h:90
@ CF_UNLANG_ASSIGNMENT
only assignments inside of map / update
Definition: cf_priv.h:93
@ CF_UNLANG_EDIT
only edit commands
Definition: cf_priv.h:92
@ CF_UNLANG_DICTIONARY
only local variable definitions
Definition: cf_priv.h:94
@ CF_UNLANG_SERVER
this section is a virtual server, allow unlang 2 down
Definition: cf_priv.h:89
fr_dlist_head_t children
The head of the ordered list of children.
Definition: cf_priv.h:54
fr_token_t * argv_quote
Definition: cf_priv.h:111
fr_token_t op
Operator e.g. =, :=.
Definition: cf_priv.h:76
CONF_ITEM item
Common set of fields.
Definition: cf_priv.h:71
fr_rb_node_t node
Definition: cf_priv.h:136
bool pass2
do expansion in pass2.
Definition: cf_priv.h:80
char const * filename
The file the config item was parsed from.
Definition: cf_priv.h:64
fr_rb_tree_t * ident1
Tree to store the first identifier (name1 || type || attr).
Definition: cf_priv.h:58
bool is_talloced
If true we can do extra checks.
Definition: cf_priv.h:131
char const * filename
name of the file
Definition: cf_priv.h:137
fr_rb_node_t ident1_node
Entry in the ident1 tree.
Definition: cf_priv.h:50
fr_dlist_t entry
Entry in dlist.
Definition: cf_priv.h:53
conf_type
Definition: cf_priv.h:39
@ CONF_ITEM_INVALID
Definition: cf_priv.h:40
@ CONF_ITEM_PAIR
Definition: cf_priv.h:41
@ CONF_ITEM_DATA
Definition: cf_priv.h:43
@ CONF_ITEM_SECTION
Definition: cf_priv.h:42
bool referenced
Was this item referenced in the config?
Definition: cf_priv.h:83
enum conf_type CONF_ITEM_TYPE
char const ** argv
additional arguments
Definition: cf_priv.h:110
char const * type
C type of data being stored.
Definition: cf_priv.h:127
CONF_ITEM item
Common set of fields.
Definition: cf_priv.h:125
bool parsed
Was this item used during parsing?
Definition: cf_priv.h:81
fr_token_t lhs_quote
Name quoting style T_(DOUBLE|SINGLE|BACK)_QUOTE_STRING or T_BARE_WORD.
Definition: cf_priv.h:77
bool free
If true, free data with talloc if parent node is freed.
Definition: cf_priv.h:132
int lineno
The line number the config item began on.
Definition: cf_priv.h:63
CONF_ITEM_TYPE type
Whether the config item is a config_pair, conf_section or cf_data.
Definition: cf_priv.h:61
Internal data that is associated with a configuration section.
Definition: cf_priv.h:124
Common header for all CONF_* types.
Definition: cf_priv.h:49
Configuration AVP similar to a fr_pair_t.
Definition: cf_priv.h:70
A section grouping multiple CONF_PAIR.
Definition: cf_priv.h:101
static bool fr_dlist_empty(fr_dlist_head_t const *list_head)
Check whether a list has any items.
Definition: dlist.h:501
Head of a doubly linked list.
Definition: dlist.h:51
Entry in a doubly linked list.
Definition: dlist.h:41
The main red black tree structure.
Definition: rb.h:73
enum fr_token fr_token_t
int nonnull(2, 5))