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