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" |
34 |
|
#include "fdlist.h" |
35 |
|
#include "hash.h" |
36 |
|
#include "irc_string.h" |
37 |
– |
#include "sprintf_irc.h" |
37 |
|
#include "ircd_signal.h" |
39 |
– |
#include "list.h" |
38 |
|
#include "s_gline.h" |
39 |
|
#include "motd.h" |
40 |
|
#include "ircd_handler.h" |
45 |
|
#include "parse.h" |
46 |
|
#include "irc_res.h" |
47 |
|
#include "restart.h" |
48 |
+ |
#include "rng_mt.h" |
49 |
|
#include "s_auth.h" |
50 |
|
#include "s_bsd.h" |
51 |
|
#include "s_conf.h" |
52 |
|
#include "s_log.h" |
53 |
|
#include "s_misc.h" |
54 |
|
#include "s_serv.h" /* try_connections */ |
56 |
– |
#include "s_stats.h" |
55 |
|
#include "send.h" |
56 |
|
#include "whowas.h" |
57 |
|
#include "modules.h" |
61 |
|
#include "balloc.h" |
62 |
|
#include "motd.h" |
63 |
|
#include "supported.h" |
64 |
+ |
#include "watch.h" |
65 |
|
|
66 |
|
/* Try and find the correct name to use with getrlimit() for setting the max. |
67 |
|
* number of files allowed to be open by this process. |
76 |
|
struct server_info ServerInfo; |
77 |
|
/* admin info set from ircd.conf */ |
78 |
|
struct admin_info AdminInfo = { NULL, NULL, NULL }; |
79 |
< |
struct Counter Count = { 0, 0, 0, 0, 0, 0, 0, 0 }; |
79 |
> |
struct Counter Count = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; |
80 |
|
struct ServerState_t server_state = { 0 }; |
81 |
|
struct logging_entry ConfigLoggingEntry = { 1, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0} }; |
82 |
+ |
struct ServerStatistics ServerStats; |
83 |
|
struct timeval SystemTime; |
84 |
|
struct Client me; /* That's me */ |
85 |
|
struct LocalUser meLocalUser; /* That's also part of me */ |
86 |
– |
unsigned long connect_id = 0; /* unique connect ID */ |
86 |
|
|
88 |
– |
static unsigned long initialVMTop = 0; /* top of virtual memory at init */ |
87 |
|
const char *logFileName = LPATH; |
88 |
|
const char *pidFileName = PPATH; |
89 |
|
|
92 |
|
|
93 |
|
int dorehash = 0; |
94 |
|
int doremotd = 0; |
97 |
– |
time_t nextconnect = 1; /* time for next try_connections call */ |
95 |
|
|
96 |
|
/* Set to zero because it should be initialized later using |
97 |
|
* initialize_server_capabs |
102 |
|
int bio_spare_fd = -1; |
103 |
|
#endif |
104 |
|
|
105 |
< |
int splitmode; |
106 |
< |
int splitchecking; |
107 |
< |
int split_users; |
105 |
> |
unsigned int splitmode; |
106 |
> |
unsigned int splitchecking; |
107 |
> |
unsigned int split_users; |
108 |
|
unsigned int split_servers; |
109 |
|
|
110 |
|
/* Do klines the same way hybrid-6 did them, i.e. at the |
119 |
|
|
120 |
|
int rehashed_klines = 0; |
121 |
|
|
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 |
– |
} |
122 |
|
|
123 |
|
/* |
124 |
|
* print_startup - print startup information |
150 |
|
|
151 |
|
setsid(); |
152 |
|
} |
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 |
– |
} |
153 |
|
|
154 |
|
static int printVersion = 0; |
155 |
|
|
179 |
|
{ |
180 |
|
static char to_send[200]; |
181 |
|
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 |
182 |
|
newtime.tv_sec = 0; |
183 |
|
newtime.tv_usec = 0; |
184 |
|
|
191 |
|
strerror(errno)); |
192 |
|
restart("Clock Failure"); |
193 |
|
} |
244 |
– |
#endif |
194 |
|
|
195 |
|
if (newtime.tv_sec < CurrentTime) |
196 |
|
{ |
197 |
< |
ircsprintf(to_send, "System clock is running backwards - (%lu < %lu)", |
198 |
< |
(unsigned long)newtime.tv_sec, (unsigned long)CurrentTime); |
197 |
> |
snprintf(to_send, sizeof(to_send), |
198 |
> |
"System clock is running backwards - (%lu < %lu)", |
199 |
> |
(unsigned long)newtime.tv_sec, (unsigned long)CurrentTime); |
200 |
|
report_error(L_ALL, to_send, me.name, 0); |
201 |
|
set_back_events(CurrentTime - newtime.tv_sec); |
202 |
|
} |
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 |
< |
if (ServerInfo.sid != NULL) /* only enable TS6 if we have an SID */ |
386 |
< |
add_capability("TS6", CAP_TS6, 0); |
334 |
> |
add_capability("TS6", CAP_TS6, 0); |
335 |
|
add_capability("ZIP", CAP_ZIP, 0); |
336 |
|
add_capability("CLUSTER", CAP_CLUSTER, 1); |
337 |
|
#ifdef HALFOPS |
354 |
|
{ |
355 |
|
char buff[32]; |
356 |
|
unsigned int pid = (unsigned int)getpid(); |
357 |
< |
size_t nbytes = ircsprintf(buff, "%u\n", pid); |
357 |
> |
size_t nbytes = snprintf(buff, sizeof(buff), "%u\n", pid); |
358 |
|
|
359 |
|
if ((fbputs(buff, fb, nbytes) == -1)) |
360 |
|
ilog(L_ERROR, "Error writing %u to pid file %s (%s)", |
380 |
|
static void |
381 |
|
check_pidfile(const char *filename) |
382 |
|
{ |
435 |
– |
#ifndef _WIN32 |
383 |
|
FBFILE *fb; |
384 |
|
char buff[32]; |
385 |
|
pid_t pidfromfile; |
411 |
|
{ |
412 |
|
/* log(L_ERROR, "Error opening pid file %s", filename); */ |
413 |
|
} |
467 |
– |
#endif |
414 |
|
} |
415 |
|
|
416 |
|
/* setup_corefile() |
448 |
|
SSL_load_error_strings(); |
449 |
|
SSLeay_add_ssl_algorithms(); |
450 |
|
|
451 |
< |
ServerInfo.ctx = SSL_CTX_new(SSLv23_server_method()); |
506 |
< |
if (!ServerInfo.ctx) |
451 |
> |
if ((ServerInfo.server_ctx = SSL_CTX_new(SSLv23_server_method())) == NULL) |
452 |
|
{ |
453 |
|
const char *s; |
454 |
|
|
457 |
|
ilog(L_CRIT, "ERROR: Could not initialize the SSL context -- %s\n", s); |
458 |
|
} |
459 |
|
|
460 |
< |
SSL_CTX_set_options(ServerInfo.ctx, SSL_OP_NO_SSLv2); |
461 |
< |
SSL_CTX_set_options(ServerInfo.ctx, SSL_OP_TLS_ROLLBACK_BUG|SSL_OP_ALL); |
462 |
< |
SSL_CTX_set_verify(ServerInfo.ctx, SSL_VERIFY_NONE, NULL); |
460 |
> |
SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_NO_SSLv2); |
461 |
> |
SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_TLS_ROLLBACK_BUG|SSL_OP_ALL); |
462 |
> |
SSL_CTX_set_verify(ServerInfo.server_ctx, SSL_VERIFY_NONE, NULL); |
463 |
|
|
464 |
|
bio_spare_fd = save_spare_fd("SSL private key validation"); |
465 |
|
#endif /* HAVE_LIBCRYPTO */ |
474 |
|
static void |
475 |
|
init_callbacks(void) |
476 |
|
{ |
477 |
< |
iorecv_cb = register_callback("iorecv", NULL); |
478 |
< |
iosend_cb = register_callback("iosend", NULL); |
477 |
> |
iorecv_cb = register_callback("iorecv", iorecv_default); |
478 |
> |
iosend_cb = register_callback("iosend", iosend_default); |
479 |
|
iorecvctrl_cb = register_callback("iorecvctrl", NULL); |
480 |
|
iosendctrl_cb = register_callback("iosendctrl", NULL); |
481 |
|
} |
486 |
|
/* Check to see if the user is running |
487 |
|
* us as root, which is a nono |
488 |
|
*/ |
544 |
– |
#ifndef _WIN32 |
489 |
|
if (geteuid() == 0) |
490 |
|
{ |
491 |
|
fprintf(stderr, "Don't run ircd as root!!!\n"); |
492 |
< |
return(-1); |
492 |
> |
return -1; |
493 |
|
} |
494 |
|
|
495 |
|
/* Setup corefile size immediately after boot -kre */ |
496 |
|
setup_corefile(); |
497 |
|
|
554 |
– |
/* set initialVMTop before we allocate any memory */ |
555 |
– |
initialVMTop = get_vm_top(); |
556 |
– |
#endif |
557 |
– |
|
498 |
|
/* save server boot time right away, so getrusage works correctly */ |
499 |
|
set_time(); |
500 |
|
|
501 |
< |
/* It ain't random, but it ought to be a little harder to guess */ |
502 |
< |
srand(SystemTime.tv_sec ^ (SystemTime.tv_usec | (getpid() << 20))); |
503 |
< |
memset(&me, 0, sizeof(me)); |
564 |
< |
memset(&meLocalUser, 0, sizeof(meLocalUser)); |
501 |
> |
/* It ain't random, but it ought to be a little harder to guess */ |
502 |
> |
init_genrand(SystemTime.tv_sec ^ (SystemTime.tv_usec | (getpid() << 20))); |
503 |
> |
|
504 |
|
me.localClient = &meLocalUser; |
505 |
|
dlinkAdd(&me, &me.node, &global_client_list); /* Pointer to beginning |
506 |
|
of Client list */ |
568 |
– |
|
569 |
– |
memset(&ServerInfo, 0, sizeof(ServerInfo)); |
570 |
– |
|
507 |
|
/* Initialise the channel capability usage counts... */ |
508 |
|
init_chcap_usage_counts(); |
509 |
|
|
536 |
|
|
537 |
|
init_ssl(); |
538 |
|
|
603 |
– |
#ifndef _WIN32 |
539 |
|
if (!server_state.foreground) |
540 |
|
{ |
541 |
|
make_daemon(); |
545 |
|
print_startup(getpid()); |
546 |
|
|
547 |
|
setup_signals(); |
613 |
– |
#endif |
548 |
|
|
549 |
|
get_ircd_platform(ircd_platform); |
550 |
|
|
558 |
|
/* Check if there is pidfile and daemon already running */ |
559 |
|
check_pidfile(pidFileName); |
560 |
|
|
627 |
– |
#ifndef NOBALLOC |
561 |
|
initBlockHeap(); |
629 |
– |
#endif |
562 |
|
init_dlink_nodes(); |
563 |
|
init_callbacks(); |
564 |
|
initialize_message_files(); |
570 |
|
init_client(); |
571 |
|
init_class(); |
572 |
|
init_whowas(); |
573 |
< |
init_stats(); |
642 |
< |
read_conf_files(1); /* cold start init conf files */ |
643 |
< |
initServerMask(); |
644 |
< |
me.id[0] = '\0'; |
645 |
< |
init_uid(); |
573 |
> |
watch_init(); |
574 |
|
init_auth(); /* Initialise the auth code */ |
647 |
– |
#ifndef _WIN32 |
575 |
|
init_resolver(); /* Needs to be setup before the io loop */ |
576 |
< |
#endif |
576 |
> |
read_conf_files(1); /* cold start init conf files */ |
577 |
> |
init_uid(); |
578 |
|
initialize_server_capabs(); /* Set up default_server_capabs */ |
579 |
|
initialize_global_set_options(); |
580 |
|
init_channels(); |
581 |
|
|
582 |
< |
if (ServerInfo.name == NULL) |
582 |
> |
if (EmptyString(ServerInfo.sid)) |
583 |
|
{ |
584 |
< |
ilog(L_CRIT, "No server name specified in serverinfo block."); |
584 |
> |
ilog(L_CRIT, "ERROR: No server id specified in serverinfo block."); |
585 |
|
exit(EXIT_FAILURE); |
586 |
|
} |
587 |
+ |
|
588 |
+ |
strlcpy(me.id, ServerInfo.sid, sizeof(me.id)); |
589 |
+ |
|
590 |
+ |
if (EmptyString(ServerInfo.name)) |
591 |
+ |
{ |
592 |
+ |
ilog(L_CRIT, "ERROR: No server name specified in serverinfo block."); |
593 |
+ |
exit(EXIT_FAILURE); |
594 |
+ |
} |
595 |
+ |
|
596 |
|
strlcpy(me.name, ServerInfo.name, sizeof(me.name)); |
597 |
|
|
598 |
|
/* serverinfo{} description must exist. If not, error out.*/ |
599 |
< |
if (ServerInfo.description == NULL) |
599 |
> |
if (EmptyString(ServerInfo.description)) |
600 |
|
{ |
601 |
< |
ilog(L_CRIT, |
665 |
< |
"ERROR: No server description specified in serverinfo block."); |
601 |
> |
ilog(L_CRIT, "ERROR: No server description specified in serverinfo block."); |
602 |
|
exit(EXIT_FAILURE); |
603 |
|
} |
604 |
+ |
|
605 |
|
strlcpy(me.info, ServerInfo.description, sizeof(me.info)); |
606 |
|
|
607 |
< |
me.from = &me; |
608 |
< |
me.servptr = &me; |
607 |
> |
me.from = &me; |
608 |
> |
me.servptr = &me; |
609 |
> |
me.lasttime = me.since = me.firsttime = CurrentTime; |
610 |
|
|
611 |
|
SetMe(&me); |
612 |
|
make_server(&me); |
613 |
|
|
614 |
< |
me.lasttime = me.since = me.firsttime = CurrentTime; |
614 |
> |
hash_add_id(&me); |
615 |
|
hash_add_client(&me); |
616 |
|
|
617 |
|
/* add ourselves to global_serv_list */ |
618 |
|
dlinkAdd(&me, make_dlink_node(), &global_serv_list); |
619 |
|
|
682 |
– |
check_class(); |
683 |
– |
|
684 |
– |
#ifndef STATIC_MODULES |
620 |
|
if (chdir(MODPATH)) |
621 |
|
{ |
622 |
< |
ilog (L_CRIT, "Could not load core modules. Terminating!"); |
622 |
> |
ilog(L_CRIT, "Could not load core modules. Terminating!"); |
623 |
|
exit(EXIT_FAILURE); |
624 |
|
} |
625 |
|
|
626 |
|
load_all_modules(1); |
627 |
|
load_conf_modules(); |
628 |
|
load_core_modules(1); |
629 |
+ |
|
630 |
|
/* Go back to DPATH after checking to see if we can chdir to MODPATH */ |
631 |
< |
chdir(ConfigFileEntry.dpath); |
632 |
< |
#else |
633 |
< |
load_all_modules(1); |
634 |
< |
#endif |
631 |
> |
if (chdir(ConfigFileEntry.dpath)) |
632 |
> |
{ |
633 |
> |
perror("chdir"); |
634 |
> |
exit(EXIT_FAILURE); |
635 |
> |
} |
636 |
> |
|
637 |
|
/* |
638 |
|
* assemble_umode_buffer() has to be called after |
639 |
|
* reading conf/loading modules. |
665 |
|
eventAddIsh("check_splitmode", check_splitmode, NULL, 60); |
666 |
|
|
667 |
|
io_loop(); |
668 |
< |
return(0); |
668 |
> |
return 0; |
669 |
|
} |