]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/configreader.h
Add RAWIO log level which is more verbose than DEBUG
[user/henk/code/inspircd.git] / include / configreader.h
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2010 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #ifndef INSPIRCD_CONFIGREADER
15 #define INSPIRCD_CONFIGREADER
16
17 #include <sstream>
18 #include <string>
19 #include <vector>
20 #include <map>
21 #include "inspircd.h"
22 #include "modules.h"
23 #include "socketengine.h"
24 #include "socket.h"
25
26 /** Structure representing a single <tag> in config */
27 class CoreExport ConfigTag : public refcountbase
28 {
29         std::vector<KeyVal> items;
30  public:
31         const std::string tag;
32         const std::string src_name;
33         const int src_line;
34
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);
43
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
49          */
50         bool readString(const std::string& key, std::string& value, bool allow_newline = false);
51
52         std::string getTagLocation();
53
54         inline const std::vector<KeyVal>& getItems() const { return items; }
55
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);
59  private:
60         ConfigTag(const std::string& Tag, const std::string& file, int line);
61 };
62
63 /** Defines the server's length limits on various length-limited
64  * items such as topics, nicknames, channel names etc.
65  */
66 class ServerLimits
67 {
68  public:
69         /** Maximum nickname length */
70         size_t NickMax;
71         /** Maximum channel length */
72         size_t ChanMax;
73         /** Maximum number of modes per line */
74         size_t MaxModes;
75         /** Maximum length of ident, not including ~ etc */
76         size_t IdentMax;
77         /** Maximum length of a quit message */
78         size_t MaxQuit;
79         /** Maximum topic length */
80         size_t MaxTopic;
81         /** Maximum kick message length */
82         size_t MaxKick;
83         /** Maximum GECOS (real name) length */
84         size_t MaxGecos;
85         /** Maximum away message length */
86         size_t MaxAway;
87
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.
91          */
92         ServerLimits() : NickMax(31), ChanMax(64), MaxModes(20), IdentMax(12), MaxQuit(255), MaxTopic(307), MaxKick(255), MaxGecos(128), MaxAway(200)
93         {
94         }
95
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.
98          */
99         void Finalise()
100         {
101                 NickMax++;
102                 ChanMax++;
103                 IdentMax++;
104                 MaxQuit++;
105                 MaxTopic++;
106                 MaxKick++;
107                 MaxGecos++;
108                 MaxAway++;
109         }
110 };
111
112 struct CommandLineConf
113 {
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
117          * foreground.
118          */
119         bool nofork;
120
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
125          * option.
126          */
127         bool forcedebug;
128
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
135          * hard disk.
136          */
137         bool writelog;
138
139         /** True if we have been told to run the testsuite from the commandline,
140          * rather than entering the mainloop.
141          */
142         bool TestSuite;
143
144         /** Saved argc from startup
145          */
146         int argc;
147
148         /** Saved argv from startup
149          */
150         char** argv;
151
152         std::string startup_log;
153 };
154
155 class CoreExport OperInfo : public refcountbase
156 {
157  public:
158         std::set<std::string> AllowedOperCommands;
159         std::set<std::string> AllowedPrivs;
160
161         /** Allowed user modes from oper classes. */
162         std::bitset<64> AllowedUserModes;
163
164         /** Allowed channel modes from oper classes. */
165         std::bitset<64> AllowedChanModes;
166
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 */
174         std::string name;
175
176         /** Get a configuration item, searching in the oper, type, and class blocks (in that order) */
177         std::string getConfig(const std::string& key);
178         void init();
179
180         inline const char* NameStr()
181         {
182                 return irc::Spacify(name.c_str());
183         }
184 };
185
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.
190  */
191 class CoreExport ServerConfig
192 {
193   private:
194         void CrossCheckOperClassType();
195         void CrossCheckConnectBlocks(ServerConfig* current);
196
197  public:
198
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
202          */
203         ConfigTag* ConfValue(const std::string& tag);
204
205         ConfigTagList ConfTags(const std::string& tag);
206
207         /** Error stream, contains error output from any failed configuration parsing.
208          */
209         std::stringstream errstr;
210
211         /** True if this configuration is valid enough to run with */
212         bool valid;
213
214         /** Bind to IPv6 by default */
215         bool WildcardIPv6;
216
217         /** Used to indicate who we announce invites to on a channel */
218         enum InviteAnnounceState { INVITE_ANNOUNCE_NONE, INVITE_ANNOUNCE_ALL, INVITE_ANNOUNCE_OPS, INVITE_ANNOUNCE_DYNAMIC };
219
220         /** This holds all the information in the config file,
221          * it's indexed by tag name to a vector of key/values.
222          */
223         ConfigDataHash config_data;
224
225         /** This holds all extra files that have been read in the configuration
226          * (for example, MOTD and RULES files are stored here)
227          */
228         ConfigFileCache Files;
229
230         /** Length limits, see definition of ServerLimits class
231          */
232         ServerLimits Limits;
233
234         /** Configuration parsed from the command line.
235          */
236         CommandLineConf cmdline;
237
238         /** Clones CIDR range for ipv4 (0-32)
239          * Defaults to 32 (checks clones on all IPs seperately)
240          */
241         int c_ipv4_range;
242
243         /** Clones CIDR range for ipv6 (0-128)
244          * Defaults to 128 (checks on all IPs seperately)
245          */
246         int c_ipv6_range;
247
248         /** Max number of WhoWas entries per user.
249          */
250         int WhoWasGroupSize;
251
252         /** Max number of cumulative user-entries in WhoWas.
253          *  When max reached and added to, push out oldest entry FIFO style.
254          */
255         int WhoWasMaxGroups;
256
257         /** Max seconds a user is kept in WhoWas before being pruned.
258          */
259         int WhoWasMaxKeep;
260
261         /** Holds the server name of the local server
262          * as defined by the administrator.
263          */
264         std::string ServerName;
265
266         /** Notice to give to users when they are Xlined
267          */
268         std::string MoronBanner;
269
270         /* Holds the network name the local server
271          * belongs to. This is an arbitary field defined
272          * by the administrator.
273          */
274         std::string Network;
275
276         /** Holds the description of the local server
277          * as defined by the administrator.
278          */
279         std::string ServerDesc;
280
281         /** Holds the admin's name, for output in
282          * the /ADMIN command.
283          */
284         std::string AdminName;
285
286         /** Holds the email address of the admin,
287          * for output in the /ADMIN command.
288          */
289         std::string AdminEmail;
290
291         /** Holds the admin's nickname, for output
292          * in the /ADMIN command
293          */
294         std::string AdminNick;
295
296         /** The admin-configured /DIE password
297          */
298         std::string diepass;
299
300         /** The admin-configured /RESTART password
301          */
302         std::string restartpass;
303
304         /** The hash method for *BOTH* the die and restart passwords.
305          */
306         std::string powerhash;
307
308         /** The pathname and filename of the message of the
309          * day file, as defined by the administrator.
310          */
311         std::string motd;
312
313         /** The pathname and filename of the rules file,
314          * as defined by the administrator.
315          */
316         std::string rules;
317
318         /** The quit prefix in use, or an empty string
319          */
320         std::string PrefixQuit;
321
322         /** The quit suffix in use, or an empty string
323          */
324         std::string SuffixQuit;
325
326         /** The fixed quit message in use, or an empty string
327          */
328         std::string FixedQuit;
329
330         /** The part prefix in use, or an empty string
331          */
332         std::string PrefixPart;
333
334         /** The part suffix in use, or an empty string
335          */
336         std::string SuffixPart;
337
338         /** The fixed part message in use, or an empty string
339          */
340         std::string FixedPart;
341
342         /** The DNS server to use for DNS queries
343          */
344         std::string DNSServer;
345
346         /** Pretend disabled commands don't exist.
347          */
348         bool DisabledDontExist;
349
350         /** This variable contains a space-seperated list
351          * of commands which are disabled by the
352          * administrator of the server for non-opers.
353          */
354         std::string DisabledCommands;
355
356         /** This variable identifies which usermodes have been diabled.
357          */
358         char DisabledUModes[64];
359
360         /** This variable identifies which chanmodes have been disabled.
361          */
362         char DisabledCModes[64];
363
364         /** The full path to the modules directory.
365          * This is either set at compile time, or
366          * overridden in the configuration file via
367          * the <path> tag.
368          */
369         std::string ModPath;
370
371         /** If set to true, then all opers on this server are
372          * shown with a generic 'is an IRC operator' line rather
373          * than the oper type. Oper types are still used internally.
374          */
375         bool GenericOper;
376
377         /** If this value is true, banned users (+b, not extbans) will not be able to change nick
378          * if banned on any channel, nor to message them.
379          */
380         bool RestrictBannedUsers;
381
382         /** If this is set to true, then mode lists (e.g
383          * MODE #chan b) are hidden from unprivileged
384          * users.
385          */
386         bool HideModeLists[256];
387
388         /** The number of seconds the DNS subsystem
389          * will wait before timing out any request.
390          */
391         int dns_timeout;
392
393         /** The size of the read() buffer in the user
394          * handling code, used to read data into a user's
395          * recvQ.
396          */
397         int NetBufferSize;
398
399         /** The value to be used for listen() backlogs
400          * as default.
401          */
402         int MaxConn;
403
404         /** The soft limit value assigned to the irc server.
405          * The IRC server will not allow more than this
406          * number of local users.
407          */
408         unsigned int SoftLimit;
409
410         /** Maximum number of targets for a multi target command
411          * such as PRIVMSG or KICK
412          */
413         unsigned int MaxTargets;
414
415         /** True if we're going to hide netsplits as *.net *.split for non-opers
416          */
417         bool HideSplits;
418
419         /** True if we're going to hide ban reasons for non-opers (e.g. G-Lines,
420          * K-Lines, Z-Lines)
421          */
422         bool HideBans;
423
424         /** Announce invites to the channel with a server notice
425          */
426         InviteAnnounceState AnnounceInvites;
427
428         /** If this is enabled then operators will
429          * see invisible (+i) channels in /whois.
430          */
431         bool OperSpyWhois;
432
433         /** True if raw I/O is being logged */
434         bool RawLog;
435
436         /** Set to a non-empty string to obfuscate the server name of users in WHOIS
437          */
438         std::string HideWhoisServer;
439
440         /** Set to a non empty string to obfuscate nicknames prepended to a KILL.
441          */
442         std::string HideKillsServer;
443
444         /** The full pathname and filename of the PID
445          * file as defined in the configuration.
446          */
447         std::string PID;
448
449         /** The connect classes in use by the IRC server.
450          */
451         ClassVector Classes;
452
453         /** The 005 tokens of this server (ISUPPORT)
454          * populated/repopulated upon loading or unloading
455          * modules.
456          */
457         std::string data005;
458
459         /** isupport strings
460          */
461         std::vector<std::string> isupport;
462
463         /** STATS characters in this list are available
464          * only to operators.
465          */
466         std::string UserStats;
467
468         /** Default channel modes
469          */
470         std::string DefaultModes;
471
472         /** Custom version string, which if defined can replace the system info in VERSION.
473          */
474         std::string CustomVersion;
475
476         /** List of u-lined servers
477          */
478         std::map<irc::string, bool> ulines;
479
480         /** Max banlist sizes for channels (the std::string is a glob)
481          */
482         std::map<std::string, int> maxbans;
483
484         /** If set to true, no user DNS lookups are to be performed
485          */
486         bool NoUserDns;
487
488         /** If set to true, provide syntax hints for unknown commands
489          */
490         bool SyntaxHints;
491
492         /** If set to true, users appear to quit then rejoin when their hosts change.
493          * This keeps clients synchronized properly.
494          */
495         bool CycleHosts;
496
497         /** If set to true, the CycleHosts mode change will be sourced from the user,
498          * rather than the server
499          */
500         bool CycleHostsFromUser;
501
502         /** If set to true, prefixed channel NOTICEs and PRIVMSGs will have the prefix
503          *  added to the outgoing text for undernet style msg prefixing.
504          */
505         bool UndernetMsgPrefix;
506
507         /** If set to true, the full nick!user@host will be shown in the TOPIC command
508          * for who set the topic last. If false, only the nick is shown.
509          */
510         bool FullHostInTopic;
511
512         /** Oper block and type index.
513          * For anonymous oper blocks (type only), prefix with a space.
514          */
515         OperIndex oper_blocks;
516
517         /** Max channels per user
518          */
519         unsigned int MaxChans;
520
521         /** Oper max channels per user
522          */
523         unsigned int OperMaxChans;
524
525         /** TS6-like server ID.
526          * NOTE: 000...999 are usable for InspIRCd servers. This
527          * makes code simpler. 0AA, 1BB etc with letters are reserved
528          * for services use.
529          */
530         std::string sid;
531
532         /** Construct a new ServerConfig
533          */
534         ServerConfig();
535
536         /** Get server ID as string with required leading zeroes
537          */
538         std::string GetSID();
539
540         /** Update the 005 vector
541          */
542         void Update005();
543
544         /** Send the 005 numerics (ISUPPORT) to a user
545          */
546         void Send005(User* user);
547
548         /** Read the entire configuration into memory
549          * and initialize this class. All other methods
550          * should be used only by the core.
551          */
552         void Read();
553
554         /** Apply configuration changes from the old configuration.
555          */
556         void Apply(ServerConfig* old, const std::string &useruid);
557         void ApplyModules(User* user);
558
559         void Fill();
560
561         /* Returns true if the given string starts with a windows drive letter
562          */
563         bool StartsWithWindowsDriveLetter(const std::string &path);
564
565         bool ApplyDisabledCommands(const std::string& data);
566
567         /** Clean a filename, stripping the directories (and drives) from string.
568          * @param name Directory to tidy
569          * @return The cleaned filename
570          */
571         static const char* CleanFilename(const char* name);
572
573         /** Check if a file exists.
574          * @param file The full path to a file
575          * @return True if the file exists and is readable.
576          */
577         static bool FileExists(const char* file);
578
579         /** If this value is true, invites will bypass more than just +i
580          */
581         bool InvBypassModes;
582
583 };
584
585 /** The background thread for config reading, so that reading from executable includes
586  * does not block.
587  */
588 class CoreExport ConfigReaderThread : public Thread
589 {
590         ServerConfig* Config;
591         volatile bool done;
592  public:
593         const std::string TheUserUID;
594         ConfigReaderThread(const std::string &useruid)
595                 : Config(new ServerConfig), done(false), TheUserUID(useruid)
596         {
597         }
598
599         virtual ~ConfigReaderThread()
600         {
601                 delete Config;
602         }
603
604         void Run();
605         /** Run in the main thread to apply the configuration */
606         void Finish();
607         bool IsDone() { return done; }
608 };
609
610 #endif