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-2015 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 |
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 |
18 |
> |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 |
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" |
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" |
33 |
|
#include "event.h" |
34 |
|
#include "fdlist.h" |
35 |
|
#include "hash.h" |
36 |
|
#include "irc_string.h" |
37 |
|
#include "ircd_signal.h" |
38 |
< |
#include "s_gline.h" |
38 |
> |
#include "gline.h" |
39 |
|
#include "motd.h" |
40 |
+ |
#include "conf.h" |
41 |
|
#include "hostmask.h" |
40 |
– |
#include "numeric.h" |
41 |
– |
#include "packet.h" |
42 |
|
#include "parse.h" |
43 |
< |
#include "irc_res.h" |
43 |
> |
#include "res.h" |
44 |
|
#include "restart.h" |
45 |
|
#include "rng_mt.h" |
46 |
< |
#include "s_auth.h" |
46 |
> |
#include "auth.h" |
47 |
|
#include "s_bsd.h" |
48 |
– |
#include "conf.h" |
48 |
|
#include "log.h" |
49 |
< |
#include "s_misc.h" |
51 |
< |
#include "s_serv.h" /* try_connections */ |
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" |
58 |
– |
#include "balloc.h" |
59 |
– |
#include "motd.h" |
60 |
– |
#include "supported.h" |
56 |
|
#include "watch.h" |
57 |
|
#include "conf_db.h" |
58 |
+ |
#include "conf_class.h" |
59 |
+ |
#include "ipcache.h" |
60 |
|
|
64 |
– |
/* /quote set variables */ |
65 |
– |
struct SetOptions GlobalSetOptions; |
61 |
|
|
62 |
< |
/* configuration set from ircd.conf */ |
63 |
< |
struct config_file_entry ConfigFileEntry; |
64 |
< |
/* server info set from ircd.conf */ |
65 |
< |
struct server_info ServerInfo; |
66 |
< |
/* admin info set from ircd.conf */ |
67 |
< |
struct admin_info AdminInfo = { NULL, NULL, NULL }; |
68 |
< |
struct Counter Count = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; |
74 |
< |
struct ServerState_t server_state = { 0 }; |
75 |
< |
struct logging_entry ConfigLoggingEntry = { .use_logging = 1 }; |
62 |
> |
#ifdef HAVE_LIBGEOIP |
63 |
> |
GeoIP *geoip_ctx; |
64 |
> |
#endif |
65 |
> |
|
66 |
> |
struct SetOptions GlobalSetOptions; /* /quote set variables */ |
67 |
> |
struct Counter Count; |
68 |
> |
struct ServerState_t server_state; |
69 |
|
struct ServerStatistics ServerStats; |
70 |
|
struct timeval SystemTime; |
71 |
< |
struct Client me; /* That's me */ |
72 |
< |
struct LocalUser meLocalUser; /* That's also part of me */ |
71 |
> |
struct Connection meConnection; /* That's also part of me */ |
72 |
> |
struct Client me = { .connection = &meConnection }; /* That's me */ |
73 |
|
|
74 |
+ |
char **myargv; |
75 |
|
const char *logFileName = LPATH; |
76 |
|
const char *pidFileName = PPATH; |
77 |
|
|
78 |
< |
char **myargv; |
79 |
< |
|
86 |
< |
int dorehash = 0; |
87 |
< |
int doremotd = 0; |
88 |
< |
|
89 |
< |
/* Set to zero because it should be initialized later using |
90 |
< |
* initialize_server_capabs |
91 |
< |
*/ |
92 |
< |
int default_server_capabs = 0; |
78 |
> |
unsigned int dorehash; |
79 |
> |
unsigned int doremotd; |
80 |
|
unsigned int splitmode; |
81 |
|
unsigned int splitchecking; |
82 |
|
unsigned int split_users; |
83 |
|
unsigned int split_servers; |
84 |
|
|
85 |
< |
/* Do klines the same way hybrid-6 did them, i.e. at the |
86 |
< |
* top of the next io_loop instead of in the same loop as |
87 |
< |
* the klines are being applied. |
88 |
< |
* |
89 |
< |
* This should fix strange CPU starvation as very indirectly reported. |
90 |
< |
* (Why do you people not email bug reports? WHY? WHY?) |
91 |
< |
* |
92 |
< |
* - Dianora |
93 |
< |
*/ |
85 |
> |
static struct event event_cleanup_glines = |
86 |
> |
{ |
87 |
> |
.name = "cleanup_glines", |
88 |
> |
.handler = cleanup_glines, |
89 |
> |
.when = CLEANUP_GLINES_TIME |
90 |
> |
}; |
91 |
> |
|
92 |
> |
static struct event event_cleanup_tklines = |
93 |
> |
{ |
94 |
> |
.name = "cleanup_tklines", |
95 |
> |
.handler = cleanup_tklines, |
96 |
> |
.when = CLEANUP_TKLINES_TIME |
97 |
> |
}; |
98 |
> |
|
99 |
> |
static struct event event_try_connections = |
100 |
> |
{ |
101 |
> |
.name = "try_connections", |
102 |
> |
.handler = try_connections, |
103 |
> |
.when = STARTUP_CONNECTIONS_TIME |
104 |
> |
}; |
105 |
> |
|
106 |
> |
static struct event event_comm_checktimeouts = |
107 |
> |
{ |
108 |
> |
.name = "comm_checktimeouts", |
109 |
> |
.handler = comm_checktimeouts, |
110 |
> |
.when = 1 |
111 |
> |
}; |
112 |
|
|
113 |
< |
int rehashed_klines = 0; |
113 |
> |
static struct event event_save_all_databases = |
114 |
> |
{ |
115 |
> |
.name = "save_all_databases", |
116 |
> |
.handler = save_all_databases, |
117 |
> |
.when = DATABASE_UPDATE_TIMEOUT |
118 |
> |
}; |
119 |
> |
|
120 |
> |
struct event event_write_links_file = |
121 |
> |
{ |
122 |
> |
.name = "write_links_file", |
123 |
> |
.handler = write_links_file, |
124 |
> |
}; |
125 |
|
|
126 |
|
|
127 |
|
/* |
130 |
|
static void |
131 |
|
print_startup(int pid) |
132 |
|
{ |
133 |
< |
printf("ircd: version %s\n", ircd_version); |
133 |
> |
printf("ircd: version %s(%s)\n", ircd_version, serno); |
134 |
|
printf("ircd: pid %d\n", pid); |
135 |
|
printf("ircd: running in %s mode from %s\n", !server_state.foreground ? "background" |
136 |
< |
: "foreground", ConfigFileEntry.dpath); |
136 |
> |
: "foreground", ConfigGeneral.dpath); |
137 |
|
} |
138 |
|
|
139 |
|
static void |
157 |
|
|
158 |
|
static int printVersion = 0; |
159 |
|
|
160 |
< |
static struct lgetopt myopts[] = { |
161 |
< |
{"dlinefile", &ConfigFileEntry.dlinefile, |
162 |
< |
STRING, "File to use for dline.conf"}, |
147 |
< |
{"configfile", &ConfigFileEntry.configfile, |
160 |
> |
static struct lgetopt myopts[] = |
161 |
> |
{ |
162 |
> |
{"configfile", &ConfigGeneral.configfile, |
163 |
|
STRING, "File to use for ircd.conf"}, |
164 |
< |
{"klinefile", &ConfigFileEntry.klinefile, |
165 |
< |
STRING, "File to use for kline.conf"}, |
166 |
< |
{"xlinefile", &ConfigFileEntry.xlinefile, |
167 |
< |
STRING, "File to use for xline.conf"}, |
168 |
< |
{"logfile", &logFileName, |
164 |
> |
{"glinefile", &ConfigGeneral.glinefile, |
165 |
> |
STRING, "File to use for gline database"}, |
166 |
> |
{"klinefile", &ConfigGeneral.klinefile, |
167 |
> |
STRING, "File to use for kline database"}, |
168 |
> |
{"dlinefile", &ConfigGeneral.dlinefile, |
169 |
> |
STRING, "File to use for dline database"}, |
170 |
> |
{"xlinefile", &ConfigGeneral.xlinefile, |
171 |
> |
STRING, "File to use for xline database"}, |
172 |
> |
{"resvfile", &ConfigGeneral.resvfile, |
173 |
> |
STRING, "File to use for resv database"}, |
174 |
> |
{"logfile", &logFileName, |
175 |
|
STRING, "File to use for ircd.log"}, |
176 |
|
{"pidfile", &pidFileName, |
177 |
|
STRING, "File to use for process ID"}, |
178 |
< |
{"foreground", &server_state.foreground, |
178 |
> |
{"foreground", &server_state.foreground, |
179 |
|
YESNO, "Run in foreground (don't detach)"}, |
180 |
< |
{"version", &printVersion, |
180 |
> |
{"version", &printVersion, |
181 |
|
YESNO, "Print version and exit"}, |
182 |
|
{"help", NULL, USAGE, "Print this text"}, |
183 |
|
{NULL, NULL, STRING, NULL}, |
186 |
|
void |
187 |
|
set_time(void) |
188 |
|
{ |
189 |
< |
static char to_send[200]; |
169 |
< |
struct timeval newtime; |
170 |
< |
newtime.tv_sec = 0; |
171 |
< |
newtime.tv_usec = 0; |
189 |
> |
struct timeval newtime = { .tv_sec = 0, .tv_usec = 0 }; |
190 |
|
|
191 |
|
if (gettimeofday(&newtime, NULL) == -1) |
192 |
|
{ |
195 |
|
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
196 |
|
"Clock Failure (%s), TS can be corrupted", |
197 |
|
strerror(errno)); |
198 |
< |
restart("Clock Failure"); |
198 |
> |
server_die("Clock Failure", 1); |
199 |
|
} |
200 |
|
|
201 |
|
if (newtime.tv_sec < CurrentTime) |
202 |
|
{ |
203 |
< |
snprintf(to_send, sizeof(to_send), |
204 |
< |
"System clock is running backwards - (%lu < %lu)", |
205 |
< |
(unsigned long)newtime.tv_sec, (unsigned long)CurrentTime); |
206 |
< |
report_error(L_ALL, to_send, me.name, 0); |
203 |
> |
ilog(LOG_TYPE_IRCD, "System clock is running backwards - (%lu < %lu)", |
204 |
> |
(unsigned long)newtime.tv_sec, (unsigned long)CurrentTime); |
205 |
> |
sendto_realops_flags(UMODE_DEBUG, L_ALL, SEND_NOTICE, |
206 |
> |
"System clock is running backwards - (%lu < %lu)", |
207 |
> |
(unsigned long)newtime.tv_sec, |
208 |
> |
(unsigned long)CurrentTime); |
209 |
|
set_back_events(CurrentTime - newtime.tv_sec); |
210 |
|
} |
211 |
|
|
216 |
|
static void |
217 |
|
io_loop(void) |
218 |
|
{ |
219 |
< |
while (1 == 1) |
219 |
> |
while (1) |
220 |
|
{ |
201 |
– |
/* |
202 |
– |
* Maybe we want a flags word? |
203 |
– |
* ie. if (REHASHED_KLINES(global_flags)) |
204 |
– |
* SET_REHASHED_KLINES(global_flags) |
205 |
– |
* CLEAR_REHASHED_KLINES(global_flags) |
206 |
– |
* |
207 |
– |
* - Dianora |
208 |
– |
*/ |
209 |
– |
if (rehashed_klines) |
210 |
– |
{ |
211 |
– |
check_conf_klines(); |
212 |
– |
rehashed_klines = 0; |
213 |
– |
} |
214 |
– |
|
221 |
|
if (listing_client_list.head) |
222 |
|
{ |
223 |
< |
dlink_node *ptr = NULL, *ptr_next = NULL; |
224 |
< |
DLINK_FOREACH_SAFE(ptr, ptr_next, listing_client_list.head) |
225 |
< |
{ |
220 |
< |
struct Client *client_p = ptr->data; |
221 |
< |
assert(client_p->localClient->list_task); |
222 |
< |
safe_list_channels(client_p, client_p->localClient->list_task, 0); |
223 |
< |
} |
223 |
> |
dlink_node *node = NULL, *node_next = NULL; |
224 |
> |
DLINK_FOREACH_SAFE(node, node_next, listing_client_list.head) |
225 |
> |
safe_list_channels(node->data, 0); |
226 |
|
} |
227 |
|
|
228 |
< |
/* Run pending events, then get the number of seconds to the next |
229 |
< |
* event |
228 |
< |
*/ |
229 |
< |
while (eventNextTime() <= CurrentTime) |
230 |
< |
eventRun(); |
228 |
> |
/* Run pending events */ |
229 |
> |
event_run(); |
230 |
|
|
231 |
|
comm_select(); |
232 |
|
exit_aborted_clients(); |
233 |
|
free_exited_clients(); |
235 |
– |
send_queued_all(); |
234 |
|
|
235 |
|
/* Check to see whether we have to rehash the configuration .. */ |
236 |
|
if (dorehash) |
237 |
|
{ |
238 |
< |
rehash(1); |
238 |
> |
conf_rehash(1); |
239 |
|
dorehash = 0; |
240 |
|
} |
241 |
+ |
|
242 |
|
if (doremotd) |
243 |
|
{ |
244 |
< |
read_message_file(&ConfigFileEntry.motd); |
244 |
> |
motd_recache(); |
245 |
|
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
246 |
< |
"Got signal SIGUSR1, reloading ircd motd file"); |
246 |
> |
"Got signal SIGUSR1, reloading motd file(s)"); |
247 |
|
doremotd = 0; |
248 |
|
} |
249 |
|
} |
253 |
|
* |
254 |
|
* inputs - none |
255 |
|
* output - none |
256 |
< |
* side effects - This sets all global set options needed |
256 |
> |
* side effects - This sets all global set options needed |
257 |
|
*/ |
258 |
|
static void |
259 |
|
initialize_global_set_options(void) |
260 |
|
{ |
261 |
< |
memset(&GlobalSetOptions, 0, sizeof(GlobalSetOptions)); |
262 |
< |
|
264 |
< |
GlobalSetOptions.autoconn = 1; |
261 |
> |
GlobalSetOptions.maxclients = ConfigServerInfo.default_max_clients; |
262 |
> |
GlobalSetOptions.autoconn = 1; |
263 |
|
GlobalSetOptions.spam_time = MIN_JOIN_LEAVE_TIME; |
264 |
< |
GlobalSetOptions.spam_num = MAX_JOIN_LEAVE_COUNT; |
265 |
< |
|
266 |
< |
if (ConfigFileEntry.default_floodcount) |
267 |
< |
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; |
264 |
> |
GlobalSetOptions.spam_num = MAX_JOIN_LEAVE_COUNT; |
265 |
> |
GlobalSetOptions.floodcount = ConfigGeneral.default_floodcount; |
266 |
> |
GlobalSetOptions.joinfloodcount = ConfigChannel.default_join_flood_count; |
267 |
> |
GlobalSetOptions.joinfloodtime = ConfigChannel.default_join_flood_time; |
268 |
|
|
269 |
|
split_servers = ConfigChannel.default_split_server_count; |
270 |
|
split_users = ConfigChannel.default_split_user_count; |
277 |
|
} |
278 |
|
|
279 |
|
GlobalSetOptions.ident_timeout = IDENT_TIMEOUT; |
288 |
– |
/* End of global set options */ |
289 |
– |
} |
290 |
– |
|
291 |
– |
/* initialize_message_files() |
292 |
– |
* |
293 |
– |
* inputs - none |
294 |
– |
* output - none |
295 |
– |
* side effects - Set up all message files needed, motd etc. |
296 |
– |
*/ |
297 |
– |
static void |
298 |
– |
initialize_message_files(void) |
299 |
– |
{ |
300 |
– |
init_message_file(USER_MOTD, MPATH, &ConfigFileEntry.motd); |
301 |
– |
init_message_file(USER_LINKS, LIPATH, &ConfigFileEntry.linksfile); |
302 |
– |
|
303 |
– |
read_message_file(&ConfigFileEntry.motd); |
304 |
– |
read_message_file(&ConfigFileEntry.linksfile); |
305 |
– |
|
306 |
– |
init_isupport(); |
280 |
|
} |
281 |
|
|
282 |
|
/* initialize_server_capabs() |
287 |
|
static void |
288 |
|
initialize_server_capabs(void) |
289 |
|
{ |
290 |
< |
add_capability("QS", CAP_QS, 1); |
291 |
< |
add_capability("EOB", CAP_EOB, 1); |
292 |
< |
add_capability("TS6", CAP_TS6, 0); |
293 |
< |
add_capability("CLUSTER", CAP_CLUSTER, 1); |
294 |
< |
add_capability("SVS", CAP_SVS, 1); |
295 |
< |
#ifdef HALFOPS |
323 |
< |
add_capability("HOPS", CAP_HOPS, 1); |
324 |
< |
#endif |
290 |
> |
add_capability("QS", CAP_QS); |
291 |
> |
add_capability("EOB", CAP_EOB); |
292 |
> |
add_capability("CLUSTER", CAP_CLUSTER); |
293 |
> |
add_capability("SVS", CAP_SVS); |
294 |
> |
add_capability("CHW", CAP_CHW); |
295 |
> |
add_capability("HOPS", CAP_HOPS); |
296 |
|
} |
297 |
|
|
298 |
|
/* write_pidfile() |
308 |
|
|
309 |
|
if ((fb = fopen(filename, "w"))) |
310 |
|
{ |
311 |
< |
char buff[32]; |
311 |
> |
char buff[IRCD_BUFSIZE]; |
312 |
|
unsigned int pid = (unsigned int)getpid(); |
313 |
|
|
314 |
|
snprintf(buff, sizeof(buff), "%u\n", pid); |
315 |
|
|
316 |
< |
if ((fputs(buff, fb) == -1)) |
317 |
< |
ilog(LOG_TYPE_IRCD, "Error writing %u to pid file %s (%s)", |
318 |
< |
pid, filename, strerror(errno)); |
316 |
> |
if (fputs(buff, fb) == -1) |
317 |
> |
ilog(LOG_TYPE_IRCD, "Error writing to pid file %s: %s", |
318 |
> |
filename, strerror(errno)); |
319 |
|
|
320 |
|
fclose(fb); |
321 |
|
} |
322 |
|
else |
323 |
< |
{ |
324 |
< |
ilog(LOG_TYPE_IRCD, "Error opening pid file %s", filename); |
354 |
< |
} |
323 |
> |
ilog(LOG_TYPE_IRCD, "Error opening pid file %s: %s", |
324 |
> |
filename, strerror(errno)); |
325 |
|
} |
326 |
|
|
327 |
|
/* check_pidfile() |
336 |
|
check_pidfile(const char *filename) |
337 |
|
{ |
338 |
|
FILE *fb; |
339 |
< |
char buff[32]; |
339 |
> |
char buff[IRCD_BUFSIZE]; |
340 |
|
pid_t pidfromfile; |
341 |
|
|
342 |
|
/* Don't do logging here, since we don't have log() initialised */ |
343 |
|
if ((fb = fopen(filename, "r"))) |
344 |
|
{ |
345 |
< |
if (fgets(buff, 20, fb) == NULL) |
345 |
> |
if (!fgets(buff, 20, fb)) |
346 |
|
{ |
347 |
|
/* log(L_ERROR, "Error reading from pid file %s (%s)", filename, |
348 |
|
* strerror(errno)); |
390 |
|
#endif |
391 |
|
} |
392 |
|
|
393 |
+ |
#ifdef HAVE_LIBCRYPTO |
394 |
+ |
static int |
395 |
+ |
always_accept_verify_cb(int preverify_ok, X509_STORE_CTX *x509_ctx) |
396 |
+ |
{ |
397 |
+ |
return 1; |
398 |
+ |
} |
399 |
+ |
#endif |
400 |
+ |
|
401 |
|
/* init_ssl() |
402 |
|
* |
403 |
|
* inputs - nothing |
405 |
|
* side effects - setups SSL context. |
406 |
|
*/ |
407 |
|
static void |
408 |
< |
init_ssl(void) |
408 |
> |
ssl_init(void) |
409 |
|
{ |
410 |
|
#ifdef HAVE_LIBCRYPTO |
411 |
|
SSL_load_error_strings(); |
412 |
|
SSLeay_add_ssl_algorithms(); |
413 |
|
|
414 |
< |
if ((ServerInfo.server_ctx = SSL_CTX_new(SSLv23_server_method())) == NULL) |
414 |
> |
if (!(ConfigServerInfo.server_ctx = SSL_CTX_new(SSLv23_server_method()))) |
415 |
|
{ |
416 |
< |
const char *s; |
416 |
> |
const char *s = ERR_lib_error_string(ERR_get_error()); |
417 |
|
|
418 |
< |
fprintf(stderr, "ERROR: Could not initialize the SSL Server context -- %s\n", |
419 |
< |
s = ERR_lib_error_string(ERR_get_error())); |
420 |
< |
ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Server context -- %s\n", s); |
418 |
> |
fprintf(stderr, "ERROR: Could not initialize the SSL Server context -- %s\n", s); |
419 |
> |
ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Server context -- %s", s); |
420 |
> |
exit(EXIT_FAILURE); |
421 |
> |
return; /* Not reached */ |
422 |
|
} |
423 |
|
|
424 |
< |
SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TLSv1); |
425 |
< |
SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_TLS_ROLLBACK_BUG|SSL_OP_ALL); |
426 |
< |
SSL_CTX_set_verify(ServerInfo.server_ctx, SSL_VERIFY_NONE, NULL); |
424 |
> |
SSL_CTX_set_options(ConfigServerInfo.server_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TICKET); |
425 |
> |
SSL_CTX_set_options(ConfigServerInfo.server_ctx, SSL_OP_SINGLE_DH_USE|SSL_OP_CIPHER_SERVER_PREFERENCE); |
426 |
> |
SSL_CTX_set_verify(ConfigServerInfo.server_ctx, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE, |
427 |
> |
always_accept_verify_cb); |
428 |
> |
SSL_CTX_set_session_cache_mode(ConfigServerInfo.server_ctx, SSL_SESS_CACHE_OFF); |
429 |
> |
SSL_CTX_set_cipher_list(ConfigServerInfo.server_ctx, "EECDH+HIGH:EDH+HIGH:HIGH:!aNULL"); |
430 |
|
|
431 |
< |
if ((ServerInfo.client_ctx = SSL_CTX_new(SSLv23_client_method())) == NULL) |
431 |
> |
#if OPENSSL_VERSION_NUMBER >= 0x009080FFL && !defined(OPENSSL_NO_ECDH) |
432 |
|
{ |
433 |
< |
const char *s; |
433 |
> |
EC_KEY *key = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1); |
434 |
|
|
435 |
< |
fprintf(stderr, "ERROR: Could not initialize the SSL Client context -- %s\n", |
436 |
< |
s = ERR_lib_error_string(ERR_get_error())); |
437 |
< |
ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Client context -- %s\n", s); |
435 |
> |
if (key) |
436 |
> |
{ |
437 |
> |
SSL_CTX_set_tmp_ecdh(ConfigServerInfo.server_ctx, key); |
438 |
> |
EC_KEY_free(key); |
439 |
> |
} |
440 |
|
} |
441 |
|
|
442 |
< |
SSL_CTX_set_options(ServerInfo.client_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TLSv1); |
443 |
< |
SSL_CTX_set_options(ServerInfo.client_ctx, SSL_OP_TLS_ROLLBACK_BUG|SSL_OP_ALL); |
460 |
< |
SSL_CTX_set_verify(ServerInfo.client_ctx, SSL_VERIFY_NONE, NULL); |
461 |
< |
#endif /* HAVE_LIBCRYPTO */ |
462 |
< |
} |
442 |
> |
SSL_CTX_set_options(ConfigServerInfo.server_ctx, SSL_OP_SINGLE_ECDH_USE); |
443 |
> |
#endif |
444 |
|
|
445 |
< |
/* init_callbacks() |
446 |
< |
* |
447 |
< |
* inputs - nothing |
448 |
< |
* output - nothing |
449 |
< |
* side effects - setups standard hook points |
450 |
< |
*/ |
451 |
< |
static void |
452 |
< |
init_callbacks(void) |
453 |
< |
{ |
454 |
< |
iorecv_cb = register_callback("iorecv", iorecv_default); |
455 |
< |
iosend_cb = register_callback("iosend", iosend_default); |
445 |
> |
if (!(ConfigServerInfo.client_ctx = SSL_CTX_new(SSLv23_client_method()))) |
446 |
> |
{ |
447 |
> |
const char *s = ERR_lib_error_string(ERR_get_error()); |
448 |
> |
|
449 |
> |
fprintf(stderr, "ERROR: Could not initialize the SSL Client context -- %s\n", s); |
450 |
> |
ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Client context -- %s", s); |
451 |
> |
exit(EXIT_FAILURE); |
452 |
> |
return; /* Not reached */ |
453 |
> |
} |
454 |
> |
|
455 |
> |
SSL_CTX_set_options(ConfigServerInfo.client_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TICKET); |
456 |
> |
SSL_CTX_set_options(ConfigServerInfo.client_ctx, SSL_OP_SINGLE_DH_USE); |
457 |
> |
SSL_CTX_set_verify(ConfigServerInfo.client_ctx, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE, |
458 |
> |
always_accept_verify_cb); |
459 |
> |
SSL_CTX_set_session_cache_mode(ConfigServerInfo.client_ctx, SSL_SESS_CACHE_OFF); |
460 |
> |
#endif /* HAVE_LIBCRYPTO */ |
461 |
|
} |
462 |
|
|
463 |
|
int |
464 |
|
main(int argc, char *argv[]) |
465 |
|
{ |
466 |
< |
/* Check to see if the user is running |
467 |
< |
* us as root, which is a nono |
482 |
< |
*/ |
483 |
< |
if (geteuid() == 0) |
466 |
> |
/* Check to see if the user is running us as root, which is a nono */ |
467 |
> |
if (!geteuid()) |
468 |
|
{ |
469 |
< |
fprintf(stderr, "Don't run ircd as root!!!\n"); |
469 |
> |
fprintf(stderr, "ERROR: This server won't run as root/superuser\n"); |
470 |
|
return -1; |
471 |
|
} |
472 |
|
|
473 |
|
/* Setup corefile size immediately after boot -kre */ |
474 |
|
setup_corefile(); |
475 |
|
|
476 |
< |
/* save server boot time right away, so getrusage works correctly */ |
476 |
> |
/* Save server boot time right away, so getrusage works correctly */ |
477 |
|
set_time(); |
478 |
|
|
479 |
< |
/* It ain't random, but it ought to be a little harder to guess */ |
479 |
> |
/* It's not random, but it ought to be a little harder to guess */ |
480 |
|
init_genrand(SystemTime.tv_sec ^ (SystemTime.tv_usec | (getpid() << 20))); |
481 |
|
|
482 |
< |
me.localClient = &meLocalUser; |
483 |
< |
dlinkAdd(&me, &me.node, &global_client_list); /* Pointer to beginning |
484 |
< |
of Client list */ |
485 |
< |
/* Initialise the channel capability usage counts... */ |
486 |
< |
init_chcap_usage_counts(); |
487 |
< |
|
488 |
< |
ConfigFileEntry.dpath = DPATH; |
489 |
< |
ConfigFileEntry.configfile = CPATH; /* Server configuration file */ |
490 |
< |
ConfigFileEntry.klinefile = KPATH; /* Server kline file */ |
491 |
< |
ConfigFileEntry.xlinefile = XPATH; /* Server xline file */ |
492 |
< |
ConfigFileEntry.dlinefile = DLPATH; /* dline file */ |
493 |
< |
// ConfigFileEntry.cresvfile = CRESVPATH; /* channel resv file */ |
510 |
< |
// ConfigFileEntry.nresvfile = NRESVPATH; /* nick resv file */ |
482 |
> |
dlinkAdd(&me, &me.node, &global_client_list); |
483 |
> |
|
484 |
> |
ConfigGeneral.dpath = DPATH; |
485 |
> |
ConfigGeneral.spath = SPATH; |
486 |
> |
ConfigGeneral.mpath = MPATH; |
487 |
> |
ConfigGeneral.configfile = CPATH; /* Server configuration file */ |
488 |
> |
ConfigGeneral.klinefile = KPATH; /* Server kline file */ |
489 |
> |
ConfigGeneral.glinefile = GPATH; /* Server gline file */ |
490 |
> |
ConfigGeneral.xlinefile = XPATH; /* Server xline file */ |
491 |
> |
ConfigGeneral.dlinefile = DLPATH; /* dline file */ |
492 |
> |
ConfigGeneral.resvfile = RESVPATH; /* resv file */ |
493 |
> |
|
494 |
|
myargv = argv; |
495 |
< |
umask(077); /* better safe than sorry --SRB */ |
495 |
> |
umask(077); /* umask 077: u=rwx,g=,o= */ |
496 |
|
|
497 |
|
parseargs(&argc, &argv, myopts); |
498 |
|
|
499 |
|
if (printVersion) |
500 |
|
{ |
501 |
< |
printf("ircd: version %s\n", ircd_version); |
501 |
> |
printf("ircd: version %s(%s)\n", ircd_version, serno); |
502 |
|
exit(EXIT_SUCCESS); |
503 |
|
} |
504 |
|
|
505 |
< |
if (chdir(ConfigFileEntry.dpath)) |
505 |
> |
if (chdir(ConfigGeneral.dpath)) |
506 |
|
{ |
507 |
|
perror("chdir"); |
508 |
|
exit(EXIT_FAILURE); |
509 |
|
} |
510 |
|
|
511 |
< |
init_ssl(); |
511 |
> |
ssl_init(); |
512 |
|
|
513 |
|
if (!server_state.foreground) |
514 |
|
{ |
520 |
|
|
521 |
|
setup_signals(); |
522 |
|
|
540 |
– |
/* Init the event subsystem */ |
541 |
– |
eventInit(); |
523 |
|
/* We need this to initialise the fd array before anything else */ |
524 |
|
fdlist_init(); |
525 |
< |
log_add_file(LOG_TYPE_IRCD, 0, logFileName); |
526 |
< |
check_can_use_v6(); |
527 |
< |
init_comm(); /* This needs to be setup early ! -- adrian */ |
525 |
> |
log_set_file(LOG_TYPE_IRCD, 0, logFileName); |
526 |
> |
|
527 |
> |
init_netio(); /* This needs to be setup early ! -- adrian */ |
528 |
> |
|
529 |
|
/* Check if there is pidfile and daemon already running */ |
530 |
|
check_pidfile(pidFileName); |
531 |
|
|
532 |
< |
initBlockHeap(); |
532 |
> |
mp_pool_init(); |
533 |
|
init_dlink_nodes(); |
534 |
< |
init_callbacks(); |
553 |
< |
initialize_message_files(); |
534 |
> |
init_isupport(); |
535 |
|
dbuf_init(); |
536 |
< |
init_hash(); |
537 |
< |
init_ip_hash_table(); /* client host ip hash table */ |
538 |
< |
init_host_hash(); /* Host-hashtable. */ |
539 |
< |
init_client(); |
559 |
< |
init_class(); |
536 |
> |
hash_init(); |
537 |
> |
ipcache_init(); |
538 |
> |
client_init(); |
539 |
> |
class_init(); |
540 |
|
whowas_init(); |
541 |
|
watch_init(); |
542 |
< |
init_auth(); /* Initialise the auth code */ |
542 |
> |
auth_init(); /* Initialise the auth code */ |
543 |
|
init_resolver(); /* Needs to be setup before the io loop */ |
544 |
|
modules_init(); |
545 |
|
read_conf_files(1); /* cold start init conf files */ |
546 |
|
init_uid(); |
547 |
|
initialize_server_capabs(); /* Set up default_server_capabs */ |
548 |
< |
initialize_global_set_options(); |
549 |
< |
init_channels(); |
548 |
> |
initialize_global_set_options(); /* Has to be called after read_conf_files() */ |
549 |
> |
channel_init(); |
550 |
> |
read_links_file(); |
551 |
> |
motd_init(); |
552 |
> |
user_usermodes_init(); |
553 |
> |
#ifdef HAVE_LIBGEOIP |
554 |
> |
geoip_ctx = GeoIP_new(GEOIP_MEMORY_CACHE); |
555 |
> |
#endif |
556 |
|
|
557 |
< |
if (EmptyString(ServerInfo.sid)) |
557 |
> |
if (EmptyString(ConfigServerInfo.sid)) |
558 |
|
{ |
559 |
|
ilog(LOG_TYPE_IRCD, "ERROR: No server id specified in serverinfo block."); |
560 |
|
exit(EXIT_FAILURE); |
561 |
|
} |
562 |
|
|
563 |
< |
strlcpy(me.id, ServerInfo.sid, sizeof(me.id)); |
563 |
> |
strlcpy(me.id, ConfigServerInfo.sid, sizeof(me.id)); |
564 |
|
|
565 |
< |
if (EmptyString(ServerInfo.name)) |
565 |
> |
if (EmptyString(ConfigServerInfo.name)) |
566 |
|
{ |
567 |
|
ilog(LOG_TYPE_IRCD, "ERROR: No server name specified in serverinfo block."); |
568 |
|
exit(EXIT_FAILURE); |
569 |
|
} |
570 |
|
|
571 |
< |
strlcpy(me.name, ServerInfo.name, sizeof(me.name)); |
571 |
> |
strlcpy(me.name, ConfigServerInfo.name, sizeof(me.name)); |
572 |
|
|
573 |
|
/* serverinfo{} description must exist. If not, error out.*/ |
574 |
< |
if (EmptyString(ServerInfo.description)) |
574 |
> |
if (EmptyString(ConfigServerInfo.description)) |
575 |
|
{ |
576 |
|
ilog(LOG_TYPE_IRCD, "ERROR: No server description specified in serverinfo block."); |
577 |
|
exit(EXIT_FAILURE); |
578 |
|
} |
579 |
|
|
580 |
< |
strlcpy(me.info, ServerInfo.description, sizeof(me.info)); |
580 |
> |
strlcpy(me.info, ConfigServerInfo.description, sizeof(me.info)); |
581 |
|
|
582 |
< |
me.from = &me; |
583 |
< |
me.servptr = &me; |
584 |
< |
me.localClient->lasttime = CurrentTime; |
585 |
< |
me.localClient->since = CurrentTime; |
586 |
< |
me.localClient->firsttime = CurrentTime; |
582 |
> |
me.from = &me; |
583 |
> |
me.servptr = &me; |
584 |
> |
me.connection->lasttime = CurrentTime; |
585 |
> |
me.connection->since = CurrentTime; |
586 |
> |
me.connection->firsttime = CurrentTime; |
587 |
|
|
588 |
|
SetMe(&me); |
589 |
|
make_server(&me); |
590 |
|
|
591 |
|
hash_add_id(&me); |
592 |
|
hash_add_client(&me); |
593 |
< |
|
594 |
< |
/* add ourselves to global_serv_list */ |
609 |
< |
dlinkAdd(&me, make_dlink_node(), &global_serv_list); |
593 |
> |
|
594 |
> |
dlinkAdd(&me, make_dlink_node(), &global_server_list); |
595 |
|
|
596 |
|
load_kline_database(); |
597 |
|
load_dline_database(); |
599 |
|
load_xline_database(); |
600 |
|
load_resv_database(); |
601 |
|
|
617 |
– |
if (chdir(MODPATH)) |
618 |
– |
{ |
619 |
– |
ilog(LOG_TYPE_IRCD, "Could not load core modules. Terminating!"); |
620 |
– |
exit(EXIT_FAILURE); |
621 |
– |
} |
622 |
– |
|
602 |
|
load_all_modules(1); |
603 |
|
load_conf_modules(); |
604 |
|
load_core_modules(1); |
605 |
|
|
627 |
– |
/* Go back to DPATH after checking to see if we can chdir to MODPATH */ |
628 |
– |
if (chdir(ConfigFileEntry.dpath)) |
629 |
– |
{ |
630 |
– |
perror("chdir"); |
631 |
– |
exit(EXIT_FAILURE); |
632 |
– |
} |
633 |
– |
|
634 |
– |
/* |
635 |
– |
* assemble_umode_buffer() has to be called after |
636 |
– |
* reading conf/loading modules. |
637 |
– |
*/ |
638 |
– |
assemble_umode_buffer(); |
639 |
– |
|
606 |
|
write_pidfile(pidFileName); |
607 |
|
|
608 |
|
ilog(LOG_TYPE_IRCD, "Server Ready"); |
609 |
|
|
610 |
< |
eventAddIsh("cleanup_glines", cleanup_glines, NULL, CLEANUP_GLINES_TIME); |
611 |
< |
eventAddIsh("cleanup_tklines", cleanup_tklines, NULL, CLEANUP_TKLINES_TIME); |
610 |
> |
event_addish(&event_cleanup_glines, NULL); |
611 |
> |
event_addish(&event_cleanup_tklines, NULL); |
612 |
|
|
613 |
|
/* We want try_connections to be called as soon as possible now! -- adrian */ |
614 |
|
/* No, 'cause after a restart it would cause all sorts of nick collides */ |
615 |
< |
eventAddIsh("try_connections", try_connections, NULL, STARTUP_CONNECTIONS_TIME); |
615 |
> |
event_addish(&event_try_connections, NULL); |
616 |
|
|
617 |
|
/* Setup the timeout check. I'll shift it later :) -- adrian */ |
618 |
< |
eventAddIsh("comm_checktimeouts", comm_checktimeouts, NULL, 1); |
618 |
> |
event_add(&event_comm_checktimeouts, NULL); |
619 |
|
|
620 |
< |
eventAddIsh("save_all_databases", save_all_databases, NULL, DATABASE_UPDATE_TIMEOUT); |
620 |
> |
event_addish(&event_save_all_databases, NULL); |
621 |
|
|
622 |
|
if (ConfigServerHide.links_delay > 0) |
623 |
< |
eventAddIsh("write_links_file", write_links_file, NULL, ConfigServerHide.links_delay); |
623 |
> |
{ |
624 |
> |
event_write_links_file.when = ConfigServerHide.links_delay; |
625 |
> |
event_addish(&event_write_links_file, NULL); |
626 |
> |
} |
627 |
|
else |
628 |
|
ConfigServerHide.links_disabled = 1; |
629 |
|
|
630 |
|
if (splitmode) |
631 |
< |
eventAddIsh("check_splitmode", check_splitmode, NULL, 60); |
631 |
> |
event_addish(&splitmode_event, NULL); |
632 |
|
|
633 |
|
io_loop(); |
634 |
|
return 0; |