From b7abfe5eca076c29a0d49a411320612264093bdf Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Thu, 4 May 2023 17:56:37 +0100 Subject: Avoid returning null when a config tag does not exist. This invokes undefined behaviour on modern compilers. --- src/config.cpp | 8 ++++---- src/init.cpp | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/config.cpp b/src/config.cpp index bd9bebe5c..dc9620f1d 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -49,7 +49,7 @@ Block* Block::GetBlock(const Anope::string &bname, int num) for (int i = 0; it.first != it.second; ++it.first, ++i) if (i == num) return &it.first->second; - return NULL; + return &(Config->EmptyBlock); } bool Block::Set(const Anope::string &tag, const Anope::string &value) @@ -116,7 +116,7 @@ template static void ValidateNotZero(const Anope::string &block, con throw ConfigException("The value for <" + block + ":" + name + "> cannot be zero!"); } -Conf::Conf() : Block("") +Conf::Conf() : Block(""), EmptyBlock("") { ReadTimeout = 0; UsePrivmsg = DefPrivmsg = false; @@ -602,7 +602,7 @@ void Conf::Post(Conf *old) Block *Conf::GetModule(Module *m) { if (!m) - return NULL; + return &(Config->EmptyBlock); return GetModule(m->name); } @@ -654,7 +654,7 @@ Block *Conf::GetCommand(CommandSource &source) return b; } - return NULL; + return &(Config->EmptyBlock); } File::File(const Anope::string &n, bool e) : name(n), executable(e), fp(NULL) diff --git a/src/init.cpp b/src/init.cpp index 025b34c4e..22f8385ee 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -427,8 +427,8 @@ void Anope::Init(int ac, char **av) if (!getuid() && !getgid()) { /* If we are configured to setuid later, don't issue a warning */ - Configuration::Block *options = Config->GetBlock("options"); - if (options->Get("user").empty()) + Configuration::Block *options = Config ? Config->GetBlock("options") : NULL; + if (!options || options->Get("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; -- cgit From 41206b991e5aa7821acd424df2ec6800d868df1c Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Thu, 11 May 2023 13:05:39 +0100 Subject: Fix not being able to log into oper accounts when DNS fails. --- src/users.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/users.cpp b/src/users.cpp index 96a3539de..09529bb5f 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -462,9 +462,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; } -- cgit From 0646547c9eecc464dfc3c6fb0c7dfa9a3298a268 Mon Sep 17 00:00:00 2001 From: Adam Date: Sun, 28 May 2023 20:40:00 -0400 Subject: config: remove dependency on no-delete-null-pointer-checks --- src/config.cpp | 71 +++++++++++++++++++++++++++++----------------------------- src/init.cpp | 28 +++++++++++------------ 2 files changed, 49 insertions(+), 50 deletions(-) (limited to 'src') 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 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 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::const_iterator it = items.find(tag); if (it != items.end()) return it->second; @@ -116,7 +115,7 @@ template 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("type"), &file = include->Get("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("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("host"); bool ipv6 = uplink->Get("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("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("name"), &modes = opertype->Get("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("name"), &type = oper->Get("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("nick"), &user = service->Get("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("logage"); bool rawio = log->Get("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("service"), &nname = command->Get("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("name"), &desc = privilege->Get("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("name"), &service = fantasy->Get("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("name"), &description = command_group->Get("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("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("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("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("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(); -- cgit From 66f37139cba97f2bb2a490376ffc33f153900b6c Mon Sep 17 00:00:00 2001 From: Adam Date: Sun, 28 May 2023 21:25:02 -0400 Subject: regchannels: remove dependency on no-delete-null-pointer-checks --- src/channels.cpp | 23 ++++++++++++++++++++--- src/logger.cpp | 2 +- src/modes.cpp | 2 +- src/regchannel.cpp | 5 ++--- src/servers.cpp | 4 ++-- 5 files changed, 26 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/channels.cpp b/src/channels.cpp index 6fcd62b67..8a1f89081 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()) + if (mask.empty() && this->ci) mask = this->ci->GetIdealBan(user); + if (mask.empty()) + 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/logger.cpp b/src/logger.cpp index 244cacdba..acacda286 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -369,7 +369,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 c5675b119..5f950df57 100644 --- a/src/modes.cpp +++ b/src/modes.cpp @@ -617,7 +617,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/regchannel.cpp b/src/regchannel.cpp index d420ab0df..984da55ab 100644 --- a/src/regchannel.cpp +++ b/src/regchannel.cpp @@ -355,7 +355,7 @@ NickCore *ChannelInfo::GetSuccessor() const BotInfo *ChannelInfo::WhoSends() const { - if (this && this->bi) + if (this->bi) return this->bi; BotInfo *ChanServ = Config->GetClient("ChanServ"); @@ -629,8 +629,7 @@ void ChannelInfo::ClearLevels() Anope::string ChannelInfo::GetIdealBan(User *u) const { - int bt = this ? this->bantype : -1; - switch (bt) + switch (this->bantype) { case 0: return "*!" + u->GetVIdent() + "@" + u->GetDisplayedHost(); diff --git a/src/servers.cpp b/src/servers.cpp index 54dd853b5..23ea18139 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; } -- cgit From 03eead042cbab9c75e9d06ea2f437efcfb835e07 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Thu, 1 Jun 2023 23:07:41 +0100 Subject: Release 2.0.13. --- src/version.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/version.sh b/src/version.sh index be6b9e5b4..e78229f19 100644 --- a/src/version.sh +++ b/src/version.sh @@ -3,4 +3,4 @@ VERSION_MAJOR=2 VERSION_MINOR=0 VERSION_PATCH=13 -VERSION_EXTRA="-git" +VERSION_EXTRA="" -- cgit From fe3926f572dc25557be0119b6c35da752365bf48 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Thu, 1 Jun 2023 23:10:11 +0100 Subject: Mark as 2.0.14-git. --- src/version.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/version.sh b/src/version.sh index e78229f19..c03b1e511 100644 --- a/src/version.sh +++ b/src/version.sh @@ -2,5 +2,5 @@ VERSION_MAJOR=2 VERSION_MINOR=0 -VERSION_PATCH=13 -VERSION_EXTRA="" +VERSION_PATCH=14 +VERSION_EXTRA="-git" -- cgit From 07babdbd77f1978f8386791272b309949e56a09b Mon Sep 17 00:00:00 2001 From: Adam Date: Fri, 2 Jun 2023 18:20:19 -0400 Subject: use Conan for extra's dependencies on Windows conan install src\win32\conanfile.txt --build=missing cmake -B build . cmake --build build --config Release --target PACKAGE --- src/win32/conanfile.txt | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/win32/conanfile.txt (limited to 'src') diff --git a/src/win32/conanfile.txt b/src/win32/conanfile.txt new file mode 100644 index 000000000..38b392415 --- /dev/null +++ b/src/win32/conanfile.txt @@ -0,0 +1,18 @@ +[requires] +libmysqlclient/8.0.31 +openssl/1.1.1t +pcre2/10.42 +sqlite3/3.41.1 + +[options] +libmysqlclient/*:shared=True +openssl/*:shared=True +pcre2/*:shared=True +sqlite3/*:shared=True + +[imports] +., *.dll -> extradll +., *.lib -> extralib + +[generators] +cmake \ No newline at end of file -- cgit From fbf3b344740f6bd4f9337e485e35e9e8103428bc Mon Sep 17 00:00:00 2001 From: Adam Date: Fri, 2 Jun 2023 23:01:27 -0400 Subject: add gettext to conan deps --- src/win32/conanfile.txt | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src') diff --git a/src/win32/conanfile.txt b/src/win32/conanfile.txt index 38b392415..c2b0f325d 100644 --- a/src/win32/conanfile.txt +++ b/src/win32/conanfile.txt @@ -3,12 +3,15 @@ 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 -- cgit