X-Git-Url: https://jfr.im/git/solanum.git/blobdiff_plain/cbeab4bc340b7b3f4fbf424ff327758defb9598a..cc264f942f73f2099dae23f9cf10efed52f4589f:/ircd/ircd.c diff --git a/ircd/ircd.c b/ircd/ircd.c index 73c52351..5c576fc8 100644 --- a/ircd/ircd.c +++ b/ircd/ircd.c @@ -23,15 +23,14 @@ * USA */ -#include "ratbox_lib.h" +#include "rb_lib.h" #include "stdinc.h" #include "setup.h" -#include "config.h" +#include "defaults.h" #include "ircd.h" #include "channel.h" #include "class.h" #include "client.h" -#include "common.h" #include "hash.h" #include "match.h" #include "ircd_signal.h" @@ -40,7 +39,6 @@ #include "numeric.h" #include "parse.h" #include "restart.h" -#include "s_auth.h" #include "s_conf.h" #include "logger.h" #include "s_serv.h" /* try_connections */ @@ -95,18 +93,15 @@ rb_dlink_list global_serv_list; /* global servers on the network */ rb_dlink_list local_oper_list; /* our opers, duplicated in lclient_list */ rb_dlink_list oper_list; /* network opers */ -const char *logFileName = LPATH; -const char *pidFileName = PPATH; - char **myargv; -int dorehash = 0; -int dorehashbans = 0; -int doremotd = 0; -int kline_queued = 0; -int server_state_foreground = 0; -int opers_see_all_users = 0; -int ssl_ok = 0; -int zlib_ok = 1; +bool dorehash = false; +bool dorehashbans = false; +bool doremotd = false; +bool kline_queued = false; +bool server_state_foreground = false; +bool opers_see_all_users = false; +bool ircd_ssl_ok = false; +bool ircd_zlib_ok = true; int testing_conf = 0; time_t startup_time; @@ -119,6 +114,28 @@ int split_users; int split_servers; int eob_count; +const char *ircd_paths[IRCD_PATH_COUNT] = { + [IRCD_PATH_PREFIX] = DPATH, + [IRCD_PATH_MODULES] = MODPATH, + [IRCD_PATH_AUTOLOAD_MODULES] = AUTOMODPATH, + [IRCD_PATH_ETC] = ETCPATH, + [IRCD_PATH_LOG] = LOGPATH, + [IRCD_PATH_USERHELP] = UHPATH, + [IRCD_PATH_OPERHELP] = HPATH, + [IRCD_PATH_IRCD_EXEC] = SPATH, + [IRCD_PATH_IRCD_CONF] = CPATH, + [IRCD_PATH_IRCD_MOTD] = MPATH, + [IRCD_PATH_IRCD_LOG] = LPATH, + [IRCD_PATH_IRCD_PID] = PPATH, + [IRCD_PATH_IRCD_OMOTD] = OPATH, + [IRCD_PATH_BANDB] = DBPATH, + [IRCD_PATH_BIN] = BINPATH, + [IRCD_PATH_LIBEXEC] = PKGLIBEXECDIR, +}; + +const char *logFileName = NULL; +const char *pidFileName = NULL; + void ircd_shutdown(const char *reason) { @@ -156,6 +173,7 @@ print_startup(int pid) { int fd; +#ifndef _WIN32 close(1); fd = open("/dev/null", O_RDWR); if (fd == -1) { @@ -166,19 +184,30 @@ print_startup(int pid) fd = dup(fd); if (fd != 1) abort(); - +#endif + inotice("runtime path: %s", rb_path_to_self()); inotice("now running in %s mode from %s as pid %d ...", !server_state_foreground ? "background" : "foreground", ConfigFileEntry.dpath, pid); +#ifndef _WIN32 /* let the parent process know the initialization was successful * -- jilles */ if (!server_state_foreground) - write(0, ".", 1); + { + /* GCC complains on Linux if we don't check the value of write pedantically. + * Technically you're supposed to check the value, yes, but it probably can't fail. + * No, casting to void is of no use to shut the warning up. You HAVE to use the value. + * --Elizfaox + */ + if(write(0, ".", 1) < 1) + abort(); + } if (dup2(1, 0) == -1) abort(); if (dup2(1, 2) == -1) abort(); +#endif } /* @@ -191,7 +220,7 @@ print_startup(int pid) static void init_sys(void) { -#if defined(RLIMIT_NOFILE) && defined(HAVE_SYS_RESOURCE_H) +#if !defined(_WIN32) && defined(RLIMIT_NOFILE) && defined(HAVE_SYS_RESOURCE_H) struct rlimit limit; if(!getrlimit(RLIMIT_NOFILE, &limit)) @@ -212,6 +241,7 @@ init_sys(void) static int make_daemon(void) { +#ifndef _WIN32 int pid; int pip[2]; char c; @@ -246,7 +276,7 @@ make_daemon(void) /* fclose(stdin); fclose(stdout); fclose(stderr); */ - +#endif return 0; } @@ -277,14 +307,14 @@ check_rehash(void *unused) */ if(dorehash) { - rehash(1); - dorehash = 0; + rehash(true); + dorehash = false; } if(dorehashbans) { - rehash_bans(1); - dorehashbans = 0; + rehash_bans(); + dorehashbans = false; } if(doremotd) @@ -292,7 +322,7 @@ check_rehash(void *unused) sendto_realops_snomask(SNO_GENERAL, L_ALL, "Got signal SIGUSR1, reloading ircd motd file"); cache_user_motd(); - doremotd = 0; + doremotd = false; } } @@ -358,6 +388,85 @@ initialize_server_capabs(void) default_server_capabs &= ~CAP_ZIP; } +/* + * relocate_paths + * + * inputs - none + * output - none + * side effects - items in ircd_paths[] array are relocated + */ +#ifdef _WIN32 +static void +relocate_paths(void) +{ + char prefix[PATH_MAX], workbuf[PATH_MAX]; + char *p; + + rb_strlcpy(prefix, rb_path_to_self(), sizeof prefix); + + ircd_paths[IRCD_PATH_IRCD_EXEC] = rb_strdup(prefix); + + /* if we're running from inside the source tree, we probably do not want to relocate any other paths */ + if (strstr(prefix, ".libs") != NULL) + return; + + /* prefix = /home/kaniini/ircd/bin/ircd */ + p = strrchr(prefix, RB_PATH_SEPARATOR); + if (rb_unlikely(p == NULL)) + return; + *p = 0; + + /* prefix = /home/kaniini/ircd/bin */ + p = strrchr(prefix, RB_PATH_SEPARATOR); + if (rb_unlikely(p == NULL)) + return; + *p = 0; + + /* prefix = /home/kaniini/ircd */ + ircd_paths[IRCD_PATH_PREFIX] = rb_strdup(prefix); + + /* now that we have our prefix, we can relocate the other paths... */ + snprintf(workbuf, sizeof workbuf, "%s%cmodules", prefix, RB_PATH_SEPARATOR); + ircd_paths[IRCD_PATH_MODULES] = rb_strdup(workbuf); + + snprintf(workbuf, sizeof workbuf, "%s%cmodules%cautoload", prefix, RB_PATH_SEPARATOR, RB_PATH_SEPARATOR); + ircd_paths[IRCD_PATH_AUTOLOAD_MODULES] = rb_strdup(workbuf); + + snprintf(workbuf, sizeof workbuf, "%s%cetc", prefix, RB_PATH_SEPARATOR); + ircd_paths[IRCD_PATH_ETC] = rb_strdup(workbuf); + + snprintf(workbuf, sizeof workbuf, "%s%clog", prefix, RB_PATH_SEPARATOR); + ircd_paths[IRCD_PATH_LOG] = rb_strdup(workbuf); + + snprintf(workbuf, sizeof workbuf, "%s%chelp%cusers", prefix, RB_PATH_SEPARATOR, RB_PATH_SEPARATOR); + ircd_paths[IRCD_PATH_USERHELP] = rb_strdup(workbuf); + + snprintf(workbuf, sizeof workbuf, "%s%chelp%copers", prefix, RB_PATH_SEPARATOR, RB_PATH_SEPARATOR); + ircd_paths[IRCD_PATH_OPERHELP] = rb_strdup(workbuf); + + snprintf(workbuf, sizeof workbuf, "%s%cetc%circd.conf", prefix, RB_PATH_SEPARATOR, RB_PATH_SEPARATOR); + ircd_paths[IRCD_PATH_IRCD_CONF] = rb_strdup(workbuf); + + snprintf(workbuf, sizeof workbuf, "%s%cetc%circd.motd", prefix, RB_PATH_SEPARATOR, RB_PATH_SEPARATOR); + ircd_paths[IRCD_PATH_IRCD_MOTD] = rb_strdup(workbuf); + + snprintf(workbuf, sizeof workbuf, "%s%cetc%copers.motd", prefix, RB_PATH_SEPARATOR, RB_PATH_SEPARATOR); + ircd_paths[IRCD_PATH_IRCD_OMOTD] = rb_strdup(workbuf); + + snprintf(workbuf, sizeof workbuf, "%s%cetc%cban.db", prefix, RB_PATH_SEPARATOR, RB_PATH_SEPARATOR); + ircd_paths[IRCD_PATH_BANDB] = rb_strdup(workbuf); + + snprintf(workbuf, sizeof workbuf, "%s%cetc%circd.pid", prefix, RB_PATH_SEPARATOR, RB_PATH_SEPARATOR); + ircd_paths[IRCD_PATH_IRCD_PID] = rb_strdup(workbuf); + + snprintf(workbuf, sizeof workbuf, "%s%clogs%circd.log", prefix, RB_PATH_SEPARATOR, RB_PATH_SEPARATOR); + ircd_paths[IRCD_PATH_IRCD_LOG] = rb_strdup(workbuf); + + snprintf(workbuf, sizeof workbuf, "%s%cbin", prefix, RB_PATH_SEPARATOR); + ircd_paths[IRCD_PATH_BIN] = rb_strdup(workbuf); + ircd_paths[IRCD_PATH_LIBEXEC] = rb_strdup(workbuf); +} +#endif /* * write_pidfile @@ -412,7 +521,7 @@ check_pidfile(const char *filename) if(fgets(buff, 20, fb) != NULL) { pidfromfile = atoi(buff); - if(!kill(pidfromfile, 0)) + if(!rb_kill(pidfromfile, 0)) { printf("ircd: daemon is already running\n"); exit(-1); @@ -448,13 +557,13 @@ setup_corefile(void) static void ircd_log_cb(const char *str) { - ilog(L_MAIN, "libratbox reports: %s", str); + ilog(L_MAIN, "librb reports: %s", str); } static void ircd_restart_cb(const char *str) { - inotice("libratbox has called the restart callback: %s", str); + inotice("librb has called the restart callback: %s", str); restart(str); } @@ -471,11 +580,11 @@ ircd_die_cb(const char *str) if(str != NULL) { /* Try to get the message out to currently logged in operators. */ - sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, "libratbox has called the die callback..aborting: %s", str); - inotice("libratbox has called the die callback..aborting: %s", str); + sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, "librb has called the die callback..aborting: %s", str); + inotice("librb has called the die callback..aborting: %s", str); } else - inotice("libratbox has called the die callback..aborting"); + inotice("librb has called the die callback..aborting"); unlink(pidFileName); exit(EXIT_FAILURE); @@ -539,19 +648,28 @@ charybdis_main(int argc, char *argv[]) { int fd; +#ifndef _WIN32 /* Check to see if the user is running us as root, which is a nono */ if(geteuid() == 0) { fprintf(stderr, "Don't run ircd as root!!!\n"); return -1; } +#endif - init_sys(); +#ifdef _WIN32 + relocate_paths(); +#endif - ConfigFileEntry.dpath = DPATH; - ConfigFileEntry.configfile = CPATH; /* Server configuration file */ + logFileName = ircd_paths[IRCD_PATH_IRCD_LOG]; + pidFileName = ircd_paths[IRCD_PATH_IRCD_PID]; + + ConfigFileEntry.dpath = ircd_paths[IRCD_PATH_PREFIX]; + ConfigFileEntry.configfile = ircd_paths[IRCD_PATH_IRCD_CONF]; /* Server configuration file */ ConfigFileEntry.connect_timeout = 30; /* Default to 30 */ + init_sys(); + umask(077); /* better safe than sorry --SRB */ myargv = argv; @@ -605,8 +723,9 @@ charybdis_main(int argc, char *argv[]) setup_signals(); if (testing_conf) - server_state_foreground = 1; + server_state_foreground = true; +#ifndef _WIN32 /* Make sure fd 0, 1 and 2 are in use -- jilles */ do { @@ -616,6 +735,7 @@ charybdis_main(int argc, char *argv[]) close(fd); else if (fd == -1) exit(1); +#endif /* Check if there is pidfile and daemon already running */ if(!testing_conf) @@ -661,13 +781,14 @@ charybdis_main(int argc, char *argv[]) load_all_modules(1); load_core_modules(1); - init_auth(); /* Initialise the auth code */ init_authd(); /* Start up authd. */ + init_dns(); /* Start up DNS query system */ + privilegeset_set_new("default", "", 0); if (testing_conf) fprintf(stderr, "\nBeginning config test\n"); - read_conf_files(YES); /* cold start init conf files */ + read_conf_files(true); /* cold start init conf files */ mod_add_path(MODULE_DIR); mod_add_path(MODULE_DIR "/autoload"); @@ -677,7 +798,7 @@ charybdis_main(int argc, char *argv[]) init_bandb(); init_ssld(); - rehash_bans(0); + rehash_bans(); initialize_server_capabs(); /* Set up default_server_capabs */ initialize_global_set_options(); @@ -711,10 +832,10 @@ charybdis_main(int argc, char *argv[]) if(!rb_setup_ssl_server(ServerInfo.ssl_cert, ServerInfo.ssl_private_key, ServerInfo.ssl_dh_params, ServerInfo.ssl_cipher_list)) { ilog(L_MAIN, "WARNING: Unable to setup SSL."); - ssl_ok = 0; + ircd_ssl_ok = false; } else - ssl_ok = 1; + ircd_ssl_ok = true; } if (testing_conf) @@ -724,6 +845,8 @@ charybdis_main(int argc, char *argv[]) return 0; /* Why? We want the launcher to exit out. */ } + configure_authd(); + me.from = &me; me.servptr = &me; SetMe(&me);