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-2016 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 |
33 |
|
#include "event.h" |
34 |
|
#include "fdlist.h" |
35 |
|
#include "hash.h" |
36 |
+ |
#include "id.h" |
37 |
|
#include "irc_string.h" |
38 |
|
#include "ircd_signal.h" |
38 |
– |
#include "gline.h" |
39 |
|
#include "motd.h" |
40 |
|
#include "conf.h" |
41 |
|
#include "hostmask.h" |
46 |
|
#include "auth.h" |
47 |
|
#include "s_bsd.h" |
48 |
|
#include "log.h" |
49 |
< |
#include "server.h" /* try_connections */ |
49 |
> |
#include "server.h" |
50 |
|
#include "send.h" |
51 |
|
#include "whowas.h" |
52 |
|
#include "modules.h" |
57 |
|
#include "conf_db.h" |
58 |
|
#include "conf_class.h" |
59 |
|
#include "ipcache.h" |
60 |
+ |
#include "isupport.h" |
61 |
+ |
#include "userhost.h" |
62 |
|
|
63 |
|
|
64 |
|
#ifdef HAVE_LIBGEOIP |
65 |
< |
GeoIP *geoip_ctx; |
65 |
> |
GeoIP *GeoIPv4_ctx; |
66 |
> |
GeoIP *GeoIPv6_ctx; |
67 |
|
#endif |
68 |
|
|
69 |
< |
struct timeval SystemTime; |
70 |
< |
struct Client me; /* That's me */ |
71 |
< |
struct Connection meConnection; /* That's also part of me */ |
69 |
> |
struct SetOptions GlobalSetOptions; /* /quote set variables */ |
70 |
> |
struct Counter Count; |
71 |
> |
struct ServerState_t server_state; |
72 |
> |
struct ServerStatistics ServerStats; |
73 |
> |
struct ServerTime SystemTime; |
74 |
> |
struct Connection meConnection; /* That's also part of me */ |
75 |
> |
struct Client me = { .connection = &meConnection }; /* That's me */ |
76 |
|
|
77 |
+ |
char **myargv; |
78 |
|
const char *logFileName = LPATH; |
79 |
|
const char *pidFileName = PPATH; |
80 |
|
|
81 |
< |
char **myargv; |
81 |
> |
unsigned int dorehash; |
82 |
> |
unsigned int doremotd; |
83 |
|
|
84 |
< |
int dorehash = 0; |
76 |
< |
int doremotd = 0; |
84 |
> |
static int printVersion; |
85 |
|
|
86 |
< |
/* Set to zero because it should be initialized later using |
87 |
< |
* initialize_server_capabs |
88 |
< |
*/ |
89 |
< |
unsigned int default_server_capabs; |
90 |
< |
unsigned int splitmode; |
91 |
< |
unsigned int splitchecking; |
92 |
< |
unsigned int split_users; |
93 |
< |
unsigned int split_servers; |
94 |
< |
|
95 |
< |
static struct event event_cleanup_glines = |
96 |
< |
{ |
97 |
< |
.name = "cleanup_glines", |
98 |
< |
.handler = cleanup_glines, |
99 |
< |
.when = CLEANUP_GLINES_TIME |
86 |
> |
static struct lgetopt myopts[] = |
87 |
> |
{ |
88 |
> |
{ "configfile", &ConfigGeneral.configfile, |
89 |
> |
STRING, "File to use for ircd.conf" }, |
90 |
> |
{ "klinefile", &ConfigGeneral.klinefile, |
91 |
> |
STRING, "File to use for kline database" }, |
92 |
> |
{ "dlinefile", &ConfigGeneral.dlinefile, |
93 |
> |
STRING, "File to use for dline database" }, |
94 |
> |
{ "xlinefile", &ConfigGeneral.xlinefile, |
95 |
> |
STRING, "File to use for xline database" }, |
96 |
> |
{ "resvfile", &ConfigGeneral.resvfile, |
97 |
> |
STRING, "File to use for resv database" }, |
98 |
> |
{ "logfile", &logFileName, |
99 |
> |
STRING, "File to use for ircd.log" }, |
100 |
> |
{ "pidfile", &pidFileName, |
101 |
> |
STRING, "File to use for process ID" }, |
102 |
> |
{ "foreground", &server_state.foreground, |
103 |
> |
YESNO, "Run in foreground (don't detach)" }, |
104 |
> |
{ "version", &printVersion, |
105 |
> |
YESNO, "Print version and exit" }, |
106 |
> |
{ "help", NULL, USAGE, "Print this text" }, |
107 |
> |
{ NULL, NULL, STRING, NULL }, |
108 |
|
}; |
109 |
|
|
110 |
|
static struct event event_cleanup_tklines = |
142 |
|
}; |
143 |
|
|
144 |
|
|
129 |
– |
/* |
130 |
– |
* print_startup - print startup information |
131 |
– |
*/ |
132 |
– |
static void |
133 |
– |
print_startup(int pid) |
134 |
– |
{ |
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", ConfigGeneral.dpath); |
139 |
– |
} |
140 |
– |
|
141 |
– |
static void |
142 |
– |
make_daemon(void) |
143 |
– |
{ |
144 |
– |
int pid; |
145 |
– |
|
146 |
– |
if ((pid = fork()) < 0) |
147 |
– |
{ |
148 |
– |
perror("fork"); |
149 |
– |
exit(EXIT_FAILURE); |
150 |
– |
} |
151 |
– |
else if (pid > 0) |
152 |
– |
{ |
153 |
– |
print_startup(pid); |
154 |
– |
exit(EXIT_SUCCESS); |
155 |
– |
} |
156 |
– |
|
157 |
– |
setsid(); |
158 |
– |
} |
159 |
– |
|
160 |
– |
static int printVersion = 0; |
161 |
– |
|
162 |
– |
static struct lgetopt myopts[] = |
163 |
– |
{ |
164 |
– |
{"configfile", &ConfigGeneral.configfile, |
165 |
– |
STRING, "File to use for ircd.conf"}, |
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, |
181 |
– |
YESNO, "Run in foreground (don't detach)"}, |
182 |
– |
{"version", &printVersion, |
183 |
– |
YESNO, "Print version and exit"}, |
184 |
– |
{"help", NULL, USAGE, "Print this text"}, |
185 |
– |
{NULL, NULL, STRING, NULL}, |
186 |
– |
}; |
187 |
– |
|
145 |
|
void |
146 |
|
set_time(void) |
147 |
|
{ |
149 |
|
|
150 |
|
if (gettimeofday(&newtime, NULL) == -1) |
151 |
|
{ |
152 |
< |
ilog(LOG_TYPE_IRCD, "Clock Failure (%s), TS can be corrupted", |
153 |
< |
strerror(errno)); |
154 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
155 |
< |
"Clock Failure (%s), TS can be corrupted", |
156 |
< |
strerror(errno)); |
200 |
< |
server_die("Clock Failure", 1); |
152 |
> |
char buf[IRCD_BUFSIZE]; |
153 |
> |
|
154 |
> |
snprintf(buf, sizeof(buf), "Clock failure, TS can be corrupted: %s", |
155 |
> |
strerror(errno)); |
156 |
> |
server_die(buf, SERVER_SHUTDOWN); |
157 |
|
} |
158 |
|
|
159 |
< |
if (newtime.tv_sec < CurrentTime) |
159 |
> |
if ((uintmax_t)newtime.tv_sec < CurrentTime) |
160 |
|
{ |
161 |
< |
ilog(LOG_TYPE_IRCD, "System clock is running backwards - (%lu < %lu)", |
162 |
< |
(unsigned long)newtime.tv_sec, (unsigned long)CurrentTime); |
161 |
> |
ilog(LOG_TYPE_IRCD, "System clock is running backwards - (%ju < %ju)", |
162 |
> |
(uintmax_t)newtime.tv_sec, CurrentTime); |
163 |
|
sendto_realops_flags(UMODE_DEBUG, L_ALL, SEND_NOTICE, |
164 |
< |
"System clock is running backwards - (%lu < %lu)", |
165 |
< |
(unsigned long)newtime.tv_sec, |
166 |
< |
(unsigned long)CurrentTime); |
211 |
< |
set_back_events(CurrentTime - newtime.tv_sec); |
164 |
> |
"System clock is running backwards - (%ju < %ju)", |
165 |
> |
(uintmax_t)newtime.tv_sec, CurrentTime); |
166 |
> |
event_set_back_events(CurrentTime - (uintmax_t)newtime.tv_sec); |
167 |
|
} |
168 |
|
|
169 |
< |
SystemTime.tv_sec = newtime.tv_sec; |
169 |
> |
SystemTime.tv_sec = newtime.tv_sec; |
170 |
|
SystemTime.tv_usec = newtime.tv_usec; |
171 |
|
} |
172 |
|
|
177 |
|
{ |
178 |
|
if (listing_client_list.head) |
179 |
|
{ |
180 |
< |
dlink_node *ptr = NULL, *ptr_next = NULL; |
181 |
< |
DLINK_FOREACH_SAFE(ptr, ptr_next, listing_client_list.head) |
182 |
< |
safe_list_channels(ptr->data, 0); |
180 |
> |
dlink_node *node = NULL, *node_next = NULL; |
181 |
> |
DLINK_FOREACH_SAFE(node, node_next, listing_client_list.head) |
182 |
> |
safe_list_channels(node->data, 0); |
183 |
|
} |
184 |
|
|
185 |
|
/* Run pending events */ |
189 |
|
exit_aborted_clients(); |
190 |
|
free_exited_clients(); |
191 |
|
|
192 |
< |
/* Check to see whether we have to rehash the configuration .. */ |
192 |
> |
/* Check to see whether we have to rehash the configuration. */ |
193 |
|
if (dorehash) |
194 |
|
{ |
195 |
< |
rehash(1); |
195 |
> |
conf_rehash(1); |
196 |
|
dorehash = 0; |
197 |
|
} |
198 |
|
|
199 |
|
if (doremotd) |
200 |
|
{ |
201 |
|
motd_recache(); |
202 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
202 |
> |
sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE, |
203 |
|
"Got signal SIGUSR1, reloading motd file(s)"); |
204 |
|
doremotd = 0; |
205 |
|
} |
215 |
|
static void |
216 |
|
initialize_global_set_options(void) |
217 |
|
{ |
218 |
< |
GlobalSetOptions.autoconn = 1; |
218 |
> |
GlobalSetOptions.maxclients = ConfigServerInfo.default_max_clients; |
219 |
> |
GlobalSetOptions.autoconn = 1; |
220 |
|
GlobalSetOptions.spam_time = MIN_JOIN_LEAVE_TIME; |
221 |
< |
GlobalSetOptions.spam_num = MAX_JOIN_LEAVE_COUNT; |
222 |
< |
|
223 |
< |
if (ConfigGeneral.default_floodcount) |
224 |
< |
GlobalSetOptions.floodcount = ConfigGeneral.default_floodcount; |
269 |
< |
else |
270 |
< |
GlobalSetOptions.floodcount = 10; |
271 |
< |
|
272 |
< |
/* XXX I have no idea what to try here - Dianora */ |
273 |
< |
GlobalSetOptions.joinfloodcount = 16; |
274 |
< |
GlobalSetOptions.joinfloodtime = 8; |
275 |
< |
|
276 |
< |
split_servers = ConfigChannel.default_split_server_count; |
277 |
< |
split_users = ConfigChannel.default_split_user_count; |
278 |
< |
|
279 |
< |
if (split_users && split_servers && (ConfigChannel.no_create_on_split || |
280 |
< |
ConfigChannel.no_join_on_split)) |
281 |
< |
{ |
282 |
< |
splitmode = 1; |
283 |
< |
splitchecking = 1; |
284 |
< |
} |
285 |
< |
|
221 |
> |
GlobalSetOptions.spam_num = MAX_JOIN_LEAVE_COUNT; |
222 |
> |
GlobalSetOptions.floodcount = ConfigGeneral.default_floodcount; |
223 |
> |
GlobalSetOptions.joinfloodcount = ConfigChannel.default_join_flood_count; |
224 |
> |
GlobalSetOptions.joinfloodtime = ConfigChannel.default_join_flood_time; |
225 |
|
GlobalSetOptions.ident_timeout = IDENT_TIMEOUT; |
226 |
|
} |
227 |
|
|
289 |
– |
/* initialize_server_capabs() |
290 |
– |
* |
291 |
– |
* inputs - none |
292 |
– |
* output - none |
293 |
– |
*/ |
294 |
– |
static void |
295 |
– |
initialize_server_capabs(void) |
296 |
– |
{ |
297 |
– |
add_capability("QS", CAP_QS, 1); |
298 |
– |
add_capability("EOB", CAP_EOB, 1); |
299 |
– |
add_capability("TS6", CAP_TS6, 0); |
300 |
– |
add_capability("CLUSTER", CAP_CLUSTER, 1); |
301 |
– |
add_capability("SVS", CAP_SVS, 1); |
302 |
– |
add_capability("CHW", CAP_CHW, 1); |
303 |
– |
add_capability("HOPS", CAP_HOPS, 1); |
304 |
– |
} |
305 |
– |
|
228 |
|
/* write_pidfile() |
229 |
|
* |
230 |
|
* inputs - filename+path of pid file |
238 |
|
|
239 |
|
if ((fb = fopen(filename, "w"))) |
240 |
|
{ |
241 |
< |
char buff[IRCD_BUFSIZE]; |
241 |
> |
char buf[IRCD_BUFSIZE]; |
242 |
|
unsigned int pid = (unsigned int)getpid(); |
243 |
|
|
244 |
< |
snprintf(buff, sizeof(buff), "%u\n", pid); |
244 |
> |
snprintf(buf, sizeof(buf), "%u\n", pid); |
245 |
|
|
246 |
< |
if ((fputs(buff, fb) == -1)) |
247 |
< |
ilog(LOG_TYPE_IRCD, "Error writing %u to pid file %s (%s)", |
248 |
< |
pid, filename, strerror(errno)); |
246 |
> |
if (fputs(buf, fb) == -1) |
247 |
> |
ilog(LOG_TYPE_IRCD, "Error writing to pid file %s: %s", |
248 |
> |
filename, strerror(errno)); |
249 |
|
|
250 |
|
fclose(fb); |
251 |
|
} |
252 |
|
else |
253 |
< |
{ |
254 |
< |
ilog(LOG_TYPE_IRCD, "Error opening pid file %s", filename); |
333 |
< |
} |
253 |
> |
ilog(LOG_TYPE_IRCD, "Error opening pid file %s: %s", |
254 |
> |
filename, strerror(errno)); |
255 |
|
} |
256 |
|
|
257 |
|
/* check_pidfile() |
266 |
|
check_pidfile(const char *filename) |
267 |
|
{ |
268 |
|
FILE *fb; |
269 |
< |
char buff[IRCD_BUFSIZE]; |
349 |
< |
pid_t pidfromfile; |
269 |
> |
char buf[IRCD_BUFSIZE]; |
270 |
|
|
351 |
– |
/* Don't do logging here, since we don't have log() initialised */ |
271 |
|
if ((fb = fopen(filename, "r"))) |
272 |
|
{ |
273 |
< |
if (!fgets(buff, 20, fb)) |
274 |
< |
{ |
275 |
< |
/* log(L_ERROR, "Error reading from pid file %s (%s)", filename, |
357 |
< |
* strerror(errno)); |
358 |
< |
*/ |
359 |
< |
} |
273 |
> |
if (!fgets(buf, 20, fb)) |
274 |
> |
ilog(LOG_TYPE_IRCD, "Error reading from pid file %s: %s", |
275 |
> |
filename, strerror(errno)); |
276 |
|
else |
277 |
|
{ |
278 |
< |
pidfromfile = atoi(buff); |
278 |
> |
pid_t pid = atoi(buf); |
279 |
|
|
280 |
< |
if (!kill(pidfromfile, 0)) |
280 |
> |
if (!kill(pid, 0)) |
281 |
|
{ |
282 |
|
/* log(L_ERROR, "Server is already running"); */ |
283 |
|
printf("ircd: daemon is already running\n"); |
284 |
< |
exit(-1); |
284 |
> |
exit(EXIT_FAILURE); |
285 |
|
} |
286 |
|
} |
287 |
|
|
288 |
|
fclose(fb); |
289 |
|
} |
290 |
|
else if (errno != ENOENT) |
291 |
< |
{ |
292 |
< |
/* log(L_ERROR, "Error opening pid file %s", filename); */ |
377 |
< |
} |
291 |
> |
ilog(LOG_TYPE_IRCD, "Error opening pid file %s: %s", |
292 |
> |
filename, strerror(errno)); |
293 |
|
} |
294 |
|
|
295 |
|
/* setup_corefile() |
314 |
|
#endif |
315 |
|
} |
316 |
|
|
317 |
< |
#ifdef HAVE_LIBCRYPTO |
318 |
< |
static int |
319 |
< |
always_accept_verify_cb(int preverify_ok, X509_STORE_CTX *x509_ctx) |
317 |
> |
/* |
318 |
> |
* print_startup - print startup information |
319 |
> |
*/ |
320 |
> |
static void |
321 |
> |
print_startup(int pid) |
322 |
|
{ |
323 |
< |
return 1; |
323 |
> |
printf("ircd: version %s(%s)\n", ircd_version, serno); |
324 |
> |
printf("ircd: pid %d\n", pid); |
325 |
> |
printf("ircd: running in %s mode from %s\n", !server_state.foreground ? "background" |
326 |
> |
: "foreground", ConfigGeneral.dpath); |
327 |
|
} |
408 |
– |
#endif |
328 |
|
|
410 |
– |
/* init_ssl() |
411 |
– |
* |
412 |
– |
* inputs - nothing |
413 |
– |
* output - nothing |
414 |
– |
* side effects - setups SSL context. |
415 |
– |
*/ |
329 |
|
static void |
330 |
< |
ssl_init(void) |
330 |
> |
make_daemon(void) |
331 |
|
{ |
332 |
< |
#ifdef HAVE_LIBCRYPTO |
420 |
< |
SSL_load_error_strings(); |
421 |
< |
SSLeay_add_ssl_algorithms(); |
332 |
> |
int pid; |
333 |
|
|
334 |
< |
if (!(ConfigServerInfo.server_ctx = SSL_CTX_new(SSLv23_server_method()))) |
334 |
> |
if ((pid = fork()) < 0) |
335 |
|
{ |
336 |
< |
const char *s = ERR_lib_error_string(ERR_get_error()); |
426 |
< |
|
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); |
336 |
> |
perror("fork"); |
337 |
|
exit(EXIT_FAILURE); |
338 |
|
} |
339 |
< |
|
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(ConfigServerInfo.server_ctx, SSL_OP_SINGLE_ECDH_USE); |
450 |
< |
#endif |
451 |
< |
|
452 |
< |
if (!(ConfigServerInfo.client_ctx = SSL_CTX_new(SSLv23_client_method()))) |
339 |
> |
else if (pid > 0) |
340 |
|
{ |
341 |
< |
const char *s = ERR_lib_error_string(ERR_get_error()); |
342 |
< |
|
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); |
341 |
> |
print_startup(pid); |
342 |
> |
exit(EXIT_SUCCESS); |
343 |
|
} |
344 |
|
|
345 |
< |
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 */ |
345 |
> |
setsid(); |
346 |
|
} |
347 |
|
|
348 |
|
int |
358 |
|
/* Setup corefile size immediately after boot -kre */ |
359 |
|
setup_corefile(); |
360 |
|
|
361 |
< |
/* save server boot time right away, so getrusage works correctly */ |
361 |
> |
/* Save server boot time right away, so getrusage works correctly */ |
362 |
|
set_time(); |
363 |
|
|
364 |
< |
/* It ain't random, but it ought to be a little harder to guess */ |
364 |
> |
/* It's not random, but it ought to be a little harder to guess */ |
365 |
|
init_genrand(SystemTime.tv_sec ^ (SystemTime.tv_usec | (getpid() << 20))); |
366 |
|
|
488 |
– |
me.connection = &meConnection; |
489 |
– |
dlinkAdd(&me, &me.node, &global_client_list); /* Pointer to beginning |
490 |
– |
of Client list */ |
491 |
– |
ConfigLog.use_logging = 1; |
367 |
|
ConfigGeneral.dpath = DPATH; |
368 |
|
ConfigGeneral.spath = SPATH; |
369 |
|
ConfigGeneral.mpath = MPATH; |
370 |
|
ConfigGeneral.configfile = CPATH; /* Server configuration file */ |
371 |
|
ConfigGeneral.klinefile = KPATH; /* Server kline file */ |
497 |
– |
ConfigGeneral.glinefile = GPATH; /* Server gline file */ |
372 |
|
ConfigGeneral.xlinefile = XPATH; /* Server xline file */ |
373 |
|
ConfigGeneral.dlinefile = DLPATH; /* dline file */ |
374 |
|
ConfigGeneral.resvfile = RESVPATH; /* resv file */ |
375 |
|
|
376 |
|
myargv = argv; |
377 |
< |
umask(077); /* better safe than sorry --SRB */ |
377 |
> |
umask(077); /* umask 077: u=rwx,g=,o= */ |
378 |
|
|
379 |
|
parseargs(&argc, &argv, myopts); |
380 |
|
|
390 |
|
exit(EXIT_FAILURE); |
391 |
|
} |
392 |
|
|
519 |
– |
ssl_init(); |
520 |
– |
|
393 |
|
if (!server_state.foreground) |
394 |
|
{ |
395 |
|
make_daemon(); |
396 |
< |
close_standard_fds(); /* this needs to be before init_netio()! */ |
396 |
> |
close_standard_fds(); /* this needs to be before netio_init()! */ |
397 |
|
} |
398 |
|
else |
399 |
|
print_startup(getpid()); |
404 |
|
fdlist_init(); |
405 |
|
log_set_file(LOG_TYPE_IRCD, 0, logFileName); |
406 |
|
|
407 |
< |
init_netio(); /* This needs to be setup early ! -- adrian */ |
407 |
> |
netio_init(); /* This needs to be setup early ! -- adrian */ |
408 |
> |
tls_init(); |
409 |
|
|
410 |
|
/* Check if there is pidfile and daemon already running */ |
411 |
|
check_pidfile(pidFileName); |
412 |
|
|
413 |
|
mp_pool_init(); |
414 |
|
init_dlink_nodes(); |
415 |
< |
init_isupport(); |
415 |
> |
isupport_init(); |
416 |
|
dbuf_init(); |
417 |
|
hash_init(); |
418 |
+ |
userhost_init(); |
419 |
|
ipcache_init(); |
546 |
– |
init_host_hash(); /* Host-hashtable. */ |
420 |
|
client_init(); |
421 |
|
class_init(); |
422 |
|
whowas_init(); |
423 |
|
watch_init(); |
424 |
|
auth_init(); /* Initialise the auth code */ |
425 |
< |
init_resolver(); /* Needs to be setup before the io loop */ |
425 |
> |
resolver_init(); /* Needs to be setup before the io loop */ |
426 |
|
modules_init(); |
427 |
|
read_conf_files(1); /* cold start init conf files */ |
428 |
< |
init_uid(); |
429 |
< |
initialize_server_capabs(); /* Set up default_server_capabs */ |
557 |
< |
initialize_global_set_options(); |
428 |
> |
server_capab_init(); /* Set up default_server_capabs */ |
429 |
> |
initialize_global_set_options(); /* Has to be called after read_conf_files() */ |
430 |
|
channel_init(); |
431 |
|
read_links_file(); |
432 |
|
motd_init(); |
433 |
< |
#ifdef HAVE_LIBGEOIP |
562 |
< |
geoip_ctx = GeoIP_new(GEOIP_MEMORY_CACHE); |
563 |
< |
#endif |
564 |
< |
|
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, ConfigServerInfo.sid, sizeof(me.id)); |
433 |
> |
user_modes_init(); |
434 |
|
|
435 |
|
if (EmptyString(ConfigServerInfo.name)) |
436 |
|
{ |
440 |
|
|
441 |
|
strlcpy(me.name, ConfigServerInfo.name, sizeof(me.name)); |
442 |
|
|
443 |
< |
/* serverinfo{} description must exist. If not, error out.*/ |
443 |
> |
/* serverinfo {} description must exist. If not, error out.*/ |
444 |
|
if (EmptyString(ConfigServerInfo.description)) |
445 |
|
{ |
446 |
|
ilog(LOG_TYPE_IRCD, "ERROR: No server description specified in serverinfo block."); |
449 |
|
|
450 |
|
strlcpy(me.info, ConfigServerInfo.description, sizeof(me.info)); |
451 |
|
|
452 |
< |
me.from = &me; |
453 |
< |
me.servptr = &me; |
454 |
< |
me.connection->lasttime = CurrentTime; |
455 |
< |
me.connection->since = CurrentTime; |
452 |
> |
if (EmptyString(ConfigServerInfo.sid)) |
453 |
> |
{ |
454 |
> |
ilog(LOG_TYPE_IRCD, "Generating server ID"); |
455 |
> |
generate_sid(); |
456 |
> |
} |
457 |
> |
else |
458 |
> |
strlcpy(me.id, ConfigServerInfo.sid, sizeof(me.id)); |
459 |
> |
|
460 |
> |
init_uid(); |
461 |
> |
|
462 |
> |
me.from = &me; |
463 |
> |
me.servptr = &me; |
464 |
> |
me.connection->lasttime = CurrentTime; |
465 |
> |
me.connection->since = CurrentTime; |
466 |
|
me.connection->firsttime = CurrentTime; |
467 |
|
|
468 |
|
SetMe(&me); |
472 |
|
hash_add_client(&me); |
473 |
|
|
474 |
|
dlinkAdd(&me, make_dlink_node(), &global_server_list); |
475 |
+ |
dlinkAdd(&me, &me.node, &global_client_list); |
476 |
|
|
477 |
< |
load_kline_database(); |
478 |
< |
load_dline_database(); |
479 |
< |
load_gline_database(); |
480 |
< |
load_xline_database(); |
608 |
< |
load_resv_database(); |
609 |
< |
|
610 |
< |
if (chdir(MODPATH)) |
611 |
< |
{ |
612 |
< |
ilog(LOG_TYPE_IRCD, "Could not load core modules. Terminating!"); |
613 |
< |
exit(EXIT_FAILURE); |
614 |
< |
} |
477 |
> |
load_kline_database(ConfigGeneral.klinefile); |
478 |
> |
load_dline_database(ConfigGeneral.dlinefile); |
479 |
> |
load_xline_database(ConfigGeneral.xlinefile); |
480 |
> |
load_resv_database(ConfigGeneral.resvfile); |
481 |
|
|
482 |
|
load_all_modules(1); |
483 |
|
load_conf_modules(); |
484 |
|
load_core_modules(1); |
485 |
|
|
620 |
– |
/* Go back to DPATH after checking to see if we can chdir to MODPATH */ |
621 |
– |
if (chdir(ConfigGeneral.dpath)) |
622 |
– |
{ |
623 |
– |
perror("chdir"); |
624 |
– |
exit(EXIT_FAILURE); |
625 |
– |
} |
626 |
– |
|
627 |
– |
/* |
628 |
– |
* assemble_umode_buffer() has to be called after |
629 |
– |
* reading conf/loading modules. |
630 |
– |
*/ |
631 |
– |
assemble_umode_buffer(); |
632 |
– |
|
486 |
|
write_pidfile(pidFileName); |
487 |
|
|
635 |
– |
ilog(LOG_TYPE_IRCD, "Server Ready"); |
636 |
– |
|
637 |
– |
event_addish(&event_cleanup_glines, NULL); |
488 |
|
event_addish(&event_cleanup_tklines, NULL); |
489 |
|
|
490 |
|
/* We want try_connections to be called as soon as possible now! -- adrian */ |
496 |
|
|
497 |
|
event_addish(&event_save_all_databases, NULL); |
498 |
|
|
499 |
< |
if (ConfigServerHide.links_delay > 0) |
499 |
> |
if (ConfigServerHide.flatten_links_delay && event_write_links_file.active == 0) |
500 |
|
{ |
501 |
< |
event_write_links_file.when = ConfigServerHide.links_delay; |
502 |
< |
event_addish(&event_write_links_file, NULL); |
501 |
> |
event_write_links_file.when = ConfigServerHide.flatten_links_delay; |
502 |
> |
event_add(&event_write_links_file, NULL); |
503 |
|
} |
654 |
– |
else |
655 |
– |
ConfigServerHide.links_disabled = 1; |
656 |
– |
|
657 |
– |
if (splitmode) |
658 |
– |
event_addish(&splitmode_event, NULL); |
504 |
|
|
505 |
+ |
ilog(LOG_TYPE_IRCD, "Server Ready"); |
506 |
|
io_loop(); |
507 |
+ |
|
508 |
|
return 0; |
509 |
|
} |