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 typedef std::map<std::string, reference<ConfigTag> > TagIndex;
66 /** Defines the server's length limits on various length-limited
67 * items such as topics, nicknames, channel names etc.
72 /** Maximum nickname length */
74 /** Maximum channel length */
76 /** Maximum number of modes per line */
78 /** Maximum length of ident, not including ~ etc */
80 /** Maximum length of a quit message */
82 /** Maximum topic length */
84 /** Maximum kick message length */
86 /** Maximum GECOS (real name) length */
88 /** Maximum away message length */
91 /** Creating the class initialises it to the defaults
92 * as in 1.1's ./configure script. Reading other values
93 * from the config will change these values.
95 ServerLimits() : NickMax(31), ChanMax(64), MaxModes(20), IdentMax(12), MaxQuit(255), MaxTopic(307), MaxKick(255), MaxGecos(128), MaxAway(200)
99 /** Finalises the settings by adding one. This allows for them to be used as-is
100 * without a 'value+1' when using the std::string assignment methods etc.
115 /** This class holds the bulk of the runtime configuration for the ircd.
116 * It allows for reading new config values, accessing configuration files,
117 * and storage of the configuration data needed to run the ircd, such as
118 * the servername, connect classes, /ADMIN data, MOTDs and filenames etc.
120 class CoreExport ServerConfig
123 void CrossCheckOperClassType();
124 void CrossCheckConnectBlocks(ServerConfig* current);
127 /** Error stream, contains error output from any failed configuration parsing.
129 std::stringstream errstr;
131 /** True if this configuration is valid enough to run with */
134 /** Used to indicate who we announce invites to on a channel */
135 enum InviteAnnounceState { INVITE_ANNOUNCE_NONE, INVITE_ANNOUNCE_ALL, INVITE_ANNOUNCE_OPS, INVITE_ANNOUNCE_DYNAMIC };
137 /** Not used any more as it is named, can probably be removed or renamed.
141 /** This holds all the information in the config file,
142 * it's indexed by tag name to a vector of key/values.
144 ConfigDataHash config_data;
146 /** Length limits, see definition of ServerLimits class
150 /** Clones CIDR range for ipv4 (0-32)
151 * Defaults to 32 (checks clones on all IPs seperately)
155 /** Clones CIDR range for ipv6 (0-128)
156 * Defaults to 128 (checks on all IPs seperately)
160 /** Max number of WhoWas entries per user.
164 /** Max number of cumulative user-entries in WhoWas.
165 * When max reached and added to, push out oldest entry FIFO style.
169 /** Max seconds a user is kept in WhoWas before being pruned.
173 /** Both for set(g|u)id.
176 std::string SetGroup;
178 /** Holds the server name of the local server
179 * as defined by the administrator.
181 std::string ServerName;
183 /** Notice to give to users when they are Xlined
185 std::string MoronBanner;
187 /* Holds the network name the local server
188 * belongs to. This is an arbitary field defined
189 * by the administrator.
193 /** Holds the description of the local server
194 * as defined by the administrator.
196 std::string ServerDesc;
198 /** Holds the admin's name, for output in
199 * the /ADMIN command.
201 std::string AdminName;
203 /** Holds the email address of the admin,
204 * for output in the /ADMIN command.
206 std::string AdminEmail;
208 /** Holds the admin's nickname, for output
209 * in the /ADMIN command
211 std::string AdminNick;
213 /** The admin-configured /DIE password
217 /** The admin-configured /RESTART password
219 std::string restartpass;
221 /** The hash method for *BOTH* the die and restart passwords.
223 std::string powerhash;
225 /** The pathname and filename of the message of the
226 * day file, as defined by the administrator.
230 /** The pathname and filename of the rules file,
231 * as defined by the administrator.
235 /** The quit prefix in use, or an empty string
237 std::string PrefixQuit;
239 /** The quit suffix in use, or an empty string
241 std::string SuffixQuit;
243 /** The fixed quit message in use, or an empty string
245 std::string FixedQuit;
247 /** The part prefix in use, or an empty string
249 std::string PrefixPart;
251 /** The part suffix in use, or an empty string
253 std::string SuffixPart;
255 /** The fixed part message in use, or an empty string
257 std::string FixedPart;
259 /** The last string found within a <die> tag, or
262 std::string DieValue;
264 /** The DNS server to use for DNS queries
266 std::string DNSServer;
268 /** Pretend disabled commands don't exist.
270 bool DisabledDontExist;
272 /** This variable contains a space-seperated list
273 * of commands which are disabled by the
274 * administrator of the server for non-opers.
276 std::string DisabledCommands;
278 /** This variable identifies which usermodes have been diabled.
281 char DisabledUModes[64];
283 /** This variable identifies which chanmodes have been disabled.
285 char DisabledCModes[64];
287 /** The full path to the modules directory.
288 * This is either set at compile time, or
289 * overridden in the configuration file via
294 /** The file handle of the logfile. If this
295 * value is NULL, the log file is not open,
296 * probably due to a permissions error on
297 * startup (this should not happen in normal
302 /** If this value is true, the owner of the
303 * server specified -nofork on the command
304 * line, causing the daemon to stay in the
309 /** If this value if true then all log
310 * messages will be output, regardless of
311 * the level given in the config file.
312 * This is set with the -debug commandline
317 /** If this is true then log output will be
318 * written to the logfile. This is the default.
319 * If you put -nolog on the commandline then
320 * the logfile will not be written.
321 * This is meant to be used in conjunction with
322 * -debug for debugging without filling up the
327 /** If set to true, then all opers on this server are
328 * shown with a generic 'is an IRC operator' line rather
329 * than the oper type. Oper types are still used internally.
333 /** If this value is true, banned users (+b, not extbans) will not be able to change nick
334 * if banned on any channel, nor to message them.
336 bool RestrictBannedUsers;
338 /** If this value is true, halfops have been
339 * enabled in the configuration file.
343 /** If this is set to true, then mode lists (e.g
344 * MODE #chan b) are hidden from unprivileged
347 bool HideModeLists[256];
349 /** The number of seconds the DNS subsystem
350 * will wait before timing out any request.
354 /** The size of the read() buffer in the user
355 * handling code, used to read data into a user's
360 /** The value to be used for listen() backlogs
365 /** The soft limit value assigned to the irc server.
366 * The IRC server will not allow more than this
367 * number of local users.
369 unsigned int SoftLimit;
371 /** Maximum number of targets for a multi target command
372 * such as PRIVMSG or KICK
374 unsigned int MaxTargets;
376 /** The maximum number of /WHO results allowed
377 * in any single /WHO command.
381 /** True if the DEBUG loglevel is selected.
385 /** How many seconds to wait before exiting
386 * the program when /DIE is correctly issued.
390 /** True if we're going to hide netsplits as *.net *.split for non-opers
394 /** True if we're going to hide ban reasons for non-opers (e.g. G-Lines,
399 /** Announce invites to the channel with a server notice
401 InviteAnnounceState AnnounceInvites;
403 /** If this is enabled then operators will
404 * see invisible (+i) channels in /whois.
408 /** Set to a non-empty string to obfuscate the server name of users in WHOIS
410 std::string HideWhoisServer;
412 /** Set to a non empty string to obfuscate nicknames prepended to a KILL.
414 std::string HideKillsServer;
416 /** The MOTD file, cached in a file_cache type.
420 /** The RULES file, cached in a file_cache type.
424 /** The full pathname and filename of the PID
425 * file as defined in the configuration.
429 /** The connect classes in use by the IRC server.
433 /** The 005 tokens of this server (ISUPPORT)
434 * populated/repopulated upon loading or unloading
441 std::vector<std::string> isupport;
443 /** STATS characters in this list are available
446 std::string UserStats;
448 /** The path and filename of the ircd.log file
452 /** Default channel modes
454 std::string DefaultModes;
456 /** Custom version string, which if defined can replace the system info in VERSION.
458 std::string CustomVersion;
460 /** List of u-lined servers
462 std::map<irc::string, bool> ulines;
464 /** Max banlist sizes for channels (the std::string is a glob)
466 std::map<std::string, int> maxbans;
468 /** Directory where the inspircd binary resides
472 /** If set to true, no user DNS lookups are to be performed
476 /** If set to true, provide syntax hints for unknown commands
480 /** If set to true, users appear to quit then rejoin when their hosts change.
481 * This keeps clients synchronized properly.
485 /** If set to true, prefixed channel NOTICEs and PRIVMSGs will have the prefix
486 * added to the outgoing text for undernet style msg prefixing.
488 bool UndernetMsgPrefix;
490 /** If set to true, the full nick!user@host will be shown in the TOPIC command
491 * for who set the topic last. If false, only the nick is shown.
493 bool FullHostInTopic;
495 /** All oper type definitions from the config file
499 /** All oper class definitions from the config file
503 /** Saved argv from startup
507 /** Saved argc from startup
511 /** Max channels per user
513 unsigned int MaxChans;
515 /** Oper max channels per user
517 unsigned int OperMaxChans;
519 /** TS6-like server ID.
520 * NOTE: 000...999 are usable for InspIRCd servers. This
521 * makes code simpler. 0AA, 1BB etc with letters are reserved
526 /** True if we have been told to run the testsuite from the commandline,
527 * rather than entering the mainloop.
531 /** Construct a new ServerConfig
535 /** Get server ID as string with required leading zeroes
537 std::string GetSID();
539 /** Update the 005 vector
543 /** Send the 005 numerics (ISUPPORT) to a user
545 void Send005(User* user);
547 /** Read the entire configuration into memory
548 * and initialize this class. All other methods
549 * should be used only by the core.
553 /** Apply configuration changes from the old configuration.
555 void Apply(ServerConfig* old, const std::string &useruid);
556 void ApplyModules(User* user);
560 /** Read a file into a file_cache object
562 bool ReadFile(file_cache &F, const std::string& fname);
564 /* Returns true if the given string starts with a windows drive letter
566 bool StartsWithWindowsDriveLetter(const std::string &path);
568 /** Load 'filename' into 'target', with the new config parser everything is parsed into
569 * tag/key/value at load-time rather than at read-value time.
571 bool LoadConf(FILE* &conf, const char* filename, bool allowexeinc);
573 /** Load 'filename' into 'target', with the new config parser everything is parsed into
574 * tag/key/value at load-time rather than at read-value time.
576 bool LoadConf(FILE* &conf, const std::string &filename, bool allowexeinc);
578 ConfigTag* ConfValue(const std::string& tag, int offset = 0);
580 bool ApplyDisabledCommands(const std::string& data);
582 /** Clean a filename, stripping the directories (and drives) from string.
583 * @param name Directory to tidy
584 * @return The cleaned filename
586 static const char* CleanFilename(const char* name);
588 /** Check if a file exists.
589 * @param file The full path to a file
590 * @return True if the file exists and is readable.
592 static bool FileExists(const char* file);
594 /** If this value is true, invites will bypass more than just +i