diff options
author | Adam <Adam@anope.org> | 2011-08-25 00:36:04 -0400 |
---|---|---|
committer | Adam <Adam@anope.org> | 2011-09-10 01:58:38 -0400 |
commit | d4db2b84f250b98ec3422f2be9951f567e6dc97e (patch) | |
tree | 3c119be0fa5a5f166664858a0cea0c9344e1db7e /src/misc.cpp | |
parent | bb8e04c83588b6d0595eca463170643a3bd84285 (diff) |
Made the IsValidHost checks configurable
Diffstat (limited to 'src/misc.cpp')
-rw-r--r-- | src/misc.cpp | 125 |
1 files changed, 31 insertions, 94 deletions
diff --git a/src/misc.cpp b/src/misc.cpp index 4c1d03af2..5e41d42b7 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -296,113 +296,50 @@ Anope::string expire_left(NickCore *nc, time_t expires) /*************************************************************************/ -/** - * Validate the host - * shortname = ( letter / digit ) *( letter / digit / "-" ) *( letter / digit ) - * hostname = shortname *( "." shortname ) - * ip4addr = 1*3digit "." 1*3digit "." 1*3digit "." 1*3digit - * @param host = string to check - * @param type = format, 1 = ip4addr, 2 = hostname - * @return 1 if a host is valid, 0 if it isnt. +/** Checks if a username is valid + * @param ident The username + * @return true if the ident is valid */ -bool doValidHost(const Anope::string &host, int type) +bool IsValidIdent(const Anope::string &ident) { - if (type != 1 && type != 2) - return false; - if (host.empty()) - return false; - - size_t len = host.length(); - - if (len > Config->HostLen) + if (ident.empty() || ident.length() > Config->UserLen) return false; - - size_t idx, sec_len = 0, dots = 1; - switch (type) + for (unsigned i = 0; i < ident.length(); ++i) { - case 1: - for (idx = 0; idx < len; ++idx) - { - if (isdigit(host[idx])) - { - if (sec_len < 3) - ++sec_len; - else - return false; - } - else - { - if (!idx) - return false; /* cant start with a non-digit */ - if (host[idx] != '.') - return false; /* only . is a valid non-digit */ - if (sec_len > 3) - return false; /* sections cant be more than 3 digits */ - sec_len = 0; - ++dots; - } - } - if (dots != 4) - return false; - break; - case 2: - dots = 0; - for (idx = 0; idx < len; ++idx) - { - if (!isalnum(host[idx])) - { - if (!idx) - return false; - if (host[idx] != '.' && host[idx] != '-') - return false; - if (host[idx] == '.') - ++dots; - } - } - if (host[len - 1] == '.') - return false; - /** - * Ultimate3 dosnt like a non-dotted hosts at all, nor does unreal, - * so just dont allow them. - */ - if (!dots) - return false; + const char &c = ident[i]; + if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '.' || c == '-') + ; + else + return false; } + return true; } -/*************************************************************************/ - -/** - * Front end to doValidHost - * @param host = string to check - * @param type = format, 1 = ip4addr, 2 = hostname - * @return 1 if a host is valid, 0 if it isnt. +/** Checks if a host is valid + * @param host The host + * @param true if the host is valid */ -bool isValidHost(const Anope::string &host, int type) +bool IsValidHost(const Anope::string &host) { - bool status = false; - if (type == 3) + if (host.empty() || host.length() > Config->HostLen) + return false; + + if (Config->VhostDisallowBE.find_first_of(host[0]) != Anope::string::npos) + return false; + else if (Config->VhostDisallowBE.find_first_of(host[host.length() - 1]) != Anope::string::npos) + return false; + + int dots = 0; + for (unsigned i = 0; i < host.length(); ++i) { - status = doValidHost(host, 1); - if (!status) - status = doValidHost(host, 2); + if (host[i] == '.') + ++dots; + if (Config->VhostChars.find_first_of(host[i]) == Anope::string::npos) + return false; } - else - status = doValidHost(host, type); - return status; -} - -/*************************************************************************/ -/** - * Valid character check - * @param c Character to check - * @return 1 if a host is valid, 0 if it isnt. - */ -bool isvalidchar(char c) -{ - return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '.' || c == '-'; + return Config->VhostUndotted || dots > 0; } /*************************************************************************/ |