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
ServerConfig::HideKillsServer
std::string HideKillsServer
Definition: configreader.h:439
ServerConfig::rules
std::string rules
Definition: configreader.h:313
ServerConfig::SuffixQuit
std::string SuffixQuit
Definition: configreader.h:321
OperInfo
Definition: configreader.h:149
ServerConfig::HideSplits
bool HideSplits
Definition: configreader.h:414
ServerLimits::MaxGecos
size_t MaxGecos
Definition: configreader.h:93
ServerConfig::MaxTargets
unsigned int MaxTargets
Definition: configreader.h:410
ServerConfig::PrefixQuit
std::string PrefixQuit
Definition: configreader.h:317
ServerConfig::c_ipv4_range
int c_ipv4_range
Definition: configreader.h:238
ServerConfig::AdminName
std::string AdminName
Definition: configreader.h:281
ServerConfig::cmdline
CommandLineConf cmdline
Definition: configreader.h:233
ServerConfig::WhoWasGroupSize
int WhoWasGroupSize
Definition: configreader.h:247
ServerConfig::ServerDesc
std::string ServerDesc
Definition: configreader.h:276
ServerConfig::Limits
ServerLimits Limits
Definition: configreader.h:229
ServerConfig::valid
bool valid
Definition: configreader.h:208
ServerConfig::errstr
std::stringstream errstr
Definition: configreader.h:205
ConfigReaderThread
Definition: configreader.h:599
ServerConfig::ModPath
std::string ModPath
Definition: configreader.h:366
CommandLineConf
Definition: configreader.h:106
ServerConfig::MaxConn
int MaxConn
Definition: configreader.h:399
ServerConfig::InvBypassModes
bool InvBypassModes
Definition: configreader.h:584
ServerConfig::DisabledDontExist
bool DisabledDontExist
Definition: configreader.h:345
ServerConfig::CycleHosts
bool CycleHosts
Definition: configreader.h:496
ServerConfig::UndernetMsgPrefix
bool UndernetMsgPrefix
Definition: configreader.h:506
ServerConfig::AdminEmail
std::string AdminEmail
Definition: configreader.h:286
OperInfo::oper_block
reference< ConfigTag > oper_block
Definition: configreader.h:162
ServerConfig::DefaultModes
std::string DefaultModes
Definition: configreader.h:471
CommandLineConf::TestSuite
bool TestSuite
Definition: configreader.h:136
reference< ConfigTag >
Thread
Definition: threadengine.h:36
ServerLimits::IdentMax
size_t IdentMax
Definition: configreader.h:85
refcountbase
Definition: base.h:86
ServerConfig::OperSpyWhois
OperSpyWhoisState OperSpyWhois
Definition: configreader.h:428
ServerConfig::motd
std::string motd
Definition: configreader.h:308
ServerConfig::SuffixPart
std::string SuffixPart
Definition: configreader.h:333
ServerConfig::powerhash
std::string powerhash
Definition: configreader.h:303
ServerConfig::FullHostInTopic
bool FullHostInTopic
Definition: configreader.h:511
ServerLimits
Definition: configreader.h:75
ServerConfig::ulines
std::map< irc::string, bool > ulines
Definition: configreader.h:479
ServerConfig::NoSnoticeStack
bool NoSnoticeStack
Definition: configreader.h:588
ServerConfig::RawLog
bool RawLog
Definition: configreader.h:431
ServerConfig::PID
std::string PID
Definition: configreader.h:448
ServerConfig::config_data
ConfigDataHash config_data
Definition: configreader.h:220
OperInfo::type_block
reference< ConfigTag > type_block
Definition: configreader.h:164
ServerConfig::ServerName
std::string ServerName
Definition: configreader.h:261
ServerConfig
Definition: configreader.h:185
ServerConfig::CycleHostsFromUser
bool CycleHostsFromUser
Definition: configreader.h:501
ServerConfig::diepass
std::string diepass
Definition: configreader.h:295
ServerConfig::AnnounceInvites
InviteAnnounceState AnnounceInvites
Definition: configreader.h:423
ServerConfig::sid
std::string sid
Definition: configreader.h:531
ServerConfig::HideULineKills
bool HideULineKills
Definition: configreader.h:443
ServerConfig::Classes
ClassVector Classes
Definition: configreader.h:452
ServerConfig::UserStats
std::string UserStats
Definition: configreader.h:467
OperInfo::class_blocks
std::vector< reference< ConfigTag > > class_blocks
Definition: configreader.h:166
ServerConfig::SoftLimit
unsigned int SoftLimit
Definition: configreader.h:405
ServerConfig::WhoWasMaxKeep
int WhoWasMaxKeep
Definition: configreader.h:256
ServerConfig::FixedPart
std::string FixedPart
Definition: configreader.h:337
ServerLimits::MaxKick
size_t MaxKick
Definition: configreader.h:91
ServerConfig::DisabledCommands
std::string DisabledCommands
Definition: configreader.h:351
CommandLineConf::forcedebug
bool forcedebug
Definition: configreader.h:121
ServerConfig::c_ipv6_range
int c_ipv6_range
Definition: configreader.h:243
ServerConfig::HideBans
bool HideBans
Definition: configreader.h:419
OperInfo::AllowedChanModes
std::bitset< 64 > AllowedChanModes
Definition: configreader.h:159
ConfigTag
Definition: configreader.h:37
ServerConfig::PrefixPart
std::string PrefixPart
Definition: configreader.h:329
ServerConfig::Files
ConfigFileCache Files
Definition: configreader.h:225
ServerConfig::NetBufferSize
int NetBufferSize
Definition: configreader.h:394
ServerConfig::WhoWasMaxGroups
int WhoWasMaxGroups
Definition: configreader.h:252
ServerConfig::WelcomeNotice
bool WelcomeNotice
Definition: configreader.h:593
ServerConfig::HideWhoisServer
std::string HideWhoisServer
Definition: configreader.h:435
ServerConfig::EmptyTag
ConfigTag * EmptyTag
Definition: configreader.h:201
ServerLimits::MaxAway
size_t MaxAway
Definition: configreader.h:95
Thread::Run
virtual void Run()=0
OperInfo::name
std::string name
Definition: configreader.h:168
ServerConfig::MaxChans
unsigned int MaxChans
Definition: configreader.h:520
ServerConfig::WildcardIPv6
bool WildcardIPv6
Definition: configreader.h:211
User
Definition: users.h:230
ServerConfig::isupport
std::vector< std::string > isupport
Definition: configreader.h:462
ServerConfig::SyntaxHints
bool SyntaxHints
Definition: configreader.h:491
ServerConfig::MoronBanner
std::string MoronBanner
Definition: configreader.h:265
OperInfo::AllowedUserModes
std::bitset< 64 > AllowedUserModes
Definition: configreader.h:156
ServerLimits::MaxModes
size_t MaxModes
Definition: configreader.h:83
ServerConfig::data005
std::string data005
Definition: configreader.h:458
CommandLineConf::nofork
bool nofork
Definition: configreader.h:113
CommandLineConf::argv
char ** argv
Definition: configreader.h:144
ServerConfig::restartpass
std::string restartpass
Definition: configreader.h:299
CommandLineConf::writelog
bool writelog
Definition: configreader.h:131
ServerConfig::RestrictBannedUsers
bool RestrictBannedUsers
Definition: configreader.h:377
ServerLimits::MaxQuit
size_t MaxQuit
Definition: configreader.h:87
ServerLimits::MaxTopic
size_t MaxTopic
Definition: configreader.h:89
ServerLimits::ChanMax
size_t ChanMax
Definition: configreader.h:81
ServerConfig::dns_timeout
int dns_timeout
Definition: configreader.h:388
ServerConfig::AdminNick
std::string AdminNick
Definition: configreader.h:291
ServerLimits::ServerLimits
ServerLimits()
Definition: configreader.h:101
CommandLineConf::argc
int argc
Definition: configreader.h:140
ServerConfig::oper_blocks
OperIndex oper_blocks
Definition: configreader.h:516
ServerConfig::InviteAnnounceState
InviteAnnounceState
Definition: configreader.h:214
irc::Spacify
const CoreExport char * Spacify(const char *n)
Definition: hashcomp.cpp:366
ServerConfig::GenericOper
bool GenericOper
Definition: configreader.h:372
ServerConfig::FixedQuit
std::string FixedQuit
Definition: configreader.h:325
ServerConfig::DNSServer
std::string DNSServer
Definition: configreader.h:341
ServerConfig::OperMaxChans
unsigned int OperMaxChans
Definition: configreader.h:524
ServerConfig::NoUserDns
bool NoUserDns
Definition: configreader.h:487
ServerConfig::CustomVersion
std::string CustomVersion
Definition: configreader.h:475
ServerLimits::NickMax
size_t NickMax
Definition: configreader.h:79
ServerConfig::maxbans
std::map< std::string, int > maxbans
Definition: configreader.h:483