| 1 |
|
/* |
| 2 |
< |
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
| 3 |
< |
* ircd.c: Starts up and runs the ircd. |
| 2 |
> |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
| 3 |
|
* |
| 4 |
< |
* Copyright (C) 2002 by the past and present ircd coders, and others. |
| 4 |
> |
* Copyright (c) 1997-2014 ircd-hybrid development team |
| 5 |
|
* |
| 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 |
| 17 |
|
* along with this program; if not, write to the Free Software |
| 18 |
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
| 19 |
|
* USA |
| 20 |
< |
* |
| 21 |
< |
* $Id$ |
| 20 |
> |
*/ |
| 21 |
> |
|
| 22 |
> |
/*! \file ircd.c |
| 23 |
> |
* \brief Starts up and runs the ircd. |
| 24 |
> |
* \version $Id$ |
| 25 |
|
*/ |
| 26 |
|
|
| 27 |
|
#include "stdinc.h" |
| 67 |
|
#ifdef HAVE_LIBGEOIP |
| 68 |
|
GeoIP *geoip_ctx; |
| 69 |
|
#endif |
| 70 |
+ |
|
| 71 |
|
/* /quote set variables */ |
| 72 |
|
struct SetOptions GlobalSetOptions; |
| 73 |
< |
|
| 74 |
< |
/* configuration set from ircd.conf */ |
| 72 |
< |
struct config_file_entry ConfigFileEntry; |
| 73 |
< |
/* server info set from ircd.conf */ |
| 74 |
< |
struct server_info ServerInfo; |
| 75 |
< |
/* admin info set from ircd.conf */ |
| 76 |
< |
struct admin_info AdminInfo = { NULL, NULL, NULL }; |
| 77 |
< |
struct Counter Count = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; |
| 78 |
< |
struct ServerState_t server_state = { 0 }; |
| 79 |
< |
struct logging_entry ConfigLoggingEntry = { .use_logging = 1 }; |
| 73 |
> |
struct Counter Count; |
| 74 |
> |
struct ServerState_t server_state; |
| 75 |
|
struct ServerStatistics ServerStats; |
| 76 |
|
struct timeval SystemTime; |
| 77 |
|
struct Client me; /* That's me */ |
| 113 |
|
static void |
| 114 |
|
print_startup(int pid) |
| 115 |
|
{ |
| 116 |
< |
printf("ircd: version %s\n", ircd_version); |
| 116 |
> |
printf("ircd: version %s(%s)\n", ircd_version, serno); |
| 117 |
|
printf("ircd: pid %d\n", pid); |
| 118 |
|
printf("ircd: running in %s mode from %s\n", !server_state.foreground ? "background" |
| 119 |
|
: "foreground", ConfigFileEntry.dpath); |
| 140 |
|
|
| 141 |
|
static int printVersion = 0; |
| 142 |
|
|
| 143 |
< |
static struct lgetopt myopts[] = { |
| 144 |
< |
{"configfile", &ConfigFileEntry.configfile, |
| 143 |
> |
static struct lgetopt myopts[] = |
| 144 |
> |
{ |
| 145 |
> |
{"configfile", &ConfigFileEntry.configfile, |
| 146 |
|
STRING, "File to use for ircd.conf"}, |
| 147 |
|
{"glinefile", &ConfigFileEntry.glinefile, |
| 148 |
|
STRING, "File to use for gline database"}, |
| 149 |
< |
{"klinefile", &ConfigFileEntry.klinefile, |
| 149 |
> |
{"klinefile", &ConfigFileEntry.klinefile, |
| 150 |
|
STRING, "File to use for kline database"}, |
| 151 |
|
{"dlinefile", &ConfigFileEntry.dlinefile, |
| 152 |
|
STRING, "File to use for dline database"}, |
| 153 |
< |
{"xlinefile", &ConfigFileEntry.xlinefile, |
| 153 |
> |
{"xlinefile", &ConfigFileEntry.xlinefile, |
| 154 |
|
STRING, "File to use for xline database"}, |
| 155 |
|
{"resvfile", &ConfigFileEntry.resvfile, |
| 156 |
|
STRING, "File to use for resv database"}, |
| 157 |
< |
{"logfile", &logFileName, |
| 157 |
> |
{"logfile", &logFileName, |
| 158 |
|
STRING, "File to use for ircd.log"}, |
| 159 |
|
{"pidfile", &pidFileName, |
| 160 |
|
STRING, "File to use for process ID"}, |
| 161 |
< |
{"foreground", &server_state.foreground, |
| 161 |
> |
{"foreground", &server_state.foreground, |
| 162 |
|
YESNO, "Run in foreground (don't detach)"}, |
| 163 |
< |
{"version", &printVersion, |
| 163 |
> |
{"version", &printVersion, |
| 164 |
|
YESNO, "Print version and exit"}, |
| 165 |
|
{"help", NULL, USAGE, "Print this text"}, |
| 166 |
|
{NULL, NULL, STRING, NULL}, |
| 169 |
|
void |
| 170 |
|
set_time(void) |
| 171 |
|
{ |
| 172 |
< |
static char to_send[200]; |
| 177 |
< |
struct timeval newtime; |
| 178 |
< |
newtime.tv_sec = 0; |
| 179 |
< |
newtime.tv_usec = 0; |
| 172 |
> |
struct timeval newtime = { .tv_sec = 0, .tv_usec = 0 }; |
| 173 |
|
|
| 174 |
|
if (gettimeofday(&newtime, NULL) == -1) |
| 175 |
|
{ |
| 178 |
|
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
| 179 |
|
"Clock Failure (%s), TS can be corrupted", |
| 180 |
|
strerror(errno)); |
| 181 |
< |
restart("Clock Failure"); |
| 181 |
> |
server_die("Clock Failure", 1); |
| 182 |
|
} |
| 183 |
|
|
| 184 |
|
if (newtime.tv_sec < CurrentTime) |
| 185 |
|
{ |
| 186 |
< |
snprintf(to_send, sizeof(to_send), |
| 187 |
< |
"System clock is running backwards - (%lu < %lu)", |
| 188 |
< |
(unsigned long)newtime.tv_sec, (unsigned long)CurrentTime); |
| 189 |
< |
report_error(L_ALL, to_send, me.name, 0); |
| 186 |
> |
ilog(LOG_TYPE_IRCD, "System clock is running backwards - (%lu < %lu)", |
| 187 |
> |
(unsigned long)newtime.tv_sec, (unsigned long)CurrentTime); |
| 188 |
> |
sendto_realops_flags(UMODE_DEBUG, L_ALL, SEND_NOTICE, |
| 189 |
> |
"System clock is running backwards - (%lu < %lu)", |
| 190 |
> |
(unsigned long)newtime.tv_sec, |
| 191 |
> |
(unsigned long)CurrentTime); |
| 192 |
|
set_back_events(CurrentTime - newtime.tv_sec); |
| 193 |
|
} |
| 194 |
|
|
| 199 |
|
static void |
| 200 |
|
io_loop(void) |
| 201 |
|
{ |
| 202 |
< |
while (1 == 1) |
| 202 |
> |
while (1) |
| 203 |
|
{ |
| 204 |
|
/* |
| 205 |
|
* Maybe we want a flags word? |
| 206 |
< |
* ie. if (REHASHED_KLINES(global_flags)) |
| 206 |
> |
* ie. if (REHASHED_KLINES(global_flags)) |
| 207 |
|
* SET_REHASHED_KLINES(global_flags) |
| 208 |
|
* CLEAR_REHASHED_KLINES(global_flags) |
| 209 |
|
* |
| 235 |
|
comm_select(); |
| 236 |
|
exit_aborted_clients(); |
| 237 |
|
free_exited_clients(); |
| 243 |
– |
send_queued_all(); |
| 238 |
|
|
| 239 |
|
/* Check to see whether we have to rehash the configuration .. */ |
| 240 |
|
if (dorehash) |
| 242 |
|
rehash(1); |
| 243 |
|
dorehash = 0; |
| 244 |
|
} |
| 245 |
+ |
|
| 246 |
|
if (doremotd) |
| 247 |
|
{ |
| 248 |
|
motd_recache(); |
| 249 |
|
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
| 250 |
< |
"Got signal SIGUSR1, reloading motd files"); |
| 250 |
> |
"Got signal SIGUSR1, reloading motd file(s)"); |
| 251 |
|
doremotd = 0; |
| 252 |
|
} |
| 253 |
|
} |
| 257 |
|
* |
| 258 |
|
* inputs - none |
| 259 |
|
* output - none |
| 260 |
< |
* side effects - This sets all global set options needed |
| 260 |
> |
* side effects - This sets all global set options needed |
| 261 |
|
*/ |
| 262 |
|
static void |
| 263 |
|
initialize_global_set_options(void) |
| 303 |
|
add_capability("EOB", CAP_EOB, 1); |
| 304 |
|
add_capability("TS6", CAP_TS6, 0); |
| 305 |
|
add_capability("CLUSTER", CAP_CLUSTER, 1); |
| 311 |
– |
// add_capability("FAKEHOST", CAP_FAKEHOST, 1); |
| 306 |
|
add_capability("SVS", CAP_SVS, 1); |
| 307 |
+ |
add_capability("CHW", CAP_CHW, 1); |
| 308 |
|
#ifdef HALFOPS |
| 309 |
|
add_capability("HOPS", CAP_HOPS, 1); |
| 310 |
|
#endif |
| 323 |
|
|
| 324 |
|
if ((fb = fopen(filename, "w"))) |
| 325 |
|
{ |
| 326 |
< |
char buff[32]; |
| 326 |
> |
char buff[IRCD_BUFSIZE]; |
| 327 |
|
unsigned int pid = (unsigned int)getpid(); |
| 328 |
|
|
| 329 |
|
snprintf(buff, sizeof(buff), "%u\n", pid); |
| 352 |
|
check_pidfile(const char *filename) |
| 353 |
|
{ |
| 354 |
|
FILE *fb; |
| 355 |
< |
char buff[32]; |
| 355 |
> |
char buff[IRCD_BUFSIZE]; |
| 356 |
|
pid_t pidfromfile; |
| 357 |
|
|
| 358 |
|
/* Don't do logging here, since we don't have log() initialised */ |
| 424 |
|
ssl_init(void) |
| 425 |
|
{ |
| 426 |
|
#ifdef HAVE_LIBCRYPTO |
| 427 |
+ |
const unsigned char session_id[] = "ircd-hybrid"; |
| 428 |
+ |
|
| 429 |
|
SSL_load_error_strings(); |
| 430 |
|
SSLeay_add_ssl_algorithms(); |
| 431 |
|
|
| 442 |
|
SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_TLS_ROLLBACK_BUG|SSL_OP_ALL); |
| 443 |
|
SSL_CTX_set_verify(ServerInfo.server_ctx, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE, |
| 444 |
|
always_accept_verify_cb); |
| 445 |
+ |
SSL_CTX_set_session_id_context(ServerInfo.server_ctx, session_id, sizeof(session_id) - 1); |
| 446 |
|
|
| 447 |
|
if ((ServerInfo.client_ctx = SSL_CTX_new(SSLv23_client_method())) == NULL) |
| 448 |
|
{ |
| 482 |
|
me.localClient = &meLocalUser; |
| 483 |
|
dlinkAdd(&me, &me.node, &global_client_list); /* Pointer to beginning |
| 484 |
|
of Client list */ |
| 487 |
– |
/* Initialise the channel capability usage counts... */ |
| 488 |
– |
init_chcap_usage_counts(); |
| 489 |
– |
|
| 485 |
|
ConfigFileEntry.dpath = DPATH; |
| 486 |
+ |
ConfigFileEntry.spath = SPATH; |
| 487 |
+ |
ConfigFileEntry.mpath = MPATH; |
| 488 |
|
ConfigFileEntry.configfile = CPATH; /* Server configuration file */ |
| 489 |
|
ConfigFileEntry.klinefile = KPATH; /* Server kline file */ |
| 490 |
|
ConfigFileEntry.glinefile = GPATH; /* Server gline file */ |
| 499 |
|
|
| 500 |
|
if (printVersion) |
| 501 |
|
{ |
| 502 |
< |
printf("ircd: version %s\n", ircd_version); |
| 502 |
> |
printf("ircd: version %s(%s)\n", ircd_version, serno); |
| 503 |
|
exit(EXIT_SUCCESS); |
| 504 |
|
} |
| 505 |
|
|
| 594 |
|
|
| 595 |
|
hash_add_id(&me); |
| 596 |
|
hash_add_client(&me); |
| 597 |
< |
|
| 597 |
> |
|
| 598 |
|
/* add ourselves to global_serv_list */ |
| 599 |
|
dlinkAdd(&me, make_dlink_node(), &global_serv_list); |
| 600 |
|
|