InspIRCd  2.0
 All Classes Namespaces Functions Variables Typedefs Enumerations
configreader.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
5  * Copyright (C) 2007, 2009 Dennis Friis <peavey@inspircd.org>
6  * Copyright (C) 2006-2008 Craig Edwards <craigedwards@brainbox.cc>
7  * Copyright (C) 2006-2008 Robin Burchell <robin+git@viroteck.net>
8  * Copyright (C) 2006 Oliver Lupton <oliverlupton@gmail.com>
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  std::stringstream errstr;
203 
205  bool valid;
206 
209 
211  enum InviteAnnounceState { INVITE_ANNOUNCE_NONE, INVITE_ANNOUNCE_ALL, INVITE_ANNOUNCE_OPS, INVITE_ANNOUNCE_DYNAMIC };
212  enum OperSpyWhoisState { SPYWHOIS_NONE, SPYWHOIS_SINGLEMSG, SPYWHOIS_SPLITMSG };
213 
217  ConfigDataHash config_data;
218 
222  ConfigFileCache Files;
223 
227 
231 
236 
241 
245 
250 
254 
258  std::string ServerName;
259 
262  std::string MoronBanner;
263 
264  /* Holds the network name the local server
265  * belongs to. This is an arbitary field defined
266  * by the administrator.
267  */
268  std::string Network;
269 
273  std::string ServerDesc;
274 
278  std::string AdminName;
279 
283  std::string AdminEmail;
284 
288  std::string AdminNick;
289 
292  std::string diepass;
293 
296  std::string restartpass;
297 
300  std::string powerhash;
301 
305  std::string motd;
306 
310  std::string rules;
311 
314  std::string PrefixQuit;
315 
318  std::string SuffixQuit;
319 
322  std::string FixedQuit;
323 
326  std::string PrefixPart;
327 
330  std::string SuffixPart;
331 
334  std::string FixedPart;
335 
338  std::string DNSServer;
339 
343 
348  std::string DisabledCommands;
349 
352  char DisabledUModes[64];
353 
356  char DisabledCModes[64];
357 
363  std::string ModPath;
364 
370 
375 
380  bool HideModeLists[256];
381 
386 
392 
396  int MaxConn;
397 
402  unsigned int SoftLimit;
403 
407  unsigned int MaxTargets;
408 
412 
416  bool HideBans;
417 
421 
425  OperSpyWhoisState OperSpyWhois;
426 
428  bool RawLog;
429 
432  std::string HideWhoisServer;
433 
436  std::string HideKillsServer;
437 
441  std::string PID;
442 
445  ClassVector Classes;
446 
451  std::string data005;
452 
455  std::vector<std::string> isupport;
456 
460  std::string UserStats;
461 
464  std::string DefaultModes;
465 
468  std::string CustomVersion;
469 
472  std::map<irc::string, bool> ulines;
473 
476  std::map<std::string, int> maxbans;
477 
480  bool NoUserDns;
481 
485 
490 
495 
500 
505 
509  OperIndex oper_blocks;
510 
513  unsigned int MaxChans;
514 
517  unsigned int OperMaxChans;
518 
524  std::string sid;
525 
528  ServerConfig();
529 
532  const std::string& GetSID();
533 
536  void Update005();
537 
540  void Send005(User* user);
541 
546  void Read();
547 
550  void Apply(ServerConfig* old, const std::string &useruid);
551  void ApplyModules(User* user);
552 
553  void Fill();
554 
557  bool StartsWithWindowsDriveLetter(const std::string &path);
558 
559  bool ApplyDisabledCommands(const std::string& data);
560 
565  static const char* CleanFilename(const char* name);
566 
571  static bool FileExists(const char* file);
572 
576 
580 
585 };
586 
590 class CoreExport ConfigReaderThread : public Thread
591 {
592  ServerConfig* Config;
593  volatile bool done;
594  public:
595  const std::string TheUserUID;
596  ConfigReaderThread(const std::string &useruid)
597  : Config(new ServerConfig), done(false), TheUserUID(useruid)
598  {
599  }
600 
601  virtual ~ConfigReaderThread()
602  {
603  delete Config;
604  }
605 
606  void Run();
608  void Finish();
609  bool IsDone() { return done; }
610 };
611 
612 #endif
bool SyntaxHints
Definition: configreader.h:484
std::string FixedPart
Definition: configreader.h:334
std::string DNSServer
Definition: configreader.h:338
bool WelcomeNotice
Definition: configreader.h:584
CommandLineConf cmdline
Definition: configreader.h:230
bool UndernetMsgPrefix
Definition: configreader.h:499
std::string sid
Definition: configreader.h:524
ClassVector Classes
Definition: configreader.h:445
std::string DefaultModes
Definition: configreader.h:464
virtual void Run()=0
std::string diepass
Definition: configreader.h:292
size_t MaxQuit
Definition: configreader.h:87
std::string restartpass
Definition: configreader.h:296
std::string data005
Definition: configreader.h:451
int WhoWasMaxGroups
Definition: configreader.h:249
std::string MoronBanner
Definition: configreader.h:262
Definition: configreader.h:37
std::string AdminEmail
Definition: configreader.h:283
int argc
Definition: configreader.h:140
int WhoWasGroupSize
Definition: configreader.h:244
bool HideBans
Definition: configreader.h:416
Definition: configreader.h:149
std::string HideKillsServer
Definition: configreader.h:436
bool forcedebug
Definition: configreader.h:121
std::stringstream errstr
Definition: configreader.h:202
unsigned int OperMaxChans
Definition: configreader.h:517
unsigned int MaxChans
Definition: configreader.h:513
std::string PrefixPart
Definition: configreader.h:326
std::string DisabledCommands
Definition: configreader.h:348
Definition: users.h:230
reference< ConfigTag > oper_block
Definition: configreader.h:162
std::string CustomVersion
Definition: configreader.h:468
int dns_timeout
Definition: configreader.h:385
std::string PID
Definition: configreader.h:441
bool CycleHostsFromUser
Definition: configreader.h:494
InviteAnnounceState
Definition: configreader.h:211
size_t MaxGecos
Definition: configreader.h:93
std::vector< std::string > isupport
Definition: configreader.h:455
std::map< std::string, int > maxbans
Definition: configreader.h:476
Definition: configreader.h:590
int WhoWasMaxKeep
Definition: configreader.h:253
std::string powerhash
Definition: configreader.h:300
std::string SuffixQuit
Definition: configreader.h:318
unsigned int MaxTargets
Definition: configreader.h:407
size_t MaxTopic
Definition: configreader.h:89
std::string ServerDesc
Definition: configreader.h:273
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:480
bool NoSnoticeStack
Definition: configreader.h:579
OperIndex oper_blocks
Definition: configreader.h:509
char ** argv
Definition: configreader.h:144
ConfigDataHash config_data
Definition: configreader.h:217
std::string AdminNick
Definition: configreader.h:288
std::string motd
Definition: configreader.h:305
bool WildcardIPv6
Definition: configreader.h:208
bool RestrictBannedUsers
Definition: configreader.h:374
bool TestSuite
Definition: configreader.h:136
std::string name
Definition: configreader.h:168
ServerLimits Limits
Definition: configreader.h:226
bool CycleHosts
Definition: configreader.h:489
Definition: base.h:86
CoreExport const char * Spacify(const char *n)
Definition: hashcomp.cpp:368
Definition: configreader.h:75
int MaxConn
Definition: configreader.h:396
bool DisabledDontExist
Definition: configreader.h:342
ServerLimits()
Definition: configreader.h:101
bool FullHostInTopic
Definition: configreader.h:504
size_t IdentMax
Definition: configreader.h:85
reference< ConfigTag > type_block
Definition: configreader.h:164
unsigned int SoftLimit
Definition: configreader.h:402
size_t NickMax
Definition: configreader.h:79
int NetBufferSize
Definition: configreader.h:391
std::string SuffixPart
Definition: configreader.h:330
OperSpyWhoisState OperSpyWhois
Definition: configreader.h:425
std::string UserStats
Definition: configreader.h:460
int c_ipv4_range
Definition: configreader.h:235
Definition: configreader.h:106
std::string ModPath
Definition: configreader.h:363
size_t MaxAway
Definition: configreader.h:95
std::bitset< 64 > AllowedUserModes
Definition: configreader.h:156
std::string HideWhoisServer
Definition: configreader.h:432
size_t MaxKick
Definition: configreader.h:91
std::string rules
Definition: configreader.h:310
std::map< irc::string, bool > ulines
Definition: configreader.h:472
bool RawLog
Definition: configreader.h:428
int c_ipv6_range
Definition: configreader.h:240
bool valid
Definition: configreader.h:205
std::string ServerName
Definition: configreader.h:258
std::string PrefixQuit
Definition: configreader.h:314
bool InvBypassModes
Definition: configreader.h:575
size_t ChanMax
Definition: configreader.h:81
std::string FixedQuit
Definition: configreader.h:322
bool GenericOper
Definition: configreader.h:369
Definition: configreader.h:185
ConfigFileCache Files
Definition: configreader.h:222
InviteAnnounceState AnnounceInvites
Definition: configreader.h:420
size_t MaxModes
Definition: configreader.h:83
bool writelog
Definition: configreader.h:131
bool HideSplits
Definition: configreader.h:411
bool nofork
Definition: configreader.h:113
std::string AdminName
Definition: configreader.h:278