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-2019 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 NickMax;
101  size_t ChanMax;
103  size_t MaxModes;
105  size_t IdentMax;
107  size_t MaxQuit;
109  size_t MaxTopic;
111  size_t MaxKick;
113  size_t MaxReal;
115  size_t MaxAway;
117  size_t MaxLine;
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 
196  std::vector<reference<ConfigTag> > class_blocks;
198  std::string name;
199 
203  OperInfo(const std::string& Name);
204 
206  std::string getConfig(const std::string& key);
207  void init();
208 };
209 
215 class CoreExport ServerConfig
216 {
217  private:
218  void CrossCheckOperClassType();
219  void CrossCheckConnectBlocks(ServerConfig* current);
220 
221  public:
224  {
227 
230 
232  BUT_RESTRICT_NOTIFY
233  };
234 
236  {
237  public:
239  std::string Config;
240 
242  std::string Data;
243 
245  std::string Log;
246 
248  std::string Module;
249 
250  ServerPaths(ConfigTag* tag);
251 
252  std::string PrependConfig(const std::string& fn) const { return FileSystem::ExpandPath(Config, fn); }
253  std::string PrependData(const std::string& fn) const { return FileSystem::ExpandPath(Data, fn); }
254  std::string PrependLog(const std::string& fn) const { return FileSystem::ExpandPath(Log, fn); }
255  std::string PrependModule(const std::string& fn) const { return FileSystem::ExpandPath(Module, fn); }
256  };
257 
260  typedef std::vector<reference<ConnectClass> > ClassVector;
261 
265 
270  ConfigTag* ConfValue(const std::string& tag);
271 
276  ConfigTagList ConfTags(const std::string& tag);
277 
280 
283  std::stringstream errstr;
284 
286  bool valid;
287 
290 
294  ConfigDataHash config_data;
295 
299  ConfigFileCache Files;
300 
304 
307 
311 
315  unsigned char c_ipv4_range;
316 
320  unsigned char c_ipv6_range;
321 
325  std::string ServerName;
326 
329  std::string XLineMessage;
330 
331  /* Holds the network name the local server
332  * belongs to. This is an arbitary field defined
333  * by the administrator.
334  */
335  std::string Network;
336 
340  std::string ServerDesc;
341 
344 
350 
354  int MaxConn;
355 
362 
367  unsigned int SoftLimit;
368 
372  unsigned int MaxTargets;
373 
375  time_t TimeSkipWarn;
376 
380  bool HideBans;
381 
383  bool RawLog;
384 
386  std::string HideServer;
387 
391  std::string PID;
392 
396 
399  std::string DefaultModes;
400 
403  std::string CustomVersion;
404 
408 
411  std::string CaseMapping;
412 
417 
421 
425 
428  unsigned int MaxChans;
429 
432  unsigned int OperMaxChans;
433 
439  std::string sid;
440 
443  ServerConfig();
444 
445  ~ServerConfig();
446 
449  const std::string& GetSID() const { return sid; }
450 
455  void Read();
456 
459  void Apply(ServerConfig* old, const std::string &useruid);
460  void ApplyModules(User* user);
461 
462  void Fill();
463 
468  static std::string Escape(const std::string& str, bool xml = true);
469 
473 };
474 
478 class CoreExport ConfigReaderThread : public Thread
479 {
480  ServerConfig* Config;
481  volatile bool done;
482  public:
483  const std::string TheUserUID;
484  ConfigReaderThread(const std::string &useruid)
485  : Config(new ServerConfig), done(false), TheUserUID(useruid)
486  {
487  }
488 
489  virtual ~ConfigReaderThread()
490  {
491  delete Config;
492  }
493 
494  void Run() CXX11_OVERRIDE;
496  void Finish();
497  bool IsDone() { return done; }
498 };
499 
501 class CoreExport ConfigStatus
502 {
503  public:
505  bool const initial;
506 
508  User* const srcuser;
509 
514  ConfigStatus(User* user = NULL, bool isinitial = false)
515  : initial(isinitial)
516  , srcuser(user)
517  {
518  }
519 };
OperInfo
Definition: configreader.h:179
ServerConfig::BUT_RESTRICT_SILENT
@ BUT_RESTRICT_SILENT
Definition: configreader.h:229
ServerConfig::MaxTargets
unsigned int MaxTargets
Definition: configreader.h:372
ServerConfig::cmdline
CommandLineConf cmdline
Definition: configreader.h:310
ServerConfig::ServerDesc
std::string ServerDesc
Definition: configreader.h:340
ServerConfig::c_ipv4_range
unsigned char c_ipv4_range
Definition: configreader.h:315
ServerConfig::OperIndex
insp::flat_map< std::string, reference< OperInfo > > OperIndex
Definition: configreader.h:264
ServerConfig::Limits
ServerLimits Limits
Definition: configreader.h:303
ServerConfig::valid
bool valid
Definition: configreader.h:286
ServerConfig::errstr
std::stringstream errstr
Definition: configreader.h:283
ConfigReaderThread
Definition: configreader.h:478
CommandLineConf
Definition: configreader.h:130
ServerConfig::MaxConn
int MaxConn
Definition: configreader.h:354
insp::flat_map< std::string, std::string, irc::insensitive_swo >
ServerConfig::OperTypes
OperIndex OperTypes
Definition: configreader.h:424
ServerLimits::ServerLimits
ServerLimits(ConfigTag *tag)
Definition: configreader.cpp:40
OperInfo::oper_block
reference< ConfigTag > oper_block
Definition: configreader.h:192
ServerConfig::DefaultModes
std::string DefaultModes
Definition: configreader.h:399
ConfigStatus::ConfigStatus
ConfigStatus(User *user=NULL, bool isinitial=false)
Definition: configreader.h:514
ServerConfig::CCOnConnect
bool CCOnConnect
Definition: configreader.h:361
reference< ConfigTag >
Thread
Definition: threadengine.h:36
ServerLimits::IdentMax
size_t IdentMax
Definition: configreader.h:105
refcountbase
Definition: base.h:90
ServerConfig::CaseMapping
std::string CaseMapping
Definition: configreader.h:411
ServerConfig::ServerPaths::Data
std::string Data
Definition: configreader.h:242
ServerConfig::FullHostInTopic
bool FullHostInTopic
Definition: configreader.h:416
ServerConfig::ServerPaths
Definition: configreader.h:235
ServerLimits
Definition: configreader.h:95
ServerConfig::RestrictBannedUsers
BannedUserTreatment RestrictBannedUsers
Definition: configreader.h:343
ServerConfig::NoSnoticeStack
bool NoSnoticeStack
Definition: configreader.h:472
ServerLimits::MaxReal
size_t MaxReal
Definition: configreader.h:113
ServerConfig::RawLog
bool RawLog
Definition: configreader.h:383
ServerConfig::TimeSkipWarn
time_t TimeSkipWarn
Definition: configreader.h:375
ServerConfig::ServerPaths::Config
std::string Config
Definition: configreader.h:239
ServerConfig::PID
std::string PID
Definition: configreader.h:391
ServerConfig::config_data
ConfigDataHash config_data
Definition: configreader.h:294
OperInfo::type_block
reference< ConfigTag > type_block
Definition: configreader.h:194
ServerConfig::ServerName
std::string ServerName
Definition: configreader.h:325
ServerConfig
Definition: configreader.h:215
ConfigStatus::initial
const bool initial
Definition: configreader.h:505
ServerConfig::c_ipv6_range
unsigned char c_ipv6_range
Definition: configreader.h:320
ServerConfig::ServerPaths::Log
std::string Log
Definition: configreader.h:245
ServerConfig::sid
std::string sid
Definition: configreader.h:439
ServerConfig::Classes
ClassVector Classes
Definition: configreader.h:395
OperInfo::class_blocks
std::vector< reference< ConfigTag > > class_blocks
Definition: configreader.h:196
ServerConfig::SoftLimit
unsigned int SoftLimit
Definition: configreader.h:367
ServerLimits::MaxKick
size_t MaxKick
Definition: configreader.h:111
ServerConfig::GetSID
const std::string & GetSID() const
Definition: configreader.h:449
CommandLineConf::forcedebug
bool forcedebug
Definition: configreader.h:145
ServerConfig::BannedUserTreatment
BannedUserTreatment
Definition: configreader.h:223
ServerConfig::HideBans
bool HideBans
Definition: configreader.h:380
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:260
ServerConfig::Files
ConfigFileCache Files
Definition: configreader.h:299
ServerConfig::NetBufferSize
int NetBufferSize
Definition: configreader.h:349
CommandLineConf::writepid
bool writepid
Definition: configreader.h:167
ServerLimits::MaxLine
size_t MaxLine
Definition: configreader.h:117
ServerConfig::EmptyTag
ConfigTag * EmptyTag
Definition: configreader.h:279
ServerLimits::MaxAway
size_t MaxAway
Definition: configreader.h:115
Thread::Run
virtual void Run()=0
OperInfo::name
std::string name
Definition: configreader.h:198
ConfigStatus::srcuser
User *const srcuser
Definition: configreader.h:508
ServerConfig::MaxChans
unsigned int MaxChans
Definition: configreader.h:428
ServerConfig::WildcardIPv6
bool WildcardIPv6
Definition: configreader.h:289
Module
Definition: modules.h:247
ServerLimits::MaxHost
size_t MaxHost
Definition: configreader.h:119
User
Definition: users.h:233
ServerConfig::SyntaxHints
bool SyntaxHints
Definition: configreader.h:407
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:103
CommandLineConf::nofork
bool nofork
Definition: configreader.h:137
ServerConfig::Paths
ServerPaths Paths
Definition: configreader.h:306
ServerConfig::BUT_NORMAL
@ BUT_NORMAL
Definition: configreader.h:226
CommandLineConf::argv
char ** argv
Definition: configreader.h:176
CommandLineConf::writelog
bool writelog
Definition: configreader.h:155
ServerLimits::MaxQuit
size_t MaxQuit
Definition: configreader.h:107
ServerLimits::MaxTopic
size_t MaxTopic
Definition: configreader.h:109
ServerLimits::ChanMax
size_t ChanMax
Definition: configreader.h:101
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:248
ConfigStatus
Definition: configreader.h:501
CommandLineConf::argc
int argc
Definition: configreader.h:173
TokenList
Definition: token_list.h:24
ServerConfig::oper_blocks
OperIndex oper_blocks
Definition: configreader.h:420
ServerConfig::HideServer
std::string HideServer
Definition: configreader.h:386
ServerConfig::XLineMessage
std::string XLineMessage
Definition: configreader.h:329
ServerConfig::OperMaxChans
unsigned int OperMaxChans
Definition: configreader.h:432
ServerConfig::CustomVersion
std::string CustomVersion
Definition: configreader.h:403
ServerLimits::NickMax
size_t NickMax
Definition: configreader.h:99