1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2009 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
14 #ifndef INSPIRCD_CONFIGREADER
15 #define INSPIRCD_CONFIGREADER
23 #include "socketengine.h"
26 /* Required forward definitions */
32 /** A cached text file stored with its contents as lines
34 typedef std::vector<std::string> file_cache;
36 /** A configuration key and value pair
38 typedef std::pair<std::string, std::string> KeyVal;
40 /** Structure representing a single <tag> in config */
41 class CoreExport ConfigTag : public refcountbase
43 std::vector<KeyVal> items;
45 const std::string tag;
46 const std::string src_name;
49 /** Get the value of an option, using def if it does not exist */
50 std::string getString(const std::string& key, const std::string& def = "");
51 /** Get the value of an option, using def if it does not exist */
52 long getInt(const std::string& key, long def = 0);
53 /** Get the value of an option, using def if it does not exist */
54 double getFloat(const std::string& key, double def = 0);
55 /** Get the value of an option, using def if it does not exist */
56 bool getBool(const std::string& key, bool def = false);
58 /** Get the value of an option
59 * @param key The option to get
60 * @param value The location to store the value (unmodified if does not exist)
61 * @param allow_newline Allow newlines in the option (normally replaced with spaces)
62 * @return true if the option exists
64 bool readString(const std::string& key, std::string& value, bool allow_newline = false);
66 std::string getTagLocation();
68 inline const std::vector<KeyVal>& getItems() const { return items; }
70 /** Create a new ConfigTag, giving access to the private KeyVal item list */
71 static ConfigTag* create(const std::string& Tag, const std::string& file, int line,
72 std::vector<KeyVal>*&items);
74 ConfigTag(const std::string& Tag, const std::string& file, int line);
77 /** An entire config file, built up of KeyValLists
79 typedef std::multimap<std::string, reference<ConfigTag> > ConfigDataHash;
81 /** Defines the server's length limits on various length-limited
82 * items such as topics, nicknames, channel names etc.
87 /** Maximum nickname length */
89 /** Maximum channel length */
91 /** Maximum number of modes per line */
93 /** Maximum length of ident, not including ~ etc */
95 /** Maximum length of a quit message */
97 /** Maximum topic length */
99 /** Maximum kick message length */
101 /** Maximum GECOS (real name) length */
103 /** Maximum away message length */
106 /** Creating the class initialises it to the defaults
107 * as in 1.1's ./configure script. Reading other values
108 * from the config will change these values.
110 ServerLimits() : NickMax(31), ChanMax(64), MaxModes(20), IdentMax(12), MaxQuit(255), MaxTopic(307), MaxKick(255), MaxGecos(128), MaxAway(200)
114 /** Finalises the settings by adding one. This allows for them to be used as-is
115 * without a 'value+1' when using the std::string assignment methods etc.
130 struct CommandLineConf
132 /** If this value is true, the owner of the
133 * server specified -nofork on the command
134 * line, causing the daemon to stay in the
139 /** If this value if true then all log
140 * messages will be output, regardless of
141 * the level given in the config file.
142 * This is set with the -debug commandline
147 /** If this is true then log output will be
148 * written to the logfile. This is the default.
149 * If you put -nolog on the commandline then
150 * the logfile will not be written.
151 * This is meant to be used in conjunction with
152 * -debug for debugging without filling up the
157 /** True if we have been told to run the testsuite from the commandline,
158 * rather than entering the mainloop.
162 /** Saved argc from startup
166 /** Saved argv from startup
170 std::string startup_log;
173 class CoreExport OperInfo : public refcountbase
176 std::set<std::string> AllowedOperCommands;
177 std::set<std::string> AllowedPrivs;
179 /** Allowed user modes from oper classes. */
180 std::bitset<64> AllowedUserModes;
182 /** Allowed channel modes from oper classes. */
183 std::bitset<64> AllowedChanModes;
185 /** <oper> block used for this oper-up. May be NULL. */
186 reference<ConfigTag> oper_block;
187 /** <type> block used for this oper-up. Valid for local users, may be NULL on remote */
188 reference<ConfigTag> type_block;
189 /** <class> blocks referenced from the <type> block. These define individual permissions */
190 std::vector<reference<ConfigTag> > class_blocks;
191 /** Name of the oper type; i.e. the one shown in WHOIS */
194 /** Get a configuration item, searching in the oper, type, and class blocks (in that order) */
195 std::string getConfig(const std::string& key);
198 inline const char* NameStr()
200 return irc::Spacify(name.c_str());
204 typedef std::map<std::string, reference<ConfigTag> > TagIndex;
205 typedef std::map<std::string, reference<OperInfo> > OperIndex;
206 typedef ConfigDataHash::iterator ConfigIter;
207 typedef std::pair<ConfigDataHash::iterator, ConfigDataHash::iterator> ConfigTagList;
209 /** This class holds the bulk of the runtime configuration for the ircd.
210 * It allows for reading new config values, accessing configuration files,
211 * and storage of the configuration data needed to run the ircd, such as
212 * the servername, connect classes, /ADMIN data, MOTDs and filenames etc.
214 class CoreExport ServerConfig
217 void CrossCheckOperClassType();
218 void CrossCheckConnectBlocks(ServerConfig* current);
222 /** Get a configuration tag
223 * @param tag The name of the tag to get
224 * @param offset get the Nth occurance of the tag
226 ConfigTag* ConfValue(const std::string& tag);
228 ConfigTagList ConfTags(const std::string& tag);
230 /** Error stream, contains error output from any failed configuration parsing.
232 std::stringstream errstr;
234 /** True if this configuration is valid enough to run with */
237 /** Used to indicate who we announce invites to on a channel */
238 enum InviteAnnounceState { INVITE_ANNOUNCE_NONE, INVITE_ANNOUNCE_ALL, INVITE_ANNOUNCE_OPS, INVITE_ANNOUNCE_DYNAMIC };
240 /** This holds all the information in the config file,
241 * it's indexed by tag name to a vector of key/values.
243 ConfigDataHash config_data;
245 /** Length limits, see definition of ServerLimits class
249 /** Configuration parsed from the command line.
251 CommandLineConf cmdline;
253 /** Clones CIDR range for ipv4 (0-32)
254 * Defaults to 32 (checks clones on all IPs seperately)
258 /** Clones CIDR range for ipv6 (0-128)
259 * Defaults to 128 (checks on all IPs seperately)
263 /** Max number of WhoWas entries per user.
267 /** Max number of cumulative user-entries in WhoWas.
268 * When max reached and added to, push out oldest entry FIFO style.
272 /** Max seconds a user is kept in WhoWas before being pruned.
276 /** Holds the server name of the local server
277 * as defined by the administrator.
279 std::string ServerName;
281 /** Notice to give to users when they are Xlined
283 std::string MoronBanner;
285 /* Holds the network name the local server
286 * belongs to. This is an arbitary field defined
287 * by the administrator.
291 /** Holds the description of the local server
292 * as defined by the administrator.
294 std::string ServerDesc;
296 /** Holds the admin's name, for output in
297 * the /ADMIN command.
299 std::string AdminName;
301 /** Holds the email address of the admin,
302 * for output in the /ADMIN command.
304 std::string AdminEmail;
306 /** Holds the admin's nickname, for output
307 * in the /ADMIN command
309 std::string AdminNick;
311 /** The admin-configured /DIE password
315 /** The admin-configured /RESTART password
317 std::string restartpass;
319 /** The hash method for *BOTH* the die and restart passwords.
321 std::string powerhash;
323 /** The pathname and filename of the message of the
324 * day file, as defined by the administrator.
328 /** The pathname and filename of the rules file,
329 * as defined by the administrator.
333 /** The quit prefix in use, or an empty string
335 std::string PrefixQuit;
337 /** The quit suffix in use, or an empty string
339 std::string SuffixQuit;
341 /** The fixed quit message in use, or an empty string
343 std::string FixedQuit;
345 /** The part prefix in use, or an empty string
347 std::string PrefixPart;
349 /** The part suffix in use, or an empty string
351 std::string SuffixPart;
353 /** The fixed part message in use, or an empty string
355 std::string FixedPart;
357 /** The last string found within a <die> tag, or
360 std::string DieValue;
362 /** The DNS server to use for DNS queries
364 std::string DNSServer;
366 /** Pretend disabled commands don't exist.
368 bool DisabledDontExist;
370 /** This variable contains a space-seperated list
371 * of commands which are disabled by the
372 * administrator of the server for non-opers.
374 std::string DisabledCommands;
376 /** This variable identifies which usermodes have been diabled.
378 char DisabledUModes[64];
380 /** This variable identifies which chanmodes have been disabled.
382 char DisabledCModes[64];
384 /** The full path to the modules directory.
385 * This is either set at compile time, or
386 * overridden in the configuration file via
391 /** If set to true, then all opers on this server are
392 * shown with a generic 'is an IRC operator' line rather
393 * than the oper type. Oper types are still used internally.
397 /** If this value is true, banned users (+b, not extbans) will not be able to change nick
398 * if banned on any channel, nor to message them.
400 bool RestrictBannedUsers;
402 /** If this value is true, halfops have been
403 * enabled in the configuration file.
407 /** If this is set to true, then mode lists (e.g
408 * MODE #chan b) are hidden from unprivileged
411 bool HideModeLists[256];
413 /** The number of seconds the DNS subsystem
414 * will wait before timing out any request.
418 /** The size of the read() buffer in the user
419 * handling code, used to read data into a user's
424 /** The value to be used for listen() backlogs
429 /** The soft limit value assigned to the irc server.
430 * The IRC server will not allow more than this
431 * number of local users.
433 unsigned int SoftLimit;
435 /** Maximum number of targets for a multi target command
436 * such as PRIVMSG or KICK
438 unsigned int MaxTargets;
440 /** The maximum number of /WHO results allowed
441 * in any single /WHO command.
445 /** How many seconds to wait before exiting
446 * the program when /DIE is correctly issued.
450 /** True if we're going to hide netsplits as *.net *.split for non-opers
454 /** True if we're going to hide ban reasons for non-opers (e.g. G-Lines,
459 /** Announce invites to the channel with a server notice
461 InviteAnnounceState AnnounceInvites;
463 /** If this is enabled then operators will
464 * see invisible (+i) channels in /whois.
468 /** Set to a non-empty string to obfuscate the server name of users in WHOIS
470 std::string HideWhoisServer;
472 /** Set to a non empty string to obfuscate nicknames prepended to a KILL.
474 std::string HideKillsServer;
476 /** The MOTD file, cached in a file_cache type.
480 /** The RULES file, cached in a file_cache type.
484 /** The full pathname and filename of the PID
485 * file as defined in the configuration.
489 /** The connect classes in use by the IRC server.
493 /** The 005 tokens of this server (ISUPPORT)
494 * populated/repopulated upon loading or unloading
501 std::vector<std::string> isupport;
503 /** STATS characters in this list are available
506 std::string UserStats;
508 /** Default channel modes
510 std::string DefaultModes;
512 /** Custom version string, which if defined can replace the system info in VERSION.
514 std::string CustomVersion;
516 /** List of u-lined servers
518 std::map<irc::string, bool> ulines;
520 /** Max banlist sizes for channels (the std::string is a glob)
522 std::map<std::string, int> maxbans;
524 /** If set to true, no user DNS lookups are to be performed
528 /** If set to true, provide syntax hints for unknown commands
532 /** If set to true, users appear to quit then rejoin when their hosts change.
533 * This keeps clients synchronized properly.
537 /** If set to true, prefixed channel NOTICEs and PRIVMSGs will have the prefix
538 * added to the outgoing text for undernet style msg prefixing.
540 bool UndernetMsgPrefix;
542 /** If set to true, the full nick!user@host will be shown in the TOPIC command
543 * for who set the topic last. If false, only the nick is shown.
545 bool FullHostInTopic;
547 /** Oper block and type index.
548 * For anonymous oper blocks (type only), prefix with a space.
550 OperIndex oper_blocks;
552 /** Max channels per user
554 unsigned int MaxChans;
556 /** Oper max channels per user
558 unsigned int OperMaxChans;
560 /** TS6-like server ID.
561 * NOTE: 000...999 are usable for InspIRCd servers. This
562 * makes code simpler. 0AA, 1BB etc with letters are reserved
567 /** Construct a new ServerConfig
571 /** Get server ID as string with required leading zeroes
573 std::string GetSID();
575 /** Update the 005 vector
579 /** Send the 005 numerics (ISUPPORT) to a user
581 void Send005(User* user);
583 /** Read the entire configuration into memory
584 * and initialize this class. All other methods
585 * should be used only by the core.
589 /** Apply configuration changes from the old configuration.
591 void Apply(ServerConfig* old, const std::string &useruid);
592 void ApplyModules(User* user);
596 /** Read a file into a file_cache object
598 bool ReadFile(file_cache &F, const std::string& fname);
600 /* Returns true if the given string starts with a windows drive letter
602 bool StartsWithWindowsDriveLetter(const std::string &path);
604 bool ApplyDisabledCommands(const std::string& data);
606 /** Clean a filename, stripping the directories (and drives) from string.
607 * @param name Directory to tidy
608 * @return The cleaned filename
610 static const char* CleanFilename(const char* name);
612 /** Check if a file exists.
613 * @param file The full path to a file
614 * @return True if the file exists and is readable.
616 static bool FileExists(const char* file);
618 /** If this value is true, invites will bypass more than just +i