]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_spanningtree/hmac.cpp
Clarify module mismatch message
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / hmac.cpp
index 4b99a3eb7c3dc051fabfc54a3fdc235bdf970948..74462fe1c2e73b42e2f3ef3259125779da70fd0b 100644 (file)
@@ -2,7 +2,7 @@
  *       | Inspire Internet Relay Chat Daemon |
  *       +------------------------------------+
  *
- *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
+ *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
  * See: http://www.inspircd.org/wiki/index.php/Credits
  *
  * This program is free but copyrighted software; see
@@ -15,7 +15,6 @@
 #include "commands/cmd_whois.h"
 #include "commands/cmd_stats.h"
 #include "socket.h"
-#include "wildcard.h"
 #include "xline.h"
 #include "transport.h"
 #include "m_hash.h"
@@ -29,7 +28,7 @@
 #include "m_spanningtree/resolvers.h"
 #include "m_spanningtree/handshaketimer.h"
 
-/* $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 m_hash.h */
+/* $ModDep: m_spanningtree/resolvers.h m_spanningtree/main.h m_spanningtree/utils.h m_spanningtree/treeserver.h m_spanningtree/link.h m_spanningtree/treesocket.h m_hash.h */
 
 const std::string& TreeSocket::GetOurChallenge()
 {
@@ -59,7 +58,7 @@ std::string TreeSocket::MakePass(const std::string &password, const std::string
         * Note: If m_sha256.so is not loaded, we MUST fall back to plaintext with no
         *       HMAC challenge/response.
         */
-       Module* sha256 = Instance->Modules->Find("m_sha256.so");
+       Module* sha256 = ServerInstance->Modules->Find("m_sha256.so");
        if (Utils->ChallengeResponse && sha256 && !challenge.empty())
        {
                /* XXX: This is how HMAC is supposed to be done:
@@ -90,35 +89,36 @@ std::string TreeSocket::MakePass(const std::string &password, const std::string
                return "HMAC-SHA256:"+ hmac;
        }
        else if (!challenge.empty() && !sha256)
-               Instance->Log(DEFAULT,"Not authenticating to server using SHA256/HMAC because we don't have m_sha256 loaded!");
+               ServerInstance->Logs->Log("m_spanningtree",DEFAULT,"Not authenticating to server using SHA256/HMAC because we don't have m_sha256 loaded!");
 
        return password;
 }
 
-std::string TreeSocket::RandString(unsigned int length)
+std::string TreeSocket::RandString(unsigned int ilength)
 {
-       char* randombuf = new char[length+1];
+       char* randombuf = new char[ilength+1];
        std::string out;
 #ifdef WINDOWS
-       int fd = -1;
+       int f = -1;
 #else
-       int fd = open("/dev/urandom", O_RDONLY, 0);
+       int f = open("/dev/urandom", O_RDONLY, 0);
 #endif
 
-       if (fd >= 0)
+       if (f >= 0)
        {
 #ifndef WINDOWS
-               read(fd, randombuf, length);
-               close(fd);
+               if (read(f, randombuf, ilength) < 1)
+                       ServerInstance->Logs->Log("m_spanningtree", DEFAULT, "There are crack smoking monkeys in your kernel (in other words, nonblocking /dev/urandom blocked.)");
+               close(f);
 #endif
        }
        else
        {
-               for (unsigned int i = 0; i < length; i++)
+               for (unsigned int i = 0; i < ilength; i++)
                        randombuf[i] = rand();
        }
 
-       for (unsigned int i = 0; i < length; i++)
+       for (unsigned int i = 0; i < ilength; i++)
        {
                char randchar = static_cast<char>((randombuf[i] & 0x7F) | 0x21);
                out += (randchar == '=' ? '_' : randchar);
@@ -135,7 +135,7 @@ bool TreeSocket::ComparePass(const std::string &ours, const std::string &theirs)
                /* 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->Modules->Find("m_sha256.so") || !Utils->ChallengeResponse)
+               if (!ServerInstance->Modules->Find("m_sha256.so") || !Utils->ChallengeResponse)
                        return false;
                else
                        /* Straight string compare of hashes */
@@ -144,4 +144,4 @@ bool TreeSocket::ComparePass(const std::string &ours, const std::string &theirs)
        else
                /* Straight string compare of plaintext */
                return ours == theirs;
-}  
+}