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 */ |
68 |
> |
struct Connection meConnection; /* That's also part of me */ |
69 |
|
|
70 |
|
const char *logFileName = LPATH; |
71 |
|
const char *pidFileName = PPATH; |
125 |
|
.handler = write_links_file, |
126 |
|
}; |
127 |
|
|
128 |
– |
struct event event_check_splitmode = |
129 |
– |
{ |
130 |
– |
.name = "check_splitmode", |
131 |
– |
.handler = check_splitmode, |
132 |
– |
.when = 60 |
133 |
– |
}; |
128 |
|
|
129 |
|
/* |
130 |
|
* print_startup - print startup information |
135 |
|
printf("ircd: version %s(%s)\n", ircd_version, serno); |
136 |
|
printf("ircd: pid %d\n", pid); |
137 |
|
printf("ircd: running in %s mode from %s\n", !server_state.foreground ? "background" |
138 |
< |
: "foreground", ConfigFileEntry.dpath); |
138 |
> |
: "foreground", ConfigGeneral.dpath); |
139 |
|
} |
140 |
|
|
141 |
|
static void |
161 |
|
|
162 |
|
static struct lgetopt myopts[] = |
163 |
|
{ |
164 |
< |
{"configfile", &ConfigFileEntry.configfile, |
164 |
> |
{"configfile", &ConfigGeneral.configfile, |
165 |
|
STRING, "File to use for ircd.conf"}, |
166 |
< |
{"glinefile", &ConfigFileEntry.glinefile, |
166 |
> |
{"glinefile", &ConfigGeneral.glinefile, |
167 |
|
STRING, "File to use for gline database"}, |
168 |
< |
{"klinefile", &ConfigFileEntry.klinefile, |
168 |
> |
{"klinefile", &ConfigGeneral.klinefile, |
169 |
|
STRING, "File to use for kline database"}, |
170 |
< |
{"dlinefile", &ConfigFileEntry.dlinefile, |
170 |
> |
{"dlinefile", &ConfigGeneral.dlinefile, |
171 |
|
STRING, "File to use for dline database"}, |
172 |
< |
{"xlinefile", &ConfigFileEntry.xlinefile, |
172 |
> |
{"xlinefile", &ConfigGeneral.xlinefile, |
173 |
|
STRING, "File to use for xline database"}, |
174 |
< |
{"resvfile", &ConfigFileEntry.resvfile, |
174 |
> |
{"resvfile", &ConfigGeneral.resvfile, |
175 |
|
STRING, "File to use for resv database"}, |
176 |
|
{"logfile", &logFileName, |
177 |
|
STRING, "File to use for ircd.log"}, |
260 |
|
static void |
261 |
|
initialize_global_set_options(void) |
262 |
|
{ |
269 |
– |
memset(&GlobalSetOptions, 0, sizeof(GlobalSetOptions)); |
270 |
– |
|
263 |
|
GlobalSetOptions.autoconn = 1; |
264 |
|
GlobalSetOptions.spam_time = MIN_JOIN_LEAVE_TIME; |
265 |
|
GlobalSetOptions.spam_num = MAX_JOIN_LEAVE_COUNT; |
266 |
|
|
267 |
< |
if (ConfigFileEntry.default_floodcount) |
268 |
< |
GlobalSetOptions.floodcount = ConfigFileEntry.default_floodcount; |
267 |
> |
if (ConfigGeneral.default_floodcount) |
268 |
> |
GlobalSetOptions.floodcount = ConfigGeneral.default_floodcount; |
269 |
|
else |
270 |
|
GlobalSetOptions.floodcount = 10; |
271 |
|
|
284 |
|
} |
285 |
|
|
286 |
|
GlobalSetOptions.ident_timeout = IDENT_TIMEOUT; |
295 |
– |
/* End of global set options */ |
287 |
|
} |
288 |
|
|
289 |
|
/* initialize_server_capabs() |
422 |
|
SSL_load_error_strings(); |
423 |
|
SSLeay_add_ssl_algorithms(); |
424 |
|
|
425 |
< |
if ((ServerInfo.server_ctx = SSL_CTX_new(SSLv23_server_method())) == NULL) |
425 |
> |
if ((ConfigServerInfo.server_ctx = SSL_CTX_new(SSLv23_server_method())) == NULL) |
426 |
|
{ |
427 |
|
const char *s = ERR_lib_error_string(ERR_get_error()); |
428 |
|
|
429 |
|
fprintf(stderr, "ERROR: Could not initialize the SSL Server context -- %s\n", s); |
430 |
|
ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Server context -- %s\n", s); |
431 |
+ |
exit(EXIT_FAILURE); |
432 |
|
} |
433 |
|
|
434 |
< |
SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TLSv1); |
435 |
< |
SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_TLS_ROLLBACK_BUG); |
436 |
< |
SSL_CTX_set_verify(ServerInfo.server_ctx, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE, |
434 |
> |
SSL_CTX_set_options(ConfigServerInfo.server_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3); |
435 |
> |
SSL_CTX_set_options(ConfigServerInfo.server_ctx, SSL_OP_SINGLE_DH_USE|SSL_OP_CIPHER_SERVER_PREFERENCE); |
436 |
> |
SSL_CTX_set_verify(ConfigServerInfo.server_ctx, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE, |
437 |
|
always_accept_verify_cb); |
438 |
< |
SSL_CTX_set_session_id_context(ServerInfo.server_ctx, session_id, sizeof(session_id) - 1); |
438 |
> |
SSL_CTX_set_session_id_context(ConfigServerInfo.server_ctx, session_id, sizeof(session_id) - 1); |
439 |
|
|
440 |
|
#if OPENSSL_VERSION_NUMBER >= 0x1000005FL && !defined(OPENSSL_NO_ECDH) |
441 |
|
{ |
443 |
|
|
444 |
|
if (key) |
445 |
|
{ |
446 |
< |
SSL_CTX_set_tmp_ecdh(ServerInfo.server_ctx, key); |
446 |
> |
SSL_CTX_set_tmp_ecdh(ConfigServerInfo.server_ctx, key); |
447 |
|
EC_KEY_free(key); |
448 |
|
} |
449 |
|
} |
450 |
|
|
451 |
< |
SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_SINGLE_ECDH_USE); |
451 |
> |
SSL_CTX_set_options(ConfigServerInfo.server_ctx, SSL_OP_SINGLE_ECDH_USE); |
452 |
|
#endif |
453 |
|
|
454 |
< |
if ((ServerInfo.client_ctx = SSL_CTX_new(SSLv23_client_method())) == NULL) |
454 |
> |
if ((ConfigServerInfo.client_ctx = SSL_CTX_new(SSLv23_client_method())) == NULL) |
455 |
|
{ |
456 |
|
const char *s = ERR_lib_error_string(ERR_get_error()); |
457 |
|
|
458 |
|
fprintf(stderr, "ERROR: Could not initialize the SSL Client context -- %s\n", s); |
459 |
|
ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Client context -- %s\n", s); |
460 |
+ |
exit(EXIT_FAILURE); |
461 |
|
} |
462 |
|
|
463 |
< |
SSL_CTX_set_options(ServerInfo.client_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TLSv1); |
464 |
< |
SSL_CTX_set_options(ServerInfo.client_ctx, SSL_OP_TLS_ROLLBACK_BUG); |
465 |
< |
SSL_CTX_set_verify(ServerInfo.client_ctx, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE, |
463 |
> |
SSL_CTX_set_options(ConfigServerInfo.client_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3); |
464 |
> |
SSL_CTX_set_options(ConfigServerInfo.client_ctx, SSL_OP_SINGLE_DH_USE); |
465 |
> |
SSL_CTX_set_verify(ConfigServerInfo.client_ctx, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE, |
466 |
|
always_accept_verify_cb); |
467 |
|
#endif /* HAVE_LIBCRYPTO */ |
468 |
|
} |
486 |
|
/* It ain't random, but it ought to be a little harder to guess */ |
487 |
|
init_genrand(SystemTime.tv_sec ^ (SystemTime.tv_usec | (getpid() << 20))); |
488 |
|
|
489 |
< |
me.localClient = &meLocalUser; |
489 |
> |
me.connection = &meConnection; |
490 |
|
dlinkAdd(&me, &me.node, &global_client_list); /* Pointer to beginning |
491 |
|
of Client list */ |
492 |
< |
ConfigLoggingEntry.use_logging = 1; |
493 |
< |
ConfigFileEntry.dpath = DPATH; |
494 |
< |
ConfigFileEntry.spath = SPATH; |
495 |
< |
ConfigFileEntry.mpath = MPATH; |
496 |
< |
ConfigFileEntry.configfile = CPATH; /* Server configuration file */ |
497 |
< |
ConfigFileEntry.klinefile = KPATH; /* Server kline file */ |
498 |
< |
ConfigFileEntry.glinefile = GPATH; /* Server gline file */ |
499 |
< |
ConfigFileEntry.xlinefile = XPATH; /* Server xline file */ |
500 |
< |
ConfigFileEntry.dlinefile = DLPATH; /* dline file */ |
501 |
< |
ConfigFileEntry.resvfile = RESVPATH; /* resv file */ |
492 |
> |
ConfigLog.use_logging = 1; |
493 |
> |
ConfigGeneral.dpath = DPATH; |
494 |
> |
ConfigGeneral.spath = SPATH; |
495 |
> |
ConfigGeneral.mpath = MPATH; |
496 |
> |
ConfigGeneral.configfile = CPATH; /* Server configuration file */ |
497 |
> |
ConfigGeneral.klinefile = KPATH; /* Server kline file */ |
498 |
> |
ConfigGeneral.glinefile = GPATH; /* Server gline file */ |
499 |
> |
ConfigGeneral.xlinefile = XPATH; /* Server xline file */ |
500 |
> |
ConfigGeneral.dlinefile = DLPATH; /* dline file */ |
501 |
> |
ConfigGeneral.resvfile = RESVPATH; /* resv file */ |
502 |
|
|
503 |
|
myargv = argv; |
504 |
|
umask(077); /* better safe than sorry --SRB */ |
511 |
|
exit(EXIT_SUCCESS); |
512 |
|
} |
513 |
|
|
514 |
< |
if (chdir(ConfigFileEntry.dpath)) |
514 |
> |
if (chdir(ConfigGeneral.dpath)) |
515 |
|
{ |
516 |
|
perror("chdir"); |
517 |
|
exit(EXIT_FAILURE); |
532 |
|
/* We need this to initialise the fd array before anything else */ |
533 |
|
fdlist_init(); |
534 |
|
log_set_file(LOG_TYPE_IRCD, 0, logFileName); |
535 |
< |
check_can_use_v6(); |
535 |
> |
|
536 |
|
init_netio(); /* This needs to be setup early ! -- adrian */ |
537 |
|
|
538 |
|
/* Check if there is pidfile and daemon already running */ |
543 |
|
init_isupport(); |
544 |
|
dbuf_init(); |
545 |
|
hash_init(); |
546 |
< |
init_ip_hash_table(); /* client host ip hash table */ |
546 |
> |
ipcache_init(); |
547 |
|
init_host_hash(); /* Host-hashtable. */ |
548 |
|
client_init(); |
549 |
|
class_init(); |
563 |
|
geoip_ctx = GeoIP_new(GEOIP_MEMORY_CACHE); |
564 |
|
#endif |
565 |
|
|
566 |
< |
if (EmptyString(ServerInfo.sid)) |
566 |
> |
if (EmptyString(ConfigServerInfo.sid)) |
567 |
|
{ |
568 |
|
ilog(LOG_TYPE_IRCD, "ERROR: No server id specified in serverinfo block."); |
569 |
|
exit(EXIT_FAILURE); |
570 |
|
} |
571 |
|
|
572 |
< |
strlcpy(me.id, ServerInfo.sid, sizeof(me.id)); |
572 |
> |
strlcpy(me.id, ConfigServerInfo.sid, sizeof(me.id)); |
573 |
|
|
574 |
< |
if (EmptyString(ServerInfo.name)) |
574 |
> |
if (EmptyString(ConfigServerInfo.name)) |
575 |
|
{ |
576 |
|
ilog(LOG_TYPE_IRCD, "ERROR: No server name specified in serverinfo block."); |
577 |
|
exit(EXIT_FAILURE); |
578 |
|
} |
579 |
|
|
580 |
< |
strlcpy(me.name, ServerInfo.name, sizeof(me.name)); |
580 |
> |
strlcpy(me.name, ConfigServerInfo.name, sizeof(me.name)); |
581 |
|
|
582 |
|
/* serverinfo{} description must exist. If not, error out.*/ |
583 |
< |
if (EmptyString(ServerInfo.description)) |
583 |
> |
if (EmptyString(ConfigServerInfo.description)) |
584 |
|
{ |
585 |
|
ilog(LOG_TYPE_IRCD, "ERROR: No server description specified in serverinfo block."); |
586 |
|
exit(EXIT_FAILURE); |
587 |
|
} |
588 |
|
|
589 |
< |
strlcpy(me.info, ServerInfo.description, sizeof(me.info)); |
589 |
> |
strlcpy(me.info, ConfigServerInfo.description, sizeof(me.info)); |
590 |
|
|
591 |
|
me.from = &me; |
592 |
|
me.servptr = &me; |
593 |
< |
me.localClient->lasttime = CurrentTime; |
594 |
< |
me.localClient->since = CurrentTime; |
595 |
< |
me.localClient->firsttime = CurrentTime; |
593 |
> |
me.connection->lasttime = CurrentTime; |
594 |
> |
me.connection->since = CurrentTime; |
595 |
> |
me.connection->firsttime = CurrentTime; |
596 |
|
|
597 |
|
SetMe(&me); |
598 |
|
make_server(&me); |
600 |
|
hash_add_id(&me); |
601 |
|
hash_add_client(&me); |
602 |
|
|
603 |
< |
/* add ourselves to global_serv_list */ |
611 |
< |
dlinkAdd(&me, make_dlink_node(), &global_serv_list); |
603 |
> |
dlinkAdd(&me, make_dlink_node(), &global_server_list); |
604 |
|
|
605 |
|
load_kline_database(); |
606 |
|
load_dline_database(); |
619 |
|
load_core_modules(1); |
620 |
|
|
621 |
|
/* Go back to DPATH after checking to see if we can chdir to MODPATH */ |
622 |
< |
if (chdir(ConfigFileEntry.dpath)) |
622 |
> |
if (chdir(ConfigGeneral.dpath)) |
623 |
|
{ |
624 |
|
perror("chdir"); |
625 |
|
exit(EXIT_FAILURE); |
643 |
|
event_addish(&event_try_connections, NULL); |
644 |
|
|
645 |
|
/* Setup the timeout check. I'll shift it later :) -- adrian */ |
646 |
< |
event_addish(&event_comm_checktimeouts, NULL); |
646 |
> |
event_add(&event_comm_checktimeouts, NULL); |
647 |
|
|
648 |
|
event_addish(&event_save_all_databases, NULL); |
649 |
|
|
656 |
|
ConfigServerHide.links_disabled = 1; |
657 |
|
|
658 |
|
if (splitmode) |
659 |
< |
event_addish(&event_check_splitmode, NULL); |
659 |
> |
event_addish(&splitmode_event, NULL); |
660 |
|
|
661 |
|
io_loop(); |
662 |
|
return 0; |