1 |
|
/* |
2 |
< |
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
3 |
< |
* ircd.c: Starts up and runs the ircd. |
2 |
> |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
3 |
|
* |
4 |
< |
* Copyright (C) 2002 by the past and present ircd coders, and others. |
4 |
> |
* Copyright (c) 1997-2014 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 |
17 |
|
* along with this program; if not, write to the Free Software |
18 |
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
19 |
|
* USA |
20 |
< |
* |
21 |
< |
* $Id$ |
20 |
> |
*/ |
21 |
> |
|
22 |
> |
/*! \file ircd.c |
23 |
> |
* \brief Starts up and runs the ircd. |
24 |
> |
* \version $Id$ |
25 |
|
*/ |
26 |
|
|
27 |
|
#include "stdinc.h" |
58 |
|
#include "mempool.h" |
59 |
|
#include "hook.h" |
60 |
|
#include "ircd_getopt.h" |
59 |
– |
#include "motd.h" |
61 |
|
#include "supported.h" |
62 |
|
#include "watch.h" |
63 |
|
#include "conf_db.h" |
64 |
|
#include "conf_class.h" |
65 |
|
|
66 |
+ |
|
67 |
+ |
#ifdef HAVE_LIBGEOIP |
68 |
+ |
GeoIP *geoip_ctx; |
69 |
+ |
#endif |
70 |
+ |
|
71 |
|
/* /quote set variables */ |
72 |
|
struct SetOptions GlobalSetOptions; |
73 |
< |
|
74 |
< |
/* configuration set from ircd.conf */ |
69 |
< |
struct config_file_entry ConfigFileEntry; |
70 |
< |
/* server info set from ircd.conf */ |
71 |
< |
struct server_info ServerInfo; |
72 |
< |
/* admin info set from ircd.conf */ |
73 |
< |
struct admin_info AdminInfo = { NULL, NULL, NULL }; |
74 |
< |
struct Counter Count = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; |
75 |
< |
struct ServerState_t server_state = { 0 }; |
76 |
< |
struct logging_entry ConfigLoggingEntry = { .use_logging = 1 }; |
73 |
> |
struct Counter Count; |
74 |
> |
struct ServerState_t server_state; |
75 |
|
struct ServerStatistics ServerStats; |
76 |
|
struct timeval SystemTime; |
77 |
|
struct Client me; /* That's me */ |
113 |
|
static void |
114 |
|
print_startup(int pid) |
115 |
|
{ |
116 |
< |
printf("ircd: version %s\n", ircd_version); |
116 |
> |
printf("ircd: version %s(%s)\n", ircd_version, serno); |
117 |
|
printf("ircd: pid %d\n", pid); |
118 |
|
printf("ircd: running in %s mode from %s\n", !server_state.foreground ? "background" |
119 |
|
: "foreground", ConfigFileEntry.dpath); |
141 |
|
static int printVersion = 0; |
142 |
|
|
143 |
|
static struct lgetopt myopts[] = { |
144 |
< |
{"configfile", &ConfigFileEntry.configfile, |
144 |
> |
{"configfile", &ConfigFileEntry.configfile, |
145 |
|
STRING, "File to use for ircd.conf"}, |
146 |
|
{"glinefile", &ConfigFileEntry.glinefile, |
147 |
|
STRING, "File to use for gline database"}, |
148 |
< |
{"klinefile", &ConfigFileEntry.klinefile, |
148 |
> |
{"klinefile", &ConfigFileEntry.klinefile, |
149 |
|
STRING, "File to use for kline database"}, |
150 |
|
{"dlinefile", &ConfigFileEntry.dlinefile, |
151 |
|
STRING, "File to use for dline database"}, |
152 |
< |
{"xlinefile", &ConfigFileEntry.xlinefile, |
152 |
> |
{"xlinefile", &ConfigFileEntry.xlinefile, |
153 |
|
STRING, "File to use for xline database"}, |
154 |
|
{"resvfile", &ConfigFileEntry.resvfile, |
155 |
|
STRING, "File to use for resv database"}, |
156 |
< |
{"logfile", &logFileName, |
156 |
> |
{"logfile", &logFileName, |
157 |
|
STRING, "File to use for ircd.log"}, |
158 |
|
{"pidfile", &pidFileName, |
159 |
|
STRING, "File to use for process ID"}, |
160 |
< |
{"foreground", &server_state.foreground, |
160 |
> |
{"foreground", &server_state.foreground, |
161 |
|
YESNO, "Run in foreground (don't detach)"}, |
162 |
< |
{"version", &printVersion, |
162 |
> |
{"version", &printVersion, |
163 |
|
YESNO, "Print version and exit"}, |
164 |
|
{"help", NULL, USAGE, "Print this text"}, |
165 |
|
{NULL, NULL, STRING, NULL}, |
168 |
|
void |
169 |
|
set_time(void) |
170 |
|
{ |
171 |
< |
static char to_send[200]; |
174 |
< |
struct timeval newtime; |
175 |
< |
newtime.tv_sec = 0; |
176 |
< |
newtime.tv_usec = 0; |
171 |
> |
struct timeval newtime = { .tv_sec = 0, .tv_usec = 0 }; |
172 |
|
|
173 |
|
if (gettimeofday(&newtime, NULL) == -1) |
174 |
|
{ |
182 |
|
|
183 |
|
if (newtime.tv_sec < CurrentTime) |
184 |
|
{ |
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); |
185 |
> |
ilog(LOG_TYPE_IRCD, "System clock is running backwards - (%lu < %lu)", |
186 |
> |
(unsigned long)newtime.tv_sec, (unsigned long)CurrentTime); |
187 |
> |
sendto_realops_flags(UMODE_DEBUG, L_ALL, SEND_NOTICE, |
188 |
> |
"System clock is running backwards - (%lu < %lu)", |
189 |
> |
(unsigned long)newtime.tv_sec, |
190 |
> |
(unsigned long)CurrentTime); |
191 |
|
set_back_events(CurrentTime - newtime.tv_sec); |
192 |
|
} |
193 |
|
|
202 |
|
{ |
203 |
|
/* |
204 |
|
* Maybe we want a flags word? |
205 |
< |
* ie. if (REHASHED_KLINES(global_flags)) |
205 |
> |
* ie. if (REHASHED_KLINES(global_flags)) |
206 |
|
* SET_REHASHED_KLINES(global_flags) |
207 |
|
* CLEAR_REHASHED_KLINES(global_flags) |
208 |
|
* |
234 |
|
comm_select(); |
235 |
|
exit_aborted_clients(); |
236 |
|
free_exited_clients(); |
240 |
– |
send_queued_all(); |
237 |
|
|
238 |
|
/* Check to see whether we have to rehash the configuration .. */ |
239 |
|
if (dorehash) |
243 |
|
} |
244 |
|
if (doremotd) |
245 |
|
{ |
246 |
< |
read_message_file(&ConfigFileEntry.motd); |
246 |
> |
motd_recache(); |
247 |
|
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
248 |
< |
"Got signal SIGUSR1, reloading ircd motd file"); |
248 |
> |
"Got signal SIGUSR1, reloading motd file(s)"); |
249 |
|
doremotd = 0; |
250 |
|
} |
251 |
|
} |
255 |
|
* |
256 |
|
* inputs - none |
257 |
|
* output - none |
258 |
< |
* side effects - This sets all global set options needed |
258 |
> |
* side effects - This sets all global set options needed |
259 |
|
*/ |
260 |
|
static void |
261 |
|
initialize_global_set_options(void) |
289 |
|
/* End of global set options */ |
290 |
|
} |
291 |
|
|
296 |
– |
/* initialize_message_files() |
297 |
– |
* |
298 |
– |
* inputs - none |
299 |
– |
* output - none |
300 |
– |
* side effects - Set up all message files needed, motd etc. |
301 |
– |
*/ |
302 |
– |
static void |
303 |
– |
initialize_message_files(void) |
304 |
– |
{ |
305 |
– |
init_message_file(USER_MOTD, MPATH, &ConfigFileEntry.motd); |
306 |
– |
init_message_file(USER_LINKS, LIPATH, &ConfigFileEntry.linksfile); |
307 |
– |
|
308 |
– |
read_message_file(&ConfigFileEntry.motd); |
309 |
– |
read_message_file(&ConfigFileEntry.linksfile); |
310 |
– |
|
311 |
– |
init_isupport(); |
312 |
– |
} |
313 |
– |
|
292 |
|
/* initialize_server_capabs() |
293 |
|
* |
294 |
|
* inputs - none |
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 |
421 |
|
ssl_init(void) |
422 |
|
{ |
423 |
|
#ifdef HAVE_LIBCRYPTO |
424 |
+ |
const unsigned char session_id[] = "ircd-hybrid"; |
425 |
+ |
|
426 |
|
SSL_load_error_strings(); |
427 |
|
SSLeay_add_ssl_algorithms(); |
428 |
|
|
437 |
|
|
438 |
|
SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TLSv1); |
439 |
|
SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_TLS_ROLLBACK_BUG|SSL_OP_ALL); |
440 |
< |
SSL_CTX_set_verify(ServerInfo.server_ctx, SSL_VERIFY_NONE, NULL); |
440 |
> |
SSL_CTX_set_verify(ServerInfo.server_ctx, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE, |
441 |
> |
always_accept_verify_cb); |
442 |
> |
SSL_CTX_set_session_id_context(ServerInfo.server_ctx, session_id, sizeof(session_id) - 1); |
443 |
|
|
444 |
|
if ((ServerInfo.client_ctx = SSL_CTX_new(SSLv23_client_method())) == NULL) |
445 |
|
{ |
452 |
|
|
453 |
|
SSL_CTX_set_options(ServerInfo.client_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TLSv1); |
454 |
|
SSL_CTX_set_options(ServerInfo.client_ctx, SSL_OP_TLS_ROLLBACK_BUG|SSL_OP_ALL); |
455 |
< |
SSL_CTX_set_verify(ServerInfo.client_ctx, SSL_VERIFY_NONE, NULL); |
455 |
> |
SSL_CTX_set_verify(ServerInfo.client_ctx, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE, |
456 |
> |
always_accept_verify_cb); |
457 |
|
#endif /* HAVE_LIBCRYPTO */ |
458 |
|
} |
459 |
|
|
460 |
|
int |
461 |
|
main(int argc, char *argv[]) |
462 |
|
{ |
463 |
< |
/* Check to see if the user is running |
473 |
< |
* us as root, which is a nono |
474 |
< |
*/ |
463 |
> |
/* Check to see if the user is running us as root, which is a nono */ |
464 |
|
if (geteuid() == 0) |
465 |
|
{ |
466 |
|
fprintf(stderr, "Don't run ircd as root!!!\n"); |
477 |
|
init_genrand(SystemTime.tv_sec ^ (SystemTime.tv_usec | (getpid() << 20))); |
478 |
|
|
479 |
|
me.localClient = &meLocalUser; |
480 |
< |
dlinkAdd(&me, &me.node, &global_client_list); /* Pointer to beginning |
480 |
> |
dlinkAdd(&me, &me.node, &global_client_list); /* Pointer to beginning |
481 |
|
of Client list */ |
493 |
– |
/* Initialise the channel capability usage counts... */ |
494 |
– |
init_chcap_usage_counts(); |
495 |
– |
|
482 |
|
ConfigFileEntry.dpath = DPATH; |
483 |
|
ConfigFileEntry.configfile = CPATH; /* Server configuration file */ |
484 |
|
ConfigFileEntry.klinefile = KPATH; /* Server kline file */ |
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 |
|
|
518 |
|
|
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_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 |
|
mp_pool_init(); |
532 |
|
init_dlink_nodes(); |
533 |
< |
initialize_message_files(); |
533 |
> |
init_isupport(); |
534 |
|
dbuf_init(); |
535 |
|
hash_init(); |
536 |
|
init_ip_hash_table(); /* client host ip hash table */ |
547 |
|
initialize_server_capabs(); /* Set up default_server_capabs */ |
548 |
|
initialize_global_set_options(); |
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 |
|
{ |
589 |
|
|
590 |
|
hash_add_id(&me); |
591 |
|
hash_add_client(&me); |
592 |
< |
|
592 |
> |
|
593 |
|
/* add ourselves to global_serv_list */ |
594 |
|
dlinkAdd(&me, make_dlink_node(), &global_serv_list); |
595 |
|
|