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 /** Used to indicate who we announce invites to on a channel */
215 enum InviteAnnounceState { INVITE_ANNOUNCE_NONE, INVITE_ANNOUNCE_ALL, INVITE_ANNOUNCE_OPS, INVITE_ANNOUNCE_DYNAMIC };
217 /** This holds all the information in the config file,
218 * it's indexed by tag name to a vector of key/values.
220 ConfigDataHash config_data;
222 /** Length limits, see definition of ServerLimits class
226 /** Configuration parsed from the command line.
228 CommandLineConf cmdline;
230 /** Clones CIDR range for ipv4 (0-32)
231 * Defaults to 32 (checks clones on all IPs seperately)
235 /** Clones CIDR range for ipv6 (0-128)
236 * Defaults to 128 (checks on all IPs seperately)
240 /** Max number of WhoWas entries per user.
244 /** Max number of cumulative user-entries in WhoWas.
245 * When max reached and added to, push out oldest entry FIFO style.
249 /** Max seconds a user is kept in WhoWas before being pruned.
253 /** Holds the server name of the local server
254 * as defined by the administrator.
256 std::string ServerName;
258 /** Notice to give to users when they are Xlined
260 std::string MoronBanner;
262 /* Holds the network name the local server
263 * belongs to. This is an arbitary field defined
264 * by the administrator.
268 /** Holds the description of the local server
269 * as defined by the administrator.
271 std::string ServerDesc;
273 /** Holds the admin's name, for output in
274 * the /ADMIN command.
276 std::string AdminName;
278 /** Holds the email address of the admin,
279 * for output in the /ADMIN command.
281 std::string AdminEmail;
283 /** Holds the admin's nickname, for output
284 * in the /ADMIN command
286 std::string AdminNick;
288 /** The admin-configured /DIE password
292 /** The admin-configured /RESTART password
294 std::string restartpass;
296 /** The hash method for *BOTH* the die and restart passwords.
298 std::string powerhash;
300 /** The pathname and filename of the message of the
301 * day file, as defined by the administrator.
305 /** The pathname and filename of the rules file,
306 * as defined by the administrator.
310 /** The quit prefix in use, or an empty string
312 std::string PrefixQuit;
314 /** The quit suffix in use, or an empty string
316 std::string SuffixQuit;
318 /** The fixed quit message in use, or an empty string
320 std::string FixedQuit;
322 /** The part prefix in use, or an empty string
324 std::string PrefixPart;
326 /** The part suffix in use, or an empty string
328 std::string SuffixPart;
330 /** The fixed part message in use, or an empty string
332 std::string FixedPart;
334 /** The last string found within a <die> tag, or
337 std::string DieValue;
339 /** The DNS server to use for DNS queries
341 std::string DNSServer;
343 /** Pretend disabled commands don't exist.
345 bool DisabledDontExist;
347 /** This variable contains a space-seperated list
348 * of commands which are disabled by the
349 * administrator of the server for non-opers.
351 std::string DisabledCommands;
353 /** This variable identifies which usermodes have been diabled.
355 char DisabledUModes[64];
357 /** This variable identifies which chanmodes have been disabled.
359 char DisabledCModes[64];
361 /** The full path to the modules directory.
362 * This is either set at compile time, or
363 * overridden in the configuration file via
368 /** If set to true, then all opers on this server are
369 * shown with a generic 'is an IRC operator' line rather
370 * than the oper type. Oper types are still used internally.
374 /** If this value is true, banned users (+b, not extbans) will not be able to change nick
375 * if banned on any channel, nor to message them.
377 bool RestrictBannedUsers;
379 /** If this is set to true, then mode lists (e.g
380 * MODE #chan b) are hidden from unprivileged
383 bool HideModeLists[256];
385 /** The number of seconds the DNS subsystem
386 * will wait before timing out any request.
390 /** The size of the read() buffer in the user
391 * handling code, used to read data into a user's
396 /** The value to be used for listen() backlogs
401 /** The soft limit value assigned to the irc server.
402 * The IRC server will not allow more than this
403 * number of local users.
405 unsigned int SoftLimit;
407 /** Maximum number of targets for a multi target command
408 * such as PRIVMSG or KICK
410 unsigned int MaxTargets;
412 /** True if we're going to hide netsplits as *.net *.split for non-opers
416 /** True if we're going to hide ban reasons for non-opers (e.g. G-Lines,
421 /** Announce invites to the channel with a server notice
423 InviteAnnounceState AnnounceInvites;
425 /** If this is enabled then operators will
426 * see invisible (+i) channels in /whois.
430 /** Set to a non-empty string to obfuscate the server name of users in WHOIS
432 std::string HideWhoisServer;
434 /** Set to a non empty string to obfuscate nicknames prepended to a KILL.
436 std::string HideKillsServer;
438 /** The MOTD file, cached in a file_cache type.
442 /** The RULES file, cached in a file_cache type.
446 /** The full pathname and filename of the PID
447 * file as defined in the configuration.
451 /** The connect classes in use by the IRC server.
455 /** The 005 tokens of this server (ISUPPORT)
456 * populated/repopulated upon loading or unloading
463 std::vector<std::string> isupport;
465 /** STATS characters in this list are available
468 std::string UserStats;
470 /** Default channel modes
472 std::string DefaultModes;
474 /** Custom version string, which if defined can replace the system info in VERSION.
476 std::string CustomVersion;
478 /** List of u-lined servers
480 std::map<irc::string, bool> ulines;
482 /** Max banlist sizes for channels (the std::string is a glob)
484 std::map<std::string, int> maxbans;
486 /** If set to true, no user DNS lookups are to be performed
490 /** If set to true, provide syntax hints for unknown commands
494 /** If set to true, users appear to quit then rejoin when their hosts change.
495 * This keeps clients synchronized properly.
499 /** If set to true, prefixed channel NOTICEs and PRIVMSGs will have the prefix
500 * added to the outgoing text for undernet style msg prefixing.
502 bool UndernetMsgPrefix;
504 /** If set to true, the full nick!user@host will be shown in the TOPIC command
505 * for who set the topic last. If false, only the nick is shown.
507 bool FullHostInTopic;
509 /** Oper block and type index.
510 * For anonymous oper blocks (type only), prefix with a space.
512 OperIndex oper_blocks;
514 /** Max channels per user
516 unsigned int MaxChans;
518 /** Oper max channels per user
520 unsigned int OperMaxChans;
522 /** TS6-like server ID.
523 * NOTE: 000...999 are usable for InspIRCd servers. This
524 * makes code simpler. 0AA, 1BB etc with letters are reserved
529 /** Construct a new ServerConfig
533 /** Get server ID as string with required leading zeroes
535 std::string GetSID();
537 /** Update the 005 vector
541 /** Send the 005 numerics (ISUPPORT) to a user
543 void Send005(User* user);
545 /** Read the entire configuration into memory
546 * and initialize this class. All other methods
547 * should be used only by the core.
551 /** Apply configuration changes from the old configuration.
553 void Apply(ServerConfig* old, const std::string &useruid);
554 void ApplyModules(User* user);
558 /** Read a file into a file_cache object
560 bool ReadFile(file_cache &F, const std::string& fname);
562 /* Returns true if the given string starts with a windows drive letter
564 bool StartsWithWindowsDriveLetter(const std::string &path);
566 bool ApplyDisabledCommands(const std::string& data);
568 /** Clean a filename, stripping the directories (and drives) from string.
569 * @param name Directory to tidy
570 * @return The cleaned filename
572 static const char* CleanFilename(const char* name);
574 /** Check if a file exists.
575 * @param file The full path to a file
576 * @return True if the file exists and is readable.
578 static bool FileExists(const char* file);
580 /** If this value is true, invites will bypass more than just +i
586 /** The background thread for config reading, so that reading from executable includes
589 class CoreExport ConfigReaderThread : public Thread
591 ServerConfig* Config;
594 const std::string TheUserUID;
595 ConfigReaderThread(const std::string &useruid)
596 : Config(new ServerConfig), done(false), TheUserUID(useruid)
600 virtual ~ConfigReaderThread()
606 /** Run in the main thread to apply the configuration */
608 bool IsDone() { return done; }