2007-01-25 06:40:21 +00:00
|
|
|
/*
|
2008-07-28 19:02:54 +00:00
|
|
|
* charybdis: A slightly useful ircd.
|
2007-01-25 06:40:21 +00:00
|
|
|
* ircd.c: Starts up and runs the ircd.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
|
|
|
|
* Copyright (C) 1996-2002 Hybrid Development Team
|
2008-07-28 19:02:54 +00:00
|
|
|
* Copyright (C) 2002-2008 ircd-ratbox development team
|
2013-07-10 03:04:45 +00:00
|
|
|
* Copyright (C) 2005-2013 charybdis development team
|
2007-01-25 06:40:21 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
* USA
|
|
|
|
*/
|
|
|
|
|
2016-03-06 09:49:27 +00:00
|
|
|
#include "rb_lib.h"
|
2007-01-25 06:40:21 +00:00
|
|
|
#include "stdinc.h"
|
|
|
|
#include "setup.h"
|
2016-03-20 00:14:26 +00:00
|
|
|
#include "defaults.h"
|
2007-01-25 06:40:21 +00:00
|
|
|
#include "ircd.h"
|
|
|
|
#include "channel.h"
|
|
|
|
#include "class.h"
|
|
|
|
#include "client.h"
|
|
|
|
#include "hash.h"
|
2008-04-20 05:47:38 +00:00
|
|
|
#include "match.h"
|
2007-01-25 06:40:21 +00:00
|
|
|
#include "ircd_signal.h"
|
|
|
|
#include "msg.h" /* msgtab */
|
|
|
|
#include "hostmask.h"
|
|
|
|
#include "numeric.h"
|
|
|
|
#include "parse.h"
|
|
|
|
#include "restart.h"
|
|
|
|
#include "s_conf.h"
|
2008-04-03 02:52:01 +00:00
|
|
|
#include "logger.h"
|
2007-01-25 06:40:21 +00:00
|
|
|
#include "s_serv.h" /* try_connections */
|
|
|
|
#include "s_user.h"
|
|
|
|
#include "s_stats.h"
|
|
|
|
#include "scache.h"
|
|
|
|
#include "send.h"
|
|
|
|
#include "supported.h"
|
|
|
|
#include "whowas.h"
|
|
|
|
#include "modules.h"
|
|
|
|
#include "hook.h"
|
|
|
|
#include "ircd_getopt.h"
|
|
|
|
#include "newconf.h"
|
|
|
|
#include "reject.h"
|
|
|
|
#include "s_newconf.h"
|
|
|
|
#include "cache.h"
|
|
|
|
#include "monitor.h"
|
|
|
|
#include "patchlevel.h"
|
|
|
|
#include "serno.h"
|
2008-04-06 14:52:42 +00:00
|
|
|
#include "sslproc.h"
|
2016-04-02 07:56:03 +00:00
|
|
|
#include "wsproc.h"
|
2008-06-24 16:45:19 +00:00
|
|
|
#include "chmode.h"
|
2008-08-17 13:06:28 +00:00
|
|
|
#include "privilege.h"
|
2010-01-07 23:22:44 +00:00
|
|
|
#include "bandbi.h"
|
2016-04-02 21:44:04 +00:00
|
|
|
#include "authproc.h"
|
2016-01-09 07:08:15 +00:00
|
|
|
#include "operhash.h"
|
2007-01-25 06:40:21 +00:00
|
|
|
|
2016-06-01 20:05:56 +00:00
|
|
|
static void
|
|
|
|
ircd_die_cb(const char *str) __attribute__((noreturn));
|
|
|
|
|
2008-04-13 15:54:23 +00:00
|
|
|
/* /quote set variables */
|
2008-04-05 18:02:59 +00:00
|
|
|
struct SetOptions GlobalSetOptions;
|
2008-04-13 15:54:23 +00:00
|
|
|
|
|
|
|
/* configuration set from ircd.conf */
|
|
|
|
struct config_file_entry ConfigFileEntry;
|
|
|
|
/* server info set from ircd.conf */
|
|
|
|
struct server_info ServerInfo;
|
|
|
|
/* admin info set from ircd.conf */
|
2008-04-08 11:50:39 +00:00
|
|
|
struct admin_info AdminInfo;
|
|
|
|
|
2008-04-13 15:54:23 +00:00
|
|
|
struct Counter Count;
|
2008-04-04 15:54:37 +00:00
|
|
|
struct ServerStatistics ServerStats;
|
|
|
|
|
2008-04-08 11:50:39 +00:00
|
|
|
int maxconnections;
|
2008-04-13 15:54:23 +00:00
|
|
|
struct Client me; /* That's me */
|
2008-04-08 11:50:39 +00:00
|
|
|
struct LocalUser meLocalUser; /* That's also part of me */
|
|
|
|
|
2008-06-28 10:36:25 +00:00
|
|
|
rb_dlink_list global_client_list;
|
2008-04-13 15:54:23 +00:00
|
|
|
|
2008-06-28 10:36:25 +00:00
|
|
|
/* unknown/client pointer lists */
|
2008-04-13 15:54:23 +00:00
|
|
|
rb_dlink_list unknown_list; /* unknown clients ON this server only */
|
2008-06-28 10:36:25 +00:00
|
|
|
rb_dlink_list lclient_list; /* local clients only ON this server */
|
2008-04-13 15:54:23 +00:00
|
|
|
rb_dlink_list serv_list; /* local servers to this server ONLY */
|
|
|
|
rb_dlink_list global_serv_list; /* global servers on the network */
|
|
|
|
rb_dlink_list local_oper_list; /* our opers, duplicated in lclient_list */
|
2008-04-08 12:01:16 +00:00
|
|
|
rb_dlink_list oper_list; /* network opers */
|
|
|
|
|
2016-04-25 22:21:38 +00:00
|
|
|
char * const *myargv;
|
2016-03-28 00:05:38 +00:00
|
|
|
volatile sig_atomic_t dorehash = false;
|
|
|
|
volatile sig_atomic_t dorehashbans = false;
|
|
|
|
volatile sig_atomic_t doremotd = false;
|
2016-03-09 08:00:40 +00:00
|
|
|
bool kline_queued = false;
|
2016-03-09 08:19:31 +00:00
|
|
|
bool server_state_foreground = false;
|
|
|
|
bool opers_see_all_users = false;
|
2016-03-19 05:57:32 +00:00
|
|
|
bool ircd_ssl_ok = false;
|
|
|
|
bool ircd_zlib_ok = true;
|
2008-04-13 15:54:23 +00:00
|
|
|
|
|
|
|
int testing_conf = 0;
|
2008-07-27 12:25:00 +00:00
|
|
|
time_t startup_time;
|
2008-04-13 15:54:23 +00:00
|
|
|
|
2012-02-04 07:47:46 +00:00
|
|
|
int default_server_capabs;
|
2008-04-13 15:54:23 +00:00
|
|
|
|
2008-07-27 12:25:00 +00:00
|
|
|
int splitmode;
|
|
|
|
int splitchecking;
|
|
|
|
int split_users;
|
|
|
|
int split_servers;
|
|
|
|
int eob_count;
|
2008-04-06 14:52:42 +00:00
|
|
|
|
2016-03-24 23:45:28 +00:00
|
|
|
const char *ircd_paths[IRCD_PATH_COUNT] = {
|
|
|
|
[IRCD_PATH_PREFIX] = DPATH,
|
|
|
|
[IRCD_PATH_MODULES] = MODPATH,
|
|
|
|
[IRCD_PATH_AUTOLOAD_MODULES] = AUTOMODPATH,
|
|
|
|
[IRCD_PATH_ETC] = ETCPATH,
|
|
|
|
[IRCD_PATH_LOG] = LOGPATH,
|
|
|
|
[IRCD_PATH_USERHELP] = UHPATH,
|
|
|
|
[IRCD_PATH_OPERHELP] = HPATH,
|
|
|
|
[IRCD_PATH_IRCD_EXEC] = SPATH,
|
|
|
|
[IRCD_PATH_IRCD_CONF] = CPATH,
|
|
|
|
[IRCD_PATH_IRCD_MOTD] = MPATH,
|
|
|
|
[IRCD_PATH_IRCD_LOG] = LPATH,
|
|
|
|
[IRCD_PATH_IRCD_PID] = PPATH,
|
|
|
|
[IRCD_PATH_IRCD_OMOTD] = OPATH,
|
|
|
|
[IRCD_PATH_BANDB] = DBPATH,
|
|
|
|
[IRCD_PATH_BIN] = BINPATH,
|
|
|
|
[IRCD_PATH_LIBEXEC] = PKGLIBEXECDIR,
|
|
|
|
};
|
|
|
|
|
2016-06-18 04:36:47 +00:00
|
|
|
const char *ircd_pathnames[IRCD_PATH_COUNT] = {
|
|
|
|
[IRCD_PATH_PREFIX] = "prefix",
|
|
|
|
[IRCD_PATH_MODULES] = "modules",
|
|
|
|
[IRCD_PATH_AUTOLOAD_MODULES] = "autoload modules",
|
|
|
|
[IRCD_PATH_ETC] = "config",
|
|
|
|
[IRCD_PATH_LOG] = "log",
|
|
|
|
[IRCD_PATH_USERHELP] = "user help",
|
|
|
|
[IRCD_PATH_OPERHELP] = "oper help",
|
|
|
|
[IRCD_PATH_IRCD_EXEC] = "ircd binary",
|
|
|
|
[IRCD_PATH_IRCD_CONF] = "ircd.conf",
|
|
|
|
[IRCD_PATH_IRCD_MOTD] = "ircd.motd",
|
|
|
|
[IRCD_PATH_IRCD_LOG] = "ircd.log",
|
|
|
|
[IRCD_PATH_IRCD_PID] = "ircd.pid",
|
|
|
|
[IRCD_PATH_IRCD_OMOTD] = "oper motd",
|
|
|
|
[IRCD_PATH_BANDB] = "bandb",
|
|
|
|
[IRCD_PATH_BIN] = "binary dir",
|
|
|
|
[IRCD_PATH_LIBEXEC] = "libexec dir",
|
|
|
|
};
|
|
|
|
|
2016-03-25 05:00:06 +00:00
|
|
|
const char *logFileName = NULL;
|
|
|
|
const char *pidFileName = NULL;
|
2016-03-24 23:45:28 +00:00
|
|
|
|
2008-04-20 03:38:56 +00:00
|
|
|
void
|
|
|
|
ircd_shutdown(const char *reason)
|
|
|
|
{
|
|
|
|
struct Client *target_p;
|
|
|
|
rb_dlink_node *ptr;
|
|
|
|
|
|
|
|
RB_DLINK_FOREACH(ptr, lclient_list.head)
|
|
|
|
{
|
|
|
|
target_p = ptr->data;
|
|
|
|
|
|
|
|
sendto_one(target_p, ":%s NOTICE %s :Server Terminating. %s",
|
|
|
|
me.name, target_p->name, reason);
|
|
|
|
}
|
|
|
|
|
|
|
|
RB_DLINK_FOREACH(ptr, serv_list.head)
|
|
|
|
{
|
|
|
|
target_p = ptr->data;
|
|
|
|
|
|
|
|
sendto_one(target_p, ":%s ERROR :Terminated by %s",
|
|
|
|
me.name, reason);
|
|
|
|
}
|
|
|
|
|
|
|
|
ilog(L_MAIN, "Server Terminating. %s", reason);
|
2008-04-20 03:42:30 +00:00
|
|
|
close_logfiles();
|
2008-04-20 03:38:56 +00:00
|
|
|
|
|
|
|
unlink(pidFileName);
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
2007-01-25 06:40:21 +00:00
|
|
|
/*
|
|
|
|
* print_startup - print startup information
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
print_startup(int pid)
|
|
|
|
{
|
2014-02-23 20:51:19 +00:00
|
|
|
int fd;
|
|
|
|
|
2016-03-20 08:06:14 +00:00
|
|
|
#ifndef _WIN32
|
2014-02-23 20:51:19 +00:00
|
|
|
close(1);
|
|
|
|
fd = open("/dev/null", O_RDWR);
|
|
|
|
if (fd == -1) {
|
|
|
|
perror("open /dev/null");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
if (fd == 0)
|
|
|
|
fd = dup(fd);
|
|
|
|
if (fd != 1)
|
|
|
|
abort();
|
2016-03-20 08:06:14 +00:00
|
|
|
#endif
|
2007-01-25 06:40:21 +00:00
|
|
|
inotice("now running in %s mode from %s as pid %d ...",
|
|
|
|
!server_state_foreground ? "background" : "foreground",
|
|
|
|
ConfigFileEntry.dpath, pid);
|
|
|
|
|
2016-03-20 08:06:14 +00:00
|
|
|
#ifndef _WIN32
|
2007-01-25 06:40:21 +00:00
|
|
|
/* let the parent process know the initialization was successful
|
|
|
|
* -- jilles */
|
|
|
|
if (!server_state_foreground)
|
2016-03-18 20:53:43 +00:00
|
|
|
{
|
2016-03-23 13:07:23 +00:00
|
|
|
/* GCC complains on Linux if we don't check the value of write pedantically.
|
|
|
|
* Technically you're supposed to check the value, yes, but it probably can't fail.
|
|
|
|
* No, casting to void is of no use to shut the warning up. You HAVE to use the value.
|
|
|
|
* --Elizfaox
|
|
|
|
*/
|
|
|
|
if(write(0, ".", 1) < 1)
|
|
|
|
abort();
|
2016-03-18 20:53:43 +00:00
|
|
|
}
|
2014-02-23 20:51:19 +00:00
|
|
|
if (dup2(1, 0) == -1)
|
|
|
|
abort();
|
|
|
|
if (dup2(1, 2) == -1)
|
|
|
|
abort();
|
2016-03-20 08:06:14 +00:00
|
|
|
#endif
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* init_sys
|
|
|
|
*
|
|
|
|
* inputs - boot_daemon flag
|
|
|
|
* output - none
|
|
|
|
* side effects - if boot_daemon flag is not set, don't daemonize
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
init_sys(void)
|
|
|
|
{
|
2016-03-20 08:06:14 +00:00
|
|
|
#if !defined(_WIN32) && defined(RLIMIT_NOFILE) && defined(HAVE_SYS_RESOURCE_H)
|
2008-04-13 15:54:23 +00:00
|
|
|
struct rlimit limit;
|
|
|
|
|
|
|
|
if(!getrlimit(RLIMIT_NOFILE, &limit))
|
|
|
|
{
|
|
|
|
maxconnections = limit.rlim_cur;
|
|
|
|
if(maxconnections <= MAX_BUFFER)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "ERROR: Shell FD limits are too low.\n");
|
2008-08-16 18:38:13 +00:00
|
|
|
fprintf(stderr, "ERROR: charybdis reserves %d FDs, shell limits must be above this\n", MAX_BUFFER);
|
2008-04-13 15:54:23 +00:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif /* RLIMIT_FD_MAX */
|
2008-04-05 19:56:15 +00:00
|
|
|
maxconnections = MAXCONNECTIONS;
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
make_daemon(void)
|
|
|
|
{
|
2016-03-20 07:03:32 +00:00
|
|
|
#ifndef _WIN32
|
2007-01-25 06:40:21 +00:00
|
|
|
int pid;
|
|
|
|
int pip[2];
|
|
|
|
char c;
|
|
|
|
|
|
|
|
if (pipe(pip) < 0)
|
|
|
|
{
|
|
|
|
perror("pipe");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
dup2(pip[1], 0);
|
|
|
|
close(pip[1]);
|
|
|
|
if((pid = fork()) < 0)
|
|
|
|
{
|
|
|
|
perror("fork");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
else if(pid > 0)
|
|
|
|
{
|
|
|
|
close(0);
|
|
|
|
/* Wait for initialization to finish, successfully or
|
|
|
|
* unsuccessfully. Until this point the child may still
|
|
|
|
* write to stdout/stderr.
|
|
|
|
* -- jilles */
|
|
|
|
if (read(pip[0], &c, 1) > 0)
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
else
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
close(pip[0]);
|
|
|
|
setsid();
|
|
|
|
/* fclose(stdin);
|
|
|
|
fclose(stdout);
|
|
|
|
fclose(stderr); */
|
2016-03-20 07:03:32 +00:00
|
|
|
#endif
|
2007-01-25 06:40:21 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int printVersion = 0;
|
|
|
|
|
|
|
|
struct lgetopt myopts[] = {
|
|
|
|
{"configfile", &ConfigFileEntry.configfile,
|
|
|
|
STRING, "File to use for ircd.conf"},
|
|
|
|
{"logfile", &logFileName,
|
|
|
|
STRING, "File to use for ircd.log"},
|
|
|
|
{"pidfile", &pidFileName,
|
|
|
|
STRING, "File to use for process ID"},
|
|
|
|
{"foreground", &server_state_foreground,
|
|
|
|
YESNO, "Run in foreground (don't detach)"},
|
|
|
|
{"version", &printVersion,
|
|
|
|
YESNO, "Print version and exit"},
|
|
|
|
{"conftest", &testing_conf,
|
|
|
|
YESNO, "Test the configuration files and exit"},
|
|
|
|
{"help", NULL, USAGE, "Print this text"},
|
|
|
|
{NULL, NULL, STRING, NULL},
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
check_rehash(void *unused)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Check to see whether we have to rehash the configuration ..
|
|
|
|
*/
|
|
|
|
if(dorehash)
|
|
|
|
{
|
2016-03-23 13:52:32 +00:00
|
|
|
rehash(true);
|
2016-03-09 08:06:21 +00:00
|
|
|
dorehash = false;
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(dorehashbans)
|
|
|
|
{
|
2016-03-23 13:52:32 +00:00
|
|
|
rehash_bans();
|
2016-03-09 08:06:21 +00:00
|
|
|
dorehashbans = false;
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(doremotd)
|
|
|
|
{
|
|
|
|
sendto_realops_snomask(SNO_GENERAL, L_ALL,
|
|
|
|
"Got signal SIGUSR1, reloading ircd motd file");
|
2008-04-20 03:24:50 +00:00
|
|
|
cache_user_motd();
|
2016-03-09 08:06:21 +00:00
|
|
|
doremotd = false;
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* initalialize_global_set_options
|
|
|
|
*
|
|
|
|
* inputs - none
|
|
|
|
* output - none
|
2014-03-03 04:25:47 +00:00
|
|
|
* side effects - This sets all global set options needed
|
2007-01-25 06:40:21 +00:00
|
|
|
*/
|
|
|
|
static void
|
|
|
|
initialize_global_set_options(void)
|
|
|
|
{
|
|
|
|
memset(&GlobalSetOptions, 0, sizeof(GlobalSetOptions));
|
|
|
|
/* memset( &ConfigFileEntry, 0, sizeof(ConfigFileEntry)); */
|
|
|
|
|
2008-04-13 15:54:23 +00:00
|
|
|
GlobalSetOptions.maxclients = ServerInfo.default_max_clients;
|
|
|
|
|
|
|
|
if(GlobalSetOptions.maxclients > (maxconnections - MAX_BUFFER) || (GlobalSetOptions.maxclients <= 0))
|
2008-04-05 19:56:15 +00:00
|
|
|
GlobalSetOptions.maxclients = maxconnections - MAX_BUFFER;
|
|
|
|
|
2007-01-25 06:40:21 +00:00
|
|
|
GlobalSetOptions.autoconn = 1;
|
|
|
|
|
|
|
|
GlobalSetOptions.spam_time = MIN_JOIN_LEAVE_TIME;
|
|
|
|
GlobalSetOptions.spam_num = MAX_JOIN_LEAVE_COUNT;
|
|
|
|
|
2013-10-29 09:07:19 +00:00
|
|
|
GlobalSetOptions.floodcount = ConfigFileEntry.default_floodcount;
|
2007-01-25 06:40:21 +00:00
|
|
|
|
|
|
|
split_servers = ConfigChannel.default_split_server_count;
|
|
|
|
split_users = ConfigChannel.default_split_user_count;
|
|
|
|
|
|
|
|
if(split_users && split_servers
|
|
|
|
&& (ConfigChannel.no_create_on_split || ConfigChannel.no_join_on_split))
|
|
|
|
{
|
|
|
|
splitmode = 1;
|
|
|
|
splitchecking = 1;
|
|
|
|
}
|
|
|
|
|
2013-10-29 09:07:19 +00:00
|
|
|
GlobalSetOptions.ident_timeout = ConfigFileEntry.default_ident_timeout;
|
2007-01-25 06:40:21 +00:00
|
|
|
|
2008-04-20 04:40:40 +00:00
|
|
|
rb_strlcpy(GlobalSetOptions.operstring,
|
2007-01-25 06:40:21 +00:00
|
|
|
ConfigFileEntry.default_operstring,
|
|
|
|
sizeof(GlobalSetOptions.operstring));
|
2008-04-20 04:40:40 +00:00
|
|
|
rb_strlcpy(GlobalSetOptions.adminstring,
|
2007-01-25 06:40:21 +00:00
|
|
|
ConfigFileEntry.default_adminstring,
|
|
|
|
sizeof(GlobalSetOptions.adminstring));
|
|
|
|
|
|
|
|
/* memset( &ConfigChannel, 0, sizeof(ConfigChannel)); */
|
|
|
|
|
|
|
|
/* End of global set options */
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* initialize_server_capabs
|
|
|
|
*
|
|
|
|
* inputs - none
|
|
|
|
* output - none
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
initialize_server_capabs(void)
|
|
|
|
{
|
|
|
|
default_server_capabs &= ~CAP_ZIP;
|
|
|
|
}
|
|
|
|
|
2016-06-18 06:05:38 +00:00
|
|
|
#ifdef _WIN32
|
2016-03-25 06:57:25 +00:00
|
|
|
/*
|
|
|
|
* relocate_paths
|
|
|
|
*
|
|
|
|
* inputs - none
|
|
|
|
* output - none
|
|
|
|
* side effects - items in ircd_paths[] array are relocated
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
relocate_paths(void)
|
|
|
|
{
|
|
|
|
char prefix[PATH_MAX], workbuf[PATH_MAX];
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
rb_strlcpy(prefix, rb_path_to_self(), sizeof prefix);
|
|
|
|
|
|
|
|
ircd_paths[IRCD_PATH_IRCD_EXEC] = rb_strdup(prefix);
|
|
|
|
|
|
|
|
/* if we're running from inside the source tree, we probably do not want to relocate any other paths */
|
|
|
|
if (strstr(prefix, ".libs") != NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* prefix = /home/kaniini/ircd/bin/ircd */
|
|
|
|
p = strrchr(prefix, RB_PATH_SEPARATOR);
|
|
|
|
if (rb_unlikely(p == NULL))
|
|
|
|
return;
|
|
|
|
*p = 0;
|
|
|
|
|
|
|
|
/* prefix = /home/kaniini/ircd/bin */
|
|
|
|
p = strrchr(prefix, RB_PATH_SEPARATOR);
|
|
|
|
if (rb_unlikely(p == NULL))
|
|
|
|
return;
|
|
|
|
*p = 0;
|
|
|
|
|
|
|
|
/* prefix = /home/kaniini/ircd */
|
|
|
|
ircd_paths[IRCD_PATH_PREFIX] = rb_strdup(prefix);
|
|
|
|
|
|
|
|
/* now that we have our prefix, we can relocate the other paths... */
|
|
|
|
snprintf(workbuf, sizeof workbuf, "%s%cmodules", prefix, RB_PATH_SEPARATOR);
|
|
|
|
ircd_paths[IRCD_PATH_MODULES] = rb_strdup(workbuf);
|
|
|
|
|
|
|
|
snprintf(workbuf, sizeof workbuf, "%s%cmodules%cautoload", prefix, RB_PATH_SEPARATOR, RB_PATH_SEPARATOR);
|
|
|
|
ircd_paths[IRCD_PATH_AUTOLOAD_MODULES] = rb_strdup(workbuf);
|
|
|
|
|
|
|
|
snprintf(workbuf, sizeof workbuf, "%s%cetc", prefix, RB_PATH_SEPARATOR);
|
|
|
|
ircd_paths[IRCD_PATH_ETC] = rb_strdup(workbuf);
|
|
|
|
|
|
|
|
snprintf(workbuf, sizeof workbuf, "%s%clog", prefix, RB_PATH_SEPARATOR);
|
|
|
|
ircd_paths[IRCD_PATH_LOG] = rb_strdup(workbuf);
|
|
|
|
|
|
|
|
snprintf(workbuf, sizeof workbuf, "%s%chelp%cusers", prefix, RB_PATH_SEPARATOR, RB_PATH_SEPARATOR);
|
|
|
|
ircd_paths[IRCD_PATH_USERHELP] = rb_strdup(workbuf);
|
|
|
|
|
|
|
|
snprintf(workbuf, sizeof workbuf, "%s%chelp%copers", prefix, RB_PATH_SEPARATOR, RB_PATH_SEPARATOR);
|
|
|
|
ircd_paths[IRCD_PATH_OPERHELP] = rb_strdup(workbuf);
|
|
|
|
|
|
|
|
snprintf(workbuf, sizeof workbuf, "%s%cetc%circd.conf", prefix, RB_PATH_SEPARATOR, RB_PATH_SEPARATOR);
|
|
|
|
ircd_paths[IRCD_PATH_IRCD_CONF] = rb_strdup(workbuf);
|
|
|
|
|
|
|
|
snprintf(workbuf, sizeof workbuf, "%s%cetc%circd.motd", prefix, RB_PATH_SEPARATOR, RB_PATH_SEPARATOR);
|
|
|
|
ircd_paths[IRCD_PATH_IRCD_MOTD] = rb_strdup(workbuf);
|
|
|
|
|
|
|
|
snprintf(workbuf, sizeof workbuf, "%s%cetc%copers.motd", prefix, RB_PATH_SEPARATOR, RB_PATH_SEPARATOR);
|
|
|
|
ircd_paths[IRCD_PATH_IRCD_OMOTD] = rb_strdup(workbuf);
|
|
|
|
|
|
|
|
snprintf(workbuf, sizeof workbuf, "%s%cetc%cban.db", prefix, RB_PATH_SEPARATOR, RB_PATH_SEPARATOR);
|
|
|
|
ircd_paths[IRCD_PATH_BANDB] = rb_strdup(workbuf);
|
|
|
|
|
|
|
|
snprintf(workbuf, sizeof workbuf, "%s%cetc%circd.pid", prefix, RB_PATH_SEPARATOR, RB_PATH_SEPARATOR);
|
|
|
|
ircd_paths[IRCD_PATH_IRCD_PID] = rb_strdup(workbuf);
|
|
|
|
|
|
|
|
snprintf(workbuf, sizeof workbuf, "%s%clogs%circd.log", prefix, RB_PATH_SEPARATOR, RB_PATH_SEPARATOR);
|
|
|
|
ircd_paths[IRCD_PATH_IRCD_LOG] = rb_strdup(workbuf);
|
|
|
|
|
|
|
|
snprintf(workbuf, sizeof workbuf, "%s%cbin", prefix, RB_PATH_SEPARATOR);
|
|
|
|
ircd_paths[IRCD_PATH_BIN] = rb_strdup(workbuf);
|
|
|
|
ircd_paths[IRCD_PATH_LIBEXEC] = rb_strdup(workbuf);
|
2016-06-18 04:36:47 +00:00
|
|
|
|
2016-06-18 05:22:02 +00:00
|
|
|
inotice("runtime paths:");
|
2016-06-18 04:36:47 +00:00
|
|
|
for (int i = 0; i < IRCD_PATH_COUNT; i++)
|
|
|
|
{
|
|
|
|
inotice(" %s: %s", ircd_pathnames[i], ircd_paths[i]);
|
|
|
|
}
|
2016-03-25 06:57:25 +00:00
|
|
|
}
|
2016-06-18 06:05:38 +00:00
|
|
|
#endif
|
2007-01-25 06:40:21 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* write_pidfile
|
|
|
|
*
|
|
|
|
* inputs - filename+path of pid file
|
|
|
|
* output - none
|
|
|
|
* side effects - write the pid of the ircd to filename
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
write_pidfile(const char *filename)
|
|
|
|
{
|
|
|
|
FILE *fb;
|
|
|
|
char buff[32];
|
|
|
|
if((fb = fopen(filename, "w")))
|
|
|
|
{
|
|
|
|
unsigned int pid = (unsigned int) getpid();
|
|
|
|
|
2016-02-10 01:25:32 +00:00
|
|
|
snprintf(buff, sizeof(buff), "%u\n", pid);
|
2007-01-25 06:40:21 +00:00
|
|
|
if((fputs(buff, fb) == -1))
|
|
|
|
{
|
|
|
|
ilog(L_MAIN, "Error writing %u to pid file %s (%s)",
|
|
|
|
pid, filename, strerror(errno));
|
|
|
|
}
|
|
|
|
fclose(fb);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ilog(L_MAIN, "Error opening pid file %s", filename);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* check_pidfile
|
|
|
|
*
|
|
|
|
* inputs - filename+path of pid file
|
|
|
|
* output - none
|
|
|
|
* side effects - reads pid from pidfile and checks if ircd is in process
|
|
|
|
* list. if it is, gracefully exits
|
|
|
|
* -kre
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
check_pidfile(const char *filename)
|
|
|
|
{
|
|
|
|
FILE *fb;
|
|
|
|
char buff[32];
|
|
|
|
pid_t pidfromfile;
|
|
|
|
|
|
|
|
/* Don't do logging here, since we don't have log() initialised */
|
|
|
|
if((fb = fopen(filename, "r")))
|
|
|
|
{
|
|
|
|
if(fgets(buff, 20, fb) != NULL)
|
|
|
|
{
|
|
|
|
pidfromfile = atoi(buff);
|
2016-03-20 07:03:32 +00:00
|
|
|
if(!rb_kill(pidfromfile, 0))
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
|
|
|
printf("ircd: daemon is already running\n");
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fclose(fb);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* setup_corefile
|
|
|
|
*
|
|
|
|
* inputs - nothing
|
|
|
|
* output - nothing
|
|
|
|
* side effects - setups corefile to system limits.
|
|
|
|
* -kre
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
setup_corefile(void)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_SYS_RESOURCE_H
|
|
|
|
struct rlimit rlim; /* resource limits */
|
|
|
|
|
|
|
|
/* Set corefilesize to maximum */
|
|
|
|
if(!getrlimit(RLIMIT_CORE, &rlim))
|
|
|
|
{
|
|
|
|
rlim.rlim_cur = rlim.rlim_max;
|
|
|
|
setrlimit(RLIMIT_CORE, &rlim);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2008-07-28 19:02:54 +00:00
|
|
|
static void
|
|
|
|
ircd_log_cb(const char *str)
|
|
|
|
{
|
2016-03-06 09:49:27 +00:00
|
|
|
ilog(L_MAIN, "librb reports: %s", str);
|
2008-07-28 19:02:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ircd_restart_cb(const char *str)
|
|
|
|
{
|
2016-03-06 09:49:27 +00:00
|
|
|
inotice("librb has called the restart callback: %s", str);
|
2008-07-28 19:02:54 +00:00
|
|
|
restart(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Why EXIT_FAILURE here?
|
|
|
|
* Because if ircd_die_cb() is called it's because of a fatal
|
|
|
|
* error inside libcharybdis, and we don't know how to handle the
|
|
|
|
* exception, so it is logical to return a FAILURE exit code here.
|
|
|
|
* --nenolod
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
ircd_die_cb(const char *str)
|
|
|
|
{
|
|
|
|
if(str != NULL)
|
|
|
|
{
|
|
|
|
/* Try to get the message out to currently logged in operators. */
|
2016-03-06 09:49:27 +00:00
|
|
|
sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, "librb has called the die callback..aborting: %s", str);
|
|
|
|
inotice("librb has called the die callback..aborting: %s", str);
|
2008-07-28 19:02:54 +00:00
|
|
|
}
|
2008-08-06 19:12:02 +00:00
|
|
|
else
|
2016-03-06 09:49:27 +00:00
|
|
|
inotice("librb has called the die callback..aborting");
|
2008-07-28 19:02:54 +00:00
|
|
|
|
|
|
|
unlink(pidFileName);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2008-04-01 21:25:22 +00:00
|
|
|
struct ev_entry *check_splitmode_ev = NULL;
|
|
|
|
|
2008-04-20 04:26:14 +00:00
|
|
|
static int
|
|
|
|
seed_with_urandom(void)
|
|
|
|
{
|
|
|
|
unsigned int seed;
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
fd = open("/dev/urandom", O_RDONLY);
|
|
|
|
if(fd >= 0)
|
|
|
|
{
|
|
|
|
if(read(fd, &seed, sizeof(seed)) == sizeof(seed))
|
|
|
|
{
|
|
|
|
close(fd);
|
|
|
|
srand(seed);
|
|
|
|
return 1;
|
|
|
|
}
|
2014-03-09 13:54:45 +00:00
|
|
|
close(fd);
|
2008-04-20 04:26:14 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
seed_with_clock(void)
|
|
|
|
{
|
2014-03-03 04:25:47 +00:00
|
|
|
const struct timeval *tv;
|
2008-04-20 04:26:14 +00:00
|
|
|
rb_set_time();
|
|
|
|
tv = rb_current_time_tv();
|
|
|
|
srand(tv->tv_sec ^ (tv->tv_usec | (getpid() << 20)));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
seed_random(void *unused)
|
|
|
|
{
|
|
|
|
unsigned int seed;
|
|
|
|
if(rb_get_random(&seed, sizeof(seed)) == -1)
|
|
|
|
{
|
|
|
|
if(!seed_with_urandom())
|
|
|
|
seed_with_clock();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
srand(seed);
|
|
|
|
}
|
|
|
|
|
2007-01-25 06:40:21 +00:00
|
|
|
/*
|
|
|
|
* main
|
|
|
|
*
|
|
|
|
* Initializes the IRCd.
|
|
|
|
*
|
|
|
|
* Inputs - number of commandline args, args themselves
|
|
|
|
* Outputs - none
|
|
|
|
* Side Effects - this is where the ircd gets going right now
|
|
|
|
*/
|
|
|
|
int
|
2016-04-25 22:21:38 +00:00
|
|
|
charybdis_main(int argc, char * const argv[])
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
|
2016-03-20 07:04:26 +00:00
|
|
|
#ifndef _WIN32
|
2007-01-25 06:40:21 +00:00
|
|
|
/* Check to see if the user is running us as root, which is a nono */
|
|
|
|
if(geteuid() == 0)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Don't run ircd as root!!!\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2016-03-20 07:04:26 +00:00
|
|
|
#endif
|
2007-01-25 06:40:21 +00:00
|
|
|
|
2016-06-18 06:05:38 +00:00
|
|
|
#ifdef _WIN32
|
2016-03-25 06:57:25 +00:00
|
|
|
relocate_paths();
|
2016-06-18 06:05:38 +00:00
|
|
|
#endif
|
2008-07-28 19:14:51 +00:00
|
|
|
|
2016-03-25 05:00:06 +00:00
|
|
|
logFileName = ircd_paths[IRCD_PATH_IRCD_LOG];
|
|
|
|
pidFileName = ircd_paths[IRCD_PATH_IRCD_PID];
|
|
|
|
|
2016-03-24 23:45:28 +00:00
|
|
|
ConfigFileEntry.dpath = ircd_paths[IRCD_PATH_PREFIX];
|
|
|
|
ConfigFileEntry.configfile = ircd_paths[IRCD_PATH_IRCD_CONF]; /* Server configuration file */
|
2008-07-30 12:48:39 +00:00
|
|
|
ConfigFileEntry.connect_timeout = 30; /* Default to 30 */
|
2012-02-04 07:47:46 +00:00
|
|
|
|
2016-03-25 06:57:25 +00:00
|
|
|
init_sys();
|
|
|
|
|
2008-07-30 12:48:39 +00:00
|
|
|
umask(077); /* better safe than sorry --SRB */
|
2008-07-28 19:14:51 +00:00
|
|
|
|
|
|
|
myargv = argv;
|
|
|
|
parseargs(&argc, &argv, myopts);
|
|
|
|
|
|
|
|
if(chdir(ConfigFileEntry.dpath))
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Unable to chdir to %s: %s\n", ConfigFileEntry.dpath, strerror(errno));
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2008-06-28 10:36:25 +00:00
|
|
|
rb_set_time();
|
|
|
|
|
2007-01-25 06:40:21 +00:00
|
|
|
/*
|
|
|
|
* Setup corefile size immediately after boot -kre
|
|
|
|
*/
|
|
|
|
setup_corefile();
|
|
|
|
|
2016-01-09 07:08:15 +00:00
|
|
|
/* initialise operhash fairly early. */
|
|
|
|
init_operhash();
|
|
|
|
|
2007-01-25 06:40:21 +00:00
|
|
|
memset(&me, 0, sizeof(me));
|
|
|
|
memset(&meLocalUser, 0, sizeof(meLocalUser));
|
|
|
|
me.localClient = &meLocalUser;
|
|
|
|
|
|
|
|
/* Make sure all lists are zeroed */
|
|
|
|
memset(&unknown_list, 0, sizeof(unknown_list));
|
|
|
|
memset(&lclient_list, 0, sizeof(lclient_list));
|
|
|
|
memset(&serv_list, 0, sizeof(serv_list));
|
|
|
|
memset(&global_serv_list, 0, sizeof(global_serv_list));
|
|
|
|
memset(&local_oper_list, 0, sizeof(local_oper_list));
|
|
|
|
memset(&oper_list, 0, sizeof(oper_list));
|
|
|
|
|
2008-04-01 20:41:52 +00:00
|
|
|
rb_dlinkAddTail(&me, &me.node, &global_client_list);
|
2007-01-25 06:40:21 +00:00
|
|
|
|
2008-04-05 18:02:59 +00:00
|
|
|
memset(&Count, 0, sizeof(Count));
|
|
|
|
memset(&ServerInfo, 0, sizeof(ServerInfo));
|
|
|
|
memset(&AdminInfo, 0, sizeof(AdminInfo));
|
|
|
|
memset(&ServerStats, 0, sizeof(struct ServerStatistics));
|
2007-01-25 06:40:21 +00:00
|
|
|
|
|
|
|
if(printVersion)
|
|
|
|
{
|
2008-04-22 21:41:16 +00:00
|
|
|
printf("ircd: version %s(%s)\n", ircd_version, serno);
|
2011-05-08 14:11:50 +00:00
|
|
|
#ifdef CUSTOM_BRANDING
|
|
|
|
printf("ircd: based on %s-%s\n", PACKAGE_NAME, PACKAGE_VERSION);
|
|
|
|
#endif
|
2008-12-22 09:58:33 +00:00
|
|
|
printf("ircd: %s\n", rb_lib_version());
|
2007-01-25 06:40:21 +00:00
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
setup_signals();
|
|
|
|
|
|
|
|
if (testing_conf)
|
2016-03-09 08:19:31 +00:00
|
|
|
server_state_foreground = true;
|
2007-01-25 06:40:21 +00:00
|
|
|
|
2016-03-20 08:10:05 +00:00
|
|
|
#ifndef _WIN32
|
2007-01-25 06:40:21 +00:00
|
|
|
/* Make sure fd 0, 1 and 2 are in use -- jilles */
|
|
|
|
do
|
|
|
|
{
|
|
|
|
fd = open("/dev/null", O_RDWR);
|
|
|
|
} while (fd < 2 && fd != -1);
|
|
|
|
if (fd > 2)
|
|
|
|
close(fd);
|
|
|
|
else if (fd == -1)
|
|
|
|
exit(1);
|
2016-03-20 08:10:05 +00:00
|
|
|
#endif
|
2007-01-25 06:40:21 +00:00
|
|
|
|
|
|
|
/* Check if there is pidfile and daemon already running */
|
|
|
|
if(!testing_conf)
|
|
|
|
{
|
|
|
|
check_pidfile(pidFileName);
|
|
|
|
|
|
|
|
if(!server_state_foreground)
|
|
|
|
make_daemon();
|
|
|
|
inotice("starting %s ...", ircd_version);
|
2008-12-22 20:50:21 +00:00
|
|
|
inotice("%s", rb_lib_version());
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Init the event subsystem */
|
2008-04-02 01:47:12 +00:00
|
|
|
rb_lib_init(ircd_log_cb, ircd_restart_cb, ircd_die_cb, !server_state_foreground, maxconnections, DNODE_HEAP_SIZE, FD_HEAP_SIZE);
|
2008-04-02 23:40:32 +00:00
|
|
|
rb_linebuf_init(LINEBUF_HEAP_SIZE);
|
2007-01-25 06:40:21 +00:00
|
|
|
|
2015-03-01 07:05:14 +00:00
|
|
|
rb_init_prng(NULL, RB_PRNG_DEFAULT);
|
2008-08-16 18:29:33 +00:00
|
|
|
|
2008-08-16 18:30:28 +00:00
|
|
|
seed_random(NULL);
|
|
|
|
|
2012-02-04 07:47:46 +00:00
|
|
|
init_builtin_capabs();
|
|
|
|
default_server_capabs = CAP_MASK;
|
|
|
|
|
2007-01-25 06:40:21 +00:00
|
|
|
init_main_logfile();
|
|
|
|
newconf_init();
|
|
|
|
init_s_conf();
|
|
|
|
init_s_newconf();
|
|
|
|
init_hash();
|
|
|
|
clear_scache_hash_table(); /* server cache name table */
|
|
|
|
init_host_hash();
|
|
|
|
clear_hash_parse();
|
|
|
|
init_client();
|
|
|
|
init_hook();
|
|
|
|
init_channels();
|
|
|
|
initclass();
|
2016-01-23 16:16:34 +00:00
|
|
|
whowas_init();
|
2007-01-25 06:40:21 +00:00
|
|
|
init_reject();
|
|
|
|
init_cache();
|
|
|
|
init_monitor();
|
2010-03-07 20:45:42 +00:00
|
|
|
|
2010-03-31 23:16:16 +00:00
|
|
|
construct_cflags_strings();
|
2010-03-07 20:45:42 +00:00
|
|
|
|
2016-01-08 11:20:09 +00:00
|
|
|
init_authd(); /* Start up authd. */
|
2016-03-13 08:23:41 +00:00
|
|
|
init_dns(); /* Start up DNS query system */
|
2016-06-18 05:38:40 +00:00
|
|
|
init_modules(); /* Start up modules system */
|
2016-03-08 09:22:25 +00:00
|
|
|
|
2008-08-17 13:06:28 +00:00
|
|
|
privilegeset_set_new("default", "", 0);
|
2007-01-25 06:40:21 +00:00
|
|
|
|
|
|
|
if (testing_conf)
|
|
|
|
fprintf(stderr, "\nBeginning config test\n");
|
2016-03-08 19:52:48 +00:00
|
|
|
read_conf_files(true); /* cold start init conf files */
|
2007-01-25 06:40:21 +00:00
|
|
|
|
2016-04-06 12:43:45 +00:00
|
|
|
load_all_modules(1);
|
|
|
|
load_core_modules(1);
|
2007-01-25 06:40:21 +00:00
|
|
|
|
2011-11-29 22:10:21 +00:00
|
|
|
init_isupport();
|
|
|
|
|
2010-01-07 23:22:44 +00:00
|
|
|
init_bandb();
|
2008-04-06 14:52:42 +00:00
|
|
|
init_ssld();
|
2016-04-02 07:56:03 +00:00
|
|
|
init_wsockd();
|
2008-04-06 14:52:42 +00:00
|
|
|
|
2016-03-23 13:52:32 +00:00
|
|
|
rehash_bans();
|
2010-01-08 00:06:15 +00:00
|
|
|
|
2007-01-25 06:40:21 +00:00
|
|
|
initialize_server_capabs(); /* Set up default_server_capabs */
|
|
|
|
initialize_global_set_options();
|
|
|
|
|
|
|
|
if(ServerInfo.name == NULL)
|
|
|
|
{
|
|
|
|
ierror("no server name specified in serverinfo block.");
|
|
|
|
return -1;
|
|
|
|
}
|
2008-04-20 04:40:40 +00:00
|
|
|
rb_strlcpy(me.name, ServerInfo.name, sizeof(me.name));
|
2007-01-25 06:40:21 +00:00
|
|
|
|
|
|
|
if(ServerInfo.sid[0] == '\0')
|
|
|
|
{
|
|
|
|
ierror("no server sid specified in serverinfo block.");
|
|
|
|
return -2;
|
|
|
|
}
|
2016-05-15 03:57:16 +00:00
|
|
|
rb_strlcpy(me.id, ServerInfo.sid, sizeof(me.id));
|
2007-01-25 06:40:21 +00:00
|
|
|
init_uid();
|
|
|
|
|
|
|
|
/* serverinfo{} description must exist. If not, error out. */
|
|
|
|
if(ServerInfo.description == NULL)
|
|
|
|
{
|
|
|
|
ierror("no server description specified in serverinfo block.");
|
|
|
|
return -3;
|
|
|
|
}
|
2008-04-20 04:40:40 +00:00
|
|
|
rb_strlcpy(me.info, ServerInfo.description, sizeof(me.info));
|
2007-01-25 06:40:21 +00:00
|
|
|
|
2016-05-05 04:10:57 +00:00
|
|
|
if(ServerInfo.ssl_cert != NULL)
|
2008-04-13 15:54:23 +00:00
|
|
|
{
|
|
|
|
/* just do the rb_setup_ssl_server to validate the config */
|
2015-12-12 13:50:48 +00:00
|
|
|
if(!rb_setup_ssl_server(ServerInfo.ssl_cert, ServerInfo.ssl_private_key, ServerInfo.ssl_dh_params, ServerInfo.ssl_cipher_list))
|
2008-04-13 15:54:23 +00:00
|
|
|
{
|
|
|
|
ilog(L_MAIN, "WARNING: Unable to setup SSL.");
|
2016-03-19 05:57:32 +00:00
|
|
|
ircd_ssl_ok = false;
|
2008-04-13 15:54:23 +00:00
|
|
|
}
|
|
|
|
else
|
2016-03-19 05:57:32 +00:00
|
|
|
ircd_ssl_ok = true;
|
2008-04-06 14:52:42 +00:00
|
|
|
}
|
|
|
|
|
2007-01-25 06:40:21 +00:00
|
|
|
if (testing_conf)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "\nConfig testing complete.\n");
|
|
|
|
fflush(stderr);
|
|
|
|
return 0; /* Why? We want the launcher to exit out. */
|
|
|
|
}
|
|
|
|
|
|
|
|
me.from = &me;
|
|
|
|
me.servptr = &me;
|
|
|
|
SetMe(&me);
|
|
|
|
make_server(&me);
|
2008-04-01 23:53:20 +00:00
|
|
|
startup_time = rb_current_time();
|
2007-01-25 06:40:21 +00:00
|
|
|
add_to_client_hash(me.name, &me);
|
|
|
|
add_to_id_hash(me.id, &me);
|
2007-11-23 21:11:25 +00:00
|
|
|
me.serv->nameinfo = scache_connect(me.name, me.info, 0);
|
2007-01-25 06:40:21 +00:00
|
|
|
|
2008-04-01 20:41:52 +00:00
|
|
|
rb_dlinkAddAlloc(&me, &global_serv_list);
|
2007-01-25 06:40:21 +00:00
|
|
|
|
|
|
|
construct_umodebuf();
|
|
|
|
|
|
|
|
check_class();
|
|
|
|
write_pidfile(pidFileName);
|
|
|
|
load_help();
|
|
|
|
open_logfiles();
|
|
|
|
|
2016-03-28 21:47:51 +00:00
|
|
|
configure_authd();
|
|
|
|
|
2007-01-25 06:40:21 +00:00
|
|
|
ilog(L_MAIN, "Server Ready");
|
|
|
|
|
|
|
|
/* We want try_connections to be called as soon as possible now! -- adrian */
|
|
|
|
/* No, 'cause after a restart it would cause all sorts of nick collides */
|
|
|
|
/* um. by waiting even longer, that just means we have even *more*
|
|
|
|
* nick collisions. what a stupid idea. set an event for the IO loop --fl
|
|
|
|
*/
|
2008-04-02 01:43:35 +00:00
|
|
|
rb_event_addish("try_connections", try_connections, NULL, STARTUP_CONNECTIONS_TIME);
|
2008-06-28 10:50:21 +00:00
|
|
|
rb_event_addonce("try_connections_startup", try_connections, NULL, 2);
|
|
|
|
rb_event_add("check_rehash", check_rehash, NULL, 3);
|
2008-04-20 04:26:14 +00:00
|
|
|
rb_event_addish("reseed_srand", seed_random, NULL, 300); /* reseed every 10 minutes */
|
2007-01-25 06:40:21 +00:00
|
|
|
|
|
|
|
if(splitmode)
|
2008-06-28 10:50:21 +00:00
|
|
|
check_splitmode_ev = rb_event_add("check_splitmode", check_splitmode, NULL, 5);
|
2007-01-25 06:40:21 +00:00
|
|
|
|
|
|
|
print_startup(getpid());
|
|
|
|
|
2008-04-08 14:09:32 +00:00
|
|
|
rb_lib_loop(0);
|
2007-01-25 06:40:21 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|