2012-04-19 20:58:29 +02:00
|
|
|
/*
|
|
|
|
* InspIRCd -- Internet Relay Chat Daemon
|
2007-07-16 17:30:04 +00:00
|
|
|
*
|
2020-01-11 22:02:47 +00:00
|
|
|
* Copyright (C) 2019 Matt Schatz <genius3000@g3k.solutions>
|
2021-12-30 18:52:08 +00:00
|
|
|
* Copyright (C) 2018 Chris Novakovic
|
2020-01-11 22:02:47 +00:00
|
|
|
* Copyright (C) 2013-2014, 2016 Attila Molnar <attilamolnar@hush.com>
|
|
|
|
* Copyright (C) 2013 Daniel Vassdal <shutter@canternet.org>
|
2022-04-28 18:49:16 +01:00
|
|
|
* Copyright (C) 2012-2014, 2016-2022 Sadie Powell <sadie@witchery.services>
|
2020-01-11 22:02:47 +00:00
|
|
|
* Copyright (C) 2012, 2019 Robby <robby@chatbelgie.be>
|
|
|
|
* Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
|
|
|
|
* Copyright (C) 2008 Thomas Stagner <aquanight@inspircd.org>
|
|
|
|
* Copyright (C) 2007-2008 Robin Burchell <robin+git@viroteck.net>
|
|
|
|
* Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
|
2021-03-05 02:04:16 +00:00
|
|
|
* Copyright (C) 2006-2008 Craig Edwards <brain@inspircd.org>
|
|
|
|
* Copyright (C) 2006 Oliver Lupton <om@inspircd.org>
|
2007-07-16 17:30:04 +00:00
|
|
|
*
|
2012-04-19 20:58:29 +02:00
|
|
|
* This file is part of InspIRCd. InspIRCd 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, version 2.
|
2007-07-16 17:30:04 +00:00
|
|
|
*
|
2012-04-19 20:58:29 +02:00
|
|
|
* 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, see <http://www.gnu.org/licenses/>.
|
2007-07-16 17:30:04 +00:00
|
|
|
*/
|
|
|
|
|
2012-04-19 20:58:29 +02:00
|
|
|
|
2013-04-02 20:12:15 +01:00
|
|
|
#pragma once
|
2007-07-16 17:30:04 +00:00
|
|
|
|
|
|
|
#include "inspircd.h"
|
2022-05-21 16:55:11 +01:00
|
|
|
#include "inspstring.h"
|
2007-07-16 17:30:04 +00:00
|
|
|
|
2022-01-18 16:39:27 +00:00
|
|
|
/** Represents the position within a file. */
|
|
|
|
class CoreExport FilePosition final
|
|
|
|
{
|
2022-01-25 13:59:42 +00:00
|
|
|
public:
|
2022-01-18 16:39:27 +00:00
|
|
|
/** The name of the file that the position points to. */
|
|
|
|
std::string name;
|
|
|
|
|
|
|
|
/** The line of the file that this position points to. */
|
|
|
|
unsigned long line;
|
|
|
|
|
|
|
|
/** The column of the file that this position points to. */
|
|
|
|
unsigned long column;
|
|
|
|
|
|
|
|
/** Initialises a new file position with the specified name, line, and column.
|
|
|
|
* @param Name The name of the file that the position points to.
|
|
|
|
* @param Line The line of the file that this position points to.
|
|
|
|
* @param Column The column of the file that this position points to.
|
|
|
|
*/
|
|
|
|
FilePosition(const std::string& Name, unsigned long Line, unsigned long Column);
|
|
|
|
|
|
|
|
/** Returns a string that represents this file position. */
|
|
|
|
std::string str() const;
|
|
|
|
};
|
|
|
|
|
2012-07-05 21:00:35 +01:00
|
|
|
/** Structure representing a single \<tag> in config */
|
2021-12-20 20:00:03 +00:00
|
|
|
class CoreExport ConfigTag final
|
2008-03-23 20:43:35 +00:00
|
|
|
{
|
2020-11-03 18:43:19 +00:00
|
|
|
public:
|
|
|
|
/** A mapping of configuration keys to their assigned values. */
|
|
|
|
typedef insp::flat_map<std::string, std::string, irc::insensitive_swo> Items;
|
|
|
|
|
2022-01-25 13:59:42 +00:00
|
|
|
private:
|
2020-11-03 18:43:19 +00:00
|
|
|
Items items;
|
2020-10-31 23:21:15 +00:00
|
|
|
|
2022-01-25 13:59:42 +00:00
|
|
|
public:
|
2021-05-11 03:53:43 +01:00
|
|
|
/** The name of the configuration tag (e.g. "foo" for \<foo bar="baz">). */
|
2020-11-03 19:57:39 +00:00
|
|
|
const std::string name;
|
2020-11-03 19:40:42 +00:00
|
|
|
|
|
|
|
/** The position within the source file that this tag was read from. */
|
|
|
|
const FilePosition source;
|
2008-10-18 16:52:48 +00:00
|
|
|
|
2020-11-03 19:01:53 +00:00
|
|
|
/** Creates a new ConfigTag instance with the specified tag name, file, and line.
|
2020-11-03 19:57:39 +00:00
|
|
|
* @param Name The name of this config tag (e.g. "foo" for \<foo bar="baz">).
|
2020-11-03 19:40:42 +00:00
|
|
|
* @param Source The source of this config tag.
|
2020-11-03 19:01:53 +00:00
|
|
|
*/
|
2020-11-03 19:57:39 +00:00
|
|
|
ConfigTag(const std::string& Name, const FilePosition& Source);
|
2020-11-03 19:01:53 +00:00
|
|
|
|
2018-06-29 11:26:51 +01:00
|
|
|
/** Get the value of an option, using def if it does not exist */
|
2020-04-12 05:52:10 +01:00
|
|
|
std::string getString(const std::string& key, const std::string& def, const std::function<bool(const std::string&)>& validator) const;
|
2009-10-22 22:29:35 +00:00
|
|
|
/** Get the value of an option, using def if it does not exist */
|
2020-04-12 05:52:10 +01:00
|
|
|
std::string getString(const std::string& key, const std::string& def = "", size_t minlen = 0, size_t maxlen = UINT32_MAX) const;
|
2009-10-22 22:29:35 +00:00
|
|
|
/** Get the value of an option, using def if it does not exist */
|
2020-04-12 05:52:10 +01:00
|
|
|
long getInt(const std::string& key, long def, long min = LONG_MIN, long max = LONG_MAX) const;
|
2009-10-22 22:29:35 +00:00
|
|
|
/** Get the value of an option, using def if it does not exist */
|
2020-04-12 05:52:10 +01:00
|
|
|
unsigned long getUInt(const std::string& key, unsigned long def, unsigned long min = 0, unsigned long max = ULONG_MAX) const;
|
2018-04-14 15:43:03 +01:00
|
|
|
/** Get the value of an option, using def if it does not exist */
|
2020-04-12 05:52:10 +01:00
|
|
|
double getFloat(const std::string& key, double def, double min = DBL_MIN, double max = DBL_MAX) const;
|
2009-10-22 22:29:35 +00:00
|
|
|
/** Get the value of an option, using def if it does not exist */
|
2020-04-12 05:52:10 +01:00
|
|
|
bool getBool(const std::string& key, bool def = false) const;
|
2022-04-10 23:43:43 +01:00
|
|
|
/** Get the value of an option, using def if it does not exist */
|
2022-04-16 16:16:29 +01:00
|
|
|
unsigned char getCharacter(const std::string& key, unsigned char def = '\0') const;
|
2008-10-18 16:52:48 +00:00
|
|
|
|
2013-08-12 19:20:18 +02:00
|
|
|
/** Get the value in seconds of a duration that is in the user-friendly "1h2m3s" format,
|
|
|
|
* using a default value if it does not exist or is out of bounds.
|
|
|
|
* @param key The config key name
|
|
|
|
* @param def Default value (optional)
|
|
|
|
* @param min Minimum acceptable value (optional)
|
|
|
|
* @param max Maximum acceptable value (optional)
|
|
|
|
* @return The duration in seconds
|
|
|
|
*/
|
2020-04-12 05:52:10 +01:00
|
|
|
unsigned long getDuration(const std::string& key, unsigned long def, unsigned long min = 0, unsigned long max = ULONG_MAX) const;
|
2013-08-12 19:20:18 +02:00
|
|
|
|
2020-05-13 14:09:38 +01:00
|
|
|
template<typename TReturn>
|
|
|
|
TReturn getEnum(const std::string& key, TReturn def, std::initializer_list<std::pair<const char*, TReturn>> enumvals)
|
|
|
|
{
|
|
|
|
const std::string val = getString(key);
|
|
|
|
if (val.empty())
|
|
|
|
return def;
|
|
|
|
|
2022-06-25 17:58:11 +01:00
|
|
|
for (const auto& [enumkey, enumval] : enumvals)
|
|
|
|
if (stdalgo::string::equalsci(val, enumkey))
|
|
|
|
return enumval;
|
|
|
|
|
|
|
|
// Unfortunately we have to iterate this twice.
|
|
|
|
std::string enumdef = "(unknown)";
|
|
|
|
std::string enumkeys;
|
|
|
|
for (const auto& [enumkey, enumval] : enumvals)
|
|
|
|
{
|
|
|
|
enumkeys.append(enumkey).append(", ");
|
|
|
|
if (enumval == def)
|
|
|
|
enumdef = enumkey;
|
|
|
|
}
|
|
|
|
if (!enumkeys.empty())
|
|
|
|
enumkeys.erase(enumkeys.length() - 2);
|
|
|
|
|
|
|
|
LogMalformed(key, val, enumdef, "not one of " + enumkeys);
|
|
|
|
return def;
|
2020-05-13 14:09:38 +01:00
|
|
|
}
|
|
|
|
|
2009-10-22 22:29:35 +00:00
|
|
|
/** Get the value of an option
|
|
|
|
* @param key The option to get
|
|
|
|
* @param value The location to store the value (unmodified if does not exist)
|
|
|
|
* @param allow_newline Allow newlines in the option (normally replaced with spaces)
|
|
|
|
* @return true if the option exists
|
|
|
|
*/
|
2020-04-12 05:52:10 +01:00
|
|
|
bool readString(const std::string& key, std::string& value, bool allow_newline = false) const;
|
2009-10-17 17:53:22 +00:00
|
|
|
|
2020-11-03 19:01:53 +00:00
|
|
|
/** Retrieves the underlying map of config entries. */
|
2020-11-03 18:43:19 +00:00
|
|
|
inline const Items& GetItems() const { return items; }
|
2020-11-03 19:01:53 +00:00
|
|
|
inline Items& GetItems() { return items; }
|
2022-06-25 17:05:35 +01:00
|
|
|
|
|
|
|
/** @internal Logs that the value of a config field is malformed. */
|
|
|
|
void LogMalformed(const std::string& key, const std::string& val, const std::string& def, const std::string& reason) const;
|
2008-03-23 20:43:35 +00:00
|
|
|
};
|
|
|
|
|
2008-09-20 20:53:04 +00:00
|
|
|
/** Defines the server's length limits on various length-limited
|
|
|
|
* items such as topics, nicknames, channel names etc.
|
|
|
|
*/
|
2021-12-20 20:00:03 +00:00
|
|
|
class ServerLimits final
|
2008-05-25 17:30:43 +00:00
|
|
|
{
|
2022-01-25 13:59:42 +00:00
|
|
|
public:
|
2020-09-30 17:21:52 +01:00
|
|
|
/** Maximum line length */
|
|
|
|
size_t MaxLine;
|
2008-09-20 20:53:04 +00:00
|
|
|
/** Maximum nickname length */
|
2020-11-27 12:30:06 +00:00
|
|
|
size_t MaxNick;
|
2008-09-20 20:53:04 +00:00
|
|
|
/** Maximum channel length */
|
2020-11-27 12:36:44 +00:00
|
|
|
size_t MaxChannel;
|
2008-09-20 20:53:04 +00:00
|
|
|
/** Maximum number of modes per line */
|
2008-05-25 17:30:43 +00:00
|
|
|
size_t MaxModes;
|
2020-11-27 12:27:48 +00:00
|
|
|
/** Maximum length of a username (ident) */
|
|
|
|
size_t MaxUser;
|
2008-09-20 20:53:04 +00:00
|
|
|
/** Maximum length of a quit message */
|
2008-05-25 17:30:43 +00:00
|
|
|
size_t MaxQuit;
|
2008-09-20 20:53:04 +00:00
|
|
|
/** Maximum topic length */
|
2008-05-25 17:30:43 +00:00
|
|
|
size_t MaxTopic;
|
2008-09-20 20:53:04 +00:00
|
|
|
/** Maximum kick message length */
|
2008-05-25 17:30:43 +00:00
|
|
|
size_t MaxKick;
|
2018-07-30 18:30:11 +01:00
|
|
|
/** Maximum real name length */
|
|
|
|
size_t MaxReal;
|
2008-09-20 20:53:04 +00:00
|
|
|
/** Maximum away message length */
|
2008-05-25 17:30:43 +00:00
|
|
|
size_t MaxAway;
|
2014-03-06 21:43:36 +00:00
|
|
|
/** Maximum hostname length */
|
|
|
|
size_t MaxHost;
|
2008-05-25 17:30:43 +00:00
|
|
|
|
2014-12-09 12:35:31 +01:00
|
|
|
/** Read all limits from a config tag. Limits which aren't specified in the tag are set to a default value.
|
|
|
|
* @param tag Configuration tag to read the limits from
|
|
|
|
*/
|
2023-01-10 20:57:56 +00:00
|
|
|
ServerLimits(const std::shared_ptr<ConfigTag>& tag);
|
2016-07-22 11:26:11 +01:00
|
|
|
|
2017-08-25 13:03:53 +01:00
|
|
|
/** Maximum length of a n!u\@h mask */
|
2020-11-27 12:30:06 +00:00
|
|
|
size_t GetMaxMask() const { return MaxNick + 1 + MaxUser + 1 + MaxHost; }
|
2008-05-25 17:30:43 +00:00
|
|
|
};
|
|
|
|
|
2021-12-20 20:00:03 +00:00
|
|
|
struct CommandLineConf final
|
2009-10-21 23:46:24 +00:00
|
|
|
{
|
|
|
|
/** If this value is true, the owner of the
|
|
|
|
* server specified -nofork on the command
|
|
|
|
* line, causing the daemon to stay in the
|
|
|
|
* foreground.
|
|
|
|
*/
|
|
|
|
bool nofork;
|
|
|
|
|
|
|
|
/** If this value if true then all log
|
|
|
|
* messages will be output, regardless of
|
|
|
|
* the level given in the config file.
|
|
|
|
* This is set with the -debug commandline
|
|
|
|
* option.
|
|
|
|
*/
|
|
|
|
bool forcedebug;
|
|
|
|
|
|
|
|
/** If this is true then log output will be
|
|
|
|
* written to the logfile. This is the default.
|
|
|
|
* If you put -nolog on the commandline then
|
|
|
|
* the logfile will not be written.
|
|
|
|
* This is meant to be used in conjunction with
|
|
|
|
* -debug for debugging without filling up the
|
|
|
|
* hard disk.
|
|
|
|
*/
|
|
|
|
bool writelog;
|
|
|
|
|
2018-06-04 12:40:32 +01:00
|
|
|
/** If this is true, a PID file will be written
|
|
|
|
* to the file given in the "file" variable of
|
2018-10-21 19:18:08 +01:00
|
|
|
* the \<pid> tag in the config file. This is
|
2018-06-04 12:40:32 +01:00
|
|
|
* the default.
|
|
|
|
* Passing --nopid as a command line argument
|
|
|
|
* sets this to false; in this case, a PID file
|
|
|
|
* will not be written, even the default PID
|
2018-10-21 19:18:08 +01:00
|
|
|
* file that is usually written when the \<pid>
|
2018-06-04 12:40:32 +01:00
|
|
|
* tag is not defined in the config file.
|
|
|
|
*/
|
|
|
|
bool writepid;
|
|
|
|
|
2019-12-09 01:15:31 +00:00
|
|
|
/* Whether the --runasroot option was specified at boot. */
|
|
|
|
bool runasroot;
|
|
|
|
|
|
|
|
/** Saved argc from startup. */
|
2009-10-21 23:46:24 +00:00
|
|
|
int argc;
|
|
|
|
|
2019-12-09 01:15:31 +00:00
|
|
|
/** Saved argv from startup. */
|
2009-10-21 23:46:24 +00:00
|
|
|
char** argv;
|
|
|
|
};
|
|
|
|
|
2007-07-16 17:30:04 +00:00
|
|
|
/** This class holds the bulk of the runtime configuration for the ircd.
|
|
|
|
* It allows for reading new config values, accessing configuration files,
|
|
|
|
* and storage of the configuration data needed to run the ircd, such as
|
|
|
|
* the servername, connect classes, /ADMIN data, MOTDs and filenames etc.
|
|
|
|
*/
|
2021-12-20 20:00:03 +00:00
|
|
|
class CoreExport ServerConfig final
|
2007-07-16 17:30:04 +00:00
|
|
|
{
|
2022-01-25 13:59:42 +00:00
|
|
|
private:
|
2023-01-11 00:45:36 +00:00
|
|
|
void ApplyModules(User* user) const;
|
2009-08-12 18:03:52 +00:00
|
|
|
void CrossCheckConnectBlocks(ServerConfig* current);
|
2022-11-27 07:32:42 +00:00
|
|
|
void CrossCheckOperBlocks();
|
2021-05-13 15:29:39 +01:00
|
|
|
void Fill();
|
2009-08-12 18:03:52 +00:00
|
|
|
|
2022-01-25 13:59:42 +00:00
|
|
|
public:
|
2018-07-10 20:32:08 +01:00
|
|
|
/** How to treat a user in a channel who is banned. */
|
|
|
|
enum BannedUserTreatment
|
|
|
|
{
|
|
|
|
/** Don't treat a banned user any different to normal. */
|
|
|
|
BUT_NORMAL,
|
|
|
|
|
|
|
|
/** Restrict the actions of a banned user. */
|
|
|
|
BUT_RESTRICT_SILENT,
|
|
|
|
|
|
|
|
/** Restrict the actions of a banned user and notify them of their treatment. */
|
|
|
|
BUT_RESTRICT_NOTIFY
|
|
|
|
};
|
|
|
|
|
2022-01-15 23:36:33 +00:00
|
|
|
class CoreExport ServerPaths
|
2013-07-10 18:11:48 +01:00
|
|
|
{
|
2022-01-25 13:59:42 +00:00
|
|
|
private:
|
2022-01-15 22:45:11 +00:00
|
|
|
/** Expands a path fragment to a full path.
|
|
|
|
* @param base The base path to expand from
|
|
|
|
* @param fragment The path fragment to expand on top of base.
|
|
|
|
*/
|
|
|
|
static std::string ExpandPath(const std::string& base, const std::string& fragment);
|
|
|
|
|
2022-01-25 13:59:42 +00:00
|
|
|
public:
|
2013-07-10 18:11:48 +01:00
|
|
|
/** Config path */
|
|
|
|
std::string Config;
|
|
|
|
|
|
|
|
/** Data path */
|
|
|
|
std::string Data;
|
|
|
|
|
|
|
|
/** Log path */
|
|
|
|
std::string Log;
|
|
|
|
|
|
|
|
/** Module path */
|
|
|
|
std::string Module;
|
|
|
|
|
2021-01-18 06:56:18 +00:00
|
|
|
/** Runtime path */
|
|
|
|
std::string Runtime;
|
|
|
|
|
2023-01-10 20:57:56 +00:00
|
|
|
ServerPaths(const std::shared_ptr<ConfigTag>& tag);
|
2013-07-10 18:11:48 +01:00
|
|
|
|
2022-01-15 22:45:11 +00:00
|
|
|
inline std::string PrependConfig(const std::string& fn) const { return ExpandPath(Config, fn); }
|
|
|
|
inline std::string PrependData(const std::string& fn) const { return ExpandPath(Data, fn); }
|
|
|
|
inline std::string PrependLog(const std::string& fn) const { return ExpandPath(Log, fn); }
|
|
|
|
inline std::string PrependModule(const std::string& fn) const { return ExpandPath(Module, fn); }
|
|
|
|
inline std::string PrependRuntime(const std::string& fn) const { return ExpandPath(Runtime, fn); }
|
2013-07-10 18:11:48 +01:00
|
|
|
};
|
2009-10-21 23:44:27 +00:00
|
|
|
|
2014-07-16 12:30:05 +02:00
|
|
|
/** Holds a complete list of all connect blocks
|
|
|
|
*/
|
2023-01-08 16:12:43 +00:00
|
|
|
typedef std::vector<std::shared_ptr<ConnectClass>> ClassVector;
|
2014-07-16 12:30:05 +02:00
|
|
|
|
2022-11-27 07:32:42 +00:00
|
|
|
/** Holds the oper accounts from the server config. */
|
|
|
|
typedef insp::flat_map<std::string, std::shared_ptr<OperAccount>> OperAccountMap;
|
|
|
|
|
|
|
|
/** Holds the oper types from the server config. */
|
|
|
|
typedef insp::flat_map<std::string, std::shared_ptr<OperType>> OperTypeMap;
|
2014-07-16 12:32:47 +02:00
|
|
|
|
2020-11-03 22:30:58 +00:00
|
|
|
/** Holds the server config. */
|
|
|
|
typedef std::multimap<std::string, std::shared_ptr<ConfigTag>, irc::insensitive_swo> TagMap;
|
|
|
|
|
|
|
|
/** Holds iterators to a subsection of the server config map. */
|
2021-03-02 02:44:41 +00:00
|
|
|
typedef insp::iterator_range<TagMap::const_iterator> TagList;
|
2020-11-03 22:30:58 +00:00
|
|
|
|
2018-10-01 16:09:45 +01:00
|
|
|
/** Get a configuration tag by name. If one or more tags are present then the first is returned.
|
|
|
|
* @param tag The name of the tag to get.
|
2021-01-30 14:04:19 +00:00
|
|
|
* @param def The value to return if the tag doesn't exist.
|
2018-10-01 16:09:45 +01:00
|
|
|
* @returns Either a tag from the config or EmptyTag.
|
2009-10-21 23:44:27 +00:00
|
|
|
*/
|
2023-01-10 20:57:56 +00:00
|
|
|
const std::shared_ptr<ConfigTag>& ConfValue(const std::string& tag, const std::shared_ptr<ConfigTag>& def = nullptr) const;
|
2009-10-21 23:46:13 +00:00
|
|
|
|
2018-10-01 16:09:45 +01:00
|
|
|
/** Get a list of configuration tags by name.
|
|
|
|
* @param tag The name of the tags to get.
|
2021-01-30 14:04:19 +00:00
|
|
|
* @param def The value to return if the tag doesn't exist.
|
2020-11-03 22:30:58 +00:00
|
|
|
* @returns Either a list of tags from the config or an empty TagList.
|
2018-10-01 16:09:45 +01:00
|
|
|
*/
|
2022-09-03 22:52:53 +01:00
|
|
|
TagList ConfTags(const std::string& tag, std::optional<TagList> def = std::nullopt) const;
|
2009-10-21 23:44:27 +00:00
|
|
|
|
2014-10-08 16:34:37 +01:00
|
|
|
/** An empty configuration tag. */
|
2020-10-31 23:21:15 +00:00
|
|
|
std::shared_ptr<ConfigTag> EmptyTag;
|
2014-10-08 16:34:37 +01:00
|
|
|
|
2008-09-20 20:53:04 +00:00
|
|
|
/** Error stream, contains error output from any failed configuration parsing.
|
|
|
|
*/
|
2009-07-01 22:55:54 +00:00
|
|
|
std::stringstream errstr;
|
2007-11-11 23:09:09 +00:00
|
|
|
|
2009-07-01 22:55:46 +00:00
|
|
|
/** True if this configuration is valid enough to run with */
|
|
|
|
bool valid;
|
2007-11-11 23:09:09 +00:00
|
|
|
|
2010-02-23 18:45:26 +00:00
|
|
|
/** Bind to IPv6 by default */
|
|
|
|
bool WildcardIPv6;
|
|
|
|
|
2018-03-31 13:02:57 +01:00
|
|
|
/** This holds all the information in the config file,
|
2007-07-16 17:30:04 +00:00
|
|
|
* it's indexed by tag name to a vector of key/values.
|
|
|
|
*/
|
2020-11-03 22:30:58 +00:00
|
|
|
TagMap config_data;
|
2007-07-16 17:30:04 +00:00
|
|
|
|
2010-02-02 16:47:25 +00:00
|
|
|
/** This holds all extra files that have been read in the configuration
|
|
|
|
* (for example, MOTD and RULES files are stored here)
|
|
|
|
*/
|
|
|
|
ConfigFileCache Files;
|
|
|
|
|
2008-09-20 20:53:04 +00:00
|
|
|
/** Length limits, see definition of ServerLimits class
|
|
|
|
*/
|
2008-05-25 17:30:43 +00:00
|
|
|
ServerLimits Limits;
|
|
|
|
|
2013-07-10 18:11:48 +01:00
|
|
|
/** Locations of various types of file (config, module, etc). */
|
|
|
|
ServerPaths Paths;
|
|
|
|
|
2009-10-21 23:46:24 +00:00
|
|
|
/** Configuration parsed from the command line.
|
|
|
|
*/
|
|
|
|
CommandLineConf cmdline;
|
|
|
|
|
2008-07-12 13:58:37 +00:00
|
|
|
/** Clones CIDR range for ipv4 (0-32)
|
2020-04-21 06:34:17 +00:00
|
|
|
* Defaults to 32 (checks clones on all IPs separately)
|
2008-07-12 13:58:37 +00:00
|
|
|
*/
|
2017-11-17 00:02:03 +00:00
|
|
|
unsigned char c_ipv4_range;
|
2008-07-12 13:58:37 +00:00
|
|
|
|
|
|
|
/** Clones CIDR range for ipv6 (0-128)
|
2020-04-21 06:34:17 +00:00
|
|
|
* Defaults to 128 (checks on all IPs separately)
|
2008-07-12 13:58:37 +00:00
|
|
|
*/
|
2017-11-17 00:02:03 +00:00
|
|
|
unsigned char c_ipv6_range;
|
2008-07-12 13:58:37 +00:00
|
|
|
|
2007-07-16 17:30:04 +00:00
|
|
|
/** Holds the server name of the local server
|
|
|
|
* as defined by the administrator.
|
|
|
|
*/
|
2009-10-03 01:52:59 +00:00
|
|
|
std::string ServerName;
|
2007-07-16 17:30:04 +00:00
|
|
|
|
2013-07-10 14:50:26 +01:00
|
|
|
/** Notice to give to users when they are banned by an XLine
|
2007-07-16 17:30:04 +00:00
|
|
|
*/
|
2013-07-10 14:50:26 +01:00
|
|
|
std::string XLineMessage;
|
2009-02-14 21:14:36 +00:00
|
|
|
|
2007-07-16 17:30:04 +00:00
|
|
|
/* Holds the network name the local server
|
2020-04-21 06:34:17 +00:00
|
|
|
* belongs to. This is an arbitrary field defined
|
2007-07-16 17:30:04 +00:00
|
|
|
* by the administrator.
|
|
|
|
*/
|
2009-10-03 01:52:59 +00:00
|
|
|
std::string Network;
|
2007-07-16 17:30:04 +00:00
|
|
|
|
|
|
|
/** Holds the description of the local server
|
|
|
|
* as defined by the administrator.
|
|
|
|
*/
|
2009-10-03 01:52:59 +00:00
|
|
|
std::string ServerDesc;
|
2007-07-16 17:30:04 +00:00
|
|
|
|
2018-07-10 20:32:08 +01:00
|
|
|
/** How to treat a user in a channel who is banned. */
|
|
|
|
BannedUserTreatment RestrictBannedUsers;
|
2008-11-01 23:58:33 +00:00
|
|
|
|
2007-07-16 17:30:04 +00:00
|
|
|
/** The size of the read() buffer in the user
|
|
|
|
* handling code, used to read data into a user's
|
|
|
|
* recvQ.
|
|
|
|
*/
|
2023-01-24 23:02:35 +00:00
|
|
|
size_t NetBufferSize;
|
2007-07-16 17:30:04 +00:00
|
|
|
|
2021-05-30 20:37:54 +01:00
|
|
|
/** The value to be used for listen() backlogs as default.
|
|
|
|
* As listen() expects a backlog to be `int` sized, so this must be.
|
2007-07-16 17:30:04 +00:00
|
|
|
*/
|
|
|
|
int MaxConn;
|
|
|
|
|
|
|
|
/** The soft limit value assigned to the irc server.
|
|
|
|
* The IRC server will not allow more than this
|
|
|
|
* number of local users.
|
|
|
|
*/
|
2021-05-30 20:37:54 +01:00
|
|
|
unsigned long SoftLimit;
|
2007-07-16 17:30:04 +00:00
|
|
|
|
|
|
|
/** Maximum number of targets for a multi target command
|
|
|
|
* such as PRIVMSG or KICK
|
|
|
|
*/
|
2021-05-30 20:37:54 +01:00
|
|
|
unsigned long MaxTargets;
|
2007-07-16 17:30:04 +00:00
|
|
|
|
2018-12-04 19:04:09 +00:00
|
|
|
/** The number of seconds that the server clock can skip by before server operators are warned. */
|
|
|
|
time_t TimeSkipWarn;
|
|
|
|
|
2019-01-08 03:03:53 -07:00
|
|
|
/** True if we're going to hide ban reasons for non-opers (e.g. G-lines,
|
|
|
|
* K-lines, Z-lines)
|
2007-07-16 17:30:04 +00:00
|
|
|
*/
|
|
|
|
bool HideBans;
|
|
|
|
|
2010-03-19 18:06:39 +00:00
|
|
|
/** True if raw I/O is being logged */
|
2020-02-06 11:25:42 +00:00
|
|
|
bool RawLog = false;
|
2010-03-19 18:06:39 +00:00
|
|
|
|
2017-12-15 23:26:15 +00:00
|
|
|
/** Set to a non-empty string to obfuscate server names. */
|
|
|
|
std::string HideServer;
|
2007-07-16 17:30:04 +00:00
|
|
|
|
|
|
|
/** The connect classes in use by the IRC server.
|
|
|
|
*/
|
|
|
|
ClassVector Classes;
|
|
|
|
|
|
|
|
/** Default channel modes
|
|
|
|
*/
|
2009-10-03 01:52:59 +00:00
|
|
|
std::string DefaultModes;
|
2007-07-16 17:30:04 +00:00
|
|
|
|
|
|
|
/** Custom version string, which if defined can replace the system info in VERSION.
|
|
|
|
*/
|
2009-10-03 01:52:59 +00:00
|
|
|
std::string CustomVersion;
|
2007-07-16 17:30:04 +00:00
|
|
|
|
|
|
|
/** If set to true, provide syntax hints for unknown commands
|
|
|
|
*/
|
|
|
|
bool SyntaxHints;
|
|
|
|
|
2017-07-30 17:34:05 +01:00
|
|
|
/** The name of the casemapping method used by this server.
|
|
|
|
*/
|
|
|
|
std::string CaseMapping;
|
|
|
|
|
2012-07-05 21:00:35 +01:00
|
|
|
/** If set to true, the full nick!user\@host will be shown in the TOPIC command
|
2007-07-16 17:30:04 +00:00
|
|
|
* for who set the topic last. If false, only the nick is shown.
|
|
|
|
*/
|
|
|
|
bool FullHostInTopic;
|
|
|
|
|
2022-11-27 07:32:42 +00:00
|
|
|
/** Oper accounts keyed by their name. */
|
|
|
|
OperAccountMap OperAccounts;
|
2007-07-16 17:30:04 +00:00
|
|
|
|
2022-11-27 07:32:42 +00:00
|
|
|
/** Oper types keyed by their name. */
|
|
|
|
OperTypeMap OperTypes;
|
2013-08-13 14:22:07 +02:00
|
|
|
|
2021-03-05 03:23:25 +00:00
|
|
|
/** Unique server ID.
|
2007-08-27 19:56:38 +00:00
|
|
|
* NOTE: 000...999 are usable for InspIRCd servers. This
|
|
|
|
* makes code simpler. 0AA, 1BB etc with letters are reserved
|
|
|
|
* for services use.
|
|
|
|
*/
|
2009-10-03 01:52:59 +00:00
|
|
|
std::string sid;
|
2007-08-27 19:56:38 +00:00
|
|
|
|
2007-07-16 17:30:04 +00:00
|
|
|
/** Construct a new ServerConfig
|
|
|
|
*/
|
2009-09-26 14:13:13 +00:00
|
|
|
ServerConfig();
|
2007-07-16 17:30:04 +00:00
|
|
|
|
2007-08-28 18:02:01 +00:00
|
|
|
/** Get server ID as string with required leading zeroes
|
|
|
|
*/
|
2013-06-02 00:28:55 +02:00
|
|
|
const std::string& GetSID() const { return sid; }
|
2007-08-28 18:02:01 +00:00
|
|
|
|
2020-12-20 03:04:21 +00:00
|
|
|
/** Retrieves the server name which should be shown to users. */
|
|
|
|
const std::string& GetServerName() const { return HideServer.empty() ? ServerName : HideServer; }
|
|
|
|
|
|
|
|
/** Retrieves the server description which should be shown to users. */
|
2021-09-04 20:14:47 +01:00
|
|
|
const std::string& GetServerDesc() const { return HideServer.empty() ? ServerDesc : Network; }
|
2020-12-20 03:04:21 +00:00
|
|
|
|
2007-07-16 17:30:04 +00:00
|
|
|
/** Read the entire configuration into memory
|
|
|
|
* and initialize this class. All other methods
|
|
|
|
* should be used only by the core.
|
|
|
|
*/
|
2009-07-01 22:55:46 +00:00
|
|
|
void Read();
|
|
|
|
|
|
|
|
/** Apply configuration changes from the old configuration.
|
|
|
|
*/
|
2022-09-29 12:01:29 +01:00
|
|
|
void Apply(ServerConfig* old, const std::string& useruid);
|
2009-10-17 02:14:44 +00:00
|
|
|
|
2013-05-17 02:03:16 +01:00
|
|
|
/** Escapes a value for storage in a configuration key.
|
|
|
|
* @param str The string to escape.
|
|
|
|
*/
|
2019-01-25 03:27:13 +00:00
|
|
|
static std::string Escape(const std::string& str);
|
2008-08-07 16:35:58 +00:00
|
|
|
|
2022-10-17 00:13:30 +01:00
|
|
|
/** Retrieves the list of modules that were specified in the config. */
|
|
|
|
std::vector<std::string> GetModules() const;
|
|
|
|
|
2012-04-15 10:45:34 +02:00
|
|
|
/** If this value is true, snotices will not stack when repeats are sent
|
|
|
|
*/
|
2020-02-06 11:25:42 +00:00
|
|
|
bool NoSnoticeStack = false;
|
2007-07-16 17:30:04 +00:00
|
|
|
};
|
2009-10-21 23:46:13 +00:00
|
|
|
|
2009-10-25 15:21:45 +00:00
|
|
|
/** The background thread for config reading, so that reading from executable includes
|
|
|
|
* does not block.
|
|
|
|
*/
|
2021-12-20 20:00:03 +00:00
|
|
|
class CoreExport ConfigReaderThread final
|
|
|
|
: public Thread
|
2009-10-25 15:21:45 +00:00
|
|
|
{
|
2022-01-25 13:59:42 +00:00
|
|
|
private:
|
2019-05-15 16:22:24 +01:00
|
|
|
/** The new server configuration. */
|
|
|
|
ServerConfig* Config = new ServerConfig();
|
|
|
|
|
|
|
|
/** Whether the config has been read yet. */
|
|
|
|
std::atomic_bool done = { false };
|
|
|
|
|
2022-01-25 13:59:42 +00:00
|
|
|
protected:
|
2019-05-15 16:22:24 +01:00
|
|
|
/** @copydoc Thread::OnStart */
|
|
|
|
void OnStart() override;
|
|
|
|
|
|
|
|
/** @copydoc Thread::OnStop */
|
|
|
|
void OnStop() override;
|
|
|
|
|
2022-01-25 13:59:42 +00:00
|
|
|
public:
|
2019-05-15 16:22:24 +01:00
|
|
|
const std::string UUID;
|
|
|
|
|
|
|
|
ConfigReaderThread(const std::string& uuid)
|
|
|
|
: UUID(uuid)
|
2009-10-25 15:21:45 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-04-04 23:42:15 +01:00
|
|
|
~ConfigReaderThread() override
|
2009-10-25 15:21:45 +00:00
|
|
|
{
|
|
|
|
delete Config;
|
|
|
|
}
|
|
|
|
|
2019-05-15 16:22:24 +01:00
|
|
|
/** Whether the configuration has been read yet. */
|
|
|
|
bool IsDone() { return done.load(); }
|
2009-10-25 15:21:45 +00:00
|
|
|
};
|
2013-08-16 12:10:55 +02:00
|
|
|
|
2019-09-02 15:17:30 +01:00
|
|
|
/** Represents the status of a config load. */
|
2021-12-20 20:00:03 +00:00
|
|
|
class CoreExport ConfigStatus final
|
2013-08-16 12:10:55 +02:00
|
|
|
{
|
2022-01-25 13:59:42 +00:00
|
|
|
public:
|
2019-09-02 15:17:30 +01:00
|
|
|
/** Whether this is the initial config load. */
|
|
|
|
bool const initial;
|
|
|
|
|
|
|
|
/** The user who initiated the config load or NULL if not initiated by a user. */
|
2013-08-16 12:10:55 +02:00
|
|
|
User* const srcuser;
|
|
|
|
|
2019-09-02 15:17:30 +01:00
|
|
|
/** Initializes a new instance of the ConfigStatus class.
|
|
|
|
* @param user The user who initiated the config load or NULL if not initiated by a user.
|
|
|
|
* @param isinitial Whether this is the initial config load.
|
|
|
|
*/
|
2022-07-22 18:33:38 +01:00
|
|
|
ConfigStatus(User* user = nullptr, bool isinitial = false)
|
2019-09-02 15:17:30 +01:00
|
|
|
: initial(isinitial)
|
|
|
|
, srcuser(user)
|
2013-08-16 12:10:55 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|