From 000660608eaa3be3f55333ee0c1080c72461f533 Mon Sep 17 00:00:00 2001 From: Adam Date: Tue, 21 Feb 2012 20:50:14 -0500 Subject: Fixed m_dnsbl handling users with spoofs/other non ips --- modules/extra/m_dnsbl.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'modules/extra') diff --git a/modules/extra/m_dnsbl.cpp b/modules/extra/m_dnsbl.cpp index 71011760e..d4c49501c 100644 --- a/modules/extra/m_dnsbl.cpp +++ b/modules/extra/m_dnsbl.cpp @@ -135,9 +135,16 @@ class ModuleDNSBL : public Module return; /* At this time we only support IPv4 */ - sockaddrs user_ip(user->ip); - if (user_ip.sa.sa_family != AF_INET) + sockaddrs user_ip; + try + { + user_ip.pton(AF_INET, user->ip); + } + catch (const SocketException &) + { + /* User doesn't have a valid IPv4 IP (ipv6/spoof/etc) */ 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); -- cgit From bd31fbb9f0bd0ff282c6413928e61b819f0ee474 Mon Sep 17 00:00:00 2001 From: Adam Date: Wed, 22 Feb 2012 14:41:36 -0500 Subject: Also fixed m_proxyscan to handle users with invalid ips --- modules/extra/m_proxyscan.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'modules/extra') diff --git a/modules/extra/m_proxyscan.cpp b/modules/extra/m_proxyscan.cpp index ea35e8f77..badc293fc 100644 --- a/modules/extra/m_proxyscan.cpp +++ b/modules/extra/m_proxyscan.cpp @@ -346,10 +346,17 @@ class ModuleProxyScan : public Module if (exempt || !user || !Me->IsSynced() || !user->server->IsSynced()) return; - sockaddrs user_ip(user->ip); /* At this time we only support IPv4 */ - if (user_ip.sa.sa_family != AF_INET) + sockaddrs user_ip; + try + { + user_ip.pton(AF_INET, user->ip); + } + catch (const SocketException &) + { + /* User doesn't have a valid IPv4 IP (ipv6/spoof/etc) */ return; + } if (!this->con_notice.empty() && !this->con_source.empty()) { -- cgit From 3850b073ddf610415de54dced9ff134397779676 Mon Sep 17 00:00:00 2001 From: Adam Date: Wed, 22 Feb 2012 18:12:02 -0500 Subject: Added regex support for many commands, such as akill, sqline, snline, all of the */list commands, etc. Also extended the ability of akill to match a full nick!user@host and real name of users. --- modules/extra/m_regex_pcre.cpp | 55 ++++++++++++++++++++++++++++++++++++++ modules/extra/m_regex_posix.cpp | 57 ++++++++++++++++++++++++++++++++++++++++ modules/extra/m_regex_tre.cpp | 58 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 170 insertions(+) create mode 100644 modules/extra/m_regex_pcre.cpp create mode 100644 modules/extra/m_regex_posix.cpp create mode 100644 modules/extra/m_regex_tre.cpp (limited to 'modules/extra') diff --git a/modules/extra/m_regex_pcre.cpp b/modules/extra/m_regex_pcre.cpp new file mode 100644 index 000000000..998a7692d --- /dev/null +++ b/modules/extra/m_regex_pcre.cpp @@ -0,0 +1,55 @@ +/* RequiredLibraries: pcre */ + +#include "module.h" +#include + +class PCRERegex : public Regex +{ + pcre *regex; + + public: + PCRERegex(const Anope::string &expr) : Regex(expr) + { + const char *error; + int erroffset; + this->regex = pcre_compile(expr.c_str(), PCRE_CASELESS, &error, &erroffset, NULL); + if (!this->regex) + throw RegexException("Error in regex " + expr + " at offset " + stringify(erroffset) + ": " + error); + } + + ~PCRERegex() + { + pcre_free(this->regex); + } + + bool Matches(const Anope::string &str) + { + return pcre_exec(this->regex, NULL, str.c_str(), str.length(), 0, 0, NULL, 0) > -1; + } +}; + +class PCRERegexProvider : public RegexProvider +{ + public: + PCRERegexProvider(Module *creator) : RegexProvider(creator, "regex/pcre") { } + + Regex *Compile(const Anope::string &expression) anope_override + { + return new PCRERegex(expression); + } +}; + +class ModuleRegexPCRE : public Module +{ + PCRERegexProvider pcre_regex_provider; + + public: + ModuleRegexPCRE(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, SUPPORTED), + pcre_regex_provider(this) + { + this->SetAuthor("Anope"); + this->SetPermanent(true); + } +}; + +MODULE_INIT(ModuleRegexPCRE) diff --git a/modules/extra/m_regex_posix.cpp b/modules/extra/m_regex_posix.cpp new file mode 100644 index 000000000..409a057ba --- /dev/null +++ b/modules/extra/m_regex_posix.cpp @@ -0,0 +1,57 @@ +#include "module.h" +#include +#include + +class POSIXRegex : public Regex +{ + regex_t regbuf; + + public: + POSIXRegex(const Anope::string &expr) : Regex(expr) + { + int err = regcomp(&this->regbuf, expr.c_str(), REG_EXTENDED | REG_NOSUB); + if (err) + { + char buf[BUFSIZE]; + regerror(err, &this->regbuf, buf, sizeof(buf)); + regfree(&this->regbuf); + throw RegexException("Error in regex " + expr + ": " + buf); + } + } + + ~POSIXRegex() + { + regfree(&this->regbuf); + } + + bool Matches(const Anope::string &str) + { + return regexec(&this->regbuf, str.c_str(), 0, NULL, 0) == 0; + } +}; + +class POSIXRegexProvider : public RegexProvider +{ + public: + POSIXRegexProvider(Module *creator) : RegexProvider(creator, "regex/posix") { } + + Regex *Compile(const Anope::string &expression) anope_override + { + return new POSIXRegex(expression); + } +}; + +class ModuleRegexPOSIX : public Module +{ + POSIXRegexProvider posix_regex_provider; + + public: + ModuleRegexPOSIX(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, SUPPORTED), + posix_regex_provider(this) + { + this->SetAuthor("Anope"); + this->SetPermanent(true); + } +}; + +MODULE_INIT(ModuleRegexPOSIX) diff --git a/modules/extra/m_regex_tre.cpp b/modules/extra/m_regex_tre.cpp new file mode 100644 index 000000000..8cfbd3b18 --- /dev/null +++ b/modules/extra/m_regex_tre.cpp @@ -0,0 +1,58 @@ +/* RequiredLibraries: tre */ + +#include "module.h" +#include + +class TRERegex : public Regex +{ + regex_t regbuf; + + public: + TRERegex(const Anope::string &expr) : Regex(expr) + { + int err = regcomp(&this->regbuf, expr.c_str(), REG_EXTENDED | REG_NOSUB); + if (err) + { + char buf[BUFSIZE]; + regerror(err, &this->regbuf, buf, sizeof(buf)); + regfree(&this->regbuf); + throw RegexException("Error in regex " + expr + ": " + buf); + } + } + + ~TRERegex() + { + regfree(&this->regbuf); + } + + bool Matches(const Anope::string &str) + { + return regexec(&this->regbuf, str.c_str(), 0, NULL, 0) == 0; + } +}; + +class TRERegexProvider : public RegexProvider +{ + public: + TRERegexProvider(Module *creator) : RegexProvider(creator, "regex/tre") { } + + Regex *Compile(const Anope::string &expression) anope_override + { + return new TRERegex(expression); + } +}; + +class ModuleRegexTRE : public Module +{ + TRERegexProvider tre_regex_provider; + + public: + ModuleRegexTRE(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, SUPPORTED), + tre_regex_provider(this) + { + this->SetAuthor("Anope"); + this->SetPermanent(true); + } +}; + +MODULE_INIT(ModuleRegexTRE) -- cgit