1 |
adx |
30 |
/* |
2 |
michael |
2916 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
3 |
adx |
30 |
* |
4 |
michael |
2916 |
* Copyright (c) 1997-2014 ircd-hybrid development team |
5 |
adx |
30 |
* |
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 |
8 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
9 |
|
|
* (at your option) any later version. |
10 |
|
|
* |
11 |
|
|
* This program is distributed in the hope that it will be useful, |
12 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
|
|
* GNU General Public License for more details. |
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 |
19 |
|
|
* USA |
20 |
|
|
*/ |
21 |
|
|
|
22 |
michael |
2916 |
/*! \file ircd.c |
23 |
|
|
* \brief Starts up and runs the ircd. |
24 |
|
|
* \version $Id$ |
25 |
|
|
*/ |
26 |
|
|
|
27 |
adx |
30 |
#include "stdinc.h" |
28 |
michael |
3347 |
#include "user.h" |
29 |
michael |
1011 |
#include "list.h" |
30 |
adx |
30 |
#include "ircd.h" |
31 |
|
|
#include "channel.h" |
32 |
|
|
#include "client.h" |
33 |
|
|
#include "event.h" |
34 |
|
|
#include "fdlist.h" |
35 |
|
|
#include "hash.h" |
36 |
|
|
#include "irc_string.h" |
37 |
|
|
#include "ircd_signal.h" |
38 |
michael |
3321 |
#include "gline.h" |
39 |
adx |
30 |
#include "motd.h" |
40 |
michael |
1632 |
#include "conf.h" |
41 |
adx |
30 |
#include "hostmask.h" |
42 |
|
|
#include "parse.h" |
43 |
michael |
3322 |
#include "res.h" |
44 |
adx |
30 |
#include "restart.h" |
45 |
michael |
982 |
#include "rng_mt.h" |
46 |
michael |
3324 |
#include "auth.h" |
47 |
adx |
30 |
#include "s_bsd.h" |
48 |
michael |
1309 |
#include "log.h" |
49 |
michael |
3347 |
#include "server.h" /* try_connections */ |
50 |
adx |
30 |
#include "send.h" |
51 |
|
|
#include "whowas.h" |
52 |
|
|
#include "modules.h" |
53 |
|
|
#include "memory.h" |
54 |
michael |
1654 |
#include "mempool.h" |
55 |
adx |
30 |
#include "ircd_getopt.h" |
56 |
|
|
#include "supported.h" |
57 |
michael |
876 |
#include "watch.h" |
58 |
michael |
1622 |
#include "conf_db.h" |
59 |
michael |
1632 |
#include "conf_class.h" |
60 |
adx |
30 |
|
61 |
michael |
1858 |
|
62 |
|
|
#ifdef HAVE_LIBGEOIP |
63 |
|
|
GeoIP *geoip_ctx; |
64 |
|
|
#endif |
65 |
michael |
2872 |
|
66 |
adx |
30 |
/* /quote set variables */ |
67 |
|
|
struct SetOptions GlobalSetOptions; |
68 |
michael |
2872 |
struct Counter Count; |
69 |
|
|
struct ServerState_t server_state; |
70 |
michael |
896 |
struct ServerStatistics ServerStats; |
71 |
adx |
30 |
struct timeval SystemTime; |
72 |
|
|
struct Client me; /* That's me */ |
73 |
|
|
struct LocalUser meLocalUser; /* That's also part of me */ |
74 |
|
|
|
75 |
|
|
const char *logFileName = LPATH; |
76 |
|
|
const char *pidFileName = PPATH; |
77 |
|
|
|
78 |
|
|
char **myargv; |
79 |
|
|
|
80 |
|
|
int dorehash = 0; |
81 |
|
|
int doremotd = 0; |
82 |
|
|
|
83 |
|
|
/* Set to zero because it should be initialized later using |
84 |
|
|
* initialize_server_capabs |
85 |
|
|
*/ |
86 |
michael |
3907 |
unsigned int default_server_capabs; |
87 |
michael |
1013 |
unsigned int splitmode; |
88 |
|
|
unsigned int splitchecking; |
89 |
|
|
unsigned int split_users; |
90 |
adx |
30 |
unsigned int split_servers; |
91 |
|
|
|
92 |
|
|
/* Do klines the same way hybrid-6 did them, i.e. at the |
93 |
|
|
* top of the next io_loop instead of in the same loop as |
94 |
|
|
* the klines are being applied. |
95 |
|
|
* |
96 |
|
|
* This should fix strange CPU starvation as very indirectly reported. |
97 |
|
|
* (Why do you people not email bug reports? WHY? WHY?) |
98 |
|
|
* |
99 |
|
|
* - Dianora |
100 |
|
|
*/ |
101 |
|
|
|
102 |
|
|
int rehashed_klines = 0; |
103 |
|
|
|
104 |
|
|
|
105 |
|
|
/* |
106 |
|
|
* print_startup - print startup information |
107 |
|
|
*/ |
108 |
|
|
static void |
109 |
|
|
print_startup(int pid) |
110 |
|
|
{ |
111 |
michael |
2646 |
printf("ircd: version %s(%s)\n", ircd_version, serno); |
112 |
adx |
30 |
printf("ircd: pid %d\n", pid); |
113 |
|
|
printf("ircd: running in %s mode from %s\n", !server_state.foreground ? "background" |
114 |
|
|
: "foreground", ConfigFileEntry.dpath); |
115 |
|
|
} |
116 |
|
|
|
117 |
|
|
static void |
118 |
|
|
make_daemon(void) |
119 |
|
|
{ |
120 |
|
|
int pid; |
121 |
|
|
|
122 |
|
|
if ((pid = fork()) < 0) |
123 |
|
|
{ |
124 |
|
|
perror("fork"); |
125 |
|
|
exit(EXIT_FAILURE); |
126 |
|
|
} |
127 |
|
|
else if (pid > 0) |
128 |
|
|
{ |
129 |
|
|
print_startup(pid); |
130 |
|
|
exit(EXIT_SUCCESS); |
131 |
|
|
} |
132 |
|
|
|
133 |
|
|
setsid(); |
134 |
|
|
} |
135 |
|
|
|
136 |
|
|
static int printVersion = 0; |
137 |
|
|
|
138 |
michael |
3215 |
static struct lgetopt myopts[] = |
139 |
|
|
{ |
140 |
michael |
2916 |
{"configfile", &ConfigFileEntry.configfile, |
141 |
adx |
30 |
STRING, "File to use for ircd.conf"}, |
142 |
michael |
1718 |
{"glinefile", &ConfigFileEntry.glinefile, |
143 |
|
|
STRING, "File to use for gline database"}, |
144 |
michael |
2916 |
{"klinefile", &ConfigFileEntry.klinefile, |
145 |
michael |
1718 |
STRING, "File to use for kline database"}, |
146 |
|
|
{"dlinefile", &ConfigFileEntry.dlinefile, |
147 |
|
|
STRING, "File to use for dline database"}, |
148 |
michael |
2916 |
{"xlinefile", &ConfigFileEntry.xlinefile, |
149 |
michael |
1718 |
STRING, "File to use for xline database"}, |
150 |
|
|
{"resvfile", &ConfigFileEntry.resvfile, |
151 |
|
|
STRING, "File to use for resv database"}, |
152 |
michael |
2916 |
{"logfile", &logFileName, |
153 |
adx |
30 |
STRING, "File to use for ircd.log"}, |
154 |
|
|
{"pidfile", &pidFileName, |
155 |
|
|
STRING, "File to use for process ID"}, |
156 |
michael |
2916 |
{"foreground", &server_state.foreground, |
157 |
adx |
30 |
YESNO, "Run in foreground (don't detach)"}, |
158 |
michael |
2916 |
{"version", &printVersion, |
159 |
adx |
30 |
YESNO, "Print version and exit"}, |
160 |
|
|
{"help", NULL, USAGE, "Print this text"}, |
161 |
|
|
{NULL, NULL, STRING, NULL}, |
162 |
|
|
}; |
163 |
|
|
|
164 |
|
|
void |
165 |
|
|
set_time(void) |
166 |
|
|
{ |
167 |
michael |
2978 |
struct timeval newtime = { .tv_sec = 0, .tv_usec = 0 }; |
168 |
adx |
30 |
|
169 |
|
|
if (gettimeofday(&newtime, NULL) == -1) |
170 |
|
|
{ |
171 |
michael |
1247 |
ilog(LOG_TYPE_IRCD, "Clock Failure (%s), TS can be corrupted", |
172 |
adx |
30 |
strerror(errno)); |
173 |
michael |
1618 |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
174 |
adx |
30 |
"Clock Failure (%s), TS can be corrupted", |
175 |
|
|
strerror(errno)); |
176 |
michael |
3167 |
server_die("Clock Failure", 1); |
177 |
adx |
30 |
} |
178 |
|
|
|
179 |
|
|
if (newtime.tv_sec < CurrentTime) |
180 |
|
|
{ |
181 |
michael |
2980 |
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 |
adx |
30 |
set_back_events(CurrentTime - newtime.tv_sec); |
188 |
|
|
} |
189 |
|
|
|
190 |
|
|
SystemTime.tv_sec = newtime.tv_sec; |
191 |
|
|
SystemTime.tv_usec = newtime.tv_usec; |
192 |
|
|
} |
193 |
|
|
|
194 |
|
|
static void |
195 |
|
|
io_loop(void) |
196 |
|
|
{ |
197 |
michael |
3215 |
while (1) |
198 |
adx |
30 |
{ |
199 |
|
|
/* |
200 |
|
|
* Maybe we want a flags word? |
201 |
michael |
2916 |
* ie. if (REHASHED_KLINES(global_flags)) |
202 |
adx |
30 |
* SET_REHASHED_KLINES(global_flags) |
203 |
|
|
* CLEAR_REHASHED_KLINES(global_flags) |
204 |
|
|
* |
205 |
|
|
* - Dianora |
206 |
|
|
*/ |
207 |
|
|
if (rehashed_klines) |
208 |
|
|
{ |
209 |
|
|
check_conf_klines(); |
210 |
|
|
rehashed_klines = 0; |
211 |
|
|
} |
212 |
|
|
|
213 |
|
|
if (listing_client_list.head) |
214 |
|
|
{ |
215 |
|
|
dlink_node *ptr = NULL, *ptr_next = NULL; |
216 |
|
|
DLINK_FOREACH_SAFE(ptr, ptr_next, listing_client_list.head) |
217 |
michael |
3288 |
safe_list_channels(ptr->data, 0); |
218 |
adx |
30 |
} |
219 |
|
|
|
220 |
|
|
/* Run pending events, then get the number of seconds to the next |
221 |
|
|
* event |
222 |
|
|
*/ |
223 |
|
|
while (eventNextTime() <= CurrentTime) |
224 |
|
|
eventRun(); |
225 |
|
|
|
226 |
|
|
comm_select(); |
227 |
|
|
exit_aborted_clients(); |
228 |
|
|
free_exited_clients(); |
229 |
|
|
|
230 |
|
|
/* Check to see whether we have to rehash the configuration .. */ |
231 |
|
|
if (dorehash) |
232 |
|
|
{ |
233 |
|
|
rehash(1); |
234 |
|
|
dorehash = 0; |
235 |
|
|
} |
236 |
michael |
3215 |
|
237 |
adx |
30 |
if (doremotd) |
238 |
|
|
{ |
239 |
michael |
2150 |
motd_recache(); |
240 |
michael |
1618 |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
241 |
michael |
3065 |
"Got signal SIGUSR1, reloading motd file(s)"); |
242 |
adx |
30 |
doremotd = 0; |
243 |
|
|
} |
244 |
|
|
} |
245 |
|
|
} |
246 |
|
|
|
247 |
|
|
/* initalialize_global_set_options() |
248 |
|
|
* |
249 |
|
|
* inputs - none |
250 |
|
|
* output - none |
251 |
michael |
2916 |
* side effects - This sets all global set options needed |
252 |
adx |
30 |
*/ |
253 |
|
|
static void |
254 |
|
|
initialize_global_set_options(void) |
255 |
|
|
{ |
256 |
|
|
memset(&GlobalSetOptions, 0, sizeof(GlobalSetOptions)); |
257 |
|
|
|
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; |
264 |
|
|
else |
265 |
|
|
GlobalSetOptions.floodcount = 10; |
266 |
|
|
|
267 |
|
|
/* XXX I have no idea what to try here - Dianora */ |
268 |
|
|
GlobalSetOptions.joinfloodcount = 16; |
269 |
|
|
GlobalSetOptions.joinfloodtime = 8; |
270 |
|
|
|
271 |
|
|
split_servers = ConfigChannel.default_split_server_count; |
272 |
|
|
split_users = ConfigChannel.default_split_user_count; |
273 |
|
|
|
274 |
|
|
if (split_users && split_servers && (ConfigChannel.no_create_on_split || |
275 |
|
|
ConfigChannel.no_join_on_split)) |
276 |
|
|
{ |
277 |
|
|
splitmode = 1; |
278 |
|
|
splitchecking = 1; |
279 |
|
|
} |
280 |
|
|
|
281 |
|
|
GlobalSetOptions.ident_timeout = IDENT_TIMEOUT; |
282 |
|
|
/* End of global set options */ |
283 |
|
|
} |
284 |
|
|
|
285 |
|
|
/* initialize_server_capabs() |
286 |
|
|
* |
287 |
|
|
* inputs - none |
288 |
|
|
* output - none |
289 |
|
|
*/ |
290 |
|
|
static void |
291 |
|
|
initialize_server_capabs(void) |
292 |
|
|
{ |
293 |
|
|
add_capability("QS", CAP_QS, 1); |
294 |
|
|
add_capability("EOB", CAP_EOB, 1); |
295 |
michael |
1117 |
add_capability("TS6", CAP_TS6, 0); |
296 |
adx |
30 |
add_capability("CLUSTER", CAP_CLUSTER, 1); |
297 |
michael |
1196 |
add_capability("SVS", CAP_SVS, 1); |
298 |
michael |
3267 |
add_capability("CHW", CAP_CHW, 1); |
299 |
adx |
30 |
add_capability("HOPS", CAP_HOPS, 1); |
300 |
|
|
} |
301 |
|
|
|
302 |
|
|
/* write_pidfile() |
303 |
|
|
* |
304 |
|
|
* inputs - filename+path of pid file |
305 |
|
|
* output - NONE |
306 |
|
|
* side effects - write the pid of the ircd to filename |
307 |
|
|
*/ |
308 |
|
|
static void |
309 |
|
|
write_pidfile(const char *filename) |
310 |
|
|
{ |
311 |
michael |
1325 |
FILE *fb; |
312 |
adx |
30 |
|
313 |
michael |
1325 |
if ((fb = fopen(filename, "w"))) |
314 |
adx |
30 |
{ |
315 |
michael |
2691 |
char buff[IRCD_BUFSIZE]; |
316 |
adx |
30 |
unsigned int pid = (unsigned int)getpid(); |
317 |
|
|
|
318 |
michael |
1325 |
snprintf(buff, sizeof(buff), "%u\n", pid); |
319 |
|
|
|
320 |
|
|
if ((fputs(buff, fb) == -1)) |
321 |
michael |
1247 |
ilog(LOG_TYPE_IRCD, "Error writing %u to pid file %s (%s)", |
322 |
adx |
30 |
pid, filename, strerror(errno)); |
323 |
|
|
|
324 |
michael |
1325 |
fclose(fb); |
325 |
adx |
30 |
} |
326 |
|
|
else |
327 |
|
|
{ |
328 |
michael |
1247 |
ilog(LOG_TYPE_IRCD, "Error opening pid file %s", filename); |
329 |
adx |
30 |
} |
330 |
|
|
} |
331 |
|
|
|
332 |
|
|
/* check_pidfile() |
333 |
|
|
* |
334 |
|
|
* inputs - filename+path of pid file |
335 |
|
|
* output - none |
336 |
|
|
* side effects - reads pid from pidfile and checks if ircd is in process |
337 |
|
|
* list. if it is, gracefully exits |
338 |
|
|
* -kre |
339 |
|
|
*/ |
340 |
|
|
static void |
341 |
|
|
check_pidfile(const char *filename) |
342 |
|
|
{ |
343 |
michael |
1325 |
FILE *fb; |
344 |
michael |
2691 |
char buff[IRCD_BUFSIZE]; |
345 |
adx |
30 |
pid_t pidfromfile; |
346 |
|
|
|
347 |
|
|
/* Don't do logging here, since we don't have log() initialised */ |
348 |
michael |
1325 |
if ((fb = fopen(filename, "r"))) |
349 |
adx |
30 |
{ |
350 |
michael |
1325 |
if (fgets(buff, 20, fb) == NULL) |
351 |
adx |
30 |
{ |
352 |
|
|
/* log(L_ERROR, "Error reading from pid file %s (%s)", filename, |
353 |
|
|
* strerror(errno)); |
354 |
|
|
*/ |
355 |
|
|
} |
356 |
|
|
else |
357 |
|
|
{ |
358 |
|
|
pidfromfile = atoi(buff); |
359 |
|
|
|
360 |
|
|
if (!kill(pidfromfile, 0)) |
361 |
|
|
{ |
362 |
|
|
/* log(L_ERROR, "Server is already running"); */ |
363 |
|
|
printf("ircd: daemon is already running\n"); |
364 |
|
|
exit(-1); |
365 |
|
|
} |
366 |
|
|
} |
367 |
|
|
|
368 |
michael |
1325 |
fclose(fb); |
369 |
adx |
30 |
} |
370 |
|
|
else if (errno != ENOENT) |
371 |
|
|
{ |
372 |
|
|
/* log(L_ERROR, "Error opening pid file %s", filename); */ |
373 |
|
|
} |
374 |
|
|
} |
375 |
|
|
|
376 |
|
|
/* setup_corefile() |
377 |
|
|
* |
378 |
|
|
* inputs - nothing |
379 |
|
|
* output - nothing |
380 |
|
|
* side effects - setups corefile to system limits. |
381 |
|
|
* -kre |
382 |
|
|
*/ |
383 |
|
|
static void |
384 |
|
|
setup_corefile(void) |
385 |
|
|
{ |
386 |
|
|
#ifdef HAVE_SYS_RESOURCE_H |
387 |
|
|
struct rlimit rlim; /* resource limits */ |
388 |
|
|
|
389 |
|
|
/* Set corefilesize to maximum */ |
390 |
|
|
if (!getrlimit(RLIMIT_CORE, &rlim)) |
391 |
|
|
{ |
392 |
|
|
rlim.rlim_cur = rlim.rlim_max; |
393 |
|
|
setrlimit(RLIMIT_CORE, &rlim); |
394 |
|
|
} |
395 |
|
|
#endif |
396 |
|
|
} |
397 |
|
|
|
398 |
michael |
2228 |
#ifdef HAVE_LIBCRYPTO |
399 |
|
|
static int |
400 |
|
|
always_accept_verify_cb(int preverify_ok, X509_STORE_CTX *x509_ctx) |
401 |
|
|
{ |
402 |
|
|
return 1; |
403 |
|
|
} |
404 |
|
|
#endif |
405 |
|
|
|
406 |
adx |
30 |
/* init_ssl() |
407 |
|
|
* |
408 |
|
|
* inputs - nothing |
409 |
|
|
* output - nothing |
410 |
|
|
* side effects - setups SSL context. |
411 |
|
|
*/ |
412 |
|
|
static void |
413 |
michael |
1798 |
ssl_init(void) |
414 |
adx |
30 |
{ |
415 |
|
|
#ifdef HAVE_LIBCRYPTO |
416 |
michael |
2914 |
const unsigned char session_id[] = "ircd-hybrid"; |
417 |
|
|
|
418 |
adx |
30 |
SSL_load_error_strings(); |
419 |
|
|
SSLeay_add_ssl_algorithms(); |
420 |
|
|
|
421 |
michael |
967 |
if ((ServerInfo.server_ctx = SSL_CTX_new(SSLv23_server_method())) == NULL) |
422 |
adx |
30 |
{ |
423 |
|
|
const char *s; |
424 |
|
|
|
425 |
michael |
1303 |
fprintf(stderr, "ERROR: Could not initialize the SSL Server context -- %s\n", |
426 |
adx |
30 |
s = ERR_lib_error_string(ERR_get_error())); |
427 |
michael |
1303 |
ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Server context -- %s\n", s); |
428 |
adx |
30 |
} |
429 |
|
|
|
430 |
michael |
1316 |
SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TLSv1); |
431 |
michael |
967 |
SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_TLS_ROLLBACK_BUG|SSL_OP_ALL); |
432 |
michael |
2228 |
SSL_CTX_set_verify(ServerInfo.server_ctx, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE, |
433 |
|
|
always_accept_verify_cb); |
434 |
michael |
2914 |
SSL_CTX_set_session_id_context(ServerInfo.server_ctx, session_id, sizeof(session_id) - 1); |
435 |
adx |
30 |
|
436 |
michael |
1303 |
if ((ServerInfo.client_ctx = SSL_CTX_new(SSLv23_client_method())) == NULL) |
437 |
|
|
{ |
438 |
|
|
const char *s; |
439 |
|
|
|
440 |
|
|
fprintf(stderr, "ERROR: Could not initialize the SSL Client context -- %s\n", |
441 |
|
|
s = ERR_lib_error_string(ERR_get_error())); |
442 |
|
|
ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Client context -- %s\n", s); |
443 |
|
|
} |
444 |
|
|
|
445 |
michael |
1316 |
SSL_CTX_set_options(ServerInfo.client_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TLSv1); |
446 |
michael |
1303 |
SSL_CTX_set_options(ServerInfo.client_ctx, SSL_OP_TLS_ROLLBACK_BUG|SSL_OP_ALL); |
447 |
michael |
2253 |
SSL_CTX_set_verify(ServerInfo.client_ctx, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE, |
448 |
michael |
2228 |
always_accept_verify_cb); |
449 |
adx |
30 |
#endif /* HAVE_LIBCRYPTO */ |
450 |
|
|
} |
451 |
|
|
|
452 |
|
|
int |
453 |
|
|
main(int argc, char *argv[]) |
454 |
|
|
{ |
455 |
michael |
2253 |
/* Check to see if the user is running us as root, which is a nono */ |
456 |
adx |
30 |
if (geteuid() == 0) |
457 |
|
|
{ |
458 |
michael |
3525 |
fprintf(stderr, "ERROR: This server won't run as root/superuser\n"); |
459 |
michael |
982 |
return -1; |
460 |
adx |
30 |
} |
461 |
|
|
|
462 |
|
|
/* Setup corefile size immediately after boot -kre */ |
463 |
|
|
setup_corefile(); |
464 |
|
|
|
465 |
|
|
/* save server boot time right away, so getrusage works correctly */ |
466 |
|
|
set_time(); |
467 |
|
|
|
468 |
michael |
982 |
/* It ain't random, but it ought to be a little harder to guess */ |
469 |
|
|
init_genrand(SystemTime.tv_sec ^ (SystemTime.tv_usec | (getpid() << 20))); |
470 |
|
|
|
471 |
adx |
30 |
me.localClient = &meLocalUser; |
472 |
michael |
2253 |
dlinkAdd(&me, &me.node, &global_client_list); /* Pointer to beginning |
473 |
adx |
30 |
of Client list */ |
474 |
|
|
ConfigFileEntry.dpath = DPATH; |
475 |
michael |
3239 |
ConfigFileEntry.spath = SPATH; |
476 |
|
|
ConfigFileEntry.mpath = MPATH; |
477 |
michael |
1702 |
ConfigFileEntry.configfile = CPATH; /* Server configuration file */ |
478 |
|
|
ConfigFileEntry.klinefile = KPATH; /* Server kline file */ |
479 |
michael |
1718 |
ConfigFileEntry.glinefile = GPATH; /* Server gline file */ |
480 |
michael |
1702 |
ConfigFileEntry.xlinefile = XPATH; /* Server xline file */ |
481 |
|
|
ConfigFileEntry.dlinefile = DLPATH; /* dline file */ |
482 |
|
|
ConfigFileEntry.resvfile = RESVPATH; /* resv file */ |
483 |
|
|
|
484 |
adx |
30 |
myargv = argv; |
485 |
|
|
umask(077); /* better safe than sorry --SRB */ |
486 |
|
|
|
487 |
|
|
parseargs(&argc, &argv, myopts); |
488 |
|
|
|
489 |
|
|
if (printVersion) |
490 |
|
|
{ |
491 |
michael |
2646 |
printf("ircd: version %s(%s)\n", ircd_version, serno); |
492 |
adx |
30 |
exit(EXIT_SUCCESS); |
493 |
|
|
} |
494 |
|
|
|
495 |
|
|
if (chdir(ConfigFileEntry.dpath)) |
496 |
|
|
{ |
497 |
|
|
perror("chdir"); |
498 |
|
|
exit(EXIT_FAILURE); |
499 |
|
|
} |
500 |
|
|
|
501 |
michael |
1798 |
ssl_init(); |
502 |
adx |
30 |
|
503 |
|
|
if (!server_state.foreground) |
504 |
|
|
{ |
505 |
|
|
make_daemon(); |
506 |
|
|
close_standard_fds(); /* this needs to be before init_netio()! */ |
507 |
|
|
} |
508 |
|
|
else |
509 |
|
|
print_startup(getpid()); |
510 |
|
|
|
511 |
|
|
setup_signals(); |
512 |
|
|
|
513 |
|
|
/* Init the event subsystem */ |
514 |
|
|
eventInit(); |
515 |
michael |
2253 |
|
516 |
adx |
30 |
/* We need this to initialise the fd array before anything else */ |
517 |
|
|
fdlist_init(); |
518 |
michael |
1831 |
log_set_file(LOG_TYPE_IRCD, 0, logFileName); |
519 |
adx |
30 |
check_can_use_v6(); |
520 |
michael |
2632 |
init_netio(); /* This needs to be setup early ! -- adrian */ |
521 |
michael |
2253 |
|
522 |
adx |
30 |
/* Check if there is pidfile and daemon already running */ |
523 |
|
|
check_pidfile(pidFileName); |
524 |
|
|
|
525 |
michael |
1654 |
mp_pool_init(); |
526 |
adx |
30 |
init_dlink_nodes(); |
527 |
michael |
2159 |
init_isupport(); |
528 |
adx |
30 |
dbuf_init(); |
529 |
michael |
1798 |
hash_init(); |
530 |
adx |
30 |
init_ip_hash_table(); /* client host ip hash table */ |
531 |
|
|
init_host_hash(); /* Host-hashtable. */ |
532 |
michael |
1798 |
client_init(); |
533 |
michael |
1632 |
class_init(); |
534 |
michael |
1358 |
whowas_init(); |
535 |
michael |
876 |
watch_init(); |
536 |
michael |
1798 |
auth_init(); /* Initialise the auth code */ |
537 |
michael |
998 |
init_resolver(); /* Needs to be setup before the io loop */ |
538 |
michael |
1404 |
modules_init(); |
539 |
adx |
30 |
read_conf_files(1); /* cold start init conf files */ |
540 |
|
|
init_uid(); |
541 |
|
|
initialize_server_capabs(); /* Set up default_server_capabs */ |
542 |
|
|
initialize_global_set_options(); |
543 |
michael |
1798 |
channel_init(); |
544 |
michael |
2216 |
read_links_file(); |
545 |
michael |
2150 |
motd_init(); |
546 |
michael |
1858 |
#ifdef HAVE_LIBGEOIP |
547 |
|
|
geoip_ctx = GeoIP_new(GEOIP_MEMORY_CACHE); |
548 |
|
|
#endif |
549 |
adx |
30 |
|
550 |
michael |
1115 |
if (EmptyString(ServerInfo.sid)) |
551 |
adx |
30 |
{ |
552 |
michael |
1247 |
ilog(LOG_TYPE_IRCD, "ERROR: No server id specified in serverinfo block."); |
553 |
adx |
30 |
exit(EXIT_FAILURE); |
554 |
|
|
} |
555 |
michael |
885 |
|
556 |
michael |
1115 |
strlcpy(me.id, ServerInfo.sid, sizeof(me.id)); |
557 |
|
|
|
558 |
|
|
if (EmptyString(ServerInfo.name)) |
559 |
|
|
{ |
560 |
michael |
1247 |
ilog(LOG_TYPE_IRCD, "ERROR: No server name specified in serverinfo block."); |
561 |
michael |
1115 |
exit(EXIT_FAILURE); |
562 |
|
|
} |
563 |
|
|
|
564 |
adx |
30 |
strlcpy(me.name, ServerInfo.name, sizeof(me.name)); |
565 |
|
|
|
566 |
|
|
/* serverinfo{} description must exist. If not, error out.*/ |
567 |
michael |
1115 |
if (EmptyString(ServerInfo.description)) |
568 |
adx |
30 |
{ |
569 |
michael |
1247 |
ilog(LOG_TYPE_IRCD, "ERROR: No server description specified in serverinfo block."); |
570 |
adx |
30 |
exit(EXIT_FAILURE); |
571 |
|
|
} |
572 |
michael |
885 |
|
573 |
adx |
30 |
strlcpy(me.info, ServerInfo.description, sizeof(me.info)); |
574 |
|
|
|
575 |
michael |
1241 |
me.from = &me; |
576 |
|
|
me.servptr = &me; |
577 |
|
|
me.localClient->lasttime = CurrentTime; |
578 |
|
|
me.localClient->since = CurrentTime; |
579 |
|
|
me.localClient->firsttime = CurrentTime; |
580 |
adx |
30 |
|
581 |
|
|
SetMe(&me); |
582 |
|
|
make_server(&me); |
583 |
|
|
|
584 |
michael |
1115 |
hash_add_id(&me); |
585 |
adx |
30 |
hash_add_client(&me); |
586 |
michael |
2916 |
|
587 |
adx |
30 |
/* add ourselves to global_serv_list */ |
588 |
|
|
dlinkAdd(&me, make_dlink_node(), &global_serv_list); |
589 |
|
|
|
590 |
michael |
1622 |
load_kline_database(); |
591 |
|
|
load_dline_database(); |
592 |
|
|
load_gline_database(); |
593 |
|
|
load_xline_database(); |
594 |
|
|
load_resv_database(); |
595 |
|
|
|
596 |
adx |
30 |
if (chdir(MODPATH)) |
597 |
|
|
{ |
598 |
michael |
1247 |
ilog(LOG_TYPE_IRCD, "Could not load core modules. Terminating!"); |
599 |
adx |
30 |
exit(EXIT_FAILURE); |
600 |
|
|
} |
601 |
|
|
|
602 |
|
|
load_all_modules(1); |
603 |
|
|
load_conf_modules(); |
604 |
|
|
load_core_modules(1); |
605 |
michael |
1115 |
|
606 |
adx |
30 |
/* Go back to DPATH after checking to see if we can chdir to MODPATH */ |
607 |
michael |
1115 |
if (chdir(ConfigFileEntry.dpath)) |
608 |
|
|
{ |
609 |
|
|
perror("chdir"); |
610 |
|
|
exit(EXIT_FAILURE); |
611 |
|
|
} |
612 |
michael |
1121 |
|
613 |
adx |
30 |
/* |
614 |
|
|
* assemble_umode_buffer() has to be called after |
615 |
|
|
* reading conf/loading modules. |
616 |
|
|
*/ |
617 |
|
|
assemble_umode_buffer(); |
618 |
|
|
|
619 |
|
|
write_pidfile(pidFileName); |
620 |
|
|
|
621 |
michael |
1247 |
ilog(LOG_TYPE_IRCD, "Server Ready"); |
622 |
adx |
30 |
|
623 |
|
|
eventAddIsh("cleanup_glines", cleanup_glines, NULL, CLEANUP_GLINES_TIME); |
624 |
|
|
eventAddIsh("cleanup_tklines", cleanup_tklines, NULL, CLEANUP_TKLINES_TIME); |
625 |
|
|
|
626 |
|
|
/* We want try_connections to be called as soon as possible now! -- adrian */ |
627 |
|
|
/* No, 'cause after a restart it would cause all sorts of nick collides */ |
628 |
|
|
eventAddIsh("try_connections", try_connections, NULL, STARTUP_CONNECTIONS_TIME); |
629 |
|
|
|
630 |
|
|
/* Setup the timeout check. I'll shift it later :) -- adrian */ |
631 |
|
|
eventAddIsh("comm_checktimeouts", comm_checktimeouts, NULL, 1); |
632 |
|
|
|
633 |
michael |
1625 |
eventAddIsh("save_all_databases", save_all_databases, NULL, DATABASE_UPDATE_TIMEOUT); |
634 |
|
|
|
635 |
adx |
30 |
if (ConfigServerHide.links_delay > 0) |
636 |
|
|
eventAddIsh("write_links_file", write_links_file, NULL, ConfigServerHide.links_delay); |
637 |
|
|
else |
638 |
|
|
ConfigServerHide.links_disabled = 1; |
639 |
|
|
|
640 |
|
|
if (splitmode) |
641 |
|
|
eventAddIsh("check_splitmode", check_splitmode, NULL, 60); |
642 |
|
|
|
643 |
|
|
io_loop(); |
644 |
michael |
885 |
return 0; |
645 |
adx |
30 |
} |