23 RCSID(
"$Id: 4dc328019e1dde737efac8a93a36943c05a063af $")
25 #include <freeradius-devel/server/cf_file.h>
26 #include <freeradius-devel/server/main_config.h>
27 #include <freeradius-devel/server/modpriv.h>
28 #include <freeradius-devel/server/module_rlm.h>
29 #include <freeradius-devel/util/atexit.h>
30 #include <freeradius-devel/util/file.h>
32 #include <freeradius-devel/util/conf.h>
40 #include <freeradius-devel/server/log.h>
42 #define EXIT_WITH_FAILURE \
61 fprintf(stderr,
"usage: %s [OPTS] filename ...\n", argv[0]);
62 fprintf(stderr,
" -d <raddb> Set user dictionary directory (defaults to " RADDBDIR
").\n");
63 fprintf(stderr,
" -D <dictdir> Set main dictionary directory (defaults to " DICTDIR
").\n");
64 fprintf(stderr,
" -x Debugging mode.\n");
65 fprintf(stderr,
" -M Show program version information.\n");
66 fprintf(stderr,
" -r <receipt_file> Create the <receipt_file> as a 'success' exit.\n");
74 char const *name1, *name2;
86 .allow_foreign =
false,
94 fprintf(stderr,
"Failed allocating main config");
101 fprintf(stderr,
"unit_test_map: Failed parsing %s\n", filename);
124 if (map_list_empty(&list)) {
125 cf_log_err(cs,
"'update' sections cannot be empty");
138 printf(
"%s {\n", name1);
140 printf(
"%s %s {\n", name1, name2);
143 while ((map = map_list_next(&list, map))) {
159 int main(
int argc,
char *argv[])
161 int c, ret = EXIT_SUCCESS;
162 char const *raddb_dir = RADDBDIR;
163 char const *dict_dir = DICTDIR;
165 char const *receipt_file = NULL;
195 while ((c = getopt(argc, argv,
"d:D:xMhr:")) != -1)
switch (c) {
209 talloc_enable_leak_report();
213 receipt_file = optarg;
220 argc -= (optind - 1);
221 argv += (optind - 1);
223 if (receipt_file && (
fr_unlink(receipt_file) < 0)) {
272 if (ret < 0) ret = 1;
296 if (receipt_file && (ret == EXIT_SUCCESS) && (
fr_touch(NULL, receipt_file, 0644,
true, 0755) <= 0)) {
static int const char char buffer[256]
int fr_atexit_global_setup(void)
Setup the atexit handler, should be called at the start of a program's execution.
int fr_atexit_global_trigger_all(void)
Cause all global free triggers to fire.
#define fr_atexit_thread_trigger_all(...)
#define NEVER_RETURNS
Should be placed before the function return type.
void cf_section_set_unlang(CONF_SECTION *cs)
int cf_file_read(CONF_SECTION *cs, char const *filename)
int cf_section_pass2(CONF_SECTION *cs)
A section grouping multiple CONF_PAIR.
CONF_SECTION * cf_section_find(CONF_SECTION const *cs, char const *name1, char const *name2)
Find a CONF_SECTION with name1 and optionally name2.
char const * cf_section_name2(CONF_SECTION const *cs)
Return the second identifier of a CONF_SECTION.
char const * cf_section_name1(CONF_SECTION const *cs)
Return the second identifier of a CONF_SECTION.
#define cf_log_err(_cf, _fmt,...)
#define cf_log_perr(_cf, _fmt,...)
#define cf_section_alloc(_ctx, _parent, _name1, _name2)
void fr_disable_null_tracking_on_free(TALLOC_CTX *ctx)
Disable the null tracking context when a talloc chunk is freed.
int fr_fault_setup(TALLOC_CTX *ctx, char const *cmd, char const *program)
Registers signal handlers to execute panic_action on fatal signal.
#define fr_exit(_x)
Exit, producing a log message in debug builds.
#define fr_exit_now(_x)
Exit without calling atexit() handlers, producing a log message in debug builds.
int fr_dict_internal_afrom_file(fr_dict_t **out, char const *internal_name, char const *dependent)
(Re-)Initialize the special internal dictionary
#define fr_dict_autofree(_to_free)
fr_dict_t const ** out
Where to write a pointer to the loaded/resolved fr_dict_t.
int fr_dict_free(fr_dict_t **dict, char const *dependent)
Decrement the reference count on a previously loaded dictionary.
#define fr_dict_autoload(_to_load)
int fr_dict_read(fr_dict_t *dict, char const *dict_dir, char const *filename)
Read supplementary attribute definitions into an existing dictionary.
fr_dict_gctx_t * fr_dict_global_ctx_init(TALLOC_CTX *ctx, bool free_at_exit, char const *dict_dir)
Initialise the global protocol hashes.
Specifies a dictionary which must be loaded/loadable for the module to function.
int fr_unlink(char const *filename)
Remove a regular file from the filesystem.
ssize_t fr_touch(int *fd_out, char const *filename, mode_t mode, bool mkdir, mode_t dir_mode)
Create an empty file.
int map_afrom_cs(TALLOC_CTX *ctx, map_list_t *out, CONF_SECTION *cs, tmpl_rules_t const *lhs_rules, tmpl_rules_t const *rhs_rules, map_validate_t validate, void *uctx, unsigned int max)
Convert a config section into an attribute map.
ssize_t map_print(fr_sbuff_t *out, map_t const *map)
Print a map to a string.
void main_config_name_set_default(main_config_t *config, char const *name, bool overwrite_config)
Set the server name.
main_config_t * main_config_alloc(TALLOC_CTX *ctx)
Allocate a main_config_t struct, setting defaults.
Main server configuration.
int unlang_fixup_update(map_t *map, void *ctx)
Validate and fixup a map that's part of an update section.
static const conf_parser_t config[]
static TALLOC_CTX * autofree
fr_dict_attr_t const * request_attr_request
int request_global_init(void)
#define FR_SBUFF_OUT(_start, _len_or_end)
tmpl_attr_rules_t attr
Rules/data for parsing attribute references.
Optional arguments passed to vp_tmpl functions.
fr_dict_t const * dict_def
Default dictionary to use with unqualified attribute references.
#define talloc_autofree_context
The original function is deprecated, so replace it with our version.
int fr_time_start(void)
Initialize the local time.
int main(int argc, char *argv[])
fr_dict_autoload_t unit_test_module_dict[]
static fr_dict_t const * dict_freeradius
static int process_file(char const *filename)
static fr_dict_t const * dict_radius
static NEVER_RETURNS void usage(char *argv[])
#define EXIT_WITH_FAILURE
#define FR_DICTIONARY_FILE
#define FR_DICTIONARY_INTERNAL_DIR
void fr_perror(char const *fmt,...)
Print the current error to stderr with a prefix.
#define fr_strerror_const_push(_msg)
int fr_check_lib_magic(uint64_t magic)
Check if the application linking to the library has the correct magic number.
#define RADIUSD_MAGIC_NUMBER