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 | |
parent | bb8e04c83588b6d0595eca463170643a3bd84285 (diff) |
Made the IsValidHost checks configurable
-rw-r--r-- | data/hostserv.example.conf | 28 | ||||
-rw-r--r-- | include/config.h | 7 | ||||
-rw-r--r-- | include/extern.h | 6 | ||||
-rw-r--r-- | modules/commands/bs_bot.cpp | 6 | ||||
-rw-r--r-- | modules/commands/hs_request.cpp | 2 | ||||
-rw-r--r-- | modules/commands/hs_set.cpp | 32 | ||||
-rw-r--r-- | modules/commands/os_jupe.cpp | 2 | ||||
-rw-r--r-- | src/config.cpp | 3 | ||||
-rw-r--r-- | src/misc.cpp | 125 |
9 files changed, 86 insertions, 125 deletions
diff --git a/data/hostserv.example.conf b/data/hostserv.example.conf index 575c6a416..7e6156374 100644 --- a/data/hostserv.example.conf +++ b/data/hostserv.example.conf @@ -64,6 +64,34 @@ hostserv * The name of the client that should be HostServ. */ name = "HostServ" + + /* + * The characters allowed in a vhost. Changing this is not recommended unless + * you know for sure your IRCd supports whatever characters you are wanting to use. + * Telling services to set a vhost containing characters your IRCd disallows could + * potentially break the IRCd and/or Services. Note these are 1 byte characters, so + * UTF-8 characters will not work. + * + * It is recommended you DON'T change this. + */ + vhost_chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJMLMNOPQRSTUVWXYZ0123456789.-" + + /* + * If set, allows vhosts to not contain dots (.). + * Newer IRCds generally do not have a problem with this, but the same warning as + * vhost_chars applies. + * + * It is recommended you DON'T change this. + */ + allow_undotted_vhosts = false + + /* + * The characters that are not allowed to be at the very beginning or very ending + * of a vhost. The same warning as vhost_chars applies. + * + * It is recommended you DON'T change this. + */ + disallow_start_or_end = ".-" } /* diff --git a/include/config.h b/include/config.h index e2b626c9c..47b4c36e1 100644 --- a/include/config.h +++ b/include/config.h @@ -541,6 +541,13 @@ class CoreExport ServerConfig /* Who can use memos reciepts */ unsigned MSMemoReceipt; + /* Valid chars allowed in vhosts */ + Anope::string VhostChars; + /* Allow undotted vhosts? */ + bool VhostUndotted; + /* Chars disallowed at the beginning or end of vhosts */ + Anope::string VhostDisallowBE; + /* Core BotServ modules */ Anope::string BotCoreModules; /* Default BotServ flags */ diff --git a/include/extern.h b/include/extern.h index 1772c965c..b62997aad 100644 --- a/include/extern.h +++ b/include/extern.h @@ -159,10 +159,8 @@ E time_t dotime(const Anope::string &s); E Anope::string duration(const time_t &seconds, NickCore *nc = NULL); E Anope::string expire_left(NickCore *nc, time_t expires); E Anope::string do_strftime(const time_t &t, NickCore *nc = NULL, bool short_output = false); -E bool doValidHost(const Anope::string &host, int type); - -E bool isValidHost(const Anope::string &host, int type); -E bool isvalidchar(char c); +E bool IsValidIdent(const Anope::string &ident); +E bool IsValidHost(const Anope::string &host); E Anope::string myStrGetToken(const Anope::string &str, char dilim, int token_number); E Anope::string myStrGetTokenRemainder(const Anope::string &str, char dilim, int token_number); diff --git a/modules/commands/bs_bot.cpp b/modules/commands/bs_bot.cpp index 02af6b340..e4f88856f 100644 --- a/modules/commands/bs_bot.cpp +++ b/modules/commands/bs_bot.cpp @@ -69,8 +69,8 @@ class CommandBSBot : public Command return; } - /* Check the host is valid re RFC 2812 */ - if (!isValidHost(host, 3)) + /* Check the host is valid */ + if (!IsValidHost(host)) { source.Reply(_("Bot Hosts may only contain valid host characters.")); return; @@ -186,7 +186,7 @@ class CommandBSBot : public Command return; } - if (!host.empty() && !isValidHost(host, 3)) + if (!host.empty() && !IsValidHost(host)) { source.Reply(_("Bot Hosts may only contain valid host characters.")); return; diff --git a/modules/commands/hs_request.cpp b/modules/commands/hs_request.cpp index 861448240..75bb7994d 100644 --- a/modules/commands/hs_request.cpp +++ b/modules/commands/hs_request.cpp @@ -99,7 +99,7 @@ class CommandHSRequest : public Command return; } - if (!isValidHost(host, 3)) + if (!IsValidHost(host)) { source.Reply(HOST_SET_ERROR); return; diff --git a/modules/commands/hs_set.cpp b/modules/commands/hs_set.cpp index 4711022db..44a501cc1 100644 --- a/modules/commands/hs_set.cpp +++ b/modules/commands/hs_set.cpp @@ -56,22 +56,16 @@ class CommandHSSet : public Command if (!user.empty()) { - if (user.length() > Config->UserLen) + if (!ircd->vident) { - source.Reply(HOST_SET_IDENTTOOLONG, Config->UserLen); + source.Reply(HOST_NO_VIDENT); return; } - else if (!ircd->vident) + else if (!IsValidIdent(user)) { - source.Reply(HOST_NO_VIDENT); + source.Reply(HOST_SET_IDENT_ERROR); return; } - for (Anope::string::iterator s = user.begin(), s_end = user.end(); s != s_end; ++s) - if (!isvalidchar(*s)) - { - source.Reply(HOST_SET_IDENT_ERROR); - return; - } } if (host.length() > Config->HostLen) @@ -80,7 +74,7 @@ class CommandHSSet : public Command return; } - if (!isValidHost(host, 3)) + if (!IsValidHost(host)) { source.Reply(HOST_SET_ERROR); return; @@ -163,22 +157,16 @@ class CommandHSSetAll : public Command if (!user.empty()) { - if (user.length() > Config->UserLen) + if (!ircd->vident) { - source.Reply(HOST_SET_IDENTTOOLONG, Config->UserLen); + source.Reply(HOST_NO_VIDENT); return; } - else if (!ircd->vident) + else if (!IsValidIdent(user)) { - source.Reply(HOST_NO_VIDENT); + source.Reply(HOST_SET_IDENT_ERROR); return; } - for (Anope::string::iterator s = user.begin(), s_end = user.end(); s != s_end; ++s) - if (!isvalidchar(*s)) - { - source.Reply(HOST_SET_IDENT_ERROR); - return; - } } if (host.length() > Config->HostLen) @@ -187,7 +175,7 @@ class CommandHSSetAll : public Command return; } - if (!isValidHost(host, 3)) + if (!IsValidHost(host)) { source.Reply(HOST_SET_ERROR); return; diff --git a/modules/commands/os_jupe.cpp b/modules/commands/os_jupe.cpp index a689b33e2..b11b975d8 100644 --- a/modules/commands/os_jupe.cpp +++ b/modules/commands/os_jupe.cpp @@ -29,7 +29,7 @@ class CommandOSJupe : public Command const Anope::string &reason = params.size() > 1 ? params[1] : ""; Server *server = Server::Find(jserver); - if (!isValidHost(jserver, 3)) + if (!IsValidHost(jserver) || jserver.find('.') == Anope::string::npos) source.Reply(_("Please use a valid server name when juping")); else if (server && (server == Me || server == Me->GetLinks().front())) source.Reply(_("You can not jupe your services server or your uplink server.")); diff --git a/src/config.cpp b/src/config.cpp index 28cf7aee6..bf32bce5f 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -1195,6 +1195,9 @@ ConfigItems::ConfigItems(ServerConfig *conf) {"memoserv", "notifyall", "no", new ValueContainerBool(&conf->MSNotifyAll), DT_BOOLEAN, NoValidation}, {"memoserv", "memoreceipt", "0", new ValueContainerUInt(&conf->MSMemoReceipt), DT_UINTEGER, NoValidation}, {"hostserv", "name", "", new ValueContainerString(&conf->HostServ), DT_STRING, NoValidation}, + {"hostserv", "vhost_chars", "abcdefghijklmnopqrstuvwxyzABCDEFGHIJMLMNOPQRSTUVWXYZ0123456789.-", new ValueContainerString(&conf->VhostChars), DT_STRING, NoValidation}, + {"hostserv", "allow_undotted_vhosts", "false", new ValueContainerBool(&conf->VhostUndotted), DT_BOOLEAN, NoValidation}, + {"hostserv", "disallow_start_or_end", "", new ValueContainerString(&conf->VhostDisallowBE), DT_STRING, NoValidation}, {"botserv", "name", "", new ValueContainerString(&conf->BotServ), DT_STRING, NoValidation}, {"botserv", "defaults", "", new ValueContainerString(&BSDefaults), DT_STRING, NoValidation}, {"botserv", "minusers", "0", new ValueContainerUInt(&conf->BSMinUsers), DT_UINTEGER, ValidateBotServ}, 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; } /*************************************************************************/ |