All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
conffile.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 2 of the License, or
5  * (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
15  */
16 #ifndef _FR_CONFFILE_H
17 #define _FR_CONFFILE_H
18 /**
19  * $Id: 1ca20fc179e138bbc8d9aef64301a3aa8f193ad8 $
20  *
21  * @file include/conffile.h
22  * @brief API to parse FreeRADIUS configuration file format, and convert string
23  * values to native C datatypes.
24  *
25  * @copyright 2015 The FreeRADIUS server project
26  */
27 RCSIDH(conffile_h, "$Id: 1ca20fc179e138bbc8d9aef64301a3aa8f193ad8 $")
28 
29 #include <stddef.h>
30 #include <freeradius-devel/token.h>
31 #include <sys/time.h>
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
37 /*
38  * Export the minimum amount of information about these structs
39  */
40 typedef struct conf_item CONF_ITEM; //!< Generic configuration element, extended to become
41  ///< a #CONF_PAIR, a #CONF_SECTION or #CONF_DATA.
42 typedef struct conf_pair CONF_PAIR; //!< #CONF_ITEM with an attribute, an operator and a value.
43 typedef struct conf_part CONF_SECTION; //!< #CONF_ITEM used to group multiple #CONF_PAIR and #CONF_SECTION, together.
44 typedef struct conf_data CONF_DATA; //!< #CONF_ITEM used to associate arbitrary data
45  ///< with a #CONF_PAIR or #CONF_SECTION.
46 
47 
48 typedef void conf_type_mismatch; //!< Dummy type used to indicate PW_TYPE_*/C type mismatch.
49 typedef void conf_type_invalid; //!< Dummy type used to indicate invalid PW_TYPE_*.
50 
51 #if defined(HAVE_BUILTIN_CHOOSE_EXPR) && defined(HAVE_BUILTIN_TYPES_COMPATIBLE_P)
52 /*
53  * Dumb hack for GCC which explodes with lots of errors masking the real
54  * error cause, if we don't use typdefs for these structures.
55  */
56 typedef struct timeval _timeval_t;
57 
58 /** Check the type #_t matches the destination data type
59  *
60  * Validation macro to check the type of the pointer or offset #_p passed in
61  * matches the type #_t of the configuration item.
62  *
63  * Uses various magic builtin precompilation functions, so will likely only
64  * work with recent versions of clang and gcc.
65  *
66  * @note The warnings/errors emitted are usually awful.
67  *
68  * @param _t a #PW_TYPE value with optional PW_TYPE_* flags.
69  * @param _ct data type of global or struct field, obtained with ``__typeof__``.
70  * @param _p Pointer or offset.
71  */
72 # define FR_CONF_TYPE_CHECK(_t, _ct, _p) \
73  __builtin_choose_expr(((_t & PW_TYPE_TMPL) && (_t & PW_TYPE_MULTI)),\
74  __builtin_choose_expr(__builtin_types_compatible_p(vp_tmpl_t ***, _ct), _p, (conf_type_mismatch) 0),\
75  __builtin_choose_expr((_t & PW_TYPE_TMPL),\
76  __builtin_choose_expr(__builtin_types_compatible_p(vp_tmpl_t **, _ct), _p, (conf_type_mismatch) 0),\
77  __builtin_choose_expr((((_t) & 0xff) == PW_TYPE_STRING) && (_t & PW_TYPE_MULTI),\
78  __builtin_choose_expr(__builtin_types_compatible_p(char const ***, _ct), _p, (conf_type_mismatch) 0),\
79  __builtin_choose_expr((((_t) & 0xff) == PW_TYPE_STRING),\
80  __builtin_choose_expr(__builtin_types_compatible_p(char const **, _ct), _p, (conf_type_mismatch) 0),\
81  __builtin_choose_expr((((_t) & 0xff) == PW_TYPE_BOOLEAN) && (_t & PW_TYPE_MULTI),\
82  __builtin_choose_expr(__builtin_types_compatible_p(bool **, _ct), _p, (conf_type_mismatch) 0),\
83  __builtin_choose_expr((((_t) & 0xff) == PW_TYPE_BOOLEAN),\
84  __builtin_choose_expr(__builtin_types_compatible_p(bool *, _ct), _p, (conf_type_mismatch) 0),\
85  __builtin_choose_expr((((_t) & 0xff) == PW_TYPE_SUBSECTION),\
86  _p,\
87  __builtin_choose_expr((((_t) & 0xff) == PW_TYPE_INTEGER) && (_t & PW_TYPE_MULTI),\
88  __builtin_choose_expr(__builtin_types_compatible_p(uint32_t **, _ct), _p, (conf_type_mismatch) 0),\
89  __builtin_choose_expr((((_t) & 0xff) == PW_TYPE_INTEGER),\
90  __builtin_choose_expr(__builtin_types_compatible_p(uint32_t *, _ct), _p, (conf_type_mismatch) 0),\
91  __builtin_choose_expr((((_t) & 0xff) == PW_TYPE_IPV4_ADDR) && (_t & PW_TYPE_MULTI),\
92  __builtin_choose_expr(__builtin_types_compatible_p(fr_ipaddr_t **, _ct), _p, (conf_type_mismatch) 0),\
93  __builtin_choose_expr((((_t) & 0xff) == PW_TYPE_IPV4_ADDR),\
94  __builtin_choose_expr(__builtin_types_compatible_p(fr_ipaddr_t *, _ct), _p, (conf_type_mismatch) 0),\
95  __builtin_choose_expr((((_t) & 0xff) == PW_TYPE_DATE) && (_t & PW_TYPE_MULTI),\
96  __builtin_choose_expr(__builtin_types_compatible_p(uint32_t **, _ct), _p, (conf_type_mismatch) 0),\
97  __builtin_choose_expr((((_t) & 0xff) == PW_TYPE_DATE),\
98  __builtin_choose_expr(__builtin_types_compatible_p(uint32_t *, _ct), _p, (conf_type_mismatch) 0),\
99  __builtin_choose_expr((((_t) & 0xff) == PW_TYPE_ABINARY) && (_t & PW_TYPE_MULTI),\
100  __builtin_choose_expr(__builtin_types_compatible_p(size_t*[32/sizeof(size_t)], _ct), _p, (conf_type_mismatch) 0),\
101  __builtin_choose_expr((((_t) & 0xff) == PW_TYPE_ABINARY),\
102  __builtin_choose_expr(__builtin_types_compatible_p(size_t[32/sizeof(size_t)], _ct), _p, (conf_type_mismatch) 0),\
103  __builtin_choose_expr((((_t) & 0xff) == PW_TYPE_OCTETS) && (_t & PW_TYPE_MULTI),\
104  __builtin_choose_expr(__builtin_types_compatible_p(uint8_t **, _ct), _p, (conf_type_mismatch) 0),\
105  __builtin_choose_expr((((_t) & 0xff) == PW_TYPE_OCTETS),\
106  __builtin_choose_expr(__builtin_types_compatible_p(uint8_t *, _ct), _p, (conf_type_mismatch) 0),\
107  __builtin_choose_expr((((_t) & 0xff) == PW_TYPE_IFID) && (_t & PW_TYPE_MULTI),\
108  __builtin_choose_expr(__builtin_types_compatible_p(uint8_t*[8], _ct), _p, (conf_type_mismatch) 0),\
109  __builtin_choose_expr((((_t) & 0xff) == PW_TYPE_IFID),\
110  __builtin_choose_expr(__builtin_types_compatible_p(uint8_t[8], _ct), _p, (conf_type_mismatch) 0),\
111  __builtin_choose_expr((((_t) & 0xff) == PW_TYPE_IPV6_ADDR) && (_t & PW_TYPE_MULTI),\
112  __builtin_choose_expr(__builtin_types_compatible_p(fr_ipaddr_t **, _ct), _p, (conf_type_mismatch) 0),\
113  __builtin_choose_expr((((_t) & 0xff) == PW_TYPE_IPV6_ADDR),\
114  __builtin_choose_expr(__builtin_types_compatible_p(fr_ipaddr_t *, _ct), _p, (conf_type_mismatch) 0),\
115  __builtin_choose_expr((((_t) & 0xff) == PW_TYPE_IPV6_PREFIX) && (_t & PW_TYPE_MULTI),\
116  __builtin_choose_expr(__builtin_types_compatible_p(fr_ipaddr_t **, _ct), _p, (conf_type_mismatch) 0),\
117  __builtin_choose_expr((((_t) & 0xff) == PW_TYPE_IPV6_PREFIX),\
118  __builtin_choose_expr(__builtin_types_compatible_p(fr_ipaddr_t *, _ct), _p, (conf_type_mismatch) 0),\
119  __builtin_choose_expr((((_t) & 0xff) == PW_TYPE_BYTE) && (_t & PW_TYPE_MULTI),\
120  __builtin_choose_expr(__builtin_types_compatible_p(uint8_t **, _ct), _p, (conf_type_mismatch) 0),\
121  __builtin_choose_expr((((_t) & 0xff) == PW_TYPE_BYTE),\
122  __builtin_choose_expr(__builtin_types_compatible_p(uint8_t *, _ct), _p, (conf_type_mismatch) 0),\
123  __builtin_choose_expr((((_t) & 0xff) == PW_TYPE_SHORT) && (_t & PW_TYPE_MULTI),\
124  __builtin_choose_expr(__builtin_types_compatible_p(uint16_t **, _ct), _p, (conf_type_mismatch) 0),\
125  __builtin_choose_expr((((_t) & 0xff) == PW_TYPE_SHORT),\
126  __builtin_choose_expr(__builtin_types_compatible_p(uint16_t *, _ct), _p, (conf_type_mismatch) 0),\
127  __builtin_choose_expr((((_t) & 0xff) == PW_TYPE_ETHERNET) && (_t & PW_TYPE_MULTI),\
128  __builtin_choose_expr(__builtin_types_compatible_p(uint8_t*[6], _ct), _p, (conf_type_mismatch) 0),\
129  __builtin_choose_expr((((_t) & 0xff) == PW_TYPE_ETHERNET),\
130  __builtin_choose_expr(__builtin_types_compatible_p(uint8_t[6], _ct), _p, (conf_type_mismatch) 0),\
131  __builtin_choose_expr((((_t) & 0xff) == PW_TYPE_SIGNED) && (_t & PW_TYPE_MULTI),\
132  __builtin_choose_expr(__builtin_types_compatible_p(int32_t **, _ct), _p, (conf_type_mismatch) 0),\
133  __builtin_choose_expr((((_t) & 0xff) == PW_TYPE_SIGNED),\
134  __builtin_choose_expr(__builtin_types_compatible_p(int32_t *, _ct), _p, (conf_type_mismatch) 0),\
135  __builtin_choose_expr((((_t) & 0xff) == PW_TYPE_COMBO_IP_ADDR) && (_t & PW_TYPE_MULTI),\
136  __builtin_choose_expr(__builtin_types_compatible_p(fr_ipaddr_t **, _ct), _p, (conf_type_mismatch) 0),\
137  __builtin_choose_expr((((_t) & 0xff) == PW_TYPE_COMBO_IP_ADDR),\
138  __builtin_choose_expr(__builtin_types_compatible_p(fr_ipaddr_t *, _ct), _p, (conf_type_mismatch) 0),\
139  __builtin_choose_expr((((_t) & 0xff) == PW_TYPE_INTEGER64) && (_t & PW_TYPE_MULTI),\
140  __builtin_choose_expr(__builtin_types_compatible_p(uint64_t **, _ct), _p, (conf_type_mismatch) 0),\
141  __builtin_choose_expr((((_t) & 0xff) == PW_TYPE_INTEGER64),\
142  __builtin_choose_expr(__builtin_types_compatible_p(uint64_t *, _ct), _p, (conf_type_mismatch) 0),\
143  __builtin_choose_expr((((_t) & 0xff) == PW_TYPE_IPV4_PREFIX) && (_t & PW_TYPE_MULTI),\
144  __builtin_choose_expr(__builtin_types_compatible_p(fr_ipaddr_t **, _ct), _p, (conf_type_mismatch) 0),\
145  __builtin_choose_expr((((_t) & 0xff) == PW_TYPE_IPV4_PREFIX),\
146  __builtin_choose_expr(__builtin_types_compatible_p(fr_ipaddr_t *, _ct), _p, (conf_type_mismatch) 0),\
147  __builtin_choose_expr((((_t) & 0xff) == PW_TYPE_TIMEVAL) && (_t & PW_TYPE_MULTI),\
148  __builtin_choose_expr(__builtin_types_compatible_p(_timeval_t **, _ct), _p, (conf_type_mismatch) 0),\
149  __builtin_choose_expr((((_t) & 0xff) == PW_TYPE_TIMEVAL),\
150  __builtin_choose_expr(__builtin_types_compatible_p(_timeval_t *, _ct), _p, (conf_type_mismatch) 0),\
151  __builtin_choose_expr((((_t) & 0xff) == PW_TYPE_COMBO_IP_PREFIX) && (_t & PW_TYPE_MULTI),\
152  __builtin_choose_expr(__builtin_types_compatible_p(fr_ipaddr_t **, _ct), _p, (conf_type_mismatch) 0),\
153  __builtin_choose_expr((((_t) & 0xff) == PW_TYPE_COMBO_IP_PREFIX),\
154  __builtin_choose_expr(__builtin_types_compatible_p(fr_ipaddr_t *, _ct), _p, (conf_type_mismatch) 0),\
155  (conf_type_invalid) 0\
156  )))))))))))))))))))))))))))))))))))))))))
157 
158 # define FR_CONF_OFFSET(_n, _t, _s, _f) \
159  .name = _n, \
160  .type = _t, \
161  .offset = FR_CONF_TYPE_CHECK((_t), __typeof__(&(((_s *)NULL)->_f)), offsetof(_s, _f))
162 # define FR_CONF_POINTER(_n, _t, _p) \
163  .name = _n, \
164  .type = _t, \
165  .data = FR_CONF_TYPE_CHECK((_t), __typeof__(_p), _p)
166 # define FR_ITEM_POINTER(_t, _p) _t, FR_CONF_TYPE_CHECK((_t), __typeof__(_p), _p)
167 #else
168 # define FR_CONF_OFFSET(_n, _t, _s, _f) \
169  .name = _n, \
170  .type = _t, \
171  .offset = offsetof(_s, _f)
172 # define FR_CONF_POINTER(_n, _t, _p) \
173  .name = _n, \
174  .type = _t, \
175  .data = _p
176 # define FR_ITEM_POINTER(_t, _p) .type = _t, .data = _p
177 #endif
178 
179 #define FR_CONF_DEPRECATED(_n, _t, _p, _f) \
180  .name = _n, \
181  .type = (_t) | PW_TYPE_DEPRECATED
182 
183 /*
184  * Instead of putting the information into a configuration structure,
185  * the configuration file routines MAY just parse it directly into
186  * user-supplied variables.
187  */
188 #define PW_TYPE_SUBSECTION 102
189 
190 /** @name #CONF_PARSER type flags
191  *
192  * These flags should be or'd with another PW_TYPE_* value to create validation
193  * rules for the #cf_pair_parse function.
194  *
195  * @note File PW_TYPE_FILE_* types have a base type of string, so they're validated
196  * correctly by the config parser.
197  * @{
198  */
199 #define PW_TYPE_DEPRECATED (1 << 10) //!< If a matching #CONF_PAIR is found, error out with a deprecated message.
200 #define PW_TYPE_REQUIRED (1 << 11) //!< Error out if no matching #CONF_PAIR is found, and no dflt value is set.
201 #define PW_TYPE_ATTRIBUTE (1 << 12) //!< Value must resolve to attribute in dict (deprecated, use #PW_TYPE_TMPL).
202 #define PW_TYPE_SECRET (1 << 13) //!< Only print value if debug level >= 3.
203 
204 #define PW_TYPE_FILE_INPUT ((1 << 14) | PW_TYPE_STRING) //!< File matching value must exist, and must be readable.
205 #define PW_TYPE_FILE_OUTPUT ((1 << 15) | PW_TYPE_STRING) //!< File matching value must exist, and must be writeable.
206 
207 #define PW_TYPE_XLAT (1 << 16) //!< string will be dynamically expanded.
208 #define PW_TYPE_TMPL (1 << 17) //!< CONF_PAIR should be parsed as a template.
209 
210 #define PW_TYPE_MULTI (1 << 18) //!< CONF_PAIR can have multiple copies.
211 #define PW_TYPE_NOT_EMPTY (1 << 19) //!< CONF_PAIR is required to have a non zero length value.
212 /* @} **/
213 
214 #define FR_INTEGER_COND_CHECK(_name, _var, _cond, _new)\
215 do {\
216  if (!(_cond)) {\
217  WARN("WARNING: Ignoring \"" _name " = %i\", forcing to \"" _name " = %i\"", _var, _new);\
218  _var = _new;\
219  }\
220 } while (0)
221 
222 #define FR_INTEGER_BOUND_CHECK(_name, _var, _op, _bound) FR_INTEGER_COND_CHECK(_name, _var, (_var _op _bound), _bound)
223 
224 #define FR_TIMEVAL_BOUND_CHECK(_name, _var, _op, _bound_sec, _bound_usec)\
225 do {\
226  struct timeval _bound = {_bound_sec, _bound_usec};\
227  if (!timercmp(_var, &_bound, _op)) {\
228  WARN("WARNING: Ignoring \"" _name " = %d.%.06d\", forcing to \"" _name " = %d.%06d\"",\
229  (int)(_var)->tv_sec, (int)(_var)->tv_usec,\
230  (int)_bound.tv_sec, (int)_bound.tv_usec);\
231  *_var = _bound;\
232  }\
233 } while (0)
234 
235 #define FR_TIMEVAL_TO_MS(_x) (((_x)->tv_usec / 1000) + ((_x)->tv_sec * (uint64_t)1000))
236 #define FR_TIMESPEC_TO_MS(_x) (((_x)->tv_usec / 1000000) + ((_x)->tv_sec * (uint64_t)1000))
237 extern bool check_config;
238 
239 /** Defines a #CONF_PAIR to C data type mapping
240  *
241  * Is typically used to define mappings between module sections, and module instance structs.
242  * May also be used to set global configuration options.
243  *
244  * Offset/data values should be set using #FR_CONF_OFFSET or #FR_CONF_POINTER.
245  *
246  * Example with #FR_CONF_OFFSET :
247  @code{.c}
248  static CONF_PARSER module_config[] = {
249  { FR_CONF_OFFSET("example", PW_TYPE_STRING | PW_TYPE_NOT_EMPTY, example_instance_t, example), .dflt = "default_value" },
250  CONF_PARSER_TERMINATOR
251  }
252  @endcode
253  *
254  * Example with #FR_CONF_POINTER :
255  @code{.c}
256  static CONF_PARSER global_config[] = {
257  { FR_CONF_POINTER("example", PW_TYPE_STRING | PW_TYPE_NOT_EMPTY, &my_global), .dflt = "default_value" },
258  CONF_PARSER_TERMINATOR
259  }
260  @endcode
261  *
262  * @see FR_CONF_OFFSET
263  * @see FR_CONF_POINTER
264  * @see cf_section_parse
265  * @see cf_pair_parse
266  */
267 typedef struct CONF_PARSER {
268  char const *name; //!< Name of the #CONF_ITEM to parse.
269  int type; //!< A #PW_TYPE value, may be or'd with one or more PW_TYPE_* flags.
270  //!< @see cf_pair_parse.
271 
272  size_t offset; //!< Relative offset of field or structure to write the parsed value to.
273  //!< When #type is set to #PW_TYPE_SUBSECTION, may be used to specify
274  //!< a base offset to add to all offsets contained within the
275  //!< subsection.
276  //!< @note Must be used exclusively to #data.
277 
278  void *data; //!< Pointer to a static variable to write the parsed value to.
279  //!< @note Must be used exclusively to #offset.
280 
281  const void *dflt; //!< Default as it would appear in radiusd.conf.
282  //!< When #type is set to #PW_TYPE_SUBSECTION, should be a pointer
283  //!< to the start of another array of #CONF_PARSER structs, forming
284  //!< the subsection.
285 
286  FR_TOKEN quote; //!< Quoting around the default value. Only used for templates.
287 } CONF_PARSER;
288 
289 #define CONF_PARSER_TERMINATOR { NULL, -1, 0, NULL, NULL, T_INVALID }
290 
291 CONF_PAIR *cf_pair_alloc(CONF_SECTION *parent, char const *attr, char const *value,
292  FR_TOKEN op, FR_TOKEN lhs_type, FR_TOKEN rhs_type);
294 void cf_pair_add(CONF_SECTION *parent, CONF_PAIR *cp);
295 
296 CONF_SECTION *cf_section_alloc(CONF_SECTION *parent, char const *name1, char const *name2);
298  char const *name1, char const *name2, bool copy_meta);
299 void cf_section_add(CONF_SECTION *parent, CONF_SECTION *cs);
300 int cf_pair_replace(CONF_SECTION *cs, CONF_PAIR *cp, char const *value);
301 int cf_pair_parse(CONF_SECTION *cs, char const *name, unsigned int type, void *data,
302  char const *dflt, FR_TOKEN dflt_quote);
303 int cf_section_parse(CONF_SECTION *, void *base, CONF_PARSER const *variables);
304 int cf_section_parse_pass2(CONF_SECTION *, void *base, CONF_PARSER const *variables);
306 int cf_file_read(CONF_SECTION *cs, char const *file);
307 void cf_file_free(CONF_SECTION *cs);
308 
309 CONF_PAIR *cf_pair_find(CONF_SECTION const *, char const *name);
310 CONF_PAIR *cf_pair_find_next(CONF_SECTION const *, CONF_PAIR const *, char const *name);
312  char const *name1, char const *name2);
313 CONF_SECTION *cf_section_sub_find(CONF_SECTION const *, char const *name);
314 CONF_SECTION *cf_section_sub_find_name2(CONF_SECTION const *, char const *name1, char const *name2);
315 char const *cf_section_value_find(CONF_SECTION const *, char const *attr);
317 
318 void *cf_data_find(CONF_SECTION const *, char const *);
319 int cf_data_add(CONF_SECTION *, char const *, void *, void (*)(void *));
320 void *cf_data_remove(CONF_SECTION *cs, char const *name);
321 
322 char const *cf_pair_attr(CONF_PAIR const *pair);
323 char const *cf_pair_value(CONF_PAIR const *pair);
324 FR_TOKEN cf_pair_operator(CONF_PAIR const *pair);
328 char const *cf_section_name1(CONF_SECTION const *cs);
329 char const *cf_section_name2(CONF_SECTION const *cs);
330 char const *cf_section_name(CONF_SECTION const *cs);
331 char const *cf_section_argv(CONF_SECTION const *cs, int argc);
333 FR_TOKEN cf_section_argv_type(CONF_SECTION const *cs, int argc);
334 int dump_config(CONF_SECTION const *cs);
336  CONF_SECTION const *subsection,
337  char const *name1);
339  CONF_SECTION const *subsection,
340  char const *name1);
341 int cf_section_lineno(CONF_SECTION const *section);
342 int cf_pair_lineno(CONF_PAIR const *pair);
343 char const *cf_pair_filename(CONF_PAIR const *pair);
344 char const *cf_section_filename(CONF_SECTION const *section);
345 CONF_ITEM *cf_item_find_next(CONF_SECTION const *section, CONF_ITEM const *item);
346 int cf_pair_count(CONF_SECTION const *cs);
348 bool cf_item_is_section(CONF_ITEM const *item);
349 bool cf_item_is_pair(CONF_ITEM const *item);
350 CONF_PAIR *cf_item_to_pair(CONF_ITEM const *item);
354 
355 void cf_log_err(CONF_ITEM const *ci, char const *fmt, ...) CC_HINT(format (printf, 2, 3));
356 void cf_log_err_cs(CONF_SECTION const *cs, char const *fmt, ...) CC_HINT(format (printf, 2, 3));
357 void cf_log_err_cp(CONF_PAIR const *cp, char const *fmt, ...) CC_HINT(format (printf, 2, 3));
358 void cf_log_info(CONF_SECTION const *cs, char const *fmt, ...) CC_HINT(format (printf, 2, 3));
359 void cf_log_module(CONF_SECTION const *cs, char const *fmt, ...) CC_HINT(format (printf, 2, 3));
360 
361 void cf_item_add(CONF_SECTION *cs, CONF_ITEM *ci);
362 CONF_ITEM *cf_reference_item(CONF_SECTION const *parentcs,
363  CONF_SECTION *outercs,
364  char const *ptr);
365 #ifdef WITH_CONF_WRITE
366 size_t cf_section_write(FILE *fp, CONF_SECTION *cs, int depth);
367 #endif
368 
369 #define CF_FILE_NONE (0)
370 #define CF_FILE_ERROR (1)
371 #define CF_FILE_CONFIG (1 << 2)
372 #define CF_FILE_MODULE (1 << 3)
373 int cf_file_changed(CONF_SECTION *cs, rb_walker_t callback);
374 
375 #ifdef __cplusplus
376 }
377 #endif
378 
379 #endif /* _FR_CONFFILE_H */
char const * cf_pair_filename(CONF_PAIR const *pair)
Definition: conffile.c:3908
FR_TOKEN quote
Quoting around the default value. Only used for templates.
Definition: conffile.h:286
#define RCSIDH(h, id)
Definition: build.h:136
int dump_config(CONF_SECTION const *cs)
FR_TOKEN cf_pair_value_type(CONF_PAIR const *pair)
Return the value (rhs) type.
Definition: conffile.c:3541
int cf_pair_parse(CONF_SECTION *cs, char const *name, unsigned int type, void *data, char const *dflt, FR_TOKEN dflt_quote)
Parses a CONF_PAIR into a C data type, with a default value.
Definition: conffile.c:1968
void * data
Pointer to a static variable to write the parsed value to.
Definition: conffile.h:278
char const * name
Name of the CONF_ITEM to parse.
Definition: conffile.h:268
char const * cf_section_filename(CONF_SECTION const *section)
Definition: conffile.c:3913
int type
A PW_TYPE value, may be or'd with one or more PW_TYPE_* flags.
Definition: conffile.h:269
FR_TOKEN cf_section_name2_type(CONF_SECTION const *cs)
Definition: conffile.c:4148
CONF_ITEM * cf_pair_to_item(CONF_PAIR const *cp)
Cast a CONF_PAIR to a CONF_ITEM.
Definition: conffile.c:211
static char const * name
#define CC_HINT(_x)
Definition: build.h:71
void cf_pair_add(CONF_SECTION *parent, CONF_PAIR *cp)
Add a configuration pair to a section.
Definition: conffile.c:612
int cf_file_read(CONF_SECTION *cs, char const *file)
Definition: conffile.c:3421
void void void cf_log_err_cp(CONF_PAIR const *cp, char const *fmt,...) CC_HINT(format(printf
CONF_SECTION * cf_section_find_name2(CONF_SECTION const *section, char const *name1, char const *name2)
Definition: conffile.c:3639
size_t offset
Relative offset of field or structure to write the parsed value to.
Definition: conffile.h:272
void * cf_data_remove(CONF_SECTION *cs, char const *name)
Remove named data from a configuration section.
Definition: conffile.c:4027
int cf_file_changed(CONF_SECTION *cs, rb_walker_t callback)
Definition: conffile.c:486
CONF_SECTION * cf_item_to_section(CONF_ITEM const *item)
Cast a CONF_ITEM to a CONF_SECTION.
Definition: conffile.c:196
FR_TOKEN cf_section_argv_type(CONF_SECTION const *cs, int argc)
Definition: conffile.c:4155
Defines a CONF_PAIR to C data type mapping.
Definition: conffile.h:267
void void void void void void cf_item_add(CONF_SECTION *cs, CONF_ITEM *ci)
Definition: conffile.c:803
void conf_type_invalid
Dummy type used to indicate invalid PW_TYPE_*.
Definition: conffile.h:49
CONF_PAIR * cf_pair_find(CONF_SECTION const *, char const *name)
Definition: conffile.c:3478
char const * cf_pair_value(CONF_PAIR const *pair)
Definition: conffile.c:3506
int cf_section_lineno(CONF_SECTION const *section)
Definition: conffile.c:3903
const CONF_PARSER * cf_section_parse_table(CONF_SECTION *cs)
Definition: conffile.c:4138
void cf_file_free(CONF_SECTION *cs)
Definition: conffile.c:3469
int cf_pair_replace(CONF_SECTION *cs, CONF_PAIR *cp, char const *value)
Replace pair in a given section with a new pair, of the given value.
Definition: conffile.c:768
char const * cf_pair_attr(CONF_PAIR const *pair)
Definition: conffile.c:3497
CONF_SECTION * cf_section_dup(CONF_SECTION *parent, CONF_SECTION const *cs, char const *name1, char const *name2, bool copy_meta)
Duplicate a configuration section.
Definition: conffile.c:697
VALUE_PAIR * cf_pairtovp(CONF_PAIR *pair)
Definition: conffile.c:3550
bool cf_item_is_section(CONF_ITEM const *item)
Definition: conffile.c:3923
void void void void cf_log_info(CONF_SECTION const *cs, char const *fmt,...) CC_HINT(format(printf
CONF_SECTION * cf_subsection_find_next(CONF_SECTION const *section, CONF_SECTION const *subsection, char const *name1)
Definition: conffile.c:3799
char const * cf_section_name(CONF_SECTION const *cs)
Return name2 if set, else name1.
Definition: conffile.c:3609
int cf_section_parse_pass2(CONF_SECTION *, void *base, CONF_PARSER const *variables)
CONF_PAIR * cf_item_to_pair(CONF_ITEM const *item)
Cast a CONF_ITEM to a CONF_PAIR.
Definition: conffile.c:181
CONF_SECTION * cf_item_parent(CONF_ITEM const *ci)
Definition: conffile.c:3896
int cf_section_parse(CONF_SECTION *, void *base, CONF_PARSER const *variables)
Parse a configuration section into user-supplied variables.
Definition: conffile.c:2234
const void * dflt
Default as it would appear in radiusd.conf.
Definition: conffile.h:281
CONF_SECTION * cf_top_section(CONF_SECTION *cs)
Definition: conffile.c:1041
CONF_ITEM * cf_section_to_item(CONF_SECTION const *cs)
Cast a CONF_SECTION to a CONF_ITEM.
Definition: conffile.c:224
int cf_pair_count(CONF_SECTION const *cs)
Count the number of conf pairs beneath a section.
Definition: conffile.c:3887
void conf_type_mismatch
Dummy type used to indicate PW_TYPE_*/C type mismatch.
Definition: conffile.h:48
CONF_SECTION * cf_section_find_next(CONF_SECTION const *section, CONF_SECTION const *subsection, char const *name1)
Definition: conffile.c:3836
Stores an attribute, a value and various bits of other data.
Definition: pair.h:112
void void cf_log_err_cs(CONF_SECTION const *cs, char const *fmt,...) CC_HINT(format(printf
CONF_PAIR * cf_pair_find_next(CONF_SECTION const *, CONF_PAIR const *, char const *name)
Find a pair with a name matching attr, after specified pair.
Definition: conffile.c:3673
bool cf_item_is_pair(CONF_ITEM const *item)
Definition: conffile.c:3928
int cf_pair_lineno(CONF_PAIR const *pair)
Definition: conffile.c:3918
int cf_data_add(CONF_SECTION *, char const *, void *, void(*)(void *))
Definition: conffile.c:4018
Configuration AVP similar to a VALUE_PAIR.
Definition: conffile.c:82
int(* rb_walker_t)(void *ctx, void *data)
Definition: libradius.h:530
Internal data that is associated with a configuration section.
Definition: conffile.c:99
CONF_SECTION * cf_section_sub_find(CONF_SECTION const *, char const *name)
Find a sub-section in a section.
Definition: conffile.c:3708
char const * cf_section_name1(CONF_SECTION const *cs)
Definition: conffile.c:3592
CONF_PAIR * cf_pair_alloc(CONF_SECTION *parent, char const *attr, char const *value, FR_TOKEN op, FR_TOKEN lhs_type, FR_TOKEN rhs_type)
Allocate a CONF_PAIR.
Definition: conffile.c:546
char const * cf_section_argv(CONF_SECTION const *cs, int argc)
Definition: conffile.c:3619
uint8_t data[]
Definition: eap_pwd.h:625
void cf_log_err(CONF_ITEM const *ci, char const *fmt,...) CC_HINT(format(printf
CONF_SECTION * cf_section_alloc(CONF_SECTION *parent, char const *name1, char const *name2)
Allocate a CONF_SECTION.
Definition: conffile.c:626
char const * cf_section_value_find(CONF_SECTION const *, char const *attr)
Definition: conffile.c:3629
CONF_ITEM * cf_item_find_next(CONF_SECTION const *section, CONF_ITEM const *item)
Return the next item after a CONF_ITEM.
Definition: conffile.c:3850
bool check_config
Definition: conffile.c:45
enum fr_token FR_TOKEN
FR_TOKEN cf_pair_attr_type(CONF_PAIR const *pair)
Return the value (lhs) type.
Definition: conffile.c:3526
void * cf_data_find(CONF_SECTION const *, char const *)
Definition: conffile.c:3981
CONF_PAIR * cf_pair_dup(CONF_SECTION *parent, CONF_PAIR *cp)
Duplicate a CONF_PAIR.
Definition: conffile.c:589
CONF_SECTION * cf_section_sub_find_name2(CONF_SECTION const *, char const *name1, char const *name2)
Find a CONF_SECTION with both names.
Definition: conffile.c:3728
void cf_section_add(CONF_SECTION *parent, CONF_SECTION *cs)
Definition: conffile.c:754
FR_TOKEN cf_pair_operator(CONF_PAIR const *pair)
Definition: conffile.c:3511
void void void void void cf_log_module(CONF_SECTION const *cs, char const *fmt,...) CC_HINT(format(printf
struct CONF_PARSER CONF_PARSER
Defines a CONF_PAIR to C data type mapping.
char const * cf_section_name2(CONF_SECTION const *cs)
Definition: conffile.c:3601
CONF_ITEM * cf_reference_item(CONF_SECTION const *parentcs, CONF_SECTION *outercs, char const *ptr)
Definition: conffile.c:906