X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_dnsbl.cpp;h=8429eb21b1eea19d67ae7f4cf108193bcd91d4b4;hb=551d687ec6d7ce44be35fae0dd7345fe73c4f63a;hp=c6a9e1fb0dc47e0f035c2c760e80a9a5a27c394a;hpb=e496d321efe3e9b27f2f116bd22a05ec44aec564;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_dnsbl.cpp b/src/modules/m_dnsbl.cpp index c6a9e1fb0..8429eb21b 100644 --- a/src/modules/m_dnsbl.cpp +++ b/src/modules/m_dnsbl.cpp @@ -40,7 +40,6 @@ class DNSBLConfEntry unsigned char records[256]; unsigned long stats_hits, stats_misses; DNSBLConfEntry(): type(A_BITMASK),duration(86400),bitmask(0),stats_hits(0), stats_misses(0) {} - ~DNSBLConfEntry() { } }; @@ -137,7 +136,7 @@ class DNSBLResolver : public Resolver { std::string timestr = ServerInstance->TimeString(kl->expiry); ServerInstance->SNO->WriteGlobalSno('x',"K:line added due to DNSBL match on *@%s to expire on %s: %s", - them->GetIPString(), timestr.c_str(), reason.c_str()); + them->GetIPString().c_str(), timestr.c_str(), reason.c_str()); ServerInstance->XLines->ApplyLines(); } else @@ -152,7 +151,7 @@ class DNSBLResolver : public Resolver { std::string timestr = ServerInstance->TimeString(gl->expiry); ServerInstance->SNO->WriteGlobalSno('x',"G:line added due to DNSBL match on *@%s to expire on %s: %s", - them->GetIPString(), timestr.c_str(), reason.c_str()); + them->GetIPString().c_str(), timestr.c_str(), reason.c_str()); ServerInstance->XLines->ApplyLines(); } else @@ -167,7 +166,7 @@ class DNSBLResolver : public Resolver { std::string timestr = ServerInstance->TimeString(zl->expiry); ServerInstance->SNO->WriteGlobalSno('x',"Z:line added due to DNSBL match on *@%s to expire on %s: %s", - them->GetIPString(), timestr.c_str(), reason.c_str()); + them->GetIPString().c_str(), timestr.c_str(), reason.c_str()); ServerInstance->XLines->ApplyLines(); } else @@ -201,10 +200,6 @@ class DNSBLResolver : public Resolver countExt.set(them, i - 1); } } - - virtual ~DNSBLResolver() - { - } }; class ModuleDNSBL : public Module @@ -240,7 +235,7 @@ class ModuleDNSBL : public Module ServerInstance->Modules->AddService(nameExt); ServerInstance->Modules->AddService(countExt); Implementation eventlist[] = { I_OnRehash, I_OnSetUserIP, I_OnStats, I_OnSetConnectClass, I_OnCheckReady }; - ServerInstance->Modules->Attach(eventlist, this, 5); + ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation)); } virtual ~ModuleDNSBL() @@ -296,7 +291,7 @@ class ModuleDNSBL : public Module } e->banaction = str2banaction(tag->getString("action")); - e->duration = ServerInstance->Duration(tag->getString("duration", "60")); + e->duration = InspIRCd::Duration(tag->getString("duration", "60")); /* Use portparser for record replies */ @@ -352,16 +347,21 @@ class ModuleDNSBL : public Module void OnSetUserIP(LocalUser* user) { - if (user->exempt) + if ((user->exempt) || (user->client_sa.sa.sa_family != AF_INET)) return; + if (user->MyClass) + { + if (!user->MyClass->config->getBool("usednsbl", true)) + return; + } + else + ServerInstance->Logs->Log("m_dnsbl", LOG_DEBUG, "User has no connect class in OnSetUserIP"); + unsigned char a, b, c, d; char reversedipbuf[128]; std::string reversedip; - if (user->client_sa.sa.sa_family != AF_INET) - return; - d = (unsigned char) (user->client_sa.in4.sin_addr.s_addr >> 24) & 0xFF; c = (unsigned char) (user->client_sa.in4.sin_addr.s_addr >> 16) & 0xFF; b = (unsigned char) (user->client_sa.in4.sin_addr.s_addr >> 8) & 0xFF; @@ -370,6 +370,8 @@ class ModuleDNSBL : public Module snprintf(reversedipbuf, 128, "%d.%d.%d.%d", d, c, b, a); reversedip = std::string(reversedipbuf); + countExt.set(user, DNSBLConfEntries.size()); + // For each DNSBL, we will run through this lookup unsigned int i = 0; while (i < DNSBLConfEntries.size()) @@ -381,9 +383,10 @@ class ModuleDNSBL : public Module bool cached; DNSBLResolver *r = new DNSBLResolver(this, nameExt, countExt, hostname, user, DNSBLConfEntries[i], cached); ServerInstance->AddResolver(r, cached); + if (user->quitting) + break; i++; } - countExt.set(user, i); } ModResult OnSetConnectClass(LocalUser* user, ConnectClass* myclass) @@ -397,7 +400,7 @@ class ModuleDNSBL : public Module return MOD_RES_PASSTHRU; return MOD_RES_DENY; } - + ModResult OnCheckReady(LocalUser *user) { if (countExt.get(user)) @@ -417,12 +420,12 @@ class ModuleDNSBL : public Module total_hits += (*i)->stats_hits; total_misses += (*i)->stats_misses; - results.push_back(std::string(ServerInstance->Config->ServerName.c_str()) + " 304 " + user->nick + " :DNSBLSTATS DNSbl \"" + (*i)->name + "\" had " + + results.push_back(ServerInstance->Config->ServerName + " 304 " + user->nick + " :DNSBLSTATS DNSbl \"" + (*i)->name + "\" had " + ConvToStr((*i)->stats_hits) + " hits and " + ConvToStr((*i)->stats_misses) + " misses"); } - results.push_back(std::string(ServerInstance->Config->ServerName.c_str()) + " 304 " + user->nick + " :DNSBLSTATS Total hits: " + ConvToStr(total_hits)); - results.push_back(std::string(ServerInstance->Config->ServerName.c_str()) + " 304 " + user->nick + " :DNSBLSTATS Total misses: " + ConvToStr(total_misses)); + results.push_back(ServerInstance->Config->ServerName + " 304 " + user->nick + " :DNSBLSTATS Total hits: " + ConvToStr(total_hits)); + results.push_back(ServerInstance->Config->ServerName + " 304 " + user->nick + " :DNSBLSTATS Total misses: " + ConvToStr(total_misses)); return MOD_RES_PASSTHRU; }