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
19 /** Determines if a channel op is exempt from given mode m,
20 * in config of server instance s.
22 #define CHANOPS_EXEMPT(s, m) (s->Config->ExemptChanOps[(unsigned char)m])
30 #include "socketengine.h"
33 /* Required forward definitions */
39 /** A set of oper types
41 typedef std::map<irc::string,std::string> opertype_t;
43 /** Holds an oper class.
45 struct operclass_data : public classbase
47 /** Command list for the class
49 std::string commandlist;
51 /** Channel mode list for the class
53 std::string cmodelist;
55 /** User mode list for the class
57 std::string umodelist;
59 /** Priviledges given by this class
64 /** A Set of oper classes
66 typedef std::map<irc::string, operclass_data> operclass_t;
68 /** Defines the server's length limits on various length-limited
69 * items such as topics, nicknames, channel names etc.
74 /** Maximum nickname length */
76 /** Maximum channel length */
78 /** Maximum number of modes per line */
80 /** Maximum length of ident, not including ~ etc */
82 /** Maximum length of a quit message */
84 /** Maximum topic length */
86 /** Maximum kick message length */
88 /** Maximum GECOS (real name) length */
90 /** Maximum away message length */
93 /** Creating the class initialises it to the defaults
94 * as in 1.1's ./configure script. Reading other values
95 * from the config will change these values.
97 ServerLimits() : NickMax(31), ChanMax(64), MaxModes(20), IdentMax(12), MaxQuit(255), MaxTopic(307), MaxKick(255), MaxGecos(128), MaxAway(200)
101 /** Finalises the settings by adding one. This allows for them to be used as-is
102 * without a 'value+1' when using the std::string assignment methods etc.
117 /** This class holds the bulk of the runtime configuration for the ircd.
118 * It allows for reading new config values, accessing configuration files,
119 * and storage of the configuration data needed to run the ircd, such as
120 * the servername, connect classes, /ADMIN data, MOTDs and filenames etc.
122 class CoreExport ServerConfig : public classbase
125 /** Creator/owner pointer
127 InspIRCd* ServerInstance;
129 /** This variable holds the names of all
130 * files included from the main one. This
131 * is used to make sure that no files are
132 * recursively included.
134 std::vector<std::string> include_stack;
136 /* classes removed by this rehash */
137 std::vector<ConnectClass*> removed_classes;
139 /** This private method processes one line of
140 * configutation, appending errors to errorstream
141 * and setting error if an error has occured.
143 bool ParseLine(const std::string &filename, std::string &line, long &linenumber);
145 /** Check that there is only one of each configuration item
147 bool CheckOnce(const char* tag);
149 void CrossCheckOperClassType();
150 void CrossCheckConnectBlocks(ServerConfig* current);
153 /** Process an include executable directive
155 bool DoPipe(const std::string &file);
157 /** Process an include file directive
159 bool DoInclude(const std::string &file);
161 /** Error stream, contains error output from any failed configuration parsing.
163 std::stringstream errstr;
165 /** True if this configuration is valid enough to run with */
168 /** Set of included files. Do we use this any more?
170 std::map<std::string, std::istream*> IncludedFiles;
172 /** Used to indicate who we announce invites to on a channel */
173 enum InviteAnnounceState { INVITE_ANNOUNCE_NONE, INVITE_ANNOUNCE_ALL, INVITE_ANNOUNCE_OPS, INVITE_ANNOUNCE_DYNAMIC };
175 /** Returns the creator InspIRCd pointer
177 InspIRCd* GetInstance();
179 /** Not used any more as it is named, can probably be removed or renamed.
183 /** This holds all the information in the config file,
184 * it's indexed by tag name to a vector of key/values.
186 ConfigDataHash config_data;
188 /** Length limits, see definition of ServerLimits class
192 /** Clones CIDR range for ipv4 (0-32)
193 * Defaults to 32 (checks clones on all IPs seperately)
197 /** Clones CIDR range for ipv6 (0-128)
198 * Defaults to 128 (checks on all IPs seperately)
202 /** Max number of WhoWas entries per user.
206 /** Max number of cumulative user-entries in WhoWas.
207 * When max reached and added to, push out oldest entry FIFO style.
211 /** Max seconds a user is kept in WhoWas before being pruned.
215 /** Both for set(g|u)id.
217 char SetUser[MAXBUF];
218 char SetGroup[MAXBUF];
220 /** Holds the server name of the local server
221 * as defined by the administrator.
223 char ServerName[MAXBUF];
225 /** Notice to give to users when they are Xlined
227 char MoronBanner[MAXBUF];
229 /* Holds the network name the local server
230 * belongs to. This is an arbitary field defined
231 * by the administrator.
233 char Network[MAXBUF];
235 /** Holds the description of the local server
236 * as defined by the administrator.
238 char ServerDesc[MAXBUF];
240 /** Holds the admin's name, for output in
241 * the /ADMIN command.
243 char AdminName[MAXBUF];
245 /** Holds the email address of the admin,
246 * for output in the /ADMIN command.
248 char AdminEmail[MAXBUF];
250 /** Holds the admin's nickname, for output
251 * in the /ADMIN command
253 char AdminNick[MAXBUF];
255 /** The admin-configured /DIE password
257 char diepass[MAXBUF];
259 /** The admin-configured /RESTART password
261 char restartpass[MAXBUF];
263 /** The hash method for *BOTH* the die and restart passwords.
265 char powerhash[MAXBUF];
267 /** The pathname and filename of the message of the
268 * day file, as defined by the administrator.
272 /** The pathname and filename of the rules file,
273 * as defined by the administrator.
277 /** The quit prefix in use, or an empty string
279 char PrefixQuit[MAXBUF];
281 /** The quit suffix in use, or an empty string
283 char SuffixQuit[MAXBUF];
285 /** The fixed quit message in use, or an empty string
287 char FixedQuit[MAXBUF];
289 /** The part prefix in use, or an empty string
291 char PrefixPart[MAXBUF];
293 /** The part suffix in use, or an empty string
295 char SuffixPart[MAXBUF];
297 /** The fixed part message in use, or an empty string
299 char FixedPart[MAXBUF];
301 /** The last string found within a <die> tag, or
304 char DieValue[MAXBUF];
306 /** The DNS server to use for DNS queries
308 char DNSServer[MAXBUF];
310 /** Pretend disabled commands don't exist.
312 bool DisabledDontExist;
314 /** This variable contains a space-seperated list
315 * of commands which are disabled by the
316 * administrator of the server for non-opers.
318 char DisabledCommands[MAXBUF];
320 /** This variable identifies which usermodes have been diabled.
323 char DisabledUModes[64];
325 /** This variable identifies which chanmodes have been disabled.
327 char DisabledCModes[64];
329 /** The full path to the modules directory.
330 * This is either set at compile time, or
331 * overridden in the configuration file via
336 /** The full pathname to the executable, as
337 * given in argv[0] when the program starts.
339 std::string MyExecutable;
341 /** The file handle of the logfile. If this
342 * value is NULL, the log file is not open,
343 * probably due to a permissions error on
344 * startup (this should not happen in normal
349 /** If this value is true, the owner of the
350 * server specified -nofork on the command
351 * line, causing the daemon to stay in the
356 /** If this value if true then all log
357 * messages will be output, regardless of
358 * the level given in the config file.
359 * This is set with the -debug commandline
364 /** If this is true then log output will be
365 * written to the logfile. This is the default.
366 * If you put -nolog on the commandline then
367 * the logfile will not be written.
368 * This is meant to be used in conjunction with
369 * -debug for debugging without filling up the
374 /** If set to true, then all opers on this server are
375 * shown with a generic 'is an IRC operator' line rather
376 * than the oper type. Oper types are still used internally.
380 /** If this value is true, banned users (+b, not extbans) will not be able to change nick
381 * if banned on any channel, nor to message them.
383 bool RestrictBannedUsers;
385 /** If this value is true, halfops have been
386 * enabled in the configuration file.
390 /** If this is set to true, then mode lists (e.g
391 * MODE #chan b) are hidden from unprivileged
394 bool HideModeLists[256];
396 /** If this is set to true, then channel operators
397 * are exempt from this channel mode. Used for +Sc etc.
399 bool ExemptChanOps[256];
401 /** The number of seconds the DNS subsystem
402 * will wait before timing out any request.
406 /** The size of the read() buffer in the user
407 * handling code, used to read data into a user's
412 /** The value to be used for listen() backlogs
417 /** The soft limit value assigned to the irc server.
418 * The IRC server will not allow more than this
419 * number of local users.
421 unsigned int SoftLimit;
423 /** Maximum number of targets for a multi target command
424 * such as PRIVMSG or KICK
426 unsigned int MaxTargets;
428 /** The maximum number of /WHO results allowed
429 * in any single /WHO command.
433 /** True if the DEBUG loglevel is selected.
437 /** How many seconds to wait before exiting
438 * the program when /DIE is correctly issued.
442 /** True if we're going to hide netsplits as *.net *.split for non-opers
446 /** True if we're going to hide ban reasons for non-opers (e.g. G-Lines,
451 /** Announce invites to the channel with a server notice
453 InviteAnnounceState AnnounceInvites;
455 /** If this is enabled then operators will
456 * see invisible (+i) channels in /whois.
460 /** Set to a non-empty string to obfuscate the server name of users in WHOIS
462 char HideWhoisServer[MAXBUF];
464 /** Set to a non empty string to obfuscate nicknames prepended to a KILL.
466 char HideKillsServer[MAXBUF];
468 /** The MOTD file, cached in a file_cache type.
472 /** The RULES file, cached in a file_cache type.
476 /** The full pathname and filename of the PID
477 * file as defined in the configuration.
481 /** The connect classes in use by the IRC server.
485 /** The 005 tokens of this server (ISUPPORT)
486 * populated/repopulated upon loading or unloading
493 std::vector<std::string> isupport;
495 /** STATS characters in this list are available
498 char UserStats[MAXBUF];
500 /** The path and filename of the ircd.log file
504 /** Default channel modes
506 char DefaultModes[MAXBUF];
508 /** Custom version string, which if defined can replace the system info in VERSION.
510 char CustomVersion[MAXBUF];
512 /** List of u-lined servers
514 std::map<irc::string, bool> ulines;
516 /** Max banlist sizes for channels (the std::string is a glob)
518 std::map<std::string, int> maxbans;
520 /** Directory where the inspircd binary resides
524 /** If set to true, no user DNS lookups are to be performed
528 /** If set to true, provide syntax hints for unknown commands
532 /** If set to true, users appear to quit then rejoin when their hosts change.
533 * This keeps clients synchronized properly.
537 /** If set to true, prefixed channel NOTICEs and PRIVMSGs will have the prefix
538 * added to the outgoing text for undernet style msg prefixing.
540 bool UndernetMsgPrefix;
542 /** If set to true, the full nick!user@host will be shown in the TOPIC command
543 * for who set the topic last. If false, only the nick is shown.
545 bool FullHostInTopic;
547 /** All oper type definitions from the config file
549 opertype_t opertypes;
551 /** All oper class definitions from the config file
553 operclass_t operclass;
555 /** Saved argv from startup
559 /** Saved argc from startup
563 /** Max channels per user
565 unsigned int MaxChans;
567 /** Oper max channels per user
569 unsigned int OperMaxChans;
571 /** TS6-like server ID.
572 * NOTE: 000...999 are usable for InspIRCd servers. This
573 * makes code simpler. 0AA, 1BB etc with letters are reserved
578 /** True if we have been told to run the testsuite from the commandline,
579 * rather than entering the mainloop.
583 /** Construct a new ServerConfig
585 ServerConfig(InspIRCd* Instance);
587 /** Get server ID as string with required leading zeroes
589 std::string GetSID();
591 /** Update the 005 vector
595 /** Send the 005 numerics (ISUPPORT) to a user
597 void Send005(User* user);
599 /** Read the entire configuration into memory
600 * and initialize this class. All other methods
601 * should be used only by the core.
605 /** Apply configuration changes from the old configuration.
607 void Apply(ServerConfig* old, const std::string &useruid);
608 void ApplyModules(User* user);
610 /** Read a file into a file_cache object
612 bool ReadFile(file_cache &F, const char* fname);
614 /* Returns true if the given string starts with a windows drive letter
616 bool StartsWithWindowsDriveLetter(const std::string &path);
618 /** Load 'filename' into 'target', with the new config parser everything is parsed into
619 * tag/key/value at load-time rather than at read-value time.
621 bool LoadConf(FILE* &conf, const char* filename);
623 /** Load 'filename' into 'target', with the new config parser everything is parsed into
624 * tag/key/value at load-time rather than at read-value time.
626 bool LoadConf(FILE* &conf, const std::string &filename);
628 /** Writes 'length' chars into 'result' as a string
630 bool ConfValue(const char* tag, const char* var, int index, char* result, int length, bool allow_linefeeds = false);
632 /** Writes 'length' chars into 'result' as a string
634 bool ConfValue(const char* tag, const char* var, const char* default_value, int index, char* result, int length, bool allow_linefeeds = false);
636 /** Writes 'length' chars into 'result' as a string
638 bool ConfValue(const std::string &tag, const std::string &var, int index, std::string &result, bool allow_linefeeds = false);
640 /** Writes 'length' chars into 'result' as a string
642 bool ConfValue(const std::string &tag, const std::string &var, const std::string &default_value, int index, std::string &result, bool allow_linefeeds = false);
644 /** Tries to convert the value to an integer and write it to 'result'
646 bool ConfValueInteger(const char* tag, const char* var, int index, int &result);
648 /** Tries to convert the value to an integer and write it to 'result'
650 bool ConfValueInteger(const char* tag, const char* var, const char* default_value, int index, int &result);
652 /** Tries to convert the value to an integer and write it to 'result'
654 bool ConfValueInteger(const std::string &tag, const std::string &var, int index, int &result);
656 /** Tries to convert the value to an integer and write it to 'result'
658 bool ConfValueInteger(const std::string &tag, const std::string &var, const std::string &default_value, int index, int &result);
660 /** Returns true if the value exists and has a true value, false otherwise
662 bool ConfValueBool(const char* tag, const char* var, int index);
664 /** Returns true if the value exists and has a true value, false otherwise
666 bool ConfValueBool(const char* tag, const char* var, const char* default_value, int index);
668 /** Returns true if the value exists and has a true value, false otherwise
670 bool ConfValueBool(const std::string &tag, const std::string &var, int index);
672 /** Returns true if the value exists and has a true value, false otherwise
674 bool ConfValueBool(const std::string &tag, const std::string &var, const std::string &default_value, int index);
676 /** Returns the number of occurences of tag in the config file
678 int ConfValueEnum(const char* tag);
679 /** Returns the number of occurences of tag in the config file
681 int ConfValueEnum(const std::string &tag);
683 /** Returns the numbers of vars inside the index'th 'tag in the config file
685 int ConfVarEnum(const char* tag, int index);
686 /** Returns the numbers of vars inside the index'th 'tag in the config file
688 int ConfVarEnum(const std::string &tag, int index);
690 bool ApplyDisabledCommands(const char* data);
692 /** Returns the fully qualified path to the inspircd directory
693 * @return The full program directory
695 std::string GetFullProgDir();
697 /** Clean a filename, stripping the directories (and drives) from string.
698 * @param name Directory to tidy
699 * @return The cleaned filename
701 static char* CleanFilename(char* name);
703 /** Check if a file exists.
704 * @param file The full path to a file
705 * @return True if the file exists and is readable.
707 static bool FileExists(const char* file);
709 /** If this value is true, invites will bypass more than just +i
716 /** Types of data in the core config
720 DT_NOTHING = 0, /* No data */
721 DT_INTEGER = 1, /* Integer */
722 DT_CHARPTR = 2, /* Char pointer */
723 DT_BOOLEAN = 3, /* Boolean */
724 DT_HOSTNAME = 4, /* Hostname syntax */
725 DT_NOSPACES = 5, /* No spaces */
726 DT_IPADDRESS = 6, /* IP address (v4, v6) */
727 DT_CHANNEL = 7, /* Channel name */
728 DT_LIMIT = 8, /* size_t */
729 DT_ALLOW_WILD = 64, /* Allow wildcards/CIDR in DT_IPADDRESS */
730 DT_ALLOW_NEWLINE = 128 /* New line characters allowed in DT_CHARPTR */
733 /** The maximum number of values in a core configuration tag. Can be increased if needed.
735 #define MAX_VALUES_PER_TAG 18
737 /** Holds a config value, either string, integer or boolean.
738 * Callback functions receive one or more of these, either on
739 * their own as a reference, or in a reference to a deque of them.
740 * The callback function can then alter the values of the ValueItem
741 * classes to validate the settings.
748 /** Initialize with an int */
749 ValueItem(int value);
750 /** Initialize with a bool */
751 ValueItem(bool value);
752 /** Initialize with a string */
753 ValueItem(const char* value) : v(value) { }
754 /** Change value to a string */
755 void Set(const std::string &val);
756 /** Change value to an int */
758 /** Get value as an int */
760 /** Get value as a string */
761 const char* GetString() const;
762 /** Get value as a string */
763 inline const std::string& GetValue() const { return v; }
764 /** Get value as a bool */
768 /** The base class of the container 'ValueContainer'
769 * used internally by the core to hold core values.
771 class ValueContainerBase
775 ValueContainerBase() { }
777 virtual ~ValueContainerBase() { }
780 /** ValueContainer is used to contain pointers to different
781 * core values such as the server name, maximum number of
783 * It is specialized to hold a data type, then pointed at
784 * a value in the ServerConfig class. When the value has been
785 * read and validated, the Set method is called to write the
786 * value safely in a type-safe manner.
788 template<typename T> class ValueContainer : public ValueContainerBase
790 T ServerConfig::* const vptr;
792 /** Initialize with a value of type T */
793 ValueContainer(T ServerConfig::* const offset) : vptr(offset)
797 /** Change value to type T of size s */
798 void Set(ServerConfig* conf, const T& value)
803 void Set(ServerConfig* conf, const ValueItem& item);
806 template<> void ValueContainer<char[MAXBUF]>::Set(ServerConfig* conf, ValueItem const& item);
809 class ValueContainerLimit : public ValueContainerBase
811 size_t ServerLimits::* const vptr;
813 /** Initialize with a value of type T */
814 ValueContainerLimit(size_t ServerLimits::* const offset) : vptr(offset)
818 /** Change value to type T of size s */
819 void Set(ServerConfig* conf, const size_t& value)
821 conf->Limits.*vptr = value;
825 /** A specialization of ValueContainer to hold a pointer to a bool
827 typedef ValueContainer<bool> ValueContainerBool;
829 /** A specialization of ValueContainer to hold a pointer to
832 typedef ValueContainer<unsigned int> ValueContainerUInt;
834 /** A specialization of ValueContainer to hold a pointer to
837 typedef ValueContainer<char[MAXBUF]> ValueContainerChar;
839 /** A specialization of ValueContainer to hold a pointer to
842 typedef ValueContainer<std::string> ValueContainerString;
844 /** A specialization of ValueContainer to hold a pointer to
847 typedef ValueContainer<int> ValueContainerInt;
849 /** A set of ValueItems used by multi-value validator functions
851 typedef std::deque<ValueItem> ValueList;
853 /** A callback for validating a single value
855 typedef bool (*Validator)(ServerConfig* conf, const char*, const char*, ValueItem&);
856 /** A callback for validating multiple value entries
858 typedef bool (*MultiValidator)(ServerConfig* conf, const char*, const char**, ValueList&, int*);
859 /** A callback indicating the end of a group of entries
861 typedef bool (*MultiNotify)(ServerConfig* conf, const char*);
863 /** Holds a core configuration item and its callbacks
871 /** Default, if not defined */
872 const char* default_value;
873 /** Value containers */
874 ValueContainerBase* val;
877 /** Validation function */
878 Validator validation_function;
881 /** Represents a deprecated configuration tag.
891 /** Reason for deprecation
896 /** Holds a core configuration item and its callbacks
897 * where there may be more than one item
903 /** One or more items within tag */
904 const char* items[MAX_VALUES_PER_TAG];
905 /** One or more defaults for items within tags */
906 const char* items_default[MAX_VALUES_PER_TAG];
907 /** One or more data types */
908 int datatype[MAX_VALUES_PER_TAG];
909 /** Validation function */
910 MultiValidator validation_function;