X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fhelperfuncs.cpp;h=6830612c70bedbc1bf0ee473aef6673d7d18d84e;hb=36e701f4abfa6d8fc4f096be023a681a6b7cec2e;hp=719454742f86de7bfb6e0d34ebaa4440c3b922ec;hpb=3b3cb845602bbaa3935f736785a53724750230dc;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/helperfuncs.cpp b/src/helperfuncs.cpp index 719454742..6830612c7 100644 --- a/src/helperfuncs.cpp +++ b/src/helperfuncs.cpp @@ -101,7 +101,7 @@ bool InspIRCd::IsValidMask(const std::string &mask) if (exclamation != 1 || atsign != 1) return false; - if (mask.length() > 250) + if (mask.length() > ServerInstance->Config->Limits.GetMaxMask()) return false; return true; @@ -146,19 +146,20 @@ void InspIRCd::ProcessColors(file_cache& input) { 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++) @@ -193,7 +194,7 @@ void InspIRCd::ProcessColors(file_cache& input) } /* 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; @@ -266,6 +267,65 @@ bool InspIRCd::DefaultIsIdent(const std::string& n) 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(*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, @@ -331,7 +391,7 @@ unsigned long InspIRCd::Duration(const std::string &str) 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 formatBuffer(1024); @@ -351,12 +411,12 @@ const char* InspIRCd::Format(va_list &vaList, const char* formatString) 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; } @@ -415,10 +475,13 @@ unsigned long InspIRCd::GenRandomInt(unsigned long max) } // 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) @@ -426,7 +489,8 @@ void GenRandomHandler::Call(char *output, size_t max) else output[i] = uTemp; } -#else +# else output[i] = random(); +# endif #endif }