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 /** Create a new ConfigTag, giving access to the private KeyVal item list */
69 static ConfigTag* create(const std::string& Tag, const std::string& file, int line,
70 std::vector<KeyVal>*&items);
72 ConfigTag(const std::string& Tag, const std::string& file, int line);
75 /** An entire config file, built up of KeyValLists
77 typedef std::multimap<std::string, reference<ConfigTag> > ConfigDataHash;
79 /** Defines the server's length limits on various length-limited
80 * items such as topics, nicknames, channel names etc.
85 /** Maximum nickname length */
87 /** Maximum channel length */
89 /** Maximum number of modes per line */
91 /** Maximum length of ident, not including ~ etc */
93 /** Maximum length of a quit message */
95 /** Maximum topic length */
97 /** Maximum kick message length */
99 /** Maximum GECOS (real name) length */
101 /** Maximum away message length */
104 /** Creating the class initialises it to the defaults
105 * as in 1.1's ./configure script. Reading other values
106 * from the config will change these values.
108 ServerLimits() : NickMax(31), ChanMax(64), MaxModes(20), IdentMax(12), MaxQuit(255), MaxTopic(307), MaxKick(255), MaxGecos(128), MaxAway(200)
112 /** Finalises the settings by adding one. This allows for them to be used as-is
113 * without a 'value+1' when using the std::string assignment methods etc.
128 struct CommandLineConf
130 /** If this value is true, the owner of the
131 * server specified -nofork on the command
132 * line, causing the daemon to stay in the
137 /** If this value if true then all log
138 * messages will be output, regardless of
139 * the level given in the config file.
140 * This is set with the -debug commandline
145 /** If this is true then log output will be
146 * written to the logfile. This is the default.
147 * If you put -nolog on the commandline then
148 * the logfile will not be written.
149 * This is meant to be used in conjunction with
150 * -debug for debugging without filling up the
155 /** True if we have been told to run the testsuite from the commandline,
156 * rather than entering the mainloop.
160 /** Saved argc from startup
164 /** Saved argv from startup
168 std::string startup_log;
171 class CoreExport OperInfo : public refcountbase
174 std::set<std::string> AllowedOperCommands;
175 std::set<std::string> AllowedPrivs;
177 /** Allowed user modes from oper classes. */
178 std::bitset<64> AllowedUserModes;
180 /** Allowed channel modes from oper classes. */
181 std::bitset<64> AllowedChanModes;
183 /** <oper> block used for this oper-up. May be NULL. */
184 reference<ConfigTag> oper_block;
185 /** <type> block used for this oper-up. Valid for local users, may be NULL on remote */
186 reference<ConfigTag> type_block;
187 /** <class> blocks referenced from the <type> block. These define individual permissions */
188 std::vector<reference<ConfigTag> > class_blocks;
189 /** Name of the oper type; i.e. the one shown in WHOIS */
192 /** Get a configuration item, searching in the oper, type, and class blocks (in that order) */
193 std::string getConfig(const std::string& key);
196 inline const char* NameStr()
198 return irc::Spacify(name.c_str());
202 typedef std::map<std::string, reference<ConfigTag> > TagIndex;
203 typedef std::map<std::string, reference<OperInfo> > OperIndex;
204 typedef ConfigDataHash::iterator ConfigIter;
205 typedef std::pair<ConfigDataHash::iterator, ConfigDataHash::iterator> ConfigTagList;
207 /** This class holds the bulk of the runtime configuration for the ircd.
208 * It allows for reading new config values, accessing configuration files,
209 * and storage of the configuration data needed to run the ircd, such as
210 * the servername, connect classes, /ADMIN data, MOTDs and filenames etc.
212 class CoreExport ServerConfig
215 void CrossCheckOperClassType();
216 void CrossCheckConnectBlocks(ServerConfig* current);
220 /** Get a configuration tag
221 * @param tag The name of the tag to get
222 * @param offset get the Nth occurance of the tag
224 ConfigTag* ConfValue(const std::string& tag);
226 ConfigTagList ConfTags(const std::string& tag);
228 /** Error stream, contains error output from any failed configuration parsing.
230 std::stringstream errstr;
232 /** True if this configuration is valid enough to run with */
235 /** Used to indicate who we announce invites to on a channel */
236 enum InviteAnnounceState { INVITE_ANNOUNCE_NONE, INVITE_ANNOUNCE_ALL, INVITE_ANNOUNCE_OPS, INVITE_ANNOUNCE_DYNAMIC };
238 /** This holds all the information in the config file,
239 * it's indexed by tag name to a vector of key/values.
241 ConfigDataHash config_data;
243 /** Length limits, see definition of ServerLimits class
247 /** Configuration parsed from the command line.
249 CommandLineConf cmdline;
251 /** Clones CIDR range for ipv4 (0-32)
252 * Defaults to 32 (checks clones on all IPs seperately)
256 /** Clones CIDR range for ipv6 (0-128)
257 * Defaults to 128 (checks on all IPs seperately)
261 /** Max number of WhoWas entries per user.
265 /** Max number of cumulative user-entries in WhoWas.
266 * When max reached and added to, push out oldest entry FIFO style.
270 /** Max seconds a user is kept in WhoWas before being pruned.
274 /** Holds the server name of the local server
275 * as defined by the administrator.
277 std::string ServerName;
279 /** Notice to give to users when they are Xlined
281 std::string MoronBanner;
283 /* Holds the network name the local server
284 * belongs to. This is an arbitary field defined
285 * by the administrator.
289 /** Holds the description of the local server
290 * as defined by the administrator.
292 std::string ServerDesc;
294 /** Holds the admin's name, for output in
295 * the /ADMIN command.
297 std::string AdminName;
299 /** Holds the email address of the admin,
300 * for output in the /ADMIN command.
302 std::string AdminEmail;
304 /** Holds the admin's nickname, for output
305 * in the /ADMIN command
307 std::string AdminNick;
309 /** The admin-configured /DIE password
313 /** The admin-configured /RESTART password
315 std::string restartpass;
317 /** The hash method for *BOTH* the die and restart passwords.
319 std::string powerhash;
321 /** The pathname and filename of the message of the
322 * day file, as defined by the administrator.
326 /** The pathname and filename of the rules file,
327 * as defined by the administrator.
331 /** The quit prefix in use, or an empty string
333 std::string PrefixQuit;
335 /** The quit suffix in use, or an empty string
337 std::string SuffixQuit;
339 /** The fixed quit message in use, or an empty string
341 std::string FixedQuit;
343 /** The part prefix in use, or an empty string
345 std::string PrefixPart;
347 /** The part suffix in use, or an empty string
349 std::string SuffixPart;
351 /** The fixed part message in use, or an empty string
353 std::string FixedPart;
355 /** The last string found within a <die> tag, or
358 std::string DieValue;
360 /** The DNS server to use for DNS queries
362 std::string DNSServer;
364 /** Pretend disabled commands don't exist.
366 bool DisabledDontExist;
368 /** This variable contains a space-seperated list
369 * of commands which are disabled by the
370 * administrator of the server for non-opers.
372 std::string DisabledCommands;
374 /** This variable identifies which usermodes have been diabled.
376 char DisabledUModes[64];
378 /** This variable identifies which chanmodes have been disabled.
380 char DisabledCModes[64];
382 /** The full path to the modules directory.
383 * This is either set at compile time, or
384 * overridden in the configuration file via
389 /** If set to true, then all opers on this server are
390 * shown with a generic 'is an IRC operator' line rather
391 * than the oper type. Oper types are still used internally.
395 /** If this value is true, banned users (+b, not extbans) will not be able to change nick
396 * if banned on any channel, nor to message them.
398 bool RestrictBannedUsers;
400 /** If this value is true, halfops have been
401 * enabled in the configuration file.
405 /** If this is set to true, then mode lists (e.g
406 * MODE #chan b) are hidden from unprivileged
409 bool HideModeLists[256];
411 /** The number of seconds the DNS subsystem
412 * will wait before timing out any request.
416 /** The size of the read() buffer in the user
417 * handling code, used to read data into a user's
422 /** The value to be used for listen() backlogs
427 /** The soft limit value assigned to the irc server.
428 * The IRC server will not allow more than this
429 * number of local users.
431 unsigned int SoftLimit;
433 /** Maximum number of targets for a multi target command
434 * such as PRIVMSG or KICK
436 unsigned int MaxTargets;
438 /** The maximum number of /WHO results allowed
439 * in any single /WHO command.
443 /** How many seconds to wait before exiting
444 * the program when /DIE is correctly issued.
448 /** True if we're going to hide netsplits as *.net *.split for non-opers
452 /** True if we're going to hide ban reasons for non-opers (e.g. G-Lines,
457 /** Announce invites to the channel with a server notice
459 InviteAnnounceState AnnounceInvites;
461 /** If this is enabled then operators will
462 * see invisible (+i) channels in /whois.
466 /** Set to a non-empty string to obfuscate the server name of users in WHOIS
468 std::string HideWhoisServer;
470 /** Set to a non empty string to obfuscate nicknames prepended to a KILL.
472 std::string HideKillsServer;
474 /** The MOTD file, cached in a file_cache type.
478 /** The RULES file, cached in a file_cache type.
482 /** The full pathname and filename of the PID
483 * file as defined in the configuration.
487 /** The connect classes in use by the IRC server.
491 /** The 005 tokens of this server (ISUPPORT)
492 * populated/repopulated upon loading or unloading
499 std::vector<std::string> isupport;
501 /** STATS characters in this list are available
504 std::string UserStats;
506 /** Default channel modes
508 std::string DefaultModes;
510 /** Custom version string, which if defined can replace the system info in VERSION.
512 std::string CustomVersion;
514 /** List of u-lined servers
516 std::map<irc::string, bool> ulines;
518 /** Max banlist sizes for channels (the std::string is a glob)
520 std::map<std::string, int> maxbans;
522 /** If set to true, no user DNS lookups are to be performed
526 /** If set to true, provide syntax hints for unknown commands
530 /** If set to true, users appear to quit then rejoin when their hosts change.
531 * This keeps clients synchronized properly.
535 /** If set to true, prefixed channel NOTICEs and PRIVMSGs will have the prefix
536 * added to the outgoing text for undernet style msg prefixing.
538 bool UndernetMsgPrefix;
540 /** If set to true, the full nick!user@host will be shown in the TOPIC command
541 * for who set the topic last. If false, only the nick is shown.
543 bool FullHostInTopic;
545 /** Oper block and type index.
546 * For anonymous oper blocks (type only), prefix with a space.
548 OperIndex oper_blocks;
550 /** Max channels per user
552 unsigned int MaxChans;
554 /** Oper max channels per user
556 unsigned int OperMaxChans;
558 /** TS6-like server ID.
559 * NOTE: 000...999 are usable for InspIRCd servers. This
560 * makes code simpler. 0AA, 1BB etc with letters are reserved
565 /** Construct a new ServerConfig
569 /** Get server ID as string with required leading zeroes
571 std::string GetSID();
573 /** Update the 005 vector
577 /** Send the 005 numerics (ISUPPORT) to a user
579 void Send005(User* user);
581 /** Read the entire configuration into memory
582 * and initialize this class. All other methods
583 * should be used only by the core.
587 /** Apply configuration changes from the old configuration.
589 void Apply(ServerConfig* old, const std::string &useruid);
590 void ApplyModules(User* user);
594 /** Read a file into a file_cache object
596 bool ReadFile(file_cache &F, const std::string& fname);
598 /* Returns true if the given string starts with a windows drive letter
600 bool StartsWithWindowsDriveLetter(const std::string &path);
602 bool ApplyDisabledCommands(const std::string& data);
604 /** Clean a filename, stripping the directories (and drives) from string.
605 * @param name Directory to tidy
606 * @return The cleaned filename
608 static const char* CleanFilename(const char* name);
610 /** Check if a file exists.
611 * @param file The full path to a file
612 * @return True if the file exists and is readable.
614 static bool FileExists(const char* file);
616 /** If this value is true, invites will bypass more than just +i