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 |
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 |
|
|
61 |
|
|
62 |
< |
/* /quote set variables */ |
63 |
< |
struct SetOptions GlobalSetOptions; |
62 |
> |
#ifdef HAVE_LIBGEOIP |
63 |
> |
GeoIP *geoip_ctx; |
64 |
> |
#endif |
65 |
|
|
67 |
– |
/* configuration set from ircd.conf */ |
68 |
– |
struct config_file_entry ConfigFileEntry; |
69 |
– |
/* server info set from ircd.conf */ |
70 |
– |
struct server_info ServerInfo; |
71 |
– |
/* admin info set from ircd.conf */ |
72 |
– |
struct admin_info AdminInfo = { NULL, NULL, NULL }; |
73 |
– |
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 }; |
76 |
– |
struct ServerStatistics ServerStats; |
66 |
|
struct timeval SystemTime; |
67 |
|
struct Client me; /* That's me */ |
68 |
< |
struct LocalUser meLocalUser; /* That's also part of me */ |
68 |
> |
struct Connection meConnection; /* That's also part of me */ |
69 |
|
|
70 |
|
const char *logFileName = LPATH; |
71 |
|
const char *pidFileName = PPATH; |
72 |
|
|
73 |
|
char **myargv; |
85 |
– |
char ircd_platform[PLATFORMLEN]; |
74 |
|
|
75 |
|
int dorehash = 0; |
76 |
|
int doremotd = 0; |
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 |
< |
/* Do klines the same way hybrid-6 did them, i.e. at the |
88 |
< |
* top of the next io_loop instead of in the same loop as |
89 |
< |
* the klines are being applied. |
90 |
< |
* |
91 |
< |
* This should fix strange CPU starvation as very indirectly reported. |
92 |
< |
* (Why do you people not email bug reports? WHY? WHY?) |
93 |
< |
* |
94 |
< |
* - Dianora |
95 |
< |
*/ |
87 |
> |
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 |
< |
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 |
|
|
129 |
|
/* |
132 |
|
static void |
133 |
|
print_startup(int pid) |
134 |
|
{ |
135 |
< |
printf("ircd: version %s\n", ircd_version); |
135 |
> |
printf("ircd: version %s(%s)\n", ircd_version, serno); |
136 |
|
printf("ircd: pid %d\n", pid); |
137 |
|
printf("ircd: running in %s mode from %s\n", !server_state.foreground ? "background" |
138 |
< |
: "foreground", ConfigFileEntry.dpath); |
138 |
> |
: "foreground", ConfigGeneral.dpath); |
139 |
|
} |
140 |
|
|
141 |
|
static void |
159 |
|
|
160 |
|
static int printVersion = 0; |
161 |
|
|
162 |
< |
static struct lgetopt myopts[] = { |
163 |
< |
{"dlinefile", &ConfigFileEntry.dlinefile, |
164 |
< |
STRING, "File to use for dline.conf"}, |
148 |
< |
{"configfile", &ConfigFileEntry.configfile, |
162 |
> |
static struct lgetopt myopts[] = |
163 |
> |
{ |
164 |
> |
{"configfile", &ConfigGeneral.configfile, |
165 |
|
STRING, "File to use for ircd.conf"}, |
166 |
< |
{"klinefile", &ConfigFileEntry.klinefile, |
167 |
< |
STRING, "File to use for kline.conf"}, |
168 |
< |
{"xlinefile", &ConfigFileEntry.xlinefile, |
169 |
< |
STRING, "File to use for xline.conf"}, |
170 |
< |
{"logfile", &logFileName, |
166 |
> |
{"glinefile", &ConfigGeneral.glinefile, |
167 |
> |
STRING, "File to use for gline database"}, |
168 |
> |
{"klinefile", &ConfigGeneral.klinefile, |
169 |
> |
STRING, "File to use for kline database"}, |
170 |
> |
{"dlinefile", &ConfigGeneral.dlinefile, |
171 |
> |
STRING, "File to use for dline database"}, |
172 |
> |
{"xlinefile", &ConfigGeneral.xlinefile, |
173 |
> |
STRING, "File to use for xline database"}, |
174 |
> |
{"resvfile", &ConfigGeneral.resvfile, |
175 |
> |
STRING, "File to use for resv database"}, |
176 |
> |
{"logfile", &logFileName, |
177 |
|
STRING, "File to use for ircd.log"}, |
178 |
|
{"pidfile", &pidFileName, |
179 |
|
STRING, "File to use for process ID"}, |
180 |
< |
{"foreground", &server_state.foreground, |
180 |
> |
{"foreground", &server_state.foreground, |
181 |
|
YESNO, "Run in foreground (don't detach)"}, |
182 |
< |
{"version", &printVersion, |
182 |
> |
{"version", &printVersion, |
183 |
|
YESNO, "Print version and exit"}, |
184 |
|
{"help", NULL, USAGE, "Print this text"}, |
185 |
|
{NULL, NULL, STRING, NULL}, |
188 |
|
void |
189 |
|
set_time(void) |
190 |
|
{ |
191 |
< |
static char to_send[200]; |
170 |
< |
struct timeval newtime; |
171 |
< |
newtime.tv_sec = 0; |
172 |
< |
newtime.tv_usec = 0; |
191 |
> |
struct timeval newtime = { .tv_sec = 0, .tv_usec = 0 }; |
192 |
|
|
193 |
|
if (gettimeofday(&newtime, NULL) == -1) |
194 |
|
{ |
195 |
|
ilog(LOG_TYPE_IRCD, "Clock Failure (%s), TS can be corrupted", |
196 |
|
strerror(errno)); |
197 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, |
197 |
> |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
198 |
|
"Clock Failure (%s), TS can be corrupted", |
199 |
|
strerror(errno)); |
200 |
< |
restart("Clock Failure"); |
200 |
> |
server_die("Clock Failure", 1); |
201 |
|
} |
202 |
|
|
203 |
|
if (newtime.tv_sec < CurrentTime) |
204 |
|
{ |
205 |
< |
snprintf(to_send, sizeof(to_send), |
206 |
< |
"System clock is running backwards - (%lu < %lu)", |
207 |
< |
(unsigned long)newtime.tv_sec, (unsigned long)CurrentTime); |
208 |
< |
report_error(L_ALL, to_send, me.name, 0); |
205 |
> |
ilog(LOG_TYPE_IRCD, "System clock is running backwards - (%lu < %lu)", |
206 |
> |
(unsigned long)newtime.tv_sec, (unsigned long)CurrentTime); |
207 |
> |
sendto_realops_flags(UMODE_DEBUG, L_ALL, SEND_NOTICE, |
208 |
> |
"System clock is running backwards - (%lu < %lu)", |
209 |
> |
(unsigned long)newtime.tv_sec, |
210 |
> |
(unsigned long)CurrentTime); |
211 |
|
set_back_events(CurrentTime - newtime.tv_sec); |
212 |
|
} |
213 |
|
|
218 |
|
static void |
219 |
|
io_loop(void) |
220 |
|
{ |
221 |
< |
while (1 == 1) |
221 |
> |
while (1) |
222 |
|
{ |
202 |
– |
/* |
203 |
– |
* Maybe we want a flags word? |
204 |
– |
* ie. if (REHASHED_KLINES(global_flags)) |
205 |
– |
* SET_REHASHED_KLINES(global_flags) |
206 |
– |
* CLEAR_REHASHED_KLINES(global_flags) |
207 |
– |
* |
208 |
– |
* - Dianora |
209 |
– |
*/ |
210 |
– |
if (rehashed_klines) |
211 |
– |
{ |
212 |
– |
check_conf_klines(); |
213 |
– |
rehashed_klines = 0; |
214 |
– |
} |
215 |
– |
|
223 |
|
if (listing_client_list.head) |
224 |
|
{ |
225 |
|
dlink_node *ptr = NULL, *ptr_next = NULL; |
226 |
|
DLINK_FOREACH_SAFE(ptr, ptr_next, listing_client_list.head) |
227 |
< |
{ |
221 |
< |
struct Client *client_p = ptr->data; |
222 |
< |
assert(client_p->localClient->list_task); |
223 |
< |
safe_list_channels(client_p, client_p->localClient->list_task, 0); |
224 |
< |
} |
227 |
> |
safe_list_channels(ptr->data, 0); |
228 |
|
} |
229 |
|
|
230 |
< |
/* Run pending events, then get the number of seconds to the next |
231 |
< |
* event |
229 |
< |
*/ |
230 |
< |
while (eventNextTime() <= CurrentTime) |
231 |
< |
eventRun(); |
230 |
> |
/* Run pending events */ |
231 |
> |
event_run(); |
232 |
|
|
233 |
|
comm_select(); |
234 |
|
exit_aborted_clients(); |
235 |
|
free_exited_clients(); |
236 |
– |
send_queued_all(); |
236 |
|
|
237 |
|
/* Check to see whether we have to rehash the configuration .. */ |
238 |
|
if (dorehash) |
240 |
|
rehash(1); |
241 |
|
dorehash = 0; |
242 |
|
} |
243 |
+ |
|
244 |
|
if (doremotd) |
245 |
|
{ |
246 |
< |
read_message_file(&ConfigFileEntry.motd); |
247 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, |
248 |
< |
"Got signal SIGUSR1, reloading ircd motd file"); |
246 |
> |
motd_recache(); |
247 |
> |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
248 |
> |
"Got signal SIGUSR1, reloading motd file(s)"); |
249 |
|
doremotd = 0; |
250 |
|
} |
251 |
|
} |
255 |
|
* |
256 |
|
* inputs - none |
257 |
|
* output - none |
258 |
< |
* side effects - This sets all global set options needed |
258 |
> |
* side effects - This sets all global set options needed |
259 |
|
*/ |
260 |
|
static void |
261 |
|
initialize_global_set_options(void) |
262 |
|
{ |
263 |
– |
memset(&GlobalSetOptions, 0, sizeof(GlobalSetOptions)); |
264 |
– |
|
263 |
|
GlobalSetOptions.autoconn = 1; |
264 |
|
GlobalSetOptions.spam_time = MIN_JOIN_LEAVE_TIME; |
265 |
|
GlobalSetOptions.spam_num = MAX_JOIN_LEAVE_COUNT; |
266 |
|
|
267 |
< |
if (ConfigFileEntry.default_floodcount) |
268 |
< |
GlobalSetOptions.floodcount = ConfigFileEntry.default_floodcount; |
267 |
> |
if (ConfigGeneral.default_floodcount) |
268 |
> |
GlobalSetOptions.floodcount = ConfigGeneral.default_floodcount; |
269 |
|
else |
270 |
|
GlobalSetOptions.floodcount = 10; |
271 |
|
|
284 |
|
} |
285 |
|
|
286 |
|
GlobalSetOptions.ident_timeout = IDENT_TIMEOUT; |
289 |
– |
/* End of global set options */ |
290 |
– |
} |
291 |
– |
|
292 |
– |
/* initialize_message_files() |
293 |
– |
* |
294 |
– |
* inputs - none |
295 |
– |
* output - none |
296 |
– |
* side effects - Set up all message files needed, motd etc. |
297 |
– |
*/ |
298 |
– |
static void |
299 |
– |
initialize_message_files(void) |
300 |
– |
{ |
301 |
– |
init_message_file(USER_MOTD, MPATH, &ConfigFileEntry.motd); |
302 |
– |
init_message_file(OPER_MOTD, OPATH, &ConfigFileEntry.opermotd); |
303 |
– |
init_message_file(USER_LINKS, LIPATH, &ConfigFileEntry.linksfile); |
304 |
– |
|
305 |
– |
read_message_file(&ConfigFileEntry.motd); |
306 |
– |
read_message_file(&ConfigFileEntry.opermotd); |
307 |
– |
read_message_file(&ConfigFileEntry.linksfile); |
308 |
– |
|
309 |
– |
init_isupport(); |
287 |
|
} |
288 |
|
|
289 |
|
/* initialize_server_capabs() |
299 |
|
add_capability("TS6", CAP_TS6, 0); |
300 |
|
add_capability("CLUSTER", CAP_CLUSTER, 1); |
301 |
|
add_capability("SVS", CAP_SVS, 1); |
302 |
< |
#ifdef HALFOPS |
302 |
> |
add_capability("CHW", CAP_CHW, 1); |
303 |
|
add_capability("HOPS", CAP_HOPS, 1); |
327 |
– |
#endif |
304 |
|
} |
305 |
|
|
306 |
|
/* write_pidfile() |
316 |
|
|
317 |
|
if ((fb = fopen(filename, "w"))) |
318 |
|
{ |
319 |
< |
char buff[32]; |
319 |
> |
char buff[IRCD_BUFSIZE]; |
320 |
|
unsigned int pid = (unsigned int)getpid(); |
321 |
|
|
322 |
|
snprintf(buff, sizeof(buff), "%u\n", pid); |
323 |
|
|
324 |
< |
if ((fputs(buff, fb) == -1)) |
324 |
> |
if (fputs(buff, fb) == -1) |
325 |
|
ilog(LOG_TYPE_IRCD, "Error writing %u to pid file %s (%s)", |
326 |
|
pid, filename, strerror(errno)); |
327 |
|
|
345 |
|
check_pidfile(const char *filename) |
346 |
|
{ |
347 |
|
FILE *fb; |
348 |
< |
char buff[32]; |
348 |
> |
char buff[IRCD_BUFSIZE]; |
349 |
|
pid_t pidfromfile; |
350 |
|
|
351 |
|
/* Don't do logging here, since we don't have log() initialised */ |
352 |
|
if ((fb = fopen(filename, "r"))) |
353 |
|
{ |
354 |
< |
if (fgets(buff, 20, fb) == NULL) |
354 |
> |
if (!fgets(buff, 20, fb)) |
355 |
|
{ |
356 |
|
/* log(L_ERROR, "Error reading from pid file %s (%s)", filename, |
357 |
|
* strerror(errno)); |
399 |
|
#endif |
400 |
|
} |
401 |
|
|
402 |
+ |
#ifdef HAVE_LIBCRYPTO |
403 |
+ |
static int |
404 |
+ |
always_accept_verify_cb(int preverify_ok, X509_STORE_CTX *x509_ctx) |
405 |
+ |
{ |
406 |
+ |
return 1; |
407 |
+ |
} |
408 |
+ |
#endif |
409 |
+ |
|
410 |
|
/* init_ssl() |
411 |
|
* |
412 |
|
* inputs - nothing |
414 |
|
* side effects - setups SSL context. |
415 |
|
*/ |
416 |
|
static void |
417 |
< |
init_ssl(void) |
417 |
> |
ssl_init(void) |
418 |
|
{ |
419 |
|
#ifdef HAVE_LIBCRYPTO |
420 |
|
SSL_load_error_strings(); |
421 |
|
SSLeay_add_ssl_algorithms(); |
422 |
|
|
423 |
< |
if ((ServerInfo.server_ctx = SSL_CTX_new(SSLv23_server_method())) == NULL) |
423 |
> |
if (!(ConfigServerInfo.server_ctx = SSL_CTX_new(SSLv23_server_method()))) |
424 |
|
{ |
425 |
< |
const char *s; |
425 |
> |
const char *s = ERR_lib_error_string(ERR_get_error()); |
426 |
|
|
427 |
< |
fprintf(stderr, "ERROR: Could not initialize the SSL Server context -- %s\n", |
444 |
< |
s = ERR_lib_error_string(ERR_get_error())); |
427 |
> |
fprintf(stderr, "ERROR: Could not initialize the SSL Server context -- %s\n", s); |
428 |
|
ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Server context -- %s\n", s); |
429 |
+ |
exit(EXIT_FAILURE); |
430 |
+ |
} |
431 |
+ |
|
432 |
+ |
SSL_CTX_set_options(ConfigServerInfo.server_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TICKET); |
433 |
+ |
SSL_CTX_set_options(ConfigServerInfo.server_ctx, SSL_OP_SINGLE_DH_USE|SSL_OP_CIPHER_SERVER_PREFERENCE); |
434 |
+ |
SSL_CTX_set_verify(ConfigServerInfo.server_ctx, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE, |
435 |
+ |
always_accept_verify_cb); |
436 |
+ |
SSL_CTX_set_session_cache_mode(ConfigServerInfo.server_ctx, SSL_SESS_CACHE_OFF); |
437 |
+ |
|
438 |
+ |
#if OPENSSL_VERSION_NUMBER >= 0x1000005FL && !defined(OPENSSL_NO_ECDH) |
439 |
+ |
{ |
440 |
+ |
EC_KEY *key = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1); |
441 |
+ |
|
442 |
+ |
if (key) |
443 |
+ |
{ |
444 |
+ |
SSL_CTX_set_tmp_ecdh(ConfigServerInfo.server_ctx, key); |
445 |
+ |
EC_KEY_free(key); |
446 |
+ |
} |
447 |
|
} |
448 |
|
|
449 |
< |
SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TLSv1); |
450 |
< |
SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_TLS_ROLLBACK_BUG|SSL_OP_ALL); |
450 |
< |
SSL_CTX_set_verify(ServerInfo.server_ctx, SSL_VERIFY_NONE, NULL); |
449 |
> |
SSL_CTX_set_options(ConfigServerInfo.server_ctx, SSL_OP_SINGLE_ECDH_USE); |
450 |
> |
#endif |
451 |
|
|
452 |
< |
if ((ServerInfo.client_ctx = SSL_CTX_new(SSLv23_client_method())) == NULL) |
452 |
> |
if (!(ConfigServerInfo.client_ctx = SSL_CTX_new(SSLv23_client_method()))) |
453 |
|
{ |
454 |
< |
const char *s; |
454 |
> |
const char *s = ERR_lib_error_string(ERR_get_error()); |
455 |
|
|
456 |
< |
fprintf(stderr, "ERROR: Could not initialize the SSL Client context -- %s\n", |
457 |
< |
s = ERR_lib_error_string(ERR_get_error())); |
456 |
> |
fprintf(stderr, "ERROR: Could not initialize the SSL Client context -- %s\n", s); |
457 |
|
ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Client context -- %s\n", s); |
458 |
+ |
exit(EXIT_FAILURE); |
459 |
|
} |
460 |
|
|
461 |
< |
SSL_CTX_set_options(ServerInfo.client_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TLSv1); |
462 |
< |
SSL_CTX_set_options(ServerInfo.client_ctx, SSL_OP_TLS_ROLLBACK_BUG|SSL_OP_ALL); |
463 |
< |
SSL_CTX_set_verify(ServerInfo.client_ctx, SSL_VERIFY_NONE, NULL); |
461 |
> |
SSL_CTX_set_options(ConfigServerInfo.client_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TICKET); |
462 |
> |
SSL_CTX_set_options(ConfigServerInfo.client_ctx, SSL_OP_SINGLE_DH_USE); |
463 |
> |
SSL_CTX_set_verify(ConfigServerInfo.client_ctx, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE, |
464 |
> |
always_accept_verify_cb); |
465 |
> |
SSL_CTX_set_session_cache_mode(ConfigServerInfo.client_ctx, SSL_SESS_CACHE_OFF); |
466 |
|
#endif /* HAVE_LIBCRYPTO */ |
467 |
|
} |
468 |
|
|
467 |
– |
/* init_callbacks() |
468 |
– |
* |
469 |
– |
* inputs - nothing |
470 |
– |
* output - nothing |
471 |
– |
* side effects - setups standard hook points |
472 |
– |
*/ |
473 |
– |
static void |
474 |
– |
init_callbacks(void) |
475 |
– |
{ |
476 |
– |
iorecv_cb = register_callback("iorecv", iorecv_default); |
477 |
– |
iosend_cb = register_callback("iosend", iosend_default); |
478 |
– |
} |
479 |
– |
|
469 |
|
int |
470 |
|
main(int argc, char *argv[]) |
471 |
|
{ |
472 |
< |
/* Check to see if the user is running |
473 |
< |
* us as root, which is a nono |
485 |
< |
*/ |
486 |
< |
if (geteuid() == 0) |
472 |
> |
/* Check to see if the user is running us as root, which is a nono */ |
473 |
> |
if (!geteuid()) |
474 |
|
{ |
475 |
< |
fprintf(stderr, "Don't run ircd as root!!!\n"); |
475 |
> |
fprintf(stderr, "ERROR: This server won't run as root/superuser\n"); |
476 |
|
return -1; |
477 |
|
} |
478 |
|
|
485 |
|
/* 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 |
< |
me.localClient = &meLocalUser; |
489 |
< |
dlinkAdd(&me, &me.node, &global_client_list); /* Pointer to beginning |
488 |
> |
me.connection = &meConnection; |
489 |
> |
dlinkAdd(&me, &me.node, &global_client_list); /* Pointer to beginning |
490 |
|
of Client list */ |
491 |
< |
/* Initialise the channel capability usage counts... */ |
492 |
< |
init_chcap_usage_counts(); |
491 |
> |
ConfigLog.use_logging = 1; |
492 |
> |
ConfigGeneral.dpath = DPATH; |
493 |
> |
ConfigGeneral.spath = SPATH; |
494 |
> |
ConfigGeneral.mpath = MPATH; |
495 |
> |
ConfigGeneral.configfile = CPATH; /* Server configuration file */ |
496 |
> |
ConfigGeneral.klinefile = KPATH; /* Server kline file */ |
497 |
> |
ConfigGeneral.glinefile = GPATH; /* Server gline file */ |
498 |
> |
ConfigGeneral.xlinefile = XPATH; /* Server xline file */ |
499 |
> |
ConfigGeneral.dlinefile = DLPATH; /* dline file */ |
500 |
> |
ConfigGeneral.resvfile = RESVPATH; /* resv file */ |
501 |
|
|
507 |
– |
ConfigFileEntry.dpath = DPATH; |
508 |
– |
ConfigFileEntry.configfile = CPATH; /* Server configuration file */ |
509 |
– |
ConfigFileEntry.klinefile = KPATH; /* Server kline file */ |
510 |
– |
ConfigFileEntry.xlinefile = XPATH; /* Server xline file */ |
511 |
– |
ConfigFileEntry.rxlinefile = RXPATH; /* Server regex xline file */ |
512 |
– |
ConfigFileEntry.rklinefile = RKPATH; /* Server regex kline file */ |
513 |
– |
ConfigFileEntry.dlinefile = DLPATH; /* dline file */ |
514 |
– |
ConfigFileEntry.glinefile = GPATH; /* gline log file */ |
515 |
– |
ConfigFileEntry.cresvfile = CRESVPATH; /* channel resv file */ |
516 |
– |
ConfigFileEntry.nresvfile = NRESVPATH; /* nick resv file */ |
502 |
|
myargv = argv; |
503 |
|
umask(077); /* better safe than sorry --SRB */ |
504 |
|
|
506 |
|
|
507 |
|
if (printVersion) |
508 |
|
{ |
509 |
< |
printf("ircd: version %s\n", ircd_version); |
509 |
> |
printf("ircd: version %s(%s)\n", ircd_version, serno); |
510 |
|
exit(EXIT_SUCCESS); |
511 |
|
} |
512 |
|
|
513 |
< |
if (chdir(ConfigFileEntry.dpath)) |
513 |
> |
if (chdir(ConfigGeneral.dpath)) |
514 |
|
{ |
515 |
|
perror("chdir"); |
516 |
|
exit(EXIT_FAILURE); |
517 |
|
} |
518 |
|
|
519 |
< |
init_ssl(); |
519 |
> |
ssl_init(); |
520 |
|
|
521 |
|
if (!server_state.foreground) |
522 |
|
{ |
528 |
|
|
529 |
|
setup_signals(); |
530 |
|
|
546 |
– |
get_ircd_platform(ircd_platform); |
547 |
– |
|
548 |
– |
/* Init the event subsystem */ |
549 |
– |
eventInit(); |
531 |
|
/* We need this to initialise the fd array before anything else */ |
532 |
|
fdlist_init(); |
533 |
< |
log_add_file(LOG_TYPE_IRCD, 0, logFileName); |
534 |
< |
check_can_use_v6(); |
535 |
< |
init_comm(); /* This needs to be setup early ! -- adrian */ |
533 |
> |
log_set_file(LOG_TYPE_IRCD, 0, logFileName); |
534 |
> |
|
535 |
> |
init_netio(); /* This needs to be setup early ! -- adrian */ |
536 |
> |
|
537 |
|
/* Check if there is pidfile and daemon already running */ |
538 |
|
check_pidfile(pidFileName); |
539 |
|
|
540 |
< |
initBlockHeap(); |
540 |
> |
mp_pool_init(); |
541 |
|
init_dlink_nodes(); |
542 |
< |
init_callbacks(); |
561 |
< |
initialize_message_files(); |
542 |
> |
init_isupport(); |
543 |
|
dbuf_init(); |
544 |
< |
init_hash(); |
545 |
< |
init_ip_hash_table(); /* client host ip hash table */ |
544 |
> |
hash_init(); |
545 |
> |
ipcache_init(); |
546 |
|
init_host_hash(); /* Host-hashtable. */ |
547 |
< |
clear_tree_parse(); |
548 |
< |
init_client(); |
549 |
< |
init_class(); |
569 |
< |
init_whowas(); |
547 |
> |
client_init(); |
548 |
> |
class_init(); |
549 |
> |
whowas_init(); |
550 |
|
watch_init(); |
551 |
< |
init_auth(); /* Initialise the auth code */ |
551 |
> |
auth_init(); /* Initialise the auth code */ |
552 |
|
init_resolver(); /* Needs to be setup before the io loop */ |
553 |
+ |
modules_init(); |
554 |
|
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 |
< |
init_channels(); |
558 |
> |
channel_init(); |
559 |
> |
read_links_file(); |
560 |
> |
motd_init(); |
561 |
> |
#ifdef HAVE_LIBGEOIP |
562 |
> |
geoip_ctx = GeoIP_new(GEOIP_MEMORY_CACHE); |
563 |
> |
#endif |
564 |
|
|
565 |
< |
if (EmptyString(ServerInfo.sid)) |
565 |
> |
if (EmptyString(ConfigServerInfo.sid)) |
566 |
|
{ |
567 |
|
ilog(LOG_TYPE_IRCD, "ERROR: No server id specified in serverinfo block."); |
568 |
|
exit(EXIT_FAILURE); |
569 |
|
} |
570 |
|
|
571 |
< |
strlcpy(me.id, ServerInfo.sid, sizeof(me.id)); |
571 |
> |
strlcpy(me.id, ConfigServerInfo.sid, sizeof(me.id)); |
572 |
|
|
573 |
< |
if (EmptyString(ServerInfo.name)) |
573 |
> |
if (EmptyString(ConfigServerInfo.name)) |
574 |
|
{ |
575 |
|
ilog(LOG_TYPE_IRCD, "ERROR: No server name specified in serverinfo block."); |
576 |
|
exit(EXIT_FAILURE); |
577 |
|
} |
578 |
|
|
579 |
< |
strlcpy(me.name, ServerInfo.name, sizeof(me.name)); |
579 |
> |
strlcpy(me.name, ConfigServerInfo.name, sizeof(me.name)); |
580 |
|
|
581 |
|
/* serverinfo{} description must exist. If not, error out.*/ |
582 |
< |
if (EmptyString(ServerInfo.description)) |
582 |
> |
if (EmptyString(ConfigServerInfo.description)) |
583 |
|
{ |
584 |
|
ilog(LOG_TYPE_IRCD, "ERROR: No server description specified in serverinfo block."); |
585 |
|
exit(EXIT_FAILURE); |
586 |
|
} |
587 |
|
|
588 |
< |
strlcpy(me.info, ServerInfo.description, sizeof(me.info)); |
588 |
> |
strlcpy(me.info, ConfigServerInfo.description, sizeof(me.info)); |
589 |
|
|
590 |
|
me.from = &me; |
591 |
|
me.servptr = &me; |
592 |
< |
me.localClient->lasttime = CurrentTime; |
593 |
< |
me.localClient->since = CurrentTime; |
594 |
< |
me.localClient->firsttime = CurrentTime; |
592 |
> |
me.connection->lasttime = CurrentTime; |
593 |
> |
me.connection->since = CurrentTime; |
594 |
> |
me.connection->firsttime = CurrentTime; |
595 |
|
|
596 |
|
SetMe(&me); |
597 |
|
make_server(&me); |
598 |
|
|
599 |
|
hash_add_id(&me); |
600 |
|
hash_add_client(&me); |
601 |
< |
|
602 |
< |
/* add ourselves to global_serv_list */ |
603 |
< |
dlinkAdd(&me, make_dlink_node(), &global_serv_list); |
601 |
> |
|
602 |
> |
dlinkAdd(&me, make_dlink_node(), &global_server_list); |
603 |
> |
|
604 |
> |
load_kline_database(); |
605 |
> |
load_dline_database(); |
606 |
> |
load_gline_database(); |
607 |
> |
load_xline_database(); |
608 |
> |
load_resv_database(); |
609 |
|
|
610 |
|
if (chdir(MODPATH)) |
611 |
|
{ |
618 |
|
load_core_modules(1); |
619 |
|
|
620 |
|
/* Go back to DPATH after checking to see if we can chdir to MODPATH */ |
621 |
< |
if (chdir(ConfigFileEntry.dpath)) |
621 |
> |
if (chdir(ConfigGeneral.dpath)) |
622 |
|
{ |
623 |
|
perror("chdir"); |
624 |
|
exit(EXIT_FAILURE); |
634 |
|
|
635 |
|
ilog(LOG_TYPE_IRCD, "Server Ready"); |
636 |
|
|
637 |
< |
eventAddIsh("cleanup_glines", cleanup_glines, NULL, CLEANUP_GLINES_TIME); |
638 |
< |
eventAddIsh("cleanup_tklines", cleanup_tklines, NULL, CLEANUP_TKLINES_TIME); |
637 |
> |
event_addish(&event_cleanup_glines, NULL); |
638 |
> |
event_addish(&event_cleanup_tklines, NULL); |
639 |
|
|
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 |
< |
eventAddIsh("try_connections", try_connections, NULL, STARTUP_CONNECTIONS_TIME); |
642 |
> |
event_addish(&event_try_connections, NULL); |
643 |
|
|
644 |
|
/* Setup the timeout check. I'll shift it later :) -- adrian */ |
645 |
< |
eventAddIsh("comm_checktimeouts", comm_checktimeouts, NULL, 1); |
645 |
> |
event_add(&event_comm_checktimeouts, NULL); |
646 |
> |
|
647 |
> |
event_addish(&event_save_all_databases, NULL); |
648 |
|
|
649 |
|
if (ConfigServerHide.links_delay > 0) |
650 |
< |
eventAddIsh("write_links_file", write_links_file, NULL, ConfigServerHide.links_delay); |
650 |
> |
{ |
651 |
> |
event_write_links_file.when = ConfigServerHide.links_delay; |
652 |
> |
event_addish(&event_write_links_file, NULL); |
653 |
> |
} |
654 |
|
else |
655 |
|
ConfigServerHide.links_disabled = 1; |
656 |
|
|
657 |
|
if (splitmode) |
658 |
< |
eventAddIsh("check_splitmode", check_splitmode, NULL, 60); |
658 |
> |
event_addish(&splitmode_event, NULL); |
659 |
|
|
660 |
|
io_loop(); |
661 |
|
return 0; |