diff options
author | w00t <w00t@e03df62e-2008-0410-955e-edbf42e46eb7> | 2008-01-16 21:36:07 +0000 |
---|---|---|
committer | w00t <w00t@e03df62e-2008-0410-955e-edbf42e46eb7> | 2008-01-16 21:36:07 +0000 |
commit | b979bc46743bcb180af93f34b4bb337edce67b7d (patch) | |
tree | 2b419ca64151c0d1887eb77e89a0deee3c134f95 | |
parent | c28e8dc34a04c1c91b268687e9e0b4146d7c3c3a (diff) |
Validate <server:id> on startup if provided, thx Brain
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@8721 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r-- | include/inspircd.h | 5 | ||||
-rw-r--r-- | src/configreader.cpp | 8 | ||||
-rw-r--r-- | src/helperfuncs.cpp | 10 | ||||
-rw-r--r-- | src/modules/m_spanningtree/treesocket2.cpp | 6 | ||||
-rw-r--r-- | src/modules/m_spanningtree/utils.cpp | 12 | ||||
-rw-r--r-- | src/modules/m_spanningtree/utils.h | 5 |
6 files changed, 26 insertions, 20 deletions
diff --git a/include/inspircd.h b/include/inspircd.h index c60f7c230..320aa83ca 100644 --- a/include/inspircd.h +++ b/include/inspircd.h @@ -619,6 +619,11 @@ class CoreExport InspIRCd : public classbase */ bool IsChannel(const char *chname); + /** Return true if str looks like a server ID + * @param string to check against + */ + bool IsSID(const std::string &str); + /** Rehash the local server */ void Rehash(); diff --git a/src/configreader.cpp b/src/configreader.cpp index 23c3fd925..d854edfaf 100644 --- a/src/configreader.cpp +++ b/src/configreader.cpp @@ -478,7 +478,13 @@ bool ValidateInvite(ServerConfig* conf, const char*, const char*, ValueItem &dat bool ValidateSID(ServerConfig* conf, const char*, const char*, ValueItem &data) { -// std::string sid = data.GetString(); + const char *sid = data.GetString(); + + if (*sid && !conf->GetInstance()->IsSID(sid)) + { + throw CoreException(std::string(sid) + " is not a valid server ID."); + } + return true; } diff --git a/src/helperfuncs.cpp b/src/helperfuncs.cpp index 309267c38..40b2d7d90 100644 --- a/src/helperfuncs.cpp +++ b/src/helperfuncs.cpp @@ -506,6 +506,16 @@ bool IsIdentHandler::Call(const char* n) return true; } +bool InspIRCd::IsSID(const std::string &str) +{ + /* Returns true if the string given is exactly 3 characters long, + * starts with a digit, and the other two characters are A-Z or digits + */ + return ((str.length() == 3) && isdigit(str[0]) && + ((str[1] >= 'A' && str[1] <= 'Z') || isdigit(str[1])) && + ((str[2] >= 'A' && str[2] <= 'Z') || isdigit(str[2]))); +} + /* open the proper logfile */ bool InspIRCd::OpenLog(char**, int) { diff --git a/src/modules/m_spanningtree/treesocket2.cpp b/src/modules/m_spanningtree/treesocket2.cpp index 8f0ee0f17..e5d25dc50 100644 --- a/src/modules/m_spanningtree/treesocket2.cpp +++ b/src/modules/m_spanningtree/treesocket2.cpp @@ -818,7 +818,7 @@ bool TreeSocket::RemoteServer(const std::string &prefix, std::deque<std::string> this->SendError("Protocol error - Introduced remote server from unknown server "+prefix); return false; } - if (!Utils->IsSID(sid)) + if (!this->Instance->IsSID(sid)) { this->SendError("Invalid format server ID: "+sid+"!"); return false; @@ -897,7 +897,7 @@ bool TreeSocket::Outbound_Reply_Server(std::deque<std::string> ¶ms) return false; } - if (!Utils->IsSID(sid)) + if (!this->Instance->IsSID(sid)) { this->SendError("Invalid format server ID: "+sid+"!"); return false; @@ -974,7 +974,7 @@ bool TreeSocket::Inbound_Server(std::deque<std::string> ¶ms) return false; } - if (!Utils->IsSID(sid)) + if (!this->Instance->IsSID(sid)) { this->SendError("Invalid format server ID: "+sid+"!"); return false; diff --git a/src/modules/m_spanningtree/utils.cpp b/src/modules/m_spanningtree/utils.cpp index 32580cd97..4e0193727 100644 --- a/src/modules/m_spanningtree/utils.cpp +++ b/src/modules/m_spanningtree/utils.cpp @@ -29,16 +29,6 @@ /* $ModDep: m_spanningtree/timesynctimer.h m_spanningtree/resolvers.h m_spanningtree/main.h m_spanningtree/utils.h m_spanningtree/treeserver.h m_spanningtree/link.h m_spanningtree/treesocket.h */ -bool SpanningTreeUtilities::IsSID(const std::string &str) -{ - /* Returns true if the string given is exactly 3 characters long, - * starts with a digit, and the other two characters are A-Z or digits - */ - return ((str.length() == 3) && isdigit(str[0]) && - ((str[1] >= 'A' && str[1] <= 'Z') || isdigit(str[1])) && - ((str[2] >= 'A' && str[2] <= 'Z') || isdigit(str[2]))); -} - /** Yay for fast searches! * This is hundreds of times faster than recursion * or even scanning a linked list, especially when @@ -47,7 +37,7 @@ bool SpanningTreeUtilities::IsSID(const std::string &str) */ TreeServer* SpanningTreeUtilities::FindServer(const std::string &ServerName) { - if (IsSID(ServerName)) + if (this->ServerInstance->IsSID(ServerName)) return this->FindServerID(ServerName); server_hash::iterator iter = serverlist.find(ServerName.c_str()); diff --git a/src/modules/m_spanningtree/utils.h b/src/modules/m_spanningtree/utils.h index 6fb8b3e6e..f79b5280e 100644 --- a/src/modules/m_spanningtree/utils.h +++ b/src/modules/m_spanningtree/utils.h @@ -190,11 +190,6 @@ class SpanningTreeUtilities void AddBurstingServer(const std::string &ServerName, TreeSocket* s); void DelBurstingServer(TreeSocket* s); - - /** Return true if str looks like a server ID - * @param string to check against - */ - bool IsSID(const std::string &str); }; #endif |