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" |
48 |
– |
#include "conf.h" |
49 |
|
#include "log.h" |
50 |
|
#include "s_misc.h" |
51 |
|
#include "s_serv.h" /* try_connections */ |
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" |
59 |
|
#include "supported.h" |
60 |
|
#include "watch.h" |
61 |
+ |
#include "conf_db.h" |
62 |
+ |
#include "conf_class.h" |
63 |
|
|
64 |
|
|
65 |
+ |
#ifdef HAVE_LIBGEOIP |
66 |
+ |
GeoIP *geoip_ctx; |
67 |
+ |
#endif |
68 |
+ |
|
69 |
|
/* /quote set variables */ |
70 |
|
struct SetOptions GlobalSetOptions; |
71 |
< |
|
72 |
< |
/* configuration set from ircd.conf */ |
68 |
< |
struct config_file_entry ConfigFileEntry; |
69 |
< |
/* server info set from ircd.conf */ |
70 |
< |
struct server_info ServerInfo; |
71 |
< |
/* admin info set from ircd.conf */ |
72 |
< |
struct admin_info AdminInfo = { NULL, NULL, NULL }; |
73 |
< |
struct Counter Count = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; |
74 |
< |
struct ServerState_t server_state = { 0 }; |
75 |
< |
struct logging_entry ConfigLoggingEntry = { .use_logging = 1 }; |
71 |
> |
struct Counter Count; |
72 |
> |
struct ServerState_t server_state; |
73 |
|
struct ServerStatistics ServerStats; |
74 |
|
struct timeval SystemTime; |
75 |
|
struct Client me; /* That's me */ |
79 |
|
const char *pidFileName = PPATH; |
80 |
|
|
81 |
|
char **myargv; |
85 |
– |
char ircd_platform[PLATFORMLEN]; |
82 |
|
|
83 |
|
int dorehash = 0; |
84 |
|
int doremotd = 0; |
111 |
|
static void |
112 |
|
print_startup(int pid) |
113 |
|
{ |
114 |
< |
printf("ircd: version %s\n", ircd_version); |
114 |
> |
printf("ircd: version %s(%s)\n", ircd_version, serno); |
115 |
|
printf("ircd: pid %d\n", pid); |
116 |
|
printf("ircd: running in %s mode from %s\n", !server_state.foreground ? "background" |
117 |
|
: "foreground", ConfigFileEntry.dpath); |
138 |
|
|
139 |
|
static int printVersion = 0; |
140 |
|
|
141 |
< |
struct lgetopt myopts[] = { |
146 |
< |
{"dlinefile", &ConfigFileEntry.dlinefile, |
147 |
< |
STRING, "File to use for dline.conf"}, |
141 |
> |
static struct lgetopt myopts[] = { |
142 |
|
{"configfile", &ConfigFileEntry.configfile, |
143 |
|
STRING, "File to use for ircd.conf"}, |
144 |
+ |
{"glinefile", &ConfigFileEntry.glinefile, |
145 |
+ |
STRING, "File to use for gline database"}, |
146 |
|
{"klinefile", &ConfigFileEntry.klinefile, |
147 |
< |
STRING, "File to use for kline.conf"}, |
147 |
> |
STRING, "File to use for kline database"}, |
148 |
> |
{"dlinefile", &ConfigFileEntry.dlinefile, |
149 |
> |
STRING, "File to use for dline database"}, |
150 |
|
{"xlinefile", &ConfigFileEntry.xlinefile, |
151 |
< |
STRING, "File to use for xline.conf"}, |
151 |
> |
STRING, "File to use for xline database"}, |
152 |
> |
{"resvfile", &ConfigFileEntry.resvfile, |
153 |
> |
STRING, "File to use for resv database"}, |
154 |
|
{"logfile", &logFileName, |
155 |
|
STRING, "File to use for ircd.log"}, |
156 |
|
{"pidfile", &pidFileName, |
166 |
|
void |
167 |
|
set_time(void) |
168 |
|
{ |
169 |
< |
static char to_send[200]; |
169 |
> |
static char to_send[IRCD_BUFSIZE]; |
170 |
|
struct timeval newtime; |
171 |
|
newtime.tv_sec = 0; |
172 |
|
newtime.tv_usec = 0; |
175 |
|
{ |
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"); |
233 |
|
comm_select(); |
234 |
|
exit_aborted_clients(); |
235 |
|
free_exited_clients(); |
236 |
– |
send_queued_all(); |
236 |
|
|
237 |
|
/* Check to see whether we have to rehash the configuration .. */ |
238 |
|
if (dorehash) |
242 |
|
} |
243 |
|
if (doremotd) |
244 |
|
{ |
245 |
< |
read_message_file(&ConfigFileEntry.motd); |
246 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, |
247 |
< |
"Got signal SIGUSR1, reloading ircd motd file"); |
245 |
> |
motd_recache(); |
246 |
> |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
247 |
> |
"Got signal SIGUSR1, reloading motd files"); |
248 |
|
doremotd = 0; |
249 |
|
} |
250 |
|
} |
288 |
|
/* End of global set options */ |
289 |
|
} |
290 |
|
|
292 |
– |
/* initialize_message_files() |
293 |
– |
* |
294 |
– |
* inputs - none |
295 |
– |
* output - none |
296 |
– |
* side effects - Set up all message files needed, motd etc. |
297 |
– |
*/ |
298 |
– |
static void |
299 |
– |
initialize_message_files(void) |
300 |
– |
{ |
301 |
– |
init_message_file(USER_MOTD, MPATH, &ConfigFileEntry.motd); |
302 |
– |
init_message_file(OPER_MOTD, OPATH, &ConfigFileEntry.opermotd); |
303 |
– |
init_message_file(USER_LINKS, LIPATH, &ConfigFileEntry.linksfile); |
304 |
– |
|
305 |
– |
read_message_file(&ConfigFileEntry.motd); |
306 |
– |
read_message_file(&ConfigFileEntry.opermotd); |
307 |
– |
read_message_file(&ConfigFileEntry.linksfile); |
308 |
– |
|
309 |
– |
init_isupport(); |
310 |
– |
} |
311 |
– |
|
291 |
|
/* initialize_server_capabs() |
292 |
|
* |
293 |
|
* inputs - none |
300 |
|
add_capability("EOB", CAP_EOB, 1); |
301 |
|
add_capability("TS6", CAP_TS6, 0); |
302 |
|
add_capability("CLUSTER", CAP_CLUSTER, 1); |
303 |
+ |
// add_capability("FAKEHOST", CAP_FAKEHOST, 1); |
304 |
|
add_capability("SVS", CAP_SVS, 1); |
305 |
|
#ifdef HALFOPS |
306 |
|
add_capability("HOPS", CAP_HOPS, 1); |
320 |
|
|
321 |
|
if ((fb = fopen(filename, "w"))) |
322 |
|
{ |
323 |
< |
char buff[32]; |
323 |
> |
char buff[IRCD_BUFSIZE]; |
324 |
|
unsigned int pid = (unsigned int)getpid(); |
325 |
|
|
326 |
|
snprintf(buff, sizeof(buff), "%u\n", pid); |
349 |
|
check_pidfile(const char *filename) |
350 |
|
{ |
351 |
|
FILE *fb; |
352 |
< |
char buff[32]; |
352 |
> |
char buff[IRCD_BUFSIZE]; |
353 |
|
pid_t pidfromfile; |
354 |
|
|
355 |
|
/* Don't do logging here, since we don't have log() initialised */ |
403 |
|
#endif |
404 |
|
} |
405 |
|
|
406 |
+ |
#ifdef HAVE_LIBCRYPTO |
407 |
+ |
static int |
408 |
+ |
always_accept_verify_cb(int preverify_ok, X509_STORE_CTX *x509_ctx) |
409 |
+ |
{ |
410 |
+ |
return 1; |
411 |
+ |
} |
412 |
+ |
#endif |
413 |
+ |
|
414 |
|
/* init_ssl() |
415 |
|
* |
416 |
|
* inputs - nothing |
418 |
|
* side effects - setups SSL context. |
419 |
|
*/ |
420 |
|
static void |
421 |
< |
init_ssl(void) |
421 |
> |
ssl_init(void) |
422 |
|
{ |
423 |
|
#ifdef HAVE_LIBCRYPTO |
424 |
|
SSL_load_error_strings(); |
435 |
|
|
436 |
|
SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TLSv1); |
437 |
|
SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_TLS_ROLLBACK_BUG|SSL_OP_ALL); |
438 |
< |
SSL_CTX_set_verify(ServerInfo.server_ctx, SSL_VERIFY_NONE, NULL); |
438 |
> |
SSL_CTX_set_verify(ServerInfo.server_ctx, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE, |
439 |
> |
always_accept_verify_cb); |
440 |
|
|
441 |
|
if ((ServerInfo.client_ctx = SSL_CTX_new(SSLv23_client_method())) == NULL) |
442 |
|
{ |
449 |
|
|
450 |
|
SSL_CTX_set_options(ServerInfo.client_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TLSv1); |
451 |
|
SSL_CTX_set_options(ServerInfo.client_ctx, SSL_OP_TLS_ROLLBACK_BUG|SSL_OP_ALL); |
452 |
< |
SSL_CTX_set_verify(ServerInfo.client_ctx, SSL_VERIFY_NONE, NULL); |
452 |
> |
SSL_CTX_set_verify(ServerInfo.client_ctx, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE, |
453 |
> |
always_accept_verify_cb); |
454 |
|
#endif /* HAVE_LIBCRYPTO */ |
455 |
|
} |
456 |
|
|
467 |
– |
/* init_callbacks() |
468 |
– |
* |
469 |
– |
* inputs - nothing |
470 |
– |
* output - nothing |
471 |
– |
* side effects - setups standard hook points |
472 |
– |
*/ |
473 |
– |
static void |
474 |
– |
init_callbacks(void) |
475 |
– |
{ |
476 |
– |
iorecv_cb = register_callback("iorecv", iorecv_default); |
477 |
– |
iosend_cb = register_callback("iosend", iosend_default); |
478 |
– |
} |
479 |
– |
|
457 |
|
int |
458 |
|
main(int argc, char *argv[]) |
459 |
|
{ |
460 |
< |
/* Check to see if the user is running |
484 |
< |
* us as root, which is a nono |
485 |
< |
*/ |
460 |
> |
/* Check to see if the user is running us as root, which is a nono */ |
461 |
|
if (geteuid() == 0) |
462 |
|
{ |
463 |
|
fprintf(stderr, "Don't run ircd as root!!!\n"); |
474 |
|
init_genrand(SystemTime.tv_sec ^ (SystemTime.tv_usec | (getpid() << 20))); |
475 |
|
|
476 |
|
me.localClient = &meLocalUser; |
477 |
< |
dlinkAdd(&me, &me.node, &global_client_list); /* Pointer to beginning |
477 |
> |
dlinkAdd(&me, &me.node, &global_client_list); /* Pointer to beginning |
478 |
|
of Client list */ |
479 |
|
/* Initialise the channel capability usage counts... */ |
480 |
|
init_chcap_usage_counts(); |
481 |
|
|
482 |
|
ConfigFileEntry.dpath = DPATH; |
483 |
< |
ConfigFileEntry.configfile = CPATH; /* Server configuration file */ |
484 |
< |
ConfigFileEntry.klinefile = KPATH; /* Server kline file */ |
485 |
< |
ConfigFileEntry.xlinefile = XPATH; /* Server xline file */ |
486 |
< |
ConfigFileEntry.rxlinefile = RXPATH; /* Server regex xline file */ |
487 |
< |
ConfigFileEntry.rklinefile = RKPATH; /* Server regex kline file */ |
488 |
< |
ConfigFileEntry.dlinefile = DLPATH; /* dline file */ |
489 |
< |
ConfigFileEntry.glinefile = GPATH; /* gline log file */ |
515 |
< |
ConfigFileEntry.cresvfile = CRESVPATH; /* channel resv file */ |
516 |
< |
ConfigFileEntry.nresvfile = NRESVPATH; /* nick resv file */ |
483 |
> |
ConfigFileEntry.configfile = CPATH; /* Server configuration file */ |
484 |
> |
ConfigFileEntry.klinefile = KPATH; /* Server kline file */ |
485 |
> |
ConfigFileEntry.glinefile = GPATH; /* Server gline file */ |
486 |
> |
ConfigFileEntry.xlinefile = XPATH; /* Server xline file */ |
487 |
> |
ConfigFileEntry.dlinefile = DLPATH; /* dline file */ |
488 |
> |
ConfigFileEntry.resvfile = RESVPATH; /* resv file */ |
489 |
> |
|
490 |
|
myargv = argv; |
491 |
|
umask(077); /* better safe than sorry --SRB */ |
492 |
|
|
494 |
|
|
495 |
|
if (printVersion) |
496 |
|
{ |
497 |
< |
printf("ircd: version %s\n", ircd_version); |
497 |
> |
printf("ircd: version %s(%s)\n", ircd_version, serno); |
498 |
|
exit(EXIT_SUCCESS); |
499 |
|
} |
500 |
|
|
504 |
|
exit(EXIT_FAILURE); |
505 |
|
} |
506 |
|
|
507 |
< |
init_ssl(); |
507 |
> |
ssl_init(); |
508 |
|
|
509 |
|
if (!server_state.foreground) |
510 |
|
{ |
516 |
|
|
517 |
|
setup_signals(); |
518 |
|
|
546 |
– |
get_ircd_platform(ircd_platform); |
547 |
– |
|
519 |
|
/* Init the event subsystem */ |
520 |
|
eventInit(); |
521 |
+ |
|
522 |
|
/* We need this to initialise the fd array before anything else */ |
523 |
|
fdlist_init(); |
524 |
< |
log_add_file(LOG_TYPE_IRCD, 0, logFileName); |
524 |
> |
log_set_file(LOG_TYPE_IRCD, 0, logFileName); |
525 |
|
check_can_use_v6(); |
526 |
< |
init_comm(); /* This needs to be setup early ! -- adrian */ |
526 |
> |
init_netio(); /* This needs to be setup early ! -- adrian */ |
527 |
> |
|
528 |
|
/* Check if there is pidfile and daemon already running */ |
529 |
|
check_pidfile(pidFileName); |
530 |
|
|
531 |
< |
initBlockHeap(); |
531 |
> |
mp_pool_init(); |
532 |
|
init_dlink_nodes(); |
533 |
< |
init_callbacks(); |
561 |
< |
initialize_message_files(); |
533 |
> |
init_isupport(); |
534 |
|
dbuf_init(); |
535 |
< |
init_hash(); |
535 |
> |
hash_init(); |
536 |
|
init_ip_hash_table(); /* client host ip hash table */ |
537 |
|
init_host_hash(); /* Host-hashtable. */ |
538 |
< |
clear_tree_parse(); |
539 |
< |
init_client(); |
540 |
< |
init_class(); |
569 |
< |
init_whowas(); |
538 |
> |
client_init(); |
539 |
> |
class_init(); |
540 |
> |
whowas_init(); |
541 |
|
watch_init(); |
542 |
< |
init_auth(); /* Initialise the auth code */ |
542 |
> |
auth_init(); /* Initialise the auth code */ |
543 |
|
init_resolver(); /* Needs to be setup before the io loop */ |
544 |
+ |
modules_init(); |
545 |
|
read_conf_files(1); /* cold start init conf files */ |
546 |
|
init_uid(); |
547 |
|
initialize_server_capabs(); /* Set up default_server_capabs */ |
548 |
|
initialize_global_set_options(); |
549 |
< |
init_channels(); |
549 |
> |
channel_init(); |
550 |
> |
read_links_file(); |
551 |
> |
motd_init(); |
552 |
> |
#ifdef HAVE_LIBGEOIP |
553 |
> |
geoip_ctx = GeoIP_new(GEOIP_MEMORY_CACHE); |
554 |
> |
#endif |
555 |
|
|
556 |
|
if (EmptyString(ServerInfo.sid)) |
557 |
|
{ |
593 |
|
/* add ourselves to global_serv_list */ |
594 |
|
dlinkAdd(&me, make_dlink_node(), &global_serv_list); |
595 |
|
|
596 |
+ |
load_kline_database(); |
597 |
+ |
load_dline_database(); |
598 |
+ |
load_gline_database(); |
599 |
+ |
load_xline_database(); |
600 |
+ |
load_resv_database(); |
601 |
+ |
|
602 |
|
if (chdir(MODPATH)) |
603 |
|
{ |
604 |
|
ilog(LOG_TYPE_IRCD, "Could not load core modules. Terminating!"); |
636 |
|
/* Setup the timeout check. I'll shift it later :) -- adrian */ |
637 |
|
eventAddIsh("comm_checktimeouts", comm_checktimeouts, NULL, 1); |
638 |
|
|
639 |
+ |
eventAddIsh("save_all_databases", save_all_databases, NULL, DATABASE_UPDATE_TIMEOUT); |
640 |
+ |
|
641 |
|
if (ConfigServerHide.links_delay > 0) |
642 |
|
eventAddIsh("write_links_file", write_links_file, NULL, ConfigServerHide.links_delay); |
643 |
|
else |