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 |
|
|
56 |
|
#include "watch.h" |
57 |
|
#include "conf_db.h" |
58 |
|
#include "conf_class.h" |
59 |
+ |
#include "ipcache.h" |
60 |
|
|
61 |
|
|
62 |
|
#ifdef HAVE_LIBGEOIP |
63 |
|
GeoIP *geoip_ctx; |
64 |
|
#endif |
65 |
|
|
65 |
– |
struct ServerStatistics ServerStats; |
66 |
|
struct timeval SystemTime; |
67 |
< |
struct Client me; /* That's me */ |
68 |
< |
struct LocalUser meLocalUser; /* That's also part of me */ |
67 |
> |
struct Connection meConnection; /* That's also part of me */ |
68 |
> |
struct Client me = { .connection = &meConnection }; /* That's me */ |
69 |
|
|
70 |
+ |
char **myargv; |
71 |
|
const char *logFileName = LPATH; |
72 |
|
const char *pidFileName = PPATH; |
73 |
|
|
74 |
< |
char **myargv; |
75 |
< |
|
75 |
< |
int dorehash = 0; |
76 |
< |
int doremotd = 0; |
77 |
< |
|
78 |
< |
/* Set to zero because it should be initialized later using |
79 |
< |
* initialize_server_capabs |
80 |
< |
*/ |
74 |
> |
unsigned int dorehash; |
75 |
> |
unsigned int doremotd; |
76 |
|
unsigned int default_server_capabs; |
77 |
|
unsigned int splitmode; |
78 |
|
unsigned int splitchecking; |
130 |
|
printf("ircd: version %s(%s)\n", ircd_version, serno); |
131 |
|
printf("ircd: pid %d\n", pid); |
132 |
|
printf("ircd: running in %s mode from %s\n", !server_state.foreground ? "background" |
133 |
< |
: "foreground", ConfigFileEntry.dpath); |
133 |
> |
: "foreground", ConfigGeneral.dpath); |
134 |
|
} |
135 |
|
|
136 |
|
static void |
156 |
|
|
157 |
|
static struct lgetopt myopts[] = |
158 |
|
{ |
159 |
< |
{"configfile", &ConfigFileEntry.configfile, |
159 |
> |
{"configfile", &ConfigGeneral.configfile, |
160 |
|
STRING, "File to use for ircd.conf"}, |
161 |
< |
{"glinefile", &ConfigFileEntry.glinefile, |
161 |
> |
{"glinefile", &ConfigGeneral.glinefile, |
162 |
|
STRING, "File to use for gline database"}, |
163 |
< |
{"klinefile", &ConfigFileEntry.klinefile, |
163 |
> |
{"klinefile", &ConfigGeneral.klinefile, |
164 |
|
STRING, "File to use for kline database"}, |
165 |
< |
{"dlinefile", &ConfigFileEntry.dlinefile, |
165 |
> |
{"dlinefile", &ConfigGeneral.dlinefile, |
166 |
|
STRING, "File to use for dline database"}, |
167 |
< |
{"xlinefile", &ConfigFileEntry.xlinefile, |
167 |
> |
{"xlinefile", &ConfigGeneral.xlinefile, |
168 |
|
STRING, "File to use for xline database"}, |
169 |
< |
{"resvfile", &ConfigFileEntry.resvfile, |
169 |
> |
{"resvfile", &ConfigGeneral.resvfile, |
170 |
|
STRING, "File to use for resv database"}, |
171 |
|
{"logfile", &logFileName, |
172 |
|
STRING, "File to use for ircd.log"}, |
217 |
|
{ |
218 |
|
if (listing_client_list.head) |
219 |
|
{ |
220 |
< |
dlink_node *ptr = NULL, *ptr_next = NULL; |
221 |
< |
DLINK_FOREACH_SAFE(ptr, ptr_next, listing_client_list.head) |
222 |
< |
safe_list_channels(ptr->data, 0); |
220 |
> |
dlink_node *node = NULL, *node_next = NULL; |
221 |
> |
DLINK_FOREACH_SAFE(node, node_next, listing_client_list.head) |
222 |
> |
safe_list_channels(node->data, 0); |
223 |
|
} |
224 |
|
|
225 |
|
/* Run pending events */ |
232 |
|
/* Check to see whether we have to rehash the configuration .. */ |
233 |
|
if (dorehash) |
234 |
|
{ |
235 |
< |
rehash(1); |
235 |
> |
conf_rehash(1); |
236 |
|
dorehash = 0; |
237 |
|
} |
238 |
|
|
255 |
|
static void |
256 |
|
initialize_global_set_options(void) |
257 |
|
{ |
263 |
– |
memset(&GlobalSetOptions, 0, sizeof(GlobalSetOptions)); |
264 |
– |
|
258 |
|
GlobalSetOptions.autoconn = 1; |
259 |
|
GlobalSetOptions.spam_time = MIN_JOIN_LEAVE_TIME; |
260 |
|
GlobalSetOptions.spam_num = MAX_JOIN_LEAVE_COUNT; |
261 |
|
|
262 |
< |
if (ConfigFileEntry.default_floodcount) |
263 |
< |
GlobalSetOptions.floodcount = ConfigFileEntry.default_floodcount; |
262 |
> |
if (ConfigGeneral.default_floodcount) |
263 |
> |
GlobalSetOptions.floodcount = ConfigGeneral.default_floodcount; |
264 |
|
else |
265 |
|
GlobalSetOptions.floodcount = 10; |
266 |
|
|
267 |
< |
/* XXX I have no idea what to try here - Dianora */ |
268 |
< |
GlobalSetOptions.joinfloodcount = 16; |
276 |
< |
GlobalSetOptions.joinfloodtime = 8; |
267 |
> |
GlobalSetOptions.joinfloodcount = 18; |
268 |
> |
GlobalSetOptions.joinfloodtime = 6; |
269 |
|
|
270 |
|
split_servers = ConfigChannel.default_split_server_count; |
271 |
|
split_users = ConfigChannel.default_split_user_count; |
278 |
|
} |
279 |
|
|
280 |
|
GlobalSetOptions.ident_timeout = IDENT_TIMEOUT; |
289 |
– |
/* End of global set options */ |
281 |
|
} |
282 |
|
|
283 |
|
/* initialize_server_capabs() |
315 |
|
|
316 |
|
snprintf(buff, sizeof(buff), "%u\n", pid); |
317 |
|
|
318 |
< |
if ((fputs(buff, fb) == -1)) |
318 |
> |
if (fputs(buff, fb) == -1) |
319 |
|
ilog(LOG_TYPE_IRCD, "Error writing %u to pid file %s (%s)", |
320 |
|
pid, filename, strerror(errno)); |
321 |
|
|
323 |
|
} |
324 |
|
else |
325 |
|
{ |
326 |
< |
ilog(LOG_TYPE_IRCD, "Error opening pid file %s", filename); |
326 |
> |
ilog(LOG_TYPE_IRCD, "Error opening pid file %s (%s)", |
327 |
> |
filename, strerror(errno)); |
328 |
|
} |
329 |
|
} |
330 |
|
|
346 |
|
/* Don't do logging here, since we don't have log() initialised */ |
347 |
|
if ((fb = fopen(filename, "r"))) |
348 |
|
{ |
349 |
< |
if (fgets(buff, 20, fb) == NULL) |
349 |
> |
if (!fgets(buff, 20, fb)) |
350 |
|
{ |
351 |
|
/* log(L_ERROR, "Error reading from pid file %s (%s)", filename, |
352 |
|
* strerror(errno)); |
412 |
|
ssl_init(void) |
413 |
|
{ |
414 |
|
#ifdef HAVE_LIBCRYPTO |
423 |
– |
const unsigned char session_id[] = "ircd-hybrid"; |
424 |
– |
|
415 |
|
SSL_load_error_strings(); |
416 |
|
SSLeay_add_ssl_algorithms(); |
417 |
|
|
418 |
< |
if ((ServerInfo.server_ctx = SSL_CTX_new(SSLv23_server_method())) == NULL) |
418 |
> |
if (!(ConfigServerInfo.server_ctx = SSL_CTX_new(SSLv23_server_method()))) |
419 |
|
{ |
420 |
|
const char *s = ERR_lib_error_string(ERR_get_error()); |
421 |
|
|
422 |
|
fprintf(stderr, "ERROR: Could not initialize the SSL Server context -- %s\n", s); |
423 |
< |
ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Server context -- %s\n", s); |
423 |
> |
ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Server context -- %s", s); |
424 |
> |
exit(EXIT_FAILURE); |
425 |
> |
return; /* Not reached */ |
426 |
|
} |
427 |
|
|
428 |
< |
SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TLSv1); |
429 |
< |
SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_SINGLE_DH_USE); |
430 |
< |
SSL_CTX_set_verify(ServerInfo.server_ctx, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE, |
428 |
> |
SSL_CTX_set_options(ConfigServerInfo.server_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TICKET); |
429 |
> |
SSL_CTX_set_options(ConfigServerInfo.server_ctx, SSL_OP_SINGLE_DH_USE|SSL_OP_CIPHER_SERVER_PREFERENCE); |
430 |
> |
SSL_CTX_set_verify(ConfigServerInfo.server_ctx, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE, |
431 |
|
always_accept_verify_cb); |
432 |
< |
SSL_CTX_set_session_id_context(ServerInfo.server_ctx, session_id, sizeof(session_id) - 1); |
432 |
> |
SSL_CTX_set_session_cache_mode(ConfigServerInfo.server_ctx, SSL_SESS_CACHE_OFF); |
433 |
> |
SSL_CTX_set_cipher_list(ConfigServerInfo.server_ctx, "EECDH+HIGH:EDH+HIGH:HIGH:!aNULL"); |
434 |
|
|
435 |
< |
#if OPENSSL_VERSION_NUMBER >= 0x1000005FL && !defined(OPENSSL_NO_ECDH) |
435 |
> |
#if OPENSSL_VERSION_NUMBER >= 0x009080FFL && !defined(OPENSSL_NO_ECDH) |
436 |
|
{ |
437 |
|
EC_KEY *key = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1); |
438 |
|
|
439 |
|
if (key) |
440 |
|
{ |
441 |
< |
SSL_CTX_set_tmp_ecdh(ServerInfo.server_ctx, key); |
441 |
> |
SSL_CTX_set_tmp_ecdh(ConfigServerInfo.server_ctx, key); |
442 |
|
EC_KEY_free(key); |
443 |
|
} |
444 |
|
} |
445 |
|
|
446 |
< |
SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_SINGLE_ECDH_USE); |
446 |
> |
SSL_CTX_set_options(ConfigServerInfo.server_ctx, SSL_OP_SINGLE_ECDH_USE); |
447 |
|
#endif |
448 |
|
|
449 |
< |
if ((ServerInfo.client_ctx = SSL_CTX_new(SSLv23_client_method())) == NULL) |
449 |
> |
if (!(ConfigServerInfo.client_ctx = SSL_CTX_new(SSLv23_client_method()))) |
450 |
|
{ |
451 |
|
const char *s = ERR_lib_error_string(ERR_get_error()); |
452 |
|
|
453 |
|
fprintf(stderr, "ERROR: Could not initialize the SSL Client context -- %s\n", s); |
454 |
< |
ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Client context -- %s\n", s); |
454 |
> |
ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Client context -- %s", s); |
455 |
> |
exit(EXIT_FAILURE); |
456 |
> |
return; /* Not reached */ |
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_SINGLE_DH_USE); |
461 |
< |
SSL_CTX_set_verify(ServerInfo.client_ctx, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE, |
459 |
> |
SSL_CTX_set_options(ConfigServerInfo.client_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TICKET); |
460 |
> |
SSL_CTX_set_options(ConfigServerInfo.client_ctx, SSL_OP_SINGLE_DH_USE); |
461 |
> |
SSL_CTX_set_verify(ConfigServerInfo.client_ctx, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE, |
462 |
|
always_accept_verify_cb); |
463 |
+ |
SSL_CTX_set_session_cache_mode(ConfigServerInfo.client_ctx, SSL_SESS_CACHE_OFF); |
464 |
|
#endif /* HAVE_LIBCRYPTO */ |
465 |
|
} |
466 |
|
|
468 |
|
main(int argc, char *argv[]) |
469 |
|
{ |
470 |
|
/* Check to see if the user is running us as root, which is a nono */ |
471 |
< |
if (geteuid() == 0) |
471 |
> |
if (!geteuid()) |
472 |
|
{ |
473 |
|
fprintf(stderr, "ERROR: This server won't run as root/superuser\n"); |
474 |
|
return -1; |
483 |
|
/* It ain't random, but it ought to be a little harder to guess */ |
484 |
|
init_genrand(SystemTime.tv_sec ^ (SystemTime.tv_usec | (getpid() << 20))); |
485 |
|
|
490 |
– |
me.localClient = &meLocalUser; |
486 |
|
dlinkAdd(&me, &me.node, &global_client_list); /* Pointer to beginning |
487 |
|
of Client list */ |
488 |
< |
ConfigLoggingEntry.use_logging = 1; |
489 |
< |
ConfigFileEntry.dpath = DPATH; |
490 |
< |
ConfigFileEntry.spath = SPATH; |
491 |
< |
ConfigFileEntry.mpath = MPATH; |
492 |
< |
ConfigFileEntry.configfile = CPATH; /* Server configuration file */ |
493 |
< |
ConfigFileEntry.klinefile = KPATH; /* Server kline file */ |
494 |
< |
ConfigFileEntry.glinefile = GPATH; /* Server gline file */ |
495 |
< |
ConfigFileEntry.xlinefile = XPATH; /* Server xline file */ |
496 |
< |
ConfigFileEntry.dlinefile = DLPATH; /* dline file */ |
497 |
< |
ConfigFileEntry.resvfile = RESVPATH; /* resv file */ |
488 |
> |
ConfigLog.use_logging = 1; |
489 |
> |
ConfigGeneral.dpath = DPATH; |
490 |
> |
ConfigGeneral.spath = SPATH; |
491 |
> |
ConfigGeneral.mpath = MPATH; |
492 |
> |
ConfigGeneral.configfile = CPATH; /* Server configuration file */ |
493 |
> |
ConfigGeneral.klinefile = KPATH; /* Server kline file */ |
494 |
> |
ConfigGeneral.glinefile = GPATH; /* Server gline file */ |
495 |
> |
ConfigGeneral.xlinefile = XPATH; /* Server xline file */ |
496 |
> |
ConfigGeneral.dlinefile = DLPATH; /* dline file */ |
497 |
> |
ConfigGeneral.resvfile = RESVPATH; /* resv file */ |
498 |
|
|
499 |
|
myargv = argv; |
500 |
|
umask(077); /* better safe than sorry --SRB */ |
507 |
|
exit(EXIT_SUCCESS); |
508 |
|
} |
509 |
|
|
510 |
< |
if (chdir(ConfigFileEntry.dpath)) |
510 |
> |
if (chdir(ConfigGeneral.dpath)) |
511 |
|
{ |
512 |
|
perror("chdir"); |
513 |
|
exit(EXIT_FAILURE); |
528 |
|
/* We need this to initialise the fd array before anything else */ |
529 |
|
fdlist_init(); |
530 |
|
log_set_file(LOG_TYPE_IRCD, 0, logFileName); |
531 |
< |
check_can_use_v6(); |
531 |
> |
|
532 |
|
init_netio(); /* This needs to be setup early ! -- adrian */ |
533 |
|
|
534 |
|
/* Check if there is pidfile and daemon already running */ |
539 |
|
init_isupport(); |
540 |
|
dbuf_init(); |
541 |
|
hash_init(); |
542 |
< |
init_ip_hash_table(); /* client host ip hash table */ |
548 |
< |
init_host_hash(); /* Host-hashtable. */ |
542 |
> |
ipcache_init(); |
543 |
|
client_init(); |
544 |
|
class_init(); |
545 |
|
whowas_init(); |
554 |
|
channel_init(); |
555 |
|
read_links_file(); |
556 |
|
motd_init(); |
557 |
+ |
user_usermodes_init(); |
558 |
|
#ifdef HAVE_LIBGEOIP |
559 |
|
geoip_ctx = GeoIP_new(GEOIP_MEMORY_CACHE); |
560 |
|
#endif |
561 |
|
|
562 |
< |
if (EmptyString(ServerInfo.sid)) |
562 |
> |
if (EmptyString(ConfigServerInfo.sid)) |
563 |
|
{ |
564 |
|
ilog(LOG_TYPE_IRCD, "ERROR: No server id specified in serverinfo block."); |
565 |
|
exit(EXIT_FAILURE); |
566 |
|
} |
567 |
|
|
568 |
< |
strlcpy(me.id, ServerInfo.sid, sizeof(me.id)); |
568 |
> |
strlcpy(me.id, ConfigServerInfo.sid, sizeof(me.id)); |
569 |
|
|
570 |
< |
if (EmptyString(ServerInfo.name)) |
570 |
> |
if (EmptyString(ConfigServerInfo.name)) |
571 |
|
{ |
572 |
|
ilog(LOG_TYPE_IRCD, "ERROR: No server name specified in serverinfo block."); |
573 |
|
exit(EXIT_FAILURE); |
574 |
|
} |
575 |
|
|
576 |
< |
strlcpy(me.name, ServerInfo.name, sizeof(me.name)); |
576 |
> |
strlcpy(me.name, ConfigServerInfo.name, sizeof(me.name)); |
577 |
|
|
578 |
|
/* serverinfo{} description must exist. If not, error out.*/ |
579 |
< |
if (EmptyString(ServerInfo.description)) |
579 |
> |
if (EmptyString(ConfigServerInfo.description)) |
580 |
|
{ |
581 |
|
ilog(LOG_TYPE_IRCD, "ERROR: No server description specified in serverinfo block."); |
582 |
|
exit(EXIT_FAILURE); |
583 |
|
} |
584 |
|
|
585 |
< |
strlcpy(me.info, ServerInfo.description, sizeof(me.info)); |
585 |
> |
strlcpy(me.info, ConfigServerInfo.description, sizeof(me.info)); |
586 |
|
|
587 |
|
me.from = &me; |
588 |
|
me.servptr = &me; |
589 |
< |
me.localClient->lasttime = CurrentTime; |
590 |
< |
me.localClient->since = CurrentTime; |
591 |
< |
me.localClient->firsttime = CurrentTime; |
589 |
> |
me.connection->lasttime = CurrentTime; |
590 |
> |
me.connection->since = CurrentTime; |
591 |
> |
me.connection->firsttime = CurrentTime; |
592 |
|
|
593 |
|
SetMe(&me); |
594 |
|
make_server(&me); |
596 |
|
hash_add_id(&me); |
597 |
|
hash_add_client(&me); |
598 |
|
|
599 |
< |
/* add ourselves to global_serv_list */ |
605 |
< |
dlinkAdd(&me, make_dlink_node(), &global_serv_list); |
599 |
> |
dlinkAdd(&me, make_dlink_node(), &global_server_list); |
600 |
|
|
601 |
|
load_kline_database(); |
602 |
|
load_dline_database(); |
604 |
|
load_xline_database(); |
605 |
|
load_resv_database(); |
606 |
|
|
613 |
– |
if (chdir(MODPATH)) |
614 |
– |
{ |
615 |
– |
ilog(LOG_TYPE_IRCD, "Could not load core modules. Terminating!"); |
616 |
– |
exit(EXIT_FAILURE); |
617 |
– |
} |
618 |
– |
|
607 |
|
load_all_modules(1); |
608 |
|
load_conf_modules(); |
609 |
|
load_core_modules(1); |
610 |
|
|
623 |
– |
/* Go back to DPATH after checking to see if we can chdir to MODPATH */ |
624 |
– |
if (chdir(ConfigFileEntry.dpath)) |
625 |
– |
{ |
626 |
– |
perror("chdir"); |
627 |
– |
exit(EXIT_FAILURE); |
628 |
– |
} |
629 |
– |
|
630 |
– |
/* |
631 |
– |
* assemble_umode_buffer() has to be called after |
632 |
– |
* reading conf/loading modules. |
633 |
– |
*/ |
634 |
– |
assemble_umode_buffer(); |
635 |
– |
|
611 |
|
write_pidfile(pidFileName); |
612 |
|
|
613 |
|
ilog(LOG_TYPE_IRCD, "Server Ready"); |
620 |
|
event_addish(&event_try_connections, NULL); |
621 |
|
|
622 |
|
/* Setup the timeout check. I'll shift it later :) -- adrian */ |
623 |
< |
event_addish(&event_comm_checktimeouts, NULL); |
623 |
> |
event_add(&event_comm_checktimeouts, NULL); |
624 |
|
|
625 |
|
event_addish(&event_save_all_databases, NULL); |
626 |
|
|