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-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 |
< |
* $Id$ |
20 |
> |
*/ |
21 |
> |
|
22 |
> |
/*! \file ircd.c |
23 |
> |
* \brief Starts up and runs the ircd. |
24 |
> |
* \version $Id$ |
25 |
|
*/ |
26 |
|
|
27 |
|
#include "stdinc.h" |
28 |
< |
#include "s_user.h" |
28 |
> |
#include "user.h" |
29 |
|
#include "list.h" |
30 |
|
#include "ircd.h" |
31 |
|
#include "channel.h" |
30 |
– |
#include "channel_mode.h" |
32 |
|
#include "client.h" |
33 |
|
#include "event.h" |
34 |
|
#include "fdlist.h" |
35 |
|
#include "hash.h" |
36 |
+ |
#include "id.h" |
37 |
|
#include "irc_string.h" |
38 |
|
#include "ircd_signal.h" |
37 |
– |
#include "s_gline.h" |
39 |
|
#include "motd.h" |
40 |
+ |
#include "conf.h" |
41 |
|
#include "hostmask.h" |
40 |
– |
#include "numeric.h" |
41 |
– |
#include "packet.h" |
42 |
|
#include "parse.h" |
43 |
< |
#include "irc_res.h" |
43 |
> |
#include "res.h" |
44 |
|
#include "restart.h" |
45 |
|
#include "rng_mt.h" |
46 |
< |
#include "s_auth.h" |
46 |
> |
#include "auth.h" |
47 |
|
#include "s_bsd.h" |
48 |
< |
#include "s_conf.h" |
49 |
< |
#include "s_log.h" |
50 |
< |
#include "s_misc.h" |
51 |
< |
#include "s_serv.h" /* try_connections */ |
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" |
58 |
– |
#include "balloc.h" |
59 |
– |
#include "motd.h" |
60 |
– |
#include "supported.h" |
56 |
|
#include "watch.h" |
57 |
+ |
#include "conf_db.h" |
58 |
+ |
#include "conf_class.h" |
59 |
+ |
#include "ipcache.h" |
60 |
+ |
#include "isupport.h" |
61 |
|
|
62 |
|
|
63 |
< |
/* /quote set variables */ |
64 |
< |
struct SetOptions GlobalSetOptions; |
63 |
> |
#ifdef HAVE_LIBGEOIP |
64 |
> |
GeoIP *geoip_ctx; |
65 |
> |
#endif |
66 |
|
|
67 |
< |
/* configuration set from ircd.conf */ |
68 |
< |
struct config_file_entry ConfigFileEntry; |
69 |
< |
/* server info set from ircd.conf */ |
70 |
< |
struct server_info ServerInfo; |
71 |
< |
/* admin info set from ircd.conf */ |
72 |
< |
struct admin_info AdminInfo = { NULL, NULL, NULL }; |
73 |
< |
struct Counter Count = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; |
74 |
< |
struct ServerState_t server_state = { 0 }; |
75 |
< |
struct logging_entry ConfigLoggingEntry = { 1, 1 }; |
67 |
> |
struct SetOptions GlobalSetOptions; /* /quote set variables */ |
68 |
> |
struct Counter Count; |
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 |
< |
char ircd_platform[PLATFORMLEN]; |
86 |
< |
|
87 |
< |
int dorehash = 0; |
88 |
< |
int doremotd = 0; |
89 |
< |
|
90 |
< |
/* Set to zero because it should be initialized later using |
91 |
< |
* initialize_server_capabs |
92 |
< |
*/ |
93 |
< |
int default_server_capabs = 0; |
79 |
> |
unsigned int dorehash; |
80 |
> |
unsigned int doremotd; |
81 |
|
unsigned int splitmode; |
82 |
|
unsigned int splitchecking; |
83 |
|
unsigned int split_users; |
84 |
|
unsigned int split_servers; |
85 |
|
|
86 |
< |
/* Do klines the same way hybrid-6 did them, i.e. at the |
87 |
< |
* top of the next io_loop instead of in the same loop as |
88 |
< |
* the klines are being applied. |
89 |
< |
* |
90 |
< |
* This should fix strange CPU starvation as very indirectly reported. |
91 |
< |
* (Why do you people not email bug reports? WHY? WHY?) |
92 |
< |
* |
93 |
< |
* - Dianora |
94 |
< |
*/ |
86 |
> |
static struct event event_cleanup_tklines = |
87 |
> |
{ |
88 |
> |
.name = "cleanup_tklines", |
89 |
> |
.handler = cleanup_tklines, |
90 |
> |
.when = CLEANUP_TKLINES_TIME |
91 |
> |
}; |
92 |
> |
|
93 |
> |
static struct event event_try_connections = |
94 |
> |
{ |
95 |
> |
.name = "try_connections", |
96 |
> |
.handler = try_connections, |
97 |
> |
.when = STARTUP_CONNECTIONS_TIME |
98 |
> |
}; |
99 |
> |
|
100 |
> |
static struct event event_comm_checktimeouts = |
101 |
> |
{ |
102 |
> |
.name = "comm_checktimeouts", |
103 |
> |
.handler = comm_checktimeouts, |
104 |
> |
.when = 1 |
105 |
> |
}; |
106 |
|
|
107 |
< |
int rehashed_klines = 0; |
107 |
> |
static struct event event_save_all_databases = |
108 |
> |
{ |
109 |
> |
.name = "save_all_databases", |
110 |
> |
.handler = save_all_databases, |
111 |
> |
.when = DATABASE_UPDATE_TIMEOUT |
112 |
> |
}; |
113 |
> |
|
114 |
> |
struct event event_write_links_file = |
115 |
> |
{ |
116 |
> |
.name = "write_links_file", |
117 |
> |
.handler = write_links_file, |
118 |
> |
}; |
119 |
|
|
120 |
|
|
121 |
|
/* |
124 |
|
static void |
125 |
|
print_startup(int pid) |
126 |
|
{ |
127 |
< |
printf("ircd: version %s\n", ircd_version); |
127 |
> |
printf("ircd: version %s(%s)\n", ircd_version, serno); |
128 |
|
printf("ircd: pid %d\n", pid); |
129 |
|
printf("ircd: running in %s mode from %s\n", !server_state.foreground ? "background" |
130 |
< |
: "foreground", ConfigFileEntry.dpath); |
130 |
> |
: "foreground", ConfigGeneral.dpath); |
131 |
|
} |
132 |
|
|
133 |
|
static void |
151 |
|
|
152 |
|
static int printVersion = 0; |
153 |
|
|
154 |
< |
struct lgetopt myopts[] = { |
155 |
< |
{"dlinefile", &ConfigFileEntry.dlinefile, |
156 |
< |
STRING, "File to use for dline.conf"}, |
148 |
< |
{"configfile", &ConfigFileEntry.configfile, |
154 |
> |
static struct lgetopt myopts[] = |
155 |
> |
{ |
156 |
> |
{"configfile", &ConfigGeneral.configfile, |
157 |
|
STRING, "File to use for ircd.conf"}, |
158 |
< |
{"klinefile", &ConfigFileEntry.klinefile, |
159 |
< |
STRING, "File to use for kline.conf"}, |
160 |
< |
{"xlinefile", &ConfigFileEntry.xlinefile, |
161 |
< |
STRING, "File to use for xline.conf"}, |
162 |
< |
{"logfile", &logFileName, |
158 |
> |
{"klinefile", &ConfigGeneral.klinefile, |
159 |
> |
STRING, "File to use for kline database"}, |
160 |
> |
{"dlinefile", &ConfigGeneral.dlinefile, |
161 |
> |
STRING, "File to use for dline database"}, |
162 |
> |
{"xlinefile", &ConfigGeneral.xlinefile, |
163 |
> |
STRING, "File to use for xline database"}, |
164 |
> |
{"resvfile", &ConfigGeneral.resvfile, |
165 |
> |
STRING, "File to use for resv database"}, |
166 |
> |
{"logfile", &logFileName, |
167 |
|
STRING, "File to use for ircd.log"}, |
168 |
|
{"pidfile", &pidFileName, |
169 |
|
STRING, "File to use for process ID"}, |
170 |
< |
{"foreground", &server_state.foreground, |
170 |
> |
{"foreground", &server_state.foreground, |
171 |
|
YESNO, "Run in foreground (don't detach)"}, |
172 |
< |
{"version", &printVersion, |
172 |
> |
{"version", &printVersion, |
173 |
|
YESNO, "Print version and exit"}, |
174 |
|
{"help", NULL, USAGE, "Print this text"}, |
175 |
|
{NULL, NULL, STRING, NULL}, |
178 |
|
void |
179 |
|
set_time(void) |
180 |
|
{ |
181 |
< |
static char to_send[200]; |
170 |
< |
struct timeval newtime; |
171 |
< |
newtime.tv_sec = 0; |
172 |
< |
newtime.tv_usec = 0; |
181 |
> |
struct timeval newtime = { .tv_sec = 0, .tv_usec = 0 }; |
182 |
|
|
183 |
|
if (gettimeofday(&newtime, NULL) == -1) |
184 |
|
{ |
185 |
|
ilog(LOG_TYPE_IRCD, "Clock Failure (%s), TS can be corrupted", |
186 |
|
strerror(errno)); |
187 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, |
187 |
> |
sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE, |
188 |
|
"Clock Failure (%s), TS can be corrupted", |
189 |
|
strerror(errno)); |
190 |
< |
restart("Clock Failure"); |
190 |
> |
server_die("Clock Failure", 1); |
191 |
|
} |
192 |
|
|
193 |
|
if (newtime.tv_sec < CurrentTime) |
194 |
|
{ |
195 |
< |
snprintf(to_send, sizeof(to_send), |
196 |
< |
"System clock is running backwards - (%lu < %lu)", |
197 |
< |
(unsigned long)newtime.tv_sec, (unsigned long)CurrentTime); |
198 |
< |
report_error(L_ALL, to_send, me.name, 0); |
195 |
> |
ilog(LOG_TYPE_IRCD, "System clock is running backwards - (%lu < %lu)", |
196 |
> |
(unsigned long)newtime.tv_sec, (unsigned long)CurrentTime); |
197 |
> |
sendto_realops_flags(UMODE_DEBUG, L_ALL, SEND_NOTICE, |
198 |
> |
"System clock is running backwards - (%lu < %lu)", |
199 |
> |
(unsigned long)newtime.tv_sec, |
200 |
> |
(unsigned long)CurrentTime); |
201 |
|
set_back_events(CurrentTime - newtime.tv_sec); |
202 |
|
} |
203 |
|
|
208 |
|
static void |
209 |
|
io_loop(void) |
210 |
|
{ |
211 |
< |
while (1 == 1) |
211 |
> |
while (1) |
212 |
|
{ |
202 |
– |
/* |
203 |
– |
* Maybe we want a flags word? |
204 |
– |
* ie. if (REHASHED_KLINES(global_flags)) |
205 |
– |
* SET_REHASHED_KLINES(global_flags) |
206 |
– |
* CLEAR_REHASHED_KLINES(global_flags) |
207 |
– |
* |
208 |
– |
* - Dianora |
209 |
– |
*/ |
210 |
– |
if (rehashed_klines) |
211 |
– |
{ |
212 |
– |
check_conf_klines(); |
213 |
– |
rehashed_klines = 0; |
214 |
– |
} |
215 |
– |
|
213 |
|
if (listing_client_list.head) |
214 |
|
{ |
215 |
< |
dlink_node *ptr = NULL, *ptr_next = NULL; |
216 |
< |
DLINK_FOREACH_SAFE(ptr, ptr_next, listing_client_list.head) |
217 |
< |
{ |
221 |
< |
struct Client *client_p = ptr->data; |
222 |
< |
assert(client_p->localClient->list_task); |
223 |
< |
safe_list_channels(client_p, client_p->localClient->list_task, 0); |
224 |
< |
} |
215 |
> |
dlink_node *node = NULL, *node_next = NULL; |
216 |
> |
DLINK_FOREACH_SAFE(node, node_next, listing_client_list.head) |
217 |
> |
safe_list_channels(node->data, 0); |
218 |
|
} |
219 |
|
|
220 |
< |
/* Run pending events, then get the number of seconds to the next |
221 |
< |
* event |
229 |
< |
*/ |
230 |
< |
while (eventNextTime() <= CurrentTime) |
231 |
< |
eventRun(); |
220 |
> |
/* Run pending events */ |
221 |
> |
event_run(); |
222 |
|
|
223 |
|
comm_select(); |
224 |
|
exit_aborted_clients(); |
225 |
|
free_exited_clients(); |
236 |
– |
send_queued_all(); |
226 |
|
|
227 |
|
/* Check to see whether we have to rehash the configuration .. */ |
228 |
|
if (dorehash) |
229 |
|
{ |
230 |
< |
rehash(1); |
230 |
> |
conf_rehash(1); |
231 |
|
dorehash = 0; |
232 |
|
} |
233 |
+ |
|
234 |
|
if (doremotd) |
235 |
|
{ |
236 |
< |
read_message_file(&ConfigFileEntry.motd); |
237 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, |
238 |
< |
"Got signal SIGUSR1, reloading ircd motd file"); |
236 |
> |
motd_recache(); |
237 |
> |
sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE, |
238 |
> |
"Got signal SIGUSR1, reloading motd file(s)"); |
239 |
|
doremotd = 0; |
240 |
|
} |
241 |
|
} |
245 |
|
* |
246 |
|
* inputs - none |
247 |
|
* output - none |
248 |
< |
* side effects - This sets all global set options needed |
248 |
> |
* side effects - This sets all global set options needed |
249 |
|
*/ |
250 |
|
static void |
251 |
|
initialize_global_set_options(void) |
252 |
|
{ |
253 |
< |
memset(&GlobalSetOptions, 0, sizeof(GlobalSetOptions)); |
254 |
< |
|
265 |
< |
GlobalSetOptions.autoconn = 1; |
253 |
> |
GlobalSetOptions.maxclients = ConfigServerInfo.default_max_clients; |
254 |
> |
GlobalSetOptions.autoconn = 1; |
255 |
|
GlobalSetOptions.spam_time = MIN_JOIN_LEAVE_TIME; |
256 |
< |
GlobalSetOptions.spam_num = MAX_JOIN_LEAVE_COUNT; |
257 |
< |
|
258 |
< |
if (ConfigFileEntry.default_floodcount) |
259 |
< |
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; |
256 |
> |
GlobalSetOptions.spam_num = MAX_JOIN_LEAVE_COUNT; |
257 |
> |
GlobalSetOptions.floodcount = ConfigGeneral.default_floodcount; |
258 |
> |
GlobalSetOptions.joinfloodcount = ConfigChannel.default_join_flood_count; |
259 |
> |
GlobalSetOptions.joinfloodtime = ConfigChannel.default_join_flood_time; |
260 |
|
|
261 |
|
split_servers = ConfigChannel.default_split_server_count; |
262 |
|
split_users = ConfigChannel.default_split_user_count; |
269 |
|
} |
270 |
|
|
271 |
|
GlobalSetOptions.ident_timeout = IDENT_TIMEOUT; |
289 |
– |
/* End of global set options */ |
290 |
– |
} |
291 |
– |
|
292 |
– |
/* initialize_message_files() |
293 |
– |
* |
294 |
– |
* inputs - none |
295 |
– |
* output - none |
296 |
– |
* side effects - Set up all message files needed, motd etc. |
297 |
– |
*/ |
298 |
– |
static void |
299 |
– |
initialize_message_files(void) |
300 |
– |
{ |
301 |
– |
init_message_file(USER_MOTD, MPATH, &ConfigFileEntry.motd); |
302 |
– |
init_message_file(OPER_MOTD, OPATH, &ConfigFileEntry.opermotd); |
303 |
– |
init_message_file(USER_LINKS, LIPATH, &ConfigFileEntry.linksfile); |
304 |
– |
|
305 |
– |
read_message_file(&ConfigFileEntry.motd); |
306 |
– |
read_message_file(&ConfigFileEntry.opermotd); |
307 |
– |
read_message_file(&ConfigFileEntry.linksfile); |
308 |
– |
|
309 |
– |
init_isupport(); |
272 |
|
} |
273 |
|
|
274 |
|
/* initialize_server_capabs() |
279 |
|
static void |
280 |
|
initialize_server_capabs(void) |
281 |
|
{ |
282 |
< |
add_capability("QS", CAP_QS, 1); |
283 |
< |
add_capability("EOB", CAP_EOB, 1); |
284 |
< |
add_capability("TS6", CAP_TS6, 0); |
285 |
< |
add_capability("CLUSTER", CAP_CLUSTER, 1); |
286 |
< |
add_capability("SVS", CAP_SVS, 1); |
287 |
< |
#ifdef HALFOPS |
326 |
< |
add_capability("HOPS", CAP_HOPS, 1); |
327 |
< |
#endif |
282 |
> |
add_capability("QS", CAPAB_QS); |
283 |
> |
add_capability("EOB", CAPAB_EOB); |
284 |
> |
add_capability("CLUSTER", CAPAB_CLUSTER); |
285 |
> |
add_capability("SVS", CAPAB_SVS); |
286 |
> |
add_capability("CHW", CAPAB_CHW); |
287 |
> |
add_capability("HOPS", CAPAB_HOPS); |
288 |
|
} |
289 |
|
|
290 |
|
/* write_pidfile() |
296 |
|
static void |
297 |
|
write_pidfile(const char *filename) |
298 |
|
{ |
299 |
< |
FBFILE *fb; |
299 |
> |
FILE *fb; |
300 |
|
|
301 |
< |
if ((fb = fbopen(filename, "w"))) |
301 |
> |
if ((fb = fopen(filename, "w"))) |
302 |
|
{ |
303 |
< |
char buff[32]; |
303 |
> |
char buff[IRCD_BUFSIZE]; |
304 |
|
unsigned int pid = (unsigned int)getpid(); |
345 |
– |
size_t nbytes = snprintf(buff, sizeof(buff), "%u\n", pid); |
305 |
|
|
306 |
< |
if ((fbputs(buff, fb, nbytes) == -1)) |
307 |
< |
ilog(LOG_TYPE_IRCD, "Error writing %u to pid file %s (%s)", |
308 |
< |
pid, filename, strerror(errno)); |
306 |
> |
snprintf(buff, sizeof(buff), "%u\n", pid); |
307 |
> |
|
308 |
> |
if (fputs(buff, fb) == -1) |
309 |
> |
ilog(LOG_TYPE_IRCD, "Error writing to pid file %s: %s", |
310 |
> |
filename, strerror(errno)); |
311 |
|
|
312 |
< |
fbclose(fb); |
352 |
< |
return; |
312 |
> |
fclose(fb); |
313 |
|
} |
314 |
|
else |
315 |
< |
{ |
316 |
< |
ilog(LOG_TYPE_IRCD, "Error opening pid file %s", filename); |
357 |
< |
} |
315 |
> |
ilog(LOG_TYPE_IRCD, "Error opening pid file %s: %s", |
316 |
> |
filename, strerror(errno)); |
317 |
|
} |
318 |
|
|
319 |
|
/* check_pidfile() |
327 |
|
static void |
328 |
|
check_pidfile(const char *filename) |
329 |
|
{ |
330 |
< |
FBFILE *fb; |
331 |
< |
char buff[32]; |
330 |
> |
FILE *fb; |
331 |
> |
char buff[IRCD_BUFSIZE]; |
332 |
|
pid_t pidfromfile; |
333 |
|
|
334 |
< |
/* Don't do logging here, since we don't have log() initialised */ |
376 |
< |
if ((fb = fbopen(filename, "r"))) |
334 |
> |
if ((fb = fopen(filename, "r"))) |
335 |
|
{ |
336 |
< |
if (fbgets(buff, 20, fb) == NULL) |
337 |
< |
{ |
338 |
< |
/* log(L_ERROR, "Error reading from pid file %s (%s)", filename, |
381 |
< |
* strerror(errno)); |
382 |
< |
*/ |
383 |
< |
} |
336 |
> |
if (!fgets(buff, 20, fb)) |
337 |
> |
ilog(LOG_TYPE_IRCD, "Error reading from pid file %s: %s", |
338 |
> |
filename, strerror(errno)); |
339 |
|
else |
340 |
|
{ |
341 |
|
pidfromfile = atoi(buff); |
348 |
|
} |
349 |
|
} |
350 |
|
|
351 |
< |
fbclose(fb); |
351 |
> |
fclose(fb); |
352 |
|
} |
353 |
|
else if (errno != ENOENT) |
354 |
< |
{ |
355 |
< |
/* log(L_ERROR, "Error opening pid file %s", filename); */ |
401 |
< |
} |
354 |
> |
ilog(LOG_TYPE_IRCD, "Error opening pid file %s: %s", |
355 |
> |
filename, strerror(errno)); |
356 |
|
} |
357 |
|
|
358 |
|
/* setup_corefile() |
377 |
|
#endif |
378 |
|
} |
379 |
|
|
380 |
+ |
#ifdef HAVE_LIBCRYPTO |
381 |
+ |
static int |
382 |
+ |
always_accept_verify_cb(int preverify_ok, X509_STORE_CTX *x509_ctx) |
383 |
+ |
{ |
384 |
+ |
return 1; |
385 |
+ |
} |
386 |
+ |
#endif |
387 |
+ |
|
388 |
|
/* init_ssl() |
389 |
|
* |
390 |
|
* inputs - nothing |
392 |
|
* side effects - setups SSL context. |
393 |
|
*/ |
394 |
|
static void |
395 |
< |
init_ssl(void) |
395 |
> |
ssl_init(void) |
396 |
|
{ |
397 |
|
#ifdef HAVE_LIBCRYPTO |
398 |
|
SSL_load_error_strings(); |
399 |
|
SSLeay_add_ssl_algorithms(); |
400 |
|
|
401 |
< |
if ((ServerInfo.server_ctx = SSL_CTX_new(SSLv23_server_method())) == NULL) |
401 |
> |
if (!(ConfigServerInfo.server_ctx = SSL_CTX_new(SSLv23_server_method()))) |
402 |
|
{ |
403 |
< |
const char *s; |
403 |
> |
const char *s = ERR_lib_error_string(ERR_get_error()); |
404 |
|
|
405 |
< |
fprintf(stderr, "ERROR: Could not initialize the SSL Server context -- %s\n", |
406 |
< |
s = ERR_lib_error_string(ERR_get_error())); |
407 |
< |
ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Server context -- %s\n", s); |
405 |
> |
fprintf(stderr, "ERROR: Could not initialize the SSL Server context -- %s\n", s); |
406 |
> |
ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Server context -- %s", s); |
407 |
> |
exit(EXIT_FAILURE); |
408 |
> |
return; /* Not reached */ |
409 |
|
} |
410 |
|
|
411 |
< |
SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_NO_SSLv2); |
412 |
< |
SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_TLS_ROLLBACK_BUG|SSL_OP_ALL); |
413 |
< |
SSL_CTX_set_verify(ServerInfo.server_ctx, SSL_VERIFY_NONE, NULL); |
411 |
> |
SSL_CTX_set_options(ConfigServerInfo.server_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TICKET); |
412 |
> |
SSL_CTX_set_options(ConfigServerInfo.server_ctx, SSL_OP_SINGLE_DH_USE|SSL_OP_CIPHER_SERVER_PREFERENCE); |
413 |
> |
SSL_CTX_set_verify(ConfigServerInfo.server_ctx, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE, |
414 |
> |
always_accept_verify_cb); |
415 |
> |
SSL_CTX_set_session_cache_mode(ConfigServerInfo.server_ctx, SSL_SESS_CACHE_OFF); |
416 |
> |
SSL_CTX_set_cipher_list(ConfigServerInfo.server_ctx, "EECDH+HIGH:EDH+HIGH:HIGH:!aNULL"); |
417 |
|
|
418 |
< |
if ((ServerInfo.client_ctx = SSL_CTX_new(SSLv23_client_method())) == NULL) |
418 |
> |
#if OPENSSL_VERSION_NUMBER >= 0x009080FFL && !defined(OPENSSL_NO_ECDH) |
419 |
|
{ |
420 |
< |
const char *s; |
420 |
> |
EC_KEY *key = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1); |
421 |
|
|
422 |
< |
fprintf(stderr, "ERROR: Could not initialize the SSL Client context -- %s\n", |
423 |
< |
s = ERR_lib_error_string(ERR_get_error())); |
424 |
< |
ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Client context -- %s\n", s); |
422 |
> |
if (key) |
423 |
> |
{ |
424 |
> |
SSL_CTX_set_tmp_ecdh(ConfigServerInfo.server_ctx, key); |
425 |
> |
EC_KEY_free(key); |
426 |
> |
} |
427 |
|
} |
428 |
|
|
429 |
< |
SSL_CTX_set_options(ServerInfo.client_ctx, SSL_OP_NO_SSLv2); |
430 |
< |
SSL_CTX_set_options(ServerInfo.client_ctx, SSL_OP_TLS_ROLLBACK_BUG|SSL_OP_ALL); |
463 |
< |
SSL_CTX_set_verify(ServerInfo.client_ctx, SSL_VERIFY_NONE, NULL); |
464 |
< |
#endif /* HAVE_LIBCRYPTO */ |
465 |
< |
} |
429 |
> |
SSL_CTX_set_options(ConfigServerInfo.server_ctx, SSL_OP_SINGLE_ECDH_USE); |
430 |
> |
#endif |
431 |
|
|
432 |
< |
/* init_callbacks() |
433 |
< |
* |
434 |
< |
* inputs - nothing |
435 |
< |
* output - nothing |
436 |
< |
* side effects - setups standard hook points |
437 |
< |
*/ |
438 |
< |
static void |
439 |
< |
init_callbacks(void) |
440 |
< |
{ |
441 |
< |
iorecv_cb = register_callback("iorecv", iorecv_default); |
442 |
< |
iosend_cb = register_callback("iosend", iosend_default); |
432 |
> |
if (!(ConfigServerInfo.client_ctx = SSL_CTX_new(SSLv23_client_method()))) |
433 |
> |
{ |
434 |
> |
const char *s = ERR_lib_error_string(ERR_get_error()); |
435 |
> |
|
436 |
> |
fprintf(stderr, "ERROR: Could not initialize the SSL Client context -- %s\n", s); |
437 |
> |
ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Client context -- %s", s); |
438 |
> |
exit(EXIT_FAILURE); |
439 |
> |
return; /* Not reached */ |
440 |
> |
} |
441 |
> |
|
442 |
> |
SSL_CTX_set_options(ConfigServerInfo.client_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TICKET); |
443 |
> |
SSL_CTX_set_options(ConfigServerInfo.client_ctx, SSL_OP_SINGLE_DH_USE); |
444 |
> |
SSL_CTX_set_verify(ConfigServerInfo.client_ctx, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE, |
445 |
> |
always_accept_verify_cb); |
446 |
> |
SSL_CTX_set_session_cache_mode(ConfigServerInfo.client_ctx, SSL_SESS_CACHE_OFF); |
447 |
> |
#endif /* HAVE_LIBCRYPTO */ |
448 |
|
} |
449 |
|
|
450 |
|
int |
451 |
|
main(int argc, char *argv[]) |
452 |
|
{ |
453 |
< |
/* Check to see if the user is running |
454 |
< |
* us as root, which is a nono |
485 |
< |
*/ |
486 |
< |
if (geteuid() == 0) |
453 |
> |
/* Check to see if the user is running us as root, which is a nono */ |
454 |
> |
if (!geteuid()) |
455 |
|
{ |
456 |
< |
fprintf(stderr, "Don't run ircd as root!!!\n"); |
456 |
> |
fprintf(stderr, "ERROR: This server won't run as root/superuser\n"); |
457 |
|
return -1; |
458 |
|
} |
459 |
|
|
460 |
|
/* Setup corefile size immediately after boot -kre */ |
461 |
|
setup_corefile(); |
462 |
|
|
463 |
< |
/* save server boot time right away, so getrusage works correctly */ |
463 |
> |
/* Save server boot time right away, so getrusage works correctly */ |
464 |
|
set_time(); |
465 |
|
|
466 |
< |
/* It ain't random, but it ought to be a little harder to guess */ |
466 |
> |
/* It's not random, but it ought to be a little harder to guess */ |
467 |
|
init_genrand(SystemTime.tv_sec ^ (SystemTime.tv_usec | (getpid() << 20))); |
468 |
|
|
469 |
< |
me.localClient = &meLocalUser; |
470 |
< |
dlinkAdd(&me, &me.node, &global_client_list); /* Pointer to beginning |
471 |
< |
of Client list */ |
472 |
< |
/* Initialise the channel capability usage counts... */ |
473 |
< |
init_chcap_usage_counts(); |
474 |
< |
|
475 |
< |
ConfigFileEntry.dpath = DPATH; |
476 |
< |
ConfigFileEntry.configfile = CPATH; /* Server configuration file */ |
477 |
< |
ConfigFileEntry.klinefile = KPATH; /* Server kline file */ |
478 |
< |
ConfigFileEntry.xlinefile = XPATH; /* Server xline file */ |
479 |
< |
ConfigFileEntry.rxlinefile = RXPATH; /* Server regex xline file */ |
512 |
< |
ConfigFileEntry.rklinefile = RKPATH; /* Server regex kline file */ |
513 |
< |
ConfigFileEntry.dlinefile = DLPATH; /* dline file */ |
514 |
< |
ConfigFileEntry.glinefile = GPATH; /* gline log file */ |
515 |
< |
ConfigFileEntry.cresvfile = CRESVPATH; /* channel resv file */ |
516 |
< |
ConfigFileEntry.nresvfile = NRESVPATH; /* nick resv file */ |
469 |
> |
dlinkAdd(&me, &me.node, &global_client_list); |
470 |
> |
|
471 |
> |
ConfigGeneral.dpath = DPATH; |
472 |
> |
ConfigGeneral.spath = SPATH; |
473 |
> |
ConfigGeneral.mpath = MPATH; |
474 |
> |
ConfigGeneral.configfile = CPATH; /* Server configuration file */ |
475 |
> |
ConfigGeneral.klinefile = KPATH; /* Server kline file */ |
476 |
> |
ConfigGeneral.xlinefile = XPATH; /* Server xline file */ |
477 |
> |
ConfigGeneral.dlinefile = DLPATH; /* dline file */ |
478 |
> |
ConfigGeneral.resvfile = RESVPATH; /* resv file */ |
479 |
> |
|
480 |
|
myargv = argv; |
481 |
< |
umask(077); /* better safe than sorry --SRB */ |
481 |
> |
umask(077); /* umask 077: u=rwx,g=,o= */ |
482 |
|
|
483 |
|
parseargs(&argc, &argv, myopts); |
484 |
|
|
485 |
|
if (printVersion) |
486 |
|
{ |
487 |
< |
printf("ircd: version %s\n", ircd_version); |
487 |
> |
printf("ircd: version %s(%s)\n", ircd_version, serno); |
488 |
|
exit(EXIT_SUCCESS); |
489 |
|
} |
490 |
|
|
491 |
< |
if (chdir(ConfigFileEntry.dpath)) |
491 |
> |
if (chdir(ConfigGeneral.dpath)) |
492 |
|
{ |
493 |
|
perror("chdir"); |
494 |
|
exit(EXIT_FAILURE); |
495 |
|
} |
496 |
|
|
497 |
< |
init_ssl(); |
497 |
> |
ssl_init(); |
498 |
|
|
499 |
|
if (!server_state.foreground) |
500 |
|
{ |
506 |
|
|
507 |
|
setup_signals(); |
508 |
|
|
546 |
– |
get_ircd_platform(ircd_platform); |
547 |
– |
|
548 |
– |
/* Init the event subsystem */ |
549 |
– |
eventInit(); |
509 |
|
/* We need this to initialise the fd array before anything else */ |
510 |
|
fdlist_init(); |
511 |
< |
log_add_file(LOG_TYPE_IRCD, 0, logFileName); |
512 |
< |
check_can_use_v6(); |
513 |
< |
init_comm(); /* This needs to be setup early ! -- adrian */ |
511 |
> |
log_set_file(LOG_TYPE_IRCD, 0, logFileName); |
512 |
> |
|
513 |
> |
init_netio(); /* This needs to be setup early ! -- adrian */ |
514 |
> |
|
515 |
|
/* Check if there is pidfile and daemon already running */ |
516 |
|
check_pidfile(pidFileName); |
517 |
|
|
518 |
< |
initBlockHeap(); |
518 |
> |
mp_pool_init(); |
519 |
|
init_dlink_nodes(); |
520 |
< |
init_callbacks(); |
561 |
< |
initialize_message_files(); |
520 |
> |
isupport_init(); |
521 |
|
dbuf_init(); |
522 |
< |
init_hash(); |
523 |
< |
init_ip_hash_table(); /* client host ip hash table */ |
524 |
< |
init_host_hash(); /* Host-hashtable. */ |
525 |
< |
clear_tree_parse(); |
526 |
< |
init_client(); |
568 |
< |
init_class(); |
569 |
< |
init_whowas(); |
522 |
> |
hash_init(); |
523 |
> |
ipcache_init(); |
524 |
> |
client_init(); |
525 |
> |
class_init(); |
526 |
> |
whowas_init(); |
527 |
|
watch_init(); |
528 |
< |
init_auth(); /* Initialise the auth code */ |
528 |
> |
auth_init(); /* Initialise the auth code */ |
529 |
|
init_resolver(); /* Needs to be setup before the io loop */ |
530 |
+ |
modules_init(); |
531 |
|
read_conf_files(1); /* cold start init conf files */ |
574 |
– |
init_uid(); |
532 |
|
initialize_server_capabs(); /* Set up default_server_capabs */ |
533 |
< |
initialize_global_set_options(); |
534 |
< |
init_channels(); |
535 |
< |
|
536 |
< |
if (EmptyString(ServerInfo.sid)) |
537 |
< |
{ |
538 |
< |
ilog(LOG_TYPE_IRCD, "ERROR: No server id specified in serverinfo block."); |
539 |
< |
exit(EXIT_FAILURE); |
540 |
< |
} |
584 |
< |
|
585 |
< |
strlcpy(me.id, ServerInfo.sid, sizeof(me.id)); |
533 |
> |
initialize_global_set_options(); /* Has to be called after read_conf_files() */ |
534 |
> |
channel_init(); |
535 |
> |
read_links_file(); |
536 |
> |
motd_init(); |
537 |
> |
user_modes_init(); |
538 |
> |
#ifdef HAVE_LIBGEOIP |
539 |
> |
geoip_ctx = GeoIP_new(GEOIP_MEMORY_CACHE); |
540 |
> |
#endif |
541 |
|
|
542 |
< |
if (EmptyString(ServerInfo.name)) |
542 |
> |
if (EmptyString(ConfigServerInfo.name)) |
543 |
|
{ |
544 |
|
ilog(LOG_TYPE_IRCD, "ERROR: No server name specified in serverinfo block."); |
545 |
|
exit(EXIT_FAILURE); |
546 |
|
} |
547 |
|
|
548 |
< |
strlcpy(me.name, ServerInfo.name, sizeof(me.name)); |
548 |
> |
strlcpy(me.name, ConfigServerInfo.name, sizeof(me.name)); |
549 |
|
|
550 |
|
/* serverinfo{} description must exist. If not, error out.*/ |
551 |
< |
if (EmptyString(ServerInfo.description)) |
551 |
> |
if (EmptyString(ConfigServerInfo.description)) |
552 |
|
{ |
553 |
|
ilog(LOG_TYPE_IRCD, "ERROR: No server description specified in serverinfo block."); |
554 |
|
exit(EXIT_FAILURE); |
555 |
|
} |
556 |
|
|
557 |
< |
strlcpy(me.info, ServerInfo.description, sizeof(me.info)); |
557 |
> |
strlcpy(me.info, ConfigServerInfo.description, sizeof(me.info)); |
558 |
> |
|
559 |
> |
if (EmptyString(ConfigServerInfo.sid)) |
560 |
> |
{ |
561 |
> |
ilog(LOG_TYPE_IRCD, "Generating server ID"); |
562 |
> |
generate_sid(); |
563 |
> |
} |
564 |
> |
else |
565 |
> |
{ |
566 |
> |
strlcpy(me.id, ConfigServerInfo.sid, sizeof(me.id)); |
567 |
> |
} |
568 |
|
|
569 |
< |
me.from = &me; |
570 |
< |
me.servptr = &me; |
571 |
< |
me.localClient->lasttime = CurrentTime; |
572 |
< |
me.localClient->since = CurrentTime; |
573 |
< |
me.localClient->firsttime = CurrentTime; |
569 |
> |
me.from = &me; |
570 |
> |
me.servptr = &me; |
571 |
> |
me.connection->lasttime = CurrentTime; |
572 |
> |
me.connection->since = CurrentTime; |
573 |
> |
me.connection->firsttime = CurrentTime; |
574 |
|
|
575 |
|
SetMe(&me); |
576 |
|
make_server(&me); |
577 |
|
|
578 |
|
hash_add_id(&me); |
579 |
|
hash_add_client(&me); |
615 |
– |
|
616 |
– |
/* add ourselves to global_serv_list */ |
617 |
– |
dlinkAdd(&me, make_dlink_node(), &global_serv_list); |
580 |
|
|
581 |
< |
if (chdir(MODPATH)) |
582 |
< |
{ |
583 |
< |
ilog(LOG_TYPE_IRCD, "Could not load core modules. Terminating!"); |
584 |
< |
exit(EXIT_FAILURE); |
585 |
< |
} |
581 |
> |
dlinkAdd(&me, make_dlink_node(), &global_server_list); |
582 |
> |
|
583 |
> |
init_uid(); |
584 |
> |
|
585 |
> |
load_kline_database(); |
586 |
> |
load_dline_database(); |
587 |
> |
load_xline_database(); |
588 |
> |
load_resv_database(); |
589 |
|
|
590 |
|
load_all_modules(1); |
591 |
|
load_conf_modules(); |
592 |
|
load_core_modules(1); |
593 |
|
|
629 |
– |
/* Go back to DPATH after checking to see if we can chdir to MODPATH */ |
630 |
– |
if (chdir(ConfigFileEntry.dpath)) |
631 |
– |
{ |
632 |
– |
perror("chdir"); |
633 |
– |
exit(EXIT_FAILURE); |
634 |
– |
} |
635 |
– |
|
636 |
– |
/* |
637 |
– |
* assemble_umode_buffer() has to be called after |
638 |
– |
* reading conf/loading modules. |
639 |
– |
*/ |
640 |
– |
assemble_umode_buffer(); |
641 |
– |
|
594 |
|
write_pidfile(pidFileName); |
595 |
|
|
596 |
|
ilog(LOG_TYPE_IRCD, "Server Ready"); |
597 |
|
|
598 |
< |
eventAddIsh("cleanup_glines", cleanup_glines, NULL, CLEANUP_GLINES_TIME); |
647 |
< |
eventAddIsh("cleanup_tklines", cleanup_tklines, NULL, CLEANUP_TKLINES_TIME); |
598 |
> |
event_addish(&event_cleanup_tklines, NULL); |
599 |
|
|
600 |
|
/* We want try_connections to be called as soon as possible now! -- adrian */ |
601 |
|
/* No, 'cause after a restart it would cause all sorts of nick collides */ |
602 |
< |
eventAddIsh("try_connections", try_connections, NULL, STARTUP_CONNECTIONS_TIME); |
602 |
> |
event_addish(&event_try_connections, NULL); |
603 |
|
|
604 |
|
/* Setup the timeout check. I'll shift it later :) -- adrian */ |
605 |
< |
eventAddIsh("comm_checktimeouts", comm_checktimeouts, NULL, 1); |
605 |
> |
event_add(&event_comm_checktimeouts, NULL); |
606 |
> |
|
607 |
> |
event_addish(&event_save_all_databases, NULL); |
608 |
|
|
609 |
|
if (ConfigServerHide.links_delay > 0) |
610 |
< |
eventAddIsh("write_links_file", write_links_file, NULL, ConfigServerHide.links_delay); |
610 |
> |
{ |
611 |
> |
event_write_links_file.when = ConfigServerHide.links_delay; |
612 |
> |
event_addish(&event_write_links_file, NULL); |
613 |
> |
} |
614 |
|
else |
615 |
|
ConfigServerHide.links_disabled = 1; |
616 |
|
|
617 |
|
if (splitmode) |
618 |
< |
eventAddIsh("check_splitmode", check_splitmode, NULL, 60); |
618 |
> |
event_addish(&splitmode_event, NULL); |
619 |
|
|
620 |
|
io_loop(); |
621 |
|
return 0; |