1 |
|
/* |
2 |
|
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
3 |
|
* |
4 |
< |
* Copyright (c) 1997-2014 ircd-hybrid development team |
4 |
> |
* Copyright (c) 1997-2016 ircd-hybrid development team |
5 |
|
* |
6 |
|
* This program is free software; you can redistribute it and/or modify |
7 |
|
* it under the terms of the GNU General Public License as published by |
15 |
|
* |
16 |
|
* You should have received a copy of the GNU General Public License |
17 |
|
* along with this program; if not, write to the Free Software |
18 |
< |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
18 |
> |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 |
19 |
|
* USA |
20 |
|
*/ |
21 |
|
|
33 |
|
#include "event.h" |
34 |
|
#include "fdlist.h" |
35 |
|
#include "hash.h" |
36 |
+ |
#include "id.h" |
37 |
|
#include "irc_string.h" |
38 |
|
#include "ircd_signal.h" |
38 |
– |
#include "gline.h" |
39 |
|
#include "motd.h" |
40 |
|
#include "conf.h" |
41 |
|
#include "hostmask.h" |
46 |
|
#include "auth.h" |
47 |
|
#include "s_bsd.h" |
48 |
|
#include "log.h" |
49 |
< |
#include "server.h" /* try_connections */ |
49 |
> |
#include "server.h" |
50 |
|
#include "send.h" |
51 |
|
#include "whowas.h" |
52 |
|
#include "modules.h" |
53 |
|
#include "memory.h" |
54 |
|
#include "mempool.h" |
55 |
|
#include "ircd_getopt.h" |
56 |
– |
#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 |
|
|
63 |
|
|
64 |
|
#ifdef HAVE_LIBGEOIP |
65 |
< |
GeoIP *geoip_ctx; |
65 |
> |
GeoIP *GeoIPv4_ctx; |
66 |
> |
GeoIP *GeoIPv6_ctx; |
67 |
|
#endif |
68 |
|
|
69 |
< |
/* /quote set variables */ |
67 |
< |
struct SetOptions GlobalSetOptions; |
69 |
> |
struct SetOptions GlobalSetOptions; /* /quote set variables */ |
70 |
|
struct Counter Count; |
71 |
|
struct ServerState_t server_state; |
72 |
|
struct ServerStatistics ServerStats; |
73 |
< |
struct timeval SystemTime; |
74 |
< |
struct Client me; /* That's me */ |
75 |
< |
struct LocalUser meLocalUser; /* That's also part of me */ |
73 |
> |
struct ServerTime SystemTime; |
74 |
> |
struct Connection meConnection; /* That's also part of me */ |
75 |
> |
struct Client me = { .connection = &meConnection }; /* That's me */ |
76 |
|
|
77 |
+ |
char **myargv; |
78 |
|
const char *logFileName = LPATH; |
79 |
|
const char *pidFileName = PPATH; |
80 |
|
|
81 |
< |
char **myargv; |
81 |
> |
unsigned int dorehash; |
82 |
> |
unsigned int doremotd; |
83 |
|
|
84 |
< |
int dorehash = 0; |
81 |
< |
int doremotd = 0; |
84 |
> |
static int printVersion; |
85 |
|
|
86 |
< |
/* Set to zero because it should be initialized later using |
84 |
< |
* initialize_server_capabs |
85 |
< |
*/ |
86 |
< |
unsigned int default_server_capabs; |
87 |
< |
unsigned int splitmode; |
88 |
< |
unsigned int splitchecking; |
89 |
< |
unsigned int split_users; |
90 |
< |
unsigned int split_servers; |
91 |
< |
|
92 |
< |
/* |
93 |
< |
* print_startup - print startup information |
94 |
< |
*/ |
95 |
< |
static void |
96 |
< |
print_startup(int pid) |
86 |
> |
static struct lgetopt myopts[] = |
87 |
|
{ |
88 |
< |
printf("ircd: version %s(%s)\n", ircd_version, serno); |
89 |
< |
printf("ircd: pid %d\n", pid); |
90 |
< |
printf("ircd: running in %s mode from %s\n", !server_state.foreground ? "background" |
91 |
< |
: "foreground", ConfigFileEntry.dpath); |
92 |
< |
} |
88 |
> |
{ "configfile", &ConfigGeneral.configfile, |
89 |
> |
STRING, "File to use for ircd.conf" }, |
90 |
> |
{ "klinefile", &ConfigGeneral.klinefile, |
91 |
> |
STRING, "File to use for kline database" }, |
92 |
> |
{ "dlinefile", &ConfigGeneral.dlinefile, |
93 |
> |
STRING, "File to use for dline database" }, |
94 |
> |
{ "xlinefile", &ConfigGeneral.xlinefile, |
95 |
> |
STRING, "File to use for xline database" }, |
96 |
> |
{ "resvfile", &ConfigGeneral.resvfile, |
97 |
> |
STRING, "File to use for resv database" }, |
98 |
> |
{ "logfile", &logFileName, |
99 |
> |
STRING, "File to use for ircd.log" }, |
100 |
> |
{ "pidfile", &pidFileName, |
101 |
> |
STRING, "File to use for process ID" }, |
102 |
> |
{ "foreground", &server_state.foreground, |
103 |
> |
YESNO, "Run in foreground (don't detach)" }, |
104 |
> |
{ "version", &printVersion, |
105 |
> |
YESNO, "Print version and exit" }, |
106 |
> |
{ "help", NULL, USAGE, "Print this text" }, |
107 |
> |
{ NULL, NULL, STRING, NULL }, |
108 |
> |
}; |
109 |
|
|
110 |
< |
static void |
105 |
< |
make_daemon(void) |
110 |
> |
static struct event event_cleanup_tklines = |
111 |
|
{ |
112 |
< |
int pid; |
112 |
> |
.name = "cleanup_tklines", |
113 |
> |
.handler = cleanup_tklines, |
114 |
> |
.when = CLEANUP_TKLINES_TIME |
115 |
> |
}; |
116 |
|
|
117 |
< |
if ((pid = fork()) < 0) |
118 |
< |
{ |
119 |
< |
perror("fork"); |
120 |
< |
exit(EXIT_FAILURE); |
121 |
< |
} |
122 |
< |
else if (pid > 0) |
115 |
< |
{ |
116 |
< |
print_startup(pid); |
117 |
< |
exit(EXIT_SUCCESS); |
118 |
< |
} |
117 |
> |
static struct event event_try_connections = |
118 |
> |
{ |
119 |
> |
.name = "try_connections", |
120 |
> |
.handler = try_connections, |
121 |
> |
.when = STARTUP_CONNECTIONS_TIME |
122 |
> |
}; |
123 |
|
|
124 |
< |
setsid(); |
125 |
< |
} |
124 |
> |
static struct event event_comm_checktimeouts = |
125 |
> |
{ |
126 |
> |
.name = "comm_checktimeouts", |
127 |
> |
.handler = comm_checktimeouts, |
128 |
> |
.when = 1 |
129 |
> |
}; |
130 |
|
|
131 |
< |
static int printVersion = 0; |
131 |
> |
static struct event event_save_all_databases = |
132 |
> |
{ |
133 |
> |
.name = "save_all_databases", |
134 |
> |
.handler = save_all_databases, |
135 |
> |
.when = DATABASE_UPDATE_TIMEOUT |
136 |
> |
}; |
137 |
|
|
138 |
< |
static struct lgetopt myopts[] = |
138 |
> |
struct event event_write_links_file = |
139 |
|
{ |
140 |
< |
{"configfile", &ConfigFileEntry.configfile, |
141 |
< |
STRING, "File to use for ircd.conf"}, |
129 |
< |
{"glinefile", &ConfigFileEntry.glinefile, |
130 |
< |
STRING, "File to use for gline database"}, |
131 |
< |
{"klinefile", &ConfigFileEntry.klinefile, |
132 |
< |
STRING, "File to use for kline database"}, |
133 |
< |
{"dlinefile", &ConfigFileEntry.dlinefile, |
134 |
< |
STRING, "File to use for dline database"}, |
135 |
< |
{"xlinefile", &ConfigFileEntry.xlinefile, |
136 |
< |
STRING, "File to use for xline database"}, |
137 |
< |
{"resvfile", &ConfigFileEntry.resvfile, |
138 |
< |
STRING, "File to use for resv database"}, |
139 |
< |
{"logfile", &logFileName, |
140 |
< |
STRING, "File to use for ircd.log"}, |
141 |
< |
{"pidfile", &pidFileName, |
142 |
< |
STRING, "File to use for process ID"}, |
143 |
< |
{"foreground", &server_state.foreground, |
144 |
< |
YESNO, "Run in foreground (don't detach)"}, |
145 |
< |
{"version", &printVersion, |
146 |
< |
YESNO, "Print version and exit"}, |
147 |
< |
{"help", NULL, USAGE, "Print this text"}, |
148 |
< |
{NULL, NULL, STRING, NULL}, |
140 |
> |
.name = "write_links_file", |
141 |
> |
.handler = write_links_file, |
142 |
|
}; |
143 |
|
|
144 |
+ |
|
145 |
|
void |
146 |
|
set_time(void) |
147 |
|
{ |
149 |
|
|
150 |
|
if (gettimeofday(&newtime, NULL) == -1) |
151 |
|
{ |
152 |
< |
ilog(LOG_TYPE_IRCD, "Clock Failure (%s), TS can be corrupted", |
153 |
< |
strerror(errno)); |
154 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
155 |
< |
"Clock Failure (%s), TS can be corrupted", |
156 |
< |
strerror(errno)); |
163 |
< |
server_die("Clock Failure", 1); |
152 |
> |
char buf[IRCD_BUFSIZE]; |
153 |
> |
|
154 |
> |
snprintf(buf, sizeof(buf), "Clock failure, TS can be corrupted: %s", |
155 |
> |
strerror(errno)); |
156 |
> |
server_die(buf, SERVER_SHUTDOWN); |
157 |
|
} |
158 |
|
|
159 |
< |
if (newtime.tv_sec < CurrentTime) |
159 |
> |
if ((uintmax_t)newtime.tv_sec < CurrentTime) |
160 |
|
{ |
161 |
< |
ilog(LOG_TYPE_IRCD, "System clock is running backwards - (%lu < %lu)", |
162 |
< |
(unsigned long)newtime.tv_sec, (unsigned long)CurrentTime); |
161 |
> |
ilog(LOG_TYPE_IRCD, "System clock is running backwards - (%ju < %ju)", |
162 |
> |
(uintmax_t)newtime.tv_sec, CurrentTime); |
163 |
|
sendto_realops_flags(UMODE_DEBUG, L_ALL, SEND_NOTICE, |
164 |
< |
"System clock is running backwards - (%lu < %lu)", |
165 |
< |
(unsigned long)newtime.tv_sec, |
166 |
< |
(unsigned long)CurrentTime); |
174 |
< |
set_back_events(CurrentTime - newtime.tv_sec); |
164 |
> |
"System clock is running backwards - (%ju < %ju)", |
165 |
> |
(uintmax_t)newtime.tv_sec, CurrentTime); |
166 |
> |
event_set_back_events(CurrentTime - (uintmax_t)newtime.tv_sec); |
167 |
|
} |
168 |
|
|
169 |
< |
SystemTime.tv_sec = newtime.tv_sec; |
169 |
> |
SystemTime.tv_sec = newtime.tv_sec; |
170 |
|
SystemTime.tv_usec = newtime.tv_usec; |
171 |
|
} |
172 |
|
|
177 |
|
{ |
178 |
|
if (listing_client_list.head) |
179 |
|
{ |
180 |
< |
dlink_node *ptr = NULL, *ptr_next = NULL; |
181 |
< |
DLINK_FOREACH_SAFE(ptr, ptr_next, listing_client_list.head) |
182 |
< |
safe_list_channels(ptr->data, 0); |
180 |
> |
dlink_node *node = NULL, *node_next = NULL; |
181 |
> |
DLINK_FOREACH_SAFE(node, node_next, listing_client_list.head) |
182 |
> |
safe_list_channels(node->data, 0); |
183 |
|
} |
184 |
|
|
185 |
< |
/* Run pending events, then get the number of seconds to the next |
186 |
< |
* event |
195 |
< |
*/ |
196 |
< |
while (eventNextTime() <= CurrentTime) |
197 |
< |
eventRun(); |
185 |
> |
/* Run pending events */ |
186 |
> |
event_run(); |
187 |
|
|
188 |
|
comm_select(); |
189 |
|
exit_aborted_clients(); |
190 |
|
free_exited_clients(); |
191 |
|
|
192 |
< |
/* Check to see whether we have to rehash the configuration .. */ |
192 |
> |
/* Check to see whether we have to rehash the configuration. */ |
193 |
|
if (dorehash) |
194 |
|
{ |
195 |
< |
rehash(1); |
195 |
> |
conf_rehash(1); |
196 |
|
dorehash = 0; |
197 |
|
} |
198 |
|
|
199 |
|
if (doremotd) |
200 |
|
{ |
201 |
|
motd_recache(); |
202 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
202 |
> |
sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE, |
203 |
|
"Got signal SIGUSR1, reloading motd file(s)"); |
204 |
|
doremotd = 0; |
205 |
|
} |
215 |
|
static void |
216 |
|
initialize_global_set_options(void) |
217 |
|
{ |
218 |
< |
memset(&GlobalSetOptions, 0, sizeof(GlobalSetOptions)); |
219 |
< |
|
231 |
< |
GlobalSetOptions.autoconn = 1; |
218 |
> |
GlobalSetOptions.maxclients = ConfigServerInfo.default_max_clients; |
219 |
> |
GlobalSetOptions.autoconn = 1; |
220 |
|
GlobalSetOptions.spam_time = MIN_JOIN_LEAVE_TIME; |
221 |
< |
GlobalSetOptions.spam_num = MAX_JOIN_LEAVE_COUNT; |
222 |
< |
|
223 |
< |
if (ConfigFileEntry.default_floodcount) |
224 |
< |
GlobalSetOptions.floodcount = ConfigFileEntry.default_floodcount; |
237 |
< |
else |
238 |
< |
GlobalSetOptions.floodcount = 10; |
239 |
< |
|
240 |
< |
/* XXX I have no idea what to try here - Dianora */ |
241 |
< |
GlobalSetOptions.joinfloodcount = 16; |
242 |
< |
GlobalSetOptions.joinfloodtime = 8; |
243 |
< |
|
244 |
< |
split_servers = ConfigChannel.default_split_server_count; |
245 |
< |
split_users = ConfigChannel.default_split_user_count; |
246 |
< |
|
247 |
< |
if (split_users && split_servers && (ConfigChannel.no_create_on_split || |
248 |
< |
ConfigChannel.no_join_on_split)) |
249 |
< |
{ |
250 |
< |
splitmode = 1; |
251 |
< |
splitchecking = 1; |
252 |
< |
} |
253 |
< |
|
221 |
> |
GlobalSetOptions.spam_num = MAX_JOIN_LEAVE_COUNT; |
222 |
> |
GlobalSetOptions.floodcount = ConfigGeneral.default_floodcount; |
223 |
> |
GlobalSetOptions.joinfloodcount = ConfigChannel.default_join_flood_count; |
224 |
> |
GlobalSetOptions.joinfloodtime = ConfigChannel.default_join_flood_time; |
225 |
|
GlobalSetOptions.ident_timeout = IDENT_TIMEOUT; |
255 |
– |
/* End of global set options */ |
256 |
– |
} |
257 |
– |
|
258 |
– |
/* initialize_server_capabs() |
259 |
– |
* |
260 |
– |
* inputs - none |
261 |
– |
* output - none |
262 |
– |
*/ |
263 |
– |
static void |
264 |
– |
initialize_server_capabs(void) |
265 |
– |
{ |
266 |
– |
add_capability("QS", CAP_QS, 1); |
267 |
– |
add_capability("EOB", CAP_EOB, 1); |
268 |
– |
add_capability("TS6", CAP_TS6, 0); |
269 |
– |
add_capability("CLUSTER", CAP_CLUSTER, 1); |
270 |
– |
add_capability("SVS", CAP_SVS, 1); |
271 |
– |
add_capability("CHW", CAP_CHW, 1); |
272 |
– |
add_capability("HOPS", CAP_HOPS, 1); |
226 |
|
} |
227 |
|
|
228 |
|
/* write_pidfile() |
238 |
|
|
239 |
|
if ((fb = fopen(filename, "w"))) |
240 |
|
{ |
241 |
< |
char buff[IRCD_BUFSIZE]; |
241 |
> |
char buf[IRCD_BUFSIZE]; |
242 |
|
unsigned int pid = (unsigned int)getpid(); |
243 |
|
|
244 |
< |
snprintf(buff, sizeof(buff), "%u\n", pid); |
244 |
> |
snprintf(buf, sizeof(buf), "%u\n", pid); |
245 |
|
|
246 |
< |
if ((fputs(buff, fb) == -1)) |
247 |
< |
ilog(LOG_TYPE_IRCD, "Error writing %u to pid file %s (%s)", |
248 |
< |
pid, filename, strerror(errno)); |
246 |
> |
if (fputs(buf, fb) == -1) |
247 |
> |
ilog(LOG_TYPE_IRCD, "Error writing to pid file %s: %s", |
248 |
> |
filename, strerror(errno)); |
249 |
|
|
250 |
|
fclose(fb); |
251 |
|
} |
252 |
|
else |
253 |
< |
{ |
254 |
< |
ilog(LOG_TYPE_IRCD, "Error opening pid file %s", filename); |
302 |
< |
} |
253 |
> |
ilog(LOG_TYPE_IRCD, "Error opening pid file %s: %s", |
254 |
> |
filename, strerror(errno)); |
255 |
|
} |
256 |
|
|
257 |
|
/* check_pidfile() |
266 |
|
check_pidfile(const char *filename) |
267 |
|
{ |
268 |
|
FILE *fb; |
269 |
< |
char buff[IRCD_BUFSIZE]; |
318 |
< |
pid_t pidfromfile; |
269 |
> |
char buf[IRCD_BUFSIZE]; |
270 |
|
|
320 |
– |
/* Don't do logging here, since we don't have log() initialised */ |
271 |
|
if ((fb = fopen(filename, "r"))) |
272 |
|
{ |
273 |
< |
if (fgets(buff, 20, fb) == NULL) |
274 |
< |
{ |
275 |
< |
/* log(L_ERROR, "Error reading from pid file %s (%s)", filename, |
326 |
< |
* strerror(errno)); |
327 |
< |
*/ |
328 |
< |
} |
273 |
> |
if (!fgets(buf, 20, fb)) |
274 |
> |
ilog(LOG_TYPE_IRCD, "Error reading from pid file %s: %s", |
275 |
> |
filename, strerror(errno)); |
276 |
|
else |
277 |
|
{ |
278 |
< |
pidfromfile = atoi(buff); |
278 |
> |
pid_t pid = atoi(buf); |
279 |
|
|
280 |
< |
if (!kill(pidfromfile, 0)) |
280 |
> |
if (!kill(pid, 0)) |
281 |
|
{ |
282 |
|
/* log(L_ERROR, "Server is already running"); */ |
283 |
|
printf("ircd: daemon is already running\n"); |
284 |
< |
exit(-1); |
284 |
> |
exit(EXIT_FAILURE); |
285 |
|
} |
286 |
|
} |
287 |
|
|
288 |
|
fclose(fb); |
289 |
|
} |
290 |
|
else if (errno != ENOENT) |
291 |
< |
{ |
292 |
< |
/* log(L_ERROR, "Error opening pid file %s", filename); */ |
346 |
< |
} |
291 |
> |
ilog(LOG_TYPE_IRCD, "Error opening pid file %s: %s", |
292 |
> |
filename, strerror(errno)); |
293 |
|
} |
294 |
|
|
295 |
|
/* setup_corefile() |
314 |
|
#endif |
315 |
|
} |
316 |
|
|
317 |
< |
#ifdef HAVE_LIBCRYPTO |
318 |
< |
static int |
319 |
< |
always_accept_verify_cb(int preverify_ok, X509_STORE_CTX *x509_ctx) |
317 |
> |
/* |
318 |
> |
* print_startup - print startup information |
319 |
> |
*/ |
320 |
> |
static void |
321 |
> |
print_startup(int pid) |
322 |
|
{ |
323 |
< |
return 1; |
323 |
> |
printf("ircd: version %s(%s)\n", ircd_version, serno); |
324 |
> |
printf("ircd: pid %d\n", pid); |
325 |
> |
printf("ircd: running in %s mode from %s\n", !server_state.foreground ? "background" |
326 |
> |
: "foreground", ConfigGeneral.dpath); |
327 |
|
} |
377 |
– |
#endif |
328 |
|
|
379 |
– |
/* init_ssl() |
380 |
– |
* |
381 |
– |
* inputs - nothing |
382 |
– |
* output - nothing |
383 |
– |
* side effects - setups SSL context. |
384 |
– |
*/ |
329 |
|
static void |
330 |
< |
ssl_init(void) |
330 |
> |
make_daemon(void) |
331 |
|
{ |
332 |
< |
#ifdef HAVE_LIBCRYPTO |
389 |
< |
const unsigned char session_id[] = "ircd-hybrid"; |
390 |
< |
|
391 |
< |
SSL_load_error_strings(); |
392 |
< |
SSLeay_add_ssl_algorithms(); |
393 |
< |
|
394 |
< |
if ((ServerInfo.server_ctx = SSL_CTX_new(SSLv23_server_method())) == NULL) |
395 |
< |
{ |
396 |
< |
const char *s; |
397 |
< |
|
398 |
< |
fprintf(stderr, "ERROR: Could not initialize the SSL Server context -- %s\n", |
399 |
< |
s = ERR_lib_error_string(ERR_get_error())); |
400 |
< |
ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Server context -- %s\n", s); |
401 |
< |
} |
402 |
< |
|
403 |
< |
SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TLSv1); |
404 |
< |
SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_TLS_ROLLBACK_BUG); |
405 |
< |
SSL_CTX_set_verify(ServerInfo.server_ctx, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE, |
406 |
< |
always_accept_verify_cb); |
407 |
< |
SSL_CTX_set_session_id_context(ServerInfo.server_ctx, session_id, sizeof(session_id) - 1); |
332 |
> |
int pid; |
333 |
|
|
334 |
< |
#if OPENSSL_VERSION_NUMBER >= 0x1000005FL && !defined(OPENSSL_NO_ECDH) |
334 |
> |
if ((pid = fork()) < 0) |
335 |
|
{ |
336 |
< |
EC_KEY *key = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1); |
337 |
< |
|
413 |
< |
if (key) |
414 |
< |
{ |
415 |
< |
SSL_CTX_set_tmp_ecdh(ServerInfo.server_ctx, key); |
416 |
< |
EC_KEY_free(key); |
417 |
< |
} |
336 |
> |
perror("fork"); |
337 |
> |
exit(EXIT_FAILURE); |
338 |
|
} |
339 |
< |
|
420 |
< |
SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_SINGLE_ECDH_USE); |
421 |
< |
#endif |
422 |
< |
|
423 |
< |
if ((ServerInfo.client_ctx = SSL_CTX_new(SSLv23_client_method())) == NULL) |
339 |
> |
else if (pid > 0) |
340 |
|
{ |
341 |
< |
const char *s; |
342 |
< |
|
427 |
< |
fprintf(stderr, "ERROR: Could not initialize the SSL Client context -- %s\n", |
428 |
< |
s = ERR_lib_error_string(ERR_get_error())); |
429 |
< |
ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Client context -- %s\n", s); |
341 |
> |
print_startup(pid); |
342 |
> |
exit(EXIT_SUCCESS); |
343 |
|
} |
344 |
|
|
345 |
< |
SSL_CTX_set_options(ServerInfo.client_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TLSv1); |
433 |
< |
SSL_CTX_set_options(ServerInfo.client_ctx, SSL_OP_TLS_ROLLBACK_BUG); |
434 |
< |
SSL_CTX_set_verify(ServerInfo.client_ctx, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE, |
435 |
< |
always_accept_verify_cb); |
436 |
< |
#endif /* HAVE_LIBCRYPTO */ |
345 |
> |
setsid(); |
346 |
|
} |
347 |
|
|
348 |
|
int |
349 |
|
main(int argc, char *argv[]) |
350 |
|
{ |
351 |
|
/* Check to see if the user is running us as root, which is a nono */ |
352 |
< |
if (geteuid() == 0) |
352 |
> |
if (!geteuid()) |
353 |
|
{ |
354 |
|
fprintf(stderr, "ERROR: This server won't run as root/superuser\n"); |
355 |
|
return -1; |
358 |
|
/* Setup corefile size immediately after boot -kre */ |
359 |
|
setup_corefile(); |
360 |
|
|
361 |
< |
/* save server boot time right away, so getrusage works correctly */ |
361 |
> |
/* Save server boot time right away, so getrusage works correctly */ |
362 |
|
set_time(); |
363 |
|
|
364 |
< |
/* It ain't random, but it ought to be a little harder to guess */ |
364 |
> |
/* It's not random, but it ought to be a little harder to guess */ |
365 |
|
init_genrand(SystemTime.tv_sec ^ (SystemTime.tv_usec | (getpid() << 20))); |
366 |
|
|
367 |
< |
me.localClient = &meLocalUser; |
368 |
< |
dlinkAdd(&me, &me.node, &global_client_list); /* Pointer to beginning |
369 |
< |
of Client list */ |
370 |
< |
ConfigLoggingEntry.use_logging = 1; |
371 |
< |
ConfigFileEntry.dpath = DPATH; |
372 |
< |
ConfigFileEntry.spath = SPATH; |
373 |
< |
ConfigFileEntry.mpath = MPATH; |
374 |
< |
ConfigFileEntry.configfile = CPATH; /* Server configuration file */ |
466 |
< |
ConfigFileEntry.klinefile = KPATH; /* Server kline file */ |
467 |
< |
ConfigFileEntry.glinefile = GPATH; /* Server gline file */ |
468 |
< |
ConfigFileEntry.xlinefile = XPATH; /* Server xline file */ |
469 |
< |
ConfigFileEntry.dlinefile = DLPATH; /* dline file */ |
470 |
< |
ConfigFileEntry.resvfile = RESVPATH; /* resv file */ |
367 |
> |
ConfigGeneral.dpath = DPATH; |
368 |
> |
ConfigGeneral.spath = SPATH; |
369 |
> |
ConfigGeneral.mpath = MPATH; |
370 |
> |
ConfigGeneral.configfile = CPATH; /* Server configuration file */ |
371 |
> |
ConfigGeneral.klinefile = KPATH; /* Server kline file */ |
372 |
> |
ConfigGeneral.xlinefile = XPATH; /* Server xline file */ |
373 |
> |
ConfigGeneral.dlinefile = DLPATH; /* dline file */ |
374 |
> |
ConfigGeneral.resvfile = RESVPATH; /* resv file */ |
375 |
|
|
376 |
|
myargv = argv; |
377 |
< |
umask(077); /* better safe than sorry --SRB */ |
377 |
> |
umask(077); /* umask 077: u=rwx,g=,o= */ |
378 |
|
|
379 |
|
parseargs(&argc, &argv, myopts); |
380 |
|
|
384 |
|
exit(EXIT_SUCCESS); |
385 |
|
} |
386 |
|
|
387 |
< |
if (chdir(ConfigFileEntry.dpath)) |
387 |
> |
if (chdir(ConfigGeneral.dpath)) |
388 |
|
{ |
389 |
|
perror("chdir"); |
390 |
|
exit(EXIT_FAILURE); |
391 |
|
} |
392 |
|
|
489 |
– |
ssl_init(); |
490 |
– |
|
393 |
|
if (!server_state.foreground) |
394 |
|
{ |
395 |
|
make_daemon(); |
396 |
< |
close_standard_fds(); /* this needs to be before init_netio()! */ |
396 |
> |
close_standard_fds(); /* this needs to be before netio_init()! */ |
397 |
|
} |
398 |
|
else |
399 |
|
print_startup(getpid()); |
400 |
|
|
401 |
|
setup_signals(); |
402 |
|
|
501 |
– |
/* Init the event subsystem */ |
502 |
– |
eventInit(); |
503 |
– |
|
403 |
|
/* We need this to initialise the fd array before anything else */ |
404 |
|
fdlist_init(); |
405 |
|
log_set_file(LOG_TYPE_IRCD, 0, logFileName); |
406 |
< |
check_can_use_v6(); |
407 |
< |
init_netio(); /* This needs to be setup early ! -- adrian */ |
406 |
> |
|
407 |
> |
netio_init(); /* This needs to be setup early ! -- adrian */ |
408 |
> |
tls_init(); |
409 |
|
|
410 |
|
/* Check if there is pidfile and daemon already running */ |
411 |
|
check_pidfile(pidFileName); |
412 |
|
|
413 |
|
mp_pool_init(); |
414 |
|
init_dlink_nodes(); |
415 |
< |
init_isupport(); |
415 |
> |
isupport_init(); |
416 |
|
dbuf_init(); |
417 |
|
hash_init(); |
418 |
< |
init_ip_hash_table(); /* client host ip hash table */ |
419 |
< |
init_host_hash(); /* Host-hashtable. */ |
418 |
> |
userhost_init(); |
419 |
> |
ipcache_init(); |
420 |
|
client_init(); |
421 |
|
class_init(); |
422 |
|
whowas_init(); |
423 |
|
watch_init(); |
424 |
|
auth_init(); /* Initialise the auth code */ |
425 |
< |
init_resolver(); /* Needs to be setup before the io loop */ |
425 |
> |
resolver_init(); /* Needs to be setup before the io loop */ |
426 |
|
modules_init(); |
427 |
|
read_conf_files(1); /* cold start init conf files */ |
428 |
< |
init_uid(); |
429 |
< |
initialize_server_capabs(); /* Set up default_server_capabs */ |
530 |
< |
initialize_global_set_options(); |
428 |
> |
server_capab_init(); /* Set up default_server_capabs */ |
429 |
> |
initialize_global_set_options(); /* Has to be called after read_conf_files() */ |
430 |
|
channel_init(); |
431 |
|
read_links_file(); |
432 |
|
motd_init(); |
433 |
< |
#ifdef HAVE_LIBGEOIP |
535 |
< |
geoip_ctx = GeoIP_new(GEOIP_MEMORY_CACHE); |
536 |
< |
#endif |
433 |
> |
user_modes_init(); |
434 |
|
|
435 |
< |
if (EmptyString(ServerInfo.sid)) |
435 |
> |
if (EmptyString(ConfigServerInfo.name)) |
436 |
|
{ |
437 |
< |
ilog(LOG_TYPE_IRCD, "ERROR: No server id specified in serverinfo block."); |
437 |
> |
ilog(LOG_TYPE_IRCD, "ERROR: No server name specified in serverinfo block."); |
438 |
|
exit(EXIT_FAILURE); |
439 |
|
} |
440 |
|
|
441 |
< |
strlcpy(me.id, ServerInfo.sid, sizeof(me.id)); |
441 |
> |
strlcpy(me.name, ConfigServerInfo.name, sizeof(me.name)); |
442 |
|
|
443 |
< |
if (EmptyString(ServerInfo.name)) |
443 |
> |
/* serverinfo {} description must exist. If not, error out.*/ |
444 |
> |
if (EmptyString(ConfigServerInfo.description)) |
445 |
|
{ |
446 |
< |
ilog(LOG_TYPE_IRCD, "ERROR: No server name specified in serverinfo block."); |
446 |
> |
ilog(LOG_TYPE_IRCD, "ERROR: No server description specified in serverinfo block."); |
447 |
|
exit(EXIT_FAILURE); |
448 |
|
} |
449 |
|
|
450 |
< |
strlcpy(me.name, ServerInfo.name, sizeof(me.name)); |
450 |
> |
strlcpy(me.info, ConfigServerInfo.description, sizeof(me.info)); |
451 |
|
|
452 |
< |
/* serverinfo{} description must exist. If not, error out.*/ |
555 |
< |
if (EmptyString(ServerInfo.description)) |
452 |
> |
if (EmptyString(ConfigServerInfo.sid)) |
453 |
|
{ |
454 |
< |
ilog(LOG_TYPE_IRCD, "ERROR: No server description specified in serverinfo block."); |
455 |
< |
exit(EXIT_FAILURE); |
454 |
> |
ilog(LOG_TYPE_IRCD, "Generating server ID"); |
455 |
> |
generate_sid(); |
456 |
|
} |
457 |
+ |
else |
458 |
+ |
strlcpy(me.id, ConfigServerInfo.sid, sizeof(me.id)); |
459 |
|
|
460 |
< |
strlcpy(me.info, ServerInfo.description, sizeof(me.info)); |
460 |
> |
init_uid(); |
461 |
|
|
462 |
< |
me.from = &me; |
463 |
< |
me.servptr = &me; |
464 |
< |
me.localClient->lasttime = CurrentTime; |
465 |
< |
me.localClient->since = CurrentTime; |
466 |
< |
me.localClient->firsttime = CurrentTime; |
462 |
> |
me.from = &me; |
463 |
> |
me.servptr = &me; |
464 |
> |
me.connection->lasttime = CurrentTime; |
465 |
> |
me.connection->since = CurrentTime; |
466 |
> |
me.connection->firsttime = CurrentTime; |
467 |
|
|
468 |
|
SetMe(&me); |
469 |
|
make_server(&me); |
471 |
|
hash_add_id(&me); |
472 |
|
hash_add_client(&me); |
473 |
|
|
474 |
< |
/* add ourselves to global_serv_list */ |
475 |
< |
dlinkAdd(&me, make_dlink_node(), &global_serv_list); |
474 |
> |
dlinkAdd(&me, make_dlink_node(), &global_server_list); |
475 |
> |
dlinkAdd(&me, &me.node, &global_client_list); |
476 |
|
|
477 |
< |
load_kline_database(); |
478 |
< |
load_dline_database(); |
479 |
< |
load_gline_database(); |
480 |
< |
load_xline_database(); |
582 |
< |
load_resv_database(); |
583 |
< |
|
584 |
< |
if (chdir(MODPATH)) |
585 |
< |
{ |
586 |
< |
ilog(LOG_TYPE_IRCD, "Could not load core modules. Terminating!"); |
587 |
< |
exit(EXIT_FAILURE); |
588 |
< |
} |
477 |
> |
load_kline_database(ConfigGeneral.klinefile); |
478 |
> |
load_dline_database(ConfigGeneral.dlinefile); |
479 |
> |
load_xline_database(ConfigGeneral.xlinefile); |
480 |
> |
load_resv_database(ConfigGeneral.resvfile); |
481 |
|
|
482 |
|
load_all_modules(1); |
483 |
|
load_conf_modules(); |
484 |
|
load_core_modules(1); |
485 |
|
|
594 |
– |
/* Go back to DPATH after checking to see if we can chdir to MODPATH */ |
595 |
– |
if (chdir(ConfigFileEntry.dpath)) |
596 |
– |
{ |
597 |
– |
perror("chdir"); |
598 |
– |
exit(EXIT_FAILURE); |
599 |
– |
} |
600 |
– |
|
601 |
– |
/* |
602 |
– |
* assemble_umode_buffer() has to be called after |
603 |
– |
* reading conf/loading modules. |
604 |
– |
*/ |
605 |
– |
assemble_umode_buffer(); |
606 |
– |
|
486 |
|
write_pidfile(pidFileName); |
487 |
|
|
488 |
< |
ilog(LOG_TYPE_IRCD, "Server Ready"); |
610 |
< |
|
611 |
< |
eventAddIsh("cleanup_glines", cleanup_glines, NULL, CLEANUP_GLINES_TIME); |
612 |
< |
eventAddIsh("cleanup_tklines", cleanup_tklines, NULL, CLEANUP_TKLINES_TIME); |
488 |
> |
event_addish(&event_cleanup_tklines, NULL); |
489 |
|
|
490 |
|
/* We want try_connections to be called as soon as possible now! -- adrian */ |
491 |
|
/* No, 'cause after a restart it would cause all sorts of nick collides */ |
492 |
< |
eventAddIsh("try_connections", try_connections, NULL, STARTUP_CONNECTIONS_TIME); |
492 |
> |
event_addish(&event_try_connections, NULL); |
493 |
|
|
494 |
|
/* Setup the timeout check. I'll shift it later :) -- adrian */ |
495 |
< |
eventAddIsh("comm_checktimeouts", comm_checktimeouts, NULL, 1); |
495 |
> |
event_add(&event_comm_checktimeouts, NULL); |
496 |
|
|
497 |
< |
eventAddIsh("save_all_databases", save_all_databases, NULL, DATABASE_UPDATE_TIMEOUT); |
622 |
< |
|
623 |
< |
if (ConfigServerHide.links_delay > 0) |
624 |
< |
eventAddIsh("write_links_file", write_links_file, NULL, ConfigServerHide.links_delay); |
625 |
< |
else |
626 |
< |
ConfigServerHide.links_disabled = 1; |
497 |
> |
event_addish(&event_save_all_databases, NULL); |
498 |
|
|
499 |
< |
if (splitmode) |
500 |
< |
eventAddIsh("check_splitmode", check_splitmode, NULL, 60); |
499 |
> |
if (ConfigServerHide.flatten_links_delay && event_write_links_file.active == 0) |
500 |
> |
{ |
501 |
> |
event_write_links_file.when = ConfigServerHide.flatten_links_delay; |
502 |
> |
event_add(&event_write_links_file, NULL); |
503 |
> |
} |
504 |
|
|
505 |
+ |
ilog(LOG_TYPE_IRCD, "Server Ready"); |
506 |
|
io_loop(); |
507 |
+ |
|
508 |
|
return 0; |
509 |
|
} |