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>
24 #include <freeradius-devel/ident.h>
27 #include <freeradius-devel/radiusd.h>
28 #include <freeradius-devel/modules.h>
29 #include <freeradius-devel/rad_assert.h>
33 #ifdef HAVE_SYS_RESOURCE_H
34 #include <sys/resource.h>
45 #ifdef HAVE_SYS_PRCTL_H
46 #include <sys/prctl.h>
53 #ifdef HAVE_SYS_STAT_H
61 struct main_config_t mainconfig;
62 char *request_log_file = NULL;
63 char *debug_condition = NULL;
66 extern int log_dates_utc;
69 typedef struct cached_config_t {
70 struct cached_config_t *next;
75 static cached_config_t *cs_cache = NULL;
78 * Temporary local variables for parsing the configuration
83 * Systems that have set/getresuid also have setuid.
85 static uid_t server_uid = 0;
86 static gid_t server_gid = 0;
87 static const char *uid_name = NULL;
88 static const char *gid_name = NULL;
90 static const char *chroot_dir = NULL;
91 static int allow_core_dumps = 0;
92 static const char *radlog_dest = NULL;
95 * These are not used anywhere else..
97 static const char *localstatedir = NULL;
98 static const char *prefix = NULL;
99 static const char *my_name = NULL;
100 static const char *sbindir = NULL;
101 static const char *run_dir = NULL;
102 static char *syslog_facility = NULL;
105 * Syslog facility table.
107 const FR_NAME_NUMBER syslog_str2fac[] = {
109 { "kern", LOG_KERN },
112 { "user", LOG_USER },
115 { "mail", LOG_MAIL },
118 { "daemon", LOG_DAEMON },
121 { "auth", LOG_AUTH },
127 { "news", LOG_NEWS },
130 { "uucp", LOG_UUCP },
133 { "cron", LOG_CRON },
136 { "authpriv", LOG_AUTHPRIV },
142 { "local0", LOG_LOCAL0 },
145 { "local1", LOG_LOCAL1 },
148 { "local2", LOG_LOCAL2 },
151 { "local3", LOG_LOCAL3 },
154 { "local4", LOG_LOCAL4 },
157 { "local5", LOG_LOCAL5 },
160 { "local6", LOG_LOCAL6 },
163 { "local7", LOG_LOCAL7 },
169 * Security configuration for the server.
171 static const CONF_PARSER security_config[] = {
172 { "max_attributes", PW_TYPE_INTEGER, 0, &fr_max_attributes, Stringify(0) },
173 { "reject_delay", PW_TYPE_INTEGER, 0, &mainconfig.reject_delay, Stringify(0) },
174 { "status_server", PW_TYPE_BOOLEAN, 0, &mainconfig.status_server, "no"},
175 { NULL, -1, 0, NULL, NULL }
180 * Logging configuration for the server.
182 static const CONF_PARSER logdest_config[] = {
183 { "destination", PW_TYPE_STRING_PTR, 0, &radlog_dest, "files" },
184 { "syslog_facility", PW_TYPE_STRING_PTR, 0, &syslog_facility, Stringify(0) },
186 { "file", PW_TYPE_STRING_PTR, 0, &mainconfig.log_file, "${logdir}/radius.log" },
187 { "requests", PW_TYPE_STRING_PTR, 0, &request_log_file, NULL },
188 { NULL, -1, 0, NULL, NULL }
192 static const CONF_PARSER serverdest_config[] = {
193 { "log", PW_TYPE_SUBSECTION, 0, NULL, (const void *) logdest_config },
194 { "log_file", PW_TYPE_STRING_PTR, 0, &mainconfig.log_file, NULL },
195 { "log_destination", PW_TYPE_STRING_PTR, 0, &radlog_dest, NULL },
197 { "use_utc", PW_TYPE_BOOLEAN, 0, &log_dates_utc, NULL },
199 { NULL, -1, 0, NULL, NULL }
203 static const CONF_PARSER log_config_nodest[] = {
204 { "stripped_names", PW_TYPE_BOOLEAN, 0, &log_stripped_names,"no" },
206 { "auth", PW_TYPE_BOOLEAN, 0, &mainconfig.log_auth, "no" },
207 { "auth_badpass", PW_TYPE_BOOLEAN, 0, &mainconfig.log_auth_badpass, "no" },
208 { "auth_goodpass", PW_TYPE_BOOLEAN, 0, &mainconfig.log_auth_goodpass, "no" },
209 { "msg_badpass", PW_TYPE_STRING_PTR, 0, &mainconfig.auth_badpass_msg, NULL},
210 { "msg_goodpass", PW_TYPE_STRING_PTR, 0, &mainconfig.auth_goodpass_msg, NULL},
213 { "use_utc", PW_TYPE_BOOLEAN, 0, &log_dates_utc, NULL },
216 { NULL, -1, 0, NULL, NULL }
221 * A mapping of configuration file names to internal variables
223 static const CONF_PARSER server_config[] = {
225 * FIXME: 'prefix' is the ONLY one which should be
226 * configured at compile time. Hard-coding it here is
227 * bad. It will be cleaned up once we clean up the
228 * hard-coded defines for the locations of the various
231 { "name", PW_TYPE_STRING_PTR, 0, &my_name, "radiusd"},
232 { "prefix", PW_TYPE_STRING_PTR, 0, &prefix, "/usr/local"},
233 { "localstatedir", PW_TYPE_STRING_PTR, 0, &localstatedir, "${prefix}/var"},
234 { "sbindir", PW_TYPE_STRING_PTR, 0, &sbindir, "${prefix}/sbin"},
235 { "logdir", PW_TYPE_STRING_PTR, 0, &radlog_dir, "${localstatedir}/log"},
236 { "run_dir", PW_TYPE_STRING_PTR, 0, &run_dir, "${localstatedir}/run/${name}"},
237 { "libdir", PW_TYPE_STRING_PTR, 0, &radlib_dir, "${prefix}/lib"},
238 { "radacctdir", PW_TYPE_STRING_PTR, 0, &radacct_dir, "${logdir}/radacct" },
239 { "hostname_lookups", PW_TYPE_BOOLEAN, 0, &fr_dns_lookups, "no" },
240 { "max_request_time", PW_TYPE_INTEGER, 0, &mainconfig.max_request_time, Stringify(MAX_REQUEST_TIME) },
241 { "cleanup_delay", PW_TYPE_INTEGER, 0, &mainconfig.cleanup_delay, Stringify(CLEANUP_DELAY) },
242 { "max_requests", PW_TYPE_INTEGER, 0, &mainconfig.max_requests, Stringify(MAX_REQUESTS) },
243 #ifdef DELETE_BLOCKED_REQUESTS
244 { "delete_blocked_requests", PW_TYPE_INTEGER, 0, &mainconfig.kill_unresponsive_children, Stringify(FALSE) },
246 { "pidfile", PW_TYPE_STRING_PTR, 0, &mainconfig.pid_file, "${run_dir}/radiusd.pid"},
247 { "checkrad", PW_TYPE_STRING_PTR, 0, &mainconfig.checkrad, "${sbindir}/checkrad" },
249 { "debug_level", PW_TYPE_INTEGER, 0, &mainconfig.debug_level, "0"},
252 { "proxy_requests", PW_TYPE_BOOLEAN, 0, &mainconfig.proxy_requests, "yes" },
254 { "log", PW_TYPE_SUBSECTION, 0, NULL, (const void *) log_config_nodest },
257 * People with old configs will have these. They are listed
258 * AFTER the "log" section, so if they exist in radiusd.conf,
259 * it will prefer "log_foo = bar" to "log { foo = bar }".
260 * They're listed with default values of NULL, so that if they
261 * DON'T exist in radiusd.conf, then the previously parsed
262 * values for "log { foo = bar}" will be used.
264 { "log_auth", PW_TYPE_BOOLEAN, 0, &mainconfig.log_auth, NULL },
265 { "log_auth_badpass", PW_TYPE_BOOLEAN, 0, &mainconfig.log_auth_badpass, NULL },
266 { "log_auth_goodpass", PW_TYPE_BOOLEAN, 0, &mainconfig.log_auth_goodpass, NULL },
267 { "log_stripped_names", PW_TYPE_BOOLEAN, 0, &log_stripped_names, NULL },
269 { "security", PW_TYPE_SUBSECTION, 0, NULL, (const void *) security_config },
271 { NULL, -1, 0, NULL, NULL }
274 static const CONF_PARSER bootstrap_config[] = {
276 { "user", PW_TYPE_STRING_PTR, 0, &uid_name, NULL },
277 { "group", PW_TYPE_STRING_PTR, 0, &gid_name, NULL },
279 { "chroot", PW_TYPE_STRING_PTR, 0, &chroot_dir, NULL },
280 { "allow_core_dumps", PW_TYPE_BOOLEAN, 0, &allow_core_dumps, "no" },
282 { NULL, -1, 0, NULL, NULL }
287 #define MAX_ARGV (256)
290 static size_t config_escape_func(char *out, size_t outlen, const char *in)
293 static const char *disallowed = "%{}\\'\"`";
297 * Non-printable characters get replaced with their
298 * mime-encoded equivalents.
301 if (outlen <= 3) break;
303 snprintf(out, outlen, "=%02X", (unsigned char) in[0]);
310 } else if (strchr(disallowed, *in) != NULL) {
311 if (outlen <= 2) break;
323 * Only one byte left.
343 * Xlat for %{config:section.subsection.attribute}
345 static size_t xlat_config(void *instance, REQUEST *request,
346 char *fmt, char *out,
348 RADIUS_ESCAPE_STRING func)
355 request = request; /* -Wunused */
356 instance = instance; /* -Wunused */
361 if (!radius_xlat(buffer, sizeof(buffer), fmt, request, config_escape_func)) {
365 ci = cf_reference_item(request->root->config,
366 request->root->config, buffer);
367 if (!ci || !cf_item_is_pair(ci)) {
372 cp = cf_itemtopair(ci);
375 * Ensure that we only copy what's necessary.
377 * If 'outlen' is too small, then the output is chopped to fit.
379 value = cf_pair_value(cp);
385 if (outlen > strlen(value)) {
386 outlen = strlen(value) + 1;
389 return func(out, outlen, value);
394 * Xlat for %{client:foo}
396 static size_t xlat_client(UNUSED void *instance, REQUEST *request,
397 char *fmt, char *out,
399 UNUSED RADIUS_ESCAPE_STRING func)
401 const char *value = NULL;
404 if (!fmt || !out || (outlen < 1)) return 0;
406 if (!request || !request->client) {
411 cp = cf_pair_find(request->client->cs, fmt);
412 if (!cp || !(value = cf_pair_value(cp))) {
417 strlcpy(out, value, outlen);
423 * Recursively make directories.
425 static int r_mkdir(const char *part)
427 char *ptr, parentdir[500];
430 if (stat(part, &st) == 0)
433 ptr = strrchr(part, FR_DIR_SEP);
438 snprintf(parentdir, (ptr - part)+1, "%s", part);
440 if (r_mkdir(parentdir) != 0)
443 if (mkdir(part, 0770) != 0) {
444 radlog(L_ERR, "mkdir(%s) error: %s\n", part, strerror(errno));
451 #ifdef HAVE_SYS_RESOURCE_H
452 static struct rlimit core_limits;
455 static void fr_set_dumpable(void)
458 * If configured, turn core dumps off.
460 if (!allow_core_dumps) {
461 #ifdef HAVE_SYS_RESOURCE_H
462 struct rlimit no_core;
465 no_core.rlim_cur = 0;
466 no_core.rlim_max = 0;
468 if (setrlimit(RLIMIT_CORE, &no_core) < 0) {
469 radlog(L_ERR, "Failed disabling core dumps: %s",
477 * Set or re-set the dumpable flag.
479 #ifdef HAVE_SYS_PRCTL_H
480 #ifdef PR_SET_DUMPABLE
481 if (prctl(PR_SET_DUMPABLE, 1) < 0) {
482 radlog(L_ERR,"Cannot re-enable core dumps: prctl(PR_SET_DUMPABLE) failed: '%s'",
489 * Reset the core dump limits to their original value.
491 #ifdef HAVE_SYS_RESOURCE_H
492 if (setrlimit(RLIMIT_CORE, &core_limits) < 0) {
493 radlog(L_ERR, "Cannot update core dump limit: %s",
500 static int doing_setuid = FALSE;
502 #if defined(HAVE_SETRESUID) && defined (HAVE_GETRESUID)
503 void fr_suid_up(void)
505 uid_t ruid, euid, suid;
507 if (getresuid(&ruid, &euid, &suid) < 0) {
508 radlog(L_ERR, "Failed getting saved UID's");
512 if (setresuid(-1, suid, -1) < 0) {
513 radlog(L_ERR, "Failed switching to privileged user");
517 if (geteuid() != suid) {
518 radlog(L_ERR, "Switched to unknown UID");
523 void fr_suid_down(void)
525 if (!doing_setuid) return;
527 if (setresuid(-1, server_uid, geteuid()) < 0) {
528 fprintf(stderr, "%s: Failed switching to uid %s: %s\n",
529 progname, uid_name, strerror(errno));
533 if (geteuid() != server_uid) {
534 fprintf(stderr, "%s: Failed switching uid: UID is incorrect\n",
542 void fr_suid_down_permanent(void)
544 if (!doing_setuid) return;
546 if (setresuid(server_uid, server_uid, server_uid) < 0) {
547 radlog(L_ERR, "Failed in permanent switch to uid %s: %s",
548 uid_name, strerror(errno));
552 if (geteuid() != server_uid) {
553 radlog(L_ERR, "Switched to unknown uid");
561 * Much less secure...
563 void fr_suid_up(void)
566 void fr_suid_down(void)
568 if (!uid_name) return;
570 if (setuid(server_uid) < 0) {
571 fprintf(stderr, "%s: Failed switching to uid %s: %s\n",
572 progname, uid_name, strerror(errno));
578 void fr_suid_down_permanent(void)
582 #endif /* HAVE_SETRESUID && HAVE_GETRESUID */
583 #else /* HAVE_SETUID */
584 void fr_suid_up(void)
587 void fr_suid_down(void)
591 void fr_suid_down_permanent(void)
595 #endif /* HAVE_SETUID */
600 * Do chroot, if requested.
602 * Switch UID and GID to what is specified in the config file
604 static int switch_users(CONF_SECTION *cs)
606 #ifdef HAVE_SYS_RESOURCE_H
608 * Get the current maximum for core files. Do this
609 * before anything else so as to ensure it's properly
612 if (getrlimit(RLIMIT_CORE, &core_limits) < 0) {
613 radlog(L_ERR, "Failed to get current core limit: %s", strerror(errno));
619 * Don't do chroot/setuid/setgid if we're in debugging
622 if (debug_flag && (getuid() != 0)) return 1;
624 if (cf_section_parse(cs, NULL, bootstrap_config) < 0) {
625 fprintf(stderr, "radiusd: Error: Failed to parse user/group information.\n");
635 gr = getgrnam(gid_name);
637 fprintf(stderr, "%s: Cannot get ID for group %s: %s\n",
638 progname, gid_name, strerror(errno));
641 server_gid = gr->gr_gid;
643 server_gid = getgid();
652 pw = getpwnam(uid_name);
654 fprintf(stderr, "%s: Cannot get passwd entry for user %s: %s\n",
655 progname, uid_name, strerror(errno));
659 if (getuid() == pw->pw_uid) {
663 server_uid = pw->pw_uid;
664 #ifdef HAVE_INITGROUPS
665 if (initgroups(uid_name, server_gid) < 0) {
666 fprintf(stderr, "%s: Cannot initialize supplementary group list for user %s: %s\n",
667 progname, uid_name, strerror(errno));
673 server_uid = getuid();
678 if (chroot(chroot_dir) < 0) {
679 fprintf(stderr, "%s: Failed to perform chroot %s: %s",
680 progname, chroot_dir, strerror(errno));
685 * Note that we leave chdir alone. It may be
686 * OUTSIDE of the root. This allows us to read
687 * the configuration from "-d ./etc/raddb", with
688 * the chroot as "./chroot/" for example. After
689 * the server has been loaded, it does a "cd
690 * ${logdir}" below, so that core files (if any)
691 * go to a logging directory.
693 * This also allows the configuration of the
694 * server to be outside of the chroot. If the
695 * server is statically linked, then the only
696 * things needed inside of the chroot are the
697 * logging directories.
703 if (gid_name && (setgid(server_gid) < 0)) {
704 fprintf(stderr, "%s: Failed setting group to %s: %s",
705 progname, gid_name, strerror(errno));
712 * Just before losing root permissions, ensure that the
713 * log files have the correct owner && group.
715 * We have to do this because the log file MAY have been
716 * specified on the command-line.
718 if (uid_name || gid_name) {
719 if ((mainconfig.radlog_dest == RADLOG_FILES) &&
720 (mainconfig.radlog_fd < 0)) {
721 mainconfig.radlog_fd = open(mainconfig.log_file,
722 O_WRONLY | O_APPEND | O_CREAT, 0640);
723 if (mainconfig.radlog_fd < 0) {
724 fprintf(stderr, "radiusd: Failed to open log file %s: %s\n", mainconfig.log_file, strerror(errno));
728 if (chown(mainconfig.log_file, server_uid, server_gid) < 0) {
729 fprintf(stderr, "%s: Cannot change ownership of log file %s: %s\n",
730 progname, mainconfig.log_file, strerror(errno));
744 * This also clears the dumpable flag if core dumps
749 if (allow_core_dumps) {
750 radlog(L_INFO, "Core dumps are enabled.");
755 #endif /* HAVE_SETUID */
758 static const FR_NAME_NUMBER str2dest[] = {
759 { "null", RADLOG_NULL },
760 { "files", RADLOG_FILES },
761 { "syslog", RADLOG_SYSLOG },
762 { "stdout", RADLOG_STDOUT },
763 { "stderr", RADLOG_STDERR },
764 { NULL, RADLOG_NUM_DEST }
771 * This function can ONLY be called from the main server process.
773 int read_mainconfig(int reload)
775 const char *p = NULL;
783 radlog(L_ERR, "Reload is not implemented");
787 if (stat(radius_dir, &statbuf) < 0) {
788 radlog(L_ERR, "Errors reading %s: %s",
789 radius_dir, strerror(errno));
794 if ((statbuf.st_mode & S_IWOTH) != 0) {
795 radlog(L_ERR, "Configuration directory %s is globally writable. Refusing to start due to insecure configuration.",
802 if (0 && (statbuf.st_mode & S_IROTH) != 0) {
803 radlog(L_ERR, "Configuration directory %s is globally readable. Refusing to start due to insecure configuration.",
809 radlog(L_INFO, "Starting - reading configuration files ...");
811 /* Read the configuration file */
812 snprintf(buffer, sizeof(buffer), "%.200s/%.50s.conf",
813 radius_dir, mainconfig.name);
814 if ((cs = cf_file_read(buffer)) == NULL) {
815 radlog(L_ERR, "Errors reading or parsing %s", buffer);
820 * If there was no log destination set on the command line,
823 if (mainconfig.radlog_dest == RADLOG_NULL) {
824 if (cf_section_parse(cs, NULL, serverdest_config) < 0) {
825 fprintf(stderr, "radiusd: Error: Failed to parse log{} section.\n");
826 cf_section_free(&cs);
831 fprintf(stderr, "radiusd: Error: No log destination specified.\n");
832 cf_section_free(&cs);
836 mainconfig.radlog_dest = fr_str2int(str2dest, radlog_dest,
838 if (mainconfig.radlog_dest == RADLOG_NUM_DEST) {
839 fprintf(stderr, "radiusd: Error: Unknown log_destination %s\n",
841 cf_section_free(&cs);
845 if (mainconfig.radlog_dest == RADLOG_SYSLOG) {
847 * Make sure syslog_facility isn't NULL
850 if (!syslog_facility) {
851 fprintf(stderr, "radiusd: Error: Syslog chosen but no facility was specified\n");
852 cf_section_free(&cs);
855 mainconfig.syslog_facility = fr_str2int(syslog_str2fac, syslog_facility, -1);
856 if (mainconfig.syslog_facility < 0) {
857 fprintf(stderr, "radiusd: Error: Unknown syslog_facility %s\n",
859 cf_section_free(&cs);
865 * Call openlog only once, when the
868 openlog(progname, LOG_PID, mainconfig.syslog_facility);
871 } else if (mainconfig.radlog_dest == RADLOG_FILES) {
872 if (!mainconfig.log_file) {
873 fprintf(stderr, "radiusd: Error: Specified \"files\" as a log destination, but no log filename was given!\n");
874 cf_section_free(&cs);
882 * Switch users as early as possible.
884 if (!switch_users(cs)) exit(1);
888 * Open the log file AFTER switching uid / gid. If we
889 * did switch uid/gid, then the code in switch_users()
890 * took care of setting the file permissions correctly.
892 if ((mainconfig.radlog_dest == RADLOG_FILES) &&
893 (mainconfig.radlog_fd < 0)) {
894 mainconfig.radlog_fd = open(mainconfig.log_file,
895 O_WRONLY | O_APPEND | O_CREAT, 0640);
896 if (mainconfig.radlog_fd < 0) {
897 fprintf(stderr, "radiusd: Failed to open log file %s: %s\n", mainconfig.log_file, strerror(errno));
898 cf_section_free(&cs);
903 /* Initialize the dictionary */
904 cp = cf_pair_find(cs, "dictionary");
905 if (cp) p = cf_pair_value(cp);
906 if (!p) p = radius_dir;
907 DEBUG2("including dictionary file %s/%s", p, RADIUS_DICTIONARY);
908 if (dict_init(p, RADIUS_DICTIONARY) != 0) {
909 radlog(L_ERR, "Errors reading dictionary: %s",
915 * This allows us to figure out where, relative to
916 * radiusd.conf, the other configuration files exist.
918 cf_section_parse(cs, NULL, server_config);
921 * Free the old configuration items, and replace them
924 * Note that where possible, we do atomic switch-overs,
925 * to ensure that the pointers are always valid.
927 cf_section_free(&mainconfig.config);
928 mainconfig.config = cs;
930 DEBUG2("%s: #### Loading Realms and Home Servers ####", mainconfig.name);
931 if (!realms_init(cs)) {
932 DEBUG2("Failed to load realms and home servers\n");
936 DEBUG2("%s: #### Loading Clients ####", mainconfig.name);
937 if (!clients_parse_section(cs)) {
938 DEBUG2("Failed to load clients\n");
943 * Register the %{config:section.subsection} xlat function.
945 xlat_register("config", xlat_config, NULL);
946 xlat_register("client", xlat_client, NULL);
949 * Starting the server, WITHOUT "-x" on the
950 * command-line: use whatever is in the config
953 if (debug_flag == 0) {
954 debug_flag = mainconfig.debug_level;
956 fr_debug_flag = debug_flag;
959 * Go update our behaviour, based on the configuration
964 * Sanity check the configuration for internal
967 if (mainconfig.reject_delay > mainconfig.cleanup_delay) {
968 mainconfig.reject_delay = mainconfig.cleanup_delay;
970 if (mainconfig.reject_delay < 0) mainconfig.reject_delay = 0;
972 /* Reload the modules. */
973 if (setup_modules(reload, mainconfig.config) < 0) {
978 if (chdir(radlog_dir) < 0) {
979 radlog(L_ERR, "Failed to 'chdir %s' after chroot: %s",
980 radlog_dir, strerror(errno));
985 cc = rad_malloc(sizeof(*cc));
986 memset(cc, 0, sizeof(*cc));
989 rad_assert(cs_cache == NULL);
996 * Free the configuration. Called only when the server is exiting.
998 int free_mainconfig(void)
1000 cached_config_t *cc, *next;
1002 virtual_servers_free(0);
1005 * Free all of the cached configurations.
1007 for (cc = cs_cache; cc != NULL; cc = next) {
1009 cf_section_free(&cc->cs);
1014 * Clean up the configuration data
1018 listen_free(&mainconfig.listen);
1024 void hup_logfile(void)
1028 if (mainconfig.radlog_dest != RADLOG_FILES) return;
1030 fd = open(mainconfig.log_file,
1031 O_WRONLY | O_APPEND | O_CREAT, 0640);
1034 * Atomic swap. We'd like to keep the old
1035 * FD around so that callers don't
1036 * suddenly find the FD closed, and the
1037 * writes go nowhere. But that's hard to
1038 * do. So... we have the case where a
1039 * log message *might* be lost on HUP.
1041 old_fd = mainconfig.radlog_fd;
1042 mainconfig.radlog_fd = fd;
1047 void hup_mainconfig(void)
1049 cached_config_t *cc;
1053 radlog(L_INFO, "HUP - Re-reading configuration files");
1055 /* Read the configuration file */
1056 snprintf(buffer, sizeof(buffer), "%.200s/%.50s.conf",
1057 radius_dir, mainconfig.name);
1058 if ((cs = cf_file_read(buffer)) == NULL) {
1059 radlog(L_ERR, "Failed to re-read or parse %s", buffer);
1063 cc = rad_malloc(sizeof(*cc));
1064 memset(cc, 0, sizeof(*cc));
1067 * Save the current configuration. Note that we do NOT
1068 * free older ones. We should probably do so at some
1069 * point. Doing so will require us to mark which modules
1070 * are still in use, and which aren't. Modules that
1071 * can't be HUPed always use the original configuration.
1072 * Modules that can be HUPed use one of the newer
1075 cc->created = time(NULL);
1077 cc->next = cs_cache;
1081 * Re-open the log file. If we can't, then keep logging
1082 * to the old log file.
1084 * The "open log file" code is here rather than in log.c,
1085 * because it makes that function MUCH simpler.
1089 radlog(L_INFO, "HUP - loading modules");
1092 * Prefer the new module configuration.
1094 module_hup(cf_section_sub_find(cs, "modules"));
1097 * Load new servers BEFORE freeing old ones.
1099 virtual_servers_load(cs);
1101 virtual_servers_free(cc->created - mainconfig.max_request_time * 4);