diff options
author | Sadie Powell <sadie@witchery.services> | 2023-06-03 21:42:06 +0100 |
---|---|---|
committer | Sadie Powell <sadie@witchery.services> | 2023-06-03 21:51:07 +0100 |
commit | 9d0a6ddc67b1e7bd0c32603b6fa90b702c13447d (patch) | |
tree | 1e4d019535c89f67e7cf54a76afabe188947c668 /src | |
parent | 29db25dac7aff36b4f7239a9fabd57230534cf35 (diff) | |
parent | fbf3b344740f6bd4f9337e485e35e9e8103428bc (diff) |
Merge branch '2.0' into 2.1.
Diffstat (limited to 'src')
-rw-r--r-- | src/channels.cpp | 23 | ||||
-rw-r--r-- | src/config.cpp | 58 | ||||
-rw-r--r-- | src/init.cpp | 28 | ||||
-rw-r--r-- | src/logger.cpp | 2 | ||||
-rw-r--r-- | src/modes.cpp | 2 | ||||
-rw-r--r-- | src/servers.cpp | 4 | ||||
-rw-r--r-- | src/users.cpp | 9 | ||||
-rw-r--r-- | src/win32/conanfile.txt | 21 |
8 files changed, 103 insertions, 44 deletions
diff --git a/src/channels.cpp b/src/channels.cpp index b7b6b8940..e2249e528 100644 --- a/src/channels.cpp +++ b/src/channels.cpp @@ -783,7 +783,7 @@ bool Channel::Kick(BotInfo *bi, User *u, const char *reason, ...) return false; if (bi == NULL) - bi = this->ci->WhoSends(); + bi = this->WhoSends(); EventReturn MOD_RESULT; FOREACH_RESULT(OnBotKick, MOD_RESULT, (bi, this, u, buf)); @@ -812,7 +812,7 @@ void Channel::ChangeTopic(const Anope::string &user, const Anope::string &newtop this->topic_setter = user; this->topic_ts = ts; - IRCD->SendTopic(this->ci->WhoSends(), this); + IRCD->SendTopic(this->WhoSends(), this); /* Now that the topic is set update the time set. This is *after* we set it so the protocol modules are able to tell the old last set time */ this->topic_time = Anope::CurTime; @@ -911,8 +911,10 @@ bool Channel::CheckKick(User *user) if (MOD_RESULT != EVENT_STOP) return false; + if (mask.empty() && this->ci) + mask = this->ci->GetIdealBan(user); if (mask.empty()) - mask = this->ci ? this->ci->GetIdealBan(user) : "*!*@" + user->GetDisplayedHost(); + mask = "*!*@" + user->GetDisplayedHost(); if (reason.empty()) reason = Language::Translate(user->Account(), CHAN_NOT_ALLOWED_TO_JOIN); @@ -924,6 +926,21 @@ bool Channel::CheckKick(User *user) return true; } +BotInfo* Channel::WhoSends() const +{ + if (ci) + return ci->WhoSends(); + + BotInfo *ChanServ = Config->GetClient("ChanServ"); + if (ChanServ) + return ChanServ; + + if (!BotListByNick->empty()) + return BotListByNick->begin()->second; + + return NULL; +} + Channel* Channel::Find(const Anope::string &name) { channel_map::const_iterator it = ChannelList.find(name); diff --git a/src/config.cpp b/src/config.cpp index 8447a8a16..fe2336441 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("anope.conf", false); // Configuration file name Conf *Config = NULL; +Block Block::EmptyBlock(""); + Block::Block(const Anope::string &n) : name(n), linenum(-1) { } @@ -31,19 +35,29 @@ const Anope::string &Block::GetName() const return name; } -int Block::CountBlock(const Anope::string &bname) +int Block::CountBlock(const Anope::string &bname) const { return blocks.count(bname); } -Block* Block::GetBlock(const Anope::string &bname, int num) +const Block* Block::GetBlock(const Anope::string &bname, int num) const +{ + 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) @@ -52,7 +66,7 @@ bool Block::Set(const Anope::string &tag, const Anope::string &value) return true; } -const Block::item_map& Block::GetItems() const +const Block::item_map &Block::GetItems() const { return items; } @@ -101,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; @@ -110,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"); @@ -145,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"); @@ -191,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); int protocol; const Anope::string &protocolstr = uplink->Get<const Anope::string>("protocol", "ipv4"); @@ -224,7 +238,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"); @@ -235,7 +249,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"), @@ -280,7 +294,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"), @@ -314,7 +328,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"), @@ -400,7 +414,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"); @@ -426,7 +440,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"), @@ -451,7 +465,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"); @@ -462,7 +476,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"), @@ -484,7 +498,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"); @@ -601,7 +615,7 @@ void Conf::Post(Conf *old) Block *Conf::GetModule(Module *m) { if (!m) - return &(Config->EmptyBlock); + return NULL; return GetModule(m->name); } @@ -641,7 +655,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"; @@ -653,7 +667,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) @@ -904,7 +918,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 4e39a7882..cb94d77f6 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->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); - } - } #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(); diff --git a/src/logger.cpp b/src/logger.cpp index 60183de29..2bee1a80e 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -368,7 +368,7 @@ void LogInfo::ProcessMessage(const Log *l) if (!bi) bi = this->bot; if (!bi) - bi = c->ci->WhoSends(); + bi = c->WhoSends(); if (bi) IRCD->SendPrivmsg(bi, c->name, "%s", buffer.c_str()); } diff --git a/src/modes.cpp b/src/modes.cpp index 9bc07097b..be2a5fab1 100644 --- a/src/modes.cpp +++ b/src/modes.cpp @@ -607,7 +607,7 @@ void ModeManager::StackerAdd(BotInfo *bi, Channel *c, ChannelMode *cm, bool Set, if (bi) s->bi = bi; else - s->bi = c->ci->WhoSends(); + s->bi = c->WhoSends(); if (!modePipe) modePipe = new ModePipe(); diff --git a/src/servers.cpp b/src/servers.cpp index 72f2e2f8f..397ed8fe1 100644 --- a/src/servers.cpp +++ b/src/servers.cpp @@ -121,11 +121,11 @@ Server::Server(Server *up, const Anope::string &sname, unsigned shops, const Ano ChannelMode *cm = ModeManager::FindChannelModeByName(it2->first); if (!cm || cm->type != MODE_LIST) continue; - ModeManager::StackerAdd(c->ci->WhoSends(), c, cm, true, it2->second); + ModeManager::StackerAdd(c->WhoSends(), c, cm, true, it2->second); } if (!c->topic.empty() && !c->topic_setter.empty()) - IRCD->SendTopic(c->ci->WhoSends(), c); + IRCD->SendTopic(c->WhoSends(), c); c->syncing = true; } diff --git a/src/users.cpp b/src/users.cpp index bd35b432d..2b7aacd9b 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -467,9 +467,16 @@ bool User::IsServicesOper() { bool match = false; Anope::string match_host = this->GetIdent() + "@" + this->host; + Anope::string match_ip = this->GetIdent() + "@" + this->ip.addr(); for (unsigned i = 0; i < this->nc->o->hosts.size(); ++i) - if (Anope::Match(match_host, this->nc->o->hosts[i])) + { + const Anope::string &userhost = this->nc->o->hosts[i]; + if (Anope::Match(match_host, userhost) || Anope::Match(match_ip, userhost)) + { match = true; + break; + } + } if (match == false) return false; } diff --git a/src/win32/conanfile.txt b/src/win32/conanfile.txt new file mode 100644 index 000000000..c2b0f325d --- /dev/null +++ b/src/win32/conanfile.txt @@ -0,0 +1,21 @@ +[requires]
+libmysqlclient/8.0.31
+openssl/1.1.1t
+pcre2/10.42
+sqlite3/3.41.1
+gettext/0.21
+libgettext/0.21
+
+[options]
+libmysqlclient/*:shared=True
+openssl/*:shared=True
+pcre2/*:shared=True
+sqlite3/*:shared=True
+libgettext/*:shared=True
+
+[imports]
+., *.dll -> extradll
+., *.lib -> extralib
+
+[generators]
+cmake
\ No newline at end of file |