]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_md5.cpp
Prevent using invalid UIDs and enforce UID/SID matching
[user/henk/code/inspircd.git] / src / modules / m_md5.cpp
index 9fa4894fdce51c44eb843e78398a25d5413e627d..a6df62dd9c2605802f9fdbd32eed66d3c750d7d6 100644 (file)
@@ -2,7 +2,7 @@
  *       | Inspire Internet Relay Chat Daemon |
  *       +------------------------------------+
  *
- *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
+ *  InspIRCd: (C) 2002-2010 InspIRCd Development Team
  * See: http://wiki.inspircd.org/Credits
  *
  * This program is free but copyrighted software; see
  */
 
 /* $ModDesc: Allows for MD5 encrypted oper passwords */
-/* $ModDep: m_hash.h */
 
 #include "inspircd.h"
 #ifdef HAS_STDINT
 #include <stdint.h>
 #endif
-#include "m_hash.h"
+#include "hash.h"
 
 /* The four core functions - F1 is optimized somewhat */
 #define F1(x, y, z) (z ^ (x & (y ^ z)))
@@ -39,7 +38,7 @@ typedef unsigned char byte;
 
 /** An MD5 context, used by m_opermd5
  */
-class MD5Context : public classbase
+class MD5Context
 {
  public:
        word32 buf[4];
@@ -47,7 +46,7 @@ class MD5Context : public classbase
        word32 in[16];
 };
 
-class ModuleMD5 : public Module
+class MD5Provider : public HashProvider
 {
        void byteSwap(word32 *buf, unsigned words)
        {
@@ -258,45 +257,36 @@ class ModuleMD5 : public Module
                }
                *dest++ = 0;
        }
-
  public:
-
-       ModuleMD5()
+       std::string sum(const std::string& data)
        {
-               ServerInstance->Modules->PublishInterface("HashRequest", this);
+               char res[16];
+               MyMD5(res, (void*)data.data(), data.length(), NULL);
+               return std::string(res, 16);
        }
 
-       virtual ~ModuleMD5()
+       std::string sumIV(unsigned int* IV, const char* HexMap, const std::string &sdata)
        {
-               ServerInstance->Modules->UnpublishInterface("HashRequest", this);
+               char res[33];
+               GenHash(sdata.data(), res, HexMap, IV, sdata.length());
+               return res;
        }
 
+       MD5Provider(Module* parent) : HashProvider(parent, "hash/md5", 16, 64) {}
+};
 
-       void OnRequest(Request& request)
+class ModuleMD5 : public Module
+{
+       MD5Provider md5;
+ public:
+       ModuleMD5() : md5(this)
        {
-               if (strcmp("HASH", request.id) == 0)
-               {
-                       char res[16];
-                       HashRequest& req = static_cast<HashRequest&>(request);
-                       MyMD5(res, (void*)req.data.data(), req.data.length(), NULL);
-                       req.binresult.assign(res, 16);
-               }
-               else if (strcmp("HASH-IV", request.id) == 0)
-               {
-                       char res[33];
-                       HashRequestIV& req = static_cast<HashRequestIV&>(request);
-                       GenHash(req.data.data(), res, req.map, req.iv, req.data.length());
-                       req.result = res;
-               }
-               else if (strcmp("NAME", request.id) == 0)
-               {
-                       static_cast<HashNameRequest&>(request).response = "md5";
-               }
+               ServerInstance->Modules->AddService(md5);
        }
 
        Version GetVersion()
        {
-               return Version("Allows for MD5 encrypted oper passwords",VF_VENDOR|VF_SERVICEPROVIDER,API_VERSION);
+               return Version("Implements MD5 hashing",VF_VENDOR);
        }
 };