| 36 |
|
#include "ircd_signal.h" |
| 37 |
|
#include "s_gline.h" |
| 38 |
|
#include "motd.h" |
| 39 |
+ |
#include "conf.h" |
| 40 |
|
#include "hostmask.h" |
| 41 |
|
#include "numeric.h" |
| 42 |
|
#include "packet.h" |
| 46 |
|
#include "rng_mt.h" |
| 47 |
|
#include "s_auth.h" |
| 48 |
|
#include "s_bsd.h" |
| 49 |
< |
#include "s_conf.h" |
| 49 |
< |
#include "s_log.h" |
| 49 |
> |
#include "log.h" |
| 50 |
|
#include "s_misc.h" |
| 51 |
|
#include "s_serv.h" /* try_connections */ |
| 52 |
|
#include "send.h" |
| 53 |
|
#include "whowas.h" |
| 54 |
|
#include "modules.h" |
| 55 |
|
#include "memory.h" |
| 56 |
+ |
#include "mempool.h" |
| 57 |
|
#include "hook.h" |
| 58 |
|
#include "ircd_getopt.h" |
| 58 |
– |
#include "balloc.h" |
| 59 |
|
#include "motd.h" |
| 60 |
|
#include "supported.h" |
| 61 |
|
#include "watch.h" |
| 62 |
< |
|
| 62 |
> |
#include "conf_db.h" |
| 63 |
> |
#include "conf_class.h" |
| 64 |
|
|
| 65 |
|
/* /quote set variables */ |
| 66 |
|
struct SetOptions GlobalSetOptions; |
| 73 |
|
struct admin_info AdminInfo = { NULL, NULL, NULL }; |
| 74 |
|
struct Counter Count = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; |
| 75 |
|
struct ServerState_t server_state = { 0 }; |
| 76 |
< |
struct logging_entry ConfigLoggingEntry = { 1, 1 }; |
| 76 |
> |
struct logging_entry ConfigLoggingEntry = { .use_logging = 1 }; |
| 77 |
|
struct ServerStatistics ServerStats; |
| 78 |
|
struct timeval SystemTime; |
| 79 |
|
struct Client me; /* That's me */ |
| 83 |
|
const char *pidFileName = PPATH; |
| 84 |
|
|
| 85 |
|
char **myargv; |
| 85 |
– |
char ircd_platform[PLATFORMLEN]; |
| 86 |
|
|
| 87 |
|
int dorehash = 0; |
| 88 |
|
int doremotd = 0; |
| 91 |
|
* initialize_server_capabs |
| 92 |
|
*/ |
| 93 |
|
int default_server_capabs = 0; |
| 94 |
– |
|
| 95 |
– |
#ifdef HAVE_LIBCRYPTO |
| 96 |
– |
int bio_spare_fd = -1; |
| 97 |
– |
#endif |
| 98 |
– |
|
| 94 |
|
unsigned int splitmode; |
| 95 |
|
unsigned int splitchecking; |
| 96 |
|
unsigned int split_users; |
| 142 |
|
|
| 143 |
|
static int printVersion = 0; |
| 144 |
|
|
| 145 |
< |
struct lgetopt myopts[] = { |
| 151 |
< |
{"dlinefile", &ConfigFileEntry.dlinefile, |
| 152 |
< |
STRING, "File to use for dline.conf"}, |
| 145 |
> |
static struct lgetopt myopts[] = { |
| 146 |
|
{"configfile", &ConfigFileEntry.configfile, |
| 147 |
|
STRING, "File to use for ircd.conf"}, |
| 148 |
+ |
{"glinefile", &ConfigFileEntry.glinefile, |
| 149 |
+ |
STRING, "File to use for gline database"}, |
| 150 |
|
{"klinefile", &ConfigFileEntry.klinefile, |
| 151 |
< |
STRING, "File to use for kline.conf"}, |
| 151 |
> |
STRING, "File to use for kline database"}, |
| 152 |
> |
{"dlinefile", &ConfigFileEntry.dlinefile, |
| 153 |
> |
STRING, "File to use for dline database"}, |
| 154 |
|
{"xlinefile", &ConfigFileEntry.xlinefile, |
| 155 |
< |
STRING, "File to use for xline.conf"}, |
| 155 |
> |
STRING, "File to use for xline database"}, |
| 156 |
> |
{"resvfile", &ConfigFileEntry.resvfile, |
| 157 |
> |
STRING, "File to use for resv database"}, |
| 158 |
|
{"logfile", &logFileName, |
| 159 |
|
STRING, "File to use for ircd.log"}, |
| 160 |
|
{"pidfile", &pidFileName, |
| 179 |
|
{ |
| 180 |
|
ilog(LOG_TYPE_IRCD, "Clock Failure (%s), TS can be corrupted", |
| 181 |
|
strerror(errno)); |
| 182 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, |
| 182 |
> |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
| 183 |
|
"Clock Failure (%s), TS can be corrupted", |
| 184 |
|
strerror(errno)); |
| 185 |
|
restart("Clock Failure"); |
| 248 |
|
if (doremotd) |
| 249 |
|
{ |
| 250 |
|
read_message_file(&ConfigFileEntry.motd); |
| 251 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, |
| 251 |
> |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
| 252 |
|
"Got signal SIGUSR1, reloading ircd motd file"); |
| 253 |
|
doremotd = 0; |
| 254 |
|
} |
| 303 |
|
initialize_message_files(void) |
| 304 |
|
{ |
| 305 |
|
init_message_file(USER_MOTD, MPATH, &ConfigFileEntry.motd); |
| 307 |
– |
init_message_file(OPER_MOTD, OPATH, &ConfigFileEntry.opermotd); |
| 306 |
|
init_message_file(USER_LINKS, LIPATH, &ConfigFileEntry.linksfile); |
| 307 |
|
|
| 308 |
|
read_message_file(&ConfigFileEntry.motd); |
| 311 |
– |
read_message_file(&ConfigFileEntry.opermotd); |
| 309 |
|
read_message_file(&ConfigFileEntry.linksfile); |
| 310 |
|
|
| 311 |
|
init_isupport(); |
| 338 |
|
static void |
| 339 |
|
write_pidfile(const char *filename) |
| 340 |
|
{ |
| 341 |
< |
FBFILE *fb; |
| 341 |
> |
FILE *fb; |
| 342 |
|
|
| 343 |
< |
if ((fb = fbopen(filename, "w"))) |
| 343 |
> |
if ((fb = fopen(filename, "w"))) |
| 344 |
|
{ |
| 345 |
|
char buff[32]; |
| 346 |
|
unsigned int pid = (unsigned int)getpid(); |
| 350 |
– |
size_t nbytes = snprintf(buff, sizeof(buff), "%u\n", pid); |
| 347 |
|
|
| 348 |
< |
if ((fbputs(buff, fb, nbytes) == -1)) |
| 348 |
> |
snprintf(buff, sizeof(buff), "%u\n", pid); |
| 349 |
> |
|
| 350 |
> |
if ((fputs(buff, fb) == -1)) |
| 351 |
|
ilog(LOG_TYPE_IRCD, "Error writing %u to pid file %s (%s)", |
| 352 |
|
pid, filename, strerror(errno)); |
| 353 |
|
|
| 354 |
< |
fbclose(fb); |
| 357 |
< |
return; |
| 354 |
> |
fclose(fb); |
| 355 |
|
} |
| 356 |
|
else |
| 357 |
|
{ |
| 370 |
|
static void |
| 371 |
|
check_pidfile(const char *filename) |
| 372 |
|
{ |
| 373 |
< |
FBFILE *fb; |
| 373 |
> |
FILE *fb; |
| 374 |
|
char buff[32]; |
| 375 |
|
pid_t pidfromfile; |
| 376 |
|
|
| 377 |
|
/* Don't do logging here, since we don't have log() initialised */ |
| 378 |
< |
if ((fb = fbopen(filename, "r"))) |
| 378 |
> |
if ((fb = fopen(filename, "r"))) |
| 379 |
|
{ |
| 380 |
< |
if (fbgets(buff, 20, fb) == NULL) |
| 380 |
> |
if (fgets(buff, 20, fb) == NULL) |
| 381 |
|
{ |
| 382 |
|
/* log(L_ERROR, "Error reading from pid file %s (%s)", filename, |
| 383 |
|
* strerror(errno)); |
| 395 |
|
} |
| 396 |
|
} |
| 397 |
|
|
| 398 |
< |
fbclose(fb); |
| 398 |
> |
fclose(fb); |
| 399 |
|
} |
| 400 |
|
else if (errno != ENOENT) |
| 401 |
|
{ |
| 432 |
|
* side effects - setups SSL context. |
| 433 |
|
*/ |
| 434 |
|
static void |
| 435 |
< |
init_ssl(void) |
| 435 |
> |
ssl_init(void) |
| 436 |
|
{ |
| 437 |
|
#ifdef HAVE_LIBCRYPTO |
| 438 |
|
SSL_load_error_strings(); |
| 442 |
|
{ |
| 443 |
|
const char *s; |
| 444 |
|
|
| 445 |
< |
fprintf(stderr, "ERROR: Could not initialize the SSL context -- %s\n", |
| 445 |
> |
fprintf(stderr, "ERROR: Could not initialize the SSL Server context -- %s\n", |
| 446 |
|
s = ERR_lib_error_string(ERR_get_error())); |
| 447 |
< |
ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL context -- %s\n", s); |
| 447 |
> |
ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Server context -- %s\n", s); |
| 448 |
|
} |
| 449 |
|
|
| 450 |
< |
SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_NO_SSLv2); |
| 450 |
> |
SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TLSv1); |
| 451 |
|
SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_TLS_ROLLBACK_BUG|SSL_OP_ALL); |
| 452 |
|
SSL_CTX_set_verify(ServerInfo.server_ctx, SSL_VERIFY_NONE, NULL); |
| 453 |
|
|
| 454 |
< |
bio_spare_fd = save_spare_fd("SSL private key validation"); |
| 455 |
< |
#endif /* HAVE_LIBCRYPTO */ |
| 456 |
< |
} |
| 454 |
> |
if ((ServerInfo.client_ctx = SSL_CTX_new(SSLv23_client_method())) == NULL) |
| 455 |
> |
{ |
| 456 |
> |
const char *s; |
| 457 |
|
|
| 458 |
< |
/* init_callbacks() |
| 459 |
< |
* |
| 460 |
< |
* inputs - nothing |
| 461 |
< |
* output - nothing |
| 462 |
< |
* side effects - setups standard hook points |
| 463 |
< |
*/ |
| 464 |
< |
static void |
| 465 |
< |
init_callbacks(void) |
| 466 |
< |
{ |
| 470 |
< |
iorecv_cb = register_callback("iorecv", iorecv_default); |
| 471 |
< |
iosend_cb = register_callback("iosend", iosend_default); |
| 458 |
> |
fprintf(stderr, "ERROR: Could not initialize the SSL Client context -- %s\n", |
| 459 |
> |
s = ERR_lib_error_string(ERR_get_error())); |
| 460 |
> |
ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Client context -- %s\n", s); |
| 461 |
> |
} |
| 462 |
> |
|
| 463 |
> |
SSL_CTX_set_options(ServerInfo.client_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TLSv1); |
| 464 |
> |
SSL_CTX_set_options(ServerInfo.client_ctx, SSL_OP_TLS_ROLLBACK_BUG|SSL_OP_ALL); |
| 465 |
> |
SSL_CTX_set_verify(ServerInfo.client_ctx, SSL_VERIFY_NONE, NULL); |
| 466 |
> |
#endif /* HAVE_LIBCRYPTO */ |
| 467 |
|
} |
| 468 |
|
|
| 469 |
|
int |
| 494 |
|
init_chcap_usage_counts(); |
| 495 |
|
|
| 496 |
|
ConfigFileEntry.dpath = DPATH; |
| 497 |
< |
ConfigFileEntry.configfile = CPATH; /* Server configuration file */ |
| 498 |
< |
ConfigFileEntry.klinefile = KPATH; /* Server kline file */ |
| 499 |
< |
ConfigFileEntry.xlinefile = XPATH; /* Server xline file */ |
| 500 |
< |
ConfigFileEntry.rxlinefile = RXPATH; /* Server regex xline file */ |
| 501 |
< |
ConfigFileEntry.rklinefile = RKPATH; /* Server regex kline file */ |
| 502 |
< |
ConfigFileEntry.dlinefile = DLPATH; /* dline file */ |
| 503 |
< |
ConfigFileEntry.glinefile = GPATH; /* gline log file */ |
| 509 |
< |
ConfigFileEntry.cresvfile = CRESVPATH; /* channel resv file */ |
| 510 |
< |
ConfigFileEntry.nresvfile = NRESVPATH; /* nick resv file */ |
| 497 |
> |
ConfigFileEntry.configfile = CPATH; /* Server configuration file */ |
| 498 |
> |
ConfigFileEntry.klinefile = KPATH; /* Server kline file */ |
| 499 |
> |
ConfigFileEntry.glinefile = GPATH; /* Server gline file */ |
| 500 |
> |
ConfigFileEntry.xlinefile = XPATH; /* Server xline file */ |
| 501 |
> |
ConfigFileEntry.dlinefile = DLPATH; /* dline file */ |
| 502 |
> |
ConfigFileEntry.resvfile = RESVPATH; /* resv file */ |
| 503 |
> |
|
| 504 |
|
myargv = argv; |
| 505 |
|
umask(077); /* better safe than sorry --SRB */ |
| 506 |
|
|
| 518 |
|
exit(EXIT_FAILURE); |
| 519 |
|
} |
| 520 |
|
|
| 521 |
< |
init_ssl(); |
| 521 |
> |
ssl_init(); |
| 522 |
|
|
| 523 |
|
if (!server_state.foreground) |
| 524 |
|
{ |
| 530 |
|
|
| 531 |
|
setup_signals(); |
| 532 |
|
|
| 540 |
– |
get_ircd_platform(ircd_platform); |
| 541 |
– |
|
| 533 |
|
/* Init the event subsystem */ |
| 534 |
|
eventInit(); |
| 535 |
|
/* We need this to initialise the fd array before anything else */ |
| 536 |
|
fdlist_init(); |
| 537 |
< |
log_add_file(LOG_TYPE_IRCD, 0, logFileName); |
| 537 |
> |
log_set_file(LOG_TYPE_IRCD, 0, logFileName); |
| 538 |
|
check_can_use_v6(); |
| 539 |
|
init_comm(); /* This needs to be setup early ! -- adrian */ |
| 540 |
|
/* Check if there is pidfile and daemon already running */ |
| 541 |
|
check_pidfile(pidFileName); |
| 542 |
|
|
| 543 |
< |
initBlockHeap(); |
| 543 |
> |
mp_pool_init(); |
| 544 |
|
init_dlink_nodes(); |
| 554 |
– |
init_callbacks(); |
| 545 |
|
initialize_message_files(); |
| 546 |
|
dbuf_init(); |
| 547 |
< |
init_hash(); |
| 547 |
> |
hash_init(); |
| 548 |
|
init_ip_hash_table(); /* client host ip hash table */ |
| 549 |
|
init_host_hash(); /* Host-hashtable. */ |
| 550 |
< |
clear_tree_parse(); |
| 551 |
< |
init_client(); |
| 552 |
< |
init_class(); |
| 563 |
< |
init_whowas(); |
| 550 |
> |
client_init(); |
| 551 |
> |
class_init(); |
| 552 |
> |
whowas_init(); |
| 553 |
|
watch_init(); |
| 554 |
< |
init_auth(); /* Initialise the auth code */ |
| 554 |
> |
auth_init(); /* Initialise the auth code */ |
| 555 |
|
init_resolver(); /* Needs to be setup before the io loop */ |
| 556 |
+ |
modules_init(); |
| 557 |
|
read_conf_files(1); /* cold start init conf files */ |
| 558 |
|
init_uid(); |
| 559 |
|
initialize_server_capabs(); /* Set up default_server_capabs */ |
| 560 |
|
initialize_global_set_options(); |
| 561 |
< |
init_channels(); |
| 561 |
> |
channel_init(); |
| 562 |
|
|
| 563 |
|
if (EmptyString(ServerInfo.sid)) |
| 564 |
|
{ |
| 600 |
|
/* add ourselves to global_serv_list */ |
| 601 |
|
dlinkAdd(&me, make_dlink_node(), &global_serv_list); |
| 602 |
|
|
| 603 |
+ |
load_kline_database(); |
| 604 |
+ |
load_dline_database(); |
| 605 |
+ |
load_gline_database(); |
| 606 |
+ |
load_xline_database(); |
| 607 |
+ |
load_resv_database(); |
| 608 |
+ |
|
| 609 |
|
if (chdir(MODPATH)) |
| 610 |
|
{ |
| 611 |
|
ilog(LOG_TYPE_IRCD, "Could not load core modules. Terminating!"); |
| 643 |
|
/* Setup the timeout check. I'll shift it later :) -- adrian */ |
| 644 |
|
eventAddIsh("comm_checktimeouts", comm_checktimeouts, NULL, 1); |
| 645 |
|
|
| 646 |
+ |
eventAddIsh("save_all_databases", save_all_databases, NULL, DATABASE_UPDATE_TIMEOUT); |
| 647 |
+ |
|
| 648 |
|
if (ConfigServerHide.links_delay > 0) |
| 649 |
|
eventAddIsh("write_links_file", write_links_file, NULL, ConfigServerHide.links_delay); |
| 650 |
|
else |