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" |
35 |
|
#include "irc_string.h" |
37 |
– |
#include "sprintf_irc.h" |
36 |
|
#include "ircd_signal.h" |
37 |
|
#include "s_gline.h" |
38 |
|
#include "motd.h" |
41 |
– |
#include "ircd_handler.h" |
42 |
– |
#include "msg.h" /* msgtab */ |
39 |
|
#include "hostmask.h" |
40 |
|
#include "numeric.h" |
41 |
|
#include "packet.h" |
45 |
|
#include "rng_mt.h" |
46 |
|
#include "s_auth.h" |
47 |
|
#include "s_bsd.h" |
48 |
< |
#include "s_conf.h" |
49 |
< |
#include "s_log.h" |
48 |
> |
#include "conf.h" |
49 |
> |
#include "log.h" |
50 |
|
#include "s_misc.h" |
51 |
|
#include "s_serv.h" /* try_connections */ |
52 |
|
#include "send.h" |
60 |
|
#include "supported.h" |
61 |
|
#include "watch.h" |
62 |
|
|
67 |
– |
/* Try and find the correct name to use with getrlimit() for setting the max. |
68 |
– |
* number of files allowed to be open by this process. |
69 |
– |
*/ |
63 |
|
|
64 |
|
/* /quote set variables */ |
65 |
|
struct SetOptions GlobalSetOptions; |
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 }; |
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 = { 1, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0} }; |
75 |
> |
struct logging_entry ConfigLoggingEntry = { .use_logging = 1 }; |
76 |
|
struct ServerStatistics ServerStats; |
77 |
|
struct timeval SystemTime; |
78 |
|
struct Client me; /* That's me */ |
82 |
|
const char *pidFileName = PPATH; |
83 |
|
|
84 |
|
char **myargv; |
92 |
– |
char ircd_platform[PLATFORMLEN]; |
85 |
|
|
86 |
|
int dorehash = 0; |
87 |
|
int doremotd = 0; |
90 |
|
* initialize_server_capabs |
91 |
|
*/ |
92 |
|
int default_server_capabs = 0; |
101 |
– |
|
102 |
– |
#ifdef HAVE_LIBCRYPTO |
103 |
– |
int bio_spare_fd = -1; |
104 |
– |
#endif |
105 |
– |
|
93 |
|
unsigned int splitmode; |
94 |
|
unsigned int splitchecking; |
95 |
|
unsigned int split_users; |
141 |
|
|
142 |
|
static int printVersion = 0; |
143 |
|
|
144 |
< |
struct lgetopt myopts[] = { |
144 |
> |
static struct lgetopt myopts[] = { |
145 |
|
{"dlinefile", &ConfigFileEntry.dlinefile, |
146 |
|
STRING, "File to use for dline.conf"}, |
147 |
|
{"configfile", &ConfigFileEntry.configfile, |
172 |
|
|
173 |
|
if (gettimeofday(&newtime, NULL) == -1) |
174 |
|
{ |
175 |
< |
ilog(L_ERROR, "Clock Failure (%s), TS can be corrupted", |
175 |
> |
ilog(LOG_TYPE_IRCD, "Clock Failure (%s), TS can be corrupted", |
176 |
|
strerror(errno)); |
177 |
|
sendto_realops_flags(UMODE_ALL, L_ALL, |
178 |
|
"Clock Failure (%s), TS can be corrupted", |
182 |
|
|
183 |
|
if (newtime.tv_sec < CurrentTime) |
184 |
|
{ |
185 |
< |
ircsprintf(to_send, "System clock is running backwards - (%lu < %lu)", |
186 |
< |
(unsigned long)newtime.tv_sec, (unsigned long)CurrentTime); |
185 |
> |
snprintf(to_send, sizeof(to_send), |
186 |
> |
"System clock is running backwards - (%lu < %lu)", |
187 |
> |
(unsigned long)newtime.tv_sec, (unsigned long)CurrentTime); |
188 |
|
report_error(L_ALL, to_send, me.name, 0); |
189 |
|
set_back_events(CurrentTime - newtime.tv_sec); |
190 |
|
} |
285 |
|
} |
286 |
|
|
287 |
|
GlobalSetOptions.ident_timeout = IDENT_TIMEOUT; |
300 |
– |
GlobalSetOptions.idletime = ConfigFileEntry.idletime; |
288 |
|
/* End of global set options */ |
289 |
|
} |
290 |
|
|
319 |
|
add_capability("QS", CAP_QS, 1); |
320 |
|
add_capability("EOB", CAP_EOB, 1); |
321 |
|
add_capability("TS6", CAP_TS6, 0); |
335 |
– |
add_capability("ZIP", CAP_ZIP, 0); |
322 |
|
add_capability("CLUSTER", CAP_CLUSTER, 1); |
323 |
+ |
add_capability("SVS", CAP_SVS, 1); |
324 |
|
#ifdef HALFOPS |
325 |
|
add_capability("HOPS", CAP_HOPS, 1); |
326 |
|
#endif |
335 |
|
static void |
336 |
|
write_pidfile(const char *filename) |
337 |
|
{ |
338 |
< |
FBFILE *fb; |
338 |
> |
FILE *fb; |
339 |
|
|
340 |
< |
if ((fb = fbopen(filename, "w"))) |
340 |
> |
if ((fb = fopen(filename, "w"))) |
341 |
|
{ |
342 |
|
char buff[32]; |
343 |
|
unsigned int pid = (unsigned int)getpid(); |
357 |
– |
size_t nbytes = ircsprintf(buff, "%u\n", pid); |
344 |
|
|
345 |
< |
if ((fbputs(buff, fb, nbytes) == -1)) |
346 |
< |
ilog(L_ERROR, "Error writing %u to pid file %s (%s)", |
345 |
> |
snprintf(buff, sizeof(buff), "%u\n", pid); |
346 |
> |
|
347 |
> |
if ((fputs(buff, fb) == -1)) |
348 |
> |
ilog(LOG_TYPE_IRCD, "Error writing %u to pid file %s (%s)", |
349 |
|
pid, filename, strerror(errno)); |
350 |
|
|
351 |
< |
fbclose(fb); |
364 |
< |
return; |
351 |
> |
fclose(fb); |
352 |
|
} |
353 |
|
else |
354 |
|
{ |
355 |
< |
ilog(L_ERROR, "Error opening pid file %s", filename); |
355 |
> |
ilog(LOG_TYPE_IRCD, "Error opening pid file %s", filename); |
356 |
|
} |
357 |
|
} |
358 |
|
|
367 |
|
static void |
368 |
|
check_pidfile(const char *filename) |
369 |
|
{ |
370 |
< |
FBFILE *fb; |
370 |
> |
FILE *fb; |
371 |
|
char buff[32]; |
372 |
|
pid_t pidfromfile; |
373 |
|
|
374 |
|
/* Don't do logging here, since we don't have log() initialised */ |
375 |
< |
if ((fb = fbopen(filename, "r"))) |
375 |
> |
if ((fb = fopen(filename, "r"))) |
376 |
|
{ |
377 |
< |
if (fbgets(buff, 20, fb) == NULL) |
377 |
> |
if (fgets(buff, 20, fb) == NULL) |
378 |
|
{ |
379 |
|
/* log(L_ERROR, "Error reading from pid file %s (%s)", filename, |
380 |
|
* strerror(errno)); |
392 |
|
} |
393 |
|
} |
394 |
|
|
395 |
< |
fbclose(fb); |
395 |
> |
fclose(fb); |
396 |
|
} |
397 |
|
else if (errno != ENOENT) |
398 |
|
{ |
439 |
|
{ |
440 |
|
const char *s; |
441 |
|
|
442 |
< |
fprintf(stderr, "ERROR: Could not initialize the SSL context -- %s\n", |
442 |
> |
fprintf(stderr, "ERROR: Could not initialize the SSL Server context -- %s\n", |
443 |
|
s = ERR_lib_error_string(ERR_get_error())); |
444 |
< |
ilog(L_CRIT, "ERROR: Could not initialize the SSL context -- %s\n", s); |
444 |
> |
ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Server context -- %s\n", s); |
445 |
|
} |
446 |
|
|
447 |
< |
SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_NO_SSLv2); |
447 |
> |
SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TLSv1); |
448 |
|
SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_TLS_ROLLBACK_BUG|SSL_OP_ALL); |
449 |
|
SSL_CTX_set_verify(ServerInfo.server_ctx, SSL_VERIFY_NONE, NULL); |
450 |
|
|
451 |
< |
bio_spare_fd = save_spare_fd("SSL private key validation"); |
451 |
> |
if ((ServerInfo.client_ctx = SSL_CTX_new(SSLv23_client_method())) == NULL) |
452 |
> |
{ |
453 |
> |
const char *s; |
454 |
> |
|
455 |
> |
fprintf(stderr, "ERROR: Could not initialize the SSL Client context -- %s\n", |
456 |
> |
s = ERR_lib_error_string(ERR_get_error())); |
457 |
> |
ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Client context -- %s\n", s); |
458 |
> |
} |
459 |
> |
|
460 |
> |
SSL_CTX_set_options(ServerInfo.client_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TLSv1); |
461 |
> |
SSL_CTX_set_options(ServerInfo.client_ctx, SSL_OP_TLS_ROLLBACK_BUG|SSL_OP_ALL); |
462 |
> |
SSL_CTX_set_verify(ServerInfo.client_ctx, SSL_VERIFY_NONE, NULL); |
463 |
|
#endif /* HAVE_LIBCRYPTO */ |
464 |
|
} |
465 |
|
|
474 |
|
{ |
475 |
|
iorecv_cb = register_callback("iorecv", iorecv_default); |
476 |
|
iosend_cb = register_callback("iosend", iosend_default); |
479 |
– |
iorecvctrl_cb = register_callback("iorecvctrl", NULL); |
480 |
– |
iosendctrl_cb = register_callback("iosendctrl", NULL); |
477 |
|
} |
478 |
|
|
479 |
|
int |
497 |
|
/* It ain't random, but it ought to be a little harder to guess */ |
498 |
|
init_genrand(SystemTime.tv_sec ^ (SystemTime.tv_usec | (getpid() << 20))); |
499 |
|
|
504 |
– |
memset(&me, 0, sizeof(me)); |
505 |
– |
memset(&meLocalUser, 0, sizeof(meLocalUser)); |
500 |
|
me.localClient = &meLocalUser; |
501 |
|
dlinkAdd(&me, &me.node, &global_client_list); /* Pointer to beginning |
502 |
|
of Client list */ |
509 |
– |
|
510 |
– |
memset(&ServerInfo, 0, sizeof(ServerInfo)); |
511 |
– |
memset(&ServerStats, 0, sizeof(ServerStats)); |
512 |
– |
|
503 |
|
/* Initialise the channel capability usage counts... */ |
504 |
|
init_chcap_usage_counts(); |
505 |
|
|
542 |
|
|
543 |
|
setup_signals(); |
544 |
|
|
555 |
– |
get_ircd_platform(ircd_platform); |
556 |
– |
|
545 |
|
/* Init the event subsystem */ |
546 |
|
eventInit(); |
547 |
|
/* We need this to initialise the fd array before anything else */ |
548 |
|
fdlist_init(); |
549 |
< |
init_log(logFileName); |
549 |
> |
log_add_file(LOG_TYPE_IRCD, 0, logFileName); |
550 |
|
check_can_use_v6(); |
551 |
|
init_comm(); /* This needs to be setup early ! -- adrian */ |
552 |
|
/* Check if there is pidfile and daemon already running */ |
560 |
|
init_hash(); |
561 |
|
init_ip_hash_table(); /* client host ip hash table */ |
562 |
|
init_host_hash(); /* Host-hashtable. */ |
575 |
– |
clear_tree_parse(); |
563 |
|
init_client(); |
564 |
|
init_class(); |
565 |
< |
init_whowas(); |
565 |
> |
whowas_init(); |
566 |
|
watch_init(); |
567 |
|
init_auth(); /* Initialise the auth code */ |
568 |
|
init_resolver(); /* Needs to be setup before the io loop */ |
574 |
|
|
575 |
|
if (EmptyString(ServerInfo.sid)) |
576 |
|
{ |
577 |
< |
ilog(L_CRIT, "ERROR: No server id specified in serverinfo block."); |
577 |
> |
ilog(LOG_TYPE_IRCD, "ERROR: No server id specified in serverinfo block."); |
578 |
|
exit(EXIT_FAILURE); |
579 |
|
} |
580 |
|
|
582 |
|
|
583 |
|
if (EmptyString(ServerInfo.name)) |
584 |
|
{ |
585 |
< |
ilog(L_CRIT, "ERROR: No server name specified in serverinfo block."); |
585 |
> |
ilog(LOG_TYPE_IRCD, "ERROR: No server name specified in serverinfo block."); |
586 |
|
exit(EXIT_FAILURE); |
587 |
|
} |
588 |
|
|
591 |
|
/* serverinfo{} description must exist. If not, error out.*/ |
592 |
|
if (EmptyString(ServerInfo.description)) |
593 |
|
{ |
594 |
< |
ilog(L_CRIT, "ERROR: No server description specified in serverinfo block."); |
594 |
> |
ilog(LOG_TYPE_IRCD, "ERROR: No server description specified in serverinfo block."); |
595 |
|
exit(EXIT_FAILURE); |
596 |
|
} |
597 |
|
|
598 |
|
strlcpy(me.info, ServerInfo.description, sizeof(me.info)); |
599 |
|
|
600 |
< |
me.from = &me; |
601 |
< |
me.servptr = &me; |
600 |
> |
me.from = &me; |
601 |
> |
me.servptr = &me; |
602 |
> |
me.localClient->lasttime = CurrentTime; |
603 |
> |
me.localClient->since = CurrentTime; |
604 |
> |
me.localClient->firsttime = CurrentTime; |
605 |
|
|
606 |
|
SetMe(&me); |
607 |
|
make_server(&me); |
608 |
|
|
619 |
– |
me.lasttime = me.since = me.firsttime = CurrentTime; |
620 |
– |
|
609 |
|
hash_add_id(&me); |
610 |
|
hash_add_client(&me); |
611 |
|
|
614 |
|
|
615 |
|
if (chdir(MODPATH)) |
616 |
|
{ |
617 |
< |
ilog(L_CRIT, "Could not load core modules. Terminating!"); |
617 |
> |
ilog(LOG_TYPE_IRCD, "Could not load core modules. Terminating!"); |
618 |
|
exit(EXIT_FAILURE); |
619 |
|
} |
620 |
|
|
637 |
|
|
638 |
|
write_pidfile(pidFileName); |
639 |
|
|
640 |
< |
ilog(L_NOTICE, "Server Ready"); |
640 |
> |
ilog(LOG_TYPE_IRCD, "Server Ready"); |
641 |
|
|
642 |
|
eventAddIsh("cleanup_glines", cleanup_glines, NULL, CLEANUP_GLINES_TIME); |
643 |
|
eventAddIsh("cleanup_tklines", cleanup_tklines, NULL, CLEANUP_TKLINES_TIME); |
646 |
|
/* No, 'cause after a restart it would cause all sorts of nick collides */ |
647 |
|
eventAddIsh("try_connections", try_connections, NULL, STARTUP_CONNECTIONS_TIME); |
648 |
|
|
661 |
– |
eventAddIsh("collect_zipstats", collect_zipstats, NULL, ZIPSTATS_TIME); |
662 |
– |
|
649 |
|
/* Setup the timeout check. I'll shift it later :) -- adrian */ |
650 |
|
eventAddIsh("comm_checktimeouts", comm_checktimeouts, NULL, 1); |
651 |
|
|