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 |
17 |
|
* along with this program; if not, write to the Free Software |
18 |
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
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" |
29 |
< |
#include "tools.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" |
32 |
– |
#include "common.h" |
33 |
|
#include "event.h" |
34 |
|
#include "fdlist.h" |
35 |
|
#include "hash.h" |
36 |
|
#include "irc_string.h" |
37 |
– |
#include "sprintf_irc.h" |
37 |
|
#include "ircd_signal.h" |
38 |
< |
#include "list.h" |
40 |
< |
#include "s_gline.h" |
38 |
> |
#include "gline.h" |
39 |
|
#include "motd.h" |
40 |
< |
#include "ircd_handler.h" |
43 |
< |
#include "msg.h" /* msgtab */ |
40 |
> |
#include "conf.h" |
41 |
|
#include "hostmask.h" |
45 |
– |
#include "numeric.h" |
46 |
– |
#include "packet.h" |
42 |
|
#include "parse.h" |
43 |
< |
#include "irc_res.h" |
43 |
> |
#include "res.h" |
44 |
|
#include "restart.h" |
45 |
< |
#include "s_auth.h" |
45 |
> |
#include "rng_mt.h" |
46 |
> |
#include "auth.h" |
47 |
|
#include "s_bsd.h" |
48 |
< |
#include "s_conf.h" |
49 |
< |
#include "s_log.h" |
54 |
< |
#include "s_misc.h" |
55 |
< |
#include "s_serv.h" /* try_connections */ |
56 |
< |
#include "s_stats.h" |
48 |
> |
#include "log.h" |
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" |
56 |
< |
#include "balloc.h" |
57 |
< |
#include "motd.h" |
58 |
< |
#include "supported.h" |
56 |
> |
#include "watch.h" |
57 |
> |
#include "conf_db.h" |
58 |
> |
#include "conf_class.h" |
59 |
|
|
67 |
– |
/* Try and find the correct name to use with getrlimit() for setting the max. |
68 |
– |
* number of files allowed to be open by this process. |
69 |
– |
*/ |
60 |
|
|
61 |
< |
/* /quote set variables */ |
62 |
< |
struct SetOptions GlobalSetOptions; |
61 |
> |
#ifdef HAVE_LIBGEOIP |
62 |
> |
GeoIP *geoip_ctx; |
63 |
> |
#endif |
64 |
|
|
65 |
< |
/* configuration set from ircd.conf */ |
75 |
< |
struct config_file_entry ConfigFileEntry; |
76 |
< |
/* server info set from ircd.conf */ |
77 |
< |
struct server_info ServerInfo; |
78 |
< |
/* admin info set from ircd.conf */ |
79 |
< |
struct admin_info AdminInfo = { NULL, NULL, NULL }; |
80 |
< |
struct Counter Count = { 0, 0, 0, 0, 0, 0, 0, 0 }; |
81 |
< |
struct ServerState_t server_state = { 0 }; |
82 |
< |
struct logging_entry ConfigLoggingEntry = { 1, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0} }; |
65 |
> |
struct ServerStatistics ServerStats; |
66 |
|
struct timeval SystemTime; |
67 |
|
struct Client me; /* That's me */ |
68 |
|
struct LocalUser meLocalUser; /* That's also part of me */ |
86 |
– |
unsigned long connect_id = 0; /* unique connect ID */ |
69 |
|
|
88 |
– |
static unsigned long initialVMTop = 0; /* top of virtual memory at init */ |
70 |
|
const char *logFileName = LPATH; |
71 |
|
const char *pidFileName = PPATH; |
72 |
|
|
73 |
|
char **myargv; |
93 |
– |
char ircd_platform[PLATFORMLEN]; |
74 |
|
|
75 |
|
int dorehash = 0; |
76 |
|
int doremotd = 0; |
97 |
– |
time_t nextconnect = 1; /* time for next try_connections call */ |
77 |
|
|
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 |
< |
#ifdef HAVE_LIBCRYPTO |
88 |
< |
int bio_spare_fd = -1; |
89 |
< |
#endif |
87 |
> |
static struct event event_cleanup_glines = |
88 |
> |
{ |
89 |
> |
.name = "cleanup_glines", |
90 |
> |
.handler = cleanup_glines, |
91 |
> |
.when = CLEANUP_GLINES_TIME |
92 |
> |
}; |
93 |
|
|
94 |
< |
int splitmode; |
95 |
< |
int splitchecking; |
96 |
< |
int split_users; |
97 |
< |
unsigned int split_servers; |
94 |
> |
static struct event event_cleanup_tklines = |
95 |
> |
{ |
96 |
> |
.name = "cleanup_tklines", |
97 |
> |
.handler = cleanup_tklines, |
98 |
> |
.when = CLEANUP_TKLINES_TIME |
99 |
> |
}; |
100 |
|
|
101 |
< |
/* Do klines the same way hybrid-6 did them, i.e. at the |
102 |
< |
* top of the next io_loop instead of in the same loop as |
103 |
< |
* the klines are being applied. |
104 |
< |
* |
105 |
< |
* This should fix strange CPU starvation as very indirectly reported. |
106 |
< |
* (Why do you people not email bug reports? WHY? WHY?) |
119 |
< |
* |
120 |
< |
* - Dianora |
121 |
< |
*/ |
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 |
< |
/* |
126 |
< |
* get_vm_top - get the operating systems notion of the resident set size |
127 |
< |
*/ |
128 |
< |
#ifndef _WIN32 |
129 |
< |
static unsigned long |
130 |
< |
get_vm_top(void) |
115 |
> |
static struct event event_save_all_databases = |
116 |
|
{ |
117 |
< |
/* |
118 |
< |
* NOTE: sbrk is not part of the ANSI C library or the POSIX.1 standard |
119 |
< |
* however it seems that everyone defines it. Calling sbrk with a 0 |
120 |
< |
* argument will return a pointer to the top of the process virtual |
121 |
< |
* memory without changing the process size, so this call should be |
122 |
< |
* reasonably safe (sbrk returns the new value for the top of memory). |
123 |
< |
* This code relies on the notion that the address returned will be an |
124 |
< |
* offset from 0 (NULL), so the result of sbrk is cast to a size_t and |
125 |
< |
* returned. We really shouldn't be using it here but... |
126 |
< |
*/ |
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 |
|
|
143 |
– |
void *vptr = sbrk(0); |
144 |
– |
return((unsigned long)vptr); |
145 |
– |
} |
128 |
|
|
129 |
|
/* |
130 |
|
* print_startup - print startup information |
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); |
156 |
|
|
157 |
|
setsid(); |
158 |
|
} |
177 |
– |
#endif |
178 |
– |
|
179 |
– |
/* |
180 |
– |
* get_maxrss - get the operating systems notion of the resident set size |
181 |
– |
*/ |
182 |
– |
unsigned long |
183 |
– |
get_maxrss(void) |
184 |
– |
{ |
185 |
– |
#ifdef _WIN32 |
186 |
– |
return (0); /* FIXME */ |
187 |
– |
#else |
188 |
– |
return (get_vm_top() - initialVMTop); |
189 |
– |
#endif |
190 |
– |
} |
159 |
|
|
160 |
|
static int printVersion = 0; |
161 |
|
|
162 |
< |
struct lgetopt myopts[] = { |
163 |
< |
{"dlinefile", &ConfigFileEntry.dlinefile, |
164 |
< |
STRING, "File to use for dline.conf"}, |
197 |
< |
{"configfile", &ConfigFileEntry.configfile, |
162 |
> |
static struct lgetopt myopts[] = |
163 |
> |
{ |
164 |
> |
{"configfile", &ConfigFileEntry.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", &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, |
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]; |
219 |
< |
struct timeval newtime; |
220 |
< |
#ifdef _WIN32 |
221 |
< |
FILETIME ft; |
222 |
< |
|
223 |
< |
GetSystemTimeAsFileTime(&ft); |
224 |
< |
if (ft.dwLowDateTime < 0xd53e8000) |
225 |
< |
ft.dwHighDateTime--; |
226 |
< |
ft.dwLowDateTime -= 0xd53e8000; |
227 |
< |
ft.dwHighDateTime -= 0x19db1de; |
228 |
< |
|
229 |
< |
newtime.tv_sec = (*(uint64_t *) &ft) / 10000000; |
230 |
< |
newtime.tv_usec = (*(uint64_t *) &ft) / 10 % 1000000; |
231 |
< |
#else |
232 |
< |
newtime.tv_sec = 0; |
233 |
< |
newtime.tv_usec = 0; |
191 |
> |
struct timeval newtime = { .tv_sec = 0, .tv_usec = 0 }; |
192 |
|
|
193 |
|
if (gettimeofday(&newtime, NULL) == -1) |
194 |
|
{ |
195 |
< |
ilog(L_ERROR, "Clock Failure (%s), TS can be corrupted", |
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 |
|
} |
244 |
– |
#endif |
202 |
|
|
203 |
|
if (newtime.tv_sec < CurrentTime) |
204 |
|
{ |
205 |
< |
ircsprintf(to_send, "System clock is running backwards - (%lu < %lu)", |
206 |
< |
(unsigned long)newtime.tv_sec, (unsigned long)CurrentTime); |
207 |
< |
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 |
|
{ |
263 |
– |
/* |
264 |
– |
* Maybe we want a flags word? |
265 |
– |
* ie. if (REHASHED_KLINES(global_flags)) |
266 |
– |
* SET_REHASHED_KLINES(global_flags) |
267 |
– |
* CLEAR_REHASHED_KLINES(global_flags) |
268 |
– |
* |
269 |
– |
* - Dianora |
270 |
– |
*/ |
271 |
– |
if (rehashed_klines) |
272 |
– |
{ |
273 |
– |
check_conf_klines(); |
274 |
– |
rehashed_klines = 0; |
275 |
– |
} |
276 |
– |
|
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 |
< |
{ |
282 |
< |
struct Client *client_p = ptr->data; |
283 |
< |
assert(client_p->localClient->list_task); |
284 |
< |
safe_list_channels(client_p, client_p->localClient->list_task, 0, 0); |
285 |
< |
} |
227 |
> |
safe_list_channels(ptr->data, 0); |
228 |
|
} |
229 |
|
|
230 |
< |
/* Run pending events, then get the number of seconds to the next |
231 |
< |
* event |
290 |
< |
*/ |
291 |
< |
while (eventNextTime() <= CurrentTime) |
292 |
< |
eventRun(); |
230 |
> |
/* Run pending events */ |
231 |
> |
event_run(); |
232 |
|
|
233 |
|
comm_select(); |
234 |
|
exit_aborted_clients(); |
235 |
|
free_exited_clients(); |
297 |
– |
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) |
286 |
|
} |
287 |
|
|
288 |
|
GlobalSetOptions.ident_timeout = IDENT_TIMEOUT; |
350 |
– |
GlobalSetOptions.idletime = ConfigFileEntry.idletime; |
289 |
|
/* End of global set options */ |
290 |
|
} |
291 |
|
|
354 |
– |
/* initialize_message_files() |
355 |
– |
* |
356 |
– |
* inputs - none |
357 |
– |
* output - none |
358 |
– |
* side effects - Set up all message files needed, motd etc. |
359 |
– |
*/ |
360 |
– |
static void |
361 |
– |
initialize_message_files(void) |
362 |
– |
{ |
363 |
– |
init_message_file(USER_MOTD, MPATH, &ConfigFileEntry.motd); |
364 |
– |
init_message_file(OPER_MOTD, OPATH, &ConfigFileEntry.opermotd); |
365 |
– |
init_message_file(USER_LINKS, LIPATH, &ConfigFileEntry.linksfile); |
366 |
– |
|
367 |
– |
read_message_file(&ConfigFileEntry.motd); |
368 |
– |
read_message_file(&ConfigFileEntry.opermotd); |
369 |
– |
read_message_file(&ConfigFileEntry.linksfile); |
370 |
– |
|
371 |
– |
init_isupport(); |
372 |
– |
} |
373 |
– |
|
292 |
|
/* initialize_server_capabs() |
293 |
|
* |
294 |
|
* inputs - none |
298 |
|
initialize_server_capabs(void) |
299 |
|
{ |
300 |
|
add_capability("QS", CAP_QS, 1); |
383 |
– |
add_capability("LL", CAP_LL, 1); |
301 |
|
add_capability("EOB", CAP_EOB, 1); |
302 |
< |
if (ServerInfo.sid != NULL) /* only enable TS6 if we have an SID */ |
386 |
< |
add_capability("TS6", CAP_TS6, 0); |
387 |
< |
add_capability("ZIP", CAP_ZIP, 0); |
302 |
> |
add_capability("TS6", CAP_TS6, 0); |
303 |
|
add_capability("CLUSTER", CAP_CLUSTER, 1); |
304 |
< |
#ifdef HALFOPS |
304 |
> |
add_capability("SVS", CAP_SVS, 1); |
305 |
> |
add_capability("CHW", CAP_CHW, 1); |
306 |
|
add_capability("HOPS", CAP_HOPS, 1); |
391 |
– |
#endif |
307 |
|
} |
308 |
|
|
309 |
|
/* write_pidfile() |
315 |
|
static void |
316 |
|
write_pidfile(const char *filename) |
317 |
|
{ |
318 |
< |
FBFILE *fb; |
318 |
> |
FILE *fb; |
319 |
|
|
320 |
< |
if ((fb = fbopen(filename, "w"))) |
320 |
> |
if ((fb = fopen(filename, "w"))) |
321 |
|
{ |
322 |
< |
char buff[32]; |
322 |
> |
char buff[IRCD_BUFSIZE]; |
323 |
|
unsigned int pid = (unsigned int)getpid(); |
409 |
– |
size_t nbytes = ircsprintf(buff, "%u\n", pid); |
324 |
|
|
325 |
< |
if ((fbputs(buff, fb, nbytes) == -1)) |
326 |
< |
ilog(L_ERROR, "Error writing %u to pid file %s (%s)", |
325 |
> |
snprintf(buff, sizeof(buff), "%u\n", pid); |
326 |
> |
|
327 |
> |
if ((fputs(buff, fb) == -1)) |
328 |
> |
ilog(LOG_TYPE_IRCD, "Error writing %u to pid file %s (%s)", |
329 |
|
pid, filename, strerror(errno)); |
330 |
|
|
331 |
< |
fbclose(fb); |
416 |
< |
return; |
331 |
> |
fclose(fb); |
332 |
|
} |
333 |
|
else |
334 |
|
{ |
335 |
< |
ilog(L_ERROR, "Error opening pid file %s", filename); |
335 |
> |
ilog(LOG_TYPE_IRCD, "Error opening pid file %s", filename); |
336 |
|
} |
337 |
|
} |
338 |
|
|
347 |
|
static void |
348 |
|
check_pidfile(const char *filename) |
349 |
|
{ |
350 |
< |
#ifndef _WIN32 |
351 |
< |
FBFILE *fb; |
437 |
< |
char buff[32]; |
350 |
> |
FILE *fb; |
351 |
> |
char buff[IRCD_BUFSIZE]; |
352 |
|
pid_t pidfromfile; |
353 |
|
|
354 |
|
/* Don't do logging here, since we don't have log() initialised */ |
355 |
< |
if ((fb = fbopen(filename, "r"))) |
355 |
> |
if ((fb = fopen(filename, "r"))) |
356 |
|
{ |
357 |
< |
if (fbgets(buff, 20, fb) == NULL) |
357 |
> |
if (fgets(buff, 20, fb) == NULL) |
358 |
|
{ |
359 |
|
/* log(L_ERROR, "Error reading from pid file %s (%s)", filename, |
360 |
|
* strerror(errno)); |
372 |
|
} |
373 |
|
} |
374 |
|
|
375 |
< |
fbclose(fb); |
375 |
> |
fclose(fb); |
376 |
|
} |
377 |
|
else if (errno != ENOENT) |
378 |
|
{ |
379 |
|
/* log(L_ERROR, "Error opening pid file %s", filename); */ |
380 |
|
} |
467 |
– |
#endif |
381 |
|
} |
382 |
|
|
383 |
|
/* setup_corefile() |
402 |
|
#endif |
403 |
|
} |
404 |
|
|
405 |
+ |
#ifdef HAVE_LIBCRYPTO |
406 |
+ |
static int |
407 |
+ |
always_accept_verify_cb(int preverify_ok, X509_STORE_CTX *x509_ctx) |
408 |
+ |
{ |
409 |
+ |
return 1; |
410 |
+ |
} |
411 |
+ |
#endif |
412 |
+ |
|
413 |
|
/* init_ssl() |
414 |
|
* |
415 |
|
* inputs - nothing |
417 |
|
* side effects - setups SSL context. |
418 |
|
*/ |
419 |
|
static void |
420 |
< |
init_ssl(void) |
420 |
> |
ssl_init(void) |
421 |
|
{ |
422 |
|
#ifdef HAVE_LIBCRYPTO |
423 |
+ |
const unsigned char session_id[] = "ircd-hybrid"; |
424 |
+ |
|
425 |
|
SSL_load_error_strings(); |
426 |
|
SSLeay_add_ssl_algorithms(); |
427 |
|
|
428 |
< |
ServerInfo.ctx = SSL_CTX_new(SSLv23_server_method()); |
506 |
< |
if (!ServerInfo.ctx) |
428 |
> |
if ((ServerInfo.server_ctx = SSL_CTX_new(SSLv23_server_method())) == NULL) |
429 |
|
{ |
430 |
< |
const char *s; |
430 |
> |
const char *s = ERR_lib_error_string(ERR_get_error()); |
431 |
|
|
432 |
< |
fprintf(stderr, "ERROR: Could not initialize the SSL context -- %s\n", |
433 |
< |
s = ERR_lib_error_string(ERR_get_error())); |
512 |
< |
ilog(L_CRIT, "ERROR: Could not initialize the SSL context -- %s\n", s); |
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.ctx, SSL_OP_NO_SSLv2); |
437 |
< |
SSL_CTX_set_options(ServerInfo.ctx, SSL_OP_TLS_ROLLBACK_BUG|SSL_OP_ALL); |
438 |
< |
SSL_CTX_set_verify(ServerInfo.ctx, SSL_VERIFY_NONE, NULL); |
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); |
441 |
|
|
442 |
< |
bio_spare_fd = save_spare_fd("SSL private key validation"); |
443 |
< |
#endif /* HAVE_LIBCRYPTO */ |
444 |
< |
} |
442 |
> |
#if OPENSSL_VERSION_NUMBER >= 0x1000005FL && !defined(OPENSSL_NO_ECDH) |
443 |
> |
{ |
444 |
> |
EC_KEY *key = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1); |
445 |
|
|
446 |
< |
/* init_callbacks() |
447 |
< |
* |
448 |
< |
* inputs - nothing |
449 |
< |
* output - nothing |
450 |
< |
* side effects - setups standard hook points |
451 |
< |
*/ |
452 |
< |
static void |
453 |
< |
init_callbacks(void) |
454 |
< |
{ |
455 |
< |
iorecv_cb = register_callback("iorecv", NULL); |
456 |
< |
iosend_cb = register_callback("iosend", NULL); |
457 |
< |
iorecvctrl_cb = register_callback("iorecvctrl", NULL); |
458 |
< |
iosendctrl_cb = register_callback("iosendctrl", NULL); |
446 |
> |
if (key) |
447 |
> |
{ |
448 |
> |
SSL_CTX_set_tmp_ecdh(ServerInfo.server_ctx, key); |
449 |
> |
EC_KEY_free(key); |
450 |
> |
} |
451 |
> |
} |
452 |
> |
|
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) |
457 |
> |
{ |
458 |
> |
const char *s = ERR_lib_error_string(ERR_get_error()); |
459 |
> |
|
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); |
462 |
> |
} |
463 |
> |
|
464 |
> |
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 */ |
469 |
|
} |
470 |
|
|
471 |
|
int |
472 |
|
main(int argc, char *argv[]) |
473 |
|
{ |
474 |
< |
/* Check to see if the user is running |
542 |
< |
* us as root, which is a nono |
543 |
< |
*/ |
544 |
< |
#ifndef _WIN32 |
474 |
> |
/* Check to see if the user is running us as root, which is a nono */ |
475 |
|
if (geteuid() == 0) |
476 |
|
{ |
477 |
< |
fprintf(stderr, "Don't run ircd as root!!!\n"); |
478 |
< |
return(-1); |
477 |
> |
fprintf(stderr, "ERROR: This server won't run as root/superuser\n"); |
478 |
> |
return -1; |
479 |
|
} |
480 |
|
|
481 |
|
/* Setup corefile size immediately after boot -kre */ |
482 |
|
setup_corefile(); |
483 |
|
|
554 |
– |
/* set initialVMTop before we allocate any memory */ |
555 |
– |
initialVMTop = get_vm_top(); |
556 |
– |
#endif |
557 |
– |
|
484 |
|
/* save server boot time right away, so getrusage works correctly */ |
485 |
|
set_time(); |
486 |
|
|
487 |
< |
/* It ain't random, but it ought to be a little harder to guess */ |
488 |
< |
srand(SystemTime.tv_sec ^ (SystemTime.tv_usec | (getpid() << 20))); |
489 |
< |
memset(&me, 0, sizeof(me)); |
564 |
< |
memset(&meLocalUser, 0, sizeof(meLocalUser)); |
487 |
> |
/* It ain't random, but it ought to be a little harder to guess */ |
488 |
> |
init_genrand(SystemTime.tv_sec ^ (SystemTime.tv_usec | (getpid() << 20))); |
489 |
> |
|
490 |
|
me.localClient = &meLocalUser; |
491 |
< |
dlinkAdd(&me, &me.node, &global_client_list); /* Pointer to beginning |
491 |
> |
dlinkAdd(&me, &me.node, &global_client_list); /* Pointer to beginning |
492 |
|
of Client list */ |
493 |
< |
|
569 |
< |
memset(&ServerInfo, 0, sizeof(ServerInfo)); |
570 |
< |
|
571 |
< |
/* Initialise the channel capability usage counts... */ |
572 |
< |
init_chcap_usage_counts(); |
573 |
< |
|
493 |
> |
ConfigLoggingEntry.use_logging = 1; |
494 |
|
ConfigFileEntry.dpath = DPATH; |
495 |
< |
ConfigFileEntry.configfile = CPATH; /* Server configuration file */ |
496 |
< |
ConfigFileEntry.klinefile = KPATH; /* Server kline file */ |
497 |
< |
ConfigFileEntry.xlinefile = XPATH; /* Server xline file */ |
498 |
< |
ConfigFileEntry.rxlinefile = RXPATH; /* Server regex xline file */ |
499 |
< |
ConfigFileEntry.rklinefile = RKPATH; /* Server regex kline file */ |
500 |
< |
ConfigFileEntry.dlinefile = DLPATH; /* dline file */ |
501 |
< |
ConfigFileEntry.glinefile = GPATH; /* gline log file */ |
502 |
< |
ConfigFileEntry.cresvfile = CRESVPATH; /* channel resv file */ |
503 |
< |
ConfigFileEntry.nresvfile = NRESVPATH; /* nick resv file */ |
495 |
> |
ConfigFileEntry.spath = SPATH; |
496 |
> |
ConfigFileEntry.mpath = MPATH; |
497 |
> |
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 */ |
503 |
> |
|
504 |
|
myargv = argv; |
505 |
|
umask(077); /* better safe than sorry --SRB */ |
506 |
|
|
508 |
|
|
509 |
|
if (printVersion) |
510 |
|
{ |
511 |
< |
printf("ircd: version %s\n", ircd_version); |
511 |
> |
printf("ircd: version %s(%s)\n", ircd_version, serno); |
512 |
|
exit(EXIT_SUCCESS); |
513 |
|
} |
514 |
|
|
518 |
|
exit(EXIT_FAILURE); |
519 |
|
} |
520 |
|
|
521 |
< |
init_ssl(); |
521 |
> |
ssl_init(); |
522 |
|
|
603 |
– |
#ifndef _WIN32 |
523 |
|
if (!server_state.foreground) |
524 |
|
{ |
525 |
|
make_daemon(); |
529 |
|
print_startup(getpid()); |
530 |
|
|
531 |
|
setup_signals(); |
613 |
– |
#endif |
532 |
|
|
615 |
– |
get_ircd_platform(ircd_platform); |
616 |
– |
|
617 |
– |
/* Init the event subsystem */ |
618 |
– |
eventInit(); |
533 |
|
/* We need this to initialise the fd array before anything else */ |
534 |
|
fdlist_init(); |
535 |
< |
init_log(logFileName); |
535 |
> |
log_set_file(LOG_TYPE_IRCD, 0, logFileName); |
536 |
|
check_can_use_v6(); |
537 |
< |
init_comm(); /* This needs to be setup early ! -- adrian */ |
537 |
> |
init_netio(); /* This needs to be setup early ! -- adrian */ |
538 |
> |
|
539 |
|
/* Check if there is pidfile and daemon already running */ |
540 |
|
check_pidfile(pidFileName); |
541 |
|
|
542 |
< |
#ifndef NOBALLOC |
628 |
< |
initBlockHeap(); |
629 |
< |
#endif |
542 |
> |
mp_pool_init(); |
543 |
|
init_dlink_nodes(); |
544 |
< |
init_callbacks(); |
632 |
< |
initialize_message_files(); |
544 |
> |
init_isupport(); |
545 |
|
dbuf_init(); |
546 |
< |
init_hash(); |
546 |
> |
hash_init(); |
547 |
|
init_ip_hash_table(); /* client host ip hash table */ |
548 |
|
init_host_hash(); /* Host-hashtable. */ |
549 |
< |
clear_tree_parse(); |
550 |
< |
init_client(); |
551 |
< |
init_class(); |
552 |
< |
init_whowas(); |
553 |
< |
init_stats(); |
549 |
> |
client_init(); |
550 |
> |
class_init(); |
551 |
> |
whowas_init(); |
552 |
> |
watch_init(); |
553 |
> |
auth_init(); /* Initialise the auth code */ |
554 |
> |
init_resolver(); /* Needs to be setup before the io loop */ |
555 |
> |
modules_init(); |
556 |
|
read_conf_files(1); /* cold start init conf files */ |
643 |
– |
initServerMask(); |
644 |
– |
me.id[0] = '\0'; |
557 |
|
init_uid(); |
646 |
– |
init_auth(); /* Initialise the auth code */ |
647 |
– |
#ifndef _WIN32 |
648 |
– |
init_resolver(); /* Needs to be setup before the io loop */ |
649 |
– |
#endif |
558 |
|
initialize_server_capabs(); /* Set up default_server_capabs */ |
559 |
|
initialize_global_set_options(); |
560 |
< |
init_channels(); |
560 |
> |
channel_init(); |
561 |
> |
read_links_file(); |
562 |
> |
motd_init(); |
563 |
> |
#ifdef HAVE_LIBGEOIP |
564 |
> |
geoip_ctx = GeoIP_new(GEOIP_MEMORY_CACHE); |
565 |
> |
#endif |
566 |
> |
|
567 |
> |
if (EmptyString(ServerInfo.sid)) |
568 |
> |
{ |
569 |
> |
ilog(LOG_TYPE_IRCD, "ERROR: No server id specified in serverinfo block."); |
570 |
> |
exit(EXIT_FAILURE); |
571 |
> |
} |
572 |
|
|
573 |
< |
if (ServerInfo.name == NULL) |
573 |
> |
strlcpy(me.id, ServerInfo.sid, sizeof(me.id)); |
574 |
> |
|
575 |
> |
if (EmptyString(ServerInfo.name)) |
576 |
|
{ |
577 |
< |
ilog(L_CRIT, "No server name specified in serverinfo block."); |
577 |
> |
ilog(LOG_TYPE_IRCD, "ERROR: No server name specified in serverinfo block."); |
578 |
|
exit(EXIT_FAILURE); |
579 |
|
} |
580 |
+ |
|
581 |
|
strlcpy(me.name, ServerInfo.name, sizeof(me.name)); |
582 |
|
|
583 |
|
/* serverinfo{} description must exist. If not, error out.*/ |
584 |
< |
if (ServerInfo.description == NULL) |
584 |
> |
if (EmptyString(ServerInfo.description)) |
585 |
|
{ |
586 |
< |
ilog(L_CRIT, |
665 |
< |
"ERROR: No server description specified in serverinfo block."); |
586 |
> |
ilog(LOG_TYPE_IRCD, "ERROR: No server description specified in serverinfo block."); |
587 |
|
exit(EXIT_FAILURE); |
588 |
|
} |
589 |
+ |
|
590 |
|
strlcpy(me.info, ServerInfo.description, sizeof(me.info)); |
591 |
|
|
592 |
< |
me.from = &me; |
593 |
< |
me.servptr = &me; |
592 |
> |
me.from = &me; |
593 |
> |
me.servptr = &me; |
594 |
> |
me.localClient->lasttime = CurrentTime; |
595 |
> |
me.localClient->since = CurrentTime; |
596 |
> |
me.localClient->firsttime = CurrentTime; |
597 |
|
|
598 |
|
SetMe(&me); |
599 |
|
make_server(&me); |
600 |
|
|
601 |
< |
me.lasttime = me.since = me.firsttime = CurrentTime; |
601 |
> |
hash_add_id(&me); |
602 |
|
hash_add_client(&me); |
603 |
< |
|
603 |
> |
|
604 |
|
/* add ourselves to global_serv_list */ |
605 |
|
dlinkAdd(&me, make_dlink_node(), &global_serv_list); |
606 |
|
|
607 |
< |
check_class(); |
607 |
> |
load_kline_database(); |
608 |
> |
load_dline_database(); |
609 |
> |
load_gline_database(); |
610 |
> |
load_xline_database(); |
611 |
> |
load_resv_database(); |
612 |
|
|
684 |
– |
#ifndef STATIC_MODULES |
613 |
|
if (chdir(MODPATH)) |
614 |
|
{ |
615 |
< |
ilog (L_CRIT, "Could not load core modules. Terminating!"); |
615 |
> |
ilog(LOG_TYPE_IRCD, "Could not load core modules. Terminating!"); |
616 |
|
exit(EXIT_FAILURE); |
617 |
|
} |
618 |
|
|
619 |
|
load_all_modules(1); |
620 |
|
load_conf_modules(); |
621 |
|
load_core_modules(1); |
622 |
+ |
|
623 |
|
/* Go back to DPATH after checking to see if we can chdir to MODPATH */ |
624 |
< |
chdir(ConfigFileEntry.dpath); |
625 |
< |
#else |
626 |
< |
load_all_modules(1); |
627 |
< |
#endif |
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. |
635 |
|
|
636 |
|
write_pidfile(pidFileName); |
637 |
|
|
638 |
< |
ilog(L_NOTICE, "Server Ready"); |
638 |
> |
ilog(LOG_TYPE_IRCD, "Server Ready"); |
639 |
|
|
640 |
< |
eventAddIsh("cleanup_glines", cleanup_glines, NULL, CLEANUP_GLINES_TIME); |
641 |
< |
eventAddIsh("cleanup_tklines", cleanup_tklines, NULL, CLEANUP_TKLINES_TIME); |
640 |
> |
event_addish(&event_cleanup_glines, NULL); |
641 |
> |
event_addish(&event_cleanup_tklines, NULL); |
642 |
|
|
643 |
|
/* We want try_connections to be called as soon as possible now! -- adrian */ |
644 |
|
/* No, 'cause after a restart it would cause all sorts of nick collides */ |
645 |
< |
eventAddIsh("try_connections", try_connections, NULL, STARTUP_CONNECTIONS_TIME); |
715 |
< |
|
716 |
< |
eventAddIsh("collect_zipstats", collect_zipstats, NULL, ZIPSTATS_TIME); |
645 |
> |
event_addish(&event_try_connections, NULL); |
646 |
|
|
647 |
|
/* Setup the timeout check. I'll shift it later :) -- adrian */ |
648 |
< |
eventAddIsh("comm_checktimeouts", comm_checktimeouts, NULL, 1); |
648 |
> |
event_addish(&event_comm_checktimeouts, NULL); |
649 |
> |
|
650 |
> |
event_addish(&event_save_all_databases, NULL); |
651 |
|
|
652 |
|
if (ConfigServerHide.links_delay > 0) |
653 |
< |
eventAddIsh("write_links_file", write_links_file, NULL, ConfigServerHide.links_delay); |
653 |
> |
{ |
654 |
> |
event_write_links_file.when = ConfigServerHide.links_delay; |
655 |
> |
event_addish(&event_write_links_file, NULL); |
656 |
> |
} |
657 |
|
else |
658 |
|
ConfigServerHide.links_disabled = 1; |
659 |
|
|
660 |
|
if (splitmode) |
661 |
< |
eventAddIsh("check_splitmode", check_splitmode, NULL, 60); |
661 |
> |
event_addish(&splitmode_event, NULL); |
662 |
|
|
663 |
|
io_loop(); |
664 |
< |
return(0); |
664 |
> |
return 0; |
665 |
|
} |