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