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
38 std::vector<KeyVal> items;
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 = "");
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 std::vector<KeyVal>& getItems() const { return items; }
85 /** Create a new ConfigTag, giving access to the private KeyVal item list */
86 static ConfigTag* create(const std::string& Tag, const std::string& file, int line, std::vector<KeyVal>*& 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 */
118 /** Creating the class initialises it to the defaults
119 * as in 1.1's ./configure script. Reading other values
120 * from the config will change these values.
122 ServerLimits() : NickMax(31), ChanMax(64), MaxModes(20), IdentMax(12),
123 MaxQuit(255), MaxTopic(307), MaxKick(255), MaxGecos(128), MaxAway(200),
127 struct CommandLineConf
129 /** If this value is true, the owner of the
130 * server specified -nofork on the command
131 * line, causing the daemon to stay in the
136 /** If this value if true then all log
137 * messages will be output, regardless of
138 * the level given in the config file.
139 * This is set with the -debug commandline
144 /** If this is true then log output will be
145 * written to the logfile. This is the default.
146 * If you put -nolog on the commandline then
147 * the logfile will not be written.
148 * This is meant to be used in conjunction with
149 * -debug for debugging without filling up the
154 /** Saved argc from startup
158 /** Saved argv from startup
163 class CoreExport OperInfo : public refcountbase
166 std::set<std::string> AllowedOperCommands;
167 std::set<std::string> AllowedPrivs;
169 /** Allowed user modes from oper classes. */
170 std::bitset<64> AllowedUserModes;
172 /** Allowed channel modes from oper classes. */
173 std::bitset<64> AllowedChanModes;
175 /** \<oper> block used for this oper-up. May be NULL. */
176 reference<ConfigTag> oper_block;
177 /** \<type> block used for this oper-up. Valid for local users, may be NULL on remote */
178 reference<ConfigTag> type_block;
179 /** \<class> blocks referenced from the \<type> block. These define individual permissions */
180 std::vector<reference<ConfigTag> > class_blocks;
181 /** Name of the oper type; i.e. the one shown in WHOIS */
184 /** Get a configuration item, searching in the oper, type, and class blocks (in that order) */
185 std::string getConfig(const std::string& key);
189 /** This class holds the bulk of the runtime configuration for the ircd.
190 * It allows for reading new config values, accessing configuration files,
191 * and storage of the configuration data needed to run the ircd, such as
192 * the servername, connect classes, /ADMIN data, MOTDs and filenames etc.
194 class CoreExport ServerConfig
197 void CrossCheckOperClassType();
198 void CrossCheckConnectBlocks(ServerConfig* current);
217 : Config(CONFIG_PATH)
220 , Module(MOD_PATH) { }
222 std::string PrependConfig(const std::string& fn) const { return FileSystem::ExpandPath(Config, fn); }
223 std::string PrependData(const std::string& fn) const { return FileSystem::ExpandPath(Data, fn); }
224 std::string PrependLog(const std::string& fn) const { return FileSystem::ExpandPath(Log, fn); }
225 std::string PrependModule(const std::string& fn) const { return FileSystem::ExpandPath(Module, fn); }
228 /** Get a configuration tag
229 * @param tag The name of the tag to get
231 ConfigTag* ConfValue(const std::string& tag);
233 ConfigTagList ConfTags(const std::string& tag);
235 /** Error stream, contains error output from any failed configuration parsing.
237 std::stringstream errstr;
239 /** True if this configuration is valid enough to run with */
242 /** Bind to IPv6 by default */
245 /** Used to indicate who we announce invites to on a channel */
246 enum InviteAnnounceState { INVITE_ANNOUNCE_NONE, INVITE_ANNOUNCE_ALL, INVITE_ANNOUNCE_OPS, INVITE_ANNOUNCE_DYNAMIC };
247 enum OperSpyWhoisState { SPYWHOIS_NONE, SPYWHOIS_SINGLEMSG, SPYWHOIS_SPLITMSG };
249 /** This holds all the information in the config file,
250 * it's indexed by tag name to a vector of key/values.
252 ConfigDataHash config_data;
254 /** This holds all extra files that have been read in the configuration
255 * (for example, MOTD and RULES files are stored here)
257 ConfigFileCache Files;
259 /** Length limits, see definition of ServerLimits class
263 /** Locations of various types of file (config, module, etc). */
266 /** Configuration parsed from the command line.
268 CommandLineConf cmdline;
270 /** Clones CIDR range for ipv4 (0-32)
271 * Defaults to 32 (checks clones on all IPs seperately)
275 /** Clones CIDR range for ipv6 (0-128)
276 * Defaults to 128 (checks on all IPs seperately)
280 /** Holds the server name of the local server
281 * as defined by the administrator.
283 std::string ServerName;
285 /** Notice to give to users when they are banned by an XLine
287 std::string XLineMessage;
289 /* Holds the network name the local server
290 * belongs to. This is an arbitary field defined
291 * by the administrator.
295 /** Holds the description of the local server
296 * as defined by the administrator.
298 std::string ServerDesc;
300 /** Holds the admin's name, for output in
301 * the /ADMIN command.
303 std::string AdminName;
305 /** Holds the email address of the admin,
306 * for output in the /ADMIN command.
308 std::string AdminEmail;
310 /** Holds the admin's nickname, for output
311 * in the /ADMIN command
313 std::string AdminNick;
315 /** The admin-configured /DIE password
319 /** The admin-configured /RESTART password
321 std::string restartpass;
323 /** The hash method for *BOTH* the die and restart passwords.
325 std::string powerhash;
327 /** The quit prefix in use, or an empty string
329 std::string PrefixQuit;
331 /** The quit suffix in use, or an empty string
333 std::string SuffixQuit;
335 /** The fixed quit message in use, or an empty string
337 std::string FixedQuit;
339 /** The part prefix in use, or an empty string
341 std::string PrefixPart;
343 /** The part suffix in use, or an empty string
345 std::string SuffixPart;
347 /** The fixed part message in use, or an empty string
349 std::string FixedPart;
351 /** Pretend disabled commands don't exist.
353 bool DisabledDontExist;
355 /** This variable contains a space-seperated list
356 * of commands which are disabled by the
357 * administrator of the server for non-opers.
359 std::string DisabledCommands;
361 /** This variable identifies which usermodes have been diabled.
363 char DisabledUModes[64];
365 /** This variable identifies which chanmodes have been disabled.
367 char DisabledCModes[64];
369 /** If set to true, then all opers on this server are
370 * shown with a generic 'is an IRC operator' line rather
371 * than the oper type. Oper types are still used internally.
375 /** If this value is true, banned users (+b, not extbans) will not be able to change nick
376 * if banned on any channel, nor to message them.
378 bool RestrictBannedUsers;
380 /** If this is set to true, then mode lists (e.g
381 * MODE \#chan b) are hidden from unprivileged
384 bool HideModeLists[256];
386 /** The number of seconds the DNS subsystem
387 * will wait before timing out any request.
391 /** The size of the read() buffer in the user
392 * handling code, used to read data into a user's
397 /** The value to be used for listen() backlogs
402 /** If we should check for clones during CheckClass() in AddUser()
403 * Setting this to false allows to not trigger on maxclones for users
404 * that may belong to another class after DNS-lookup is complete.
405 * It does, however, make the server spend more time on users we may potentially not want.
409 /** The soft limit value assigned to the irc server.
410 * The IRC server will not allow more than this
411 * number of local users.
413 unsigned int SoftLimit;
415 /** Maximum number of targets for a multi target command
416 * such as PRIVMSG or KICK
418 unsigned int MaxTargets;
420 /** True if we're going to hide netsplits as *.net *.split for non-opers
424 /** True if we're going to hide ban reasons for non-opers (e.g. G-Lines,
429 /** Announce invites to the channel with a server notice
431 InviteAnnounceState AnnounceInvites;
433 /** If this is enabled then operators will
434 * see invisible (+i) channels in /whois.
436 OperSpyWhoisState OperSpyWhois;
438 /** True if raw I/O is being logged */
441 /** Set to a non-empty string to obfuscate the server name of users in WHOIS
443 std::string HideWhoisServer;
445 /** Set to a non empty string to obfuscate nicknames prepended to a KILL.
447 std::string HideKillsServer;
449 /** The full pathname and filename of the PID
450 * file as defined in the configuration.
454 /** The connect classes in use by the IRC server.
458 /** STATS characters in this list are available
461 std::string UserStats;
463 /** Default channel modes
465 std::string DefaultModes;
467 /** Custom version string, which if defined can replace the system info in VERSION.
469 std::string CustomVersion;
471 /** If set to true, provide syntax hints for unknown commands
475 /** If set to true, the CycleHosts mode change will be sourced from the user,
476 * rather than the server
478 bool CycleHostsFromUser;
480 /** If set to true, prefixed channel NOTICEs and PRIVMSGs will have the prefix
481 * added to the outgoing text for undernet style msg prefixing.
483 bool UndernetMsgPrefix;
485 /** If set to true, the full nick!user\@host will be shown in the TOPIC command
486 * for who set the topic last. If false, only the nick is shown.
488 bool FullHostInTopic;
490 /** Oper blocks keyed by their name
492 OperIndex oper_blocks;
494 /** Oper types keyed by their name
498 /** Max channels per user
500 unsigned int MaxChans;
502 /** Oper max channels per user
504 unsigned int OperMaxChans;
506 /** TS6-like server ID.
507 * NOTE: 000...999 are usable for InspIRCd servers. This
508 * makes code simpler. 0AA, 1BB etc with letters are reserved
513 /** Construct a new ServerConfig
517 /** Get server ID as string with required leading zeroes
519 const std::string& GetSID() const { return sid; }
521 /** Read the entire configuration into memory
522 * and initialize this class. All other methods
523 * should be used only by the core.
527 /** Apply configuration changes from the old configuration.
529 void Apply(ServerConfig* old, const std::string &useruid);
530 void ApplyModules(User* user);
534 bool ApplyDisabledCommands(const std::string& data);
536 /** Escapes a value for storage in a configuration key.
537 * @param str The string to escape.
538 * @param xml Are we using the XML config format?
540 static std::string Escape(const std::string& str, bool xml = true);
542 /** If this value is true, invites will bypass more than just +i
546 /** If this value is true, snotices will not stack when repeats are sent
551 /** The background thread for config reading, so that reading from executable includes
554 class CoreExport ConfigReaderThread : public Thread
556 ServerConfig* Config;
559 const std::string TheUserUID;
560 ConfigReaderThread(const std::string &useruid)
561 : Config(new ServerConfig), done(false), TheUserUID(useruid)
565 virtual ~ConfigReaderThread()
571 /** Run in the main thread to apply the configuration */
573 bool IsDone() { return done; }
576 class CoreExport ConfigStatus
581 ConfigStatus(User* user = NULL)