1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2010 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 /** Structure representing a single <tag> in config */
27 class CoreExport ConfigTag : public refcountbase
29 std::vector<KeyVal> items;
31 const std::string tag;
32 const std::string src_name;
35 /** Get the value of an option, using def if it does not exist */
36 std::string getString(const std::string& key, const std::string& def = "");
37 /** Get the value of an option, using def if it does not exist */
38 long getInt(const std::string& key, long def = 0);
39 /** Get the value of an option, using def if it does not exist */
40 double getFloat(const std::string& key, double def = 0);
41 /** Get the value of an option, using def if it does not exist */
42 bool getBool(const std::string& key, bool def = false);
44 /** Get the value of an option
45 * @param key The option to get
46 * @param value The location to store the value (unmodified if does not exist)
47 * @param allow_newline Allow newlines in the option (normally replaced with spaces)
48 * @return true if the option exists
50 bool readString(const std::string& key, std::string& value, bool allow_newline = false);
52 std::string getTagLocation();
54 inline const std::vector<KeyVal>& getItems() const { return items; }
56 /** Create a new ConfigTag, giving access to the private KeyVal item list */
57 static ConfigTag* create(const std::string& Tag, const std::string& file, int line,
58 std::vector<KeyVal>*&items);
60 ConfigTag(const std::string& Tag, const std::string& file, int line);
63 /** Defines the server's length limits on various length-limited
64 * items such as topics, nicknames, channel names etc.
69 /** Maximum nickname length */
71 /** Maximum channel length */
73 /** Maximum number of modes per line */
75 /** Maximum length of ident, not including ~ etc */
77 /** Maximum length of a quit message */
79 /** Maximum topic length */
81 /** Maximum kick message length */
83 /** Maximum GECOS (real name) length */
85 /** Maximum away message length */
88 /** Creating the class initialises it to the defaults
89 * as in 1.1's ./configure script. Reading other values
90 * from the config will change these values.
92 ServerLimits() : NickMax(31), ChanMax(64), MaxModes(20), IdentMax(12), MaxQuit(255), MaxTopic(307), MaxKick(255), MaxGecos(128), MaxAway(200)
96 /** Finalises the settings by adding one. This allows for them to be used as-is
97 * without a 'value+1' when using the std::string assignment methods etc.
112 struct CommandLineConf
114 /** If this value is true, the owner of the
115 * server specified -nofork on the command
116 * line, causing the daemon to stay in the
121 /** If this value if true then all log
122 * messages will be output, regardless of
123 * the level given in the config file.
124 * This is set with the -debug commandline
129 /** If this is true then log output will be
130 * written to the logfile. This is the default.
131 * If you put -nolog on the commandline then
132 * the logfile will not be written.
133 * This is meant to be used in conjunction with
134 * -debug for debugging without filling up the
139 /** True if we have been told to run the testsuite from the commandline,
140 * rather than entering the mainloop.
144 /** Saved argc from startup
148 /** Saved argv from startup
152 std::string startup_log;
155 class CoreExport OperInfo : public refcountbase
158 std::set<std::string> AllowedOperCommands;
159 std::set<std::string> AllowedPrivs;
161 /** Allowed user modes from oper classes. */
162 std::bitset<64> AllowedUserModes;
164 /** Allowed channel modes from oper classes. */
165 std::bitset<64> AllowedChanModes;
167 /** <oper> block used for this oper-up. May be NULL. */
168 reference<ConfigTag> oper_block;
169 /** <type> block used for this oper-up. Valid for local users, may be NULL on remote */
170 reference<ConfigTag> type_block;
171 /** <class> blocks referenced from the <type> block. These define individual permissions */
172 std::vector<reference<ConfigTag> > class_blocks;
173 /** Name of the oper type; i.e. the one shown in WHOIS */
176 /** Get a configuration item, searching in the oper, type, and class blocks (in that order) */
177 std::string getConfig(const std::string& key);
180 inline const char* NameStr()
182 return irc::Spacify(name.c_str());
186 /** This class holds the bulk of the runtime configuration for the ircd.
187 * It allows for reading new config values, accessing configuration files,
188 * and storage of the configuration data needed to run the ircd, such as
189 * the servername, connect classes, /ADMIN data, MOTDs and filenames etc.
191 class CoreExport ServerConfig
194 void CrossCheckOperClassType();
195 void CrossCheckConnectBlocks(ServerConfig* current);
199 /** Get a configuration tag
200 * @param tag The name of the tag to get
201 * @param offset get the Nth occurance of the tag
203 ConfigTag* ConfValue(const std::string& tag);
205 ConfigTagList ConfTags(const std::string& tag);
207 /** Error stream, contains error output from any failed configuration parsing.
209 std::stringstream errstr;
211 /** True if this configuration is valid enough to run with */
214 /** Bind to IPv6 by default */
217 /** Used to indicate who we announce invites to on a channel */
218 enum InviteAnnounceState { INVITE_ANNOUNCE_NONE, INVITE_ANNOUNCE_ALL, INVITE_ANNOUNCE_OPS, INVITE_ANNOUNCE_DYNAMIC };
220 /** This holds all the information in the config file,
221 * it's indexed by tag name to a vector of key/values.
223 ConfigDataHash config_data;
225 /** This holds all extra files that have been read in the configuration
226 * (for example, MOTD and RULES files are stored here)
228 ConfigFileCache Files;
230 /** Length limits, see definition of ServerLimits class
234 /** Configuration parsed from the command line.
236 CommandLineConf cmdline;
238 /** Clones CIDR range for ipv4 (0-32)
239 * Defaults to 32 (checks clones on all IPs seperately)
243 /** Clones CIDR range for ipv6 (0-128)
244 * Defaults to 128 (checks on all IPs seperately)
248 /** Max number of WhoWas entries per user.
252 /** Max number of cumulative user-entries in WhoWas.
253 * When max reached and added to, push out oldest entry FIFO style.
257 /** Max seconds a user is kept in WhoWas before being pruned.
261 /** Holds the server name of the local server
262 * as defined by the administrator.
264 std::string ServerName;
266 /** Notice to give to users when they are Xlined
268 std::string MoronBanner;
270 /* Holds the network name the local server
271 * belongs to. This is an arbitary field defined
272 * by the administrator.
276 /** Holds the description of the local server
277 * as defined by the administrator.
279 std::string ServerDesc;
281 /** Holds the admin's name, for output in
282 * the /ADMIN command.
284 std::string AdminName;
286 /** Holds the email address of the admin,
287 * for output in the /ADMIN command.
289 std::string AdminEmail;
291 /** Holds the admin's nickname, for output
292 * in the /ADMIN command
294 std::string AdminNick;
296 /** The admin-configured /DIE password
300 /** The admin-configured /RESTART password
302 std::string restartpass;
304 /** The hash method for *BOTH* the die and restart passwords.
306 std::string powerhash;
308 /** The pathname and filename of the message of the
309 * day file, as defined by the administrator.
313 /** The pathname and filename of the rules file,
314 * as defined by the administrator.
318 /** The quit prefix in use, or an empty string
320 std::string PrefixQuit;
322 /** The quit suffix in use, or an empty string
324 std::string SuffixQuit;
326 /** The fixed quit message in use, or an empty string
328 std::string FixedQuit;
330 /** The part prefix in use, or an empty string
332 std::string PrefixPart;
334 /** The part suffix in use, or an empty string
336 std::string SuffixPart;
338 /** The fixed part message in use, or an empty string
340 std::string FixedPart;
342 /** The DNS server to use for DNS queries
344 std::string DNSServer;
346 /** Pretend disabled commands don't exist.
348 bool DisabledDontExist;
350 /** This variable contains a space-seperated list
351 * of commands which are disabled by the
352 * administrator of the server for non-opers.
354 std::string DisabledCommands;
356 /** This variable identifies which usermodes have been diabled.
358 char DisabledUModes[64];
360 /** This variable identifies which chanmodes have been disabled.
362 char DisabledCModes[64];
364 /** The full path to the modules directory.
365 * This is either set at compile time, or
366 * overridden in the configuration file via
371 /** If set to true, then all opers on this server are
372 * shown with a generic 'is an IRC operator' line rather
373 * than the oper type. Oper types are still used internally.
377 /** If this value is true, banned users (+b, not extbans) will not be able to change nick
378 * if banned on any channel, nor to message them.
380 bool RestrictBannedUsers;
382 /** If this is set to true, then mode lists (e.g
383 * MODE #chan b) are hidden from unprivileged
386 bool HideModeLists[256];
388 /** The number of seconds the DNS subsystem
389 * will wait before timing out any request.
393 /** The size of the read() buffer in the user
394 * handling code, used to read data into a user's
399 /** The value to be used for listen() backlogs
404 /** The soft limit value assigned to the irc server.
405 * The IRC server will not allow more than this
406 * number of local users.
408 unsigned int SoftLimit;
410 /** Maximum number of targets for a multi target command
411 * such as PRIVMSG or KICK
413 unsigned int MaxTargets;
415 /** True if we're going to hide netsplits as *.net *.split for non-opers
419 /** True if we're going to hide ban reasons for non-opers (e.g. G-Lines,
424 /** Announce invites to the channel with a server notice
426 InviteAnnounceState AnnounceInvites;
428 /** If this is enabled then operators will
429 * see invisible (+i) channels in /whois.
433 /** Set to a non-empty string to obfuscate the server name of users in WHOIS
435 std::string HideWhoisServer;
437 /** Set to a non empty string to obfuscate nicknames prepended to a KILL.
439 std::string HideKillsServer;
441 /** The full pathname and filename of the PID
442 * file as defined in the configuration.
446 /** The connect classes in use by the IRC server.
450 /** The 005 tokens of this server (ISUPPORT)
451 * populated/repopulated upon loading or unloading
458 std::vector<std::string> isupport;
460 /** STATS characters in this list are available
463 std::string UserStats;
465 /** Default channel modes
467 std::string DefaultModes;
469 /** Custom version string, which if defined can replace the system info in VERSION.
471 std::string CustomVersion;
473 /** List of u-lined servers
475 std::map<irc::string, bool> ulines;
477 /** Max banlist sizes for channels (the std::string is a glob)
479 std::map<std::string, int> maxbans;
481 /** If set to true, no user DNS lookups are to be performed
485 /** If set to true, provide syntax hints for unknown commands
489 /** If set to true, users appear to quit then rejoin when their hosts change.
490 * This keeps clients synchronized properly.
494 /** If set to true, prefixed channel NOTICEs and PRIVMSGs will have the prefix
495 * added to the outgoing text for undernet style msg prefixing.
497 bool UndernetMsgPrefix;
499 /** If set to true, the full nick!user@host will be shown in the TOPIC command
500 * for who set the topic last. If false, only the nick is shown.
502 bool FullHostInTopic;
504 /** Oper block and type index.
505 * For anonymous oper blocks (type only), prefix with a space.
507 OperIndex oper_blocks;
509 /** Max channels per user
511 unsigned int MaxChans;
513 /** Oper max channels per user
515 unsigned int OperMaxChans;
517 /** TS6-like server ID.
518 * NOTE: 000...999 are usable for InspIRCd servers. This
519 * makes code simpler. 0AA, 1BB etc with letters are reserved
524 /** Construct a new ServerConfig
528 /** Get server ID as string with required leading zeroes
530 std::string GetSID();
532 /** Update the 005 vector
536 /** Send the 005 numerics (ISUPPORT) to a user
538 void Send005(User* user);
540 /** Read the entire configuration into memory
541 * and initialize this class. All other methods
542 * should be used only by the core.
546 /** Apply configuration changes from the old configuration.
548 void Apply(ServerConfig* old, const std::string &useruid);
549 void ApplyModules(User* user);
553 /* Returns true if the given string starts with a windows drive letter
555 bool StartsWithWindowsDriveLetter(const std::string &path);
557 bool ApplyDisabledCommands(const std::string& data);
559 /** Clean a filename, stripping the directories (and drives) from string.
560 * @param name Directory to tidy
561 * @return The cleaned filename
563 static const char* CleanFilename(const char* name);
565 /** Check if a file exists.
566 * @param file The full path to a file
567 * @return True if the file exists and is readable.
569 static bool FileExists(const char* file);
571 /** If this value is true, invites will bypass more than just +i
577 /** The background thread for config reading, so that reading from executable includes
580 class CoreExport ConfigReaderThread : public Thread
582 ServerConfig* Config;
585 const std::string TheUserUID;
586 ConfigReaderThread(const std::string &useruid)
587 : Config(new ServerConfig), done(false), TheUserUID(useruid)
591 virtual ~ConfigReaderThread()
597 /** Run in the main thread to apply the configuration */
599 bool IsDone() { return done; }