summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdam <Adam@sigterm.info>2023-05-28 20:40:00 -0400
committerAdam <Adam@sigterm.info>2023-05-28 21:25:59 -0400
commit0646547c9eecc464dfc3c6fb0c7dfa9a3298a268 (patch)
treecbcc082dfb15852b9336a0c1343f2ec4d33da704 /src
parent41206b991e5aa7821acd424df2ec6800d868df1c (diff)
config: remove dependency on no-delete-null-pointer-checks
Diffstat (limited to 'src')
-rw-r--r--src/config.cpp71
-rw-r--r--src/init.cpp28
2 files changed, 49 insertions, 50 deletions
diff --git a/src/config.cpp b/src/config.cpp
index dc9620f1d..8287ad6de 100644
--- a/src/config.cpp
+++ b/src/config.cpp
@@ -17,11 +17,15 @@
#include "channels.h"
#include "hashcomp.h"
-using namespace Configuration;
+using Configuration::File;
+using Configuration::Conf;
+using Configuration::Internal::Block;
File ServicesConf("services.conf", false); // Services configuration file name
Conf *Config = NULL;
+Block Block::EmptyBlock("");
+
Block::Block(const Anope::string &n) : name(n), linenum(-1)
{
}
@@ -31,49 +35,44 @@ const Anope::string &Block::GetName() const
return name;
}
-int Block::CountBlock(const Anope::string &bname)
+int Block::CountBlock(const Anope::string &bname) const
{
- if (!this)
- return 0;
-
return blocks.count(bname);
}
-Block* Block::GetBlock(const Anope::string &bname, int num)
+const Block* Block::GetBlock(const Anope::string &bname, int num) const
{
- if (!this)
- return NULL;
+ std::pair<block_map::const_iterator, block_map::const_iterator> it = blocks.equal_range(bname);
+
+ for (int i = 0; it.first != it.second; ++it.first, ++i)
+ if (i == num)
+ return &it.first->second;
+ return &EmptyBlock;
+}
+Block* Block::GetMutableBlock(const Anope::string &bname, int num)
+{
std::pair<block_map::iterator, block_map::iterator> it = blocks.equal_range(bname);
for (int i = 0; it.first != it.second; ++it.first, ++i)
if (i == num)
return &it.first->second;
- return &(Config->EmptyBlock);
+ return NULL;
}
bool Block::Set(const Anope::string &tag, const Anope::string &value)
{
- if (!this)
- return false;
-
items[tag] = value;
return true;
}
const Block::item_map* Block::GetItems() const
{
- if (this)
- return &items;
- else
- return NULL;
+ return &items;
}
template<> const Anope::string Block::Get(const Anope::string &tag, const Anope::string& def) const
{
- if (!this)
- return def;
-
Anope::map<Anope::string>::const_iterator it = items.find(tag);
if (it != items.end())
return it->second;
@@ -116,7 +115,7 @@ template<typename T> static void ValidateNotZero(const Anope::string &block, con
throw ConfigException("The value for <" + block + ":" + name + "> cannot be zero!");
}
-Conf::Conf() : Block(""), EmptyBlock("")
+Conf::Conf() : Block("")
{
ReadTimeout = 0;
UsePrivmsg = DefPrivmsg = false;
@@ -125,7 +124,7 @@ Conf::Conf() : Block(""), EmptyBlock("")
for (int i = 0; i < this->CountBlock("include"); ++i)
{
- Block *include = this->GetBlock("include", i);
+ const Block *include = this->GetBlock("include", i);
const Anope::string &type = include->Get<const Anope::string>("type"),
&file = include->Get<const Anope::string>("name");
@@ -160,7 +159,7 @@ Conf::Conf() : Block(""), EmptyBlock("")
throw ConfigException("<" + noreload[i].block + ":" + noreload[i].name + "> can not be modified once set");
}
- Block *serverinfo = this->GetBlock("serverinfo"), *options = this->GetBlock("options"),
+ const Block *serverinfo = this->GetBlock("serverinfo"), *options = this->GetBlock("options"),
*mail = this->GetBlock("mail"), *networkinfo = this->GetBlock("networkinfo");
const Anope::string &servername = serverinfo->Get<Anope::string>("name");
@@ -206,7 +205,7 @@ Conf::Conf() : Block(""), EmptyBlock("")
for (int i = 0; i < this->CountBlock("uplink"); ++i)
{
- Block *uplink = this->GetBlock("uplink", i);
+ const Block *uplink = this->GetBlock("uplink", i);
const Anope::string &host = uplink->Get<const Anope::string>("host");
bool ipv6 = uplink->Get<bool>("ipv6");
@@ -225,7 +224,7 @@ Conf::Conf() : Block(""), EmptyBlock("")
for (int i = 0; i < this->CountBlock("module"); ++i)
{
- Block *module = this->GetBlock("module", i);
+ const Block *module = this->GetBlock("module", i);
const Anope::string &modname = module->Get<const Anope::string>("name");
@@ -236,7 +235,7 @@ Conf::Conf() : Block(""), EmptyBlock("")
for (int i = 0; i < this->CountBlock("opertype"); ++i)
{
- Block *opertype = this->GetBlock("opertype", i);
+ const Block *opertype = this->GetBlock("opertype", i);
const Anope::string &oname = opertype->Get<const Anope::string>("name"),
&modes = opertype->Get<const Anope::string>("modes"),
@@ -281,7 +280,7 @@ Conf::Conf() : Block(""), EmptyBlock("")
for (int i = 0; i < this->CountBlock("oper"); ++i)
{
- Block *oper = this->GetBlock("oper", i);
+ const Block *oper = this->GetBlock("oper", i);
const Anope::string &nname = oper->Get<const Anope::string>("name"),
&type = oper->Get<const Anope::string>("type"),
@@ -315,7 +314,7 @@ Conf::Conf() : Block(""), EmptyBlock("")
it->second->conf = false;
for (int i = 0; i < this->CountBlock("service"); ++i)
{
- Block *service = this->GetBlock("service", i);
+ const Block *service = this->GetBlock("service", i);
const Anope::string &nick = service->Get<const Anope::string>("nick"),
&user = service->Get<const Anope::string>("user"),
@@ -401,7 +400,7 @@ Conf::Conf() : Block(""), EmptyBlock("")
for (int i = 0; i < this->CountBlock("log"); ++i)
{
- Block *log = this->GetBlock("log", i);
+ const Block *log = this->GetBlock("log", i);
int logage = log->Get<int>("logage");
bool rawio = log->Get<bool>("rawio");
@@ -427,7 +426,7 @@ Conf::Conf() : Block(""), EmptyBlock("")
it->second->commands.clear();
for (int i = 0; i < this->CountBlock("command"); ++i)
{
- Block *command = this->GetBlock("command", i);
+ const Block *command = this->GetBlock("command", i);
const Anope::string &service = command->Get<const Anope::string>("service"),
&nname = command->Get<const Anope::string>("name"),
@@ -452,7 +451,7 @@ Conf::Conf() : Block(""), EmptyBlock("")
PrivilegeManager::ClearPrivileges();
for (int i = 0; i < this->CountBlock("privilege"); ++i)
{
- Block *privilege = this->GetBlock("privilege", i);
+ const Block *privilege = this->GetBlock("privilege", i);
const Anope::string &nname = privilege->Get<const Anope::string>("name"),
&desc = privilege->Get<const Anope::string>("desc");
@@ -463,7 +462,7 @@ Conf::Conf() : Block(""), EmptyBlock("")
for (int i = 0; i < this->CountBlock("fantasy"); ++i)
{
- Block *fantasy = this->GetBlock("fantasy", i);
+ const Block *fantasy = this->GetBlock("fantasy", i);
const Anope::string &nname = fantasy->Get<const Anope::string>("name"),
&service = fantasy->Get<const Anope::string>("command"),
@@ -485,7 +484,7 @@ Conf::Conf() : Block(""), EmptyBlock("")
for (int i = 0; i < this->CountBlock("command_group"); ++i)
{
- Block *command_group = this->GetBlock("command_group", i);
+ const Block *command_group = this->GetBlock("command_group", i);
const Anope::string &nname = command_group->Get<const Anope::string>("name"),
&description = command_group->Get<const Anope::string>("description");
@@ -602,7 +601,7 @@ void Conf::Post(Conf *old)
Block *Conf::GetModule(Module *m)
{
if (!m)
- return &(Config->EmptyBlock);
+ return NULL;
return GetModule(m->name);
}
@@ -642,7 +641,7 @@ BotInfo *Conf::GetClient(const Anope::string &cname)
return GetClient(cname);
}
-Block *Conf::GetCommand(CommandSource &source)
+const Block *Conf::GetCommand(CommandSource &source)
{
const Anope::string &block_name = source.c ? "fantasy" : "command";
@@ -654,7 +653,7 @@ Block *Conf::GetCommand(CommandSource &source)
return b;
}
- return &(Config->EmptyBlock);
+ return &Block::EmptyBlock;
}
File::File(const Anope::string &n, bool e) : name(n), executable(e), fp(NULL)
@@ -905,7 +904,7 @@ void Conf::LoadConf(File &file)
/* Check defines */
for (int i = 0; i < this->CountBlock("define"); ++i)
{
- Block *define = this->GetBlock("define", i);
+ const Block *define = this->GetBlock("define", i);
const Anope::string &dname = define->Get<const Anope::string>("name");
diff --git a/src/init.cpp b/src/init.cpp
index 22f8385ee..082f39b96 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -422,20 +422,6 @@ void Anope::Init(int ac, char **av)
#ifdef _WIN32
if (!SupportedWindowsVersion())
throw CoreException(GetWindowsVersion() + " is not a supported version of Windows");
-#else
- /* If we're root, issue a warning now */
- if (!getuid() && !getgid())
- {
- /* If we are configured to setuid later, don't issue a warning */
- Configuration::Block *options = Config ? Config->GetBlock("options") : NULL;
- if (!options || options->Get<const Anope::string>("user").empty())
- {
- std::cerr << "WARNING: You are currently running Anope as the root superuser. Anope does not" << std::endl;
- std::cerr << " require root privileges to run, and it is discouraged that you run Anope" << std::endl;
- std::cerr << " as the root superuser." << std::endl;
- sleep(3);
- }
- }
#endif
#ifdef _WIN32
@@ -527,6 +513,20 @@ void Anope::Init(int ac, char **av)
ModuleManager::LoadModule(Config->GetBlock("module", i)->Get<const Anope::string>("name"), NULL);
#ifndef _WIN32
+ /* If we're root, issue a warning now */
+ if (!getuid() && !getgid())
+ {
+ /* If we are configured to setuid later, don't issue a warning */
+ Configuration::Block *options = Config->GetBlock("options");
+ if (options->Get<const Anope::string>("user").empty())
+ {
+ std::cerr << "WARNING: You are currently running Anope as the root superuser. Anope does not" << std::endl;
+ std::cerr << " require root privileges to run, and it is discouraged that you run Anope" << std::endl;
+ std::cerr << " as the root superuser." << std::endl;
+ sleep(3);
+ }
+ }
+
/* We won't background later, so we should setuid now */
if (Anope::NoFork)
setuidgid();