29 |
|
#include "channel.h" |
30 |
|
#include "channel_mode.h" |
31 |
|
#include "client.h" |
32 |
– |
#include "common.h" |
32 |
|
#include "event.h" |
33 |
|
#include "fdlist.h" |
34 |
|
#include "hash.h" |
36 |
|
#include "ircd_signal.h" |
37 |
|
#include "s_gline.h" |
38 |
|
#include "motd.h" |
39 |
< |
#include "ircd_handler.h" |
41 |
< |
#include "msg.h" /* msgtab */ |
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" |
52 |
< |
#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" |
61 |
– |
#include "balloc.h" |
59 |
|
#include "motd.h" |
60 |
|
#include "supported.h" |
61 |
|
#include "watch.h" |
62 |
< |
|
63 |
< |
/* Try and find the correct name to use with getrlimit() for setting the max. |
67 |
< |
* number of files allowed to be open by this process. |
68 |
< |
*/ |
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, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0} }; |
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; |
91 |
– |
char ircd_platform[PLATFORMLEN]; |
86 |
|
|
87 |
|
int dorehash = 0; |
88 |
|
int doremotd = 0; |
91 |
|
* initialize_server_capabs |
92 |
|
*/ |
93 |
|
int default_server_capabs = 0; |
100 |
– |
|
101 |
– |
#ifdef HAVE_LIBCRYPTO |
102 |
– |
int bio_spare_fd = -1; |
103 |
– |
#endif |
104 |
– |
|
94 |
|
unsigned int splitmode; |
95 |
|
unsigned int splitchecking; |
96 |
|
unsigned int split_users; |
142 |
|
|
143 |
|
static int printVersion = 0; |
144 |
|
|
145 |
< |
struct lgetopt myopts[] = { |
145 |
> |
static struct lgetopt myopts[] = { |
146 |
|
{"dlinefile", &ConfigFileEntry.dlinefile, |
147 |
|
STRING, "File to use for dline.conf"}, |
148 |
|
{"configfile", &ConfigFileEntry.configfile, |
173 |
|
|
174 |
|
if (gettimeofday(&newtime, NULL) == -1) |
175 |
|
{ |
176 |
< |
ilog(L_ERROR, "Clock Failure (%s), TS can be corrupted", |
176 |
> |
ilog(LOG_TYPE_IRCD, "Clock Failure (%s), TS can be corrupted", |
177 |
|
strerror(errno)); |
178 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, |
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"); |
244 |
|
if (doremotd) |
245 |
|
{ |
246 |
|
read_message_file(&ConfigFileEntry.motd); |
247 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, |
247 |
> |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
248 |
|
"Got signal SIGUSR1, reloading ircd motd file"); |
249 |
|
doremotd = 0; |
250 |
|
} |
286 |
|
} |
287 |
|
|
288 |
|
GlobalSetOptions.ident_timeout = IDENT_TIMEOUT; |
300 |
– |
GlobalSetOptions.idletime = ConfigFileEntry.idletime; |
289 |
|
/* End of global set options */ |
290 |
|
} |
291 |
|
|
299 |
|
initialize_message_files(void) |
300 |
|
{ |
301 |
|
init_message_file(USER_MOTD, MPATH, &ConfigFileEntry.motd); |
314 |
– |
init_message_file(OPER_MOTD, OPATH, &ConfigFileEntry.opermotd); |
302 |
|
init_message_file(USER_LINKS, LIPATH, &ConfigFileEntry.linksfile); |
303 |
|
|
304 |
|
read_message_file(&ConfigFileEntry.motd); |
318 |
– |
read_message_file(&ConfigFileEntry.opermotd); |
305 |
|
read_message_file(&ConfigFileEntry.linksfile); |
306 |
|
|
307 |
|
init_isupport(); |
318 |
|
add_capability("QS", CAP_QS, 1); |
319 |
|
add_capability("EOB", CAP_EOB, 1); |
320 |
|
add_capability("TS6", CAP_TS6, 0); |
335 |
– |
add_capability("ZIP", CAP_ZIP, 0); |
321 |
|
add_capability("CLUSTER", CAP_CLUSTER, 1); |
322 |
+ |
add_capability("SVS", CAP_SVS, 1); |
323 |
|
#ifdef HALFOPS |
324 |
|
add_capability("HOPS", CAP_HOPS, 1); |
325 |
|
#endif |
334 |
|
static void |
335 |
|
write_pidfile(const char *filename) |
336 |
|
{ |
337 |
< |
FBFILE *fb; |
337 |
> |
FILE *fb; |
338 |
|
|
339 |
< |
if ((fb = fbopen(filename, "w"))) |
339 |
> |
if ((fb = fopen(filename, "w"))) |
340 |
|
{ |
341 |
|
char buff[32]; |
342 |
|
unsigned int pid = (unsigned int)getpid(); |
357 |
– |
size_t nbytes = snprintf(buff, sizeof(buff), "%u\n", pid); |
343 |
|
|
344 |
< |
if ((fbputs(buff, fb, nbytes) == -1)) |
345 |
< |
ilog(L_ERROR, "Error writing %u to pid file %s (%s)", |
344 |
> |
snprintf(buff, sizeof(buff), "%u\n", pid); |
345 |
> |
|
346 |
> |
if ((fputs(buff, fb) == -1)) |
347 |
> |
ilog(LOG_TYPE_IRCD, "Error writing %u to pid file %s (%s)", |
348 |
|
pid, filename, strerror(errno)); |
349 |
|
|
350 |
< |
fbclose(fb); |
364 |
< |
return; |
350 |
> |
fclose(fb); |
351 |
|
} |
352 |
|
else |
353 |
|
{ |
354 |
< |
ilog(L_ERROR, "Error opening pid file %s", filename); |
354 |
> |
ilog(LOG_TYPE_IRCD, "Error opening pid file %s", filename); |
355 |
|
} |
356 |
|
} |
357 |
|
|
366 |
|
static void |
367 |
|
check_pidfile(const char *filename) |
368 |
|
{ |
369 |
< |
FBFILE *fb; |
369 |
> |
FILE *fb; |
370 |
|
char buff[32]; |
371 |
|
pid_t pidfromfile; |
372 |
|
|
373 |
|
/* Don't do logging here, since we don't have log() initialised */ |
374 |
< |
if ((fb = fbopen(filename, "r"))) |
374 |
> |
if ((fb = fopen(filename, "r"))) |
375 |
|
{ |
376 |
< |
if (fbgets(buff, 20, fb) == NULL) |
376 |
> |
if (fgets(buff, 20, fb) == NULL) |
377 |
|
{ |
378 |
|
/* log(L_ERROR, "Error reading from pid file %s (%s)", filename, |
379 |
|
* strerror(errno)); |
391 |
|
} |
392 |
|
} |
393 |
|
|
394 |
< |
fbclose(fb); |
394 |
> |
fclose(fb); |
395 |
|
} |
396 |
|
else if (errno != ENOENT) |
397 |
|
{ |
438 |
|
{ |
439 |
|
const char *s; |
440 |
|
|
441 |
< |
fprintf(stderr, "ERROR: Could not initialize the SSL context -- %s\n", |
441 |
> |
fprintf(stderr, "ERROR: Could not initialize the SSL Server context -- %s\n", |
442 |
|
s = ERR_lib_error_string(ERR_get_error())); |
443 |
< |
ilog(L_CRIT, "ERROR: Could not initialize the SSL context -- %s\n", s); |
443 |
> |
ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Server context -- %s\n", s); |
444 |
|
} |
445 |
|
|
446 |
< |
SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_NO_SSLv2); |
446 |
> |
SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TLSv1); |
447 |
|
SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_TLS_ROLLBACK_BUG|SSL_OP_ALL); |
448 |
|
SSL_CTX_set_verify(ServerInfo.server_ctx, SSL_VERIFY_NONE, NULL); |
449 |
|
|
450 |
< |
bio_spare_fd = save_spare_fd("SSL private key validation"); |
450 |
> |
if ((ServerInfo.client_ctx = SSL_CTX_new(SSLv23_client_method())) == NULL) |
451 |
> |
{ |
452 |
> |
const char *s; |
453 |
> |
|
454 |
> |
fprintf(stderr, "ERROR: Could not initialize the SSL Client context -- %s\n", |
455 |
> |
s = ERR_lib_error_string(ERR_get_error())); |
456 |
> |
ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Client context -- %s\n", s); |
457 |
> |
} |
458 |
> |
|
459 |
> |
SSL_CTX_set_options(ServerInfo.client_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TLSv1); |
460 |
> |
SSL_CTX_set_options(ServerInfo.client_ctx, SSL_OP_TLS_ROLLBACK_BUG|SSL_OP_ALL); |
461 |
> |
SSL_CTX_set_verify(ServerInfo.client_ctx, SSL_VERIFY_NONE, NULL); |
462 |
|
#endif /* HAVE_LIBCRYPTO */ |
463 |
|
} |
464 |
|
|
473 |
|
{ |
474 |
|
iorecv_cb = register_callback("iorecv", iorecv_default); |
475 |
|
iosend_cb = register_callback("iosend", iosend_default); |
479 |
– |
iorecvctrl_cb = register_callback("iorecvctrl", NULL); |
480 |
– |
iosendctrl_cb = register_callback("iosendctrl", NULL); |
476 |
|
} |
477 |
|
|
478 |
|
int |
503 |
|
init_chcap_usage_counts(); |
504 |
|
|
505 |
|
ConfigFileEntry.dpath = DPATH; |
506 |
< |
ConfigFileEntry.configfile = CPATH; /* Server configuration file */ |
507 |
< |
ConfigFileEntry.klinefile = KPATH; /* Server kline file */ |
508 |
< |
ConfigFileEntry.xlinefile = XPATH; /* Server xline file */ |
509 |
< |
ConfigFileEntry.rxlinefile = RXPATH; /* Server regex xline file */ |
510 |
< |
ConfigFileEntry.rklinefile = RKPATH; /* Server regex kline file */ |
511 |
< |
ConfigFileEntry.dlinefile = DLPATH; /* dline file */ |
512 |
< |
ConfigFileEntry.glinefile = GPATH; /* gline log file */ |
518 |
< |
ConfigFileEntry.cresvfile = CRESVPATH; /* channel resv file */ |
519 |
< |
ConfigFileEntry.nresvfile = NRESVPATH; /* nick resv file */ |
506 |
> |
ConfigFileEntry.configfile = CPATH; /* Server configuration file */ |
507 |
> |
ConfigFileEntry.klinefile = KPATH; /* Server kline file */ |
508 |
> |
ConfigFileEntry.klinefile = GPATH; /* Server gline file */ |
509 |
> |
ConfigFileEntry.xlinefile = XPATH; /* Server xline file */ |
510 |
> |
ConfigFileEntry.dlinefile = DLPATH; /* dline file */ |
511 |
> |
ConfigFileEntry.resvfile = RESVPATH; /* resv file */ |
512 |
> |
|
513 |
|
myargv = argv; |
514 |
|
umask(077); /* better safe than sorry --SRB */ |
515 |
|
|
539 |
|
|
540 |
|
setup_signals(); |
541 |
|
|
549 |
– |
get_ircd_platform(ircd_platform); |
550 |
– |
|
542 |
|
/* Init the event subsystem */ |
543 |
|
eventInit(); |
544 |
|
/* We need this to initialise the fd array before anything else */ |
545 |
|
fdlist_init(); |
546 |
< |
init_log(logFileName); |
546 |
> |
log_add_file(LOG_TYPE_IRCD, 0, logFileName); |
547 |
|
check_can_use_v6(); |
548 |
|
init_comm(); /* This needs to be setup early ! -- adrian */ |
549 |
|
/* Check if there is pidfile and daemon already running */ |
550 |
|
check_pidfile(pidFileName); |
551 |
|
|
552 |
< |
initBlockHeap(); |
552 |
> |
mp_pool_init(); |
553 |
|
init_dlink_nodes(); |
554 |
|
init_callbacks(); |
555 |
|
initialize_message_files(); |
557 |
|
init_hash(); |
558 |
|
init_ip_hash_table(); /* client host ip hash table */ |
559 |
|
init_host_hash(); /* Host-hashtable. */ |
569 |
– |
clear_tree_parse(); |
560 |
|
init_client(); |
561 |
< |
init_class(); |
562 |
< |
init_whowas(); |
561 |
> |
class_init(); |
562 |
> |
whowas_init(); |
563 |
|
watch_init(); |
564 |
|
init_auth(); /* Initialise the auth code */ |
565 |
|
init_resolver(); /* Needs to be setup before the io loop */ |
566 |
+ |
modules_init(); |
567 |
|
read_conf_files(1); /* cold start init conf files */ |
568 |
|
init_uid(); |
569 |
|
initialize_server_capabs(); /* Set up default_server_capabs */ |
572 |
|
|
573 |
|
if (EmptyString(ServerInfo.sid)) |
574 |
|
{ |
575 |
< |
ilog(L_CRIT, "ERROR: No server id specified in serverinfo block."); |
575 |
> |
ilog(LOG_TYPE_IRCD, "ERROR: No server id specified in serverinfo block."); |
576 |
|
exit(EXIT_FAILURE); |
577 |
|
} |
578 |
|
|
580 |
|
|
581 |
|
if (EmptyString(ServerInfo.name)) |
582 |
|
{ |
583 |
< |
ilog(L_CRIT, "ERROR: No server name specified in serverinfo block."); |
583 |
> |
ilog(LOG_TYPE_IRCD, "ERROR: No server name specified in serverinfo block."); |
584 |
|
exit(EXIT_FAILURE); |
585 |
|
} |
586 |
|
|
589 |
|
/* serverinfo{} description must exist. If not, error out.*/ |
590 |
|
if (EmptyString(ServerInfo.description)) |
591 |
|
{ |
592 |
< |
ilog(L_CRIT, "ERROR: No server description specified in serverinfo block."); |
592 |
> |
ilog(LOG_TYPE_IRCD, "ERROR: No server description specified in serverinfo block."); |
593 |
|
exit(EXIT_FAILURE); |
594 |
|
} |
595 |
|
|
596 |
|
strlcpy(me.info, ServerInfo.description, sizeof(me.info)); |
597 |
|
|
598 |
< |
me.from = &me; |
599 |
< |
me.servptr = &me; |
600 |
< |
me.lasttime = me.since = me.firsttime = CurrentTime; |
598 |
> |
me.from = &me; |
599 |
> |
me.servptr = &me; |
600 |
> |
me.localClient->lasttime = CurrentTime; |
601 |
> |
me.localClient->since = CurrentTime; |
602 |
> |
me.localClient->firsttime = CurrentTime; |
603 |
|
|
604 |
|
SetMe(&me); |
605 |
|
make_server(&me); |
610 |
|
/* add ourselves to global_serv_list */ |
611 |
|
dlinkAdd(&me, make_dlink_node(), &global_serv_list); |
612 |
|
|
613 |
+ |
load_kline_database(); |
614 |
+ |
load_dline_database(); |
615 |
+ |
load_gline_database(); |
616 |
+ |
load_xline_database(); |
617 |
+ |
load_resv_database(); |
618 |
+ |
|
619 |
|
if (chdir(MODPATH)) |
620 |
|
{ |
621 |
< |
ilog(L_CRIT, "Could not load core modules. Terminating!"); |
621 |
> |
ilog(LOG_TYPE_IRCD, "Could not load core modules. Terminating!"); |
622 |
|
exit(EXIT_FAILURE); |
623 |
|
} |
624 |
|
|
641 |
|
|
642 |
|
write_pidfile(pidFileName); |
643 |
|
|
644 |
< |
ilog(L_NOTICE, "Server Ready"); |
644 |
> |
ilog(LOG_TYPE_IRCD, "Server Ready"); |
645 |
|
|
646 |
|
eventAddIsh("cleanup_glines", cleanup_glines, NULL, CLEANUP_GLINES_TIME); |
647 |
|
eventAddIsh("cleanup_tklines", cleanup_tklines, NULL, CLEANUP_TKLINES_TIME); |
650 |
|
/* No, 'cause after a restart it would cause all sorts of nick collides */ |
651 |
|
eventAddIsh("try_connections", try_connections, NULL, STARTUP_CONNECTIONS_TIME); |
652 |
|
|
654 |
– |
eventAddIsh("collect_zipstats", collect_zipstats, NULL, ZIPSTATS_TIME); |
655 |
– |
|
653 |
|
/* Setup the timeout check. I'll shift it later :) -- adrian */ |
654 |
|
eventAddIsh("comm_checktimeouts", comm_checktimeouts, NULL, 1); |
655 |
|
|
656 |
+ |
eventAddIsh("save_all_databases", save_all_databases, NULL, DATABASE_UPDATE_TIMEOUT); |
657 |
+ |
|
658 |
|
if (ConfigServerHide.links_delay > 0) |
659 |
|
eventAddIsh("write_links_file", write_links_file, NULL, ConfigServerHide.links_delay); |
660 |
|
else |