1 |
|
/* |
2 |
|
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
3 |
|
* |
4 |
< |
* Copyright (c) 1997-2014 ircd-hybrid development team |
4 |
> |
* Copyright (c) 1997-2015 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 |
15 |
|
* |
16 |
|
* You should have received a copy of the GNU General Public License |
17 |
|
* along with this program; if not, write to the Free Software |
18 |
< |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
18 |
> |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 |
19 |
|
* USA |
20 |
|
*/ |
21 |
|
|
33 |
|
#include "event.h" |
34 |
|
#include "fdlist.h" |
35 |
|
#include "hash.h" |
36 |
+ |
#include "id.h" |
37 |
|
#include "irc_string.h" |
38 |
|
#include "ircd_signal.h" |
38 |
– |
#include "gline.h" |
39 |
|
#include "motd.h" |
40 |
|
#include "conf.h" |
41 |
|
#include "hostmask.h" |
57 |
|
#include "conf_db.h" |
58 |
|
#include "conf_class.h" |
59 |
|
#include "ipcache.h" |
60 |
+ |
#include "isupport.h" |
61 |
|
|
62 |
|
|
63 |
|
#ifdef HAVE_LIBGEOIP |
64 |
|
GeoIP *geoip_ctx; |
65 |
|
#endif |
66 |
|
|
67 |
+ |
struct SetOptions GlobalSetOptions; /* /quote set variables */ |
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 */ |
73 |
< |
struct LocalUser meLocalUser; /* That's also part of me */ |
72 |
> |
struct Connection meConnection; /* That's also part of me */ |
73 |
> |
struct Client me = { .connection = &meConnection }; /* That's me */ |
74 |
|
|
75 |
+ |
char **myargv; |
76 |
|
const char *logFileName = LPATH; |
77 |
|
const char *pidFileName = PPATH; |
78 |
|
|
79 |
< |
char **myargv; |
80 |
< |
|
76 |
< |
int dorehash = 0; |
77 |
< |
int doremotd = 0; |
78 |
< |
|
79 |
< |
/* Set to zero because it should be initialized later using |
80 |
< |
* initialize_server_capabs |
81 |
< |
*/ |
82 |
< |
unsigned int default_server_capabs; |
79 |
> |
unsigned int dorehash; |
80 |
> |
unsigned int doremotd; |
81 |
|
unsigned int splitmode; |
82 |
|
unsigned int splitchecking; |
83 |
|
unsigned int split_users; |
84 |
|
unsigned int split_servers; |
85 |
|
|
88 |
– |
static struct event event_cleanup_glines = |
89 |
– |
{ |
90 |
– |
.name = "cleanup_glines", |
91 |
– |
.handler = cleanup_glines, |
92 |
– |
.when = CLEANUP_GLINES_TIME |
93 |
– |
}; |
94 |
– |
|
86 |
|
static struct event event_cleanup_tklines = |
87 |
|
{ |
88 |
|
.name = "cleanup_tklines", |
155 |
|
{ |
156 |
|
{"configfile", &ConfigGeneral.configfile, |
157 |
|
STRING, "File to use for ircd.conf"}, |
167 |
– |
{"glinefile", &ConfigGeneral.glinefile, |
168 |
– |
STRING, "File to use for gline database"}, |
158 |
|
{"klinefile", &ConfigGeneral.klinefile, |
159 |
|
STRING, "File to use for kline database"}, |
160 |
|
{"dlinefile", &ConfigGeneral.dlinefile, |
212 |
|
{ |
213 |
|
if (listing_client_list.head) |
214 |
|
{ |
215 |
< |
dlink_node *ptr = NULL, *ptr_next = NULL; |
216 |
< |
DLINK_FOREACH_SAFE(ptr, ptr_next, listing_client_list.head) |
217 |
< |
safe_list_channels(ptr->data, 0); |
215 |
> |
dlink_node *node = NULL, *node_next = NULL; |
216 |
> |
DLINK_FOREACH_SAFE(node, node_next, listing_client_list.head) |
217 |
> |
safe_list_channels(node->data, 0); |
218 |
|
} |
219 |
|
|
220 |
|
/* Run pending events */ |
227 |
|
/* Check to see whether we have to rehash the configuration .. */ |
228 |
|
if (dorehash) |
229 |
|
{ |
230 |
< |
rehash(1); |
230 |
> |
conf_rehash(1); |
231 |
|
dorehash = 0; |
232 |
|
} |
233 |
|
|
250 |
|
static void |
251 |
|
initialize_global_set_options(void) |
252 |
|
{ |
253 |
< |
GlobalSetOptions.autoconn = 1; |
253 |
> |
GlobalSetOptions.maxclients = ConfigServerInfo.default_max_clients; |
254 |
> |
GlobalSetOptions.autoconn = 1; |
255 |
|
GlobalSetOptions.spam_time = MIN_JOIN_LEAVE_TIME; |
256 |
< |
GlobalSetOptions.spam_num = MAX_JOIN_LEAVE_COUNT; |
257 |
< |
|
258 |
< |
if (ConfigGeneral.default_floodcount) |
259 |
< |
GlobalSetOptions.floodcount = ConfigGeneral.default_floodcount; |
270 |
< |
else |
271 |
< |
GlobalSetOptions.floodcount = 10; |
272 |
< |
|
273 |
< |
/* XXX I have no idea what to try here - Dianora */ |
274 |
< |
GlobalSetOptions.joinfloodcount = 16; |
275 |
< |
GlobalSetOptions.joinfloodtime = 8; |
256 |
> |
GlobalSetOptions.spam_num = MAX_JOIN_LEAVE_COUNT; |
257 |
> |
GlobalSetOptions.floodcount = ConfigGeneral.default_floodcount; |
258 |
> |
GlobalSetOptions.joinfloodcount = ConfigChannel.default_join_flood_count; |
259 |
> |
GlobalSetOptions.joinfloodtime = ConfigChannel.default_join_flood_time; |
260 |
|
|
261 |
|
split_servers = ConfigChannel.default_split_server_count; |
262 |
|
split_users = ConfigChannel.default_split_user_count; |
279 |
|
static void |
280 |
|
initialize_server_capabs(void) |
281 |
|
{ |
282 |
< |
add_capability("QS", CAP_QS, 1); |
283 |
< |
add_capability("EOB", CAP_EOB, 1); |
284 |
< |
add_capability("TS6", CAP_TS6, 0); |
285 |
< |
add_capability("CLUSTER", CAP_CLUSTER, 1); |
286 |
< |
add_capability("SVS", CAP_SVS, 1); |
287 |
< |
add_capability("CHW", CAP_CHW, 1); |
304 |
< |
add_capability("HOPS", CAP_HOPS, 1); |
282 |
> |
add_capability("QS", CAP_QS); |
283 |
> |
add_capability("EOB", CAP_EOB); |
284 |
> |
add_capability("CLUSTER", CAP_CLUSTER); |
285 |
> |
add_capability("SVS", CAP_SVS); |
286 |
> |
add_capability("CHW", CAP_CHW); |
287 |
> |
add_capability("HOPS", CAP_HOPS); |
288 |
|
} |
289 |
|
|
290 |
|
/* write_pidfile() |
305 |
|
|
306 |
|
snprintf(buff, sizeof(buff), "%u\n", pid); |
307 |
|
|
308 |
< |
if ((fputs(buff, fb) == -1)) |
309 |
< |
ilog(LOG_TYPE_IRCD, "Error writing %u to pid file %s (%s)", |
310 |
< |
pid, filename, strerror(errno)); |
308 |
> |
if (fputs(buff, fb) == -1) |
309 |
> |
ilog(LOG_TYPE_IRCD, "Error writing to pid file %s: %s", |
310 |
> |
filename, strerror(errno)); |
311 |
|
|
312 |
|
fclose(fb); |
313 |
|
} |
314 |
|
else |
315 |
< |
{ |
316 |
< |
ilog(LOG_TYPE_IRCD, "Error opening pid file %s", filename); |
334 |
< |
} |
315 |
> |
ilog(LOG_TYPE_IRCD, "Error opening pid file %s: %s", |
316 |
> |
filename, strerror(errno)); |
317 |
|
} |
318 |
|
|
319 |
|
/* check_pidfile() |
334 |
|
/* Don't do logging here, since we don't have log() initialised */ |
335 |
|
if ((fb = fopen(filename, "r"))) |
336 |
|
{ |
337 |
< |
if (fgets(buff, 20, fb) == NULL) |
337 |
> |
if (!fgets(buff, 20, fb)) |
338 |
|
{ |
339 |
|
/* log(L_ERROR, "Error reading from pid file %s (%s)", filename, |
340 |
|
* strerror(errno)); |
400 |
|
ssl_init(void) |
401 |
|
{ |
402 |
|
#ifdef HAVE_LIBCRYPTO |
421 |
– |
const unsigned char session_id[] = "ircd-hybrid"; |
422 |
– |
|
403 |
|
SSL_load_error_strings(); |
404 |
|
SSLeay_add_ssl_algorithms(); |
405 |
|
|
406 |
< |
if ((ConfigServerInfo.server_ctx = SSL_CTX_new(SSLv23_server_method())) == NULL) |
406 |
> |
if (!(ConfigServerInfo.server_ctx = SSL_CTX_new(SSLv23_server_method()))) |
407 |
|
{ |
408 |
|
const char *s = ERR_lib_error_string(ERR_get_error()); |
409 |
|
|
410 |
|
fprintf(stderr, "ERROR: Could not initialize the SSL Server context -- %s\n", s); |
411 |
< |
ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Server context -- %s\n", s); |
411 |
> |
ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Server context -- %s", s); |
412 |
|
exit(EXIT_FAILURE); |
413 |
+ |
return; /* Not reached */ |
414 |
|
} |
415 |
|
|
416 |
< |
SSL_CTX_set_options(ConfigServerInfo.server_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3); |
417 |
< |
SSL_CTX_set_options(ConfigServerInfo.server_ctx, SSL_OP_SINGLE_DH_USE); |
416 |
> |
SSL_CTX_set_options(ConfigServerInfo.server_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TICKET); |
417 |
> |
SSL_CTX_set_options(ConfigServerInfo.server_ctx, SSL_OP_SINGLE_DH_USE|SSL_OP_CIPHER_SERVER_PREFERENCE); |
418 |
|
SSL_CTX_set_verify(ConfigServerInfo.server_ctx, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE, |
419 |
|
always_accept_verify_cb); |
420 |
< |
SSL_CTX_set_session_id_context(ConfigServerInfo.server_ctx, session_id, sizeof(session_id) - 1); |
420 |
> |
SSL_CTX_set_session_cache_mode(ConfigServerInfo.server_ctx, SSL_SESS_CACHE_OFF); |
421 |
> |
SSL_CTX_set_cipher_list(ConfigServerInfo.server_ctx, "EECDH+HIGH:EDH+HIGH:HIGH:!aNULL"); |
422 |
|
|
423 |
< |
#if OPENSSL_VERSION_NUMBER >= 0x1000005FL && !defined(OPENSSL_NO_ECDH) |
423 |
> |
#if OPENSSL_VERSION_NUMBER >= 0x009080FFL && !defined(OPENSSL_NO_ECDH) |
424 |
|
{ |
425 |
|
EC_KEY *key = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1); |
426 |
|
|
434 |
|
SSL_CTX_set_options(ConfigServerInfo.server_ctx, SSL_OP_SINGLE_ECDH_USE); |
435 |
|
#endif |
436 |
|
|
437 |
< |
if ((ConfigServerInfo.client_ctx = SSL_CTX_new(SSLv23_client_method())) == NULL) |
437 |
> |
if (!(ConfigServerInfo.client_ctx = SSL_CTX_new(SSLv23_client_method()))) |
438 |
|
{ |
439 |
|
const char *s = ERR_lib_error_string(ERR_get_error()); |
440 |
|
|
441 |
|
fprintf(stderr, "ERROR: Could not initialize the SSL Client context -- %s\n", s); |
442 |
< |
ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Client context -- %s\n", s); |
442 |
> |
ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Client context -- %s", s); |
443 |
|
exit(EXIT_FAILURE); |
444 |
+ |
return; /* Not reached */ |
445 |
|
} |
446 |
|
|
447 |
< |
SSL_CTX_set_options(ConfigServerInfo.client_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3); |
447 |
> |
SSL_CTX_set_options(ConfigServerInfo.client_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TICKET); |
448 |
|
SSL_CTX_set_options(ConfigServerInfo.client_ctx, SSL_OP_SINGLE_DH_USE); |
449 |
|
SSL_CTX_set_verify(ConfigServerInfo.client_ctx, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE, |
450 |
|
always_accept_verify_cb); |
451 |
+ |
SSL_CTX_set_session_cache_mode(ConfigServerInfo.client_ctx, SSL_SESS_CACHE_OFF); |
452 |
|
#endif /* HAVE_LIBCRYPTO */ |
453 |
|
} |
454 |
|
|
456 |
|
main(int argc, char *argv[]) |
457 |
|
{ |
458 |
|
/* Check to see if the user is running us as root, which is a nono */ |
459 |
< |
if (geteuid() == 0) |
459 |
> |
if (!geteuid()) |
460 |
|
{ |
461 |
|
fprintf(stderr, "ERROR: This server won't run as root/superuser\n"); |
462 |
|
return -1; |
465 |
|
/* Setup corefile size immediately after boot -kre */ |
466 |
|
setup_corefile(); |
467 |
|
|
468 |
< |
/* save server boot time right away, so getrusage works correctly */ |
468 |
> |
/* Save server boot time right away, so getrusage works correctly */ |
469 |
|
set_time(); |
470 |
|
|
471 |
< |
/* It ain't random, but it ought to be a little harder to guess */ |
471 |
> |
/* It's not random, but it ought to be a little harder to guess */ |
472 |
|
init_genrand(SystemTime.tv_sec ^ (SystemTime.tv_usec | (getpid() << 20))); |
473 |
|
|
474 |
< |
me.localClient = &meLocalUser; |
475 |
< |
dlinkAdd(&me, &me.node, &global_client_list); /* Pointer to beginning |
492 |
< |
of Client list */ |
493 |
< |
ConfigLog.use_logging = 1; |
474 |
> |
dlinkAdd(&me, &me.node, &global_client_list); |
475 |
> |
|
476 |
|
ConfigGeneral.dpath = DPATH; |
477 |
|
ConfigGeneral.spath = SPATH; |
478 |
|
ConfigGeneral.mpath = MPATH; |
479 |
|
ConfigGeneral.configfile = CPATH; /* Server configuration file */ |
480 |
|
ConfigGeneral.klinefile = KPATH; /* Server kline file */ |
499 |
– |
ConfigGeneral.glinefile = GPATH; /* Server gline file */ |
481 |
|
ConfigGeneral.xlinefile = XPATH; /* Server xline file */ |
482 |
|
ConfigGeneral.dlinefile = DLPATH; /* dline file */ |
483 |
|
ConfigGeneral.resvfile = RESVPATH; /* resv file */ |
484 |
|
|
485 |
|
myargv = argv; |
486 |
< |
umask(077); /* better safe than sorry --SRB */ |
486 |
> |
umask(077); /* umask 077: u=rwx,g=,o= */ |
487 |
|
|
488 |
|
parseargs(&argc, &argv, myopts); |
489 |
|
|
522 |
|
|
523 |
|
mp_pool_init(); |
524 |
|
init_dlink_nodes(); |
525 |
< |
init_isupport(); |
525 |
> |
isupport_init(); |
526 |
|
dbuf_init(); |
527 |
|
hash_init(); |
528 |
|
ipcache_init(); |
548 |
– |
init_host_hash(); /* Host-hashtable. */ |
529 |
|
client_init(); |
530 |
|
class_init(); |
531 |
|
whowas_init(); |
534 |
|
init_resolver(); /* Needs to be setup before the io loop */ |
535 |
|
modules_init(); |
536 |
|
read_conf_files(1); /* cold start init conf files */ |
557 |
– |
init_uid(); |
537 |
|
initialize_server_capabs(); /* Set up default_server_capabs */ |
538 |
< |
initialize_global_set_options(); |
538 |
> |
initialize_global_set_options(); /* Has to be called after read_conf_files() */ |
539 |
|
channel_init(); |
540 |
|
read_links_file(); |
541 |
|
motd_init(); |
542 |
+ |
user_modes_init(); |
543 |
|
#ifdef HAVE_LIBGEOIP |
544 |
|
geoip_ctx = GeoIP_new(GEOIP_MEMORY_CACHE); |
545 |
|
#endif |
546 |
|
|
567 |
– |
if (EmptyString(ConfigServerInfo.sid)) |
568 |
– |
{ |
569 |
– |
ilog(LOG_TYPE_IRCD, "ERROR: No server id specified in serverinfo block."); |
570 |
– |
exit(EXIT_FAILURE); |
571 |
– |
} |
572 |
– |
|
573 |
– |
strlcpy(me.id, ConfigServerInfo.sid, sizeof(me.id)); |
574 |
– |
|
547 |
|
if (EmptyString(ConfigServerInfo.name)) |
548 |
|
{ |
549 |
|
ilog(LOG_TYPE_IRCD, "ERROR: No server name specified in serverinfo block."); |
561 |
|
|
562 |
|
strlcpy(me.info, ConfigServerInfo.description, sizeof(me.info)); |
563 |
|
|
564 |
< |
me.from = &me; |
565 |
< |
me.servptr = &me; |
566 |
< |
me.localClient->lasttime = CurrentTime; |
567 |
< |
me.localClient->since = CurrentTime; |
568 |
< |
me.localClient->firsttime = CurrentTime; |
564 |
> |
if (EmptyString(ConfigServerInfo.sid)) |
565 |
> |
{ |
566 |
> |
ilog(LOG_TYPE_IRCD, "Generating server ID"); |
567 |
> |
generate_sid(); |
568 |
> |
} |
569 |
> |
else |
570 |
> |
{ |
571 |
> |
strlcpy(me.id, ConfigServerInfo.sid, sizeof(me.id)); |
572 |
> |
} |
573 |
> |
|
574 |
> |
me.from = &me; |
575 |
> |
me.servptr = &me; |
576 |
> |
me.connection->lasttime = CurrentTime; |
577 |
> |
me.connection->since = CurrentTime; |
578 |
> |
me.connection->firsttime = CurrentTime; |
579 |
|
|
580 |
|
SetMe(&me); |
581 |
|
make_server(&me); |
585 |
|
|
586 |
|
dlinkAdd(&me, make_dlink_node(), &global_server_list); |
587 |
|
|
588 |
+ |
init_uid(); |
589 |
+ |
|
590 |
|
load_kline_database(); |
591 |
|
load_dline_database(); |
608 |
– |
load_gline_database(); |
592 |
|
load_xline_database(); |
593 |
|
load_resv_database(); |
594 |
|
|
612 |
– |
if (chdir(MODPATH)) |
613 |
– |
{ |
614 |
– |
ilog(LOG_TYPE_IRCD, "Could not load core modules. Terminating!"); |
615 |
– |
exit(EXIT_FAILURE); |
616 |
– |
} |
617 |
– |
|
595 |
|
load_all_modules(1); |
596 |
|
load_conf_modules(); |
597 |
|
load_core_modules(1); |
598 |
|
|
622 |
– |
/* Go back to DPATH after checking to see if we can chdir to MODPATH */ |
623 |
– |
if (chdir(ConfigGeneral.dpath)) |
624 |
– |
{ |
625 |
– |
perror("chdir"); |
626 |
– |
exit(EXIT_FAILURE); |
627 |
– |
} |
628 |
– |
|
629 |
– |
/* |
630 |
– |
* assemble_umode_buffer() has to be called after |
631 |
– |
* reading conf/loading modules. |
632 |
– |
*/ |
633 |
– |
assemble_umode_buffer(); |
634 |
– |
|
599 |
|
write_pidfile(pidFileName); |
600 |
|
|
601 |
|
ilog(LOG_TYPE_IRCD, "Server Ready"); |
602 |
|
|
639 |
– |
event_addish(&event_cleanup_glines, NULL); |
603 |
|
event_addish(&event_cleanup_tklines, NULL); |
604 |
|
|
605 |
|
/* We want try_connections to be called as soon as possible now! -- adrian */ |