1 |
|
/* |
2 |
< |
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
3 |
< |
* ircd.c: Starts up and runs the ircd. |
2 |
> |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
3 |
|
* |
4 |
< |
* Copyright (C) 2002 by the past and present ircd coders, and others. |
4 |
> |
* Copyright (c) 1997-2014 ircd-hybrid development team |
5 |
|
* |
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 |
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 |
< |
* $Id$ |
20 |
> |
*/ |
21 |
> |
|
22 |
> |
/*! \file ircd.c |
23 |
> |
* \brief Starts up and runs the ircd. |
24 |
> |
* \version $Id$ |
25 |
|
*/ |
26 |
|
|
27 |
|
#include "stdinc.h" |
28 |
< |
#include "s_user.h" |
29 |
< |
#include "tools.h" |
28 |
> |
#include "user.h" |
29 |
> |
#include "list.h" |
30 |
|
#include "ircd.h" |
31 |
|
#include "channel.h" |
30 |
– |
#include "channel_mode.h" |
32 |
|
#include "client.h" |
32 |
– |
#include "common.h" |
33 |
|
#include "event.h" |
34 |
|
#include "fdlist.h" |
35 |
|
#include "hash.h" |
36 |
|
#include "irc_string.h" |
37 |
– |
#include "sprintf_irc.h" |
37 |
|
#include "ircd_signal.h" |
38 |
< |
#include "list.h" |
40 |
< |
#include "s_gline.h" |
38 |
> |
#include "gline.h" |
39 |
|
#include "motd.h" |
40 |
< |
#include "ircd_handler.h" |
43 |
< |
#include "msg.h" /* msgtab */ |
40 |
> |
#include "conf.h" |
41 |
|
#include "hostmask.h" |
45 |
– |
#include "numeric.h" |
46 |
– |
#include "packet.h" |
42 |
|
#include "parse.h" |
43 |
< |
#include "irc_res.h" |
43 |
> |
#include "res.h" |
44 |
|
#include "restart.h" |
45 |
< |
#include "s_auth.h" |
45 |
> |
#include "rng_mt.h" |
46 |
> |
#include "auth.h" |
47 |
|
#include "s_bsd.h" |
48 |
< |
#include "s_conf.h" |
49 |
< |
#include "s_log.h" |
54 |
< |
#include "s_misc.h" |
55 |
< |
#include "s_serv.h" /* try_connections */ |
48 |
> |
#include "log.h" |
49 |
> |
#include "server.h" /* try_connections */ |
50 |
|
#include "send.h" |
51 |
|
#include "whowas.h" |
52 |
|
#include "modules.h" |
53 |
|
#include "memory.h" |
54 |
< |
#include "hook.h" |
54 |
> |
#include "mempool.h" |
55 |
|
#include "ircd_getopt.h" |
62 |
– |
#include "balloc.h" |
63 |
– |
#include "motd.h" |
64 |
– |
#include "supported.h" |
56 |
|
#include "watch.h" |
57 |
+ |
#include "conf_db.h" |
58 |
+ |
#include "conf_class.h" |
59 |
|
|
67 |
– |
/* Try and find the correct name to use with getrlimit() for setting the max. |
68 |
– |
* number of files allowed to be open by this process. |
69 |
– |
*/ |
60 |
|
|
61 |
< |
/* /quote set variables */ |
62 |
< |
struct SetOptions GlobalSetOptions; |
61 |
> |
#ifdef HAVE_LIBGEOIP |
62 |
> |
GeoIP *geoip_ctx; |
63 |
> |
#endif |
64 |
|
|
74 |
– |
/* configuration set from ircd.conf */ |
75 |
– |
struct config_file_entry ConfigFileEntry; |
76 |
– |
/* server info set from ircd.conf */ |
77 |
– |
struct server_info ServerInfo; |
78 |
– |
/* admin info set from ircd.conf */ |
79 |
– |
struct admin_info AdminInfo = { NULL, NULL, NULL }; |
80 |
– |
struct Counter Count = { 0, 0, 0, 0, 0, 0, 0, 0 }; |
81 |
– |
struct ServerState_t server_state = { 0 }; |
82 |
– |
struct logging_entry ConfigLoggingEntry = { 1, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0} }; |
65 |
|
struct ServerStatistics ServerStats; |
66 |
|
struct timeval SystemTime; |
67 |
|
struct Client me; /* That's me */ |
68 |
|
struct LocalUser meLocalUser; /* That's also part of me */ |
69 |
|
|
88 |
– |
static unsigned long initialVMTop = 0; /* top of virtual memory at init */ |
70 |
|
const char *logFileName = LPATH; |
71 |
|
const char *pidFileName = PPATH; |
72 |
|
|
73 |
|
char **myargv; |
93 |
– |
char ircd_platform[PLATFORMLEN]; |
74 |
|
|
75 |
|
int dorehash = 0; |
76 |
|
int doremotd = 0; |
97 |
– |
time_t nextconnect = 1; /* time for next try_connections call */ |
77 |
|
|
78 |
|
/* Set to zero because it should be initialized later using |
79 |
|
* initialize_server_capabs |
80 |
|
*/ |
81 |
< |
int default_server_capabs = 0; |
81 |
> |
unsigned int default_server_capabs; |
82 |
> |
unsigned int splitmode; |
83 |
> |
unsigned int splitchecking; |
84 |
> |
unsigned int split_users; |
85 |
> |
unsigned int split_servers; |
86 |
|
|
87 |
< |
#ifdef HAVE_LIBCRYPTO |
88 |
< |
int bio_spare_fd = -1; |
89 |
< |
#endif |
87 |
> |
static struct event event_cleanup_glines = |
88 |
> |
{ |
89 |
> |
.name = "cleanup_glines", |
90 |
> |
.handler = cleanup_glines, |
91 |
> |
.when = CLEANUP_GLINES_TIME |
92 |
> |
}; |
93 |
|
|
94 |
< |
int splitmode; |
95 |
< |
int splitchecking; |
96 |
< |
int split_users; |
97 |
< |
unsigned int split_servers; |
94 |
> |
static struct event event_cleanup_tklines = |
95 |
> |
{ |
96 |
> |
.name = "cleanup_tklines", |
97 |
> |
.handler = cleanup_tklines, |
98 |
> |
.when = CLEANUP_TKLINES_TIME |
99 |
> |
}; |
100 |
|
|
101 |
< |
/* Do klines the same way hybrid-6 did them, i.e. at the |
102 |
< |
* top of the next io_loop instead of in the same loop as |
103 |
< |
* the klines are being applied. |
104 |
< |
* |
105 |
< |
* This should fix strange CPU starvation as very indirectly reported. |
106 |
< |
* (Why do you people not email bug reports? WHY? WHY?) |
107 |
< |
* |
108 |
< |
* - Dianora |
109 |
< |
*/ |
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 |
< |
int rehashed_klines = 0; |
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 |
|
/* |
136 |
|
* print_startup - print startup information |
138 |
|
static void |
139 |
|
print_startup(int pid) |
140 |
|
{ |
141 |
< |
printf("ircd: version %s\n", ircd_version); |
141 |
> |
printf("ircd: version %s(%s)\n", ircd_version, serno); |
142 |
|
printf("ircd: pid %d\n", pid); |
143 |
|
printf("ircd: running in %s mode from %s\n", !server_state.foreground ? "background" |
144 |
|
: "foreground", ConfigFileEntry.dpath); |
162 |
|
|
163 |
|
setsid(); |
164 |
|
} |
156 |
– |
#endif |
165 |
|
|
166 |
|
static int printVersion = 0; |
167 |
|
|
168 |
< |
struct lgetopt myopts[] = { |
169 |
< |
{"dlinefile", &ConfigFileEntry.dlinefile, |
170 |
< |
STRING, "File to use for dline.conf"}, |
163 |
< |
{"configfile", &ConfigFileEntry.configfile, |
168 |
> |
static struct lgetopt myopts[] = |
169 |
> |
{ |
170 |
> |
{"configfile", &ConfigFileEntry.configfile, |
171 |
|
STRING, "File to use for ircd.conf"}, |
172 |
< |
{"klinefile", &ConfigFileEntry.klinefile, |
173 |
< |
STRING, "File to use for kline.conf"}, |
174 |
< |
{"xlinefile", &ConfigFileEntry.xlinefile, |
175 |
< |
STRING, "File to use for xline.conf"}, |
176 |
< |
{"logfile", &logFileName, |
172 |
> |
{"glinefile", &ConfigFileEntry.glinefile, |
173 |
> |
STRING, "File to use for gline database"}, |
174 |
> |
{"klinefile", &ConfigFileEntry.klinefile, |
175 |
> |
STRING, "File to use for kline database"}, |
176 |
> |
{"dlinefile", &ConfigFileEntry.dlinefile, |
177 |
> |
STRING, "File to use for dline database"}, |
178 |
> |
{"xlinefile", &ConfigFileEntry.xlinefile, |
179 |
> |
STRING, "File to use for xline database"}, |
180 |
> |
{"resvfile", &ConfigFileEntry.resvfile, |
181 |
> |
STRING, "File to use for resv database"}, |
182 |
> |
{"logfile", &logFileName, |
183 |
|
STRING, "File to use for ircd.log"}, |
184 |
|
{"pidfile", &pidFileName, |
185 |
|
STRING, "File to use for process ID"}, |
186 |
< |
{"foreground", &server_state.foreground, |
186 |
> |
{"foreground", &server_state.foreground, |
187 |
|
YESNO, "Run in foreground (don't detach)"}, |
188 |
< |
{"version", &printVersion, |
188 |
> |
{"version", &printVersion, |
189 |
|
YESNO, "Print version and exit"}, |
190 |
|
{"help", NULL, USAGE, "Print this text"}, |
191 |
|
{NULL, NULL, STRING, NULL}, |
194 |
|
void |
195 |
|
set_time(void) |
196 |
|
{ |
197 |
< |
static char to_send[200]; |
185 |
< |
struct timeval newtime; |
186 |
< |
#ifdef _WIN32 |
187 |
< |
FILETIME ft; |
188 |
< |
|
189 |
< |
GetSystemTimeAsFileTime(&ft); |
190 |
< |
if (ft.dwLowDateTime < 0xd53e8000) |
191 |
< |
ft.dwHighDateTime--; |
192 |
< |
ft.dwLowDateTime -= 0xd53e8000; |
193 |
< |
ft.dwHighDateTime -= 0x19db1de; |
194 |
< |
|
195 |
< |
newtime.tv_sec = (*(uint64_t *) &ft) / 10000000; |
196 |
< |
newtime.tv_usec = (*(uint64_t *) &ft) / 10 % 1000000; |
197 |
< |
#else |
198 |
< |
newtime.tv_sec = 0; |
199 |
< |
newtime.tv_usec = 0; |
197 |
> |
struct timeval newtime = { .tv_sec = 0, .tv_usec = 0 }; |
198 |
|
|
199 |
|
if (gettimeofday(&newtime, NULL) == -1) |
200 |
|
{ |
201 |
< |
ilog(L_ERROR, "Clock Failure (%s), TS can be corrupted", |
201 |
> |
ilog(LOG_TYPE_IRCD, "Clock Failure (%s), TS can be corrupted", |
202 |
|
strerror(errno)); |
203 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, |
203 |
> |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
204 |
|
"Clock Failure (%s), TS can be corrupted", |
205 |
|
strerror(errno)); |
206 |
< |
restart("Clock Failure"); |
206 |
> |
server_die("Clock Failure", 1); |
207 |
|
} |
210 |
– |
#endif |
208 |
|
|
209 |
|
if (newtime.tv_sec < CurrentTime) |
210 |
|
{ |
211 |
< |
ircsprintf(to_send, "System clock is running backwards - (%lu < %lu)", |
212 |
< |
(unsigned long)newtime.tv_sec, (unsigned long)CurrentTime); |
213 |
< |
report_error(L_ALL, to_send, me.name, 0); |
211 |
> |
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 |
|
set_back_events(CurrentTime - newtime.tv_sec); |
218 |
|
} |
219 |
|
|
224 |
|
static void |
225 |
|
io_loop(void) |
226 |
|
{ |
227 |
< |
while (1 == 1) |
227 |
> |
while (1) |
228 |
|
{ |
229 |
– |
/* |
230 |
– |
* Maybe we want a flags word? |
231 |
– |
* ie. if (REHASHED_KLINES(global_flags)) |
232 |
– |
* SET_REHASHED_KLINES(global_flags) |
233 |
– |
* CLEAR_REHASHED_KLINES(global_flags) |
234 |
– |
* |
235 |
– |
* - Dianora |
236 |
– |
*/ |
237 |
– |
if (rehashed_klines) |
238 |
– |
{ |
239 |
– |
check_conf_klines(); |
240 |
– |
rehashed_klines = 0; |
241 |
– |
} |
242 |
– |
|
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 |
< |
{ |
248 |
< |
struct Client *client_p = ptr->data; |
249 |
< |
assert(client_p->localClient->list_task); |
250 |
< |
safe_list_channels(client_p, client_p->localClient->list_task, 0); |
251 |
< |
} |
233 |
> |
safe_list_channels(ptr->data, 0); |
234 |
|
} |
235 |
|
|
236 |
< |
/* Run pending events, then get the number of seconds to the next |
237 |
< |
* event |
256 |
< |
*/ |
257 |
< |
while (eventNextTime() <= CurrentTime) |
258 |
< |
eventRun(); |
236 |
> |
/* Run pending events */ |
237 |
> |
event_run(); |
238 |
|
|
239 |
|
comm_select(); |
240 |
|
exit_aborted_clients(); |
241 |
|
free_exited_clients(); |
263 |
– |
send_queued_all(); |
242 |
|
|
243 |
|
/* Check to see whether we have to rehash the configuration .. */ |
244 |
|
if (dorehash) |
246 |
|
rehash(1); |
247 |
|
dorehash = 0; |
248 |
|
} |
249 |
+ |
|
250 |
|
if (doremotd) |
251 |
|
{ |
252 |
< |
read_message_file(&ConfigFileEntry.motd); |
253 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, |
254 |
< |
"Got signal SIGUSR1, reloading ircd motd file"); |
252 |
> |
motd_recache(); |
253 |
> |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
254 |
> |
"Got signal SIGUSR1, reloading motd file(s)"); |
255 |
|
doremotd = 0; |
256 |
|
} |
257 |
|
} |
261 |
|
* |
262 |
|
* inputs - none |
263 |
|
* output - none |
264 |
< |
* side effects - This sets all global set options needed |
264 |
> |
* side effects - This sets all global set options needed |
265 |
|
*/ |
266 |
|
static void |
267 |
|
initialize_global_set_options(void) |
292 |
|
} |
293 |
|
|
294 |
|
GlobalSetOptions.ident_timeout = IDENT_TIMEOUT; |
316 |
– |
GlobalSetOptions.idletime = ConfigFileEntry.idletime; |
295 |
|
/* End of global set options */ |
296 |
|
} |
297 |
|
|
320 |
– |
/* initialize_message_files() |
321 |
– |
* |
322 |
– |
* inputs - none |
323 |
– |
* output - none |
324 |
– |
* side effects - Set up all message files needed, motd etc. |
325 |
– |
*/ |
326 |
– |
static void |
327 |
– |
initialize_message_files(void) |
328 |
– |
{ |
329 |
– |
init_message_file(USER_MOTD, MPATH, &ConfigFileEntry.motd); |
330 |
– |
init_message_file(OPER_MOTD, OPATH, &ConfigFileEntry.opermotd); |
331 |
– |
init_message_file(USER_LINKS, LIPATH, &ConfigFileEntry.linksfile); |
332 |
– |
|
333 |
– |
read_message_file(&ConfigFileEntry.motd); |
334 |
– |
read_message_file(&ConfigFileEntry.opermotd); |
335 |
– |
read_message_file(&ConfigFileEntry.linksfile); |
336 |
– |
|
337 |
– |
init_isupport(); |
338 |
– |
} |
339 |
– |
|
298 |
|
/* initialize_server_capabs() |
299 |
|
* |
300 |
|
* inputs - none |
305 |
|
{ |
306 |
|
add_capability("QS", CAP_QS, 1); |
307 |
|
add_capability("EOB", CAP_EOB, 1); |
308 |
< |
|
351 |
< |
if (ServerInfo.sid != NULL) /* only enable TS6 if we have an SID */ |
352 |
< |
add_capability("TS6", CAP_TS6, 0); |
353 |
< |
|
354 |
< |
add_capability("ZIP", CAP_ZIP, 0); |
308 |
> |
add_capability("TS6", CAP_TS6, 0); |
309 |
|
add_capability("CLUSTER", CAP_CLUSTER, 1); |
310 |
< |
#ifdef HALFOPS |
310 |
> |
add_capability("SVS", CAP_SVS, 1); |
311 |
> |
add_capability("CHW", CAP_CHW, 1); |
312 |
|
add_capability("HOPS", CAP_HOPS, 1); |
358 |
– |
#endif |
313 |
|
} |
314 |
|
|
315 |
|
/* write_pidfile() |
321 |
|
static void |
322 |
|
write_pidfile(const char *filename) |
323 |
|
{ |
324 |
< |
FBFILE *fb; |
324 |
> |
FILE *fb; |
325 |
|
|
326 |
< |
if ((fb = fbopen(filename, "w"))) |
326 |
> |
if ((fb = fopen(filename, "w"))) |
327 |
|
{ |
328 |
< |
char buff[32]; |
328 |
> |
char buff[IRCD_BUFSIZE]; |
329 |
|
unsigned int pid = (unsigned int)getpid(); |
376 |
– |
size_t nbytes = ircsprintf(buff, "%u\n", pid); |
330 |
|
|
331 |
< |
if ((fbputs(buff, fb, nbytes) == -1)) |
332 |
< |
ilog(L_ERROR, "Error writing %u to pid file %s (%s)", |
331 |
> |
snprintf(buff, sizeof(buff), "%u\n", pid); |
332 |
> |
|
333 |
> |
if ((fputs(buff, fb) == -1)) |
334 |
> |
ilog(LOG_TYPE_IRCD, "Error writing %u to pid file %s (%s)", |
335 |
|
pid, filename, strerror(errno)); |
336 |
|
|
337 |
< |
fbclose(fb); |
383 |
< |
return; |
337 |
> |
fclose(fb); |
338 |
|
} |
339 |
|
else |
340 |
|
{ |
341 |
< |
ilog(L_ERROR, "Error opening pid file %s", filename); |
341 |
> |
ilog(LOG_TYPE_IRCD, "Error opening pid file %s", filename); |
342 |
|
} |
343 |
|
} |
344 |
|
|
353 |
|
static void |
354 |
|
check_pidfile(const char *filename) |
355 |
|
{ |
356 |
< |
#ifndef _WIN32 |
357 |
< |
FBFILE *fb; |
404 |
< |
char buff[32]; |
356 |
> |
FILE *fb; |
357 |
> |
char buff[IRCD_BUFSIZE]; |
358 |
|
pid_t pidfromfile; |
359 |
|
|
360 |
|
/* Don't do logging here, since we don't have log() initialised */ |
361 |
< |
if ((fb = fbopen(filename, "r"))) |
361 |
> |
if ((fb = fopen(filename, "r"))) |
362 |
|
{ |
363 |
< |
if (fbgets(buff, 20, fb) == NULL) |
363 |
> |
if (fgets(buff, 20, fb) == NULL) |
364 |
|
{ |
365 |
|
/* log(L_ERROR, "Error reading from pid file %s (%s)", filename, |
366 |
|
* strerror(errno)); |
378 |
|
} |
379 |
|
} |
380 |
|
|
381 |
< |
fbclose(fb); |
381 |
> |
fclose(fb); |
382 |
|
} |
383 |
|
else if (errno != ENOENT) |
384 |
|
{ |
385 |
|
/* log(L_ERROR, "Error opening pid file %s", filename); */ |
386 |
|
} |
434 |
– |
#endif |
387 |
|
} |
388 |
|
|
389 |
|
/* setup_corefile() |
408 |
|
#endif |
409 |
|
} |
410 |
|
|
411 |
+ |
#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 |
|
/* init_ssl() |
420 |
|
* |
421 |
|
* inputs - nothing |
423 |
|
* side effects - setups SSL context. |
424 |
|
*/ |
425 |
|
static void |
426 |
< |
init_ssl(void) |
426 |
> |
ssl_init(void) |
427 |
|
{ |
428 |
|
#ifdef HAVE_LIBCRYPTO |
429 |
+ |
const unsigned char session_id[] = "ircd-hybrid"; |
430 |
+ |
|
431 |
|
SSL_load_error_strings(); |
432 |
|
SSLeay_add_ssl_algorithms(); |
433 |
|
|
434 |
< |
ServerInfo.ctx = SSL_CTX_new(SSLv23_server_method()); |
473 |
< |
if (!ServerInfo.ctx) |
434 |
> |
if ((ServerInfo.server_ctx = SSL_CTX_new(SSLv23_server_method())) == NULL) |
435 |
|
{ |
436 |
< |
const char *s; |
436 |
> |
const char *s = ERR_lib_error_string(ERR_get_error()); |
437 |
|
|
438 |
< |
fprintf(stderr, "ERROR: Could not initialize the SSL context -- %s\n", |
439 |
< |
s = ERR_lib_error_string(ERR_get_error())); |
479 |
< |
ilog(L_CRIT, "ERROR: Could not initialize the SSL context -- %s\n", s); |
438 |
> |
fprintf(stderr, "ERROR: Could not initialize the SSL Server context -- %s\n", s); |
439 |
> |
ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Server context -- %s\n", s); |
440 |
|
} |
441 |
|
|
442 |
< |
SSL_CTX_set_options(ServerInfo.ctx, SSL_OP_NO_SSLv2); |
443 |
< |
SSL_CTX_set_options(ServerInfo.ctx, SSL_OP_TLS_ROLLBACK_BUG|SSL_OP_ALL); |
444 |
< |
SSL_CTX_set_verify(ServerInfo.ctx, SSL_VERIFY_NONE, NULL); |
442 |
> |
SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TLSv1); |
443 |
> |
SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_TLS_ROLLBACK_BUG); |
444 |
> |
SSL_CTX_set_verify(ServerInfo.server_ctx, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE, |
445 |
> |
always_accept_verify_cb); |
446 |
> |
SSL_CTX_set_session_id_context(ServerInfo.server_ctx, session_id, sizeof(session_id) - 1); |
447 |
|
|
448 |
< |
bio_spare_fd = save_spare_fd("SSL private key validation"); |
449 |
< |
#endif /* HAVE_LIBCRYPTO */ |
450 |
< |
} |
448 |
> |
#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 |
< |
/* init_callbacks() |
453 |
< |
* |
454 |
< |
* inputs - nothing |
455 |
< |
* output - nothing |
456 |
< |
* side effects - setups standard hook points |
457 |
< |
*/ |
458 |
< |
static void |
459 |
< |
init_callbacks(void) |
460 |
< |
{ |
461 |
< |
iorecv_cb = register_callback("iorecv", iorecv_default); |
462 |
< |
iosend_cb = register_callback("iosend", iosend_default); |
463 |
< |
iorecvctrl_cb = register_callback("iorecvctrl", NULL); |
464 |
< |
iosendctrl_cb = register_callback("iosendctrl", NULL); |
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 |
> |
if ((ServerInfo.client_ctx = SSL_CTX_new(SSLv23_client_method())) == NULL) |
463 |
> |
{ |
464 |
> |
const char *s = ERR_lib_error_string(ERR_get_error()); |
465 |
> |
|
466 |
> |
fprintf(stderr, "ERROR: Could not initialize the SSL Client context -- %s\n", s); |
467 |
> |
ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Client context -- %s\n", s); |
468 |
> |
} |
469 |
> |
|
470 |
> |
SSL_CTX_set_options(ServerInfo.client_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TLSv1); |
471 |
> |
SSL_CTX_set_options(ServerInfo.client_ctx, SSL_OP_TLS_ROLLBACK_BUG); |
472 |
> |
SSL_CTX_set_verify(ServerInfo.client_ctx, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE, |
473 |
> |
always_accept_verify_cb); |
474 |
> |
#endif /* HAVE_LIBCRYPTO */ |
475 |
|
} |
476 |
|
|
477 |
|
int |
478 |
|
main(int argc, char *argv[]) |
479 |
|
{ |
480 |
< |
/* Check to see if the user is running |
509 |
< |
* us as root, which is a nono |
510 |
< |
*/ |
511 |
< |
#ifndef _WIN32 |
480 |
> |
/* Check to see if the user is running us as root, which is a nono */ |
481 |
|
if (geteuid() == 0) |
482 |
|
{ |
483 |
< |
fprintf(stderr, "Don't run ircd as root!!!\n"); |
484 |
< |
return(-1); |
483 |
> |
fprintf(stderr, "ERROR: This server won't run as root/superuser\n"); |
484 |
> |
return -1; |
485 |
|
} |
486 |
|
|
487 |
|
/* Setup corefile size immediately after boot -kre */ |
488 |
|
setup_corefile(); |
520 |
– |
#endif |
489 |
|
|
490 |
|
/* save server boot time right away, so getrusage works correctly */ |
491 |
|
set_time(); |
492 |
|
|
493 |
< |
/* It ain't random, but it ought to be a little harder to guess */ |
494 |
< |
srand(SystemTime.tv_sec ^ (SystemTime.tv_usec | (getpid() << 20))); |
495 |
< |
memset(&me, 0, sizeof(me)); |
528 |
< |
memset(&meLocalUser, 0, sizeof(meLocalUser)); |
493 |
> |
/* 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 |
|
me.localClient = &meLocalUser; |
497 |
< |
dlinkAdd(&me, &me.node, &global_client_list); /* Pointer to beginning |
497 |
> |
dlinkAdd(&me, &me.node, &global_client_list); /* Pointer to beginning |
498 |
|
of Client list */ |
499 |
< |
|
533 |
< |
memset(&ServerInfo, 0, sizeof(ServerInfo)); |
534 |
< |
memset(&ServerStats, 0, sizeof(ServerStats)); |
535 |
< |
|
536 |
< |
/* Initialise the channel capability usage counts... */ |
537 |
< |
init_chcap_usage_counts(); |
538 |
< |
|
499 |
> |
ConfigLoggingEntry.use_logging = 1; |
500 |
|
ConfigFileEntry.dpath = DPATH; |
501 |
< |
ConfigFileEntry.configfile = CPATH; /* Server configuration file */ |
502 |
< |
ConfigFileEntry.klinefile = KPATH; /* Server kline file */ |
503 |
< |
ConfigFileEntry.xlinefile = XPATH; /* Server xline file */ |
504 |
< |
ConfigFileEntry.rxlinefile = RXPATH; /* Server regex xline file */ |
505 |
< |
ConfigFileEntry.rklinefile = RKPATH; /* Server regex kline file */ |
506 |
< |
ConfigFileEntry.dlinefile = DLPATH; /* dline file */ |
507 |
< |
ConfigFileEntry.glinefile = GPATH; /* gline log file */ |
508 |
< |
ConfigFileEntry.cresvfile = CRESVPATH; /* channel resv file */ |
509 |
< |
ConfigFileEntry.nresvfile = NRESVPATH; /* nick resv file */ |
501 |
> |
ConfigFileEntry.spath = SPATH; |
502 |
> |
ConfigFileEntry.mpath = MPATH; |
503 |
> |
ConfigFileEntry.configfile = CPATH; /* Server configuration file */ |
504 |
> |
ConfigFileEntry.klinefile = KPATH; /* Server kline file */ |
505 |
> |
ConfigFileEntry.glinefile = GPATH; /* Server gline file */ |
506 |
> |
ConfigFileEntry.xlinefile = XPATH; /* Server xline file */ |
507 |
> |
ConfigFileEntry.dlinefile = DLPATH; /* dline file */ |
508 |
> |
ConfigFileEntry.resvfile = RESVPATH; /* resv file */ |
509 |
> |
|
510 |
|
myargv = argv; |
511 |
|
umask(077); /* better safe than sorry --SRB */ |
512 |
|
|
514 |
|
|
515 |
|
if (printVersion) |
516 |
|
{ |
517 |
< |
printf("ircd: version %s\n", ircd_version); |
517 |
> |
printf("ircd: version %s(%s)\n", ircd_version, serno); |
518 |
|
exit(EXIT_SUCCESS); |
519 |
|
} |
520 |
|
|
524 |
|
exit(EXIT_FAILURE); |
525 |
|
} |
526 |
|
|
527 |
< |
init_ssl(); |
527 |
> |
ssl_init(); |
528 |
|
|
568 |
– |
#ifndef _WIN32 |
529 |
|
if (!server_state.foreground) |
530 |
|
{ |
531 |
|
make_daemon(); |
535 |
|
print_startup(getpid()); |
536 |
|
|
537 |
|
setup_signals(); |
578 |
– |
#endif |
538 |
|
|
580 |
– |
get_ircd_platform(ircd_platform); |
581 |
– |
|
582 |
– |
/* Init the event subsystem */ |
583 |
– |
eventInit(); |
539 |
|
/* We need this to initialise the fd array before anything else */ |
540 |
|
fdlist_init(); |
541 |
< |
init_log(logFileName); |
541 |
> |
log_set_file(LOG_TYPE_IRCD, 0, logFileName); |
542 |
|
check_can_use_v6(); |
543 |
< |
init_comm(); /* This needs to be setup early ! -- adrian */ |
543 |
> |
init_netio(); /* This needs to be setup early ! -- adrian */ |
544 |
> |
|
545 |
|
/* Check if there is pidfile and daemon already running */ |
546 |
|
check_pidfile(pidFileName); |
547 |
|
|
548 |
< |
#ifndef NOBALLOC |
593 |
< |
initBlockHeap(); |
594 |
< |
#endif |
548 |
> |
mp_pool_init(); |
549 |
|
init_dlink_nodes(); |
550 |
< |
init_callbacks(); |
597 |
< |
initialize_message_files(); |
550 |
> |
init_isupport(); |
551 |
|
dbuf_init(); |
552 |
< |
init_hash(); |
552 |
> |
hash_init(); |
553 |
|
init_ip_hash_table(); /* client host ip hash table */ |
554 |
|
init_host_hash(); /* Host-hashtable. */ |
555 |
< |
clear_tree_parse(); |
556 |
< |
init_client(); |
557 |
< |
init_class(); |
605 |
< |
init_whowas(); |
555 |
> |
client_init(); |
556 |
> |
class_init(); |
557 |
> |
whowas_init(); |
558 |
|
watch_init(); |
559 |
+ |
auth_init(); /* Initialise the auth code */ |
560 |
+ |
init_resolver(); /* Needs to be setup before the io loop */ |
561 |
+ |
modules_init(); |
562 |
|
read_conf_files(1); /* cold start init conf files */ |
608 |
– |
me.id[0] = '\0'; |
563 |
|
init_uid(); |
610 |
– |
init_auth(); /* Initialise the auth code */ |
611 |
– |
#ifndef _WIN32 |
612 |
– |
init_resolver(); /* Needs to be setup before the io loop */ |
613 |
– |
#endif |
564 |
|
initialize_server_capabs(); /* Set up default_server_capabs */ |
565 |
|
initialize_global_set_options(); |
566 |
< |
init_channels(); |
566 |
> |
channel_init(); |
567 |
> |
read_links_file(); |
568 |
> |
motd_init(); |
569 |
> |
#ifdef HAVE_LIBGEOIP |
570 |
> |
geoip_ctx = GeoIP_new(GEOIP_MEMORY_CACHE); |
571 |
> |
#endif |
572 |
> |
|
573 |
> |
if (EmptyString(ServerInfo.sid)) |
574 |
> |
{ |
575 |
> |
ilog(LOG_TYPE_IRCD, "ERROR: No server id specified in serverinfo block."); |
576 |
> |
exit(EXIT_FAILURE); |
577 |
> |
} |
578 |
> |
|
579 |
> |
strlcpy(me.id, ServerInfo.sid, sizeof(me.id)); |
580 |
|
|
581 |
< |
if (ServerInfo.name == NULL) |
581 |
> |
if (EmptyString(ServerInfo.name)) |
582 |
|
{ |
583 |
< |
ilog(L_CRIT, "No server name specified in serverinfo block."); |
583 |
> |
ilog(LOG_TYPE_IRCD, "ERROR: No server name specified in serverinfo block."); |
584 |
|
exit(EXIT_FAILURE); |
585 |
|
} |
586 |
|
|
587 |
|
strlcpy(me.name, ServerInfo.name, sizeof(me.name)); |
588 |
|
|
589 |
|
/* serverinfo{} description must exist. If not, error out.*/ |
590 |
< |
if (ServerInfo.description == NULL) |
590 |
> |
if (EmptyString(ServerInfo.description)) |
591 |
|
{ |
592 |
< |
ilog(L_CRIT, |
630 |
< |
"ERROR: No server description specified in serverinfo block."); |
592 |
> |
ilog(LOG_TYPE_IRCD, "ERROR: No server description specified in serverinfo block."); |
593 |
|
exit(EXIT_FAILURE); |
594 |
|
} |
595 |
|
|
596 |
|
strlcpy(me.info, ServerInfo.description, sizeof(me.info)); |
597 |
|
|
598 |
< |
me.from = &me; |
599 |
< |
me.servptr = &me; |
598 |
> |
me.from = &me; |
599 |
> |
me.servptr = &me; |
600 |
> |
me.localClient->lasttime = CurrentTime; |
601 |
> |
me.localClient->since = CurrentTime; |
602 |
> |
me.localClient->firsttime = CurrentTime; |
603 |
|
|
604 |
|
SetMe(&me); |
605 |
|
make_server(&me); |
606 |
|
|
607 |
< |
me.lasttime = me.since = me.firsttime = CurrentTime; |
607 |
> |
hash_add_id(&me); |
608 |
|
hash_add_client(&me); |
609 |
< |
|
609 |
> |
|
610 |
|
/* add ourselves to global_serv_list */ |
611 |
|
dlinkAdd(&me, make_dlink_node(), &global_serv_list); |
612 |
|
|
613 |
< |
check_class(); |
613 |
> |
load_kline_database(); |
614 |
> |
load_dline_database(); |
615 |
> |
load_gline_database(); |
616 |
> |
load_xline_database(); |
617 |
> |
load_resv_database(); |
618 |
|
|
650 |
– |
#ifndef STATIC_MODULES |
619 |
|
if (chdir(MODPATH)) |
620 |
|
{ |
621 |
< |
ilog (L_CRIT, "Could not load core modules. Terminating!"); |
621 |
> |
ilog(LOG_TYPE_IRCD, "Could not load core modules. Terminating!"); |
622 |
|
exit(EXIT_FAILURE); |
623 |
|
} |
624 |
|
|
625 |
|
load_all_modules(1); |
626 |
|
load_conf_modules(); |
627 |
|
load_core_modules(1); |
628 |
+ |
|
629 |
|
/* Go back to DPATH after checking to see if we can chdir to MODPATH */ |
630 |
< |
chdir(ConfigFileEntry.dpath); |
631 |
< |
#else |
632 |
< |
load_all_modules(1); |
633 |
< |
#endif |
630 |
> |
if (chdir(ConfigFileEntry.dpath)) |
631 |
> |
{ |
632 |
> |
perror("chdir"); |
633 |
> |
exit(EXIT_FAILURE); |
634 |
> |
} |
635 |
> |
|
636 |
|
/* |
637 |
|
* assemble_umode_buffer() has to be called after |
638 |
|
* reading conf/loading modules. |
641 |
|
|
642 |
|
write_pidfile(pidFileName); |
643 |
|
|
644 |
< |
ilog(L_NOTICE, "Server Ready"); |
644 |
> |
ilog(LOG_TYPE_IRCD, "Server Ready"); |
645 |
|
|
646 |
< |
eventAddIsh("cleanup_glines", cleanup_glines, NULL, CLEANUP_GLINES_TIME); |
647 |
< |
eventAddIsh("cleanup_tklines", cleanup_tklines, NULL, CLEANUP_TKLINES_TIME); |
646 |
> |
event_addish(&event_cleanup_glines, NULL); |
647 |
> |
event_addish(&event_cleanup_tklines, NULL); |
648 |
|
|
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 |
< |
eventAddIsh("try_connections", try_connections, NULL, STARTUP_CONNECTIONS_TIME); |
681 |
< |
|
682 |
< |
eventAddIsh("collect_zipstats", collect_zipstats, NULL, ZIPSTATS_TIME); |
651 |
> |
event_addish(&event_try_connections, NULL); |
652 |
|
|
653 |
|
/* Setup the timeout check. I'll shift it later :) -- adrian */ |
654 |
< |
eventAddIsh("comm_checktimeouts", comm_checktimeouts, NULL, 1); |
654 |
> |
event_addish(&event_comm_checktimeouts, NULL); |
655 |
> |
|
656 |
> |
event_addish(&event_save_all_databases, NULL); |
657 |
|
|
658 |
|
if (ConfigServerHide.links_delay > 0) |
659 |
< |
eventAddIsh("write_links_file", write_links_file, NULL, ConfigServerHide.links_delay); |
659 |
> |
{ |
660 |
> |
event_write_links_file.when = ConfigServerHide.links_delay; |
661 |
> |
event_addish(&event_write_links_file, NULL); |
662 |
> |
} |
663 |
|
else |
664 |
|
ConfigServerHide.links_disabled = 1; |
665 |
|
|
666 |
|
if (splitmode) |
667 |
< |
eventAddIsh("check_splitmode", check_splitmode, NULL, 60); |
667 |
> |
event_addish(&event_check_splitmode, NULL); |
668 |
|
|
669 |
|
io_loop(); |
670 |
|
return 0; |