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