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