| 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" |
| 28 |
< |
#include "s_user.h" |
| 28 |
> |
#include "user.h" |
| 29 |
|
#include "list.h" |
| 30 |
|
#include "ircd.h" |
| 31 |
|
#include "channel.h" |
| 30 |
– |
#include "channel_mode.h" |
| 32 |
|
#include "client.h" |
| 33 |
|
#include "event.h" |
| 34 |
|
#include "fdlist.h" |
| 35 |
|
#include "hash.h" |
| 36 |
|
#include "irc_string.h" |
| 37 |
|
#include "ircd_signal.h" |
| 38 |
< |
#include "s_gline.h" |
| 38 |
> |
#include "gline.h" |
| 39 |
|
#include "motd.h" |
| 40 |
|
#include "conf.h" |
| 41 |
|
#include "hostmask.h" |
| 41 |
– |
#include "numeric.h" |
| 42 |
– |
#include "packet.h" |
| 42 |
|
#include "parse.h" |
| 43 |
< |
#include "irc_res.h" |
| 43 |
> |
#include "res.h" |
| 44 |
|
#include "restart.h" |
| 45 |
|
#include "rng_mt.h" |
| 46 |
< |
#include "s_auth.h" |
| 46 |
> |
#include "auth.h" |
| 47 |
|
#include "s_bsd.h" |
| 48 |
|
#include "log.h" |
| 49 |
< |
#include "s_misc.h" |
| 51 |
< |
#include "s_serv.h" /* try_connections */ |
| 49 |
> |
#include "server.h" /* try_connections */ |
| 50 |
|
#include "send.h" |
| 51 |
|
#include "whowas.h" |
| 52 |
|
#include "modules.h" |
| 53 |
|
#include "memory.h" |
| 54 |
|
#include "mempool.h" |
| 57 |
– |
#include "hook.h" |
| 55 |
|
#include "ircd_getopt.h" |
| 56 |
|
#include "supported.h" |
| 57 |
|
#include "watch.h" |
| 62 |
|
#ifdef HAVE_LIBGEOIP |
| 63 |
|
GeoIP *geoip_ctx; |
| 64 |
|
#endif |
| 65 |
+ |
|
| 66 |
|
/* /quote set variables */ |
| 67 |
|
struct SetOptions GlobalSetOptions; |
| 68 |
< |
|
| 69 |
< |
/* 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 }; |
| 68 |
> |
struct Counter Count; |
| 69 |
> |
struct ServerState_t server_state; |
| 70 |
|
struct ServerStatistics ServerStats; |
| 71 |
|
struct timeval SystemTime; |
| 72 |
|
struct Client me; /* That's me */ |
| 83 |
|
/* Set to zero because it should be initialized later using |
| 84 |
|
* initialize_server_capabs |
| 85 |
|
*/ |
| 86 |
< |
int default_server_capabs = 0; |
| 86 |
> |
unsigned int default_server_capabs; |
| 87 |
|
unsigned int splitmode; |
| 88 |
|
unsigned int splitchecking; |
| 89 |
|
unsigned int split_users; |
| 90 |
|
unsigned int split_servers; |
| 91 |
|
|
| 102 |
– |
/* Do klines the same way hybrid-6 did them, i.e. at the |
| 103 |
– |
* top of the next io_loop instead of in the same loop as |
| 104 |
– |
* the klines are being applied. |
| 105 |
– |
* |
| 106 |
– |
* This should fix strange CPU starvation as very indirectly reported. |
| 107 |
– |
* (Why do you people not email bug reports? WHY? WHY?) |
| 108 |
– |
* |
| 109 |
– |
* - Dianora |
| 110 |
– |
*/ |
| 111 |
– |
|
| 112 |
– |
int rehashed_klines = 0; |
| 113 |
– |
|
| 114 |
– |
|
| 92 |
|
/* |
| 93 |
|
* print_startup - print startup information |
| 94 |
|
*/ |
| 122 |
|
|
| 123 |
|
static int printVersion = 0; |
| 124 |
|
|
| 125 |
< |
static struct lgetopt myopts[] = { |
| 126 |
< |
{"configfile", &ConfigFileEntry.configfile, |
| 125 |
> |
static struct lgetopt myopts[] = |
| 126 |
> |
{ |
| 127 |
> |
{"configfile", &ConfigFileEntry.configfile, |
| 128 |
|
STRING, "File to use for ircd.conf"}, |
| 129 |
|
{"glinefile", &ConfigFileEntry.glinefile, |
| 130 |
|
STRING, "File to use for gline database"}, |
| 131 |
< |
{"klinefile", &ConfigFileEntry.klinefile, |
| 131 |
> |
{"klinefile", &ConfigFileEntry.klinefile, |
| 132 |
|
STRING, "File to use for kline database"}, |
| 133 |
|
{"dlinefile", &ConfigFileEntry.dlinefile, |
| 134 |
|
STRING, "File to use for dline database"}, |
| 135 |
< |
{"xlinefile", &ConfigFileEntry.xlinefile, |
| 135 |
> |
{"xlinefile", &ConfigFileEntry.xlinefile, |
| 136 |
|
STRING, "File to use for xline database"}, |
| 137 |
|
{"resvfile", &ConfigFileEntry.resvfile, |
| 138 |
|
STRING, "File to use for resv database"}, |
| 139 |
< |
{"logfile", &logFileName, |
| 139 |
> |
{"logfile", &logFileName, |
| 140 |
|
STRING, "File to use for ircd.log"}, |
| 141 |
|
{"pidfile", &pidFileName, |
| 142 |
|
STRING, "File to use for process ID"}, |
| 143 |
< |
{"foreground", &server_state.foreground, |
| 143 |
> |
{"foreground", &server_state.foreground, |
| 144 |
|
YESNO, "Run in foreground (don't detach)"}, |
| 145 |
< |
{"version", &printVersion, |
| 145 |
> |
{"version", &printVersion, |
| 146 |
|
YESNO, "Print version and exit"}, |
| 147 |
|
{"help", NULL, USAGE, "Print this text"}, |
| 148 |
|
{NULL, NULL, STRING, NULL}, |
| 151 |
|
void |
| 152 |
|
set_time(void) |
| 153 |
|
{ |
| 154 |
< |
static char to_send[IRCD_BUFSIZE]; |
| 177 |
< |
struct timeval newtime; |
| 178 |
< |
newtime.tv_sec = 0; |
| 179 |
< |
newtime.tv_usec = 0; |
| 154 |
> |
struct timeval newtime = { .tv_sec = 0, .tv_usec = 0 }; |
| 155 |
|
|
| 156 |
|
if (gettimeofday(&newtime, NULL) == -1) |
| 157 |
|
{ |
| 160 |
|
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
| 161 |
|
"Clock Failure (%s), TS can be corrupted", |
| 162 |
|
strerror(errno)); |
| 163 |
< |
restart("Clock Failure"); |
| 163 |
> |
server_die("Clock Failure", 1); |
| 164 |
|
} |
| 165 |
|
|
| 166 |
|
if (newtime.tv_sec < CurrentTime) |
| 167 |
|
{ |
| 168 |
< |
snprintf(to_send, sizeof(to_send), |
| 169 |
< |
"System clock is running backwards - (%lu < %lu)", |
| 170 |
< |
(unsigned long)newtime.tv_sec, (unsigned long)CurrentTime); |
| 171 |
< |
report_error(L_ALL, to_send, me.name, 0); |
| 168 |
> |
ilog(LOG_TYPE_IRCD, "System clock is running backwards - (%lu < %lu)", |
| 169 |
> |
(unsigned long)newtime.tv_sec, (unsigned long)CurrentTime); |
| 170 |
> |
sendto_realops_flags(UMODE_DEBUG, L_ALL, SEND_NOTICE, |
| 171 |
> |
"System clock is running backwards - (%lu < %lu)", |
| 172 |
> |
(unsigned long)newtime.tv_sec, |
| 173 |
> |
(unsigned long)CurrentTime); |
| 174 |
|
set_back_events(CurrentTime - newtime.tv_sec); |
| 175 |
|
} |
| 176 |
|
|
| 181 |
|
static void |
| 182 |
|
io_loop(void) |
| 183 |
|
{ |
| 184 |
< |
while (1 == 1) |
| 184 |
> |
while (1) |
| 185 |
|
{ |
| 209 |
– |
/* |
| 210 |
– |
* Maybe we want a flags word? |
| 211 |
– |
* ie. if (REHASHED_KLINES(global_flags)) |
| 212 |
– |
* SET_REHASHED_KLINES(global_flags) |
| 213 |
– |
* CLEAR_REHASHED_KLINES(global_flags) |
| 214 |
– |
* |
| 215 |
– |
* - Dianora |
| 216 |
– |
*/ |
| 217 |
– |
if (rehashed_klines) |
| 218 |
– |
{ |
| 219 |
– |
check_conf_klines(); |
| 220 |
– |
rehashed_klines = 0; |
| 221 |
– |
} |
| 222 |
– |
|
| 186 |
|
if (listing_client_list.head) |
| 187 |
|
{ |
| 188 |
|
dlink_node *ptr = NULL, *ptr_next = NULL; |
| 189 |
|
DLINK_FOREACH_SAFE(ptr, ptr_next, listing_client_list.head) |
| 190 |
< |
{ |
| 228 |
< |
struct Client *client_p = ptr->data; |
| 229 |
< |
assert(client_p->localClient->list_task); |
| 230 |
< |
safe_list_channels(client_p, client_p->localClient->list_task, 0); |
| 231 |
< |
} |
| 190 |
> |
safe_list_channels(ptr->data, 0); |
| 191 |
|
} |
| 192 |
|
|
| 193 |
|
/* Run pending events, then get the number of seconds to the next |
| 199 |
|
comm_select(); |
| 200 |
|
exit_aborted_clients(); |
| 201 |
|
free_exited_clients(); |
| 243 |
– |
send_queued_all(); |
| 202 |
|
|
| 203 |
|
/* Check to see whether we have to rehash the configuration .. */ |
| 204 |
|
if (dorehash) |
| 206 |
|
rehash(1); |
| 207 |
|
dorehash = 0; |
| 208 |
|
} |
| 209 |
+ |
|
| 210 |
|
if (doremotd) |
| 211 |
|
{ |
| 212 |
|
motd_recache(); |
| 213 |
|
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
| 214 |
< |
"Got signal SIGUSR1, reloading motd files"); |
| 214 |
> |
"Got signal SIGUSR1, reloading motd file(s)"); |
| 215 |
|
doremotd = 0; |
| 216 |
|
} |
| 217 |
|
} |
| 221 |
|
* |
| 222 |
|
* inputs - none |
| 223 |
|
* output - none |
| 224 |
< |
* side effects - This sets all global set options needed |
| 224 |
> |
* side effects - This sets all global set options needed |
| 225 |
|
*/ |
| 226 |
|
static void |
| 227 |
|
initialize_global_set_options(void) |
| 267 |
|
add_capability("EOB", CAP_EOB, 1); |
| 268 |
|
add_capability("TS6", CAP_TS6, 0); |
| 269 |
|
add_capability("CLUSTER", CAP_CLUSTER, 1); |
| 311 |
– |
// add_capability("FAKEHOST", CAP_FAKEHOST, 1); |
| 270 |
|
add_capability("SVS", CAP_SVS, 1); |
| 271 |
< |
#ifdef HALFOPS |
| 271 |
> |
add_capability("CHW", CAP_CHW, 1); |
| 272 |
|
add_capability("HOPS", CAP_HOPS, 1); |
| 315 |
– |
#endif |
| 273 |
|
} |
| 274 |
|
|
| 275 |
|
/* write_pidfile() |
| 386 |
|
ssl_init(void) |
| 387 |
|
{ |
| 388 |
|
#ifdef HAVE_LIBCRYPTO |
| 389 |
+ |
const unsigned char session_id[] = "ircd-hybrid"; |
| 390 |
+ |
|
| 391 |
|
SSL_load_error_strings(); |
| 392 |
|
SSLeay_add_ssl_algorithms(); |
| 393 |
|
|
| 401 |
|
} |
| 402 |
|
|
| 403 |
|
SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TLSv1); |
| 404 |
< |
SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_TLS_ROLLBACK_BUG|SSL_OP_ALL); |
| 404 |
> |
SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_TLS_ROLLBACK_BUG); |
| 405 |
|
SSL_CTX_set_verify(ServerInfo.server_ctx, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE, |
| 406 |
|
always_accept_verify_cb); |
| 407 |
+ |
SSL_CTX_set_session_id_context(ServerInfo.server_ctx, session_id, sizeof(session_id) - 1); |
| 408 |
+ |
|
| 409 |
+ |
#if OPENSSL_VERSION_NUMBER >= 0x1000005FL && !defined(OPENSSL_NO_ECDH) |
| 410 |
+ |
{ |
| 411 |
+ |
EC_KEY *key = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1); |
| 412 |
+ |
|
| 413 |
+ |
if (key) |
| 414 |
+ |
{ |
| 415 |
+ |
SSL_CTX_set_tmp_ecdh(ServerInfo.server_ctx, key); |
| 416 |
+ |
EC_KEY_free(key); |
| 417 |
+ |
} |
| 418 |
+ |
} |
| 419 |
+ |
|
| 420 |
+ |
SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_SINGLE_ECDH_USE); |
| 421 |
+ |
#endif |
| 422 |
|
|
| 423 |
|
if ((ServerInfo.client_ctx = SSL_CTX_new(SSLv23_client_method())) == NULL) |
| 424 |
|
{ |
| 430 |
|
} |
| 431 |
|
|
| 432 |
|
SSL_CTX_set_options(ServerInfo.client_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TLSv1); |
| 433 |
< |
SSL_CTX_set_options(ServerInfo.client_ctx, SSL_OP_TLS_ROLLBACK_BUG|SSL_OP_ALL); |
| 433 |
> |
SSL_CTX_set_options(ServerInfo.client_ctx, SSL_OP_TLS_ROLLBACK_BUG); |
| 434 |
|
SSL_CTX_set_verify(ServerInfo.client_ctx, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE, |
| 435 |
|
always_accept_verify_cb); |
| 436 |
|
#endif /* HAVE_LIBCRYPTO */ |
| 442 |
|
/* Check to see if the user is running us as root, which is a nono */ |
| 443 |
|
if (geteuid() == 0) |
| 444 |
|
{ |
| 445 |
< |
fprintf(stderr, "Don't run ircd as root!!!\n"); |
| 445 |
> |
fprintf(stderr, "ERROR: This server won't run as root/superuser\n"); |
| 446 |
|
return -1; |
| 447 |
|
} |
| 448 |
|
|
| 458 |
|
me.localClient = &meLocalUser; |
| 459 |
|
dlinkAdd(&me, &me.node, &global_client_list); /* Pointer to beginning |
| 460 |
|
of Client list */ |
| 487 |
– |
/* Initialise the channel capability usage counts... */ |
| 488 |
– |
init_chcap_usage_counts(); |
| 489 |
– |
|
| 461 |
|
ConfigFileEntry.dpath = DPATH; |
| 462 |
+ |
ConfigFileEntry.spath = SPATH; |
| 463 |
+ |
ConfigFileEntry.mpath = MPATH; |
| 464 |
|
ConfigFileEntry.configfile = CPATH; /* Server configuration file */ |
| 465 |
|
ConfigFileEntry.klinefile = KPATH; /* Server kline file */ |
| 466 |
|
ConfigFileEntry.glinefile = GPATH; /* Server gline file */ |
| 570 |
|
|
| 571 |
|
hash_add_id(&me); |
| 572 |
|
hash_add_client(&me); |
| 573 |
< |
|
| 573 |
> |
|
| 574 |
|
/* add ourselves to global_serv_list */ |
| 575 |
|
dlinkAdd(&me, make_dlink_node(), &global_serv_list); |
| 576 |
|
|