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" |
28 |
|
#include "s_user.h" |
29 |
< |
#include "tools.h" |
29 |
> |
#include "list.h" |
30 |
|
#include "ircd.h" |
31 |
|
#include "channel.h" |
32 |
|
#include "channel_mode.h" |
33 |
|
#include "client.h" |
32 |
– |
#include "common.h" |
34 |
|
#include "event.h" |
35 |
|
#include "fdlist.h" |
36 |
|
#include "hash.h" |
37 |
|
#include "irc_string.h" |
37 |
– |
#include "sprintf_irc.h" |
38 |
|
#include "ircd_signal.h" |
39 |
– |
#include "list.h" |
39 |
|
#include "s_gline.h" |
40 |
|
#include "motd.h" |
41 |
< |
#include "ircd_handler.h" |
43 |
< |
#include "msg.h" /* msgtab */ |
41 |
> |
#include "conf.h" |
42 |
|
#include "hostmask.h" |
43 |
|
#include "numeric.h" |
44 |
|
#include "packet.h" |
48 |
|
#include "rng_mt.h" |
49 |
|
#include "s_auth.h" |
50 |
|
#include "s_bsd.h" |
51 |
< |
#include "s_conf.h" |
54 |
< |
#include "s_log.h" |
51 |
> |
#include "log.h" |
52 |
|
#include "s_misc.h" |
53 |
|
#include "s_serv.h" /* try_connections */ |
54 |
|
#include "send.h" |
55 |
|
#include "whowas.h" |
56 |
|
#include "modules.h" |
57 |
|
#include "memory.h" |
58 |
+ |
#include "mempool.h" |
59 |
|
#include "hook.h" |
60 |
|
#include "ircd_getopt.h" |
63 |
– |
#include "balloc.h" |
64 |
– |
#include "motd.h" |
61 |
|
#include "supported.h" |
62 |
|
#include "watch.h" |
63 |
+ |
#include "conf_db.h" |
64 |
+ |
#include "conf_class.h" |
65 |
|
|
66 |
< |
/* Try and find the correct name to use with getrlimit() for setting the max. |
67 |
< |
* number of files allowed to be open by this process. |
68 |
< |
*/ |
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 */ |
76 |
< |
struct config_file_entry ConfigFileEntry; |
77 |
< |
/* server info set from ircd.conf */ |
78 |
< |
struct server_info ServerInfo; |
79 |
< |
/* admin info set from ircd.conf */ |
80 |
< |
struct admin_info AdminInfo = { NULL, NULL, NULL }; |
81 |
< |
struct Counter Count = { 0, 0, 0, 0, 0, 0, 0, 0 }; |
82 |
< |
struct ServerState_t server_state = { 0 }; |
83 |
< |
struct logging_entry ConfigLoggingEntry = { 1, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0} }; |
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 */ |
81 |
|
const char *pidFileName = PPATH; |
82 |
|
|
83 |
|
char **myargv; |
93 |
– |
char ircd_platform[PLATFORMLEN]; |
84 |
|
|
85 |
|
int dorehash = 0; |
86 |
|
int doremotd = 0; |
97 |
– |
time_t nextconnect = 1; /* time for next try_connections call */ |
87 |
|
|
88 |
|
/* Set to zero because it should be initialized later using |
89 |
|
* initialize_server_capabs |
90 |
|
*/ |
91 |
|
int default_server_capabs = 0; |
92 |
< |
|
93 |
< |
#ifdef HAVE_LIBCRYPTO |
94 |
< |
int bio_spare_fd = -1; |
106 |
< |
#endif |
107 |
< |
|
108 |
< |
int splitmode; |
109 |
< |
int splitchecking; |
110 |
< |
int split_users; |
92 |
> |
unsigned int splitmode; |
93 |
> |
unsigned int splitchecking; |
94 |
> |
unsigned int split_users; |
95 |
|
unsigned int split_servers; |
96 |
|
|
97 |
|
/* Do klines the same way hybrid-6 did them, i.e. at the |
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); |
140 |
|
|
141 |
|
static int printVersion = 0; |
142 |
|
|
143 |
< |
struct lgetopt myopts[] = { |
144 |
< |
{"dlinefile", &ConfigFileEntry.dlinefile, |
161 |
< |
STRING, "File to use for dline.conf"}, |
162 |
< |
{"configfile", &ConfigFileEntry.configfile, |
143 |
> |
static struct lgetopt myopts[] = { |
144 |
> |
{"configfile", &ConfigFileEntry.configfile, |
145 |
|
STRING, "File to use for ircd.conf"}, |
146 |
< |
{"klinefile", &ConfigFileEntry.klinefile, |
147 |
< |
STRING, "File to use for kline.conf"}, |
148 |
< |
{"xlinefile", &ConfigFileEntry.xlinefile, |
149 |
< |
STRING, "File to use for xline.conf"}, |
150 |
< |
{"logfile", &logFileName, |
146 |
> |
{"glinefile", &ConfigFileEntry.glinefile, |
147 |
> |
STRING, "File to use for gline database"}, |
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, |
153 |
> |
STRING, "File to use for xline database"}, |
154 |
> |
{"resvfile", &ConfigFileEntry.resvfile, |
155 |
> |
STRING, "File to use for resv database"}, |
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]; |
184 |
< |
struct timeval newtime; |
185 |
< |
newtime.tv_sec = 0; |
186 |
< |
newtime.tv_usec = 0; |
171 |
> |
struct timeval newtime = { .tv_sec = 0, .tv_usec = 0 }; |
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, |
177 |
> |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
178 |
|
"Clock Failure (%s), TS can be corrupted", |
179 |
|
strerror(errno)); |
180 |
|
restart("Clock Failure"); |
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); |
187 |
< |
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(); |
249 |
– |
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); |
247 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, |
248 |
< |
"Got signal SIGUSR1, reloading ircd motd file"); |
246 |
> |
motd_recache(); |
247 |
> |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
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) |
286 |
|
} |
287 |
|
|
288 |
|
GlobalSetOptions.ident_timeout = IDENT_TIMEOUT; |
302 |
– |
GlobalSetOptions.idletime = ConfigFileEntry.idletime; |
289 |
|
/* End of global set options */ |
290 |
|
} |
291 |
|
|
306 |
– |
/* initialize_message_files() |
307 |
– |
* |
308 |
– |
* inputs - none |
309 |
– |
* output - none |
310 |
– |
* side effects - Set up all message files needed, motd etc. |
311 |
– |
*/ |
312 |
– |
static void |
313 |
– |
initialize_message_files(void) |
314 |
– |
{ |
315 |
– |
init_message_file(USER_MOTD, MPATH, &ConfigFileEntry.motd); |
316 |
– |
init_message_file(OPER_MOTD, OPATH, &ConfigFileEntry.opermotd); |
317 |
– |
init_message_file(USER_LINKS, LIPATH, &ConfigFileEntry.linksfile); |
318 |
– |
|
319 |
– |
read_message_file(&ConfigFileEntry.motd); |
320 |
– |
read_message_file(&ConfigFileEntry.opermotd); |
321 |
– |
read_message_file(&ConfigFileEntry.linksfile); |
322 |
– |
|
323 |
– |
init_isupport(); |
324 |
– |
} |
325 |
– |
|
292 |
|
/* initialize_server_capabs() |
293 |
|
* |
294 |
|
* inputs - none |
299 |
|
{ |
300 |
|
add_capability("QS", CAP_QS, 1); |
301 |
|
add_capability("EOB", CAP_EOB, 1); |
302 |
< |
|
337 |
< |
if (ServerInfo.sid != NULL) /* only enable TS6 if we have an SID */ |
338 |
< |
add_capability("TS6", CAP_TS6, 0); |
339 |
< |
|
340 |
< |
add_capability("ZIP", CAP_ZIP, 0); |
302 |
> |
add_capability("TS6", CAP_TS6, 0); |
303 |
|
add_capability("CLUSTER", CAP_CLUSTER, 1); |
304 |
+ |
add_capability("SVS", CAP_SVS, 1); |
305 |
|
#ifdef HALFOPS |
306 |
|
add_capability("HOPS", CAP_HOPS, 1); |
307 |
|
#endif |
316 |
|
static void |
317 |
|
write_pidfile(const char *filename) |
318 |
|
{ |
319 |
< |
FBFILE *fb; |
319 |
> |
FILE *fb; |
320 |
|
|
321 |
< |
if ((fb = fbopen(filename, "w"))) |
321 |
> |
if ((fb = fopen(filename, "w"))) |
322 |
|
{ |
323 |
< |
char buff[32]; |
323 |
> |
char buff[IRCD_BUFSIZE]; |
324 |
|
unsigned int pid = (unsigned int)getpid(); |
362 |
– |
size_t nbytes = ircsprintf(buff, "%u\n", pid); |
325 |
|
|
326 |
< |
if ((fbputs(buff, fb, nbytes) == -1)) |
327 |
< |
ilog(L_ERROR, "Error writing %u to pid file %s (%s)", |
326 |
> |
snprintf(buff, sizeof(buff), "%u\n", pid); |
327 |
> |
|
328 |
> |
if ((fputs(buff, fb) == -1)) |
329 |
> |
ilog(LOG_TYPE_IRCD, "Error writing %u to pid file %s (%s)", |
330 |
|
pid, filename, strerror(errno)); |
331 |
|
|
332 |
< |
fbclose(fb); |
369 |
< |
return; |
332 |
> |
fclose(fb); |
333 |
|
} |
334 |
|
else |
335 |
|
{ |
336 |
< |
ilog(L_ERROR, "Error opening pid file %s", filename); |
336 |
> |
ilog(LOG_TYPE_IRCD, "Error opening pid file %s", filename); |
337 |
|
} |
338 |
|
} |
339 |
|
|
348 |
|
static void |
349 |
|
check_pidfile(const char *filename) |
350 |
|
{ |
351 |
< |
FBFILE *fb; |
352 |
< |
char buff[32]; |
351 |
> |
FILE *fb; |
352 |
> |
char buff[IRCD_BUFSIZE]; |
353 |
|
pid_t pidfromfile; |
354 |
|
|
355 |
|
/* Don't do logging here, since we don't have log() initialised */ |
356 |
< |
if ((fb = fbopen(filename, "r"))) |
356 |
> |
if ((fb = fopen(filename, "r"))) |
357 |
|
{ |
358 |
< |
if (fbgets(buff, 20, fb) == NULL) |
358 |
> |
if (fgets(buff, 20, fb) == NULL) |
359 |
|
{ |
360 |
|
/* log(L_ERROR, "Error reading from pid file %s (%s)", filename, |
361 |
|
* strerror(errno)); |
373 |
|
} |
374 |
|
} |
375 |
|
|
376 |
< |
fbclose(fb); |
376 |
> |
fclose(fb); |
377 |
|
} |
378 |
|
else if (errno != ENOENT) |
379 |
|
{ |
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 |
418 |
|
* side effects - setups SSL context. |
419 |
|
*/ |
420 |
|
static void |
421 |
< |
init_ssl(void) |
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 |
|
|
430 |
|
{ |
431 |
|
const char *s; |
432 |
|
|
433 |
< |
fprintf(stderr, "ERROR: Could not initialize the SSL context -- %s\n", |
433 |
> |
fprintf(stderr, "ERROR: Could not initialize the SSL Server context -- %s\n", |
434 |
|
s = ERR_lib_error_string(ERR_get_error())); |
435 |
< |
ilog(L_CRIT, "ERROR: Could not initialize the SSL context -- %s\n", s); |
435 |
> |
ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Server context -- %s\n", s); |
436 |
|
} |
437 |
|
|
438 |
< |
SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_NO_SSLv2); |
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 |
< |
bio_spare_fd = save_spare_fd("SSL private key validation"); |
445 |
< |
#endif /* HAVE_LIBCRYPTO */ |
446 |
< |
} |
444 |
> |
if ((ServerInfo.client_ctx = SSL_CTX_new(SSLv23_client_method())) == NULL) |
445 |
> |
{ |
446 |
> |
const char *s; |
447 |
|
|
448 |
< |
/* init_callbacks() |
449 |
< |
* |
450 |
< |
* inputs - nothing |
451 |
< |
* output - nothing |
452 |
< |
* side effects - setups standard hook points |
453 |
< |
*/ |
454 |
< |
static void |
455 |
< |
init_callbacks(void) |
456 |
< |
{ |
457 |
< |
iorecv_cb = register_callback("iorecv", iorecv_default); |
483 |
< |
iosend_cb = register_callback("iosend", iosend_default); |
484 |
< |
iorecvctrl_cb = register_callback("iorecvctrl", NULL); |
485 |
< |
iosendctrl_cb = register_callback("iosendctrl", NULL); |
448 |
> |
fprintf(stderr, "ERROR: Could not initialize the SSL Client context -- %s\n", |
449 |
> |
s = ERR_lib_error_string(ERR_get_error())); |
450 |
> |
ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Client context -- %s\n", s); |
451 |
> |
} |
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_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 |
492 |
< |
* us as root, which is a nono |
493 |
< |
*/ |
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"); |
476 |
|
/* It ain't random, but it ought to be a little harder to guess */ |
477 |
|
init_genrand(SystemTime.tv_sec ^ (SystemTime.tv_usec | (getpid() << 20))); |
478 |
|
|
509 |
– |
memset(&me, 0, sizeof(me)); |
510 |
– |
memset(&meLocalUser, 0, sizeof(meLocalUser)); |
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 */ |
514 |
– |
|
515 |
– |
memset(&ServerInfo, 0, sizeof(ServerInfo)); |
516 |
– |
memset(&ServerStats, 0, sizeof(ServerStats)); |
517 |
– |
|
482 |
|
/* Initialise the channel capability usage counts... */ |
483 |
|
init_chcap_usage_counts(); |
484 |
|
|
485 |
|
ConfigFileEntry.dpath = DPATH; |
486 |
< |
ConfigFileEntry.configfile = CPATH; /* Server configuration file */ |
487 |
< |
ConfigFileEntry.klinefile = KPATH; /* Server kline file */ |
488 |
< |
ConfigFileEntry.xlinefile = XPATH; /* Server xline file */ |
489 |
< |
ConfigFileEntry.rxlinefile = RXPATH; /* Server regex xline file */ |
490 |
< |
ConfigFileEntry.rklinefile = RKPATH; /* Server regex kline file */ |
491 |
< |
ConfigFileEntry.dlinefile = DLPATH; /* dline file */ |
492 |
< |
ConfigFileEntry.glinefile = GPATH; /* gline log file */ |
529 |
< |
ConfigFileEntry.cresvfile = CRESVPATH; /* channel resv file */ |
530 |
< |
ConfigFileEntry.nresvfile = NRESVPATH; /* nick resv file */ |
486 |
> |
ConfigFileEntry.configfile = CPATH; /* Server configuration file */ |
487 |
> |
ConfigFileEntry.klinefile = KPATH; /* Server kline file */ |
488 |
> |
ConfigFileEntry.glinefile = GPATH; /* Server gline file */ |
489 |
> |
ConfigFileEntry.xlinefile = XPATH; /* Server xline file */ |
490 |
> |
ConfigFileEntry.dlinefile = DLPATH; /* dline file */ |
491 |
> |
ConfigFileEntry.resvfile = RESVPATH; /* resv file */ |
492 |
> |
|
493 |
|
myargv = argv; |
494 |
|
umask(077); /* better safe than sorry --SRB */ |
495 |
|
|
497 |
|
|
498 |
|
if (printVersion) |
499 |
|
{ |
500 |
< |
printf("ircd: version %s\n", ircd_version); |
500 |
> |
printf("ircd: version %s(%s)\n", ircd_version, serno); |
501 |
|
exit(EXIT_SUCCESS); |
502 |
|
} |
503 |
|
|
507 |
|
exit(EXIT_FAILURE); |
508 |
|
} |
509 |
|
|
510 |
< |
init_ssl(); |
510 |
> |
ssl_init(); |
511 |
|
|
512 |
|
if (!server_state.foreground) |
513 |
|
{ |
519 |
|
|
520 |
|
setup_signals(); |
521 |
|
|
560 |
– |
get_ircd_platform(ircd_platform); |
561 |
– |
|
522 |
|
/* Init the event subsystem */ |
523 |
|
eventInit(); |
524 |
+ |
|
525 |
|
/* We need this to initialise the fd array before anything else */ |
526 |
|
fdlist_init(); |
527 |
< |
init_log(logFileName); |
527 |
> |
log_set_file(LOG_TYPE_IRCD, 0, logFileName); |
528 |
|
check_can_use_v6(); |
529 |
< |
init_comm(); /* This needs to be setup early ! -- adrian */ |
529 |
> |
init_netio(); /* This needs to be setup early ! -- adrian */ |
530 |
> |
|
531 |
|
/* Check if there is pidfile and daemon already running */ |
532 |
|
check_pidfile(pidFileName); |
533 |
|
|
534 |
< |
#ifndef NOBALLOC |
573 |
< |
initBlockHeap(); |
574 |
< |
#endif |
534 |
> |
mp_pool_init(); |
535 |
|
init_dlink_nodes(); |
536 |
< |
init_callbacks(); |
577 |
< |
initialize_message_files(); |
536 |
> |
init_isupport(); |
537 |
|
dbuf_init(); |
538 |
< |
init_hash(); |
538 |
> |
hash_init(); |
539 |
|
init_ip_hash_table(); /* client host ip hash table */ |
540 |
|
init_host_hash(); /* Host-hashtable. */ |
541 |
< |
clear_tree_parse(); |
542 |
< |
init_client(); |
543 |
< |
init_class(); |
585 |
< |
init_whowas(); |
541 |
> |
client_init(); |
542 |
> |
class_init(); |
543 |
> |
whowas_init(); |
544 |
|
watch_init(); |
545 |
< |
init_auth(); /* Initialise the auth code */ |
545 |
> |
auth_init(); /* Initialise the auth code */ |
546 |
|
init_resolver(); /* Needs to be setup before the io loop */ |
547 |
+ |
modules_init(); |
548 |
|
read_conf_files(1); /* cold start init conf files */ |
590 |
– |
me.id[0] = '\0'; |
549 |
|
init_uid(); |
550 |
|
initialize_server_capabs(); /* Set up default_server_capabs */ |
551 |
|
initialize_global_set_options(); |
552 |
< |
init_channels(); |
552 |
> |
channel_init(); |
553 |
> |
read_links_file(); |
554 |
> |
motd_init(); |
555 |
> |
#ifdef HAVE_LIBGEOIP |
556 |
> |
geoip_ctx = GeoIP_new(GEOIP_MEMORY_CACHE); |
557 |
> |
#endif |
558 |
|
|
559 |
< |
if (ServerInfo.name == NULL) |
559 |
> |
if (EmptyString(ServerInfo.sid)) |
560 |
|
{ |
561 |
< |
ilog(L_CRIT, "No server name specified in serverinfo block."); |
561 |
> |
ilog(LOG_TYPE_IRCD, "ERROR: No server id specified in serverinfo block."); |
562 |
> |
exit(EXIT_FAILURE); |
563 |
> |
} |
564 |
> |
|
565 |
> |
strlcpy(me.id, ServerInfo.sid, sizeof(me.id)); |
566 |
> |
|
567 |
> |
if (EmptyString(ServerInfo.name)) |
568 |
> |
{ |
569 |
> |
ilog(LOG_TYPE_IRCD, "ERROR: No server name specified in serverinfo block."); |
570 |
|
exit(EXIT_FAILURE); |
571 |
|
} |
572 |
|
|
573 |
|
strlcpy(me.name, ServerInfo.name, sizeof(me.name)); |
574 |
|
|
575 |
|
/* serverinfo{} description must exist. If not, error out.*/ |
576 |
< |
if (ServerInfo.description == NULL) |
576 |
> |
if (EmptyString(ServerInfo.description)) |
577 |
|
{ |
578 |
< |
ilog(L_CRIT, |
608 |
< |
"ERROR: No server description specified in serverinfo block."); |
578 |
> |
ilog(LOG_TYPE_IRCD, "ERROR: No server description specified in serverinfo block."); |
579 |
|
exit(EXIT_FAILURE); |
580 |
|
} |
581 |
|
|
582 |
|
strlcpy(me.info, ServerInfo.description, sizeof(me.info)); |
583 |
|
|
584 |
< |
me.from = &me; |
585 |
< |
me.servptr = &me; |
584 |
> |
me.from = &me; |
585 |
> |
me.servptr = &me; |
586 |
> |
me.localClient->lasttime = CurrentTime; |
587 |
> |
me.localClient->since = CurrentTime; |
588 |
> |
me.localClient->firsttime = CurrentTime; |
589 |
|
|
590 |
|
SetMe(&me); |
591 |
|
make_server(&me); |
592 |
|
|
593 |
< |
me.lasttime = me.since = me.firsttime = CurrentTime; |
593 |
> |
hash_add_id(&me); |
594 |
|
hash_add_client(&me); |
595 |
< |
|
595 |
> |
|
596 |
|
/* add ourselves to global_serv_list */ |
597 |
|
dlinkAdd(&me, make_dlink_node(), &global_serv_list); |
598 |
|
|
599 |
< |
check_class(); |
599 |
> |
load_kline_database(); |
600 |
> |
load_dline_database(); |
601 |
> |
load_gline_database(); |
602 |
> |
load_xline_database(); |
603 |
> |
load_resv_database(); |
604 |
|
|
628 |
– |
#ifndef STATIC_MODULES |
605 |
|
if (chdir(MODPATH)) |
606 |
|
{ |
607 |
< |
ilog (L_CRIT, "Could not load core modules. Terminating!"); |
607 |
> |
ilog(LOG_TYPE_IRCD, "Could not load core modules. Terminating!"); |
608 |
|
exit(EXIT_FAILURE); |
609 |
|
} |
610 |
|
|
611 |
|
load_all_modules(1); |
612 |
|
load_conf_modules(); |
613 |
|
load_core_modules(1); |
614 |
+ |
|
615 |
|
/* Go back to DPATH after checking to see if we can chdir to MODPATH */ |
616 |
< |
chdir(ConfigFileEntry.dpath); |
617 |
< |
#else |
618 |
< |
load_all_modules(1); |
619 |
< |
#endif |
616 |
> |
if (chdir(ConfigFileEntry.dpath)) |
617 |
> |
{ |
618 |
> |
perror("chdir"); |
619 |
> |
exit(EXIT_FAILURE); |
620 |
> |
} |
621 |
> |
|
622 |
|
/* |
623 |
|
* assemble_umode_buffer() has to be called after |
624 |
|
* reading conf/loading modules. |
627 |
|
|
628 |
|
write_pidfile(pidFileName); |
629 |
|
|
630 |
< |
ilog(L_NOTICE, "Server Ready"); |
630 |
> |
ilog(LOG_TYPE_IRCD, "Server Ready"); |
631 |
|
|
632 |
|
eventAddIsh("cleanup_glines", cleanup_glines, NULL, CLEANUP_GLINES_TIME); |
633 |
|
eventAddIsh("cleanup_tklines", cleanup_tklines, NULL, CLEANUP_TKLINES_TIME); |
636 |
|
/* No, 'cause after a restart it would cause all sorts of nick collides */ |
637 |
|
eventAddIsh("try_connections", try_connections, NULL, STARTUP_CONNECTIONS_TIME); |
638 |
|
|
660 |
– |
eventAddIsh("collect_zipstats", collect_zipstats, NULL, ZIPSTATS_TIME); |
661 |
– |
|
639 |
|
/* Setup the timeout check. I'll shift it later :) -- adrian */ |
640 |
|
eventAddIsh("comm_checktimeouts", comm_checktimeouts, NULL, 1); |
641 |
|
|
642 |
+ |
eventAddIsh("save_all_databases", save_all_databases, NULL, DATABASE_UPDATE_TIMEOUT); |
643 |
+ |
|
644 |
|
if (ConfigServerHide.links_delay > 0) |
645 |
|
eventAddIsh("write_links_file", write_links_file, NULL, ConfigServerHide.links_delay); |
646 |
|
else |