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" |
28 |
> |
#include "user.h" |
29 |
> |
#include "list.h" |
30 |
|
#include "ircd.h" |
31 |
|
#include "channel.h" |
30 |
– |
#include "channel_mode.h" |
32 |
|
#include "client.h" |
32 |
– |
#include "common.h" |
33 |
|
#include "event.h" |
34 |
|
#include "fdlist.h" |
35 |
|
#include "hash.h" |
36 |
|
#include "irc_string.h" |
37 |
– |
#include "sprintf_irc.h" |
37 |
|
#include "ircd_signal.h" |
38 |
< |
#include "list.h" |
40 |
< |
#include "s_gline.h" |
38 |
> |
#include "gline.h" |
39 |
|
#include "motd.h" |
40 |
< |
#include "ircd_handler.h" |
43 |
< |
#include "msg.h" /* msgtab */ |
40 |
> |
#include "conf.h" |
41 |
|
#include "hostmask.h" |
45 |
– |
#include "numeric.h" |
46 |
– |
#include "packet.h" |
42 |
|
#include "parse.h" |
43 |
< |
#include "irc_res.h" |
43 |
> |
#include "res.h" |
44 |
|
#include "restart.h" |
45 |
|
#include "rng_mt.h" |
46 |
< |
#include "s_auth.h" |
46 |
> |
#include "auth.h" |
47 |
|
#include "s_bsd.h" |
48 |
< |
#include "s_conf.h" |
49 |
< |
#include "s_log.h" |
55 |
< |
#include "s_misc.h" |
56 |
< |
#include "s_serv.h" /* try_connections */ |
48 |
> |
#include "log.h" |
49 |
> |
#include "server.h" /* try_connections */ |
50 |
|
#include "send.h" |
51 |
|
#include "whowas.h" |
52 |
|
#include "modules.h" |
53 |
|
#include "memory.h" |
54 |
< |
#include "hook.h" |
54 |
> |
#include "mempool.h" |
55 |
|
#include "ircd_getopt.h" |
63 |
– |
#include "balloc.h" |
64 |
– |
#include "motd.h" |
56 |
|
#include "supported.h" |
57 |
|
#include "watch.h" |
58 |
+ |
#include "conf_db.h" |
59 |
+ |
#include "conf_class.h" |
60 |
|
|
61 |
< |
/* Try and find the correct name to use with getrlimit() for setting the max. |
62 |
< |
* number of files allowed to be open by this process. |
63 |
< |
*/ |
61 |
> |
|
62 |
> |
#ifdef HAVE_LIBGEOIP |
63 |
> |
GeoIP *geoip_ctx; |
64 |
> |
#endif |
65 |
|
|
66 |
|
/* /quote set variables */ |
67 |
|
struct SetOptions GlobalSetOptions; |
68 |
< |
|
69 |
< |
/* 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} }; |
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 */ |
76 |
|
const char *pidFileName = PPATH; |
77 |
|
|
78 |
|
char **myargv; |
93 |
– |
char ircd_platform[PLATFORMLEN]; |
79 |
|
|
80 |
|
int dorehash = 0; |
81 |
|
int doremotd = 0; |
97 |
– |
time_t nextconnect = 1; /* time for next try_connections call */ |
82 |
|
|
83 |
|
/* Set to zero because it should be initialized later using |
84 |
|
* initialize_server_capabs |
85 |
|
*/ |
86 |
|
int default_server_capabs = 0; |
87 |
< |
|
88 |
< |
#ifdef HAVE_LIBCRYPTO |
89 |
< |
int bio_spare_fd = -1; |
106 |
< |
#endif |
107 |
< |
|
108 |
< |
int splitmode; |
109 |
< |
int splitchecking; |
110 |
< |
int split_users; |
87 |
> |
unsigned int splitmode; |
88 |
> |
unsigned int splitchecking; |
89 |
> |
unsigned int split_users; |
90 |
|
unsigned int split_servers; |
91 |
|
|
92 |
|
/* Do klines the same way hybrid-6 did them, i.e. at the |
102 |
|
int rehashed_klines = 0; |
103 |
|
|
104 |
|
|
126 |
– |
#ifndef _WIN32 |
105 |
|
/* |
106 |
|
* print_startup - print startup information |
107 |
|
*/ |
108 |
|
static void |
109 |
|
print_startup(int pid) |
110 |
|
{ |
111 |
< |
printf("ircd: version %s\n", ircd_version); |
111 |
> |
printf("ircd: version %s(%s)\n", ircd_version, serno); |
112 |
|
printf("ircd: pid %d\n", pid); |
113 |
|
printf("ircd: running in %s mode from %s\n", !server_state.foreground ? "background" |
114 |
|
: "foreground", ConfigFileEntry.dpath); |
132 |
|
|
133 |
|
setsid(); |
134 |
|
} |
157 |
– |
#endif |
135 |
|
|
136 |
|
static int printVersion = 0; |
137 |
|
|
138 |
< |
struct lgetopt myopts[] = { |
139 |
< |
{"dlinefile", &ConfigFileEntry.dlinefile, |
140 |
< |
STRING, "File to use for dline.conf"}, |
164 |
< |
{"configfile", &ConfigFileEntry.configfile, |
138 |
> |
static struct lgetopt myopts[] = |
139 |
> |
{ |
140 |
> |
{"configfile", &ConfigFileEntry.configfile, |
141 |
|
STRING, "File to use for ircd.conf"}, |
142 |
< |
{"klinefile", &ConfigFileEntry.klinefile, |
143 |
< |
STRING, "File to use for kline.conf"}, |
144 |
< |
{"xlinefile", &ConfigFileEntry.xlinefile, |
145 |
< |
STRING, "File to use for xline.conf"}, |
146 |
< |
{"logfile", &logFileName, |
142 |
> |
{"glinefile", &ConfigFileEntry.glinefile, |
143 |
> |
STRING, "File to use for gline database"}, |
144 |
> |
{"klinefile", &ConfigFileEntry.klinefile, |
145 |
> |
STRING, "File to use for kline database"}, |
146 |
> |
{"dlinefile", &ConfigFileEntry.dlinefile, |
147 |
> |
STRING, "File to use for dline database"}, |
148 |
> |
{"xlinefile", &ConfigFileEntry.xlinefile, |
149 |
> |
STRING, "File to use for xline database"}, |
150 |
> |
{"resvfile", &ConfigFileEntry.resvfile, |
151 |
> |
STRING, "File to use for resv database"}, |
152 |
> |
{"logfile", &logFileName, |
153 |
|
STRING, "File to use for ircd.log"}, |
154 |
|
{"pidfile", &pidFileName, |
155 |
|
STRING, "File to use for process ID"}, |
156 |
< |
{"foreground", &server_state.foreground, |
156 |
> |
{"foreground", &server_state.foreground, |
157 |
|
YESNO, "Run in foreground (don't detach)"}, |
158 |
< |
{"version", &printVersion, |
158 |
> |
{"version", &printVersion, |
159 |
|
YESNO, "Print version and exit"}, |
160 |
|
{"help", NULL, USAGE, "Print this text"}, |
161 |
|
{NULL, NULL, STRING, NULL}, |
164 |
|
void |
165 |
|
set_time(void) |
166 |
|
{ |
167 |
< |
static char to_send[200]; |
186 |
< |
struct timeval newtime; |
187 |
< |
#ifdef _WIN32 |
188 |
< |
FILETIME ft; |
189 |
< |
|
190 |
< |
GetSystemTimeAsFileTime(&ft); |
191 |
< |
if (ft.dwLowDateTime < 0xd53e8000) |
192 |
< |
ft.dwHighDateTime--; |
193 |
< |
ft.dwLowDateTime -= 0xd53e8000; |
194 |
< |
ft.dwHighDateTime -= 0x19db1de; |
195 |
< |
|
196 |
< |
newtime.tv_sec = (*(uint64_t *) &ft) / 10000000; |
197 |
< |
newtime.tv_usec = (*(uint64_t *) &ft) / 10 % 1000000; |
198 |
< |
#else |
199 |
< |
newtime.tv_sec = 0; |
200 |
< |
newtime.tv_usec = 0; |
167 |
> |
struct timeval newtime = { .tv_sec = 0, .tv_usec = 0 }; |
168 |
|
|
169 |
|
if (gettimeofday(&newtime, NULL) == -1) |
170 |
|
{ |
171 |
< |
ilog(L_ERROR, "Clock Failure (%s), TS can be corrupted", |
171 |
> |
ilog(LOG_TYPE_IRCD, "Clock Failure (%s), TS can be corrupted", |
172 |
|
strerror(errno)); |
173 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, |
173 |
> |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
174 |
|
"Clock Failure (%s), TS can be corrupted", |
175 |
|
strerror(errno)); |
176 |
< |
restart("Clock Failure"); |
176 |
> |
server_die("Clock Failure", 1); |
177 |
|
} |
211 |
– |
#endif |
178 |
|
|
179 |
|
if (newtime.tv_sec < CurrentTime) |
180 |
|
{ |
181 |
< |
ircsprintf(to_send, "System clock is running backwards - (%lu < %lu)", |
182 |
< |
(unsigned long)newtime.tv_sec, (unsigned long)CurrentTime); |
183 |
< |
report_error(L_ALL, to_send, me.name, 0); |
181 |
> |
ilog(LOG_TYPE_IRCD, "System clock is running backwards - (%lu < %lu)", |
182 |
> |
(unsigned long)newtime.tv_sec, (unsigned long)CurrentTime); |
183 |
> |
sendto_realops_flags(UMODE_DEBUG, L_ALL, SEND_NOTICE, |
184 |
> |
"System clock is running backwards - (%lu < %lu)", |
185 |
> |
(unsigned long)newtime.tv_sec, |
186 |
> |
(unsigned long)CurrentTime); |
187 |
|
set_back_events(CurrentTime - newtime.tv_sec); |
188 |
|
} |
189 |
|
|
194 |
|
static void |
195 |
|
io_loop(void) |
196 |
|
{ |
197 |
< |
while (1 == 1) |
197 |
> |
while (1) |
198 |
|
{ |
199 |
|
/* |
200 |
|
* Maybe we want a flags word? |
201 |
< |
* ie. if (REHASHED_KLINES(global_flags)) |
201 |
> |
* ie. if (REHASHED_KLINES(global_flags)) |
202 |
|
* SET_REHASHED_KLINES(global_flags) |
203 |
|
* CLEAR_REHASHED_KLINES(global_flags) |
204 |
|
* |
214 |
|
{ |
215 |
|
dlink_node *ptr = NULL, *ptr_next = NULL; |
216 |
|
DLINK_FOREACH_SAFE(ptr, ptr_next, listing_client_list.head) |
217 |
< |
{ |
249 |
< |
struct Client *client_p = ptr->data; |
250 |
< |
assert(client_p->localClient->list_task); |
251 |
< |
safe_list_channels(client_p, client_p->localClient->list_task, 0); |
252 |
< |
} |
217 |
> |
safe_list_channels(ptr->data, 0); |
218 |
|
} |
219 |
|
|
220 |
|
/* Run pending events, then get the number of seconds to the next |
226 |
|
comm_select(); |
227 |
|
exit_aborted_clients(); |
228 |
|
free_exited_clients(); |
264 |
– |
send_queued_all(); |
229 |
|
|
230 |
|
/* Check to see whether we have to rehash the configuration .. */ |
231 |
|
if (dorehash) |
233 |
|
rehash(1); |
234 |
|
dorehash = 0; |
235 |
|
} |
236 |
+ |
|
237 |
|
if (doremotd) |
238 |
|
{ |
239 |
< |
read_message_file(&ConfigFileEntry.motd); |
240 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, |
241 |
< |
"Got signal SIGUSR1, reloading ircd motd file"); |
239 |
> |
motd_recache(); |
240 |
> |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
241 |
> |
"Got signal SIGUSR1, reloading motd file(s)"); |
242 |
|
doremotd = 0; |
243 |
|
} |
244 |
|
} |
248 |
|
* |
249 |
|
* inputs - none |
250 |
|
* output - none |
251 |
< |
* side effects - This sets all global set options needed |
251 |
> |
* side effects - This sets all global set options needed |
252 |
|
*/ |
253 |
|
static void |
254 |
|
initialize_global_set_options(void) |
279 |
|
} |
280 |
|
|
281 |
|
GlobalSetOptions.ident_timeout = IDENT_TIMEOUT; |
317 |
– |
GlobalSetOptions.idletime = ConfigFileEntry.idletime; |
282 |
|
/* End of global set options */ |
283 |
|
} |
284 |
|
|
321 |
– |
/* initialize_message_files() |
322 |
– |
* |
323 |
– |
* inputs - none |
324 |
– |
* output - none |
325 |
– |
* side effects - Set up all message files needed, motd etc. |
326 |
– |
*/ |
327 |
– |
static void |
328 |
– |
initialize_message_files(void) |
329 |
– |
{ |
330 |
– |
init_message_file(USER_MOTD, MPATH, &ConfigFileEntry.motd); |
331 |
– |
init_message_file(OPER_MOTD, OPATH, &ConfigFileEntry.opermotd); |
332 |
– |
init_message_file(USER_LINKS, LIPATH, &ConfigFileEntry.linksfile); |
333 |
– |
|
334 |
– |
read_message_file(&ConfigFileEntry.motd); |
335 |
– |
read_message_file(&ConfigFileEntry.opermotd); |
336 |
– |
read_message_file(&ConfigFileEntry.linksfile); |
337 |
– |
|
338 |
– |
init_isupport(); |
339 |
– |
} |
340 |
– |
|
285 |
|
/* initialize_server_capabs() |
286 |
|
* |
287 |
|
* inputs - none |
292 |
|
{ |
293 |
|
add_capability("QS", CAP_QS, 1); |
294 |
|
add_capability("EOB", CAP_EOB, 1); |
295 |
< |
|
352 |
< |
if (ServerInfo.sid != NULL) /* only enable TS6 if we have an SID */ |
353 |
< |
add_capability("TS6", CAP_TS6, 0); |
354 |
< |
|
355 |
< |
add_capability("ZIP", CAP_ZIP, 0); |
295 |
> |
add_capability("TS6", CAP_TS6, 0); |
296 |
|
add_capability("CLUSTER", CAP_CLUSTER, 1); |
297 |
+ |
add_capability("SVS", CAP_SVS, 1); |
298 |
+ |
add_capability("CHW", CAP_CHW, 1); |
299 |
|
#ifdef HALFOPS |
300 |
|
add_capability("HOPS", CAP_HOPS, 1); |
301 |
|
#endif |
310 |
|
static void |
311 |
|
write_pidfile(const char *filename) |
312 |
|
{ |
313 |
< |
FBFILE *fb; |
313 |
> |
FILE *fb; |
314 |
|
|
315 |
< |
if ((fb = fbopen(filename, "w"))) |
315 |
> |
if ((fb = fopen(filename, "w"))) |
316 |
|
{ |
317 |
< |
char buff[32]; |
317 |
> |
char buff[IRCD_BUFSIZE]; |
318 |
|
unsigned int pid = (unsigned int)getpid(); |
377 |
– |
size_t nbytes = ircsprintf(buff, "%u\n", pid); |
319 |
|
|
320 |
< |
if ((fbputs(buff, fb, nbytes) == -1)) |
321 |
< |
ilog(L_ERROR, "Error writing %u to pid file %s (%s)", |
320 |
> |
snprintf(buff, sizeof(buff), "%u\n", pid); |
321 |
> |
|
322 |
> |
if ((fputs(buff, fb) == -1)) |
323 |
> |
ilog(LOG_TYPE_IRCD, "Error writing %u to pid file %s (%s)", |
324 |
|
pid, filename, strerror(errno)); |
325 |
|
|
326 |
< |
fbclose(fb); |
384 |
< |
return; |
326 |
> |
fclose(fb); |
327 |
|
} |
328 |
|
else |
329 |
|
{ |
330 |
< |
ilog(L_ERROR, "Error opening pid file %s", filename); |
330 |
> |
ilog(LOG_TYPE_IRCD, "Error opening pid file %s", filename); |
331 |
|
} |
332 |
|
} |
333 |
|
|
342 |
|
static void |
343 |
|
check_pidfile(const char *filename) |
344 |
|
{ |
345 |
< |
#ifndef _WIN32 |
346 |
< |
FBFILE *fb; |
405 |
< |
char buff[32]; |
345 |
> |
FILE *fb; |
346 |
> |
char buff[IRCD_BUFSIZE]; |
347 |
|
pid_t pidfromfile; |
348 |
|
|
349 |
|
/* Don't do logging here, since we don't have log() initialised */ |
350 |
< |
if ((fb = fbopen(filename, "r"))) |
350 |
> |
if ((fb = fopen(filename, "r"))) |
351 |
|
{ |
352 |
< |
if (fbgets(buff, 20, fb) == NULL) |
352 |
> |
if (fgets(buff, 20, fb) == NULL) |
353 |
|
{ |
354 |
|
/* log(L_ERROR, "Error reading from pid file %s (%s)", filename, |
355 |
|
* strerror(errno)); |
367 |
|
} |
368 |
|
} |
369 |
|
|
370 |
< |
fbclose(fb); |
370 |
> |
fclose(fb); |
371 |
|
} |
372 |
|
else if (errno != ENOENT) |
373 |
|
{ |
374 |
|
/* log(L_ERROR, "Error opening pid file %s", filename); */ |
375 |
|
} |
435 |
– |
#endif |
376 |
|
} |
377 |
|
|
378 |
|
/* setup_corefile() |
397 |
|
#endif |
398 |
|
} |
399 |
|
|
400 |
+ |
#ifdef HAVE_LIBCRYPTO |
401 |
+ |
static int |
402 |
+ |
always_accept_verify_cb(int preverify_ok, X509_STORE_CTX *x509_ctx) |
403 |
+ |
{ |
404 |
+ |
return 1; |
405 |
+ |
} |
406 |
+ |
#endif |
407 |
+ |
|
408 |
|
/* init_ssl() |
409 |
|
* |
410 |
|
* inputs - nothing |
412 |
|
* side effects - setups SSL context. |
413 |
|
*/ |
414 |
|
static void |
415 |
< |
init_ssl(void) |
415 |
> |
ssl_init(void) |
416 |
|
{ |
417 |
|
#ifdef HAVE_LIBCRYPTO |
418 |
+ |
const unsigned char session_id[] = "ircd-hybrid"; |
419 |
+ |
|
420 |
|
SSL_load_error_strings(); |
421 |
|
SSLeay_add_ssl_algorithms(); |
422 |
|
|
424 |
|
{ |
425 |
|
const char *s; |
426 |
|
|
427 |
< |
fprintf(stderr, "ERROR: Could not initialize the SSL context -- %s\n", |
427 |
> |
fprintf(stderr, "ERROR: Could not initialize the SSL Server context -- %s\n", |
428 |
|
s = ERR_lib_error_string(ERR_get_error())); |
429 |
< |
ilog(L_CRIT, "ERROR: Could not initialize the SSL context -- %s\n", s); |
429 |
> |
ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Server context -- %s\n", s); |
430 |
|
} |
431 |
|
|
432 |
< |
SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_NO_SSLv2); |
432 |
> |
SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TLSv1); |
433 |
|
SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_TLS_ROLLBACK_BUG|SSL_OP_ALL); |
434 |
< |
SSL_CTX_set_verify(ServerInfo.server_ctx, SSL_VERIFY_NONE, NULL); |
434 |
> |
SSL_CTX_set_verify(ServerInfo.server_ctx, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE, |
435 |
> |
always_accept_verify_cb); |
436 |
> |
SSL_CTX_set_session_id_context(ServerInfo.server_ctx, session_id, sizeof(session_id) - 1); |
437 |
|
|
438 |
< |
bio_spare_fd = save_spare_fd("SSL private key validation"); |
439 |
< |
#endif /* HAVE_LIBCRYPTO */ |
440 |
< |
} |
438 |
> |
if ((ServerInfo.client_ctx = SSL_CTX_new(SSLv23_client_method())) == NULL) |
439 |
> |
{ |
440 |
> |
const char *s; |
441 |
|
|
442 |
< |
/* init_callbacks() |
443 |
< |
* |
444 |
< |
* inputs - nothing |
445 |
< |
* output - nothing |
446 |
< |
* side effects - setups standard hook points |
447 |
< |
*/ |
448 |
< |
static void |
449 |
< |
init_callbacks(void) |
450 |
< |
{ |
451 |
< |
iorecv_cb = register_callback("iorecv", iorecv_default); |
500 |
< |
iosend_cb = register_callback("iosend", iosend_default); |
501 |
< |
iorecvctrl_cb = register_callback("iorecvctrl", NULL); |
502 |
< |
iosendctrl_cb = register_callback("iosendctrl", NULL); |
442 |
> |
fprintf(stderr, "ERROR: Could not initialize the SSL Client context -- %s\n", |
443 |
> |
s = ERR_lib_error_string(ERR_get_error())); |
444 |
> |
ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Client context -- %s\n", s); |
445 |
> |
} |
446 |
> |
|
447 |
> |
SSL_CTX_set_options(ServerInfo.client_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TLSv1); |
448 |
> |
SSL_CTX_set_options(ServerInfo.client_ctx, SSL_OP_TLS_ROLLBACK_BUG|SSL_OP_ALL); |
449 |
> |
SSL_CTX_set_verify(ServerInfo.client_ctx, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE, |
450 |
> |
always_accept_verify_cb); |
451 |
> |
#endif /* HAVE_LIBCRYPTO */ |
452 |
|
} |
453 |
|
|
454 |
|
int |
455 |
|
main(int argc, char *argv[]) |
456 |
|
{ |
457 |
< |
/* Check to see if the user is running |
509 |
< |
* us as root, which is a nono |
510 |
< |
*/ |
511 |
< |
#ifndef _WIN32 |
457 |
> |
/* Check to see if the user is running us as root, which is a nono */ |
458 |
|
if (geteuid() == 0) |
459 |
|
{ |
460 |
|
fprintf(stderr, "Don't run ircd as root!!!\n"); |
463 |
|
|
464 |
|
/* Setup corefile size immediately after boot -kre */ |
465 |
|
setup_corefile(); |
520 |
– |
#endif |
466 |
|
|
467 |
|
/* save server boot time right away, so getrusage works correctly */ |
468 |
|
set_time(); |
470 |
|
/* It ain't random, but it ought to be a little harder to guess */ |
471 |
|
init_genrand(SystemTime.tv_sec ^ (SystemTime.tv_usec | (getpid() << 20))); |
472 |
|
|
528 |
– |
memset(&me, 0, sizeof(me)); |
529 |
– |
memset(&meLocalUser, 0, sizeof(meLocalUser)); |
473 |
|
me.localClient = &meLocalUser; |
474 |
< |
dlinkAdd(&me, &me.node, &global_client_list); /* Pointer to beginning |
474 |
> |
dlinkAdd(&me, &me.node, &global_client_list); /* Pointer to beginning |
475 |
|
of Client list */ |
533 |
– |
|
534 |
– |
memset(&ServerInfo, 0, sizeof(ServerInfo)); |
535 |
– |
memset(&ServerStats, 0, sizeof(ServerStats)); |
536 |
– |
|
537 |
– |
/* Initialise the channel capability usage counts... */ |
538 |
– |
init_chcap_usage_counts(); |
539 |
– |
|
476 |
|
ConfigFileEntry.dpath = DPATH; |
477 |
< |
ConfigFileEntry.configfile = CPATH; /* Server configuration file */ |
478 |
< |
ConfigFileEntry.klinefile = KPATH; /* Server kline file */ |
479 |
< |
ConfigFileEntry.xlinefile = XPATH; /* Server xline file */ |
480 |
< |
ConfigFileEntry.rxlinefile = RXPATH; /* Server regex xline file */ |
481 |
< |
ConfigFileEntry.rklinefile = RKPATH; /* Server regex kline file */ |
482 |
< |
ConfigFileEntry.dlinefile = DLPATH; /* dline file */ |
483 |
< |
ConfigFileEntry.glinefile = GPATH; /* gline log file */ |
484 |
< |
ConfigFileEntry.cresvfile = CRESVPATH; /* channel resv file */ |
485 |
< |
ConfigFileEntry.nresvfile = NRESVPATH; /* nick resv file */ |
477 |
> |
ConfigFileEntry.spath = SPATH; |
478 |
> |
ConfigFileEntry.mpath = MPATH; |
479 |
> |
ConfigFileEntry.configfile = CPATH; /* Server configuration file */ |
480 |
> |
ConfigFileEntry.klinefile = KPATH; /* Server kline file */ |
481 |
> |
ConfigFileEntry.glinefile = GPATH; /* Server gline file */ |
482 |
> |
ConfigFileEntry.xlinefile = XPATH; /* Server xline file */ |
483 |
> |
ConfigFileEntry.dlinefile = DLPATH; /* dline file */ |
484 |
> |
ConfigFileEntry.resvfile = RESVPATH; /* resv file */ |
485 |
> |
|
486 |
|
myargv = argv; |
487 |
|
umask(077); /* better safe than sorry --SRB */ |
488 |
|
|
490 |
|
|
491 |
|
if (printVersion) |
492 |
|
{ |
493 |
< |
printf("ircd: version %s\n", ircd_version); |
493 |
> |
printf("ircd: version %s(%s)\n", ircd_version, serno); |
494 |
|
exit(EXIT_SUCCESS); |
495 |
|
} |
496 |
|
|
500 |
|
exit(EXIT_FAILURE); |
501 |
|
} |
502 |
|
|
503 |
< |
init_ssl(); |
503 |
> |
ssl_init(); |
504 |
|
|
569 |
– |
#ifndef _WIN32 |
505 |
|
if (!server_state.foreground) |
506 |
|
{ |
507 |
|
make_daemon(); |
511 |
|
print_startup(getpid()); |
512 |
|
|
513 |
|
setup_signals(); |
579 |
– |
#endif |
580 |
– |
|
581 |
– |
get_ircd_platform(ircd_platform); |
514 |
|
|
515 |
|
/* Init the event subsystem */ |
516 |
|
eventInit(); |
517 |
+ |
|
518 |
|
/* We need this to initialise the fd array before anything else */ |
519 |
|
fdlist_init(); |
520 |
< |
init_log(logFileName); |
520 |
> |
log_set_file(LOG_TYPE_IRCD, 0, logFileName); |
521 |
|
check_can_use_v6(); |
522 |
< |
init_comm(); /* This needs to be setup early ! -- adrian */ |
522 |
> |
init_netio(); /* This needs to be setup early ! -- adrian */ |
523 |
> |
|
524 |
|
/* Check if there is pidfile and daemon already running */ |
525 |
|
check_pidfile(pidFileName); |
526 |
|
|
527 |
< |
#ifndef NOBALLOC |
594 |
< |
initBlockHeap(); |
595 |
< |
#endif |
527 |
> |
mp_pool_init(); |
528 |
|
init_dlink_nodes(); |
529 |
< |
init_callbacks(); |
598 |
< |
initialize_message_files(); |
529 |
> |
init_isupport(); |
530 |
|
dbuf_init(); |
531 |
< |
init_hash(); |
531 |
> |
hash_init(); |
532 |
|
init_ip_hash_table(); /* client host ip hash table */ |
533 |
|
init_host_hash(); /* Host-hashtable. */ |
534 |
< |
clear_tree_parse(); |
535 |
< |
init_client(); |
536 |
< |
init_class(); |
606 |
< |
init_whowas(); |
534 |
> |
client_init(); |
535 |
> |
class_init(); |
536 |
> |
whowas_init(); |
537 |
|
watch_init(); |
538 |
+ |
auth_init(); /* Initialise the auth code */ |
539 |
+ |
init_resolver(); /* Needs to be setup before the io loop */ |
540 |
+ |
modules_init(); |
541 |
|
read_conf_files(1); /* cold start init conf files */ |
609 |
– |
me.id[0] = '\0'; |
542 |
|
init_uid(); |
611 |
– |
init_auth(); /* Initialise the auth code */ |
612 |
– |
#ifndef _WIN32 |
613 |
– |
init_resolver(); /* Needs to be setup before the io loop */ |
614 |
– |
#endif |
543 |
|
initialize_server_capabs(); /* Set up default_server_capabs */ |
544 |
|
initialize_global_set_options(); |
545 |
< |
init_channels(); |
545 |
> |
channel_init(); |
546 |
> |
read_links_file(); |
547 |
> |
motd_init(); |
548 |
> |
#ifdef HAVE_LIBGEOIP |
549 |
> |
geoip_ctx = GeoIP_new(GEOIP_MEMORY_CACHE); |
550 |
> |
#endif |
551 |
|
|
552 |
< |
if (ServerInfo.name == NULL) |
552 |
> |
if (EmptyString(ServerInfo.sid)) |
553 |
|
{ |
554 |
< |
ilog(L_CRIT, "No server name specified in serverinfo block."); |
554 |
> |
ilog(LOG_TYPE_IRCD, "ERROR: No server id specified in serverinfo block."); |
555 |
> |
exit(EXIT_FAILURE); |
556 |
> |
} |
557 |
> |
|
558 |
> |
strlcpy(me.id, ServerInfo.sid, sizeof(me.id)); |
559 |
> |
|
560 |
> |
if (EmptyString(ServerInfo.name)) |
561 |
> |
{ |
562 |
> |
ilog(LOG_TYPE_IRCD, "ERROR: No server name specified in serverinfo block."); |
563 |
|
exit(EXIT_FAILURE); |
564 |
|
} |
565 |
|
|
566 |
|
strlcpy(me.name, ServerInfo.name, sizeof(me.name)); |
567 |
|
|
568 |
|
/* serverinfo{} description must exist. If not, error out.*/ |
569 |
< |
if (ServerInfo.description == NULL) |
569 |
> |
if (EmptyString(ServerInfo.description)) |
570 |
|
{ |
571 |
< |
ilog(L_CRIT, |
631 |
< |
"ERROR: No server description specified in serverinfo block."); |
571 |
> |
ilog(LOG_TYPE_IRCD, "ERROR: No server description specified in serverinfo block."); |
572 |
|
exit(EXIT_FAILURE); |
573 |
|
} |
574 |
|
|
575 |
|
strlcpy(me.info, ServerInfo.description, sizeof(me.info)); |
576 |
|
|
577 |
< |
me.from = &me; |
578 |
< |
me.servptr = &me; |
577 |
> |
me.from = &me; |
578 |
> |
me.servptr = &me; |
579 |
> |
me.localClient->lasttime = CurrentTime; |
580 |
> |
me.localClient->since = CurrentTime; |
581 |
> |
me.localClient->firsttime = CurrentTime; |
582 |
|
|
583 |
|
SetMe(&me); |
584 |
|
make_server(&me); |
585 |
|
|
586 |
< |
me.lasttime = me.since = me.firsttime = CurrentTime; |
586 |
> |
hash_add_id(&me); |
587 |
|
hash_add_client(&me); |
588 |
< |
|
588 |
> |
|
589 |
|
/* add ourselves to global_serv_list */ |
590 |
|
dlinkAdd(&me, make_dlink_node(), &global_serv_list); |
591 |
|
|
592 |
< |
check_class(); |
592 |
> |
load_kline_database(); |
593 |
> |
load_dline_database(); |
594 |
> |
load_gline_database(); |
595 |
> |
load_xline_database(); |
596 |
> |
load_resv_database(); |
597 |
|
|
651 |
– |
#ifndef STATIC_MODULES |
598 |
|
if (chdir(MODPATH)) |
599 |
|
{ |
600 |
< |
ilog (L_CRIT, "Could not load core modules. Terminating!"); |
600 |
> |
ilog(LOG_TYPE_IRCD, "Could not load core modules. Terminating!"); |
601 |
|
exit(EXIT_FAILURE); |
602 |
|
} |
603 |
|
|
604 |
|
load_all_modules(1); |
605 |
|
load_conf_modules(); |
606 |
|
load_core_modules(1); |
607 |
+ |
|
608 |
|
/* Go back to DPATH after checking to see if we can chdir to MODPATH */ |
609 |
< |
chdir(ConfigFileEntry.dpath); |
610 |
< |
#else |
611 |
< |
load_all_modules(1); |
612 |
< |
#endif |
609 |
> |
if (chdir(ConfigFileEntry.dpath)) |
610 |
> |
{ |
611 |
> |
perror("chdir"); |
612 |
> |
exit(EXIT_FAILURE); |
613 |
> |
} |
614 |
> |
|
615 |
|
/* |
616 |
|
* assemble_umode_buffer() has to be called after |
617 |
|
* reading conf/loading modules. |
620 |
|
|
621 |
|
write_pidfile(pidFileName); |
622 |
|
|
623 |
< |
ilog(L_NOTICE, "Server Ready"); |
623 |
> |
ilog(LOG_TYPE_IRCD, "Server Ready"); |
624 |
|
|
625 |
|
eventAddIsh("cleanup_glines", cleanup_glines, NULL, CLEANUP_GLINES_TIME); |
626 |
|
eventAddIsh("cleanup_tklines", cleanup_tklines, NULL, CLEANUP_TKLINES_TIME); |
629 |
|
/* No, 'cause after a restart it would cause all sorts of nick collides */ |
630 |
|
eventAddIsh("try_connections", try_connections, NULL, STARTUP_CONNECTIONS_TIME); |
631 |
|
|
683 |
– |
eventAddIsh("collect_zipstats", collect_zipstats, NULL, ZIPSTATS_TIME); |
684 |
– |
|
632 |
|
/* Setup the timeout check. I'll shift it later :) -- adrian */ |
633 |
|
eventAddIsh("comm_checktimeouts", comm_checktimeouts, NULL, 1); |
634 |
|
|
635 |
+ |
eventAddIsh("save_all_databases", save_all_databases, NULL, DATABASE_UPDATE_TIMEOUT); |
636 |
+ |
|
637 |
|
if (ConfigServerHide.links_delay > 0) |
638 |
|
eventAddIsh("write_links_file", write_links_file, NULL, ConfigServerHide.links_delay); |
639 |
|
else |