]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/configreader.h
Change User::oper to an OperInfo reference
[user/henk/code/inspircd.git] / include / configreader.h
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 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 /* Required forward definitions */
27 class ServerConfig;
28 class ServerLimits;
29 class InspIRCd;
30 class BufferedSocket;
31
32 /** A cached text file stored with its contents as lines
33  */
34 typedef std::vector<std::string> file_cache;
35
36 /** A configuration key and value pair
37  */
38 typedef std::pair<std::string, std::string> KeyVal;
39
40 struct CoreExport ConfigTag : public refcountbase
41 {
42         const std::string tag;
43         const std::string src_name;
44         const int src_line;
45         std::vector<KeyVal> items;
46
47         ConfigTag(const std::string& Tag, const std::string& file, int line)
48                 : tag(Tag), src_name(file), src_line(line) {}
49
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);
54
55         bool readString(const std::string& key, std::string& value, bool allow_newline = false);
56
57         std::string getTagLocation();
58 };
59
60 /** An entire config file, built up of KeyValLists
61  */
62 typedef std::multimap<std::string, reference<ConfigTag> > ConfigDataHash;
63
64 /** Defines the server's length limits on various length-limited
65  * items such as topics, nicknames, channel names etc.
66  */
67 class ServerLimits
68 {
69  public:
70         /** Maximum nickname length */
71         size_t NickMax;
72         /** Maximum channel length */
73         size_t ChanMax;
74         /** Maximum number of modes per line */
75         size_t MaxModes;
76         /** Maximum length of ident, not including ~ etc */
77         size_t IdentMax;
78         /** Maximum length of a quit message */
79         size_t MaxQuit;
80         /** Maximum topic length */
81         size_t MaxTopic;
82         /** Maximum kick message length */
83         size_t MaxKick;
84         /** Maximum GECOS (real name) length */
85         size_t MaxGecos;
86         /** Maximum away message length */
87         size_t MaxAway;
88
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.
92          */
93         ServerLimits() : NickMax(31), ChanMax(64), MaxModes(20), IdentMax(12), MaxQuit(255), MaxTopic(307), MaxKick(255), MaxGecos(128), MaxAway(200)
94         {
95         }
96
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.
99          */
100         void Finalise()
101         {
102                 NickMax++;
103                 ChanMax++;
104                 IdentMax++;
105                 MaxQuit++;
106                 MaxTopic++;
107                 MaxKick++;
108                 MaxGecos++;
109                 MaxAway++;
110         }
111 };
112
113 class CoreExport OperInfo : public refcountbase
114 {
115  public:
116         /** <oper> block used for this oper-up. May be NULL. */
117         reference<ConfigTag> oper_block;
118         /** <type> block used for this oper-up. Valid for local users, may be NULL on remote */
119         reference<ConfigTag> type_block;
120         /** <class> blocks referenced from the <type> block. These define individual permissions */
121         std::vector<reference<ConfigTag> > class_blocks;
122         /** Name of the oper type; i.e. the one shown in WHOIS */
123         std::string name;
124
125         /** Get a configuration item, searching in the oper, type, and class blocks (in that order) */
126         std::string getConfig(const std::string& key);
127
128         inline const char* NameStr()
129         {
130                 return irc::Spacify(name.c_str());
131         }
132 };
133
134 typedef std::map<std::string, reference<ConfigTag> > TagIndex;
135 typedef std::map<std::string, reference<OperInfo> > OperIndex;
136
137 /** This class holds the bulk of the runtime configuration for the ircd.
138  * It allows for reading new config values, accessing configuration files,
139  * and storage of the configuration data needed to run the ircd, such as
140  * the servername, connect classes, /ADMIN data, MOTDs and filenames etc.
141  */
142 class CoreExport ServerConfig
143 {
144   private:
145         void CrossCheckOperClassType();
146         void CrossCheckConnectBlocks(ServerConfig* current);
147
148  public:
149
150         /** Get a configuration tag
151          * @param tag The name of the tag to get
152          * @param offset get the Nth occurance of the tag
153          */
154         ConfigTag* ConfValue(const std::string& tag, int offset = 0);
155
156         /** Error stream, contains error output from any failed configuration parsing.
157          */
158         std::stringstream errstr;
159
160         /** True if this configuration is valid enough to run with */
161         bool valid;
162
163         /** Used to indicate who we announce invites to on a channel */
164         enum InviteAnnounceState { INVITE_ANNOUNCE_NONE, INVITE_ANNOUNCE_ALL, INVITE_ANNOUNCE_OPS, INVITE_ANNOUNCE_DYNAMIC };
165
166         /** This holds all the information in the config file,
167          * it's indexed by tag name to a vector of key/values.
168          */
169         ConfigDataHash config_data;
170
171         /** Length limits, see definition of ServerLimits class
172          */
173         ServerLimits Limits;
174
175         /** Clones CIDR range for ipv4 (0-32)
176          * Defaults to 32 (checks clones on all IPs seperately)
177          */
178         int c_ipv4_range;
179
180         /** Clones CIDR range for ipv6 (0-128)
181          * Defaults to 128 (checks on all IPs seperately)
182          */
183         int c_ipv6_range;
184
185         /** Max number of WhoWas entries per user.
186          */
187         int WhoWasGroupSize;
188
189         /** Max number of cumulative user-entries in WhoWas.
190          *  When max reached and added to, push out oldest entry FIFO style.
191          */
192         int WhoWasMaxGroups;
193
194         /** Max seconds a user is kept in WhoWas before being pruned.
195          */
196         int WhoWasMaxKeep;
197
198         /** Both for set(g|u)id.
199          */
200         std::string SetUser;
201         std::string SetGroup;
202
203         /** Holds the server name of the local server
204          * as defined by the administrator.
205          */
206         std::string ServerName;
207
208         /** Notice to give to users when they are Xlined
209          */
210         std::string MoronBanner;
211
212         /* Holds the network name the local server
213          * belongs to. This is an arbitary field defined
214          * by the administrator.
215          */
216         std::string Network;
217
218         /** Holds the description of the local server
219          * as defined by the administrator.
220          */
221         std::string ServerDesc;
222
223         /** Holds the admin's name, for output in
224          * the /ADMIN command.
225          */
226         std::string AdminName;
227
228         /** Holds the email address of the admin,
229          * for output in the /ADMIN command.
230          */
231         std::string AdminEmail;
232
233         /** Holds the admin's nickname, for output
234          * in the /ADMIN command
235          */
236         std::string AdminNick;
237
238         /** The admin-configured /DIE password
239          */
240         std::string diepass;
241
242         /** The admin-configured /RESTART password
243          */
244         std::string restartpass;
245
246         /** The hash method for *BOTH* the die and restart passwords.
247          */
248         std::string powerhash;
249
250         /** The pathname and filename of the message of the
251          * day file, as defined by the administrator.
252          */
253         std::string motd;
254
255         /** The pathname and filename of the rules file,
256          * as defined by the administrator.
257          */
258         std::string rules;
259
260         /** The quit prefix in use, or an empty string
261          */
262         std::string PrefixQuit;
263
264         /** The quit suffix in use, or an empty string
265          */
266         std::string SuffixQuit;
267
268         /** The fixed quit message in use, or an empty string
269          */
270         std::string FixedQuit;
271
272         /** The part prefix in use, or an empty string
273          */
274         std::string PrefixPart;
275
276         /** The part suffix in use, or an empty string
277          */
278         std::string SuffixPart;
279
280         /** The fixed part message in use, or an empty string
281          */
282         std::string FixedPart;
283
284         /** The last string found within a <die> tag, or
285          * an empty string.
286          */
287         std::string DieValue;
288
289         /** The DNS server to use for DNS queries
290          */
291         std::string DNSServer;
292
293         /** Pretend disabled commands don't exist.
294          */
295         bool DisabledDontExist;
296
297         /** This variable contains a space-seperated list
298          * of commands which are disabled by the
299          * administrator of the server for non-opers.
300          */
301         std::string DisabledCommands;
302
303         /** This variable identifies which usermodes have been diabled.
304          */
305
306         char DisabledUModes[64];
307
308         /** This variable identifies which chanmodes have been disabled.
309          */
310         char DisabledCModes[64];
311
312         /** The full path to the modules directory.
313          * This is either set at compile time, or
314          * overridden in the configuration file via
315          * the <options> tag.
316          */
317         std::string ModPath;
318
319         /** The file handle of the logfile. If this
320          * value is NULL, the log file is not open,
321          * probably due to a permissions error on
322          * startup (this should not happen in normal
323          * operation!).
324          */
325         FILE *log_file;
326
327         /** If this value is true, the owner of the
328          * server specified -nofork on the command
329          * line, causing the daemon to stay in the
330          * foreground.
331          */
332         bool nofork;
333
334         /** If this value if true then all log
335          * messages will be output, regardless of
336          * the level given in the config file.
337          * This is set with the -debug commandline
338          * option.
339          */
340         bool forcedebug;
341
342         /** If this is true then log output will be
343          * written to the logfile. This is the default.
344          * If you put -nolog on the commandline then
345          * the logfile will not be written.
346          * This is meant to be used in conjunction with
347          * -debug for debugging without filling up the
348          * hard disk.
349          */
350         bool writelog;
351
352         /** If set to true, then all opers on this server are
353          * shown with a generic 'is an IRC operator' line rather
354          * than the oper type. Oper types are still used internally.
355          */
356         bool GenericOper;
357
358         /** If this value is true, banned users (+b, not extbans) will not be able to change nick
359          * if banned on any channel, nor to message them.
360          */
361         bool RestrictBannedUsers;
362
363         /** If this value is true, halfops have been
364          * enabled in the configuration file.
365          */
366         bool AllowHalfop;
367
368         /** If this is set to true, then mode lists (e.g
369          * MODE #chan b) are hidden from unprivileged
370          * users.
371          */
372         bool HideModeLists[256];
373
374         /** The number of seconds the DNS subsystem
375          * will wait before timing out any request.
376          */
377         int dns_timeout;
378
379         /** The size of the read() buffer in the user
380          * handling code, used to read data into a user's
381          * recvQ.
382          */
383         int NetBufferSize;
384
385         /** The value to be used for listen() backlogs
386          * as default.
387          */
388         int MaxConn;
389
390         /** The soft limit value assigned to the irc server.
391          * The IRC server will not allow more than this
392          * number of local users.
393          */
394         unsigned int SoftLimit;
395
396         /** Maximum number of targets for a multi target command
397          * such as PRIVMSG or KICK
398          */
399         unsigned int MaxTargets;
400
401         /** The maximum number of /WHO results allowed
402          * in any single /WHO command.
403          */
404         int MaxWhoResults;
405
406         /** True if the DEBUG loglevel is selected.
407          */
408         int debugging;
409
410         /** How many seconds to wait before exiting
411          * the program when /DIE is correctly issued.
412          */
413         int DieDelay;
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         /** Set to a non-empty string to obfuscate the server name of users in WHOIS
434          */
435         std::string HideWhoisServer;
436
437         /** Set to a non empty string to obfuscate nicknames prepended to a KILL.
438          */
439         std::string HideKillsServer;
440
441         /** The MOTD file, cached in a file_cache type.
442          */
443         file_cache MOTD;
444
445         /** The RULES file, cached in a file_cache type.
446          */
447         file_cache RULES;
448
449         /** The full pathname and filename of the PID
450          * file as defined in the configuration.
451          */
452         std::string PID;
453
454         /** The connect classes in use by the IRC server.
455          */
456         ClassVector Classes;
457
458         /** The 005 tokens of this server (ISUPPORT)
459          * populated/repopulated upon loading or unloading
460          * modules.
461          */
462         std::string data005;
463
464         /** isupport strings
465          */
466         std::vector<std::string> isupport;
467
468         /** STATS characters in this list are available
469          * only to operators.
470          */
471         std::string UserStats;
472
473         /** The path and filename of the ircd.log file
474          */
475         std::string logpath;
476
477         /** Default channel modes
478          */
479         std::string DefaultModes;
480
481         /** Custom version string, which if defined can replace the system info in VERSION.
482          */
483         std::string CustomVersion;
484
485         /** List of u-lined servers
486          */
487         std::map<irc::string, bool> ulines;
488
489         /** Max banlist sizes for channels (the std::string is a glob)
490          */
491         std::map<std::string, int> maxbans;
492
493         /** Directory where the inspircd binary resides
494          */
495         std::string MyDir;
496
497         /** If set to true, no user DNS lookups are to be performed
498          */
499         bool NoUserDns;
500
501         /** If set to true, provide syntax hints for unknown commands
502          */
503         bool SyntaxHints;
504
505         /** If set to true, users appear to quit then rejoin when their hosts change.
506          * This keeps clients synchronized properly.
507          */
508         bool CycleHosts;
509
510         /** If set to true, prefixed channel NOTICEs and PRIVMSGs will have the prefix
511          *  added to the outgoing text for undernet style msg prefixing.
512          */
513         bool UndernetMsgPrefix;
514
515         /** If set to true, the full nick!user@host will be shown in the TOPIC command
516          * for who set the topic last. If false, only the nick is shown.
517          */
518         bool FullHostInTopic;
519
520         /** Oper block and type index.
521          * For anonymous oper blocks (type only), prefix with a space.
522          */
523         OperIndex oper_blocks;
524
525         /** Saved argv from startup
526          */
527         char** argv;
528
529         /** Saved argc from startup
530          */
531         int argc;
532
533         /** Max channels per user
534          */
535         unsigned int MaxChans;
536
537         /** Oper max channels per user
538          */
539         unsigned int OperMaxChans;
540
541         /** TS6-like server ID.
542          * NOTE: 000...999 are usable for InspIRCd servers. This
543          * makes code simpler. 0AA, 1BB etc with letters are reserved
544          * for services use.
545          */
546         std::string sid;
547
548         /** True if we have been told to run the testsuite from the commandline,
549          * rather than entering the mainloop.
550          */
551         bool TestSuite;
552
553         /** Construct a new ServerConfig
554          */
555         ServerConfig();
556
557         /** Get server ID as string with required leading zeroes
558          */
559         std::string GetSID();
560
561         /** Update the 005 vector
562          */
563         void Update005();
564
565         /** Send the 005 numerics (ISUPPORT) to a user
566          */
567         void Send005(User* user);
568
569         /** Read the entire configuration into memory
570          * and initialize this class. All other methods
571          * should be used only by the core.
572          */
573         void Read();
574
575         /** Apply configuration changes from the old configuration.
576          */
577         void Apply(ServerConfig* old, const std::string &useruid);
578         void ApplyModules(User* user);
579
580         void Fill();
581
582         /** Read a file into a file_cache object
583          */
584         bool ReadFile(file_cache &F, const std::string& fname);
585
586         /* Returns true if the given string starts with a windows drive letter
587          */
588         bool StartsWithWindowsDriveLetter(const std::string &path);
589
590         bool ApplyDisabledCommands(const std::string& data);
591
592         /** Clean a filename, stripping the directories (and drives) from string.
593          * @param name Directory to tidy
594          * @return The cleaned filename
595          */
596         static const char* CleanFilename(const char* name);
597
598         /** Check if a file exists.
599          * @param file The full path to a file
600          * @return True if the file exists and is readable.
601          */
602         static bool FileExists(const char* file);
603
604         /** If this value is true, invites will bypass more than just +i
605          */
606         bool InvBypassModes;
607
608 };
609 #endif