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 of an option
54 * @param key The option to get
55 * @param value The location to store the value (unmodified if does not exist)
56 * @param allow_newline Allow newlines in the option (normally replaced with spaces)
57 * @return true if the option exists
59 bool readString(const std::string& key, std::string& value, bool allow_newline = false);
61 std::string getTagLocation();
63 inline const std::vector<KeyVal>& getItems() const { return items; }
65 /** Create a new ConfigTag, giving access to the private KeyVal item list */
66 static ConfigTag* create(const std::string& Tag, const std::string& file, int line,
67 std::vector<KeyVal>*&items);
69 ConfigTag(const std::string& Tag, const std::string& file, int line);
72 /** Defines the server's length limits on various length-limited
73 * items such as topics, nicknames, channel names etc.
78 /** Maximum nickname length */
80 /** Maximum channel length */
82 /** Maximum number of modes per line */
84 /** Maximum length of ident, not including ~ etc */
86 /** Maximum length of a quit message */
88 /** Maximum topic length */
90 /** Maximum kick message length */
92 /** Maximum GECOS (real name) length */
94 /** Maximum away message length */
96 /** Maximum line length */
99 /** Creating the class initialises it to the defaults
100 * as in 1.1's ./configure script. Reading other values
101 * from the config will change these values.
103 ServerLimits() : NickMax(31), ChanMax(64), MaxModes(20), IdentMax(12),
104 MaxQuit(255), MaxTopic(307), MaxKick(255), MaxGecos(128), MaxAway(200),
108 struct CommandLineConf
110 /** If this value is true, the owner of the
111 * server specified -nofork on the command
112 * line, causing the daemon to stay in the
117 /** If this value if true then all log
118 * messages will be output, regardless of
119 * the level given in the config file.
120 * This is set with the -debug commandline
125 /** If this is true then log output will be
126 * written to the logfile. This is the default.
127 * If you put -nolog on the commandline then
128 * the logfile will not be written.
129 * This is meant to be used in conjunction with
130 * -debug for debugging without filling up the
135 /** True if we have been told to run the testsuite from the commandline,
136 * rather than entering the mainloop.
140 /** Saved argc from startup
144 /** Saved argv from startup
149 class CoreExport OperInfo : public refcountbase
152 std::set<std::string> AllowedOperCommands;
153 std::set<std::string> AllowedPrivs;
155 /** Allowed user modes from oper classes. */
156 std::bitset<64> AllowedUserModes;
158 /** Allowed channel modes from oper classes. */
159 std::bitset<64> AllowedChanModes;
161 /** \<oper> block used for this oper-up. May be NULL. */
162 reference<ConfigTag> oper_block;
163 /** \<type> block used for this oper-up. Valid for local users, may be NULL on remote */
164 reference<ConfigTag> type_block;
165 /** \<class> blocks referenced from the \<type> block. These define individual permissions */
166 std::vector<reference<ConfigTag> > class_blocks;
167 /** Name of the oper type; i.e. the one shown in WHOIS */
170 /** Get a configuration item, searching in the oper, type, and class blocks (in that order) */
171 std::string getConfig(const std::string& key);
175 /** This class holds the bulk of the runtime configuration for the ircd.
176 * It allows for reading new config values, accessing configuration files,
177 * and storage of the configuration data needed to run the ircd, such as
178 * the servername, connect classes, /ADMIN data, MOTDs and filenames etc.
180 class CoreExport ServerConfig
183 void CrossCheckOperClassType();
184 void CrossCheckConnectBlocks(ServerConfig* current);
203 : Config(CONFIG_PATH)
206 , Module(MOD_PATH) { }
208 std::string PrependConfig(const std::string& fn) const { return ServerConfig::ExpandPath(Config, fn); }
209 std::string PrependData(const std::string& fn) const { return ServerConfig::ExpandPath(Data, fn); }
210 std::string PrependLog(const std::string& fn) const { return ServerConfig::ExpandPath(Log, fn); }
211 std::string PrependModule(const std::string& fn) const { return ServerConfig::ExpandPath(Module, fn); }
214 /** Get a configuration tag
215 * @param tag The name of the tag to get
217 ConfigTag* ConfValue(const std::string& tag);
219 ConfigTagList ConfTags(const std::string& tag);
221 /** Error stream, contains error output from any failed configuration parsing.
223 std::stringstream errstr;
225 /** True if this configuration is valid enough to run with */
228 /** Bind to IPv6 by default */
231 /** Used to indicate who we announce invites to on a channel */
232 enum InviteAnnounceState { INVITE_ANNOUNCE_NONE, INVITE_ANNOUNCE_ALL, INVITE_ANNOUNCE_OPS, INVITE_ANNOUNCE_DYNAMIC };
233 enum OperSpyWhoisState { SPYWHOIS_NONE, SPYWHOIS_SINGLEMSG, SPYWHOIS_SPLITMSG };
235 /** This holds all the information in the config file,
236 * it's indexed by tag name to a vector of key/values.
238 ConfigDataHash config_data;
240 /** This holds all extra files that have been read in the configuration
241 * (for example, MOTD and RULES files are stored here)
243 ConfigFileCache Files;
245 /** Length limits, see definition of ServerLimits class
249 /** Locations of various types of file (config, module, etc). */
252 /** Configuration parsed from the command line.
254 CommandLineConf cmdline;
256 /** Clones CIDR range for ipv4 (0-32)
257 * Defaults to 32 (checks clones on all IPs seperately)
261 /** Clones CIDR range for ipv6 (0-128)
262 * Defaults to 128 (checks on all IPs seperately)
266 /** Holds the server name of the local server
267 * as defined by the administrator.
269 std::string ServerName;
271 /** Notice to give to users when they are banned by an XLine
273 std::string XLineMessage;
275 /* Holds the network name the local server
276 * belongs to. This is an arbitary field defined
277 * by the administrator.
281 /** Holds the description of the local server
282 * as defined by the administrator.
284 std::string ServerDesc;
286 /** Holds the admin's name, for output in
287 * the /ADMIN command.
289 std::string AdminName;
291 /** Holds the email address of the admin,
292 * for output in the /ADMIN command.
294 std::string AdminEmail;
296 /** Holds the admin's nickname, for output
297 * in the /ADMIN command
299 std::string AdminNick;
301 /** The admin-configured /DIE password
305 /** The admin-configured /RESTART password
307 std::string restartpass;
309 /** The hash method for *BOTH* the die and restart passwords.
311 std::string powerhash;
313 /** The pathname and filename of the message of the
314 * day file, as defined by the administrator.
318 /** The pathname and filename of the rules file,
319 * as defined by the administrator.
323 /** The quit prefix in use, or an empty string
325 std::string PrefixQuit;
327 /** The quit suffix in use, or an empty string
329 std::string SuffixQuit;
331 /** The fixed quit message in use, or an empty string
333 std::string FixedQuit;
335 /** The part prefix in use, or an empty string
337 std::string PrefixPart;
339 /** The part suffix in use, or an empty string
341 std::string SuffixPart;
343 /** The fixed part message in use, or an empty string
345 std::string FixedPart;
347 /** Pretend disabled commands don't exist.
349 bool DisabledDontExist;
351 /** This variable contains a space-seperated list
352 * of commands which are disabled by the
353 * administrator of the server for non-opers.
355 std::string DisabledCommands;
357 /** This variable identifies which usermodes have been diabled.
359 char DisabledUModes[64];
361 /** This variable identifies which chanmodes have been disabled.
363 char DisabledCModes[64];
365 /** If set to true, then all opers on this server are
366 * shown with a generic 'is an IRC operator' line rather
367 * than the oper type. Oper types are still used internally.
371 /** If this value is true, banned users (+b, not extbans) will not be able to change nick
372 * if banned on any channel, nor to message them.
374 bool RestrictBannedUsers;
376 /** If this is set to true, then mode lists (e.g
377 * MODE \#chan b) are hidden from unprivileged
380 bool HideModeLists[256];
382 /** The number of seconds the DNS subsystem
383 * will wait before timing out any request.
387 /** The size of the read() buffer in the user
388 * handling code, used to read data into a user's
393 /** The value to be used for listen() backlogs
398 /** If we should check for clones during CheckClass() in AddUser()
399 * Setting this to false allows to not trigger on maxclones for users
400 * that may belong to another class after DNS-lookup is complete.
401 * It does, however, make the server spend more time on users we may potentially not want.
405 /** The soft limit value assigned to the irc server.
406 * The IRC server will not allow more than this
407 * number of local users.
409 unsigned int SoftLimit;
411 /** Maximum number of targets for a multi target command
412 * such as PRIVMSG or KICK
414 unsigned int MaxTargets;
416 /** True if we're going to hide netsplits as *.net *.split for non-opers
420 /** True if we're going to hide ban reasons for non-opers (e.g. G-Lines,
425 /** Announce invites to the channel with a server notice
427 InviteAnnounceState AnnounceInvites;
429 /** If this is enabled then operators will
430 * see invisible (+i) channels in /whois.
432 OperSpyWhoisState OperSpyWhois;
434 /** True if raw I/O is being logged */
437 /** Set to a non-empty string to obfuscate the server name of users in WHOIS
439 std::string HideWhoisServer;
441 /** Set to a non empty string to obfuscate nicknames prepended to a KILL.
443 std::string HideKillsServer;
445 /** The full pathname and filename of the PID
446 * file as defined in the configuration.
450 /** The connect classes in use by the IRC server.
454 /** STATS characters in this list are available
457 std::string UserStats;
459 /** Default channel modes
461 std::string DefaultModes;
463 /** Custom version string, which if defined can replace the system info in VERSION.
465 std::string CustomVersion;
467 /** List of u-lined servers
469 std::map<irc::string, bool> ulines;
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 block and type index.
491 * For anonymous oper blocks (type only), prefix with a space.
493 OperIndex oper_blocks;
495 /** Max channels per user
497 unsigned int MaxChans;
499 /** Oper max channels per user
501 unsigned int OperMaxChans;
503 /** TS6-like server ID.
504 * NOTE: 000...999 are usable for InspIRCd servers. This
505 * makes code simpler. 0AA, 1BB etc with letters are reserved
510 /** Construct a new ServerConfig
514 /** Get server ID as string with required leading zeroes
516 const std::string& GetSID() const { return sid; }
518 /** Read the entire configuration into memory
519 * and initialize this class. All other methods
520 * should be used only by the core.
524 /** Apply configuration changes from the old configuration.
526 void Apply(ServerConfig* old, const std::string &useruid);
527 void ApplyModules(User* user);
531 /** Returns true if the given string starts with a windows drive letter
533 static bool StartsWithWindowsDriveLetter(const std::string& path);
535 bool ApplyDisabledCommands(const std::string& data);
537 /** Clean a filename, stripping the directories (and drives) from string.
538 * @param name Directory to tidy
539 * @return The cleaned filename
541 static const char* CleanFilename(const char* name);
543 /** Check if a file exists.
544 * @param file The full path to a file
545 * @return True if the file exists and is readable.
547 static bool FileExists(const char* file);
549 /** Expands a path fragment to a full path.
550 * @param base The base path to expand from
551 * @param fragment The path fragment to expand on top of base.
553 static std::string ExpandPath(const std::string& base, const std::string& fragment);
555 /** Escapes a value for storage in a configuration key.
556 * @param str The string to escape.
557 * @param xml Are we using the XML config format?
559 static std::string Escape(const std::string& str, bool xml = true);
561 /** If this value is true, invites will bypass more than just +i
565 /** If this value is true, snotices will not stack when repeats are sent
570 /** The background thread for config reading, so that reading from executable includes
573 class CoreExport ConfigReaderThread : public Thread
575 ServerConfig* Config;
578 const std::string TheUserUID;
579 ConfigReaderThread(const std::string &useruid)
580 : Config(new ServerConfig), done(false), TheUserUID(useruid)
584 virtual ~ConfigReaderThread()
590 /** Run in the main thread to apply the configuration */
592 bool IsDone() { return done; }