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 |
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 |
|
|
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" |
56 |
|
#include "watch.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 SetOptions GlobalSetOptions; /* /quote set variables */ |
70 |
+ |
struct Counter Count; |
71 |
+ |
struct ServerState_t server_state; |
72 |
|
struct ServerStatistics ServerStats; |
73 |
< |
struct timeval SystemTime; |
74 |
< |
struct Client me; /* That's me */ |
75 |
< |
struct LocalUser meLocalUser; /* That's also part of me */ |
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", ConfigFileEntry.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", &ConfigFileEntry.configfile, |
165 |
– |
STRING, "File to use for ircd.conf"}, |
166 |
– |
{"glinefile", &ConfigFileEntry.glinefile, |
167 |
– |
STRING, "File to use for gline database"}, |
168 |
– |
{"klinefile", &ConfigFileEntry.klinefile, |
169 |
– |
STRING, "File to use for kline database"}, |
170 |
– |
{"dlinefile", &ConfigFileEntry.dlinefile, |
171 |
– |
STRING, "File to use for dline database"}, |
172 |
– |
{"xlinefile", &ConfigFileEntry.xlinefile, |
173 |
– |
STRING, "File to use for xline database"}, |
174 |
– |
{"resvfile", &ConfigFileEntry.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 |
< |
memset(&GlobalSetOptions, 0, sizeof(GlobalSetOptions)); |
219 |
< |
|
265 |
< |
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 (ConfigFileEntry.default_floodcount) |
224 |
< |
GlobalSetOptions.floodcount = ConfigFileEntry.default_floodcount; |
271 |
< |
else |
272 |
< |
GlobalSetOptions.floodcount = 10; |
273 |
< |
|
274 |
< |
/* XXX I have no idea what to try here - Dianora */ |
275 |
< |
GlobalSetOptions.joinfloodcount = 16; |
276 |
< |
GlobalSetOptions.joinfloodtime = 8; |
277 |
< |
|
278 |
< |
split_servers = ConfigChannel.default_split_server_count; |
279 |
< |
split_users = ConfigChannel.default_split_user_count; |
280 |
< |
|
281 |
< |
if (split_users && split_servers && (ConfigChannel.no_create_on_split || |
282 |
< |
ConfigChannel.no_join_on_split)) |
283 |
< |
{ |
284 |
< |
splitmode = 1; |
285 |
< |
splitchecking = 1; |
286 |
< |
} |
287 |
< |
|
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; |
289 |
– |
/* End of global set options */ |
226 |
|
} |
227 |
|
|
228 |
|
/* initialize_server_capabs() |
233 |
|
static void |
234 |
|
initialize_server_capabs(void) |
235 |
|
{ |
236 |
< |
add_capability("QS", CAP_QS, 1); |
237 |
< |
add_capability("EOB", CAP_EOB, 1); |
238 |
< |
add_capability("TS6", CAP_TS6, 0); |
239 |
< |
add_capability("CLUSTER", CAP_CLUSTER, 1); |
240 |
< |
add_capability("SVS", CAP_SVS, 1); |
241 |
< |
add_capability("CHW", CAP_CHW, 1); |
306 |
< |
add_capability("HOPS", CAP_HOPS, 1); |
236 |
> |
add_capability("QS", CAPAB_QS); |
237 |
> |
add_capability("EOB", CAPAB_EOB); |
238 |
> |
add_capability("CLUSTER", CAPAB_CLUSTER); |
239 |
> |
add_capability("SVS", CAPAB_SVS); |
240 |
> |
add_capability("CHW", CAPAB_CHW); |
241 |
> |
add_capability("HOPS", CAPAB_HOPS); |
242 |
|
} |
243 |
|
|
244 |
|
/* write_pidfile() |
254 |
|
|
255 |
|
if ((fb = fopen(filename, "w"))) |
256 |
|
{ |
257 |
< |
char buff[IRCD_BUFSIZE]; |
257 |
> |
char buf[IRCD_BUFSIZE]; |
258 |
|
unsigned int pid = (unsigned int)getpid(); |
259 |
|
|
260 |
< |
snprintf(buff, sizeof(buff), "%u\n", pid); |
260 |
> |
snprintf(buf, sizeof(buf), "%u\n", pid); |
261 |
|
|
262 |
< |
if ((fputs(buff, fb) == -1)) |
263 |
< |
ilog(LOG_TYPE_IRCD, "Error writing %u to pid file %s (%s)", |
264 |
< |
pid, filename, strerror(errno)); |
262 |
> |
if (fputs(buf, fb) == -1) |
263 |
> |
ilog(LOG_TYPE_IRCD, "Error writing to pid file %s: %s", |
264 |
> |
filename, strerror(errno)); |
265 |
|
|
266 |
|
fclose(fb); |
267 |
|
} |
268 |
|
else |
269 |
< |
{ |
270 |
< |
ilog(LOG_TYPE_IRCD, "Error opening pid file %s", filename); |
336 |
< |
} |
269 |
> |
ilog(LOG_TYPE_IRCD, "Error opening pid file %s: %s", |
270 |
> |
filename, strerror(errno)); |
271 |
|
} |
272 |
|
|
273 |
|
/* check_pidfile() |
282 |
|
check_pidfile(const char *filename) |
283 |
|
{ |
284 |
|
FILE *fb; |
285 |
< |
char buff[IRCD_BUFSIZE]; |
352 |
< |
pid_t pidfromfile; |
285 |
> |
char buf[IRCD_BUFSIZE]; |
286 |
|
|
354 |
– |
/* Don't do logging here, since we don't have log() initialised */ |
287 |
|
if ((fb = fopen(filename, "r"))) |
288 |
|
{ |
289 |
< |
if (fgets(buff, 20, fb) == NULL) |
290 |
< |
{ |
291 |
< |
/* log(L_ERROR, "Error reading from pid file %s (%s)", filename, |
360 |
< |
* strerror(errno)); |
361 |
< |
*/ |
362 |
< |
} |
289 |
> |
if (!fgets(buf, 20, fb)) |
290 |
> |
ilog(LOG_TYPE_IRCD, "Error reading from pid file %s: %s", |
291 |
> |
filename, strerror(errno)); |
292 |
|
else |
293 |
|
{ |
294 |
< |
pidfromfile = atoi(buff); |
294 |
> |
pid_t pid = atoi(buf); |
295 |
|
|
296 |
< |
if (!kill(pidfromfile, 0)) |
296 |
> |
if (!kill(pid, 0)) |
297 |
|
{ |
298 |
|
/* log(L_ERROR, "Server is already running"); */ |
299 |
|
printf("ircd: daemon is already running\n"); |
300 |
< |
exit(-1); |
300 |
> |
exit(EXIT_FAILURE); |
301 |
|
} |
302 |
|
} |
303 |
|
|
304 |
|
fclose(fb); |
305 |
|
} |
306 |
|
else if (errno != ENOENT) |
307 |
< |
{ |
308 |
< |
/* log(L_ERROR, "Error opening pid file %s", filename); */ |
380 |
< |
} |
307 |
> |
ilog(LOG_TYPE_IRCD, "Error opening pid file %s: %s", |
308 |
> |
filename, strerror(errno)); |
309 |
|
} |
310 |
|
|
311 |
|
/* setup_corefile() |
330 |
|
#endif |
331 |
|
} |
332 |
|
|
333 |
< |
#ifdef HAVE_LIBCRYPTO |
334 |
< |
static int |
335 |
< |
always_accept_verify_cb(int preverify_ok, X509_STORE_CTX *x509_ctx) |
333 |
> |
/* |
334 |
> |
* print_startup - print startup information |
335 |
> |
*/ |
336 |
> |
static void |
337 |
> |
print_startup(int pid) |
338 |
|
{ |
339 |
< |
return 1; |
339 |
> |
printf("ircd: version %s(%s)\n", ircd_version, serno); |
340 |
> |
printf("ircd: pid %d\n", pid); |
341 |
> |
printf("ircd: running in %s mode from %s\n", !server_state.foreground ? "background" |
342 |
> |
: "foreground", ConfigGeneral.dpath); |
343 |
|
} |
411 |
– |
#endif |
344 |
|
|
413 |
– |
/* init_ssl() |
414 |
– |
* |
415 |
– |
* inputs - nothing |
416 |
– |
* output - nothing |
417 |
– |
* side effects - setups SSL context. |
418 |
– |
*/ |
345 |
|
static void |
346 |
< |
ssl_init(void) |
346 |
> |
make_daemon(void) |
347 |
|
{ |
348 |
< |
#ifdef HAVE_LIBCRYPTO |
423 |
< |
const unsigned char session_id[] = "ircd-hybrid"; |
424 |
< |
|
425 |
< |
SSL_load_error_strings(); |
426 |
< |
SSLeay_add_ssl_algorithms(); |
427 |
< |
|
428 |
< |
if ((ServerInfo.server_ctx = SSL_CTX_new(SSLv23_server_method())) == NULL) |
429 |
< |
{ |
430 |
< |
const char *s = ERR_lib_error_string(ERR_get_error()); |
431 |
< |
|
432 |
< |
fprintf(stderr, "ERROR: Could not initialize the SSL Server context -- %s\n", s); |
433 |
< |
ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Server context -- %s\n", s); |
434 |
< |
} |
435 |
< |
|
436 |
< |
SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TLSv1); |
437 |
< |
SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_SINGLE_DH_USE); |
438 |
< |
SSL_CTX_set_verify(ServerInfo.server_ctx, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE, |
439 |
< |
always_accept_verify_cb); |
440 |
< |
SSL_CTX_set_session_id_context(ServerInfo.server_ctx, session_id, sizeof(session_id) - 1); |
348 |
> |
int pid; |
349 |
|
|
350 |
< |
#if OPENSSL_VERSION_NUMBER >= 0x1000005FL && !defined(OPENSSL_NO_ECDH) |
350 |
> |
if ((pid = fork()) < 0) |
351 |
|
{ |
352 |
< |
EC_KEY *key = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1); |
353 |
< |
|
446 |
< |
if (key) |
447 |
< |
{ |
448 |
< |
SSL_CTX_set_tmp_ecdh(ServerInfo.server_ctx, key); |
449 |
< |
EC_KEY_free(key); |
450 |
< |
} |
352 |
> |
perror("fork"); |
353 |
> |
exit(EXIT_FAILURE); |
354 |
|
} |
355 |
< |
|
453 |
< |
SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_SINGLE_ECDH_USE); |
454 |
< |
#endif |
455 |
< |
|
456 |
< |
if ((ServerInfo.client_ctx = SSL_CTX_new(SSLv23_client_method())) == NULL) |
355 |
> |
else if (pid > 0) |
356 |
|
{ |
357 |
< |
const char *s = ERR_lib_error_string(ERR_get_error()); |
358 |
< |
|
460 |
< |
fprintf(stderr, "ERROR: Could not initialize the SSL Client context -- %s\n", s); |
461 |
< |
ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Client context -- %s\n", s); |
357 |
> |
print_startup(pid); |
358 |
> |
exit(EXIT_SUCCESS); |
359 |
|
} |
360 |
|
|
361 |
< |
SSL_CTX_set_options(ServerInfo.client_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TLSv1); |
465 |
< |
SSL_CTX_set_options(ServerInfo.client_ctx, SSL_OP_SINGLE_DH_USE); |
466 |
< |
SSL_CTX_set_verify(ServerInfo.client_ctx, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE, |
467 |
< |
always_accept_verify_cb); |
468 |
< |
#endif /* HAVE_LIBCRYPTO */ |
361 |
> |
setsid(); |
362 |
|
} |
363 |
|
|
364 |
|
int |
365 |
|
main(int argc, char *argv[]) |
366 |
|
{ |
367 |
|
/* Check to see if the user is running us as root, which is a nono */ |
368 |
< |
if (geteuid() == 0) |
368 |
> |
if (!geteuid()) |
369 |
|
{ |
370 |
|
fprintf(stderr, "ERROR: This server won't run as root/superuser\n"); |
371 |
|
return -1; |
374 |
|
/* Setup corefile size immediately after boot -kre */ |
375 |
|
setup_corefile(); |
376 |
|
|
377 |
< |
/* save server boot time right away, so getrusage works correctly */ |
377 |
> |
/* Save server boot time right away, so getrusage works correctly */ |
378 |
|
set_time(); |
379 |
|
|
380 |
< |
/* It ain't random, but it ought to be a little harder to guess */ |
380 |
> |
/* It's not random, but it ought to be a little harder to guess */ |
381 |
|
init_genrand(SystemTime.tv_sec ^ (SystemTime.tv_usec | (getpid() << 20))); |
382 |
|
|
383 |
< |
me.localClient = &meLocalUser; |
384 |
< |
dlinkAdd(&me, &me.node, &global_client_list); /* Pointer to beginning |
385 |
< |
of Client list */ |
386 |
< |
ConfigLoggingEntry.use_logging = 1; |
387 |
< |
ConfigFileEntry.dpath = DPATH; |
388 |
< |
ConfigFileEntry.spath = SPATH; |
389 |
< |
ConfigFileEntry.mpath = MPATH; |
390 |
< |
ConfigFileEntry.configfile = CPATH; /* Server configuration file */ |
498 |
< |
ConfigFileEntry.klinefile = KPATH; /* Server kline file */ |
499 |
< |
ConfigFileEntry.glinefile = GPATH; /* Server gline file */ |
500 |
< |
ConfigFileEntry.xlinefile = XPATH; /* Server xline file */ |
501 |
< |
ConfigFileEntry.dlinefile = DLPATH; /* dline file */ |
502 |
< |
ConfigFileEntry.resvfile = RESVPATH; /* resv file */ |
383 |
> |
ConfigGeneral.dpath = DPATH; |
384 |
> |
ConfigGeneral.spath = SPATH; |
385 |
> |
ConfigGeneral.mpath = MPATH; |
386 |
> |
ConfigGeneral.configfile = CPATH; /* Server configuration file */ |
387 |
> |
ConfigGeneral.klinefile = KPATH; /* Server kline file */ |
388 |
> |
ConfigGeneral.xlinefile = XPATH; /* Server xline file */ |
389 |
> |
ConfigGeneral.dlinefile = DLPATH; /* dline file */ |
390 |
> |
ConfigGeneral.resvfile = RESVPATH; /* resv file */ |
391 |
|
|
392 |
|
myargv = argv; |
393 |
< |
umask(077); /* better safe than sorry --SRB */ |
393 |
> |
umask(077); /* umask 077: u=rwx,g=,o= */ |
394 |
|
|
395 |
|
parseargs(&argc, &argv, myopts); |
396 |
|
|
400 |
|
exit(EXIT_SUCCESS); |
401 |
|
} |
402 |
|
|
403 |
< |
if (chdir(ConfigFileEntry.dpath)) |
403 |
> |
if (chdir(ConfigGeneral.dpath)) |
404 |
|
{ |
405 |
|
perror("chdir"); |
406 |
|
exit(EXIT_FAILURE); |
407 |
|
} |
408 |
|
|
521 |
– |
ssl_init(); |
522 |
– |
|
409 |
|
if (!server_state.foreground) |
410 |
|
{ |
411 |
|
make_daemon(); |
419 |
|
/* We need this to initialise the fd array before anything else */ |
420 |
|
fdlist_init(); |
421 |
|
log_set_file(LOG_TYPE_IRCD, 0, logFileName); |
422 |
< |
check_can_use_v6(); |
422 |
> |
|
423 |
|
init_netio(); /* This needs to be setup early ! -- adrian */ |
424 |
+ |
tls_init(); |
425 |
|
|
426 |
|
/* Check if there is pidfile and daemon already running */ |
427 |
|
check_pidfile(pidFileName); |
428 |
|
|
429 |
|
mp_pool_init(); |
430 |
|
init_dlink_nodes(); |
431 |
< |
init_isupport(); |
431 |
> |
isupport_init(); |
432 |
|
dbuf_init(); |
433 |
|
hash_init(); |
434 |
< |
init_ip_hash_table(); /* client host ip hash table */ |
435 |
< |
init_host_hash(); /* Host-hashtable. */ |
434 |
> |
userhost_init(); |
435 |
> |
ipcache_init(); |
436 |
|
client_init(); |
437 |
|
class_init(); |
438 |
|
whowas_init(); |
441 |
|
init_resolver(); /* Needs to be setup before the io loop */ |
442 |
|
modules_init(); |
443 |
|
read_conf_files(1); /* cold start init conf files */ |
557 |
– |
init_uid(); |
444 |
|
initialize_server_capabs(); /* Set up default_server_capabs */ |
445 |
< |
initialize_global_set_options(); |
445 |
> |
initialize_global_set_options(); /* Has to be called after read_conf_files() */ |
446 |
|
channel_init(); |
447 |
|
read_links_file(); |
448 |
|
motd_init(); |
449 |
< |
#ifdef HAVE_LIBGEOIP |
564 |
< |
geoip_ctx = GeoIP_new(GEOIP_MEMORY_CACHE); |
565 |
< |
#endif |
449 |
> |
user_modes_init(); |
450 |
|
|
451 |
< |
if (EmptyString(ServerInfo.sid)) |
451 |
> |
if (EmptyString(ConfigServerInfo.name)) |
452 |
|
{ |
453 |
< |
ilog(LOG_TYPE_IRCD, "ERROR: No server id specified in serverinfo block."); |
453 |
> |
ilog(LOG_TYPE_IRCD, "ERROR: No server name specified in serverinfo block."); |
454 |
|
exit(EXIT_FAILURE); |
455 |
|
} |
456 |
|
|
457 |
< |
strlcpy(me.id, ServerInfo.sid, sizeof(me.id)); |
457 |
> |
strlcpy(me.name, ConfigServerInfo.name, sizeof(me.name)); |
458 |
|
|
459 |
< |
if (EmptyString(ServerInfo.name)) |
459 |
> |
/* serverinfo {} description must exist. If not, error out.*/ |
460 |
> |
if (EmptyString(ConfigServerInfo.description)) |
461 |
|
{ |
462 |
< |
ilog(LOG_TYPE_IRCD, "ERROR: No server name specified in serverinfo block."); |
462 |
> |
ilog(LOG_TYPE_IRCD, "ERROR: No server description specified in serverinfo block."); |
463 |
|
exit(EXIT_FAILURE); |
464 |
|
} |
465 |
|
|
466 |
< |
strlcpy(me.name, ServerInfo.name, sizeof(me.name)); |
466 |
> |
strlcpy(me.info, ConfigServerInfo.description, sizeof(me.info)); |
467 |
|
|
468 |
< |
/* serverinfo{} description must exist. If not, error out.*/ |
584 |
< |
if (EmptyString(ServerInfo.description)) |
468 |
> |
if (EmptyString(ConfigServerInfo.sid)) |
469 |
|
{ |
470 |
< |
ilog(LOG_TYPE_IRCD, "ERROR: No server description specified in serverinfo block."); |
471 |
< |
exit(EXIT_FAILURE); |
470 |
> |
ilog(LOG_TYPE_IRCD, "Generating server ID"); |
471 |
> |
generate_sid(); |
472 |
|
} |
473 |
+ |
else |
474 |
+ |
strlcpy(me.id, ConfigServerInfo.sid, sizeof(me.id)); |
475 |
|
|
476 |
< |
strlcpy(me.info, ServerInfo.description, sizeof(me.info)); |
476 |
> |
init_uid(); |
477 |
|
|
478 |
< |
me.from = &me; |
479 |
< |
me.servptr = &me; |
480 |
< |
me.localClient->lasttime = CurrentTime; |
481 |
< |
me.localClient->since = CurrentTime; |
482 |
< |
me.localClient->firsttime = CurrentTime; |
478 |
> |
me.from = &me; |
479 |
> |
me.servptr = &me; |
480 |
> |
me.connection->lasttime = CurrentTime; |
481 |
> |
me.connection->since = CurrentTime; |
482 |
> |
me.connection->firsttime = CurrentTime; |
483 |
|
|
484 |
|
SetMe(&me); |
485 |
|
make_server(&me); |
487 |
|
hash_add_id(&me); |
488 |
|
hash_add_client(&me); |
489 |
|
|
490 |
< |
/* add ourselves to global_serv_list */ |
491 |
< |
dlinkAdd(&me, make_dlink_node(), &global_serv_list); |
490 |
> |
dlinkAdd(&me, make_dlink_node(), &global_server_list); |
491 |
> |
dlinkAdd(&me, &me.node, &global_client_list); |
492 |
|
|
493 |
< |
load_kline_database(); |
494 |
< |
load_dline_database(); |
495 |
< |
load_gline_database(); |
496 |
< |
load_xline_database(); |
611 |
< |
load_resv_database(); |
612 |
< |
|
613 |
< |
if (chdir(MODPATH)) |
614 |
< |
{ |
615 |
< |
ilog(LOG_TYPE_IRCD, "Could not load core modules. Terminating!"); |
616 |
< |
exit(EXIT_FAILURE); |
617 |
< |
} |
493 |
> |
load_kline_database(ConfigGeneral.klinefile); |
494 |
> |
load_dline_database(ConfigGeneral.dlinefile); |
495 |
> |
load_xline_database(ConfigGeneral.xlinefile); |
496 |
> |
load_resv_database(ConfigGeneral.resvfile); |
497 |
|
|
498 |
|
load_all_modules(1); |
499 |
|
load_conf_modules(); |
500 |
|
load_core_modules(1); |
501 |
|
|
623 |
– |
/* Go back to DPATH after checking to see if we can chdir to MODPATH */ |
624 |
– |
if (chdir(ConfigFileEntry.dpath)) |
625 |
– |
{ |
626 |
– |
perror("chdir"); |
627 |
– |
exit(EXIT_FAILURE); |
628 |
– |
} |
629 |
– |
|
630 |
– |
/* |
631 |
– |
* assemble_umode_buffer() has to be called after |
632 |
– |
* reading conf/loading modules. |
633 |
– |
*/ |
634 |
– |
assemble_umode_buffer(); |
635 |
– |
|
502 |
|
write_pidfile(pidFileName); |
503 |
|
|
638 |
– |
ilog(LOG_TYPE_IRCD, "Server Ready"); |
639 |
– |
|
640 |
– |
event_addish(&event_cleanup_glines, NULL); |
504 |
|
event_addish(&event_cleanup_tklines, NULL); |
505 |
|
|
506 |
|
/* We want try_connections to be called as soon as possible now! -- adrian */ |
508 |
|
event_addish(&event_try_connections, NULL); |
509 |
|
|
510 |
|
/* Setup the timeout check. I'll shift it later :) -- adrian */ |
511 |
< |
event_addish(&event_comm_checktimeouts, NULL); |
511 |
> |
event_add(&event_comm_checktimeouts, NULL); |
512 |
|
|
513 |
|
event_addish(&event_save_all_databases, NULL); |
514 |
|
|
515 |
< |
if (ConfigServerHide.links_delay > 0) |
515 |
> |
if (ConfigServerHide.flatten_links_delay && event_write_links_file.active == 0) |
516 |
|
{ |
517 |
< |
event_write_links_file.when = ConfigServerHide.links_delay; |
518 |
< |
event_addish(&event_write_links_file, NULL); |
517 |
> |
event_write_links_file.when = ConfigServerHide.flatten_links_delay; |
518 |
> |
event_add(&event_write_links_file, NULL); |
519 |
|
} |
657 |
– |
else |
658 |
– |
ConfigServerHide.links_disabled = 1; |
659 |
– |
|
660 |
– |
if (splitmode) |
661 |
– |
event_addish(&splitmode_event, NULL); |
520 |
|
|
521 |
+ |
ilog(LOG_TYPE_IRCD, "Server Ready"); |
522 |
|
io_loop(); |
523 |
+ |
|
524 |
|
return 0; |
525 |
|
} |