]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_md5.cpp
fix some unitialised vectors and tidy up a bit.
[user/henk/code/inspircd.git] / src / modules / m_md5.cpp
index 5d6fdd00d6104f6f41c23468bf74a923b56b73ff..6096f9afa9bd4116f4449f9a0b91633eb3e7601a 100644 (file)
@@ -2,7 +2,7 @@
  *       | Inspire Internet Relay Chat Daemon |
  *       +------------------------------------+
  *
- *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
+ *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
  * See: http://www.inspircd.org/wiki/index.php/Credits
  *
  * This program is free but copyrighted software; see
 /* $ModDesc: Allows for MD5 encrypted oper passwords */
 /* $ModDep: m_hash.h */
 
-#include "inspircd_config.h"
+#include "inspircd.h"
 #ifdef HAS_STDINT
 #include <stdint.h>
 #endif
-#include "users.h"
-#include "channels.h"
-#include "modules.h"
-#include "inspircd.h"
-
 #include "m_hash.h"
 
 /* The four core functions - F1 is optimized somewhat */
@@ -66,10 +61,10 @@ class ModuleMD5 : public Module
                } while (--words);
        }
 
-       void MD5Init(struct MD5Context *ctx, unsigned int* key = NULL)
+       void MD5Init(MD5Context *ctx, unsigned int* ikey = NULL)
        {
                /* These are the defaults for md5 */
-               if (!key)
+               if (!ikey)
                {
                        ctx->buf[0] = 0x67452301;
                        ctx->buf[1] = 0xefcdab89;
@@ -78,17 +73,17 @@ class ModuleMD5 : public Module
                }
                else
                {
-                       ctx->buf[0] = key[0];
-                       ctx->buf[1] = key[1];
-                       ctx->buf[2] = key[2];
-                       ctx->buf[3] = key[3];
+                       ctx->buf[0] = ikey[0];
+                       ctx->buf[1] = ikey[1];
+                       ctx->buf[2] = ikey[2];
+                       ctx->buf[3] = ikey[3];
                }
        
                ctx->bytes[0] = 0;
                ctx->bytes[1] = 0;
        }
 
-       void MD5Update(struct MD5Context *ctx, byte const *buf, int len)
+       void MD5Update(MD5Context *ctx, byte const *buf, int len)
        {
                word32 t;
        
@@ -125,7 +120,7 @@ class ModuleMD5 : public Module
                memcpy(ctx->in, buf, len);
        }
        
-       void MD5Final(byte digest[16], struct MD5Context *ctx)
+       void MD5Final(byte digest[16], MD5Context *ctx)
        {
                int count = (int)(ctx->bytes[0] & 0x3f); /* Bytes in ctx->in */
                byte *p = (byte *)ctx->in + count;      /* First unused byte */
@@ -241,20 +236,20 @@ class ModuleMD5 : public Module
        }
        
        
-       void MyMD5(void *dest, void *orig, int len, unsigned int* key)
+       void MyMD5(void *dest, void *orig, int len, unsigned int* ikey)
        {
                MD5Context context;
-               MD5Init(&context, key);
+               MD5Init(&context, ikey);
                MD5Update(&context, (const unsigned char*)orig, len);
                MD5Final((unsigned char*)dest, &context);
        }
        
        
-       void GenHash(const char* src, char* dest, const char* xtab, unsigned int* key)
+       void GenHash(const char* src, char* dest, const char* xtab, unsigned int* ikey, size_t srclen)
        {
                unsigned char bytes[16];
 
-               MyMD5((char*)bytes, (void*)src, strlen(src), key);
+               MyMD5((char*)bytes, (void*)src, srclen, ikey);
 
                for (int i = 0; i < 16; i++)
                {
@@ -272,20 +267,18 @@ class ModuleMD5 : public Module
        ModuleMD5(InspIRCd* Me)
                : Module(Me), key(NULL), chars(NULL)
        {
-               ServerInstance->PublishInterface("HashRequest", this);
+               ServerInstance->Modules->PublishInterface("HashRequest", this);
+               Implementation eventlist[] = { I_OnRequest };
+               ServerInstance->Modules->Attach(eventlist, this, 1);
        }
        
        virtual ~ModuleMD5()
        {
-               ServerInstance->UnpublishInterface("HashRequest", this);
+               ServerInstance->Modules->UnpublishInterface("HashRequest", this);
        }
 
-       void Implements(char* List)
-       {
-               List[I_OnRequest] = 1;
-       }
        
-       virtual char* OnRequest(Request* request)
+       virtual const char* OnRequest(Request* request)
        {
                HashRequest* MD5 = (HashRequest*)request;
 
@@ -300,7 +293,7 @@ class ModuleMD5 : public Module
                else if (strcmp("SUM", request->GetId()) == 0)
                {
                        static char data[MAXBUF];
-                       GenHash((const char*)MD5->GetHashData(), data, chars ? chars : "0123456789abcdef", key);
+                       GenHash(MD5->GetHashData().data(), data, chars ? chars : "0123456789abcdef", key, MD5->GetHashData().length());
                        return data;
                }
                else if (strcmp("NAME", request->GetId()) == 0)
@@ -317,31 +310,8 @@ class ModuleMD5 : public Module
 
        virtual Version GetVersion()
        {
-               return Version(1,1,0,1,VF_VENDOR|VF_SERVICEPROVIDER,API_VERSION);
+               return Version(1,2,0,1,VF_VENDOR|VF_SERVICEPROVIDER,API_VERSION);
        }
 };
 
-
-class ModuleMD5Factory : public ModuleFactory
-{
- public:
-       ModuleMD5Factory()
-       {
-       }
-       
-       ~ModuleMD5Factory()
-       {
-       }
-       
-       virtual Module * CreateModule(InspIRCd* Me)
-       {
-               return new ModuleMD5(Me);
-       }
-       
-};
-
-
-extern "C" DllExport void * init_module( void )
-{
-       return new ModuleMD5Factory;
-}
+MODULE_INIT(ModuleMD5)