if (exclamation != 1 || atsign != 1)
return false;
- if (mask.length() > 250)
+ if (mask.length() > ServerInstance->Config->Limits.GetMaxMask())
return false;
return true;
{
std::string character;
std::string replace;
- special_chars(const std::string &c, const std::string &r) : character(c), replace(r) { }
- }
-
- special[] = {
- special_chars("\\002", "\002"), // Bold
- special_chars("\\037", "\037"), // underline
- special_chars("\\003", "\003"), // Color
- special_chars("\\017", "\017"), // Stop colors
- special_chars("\\u", "\037"), // Alias for underline
- special_chars("\\b", "\002"), // Alias for Bold
- special_chars("\\x", "\017"), // Alias for stop
- special_chars("\\c", "\003"), // Alias for color
- special_chars("", "")
+ special_chars(const std::string& c, const std::string& r)
+ : character(c)
+ , replace(r)
+ {
+ }
+ } special[] = {
+ special_chars("\\b", "\x02"), // Bold
+ special_chars("\\c", "\x03"), // Color
+ special_chars("\\i", "\x1D"), // Italic
+ special_chars("\\m", "\x11"), // Monospace
+ special_chars("\\s", "\x1E"), // Strikethrough
+ special_chars("\\u", "\x1F"), // Underline
+ special_chars("\\x", "\x0F"), // Reset
+ special_chars("\\", "")
};
for(file_cache::iterator it = input.begin(), it_end = input.end(); it != it_end; it++)
}
/* true for valid channel name, false else */
-bool IsChannelHandler::Call(const std::string& chname)
+bool InspIRCd::DefaultIsChannel(const std::string& chname)
{
if (chname.empty() || chname.length() > ServerInstance->Config->Limits.ChanMax)
return false;
}
/* true for valid nickname, false else */
-bool IsNickHandler::Call(const std::string& n)
+bool InspIRCd::DefaultIsNick(const std::string& n)
{
if (n.empty() || n.length() > ServerInstance->Config->Limits.NickMax)
return false;
}
/* return true for good ident, false else */
-bool IsIdentHandler::Call(const std::string& n)
+bool InspIRCd::DefaultIsIdent(const std::string& n)
{
if (n.empty())
return false;
return true;
}
+bool InspIRCd::IsHost(const std::string& host)
+{
+ // Hostnames must be non-empty and shorter than the maximum hostname length.
+ if (host.empty() || host.length() > ServerInstance->Config->Limits.MaxHost)
+ return false;
+
+ unsigned int numdashes = 0;
+ unsigned int numdots = 0;
+ bool seendot = false;
+ const std::string::const_iterator hostend = host.end() - 1;
+ for (std::string::const_iterator iter = host.begin(); iter != host.end(); ++iter)
+ {
+ unsigned char chr = static_cast<unsigned char>(*iter);
+
+ // If the current character is a label separator.
+ if (chr == '.')
+ {
+ numdots++;
+
+ // Consecutive separators are not allowed and dashes can not exist at the start or end
+ // of labels and separators must only exist between labels.
+ if (seendot || numdashes || iter == host.begin() || iter == hostend)
+ return false;
+
+ seendot = true;
+ continue;
+ }
+
+ // If this point is reached then the character is not a dot.
+ seendot = false;
+
+ // If the current character is a dash.
+ if (chr == '-')
+ {
+ // Consecutive separators are not allowed and dashes can not exist at the start or end
+ // of labels and separators must only exist between labels.
+ if (seendot || numdashes >= 2 || iter == host.begin() || iter == hostend)
+ return false;
+
+ numdashes += 1;
+ continue;
+ }
+
+ // If this point is reached then the character is not a dash.
+ numdashes = 0;
+
+ // Alphanumeric characters are allowed at any position.
+ if ((chr >= '0' && chr <= '9') || (chr >= 'A' && chr <= 'Z') || (chr >= 'a' && chr <= 'z'))
+ continue;
+
+ return false;
+ }
+
+ // Whilst simple hostnames (e.g. localhost) are valid we do not allow the server to use
+ // them to prevent issues with clients that differentiate between short client and server
+ // prefixes by checking whether the nickname contains a dot.
+ return numdots;
+}
+
bool InspIRCd::IsSID(const std::string &str)
{
/* Returns true if the string given is exactly 3 characters long,
return total + subtotal;
}
-const char* InspIRCd::Format(va_list &vaList, const char* formatString)
+std::string InspIRCd::Format(va_list& vaList, const char* formatString)
{
static std::vector<char> formatBuffer(1024);
formatBuffer.resize(formatBuffer.size() * 2);
}
- return &formatBuffer[0];
+ return std::string(&formatBuffer[0]);
}
-const char* InspIRCd::Format(const char* formatString, ...)
+std::string InspIRCd::Format(const char* formatString, ...)
{
- const char* ret;
+ std::string ret;
VAFORMAT(ret, formatString, formatString);
return ret;
}
// This is the default format used by asctime without the terminating new line.
if (!format)
- format = "%a %b %d %H:%M:%S %Y";
+ format = "%a %b %d %Y %H:%M:%S";
char buffer[512];
if (!strftime(buffer, sizeof(buffer), format, timeinfo))
return buffer;
}
-std::string InspIRCd::GenRandomStr(int length, bool printable)
+std::string InspIRCd::GenRandomStr(unsigned int length, bool printable)
{
char* buf = new char[length];
GenRandom(buf, length);
std::string rv;
rv.resize(length);
- for(int i=0; i < length; i++)
+ for(size_t i = 0; i < length; i++)
rv[i] = printable ? 0x3F + (buf[i] & 0x3F) : buf[i];
delete[] buf;
return rv;
}
// This is overridden by a higher-quality algorithm when SSL support is loaded
-void GenRandomHandler::Call(char *output, size_t max)
+void InspIRCd::DefaultGenRandom(char* output, size_t max)
{
- for(unsigned int i=0; i < max; i++)
-#ifdef _WIN32
+#if defined HAS_ARC4RANDOM_BUF
+ arc4random_buf(output, max);
+#else
+ for (unsigned int i = 0; i < max; ++i)
+# ifdef _WIN32
{
unsigned int uTemp;
if(rand_s(&uTemp) != 0)
else
output[i] = uTemp;
}
-#else
+# else
output[i] = random();
+# endif
#endif
}