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