1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2007 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/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])
31 #include "socketengine.h"
38 /** Types of data in the core config
46 DT_ALLOW_NEWLINE = 128
49 /** Holds a config value, either string, integer or boolean.
50 * Callback functions receive one or more of these, either on
51 * their own as a reference, or in a reference to a deque of them.
52 * The callback function can then alter the values of the ValueItem
53 * classes to validate the settings.
60 ValueItem(bool value);
61 ValueItem(char* value);
62 void Set(char* value);
63 void Set(const char* val);
70 /** The base class of the container 'ValueContainer'
71 * used internally by the core to hold core values.
73 class ValueContainerBase
76 ValueContainerBase() { }
77 virtual ~ValueContainerBase() { }
80 /** ValueContainer is used to contain pointers to different
81 * core values such as the server name, maximum number of
83 * It is specialized to hold a data type, then pointed at
84 * a value in the ServerConfig class. When the value has been
85 * read and validated, the Set method is called to write the
86 * value safely in a type-safe manner.
88 template<typename T> class ValueContainer : public ValueContainerBase
104 void Set(T newval, size_t s)
106 memcpy(val, newval, s);
110 /** A specialization of ValueContainer to hold a pointer to a bool
112 typedef ValueContainer<bool*> ValueContainerBool;
114 /** A specialization of ValueContainer to hold a pointer to
117 typedef ValueContainer<unsigned int*> ValueContainerUInt;
119 /** A specialization of ValueContainer to hold a pointer to
122 typedef ValueContainer<char*> ValueContainerChar;
124 /** A specialization of ValueContainer to hold a pointer to
127 typedef ValueContainer<int*> ValueContainerInt;
129 /** A set of ValueItems used by multi-value validator functions
131 typedef std::deque<ValueItem> ValueList;
133 /** A callback for validating a single value
135 typedef bool (*Validator)(ServerConfig* conf, const char*, const char*, ValueItem&);
136 /** A callback for validating multiple value entries
138 typedef bool (*MultiValidator)(ServerConfig* conf, const char*, char**, ValueList&, int*);
139 /** A callback indicating the end of a group of entries
141 typedef bool (*MultiNotify)(ServerConfig* conf, const char*);
143 /** Holds a core configuration item and its callbacks
150 ValueContainerBase* val;
151 ConfigDataType datatype;
152 Validator validation_function;
155 /** Holds a core configuration item and its callbacks
156 * where there may be more than one item
162 char* items_default[13];
164 MultiNotify init_function;
165 MultiValidator validation_function;
166 MultiNotify finish_function;
169 /** A set of oper types
171 typedef std::map<irc::string,char*> opertype_t;
173 /** A Set of oper classes
175 typedef std::map<irc::string,char*> operclass_t;
178 /** This class holds the bulk of the runtime configuration for the ircd.
179 * It allows for reading new config values, accessing configuration files,
180 * and storage of the configuration data needed to run the ircd, such as
181 * the servername, connect classes, /ADMIN data, MOTDs and filenames etc.
183 class CoreExport ServerConfig : public Extensible
188 InspIRCd* ServerInstance;
190 /** This variable holds the names of all
191 * files included from the main one. This
192 * is used to make sure that no files are
193 * recursively included.
195 std::vector<std::string> include_stack;
197 /** This private method processes one line of
198 * configutation, appending errors to errorstream
199 * and setting error if an error has occured.
201 bool ParseLine(ConfigDataHash &target, std::string &line, long linenumber, std::ostringstream &errorstream);
203 /** Process an include directive
205 bool DoInclude(ConfigDataHash &target, const std::string &file, std::ostringstream &errorstream);
207 /** Check that there is only one of each configuration item
209 bool CheckOnce(char* tag, bool bail, userrec* user);
213 InspIRCd* GetInstance();
215 /** This holds all the information in the config file,
216 * it's indexed by tag name to a vector of key/values.
218 ConfigDataHash config_data;
220 /** Max number of WhoWas entries per user.
224 /** Max number of cumulative user-entries in WhoWas.
225 * When max reached and added to, push out oldest entry FIFO style.
229 /** Max seconds a user is kept in WhoWas before being pruned.
233 /** Holds the server name of the local server
234 * as defined by the administrator.
236 char ServerName[MAXBUF];
238 /* Holds the network name the local server
239 * belongs to. This is an arbitary field defined
240 * by the administrator.
242 char Network[MAXBUF];
244 /** Holds the description of the local server
245 * as defined by the administrator.
247 char ServerDesc[MAXBUF];
249 /** Holds the admin's name, for output in
250 * the /ADMIN command.
252 char AdminName[MAXBUF];
254 /** Holds the email address of the admin,
255 * for output in the /ADMIN command.
257 char AdminEmail[MAXBUF];
259 /** Holds the admin's nickname, for output
260 * in the /ADMIN command
262 char AdminNick[MAXBUF];
264 /** The admin-configured /DIE password
266 char diepass[MAXBUF];
268 /** The admin-configured /RESTART password
270 char restartpass[MAXBUF];
272 /** The pathname and filename of the message of the
273 * day file, as defined by the administrator.
277 /** The pathname and filename of the rules file,
278 * as defined by the administrator.
282 /** The quit prefix in use, or an empty string
284 char PrefixQuit[MAXBUF];
286 /** The quit suffix in use, or an empty string
288 char SuffixQuit[MAXBUF];
290 /** The fixed quit message in use, or an empty string
292 char FixedQuit[MAXBUF];
294 /** The last string found within a <die> tag, or
297 char DieValue[MAXBUF];
299 /** The DNS server to use for DNS queries
301 char DNSServer[MAXBUF];
303 /** This variable contains a space-seperated list
304 * of commands which are disabled by the
305 * administrator of the server for non-opers.
307 char DisabledCommands[MAXBUF];
309 /** The full path to the modules directory.
310 * This is either set at compile time, or
311 * overridden in the configuration file via
316 /** The full pathname to the executable, as
317 * given in argv[0] when the program starts.
319 char MyExecutable[1024];
321 /** The file handle of the logfile. If this
322 * value is NULL, the log file is not open,
323 * probably due to a permissions error on
324 * startup (this should not happen in normal
329 /** If this value is true, the owner of the
330 * server specified -nofork on the command
331 * line, causing the daemon to stay in the
336 /** If this value if true then all log
337 * messages will be output, regardless of
338 * the level given in the config file.
339 * This is set with the -debug commandline
344 /** If this is true then log output will be
345 * written to the logfile. This is the default.
346 * If you put -nolog on the commandline then
347 * the logfile will not be written.
348 * This is meant to be used in conjunction with
349 * -debug for debugging without filling up the
354 /** If this value is true, halfops have been
355 * enabled in the configuration file.
359 /** If this is set to true, then mode lists (e.g
360 * MODE #chan b) are hidden from unprivileged
363 bool HideModeLists[256];
365 /** If this is set to true, then channel operators
366 * are exempt from this channel mode. Used for +Sc etc.
368 bool ExemptChanOps[256];
370 /** The number of seconds the DNS subsystem
371 * will wait before timing out any request.
375 /** The size of the read() buffer in the user
376 * handling code, used to read data into a user's
381 /** The value to be used for listen() backlogs
386 /** The soft limit value assigned to the irc server.
387 * The IRC server will not allow more than this
388 * number of local users.
390 unsigned int SoftLimit;
392 /** Maximum number of targets for a multi target command
393 * such as PRIVMSG or KICK
395 unsigned int MaxTargets;
397 /** The maximum number of /WHO results allowed
398 * in any single /WHO command.
402 /** True if the DEBUG loglevel is selected.
406 /** The loglevel in use by the IRC server
410 /** How many seconds to wait before exiting
411 * the program when /DIE is correctly issued.
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 bool 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 char HideWhoisServer[MAXBUF];
437 /** Set to a non empty string to obfuscate nicknames prepended to a KILL.
439 char HideKillsServer[MAXBUF];
441 /** The MOTD file, cached in a file_cache type.
445 /** The RULES file, cached in a file_cache type.
449 /** The full pathname and filename of the PID
450 * file as defined in the configuration.
454 /** The connect classes in use by the IRC server.
458 /** A list of module names (names only, no paths)
459 * which are currently loaded by the server.
461 std::vector<std::string> module_names;
463 /** A list of the classes for listening client ports
465 std::vector<ListenSocket*> ports;
467 /** Boolean sets of which modules implement which functions
469 char implement_lists[255][255];
471 /** Global implementation list
473 char global_implementation[255];
475 /** A list of ports claimed by IO Modules
477 std::map<int,Module*> IOHookModule;
479 std::map<InspSocket*, Module*> SocketIOHookModule;
481 /** The 005 tokens of this server (ISUPPORT)
482 * populated/repopulated upon loading or unloading
486 std::vector<std::string> isupport;
488 /** STATS characters in this list are available
491 char UserStats[MAXBUF];
493 /** The path and filename of the ircd.log file
497 /** Default channel modes
499 char DefaultModes[MAXBUF];
501 /** Custom version string, which if defined can replace the system info in VERSION.
503 char CustomVersion[MAXBUF];
505 /** List of u-lined servers
507 std::map<irc::string, bool> ulines;
509 /** Max banlist sizes for channels (the std::string is a glob)
511 std::map<std::string, int> maxbans;
513 /** Directory where the inspircd binary resides
517 /** If set to true, no user DNS lookups are to be performed
521 /** If set to true, provide syntax hints for unknown commands
525 /** If set to true, users appear to quit then rejoin when their hosts change.
526 * This keeps clients synchronized properly.
530 /** If set to true, prefixed channel NOTICEs and PRIVMSGs will have the prefix
531 * added to the outgoing text for undernet style msg prefixing.
533 bool UndernetMsgPrefix;
535 /** If set to true, the full nick!user@host will be shown in the TOPIC command
536 * for who set the topic last. If false, only the nick is shown.
538 bool FullHostInTopic;
540 /** All oper type definitions from the config file
542 opertype_t opertypes;
544 /** All oper class definitions from the config file
546 operclass_t operclass;
548 /** Saved argv from startup
552 /** Saved argc from startup
556 /** Max channels per user
558 unsigned int MaxChans;
560 /** Oper max channels per user
562 unsigned int OperMaxChans;
564 /** Construct a new ServerConfig
566 ServerConfig(InspIRCd* Instance);
568 /** Clears the include stack in preperation for a Read() call.
572 /** Update the 005 vector
576 /** Send the 005 numerics (ISUPPORT) to a user
578 void Send005(userrec* user);
580 /** Read the entire configuration into memory
581 * and initialize this class. All other methods
582 * should be used only by the core.
584 void Read(bool bail, userrec* user);
586 /** Read a file into a file_cache object
588 bool ReadFile(file_cache &F, const char* fname);
590 /** Load 'filename' into 'target', with the new config parser everything is parsed into
591 * tag/key/value at load-time rather than at read-value time.
594 /** Report a configuration error given in errormessage.
595 * @param bail If this is set to true, the error is sent to the console, and the program exits
596 * @param user If this is set to a non-null value, and bail is false, the errors are spooled to
597 * this user as SNOTICEs.
598 * If the parameter is NULL, the messages are spooled to all users via WriteOpers as SNOTICEs.
600 void ReportConfigError(const std::string &errormessage, bool bail, userrec* user);
602 /** Load 'filename' into 'target', with the new config parser everything is parsed into
603 * tag/key/value at load-time rather than at read-value time.
605 bool LoadConf(ConfigDataHash &target, const char* filename, std::ostringstream &errorstream);
607 /** Load 'filename' into 'target', with the new config parser everything is parsed into
608 * tag/key/value at load-time rather than at read-value time.
610 bool LoadConf(ConfigDataHash &target, const std::string &filename, std::ostringstream &errorstream);
612 /* Both these return true if the value existed or false otherwise */
614 /** Writes 'length' chars into 'result' as a string
616 bool ConfValue(ConfigDataHash &target, const char* tag, const char* var, int index, char* result, int length, bool allow_linefeeds = false);
617 bool ConfValue(ConfigDataHash &target, const char* tag, const char* var, const char* default_value, int index, char* result, int length, bool allow_linefeeds = false);
619 /** Writes 'length' chars into 'result' as a string
621 bool ConfValue(ConfigDataHash &target, const std::string &tag, const std::string &var, int index, std::string &result, bool allow_linefeeds = false);
622 bool ConfValue(ConfigDataHash &target, const std::string &tag, const std::string &var, const std::string &default_value, int index, std::string &result, bool allow_linefeeds = false);
624 /** Tries to convert the value to an integer and write it to 'result'
626 bool ConfValueInteger(ConfigDataHash &target, const char* tag, const char* var, int index, int &result);
627 bool ConfValueInteger(ConfigDataHash &target, const char* tag, const char* var, const char* default_value, int index, int &result);
628 /** Tries to convert the value to an integer and write it to 'result'
630 bool ConfValueInteger(ConfigDataHash &target, const std::string &tag, const std::string &var, int index, int &result);
631 bool ConfValueInteger(ConfigDataHash &target, const std::string &tag, const std::string &var, const std::string &default_value, int index, int &result);
633 /** Returns true if the value exists and has a true value, false otherwise
635 bool ConfValueBool(ConfigDataHash &target, const char* tag, const char* var, int index);
636 bool ConfValueBool(ConfigDataHash &target, const char* tag, const char* var, const char* default_value, int index);
637 /** Returns true if the value exists and has a true value, false otherwise
639 bool ConfValueBool(ConfigDataHash &target, const std::string &tag, const std::string &var, int index);
640 bool ConfValueBool(ConfigDataHash &target, const std::string &tag, const std::string &var, const std::string &default_value, int index);
642 /** Returns the number of occurences of tag in the config file
644 int ConfValueEnum(ConfigDataHash &target, const char* tag);
645 /** Returns the number of occurences of tag in the config file
647 int ConfValueEnum(ConfigDataHash &target, const std::string &tag);
649 /** Returns the numbers of vars inside the index'th 'tag in the config file
651 int ConfVarEnum(ConfigDataHash &target, const char* tag, int index);
652 /** Returns the numbers of vars inside the index'th 'tag in the config file
654 int ConfVarEnum(ConfigDataHash &target, const std::string &tag, int index);
656 Module* GetIOHook(int port);
657 bool AddIOHook(int port, Module* iomod);
658 bool DelIOHook(int port);
659 Module* GetIOHook(InspSocket* is);
660 bool AddIOHook(Module* iomod, InspSocket* is);
661 bool DelIOHook(InspSocket* is);
663 std::string GetFullProgDir();
664 static bool DirValid(const char* dirandfile);
665 static char* CleanFilename(char* name);
666 static bool FileExists(const char* file);
670 CoreExport bool InitializeDisabledCommands(const char* data, InspIRCd* ServerInstance);
672 bool InitTypes(ServerConfig* conf, const char* tag);
673 bool InitClasses(ServerConfig* conf, const char* tag);
674 bool DoType(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types);
675 bool DoClass(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types);
676 bool DoneClassesAndTypes(ServerConfig* conf, const char* tag);