InspIRCd  2.0
configreader.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  * Copyright (C) 2009 Daniel De Graaf <[email protected]>
5  * Copyright (C) 2007, 2009 Dennis Friis <[email protected]>
6  * Copyright (C) 2006-2008 Craig Edwards <[email protected]>
7  * Copyright (C) 2006-2008 Robin Burchell <[email protected]>
8  * Copyright (C) 2006 Oliver Lupton <[email protected]>
9  *
10  * This file is part of InspIRCd. InspIRCd is free software: you can
11  * redistribute it and/or modify it under the terms of the GNU General Public
12  * License as published by the Free Software Foundation, version 2.
13  *
14  * This program is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17  * details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
23 
24 #ifndef INSPIRCD_CONFIGREADER
25 #define INSPIRCD_CONFIGREADER
26 
27 #include <sstream>
28 #include <string>
29 #include <vector>
30 #include <map>
31 #include "inspircd.h"
32 #include "modules.h"
33 #include "socketengine.h"
34 #include "socket.h"
35 
37 class CoreExport ConfigTag : public refcountbase
38 {
39  std::vector<KeyVal> items;
40  public:
41  const std::string tag;
42  const std::string src_name;
43  const int src_line;
44 
46  std::string getString(const std::string& key, const std::string& def = "");
48  long getInt(const std::string& key, long def = 0);
50  double getFloat(const std::string& key, double def = 0);
52  bool getBool(const std::string& key, bool def = false);
53 
60  bool readString(const std::string& key, std::string& value, bool allow_newline = false);
61 
62  std::string getTagLocation();
63 
64  inline const std::vector<KeyVal>& getItems() const { return items; }
65 
67  static ConfigTag* create(const std::string& Tag, const std::string& file, int line, std::vector<KeyVal>*& Items);
68  private:
69  ConfigTag(const std::string& Tag, const std::string& file, int line);
70 };
71 
76 {
77  public:
79  size_t NickMax;
81  size_t ChanMax;
83  size_t MaxModes;
85  size_t IdentMax;
87  size_t MaxQuit;
89  size_t MaxTopic;
91  size_t MaxKick;
93  size_t MaxGecos;
95  size_t MaxAway;
96 
101  ServerLimits() : NickMax(31), ChanMax(64), MaxModes(20), IdentMax(12), MaxQuit(255), MaxTopic(307), MaxKick(255), MaxGecos(128), MaxAway(200)
102  {
103  }
104 };
105 
107 {
113  bool nofork;
114 
122 
131  bool writelog;
132 
136  bool TestSuite;
137 
140  int argc;
141 
144  char** argv;
145 
146  std::string startup_log;
147 };
148 
149 class CoreExport OperInfo : public refcountbase
150 {
151  public:
152  std::set<std::string> AllowedOperCommands;
153  std::set<std::string> AllowedPrivs;
154 
156  std::bitset<64> AllowedUserModes;
157 
159  std::bitset<64> AllowedChanModes;
160 
166  std::vector<reference<ConfigTag> > class_blocks;
168  std::string name;
169 
171  std::string getConfig(const std::string& key);
172  void init();
173 
174  inline const char* NameStr()
175  {
176  return irc::Spacify(name.c_str());
177  }
178 };
179 
185 class CoreExport ServerConfig
186 {
187  private:
188  void CrossCheckOperClassType();
189  void CrossCheckConnectBlocks(ServerConfig* current);
190 
191  public:
192 
196  ConfigTag* ConfValue(const std::string& tag);
197 
198  ConfigTagList ConfTags(const std::string& tag);
199 
202 
205  std::stringstream errstr;
206 
208  bool valid;
209 
212 
214  enum InviteAnnounceState { INVITE_ANNOUNCE_NONE, INVITE_ANNOUNCE_ALL, INVITE_ANNOUNCE_OPS, INVITE_ANNOUNCE_DYNAMIC };
215  enum OperSpyWhoisState { SPYWHOIS_NONE, SPYWHOIS_SINGLEMSG, SPYWHOIS_SPLITMSG };
216 
220  ConfigDataHash config_data;
221 
225  ConfigFileCache Files;
226 
230 
234 
239 
244 
248 
253 
257 
261  std::string ServerName;
262 
265  std::string MoronBanner;
266 
267  /* Holds the network name the local server
268  * belongs to. This is an arbitary field defined
269  * by the administrator.
270  */
271  std::string Network;
272 
276  std::string ServerDesc;
277 
281  std::string AdminName;
282 
286  std::string AdminEmail;
287 
291  std::string AdminNick;
292 
295  std::string diepass;
296 
299  std::string restartpass;
300 
303  std::string powerhash;
304 
308  std::string motd;
309 
313  std::string rules;
314 
317  std::string PrefixQuit;
318 
321  std::string SuffixQuit;
322 
325  std::string FixedQuit;
326 
329  std::string PrefixPart;
330 
333  std::string SuffixPart;
334 
337  std::string FixedPart;
338 
341  std::string DNSServer;
342 
346 
351  std::string DisabledCommands;
352 
355  char DisabledUModes[64];
356 
359  char DisabledCModes[64];
360 
366  std::string ModPath;
367 
373 
378 
383  bool HideModeLists[256];
384 
389 
395 
399  int MaxConn;
400 
405  unsigned int SoftLimit;
406 
410  unsigned int MaxTargets;
411 
415 
419  bool HideBans;
420 
424 
428  OperSpyWhoisState OperSpyWhois;
429 
431  bool RawLog;
432 
435  std::string HideWhoisServer;
436 
439  std::string HideKillsServer;
440 
444 
448  std::string PID;
449 
452  ClassVector Classes;
453 
458  std::string data005;
459 
462  std::vector<std::string> isupport;
463 
467  std::string UserStats;
468 
471  std::string DefaultModes;
472 
475  std::string CustomVersion;
476 
479  std::map<irc::string, bool> ulines;
480 
483  std::map<std::string, int> maxbans;
484 
487  bool NoUserDns;
488 
492 
497 
502 
507 
512 
516  OperIndex oper_blocks;
517 
520  unsigned int MaxChans;
521 
524  unsigned int OperMaxChans;
525 
531  std::string sid;
532 
535  ServerConfig();
536 
537  ~ServerConfig();
538 
541  const std::string& GetSID();
542 
545  void Update005();
546 
549  void Send005(User* user);
550 
555  void Read();
556 
559  void Apply(ServerConfig* old, const std::string &useruid);
560  void ApplyModules(User* user);
561 
562  void Fill();
563 
566  bool StartsWithWindowsDriveLetter(const std::string &path);
567 
568  bool ApplyDisabledCommands(const std::string& data);
569 
574  static const char* CleanFilename(const char* name);
575 
580  static bool FileExists(const char* file);
581 
585 
589 
594 };
595 
599 class CoreExport ConfigReaderThread : public Thread
600 {
601  ServerConfig* Config;
602  volatile bool done;
603  public:
604  const std::string TheUserUID;
605  ConfigReaderThread(const std::string &useruid)
606  : Config(new ServerConfig), done(false), TheUserUID(useruid)
607  {
608  }
609 
610  virtual ~ConfigReaderThread()
611  {
612  delete Config;
613  }
614 
615  void Run();
617  void Finish();
618  bool IsDone() { return done; }
619 };
620 
621 #endif
bool SyntaxHints
Definition: configreader.h:491
std::string FixedPart
Definition: configreader.h:337
std::string DNSServer
Definition: configreader.h:341
bool WelcomeNotice
Definition: configreader.h:593
CommandLineConf cmdline
Definition: configreader.h:233
bool UndernetMsgPrefix
Definition: configreader.h:506
std::string sid
Definition: configreader.h:531
ClassVector Classes
Definition: configreader.h:452
std::string DefaultModes
Definition: configreader.h:471
std::string diepass
Definition: configreader.h:295
size_t MaxQuit
Definition: configreader.h:87
std::string restartpass
Definition: configreader.h:299
std::string data005
Definition: configreader.h:458
int WhoWasMaxGroups
Definition: configreader.h:252
std::string MoronBanner
Definition: configreader.h:265
Definition: configreader.h:37
std::string AdminEmail
Definition: configreader.h:286
int argc
Definition: configreader.h:140
int WhoWasGroupSize
Definition: configreader.h:247
bool HideBans
Definition: configreader.h:419
Definition: configreader.h:149
std::string HideKillsServer
Definition: configreader.h:439
bool forcedebug
Definition: configreader.h:121
std::stringstream errstr
Definition: configreader.h:205
unsigned int OperMaxChans
Definition: configreader.h:524
unsigned int MaxChans
Definition: configreader.h:520
std::string PrefixPart
Definition: configreader.h:329
std::string DisabledCommands
Definition: configreader.h:351
Definition: users.h:230
reference< ConfigTag > oper_block
Definition: configreader.h:162
std::string CustomVersion
Definition: configreader.h:475
int dns_timeout
Definition: configreader.h:388
std::string PID
Definition: configreader.h:448
bool CycleHostsFromUser
Definition: configreader.h:501
InviteAnnounceState
Definition: configreader.h:214
size_t MaxGecos
Definition: configreader.h:93
std::vector< std::string > isupport
Definition: configreader.h:462
std::map< std::string, int > maxbans
Definition: configreader.h:483
Definition: configreader.h:599
int WhoWasMaxKeep
Definition: configreader.h:256
std::string powerhash
Definition: configreader.h:303
std::string SuffixQuit
Definition: configreader.h:321
unsigned int MaxTargets
Definition: configreader.h:410
size_t MaxTopic
Definition: configreader.h:89
std::string ServerDesc
Definition: configreader.h:276
Definition: threadengine.h:36
std::vector< reference< ConfigTag > > class_blocks
Definition: configreader.h:166
std::bitset< 64 > AllowedChanModes
Definition: configreader.h:159
bool NoUserDns
Definition: configreader.h:487
bool NoSnoticeStack
Definition: configreader.h:588
OperIndex oper_blocks
Definition: configreader.h:516
char ** argv
Definition: configreader.h:144
ConfigDataHash config_data
Definition: configreader.h:220
ConfigTag * EmptyTag
Definition: configreader.h:201
std::string AdminNick
Definition: configreader.h:291
std::string motd
Definition: configreader.h:308
bool WildcardIPv6
Definition: configreader.h:211
bool RestrictBannedUsers
Definition: configreader.h:377
bool TestSuite
Definition: configreader.h:136
std::string name
Definition: configreader.h:168
ServerLimits Limits
Definition: configreader.h:229
bool CycleHosts
Definition: configreader.h:496
Definition: base.h:86
CoreExport const char * Spacify(const char *n)
Definition: hashcomp.cpp:368
Definition: configreader.h:75
bool HideULineKills
Definition: configreader.h:443
int MaxConn
Definition: configreader.h:399
bool DisabledDontExist
Definition: configreader.h:345
ServerLimits()
Definition: configreader.h:101
bool FullHostInTopic
Definition: configreader.h:511
size_t IdentMax
Definition: configreader.h:85
reference< ConfigTag > type_block
Definition: configreader.h:164
unsigned int SoftLimit
Definition: configreader.h:405
size_t NickMax
Definition: configreader.h:79
int NetBufferSize
Definition: configreader.h:394
std::string SuffixPart
Definition: configreader.h:333
OperSpyWhoisState OperSpyWhois
Definition: configreader.h:428
std::string UserStats
Definition: configreader.h:467
int c_ipv4_range
Definition: configreader.h:238
Definition: configreader.h:106
std::string ModPath
Definition: configreader.h:366
size_t MaxAway
Definition: configreader.h:95
std::bitset< 64 > AllowedUserModes
Definition: configreader.h:156
std::string HideWhoisServer
Definition: configreader.h:435
size_t MaxKick
Definition: configreader.h:91
std::string rules
Definition: configreader.h:313
std::map< irc::string, bool > ulines
Definition: configreader.h:479
bool RawLog
Definition: configreader.h:431
int c_ipv6_range
Definition: configreader.h:243
bool valid
Definition: configreader.h:208
std::string ServerName
Definition: configreader.h:261
std::string PrefixQuit
Definition: configreader.h:317
bool InvBypassModes
Definition: configreader.h:584
size_t ChanMax
Definition: configreader.h:81
std::string FixedQuit
Definition: configreader.h:325
bool GenericOper
Definition: configreader.h:372
Definition: configreader.h:185
ConfigFileCache Files
Definition: configreader.h:225
InviteAnnounceState AnnounceInvites
Definition: configreader.h:423
size_t MaxModes
Definition: configreader.h:83
bool writelog
Definition: configreader.h:131
bool HideSplits
Definition: configreader.h:414
bool nofork
Definition: configreader.h:113
std::string AdminName
Definition: configreader.h:281