summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/config.h23
-rw-r--r--modules/commands/os_config.cpp2
-rw-r--r--src/config.cpp71
-rw-r--r--src/init.cpp28
4 files changed, 65 insertions, 59 deletions
diff --git a/include/config.h b/include/config.h
index f3d30559c..f3e5d8816 100644
--- a/include/config.h
+++ b/include/config.h
@@ -20,9 +20,11 @@
namespace Configuration
{
+ namespace Internal
+ {
class CoreExport Block
{
- friend struct Conf;
+ friend struct Configuration::Conf;
public:
typedef Anope::map<Anope::string> item_map;
@@ -34,13 +36,17 @@ namespace Configuration
block_map blocks;
int linenum;
+ /* Represents a missing tag. */
+ static Block EmptyBlock;
+
public:
Block(const Anope::string &);
const Anope::string &GetName() const;
- int CountBlock(const Anope::string &name);
- Block* GetBlock(const Anope::string &name, int num = 0);
+ int CountBlock(const Anope::string &name) const;
+ const Block* GetBlock(const Anope::string &name, int num = 0) const;
+ Block* GetMutableBlock(const Anope::string &name, int num = 0);
- template<typename T> inline T Get(const Anope::string &tag)
+ template<typename T> inline T Get(const Anope::string &tag) const
{
return this->Get<T>(tag, "");
}
@@ -66,6 +72,10 @@ namespace Configuration
template<> CoreExport const Anope::string Block::Get(const Anope::string &tag, const Anope::string& def) const;
template<> CoreExport time_t Block::Get(const Anope::string &tag, const Anope::string &def) const;
template<> CoreExport bool Block::Get(const Anope::string &tag, const Anope::string &def) const;
+ } // namespace Internal
+
+ typedef const Internal::Block Block;
+ typedef Internal::Block MutableBlock;
/** Represents a configuration file
*/
@@ -129,9 +139,6 @@ namespace Configuration
std::map<Anope::string, Block *> modules;
Anope::map<Anope::string> bots;
- /* Represents a missing tag. */
- Block EmptyBlock;
-
Conf();
~Conf();
@@ -143,7 +150,7 @@ namespace Configuration
BotInfo *GetClient(const Anope::string &name);
- Block *GetCommand(CommandSource &);
+ const Block *GetCommand(CommandSource &);
};
struct Uplink
diff --git a/modules/commands/os_config.cpp b/modules/commands/os_config.cpp
index 701cdc1f9..d54730462 100644
--- a/modules/commands/os_config.cpp
+++ b/modules/commands/os_config.cpp
@@ -32,7 +32,7 @@ class CommandOSConfig : public Command
return;
}
- Configuration::Block *block = Config->GetBlock(params[1]);
+ Configuration::MutableBlock *block = Config->GetMutableBlock(params[1]);
if (!block)
block = Config->GetModule(params[1]);
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();