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-2021 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 Dennis Friis <[email protected]>
14  * Copyright (C) 2006-2008 Craig Edwards <[email protected]>
15  * Copyright (C) 2006 Oliver Lupton <[email protected]>
16  *
17  * This file is part of InspIRCd. InspIRCd is free software: you can
18  * redistribute it and/or modify it under the terms of the GNU General Public
19  * License as published by the Free Software Foundation, version 2.
20  *
21  * This program is distributed in the hope that it will be useful, but WITHOUT
22  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
23  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
24  * details.
25  *
26  * You should have received a copy of the GNU General Public License
27  * along with this program. If not, see <http://www.gnu.org/licenses/>.
28  */
29 
30 
31 #pragma once
32 
33 #include "inspircd.h"
34 #include "token_list.h"
35 
37 class CoreExport ConfigTag : public refcountbase
38 {
39  ConfigItems 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, const TR1NS::function<bool(const std::string&)>& validator);
48  std::string getString(const std::string& key, const std::string& def = "", size_t minlen = 0, size_t maxlen = UINT32_MAX);
50  long getInt(const std::string& key, long def, long min = LONG_MIN, long max = LONG_MAX);
52  unsigned long getUInt(const std::string& key, unsigned long def, unsigned long min = 0, unsigned long max = ULONG_MAX);
54  double getFloat(const std::string& key, double def, double min = DBL_MIN, double max = DBL_MAX);
56  bool getBool(const std::string& key, bool def = false);
57 
66  unsigned long getDuration(const std::string& key, unsigned long def, unsigned long min = 0, unsigned long max = ULONG_MAX);
67 
74  bool readString(const std::string& key, std::string& value, bool allow_newline = false);
75 
76  std::string getTagLocation();
77 
78  inline const ConfigItems& getItems() const { return items; }
79 
81  static ConfigTag* create(const std::string& Tag, const std::string& file, int line, ConfigItems*& Items);
82  private:
83  ConfigTag(const std::string& Tag, const std::string& file, int line);
84 };
85 
90 {
91  public:
93  size_t MaxLine;
95  size_t NickMax;
97  size_t ChanMax;
99  size_t MaxModes;
101  size_t IdentMax;
103  size_t MaxQuit;
105  size_t MaxTopic;
107  size_t MaxKick;
109  size_t MaxReal;
111  size_t MaxAway;
113  size_t MaxHost;
114 
118  ServerLimits(ConfigTag* tag);
119 
121  size_t GetMaxMask() const { return NickMax + 1 + IdentMax + 1 + MaxHost; }
122 };
123 
125 {
131  bool nofork;
132 
140 
149  bool writelog;
150 
161  bool writepid;
162 
163  /* Whether the --runasroot option was specified at boot. */
164  bool runasroot;
165 
167  int argc;
168 
170  char** argv;
171 };
172 
173 class CoreExport OperInfo : public refcountbase
174 {
175  public:
176  TokenList AllowedOperCommands;
177  TokenList AllowedPrivs;
178 
180  std::bitset<64> AllowedUserModes;
181 
183  std::bitset<64> AllowedChanModes;
184 
186  std::bitset<64> AllowedSnomasks;
187 
193  std::vector<reference<ConfigTag> > class_blocks;
195  std::string name;
196 
200  OperInfo(const std::string& Name);
201 
203  std::string getConfig(const std::string& key);
204  void init();
205 };
206 
212 class CoreExport ServerConfig
213 {
214  private:
215  void CrossCheckOperClassType();
216  void CrossCheckConnectBlocks(ServerConfig* current);
217 
218  public:
221  {
224 
227 
229  BUT_RESTRICT_NOTIFY
230  };
231 
233  {
234  public:
236  std::string Config;
237 
239  std::string Data;
240 
242  std::string Log;
243 
245  std::string Module;
246 
248  std::string Runtime;
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  std::string PrependRuntime(const std::string& fn) const { return FileSystem::ExpandPath(Runtime, fn); }
257  };
258 
261  typedef std::vector<reference<ConnectClass> > ClassVector;
262 
266 
271  ConfigTag* ConfValue(const std::string& tag);
272 
277  ConfigTagList ConfTags(const std::string& tag);
278 
281 
284  std::stringstream errstr;
285 
287  bool valid;
288 
291 
295  ConfigDataHash config_data;
296 
300  ConfigFileCache Files;
301 
305 
308 
312 
316  unsigned char c_ipv4_range;
317 
321  unsigned char c_ipv6_range;
322 
326  std::string ServerName;
327 
330  std::string XLineMessage;
331 
332  /* Holds the network name the local server
333  * belongs to. This is an arbitrary field defined
334  * by the administrator.
335  */
336  std::string Network;
337 
341  std::string ServerDesc;
342 
345 
351 
355  int MaxConn;
356 
363 
368  unsigned int SoftLimit;
369 
373  unsigned int MaxTargets;
374 
376  time_t TimeSkipWarn;
377 
381  bool HideBans;
382 
384  bool RawLog;
385 
387  std::string HideServer;
388 
392  std::string PID;
393 
397 
400  std::string DefaultModes;
401 
404  std::string CustomVersion;
405 
409 
412  std::string CaseMapping;
413 
418 
422 
426 
429  unsigned int MaxChans;
430 
433  unsigned int OperMaxChans;
434 
440  std::string sid;
441 
444  ServerConfig();
445 
446  ~ServerConfig();
447 
450  const std::string& GetSID() const { return sid; }
451 
453  const std::string& GetServerName() const { return HideServer.empty() ? ServerName : HideServer; }
454 
456  const std::string& GetServerDesc() const { return HideServer.empty() ? ServerDesc : HideServer; }
457 
462  void Read();
463 
466  void Apply(ServerConfig* old, const std::string &useruid);
467  void ApplyModules(User* user);
468 
469  void Fill();
470 
475  static std::string Escape(const std::string& str, bool xml = true);
476 
480 };
481 
485 class CoreExport ConfigReaderThread : public Thread
486 {
487  ServerConfig* Config;
488  volatile bool done;
489  public:
490  const std::string TheUserUID;
491  ConfigReaderThread(const std::string &useruid)
492  : Config(new ServerConfig), done(false), TheUserUID(useruid)
493  {
494  }
495 
496  virtual ~ConfigReaderThread()
497  {
498  delete Config;
499  }
500 
501  void Run() CXX11_OVERRIDE;
503  void Finish();
504  bool IsDone() { return done; }
505 };
506 
508 class CoreExport ConfigStatus
509 {
510  public:
512  bool const initial;
513 
515  User* const srcuser;
516 
521  ConfigStatus(User* user = NULL, bool isinitial = false)
522  : initial(isinitial)
523  , srcuser(user)
524  {
525  }
526 };
Definition: configreader.h:486
Definition: configreader.h:509
User *const srcuser
Definition: configreader.h:515
ConfigStatus(User *user=NULL, bool isinitial=false)
Definition: configreader.h:521
bool const initial
Definition: configreader.h:512
Definition: configreader.h:38
std::string getString(const std::string &key, const std::string &def, const std::tr1 ::function< bool(const std::string &)> &validator)
static std::string ExpandPath(const std::string &base, const std::string &fragment)
Definition: fileutils.cpp:73
Definition: modules.h:317
Definition: configreader.h:174
std::string name
Definition: configreader.h:195
std::bitset< 64 > AllowedSnomasks
Definition: configreader.h:186
reference< ConfigTag > oper_block
Definition: configreader.h:189
std::bitset< 64 > AllowedChanModes
Definition: configreader.h:183
reference< ConfigTag > type_block
Definition: configreader.h:191
std::bitset< 64 > AllowedUserModes
Definition: configreader.h:180
std::vector< reference< ConfigTag > > class_blocks
Definition: configreader.h:193
Definition: configreader.h:233
std::string Module
Definition: configreader.h:245
std::string Runtime
Definition: configreader.h:248
std::string Log
Definition: configreader.h:242
std::string Data
Definition: configreader.h:239
std::string Config
Definition: configreader.h:236
Definition: configreader.h:213
std::string PID
Definition: configreader.h:392
ClassVector Classes
Definition: configreader.h:396
OperIndex oper_blocks
Definition: configreader.h:421
ServerLimits Limits
Definition: configreader.h:304
std::string XLineMessage
Definition: configreader.h:330
BannedUserTreatment
Definition: configreader.h:221
@ BUT_RESTRICT_SILENT
Definition: configreader.h:226
@ BUT_NORMAL
Definition: configreader.h:223
int MaxConn
Definition: configreader.h:355
const std::string & GetServerDesc() const
Definition: configreader.h:456
ConfigDataHash config_data
Definition: configreader.h:295
unsigned int MaxTargets
Definition: configreader.h:373
unsigned int OperMaxChans
Definition: configreader.h:433
const std::string & GetSID() const
Definition: configreader.h:450
bool CCOnConnect
Definition: configreader.h:362
bool WildcardIPv6
Definition: configreader.h:290
std::stringstream errstr
Definition: configreader.h:284
std::string ServerDesc
Definition: configreader.h:341
bool NoSnoticeStack
Definition: configreader.h:479
unsigned int MaxChans
Definition: configreader.h:429
time_t TimeSkipWarn
Definition: configreader.h:376
std::vector< reference< ConnectClass > > ClassVector
Definition: configreader.h:261
ConfigFileCache Files
Definition: configreader.h:300
std::string CaseMapping
Definition: configreader.h:412
bool FullHostInTopic
Definition: configreader.h:417
unsigned int SoftLimit
Definition: configreader.h:368
insp::flat_map< std::string, reference< OperInfo > > OperIndex
Definition: configreader.h:265
std::string HideServer
Definition: configreader.h:387
OperIndex OperTypes
Definition: configreader.h:425
std::string ServerName
Definition: configreader.h:326
bool RawLog
Definition: configreader.h:384
CommandLineConf cmdline
Definition: configreader.h:311
BannedUserTreatment RestrictBannedUsers
Definition: configreader.h:344
unsigned char c_ipv6_range
Definition: configreader.h:321
std::string sid
Definition: configreader.h:440
bool HideBans
Definition: configreader.h:381
ConfigTag * EmptyTag
Definition: configreader.h:280
bool valid
Definition: configreader.h:287
ServerPaths Paths
Definition: configreader.h:307
unsigned char c_ipv4_range
Definition: configreader.h:316
bool SyntaxHints
Definition: configreader.h:408
int NetBufferSize
Definition: configreader.h:350
std::string DefaultModes
Definition: configreader.h:400
std::string CustomVersion
Definition: configreader.h:404
const std::string & GetServerName() const
Definition: configreader.h:453
Definition: configreader.h:90
size_t ChanMax
Definition: configreader.h:97
size_t MaxModes
Definition: configreader.h:99
ServerLimits(ConfigTag *tag)
Definition: configreader.cpp:41
size_t GetMaxMask() const
Definition: configreader.h:121
size_t IdentMax
Definition: configreader.h:101
size_t MaxTopic
Definition: configreader.h:105
size_t MaxLine
Definition: configreader.h:93
size_t MaxQuit
Definition: configreader.h:103
size_t MaxHost
Definition: configreader.h:113
size_t MaxAway
Definition: configreader.h:111
size_t MaxKick
Definition: configreader.h:107
size_t NickMax
Definition: configreader.h:95
size_t MaxReal
Definition: configreader.h:109
Definition: threadengine.h:33
Definition: token_list.h:25
Definition: users.h:244
Definition: base.h:90
Definition: configreader.h:125
bool forcedebug
Definition: configreader.h:139
int argc
Definition: configreader.h:167
bool writelog
Definition: configreader.h:149
bool nofork
Definition: configreader.h:131
char ** argv
Definition: configreader.h:170
bool writepid
Definition: configreader.h:161