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 |
michael |
6161 |
#include "id.h" |
37 |
adx |
30 |
#include "irc_string.h" |
38 |
|
|
#include "ircd_signal.h" |
39 |
|
|
#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 |
michael |
6185 |
#include "isupport.h" |
61 |
adx |
30 |
|
62 |
michael |
1858 |
|
63 |
|
|
#ifdef HAVE_LIBGEOIP |
64 |
|
|
GeoIP *geoip_ctx; |
65 |
|
|
#endif |
66 |
michael |
2872 |
|
67 |
michael |
5737 |
struct SetOptions GlobalSetOptions; /* /quote set variables */ |
68 |
michael |
5602 |
struct Counter Count; |
69 |
|
|
struct ServerState_t server_state; |
70 |
|
|
struct ServerStatistics ServerStats; |
71 |
adx |
30 |
struct timeval SystemTime; |
72 |
michael |
5737 |
struct Connection meConnection; /* That's also part of me */ |
73 |
michael |
5470 |
struct Client me = { .connection = &meConnection }; /* That's me */ |
74 |
adx |
30 |
|
75 |
michael |
5460 |
char **myargv; |
76 |
adx |
30 |
const char *logFileName = LPATH; |
77 |
|
|
const char *pidFileName = PPATH; |
78 |
|
|
|
79 |
michael |
5460 |
unsigned int dorehash; |
80 |
|
|
unsigned int doremotd; |
81 |
michael |
1013 |
unsigned int splitmode; |
82 |
|
|
unsigned int splitchecking; |
83 |
|
|
unsigned int split_users; |
84 |
adx |
30 |
unsigned int split_servers; |
85 |
|
|
|
86 |
michael |
4094 |
static struct event event_cleanup_tklines = |
87 |
|
|
{ |
88 |
|
|
.name = "cleanup_tklines", |
89 |
|
|
.handler = cleanup_tklines, |
90 |
|
|
.when = CLEANUP_TKLINES_TIME |
91 |
|
|
}; |
92 |
|
|
|
93 |
|
|
static struct event event_try_connections = |
94 |
|
|
{ |
95 |
|
|
.name = "try_connections", |
96 |
|
|
.handler = try_connections, |
97 |
|
|
.when = STARTUP_CONNECTIONS_TIME |
98 |
|
|
}; |
99 |
|
|
|
100 |
|
|
static struct event event_comm_checktimeouts = |
101 |
|
|
{ |
102 |
|
|
.name = "comm_checktimeouts", |
103 |
|
|
.handler = comm_checktimeouts, |
104 |
|
|
.when = 1 |
105 |
|
|
}; |
106 |
|
|
|
107 |
|
|
static struct event event_save_all_databases = |
108 |
|
|
{ |
109 |
|
|
.name = "save_all_databases", |
110 |
|
|
.handler = save_all_databases, |
111 |
|
|
.when = DATABASE_UPDATE_TIMEOUT |
112 |
|
|
}; |
113 |
|
|
|
114 |
|
|
struct event event_write_links_file = |
115 |
|
|
{ |
116 |
|
|
.name = "write_links_file", |
117 |
|
|
.handler = write_links_file, |
118 |
|
|
}; |
119 |
|
|
|
120 |
|
|
|
121 |
adx |
30 |
/* |
122 |
|
|
* print_startup - print startup information |
123 |
|
|
*/ |
124 |
|
|
static void |
125 |
|
|
print_startup(int pid) |
126 |
|
|
{ |
127 |
michael |
2646 |
printf("ircd: version %s(%s)\n", ircd_version, serno); |
128 |
adx |
30 |
printf("ircd: pid %d\n", pid); |
129 |
|
|
printf("ircd: running in %s mode from %s\n", !server_state.foreground ? "background" |
130 |
michael |
4340 |
: "foreground", ConfigGeneral.dpath); |
131 |
adx |
30 |
} |
132 |
|
|
|
133 |
|
|
static void |
134 |
|
|
make_daemon(void) |
135 |
|
|
{ |
136 |
|
|
int pid; |
137 |
|
|
|
138 |
|
|
if ((pid = fork()) < 0) |
139 |
|
|
{ |
140 |
|
|
perror("fork"); |
141 |
|
|
exit(EXIT_FAILURE); |
142 |
|
|
} |
143 |
|
|
else if (pid > 0) |
144 |
|
|
{ |
145 |
|
|
print_startup(pid); |
146 |
|
|
exit(EXIT_SUCCESS); |
147 |
|
|
} |
148 |
|
|
|
149 |
|
|
setsid(); |
150 |
|
|
} |
151 |
|
|
|
152 |
|
|
static int printVersion = 0; |
153 |
|
|
|
154 |
michael |
3215 |
static struct lgetopt myopts[] = |
155 |
|
|
{ |
156 |
michael |
4340 |
{"configfile", &ConfigGeneral.configfile, |
157 |
adx |
30 |
STRING, "File to use for ircd.conf"}, |
158 |
michael |
4340 |
{"klinefile", &ConfigGeneral.klinefile, |
159 |
michael |
1718 |
STRING, "File to use for kline database"}, |
160 |
michael |
4340 |
{"dlinefile", &ConfigGeneral.dlinefile, |
161 |
michael |
1718 |
STRING, "File to use for dline database"}, |
162 |
michael |
4340 |
{"xlinefile", &ConfigGeneral.xlinefile, |
163 |
michael |
1718 |
STRING, "File to use for xline database"}, |
164 |
michael |
4340 |
{"resvfile", &ConfigGeneral.resvfile, |
165 |
michael |
1718 |
STRING, "File to use for resv database"}, |
166 |
michael |
2916 |
{"logfile", &logFileName, |
167 |
adx |
30 |
STRING, "File to use for ircd.log"}, |
168 |
|
|
{"pidfile", &pidFileName, |
169 |
|
|
STRING, "File to use for process ID"}, |
170 |
michael |
2916 |
{"foreground", &server_state.foreground, |
171 |
adx |
30 |
YESNO, "Run in foreground (don't detach)"}, |
172 |
michael |
2916 |
{"version", &printVersion, |
173 |
adx |
30 |
YESNO, "Print version and exit"}, |
174 |
|
|
{"help", NULL, USAGE, "Print this text"}, |
175 |
|
|
{NULL, NULL, STRING, NULL}, |
176 |
|
|
}; |
177 |
|
|
|
178 |
|
|
void |
179 |
|
|
set_time(void) |
180 |
|
|
{ |
181 |
michael |
2978 |
struct timeval newtime = { .tv_sec = 0, .tv_usec = 0 }; |
182 |
adx |
30 |
|
183 |
|
|
if (gettimeofday(&newtime, NULL) == -1) |
184 |
|
|
{ |
185 |
michael |
1247 |
ilog(LOG_TYPE_IRCD, "Clock Failure (%s), TS can be corrupted", |
186 |
adx |
30 |
strerror(errno)); |
187 |
michael |
1618 |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
188 |
adx |
30 |
"Clock Failure (%s), TS can be corrupted", |
189 |
|
|
strerror(errno)); |
190 |
michael |
3167 |
server_die("Clock Failure", 1); |
191 |
adx |
30 |
} |
192 |
|
|
|
193 |
|
|
if (newtime.tv_sec < CurrentTime) |
194 |
|
|
{ |
195 |
michael |
2980 |
ilog(LOG_TYPE_IRCD, "System clock is running backwards - (%lu < %lu)", |
196 |
|
|
(unsigned long)newtime.tv_sec, (unsigned long)CurrentTime); |
197 |
|
|
sendto_realops_flags(UMODE_DEBUG, L_ALL, SEND_NOTICE, |
198 |
|
|
"System clock is running backwards - (%lu < %lu)", |
199 |
|
|
(unsigned long)newtime.tv_sec, |
200 |
|
|
(unsigned long)CurrentTime); |
201 |
adx |
30 |
set_back_events(CurrentTime - newtime.tv_sec); |
202 |
|
|
} |
203 |
|
|
|
204 |
|
|
SystemTime.tv_sec = newtime.tv_sec; |
205 |
|
|
SystemTime.tv_usec = newtime.tv_usec; |
206 |
|
|
} |
207 |
|
|
|
208 |
|
|
static void |
209 |
|
|
io_loop(void) |
210 |
|
|
{ |
211 |
michael |
3215 |
while (1) |
212 |
adx |
30 |
{ |
213 |
|
|
if (listing_client_list.head) |
214 |
|
|
{ |
215 |
michael |
4815 |
dlink_node *node = NULL, *node_next = NULL; |
216 |
|
|
DLINK_FOREACH_SAFE(node, node_next, listing_client_list.head) |
217 |
|
|
safe_list_channels(node->data, 0); |
218 |
adx |
30 |
} |
219 |
|
|
|
220 |
michael |
4094 |
/* Run pending events */ |
221 |
|
|
event_run(); |
222 |
adx |
30 |
|
223 |
|
|
comm_select(); |
224 |
|
|
exit_aborted_clients(); |
225 |
|
|
free_exited_clients(); |
226 |
|
|
|
227 |
|
|
/* Check to see whether we have to rehash the configuration .. */ |
228 |
|
|
if (dorehash) |
229 |
|
|
{ |
230 |
michael |
4982 |
conf_rehash(1); |
231 |
adx |
30 |
dorehash = 0; |
232 |
|
|
} |
233 |
michael |
3215 |
|
234 |
adx |
30 |
if (doremotd) |
235 |
|
|
{ |
236 |
michael |
2150 |
motd_recache(); |
237 |
michael |
1618 |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
238 |
michael |
3065 |
"Got signal SIGUSR1, reloading motd file(s)"); |
239 |
adx |
30 |
doremotd = 0; |
240 |
|
|
} |
241 |
|
|
} |
242 |
|
|
} |
243 |
|
|
|
244 |
|
|
/* initalialize_global_set_options() |
245 |
|
|
* |
246 |
|
|
* inputs - none |
247 |
|
|
* output - none |
248 |
michael |
2916 |
* side effects - This sets all global set options needed |
249 |
adx |
30 |
*/ |
250 |
|
|
static void |
251 |
|
|
initialize_global_set_options(void) |
252 |
|
|
{ |
253 |
michael |
5489 |
GlobalSetOptions.maxclients = ConfigServerInfo.default_max_clients; |
254 |
michael |
5499 |
GlobalSetOptions.autoconn = 1; |
255 |
adx |
30 |
GlobalSetOptions.spam_time = MIN_JOIN_LEAVE_TIME; |
256 |
michael |
5499 |
GlobalSetOptions.spam_num = MAX_JOIN_LEAVE_COUNT; |
257 |
|
|
GlobalSetOptions.floodcount = ConfigGeneral.default_floodcount; |
258 |
michael |
5489 |
GlobalSetOptions.joinfloodcount = ConfigChannel.default_join_flood_count; |
259 |
|
|
GlobalSetOptions.joinfloodtime = ConfigChannel.default_join_flood_time; |
260 |
adx |
30 |
|
261 |
|
|
split_servers = ConfigChannel.default_split_server_count; |
262 |
|
|
split_users = ConfigChannel.default_split_user_count; |
263 |
|
|
|
264 |
|
|
if (split_users && split_servers && (ConfigChannel.no_create_on_split || |
265 |
|
|
ConfigChannel.no_join_on_split)) |
266 |
|
|
{ |
267 |
|
|
splitmode = 1; |
268 |
|
|
splitchecking = 1; |
269 |
|
|
} |
270 |
|
|
|
271 |
|
|
GlobalSetOptions.ident_timeout = IDENT_TIMEOUT; |
272 |
|
|
} |
273 |
|
|
|
274 |
|
|
/* initialize_server_capabs() |
275 |
|
|
* |
276 |
|
|
* inputs - none |
277 |
|
|
* output - none |
278 |
|
|
*/ |
279 |
|
|
static void |
280 |
|
|
initialize_server_capabs(void) |
281 |
|
|
{ |
282 |
michael |
5796 |
add_capability("QS", CAP_QS); |
283 |
|
|
add_capability("EOB", CAP_EOB); |
284 |
|
|
add_capability("CLUSTER", CAP_CLUSTER); |
285 |
|
|
add_capability("SVS", CAP_SVS); |
286 |
|
|
add_capability("CHW", CAP_CHW); |
287 |
|
|
add_capability("HOPS", CAP_HOPS); |
288 |
adx |
30 |
} |
289 |
|
|
|
290 |
|
|
/* write_pidfile() |
291 |
|
|
* |
292 |
|
|
* inputs - filename+path of pid file |
293 |
|
|
* output - NONE |
294 |
|
|
* side effects - write the pid of the ircd to filename |
295 |
|
|
*/ |
296 |
|
|
static void |
297 |
|
|
write_pidfile(const char *filename) |
298 |
|
|
{ |
299 |
michael |
1325 |
FILE *fb; |
300 |
adx |
30 |
|
301 |
michael |
1325 |
if ((fb = fopen(filename, "w"))) |
302 |
adx |
30 |
{ |
303 |
michael |
2691 |
char buff[IRCD_BUFSIZE]; |
304 |
adx |
30 |
unsigned int pid = (unsigned int)getpid(); |
305 |
|
|
|
306 |
michael |
1325 |
snprintf(buff, sizeof(buff), "%u\n", pid); |
307 |
|
|
|
308 |
michael |
4736 |
if (fputs(buff, fb) == -1) |
309 |
michael |
5737 |
ilog(LOG_TYPE_IRCD, "Error writing to pid file %s: %s", |
310 |
|
|
filename, strerror(errno)); |
311 |
adx |
30 |
|
312 |
michael |
1325 |
fclose(fb); |
313 |
adx |
30 |
} |
314 |
|
|
else |
315 |
michael |
5566 |
ilog(LOG_TYPE_IRCD, "Error opening pid file %s: %s", |
316 |
michael |
4748 |
filename, strerror(errno)); |
317 |
adx |
30 |
} |
318 |
|
|
|
319 |
|
|
/* check_pidfile() |
320 |
|
|
* |
321 |
|
|
* inputs - filename+path of pid file |
322 |
|
|
* output - none |
323 |
|
|
* side effects - reads pid from pidfile and checks if ircd is in process |
324 |
|
|
* list. if it is, gracefully exits |
325 |
|
|
* -kre |
326 |
|
|
*/ |
327 |
|
|
static void |
328 |
|
|
check_pidfile(const char *filename) |
329 |
|
|
{ |
330 |
michael |
1325 |
FILE *fb; |
331 |
michael |
2691 |
char buff[IRCD_BUFSIZE]; |
332 |
adx |
30 |
pid_t pidfromfile; |
333 |
|
|
|
334 |
|
|
/* Don't do logging here, since we don't have log() initialised */ |
335 |
michael |
1325 |
if ((fb = fopen(filename, "r"))) |
336 |
adx |
30 |
{ |
337 |
michael |
4733 |
if (!fgets(buff, 20, fb)) |
338 |
adx |
30 |
{ |
339 |
|
|
/* log(L_ERROR, "Error reading from pid file %s (%s)", filename, |
340 |
|
|
* strerror(errno)); |
341 |
|
|
*/ |
342 |
|
|
} |
343 |
|
|
else |
344 |
|
|
{ |
345 |
|
|
pidfromfile = atoi(buff); |
346 |
|
|
|
347 |
|
|
if (!kill(pidfromfile, 0)) |
348 |
|
|
{ |
349 |
|
|
/* log(L_ERROR, "Server is already running"); */ |
350 |
|
|
printf("ircd: daemon is already running\n"); |
351 |
|
|
exit(-1); |
352 |
|
|
} |
353 |
|
|
} |
354 |
|
|
|
355 |
michael |
1325 |
fclose(fb); |
356 |
adx |
30 |
} |
357 |
|
|
else if (errno != ENOENT) |
358 |
|
|
{ |
359 |
|
|
/* log(L_ERROR, "Error opening pid file %s", filename); */ |
360 |
|
|
} |
361 |
|
|
} |
362 |
|
|
|
363 |
|
|
/* setup_corefile() |
364 |
|
|
* |
365 |
|
|
* inputs - nothing |
366 |
|
|
* output - nothing |
367 |
|
|
* side effects - setups corefile to system limits. |
368 |
|
|
* -kre |
369 |
|
|
*/ |
370 |
|
|
static void |
371 |
|
|
setup_corefile(void) |
372 |
|
|
{ |
373 |
|
|
#ifdef HAVE_SYS_RESOURCE_H |
374 |
|
|
struct rlimit rlim; /* resource limits */ |
375 |
|
|
|
376 |
|
|
/* Set corefilesize to maximum */ |
377 |
|
|
if (!getrlimit(RLIMIT_CORE, &rlim)) |
378 |
|
|
{ |
379 |
|
|
rlim.rlim_cur = rlim.rlim_max; |
380 |
|
|
setrlimit(RLIMIT_CORE, &rlim); |
381 |
|
|
} |
382 |
|
|
#endif |
383 |
|
|
} |
384 |
|
|
|
385 |
michael |
2228 |
#ifdef HAVE_LIBCRYPTO |
386 |
|
|
static int |
387 |
|
|
always_accept_verify_cb(int preverify_ok, X509_STORE_CTX *x509_ctx) |
388 |
|
|
{ |
389 |
|
|
return 1; |
390 |
|
|
} |
391 |
|
|
#endif |
392 |
|
|
|
393 |
adx |
30 |
/* init_ssl() |
394 |
|
|
* |
395 |
|
|
* inputs - nothing |
396 |
|
|
* output - nothing |
397 |
|
|
* side effects - setups SSL context. |
398 |
|
|
*/ |
399 |
|
|
static void |
400 |
michael |
1798 |
ssl_init(void) |
401 |
adx |
30 |
{ |
402 |
|
|
#ifdef HAVE_LIBCRYPTO |
403 |
|
|
SSL_load_error_strings(); |
404 |
|
|
SSLeay_add_ssl_algorithms(); |
405 |
|
|
|
406 |
michael |
4733 |
if (!(ConfigServerInfo.server_ctx = SSL_CTX_new(SSLv23_server_method()))) |
407 |
adx |
30 |
{ |
408 |
michael |
4129 |
const char *s = ERR_lib_error_string(ERR_get_error()); |
409 |
adx |
30 |
|
410 |
michael |
4129 |
fprintf(stderr, "ERROR: Could not initialize the SSL Server context -- %s\n", s); |
411 |
michael |
4763 |
ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Server context -- %s", s); |
412 |
michael |
4497 |
exit(EXIT_FAILURE); |
413 |
michael |
4751 |
return; /* Not reached */ |
414 |
adx |
30 |
} |
415 |
|
|
|
416 |
michael |
4730 |
SSL_CTX_set_options(ConfigServerInfo.server_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TICKET); |
417 |
michael |
4593 |
SSL_CTX_set_options(ConfigServerInfo.server_ctx, SSL_OP_SINGLE_DH_USE|SSL_OP_CIPHER_SERVER_PREFERENCE); |
418 |
michael |
4340 |
SSL_CTX_set_verify(ConfigServerInfo.server_ctx, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE, |
419 |
michael |
2228 |
always_accept_verify_cb); |
420 |
michael |
4730 |
SSL_CTX_set_session_cache_mode(ConfigServerInfo.server_ctx, SSL_SESS_CACHE_OFF); |
421 |
michael |
4892 |
SSL_CTX_set_cipher_list(ConfigServerInfo.server_ctx, "EECDH+HIGH:EDH+HIGH:HIGH:!aNULL"); |
422 |
adx |
30 |
|
423 |
michael |
4744 |
#if OPENSSL_VERSION_NUMBER >= 0x009080FFL && !defined(OPENSSL_NO_ECDH) |
424 |
michael |
4070 |
{ |
425 |
|
|
EC_KEY *key = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1); |
426 |
|
|
|
427 |
|
|
if (key) |
428 |
|
|
{ |
429 |
michael |
4340 |
SSL_CTX_set_tmp_ecdh(ConfigServerInfo.server_ctx, key); |
430 |
michael |
4070 |
EC_KEY_free(key); |
431 |
|
|
} |
432 |
|
|
} |
433 |
|
|
|
434 |
michael |
4340 |
SSL_CTX_set_options(ConfigServerInfo.server_ctx, SSL_OP_SINGLE_ECDH_USE); |
435 |
michael |
4070 |
#endif |
436 |
|
|
|
437 |
michael |
4733 |
if (!(ConfigServerInfo.client_ctx = SSL_CTX_new(SSLv23_client_method()))) |
438 |
michael |
1303 |
{ |
439 |
michael |
4129 |
const char *s = ERR_lib_error_string(ERR_get_error()); |
440 |
michael |
1303 |
|
441 |
michael |
4129 |
fprintf(stderr, "ERROR: Could not initialize the SSL Client context -- %s\n", s); |
442 |
michael |
4763 |
ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Client context -- %s", s); |
443 |
michael |
4497 |
exit(EXIT_FAILURE); |
444 |
michael |
4751 |
return; /* Not reached */ |
445 |
michael |
1303 |
} |
446 |
|
|
|
447 |
michael |
4730 |
SSL_CTX_set_options(ConfigServerInfo.client_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TICKET); |
448 |
michael |
4340 |
SSL_CTX_set_options(ConfigServerInfo.client_ctx, SSL_OP_SINGLE_DH_USE); |
449 |
|
|
SSL_CTX_set_verify(ConfigServerInfo.client_ctx, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE, |
450 |
michael |
2228 |
always_accept_verify_cb); |
451 |
michael |
4730 |
SSL_CTX_set_session_cache_mode(ConfigServerInfo.client_ctx, SSL_SESS_CACHE_OFF); |
452 |
adx |
30 |
#endif /* HAVE_LIBCRYPTO */ |
453 |
|
|
} |
454 |
|
|
|
455 |
|
|
int |
456 |
|
|
main(int argc, char *argv[]) |
457 |
|
|
{ |
458 |
michael |
2253 |
/* Check to see if the user is running us as root, which is a nono */ |
459 |
michael |
4733 |
if (!geteuid()) |
460 |
adx |
30 |
{ |
461 |
michael |
3525 |
fprintf(stderr, "ERROR: This server won't run as root/superuser\n"); |
462 |
michael |
982 |
return -1; |
463 |
adx |
30 |
} |
464 |
|
|
|
465 |
|
|
/* Setup corefile size immediately after boot -kre */ |
466 |
|
|
setup_corefile(); |
467 |
|
|
|
468 |
michael |
5545 |
/* Save server boot time right away, so getrusage works correctly */ |
469 |
adx |
30 |
set_time(); |
470 |
|
|
|
471 |
michael |
5545 |
/* It's not random, but it ought to be a little harder to guess */ |
472 |
michael |
982 |
init_genrand(SystemTime.tv_sec ^ (SystemTime.tv_usec | (getpid() << 20))); |
473 |
|
|
|
474 |
michael |
5545 |
dlinkAdd(&me, &me.node, &global_client_list); |
475 |
|
|
|
476 |
michael |
4340 |
ConfigGeneral.dpath = DPATH; |
477 |
|
|
ConfigGeneral.spath = SPATH; |
478 |
|
|
ConfigGeneral.mpath = MPATH; |
479 |
|
|
ConfigGeneral.configfile = CPATH; /* Server configuration file */ |
480 |
|
|
ConfigGeneral.klinefile = KPATH; /* Server kline file */ |
481 |
|
|
ConfigGeneral.xlinefile = XPATH; /* Server xline file */ |
482 |
|
|
ConfigGeneral.dlinefile = DLPATH; /* dline file */ |
483 |
|
|
ConfigGeneral.resvfile = RESVPATH; /* resv file */ |
484 |
michael |
1702 |
|
485 |
adx |
30 |
myargv = argv; |
486 |
michael |
5723 |
umask(077); /* umask 077: u=rwx,g=,o= */ |
487 |
adx |
30 |
|
488 |
|
|
parseargs(&argc, &argv, myopts); |
489 |
|
|
|
490 |
|
|
if (printVersion) |
491 |
|
|
{ |
492 |
michael |
2646 |
printf("ircd: version %s(%s)\n", ircd_version, serno); |
493 |
adx |
30 |
exit(EXIT_SUCCESS); |
494 |
|
|
} |
495 |
|
|
|
496 |
michael |
4340 |
if (chdir(ConfigGeneral.dpath)) |
497 |
adx |
30 |
{ |
498 |
|
|
perror("chdir"); |
499 |
|
|
exit(EXIT_FAILURE); |
500 |
|
|
} |
501 |
|
|
|
502 |
michael |
1798 |
ssl_init(); |
503 |
adx |
30 |
|
504 |
|
|
if (!server_state.foreground) |
505 |
|
|
{ |
506 |
|
|
make_daemon(); |
507 |
|
|
close_standard_fds(); /* this needs to be before init_netio()! */ |
508 |
|
|
} |
509 |
|
|
else |
510 |
|
|
print_startup(getpid()); |
511 |
|
|
|
512 |
|
|
setup_signals(); |
513 |
|
|
|
514 |
|
|
/* We need this to initialise the fd array before anything else */ |
515 |
|
|
fdlist_init(); |
516 |
michael |
1831 |
log_set_file(LOG_TYPE_IRCD, 0, logFileName); |
517 |
michael |
4415 |
|
518 |
michael |
2632 |
init_netio(); /* This needs to be setup early ! -- adrian */ |
519 |
michael |
2253 |
|
520 |
adx |
30 |
/* Check if there is pidfile and daemon already running */ |
521 |
|
|
check_pidfile(pidFileName); |
522 |
|
|
|
523 |
michael |
1654 |
mp_pool_init(); |
524 |
adx |
30 |
init_dlink_nodes(); |
525 |
michael |
6185 |
isupport_init(); |
526 |
adx |
30 |
dbuf_init(); |
527 |
michael |
1798 |
hash_init(); |
528 |
michael |
4319 |
ipcache_init(); |
529 |
michael |
1798 |
client_init(); |
530 |
michael |
1632 |
class_init(); |
531 |
michael |
1358 |
whowas_init(); |
532 |
michael |
876 |
watch_init(); |
533 |
michael |
1798 |
auth_init(); /* Initialise the auth code */ |
534 |
michael |
998 |
init_resolver(); /* Needs to be setup before the io loop */ |
535 |
michael |
1404 |
modules_init(); |
536 |
adx |
30 |
read_conf_files(1); /* cold start init conf files */ |
537 |
|
|
initialize_server_capabs(); /* Set up default_server_capabs */ |
538 |
michael |
5489 |
initialize_global_set_options(); /* Has to be called after read_conf_files() */ |
539 |
michael |
1798 |
channel_init(); |
540 |
michael |
2216 |
read_links_file(); |
541 |
michael |
2150 |
motd_init(); |
542 |
michael |
6189 |
user_modes_init(); |
543 |
michael |
1858 |
#ifdef HAVE_LIBGEOIP |
544 |
|
|
geoip_ctx = GeoIP_new(GEOIP_MEMORY_CACHE); |
545 |
|
|
#endif |
546 |
adx |
30 |
|
547 |
michael |
4340 |
if (EmptyString(ConfigServerInfo.name)) |
548 |
michael |
1115 |
{ |
549 |
michael |
1247 |
ilog(LOG_TYPE_IRCD, "ERROR: No server name specified in serverinfo block."); |
550 |
michael |
1115 |
exit(EXIT_FAILURE); |
551 |
|
|
} |
552 |
|
|
|
553 |
michael |
4340 |
strlcpy(me.name, ConfigServerInfo.name, sizeof(me.name)); |
554 |
adx |
30 |
|
555 |
|
|
/* serverinfo{} description must exist. If not, error out.*/ |
556 |
michael |
4340 |
if (EmptyString(ConfigServerInfo.description)) |
557 |
adx |
30 |
{ |
558 |
michael |
1247 |
ilog(LOG_TYPE_IRCD, "ERROR: No server description specified in serverinfo block."); |
559 |
adx |
30 |
exit(EXIT_FAILURE); |
560 |
|
|
} |
561 |
michael |
885 |
|
562 |
michael |
4340 |
strlcpy(me.info, ConfigServerInfo.description, sizeof(me.info)); |
563 |
adx |
30 |
|
564 |
michael |
6156 |
if (EmptyString(ConfigServerInfo.sid)) |
565 |
|
|
{ |
566 |
|
|
ilog(LOG_TYPE_IRCD, "Generating server ID"); |
567 |
|
|
generate_sid(); |
568 |
|
|
} |
569 |
|
|
else |
570 |
|
|
{ |
571 |
|
|
strlcpy(me.id, ConfigServerInfo.sid, sizeof(me.id)); |
572 |
|
|
} |
573 |
|
|
|
574 |
michael |
5545 |
me.from = &me; |
575 |
|
|
me.servptr = &me; |
576 |
|
|
me.connection->lasttime = CurrentTime; |
577 |
|
|
me.connection->since = CurrentTime; |
578 |
michael |
4588 |
me.connection->firsttime = CurrentTime; |
579 |
adx |
30 |
|
580 |
|
|
SetMe(&me); |
581 |
|
|
make_server(&me); |
582 |
|
|
|
583 |
michael |
1115 |
hash_add_id(&me); |
584 |
adx |
30 |
hash_add_client(&me); |
585 |
michael |
2916 |
|
586 |
michael |
4209 |
dlinkAdd(&me, make_dlink_node(), &global_server_list); |
587 |
adx |
30 |
|
588 |
michael |
6156 |
init_uid(); |
589 |
|
|
|
590 |
michael |
1622 |
load_kline_database(); |
591 |
|
|
load_dline_database(); |
592 |
|
|
load_xline_database(); |
593 |
|
|
load_resv_database(); |
594 |
|
|
|
595 |
adx |
30 |
load_all_modules(1); |
596 |
|
|
load_conf_modules(); |
597 |
|
|
load_core_modules(1); |
598 |
michael |
1115 |
|
599 |
adx |
30 |
write_pidfile(pidFileName); |
600 |
|
|
|
601 |
michael |
1247 |
ilog(LOG_TYPE_IRCD, "Server Ready"); |
602 |
adx |
30 |
|
603 |
michael |
4094 |
event_addish(&event_cleanup_tklines, NULL); |
604 |
adx |
30 |
|
605 |
|
|
/* We want try_connections to be called as soon as possible now! -- adrian */ |
606 |
|
|
/* No, 'cause after a restart it would cause all sorts of nick collides */ |
607 |
michael |
4094 |
event_addish(&event_try_connections, NULL); |
608 |
adx |
30 |
|
609 |
|
|
/* Setup the timeout check. I'll shift it later :) -- adrian */ |
610 |
michael |
4399 |
event_add(&event_comm_checktimeouts, NULL); |
611 |
adx |
30 |
|
612 |
michael |
4094 |
event_addish(&event_save_all_databases, NULL); |
613 |
michael |
1625 |
|
614 |
adx |
30 |
if (ConfigServerHide.links_delay > 0) |
615 |
michael |
4094 |
{ |
616 |
|
|
event_write_links_file.when = ConfigServerHide.links_delay; |
617 |
|
|
event_addish(&event_write_links_file, NULL); |
618 |
|
|
} |
619 |
adx |
30 |
else |
620 |
|
|
ConfigServerHide.links_disabled = 1; |
621 |
|
|
|
622 |
|
|
if (splitmode) |
623 |
michael |
4133 |
event_addish(&splitmode_event, NULL); |
624 |
adx |
30 |
|
625 |
|
|
io_loop(); |
626 |
michael |
885 |
return 0; |
627 |
adx |
30 |
} |