diff options
author | Adam <Adam@anope.org> | 2013-05-08 09:50:43 -0400 |
---|---|---|
committer | Adam <Adam@anope.org> | 2013-05-08 09:50:43 -0400 |
commit | 9b07e163c0e1ceed30e72aead2338b47ef2da1b2 (patch) | |
tree | 4c13bd545846700a58c5526c3e4e9a6fdf0afc87 /src/users.cpp | |
parent | 6859decfb8ed0430e946ff81eca4f9da879f69c9 (diff) |
Make sockaddrs/cidr not throw on invalid ips to give us an easier/cheaper way to test for a valid IP
Diffstat (limited to 'src/users.cpp')
-rw-r--r-- | src/users.cpp | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/src/users.cpp b/src/users.cpp index 58f586e27..bd376f6a1 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -22,6 +22,7 @@ #include "config.h" #include "opertype.h" #include "language.h" +#include "sockets.h" user_map UserListByNick, UserListByUID; @@ -753,24 +754,24 @@ bool User::Quitting() const Anope::string User::Mask() const { Anope::string mask; - Anope::string mident = this->GetIdent(); - Anope::string mhost = this->GetDisplayedHost(); + const Anope::string &mident = this->GetIdent(); + const Anope::string &mhost = this->GetDisplayedHost(); if (mident[0] == '~') mask = "*" + mident + "@"; else mask = mident + "@"; - size_t dot; - /* To make sure this is an IP, make sure the host contains only numbers and dots, and check to make sure it only contains 3 dots */ - if (mhost.find_first_not_of("0123456789.") == Anope::string::npos && (dot = mhost.find('.')) != Anope::string::npos && (dot = mhost.find('.', dot + 1)) != Anope::string::npos && (dot = mhost.find('.', dot + 1)) != Anope::string::npos && mhost.find('.', dot + 1) == Anope::string::npos) - { /* IP addr */ - dot = mhost.find('.'); - mask += mhost.substr(0, dot) + ".*"; + sockaddrs addr(mhost); + if (addr.valid() && addr.sa.sa_family == AF_INET) + { + size_t dot = mhost.find('.'); + mask += mhost.substr(0, dot) + (dot == Anope::string::npos ? "" : ".*"); } else { - if ((dot = mhost.find('.')) != Anope::string::npos && mhost.find('.', dot + 1) != Anope::string::npos) + size_t dot = mhost.find('.'); + if (dot != Anope::string::npos && mhost.find('.', dot + 1) != Anope::string::npos) mask += "*" + mhost.substr(dot); else mask += mhost; |