diff options
| author | Adam <Adam@anope.org> | 2015-01-05 16:31:09 -0500 |
|---|---|---|
| committer | Adam <Adam@anope.org> | 2015-01-05 19:00:51 -0500 |
| commit | d79d8e2608e304760c42bdf87502e3bc51781b88 (patch) | |
| tree | 179913b8b328f88d52d84c3453fceb28a2d63422 /modules/m_dnsbl.cpp | |
| parent | 8ab1c71d7dc7a0d47e5711dc72e3fc9c3ee850bb (diff) | |
| parent | c46ec39e5088119cd21f5f7e16e64e61a876ca20 (diff) | |
Merge branch '2.0' into 2.1
Conflicts:
CMakeLists.txt
include/modules.h
include/serialize.h
modules/commands/bs_assign.cpp
modules/commands/bs_badwords.cpp
modules/commands/bs_bot.cpp
modules/commands/bs_control.cpp
modules/commands/bs_kick.cpp
modules/commands/cs_access.cpp
modules/commands/cs_akick.cpp
modules/commands/cs_drop.cpp
modules/commands/cs_entrymsg.cpp
modules/commands/cs_flags.cpp
modules/commands/cs_info.cpp
modules/commands/cs_invite.cpp
modules/commands/cs_kick.cpp
modules/commands/cs_mode.cpp
modules/commands/cs_register.cpp
modules/commands/cs_seen.cpp
modules/commands/cs_set.cpp
modules/commands/cs_suspend.cpp
modules/commands/cs_topic.cpp
modules/commands/cs_unban.cpp
modules/commands/cs_xop.cpp
modules/commands/hs_del.cpp
modules/commands/hs_list.cpp
modules/commands/hs_request.cpp
modules/commands/ms_ignore.cpp
modules/commands/ms_send.cpp
modules/commands/ns_recover.cpp
modules/commands/ns_register.cpp
modules/commands/ns_suspend.cpp
modules/commands/os_dns.cpp
modules/commands/os_noop.cpp
modules/commands/os_oper.cpp
modules/commands/os_session.cpp
modules/database/db_sql_live.cpp
modules/encryption/enc_bcrypt.cpp
modules/extra/m_ldap_authentication.cpp
modules/extra/m_ldap_oper.cpp
modules/fantasy.cpp
modules/m_dnsbl.cpp
modules/m_sasl.cpp
modules/protocol/hybrid.cpp
modules/protocol/inspircd20.cpp
modules/protocol/unreal.cpp
modules/pseudoclients/chanserv.cpp
modules/pseudoclients/nickserv.cpp
modules/webcpanel/pages/chanserv/access.cpp
modules/webcpanel/webcpanel.cpp
modules/webcpanel/webcpanel.h
src/command.cpp
src/messages.cpp
src/modulemanager.cpp
src/regchannel.cpp
src/serialize.cpp
Diffstat (limited to 'modules/m_dnsbl.cpp')
| -rw-r--r-- | modules/m_dnsbl.cpp | 78 |
1 files changed, 54 insertions, 24 deletions
diff --git a/modules/m_dnsbl.cpp b/modules/m_dnsbl.cpp index 80656959a..49739a80c 100644 --- a/modules/m_dnsbl.cpp +++ b/modules/m_dnsbl.cpp @@ -14,12 +14,29 @@ static ServiceReference<XLineManager> akills("XLineManager", "xlinemanager/sglin struct Blacklist { + struct Reply + { + int code; + Anope::string reason; + bool allow_account; + + Reply() : code(0), allow_account(false) { } + }; + Anope::string name; time_t bantime; Anope::string reason; - std::map<int, Anope::string> replies; + std::vector<Reply> replies; - Blacklist(const Anope::string &n, time_t b, const Anope::string &r, const std::map<int, Anope::string> &re) : name(n), bantime(b), reason(r), replies(re) { } + Blacklist() : bantime(0) { } + + Reply *Find(int code) + { + for (unsigned int i = 0; i < replies.size(); ++i) + if (replies[i].code == code) + return &replies[i]; + return NULL; + } }; class DNSBLResolver : public Request @@ -41,17 +58,16 @@ class DNSBLResolver : public Request if (ans_record.rdata.find("127.0.0.") != 0) return; - Anope::string record_reason; - if (!this->blacklist.replies.empty()) - { - sockaddrs sresult; - sresult.pton(AF_INET, ans_record.rdata); - int result = sresult.sa4.sin_addr.s_addr >> 24; + sockaddrs sresult; + sresult.pton(AF_INET, ans_record.rdata); + int result = sresult.sa4.sin_addr.s_addr >> 24; - if (!this->blacklist.replies.count(result)) - return; - record_reason = this->blacklist.replies[result]; - } + Blacklist::Reply *reply = blacklist.Find(result); + if (!blacklist.replies.empty() && !reply) + return; + + if (reply && reply->allow_account && user->Account()) + return; Anope::string reason = this->blacklist.reason, addr = user->ip.addr(); reason = reason.replace_all_cs("%n", user->nick); @@ -59,7 +75,7 @@ class DNSBLResolver : public Request reason = reason.replace_all_cs("%g", user->realname); reason = reason.replace_all_cs("%h", user->host); reason = reason.replace_all_cs("%i", addr); - reason = reason.replace_all_cs("%r", record_reason); + reason = reason.replace_all_cs("%r", reply ? reply->reason : ""); reason = reason.replace_all_cs("%N", Config->GetBlock("networkinfo")->Get<Anope::string>("networkname")); ServiceBot *OperServ = Config->GetClient("OperServ"); @@ -90,6 +106,7 @@ class ModuleDNSBL : public Module , public EventHook<Event::UserConnect> { std::vector<Blacklist> blacklists; + std::set<Anope::string> exempts; bool check_on_connect; bool check_on_netburst; bool add_to_akill; @@ -108,25 +125,35 @@ class ModuleDNSBL : public Module this->add_to_akill = block->Get<bool>("add_to_akill", "yes"); this->blacklists.clear(); - for (int i = 0, num = block->CountBlock("blacklist"); i < num; ++i) + for (int i = 0; i < block->CountBlock("blacklist"); ++i) { Configuration::Block *bl = block->GetBlock("blacklist", i); + Blacklist blacklist; - Anope::string bname = bl->Get<Anope::string>("name"); - if (bname.empty()) + blacklist.name = bl->Get<Anope::string>("name"); + if (blacklist.name.empty()) continue; - time_t bantime = bl->Get<time_t>("time", "4h"); - Anope::string reason = bl->Get<Anope::string>("reason"); - std::map<int, Anope::string> replies; - for (int j = 0; j < 256; ++j) + blacklist.bantime = bl->Get<time_t>("time", "4h"); + blacklist.reason = bl->Get<Anope::string>("reason"); + + for (int j = 0; j < bl->CountBlock("reply"); ++j) { - Anope::string k = bl->Get<Anope::string>(stringify(j)); - if (!k.empty()) - replies[j] = k; + Configuration::Block *reply = bl->GetBlock("reply", j); + Blacklist::Reply r; + + r.code = reply->Get<int>("code"); + r.reason = reply->Get<Anope::string>("reason"); + r.allow_account = reply->Get<bool>("allow_account"); + + blacklist.replies.push_back(r); } - this->blacklists.push_back(Blacklist(bname, bantime, reason, replies)); + this->blacklists.push_back(blacklist); } + + this->exempts.clear(); + for (int i = 0; i < block->CountBlock("exempt"); ++i) + this->exempts.insert(block->Get<Anope::string>("ip")); } void OnUserConnect(User *user, bool &exempt) override @@ -142,6 +169,9 @@ class ModuleDNSBL : public Module /* User doesn't have a valid IPv4 IP (ipv6/spoof/etc) */ return; + if (this->exempts.count(user->ip.addr())) + return; + const unsigned long &ip = user->ip.sa4.sin_addr.s_addr; unsigned long reverse_ip = (ip << 24) | ((ip & 0xFF00) << 8) | ((ip & 0xFF0000) >> 8) | (ip >> 24); |
