2 * mainconf.c Handle the server's configuration.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 * Copyright 2002,2006-2007 The FreeRADIUS server project
21 * Copyright 2002 Alan DeKok <aland@ox.org>
26 #include <freeradius-devel/radiusd.h>
27 #include <freeradius-devel/modules.h>
28 #include <freeradius-devel/rad_assert.h>
44 #ifdef HAVE_SYS_STAT_H
52 struct main_config_t mainconfig;
53 char *debug_condition = NULL;
54 extern int log_dates_utc;
56 typedef struct cached_config_t {
57 struct cached_config_t *next;
62 static cached_config_t *cs_cache = NULL;
65 * Temporary local variables for parsing the configuration
70 * Systems that have set/getresuid also have setuid.
72 static uid_t server_uid = 0;
73 static gid_t server_gid = 0;
74 static char const *uid_name = NULL;
75 static char const *gid_name = NULL;
77 static char const *chroot_dir = NULL;
78 static bool allow_core_dumps = false;
79 static char const *radlog_dest = NULL;
82 * These are not used anywhere else..
84 static char const *localstatedir = NULL;
85 static char const *prefix = NULL;
87 static char const *sbindir = NULL;
88 static char const *run_dir = NULL;
89 static char *syslog_facility = NULL;
90 static bool do_colourise = false;
92 static char const *radius_dir = NULL; //!< Path to raddb directory
96 * Security configuration for the server.
98 static const CONF_PARSER security_config[] = {
99 { "max_attributes", PW_TYPE_INTEGER, 0, &fr_max_attributes, STRINGIFY(0) },
100 { "reject_delay", PW_TYPE_INTEGER, 0, &mainconfig.reject_delay, STRINGIFY(0) },
101 { "status_server", PW_TYPE_BOOLEAN, 0, &mainconfig.status_server, "no"},
102 { "allow_vulnerable_openssl", PW_TYPE_BOOLEAN, 0, &mainconfig.allow_vulnerable_openssl, "no"},
103 { NULL, -1, 0, NULL, NULL }
108 * Logging configuration for the server.
110 static const CONF_PARSER logdest_config[] = {
111 { "destination", PW_TYPE_STRING_PTR, 0, &radlog_dest, "files" },
112 { "syslog_facility", PW_TYPE_STRING_PTR, 0, &syslog_facility, STRINGIFY(0) },
114 { "file", PW_TYPE_STRING_PTR, 0, &mainconfig.log_file, "${logdir}/radius.log" },
115 { "requests", PW_TYPE_STRING_PTR, 0, &default_log.file, NULL },
116 { NULL, -1, 0, NULL, NULL }
120 static const CONF_PARSER serverdest_config[] = {
121 { "log", PW_TYPE_SUBSECTION, 0, NULL, (void const *) logdest_config },
122 { "log_file", PW_TYPE_STRING_PTR, 0, &mainconfig.log_file, NULL },
123 { "log_destination", PW_TYPE_STRING_PTR, 0, &radlog_dest, NULL },
124 { "use_utc", PW_TYPE_BOOLEAN, 0, &log_dates_utc, NULL },
125 { NULL, -1, 0, NULL, NULL }
129 static const CONF_PARSER log_config_nodest[] = {
130 { "stripped_names", PW_TYPE_BOOLEAN, 0, &log_stripped_names,"no" },
131 { "auth", PW_TYPE_BOOLEAN, 0, &mainconfig.log_auth, "no" },
132 { "auth_badpass", PW_TYPE_BOOLEAN, 0, &mainconfig.log_auth_badpass, "no" },
133 { "auth_goodpass", PW_TYPE_BOOLEAN, 0, &mainconfig.log_auth_goodpass, "no" },
134 { "msg_badpass", PW_TYPE_STRING_PTR, 0, &mainconfig.auth_badpass_msg, NULL},
135 { "msg_goodpass", PW_TYPE_STRING_PTR, 0, &mainconfig.auth_goodpass_msg, NULL},
136 { "colourise", PW_TYPE_BOOLEAN, 0, &do_colourise, NULL },
137 { "use_utc", PW_TYPE_BOOLEAN, 0, &log_dates_utc, NULL },
138 { "msg_denied", PW_TYPE_STRING_PTR, 0, &mainconfig.denied_msg,
139 "You are already logged in - access denied" },
141 { NULL, -1, 0, NULL, NULL }
146 * A mapping of configuration file names to internal variables
148 static const CONF_PARSER server_config[] = {
150 * FIXME: 'prefix' is the ONLY one which should be
151 * configured at compile time. Hard-coding it here is
152 * bad. It will be cleaned up once we clean up the
153 * hard-coded defines for the locations of the various
156 { "name", PW_TYPE_STRING_PTR, 0, &my_name, "radiusd"},
157 { "prefix", PW_TYPE_STRING_PTR, 0, &prefix, "/usr/local"},
158 { "localstatedir", PW_TYPE_STRING_PTR, 0, &localstatedir, "${prefix}/var"},
159 { "sbindir", PW_TYPE_STRING_PTR, 0, &sbindir, "${prefix}/sbin"},
160 { "logdir", PW_TYPE_STRING_PTR, 0, &radlog_dir, "${localstatedir}/log"},
161 { "run_dir", PW_TYPE_STRING_PTR, 0, &run_dir, "${localstatedir}/run/${name}"},
162 { "libdir", PW_TYPE_STRING_PTR, 0, &radlib_dir, "${prefix}/lib"},
163 { "radacctdir", PW_TYPE_STRING_PTR, 0, &radacct_dir, "${logdir}/radacct" },
164 { "panic_action", PW_TYPE_STRING_PTR, 0, &mainconfig.panic_action, NULL},
165 { "hostname_lookups", PW_TYPE_BOOLEAN, 0, &fr_dns_lookups, "no" },
166 { "max_request_time", PW_TYPE_INTEGER, 0, &mainconfig.max_request_time, STRINGIFY(MAX_REQUEST_TIME) },
167 { "cleanup_delay", PW_TYPE_INTEGER, 0, &mainconfig.cleanup_delay, STRINGIFY(CLEANUP_DELAY) },
168 { "max_requests", PW_TYPE_INTEGER, 0, &mainconfig.max_requests, STRINGIFY(MAX_REQUESTS) },
169 #ifdef DELETE_BLOCKED_REQUESTS
170 { "delete_blocked_requests", PW_TYPE_INTEGER, 0, &mainconfig.kill_unresponsive_children, STRINGIFY(false) },
172 { "pidfile", PW_TYPE_STRING_PTR, 0, &mainconfig.pid_file, "${run_dir}/radiusd.pid"},
173 { "checkrad", PW_TYPE_STRING_PTR, 0, &mainconfig.checkrad, "${sbindir}/checkrad" },
175 { "debug_level", PW_TYPE_INTEGER, 0, &mainconfig.debug_level, "0"},
178 { "proxy_requests", PW_TYPE_BOOLEAN, 0, &mainconfig.proxy_requests, "yes" },
180 { "log", PW_TYPE_SUBSECTION, 0, NULL, (void const *) log_config_nodest },
183 * People with old configs will have these. They are listed
184 * AFTER the "log" section, so if they exist in radiusd.conf,
185 * it will prefer "log_foo = bar" to "log { foo = bar }".
186 * They're listed with default values of NULL, so that if they
187 * DON'T exist in radiusd.conf, then the previously parsed
188 * values for "log { foo = bar}" will be used.
190 { "log_auth", PW_TYPE_BOOLEAN | PW_TYPE_DEPRECATED, 0, &mainconfig.log_auth, NULL },
191 { "log_auth_badpass", PW_TYPE_BOOLEAN | PW_TYPE_DEPRECATED, 0, &mainconfig.log_auth_badpass, NULL },
192 { "log_auth_goodpass", PW_TYPE_BOOLEAN | PW_TYPE_DEPRECATED, 0, &mainconfig.log_auth_goodpass, NULL },
193 { "log_stripped_names", PW_TYPE_BOOLEAN | PW_TYPE_DEPRECATED, 0, &log_stripped_names, NULL },
195 { "security", PW_TYPE_SUBSECTION, 0, NULL, (void const *) security_config },
197 { NULL, -1, 0, NULL, NULL }
200 static const CONF_PARSER bootstrap_security_config[] = {
202 { "user", PW_TYPE_STRING_PTR, 0, &uid_name, NULL },
203 { "group", PW_TYPE_STRING_PTR, 0, &gid_name, NULL },
205 { "chroot", PW_TYPE_STRING_PTR, 0, &chroot_dir, NULL },
206 { "allow_core_dumps", PW_TYPE_BOOLEAN, 0, &allow_core_dumps, "no" },
208 { NULL, -1, 0, NULL, NULL }
211 static const CONF_PARSER bootstrap_config[] = {
212 { "security", PW_TYPE_SUBSECTION, 0, NULL, (void const *) bootstrap_security_config },
215 * For backwards compatibility.
218 { "user", PW_TYPE_STRING_PTR | PW_TYPE_DEPRECATED, 0, &uid_name, NULL },
219 { "group", PW_TYPE_STRING_PTR | PW_TYPE_DEPRECATED, 0, &gid_name, NULL },
221 { "chroot", PW_TYPE_STRING_PTR | PW_TYPE_DEPRECATED, 0, &chroot_dir, NULL },
222 { "allow_core_dumps", PW_TYPE_BOOLEAN | PW_TYPE_DEPRECATED, 0, &allow_core_dumps, NULL },
224 { NULL, -1, 0, NULL, NULL }
229 #define MAX_ARGV (256)
232 static size_t config_escape_func(UNUSED REQUEST *request, char *out, size_t outlen, char const *in, UNUSED void *arg)
235 static char const *disallowed = "%{}\\'\"`";
239 * Non-printable characters get replaced with their
240 * mime-encoded equivalents.
243 if (outlen <= 3) break;
245 snprintf(out, outlen, "=%02X", (unsigned char) in[0]);
252 } else if (strchr(disallowed, *in) != NULL) {
253 if (outlen <= 2) break;
265 * Only one byte left.
285 * Xlat for %{config:section.subsection.attribute}
287 static ssize_t xlat_config(UNUSED void *instance, REQUEST *request, char const *fmt, char *out, size_t outlen)
297 if (radius_xlat(buffer, sizeof(buffer), request, fmt, config_escape_func, NULL) < 0) {
301 ci = cf_reference_item(request->root->config,
302 request->root->config, buffer);
303 if (!ci || !cf_item_is_pair(ci)) {
304 REDEBUG("Config item \"%s\" does not exist", fmt);
309 cp = cf_itemtopair(ci);
312 * Ensure that we only copy what's necessary.
314 * If 'outlen' is too small, then the output is chopped to fit.
316 value = cf_pair_value(cp);
322 if (outlen > strlen(value)) {
323 outlen = strlen(value) + 1;
326 strlcpy(out, value, outlen);
333 * Xlat for %{client:foo}
335 static ssize_t xlat_client(UNUSED void *instance, REQUEST *request, char const *fmt, char *out, size_t outlen)
337 char const *value = NULL;
340 if (!fmt || !out || (outlen < 1)) return 0;
342 if (!request || !request->client) {
343 RWDEBUG("No client associated with this request");
348 cp = cf_pair_find(request->client->cs, fmt);
349 if (!cp || !(value = cf_pair_value(cp))) {
350 if (strcmp(fmt, "shortname") == 0) {
351 strlcpy(out, request->client->shortname, outlen);
354 RDEBUG("Client does not contain config item \"%s\"", fmt);
359 strlcpy(out, value, outlen);
365 * Xlat for %{getclient:<ipaddr>.foo}
367 static ssize_t xlat_getclient(UNUSED void *instance, REQUEST *request, char const *fmt, char *out, size_t outlen)
369 char const *value = NULL;
370 char buffer[INET6_ADDRSTRLEN], *q;
374 RADCLIENT *client = NULL;
376 if (!fmt || !out || (outlen < 1)) return 0;
379 if (!q || (q == p) || (((size_t)(q - p)) > sizeof(buffer))) {
380 REDEBUG("Invalid client string");
384 strlcpy(buffer, p, (q + 1) - p);
385 if (ip_ptonx(buffer, &ip) <= 0) {
386 REDEBUG("\"%s\" is not a valid IPv4 or IPv6 address", buffer);
392 client = client_find(NULL, &ip, IPPROTO_IP);
394 RDEBUG("No client found with IP \"%s\"", buffer);
399 cp = cf_pair_find(client->cs, fmt);
400 if (!cp || !(value = cf_pair_value(cp))) {
401 if (strcmp(fmt, "shortname") == 0) {
402 strlcpy(out, request->client->shortname, outlen);
405 RDEBUG("Client does not contain config item \"%s\"", fmt);
410 strlcpy(out, value, outlen);
419 static bool doing_setuid = false;
421 # if defined(HAVE_SETRESUID) && defined (HAVE_GETRESUID)
422 void fr_suid_up(void)
424 uid_t ruid, euid, suid;
426 if (getresuid(&ruid, &euid, &suid) < 0) {
427 ERROR("Failed getting saved UID's");
431 if (setresuid(-1, suid, -1) < 0) {
432 ERROR("Failed switching to privileged user");
436 if (geteuid() != suid) {
437 ERROR("Switched to unknown UID");
442 void fr_suid_down(void)
444 if (!doing_setuid) return;
446 if (setresuid(-1, server_uid, geteuid()) < 0) {
447 fprintf(stderr, "%s: Failed switching to uid %s: %s\n",
448 progname, uid_name, fr_syserror(errno));
452 if (geteuid() != server_uid) {
453 fprintf(stderr, "%s: Failed switching uid: UID is incorrect\n",
458 fr_set_dumpable(allow_core_dumps);
461 void fr_suid_down_permanent(void)
463 if (!doing_setuid) return;
465 if (setresuid(server_uid, server_uid, server_uid) < 0) {
466 ERROR("Failed in permanent switch to uid %s: %s",
467 uid_name, fr_syserror(errno));
471 if (geteuid() != server_uid) {
472 ERROR("Switched to unknown uid");
476 fr_set_dumpable(allow_core_dumps);
480 * Much less secure...
482 void fr_suid_up(void)
486 void fr_suid_down(void)
488 if (!uid_name) return;
490 if (setuid(server_uid) < 0) {
491 fprintf(stderr, "%s: Failed switching to uid %s: %s\n",
492 progname, uid_name, fr_syserror(errno));
496 fr_set_dumpable(allow_core_dumps);
499 void fr_suid_down_permanent(void)
501 fr_set_dumpable(allow_core_dumps);
503 # endif /* HAVE_SETRESUID && HAVE_GETRESUID */
504 #else /* HAVE_SETUID */
505 void fr_suid_up(void)
508 void fr_suid_down(void)
510 fr_set_dumpable(allow_core_dumps);
512 void fr_suid_down_permanent(void)
514 fr_set_dumpable(allow_core_dumps);
516 #endif /* HAVE_SETUID */
521 * Do chroot, if requested.
523 * Switch UID and GID to what is specified in the config file
525 static int switch_users(CONF_SECTION *cs)
528 * Get the current maximum for core files. Do this
529 * before anything else so as to ensure it's properly
532 if (fr_set_dumpable_init() < 0) {
533 fr_perror("radiusd");
538 * Don't do chroot/setuid/setgid if we're in debugging
541 if (debug_flag && (getuid() != 0)) return 1;
543 if (cf_section_parse(cs, NULL, bootstrap_config) < 0) {
544 fprintf(stderr, "radiusd: Error: Failed to parse user/group information.\n");
554 gr = getgrnam(gid_name);
556 fprintf(stderr, "%s: Cannot get ID for group %s: %s\n",
557 progname, gid_name, fr_syserror(errno));
560 server_gid = gr->gr_gid;
562 server_gid = getgid();
571 pw = getpwnam(uid_name);
573 fprintf(stderr, "%s: Cannot get passwd entry for user %s: %s\n",
574 progname, uid_name, fr_syserror(errno));
578 if (getuid() == pw->pw_uid) {
582 server_uid = pw->pw_uid;
583 #ifdef HAVE_INITGROUPS
584 if (initgroups(uid_name, server_gid) < 0) {
585 fprintf(stderr, "%s: Cannot initialize supplementary group list for user %s: %s\n",
586 progname, uid_name, fr_syserror(errno));
592 server_uid = getuid();
597 if (chroot(chroot_dir) < 0) {
598 fprintf(stderr, "%s: Failed to perform chroot %s: %s",
599 progname, chroot_dir, fr_syserror(errno));
604 * Note that we leave chdir alone. It may be
605 * OUTSIDE of the root. This allows us to read
606 * the configuration from "-d ./etc/raddb", with
607 * the chroot as "./chroot/" for example. After
608 * the server has been loaded, it does a "cd
609 * ${logdir}" below, so that core files (if any)
610 * go to a logging directory.
612 * This also allows the configuration of the
613 * server to be outside of the chroot. If the
614 * server is statically linked, then the only
615 * things needed inside of the chroot are the
616 * logging directories.
622 if (gid_name && (setgid(server_gid) < 0)) {
623 fprintf(stderr, "%s: Failed setting group to %s: %s",
624 progname, gid_name, fr_syserror(errno));
631 * Just before losing root permissions, ensure that the
632 * log files have the correct owner && group.
634 * We have to do this because the log file MAY have been
635 * specified on the command-line.
637 if (uid_name || gid_name) {
638 if ((default_log.dst == L_DST_FILES) &&
639 (default_log.fd < 0)) {
640 default_log.fd = open(mainconfig.log_file,
641 O_WRONLY | O_APPEND | O_CREAT, 0640);
642 if (default_log.fd < 0) {
643 fprintf(stderr, "radiusd: Failed to open log file %s: %s\n", mainconfig.log_file, fr_syserror(errno));
647 if (chown(mainconfig.log_file, server_uid, server_gid) < 0) {
648 fprintf(stderr, "%s: Cannot change ownership of log file %s: %s\n",
649 progname, mainconfig.log_file, fr_syserror(errno));
663 * This also clears the dumpable flag if core dumps
666 if (fr_set_dumpable(allow_core_dumps) < 0) {
667 ERROR("%s", fr_strerror());
670 if (allow_core_dumps) {
671 INFO("Core dumps are enabled.");
676 #endif /* HAVE_SETUID */
678 /** Set the global radius config directory.
680 * @param ctx Where to allocate the memory for the path string.
681 * @param path to config dir root e.g. /usr/local/etc/raddb
683 void set_radius_dir(TALLOC_CTX *ctx, char const *path)
688 memcpy(&p, &radius_dir, sizeof(p));
692 if (path) radius_dir = talloc_strdup(ctx, path);
695 /** Get the global radius config directory.
697 * @return the global radius config directory.
699 char const *get_radius_dir(void)
707 * This function can ONLY be called from the main server process.
709 int read_mainconfig(int reload)
712 char const *p = NULL;
719 ERROR("Reload is not implemented");
723 if (stat(radius_dir, &statbuf) < 0) {
724 ERROR("Errors reading %s: %s",
725 radius_dir, fr_syserror(errno));
730 if ((statbuf.st_mode & S_IWOTH) != 0) {
731 ERROR("Configuration directory %s is globally writable. Refusing to start due to insecure configuration.",
738 if (0 && (statbuf.st_mode & S_IROTH) != 0) {
739 ERROR("Configuration directory %s is globally readable. Refusing to start due to insecure configuration.",
744 INFO("Starting - reading configuration files ...");
747 * We need to load the dictionaries before reading the
748 * configuration files. This is because of the
749 * pre-compilation in conffile.c. That should probably
750 * be fixed to be done as a second stage.
752 if (!mainconfig.dictionary_dir) {
753 mainconfig.dictionary_dir = DICTDIR;
757 * Read the distribution dictionaries first, then
760 DEBUG2("including dictionary file %s/%s", mainconfig.dictionary_dir, RADIUS_DICTIONARY);
761 if (dict_init(mainconfig.dictionary_dir, RADIUS_DICTIONARY) != 0) {
762 ERROR("Errors reading dictionary: %s",
768 * Try to load protocol-specific dictionaries. It's OK
769 * if they don't exist.
772 dict_read(mainconfig.dictionary_dir, "dictionary.dhcp");
776 dict_read(mainconfig.dictionary_dir, "dictionary.vqp");
780 * It's OK if this one doesn't exist.
782 rcode = dict_read(radius_dir, RADIUS_DICTIONARY);
784 ERROR("Errors reading %s/%s: %s", radius_dir, RADIUS_DICTIONARY,
790 * We print this after reading it. That way if
791 * it doesn't exist, it's OK, and we don't print
795 DEBUG2("including dictionary file %s/%s", radius_dir, RADIUS_DICTIONARY);
798 /* Read the configuration file */
799 snprintf(buffer, sizeof(buffer), "%.200s/%.50s.conf",
800 radius_dir, mainconfig.name);
801 if ((cs = cf_file_read(buffer)) == NULL) {
802 ERROR("Errors reading or parsing %s", buffer);
807 * If there was no log destination set on the command line,
810 if (default_log.dst == L_DST_NULL) {
811 if (cf_section_parse(cs, NULL, serverdest_config) < 0) {
812 fprintf(stderr, "radiusd: Error: Failed to parse log{} section.\n");
818 fprintf(stderr, "radiusd: Error: No log destination specified.\n");
823 default_log.dst = fr_str2int(log_str2dst, radlog_dest,
825 if (default_log.dst == L_DST_NUM_DEST) {
826 fprintf(stderr, "radiusd: Error: Unknown log_destination %s\n",
832 if (default_log.dst == L_DST_SYSLOG) {
834 * Make sure syslog_facility isn't NULL
837 if (!syslog_facility) {
838 fprintf(stderr, "radiusd: Error: Syslog chosen but no facility was specified\n");
842 mainconfig.syslog_facility = fr_str2int(syslog_str2fac, syslog_facility, -1);
843 if (mainconfig.syslog_facility < 0) {
844 fprintf(stderr, "radiusd: Error: Unknown syslog_facility %s\n",
852 * Call openlog only once, when the
855 openlog(progname, LOG_PID, mainconfig.syslog_facility);
858 } else if (default_log.dst == L_DST_FILES) {
859 if (!mainconfig.log_file) {
860 fprintf(stderr, "radiusd: Error: Specified \"files\" as a log destination, but no log filename was given!\n");
869 * Switch users as early as possible.
871 if (!switch_users(cs)) fr_exit(1);
875 * Open the log file AFTER switching uid / gid. If we
876 * did switch uid/gid, then the code in switch_users()
877 * took care of setting the file permissions correctly.
879 if ((default_log.dst == L_DST_FILES) &&
880 (default_log.fd < 0)) {
881 default_log.fd = open(mainconfig.log_file,
882 O_WRONLY | O_APPEND | O_CREAT, 0640);
883 if (default_log.fd < 0) {
884 fprintf(stderr, "radiusd: Failed to open log file %s: %s\n", mainconfig.log_file, fr_syserror(errno));
891 * This allows us to figure out where, relative to
892 * radiusd.conf, the other configuration files exist.
894 if (cf_section_parse(cs, NULL, server_config) < 0) {
899 * We ignore colourization of output until after the
900 * configuration files have been parsed.
903 if (do_colourise && p && isatty(default_log.fd) && strstr(p, "xterm")) {
904 default_log.colourise = true;
906 default_log.colourise = false;
909 if (mainconfig.max_request_time == 0) mainconfig.max_request_time = 100;
910 if (mainconfig.reject_delay > 5) mainconfig.reject_delay = 5;
911 if (mainconfig.cleanup_delay > 5) mainconfig.cleanup_delay =5;
914 * Free the old configuration items, and replace them
917 * Note that where possible, we do atomic switch-overs,
918 * to ensure that the pointers are always valid.
920 rad_assert(mainconfig.config == NULL);
921 root_config = mainconfig.config = cs;
923 DEBUG2("%s: #### Loading Realms and Home Servers ####", mainconfig.name);
924 if (!realms_init(cs)) {
928 DEBUG2("%s: #### Loading Clients ####", mainconfig.name);
929 if (!clients_parse_section(cs, false)) {
934 * Register the %{config:section.subsection} xlat function.
936 xlat_register("config", xlat_config, NULL, NULL);
937 xlat_register("client", xlat_client, NULL, NULL);
938 xlat_register("getclient", xlat_getclient, NULL, NULL);
941 * Starting the server, WITHOUT "-x" on the
942 * command-line: use whatever is in the config
945 if (debug_flag == 0) {
946 debug_flag = mainconfig.debug_level;
948 fr_debug_flag = debug_flag;
951 * Go update our behaviour, based on the configuration
956 * Sanity check the configuration for internal
959 if (mainconfig.reject_delay > mainconfig.cleanup_delay) {
960 mainconfig.reject_delay = mainconfig.cleanup_delay;
962 if (mainconfig.reject_delay < 0) mainconfig.reject_delay = 0;
964 /* Reload the modules. */
965 if (setup_modules(reload, mainconfig.config) < 0) {
970 if (chdir(radlog_dir) < 0) {
971 ERROR("Failed to 'chdir %s' after chroot: %s",
972 radlog_dir, fr_syserror(errno));
977 cc = talloc_zero(NULL, cached_config_t);
980 cc->cs = talloc_steal(cc ,cs);
981 rad_assert(cs_cache == NULL);
984 /* Clear any unprocessed configuration errors */
985 (void) fr_strerror();
991 * Free the configuration. Called only when the server is exiting.
993 int free_mainconfig(void)
995 virtual_servers_free(0);
998 * Clean up the configuration data
1003 listen_free(&mainconfig.listen);
1006 * Frees current config and any previous configs.
1008 TALLOC_FREE(cs_cache);
1014 void hup_logfile(void)
1018 if (default_log.dst != L_DST_FILES) return;
1020 fd = open(mainconfig.log_file,
1021 O_WRONLY | O_APPEND | O_CREAT, 0640);
1024 * Atomic swap. We'd like to keep the old
1025 * FD around so that callers don't
1026 * suddenly find the FD closed, and the
1027 * writes go nowhere. But that's hard to
1028 * do. So... we have the case where a
1029 * log message *might* be lost on HUP.
1031 old_fd = default_log.fd;
1032 default_log.fd = fd;
1037 void hup_mainconfig(void)
1039 cached_config_t *cc;
1043 INFO("HUP - Re-reading configuration files");
1045 /* Read the configuration file */
1046 snprintf(buffer, sizeof(buffer), "%.200s/%.50s.conf",
1047 radius_dir, mainconfig.name);
1048 if ((cs = cf_file_read(buffer)) == NULL) {
1049 ERROR("Failed to re-read or parse %s", buffer);
1053 cc = talloc_zero(cs_cache, cached_config_t);
1055 ERROR("Out of memory");
1060 * Save the current configuration. Note that we do NOT
1061 * free older ones. We should probably do so at some
1062 * point. Doing so will require us to mark which modules
1063 * are still in use, and which aren't. Modules that
1064 * can't be HUPed always use the original configuration.
1065 * Modules that can be HUPed use one of the newer
1068 cc->created = time(NULL);
1069 cc->cs = talloc_steal(cc, cs);
1070 cc->next = cs_cache;
1074 * Re-open the log file. If we can't, then keep logging
1075 * to the old log file.
1077 * The "open log file" code is here rather than in log.c,
1078 * because it makes that function MUCH simpler.
1082 INFO("HUP - loading modules");
1085 * Prefer the new module configuration.
1087 module_hup(cf_section_sub_find(cs, "modules"));
1090 * Load new servers BEFORE freeing old ones.
1092 virtual_servers_load(cs);
1094 virtual_servers_free(cc->created - mainconfig.max_request_time * 4);