28 RCSID(
"$Id: 2674e30c099136ec84cb4b09ca58d3235853ec6e $")
30 #include <freeradius-devel/radiusd.h>
31 #include <freeradius-devel/modules.h>
32 #include <freeradius-devel/state.h>
33 #include <freeradius-devel/map_proc.h>
34 #include <freeradius-devel/rad_assert.h>
45 #ifdef HAVE_SYS_WAIT_H
46 # include <sys/wait.h>
49 # define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8)
52 # define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
64 #ifdef RADIUSD_VERSION_COMMIT
65 " (git #" STRINGIFY(RADIUSD_VERSION_COMMIT)
")"
67 ", for host " HOSTINFO
", built on " __DATE__
" at " __TIME__;
78 static void usage(
int);
82 static void sig_hup (
int);
88 int main(
int argc,
char *argv[])
90 int rcode = EXIT_SUCCESS;
93 bool display_version =
false;
94 int from_child[2] = {-1, -1};
102 TALLOC_CTX *
autofree = talloc_init(
"main");
105 set_auth_parameters(argc, argv);
111 if (WSAStartup(MAKEWORD(2, 0), &wsaData)) {
112 fprintf(stderr,
"%s: Unable to initialize socket library.\n",
129 p = strrchr(argv[0], FR_DIR_SEP);
145 while ((argval = getopt(argc, argv,
"Cd:D:fhi:l:mMn:p:PstvxX")) != EOF) {
171 if (strcmp(optarg,
"stdout") == 0) {
178 fprintf(stderr,
"%s: Failed to open log file %s: %s\n",
213 display_version =
true;
253 #ifdef HAVE_OPENSSL_CRYPTO_H
265 fprintf(stderr,
"%s: The server cannot produce memory reports (-M) in threaded mode\n",
269 talloc_enable_null_tracking();
271 talloc_disable_null_tracking();
278 #ifdef HAVE_OPENSSL_CRYPTO_H
279 if (tls_global_init() < 0) exit(EXIT_FAILURE);
285 if (display_version) {
323 #if defined(HAVE_OPENSSL_CRYPTO_H) && defined(ENABLE_OPENSSL_VERSION_CHECK)
324 if (tls_global_version_check(
main_config.allow_vulnerable_openssl) < 0) exit(EXIT_FAILURE);
335 panic_action = getenv(
"PANIC_ACTION");
338 if (panic_action && (
fr_fault_setup(panic_action, argv[0]) < 0)) {
356 devnull = open(
"/dev/null", O_RDWR);
361 dup2(devnull, STDIN_FILENO);
365 if (pipe(from_child) != 0) {
390 close(from_child[1]);
396 if ((read(from_child[0], &ret, 1) < 0)) {
401 close(from_child[0]);
405 waitpid(pid, &stat_loc, WNOHANG);
413 close(from_child[0]);
424 radius_pid = getpid();
426 #ifdef HAVE_PTHREAD_H
475 #ifdef HAVE_PTHREAD_H
510 DEBUG(
"Configuration appears to be OK");
524 signal(SIGPIPE, SIG_IGN);
549 fprintf(fp,
"%d\n", (
int) radius_pid);
566 if (write(from_child[1],
"\001", 1) < 0) {
567 WARN(
"Failed informing parent of successful start: %s",
570 close(from_child[1]);
595 rcode = EXIT_FAILURE;
597 INFO(
"Exiting normally");
598 rcode = EXIT_SUCCESS;
604 signal(SIGTERM, SIG_IGN);
610 if (status == 2)
exec_trigger(NULL, NULL,
"server.signal.term",
true);
637 #ifdef HAVE_PTHREAD_H
654 #ifdef HAVE_OPENSSL_CRYPTO_H
655 tls_global_cleanup();
657 talloc_free(autofree);
674 FILE *output = status?stderr:stdout;
677 fprintf(output,
"Options:\n");
678 fprintf(output,
" -C Check configuration and exit.\n");
679 fprintf(stderr,
" -d <raddb> Set configuration directory (defaults to " RADDBDIR
").\n");
680 fprintf(stderr,
" -D <dictdir> Set main dictionary directory (defaults to " DICTDIR
").\n");
681 fprintf(output,
" -f Run as a foreground process, not a daemon.\n");
682 fprintf(output,
" -h Print this help message.\n");
683 fprintf(output,
" -l <log_file> Logging output will be written to this file.\n");
684 fprintf(output,
" -m On SIGINT or SIGQUIT clean up all used memory instead of just exiting.\n");
685 fprintf(output,
" -n <name> Read raddb/name.conf instead of raddb/radiusd.conf.\n");
686 fprintf(output,
" -P Always write out PID, even with -f.\n");
687 fprintf(output,
" -s Do not spawn child processes to handle requests (same as -ft).\n");
688 fprintf(output,
" -t Disable threads.\n");
689 fprintf(output,
" -v Print server version information.\n");
690 fprintf(output,
" -X Turn on full debugging (similar to -tfxxl stdout).\n");
691 fprintf(output,
" -x Turn on additional debugging (-xx gives more debugging).\n");
701 if (getpid() != radius_pid) _exit(sig);
728 static void sig_hup(
UNUSED int sig)
int ssl_check_consistency(void)
Main server configuration.
void exec_trigger(REQUEST *request, CONF_SECTION *cs, char const *name, bool quench) CC_HINT(nonnull(3))
Execute a trigger - call an executable to process an event.
int main_config_init(void)
bool write_pid
write the PID file
static void sig_fatal(int)
int virtual_servers_init(CONF_SECTION *config)
bool daemonize
Should the server daemonize on startup.
int radius_event_start(bool spawn_flag)
int main(int argc, char *argv[])
int main_config_free(void)
fr_state_tree_t * fr_state_tree_init(TALLOC_CTX *ctx, uint32_t max_sessions, uint32_t timeout)
Initialise a new state tree.
char const * pid_file
Path to write out PID file.
int fr_log_talloc_report(TALLOC_CTX *ctx)
Generate a talloc memory report for a context and print to stderr/stdout.
char const * name
Name of the daemon, usually 'radiusd'.
int virtual_servers_bootstrap(CONF_SECTION *config)
void set_radius_dir(TALLOC_CTX *ctx, char const *path)
Set the global radius config directory.
void radius_stats_init(int flag)
int fr_fault_setup(char const *cmd, char const *program)
Registers signal handlers to execute panic_action on fatal signal.
uint32_t continuation_timeout
How long to wait before cleaning up state entries.
void(*) fr_debug_state_ fr_debug_state)
int modules_init(CONF_SECTION *)
Instantiate the modules.
char const * fr_syserror(int num)
Guaranteed to be thread-safe version of strerror.
int fr_check_lib_magic(uint64_t magic)
Check if the application linking to the library has the correct magic number.
void(*)(int) reset_signal(int signo, void(*func)(int))
bool debug_memory
Cleanup the server properly on exit, freeing up any memory we allocated.
void fr_store_debug_state(void)
Should be run before using setuid or setgid to get useful results.
void main_config_hup(void)
void void fr_perror(char const *,...) CC_HINT(format(printf
void thread_pool_stop(void)
static char panic_action[512]
The command to execute when panicking.
bool log_auth_goodpass
Log failed authentications.
bool log_auth
Log authentication attempts.
bool memory_report
Print a memory report on what's left unfreed.
int radius_event_init(TALLOC_CTX *ctx)
char const * fr_strerror(void)
Get the last library error.
int radlog_init(fr_log_t *log, bool daemonize)
Initialise file descriptors based on logging destination.
void xlat_free(void)
De-register all xlat functions, used mainly for debugging.
bool event_loop_started
Whether the main event loop has been started yet.
CONF_SECTION * config
Root of the server config.
log_lvl_t rad_debug_lvl
Global debugging level.
void radius_signal_self(int flag)
int thread_pool_bootstrap(CONF_SECTION *cs, bool *spawn_workers)
char const * radiusd_version
char const * dictionary_dir
Where to load dictionaries from.
int modules_bootstrap(CONF_SECTION *)
void int fr_set_signal(int sig, sig_t func)
Sets a signal handler using sigaction if available, else signal.
char const * panic_action
Command to execute if the server receives a fatal signal.
void fr_talloc_fault_setup(void)
Register talloc fault handlers.
bool log_auth_badpass
Log successful authentications.
char const * fr_debug_state_to_msg(fr_debug_state_t state)
Return current value of debug_state.
static TALLOC_CTX * autofree
log_dst_t dst
Log destination.
void radius_event_free(void)
bool spawn_workers
Should the server spawn threads.
char * talloc_typed_strdup(void const *t, char const *p)
Call talloc strdup, setting the type on the new chunk correctly.
int fd
File descriptor to write messages to.
int thread_pool_init(void)
int radius_event_process(void)
fr_state_tree_t * global_state
int rad_check_lib_magic(uint64_t magic)
Check if the application linking to the library has the correct magic number.
#define RADIUSD_MAGIC_NUMBER