1 |
adx |
30 |
/* |
2 |
michael |
2916 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
3 |
adx |
30 |
* |
4 |
michael |
5347 |
* Copyright (c) 1997-2015 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 |
michael |
4565 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 |
19 |
adx |
30 |
* 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 |
michael |
876 |
#include "watch.h" |
57 |
michael |
1622 |
#include "conf_db.h" |
58 |
michael |
1632 |
#include "conf_class.h" |
59 |
michael |
4325 |
#include "ipcache.h" |
60 |
adx |
30 |
|
61 |
michael |
1858 |
|
62 |
|
|
#ifdef HAVE_LIBGEOIP |
63 |
|
|
GeoIP *geoip_ctx; |
64 |
|
|
#endif |
65 |
michael |
2872 |
|
66 |
adx |
30 |
struct timeval SystemTime; |
67 |
michael |
5470 |
struct Connection meConnection; /* That's also part of me */ |
68 |
|
|
struct Client me = { .connection = &meConnection }; /* That's me */ |
69 |
adx |
30 |
|
70 |
michael |
5460 |
char **myargv; |
71 |
adx |
30 |
const char *logFileName = LPATH; |
72 |
|
|
const char *pidFileName = PPATH; |
73 |
|
|
|
74 |
michael |
5460 |
unsigned int dorehash; |
75 |
|
|
unsigned int doremotd; |
76 |
michael |
3907 |
unsigned int default_server_capabs; |
77 |
michael |
1013 |
unsigned int splitmode; |
78 |
|
|
unsigned int splitchecking; |
79 |
|
|
unsigned int split_users; |
80 |
adx |
30 |
unsigned int split_servers; |
81 |
|
|
|
82 |
michael |
4094 |
static struct event event_cleanup_glines = |
83 |
|
|
{ |
84 |
|
|
.name = "cleanup_glines", |
85 |
|
|
.handler = cleanup_glines, |
86 |
|
|
.when = CLEANUP_GLINES_TIME |
87 |
|
|
}; |
88 |
|
|
|
89 |
|
|
static struct event event_cleanup_tklines = |
90 |
|
|
{ |
91 |
|
|
.name = "cleanup_tklines", |
92 |
|
|
.handler = cleanup_tklines, |
93 |
|
|
.when = CLEANUP_TKLINES_TIME |
94 |
|
|
}; |
95 |
|
|
|
96 |
|
|
static struct event event_try_connections = |
97 |
|
|
{ |
98 |
|
|
.name = "try_connections", |
99 |
|
|
.handler = try_connections, |
100 |
|
|
.when = STARTUP_CONNECTIONS_TIME |
101 |
|
|
}; |
102 |
|
|
|
103 |
|
|
static struct event event_comm_checktimeouts = |
104 |
|
|
{ |
105 |
|
|
.name = "comm_checktimeouts", |
106 |
|
|
.handler = comm_checktimeouts, |
107 |
|
|
.when = 1 |
108 |
|
|
}; |
109 |
|
|
|
110 |
|
|
static struct event event_save_all_databases = |
111 |
|
|
{ |
112 |
|
|
.name = "save_all_databases", |
113 |
|
|
.handler = save_all_databases, |
114 |
|
|
.when = DATABASE_UPDATE_TIMEOUT |
115 |
|
|
}; |
116 |
|
|
|
117 |
|
|
struct event event_write_links_file = |
118 |
|
|
{ |
119 |
|
|
.name = "write_links_file", |
120 |
|
|
.handler = write_links_file, |
121 |
|
|
}; |
122 |
|
|
|
123 |
|
|
|
124 |
adx |
30 |
/* |
125 |
|
|
* print_startup - print startup information |
126 |
|
|
*/ |
127 |
|
|
static void |
128 |
|
|
print_startup(int pid) |
129 |
|
|
{ |
130 |
michael |
2646 |
printf("ircd: version %s(%s)\n", ircd_version, serno); |
131 |
adx |
30 |
printf("ircd: pid %d\n", pid); |
132 |
|
|
printf("ircd: running in %s mode from %s\n", !server_state.foreground ? "background" |
133 |
michael |
4340 |
: "foreground", ConfigGeneral.dpath); |
134 |
adx |
30 |
} |
135 |
|
|
|
136 |
|
|
static void |
137 |
|
|
make_daemon(void) |
138 |
|
|
{ |
139 |
|
|
int pid; |
140 |
|
|
|
141 |
|
|
if ((pid = fork()) < 0) |
142 |
|
|
{ |
143 |
|
|
perror("fork"); |
144 |
|
|
exit(EXIT_FAILURE); |
145 |
|
|
} |
146 |
|
|
else if (pid > 0) |
147 |
|
|
{ |
148 |
|
|
print_startup(pid); |
149 |
|
|
exit(EXIT_SUCCESS); |
150 |
|
|
} |
151 |
|
|
|
152 |
|
|
setsid(); |
153 |
|
|
} |
154 |
|
|
|
155 |
|
|
static int printVersion = 0; |
156 |
|
|
|
157 |
michael |
3215 |
static struct lgetopt myopts[] = |
158 |
|
|
{ |
159 |
michael |
4340 |
{"configfile", &ConfigGeneral.configfile, |
160 |
adx |
30 |
STRING, "File to use for ircd.conf"}, |
161 |
michael |
4340 |
{"glinefile", &ConfigGeneral.glinefile, |
162 |
michael |
1718 |
STRING, "File to use for gline database"}, |
163 |
michael |
4340 |
{"klinefile", &ConfigGeneral.klinefile, |
164 |
michael |
1718 |
STRING, "File to use for kline database"}, |
165 |
michael |
4340 |
{"dlinefile", &ConfigGeneral.dlinefile, |
166 |
michael |
1718 |
STRING, "File to use for dline database"}, |
167 |
michael |
4340 |
{"xlinefile", &ConfigGeneral.xlinefile, |
168 |
michael |
1718 |
STRING, "File to use for xline database"}, |
169 |
michael |
4340 |
{"resvfile", &ConfigGeneral.resvfile, |
170 |
michael |
1718 |
STRING, "File to use for resv database"}, |
171 |
michael |
2916 |
{"logfile", &logFileName, |
172 |
adx |
30 |
STRING, "File to use for ircd.log"}, |
173 |
|
|
{"pidfile", &pidFileName, |
174 |
|
|
STRING, "File to use for process ID"}, |
175 |
michael |
2916 |
{"foreground", &server_state.foreground, |
176 |
adx |
30 |
YESNO, "Run in foreground (don't detach)"}, |
177 |
michael |
2916 |
{"version", &printVersion, |
178 |
adx |
30 |
YESNO, "Print version and exit"}, |
179 |
|
|
{"help", NULL, USAGE, "Print this text"}, |
180 |
|
|
{NULL, NULL, STRING, NULL}, |
181 |
|
|
}; |
182 |
|
|
|
183 |
|
|
void |
184 |
|
|
set_time(void) |
185 |
|
|
{ |
186 |
michael |
2978 |
struct timeval newtime = { .tv_sec = 0, .tv_usec = 0 }; |
187 |
adx |
30 |
|
188 |
|
|
if (gettimeofday(&newtime, NULL) == -1) |
189 |
|
|
{ |
190 |
michael |
1247 |
ilog(LOG_TYPE_IRCD, "Clock Failure (%s), TS can be corrupted", |
191 |
adx |
30 |
strerror(errno)); |
192 |
michael |
1618 |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
193 |
adx |
30 |
"Clock Failure (%s), TS can be corrupted", |
194 |
|
|
strerror(errno)); |
195 |
michael |
3167 |
server_die("Clock Failure", 1); |
196 |
adx |
30 |
} |
197 |
|
|
|
198 |
|
|
if (newtime.tv_sec < CurrentTime) |
199 |
|
|
{ |
200 |
michael |
2980 |
ilog(LOG_TYPE_IRCD, "System clock is running backwards - (%lu < %lu)", |
201 |
|
|
(unsigned long)newtime.tv_sec, (unsigned long)CurrentTime); |
202 |
|
|
sendto_realops_flags(UMODE_DEBUG, L_ALL, SEND_NOTICE, |
203 |
|
|
"System clock is running backwards - (%lu < %lu)", |
204 |
|
|
(unsigned long)newtime.tv_sec, |
205 |
|
|
(unsigned long)CurrentTime); |
206 |
adx |
30 |
set_back_events(CurrentTime - newtime.tv_sec); |
207 |
|
|
} |
208 |
|
|
|
209 |
|
|
SystemTime.tv_sec = newtime.tv_sec; |
210 |
|
|
SystemTime.tv_usec = newtime.tv_usec; |
211 |
|
|
} |
212 |
|
|
|
213 |
|
|
static void |
214 |
|
|
io_loop(void) |
215 |
|
|
{ |
216 |
michael |
3215 |
while (1) |
217 |
adx |
30 |
{ |
218 |
|
|
if (listing_client_list.head) |
219 |
|
|
{ |
220 |
michael |
4815 |
dlink_node *node = NULL, *node_next = NULL; |
221 |
|
|
DLINK_FOREACH_SAFE(node, node_next, listing_client_list.head) |
222 |
|
|
safe_list_channels(node->data, 0); |
223 |
adx |
30 |
} |
224 |
|
|
|
225 |
michael |
4094 |
/* Run pending events */ |
226 |
|
|
event_run(); |
227 |
adx |
30 |
|
228 |
|
|
comm_select(); |
229 |
|
|
exit_aborted_clients(); |
230 |
|
|
free_exited_clients(); |
231 |
|
|
|
232 |
|
|
/* Check to see whether we have to rehash the configuration .. */ |
233 |
|
|
if (dorehash) |
234 |
|
|
{ |
235 |
michael |
4982 |
conf_rehash(1); |
236 |
adx |
30 |
dorehash = 0; |
237 |
|
|
} |
238 |
michael |
3215 |
|
239 |
adx |
30 |
if (doremotd) |
240 |
|
|
{ |
241 |
michael |
2150 |
motd_recache(); |
242 |
michael |
1618 |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
243 |
michael |
3065 |
"Got signal SIGUSR1, reloading motd file(s)"); |
244 |
adx |
30 |
doremotd = 0; |
245 |
|
|
} |
246 |
|
|
} |
247 |
|
|
} |
248 |
|
|
|
249 |
|
|
/* initalialize_global_set_options() |
250 |
|
|
* |
251 |
|
|
* inputs - none |
252 |
|
|
* output - none |
253 |
michael |
2916 |
* side effects - This sets all global set options needed |
254 |
adx |
30 |
*/ |
255 |
|
|
static void |
256 |
|
|
initialize_global_set_options(void) |
257 |
|
|
{ |
258 |
|
|
GlobalSetOptions.autoconn = 1; |
259 |
|
|
GlobalSetOptions.spam_time = MIN_JOIN_LEAVE_TIME; |
260 |
|
|
GlobalSetOptions.spam_num = MAX_JOIN_LEAVE_COUNT; |
261 |
|
|
|
262 |
michael |
4340 |
if (ConfigGeneral.default_floodcount) |
263 |
|
|
GlobalSetOptions.floodcount = ConfigGeneral.default_floodcount; |
264 |
adx |
30 |
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 |
|
|
} |
283 |
|
|
|
284 |
|
|
/* initialize_server_capabs() |
285 |
|
|
* |
286 |
|
|
* inputs - none |
287 |
|
|
* output - none |
288 |
|
|
*/ |
289 |
|
|
static void |
290 |
|
|
initialize_server_capabs(void) |
291 |
|
|
{ |
292 |
|
|
add_capability("QS", CAP_QS, 1); |
293 |
|
|
add_capability("EOB", CAP_EOB, 1); |
294 |
michael |
1117 |
add_capability("TS6", CAP_TS6, 0); |
295 |
adx |
30 |
add_capability("CLUSTER", CAP_CLUSTER, 1); |
296 |
michael |
1196 |
add_capability("SVS", CAP_SVS, 1); |
297 |
michael |
3267 |
add_capability("CHW", CAP_CHW, 1); |
298 |
adx |
30 |
add_capability("HOPS", CAP_HOPS, 1); |
299 |
|
|
} |
300 |
|
|
|
301 |
|
|
/* write_pidfile() |
302 |
|
|
* |
303 |
|
|
* inputs - filename+path of pid file |
304 |
|
|
* output - NONE |
305 |
|
|
* side effects - write the pid of the ircd to filename |
306 |
|
|
*/ |
307 |
|
|
static void |
308 |
|
|
write_pidfile(const char *filename) |
309 |
|
|
{ |
310 |
michael |
1325 |
FILE *fb; |
311 |
adx |
30 |
|
312 |
michael |
1325 |
if ((fb = fopen(filename, "w"))) |
313 |
adx |
30 |
{ |
314 |
michael |
2691 |
char buff[IRCD_BUFSIZE]; |
315 |
adx |
30 |
unsigned int pid = (unsigned int)getpid(); |
316 |
|
|
|
317 |
michael |
1325 |
snprintf(buff, sizeof(buff), "%u\n", pid); |
318 |
|
|
|
319 |
michael |
4736 |
if (fputs(buff, fb) == -1) |
320 |
michael |
1247 |
ilog(LOG_TYPE_IRCD, "Error writing %u to pid file %s (%s)", |
321 |
adx |
30 |
pid, filename, strerror(errno)); |
322 |
|
|
|
323 |
michael |
1325 |
fclose(fb); |
324 |
adx |
30 |
} |
325 |
|
|
else |
326 |
|
|
{ |
327 |
michael |
4748 |
ilog(LOG_TYPE_IRCD, "Error opening pid file %s (%s)", |
328 |
|
|
filename, strerror(errno)); |
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 |
4733 |
if (!fgets(buff, 20, fb)) |
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 |
|
|
SSL_load_error_strings(); |
417 |
|
|
SSLeay_add_ssl_algorithms(); |
418 |
|
|
|
419 |
michael |
4733 |
if (!(ConfigServerInfo.server_ctx = SSL_CTX_new(SSLv23_server_method()))) |
420 |
adx |
30 |
{ |
421 |
michael |
4129 |
const char *s = ERR_lib_error_string(ERR_get_error()); |
422 |
adx |
30 |
|
423 |
michael |
4129 |
fprintf(stderr, "ERROR: Could not initialize the SSL Server context -- %s\n", s); |
424 |
michael |
4763 |
ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Server context -- %s", s); |
425 |
michael |
4497 |
exit(EXIT_FAILURE); |
426 |
michael |
4751 |
return; /* Not reached */ |
427 |
adx |
30 |
} |
428 |
|
|
|
429 |
michael |
4730 |
SSL_CTX_set_options(ConfigServerInfo.server_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TICKET); |
430 |
michael |
4593 |
SSL_CTX_set_options(ConfigServerInfo.server_ctx, SSL_OP_SINGLE_DH_USE|SSL_OP_CIPHER_SERVER_PREFERENCE); |
431 |
michael |
4340 |
SSL_CTX_set_verify(ConfigServerInfo.server_ctx, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE, |
432 |
michael |
2228 |
always_accept_verify_cb); |
433 |
michael |
4730 |
SSL_CTX_set_session_cache_mode(ConfigServerInfo.server_ctx, SSL_SESS_CACHE_OFF); |
434 |
michael |
4892 |
SSL_CTX_set_cipher_list(ConfigServerInfo.server_ctx, "EECDH+HIGH:EDH+HIGH:HIGH:!aNULL"); |
435 |
adx |
30 |
|
436 |
michael |
4744 |
#if OPENSSL_VERSION_NUMBER >= 0x009080FFL && !defined(OPENSSL_NO_ECDH) |
437 |
michael |
4070 |
{ |
438 |
|
|
EC_KEY *key = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1); |
439 |
|
|
|
440 |
|
|
if (key) |
441 |
|
|
{ |
442 |
michael |
4340 |
SSL_CTX_set_tmp_ecdh(ConfigServerInfo.server_ctx, key); |
443 |
michael |
4070 |
EC_KEY_free(key); |
444 |
|
|
} |
445 |
|
|
} |
446 |
|
|
|
447 |
michael |
4340 |
SSL_CTX_set_options(ConfigServerInfo.server_ctx, SSL_OP_SINGLE_ECDH_USE); |
448 |
michael |
4070 |
#endif |
449 |
|
|
|
450 |
michael |
4733 |
if (!(ConfigServerInfo.client_ctx = SSL_CTX_new(SSLv23_client_method()))) |
451 |
michael |
1303 |
{ |
452 |
michael |
4129 |
const char *s = ERR_lib_error_string(ERR_get_error()); |
453 |
michael |
1303 |
|
454 |
michael |
4129 |
fprintf(stderr, "ERROR: Could not initialize the SSL Client context -- %s\n", s); |
455 |
michael |
4763 |
ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Client context -- %s", s); |
456 |
michael |
4497 |
exit(EXIT_FAILURE); |
457 |
michael |
4751 |
return; /* Not reached */ |
458 |
michael |
1303 |
} |
459 |
|
|
|
460 |
michael |
4730 |
SSL_CTX_set_options(ConfigServerInfo.client_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TICKET); |
461 |
michael |
4340 |
SSL_CTX_set_options(ConfigServerInfo.client_ctx, SSL_OP_SINGLE_DH_USE); |
462 |
|
|
SSL_CTX_set_verify(ConfigServerInfo.client_ctx, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE, |
463 |
michael |
2228 |
always_accept_verify_cb); |
464 |
michael |
4730 |
SSL_CTX_set_session_cache_mode(ConfigServerInfo.client_ctx, SSL_SESS_CACHE_OFF); |
465 |
adx |
30 |
#endif /* HAVE_LIBCRYPTO */ |
466 |
|
|
} |
467 |
|
|
|
468 |
|
|
int |
469 |
|
|
main(int argc, char *argv[]) |
470 |
|
|
{ |
471 |
michael |
2253 |
/* Check to see if the user is running us as root, which is a nono */ |
472 |
michael |
4733 |
if (!geteuid()) |
473 |
adx |
30 |
{ |
474 |
michael |
3525 |
fprintf(stderr, "ERROR: This server won't run as root/superuser\n"); |
475 |
michael |
982 |
return -1; |
476 |
adx |
30 |
} |
477 |
|
|
|
478 |
|
|
/* Setup corefile size immediately after boot -kre */ |
479 |
|
|
setup_corefile(); |
480 |
|
|
|
481 |
|
|
/* save server boot time right away, so getrusage works correctly */ |
482 |
|
|
set_time(); |
483 |
|
|
|
484 |
michael |
982 |
/* It ain't random, but it ought to be a little harder to guess */ |
485 |
|
|
init_genrand(SystemTime.tv_sec ^ (SystemTime.tv_usec | (getpid() << 20))); |
486 |
|
|
|
487 |
michael |
2253 |
dlinkAdd(&me, &me.node, &global_client_list); /* Pointer to beginning |
488 |
adx |
30 |
of Client list */ |
489 |
michael |
4340 |
ConfigLog.use_logging = 1; |
490 |
|
|
ConfigGeneral.dpath = DPATH; |
491 |
|
|
ConfigGeneral.spath = SPATH; |
492 |
|
|
ConfigGeneral.mpath = MPATH; |
493 |
|
|
ConfigGeneral.configfile = CPATH; /* Server configuration file */ |
494 |
|
|
ConfigGeneral.klinefile = KPATH; /* Server kline file */ |
495 |
|
|
ConfigGeneral.glinefile = GPATH; /* Server gline file */ |
496 |
|
|
ConfigGeneral.xlinefile = XPATH; /* Server xline file */ |
497 |
|
|
ConfigGeneral.dlinefile = DLPATH; /* dline file */ |
498 |
|
|
ConfigGeneral.resvfile = RESVPATH; /* resv file */ |
499 |
michael |
1702 |
|
500 |
adx |
30 |
myargv = argv; |
501 |
|
|
umask(077); /* better safe than sorry --SRB */ |
502 |
|
|
|
503 |
|
|
parseargs(&argc, &argv, myopts); |
504 |
|
|
|
505 |
|
|
if (printVersion) |
506 |
|
|
{ |
507 |
michael |
2646 |
printf("ircd: version %s(%s)\n", ircd_version, serno); |
508 |
adx |
30 |
exit(EXIT_SUCCESS); |
509 |
|
|
} |
510 |
|
|
|
511 |
michael |
4340 |
if (chdir(ConfigGeneral.dpath)) |
512 |
adx |
30 |
{ |
513 |
|
|
perror("chdir"); |
514 |
|
|
exit(EXIT_FAILURE); |
515 |
|
|
} |
516 |
|
|
|
517 |
michael |
1798 |
ssl_init(); |
518 |
adx |
30 |
|
519 |
|
|
if (!server_state.foreground) |
520 |
|
|
{ |
521 |
|
|
make_daemon(); |
522 |
|
|
close_standard_fds(); /* this needs to be before init_netio()! */ |
523 |
|
|
} |
524 |
|
|
else |
525 |
|
|
print_startup(getpid()); |
526 |
|
|
|
527 |
|
|
setup_signals(); |
528 |
|
|
|
529 |
|
|
/* We need this to initialise the fd array before anything else */ |
530 |
|
|
fdlist_init(); |
531 |
michael |
1831 |
log_set_file(LOG_TYPE_IRCD, 0, logFileName); |
532 |
michael |
4415 |
|
533 |
michael |
2632 |
init_netio(); /* This needs to be setup early ! -- adrian */ |
534 |
michael |
2253 |
|
535 |
adx |
30 |
/* Check if there is pidfile and daemon already running */ |
536 |
|
|
check_pidfile(pidFileName); |
537 |
|
|
|
538 |
michael |
1654 |
mp_pool_init(); |
539 |
adx |
30 |
init_dlink_nodes(); |
540 |
michael |
2159 |
init_isupport(); |
541 |
adx |
30 |
dbuf_init(); |
542 |
michael |
1798 |
hash_init(); |
543 |
michael |
4319 |
ipcache_init(); |
544 |
michael |
1798 |
client_init(); |
545 |
michael |
1632 |
class_init(); |
546 |
michael |
1358 |
whowas_init(); |
547 |
michael |
876 |
watch_init(); |
548 |
michael |
1798 |
auth_init(); /* Initialise the auth code */ |
549 |
michael |
998 |
init_resolver(); /* Needs to be setup before the io loop */ |
550 |
michael |
1404 |
modules_init(); |
551 |
adx |
30 |
read_conf_files(1); /* cold start init conf files */ |
552 |
|
|
init_uid(); |
553 |
|
|
initialize_server_capabs(); /* Set up default_server_capabs */ |
554 |
|
|
initialize_global_set_options(); |
555 |
michael |
1798 |
channel_init(); |
556 |
michael |
2216 |
read_links_file(); |
557 |
michael |
2150 |
motd_init(); |
558 |
michael |
5392 |
user_usermodes_init(); |
559 |
michael |
1858 |
#ifdef HAVE_LIBGEOIP |
560 |
|
|
geoip_ctx = GeoIP_new(GEOIP_MEMORY_CACHE); |
561 |
|
|
#endif |
562 |
adx |
30 |
|
563 |
michael |
4340 |
if (EmptyString(ConfigServerInfo.sid)) |
564 |
adx |
30 |
{ |
565 |
michael |
1247 |
ilog(LOG_TYPE_IRCD, "ERROR: No server id specified in serverinfo block."); |
566 |
adx |
30 |
exit(EXIT_FAILURE); |
567 |
|
|
} |
568 |
michael |
885 |
|
569 |
michael |
4340 |
strlcpy(me.id, ConfigServerInfo.sid, sizeof(me.id)); |
570 |
michael |
1115 |
|
571 |
michael |
4340 |
if (EmptyString(ConfigServerInfo.name)) |
572 |
michael |
1115 |
{ |
573 |
michael |
1247 |
ilog(LOG_TYPE_IRCD, "ERROR: No server name specified in serverinfo block."); |
574 |
michael |
1115 |
exit(EXIT_FAILURE); |
575 |
|
|
} |
576 |
|
|
|
577 |
michael |
4340 |
strlcpy(me.name, ConfigServerInfo.name, sizeof(me.name)); |
578 |
adx |
30 |
|
579 |
|
|
/* serverinfo{} description must exist. If not, error out.*/ |
580 |
michael |
4340 |
if (EmptyString(ConfigServerInfo.description)) |
581 |
adx |
30 |
{ |
582 |
michael |
1247 |
ilog(LOG_TYPE_IRCD, "ERROR: No server description specified in serverinfo block."); |
583 |
adx |
30 |
exit(EXIT_FAILURE); |
584 |
|
|
} |
585 |
michael |
885 |
|
586 |
michael |
4340 |
strlcpy(me.info, ConfigServerInfo.description, sizeof(me.info)); |
587 |
adx |
30 |
|
588 |
michael |
1241 |
me.from = &me; |
589 |
|
|
me.servptr = &me; |
590 |
michael |
4588 |
me.connection->lasttime = CurrentTime; |
591 |
|
|
me.connection->since = CurrentTime; |
592 |
|
|
me.connection->firsttime = CurrentTime; |
593 |
adx |
30 |
|
594 |
|
|
SetMe(&me); |
595 |
|
|
make_server(&me); |
596 |
|
|
|
597 |
michael |
1115 |
hash_add_id(&me); |
598 |
adx |
30 |
hash_add_client(&me); |
599 |
michael |
2916 |
|
600 |
michael |
4209 |
dlinkAdd(&me, make_dlink_node(), &global_server_list); |
601 |
adx |
30 |
|
602 |
michael |
1622 |
load_kline_database(); |
603 |
|
|
load_dline_database(); |
604 |
|
|
load_gline_database(); |
605 |
|
|
load_xline_database(); |
606 |
|
|
load_resv_database(); |
607 |
|
|
|
608 |
adx |
30 |
load_all_modules(1); |
609 |
|
|
load_conf_modules(); |
610 |
|
|
load_core_modules(1); |
611 |
michael |
1115 |
|
612 |
adx |
30 |
write_pidfile(pidFileName); |
613 |
|
|
|
614 |
michael |
1247 |
ilog(LOG_TYPE_IRCD, "Server Ready"); |
615 |
adx |
30 |
|
616 |
michael |
4094 |
event_addish(&event_cleanup_glines, NULL); |
617 |
|
|
event_addish(&event_cleanup_tklines, NULL); |
618 |
adx |
30 |
|
619 |
|
|
/* We want try_connections to be called as soon as possible now! -- adrian */ |
620 |
|
|
/* No, 'cause after a restart it would cause all sorts of nick collides */ |
621 |
michael |
4094 |
event_addish(&event_try_connections, NULL); |
622 |
adx |
30 |
|
623 |
|
|
/* Setup the timeout check. I'll shift it later :) -- adrian */ |
624 |
michael |
4399 |
event_add(&event_comm_checktimeouts, NULL); |
625 |
adx |
30 |
|
626 |
michael |
4094 |
event_addish(&event_save_all_databases, NULL); |
627 |
michael |
1625 |
|
628 |
adx |
30 |
if (ConfigServerHide.links_delay > 0) |
629 |
michael |
4094 |
{ |
630 |
|
|
event_write_links_file.when = ConfigServerHide.links_delay; |
631 |
|
|
event_addish(&event_write_links_file, NULL); |
632 |
|
|
} |
633 |
adx |
30 |
else |
634 |
|
|
ConfigServerHide.links_disabled = 1; |
635 |
|
|
|
636 |
|
|
if (splitmode) |
637 |
michael |
4133 |
event_addish(&splitmode_event, NULL); |
638 |
adx |
30 |
|
639 |
|
|
io_loop(); |
640 |
michael |
885 |
return 0; |
641 |
adx |
30 |
} |