]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_spanningtree/treesocket2.cpp
Add config <options:disablehmac> to support disabling of HMAC, and tidy up to detect...
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / treesocket2.cpp
index 2172940216149fbeef60add7967631092f7f3f2d..6c0418a0bd9a9bb414c86bc2741be8f5d4049aa1 100644 (file)
@@ -1,3 +1,16 @@
+/*       +------------------------------------+
+ *       | Inspire Internet Relay Chat Daemon |
+ *       +------------------------------------+
+ *
+ *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
+ * See: http://www.inspircd.org/wiki/index.php/Credits
+ *
+ * This program is free but copyrighted software; see
+ *            the file COPYING for details.
+ *
+ * ---------------------------------------------------
+ */
+
 #include "configreader.h"
 #include "users.h"
 #include "channels.h"
@@ -801,6 +814,24 @@ bool TreeSocket::RemoteServer(const std::string &prefix, std::deque<std::string>
        return true;
 }
 
+bool TreeSocket::ComparePass(const std::string &ours, const std::string &theirs)
+{
+       if ((!strncmp(ours.c_str(), "HMAC-SHA256:", 12)) || (!strncmp(theirs.c_str(), "HMAC-SHA256:", 12)))
+       {
+               /* One or both of us specified hmac sha256, but we don't have sha256 module loaded!
+                * We can't allow this password as valid.
+                */
+               if (!Instance->FindModule("m_sha256.so") || !Utils->ChallengeResponse)
+                               return false;
+               else
+                       /* Straight string compare of hashes */
+                       return ours == theirs;
+       }
+       else
+               /* Straight string compare of plaintext */
+               return ours == theirs;
+}
+
 bool TreeSocket::Outbound_Reply_Server(std::deque<std::string> &params)
 {
        if (params.size() < 4)
@@ -820,7 +851,7 @@ bool TreeSocket::Outbound_Reply_Server(std::deque<std::string> &params)
        std::string description = params[3];
        for (std::vector<Link>::iterator x = Utils->LinkBlocks.begin(); x < Utils->LinkBlocks.end(); x++)
        {
-               if ((x->Name == servername) && (x->RecvPass == password))
+               if ((x->Name == servername) && (ComparePass(this->MakePass(x->RecvPass,this->GetOurChallenge()),password)))
                {
                        TreeServer* CheckDupe = Utils->FindServer(sname);
                        if (CheckDupe)
@@ -869,7 +900,7 @@ bool TreeSocket::Inbound_Server(std::deque<std::string> &params)
        std::string description = params[3];
        for (std::vector<Link>::iterator x = Utils->LinkBlocks.begin(); x < Utils->LinkBlocks.end(); x++)
        {
-               if ((x->Name == servername) && (x->RecvPass == password))
+               if ((x->Name == servername) && (ComparePass(this->MakePass(x->RecvPass,this->GetOurChallenge()),password)))
                {
                        TreeServer* CheckDupe = Utils->FindServer(sname);
                        if (CheckDupe)
@@ -889,7 +920,7 @@ bool TreeSocket::Inbound_Server(std::deque<std::string> &params)
                        this->InboundDescription = description;
                        // this is good. Send our details: Our server name and description and hopcount of 0,
                        // along with the sendpass from this block.
-                       this->WriteLine(std::string("SERVER ")+this->Instance->Config->ServerName+" "+x->SendPass+" 0 :"+this->Instance->Config->ServerDesc);
+                       this->WriteLine(std::string("SERVER ")+this->Instance->Config->ServerName+" "+this->MakePass(x->SendPass, this->GetTheirChallenge())+" 0 :"+this->Instance->Config->ServerDesc);
                        // move to the next state, we are now waiting for THEM.
                        this->LinkState = WAIT_AUTH_2;
                        return true;
@@ -1056,6 +1087,10 @@ bool TreeSocket::ProcessLine(std::string &line)
                        {
                                return this->Error(params);
                        }
+                       else if (command == "CAPAB")
+                       {
+                               return this->Capab(params);
+                       }
                break;
                case CONNECTED:
                        // This is the 'authenticated' state, when all passwords