2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
5 * Copyright (C) 2007, 2009 Dennis Friis <peavey@inspircd.org>
6 * Copyright (C) 2006-2008 Craig Edwards <craigedwards@brainbox.cc>
7 * Copyright (C) 2006-2008 Robin Burchell <robin+git@viroteck.net>
8 * Copyright (C) 2006 Oliver Lupton <oliverlupton@gmail.com>
10 * This file is part of InspIRCd. InspIRCd is free software: you can
11 * redistribute it and/or modify it under the terms of the GNU General Public
12 * License as published by the Free Software Foundation, version 2.
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
32 #include "socketengine.h"
35 /** Structure representing a single \<tag> in config */
36 class CoreExport ConfigTag : public refcountbase
40 const std::string tag;
41 const std::string src_name;
44 /** Get the value of an option, using def if it does not exist */
45 std::string getString(const std::string& key, const std::string& def = "", size_t minlen = 0, size_t maxlen = UINT32_MAX);
46 /** Get the value of an option, using def if it does not exist */
47 long getInt(const std::string& key, long def = 0, long min = LONG_MIN, long max = LONG_MAX);
48 /** Get the value of an option, using def if it does not exist */
49 double getFloat(const std::string& key, double def = 0);
50 /** Get the value of an option, using def if it does not exist */
51 bool getBool(const std::string& key, bool def = false);
53 /** Get the value in seconds of a duration that is in the user-friendly "1h2m3s" format,
54 * using a default value if it does not exist or is out of bounds.
55 * @param key The config key name
56 * @param def Default value (optional)
57 * @param min Minimum acceptable value (optional)
58 * @param max Maximum acceptable value (optional)
59 * @return The duration in seconds
61 long getDuration(const std::string& key, long def = 0, long min = LONG_MIN, long max = LONG_MAX);
63 /** Get the value of an option
64 * @param key The option to get
65 * @param value The location to store the value (unmodified if does not exist)
66 * @param allow_newline Allow newlines in the option (normally replaced with spaces)
67 * @return true if the option exists
69 bool readString(const std::string& key, std::string& value, bool allow_newline = false);
71 /** Check for an out of range value. If the value falls outside the boundaries a warning is
72 * logged and the value is corrected (set to def).
73 * @param key The key name, used in the warning message
74 * @param res The value to verify and modify if needed
75 * @param def The default value, res will be set to this if (min <= res <= max) doesn't hold true
76 * @param min Minimum accepted value for res
77 * @param max Maximum accepted value for res
79 void CheckRange(const std::string& key, long& res, long def, long min, long max);
81 std::string getTagLocation();
83 inline const ConfigItems& getItems() const { return items; }
85 /** Create a new ConfigTag, giving access to the private ConfigItems item list */
86 static ConfigTag* create(const std::string& Tag, const std::string& file, int line, ConfigItems*& Items);
88 ConfigTag(const std::string& Tag, const std::string& file, int line);
91 /** Defines the server's length limits on various length-limited
92 * items such as topics, nicknames, channel names etc.
97 /** Maximum nickname length */
99 /** Maximum channel length */
101 /** Maximum number of modes per line */
103 /** Maximum length of ident, not including ~ etc */
105 /** Maximum length of a quit message */
107 /** Maximum topic length */
109 /** Maximum kick message length */
111 /** Maximum GECOS (real name) length */
113 /** Maximum away message length */
115 /** Maximum line length */
117 /** Maximum hostname length */
120 /** Read all limits from a config tag. Limits which aren't specified in the tag are set to a default value.
121 * @param tag Configuration tag to read the limits from
123 ServerLimits(ConfigTag* tag);
125 /** Maximum length of a n!u\@h mask */
126 size_t GetMaxMask() const { return NickMax + 1 + IdentMax + 1 + MaxHost; }
129 struct CommandLineConf
131 /** If this value is true, the owner of the
132 * server specified -nofork on the command
133 * line, causing the daemon to stay in the
138 /** If this value if true then all log
139 * messages will be output, regardless of
140 * the level given in the config file.
141 * This is set with the -debug commandline
146 /** If this is true then log output will be
147 * written to the logfile. This is the default.
148 * If you put -nolog on the commandline then
149 * the logfile will not be written.
150 * This is meant to be used in conjunction with
151 * -debug for debugging without filling up the
156 /** Saved argc from startup
160 /** Saved argv from startup
165 class CoreExport OperInfo : public refcountbase
168 typedef insp::flat_set<std::string> PrivSet;
169 PrivSet AllowedOperCommands;
170 PrivSet AllowedPrivs;
172 /** Allowed user modes from oper classes. */
173 std::bitset<64> AllowedUserModes;
175 /** Allowed channel modes from oper classes. */
176 std::bitset<64> AllowedChanModes;
178 /** \<oper> block used for this oper-up. May be NULL. */
179 reference<ConfigTag> oper_block;
180 /** \<type> block used for this oper-up. Valid for local users, may be NULL on remote */
181 reference<ConfigTag> type_block;
182 /** \<class> blocks referenced from the \<type> block. These define individual permissions */
183 std::vector<reference<ConfigTag> > class_blocks;
184 /** Name of the oper type; i.e. the one shown in WHOIS */
187 /** Creates a new OperInfo with the specified oper type name.
188 * @param Name The name of the oper type.
190 OperInfo(const std::string& Name);
192 /** Get a configuration item, searching in the oper, type, and class blocks (in that order) */
193 std::string getConfig(const std::string& key);
197 /** This class holds the bulk of the runtime configuration for the ircd.
198 * It allows for reading new config values, accessing configuration files,
199 * and storage of the configuration data needed to run the ircd, such as
200 * the servername, connect classes, /ADMIN data, MOTDs and filenames etc.
202 class CoreExport ServerConfig
205 void CrossCheckOperClassType();
206 void CrossCheckConnectBlocks(ServerConfig* current);
224 ServerPaths(ConfigTag* tag);
226 std::string PrependConfig(const std::string& fn) const { return FileSystem::ExpandPath(Config, fn); }
227 std::string PrependData(const std::string& fn) const { return FileSystem::ExpandPath(Data, fn); }
228 std::string PrependLog(const std::string& fn) const { return FileSystem::ExpandPath(Log, fn); }
229 std::string PrependModule(const std::string& fn) const { return FileSystem::ExpandPath(Module, fn); }
232 /** Holds a complete list of all connect blocks
234 typedef std::vector<reference<ConnectClass> > ClassVector;
236 /** Index of valid oper blocks and types
238 typedef insp::flat_map<std::string, reference<OperInfo> > OperIndex;
240 /** Get a configuration tag
241 * @param tag The name of the tag to get
243 ConfigTag* ConfValue(const std::string& tag);
245 ConfigTagList ConfTags(const std::string& tag);
247 /** An empty configuration tag. */
250 /** Error stream, contains error output from any failed configuration parsing.
252 std::stringstream errstr;
254 /** True if this configuration is valid enough to run with */
257 /** Bind to IPv6 by default */
260 /** Used to indicate who we announce invites to on a channel */
261 enum InviteAnnounceState { INVITE_ANNOUNCE_NONE, INVITE_ANNOUNCE_ALL, INVITE_ANNOUNCE_OPS, INVITE_ANNOUNCE_DYNAMIC };
262 enum OperSpyWhoisState { SPYWHOIS_NONE, SPYWHOIS_SINGLEMSG, SPYWHOIS_SPLITMSG };
264 /** This holds all the information in the config file,
265 * it's indexed by tag name to a vector of key/values.
267 ConfigDataHash config_data;
269 /** This holds all extra files that have been read in the configuration
270 * (for example, MOTD and RULES files are stored here)
272 ConfigFileCache Files;
274 /** Length limits, see definition of ServerLimits class
278 /** Locations of various types of file (config, module, etc). */
281 /** Configuration parsed from the command line.
283 CommandLineConf cmdline;
285 /** Clones CIDR range for ipv4 (0-32)
286 * Defaults to 32 (checks clones on all IPs seperately)
290 /** Clones CIDR range for ipv6 (0-128)
291 * Defaults to 128 (checks on all IPs seperately)
295 /** Holds the server name of the local server
296 * as defined by the administrator.
298 std::string ServerName;
300 /** Notice to give to users when they are banned by an XLine
302 std::string XLineMessage;
304 /* Holds the network name the local server
305 * belongs to. This is an arbitary field defined
306 * by the administrator.
310 /** Holds the description of the local server
311 * as defined by the administrator.
313 std::string ServerDesc;
315 /** Pretend disabled commands don't exist.
317 bool DisabledDontExist;
319 /** This variable identifies which usermodes have been diabled.
321 std::bitset<64> DisabledUModes;
323 /** This variable identifies which chanmodes have been disabled.
325 std::bitset<64> DisabledCModes;
327 /** If set to true, then all opers on this server are
328 * shown with a generic 'is an IRC operator' line rather
329 * than the oper type. Oper types are still used internally.
333 /** If this value is true, banned users (+b, not extbans) will not be able to change nick
334 * if banned on any channel, nor to message them.
336 bool RestrictBannedUsers;
338 /** The size of the read() buffer in the user
339 * handling code, used to read data into a user's
344 /** The value to be used for listen() backlogs
349 /** If we should check for clones during CheckClass() in AddUser()
350 * Setting this to false allows to not trigger on maxclones for users
351 * that may belong to another class after DNS-lookup is complete.
352 * It does, however, make the server spend more time on users we may potentially not want.
356 /** The soft limit value assigned to the irc server.
357 * The IRC server will not allow more than this
358 * number of local users.
360 unsigned int SoftLimit;
362 /** Maximum number of targets for a multi target command
363 * such as PRIVMSG or KICK
365 unsigned int MaxTargets;
367 /** True if we're going to hide netsplits as *.net *.split for non-opers
371 /** True if we're going to hide ban reasons for non-opers (e.g. G-Lines,
376 /** Announce invites to the channel with a server notice
378 InviteAnnounceState AnnounceInvites;
380 /** If this is enabled then operators will
381 * see invisible (+i) channels in /whois.
383 OperSpyWhoisState OperSpyWhois;
385 /** True if raw I/O is being logged */
388 /** Set to a non-empty string to obfuscate the server name of users in WHOIS
390 std::string HideWhoisServer;
392 /** Set to a non empty string to obfuscate nicknames prepended to a KILL.
394 std::string HideKillsServer;
396 /** Set to hide kills from clients of ulined servers in snotices.
400 /** The full pathname and filename of the PID
401 * file as defined in the configuration.
405 /** The connect classes in use by the IRC server.
409 /** STATS characters in this list are available
412 std::string UserStats;
414 /** Default channel modes
416 std::string DefaultModes;
418 /** Custom version string, which if defined can replace the system info in VERSION.
420 std::string CustomVersion;
422 /** If set to true, provide syntax hints for unknown commands
426 /** The name of the casemapping method used by this server.
428 std::string CaseMapping;
430 /** If set to true, the CycleHosts mode change will be sourced from the user,
431 * rather than the server
433 bool CycleHostsFromUser;
435 /** If set to true, the full nick!user\@host will be shown in the TOPIC command
436 * for who set the topic last. If false, only the nick is shown.
438 bool FullHostInTopic;
440 /** Oper blocks keyed by their name
442 OperIndex oper_blocks;
444 /** Oper types keyed by their name
448 /** Default value for <connect:maxchans>, deprecated in 3.0
450 unsigned int MaxChans;
452 /** Default value for <oper:maxchans>, deprecated in 3.0
454 unsigned int OperMaxChans;
456 /** TS6-like server ID.
457 * NOTE: 000...999 are usable for InspIRCd servers. This
458 * makes code simpler. 0AA, 1BB etc with letters are reserved
463 /** Construct a new ServerConfig
469 /** Get server ID as string with required leading zeroes
471 const std::string& GetSID() const { return sid; }
473 /** Read the entire configuration into memory
474 * and initialize this class. All other methods
475 * should be used only by the core.
479 /** Apply configuration changes from the old configuration.
481 void Apply(ServerConfig* old, const std::string &useruid);
482 void ApplyModules(User* user);
486 /** Disables the commands specified in <disabled:commands>. */
487 bool ApplyDisabledCommands();
489 /** Escapes a value for storage in a configuration key.
490 * @param str The string to escape.
491 * @param xml Are we using the XML config format?
493 static std::string Escape(const std::string& str, bool xml = true);
495 /** If this value is true, snotices will not stack when repeats are sent
500 /** The background thread for config reading, so that reading from executable includes
503 class CoreExport ConfigReaderThread : public Thread
505 ServerConfig* Config;
508 const std::string TheUserUID;
509 ConfigReaderThread(const std::string &useruid)
510 : Config(new ServerConfig), done(false), TheUserUID(useruid)
514 virtual ~ConfigReaderThread()
520 /** Run in the main thread to apply the configuration */
522 bool IsDone() { return done; }
525 class CoreExport ConfigStatus
530 ConfigStatus(User* user = NULL)