1 |
|
/* |
2 |
|
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
3 |
|
* |
4 |
< |
* Copyright (c) 1997-2014 ircd-hybrid development team |
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 |
|
|
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" |
32 |
– |
#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" |
43 |
– |
#include "numeric.h" |
44 |
– |
#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 "log.h" |
49 |
< |
#include "s_misc.h" |
53 |
< |
#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 "mempool.h" |
59 |
– |
#include "hook.h" |
55 |
|
#include "ircd_getopt.h" |
61 |
– |
#include "supported.h" |
56 |
|
#include "watch.h" |
57 |
|
#include "conf_db.h" |
58 |
|
#include "conf_class.h" |
59 |
+ |
#include "ipcache.h" |
60 |
|
|
61 |
|
|
62 |
|
#ifdef HAVE_LIBGEOIP |
69 |
|
struct ServerState_t server_state; |
70 |
|
struct ServerStatistics ServerStats; |
71 |
|
struct timeval SystemTime; |
72 |
< |
struct Client me; /* That's me */ |
73 |
< |
struct LocalUser meLocalUser; /* That's also part of me */ |
72 |
> |
struct Connection meConnection; /* That's also part of me */ |
73 |
> |
struct Client me = { .connection = &meConnection }; /* That's me */ |
74 |
|
|
75 |
+ |
char **myargv; |
76 |
|
const char *logFileName = LPATH; |
77 |
|
const char *pidFileName = PPATH; |
78 |
|
|
79 |
< |
char **myargv; |
80 |
< |
|
81 |
< |
int dorehash = 0; |
86 |
< |
int doremotd = 0; |
87 |
< |
|
88 |
< |
/* Set to zero because it should be initialized later using |
89 |
< |
* initialize_server_capabs |
90 |
< |
*/ |
91 |
< |
int default_server_capabs = 0; |
79 |
> |
unsigned int dorehash; |
80 |
> |
unsigned int doremotd; |
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 |
< |
int rehashed_klines = 0; |
108 |
> |
static struct event event_comm_checktimeouts = |
109 |
> |
{ |
110 |
> |
.name = "comm_checktimeouts", |
111 |
> |
.handler = comm_checktimeouts, |
112 |
> |
.when = 1 |
113 |
> |
}; |
114 |
> |
|
115 |
> |
static struct event event_save_all_databases = |
116 |
> |
{ |
117 |
> |
.name = "save_all_databases", |
118 |
> |
.handler = save_all_databases, |
119 |
> |
.when = DATABASE_UPDATE_TIMEOUT |
120 |
> |
}; |
121 |
> |
|
122 |
> |
struct event event_write_links_file = |
123 |
> |
{ |
124 |
> |
.name = "write_links_file", |
125 |
> |
.handler = write_links_file, |
126 |
> |
}; |
127 |
|
|
128 |
|
|
129 |
|
/* |
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 |
< |
{"configfile", &ConfigFileEntry.configfile, |
162 |
> |
static struct lgetopt myopts[] = |
163 |
> |
{ |
164 |
> |
{"configfile", &ConfigGeneral.configfile, |
165 |
|
STRING, "File to use for ircd.conf"}, |
166 |
< |
{"glinefile", &ConfigFileEntry.glinefile, |
166 |
> |
{"glinefile", &ConfigGeneral.glinefile, |
167 |
|
STRING, "File to use for gline database"}, |
168 |
< |
{"klinefile", &ConfigFileEntry.klinefile, |
168 |
> |
{"klinefile", &ConfigGeneral.klinefile, |
169 |
|
STRING, "File to use for kline database"}, |
170 |
< |
{"dlinefile", &ConfigFileEntry.dlinefile, |
170 |
> |
{"dlinefile", &ConfigGeneral.dlinefile, |
171 |
|
STRING, "File to use for dline database"}, |
172 |
< |
{"xlinefile", &ConfigFileEntry.xlinefile, |
172 |
> |
{"xlinefile", &ConfigGeneral.xlinefile, |
173 |
|
STRING, "File to use for xline database"}, |
174 |
< |
{"resvfile", &ConfigFileEntry.resvfile, |
174 |
> |
{"resvfile", &ConfigGeneral.resvfile, |
175 |
|
STRING, "File to use for resv database"}, |
176 |
|
{"logfile", &logFileName, |
177 |
|
STRING, "File to use for ircd.log"}, |
188 |
|
void |
189 |
|
set_time(void) |
190 |
|
{ |
191 |
< |
static char to_send[IRCD_BUFSIZE]; |
172 |
< |
struct timeval newtime; |
173 |
< |
newtime.tv_sec = 0; |
174 |
< |
newtime.tv_usec = 0; |
191 |
> |
struct timeval newtime = { .tv_sec = 0, .tv_usec = 0 }; |
192 |
|
|
193 |
|
if (gettimeofday(&newtime, NULL) == -1) |
194 |
|
{ |
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 |
|
{ |
204 |
– |
/* |
205 |
– |
* Maybe we want a flags word? |
206 |
– |
* ie. if (REHASHED_KLINES(global_flags)) |
207 |
– |
* SET_REHASHED_KLINES(global_flags) |
208 |
– |
* CLEAR_REHASHED_KLINES(global_flags) |
209 |
– |
* |
210 |
– |
* - Dianora |
211 |
– |
*/ |
212 |
– |
if (rehashed_klines) |
213 |
– |
{ |
214 |
– |
check_conf_klines(); |
215 |
– |
rehashed_klines = 0; |
216 |
– |
} |
217 |
– |
|
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 |
< |
{ |
223 |
< |
struct Client *client_p = ptr->data; |
224 |
< |
assert(client_p->localClient->list_task); |
225 |
< |
safe_list_channels(client_p, client_p->localClient->list_task, 0); |
226 |
< |
} |
225 |
> |
dlink_node *node = NULL, *node_next = NULL; |
226 |
> |
DLINK_FOREACH_SAFE(node, node_next, listing_client_list.head) |
227 |
> |
safe_list_channels(node->data, 0); |
228 |
|
} |
229 |
|
|
230 |
< |
/* Run pending events, then get the number of seconds to the next |
231 |
< |
* event |
231 |
< |
*/ |
232 |
< |
while (eventNextTime() <= CurrentTime) |
233 |
< |
eventRun(); |
230 |
> |
/* Run pending events */ |
231 |
> |
event_run(); |
232 |
|
|
233 |
|
comm_select(); |
234 |
|
exit_aborted_clients(); |
237 |
|
/* Check to see whether we have to rehash the configuration .. */ |
238 |
|
if (dorehash) |
239 |
|
{ |
240 |
< |
rehash(1); |
240 |
> |
conf_rehash(1); |
241 |
|
dorehash = 0; |
242 |
|
} |
243 |
+ |
|
244 |
|
if (doremotd) |
245 |
|
{ |
246 |
|
motd_recache(); |
247 |
|
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
248 |
< |
"Got signal SIGUSR1, reloading motd files"); |
248 |
> |
"Got signal SIGUSR1, reloading motd file(s)"); |
249 |
|
doremotd = 0; |
250 |
|
} |
251 |
|
} |
260 |
|
static void |
261 |
|
initialize_global_set_options(void) |
262 |
|
{ |
263 |
< |
memset(&GlobalSetOptions, 0, sizeof(GlobalSetOptions)); |
264 |
< |
|
266 |
< |
GlobalSetOptions.autoconn = 1; |
263 |
> |
GlobalSetOptions.maxclients = ConfigServerInfo.default_max_clients; |
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; |
272 |
< |
else |
273 |
< |
GlobalSetOptions.floodcount = 10; |
274 |
< |
|
275 |
< |
/* XXX I have no idea what to try here - Dianora */ |
276 |
< |
GlobalSetOptions.joinfloodcount = 16; |
277 |
< |
GlobalSetOptions.joinfloodtime = 8; |
266 |
> |
GlobalSetOptions.spam_num = MAX_JOIN_LEAVE_COUNT; |
267 |
> |
GlobalSetOptions.floodcount = ConfigGeneral.default_floodcount; |
268 |
> |
GlobalSetOptions.joinfloodcount = ConfigChannel.default_join_flood_count; |
269 |
> |
GlobalSetOptions.joinfloodtime = ConfigChannel.default_join_flood_time; |
270 |
|
|
271 |
|
split_servers = ConfigChannel.default_split_server_count; |
272 |
|
split_users = ConfigChannel.default_split_user_count; |
279 |
|
} |
280 |
|
|
281 |
|
GlobalSetOptions.ident_timeout = IDENT_TIMEOUT; |
290 |
– |
/* End of global set options */ |
282 |
|
} |
283 |
|
|
284 |
|
/* initialize_server_capabs() |
293 |
|
add_capability("EOB", CAP_EOB, 1); |
294 |
|
add_capability("TS6", CAP_TS6, 0); |
295 |
|
add_capability("CLUSTER", CAP_CLUSTER, 1); |
305 |
– |
// add_capability("FAKEHOST", CAP_FAKEHOST, 1); |
296 |
|
add_capability("SVS", CAP_SVS, 1); |
297 |
< |
#ifdef HALFOPS |
297 |
> |
add_capability("CHW", CAP_CHW, 1); |
298 |
|
add_capability("HOPS", CAP_HOPS, 1); |
309 |
– |
#endif |
299 |
|
} |
300 |
|
|
301 |
|
/* write_pidfile() |
316 |
|
|
317 |
|
snprintf(buff, sizeof(buff), "%u\n", pid); |
318 |
|
|
319 |
< |
if ((fputs(buff, fb) == -1)) |
320 |
< |
ilog(LOG_TYPE_IRCD, "Error writing %u to pid file %s (%s)", |
319 |
> |
if (fputs(buff, fb) == -1) |
320 |
> |
ilog(LOG_TYPE_IRCD, "Error writing %u to pid file %s: %s", |
321 |
|
pid, filename, strerror(errno)); |
322 |
|
|
323 |
|
fclose(fb); |
324 |
|
} |
325 |
|
else |
326 |
< |
{ |
327 |
< |
ilog(LOG_TYPE_IRCD, "Error opening pid file %s", filename); |
339 |
< |
} |
326 |
> |
ilog(LOG_TYPE_IRCD, "Error opening pid file %s: %s", |
327 |
> |
filename, strerror(errno)); |
328 |
|
} |
329 |
|
|
330 |
|
/* check_pidfile() |
345 |
|
/* Don't do logging here, since we don't have log() initialised */ |
346 |
|
if ((fb = fopen(filename, "r"))) |
347 |
|
{ |
348 |
< |
if (fgets(buff, 20, fb) == NULL) |
348 |
> |
if (!fgets(buff, 20, fb)) |
349 |
|
{ |
350 |
|
/* log(L_ERROR, "Error reading from pid file %s (%s)", filename, |
351 |
|
* strerror(errno)); |
411 |
|
ssl_init(void) |
412 |
|
{ |
413 |
|
#ifdef HAVE_LIBCRYPTO |
426 |
– |
const unsigned char session_id[] = "ircd-hybrid"; |
427 |
– |
|
414 |
|
SSL_load_error_strings(); |
415 |
|
SSLeay_add_ssl_algorithms(); |
416 |
|
|
417 |
< |
if ((ServerInfo.server_ctx = SSL_CTX_new(SSLv23_server_method())) == NULL) |
417 |
> |
if (!(ConfigServerInfo.server_ctx = SSL_CTX_new(SSLv23_server_method()))) |
418 |
|
{ |
419 |
< |
const char *s; |
419 |
> |
const char *s = ERR_lib_error_string(ERR_get_error()); |
420 |
|
|
421 |
< |
fprintf(stderr, "ERROR: Could not initialize the SSL Server context -- %s\n", |
422 |
< |
s = ERR_lib_error_string(ERR_get_error())); |
423 |
< |
ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Server context -- %s\n", s); |
421 |
> |
fprintf(stderr, "ERROR: Could not initialize the SSL Server context -- %s\n", s); |
422 |
> |
ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Server context -- %s", s); |
423 |
> |
exit(EXIT_FAILURE); |
424 |
> |
return; /* Not reached */ |
425 |
|
} |
426 |
|
|
427 |
< |
SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TLSv1); |
428 |
< |
SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_TLS_ROLLBACK_BUG|SSL_OP_ALL); |
429 |
< |
SSL_CTX_set_verify(ServerInfo.server_ctx, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE, |
427 |
> |
SSL_CTX_set_options(ConfigServerInfo.server_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TICKET); |
428 |
> |
SSL_CTX_set_options(ConfigServerInfo.server_ctx, SSL_OP_SINGLE_DH_USE|SSL_OP_CIPHER_SERVER_PREFERENCE); |
429 |
> |
SSL_CTX_set_verify(ConfigServerInfo.server_ctx, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE, |
430 |
|
always_accept_verify_cb); |
431 |
< |
SSL_CTX_set_session_id_context(ServerInfo.server_ctx, session_id, sizeof(session_id) - 1); |
431 |
> |
SSL_CTX_set_session_cache_mode(ConfigServerInfo.server_ctx, SSL_SESS_CACHE_OFF); |
432 |
> |
SSL_CTX_set_cipher_list(ConfigServerInfo.server_ctx, "EECDH+HIGH:EDH+HIGH:HIGH:!aNULL"); |
433 |
> |
|
434 |
> |
#if OPENSSL_VERSION_NUMBER >= 0x009080FFL && !defined(OPENSSL_NO_ECDH) |
435 |
> |
{ |
436 |
> |
EC_KEY *key = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1); |
437 |
> |
|
438 |
> |
if (key) |
439 |
> |
{ |
440 |
> |
SSL_CTX_set_tmp_ecdh(ConfigServerInfo.server_ctx, key); |
441 |
> |
EC_KEY_free(key); |
442 |
> |
} |
443 |
> |
} |
444 |
> |
|
445 |
> |
SSL_CTX_set_options(ConfigServerInfo.server_ctx, SSL_OP_SINGLE_ECDH_USE); |
446 |
> |
#endif |
447 |
|
|
448 |
< |
if ((ServerInfo.client_ctx = SSL_CTX_new(SSLv23_client_method())) == NULL) |
448 |
> |
if (!(ConfigServerInfo.client_ctx = SSL_CTX_new(SSLv23_client_method()))) |
449 |
|
{ |
450 |
< |
const char *s; |
450 |
> |
const char *s = ERR_lib_error_string(ERR_get_error()); |
451 |
|
|
452 |
< |
fprintf(stderr, "ERROR: Could not initialize the SSL Client context -- %s\n", |
453 |
< |
s = ERR_lib_error_string(ERR_get_error())); |
454 |
< |
ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Client context -- %s\n", s); |
452 |
> |
fprintf(stderr, "ERROR: Could not initialize the SSL Client context -- %s\n", s); |
453 |
> |
ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Client context -- %s", s); |
454 |
> |
exit(EXIT_FAILURE); |
455 |
> |
return; /* Not reached */ |
456 |
|
} |
457 |
|
|
458 |
< |
SSL_CTX_set_options(ServerInfo.client_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TLSv1); |
459 |
< |
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_PEER|SSL_VERIFY_CLIENT_ONCE, |
458 |
> |
SSL_CTX_set_options(ConfigServerInfo.client_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TICKET); |
459 |
> |
SSL_CTX_set_options(ConfigServerInfo.client_ctx, SSL_OP_SINGLE_DH_USE); |
460 |
> |
SSL_CTX_set_verify(ConfigServerInfo.client_ctx, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE, |
461 |
|
always_accept_verify_cb); |
462 |
+ |
SSL_CTX_set_session_cache_mode(ConfigServerInfo.client_ctx, SSL_SESS_CACHE_OFF); |
463 |
|
#endif /* HAVE_LIBCRYPTO */ |
464 |
|
} |
465 |
|
|
467 |
|
main(int argc, char *argv[]) |
468 |
|
{ |
469 |
|
/* Check to see if the user is running us as root, which is a nono */ |
470 |
< |
if (geteuid() == 0) |
470 |
> |
if (!geteuid()) |
471 |
|
{ |
472 |
< |
fprintf(stderr, "Don't run ircd as root!!!\n"); |
472 |
> |
fprintf(stderr, "ERROR: This server won't run as root/superuser\n"); |
473 |
|
return -1; |
474 |
|
} |
475 |
|
|
476 |
|
/* Setup corefile size immediately after boot -kre */ |
477 |
|
setup_corefile(); |
478 |
|
|
479 |
< |
/* save server boot time right away, so getrusage works correctly */ |
479 |
> |
/* Save server boot time right away, so getrusage works correctly */ |
480 |
|
set_time(); |
481 |
|
|
482 |
< |
/* It ain't random, but it ought to be a little harder to guess */ |
482 |
> |
/* It's not random, but it ought to be a little harder to guess */ |
483 |
|
init_genrand(SystemTime.tv_sec ^ (SystemTime.tv_usec | (getpid() << 20))); |
484 |
|
|
485 |
< |
me.localClient = &meLocalUser; |
486 |
< |
dlinkAdd(&me, &me.node, &global_client_list); /* Pointer to beginning |
487 |
< |
of Client list */ |
488 |
< |
/* Initialise the channel capability usage counts... */ |
489 |
< |
init_chcap_usage_counts(); |
490 |
< |
|
491 |
< |
ConfigFileEntry.dpath = DPATH; |
492 |
< |
ConfigFileEntry.configfile = CPATH; /* Server configuration file */ |
493 |
< |
ConfigFileEntry.klinefile = KPATH; /* Server kline file */ |
494 |
< |
ConfigFileEntry.glinefile = GPATH; /* Server gline file */ |
495 |
< |
ConfigFileEntry.xlinefile = XPATH; /* Server xline file */ |
492 |
< |
ConfigFileEntry.dlinefile = DLPATH; /* dline file */ |
493 |
< |
ConfigFileEntry.resvfile = RESVPATH; /* resv file */ |
485 |
> |
dlinkAdd(&me, &me.node, &global_client_list); |
486 |
> |
|
487 |
> |
ConfigGeneral.dpath = DPATH; |
488 |
> |
ConfigGeneral.spath = SPATH; |
489 |
> |
ConfigGeneral.mpath = MPATH; |
490 |
> |
ConfigGeneral.configfile = CPATH; /* Server configuration file */ |
491 |
> |
ConfigGeneral.klinefile = KPATH; /* Server kline file */ |
492 |
> |
ConfigGeneral.glinefile = GPATH; /* Server gline file */ |
493 |
> |
ConfigGeneral.xlinefile = XPATH; /* Server xline file */ |
494 |
> |
ConfigGeneral.dlinefile = DLPATH; /* dline file */ |
495 |
> |
ConfigGeneral.resvfile = RESVPATH; /* resv file */ |
496 |
|
|
497 |
|
myargv = argv; |
498 |
< |
umask(077); /* better safe than sorry --SRB */ |
498 |
> |
umask(077); /* umask 077: u=rwx,g=,o= */ |
499 |
|
|
500 |
|
parseargs(&argc, &argv, myopts); |
501 |
|
|
505 |
|
exit(EXIT_SUCCESS); |
506 |
|
} |
507 |
|
|
508 |
< |
if (chdir(ConfigFileEntry.dpath)) |
508 |
> |
if (chdir(ConfigGeneral.dpath)) |
509 |
|
{ |
510 |
|
perror("chdir"); |
511 |
|
exit(EXIT_FAILURE); |
523 |
|
|
524 |
|
setup_signals(); |
525 |
|
|
524 |
– |
/* Init the event subsystem */ |
525 |
– |
eventInit(); |
526 |
– |
|
526 |
|
/* We need this to initialise the fd array before anything else */ |
527 |
|
fdlist_init(); |
528 |
|
log_set_file(LOG_TYPE_IRCD, 0, logFileName); |
529 |
< |
check_can_use_v6(); |
529 |
> |
|
530 |
|
init_netio(); /* This needs to be setup early ! -- adrian */ |
531 |
|
|
532 |
|
/* Check if there is pidfile and daemon already running */ |
537 |
|
init_isupport(); |
538 |
|
dbuf_init(); |
539 |
|
hash_init(); |
540 |
< |
init_ip_hash_table(); /* client host ip hash table */ |
542 |
< |
init_host_hash(); /* Host-hashtable. */ |
540 |
> |
ipcache_init(); |
541 |
|
client_init(); |
542 |
|
class_init(); |
543 |
|
whowas_init(); |
548 |
|
read_conf_files(1); /* cold start init conf files */ |
549 |
|
init_uid(); |
550 |
|
initialize_server_capabs(); /* Set up default_server_capabs */ |
551 |
< |
initialize_global_set_options(); |
551 |
> |
initialize_global_set_options(); /* Has to be called after read_conf_files() */ |
552 |
|
channel_init(); |
553 |
|
read_links_file(); |
554 |
|
motd_init(); |
555 |
+ |
user_usermodes_init(); |
556 |
|
#ifdef HAVE_LIBGEOIP |
557 |
|
geoip_ctx = GeoIP_new(GEOIP_MEMORY_CACHE); |
558 |
|
#endif |
559 |
|
|
560 |
< |
if (EmptyString(ServerInfo.sid)) |
560 |
> |
if (EmptyString(ConfigServerInfo.sid)) |
561 |
|
{ |
562 |
|
ilog(LOG_TYPE_IRCD, "ERROR: No server id specified in serverinfo block."); |
563 |
|
exit(EXIT_FAILURE); |
564 |
|
} |
565 |
|
|
566 |
< |
strlcpy(me.id, ServerInfo.sid, sizeof(me.id)); |
566 |
> |
strlcpy(me.id, ConfigServerInfo.sid, sizeof(me.id)); |
567 |
|
|
568 |
< |
if (EmptyString(ServerInfo.name)) |
568 |
> |
if (EmptyString(ConfigServerInfo.name)) |
569 |
|
{ |
570 |
|
ilog(LOG_TYPE_IRCD, "ERROR: No server name specified in serverinfo block."); |
571 |
|
exit(EXIT_FAILURE); |
572 |
|
} |
573 |
|
|
574 |
< |
strlcpy(me.name, ServerInfo.name, sizeof(me.name)); |
574 |
> |
strlcpy(me.name, ConfigServerInfo.name, sizeof(me.name)); |
575 |
|
|
576 |
|
/* serverinfo{} description must exist. If not, error out.*/ |
577 |
< |
if (EmptyString(ServerInfo.description)) |
577 |
> |
if (EmptyString(ConfigServerInfo.description)) |
578 |
|
{ |
579 |
|
ilog(LOG_TYPE_IRCD, "ERROR: No server description specified in serverinfo block."); |
580 |
|
exit(EXIT_FAILURE); |
581 |
|
} |
582 |
|
|
583 |
< |
strlcpy(me.info, ServerInfo.description, sizeof(me.info)); |
583 |
> |
strlcpy(me.info, ConfigServerInfo.description, sizeof(me.info)); |
584 |
|
|
585 |
< |
me.from = &me; |
586 |
< |
me.servptr = &me; |
587 |
< |
me.localClient->lasttime = CurrentTime; |
588 |
< |
me.localClient->since = CurrentTime; |
589 |
< |
me.localClient->firsttime = CurrentTime; |
585 |
> |
me.from = &me; |
586 |
> |
me.servptr = &me; |
587 |
> |
me.connection->lasttime = CurrentTime; |
588 |
> |
me.connection->since = CurrentTime; |
589 |
> |
me.connection->firsttime = CurrentTime; |
590 |
|
|
591 |
|
SetMe(&me); |
592 |
|
make_server(&me); |
594 |
|
hash_add_id(&me); |
595 |
|
hash_add_client(&me); |
596 |
|
|
597 |
< |
/* add ourselves to global_serv_list */ |
599 |
< |
dlinkAdd(&me, make_dlink_node(), &global_serv_list); |
597 |
> |
dlinkAdd(&me, make_dlink_node(), &global_server_list); |
598 |
|
|
599 |
|
load_kline_database(); |
600 |
|
load_dline_database(); |
602 |
|
load_xline_database(); |
603 |
|
load_resv_database(); |
604 |
|
|
607 |
– |
if (chdir(MODPATH)) |
608 |
– |
{ |
609 |
– |
ilog(LOG_TYPE_IRCD, "Could not load core modules. Terminating!"); |
610 |
– |
exit(EXIT_FAILURE); |
611 |
– |
} |
612 |
– |
|
605 |
|
load_all_modules(1); |
606 |
|
load_conf_modules(); |
607 |
|
load_core_modules(1); |
608 |
|
|
617 |
– |
/* Go back to DPATH after checking to see if we can chdir to MODPATH */ |
618 |
– |
if (chdir(ConfigFileEntry.dpath)) |
619 |
– |
{ |
620 |
– |
perror("chdir"); |
621 |
– |
exit(EXIT_FAILURE); |
622 |
– |
} |
623 |
– |
|
624 |
– |
/* |
625 |
– |
* assemble_umode_buffer() has to be called after |
626 |
– |
* reading conf/loading modules. |
627 |
– |
*/ |
628 |
– |
assemble_umode_buffer(); |
629 |
– |
|
609 |
|
write_pidfile(pidFileName); |
610 |
|
|
611 |
|
ilog(LOG_TYPE_IRCD, "Server Ready"); |
612 |
|
|
613 |
< |
eventAddIsh("cleanup_glines", cleanup_glines, NULL, CLEANUP_GLINES_TIME); |
614 |
< |
eventAddIsh("cleanup_tklines", cleanup_tklines, NULL, CLEANUP_TKLINES_TIME); |
613 |
> |
event_addish(&event_cleanup_glines, NULL); |
614 |
> |
event_addish(&event_cleanup_tklines, NULL); |
615 |
|
|
616 |
|
/* We want try_connections to be called as soon as possible now! -- adrian */ |
617 |
|
/* No, 'cause after a restart it would cause all sorts of nick collides */ |
618 |
< |
eventAddIsh("try_connections", try_connections, NULL, STARTUP_CONNECTIONS_TIME); |
618 |
> |
event_addish(&event_try_connections, NULL); |
619 |
|
|
620 |
|
/* Setup the timeout check. I'll shift it later :) -- adrian */ |
621 |
< |
eventAddIsh("comm_checktimeouts", comm_checktimeouts, NULL, 1); |
621 |
> |
event_add(&event_comm_checktimeouts, NULL); |
622 |
|
|
623 |
< |
eventAddIsh("save_all_databases", save_all_databases, NULL, DATABASE_UPDATE_TIMEOUT); |
623 |
> |
event_addish(&event_save_all_databases, NULL); |
624 |
|
|
625 |
|
if (ConfigServerHide.links_delay > 0) |
626 |
< |
eventAddIsh("write_links_file", write_links_file, NULL, ConfigServerHide.links_delay); |
626 |
> |
{ |
627 |
> |
event_write_links_file.when = ConfigServerHide.links_delay; |
628 |
> |
event_addish(&event_write_links_file, NULL); |
629 |
> |
} |
630 |
|
else |
631 |
|
ConfigServerHide.links_disabled = 1; |
632 |
|
|
633 |
|
if (splitmode) |
634 |
< |
eventAddIsh("check_splitmode", check_splitmode, NULL, 60); |
634 |
> |
event_addish(&splitmode_event, NULL); |
635 |
|
|
636 |
|
io_loop(); |
637 |
|
return 0; |