| 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" |
| 32 |
– |
#include "common.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 "ircd_handler.h" |
| 41 |
< |
#include "msg.h" /* msgtab */ |
| 40 |
> |
#include "conf.h" |
| 41 |
|
#include "hostmask.h" |
| 43 |
– |
#include "numeric.h" |
| 44 |
– |
#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 "s_conf.h" |
| 49 |
< |
#include "s_log.h" |
| 53 |
< |
#include "s_misc.h" |
| 54 |
< |
#include "s_serv.h" /* try_connections */ |
| 48 |
> |
#include "log.h" |
| 49 |
> |
#include "server.h" /* try_connections */ |
| 50 |
|
#include "send.h" |
| 51 |
|
#include "whowas.h" |
| 52 |
|
#include "modules.h" |
| 53 |
|
#include "memory.h" |
| 54 |
< |
#include "hook.h" |
| 54 |
> |
#include "mempool.h" |
| 55 |
|
#include "ircd_getopt.h" |
| 61 |
– |
#include "balloc.h" |
| 62 |
– |
#include "motd.h" |
| 56 |
|
#include "supported.h" |
| 57 |
|
#include "watch.h" |
| 58 |
+ |
#include "conf_db.h" |
| 59 |
+ |
#include "conf_class.h" |
| 60 |
+ |
|
| 61 |
|
|
| 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 */ |
| 71 |
< |
struct config_file_entry ConfigFileEntry; |
| 72 |
< |
/* server info set from ircd.conf */ |
| 73 |
< |
struct server_info ServerInfo; |
| 74 |
< |
/* admin info set from ircd.conf */ |
| 75 |
< |
struct admin_info AdminInfo = { NULL, NULL, NULL }; |
| 76 |
< |
struct Counter Count = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; |
| 77 |
< |
struct ServerState_t server_state = { 0 }; |
| 78 |
< |
struct logging_entry ConfigLoggingEntry = { 1, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0} }; |
| 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 */ |
| 76 |
|
const char *pidFileName = PPATH; |
| 77 |
|
|
| 78 |
|
char **myargv; |
| 88 |
– |
char ircd_platform[PLATFORMLEN]; |
| 79 |
|
|
| 80 |
|
int dorehash = 0; |
| 81 |
|
int doremotd = 0; |
| 83 |
|
/* Set to zero because it should be initialized later using |
| 84 |
|
* initialize_server_capabs |
| 85 |
|
*/ |
| 86 |
< |
int default_server_capabs = 0; |
| 97 |
< |
|
| 98 |
< |
#ifdef HAVE_LIBCRYPTO |
| 99 |
< |
int bio_spare_fd = -1; |
| 100 |
< |
#endif |
| 101 |
< |
|
| 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 |
|
|
| 107 |
– |
/* Do klines the same way hybrid-6 did them, i.e. at the |
| 108 |
– |
* top of the next io_loop instead of in the same loop as |
| 109 |
– |
* the klines are being applied. |
| 110 |
– |
* |
| 111 |
– |
* This should fix strange CPU starvation as very indirectly reported. |
| 112 |
– |
* (Why do you people not email bug reports? WHY? WHY?) |
| 113 |
– |
* |
| 114 |
– |
* - Dianora |
| 115 |
– |
*/ |
| 116 |
– |
|
| 117 |
– |
int rehashed_klines = 0; |
| 118 |
– |
|
| 119 |
– |
|
| 92 |
|
/* |
| 93 |
|
* print_startup - print startup information |
| 94 |
|
*/ |
| 95 |
|
static void |
| 96 |
|
print_startup(int pid) |
| 97 |
|
{ |
| 98 |
< |
printf("ircd: version %s\n", ircd_version); |
| 98 |
> |
printf("ircd: version %s(%s)\n", ircd_version, serno); |
| 99 |
|
printf("ircd: pid %d\n", pid); |
| 100 |
|
printf("ircd: running in %s mode from %s\n", !server_state.foreground ? "background" |
| 101 |
|
: "foreground", ConfigFileEntry.dpath); |
| 122 |
|
|
| 123 |
|
static int printVersion = 0; |
| 124 |
|
|
| 125 |
< |
struct lgetopt myopts[] = { |
| 126 |
< |
{"dlinefile", &ConfigFileEntry.dlinefile, |
| 127 |
< |
STRING, "File to use for dline.conf"}, |
| 156 |
< |
{"configfile", &ConfigFileEntry.configfile, |
| 125 |
> |
static struct lgetopt myopts[] = |
| 126 |
> |
{ |
| 127 |
> |
{"configfile", &ConfigFileEntry.configfile, |
| 128 |
|
STRING, "File to use for ircd.conf"}, |
| 129 |
< |
{"klinefile", &ConfigFileEntry.klinefile, |
| 130 |
< |
STRING, "File to use for kline.conf"}, |
| 131 |
< |
{"xlinefile", &ConfigFileEntry.xlinefile, |
| 132 |
< |
STRING, "File to use for xline.conf"}, |
| 133 |
< |
{"logfile", &logFileName, |
| 129 |
> |
{"glinefile", &ConfigFileEntry.glinefile, |
| 130 |
> |
STRING, "File to use for gline database"}, |
| 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, |
| 136 |
> |
STRING, "File to use for xline database"}, |
| 137 |
> |
{"resvfile", &ConfigFileEntry.resvfile, |
| 138 |
> |
STRING, "File to use for resv database"}, |
| 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[200]; |
| 178 |
< |
struct timeval newtime; |
| 179 |
< |
newtime.tv_sec = 0; |
| 180 |
< |
newtime.tv_usec = 0; |
| 154 |
> |
struct timeval newtime = { .tv_sec = 0, .tv_usec = 0 }; |
| 155 |
|
|
| 156 |
|
if (gettimeofday(&newtime, NULL) == -1) |
| 157 |
|
{ |
| 158 |
< |
ilog(L_ERROR, "Clock Failure (%s), TS can be corrupted", |
| 158 |
> |
ilog(LOG_TYPE_IRCD, "Clock Failure (%s), TS can be corrupted", |
| 159 |
|
strerror(errno)); |
| 160 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, |
| 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 |
|
{ |
| 210 |
– |
/* |
| 211 |
– |
* Maybe we want a flags word? |
| 212 |
– |
* ie. if (REHASHED_KLINES(global_flags)) |
| 213 |
– |
* SET_REHASHED_KLINES(global_flags) |
| 214 |
– |
* CLEAR_REHASHED_KLINES(global_flags) |
| 215 |
– |
* |
| 216 |
– |
* - Dianora |
| 217 |
– |
*/ |
| 218 |
– |
if (rehashed_klines) |
| 219 |
– |
{ |
| 220 |
– |
check_conf_klines(); |
| 221 |
– |
rehashed_klines = 0; |
| 222 |
– |
} |
| 223 |
– |
|
| 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 |
< |
{ |
| 229 |
< |
struct Client *client_p = ptr->data; |
| 230 |
< |
assert(client_p->localClient->list_task); |
| 231 |
< |
safe_list_channels(client_p, client_p->localClient->list_task, 0); |
| 232 |
< |
} |
| 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(); |
| 244 |
– |
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 |
< |
read_message_file(&ConfigFileEntry.motd); |
| 213 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, |
| 214 |
< |
"Got signal SIGUSR1, reloading ircd motd file"); |
| 212 |
> |
motd_recache(); |
| 213 |
> |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
| 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) |
| 255 |
|
/* End of global set options */ |
| 256 |
|
} |
| 257 |
|
|
| 300 |
– |
/* initialize_message_files() |
| 301 |
– |
* |
| 302 |
– |
* inputs - none |
| 303 |
– |
* output - none |
| 304 |
– |
* side effects - Set up all message files needed, motd etc. |
| 305 |
– |
*/ |
| 306 |
– |
static void |
| 307 |
– |
initialize_message_files(void) |
| 308 |
– |
{ |
| 309 |
– |
init_message_file(USER_MOTD, MPATH, &ConfigFileEntry.motd); |
| 310 |
– |
init_message_file(OPER_MOTD, OPATH, &ConfigFileEntry.opermotd); |
| 311 |
– |
init_message_file(USER_LINKS, LIPATH, &ConfigFileEntry.linksfile); |
| 312 |
– |
|
| 313 |
– |
read_message_file(&ConfigFileEntry.motd); |
| 314 |
– |
read_message_file(&ConfigFileEntry.opermotd); |
| 315 |
– |
read_message_file(&ConfigFileEntry.linksfile); |
| 316 |
– |
|
| 317 |
– |
init_isupport(); |
| 318 |
– |
} |
| 319 |
– |
|
| 258 |
|
/* initialize_server_capabs() |
| 259 |
|
* |
| 260 |
|
* inputs - none |
| 266 |
|
add_capability("QS", CAP_QS, 1); |
| 267 |
|
add_capability("EOB", CAP_EOB, 1); |
| 268 |
|
add_capability("TS6", CAP_TS6, 0); |
| 331 |
– |
add_capability("ZIP", CAP_ZIP, 0); |
| 269 |
|
add_capability("CLUSTER", CAP_CLUSTER, 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); |
| 336 |
– |
#endif |
| 273 |
|
} |
| 274 |
|
|
| 275 |
|
/* write_pidfile() |
| 281 |
|
static void |
| 282 |
|
write_pidfile(const char *filename) |
| 283 |
|
{ |
| 284 |
< |
FBFILE *fb; |
| 284 |
> |
FILE *fb; |
| 285 |
|
|
| 286 |
< |
if ((fb = fbopen(filename, "w"))) |
| 286 |
> |
if ((fb = fopen(filename, "w"))) |
| 287 |
|
{ |
| 288 |
< |
char buff[32]; |
| 288 |
> |
char buff[IRCD_BUFSIZE]; |
| 289 |
|
unsigned int pid = (unsigned int)getpid(); |
| 354 |
– |
size_t nbytes = snprintf(buff, sizeof(buff), "%u\n", pid); |
| 290 |
|
|
| 291 |
< |
if ((fbputs(buff, fb, nbytes) == -1)) |
| 292 |
< |
ilog(L_ERROR, "Error writing %u to pid file %s (%s)", |
| 291 |
> |
snprintf(buff, sizeof(buff), "%u\n", pid); |
| 292 |
> |
|
| 293 |
> |
if ((fputs(buff, fb) == -1)) |
| 294 |
> |
ilog(LOG_TYPE_IRCD, "Error writing %u to pid file %s (%s)", |
| 295 |
|
pid, filename, strerror(errno)); |
| 296 |
|
|
| 297 |
< |
fbclose(fb); |
| 361 |
< |
return; |
| 297 |
> |
fclose(fb); |
| 298 |
|
} |
| 299 |
|
else |
| 300 |
|
{ |
| 301 |
< |
ilog(L_ERROR, "Error opening pid file %s", filename); |
| 301 |
> |
ilog(LOG_TYPE_IRCD, "Error opening pid file %s", filename); |
| 302 |
|
} |
| 303 |
|
} |
| 304 |
|
|
| 313 |
|
static void |
| 314 |
|
check_pidfile(const char *filename) |
| 315 |
|
{ |
| 316 |
< |
FBFILE *fb; |
| 317 |
< |
char buff[32]; |
| 316 |
> |
FILE *fb; |
| 317 |
> |
char buff[IRCD_BUFSIZE]; |
| 318 |
|
pid_t pidfromfile; |
| 319 |
|
|
| 320 |
|
/* Don't do logging here, since we don't have log() initialised */ |
| 321 |
< |
if ((fb = fbopen(filename, "r"))) |
| 321 |
> |
if ((fb = fopen(filename, "r"))) |
| 322 |
|
{ |
| 323 |
< |
if (fbgets(buff, 20, fb) == NULL) |
| 323 |
> |
if (fgets(buff, 20, fb) == NULL) |
| 324 |
|
{ |
| 325 |
|
/* log(L_ERROR, "Error reading from pid file %s (%s)", filename, |
| 326 |
|
* strerror(errno)); |
| 338 |
|
} |
| 339 |
|
} |
| 340 |
|
|
| 341 |
< |
fbclose(fb); |
| 341 |
> |
fclose(fb); |
| 342 |
|
} |
| 343 |
|
else if (errno != ENOENT) |
| 344 |
|
{ |
| 368 |
|
#endif |
| 369 |
|
} |
| 370 |
|
|
| 371 |
+ |
#ifdef HAVE_LIBCRYPTO |
| 372 |
+ |
static int |
| 373 |
+ |
always_accept_verify_cb(int preverify_ok, X509_STORE_CTX *x509_ctx) |
| 374 |
+ |
{ |
| 375 |
+ |
return 1; |
| 376 |
+ |
} |
| 377 |
+ |
#endif |
| 378 |
+ |
|
| 379 |
|
/* init_ssl() |
| 380 |
|
* |
| 381 |
|
* inputs - nothing |
| 383 |
|
* side effects - setups SSL context. |
| 384 |
|
*/ |
| 385 |
|
static void |
| 386 |
< |
init_ssl(void) |
| 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 |
|
|
| 395 |
|
{ |
| 396 |
|
const char *s; |
| 397 |
|
|
| 398 |
< |
fprintf(stderr, "ERROR: Could not initialize the SSL context -- %s\n", |
| 398 |
> |
fprintf(stderr, "ERROR: Could not initialize the SSL Server context -- %s\n", |
| 399 |
|
s = ERR_lib_error_string(ERR_get_error())); |
| 400 |
< |
ilog(L_CRIT, "ERROR: Could not initialize the SSL context -- %s\n", s); |
| 400 |
> |
ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Server context -- %s\n", s); |
| 401 |
|
} |
| 402 |
|
|
| 403 |
< |
SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_NO_SSLv2); |
| 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); |
| 405 |
< |
SSL_CTX_set_verify(ServerInfo.server_ctx, SSL_VERIFY_NONE, NULL); |
| 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 |
< |
bio_spare_fd = save_spare_fd("SSL private key validation"); |
| 410 |
< |
#endif /* HAVE_LIBCRYPTO */ |
| 411 |
< |
} |
| 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 |
< |
/* init_callbacks() |
| 414 |
< |
* |
| 415 |
< |
* inputs - nothing |
| 416 |
< |
* output - nothing |
| 417 |
< |
* side effects - setups standard hook points |
| 418 |
< |
*/ |
| 419 |
< |
static void |
| 420 |
< |
init_callbacks(void) |
| 421 |
< |
{ |
| 422 |
< |
iorecv_cb = register_callback("iorecv", iorecv_default); |
| 423 |
< |
iosend_cb = register_callback("iosend", iosend_default); |
| 424 |
< |
iorecvctrl_cb = register_callback("iorecvctrl", NULL); |
| 425 |
< |
iosendctrl_cb = register_callback("iosendctrl", NULL); |
| 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 |
> |
{ |
| 425 |
> |
const char *s; |
| 426 |
> |
|
| 427 |
> |
fprintf(stderr, "ERROR: Could not initialize the SSL Client context -- %s\n", |
| 428 |
> |
s = ERR_lib_error_string(ERR_get_error())); |
| 429 |
> |
ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Client context -- %s\n", s); |
| 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); |
| 434 |
> |
SSL_CTX_set_verify(ServerInfo.client_ctx, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE, |
| 435 |
> |
always_accept_verify_cb); |
| 436 |
> |
#endif /* HAVE_LIBCRYPTO */ |
| 437 |
|
} |
| 438 |
|
|
| 439 |
|
int |
| 440 |
|
main(int argc, char *argv[]) |
| 441 |
|
{ |
| 442 |
< |
/* Check to see if the user is running |
| 484 |
< |
* us as root, which is a nono |
| 485 |
< |
*/ |
| 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 |
|
|
| 456 |
|
init_genrand(SystemTime.tv_sec ^ (SystemTime.tv_usec | (getpid() << 20))); |
| 457 |
|
|
| 458 |
|
me.localClient = &meLocalUser; |
| 459 |
< |
dlinkAdd(&me, &me.node, &global_client_list); /* Pointer to beginning |
| 459 |
> |
dlinkAdd(&me, &me.node, &global_client_list); /* Pointer to beginning |
| 460 |
|
of Client list */ |
| 504 |
– |
/* Initialise the channel capability usage counts... */ |
| 505 |
– |
init_chcap_usage_counts(); |
| 506 |
– |
|
| 461 |
|
ConfigFileEntry.dpath = DPATH; |
| 462 |
< |
ConfigFileEntry.configfile = CPATH; /* Server configuration file */ |
| 463 |
< |
ConfigFileEntry.klinefile = KPATH; /* Server kline file */ |
| 464 |
< |
ConfigFileEntry.xlinefile = XPATH; /* Server xline file */ |
| 465 |
< |
ConfigFileEntry.rxlinefile = RXPATH; /* Server regex xline file */ |
| 466 |
< |
ConfigFileEntry.rklinefile = RKPATH; /* Server regex kline file */ |
| 467 |
< |
ConfigFileEntry.dlinefile = DLPATH; /* dline file */ |
| 468 |
< |
ConfigFileEntry.glinefile = GPATH; /* gline log file */ |
| 469 |
< |
ConfigFileEntry.cresvfile = CRESVPATH; /* channel resv file */ |
| 470 |
< |
ConfigFileEntry.nresvfile = NRESVPATH; /* nick resv file */ |
| 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 */ |
| 467 |
> |
ConfigFileEntry.xlinefile = XPATH; /* Server xline file */ |
| 468 |
> |
ConfigFileEntry.dlinefile = DLPATH; /* dline file */ |
| 469 |
> |
ConfigFileEntry.resvfile = RESVPATH; /* resv file */ |
| 470 |
> |
|
| 471 |
|
myargv = argv; |
| 472 |
|
umask(077); /* better safe than sorry --SRB */ |
| 473 |
|
|
| 475 |
|
|
| 476 |
|
if (printVersion) |
| 477 |
|
{ |
| 478 |
< |
printf("ircd: version %s\n", ircd_version); |
| 478 |
> |
printf("ircd: version %s(%s)\n", ircd_version, serno); |
| 479 |
|
exit(EXIT_SUCCESS); |
| 480 |
|
} |
| 481 |
|
|
| 485 |
|
exit(EXIT_FAILURE); |
| 486 |
|
} |
| 487 |
|
|
| 488 |
< |
init_ssl(); |
| 488 |
> |
ssl_init(); |
| 489 |
|
|
| 490 |
|
if (!server_state.foreground) |
| 491 |
|
{ |
| 497 |
|
|
| 498 |
|
setup_signals(); |
| 499 |
|
|
| 546 |
– |
get_ircd_platform(ircd_platform); |
| 547 |
– |
|
| 500 |
|
/* Init the event subsystem */ |
| 501 |
|
eventInit(); |
| 502 |
+ |
|
| 503 |
|
/* We need this to initialise the fd array before anything else */ |
| 504 |
|
fdlist_init(); |
| 505 |
< |
init_log(logFileName); |
| 505 |
> |
log_set_file(LOG_TYPE_IRCD, 0, logFileName); |
| 506 |
|
check_can_use_v6(); |
| 507 |
< |
init_comm(); /* This needs to be setup early ! -- adrian */ |
| 507 |
> |
init_netio(); /* This needs to be setup early ! -- adrian */ |
| 508 |
> |
|
| 509 |
|
/* Check if there is pidfile and daemon already running */ |
| 510 |
|
check_pidfile(pidFileName); |
| 511 |
|
|
| 512 |
< |
initBlockHeap(); |
| 512 |
> |
mp_pool_init(); |
| 513 |
|
init_dlink_nodes(); |
| 514 |
< |
init_callbacks(); |
| 561 |
< |
initialize_message_files(); |
| 514 |
> |
init_isupport(); |
| 515 |
|
dbuf_init(); |
| 516 |
< |
init_hash(); |
| 516 |
> |
hash_init(); |
| 517 |
|
init_ip_hash_table(); /* client host ip hash table */ |
| 518 |
|
init_host_hash(); /* Host-hashtable. */ |
| 519 |
< |
clear_tree_parse(); |
| 520 |
< |
init_client(); |
| 521 |
< |
init_class(); |
| 569 |
< |
init_whowas(); |
| 519 |
> |
client_init(); |
| 520 |
> |
class_init(); |
| 521 |
> |
whowas_init(); |
| 522 |
|
watch_init(); |
| 523 |
< |
init_auth(); /* Initialise the auth code */ |
| 523 |
> |
auth_init(); /* Initialise the auth code */ |
| 524 |
|
init_resolver(); /* Needs to be setup before the io loop */ |
| 525 |
+ |
modules_init(); |
| 526 |
|
read_conf_files(1); /* cold start init conf files */ |
| 527 |
|
init_uid(); |
| 528 |
|
initialize_server_capabs(); /* Set up default_server_capabs */ |
| 529 |
|
initialize_global_set_options(); |
| 530 |
< |
init_channels(); |
| 530 |
> |
channel_init(); |
| 531 |
> |
read_links_file(); |
| 532 |
> |
motd_init(); |
| 533 |
> |
#ifdef HAVE_LIBGEOIP |
| 534 |
> |
geoip_ctx = GeoIP_new(GEOIP_MEMORY_CACHE); |
| 535 |
> |
#endif |
| 536 |
|
|
| 537 |
|
if (EmptyString(ServerInfo.sid)) |
| 538 |
|
{ |
| 539 |
< |
ilog(L_CRIT, "ERROR: No server id specified in serverinfo block."); |
| 539 |
> |
ilog(LOG_TYPE_IRCD, "ERROR: No server id specified in serverinfo block."); |
| 540 |
|
exit(EXIT_FAILURE); |
| 541 |
|
} |
| 542 |
|
|
| 544 |
|
|
| 545 |
|
if (EmptyString(ServerInfo.name)) |
| 546 |
|
{ |
| 547 |
< |
ilog(L_CRIT, "ERROR: No server name specified in serverinfo block."); |
| 547 |
> |
ilog(LOG_TYPE_IRCD, "ERROR: No server name specified in serverinfo block."); |
| 548 |
|
exit(EXIT_FAILURE); |
| 549 |
|
} |
| 550 |
|
|
| 553 |
|
/* serverinfo{} description must exist. If not, error out.*/ |
| 554 |
|
if (EmptyString(ServerInfo.description)) |
| 555 |
|
{ |
| 556 |
< |
ilog(L_CRIT, "ERROR: No server description specified in serverinfo block."); |
| 556 |
> |
ilog(LOG_TYPE_IRCD, "ERROR: No server description specified in serverinfo block."); |
| 557 |
|
exit(EXIT_FAILURE); |
| 558 |
|
} |
| 559 |
|
|
| 560 |
|
strlcpy(me.info, ServerInfo.description, sizeof(me.info)); |
| 561 |
|
|
| 562 |
< |
me.from = &me; |
| 563 |
< |
me.servptr = &me; |
| 564 |
< |
me.lasttime = me.since = me.firsttime = CurrentTime; |
| 562 |
> |
me.from = &me; |
| 563 |
> |
me.servptr = &me; |
| 564 |
> |
me.localClient->lasttime = CurrentTime; |
| 565 |
> |
me.localClient->since = CurrentTime; |
| 566 |
> |
me.localClient->firsttime = CurrentTime; |
| 567 |
|
|
| 568 |
|
SetMe(&me); |
| 569 |
|
make_server(&me); |
| 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 |
|
|
| 577 |
+ |
load_kline_database(); |
| 578 |
+ |
load_dline_database(); |
| 579 |
+ |
load_gline_database(); |
| 580 |
+ |
load_xline_database(); |
| 581 |
+ |
load_resv_database(); |
| 582 |
+ |
|
| 583 |
|
if (chdir(MODPATH)) |
| 584 |
|
{ |
| 585 |
< |
ilog(L_CRIT, "Could not load core modules. Terminating!"); |
| 585 |
> |
ilog(LOG_TYPE_IRCD, "Could not load core modules. Terminating!"); |
| 586 |
|
exit(EXIT_FAILURE); |
| 587 |
|
} |
| 588 |
|
|
| 605 |
|
|
| 606 |
|
write_pidfile(pidFileName); |
| 607 |
|
|
| 608 |
< |
ilog(L_NOTICE, "Server Ready"); |
| 608 |
> |
ilog(LOG_TYPE_IRCD, "Server Ready"); |
| 609 |
|
|
| 610 |
|
eventAddIsh("cleanup_glines", cleanup_glines, NULL, CLEANUP_GLINES_TIME); |
| 611 |
|
eventAddIsh("cleanup_tklines", cleanup_tklines, NULL, CLEANUP_TKLINES_TIME); |
| 614 |
|
/* No, 'cause after a restart it would cause all sorts of nick collides */ |
| 615 |
|
eventAddIsh("try_connections", try_connections, NULL, STARTUP_CONNECTIONS_TIME); |
| 616 |
|
|
| 651 |
– |
eventAddIsh("collect_zipstats", collect_zipstats, NULL, ZIPSTATS_TIME); |
| 652 |
– |
|
| 617 |
|
/* Setup the timeout check. I'll shift it later :) -- adrian */ |
| 618 |
|
eventAddIsh("comm_checktimeouts", comm_checktimeouts, NULL, 1); |
| 619 |
|
|
| 620 |
+ |
eventAddIsh("save_all_databases", save_all_databases, NULL, DATABASE_UPDATE_TIMEOUT); |
| 621 |
+ |
|
| 622 |
|
if (ConfigServerHide.links_delay > 0) |
| 623 |
|
eventAddIsh("write_links_file", write_links_file, NULL, ConfigServerHide.links_delay); |
| 624 |
|
else |