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 struct CoreExport ConfigTag : public refcountbase
42 const std::string tag;
43 const std::string src_name;
45 std::vector<KeyVal> items;
47 ConfigTag(const std::string& Tag, const std::string& file, int line)
48 : tag(Tag), src_name(file), src_line(line) {}
50 std::string getString(const std::string& key, const std::string& def = "");
51 long getInt(const std::string& key, long def = 0);
52 double getFloat(const std::string& key, double def = 0);
53 bool getBool(const std::string& key, bool def = false);
55 bool readString(const std::string& key, std::string& value, bool allow_newline = false);
57 std::string getTagLocation();
60 /** An entire config file, built up of KeyValLists
62 typedef std::multimap<std::string, reference<ConfigTag> > ConfigDataHash;
64 /** Defines the server's length limits on various length-limited
65 * items such as topics, nicknames, channel names etc.
70 /** Maximum nickname length */
72 /** Maximum channel length */
74 /** Maximum number of modes per line */
76 /** Maximum length of ident, not including ~ etc */
78 /** Maximum length of a quit message */
80 /** Maximum topic length */
82 /** Maximum kick message length */
84 /** Maximum GECOS (real name) length */
86 /** Maximum away message length */
89 /** Creating the class initialises it to the defaults
90 * as in 1.1's ./configure script. Reading other values
91 * from the config will change these values.
93 ServerLimits() : NickMax(31), ChanMax(64), MaxModes(20), IdentMax(12), MaxQuit(255), MaxTopic(307), MaxKick(255), MaxGecos(128), MaxAway(200)
97 /** Finalises the settings by adding one. This allows for them to be used as-is
98 * without a 'value+1' when using the std::string assignment methods etc.
113 class CoreExport OperInfo : public refcountbase
116 std::set<std::string> AllowedOperCommands;
117 std::set<std::string> AllowedPrivs;
119 /** Allowed user modes from oper classes. */
120 std::bitset<64> AllowedUserModes;
122 /** Allowed channel modes from oper classes. */
123 std::bitset<64> AllowedChanModes;
125 /** <oper> block used for this oper-up. May be NULL. */
126 reference<ConfigTag> oper_block;
127 /** <type> block used for this oper-up. Valid for local users, may be NULL on remote */
128 reference<ConfigTag> type_block;
129 /** <class> blocks referenced from the <type> block. These define individual permissions */
130 std::vector<reference<ConfigTag> > class_blocks;
131 /** Name of the oper type; i.e. the one shown in WHOIS */
134 /** Get a configuration item, searching in the oper, type, and class blocks (in that order) */
135 std::string getConfig(const std::string& key);
138 inline const char* NameStr()
140 return irc::Spacify(name.c_str());
144 typedef std::map<std::string, reference<ConfigTag> > TagIndex;
145 typedef std::map<std::string, reference<OperInfo> > OperIndex;
147 /** This class holds the bulk of the runtime configuration for the ircd.
148 * It allows for reading new config values, accessing configuration files,
149 * and storage of the configuration data needed to run the ircd, such as
150 * the servername, connect classes, /ADMIN data, MOTDs and filenames etc.
152 class CoreExport ServerConfig
155 void CrossCheckOperClassType();
156 void CrossCheckConnectBlocks(ServerConfig* current);
160 /** Get a configuration tag
161 * @param tag The name of the tag to get
162 * @param offset get the Nth occurance of the tag
164 ConfigTag* ConfValue(const std::string& tag, int offset = 0);
166 /** Error stream, contains error output from any failed configuration parsing.
168 std::stringstream errstr;
170 /** True if this configuration is valid enough to run with */
173 /** Used to indicate who we announce invites to on a channel */
174 enum InviteAnnounceState { INVITE_ANNOUNCE_NONE, INVITE_ANNOUNCE_ALL, INVITE_ANNOUNCE_OPS, INVITE_ANNOUNCE_DYNAMIC };
176 /** This holds all the information in the config file,
177 * it's indexed by tag name to a vector of key/values.
179 ConfigDataHash config_data;
181 /** Length limits, see definition of ServerLimits class
185 /** Clones CIDR range for ipv4 (0-32)
186 * Defaults to 32 (checks clones on all IPs seperately)
190 /** Clones CIDR range for ipv6 (0-128)
191 * Defaults to 128 (checks on all IPs seperately)
195 /** Max number of WhoWas entries per user.
199 /** Max number of cumulative user-entries in WhoWas.
200 * When max reached and added to, push out oldest entry FIFO style.
204 /** Max seconds a user is kept in WhoWas before being pruned.
208 /** Both for set(g|u)id.
211 std::string SetGroup;
213 /** Holds the server name of the local server
214 * as defined by the administrator.
216 std::string ServerName;
218 /** Notice to give to users when they are Xlined
220 std::string MoronBanner;
222 /* Holds the network name the local server
223 * belongs to. This is an arbitary field defined
224 * by the administrator.
228 /** Holds the description of the local server
229 * as defined by the administrator.
231 std::string ServerDesc;
233 /** Holds the admin's name, for output in
234 * the /ADMIN command.
236 std::string AdminName;
238 /** Holds the email address of the admin,
239 * for output in the /ADMIN command.
241 std::string AdminEmail;
243 /** Holds the admin's nickname, for output
244 * in the /ADMIN command
246 std::string AdminNick;
248 /** The admin-configured /DIE password
252 /** The admin-configured /RESTART password
254 std::string restartpass;
256 /** The hash method for *BOTH* the die and restart passwords.
258 std::string powerhash;
260 /** The pathname and filename of the message of the
261 * day file, as defined by the administrator.
265 /** The pathname and filename of the rules file,
266 * as defined by the administrator.
270 /** The quit prefix in use, or an empty string
272 std::string PrefixQuit;
274 /** The quit suffix in use, or an empty string
276 std::string SuffixQuit;
278 /** The fixed quit message in use, or an empty string
280 std::string FixedQuit;
282 /** The part prefix in use, or an empty string
284 std::string PrefixPart;
286 /** The part suffix in use, or an empty string
288 std::string SuffixPart;
290 /** The fixed part message in use, or an empty string
292 std::string FixedPart;
294 /** The last string found within a <die> tag, or
297 std::string DieValue;
299 /** The DNS server to use for DNS queries
301 std::string DNSServer;
303 /** Pretend disabled commands don't exist.
305 bool DisabledDontExist;
307 /** This variable contains a space-seperated list
308 * of commands which are disabled by the
309 * administrator of the server for non-opers.
311 std::string DisabledCommands;
313 /** This variable identifies which usermodes have been diabled.
316 char DisabledUModes[64];
318 /** This variable identifies which chanmodes have been disabled.
320 char DisabledCModes[64];
322 /** The full path to the modules directory.
323 * This is either set at compile time, or
324 * overridden in the configuration file via
329 /** The file handle of the logfile. If this
330 * value is NULL, the log file is not open,
331 * probably due to a permissions error on
332 * startup (this should not happen in normal
337 /** If this value is true, the owner of the
338 * server specified -nofork on the command
339 * line, causing the daemon to stay in the
344 /** If this value if true then all log
345 * messages will be output, regardless of
346 * the level given in the config file.
347 * This is set with the -debug commandline
352 /** If this is true then log output will be
353 * written to the logfile. This is the default.
354 * If you put -nolog on the commandline then
355 * the logfile will not be written.
356 * This is meant to be used in conjunction with
357 * -debug for debugging without filling up the
362 /** If set to true, then all opers on this server are
363 * shown with a generic 'is an IRC operator' line rather
364 * than the oper type. Oper types are still used internally.
368 /** If this value is true, banned users (+b, not extbans) will not be able to change nick
369 * if banned on any channel, nor to message them.
371 bool RestrictBannedUsers;
373 /** If this value is true, halfops have been
374 * enabled in the configuration file.
378 /** If this is set to true, then mode lists (e.g
379 * MODE #chan b) are hidden from unprivileged
382 bool HideModeLists[256];
384 /** The number of seconds the DNS subsystem
385 * will wait before timing out any request.
389 /** The size of the read() buffer in the user
390 * handling code, used to read data into a user's
395 /** The value to be used for listen() backlogs
400 /** The soft limit value assigned to the irc server.
401 * The IRC server will not allow more than this
402 * number of local users.
404 unsigned int SoftLimit;
406 /** Maximum number of targets for a multi target command
407 * such as PRIVMSG or KICK
409 unsigned int MaxTargets;
411 /** The maximum number of /WHO results allowed
412 * in any single /WHO command.
416 /** True if the DEBUG loglevel is selected.
420 /** How many seconds to wait before exiting
421 * the program when /DIE is correctly issued.
425 /** True if we're going to hide netsplits as *.net *.split for non-opers
429 /** True if we're going to hide ban reasons for non-opers (e.g. G-Lines,
434 /** Announce invites to the channel with a server notice
436 InviteAnnounceState AnnounceInvites;
438 /** If this is enabled then operators will
439 * see invisible (+i) channels in /whois.
443 /** Set to a non-empty string to obfuscate the server name of users in WHOIS
445 std::string HideWhoisServer;
447 /** Set to a non empty string to obfuscate nicknames prepended to a KILL.
449 std::string HideKillsServer;
451 /** The MOTD file, cached in a file_cache type.
455 /** The RULES file, cached in a file_cache type.
459 /** The full pathname and filename of the PID
460 * file as defined in the configuration.
464 /** The connect classes in use by the IRC server.
468 /** The 005 tokens of this server (ISUPPORT)
469 * populated/repopulated upon loading or unloading
476 std::vector<std::string> isupport;
478 /** STATS characters in this list are available
481 std::string UserStats;
483 /** The path and filename of the ircd.log file
487 /** Default channel modes
489 std::string DefaultModes;
491 /** Custom version string, which if defined can replace the system info in VERSION.
493 std::string CustomVersion;
495 /** List of u-lined servers
497 std::map<irc::string, bool> ulines;
499 /** Max banlist sizes for channels (the std::string is a glob)
501 std::map<std::string, int> maxbans;
503 /** Directory where the inspircd binary resides
507 /** If set to true, no user DNS lookups are to be performed
511 /** If set to true, provide syntax hints for unknown commands
515 /** If set to true, users appear to quit then rejoin when their hosts change.
516 * This keeps clients synchronized properly.
520 /** If set to true, prefixed channel NOTICEs and PRIVMSGs will have the prefix
521 * added to the outgoing text for undernet style msg prefixing.
523 bool UndernetMsgPrefix;
525 /** If set to true, the full nick!user@host will be shown in the TOPIC command
526 * for who set the topic last. If false, only the nick is shown.
528 bool FullHostInTopic;
530 /** Oper block and type index.
531 * For anonymous oper blocks (type only), prefix with a space.
533 OperIndex oper_blocks;
535 /** Saved argv from startup
539 /** Saved argc from startup
543 /** Max channels per user
545 unsigned int MaxChans;
547 /** Oper max channels per user
549 unsigned int OperMaxChans;
551 /** TS6-like server ID.
552 * NOTE: 000...999 are usable for InspIRCd servers. This
553 * makes code simpler. 0AA, 1BB etc with letters are reserved
558 /** True if we have been told to run the testsuite from the commandline,
559 * rather than entering the mainloop.
563 /** Construct a new ServerConfig
567 /** Get server ID as string with required leading zeroes
569 std::string GetSID();
571 /** Update the 005 vector
575 /** Send the 005 numerics (ISUPPORT) to a user
577 void Send005(User* user);
579 /** Read the entire configuration into memory
580 * and initialize this class. All other methods
581 * should be used only by the core.
585 /** Apply configuration changes from the old configuration.
587 void Apply(ServerConfig* old, const std::string &useruid);
588 void ApplyModules(User* user);
592 /** Read a file into a file_cache object
594 bool ReadFile(file_cache &F, const std::string& fname);
596 /* Returns true if the given string starts with a windows drive letter
598 bool StartsWithWindowsDriveLetter(const std::string &path);
600 bool ApplyDisabledCommands(const std::string& data);
602 /** Clean a filename, stripping the directories (and drives) from string.
603 * @param name Directory to tidy
604 * @return The cleaned filename
606 static const char* CleanFilename(const char* name);
608 /** Check if a file exists.
609 * @param file The full path to a file
610 * @return True if the file exists and is readable.
612 static bool FileExists(const char* file);
614 /** If this value is true, invites will bypass more than just +i