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