From: Peter Powell Date: Fri, 21 Sep 2018 19:54:05 +0000 (+0100) Subject: Don't sync xlines defined in the config and expire them on rehash. X-Git-Url: https://git.netwichtig.de/gitweb/?a=commitdiff_plain;h=876b1ae4e280e99f24d37da4b819f108ddb3f1e3;p=user%2Fhenk%2Fcode%2Finspircd.git Don't sync xlines defined in the config and expire them on rehash. Closes #1427. --- diff --git a/include/xline.h b/include/xline.h index 9aae32b24..7c102c882 100644 --- a/include/xline.h +++ b/include/xline.h @@ -50,7 +50,12 @@ class CoreExport XLine : public classbase * @param t The line type, should be set by the derived class constructor */ XLine(time_t s_time, long d, std::string src, std::string re, const std::string &t) - : set_time(s_time), duration(d), source(src), reason(re), type(t) + : set_time(s_time) + , duration(d) + , source(src) + , reason(re) + , type(t) + , from_config(false) { expiry = set_time + duration; } @@ -140,6 +145,9 @@ class CoreExport XLine : public classbase */ const std::string type; + // Whether this XLine was loaded from the server config. + bool from_config; + virtual bool IsBurstable(); }; @@ -523,4 +531,7 @@ class CoreExport XLineManager * @param stats Stats context */ void InvokeStats(const std::string& type, unsigned int numeric, Stats::Context& stats); + + /** Clears any XLines which were added by the server configuration. */ + void ClearConfigLines(); }; diff --git a/src/configreader.cpp b/src/configreader.cpp index 6c7cb492a..a8e94586d 100644 --- a/src/configreader.cpp +++ b/src/configreader.cpp @@ -108,6 +108,7 @@ static void ReadXLine(ServerConfig* conf, const std::string& tag, const std::str throw CoreException("<"+tag+":"+key+"> missing at " + ctag->getTagLocation()); std::string reason = ctag->getString("reason", ""); XLine* xl = make->Generate(ServerInstance->Time(), 0, "", reason, mask); + xl->from_config = true; if (!ServerInstance->XLines->AddLine(xl, NULL)) delete xl; } @@ -446,6 +447,7 @@ void ServerConfig::Fill() SocketEngine::Close(socktest); } + ServerInstance->XLines->ClearConfigLines(); ReadXLine(this, "badip", "ipmask", ServerInstance->XLines->GetFactory("Z")); ReadXLine(this, "badnick", "nick", ServerInstance->XLines->GetFactory("Q")); ReadXLine(this, "badhost", "host", ServerInstance->XLines->GetFactory("K")); diff --git a/src/xline.cpp b/src/xline.cpp index cb4f011c0..d07fe0dc5 100644 --- a/src/xline.cpp +++ b/src/xline.cpp @@ -518,7 +518,7 @@ void XLine::Apply(User* u) bool XLine::IsBurstable() { - return true; + return !from_config; } void XLine::DefaultApply(User* u, const std::string &line, bool bancache) @@ -747,3 +747,24 @@ XLineFactory* XLineManager::GetFactory(const std::string &type) return n->second; } + +void XLineManager::ClearConfigLines() +{ + // Nothing to do. + if (lookup_lines.empty()) + return; + + ServerInstance->SNO->WriteToSnoMask('x', "Server rehashing; expiring lines defined in the server config ..."); + for (ContainerIter type = lookup_lines.begin(); type != lookup_lines.end(); ++type) + { + for (LookupIter xline = type->second.begin(); xline != type->second.end(); ) + { + // We cache this to avoid iterator invalidation. + LookupIter cachedxline = xline++; + if (cachedxline->second->from_config) + { + ExpireLine(type, cachedxline); + } + } + } +}