24 |
|
|
25 |
|
#include "stdinc.h" |
26 |
|
#include "s_user.h" |
27 |
< |
#include "tools.h" |
27 |
> |
#include "list.h" |
28 |
|
#include "ircd.h" |
29 |
|
#include "channel.h" |
30 |
|
#include "channel_mode.h" |
36 |
|
#include "irc_string.h" |
37 |
|
#include "sprintf_irc.h" |
38 |
|
#include "ircd_signal.h" |
39 |
– |
#include "list.h" |
39 |
|
#include "s_gline.h" |
40 |
|
#include "motd.h" |
41 |
|
#include "ircd_handler.h" |
46 |
|
#include "parse.h" |
47 |
|
#include "irc_res.h" |
48 |
|
#include "restart.h" |
49 |
+ |
#include "rng_mt.h" |
50 |
|
#include "s_auth.h" |
51 |
|
#include "s_bsd.h" |
52 |
|
#include "s_conf.h" |
53 |
|
#include "s_log.h" |
54 |
|
#include "s_misc.h" |
55 |
|
#include "s_serv.h" /* try_connections */ |
56 |
– |
#include "s_stats.h" |
56 |
|
#include "send.h" |
57 |
|
#include "whowas.h" |
58 |
|
#include "modules.h" |
62 |
|
#include "balloc.h" |
63 |
|
#include "motd.h" |
64 |
|
#include "supported.h" |
65 |
+ |
#include "watch.h" |
66 |
|
|
67 |
|
/* Try and find the correct name to use with getrlimit() for setting the max. |
68 |
|
* number of files allowed to be open by this process. |
80 |
|
struct Counter Count = { 0, 0, 0, 0, 0, 0, 0, 0 }; |
81 |
|
struct ServerState_t server_state = { 0 }; |
82 |
|
struct logging_entry ConfigLoggingEntry = { 1, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0} }; |
83 |
+ |
struct ServerStatistics ServerStats; |
84 |
|
struct timeval SystemTime; |
85 |
|
struct Client me; /* That's me */ |
86 |
|
struct LocalUser meLocalUser; /* That's also part of me */ |
86 |
– |
unsigned long connect_id = 0; /* unique connect ID */ |
87 |
|
|
88 |
– |
static unsigned long initialVMTop = 0; /* top of virtual memory at init */ |
88 |
|
const char *logFileName = LPATH; |
89 |
|
const char *pidFileName = PPATH; |
90 |
|
|
93 |
|
|
94 |
|
int dorehash = 0; |
95 |
|
int doremotd = 0; |
97 |
– |
time_t nextconnect = 1; /* time for next try_connections call */ |
96 |
|
|
97 |
|
/* Set to zero because it should be initialized later using |
98 |
|
* initialize_server_capabs |
103 |
|
int bio_spare_fd = -1; |
104 |
|
#endif |
105 |
|
|
106 |
< |
int splitmode; |
107 |
< |
int splitchecking; |
108 |
< |
int split_users; |
106 |
> |
unsigned int splitmode; |
107 |
> |
unsigned int splitchecking; |
108 |
> |
unsigned int split_users; |
109 |
|
unsigned int split_servers; |
110 |
|
|
111 |
|
/* Do klines the same way hybrid-6 did them, i.e. at the |
120 |
|
|
121 |
|
int rehashed_klines = 0; |
122 |
|
|
125 |
– |
/* |
126 |
– |
* get_vm_top - get the operating systems notion of the resident set size |
127 |
– |
*/ |
128 |
– |
#ifndef _WIN32 |
129 |
– |
static unsigned long |
130 |
– |
get_vm_top(void) |
131 |
– |
{ |
132 |
– |
/* |
133 |
– |
* NOTE: sbrk is not part of the ANSI C library or the POSIX.1 standard |
134 |
– |
* however it seems that everyone defines it. Calling sbrk with a 0 |
135 |
– |
* argument will return a pointer to the top of the process virtual |
136 |
– |
* memory without changing the process size, so this call should be |
137 |
– |
* reasonably safe (sbrk returns the new value for the top of memory). |
138 |
– |
* This code relies on the notion that the address returned will be an |
139 |
– |
* offset from 0 (NULL), so the result of sbrk is cast to a size_t and |
140 |
– |
* returned. We really shouldn't be using it here but... |
141 |
– |
*/ |
142 |
– |
|
143 |
– |
void *vptr = sbrk(0); |
144 |
– |
return((unsigned long)vptr); |
145 |
– |
} |
123 |
|
|
124 |
|
/* |
125 |
|
* print_startup - print startup information |
151 |
|
|
152 |
|
setsid(); |
153 |
|
} |
177 |
– |
#endif |
178 |
– |
|
179 |
– |
/* |
180 |
– |
* get_maxrss - get the operating systems notion of the resident set size |
181 |
– |
*/ |
182 |
– |
unsigned long |
183 |
– |
get_maxrss(void) |
184 |
– |
{ |
185 |
– |
#ifdef _WIN32 |
186 |
– |
return (0); /* FIXME */ |
187 |
– |
#else |
188 |
– |
return (get_vm_top() - initialVMTop); |
189 |
– |
#endif |
190 |
– |
} |
154 |
|
|
155 |
|
static int printVersion = 0; |
156 |
|
|
180 |
|
{ |
181 |
|
static char to_send[200]; |
182 |
|
struct timeval newtime; |
220 |
– |
#ifdef _WIN32 |
221 |
– |
FILETIME ft; |
222 |
– |
|
223 |
– |
GetSystemTimeAsFileTime(&ft); |
224 |
– |
if (ft.dwLowDateTime < 0xd53e8000) |
225 |
– |
ft.dwHighDateTime--; |
226 |
– |
ft.dwLowDateTime -= 0xd53e8000; |
227 |
– |
ft.dwHighDateTime -= 0x19db1de; |
228 |
– |
|
229 |
– |
newtime.tv_sec = (*(uint64_t *) &ft) / 10000000; |
230 |
– |
newtime.tv_usec = (*(uint64_t *) &ft) / 10 % 1000000; |
231 |
– |
#else |
183 |
|
newtime.tv_sec = 0; |
184 |
|
newtime.tv_usec = 0; |
185 |
|
|
192 |
|
strerror(errno)); |
193 |
|
restart("Clock Failure"); |
194 |
|
} |
244 |
– |
#endif |
195 |
|
|
196 |
|
if (newtime.tv_sec < CurrentTime) |
197 |
|
{ |
231 |
|
{ |
232 |
|
struct Client *client_p = ptr->data; |
233 |
|
assert(client_p->localClient->list_task); |
234 |
< |
safe_list_channels(client_p, client_p->localClient->list_task, 0, 0); |
234 |
> |
safe_list_channels(client_p, client_p->localClient->list_task, 0); |
235 |
|
} |
236 |
|
} |
237 |
|
|
330 |
|
initialize_server_capabs(void) |
331 |
|
{ |
332 |
|
add_capability("QS", CAP_QS, 1); |
383 |
– |
add_capability("LL", CAP_LL, 1); |
333 |
|
add_capability("EOB", CAP_EOB, 1); |
334 |
+ |
|
335 |
|
if (ServerInfo.sid != NULL) /* only enable TS6 if we have an SID */ |
336 |
|
add_capability("TS6", CAP_TS6, 0); |
337 |
+ |
|
338 |
|
add_capability("ZIP", CAP_ZIP, 0); |
339 |
|
add_capability("CLUSTER", CAP_CLUSTER, 1); |
340 |
|
#ifdef HALFOPS |
383 |
|
static void |
384 |
|
check_pidfile(const char *filename) |
385 |
|
{ |
435 |
– |
#ifndef _WIN32 |
386 |
|
FBFILE *fb; |
387 |
|
char buff[32]; |
388 |
|
pid_t pidfromfile; |
414 |
|
{ |
415 |
|
/* log(L_ERROR, "Error opening pid file %s", filename); */ |
416 |
|
} |
467 |
– |
#endif |
417 |
|
} |
418 |
|
|
419 |
|
/* setup_corefile() |
451 |
|
SSL_load_error_strings(); |
452 |
|
SSLeay_add_ssl_algorithms(); |
453 |
|
|
454 |
< |
ServerInfo.ctx = SSL_CTX_new(SSLv23_server_method()); |
506 |
< |
if (!ServerInfo.ctx) |
454 |
> |
if ((ServerInfo.server_ctx = SSL_CTX_new(SSLv23_server_method())) == NULL) |
455 |
|
{ |
456 |
|
const char *s; |
457 |
|
|
460 |
|
ilog(L_CRIT, "ERROR: Could not initialize the SSL context -- %s\n", s); |
461 |
|
} |
462 |
|
|
463 |
< |
SSL_CTX_set_options(ServerInfo.ctx, SSL_OP_NO_SSLv2); |
464 |
< |
SSL_CTX_set_options(ServerInfo.ctx, SSL_OP_TLS_ROLLBACK_BUG|SSL_OP_ALL); |
465 |
< |
SSL_CTX_set_verify(ServerInfo.ctx, SSL_VERIFY_NONE, NULL); |
463 |
> |
SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_NO_SSLv2); |
464 |
> |
SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_TLS_ROLLBACK_BUG|SSL_OP_ALL); |
465 |
> |
SSL_CTX_set_verify(ServerInfo.server_ctx, SSL_VERIFY_NONE, NULL); |
466 |
|
|
467 |
|
bio_spare_fd = save_spare_fd("SSL private key validation"); |
468 |
|
#endif /* HAVE_LIBCRYPTO */ |
477 |
|
static void |
478 |
|
init_callbacks(void) |
479 |
|
{ |
480 |
< |
iorecv_cb = register_callback("iorecv", NULL); |
481 |
< |
iosend_cb = register_callback("iosend", NULL); |
480 |
> |
iorecv_cb = register_callback("iorecv", iorecv_default); |
481 |
> |
iosend_cb = register_callback("iosend", iosend_default); |
482 |
|
iorecvctrl_cb = register_callback("iorecvctrl", NULL); |
483 |
|
iosendctrl_cb = register_callback("iosendctrl", NULL); |
484 |
|
} |
489 |
|
/* Check to see if the user is running |
490 |
|
* us as root, which is a nono |
491 |
|
*/ |
544 |
– |
#ifndef _WIN32 |
492 |
|
if (geteuid() == 0) |
493 |
|
{ |
494 |
|
fprintf(stderr, "Don't run ircd as root!!!\n"); |
495 |
< |
return(-1); |
495 |
> |
return -1; |
496 |
|
} |
497 |
|
|
498 |
|
/* Setup corefile size immediately after boot -kre */ |
499 |
|
setup_corefile(); |
500 |
|
|
554 |
– |
/* set initialVMTop before we allocate any memory */ |
555 |
– |
initialVMTop = get_vm_top(); |
556 |
– |
#endif |
557 |
– |
|
501 |
|
/* save server boot time right away, so getrusage works correctly */ |
502 |
|
set_time(); |
503 |
|
|
504 |
< |
/* It ain't random, but it ought to be a little harder to guess */ |
505 |
< |
srand(SystemTime.tv_sec ^ (SystemTime.tv_usec | (getpid() << 20))); |
504 |
> |
/* It ain't random, but it ought to be a little harder to guess */ |
505 |
> |
init_genrand(SystemTime.tv_sec ^ (SystemTime.tv_usec | (getpid() << 20))); |
506 |
> |
|
507 |
|
memset(&me, 0, sizeof(me)); |
508 |
|
memset(&meLocalUser, 0, sizeof(meLocalUser)); |
509 |
|
me.localClient = &meLocalUser; |
511 |
|
of Client list */ |
512 |
|
|
513 |
|
memset(&ServerInfo, 0, sizeof(ServerInfo)); |
514 |
+ |
memset(&ServerStats, 0, sizeof(ServerStats)); |
515 |
|
|
516 |
|
/* Initialise the channel capability usage counts... */ |
517 |
|
init_chcap_usage_counts(); |
545 |
|
|
546 |
|
init_ssl(); |
547 |
|
|
603 |
– |
#ifndef _WIN32 |
548 |
|
if (!server_state.foreground) |
549 |
|
{ |
550 |
|
make_daemon(); |
554 |
|
print_startup(getpid()); |
555 |
|
|
556 |
|
setup_signals(); |
613 |
– |
#endif |
557 |
|
|
558 |
|
get_ircd_platform(ircd_platform); |
559 |
|
|
567 |
|
/* Check if there is pidfile and daemon already running */ |
568 |
|
check_pidfile(pidFileName); |
569 |
|
|
627 |
– |
#ifndef NOBALLOC |
570 |
|
initBlockHeap(); |
629 |
– |
#endif |
571 |
|
init_dlink_nodes(); |
572 |
|
init_callbacks(); |
573 |
|
initialize_message_files(); |
579 |
|
init_client(); |
580 |
|
init_class(); |
581 |
|
init_whowas(); |
582 |
< |
init_stats(); |
582 |
> |
watch_init(); |
583 |
> |
init_auth(); /* Initialise the auth code */ |
584 |
> |
init_resolver(); /* Needs to be setup before the io loop */ |
585 |
|
read_conf_files(1); /* cold start init conf files */ |
643 |
– |
initServerMask(); |
586 |
|
me.id[0] = '\0'; |
587 |
|
init_uid(); |
646 |
– |
init_auth(); /* Initialise the auth code */ |
647 |
– |
#ifndef _WIN32 |
648 |
– |
init_resolver(); /* Needs to be setup before the io loop */ |
649 |
– |
#endif |
588 |
|
initialize_server_capabs(); /* Set up default_server_capabs */ |
589 |
|
initialize_global_set_options(); |
590 |
|
init_channels(); |
594 |
|
ilog(L_CRIT, "No server name specified in serverinfo block."); |
595 |
|
exit(EXIT_FAILURE); |
596 |
|
} |
597 |
+ |
|
598 |
|
strlcpy(me.name, ServerInfo.name, sizeof(me.name)); |
599 |
|
|
600 |
|
/* serverinfo{} description must exist. If not, error out.*/ |
604 |
|
"ERROR: No server description specified in serverinfo block."); |
605 |
|
exit(EXIT_FAILURE); |
606 |
|
} |
607 |
+ |
|
608 |
|
strlcpy(me.info, ServerInfo.description, sizeof(me.info)); |
609 |
|
|
610 |
|
me.from = &me; |
619 |
|
/* add ourselves to global_serv_list */ |
620 |
|
dlinkAdd(&me, make_dlink_node(), &global_serv_list); |
621 |
|
|
682 |
– |
check_class(); |
683 |
– |
|
622 |
|
#ifndef STATIC_MODULES |
623 |
|
if (chdir(MODPATH)) |
624 |
|
{ |
665 |
|
eventAddIsh("check_splitmode", check_splitmode, NULL, 60); |
666 |
|
|
667 |
|
io_loop(); |
668 |
< |
return(0); |
668 |
> |
return 0; |
669 |
|
} |