InspIRCd  3.0
configreader.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  * Copyright (C) 2019 Matt Schatz <[email protected]>
5  * Copyright (C) 2018 Chris Novakovic <[email protected]>
6  * Copyright (C) 2013-2014, 2016 Attila Molnar <[email protected]>
7  * Copyright (C) 2013 Daniel Vassdal <[email protected]>
8  * Copyright (C) 2012-2014, 2016-2020 Sadie Powell <[email protected]>
9  * Copyright (C) 2012, 2019 Robby <[email protected]>
10  * Copyright (C) 2009-2010 Daniel De Graaf <[email protected]>
11  * Copyright (C) 2008 Thomas Stagner <[email protected]>
12  * Copyright (C) 2007-2008 Robin Burchell <[email protected]>
13  * Copyright (C) 2007-2008 Craig Edwards <[email protected]>
14  * Copyright (C) 2007 Dennis Friis <[email protected]>
15  *
16  * This file is part of InspIRCd. InspIRCd is free software: you can
17  * redistribute it and/or modify it under the terms of the GNU General Public
18  * License as published by the Free Software Foundation, version 2.
19  *
20  * This program is distributed in the hope that it will be useful, but WITHOUT
21  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
22  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
23  * details.
24  *
25  * You should have received a copy of the GNU General Public License
26  * along with this program. If not, see <http://www.gnu.org/licenses/>.
27  */
28 
29 
30 #pragma once
31 
32 #include <sstream>
33 #include <string>
34 #include <vector>
35 #include <map>
36 #include "inspircd.h"
37 #include "modules.h"
38 #include "socketengine.h"
39 #include "socket.h"
40 #include "token_list.h"
41 
43 class CoreExport ConfigTag : public refcountbase
44 {
45  ConfigItems items;
46  public:
47  const std::string tag;
48  const std::string src_name;
49  const int src_line;
50 
52  std::string getString(const std::string& key, const std::string& def, const TR1NS::function<bool(const std::string&)>& validator);
54  std::string getString(const std::string& key, const std::string& def = "", size_t minlen = 0, size_t maxlen = UINT32_MAX);
56  long getInt(const std::string& key, long def, long min = LONG_MIN, long max = LONG_MAX);
58  unsigned long getUInt(const std::string& key, unsigned long def, unsigned long min = 0, unsigned long max = ULONG_MAX);
60  double getFloat(const std::string& key, double def, double min = DBL_MIN, double max = DBL_MAX);
62  bool getBool(const std::string& key, bool def = false);
63 
72  unsigned long getDuration(const std::string& key, unsigned long def, unsigned long min = 0, unsigned long max = ULONG_MAX);
73 
80  bool readString(const std::string& key, std::string& value, bool allow_newline = false);
81 
82  std::string getTagLocation();
83 
84  inline const ConfigItems& getItems() const { return items; }
85 
87  static ConfigTag* create(const std::string& Tag, const std::string& file, int line, ConfigItems*& Items);
88  private:
89  ConfigTag(const std::string& Tag, const std::string& file, int line);
90 };
91 
96 {
97  public:
99  size_t MaxLine;
101  size_t NickMax;
103  size_t ChanMax;
105  size_t MaxModes;
107  size_t IdentMax;
109  size_t MaxQuit;
111  size_t MaxTopic;
113  size_t MaxKick;
115  size_t MaxReal;
117  size_t MaxAway;
119  size_t MaxHost;
120 
124  ServerLimits(ConfigTag* tag);
125 
127  size_t GetMaxMask() const { return NickMax + 1 + IdentMax + 1 + MaxHost; }
128 };
129 
131 {
137  bool nofork;
138 
146 
155  bool writelog;
156 
167  bool writepid;
168 
169  /* Whether the --runasroot option was specified at boot. */
170  bool runasroot;
171 
173  int argc;
174 
176  char** argv;
177 };
178 
179 class CoreExport OperInfo : public refcountbase
180 {
181  public:
182  TokenList AllowedOperCommands;
183  TokenList AllowedPrivs;
184 
186  std::bitset<64> AllowedUserModes;
187 
189  std::bitset<64> AllowedChanModes;
190 
192  std::bitset<64> AllowedSnomasks;
193 
199  std::vector<reference<ConfigTag> > class_blocks;
201  std::string name;
202 
206  OperInfo(const std::string& Name);
207 
209  std::string getConfig(const std::string& key);
210  void init();
211 };
212 
218 class CoreExport ServerConfig
219 {
220  private:
221  void CrossCheckOperClassType();
222  void CrossCheckConnectBlocks(ServerConfig* current);
223 
224  public:
227  {
230 
233 
235  BUT_RESTRICT_NOTIFY
236  };
237 
239  {
240  public:
242  std::string Config;
243 
245  std::string Data;
246 
248  std::string Log;
249 
251  std::string Module;
252 
253  ServerPaths(ConfigTag* tag);
254 
255  std::string PrependConfig(const std::string& fn) const { return FileSystem::ExpandPath(Config, fn); }
256  std::string PrependData(const std::string& fn) const { return FileSystem::ExpandPath(Data, fn); }
257  std::string PrependLog(const std::string& fn) const { return FileSystem::ExpandPath(Log, fn); }
258  std::string PrependModule(const std::string& fn) const { return FileSystem::ExpandPath(Module, fn); }
259  };
260 
263  typedef std::vector<reference<ConnectClass> > ClassVector;
264 
268 
273  ConfigTag* ConfValue(const std::string& tag);
274 
279  ConfigTagList ConfTags(const std::string& tag);
280 
283 
286  std::stringstream errstr;
287 
289  bool valid;
290 
293 
297  ConfigDataHash config_data;
298 
302  ConfigFileCache Files;
303 
307 
310 
314 
318  unsigned char c_ipv4_range;
319 
323  unsigned char c_ipv6_range;
324 
328  std::string ServerName;
329 
332  std::string XLineMessage;
333 
334  /* Holds the network name the local server
335  * belongs to. This is an arbitrary field defined
336  * by the administrator.
337  */
338  std::string Network;
339 
343  std::string ServerDesc;
344 
347 
353 
357  int MaxConn;
358 
365 
370  unsigned int SoftLimit;
371 
375  unsigned int MaxTargets;
376 
378  time_t TimeSkipWarn;
379 
383  bool HideBans;
384 
386  bool RawLog;
387 
389  std::string HideServer;
390 
394  std::string PID;
395 
399 
402  std::string DefaultModes;
403 
406  std::string CustomVersion;
407 
411 
414  std::string CaseMapping;
415 
420 
424 
428 
431  unsigned int MaxChans;
432 
435  unsigned int OperMaxChans;
436 
442  std::string sid;
443 
446  ServerConfig();
447 
448  ~ServerConfig();
449 
452  const std::string& GetSID() const { return sid; }
453 
458  void Read();
459 
462  void Apply(ServerConfig* old, const std::string &useruid);
463  void ApplyModules(User* user);
464 
465  void Fill();
466 
471  static std::string Escape(const std::string& str, bool xml = true);
472 
476 };
477 
481 class CoreExport ConfigReaderThread : public Thread
482 {
483  ServerConfig* Config;
484  volatile bool done;
485  public:
486  const std::string TheUserUID;
487  ConfigReaderThread(const std::string &useruid)
488  : Config(new ServerConfig), done(false), TheUserUID(useruid)
489  {
490  }
491 
492  virtual ~ConfigReaderThread()
493  {
494  delete Config;
495  }
496 
497  void Run() CXX11_OVERRIDE;
499  void Finish();
500  bool IsDone() { return done; }
501 };
502 
504 class CoreExport ConfigStatus
505 {
506  public:
508  bool const initial;
509 
511  User* const srcuser;
512 
517  ConfigStatus(User* user = NULL, bool isinitial = false)
518  : initial(isinitial)
519  , srcuser(user)
520  {
521  }
522 };
OperInfo
Definition: configreader.h:179
ServerConfig::BUT_RESTRICT_SILENT
@ BUT_RESTRICT_SILENT
Definition: configreader.h:232
ServerConfig::MaxTargets
unsigned int MaxTargets
Definition: configreader.h:375
ServerConfig::cmdline
CommandLineConf cmdline
Definition: configreader.h:313
ServerConfig::ServerDesc
std::string ServerDesc
Definition: configreader.h:343
ServerConfig::c_ipv4_range
unsigned char c_ipv4_range
Definition: configreader.h:318
ServerConfig::OperIndex
insp::flat_map< std::string, reference< OperInfo > > OperIndex
Definition: configreader.h:267
ServerConfig::Limits
ServerLimits Limits
Definition: configreader.h:306
ServerConfig::valid
bool valid
Definition: configreader.h:289
ServerConfig::errstr
std::stringstream errstr
Definition: configreader.h:286
ConfigReaderThread
Definition: configreader.h:481
CommandLineConf
Definition: configreader.h:130
ServerConfig::MaxConn
int MaxConn
Definition: configreader.h:357
insp::flat_map< std::string, std::string, irc::insensitive_swo >
ServerConfig::OperTypes
OperIndex OperTypes
Definition: configreader.h:427
ServerLimits::ServerLimits
ServerLimits(ConfigTag *tag)
Definition: configreader.cpp:40
OperInfo::oper_block
reference< ConfigTag > oper_block
Definition: configreader.h:195
ServerConfig::DefaultModes
std::string DefaultModes
Definition: configreader.h:402
ConfigStatus::ConfigStatus
ConfigStatus(User *user=NULL, bool isinitial=false)
Definition: configreader.h:517
ServerConfig::CCOnConnect
bool CCOnConnect
Definition: configreader.h:364
reference< ConfigTag >
Thread
Definition: threadengine.h:36
ServerLimits::IdentMax
size_t IdentMax
Definition: configreader.h:107
refcountbase
Definition: base.h:91
ServerConfig::CaseMapping
std::string CaseMapping
Definition: configreader.h:414
ServerConfig::ServerPaths::Data
std::string Data
Definition: configreader.h:245
ServerConfig::FullHostInTopic
bool FullHostInTopic
Definition: configreader.h:419
ServerConfig::ServerPaths
Definition: configreader.h:238
ServerLimits
Definition: configreader.h:95
ServerConfig::RestrictBannedUsers
BannedUserTreatment RestrictBannedUsers
Definition: configreader.h:346
ServerConfig::NoSnoticeStack
bool NoSnoticeStack
Definition: configreader.h:475
ServerLimits::MaxReal
size_t MaxReal
Definition: configreader.h:115
ServerConfig::RawLog
bool RawLog
Definition: configreader.h:386
ServerConfig::TimeSkipWarn
time_t TimeSkipWarn
Definition: configreader.h:378
ServerConfig::ServerPaths::Config
std::string Config
Definition: configreader.h:242
ServerConfig::PID
std::string PID
Definition: configreader.h:394
ServerConfig::config_data
ConfigDataHash config_data
Definition: configreader.h:297
OperInfo::AllowedSnomasks
std::bitset< 64 > AllowedSnomasks
Definition: configreader.h:192
OperInfo::type_block
reference< ConfigTag > type_block
Definition: configreader.h:197
ServerConfig::ServerName
std::string ServerName
Definition: configreader.h:328
ServerConfig
Definition: configreader.h:218
ConfigStatus::initial
const bool initial
Definition: configreader.h:508
ServerConfig::c_ipv6_range
unsigned char c_ipv6_range
Definition: configreader.h:323
ServerConfig::ServerPaths::Log
std::string Log
Definition: configreader.h:248
ServerConfig::sid
std::string sid
Definition: configreader.h:442
ServerConfig::Classes
ClassVector Classes
Definition: configreader.h:398
OperInfo::class_blocks
std::vector< reference< ConfigTag > > class_blocks
Definition: configreader.h:199
ServerConfig::SoftLimit
unsigned int SoftLimit
Definition: configreader.h:370
ServerLimits::MaxKick
size_t MaxKick
Definition: configreader.h:113
ServerConfig::GetSID
const std::string & GetSID() const
Definition: configreader.h:452
CommandLineConf::forcedebug
bool forcedebug
Definition: configreader.h:145
ServerConfig::BannedUserTreatment
BannedUserTreatment
Definition: configreader.h:226
ServerConfig::HideBans
bool HideBans
Definition: configreader.h:383
OperInfo::AllowedChanModes
std::bitset< 64 > AllowedChanModes
Definition: configreader.h:189
ConfigTag
Definition: configreader.h:43
ServerConfig::ClassVector
std::vector< reference< ConnectClass > > ClassVector
Definition: configreader.h:263
ServerConfig::Files
ConfigFileCache Files
Definition: configreader.h:302
ServerConfig::NetBufferSize
int NetBufferSize
Definition: configreader.h:352
CommandLineConf::writepid
bool writepid
Definition: configreader.h:167
ServerLimits::MaxLine
size_t MaxLine
Definition: configreader.h:99
ServerConfig::EmptyTag
ConfigTag * EmptyTag
Definition: configreader.h:282
ServerLimits::MaxAway
size_t MaxAway
Definition: configreader.h:117
Thread::Run
virtual void Run()=0
OperInfo::name
std::string name
Definition: configreader.h:201
ConfigStatus::srcuser
User *const srcuser
Definition: configreader.h:511
ServerConfig::MaxChans
unsigned int MaxChans
Definition: configreader.h:431
ServerConfig::WildcardIPv6
bool WildcardIPv6
Definition: configreader.h:292
Module
Definition: modules.h:316
ServerLimits::MaxHost
size_t MaxHost
Definition: configreader.h:119
User
Definition: users.h:239
ServerConfig::SyntaxHints
bool SyntaxHints
Definition: configreader.h:410
OperInfo::AllowedUserModes
std::bitset< 64 > AllowedUserModes
Definition: configreader.h:186
ServerLimits::GetMaxMask
size_t GetMaxMask() const
Definition: configreader.h:127
ServerLimits::MaxModes
size_t MaxModes
Definition: configreader.h:105
CommandLineConf::nofork
bool nofork
Definition: configreader.h:137
ServerConfig::Paths
ServerPaths Paths
Definition: configreader.h:309
ServerConfig::BUT_NORMAL
@ BUT_NORMAL
Definition: configreader.h:229
CommandLineConf::argv
char ** argv
Definition: configreader.h:176
CommandLineConf::writelog
bool writelog
Definition: configreader.h:155
ServerLimits::MaxQuit
size_t MaxQuit
Definition: configreader.h:109
ServerLimits::MaxTopic
size_t MaxTopic
Definition: configreader.h:111
ServerLimits::ChanMax
size_t ChanMax
Definition: configreader.h:103
FileSystem::ExpandPath
static std::string ExpandPath(const std::string &base, const std::string &fragment)
Definition: fileutils.cpp:73
ServerConfig::ServerPaths::Module
std::string Module
Definition: configreader.h:251
ConfigStatus
Definition: configreader.h:504
CommandLineConf::argc
int argc
Definition: configreader.h:173
TokenList
Definition: token_list.h:24
ServerConfig::oper_blocks
OperIndex oper_blocks
Definition: configreader.h:423
ServerConfig::HideServer
std::string HideServer
Definition: configreader.h:389
ServerConfig::XLineMessage
std::string XLineMessage
Definition: configreader.h:332
ServerConfig::OperMaxChans
unsigned int OperMaxChans
Definition: configreader.h:435
ServerConfig::CustomVersion
std::string CustomVersion
Definition: configreader.h:406
ServerLimits::NickMax
size_t NickMax
Definition: configreader.h:101