mirror of
https://github.com/anope/anope.git
synced 2026-06-29 14:36:39 +02:00
Made the IsValidHost checks configurable
This commit is contained in:
@@ -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 = ".-"
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -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 */
|
||||
|
||||
+2
-4
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -99,7 +99,7 @@ class CommandHSRequest : public Command
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isValidHost(host, 3))
|
||||
if (!IsValidHost(host))
|
||||
{
|
||||
source.Reply(HOST_SET_ERROR);
|
||||
return;
|
||||
|
||||
+14
-26
@@ -56,22 +56,16 @@ class CommandHSSet : public Command
|
||||
|
||||
if (!user.empty())
|
||||
{
|
||||
if (user.length() > Config->UserLen)
|
||||
{
|
||||
source.Reply(HOST_SET_IDENTTOOLONG, Config->UserLen);
|
||||
return;
|
||||
}
|
||||
else if (!ircd->vident)
|
||||
if (!ircd->vident)
|
||||
{
|
||||
source.Reply(HOST_NO_VIDENT);
|
||||
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;
|
||||
}
|
||||
else if (!IsValidIdent(user))
|
||||
{
|
||||
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)
|
||||
{
|
||||
source.Reply(HOST_SET_IDENTTOOLONG, Config->UserLen);
|
||||
return;
|
||||
}
|
||||
else if (!ircd->vident)
|
||||
if (!ircd->vident)
|
||||
{
|
||||
source.Reply(HOST_NO_VIDENT);
|
||||
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;
|
||||
}
|
||||
else if (!IsValidIdent(user))
|
||||
{
|
||||
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;
|
||||
|
||||
@@ -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."));
|
||||
|
||||
@@ -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},
|
||||
|
||||
+31
-94
@@ -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)
|
||||
if (ident.empty() || ident.length() > Config->UserLen)
|
||||
return false;
|
||||
if (host.empty())
|
||||
return false;
|
||||
|
||||
size_t len = host.length();
|
||||
|
||||
if (len > Config->HostLen)
|
||||
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;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
Reference in New Issue
Block a user