| 22 |
|
* $Id$ |
| 23 |
|
*/ |
| 24 |
|
|
| 25 |
+ |
#ifdef IN_IRCD |
| 26 |
|
#include "stdinc.h" |
| 27 |
|
#include "s_user.h" |
| 27 |
– |
#include "tools.h" |
| 28 |
|
#include "ircd.h" |
| 29 |
|
#include "channel.h" |
| 30 |
|
#include "channel_mode.h" |
| 31 |
|
#include "client.h" |
| 32 |
|
#include "common.h" |
| 33 |
– |
#include "event.h" |
| 34 |
– |
#include "fdlist.h" |
| 33 |
|
#include "hash.h" |
| 36 |
– |
#include "irc_string.h" |
| 37 |
– |
#include "sprintf_irc.h" |
| 34 |
|
#include "ircd_signal.h" |
| 39 |
– |
#include "list.h" |
| 35 |
|
#include "s_gline.h" |
| 36 |
|
#include "motd.h" |
| 37 |
|
#include "ircd_handler.h" |
| 40 |
|
#include "numeric.h" |
| 41 |
|
#include "packet.h" |
| 42 |
|
#include "parse.h" |
| 48 |
– |
#include "irc_res.h" |
| 43 |
|
#include "restart.h" |
| 44 |
|
#include "s_auth.h" |
| 51 |
– |
#include "s_bsd.h" |
| 45 |
|
#include "s_conf.h" |
| 46 |
< |
#include "s_log.h" |
| 47 |
< |
#include "s_misc.h" |
| 55 |
< |
#include "s_serv.h" /* try_connections */ |
| 56 |
< |
#include "s_stats.h" |
| 46 |
> |
#include "parse_aline.h" |
| 47 |
> |
#include "s_serv.h" |
| 48 |
|
#include "send.h" |
| 49 |
|
#include "whowas.h" |
| 50 |
< |
#include "modules.h" |
| 60 |
< |
#include "memory.h" |
| 61 |
< |
#include "hook.h" |
| 50 |
> |
#include "conf/modules.h" |
| 51 |
|
#include "ircd_getopt.h" |
| 63 |
– |
#include "balloc.h" |
| 52 |
|
#include "motd.h" |
| 53 |
|
#include "supported.h" |
| 54 |
+ |
#include "watch.h" |
| 55 |
|
|
| 56 |
|
/* Try and find the correct name to use with getrlimit() for setting the max. |
| 57 |
|
* number of files allowed to be open by this process. |
| 59 |
|
|
| 60 |
|
/* /quote set variables */ |
| 61 |
|
struct SetOptions GlobalSetOptions; |
| 62 |
< |
|
| 62 |
> |
struct ServerStatistics ServerStats; |
| 63 |
|
/* configuration set from ircd.conf */ |
| 64 |
|
struct config_file_entry ConfigFileEntry; |
| 65 |
|
/* server info set from ircd.conf */ |
| 69 |
|
struct Counter Count = { 0, 0, 0, 0, 0, 0, 0, 0 }; |
| 70 |
|
struct ServerState_t server_state = { 0 }; |
| 71 |
|
struct logging_entry ConfigLoggingEntry = { 1, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0} }; |
| 83 |
– |
struct timeval SystemTime; |
| 72 |
|
struct Client me; /* That's me */ |
| 73 |
|
struct LocalUser meLocalUser; /* That's also part of me */ |
| 74 |
|
unsigned long connect_id = 0; /* unique connect ID */ |
| 82 |
|
|
| 83 |
|
int dorehash = 0; |
| 84 |
|
int doremotd = 0; |
| 97 |
– |
time_t nextconnect = 1; /* time for next try_connections call */ |
| 85 |
|
|
| 86 |
|
/* Set to zero because it should be initialized later using |
| 87 |
|
* initialize_server_capabs |
| 97 |
|
int split_users; |
| 98 |
|
unsigned int split_servers; |
| 99 |
|
|
| 100 |
+ |
static dlink_node *fdlimit_hook; |
| 101 |
+ |
|
| 102 |
|
/* Do klines the same way hybrid-6 did them, i.e. at the |
| 103 |
|
* top of the next io_loop instead of in the same loop as |
| 104 |
|
* the klines are being applied. |
| 130 |
|
*/ |
| 131 |
|
|
| 132 |
|
void *vptr = sbrk(0); |
| 133 |
< |
return((unsigned long)vptr); |
| 133 |
> |
return (unsigned long)vptr; |
| 134 |
|
} |
| 135 |
|
|
| 136 |
|
/* |
| 201 |
|
{NULL, NULL, STRING, NULL}, |
| 202 |
|
}; |
| 203 |
|
|
| 215 |
– |
void |
| 216 |
– |
set_time(void) |
| 217 |
– |
{ |
| 218 |
– |
static char to_send[200]; |
| 219 |
– |
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 |
| 232 |
– |
newtime.tv_sec = 0; |
| 233 |
– |
newtime.tv_usec = 0; |
| 234 |
– |
|
| 235 |
– |
if (gettimeofday(&newtime, NULL) == -1) |
| 236 |
– |
{ |
| 237 |
– |
ilog(L_ERROR, "Clock Failure (%s), TS can be corrupted", |
| 238 |
– |
strerror(errno)); |
| 239 |
– |
sendto_realops_flags(UMODE_ALL, L_ALL, |
| 240 |
– |
"Clock Failure (%s), TS can be corrupted", |
| 241 |
– |
strerror(errno)); |
| 242 |
– |
restart("Clock Failure"); |
| 243 |
– |
} |
| 244 |
– |
#endif |
| 245 |
– |
|
| 246 |
– |
if (newtime.tv_sec < CurrentTime) |
| 247 |
– |
{ |
| 248 |
– |
ircsprintf(to_send, "System clock is running backwards - (%lu < %lu)", |
| 249 |
– |
(unsigned long)newtime.tv_sec, (unsigned long)CurrentTime); |
| 250 |
– |
report_error(L_ALL, to_send, me.name, 0); |
| 251 |
– |
set_back_events(CurrentTime - newtime.tv_sec); |
| 252 |
– |
} |
| 253 |
– |
|
| 254 |
– |
SystemTime.tv_sec = newtime.tv_sec; |
| 255 |
– |
SystemTime.tv_usec = newtime.tv_usec; |
| 256 |
– |
} |
| 257 |
– |
|
| 204 |
|
static void |
| 205 |
|
io_loop(void) |
| 206 |
|
{ |
| 227 |
|
{ |
| 228 |
|
struct Client *client_p = ptr->data; |
| 229 |
|
assert(client_p->localClient->list_task); |
| 230 |
< |
safe_list_channels(client_p, client_p->localClient->list_task, 0, 0); |
| 230 |
> |
safe_list_channels(client_p, client_p->localClient->list_task, 0); |
| 231 |
|
} |
| 232 |
|
} |
| 233 |
|
|
| 248 |
|
rehash(1); |
| 249 |
|
dorehash = 0; |
| 250 |
|
} |
| 251 |
+ |
|
| 252 |
|
if (doremotd) |
| 253 |
|
{ |
| 254 |
|
read_message_file(&ConfigFileEntry.motd); |
| 264 |
|
* inputs - none |
| 265 |
|
* output - none |
| 266 |
|
* side effects - This sets all global set options needed |
| 267 |
+ |
* XXX to be removed with old s_conf.c |
| 268 |
|
*/ |
| 269 |
|
static void |
| 270 |
|
initialize_global_set_options(void) |
| 296 |
|
|
| 297 |
|
GlobalSetOptions.ident_timeout = IDENT_TIMEOUT; |
| 298 |
|
GlobalSetOptions.idletime = ConfigFileEntry.idletime; |
| 299 |
< |
/* End of global set options */ |
| 299 |
> |
GlobalSetOptions.maxlisters = 10; /* XXX ya ya ya - db */ |
| 300 |
|
} |
| 301 |
|
|
| 302 |
|
/* initialize_message_files() |
| 328 |
|
initialize_server_capabs(void) |
| 329 |
|
{ |
| 330 |
|
add_capability("QS", CAP_QS, 1); |
| 383 |
– |
add_capability("LL", CAP_LL, 1); |
| 331 |
|
add_capability("EOB", CAP_EOB, 1); |
| 332 |
< |
if (ServerInfo.sid != NULL) /* only enable TS6 if we have an SID */ |
| 333 |
< |
add_capability("TS6", CAP_TS6, 0); |
| 332 |
> |
add_capability("HUB", CAP_HUB, 0); |
| 333 |
> |
add_capability("TS6", CAP_TS6, 0); |
| 334 |
|
add_capability("ZIP", CAP_ZIP, 0); |
| 335 |
|
add_capability("CLUSTER", CAP_CLUSTER, 1); |
| 336 |
|
#ifdef HALFOPS |
| 360 |
|
pid, filename, strerror(errno)); |
| 361 |
|
|
| 362 |
|
fbclose(fb); |
| 416 |
– |
return; |
| 363 |
|
} |
| 364 |
|
else |
| 365 |
|
{ |
| 445 |
|
init_ssl(void) |
| 446 |
|
{ |
| 447 |
|
#ifdef HAVE_LIBCRYPTO |
| 448 |
+ |
SSL_library_init(); |
| 449 |
|
SSL_load_error_strings(); |
| 503 |
– |
SSLeay_add_ssl_algorithms(); |
| 450 |
|
|
| 451 |
|
ServerInfo.ctx = SSL_CTX_new(SSLv23_server_method()); |
| 452 |
+ |
|
| 453 |
|
if (!ServerInfo.ctx) |
| 454 |
|
{ |
| 455 |
|
const char *s; |
| 476 |
|
static void |
| 477 |
|
init_callbacks(void) |
| 478 |
|
{ |
| 479 |
< |
iorecv_cb = register_callback("iorecv", NULL); |
| 480 |
< |
iosend_cb = register_callback("iosend", NULL); |
| 479 |
> |
entering_umode_cb = register_callback("entering_umode", 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 |
+ |
uid_get_cb = register_callback("uid_get", uid_get); |
| 485 |
+ |
umode_cb = register_callback("changing_umode", change_simple_umode); |
| 486 |
|
} |
| 487 |
|
|
| 488 |
< |
int |
| 488 |
> |
static void * |
| 489 |
> |
changing_fdlimit(va_list args) |
| 490 |
> |
{ |
| 491 |
> |
int old_fdlimit = hard_fdlimit; |
| 492 |
> |
int fdmax = va_arg(args, int); |
| 493 |
> |
|
| 494 |
> |
/* allow MAXCLIENTS_MIN clients even at the cost of MAX_BUFFER and |
| 495 |
> |
* some not really LEAKED_FDS */ |
| 496 |
> |
fdmax = IRCD_MAX(fdmax, LEAKED_FDS + MAX_BUFFER + MAXCLIENTS_MIN); |
| 497 |
> |
|
| 498 |
> |
pass_callback(fdlimit_hook, fdmax); |
| 499 |
> |
|
| 500 |
> |
if (ServerInfo.max_clients > MAXCLIENTS_MAX) |
| 501 |
> |
{ |
| 502 |
> |
if (old_fdlimit != 0) |
| 503 |
> |
sendto_realops_flags(UMODE_ALL, L_ALL, |
| 504 |
> |
"HARD_FDLIMIT changed to %d, adjusting MAXCLIENTS to %d", |
| 505 |
> |
hard_fdlimit, MAXCLIENTS_MAX); |
| 506 |
> |
|
| 507 |
> |
ServerInfo.max_clients = MAXCLIENTS_MAX; |
| 508 |
> |
} |
| 509 |
> |
|
| 510 |
> |
return NULL; |
| 511 |
> |
} |
| 512 |
> |
|
| 513 |
> |
EXTERN int |
| 514 |
|
main(int argc, char *argv[]) |
| 515 |
|
{ |
| 516 |
< |
/* Check to see if the user is running |
| 517 |
< |
* us as root, which is a nono |
| 516 |
> |
/* |
| 517 |
> |
* Check to see if the user is running us as root, which is a nono |
| 518 |
|
*/ |
| 519 |
|
#ifndef _WIN32 |
| 520 |
|
if (geteuid() == 0) |
| 521 |
|
{ |
| 522 |
|
fprintf(stderr, "Don't run ircd as root!!!\n"); |
| 523 |
< |
return(-1); |
| 523 |
> |
return 1; |
| 524 |
|
} |
| 525 |
|
|
| 526 |
|
/* Setup corefile size immediately after boot -kre */ |
| 530 |
|
initialVMTop = get_vm_top(); |
| 531 |
|
#endif |
| 532 |
|
|
| 558 |
– |
/* save server boot time right away, so getrusage works correctly */ |
| 559 |
– |
set_time(); |
| 560 |
– |
|
| 561 |
– |
/* It ain't random, but it ought to be a little harder to guess */ |
| 562 |
– |
srand(SystemTime.tv_sec ^ (SystemTime.tv_usec | (getpid() << 20))); |
| 563 |
– |
memset(&me, 0, sizeof(me)); |
| 564 |
– |
memset(&meLocalUser, 0, sizeof(meLocalUser)); |
| 565 |
– |
me.localClient = &meLocalUser; |
| 566 |
– |
dlinkAdd(&me, &me.node, &global_client_list); /* Pointer to beginning |
| 567 |
– |
of Client list */ |
| 568 |
– |
|
| 533 |
|
memset(&ServerInfo, 0, sizeof(ServerInfo)); |
| 534 |
< |
|
| 571 |
< |
/* Initialise the channel capability usage counts... */ |
| 572 |
< |
init_chcap_usage_counts(); |
| 534 |
> |
memset(&ServerStats, 0, sizeof(ServerStats)); |
| 535 |
|
|
| 536 |
|
ConfigFileEntry.dpath = DPATH; |
| 537 |
|
ConfigFileEntry.configfile = CPATH; /* Server configuration file */ |
| 564 |
|
|
| 565 |
|
#ifndef _WIN32 |
| 566 |
|
if (!server_state.foreground) |
| 605 |
– |
{ |
| 567 |
|
make_daemon(); |
| 607 |
– |
close_standard_fds(); /* this needs to be before init_netio()! */ |
| 608 |
– |
} |
| 568 |
|
else |
| 569 |
|
print_startup(getpid()); |
| 611 |
– |
|
| 612 |
– |
setup_signals(); |
| 570 |
|
#endif |
| 571 |
|
|
| 572 |
< |
get_ircd_platform(ircd_platform); |
| 572 |
> |
libio_init(!server_state.foreground); |
| 573 |
> |
outofmemory = ircd_outofmemory; |
| 574 |
> |
fdlimit_hook = install_hook(fdlimit_cb, changing_fdlimit); |
| 575 |
|
|
| 617 |
– |
/* Init the event subsystem */ |
| 618 |
– |
eventInit(); |
| 619 |
– |
/* We need this to initialise the fd array before anything else */ |
| 620 |
– |
fdlist_init(); |
| 621 |
– |
init_log(logFileName); |
| 622 |
– |
check_can_use_v6(); |
| 623 |
– |
init_comm(); /* This needs to be setup early ! -- adrian */ |
| 624 |
– |
/* Check if there is pidfile and daemon already running */ |
| 576 |
|
check_pidfile(pidFileName); |
| 577 |
+ |
setup_signals(); |
| 578 |
+ |
get_ircd_platform(ircd_platform); |
| 579 |
+ |
init_log(logFileName); |
| 580 |
+ |
ServerInfo.can_use_v6 = check_can_use_v6(); |
| 581 |
+ |
|
| 582 |
+ |
/* make_dlink_node() cannot be called until after libio_init() */ |
| 583 |
+ |
memset(&me, 0, sizeof(me)); |
| 584 |
+ |
memset(&meLocalUser, 0, sizeof(meLocalUser)); |
| 585 |
+ |
|
| 586 |
+ |
me.localClient = &meLocalUser; |
| 587 |
+ |
me.from = me.servptr = &me; |
| 588 |
+ |
me.lasttime = me.since = me.firsttime = CurrentTime; |
| 589 |
+ |
|
| 590 |
+ |
SetMe(&me); |
| 591 |
+ |
make_server(&me); |
| 592 |
+ |
dlinkAdd(&me, &me.node, &global_client_list); |
| 593 |
+ |
dlinkAdd(&me, make_dlink_node(), &global_serv_list); |
| 594 |
|
|
| 627 |
– |
#ifndef NOBALLOC |
| 628 |
– |
initBlockHeap(); |
| 629 |
– |
#endif |
| 630 |
– |
init_dlink_nodes(); |
| 595 |
|
init_callbacks(); |
| 596 |
|
initialize_message_files(); |
| 633 |
– |
dbuf_init(); |
| 597 |
|
init_hash(); |
| 598 |
|
init_ip_hash_table(); /* client host ip hash table */ |
| 599 |
|
init_host_hash(); /* Host-hashtable. */ |
| 601 |
|
init_client(); |
| 602 |
|
init_class(); |
| 603 |
|
init_whowas(); |
| 641 |
– |
init_stats(); |
| 642 |
– |
read_conf_files(1); /* cold start init conf files */ |
| 643 |
– |
initServerMask(); |
| 644 |
– |
me.id[0] = '\0'; |
| 645 |
– |
init_uid(); |
| 604 |
|
init_auth(); /* Initialise the auth code */ |
| 647 |
– |
#ifndef _WIN32 |
| 648 |
– |
init_resolver(); /* Needs to be setup before the io loop */ |
| 649 |
– |
#endif |
| 650 |
– |
initialize_server_capabs(); /* Set up default_server_capabs */ |
| 651 |
– |
initialize_global_set_options(); |
| 605 |
|
init_channels(); |
| 606 |
|
init_channel_modes(); |
| 607 |
+ |
initialize_server_capabs(); /* Set up default_server_capabs */ |
| 608 |
+ |
|
| 609 |
+ |
read_conf_files(1); /* cold start init conf files */ |
| 610 |
+ |
check_class(); |
| 611 |
+ |
init_watch(); |
| 612 |
|
|
| 613 |
|
if (ServerInfo.name == NULL) |
| 614 |
|
{ |
| 615 |
< |
ilog(L_CRIT, "No server name specified in serverinfo block."); |
| 615 |
> |
ilog(L_CRIT, "ERROR: No server name specified in serverinfo block."); |
| 616 |
|
exit(EXIT_FAILURE); |
| 617 |
|
} |
| 618 |
+ |
|
| 619 |
|
strlcpy(me.name, ServerInfo.name, sizeof(me.name)); |
| 620 |
|
|
| 621 |
|
/* serverinfo{} description must exist. If not, error out.*/ |
| 625 |
|
"ERROR: No server description specified in serverinfo block."); |
| 626 |
|
exit(EXIT_FAILURE); |
| 627 |
|
} |
| 669 |
– |
strlcpy(me.info, ServerInfo.description, sizeof(me.info)); |
| 670 |
– |
|
| 671 |
– |
me.from = &me; |
| 672 |
– |
me.servptr = &me; |
| 628 |
|
|
| 629 |
< |
SetMe(&me); |
| 675 |
< |
make_server(&me); |
| 629 |
> |
strlcpy(me.info, ServerInfo.description, sizeof(me.info)); |
| 630 |
|
|
| 677 |
– |
me.lasttime = me.since = me.firsttime = CurrentTime; |
| 631 |
|
hash_add_client(&me); |
| 679 |
– |
|
| 680 |
– |
/* add ourselves to global_serv_list */ |
| 681 |
– |
dlinkAdd(&me, make_dlink_node(), &global_serv_list); |
| 632 |
|
|
| 633 |
< |
check_class(); |
| 633 |
> |
init_uid(); /* XXX move this one up after inculcating new conf system */ |
| 634 |
> |
initialize_global_set_options(); /* and this one is going to be deleted */ |
| 635 |
|
|
| 636 |
|
#ifndef STATIC_MODULES |
| 637 |
|
if (chdir(MODPATH)) |
| 640 |
|
exit(EXIT_FAILURE); |
| 641 |
|
} |
| 642 |
|
|
| 643 |
< |
load_all_modules(1); |
| 644 |
< |
load_conf_modules(); |
| 694 |
< |
load_core_modules(1); |
| 643 |
> |
boot_modules(1); |
| 644 |
> |
|
| 645 |
|
/* Go back to DPATH after checking to see if we can chdir to MODPATH */ |
| 646 |
|
chdir(ConfigFileEntry.dpath); |
| 647 |
|
#else |
| 669 |
|
/* Setup the timeout check. I'll shift it later :) -- adrian */ |
| 670 |
|
eventAddIsh("comm_checktimeouts", comm_checktimeouts, NULL, 1); |
| 671 |
|
|
| 672 |
+ |
/* XXX to be removed with old s_conf.c [superseded] */ |
| 673 |
|
if (ConfigServerHide.links_delay > 0) |
| 674 |
|
eventAddIsh("write_links_file", write_links_file, NULL, ConfigServerHide.links_delay); |
| 675 |
|
else |
| 676 |
|
ConfigServerHide.links_disabled = 1; |
| 677 |
|
|
| 678 |
< |
if (splitmode) |
| 678 |
> |
if (splitmode) /* XXX */ |
| 679 |
|
eventAddIsh("check_splitmode", check_splitmode, NULL, 60); |
| 680 |
|
|
| 681 |
|
io_loop(); |
| 682 |
< |
return(0); |
| 682 |
> |
return 0; |
| 683 |
> |
} |
| 684 |
> |
|
| 685 |
> |
#else |
| 686 |
> |
|
| 687 |
> |
#include <windows.h> |
| 688 |
> |
|
| 689 |
> |
extern __declspec(dllimport) main(int, char **); |
| 690 |
> |
|
| 691 |
> |
/* |
| 692 |
> |
* Initial entry point for Win32 GUI applications, called by the C runtime. |
| 693 |
> |
* |
| 694 |
> |
* It should be only a wrapper for main(), since when compiled as a console |
| 695 |
> |
* application, main() is called instead. |
| 696 |
> |
*/ |
| 697 |
> |
int WINAPI |
| 698 |
> |
WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, |
| 699 |
> |
LPSTR lpCmdLine, int nCmdShow) |
| 700 |
> |
{ |
| 701 |
> |
/* Do we really need these pidfile, logfile etc arguments? |
| 702 |
> |
* And we are not on a console, so -help or -foreground is meaningless. */ |
| 703 |
> |
|
| 704 |
> |
char *argv[2] = {"ircd", NULL}; |
| 705 |
> |
|
| 706 |
> |
return main(1, argv); |
| 707 |
|
} |
| 708 |
+ |
|
| 709 |
+ |
#endif |