X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_md5.cpp;h=6096f9afa9bd4116f4449f9a0b91633eb3e7601a;hb=f9ef4ebc9dc4fd46cdafcc76df644b4896251dac;hp=55e462077eaf9cbcadac7c941fdc9308c27c1d33;hpb=bcac49dca78631687975771c6d0a76b595171664;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_md5.cpp b/src/modules/m_md5.cpp index 55e462077..6096f9afa 100644 --- a/src/modules/m_md5.cpp +++ b/src/modules/m_md5.cpp @@ -2,12 +2,9 @@ * | Inspire Internet Relay Chat Daemon | * +------------------------------------+ * - * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev. - * E-mail: - * - * - * - * Written by Craig Edwards, Craig McLure, and others. + * InspIRCd: (C) 2002-2008 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. * @@ -15,20 +12,13 @@ */ /* $ModDesc: Allows for MD5 encrypted oper passwords */ -/* $ModDep: m_md5.h */ - -using namespace std; +/* $ModDep: m_hash.h */ -#include "inspircd_config.h" +#include "inspircd.h" #ifdef HAS_STDINT #include #endif -#include "users.h" -#include "channels.h" -#include "modules.h" -#include "inspircd.h" - -#include "m_md5.h" +#include "m_hash.h" /* The four core functions - F1 is optimized somewhat */ #define F1(x, y, z) (z ^ (x & (y ^ z))) @@ -38,7 +28,7 @@ using namespace std; /* This is the central step in the MD5 algorithm. */ #define MD5STEP(f,w,x,y,z,in,s) \ - (w += f(x,y,z) + in, w = (w<>(32-s)) + x) + (w += f(x,y,z) + in, w = (w<>(32-s)) + x) #ifndef HAS_STDINT typedef unsigned int uint32_t; @@ -70,12 +60,11 @@ class ModuleMD5 : public Module p += 4; } while (--words); } - - /* XXX - maybe if we had an md5/encryption moduletype? *shrug* */ - 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; @@ -84,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; @@ -131,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 */ @@ -247,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++) { @@ -276,37 +265,42 @@ class ModuleMD5 : public Module public: ModuleMD5(InspIRCd* Me) - : Module::Module(Me), key(NULL), chars(NULL) + : Module(Me), key(NULL), chars(NULL) { + ServerInstance->Modules->PublishInterface("HashRequest", this); + Implementation eventlist[] = { I_OnRequest }; + ServerInstance->Modules->Attach(eventlist, this, 1); } virtual ~ModuleMD5() { + ServerInstance->Modules->UnpublishInterface("HashRequest", this); } - void Implements(char* List) - { - List[I_OnRequest] = 1; - } - virtual char* OnRequest(Request* request) + virtual const char* OnRequest(Request* request) { - MD5Request* MD5 = (MD5Request*)request; - if (strcmp("MD5_KEY", request->GetId()) == 0) + HashRequest* MD5 = (HashRequest*)request; + + if (strcmp("KEY", request->GetId()) == 0) { this->key = (unsigned int*)MD5->GetKeyData(); } - else if (strcmp("MD5_HEX", request->GetId()) == 0) + else if (strcmp("HEX", request->GetId()) == 0) { this->chars = (char*)MD5->GetOutputs(); } - else if (strcmp("MD5_SUM", request->GetId()) == 0) + 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("MD5_RESET", request->GetId()) == 0) + else if (strcmp("NAME", request->GetId()) == 0) + { + return "md5"; + } + else if (strcmp("RESET", request->GetId()) == 0) { this->chars = NULL; this->key = NULL; @@ -316,31 +310,8 @@ class ModuleMD5 : public Module virtual Version GetVersion() { - return Version(1,1,0,1,VF_VENDOR,API_VERSION); - } -}; - - -class ModuleMD5Factory : public ModuleFactory -{ - public: - ModuleMD5Factory() - { - } - - ~ModuleMD5Factory() - { - } - - virtual Module * CreateModule(InspIRCd* Me) - { - return new ModuleMD5(Me); + return Version(1,2,0,1,VF_VENDOR|VF_SERVICEPROVIDER,API_VERSION); } - }; - -extern "C" void * init_module( void ) -{ - return new ModuleMD5Factory; -} +MODULE_INIT(ModuleMD5)