From e34f345e3bf02aa0f3ac8665bf190ed77033a703 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Mon, 20 Dec 2021 15:02:26 +0000 Subject: Deduplicate xline adding code in the dnsbl module. --- src/modules/m_dnsbl.cpp | 62 ++++++++++++++++--------------------------------- 1 file changed, 20 insertions(+), 42 deletions(-) (limited to 'src/modules') diff --git a/src/modules/m_dnsbl.cpp b/src/modules/m_dnsbl.cpp index eb5eec78c..b596b89c1 100644 --- a/src/modules/m_dnsbl.cpp +++ b/src/modules/m_dnsbl.cpp @@ -166,6 +166,23 @@ class DNSBLResolver final IntExtItem& countExt; std::shared_ptr ConfEntry; + + template + void AddLine(const char* type, const std::string& reason, unsigned long duration, Extra&&... extra) + { + auto line = new Line(ServerInstance->Time(), duration, ServerInstance->Config->ServerName, reason, std::forward(extra)...); + if (ServerInstance->XLines->AddLine(line, nullptr)) + { + delete line; + return; + } + + ServerInstance->SNO.WriteToSnoMask('x', "%s added due to DNSBL match on %s to expire in %s (on %s): %s", + type, line->Displayable().c_str(), InspIRCd::DurationString(line->duration).c_str(), + InspIRCd::TimeString(line->expiry).c_str(), reason.c_str()); + ServerInstance->XLines->ApplyLines(); + } + public: DNSBLResolver(DNS::Manager *mgr, Module *me, StringExtItem& match, IntExtItem& ctr, const std::string &hostname, LocalUser* u, std::shared_ptr conf) : DNS::Request(mgr, me, hostname, DNS::QUERY_A, true, conf->timeout) @@ -278,56 +295,17 @@ class DNSBLResolver final } case DNSBLEntry::Action::KLINE: { - KLine* kl = new KLine(ServerInstance->Time(), ConfEntry->xlineduration, ServerInstance->Config->ServerName.c_str(), reason.c_str(), - them->GetBanIdent(), them->GetIPString()); - if (ServerInstance->XLines->AddLine(kl,NULL)) - { - ServerInstance->SNO.WriteToSnoMask('x', "K-line added due to DNSBL match on %s to expire in %s (on %s): %s", - kl->Displayable().c_str(), InspIRCd::DurationString(kl->duration).c_str(), - InspIRCd::TimeString(kl->expiry).c_str(), reason.c_str()); - ServerInstance->XLines->ApplyLines(); - } - else - { - delete kl; - return; - } + AddLine("K-line", reason, ConfEntry->xlineduration, them->GetBanIdent(), them->GetIPString()); break; } case DNSBLEntry::Action::GLINE: { - GLine* gl = new GLine(ServerInstance->Time(), ConfEntry->xlineduration, ServerInstance->Config->ServerName.c_str(), reason.c_str(), - them->GetBanIdent(), them->GetIPString()); - if (ServerInstance->XLines->AddLine(gl,NULL)) - { - ServerInstance->SNO.WriteToSnoMask('x', "G-line added due to DNSBL match on %s to expire in %s (on %s): %s", - gl->Displayable().c_str(), InspIRCd::DurationString(gl->duration).c_str(), - InspIRCd::TimeString(gl->expiry).c_str(), reason.c_str()); - ServerInstance->XLines->ApplyLines(); - } - else - { - delete gl; - return; - } + AddLine("G-line", reason, ConfEntry->xlineduration, them->GetBanIdent(), them->GetIPString()); break; } case DNSBLEntry::Action::ZLINE: { - ZLine* zl = new ZLine(ServerInstance->Time(), ConfEntry->xlineduration, ServerInstance->Config->ServerName.c_str(), reason.c_str(), - them->GetIPString()); - if (ServerInstance->XLines->AddLine(zl,NULL)) - { - ServerInstance->SNO.WriteToSnoMask('x', "Z-line added due to DNSBL match on %s to expire in %s (on %s): %s", - them->GetIPString().c_str(), InspIRCd::DurationString(zl->duration).c_str(), - InspIRCd::TimeString(zl->expiry).c_str(), reason.c_str()); - ServerInstance->XLines->ApplyLines(); - } - else - { - delete zl; - return; - } + AddLine("Z-line", reason, ConfEntry->xlineduration, them->GetIPString()); break; } } -- cgit v1.3.1-10-gc9f91