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/>.
24 #ifndef INSPIRCD_CONFIGREADER
25 #define INSPIRCD_CONFIGREADER
33 #include "socketengine.h"
36 /** Structure representing a single \<tag> in config */
37 class CoreExport ConfigTag : public refcountbase
39 std::vector<KeyVal> items;
41 const std::string tag;
42 const std::string src_name;
45 /** Get the value of an option, using def if it does not exist */
46 std::string getString(const std::string& key, const std::string& def = "");
47 /** Get the value of an option, using def if it does not exist */
48 long getInt(const std::string& key, long def = 0);
49 /** Get the value of an option, using def if it does not exist */
50 double getFloat(const std::string& key, double def = 0);
51 /** Get the value of an option, using def if it does not exist */
52 bool getBool(const std::string& key, bool def = false);
54 /** Get the value of an option
55 * @param key The option to get
56 * @param value The location to store the value (unmodified if does not exist)
57 * @param allow_newline Allow newlines in the option (normally replaced with spaces)
58 * @return true if the option exists
60 bool readString(const std::string& key, std::string& value, bool allow_newline = false);
62 std::string getTagLocation();
64 inline const std::vector<KeyVal>& getItems() const { return items; }
66 /** Create a new ConfigTag, giving access to the private KeyVal item list */
67 static ConfigTag* create(const std::string& Tag, const std::string& file, int line,
68 std::vector<KeyVal>*&items);
70 ConfigTag(const std::string& Tag, const std::string& file, int line);
73 /** Defines the server's length limits on various length-limited
74 * items such as topics, nicknames, channel names etc.
79 /** Maximum nickname length */
81 /** Maximum channel length */
83 /** Maximum number of modes per line */
85 /** Maximum length of ident, not including ~ etc */
87 /** Maximum length of a quit message */
89 /** Maximum topic length */
91 /** Maximum kick message length */
93 /** Maximum GECOS (real name) length */
95 /** Maximum away message length */
98 /** Creating the class initialises it to the defaults
99 * as in 1.1's ./configure script. Reading other values
100 * from the config will change these values.
102 ServerLimits() : NickMax(31), ChanMax(64), MaxModes(20), IdentMax(12), MaxQuit(255), MaxTopic(307), MaxKick(255), MaxGecos(128), MaxAway(200)
107 struct CommandLineConf
109 /** If this value is true, the owner of the
110 * server specified -nofork on the command
111 * line, causing the daemon to stay in the
116 /** If this value if true then all log
117 * messages will be output, regardless of
118 * the level given in the config file.
119 * This is set with the -debug commandline
124 /** If this is true then log output will be
125 * written to the logfile. This is the default.
126 * If you put -nolog on the commandline then
127 * the logfile will not be written.
128 * This is meant to be used in conjunction with
129 * -debug for debugging without filling up the
134 /** True if we have been told to run the testsuite from the commandline,
135 * rather than entering the mainloop.
139 /** Saved argc from startup
143 /** Saved argv from startup
147 std::string startup_log;
150 class CoreExport OperInfo : public refcountbase
153 std::set<std::string> AllowedOperCommands;
154 std::set<std::string> AllowedPrivs;
156 /** Allowed user modes from oper classes. */
157 std::bitset<64> AllowedUserModes;
159 /** Allowed channel modes from oper classes. */
160 std::bitset<64> AllowedChanModes;
162 /** \<oper> block used for this oper-up. May be NULL. */
163 reference<ConfigTag> oper_block;
164 /** \<type> block used for this oper-up. Valid for local users, may be NULL on remote */
165 reference<ConfigTag> type_block;
166 /** \<class> blocks referenced from the \<type> block. These define individual permissions */
167 std::vector<reference<ConfigTag> > class_blocks;
168 /** Name of the oper type; i.e. the one shown in WHOIS */
171 /** Get a configuration item, searching in the oper, type, and class blocks (in that order) */
172 std::string getConfig(const std::string& key);
175 inline const char* NameStr()
177 return irc::Spacify(name.c_str());
181 /** This class holds the bulk of the runtime configuration for the ircd.
182 * It allows for reading new config values, accessing configuration files,
183 * and storage of the configuration data needed to run the ircd, such as
184 * the servername, connect classes, /ADMIN data, MOTDs and filenames etc.
186 class CoreExport ServerConfig
189 void CrossCheckOperClassType();
190 void CrossCheckConnectBlocks(ServerConfig* current);
194 /** Get a configuration tag
195 * @param tag The name of the tag to get
197 ConfigTag* ConfValue(const std::string& tag);
199 ConfigTagList ConfTags(const std::string& tag);
201 /** Error stream, contains error output from any failed configuration parsing.
203 std::stringstream errstr;
205 /** True if this configuration is valid enough to run with */
208 /** Bind to IPv6 by default */
211 /** Used to indicate who we announce invites to on a channel */
212 enum InviteAnnounceState { INVITE_ANNOUNCE_NONE, INVITE_ANNOUNCE_ALL, INVITE_ANNOUNCE_OPS, INVITE_ANNOUNCE_DYNAMIC };
213 enum OperSpyWhoisState { SPYWHOIS_NONE, SPYWHOIS_SINGLEMSG, SPYWHOIS_SPLITMSG };
215 /** This holds all the information in the config file,
216 * it's indexed by tag name to a vector of key/values.
218 ConfigDataHash config_data;
220 /** This holds all extra files that have been read in the configuration
221 * (for example, MOTD and RULES files are stored here)
223 ConfigFileCache Files;
225 /** Length limits, see definition of ServerLimits class
229 /** Configuration parsed from the command line.
231 CommandLineConf cmdline;
233 /** Clones CIDR range for ipv4 (0-32)
234 * Defaults to 32 (checks clones on all IPs seperately)
238 /** Clones CIDR range for ipv6 (0-128)
239 * Defaults to 128 (checks on all IPs seperately)
243 /** Max number of WhoWas entries per user.
247 /** Max number of cumulative user-entries in WhoWas.
248 * When max reached and added to, push out oldest entry FIFO style.
252 /** Max seconds a user is kept in WhoWas before being pruned.
256 /** Holds the server name of the local server
257 * as defined by the administrator.
259 std::string ServerName;
261 /** Notice to give to users when they are Xlined
263 std::string MoronBanner;
265 /* Holds the network name the local server
266 * belongs to. This is an arbitary field defined
267 * by the administrator.
271 /** Holds the description of the local server
272 * as defined by the administrator.
274 std::string ServerDesc;
276 /** Holds the admin's name, for output in
277 * the /ADMIN command.
279 std::string AdminName;
281 /** Holds the email address of the admin,
282 * for output in the /ADMIN command.
284 std::string AdminEmail;
286 /** Holds the admin's nickname, for output
287 * in the /ADMIN command
289 std::string AdminNick;
291 /** The admin-configured /DIE password
295 /** The admin-configured /RESTART password
297 std::string restartpass;
299 /** The hash method for *BOTH* the die and restart passwords.
301 std::string powerhash;
303 /** The pathname and filename of the message of the
304 * day file, as defined by the administrator.
308 /** The pathname and filename of the rules file,
309 * as defined by the administrator.
313 /** The quit prefix in use, or an empty string
315 std::string PrefixQuit;
317 /** The quit suffix in use, or an empty string
319 std::string SuffixQuit;
321 /** The fixed quit message in use, or an empty string
323 std::string FixedQuit;
325 /** The part prefix in use, or an empty string
327 std::string PrefixPart;
329 /** The part suffix in use, or an empty string
331 std::string SuffixPart;
333 /** The fixed part message in use, or an empty string
335 std::string FixedPart;
337 /** The DNS server to use for DNS queries
339 std::string DNSServer;
341 /** Pretend disabled commands don't exist.
343 bool DisabledDontExist;
345 /** This variable contains a space-seperated list
346 * of commands which are disabled by the
347 * administrator of the server for non-opers.
349 std::string DisabledCommands;
351 /** This variable identifies which usermodes have been diabled.
353 char DisabledUModes[64];
355 /** This variable identifies which chanmodes have been disabled.
357 char DisabledCModes[64];
359 /** The full path to the modules directory.
360 * This is either set at compile time, or
361 * overridden in the configuration file via
366 /** If set to true, then all opers on this server are
367 * shown with a generic 'is an IRC operator' line rather
368 * than the oper type. Oper types are still used internally.
372 /** If this value is true, banned users (+b, not extbans) will not be able to change nick
373 * if banned on any channel, nor to message them.
375 bool RestrictBannedUsers;
377 /** If this is set to true, then mode lists (e.g
378 * MODE \#chan b) are hidden from unprivileged
381 bool HideModeLists[256];
383 /** The number of seconds the DNS subsystem
384 * will wait before timing out any request.
388 /** The size of the read() buffer in the user
389 * handling code, used to read data into a user's
394 /** The value to be used for listen() backlogs
399 /** The soft limit value assigned to the irc server.
400 * The IRC server will not allow more than this
401 * number of local users.
403 unsigned int SoftLimit;
405 /** Maximum number of targets for a multi target command
406 * such as PRIVMSG or KICK
408 unsigned int MaxTargets;
410 /** True if we're going to hide netsplits as *.net *.split for non-opers
414 /** True if we're going to hide ban reasons for non-opers (e.g. G-Lines,
419 /** Announce invites to the channel with a server notice
421 InviteAnnounceState AnnounceInvites;
423 /** If this is enabled then operators will
424 * see invisible (+i) channels in /whois.
426 OperSpyWhoisState OperSpyWhois;
428 /** True if raw I/O is being logged */
431 /** Set to a non-empty string to obfuscate the server name of users in WHOIS
433 std::string HideWhoisServer;
435 /** Set to a non empty string to obfuscate nicknames prepended to a KILL.
437 std::string HideKillsServer;
439 /** The full pathname and filename of the PID
440 * file as defined in the configuration.
444 /** The connect classes in use by the IRC server.
448 /** The 005 tokens of this server (ISUPPORT)
449 * populated/repopulated upon loading or unloading
456 std::vector<std::string> isupport;
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 /** List of u-lined servers
473 std::map<irc::string, bool> ulines;
475 /** Max banlist sizes for channels (the std::string is a glob)
477 std::map<std::string, int> maxbans;
479 /** If set to true, no user DNS lookups are to be performed
483 /** If set to true, provide syntax hints for unknown commands
487 /** If set to true, users appear to quit then rejoin when their hosts change.
488 * This keeps clients synchronized properly.
492 /** If set to true, the CycleHosts mode change will be sourced from the user,
493 * rather than the server
495 bool CycleHostsFromUser;
497 /** If set to true, prefixed channel NOTICEs and PRIVMSGs will have the prefix
498 * added to the outgoing text for undernet style msg prefixing.
500 bool UndernetMsgPrefix;
502 /** If set to true, the full nick!user\@host will be shown in the TOPIC command
503 * for who set the topic last. If false, only the nick is shown.
505 bool FullHostInTopic;
507 /** Oper block and type index.
508 * For anonymous oper blocks (type only), prefix with a space.
510 OperIndex oper_blocks;
512 /** Max channels per user
514 unsigned int MaxChans;
516 /** Oper max channels per user
518 unsigned int OperMaxChans;
520 /** TS6-like server ID.
521 * NOTE: 000...999 are usable for InspIRCd servers. This
522 * makes code simpler. 0AA, 1BB etc with letters are reserved
527 /** Construct a new ServerConfig
531 /** Get server ID as string with required leading zeroes
533 const std::string& GetSID();
535 /** Update the 005 vector
539 /** Send the 005 numerics (ISUPPORT) to a user
541 void Send005(User* user);
543 /** Read the entire configuration into memory
544 * and initialize this class. All other methods
545 * should be used only by the core.
549 /** Apply configuration changes from the old configuration.
551 void Apply(ServerConfig* old, const std::string &useruid);
552 void ApplyModules(User* user);
556 /** Returns true if the given string starts with a windows drive letter
558 bool StartsWithWindowsDriveLetter(const std::string &path);
560 bool ApplyDisabledCommands(const std::string& data);
562 /** Clean a filename, stripping the directories (and drives) from string.
563 * @param name Directory to tidy
564 * @return The cleaned filename
566 static const char* CleanFilename(const char* name);
568 /** Check if a file exists.
569 * @param file The full path to a file
570 * @return True if the file exists and is readable.
572 static bool FileExists(const char* file);
574 /** If this value is true, invites will bypass more than just +i
578 /** If this value is true, snotices will not stack when repeats are sent
582 /** If true, a "Welcome to <networkname>!" NOTICE will be sent to
588 /** The background thread for config reading, so that reading from executable includes
591 class CoreExport ConfigReaderThread : public Thread
593 ServerConfig* Config;
596 const std::string TheUserUID;
597 ConfigReaderThread(const std::string &useruid)
598 : Config(new ServerConfig), done(false), TheUserUID(useruid)
602 virtual ~ConfigReaderThread()
608 /** Run in the main thread to apply the configuration */
610 bool IsDone() { return done; }