X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_md5.cpp;h=3b7df836994ce1d24219d95184745cd9206919d7;hb=b7e299c2e10d915d5e59df4cb3f54951c8daa999;hp=419d66e28a94a19ae07580cf5594eefb86452bf9;hpb=e824558b7b38ce876991bc7e92a4dc4f40c9fc79;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_md5.cpp b/src/modules/m_md5.cpp index 419d66e28..3b7df8369 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-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. * @@ -15,18 +12,16 @@ */ /* $ModDesc: Allows for MD5 encrypted oper passwords */ +/* $ModDep: m_hash.h */ -using namespace std; - -#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_hash.h" /* The four core functions - F1 is optimized somewhat */ #define F1(x, y, z) (z ^ (x & (y ^ z))) @@ -36,7 +31,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; @@ -68,9 +63,8 @@ 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* key = NULL) { /* These are the defaults for md5 */ if (!key) @@ -92,7 +86,7 @@ class ModuleMD5 : public Module 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; @@ -129,7 +123,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 */ @@ -274,12 +268,14 @@ class ModuleMD5 : public Module public: ModuleMD5(InspIRCd* Me) - : Module::Module(Me), key(NULL), chars(NULL) + : Module(Me), key(NULL), chars(NULL) { + ServerInstance->PublishInterface("HashRequest", this); } virtual ~ModuleMD5() { + ServerInstance->UnpublishInterface("HashRequest", this); } void Implements(char* List) @@ -289,21 +285,27 @@ class ModuleMD5 : public Module virtual char* OnRequest(Request* request) { - if (strcmp("MD5_SETKEY", request->GetId()) == 0) + HashRequest* MD5 = (HashRequest*)request; + + if (strcmp("KEY", request->GetId()) == 0) { - this->key = (unsigned int*)request->GetData(); + this->key = (unsigned int*)MD5->GetKeyData(); } - else if (strcmp("MD5_SETCHARS", request->GetId()) == 0) + else if (strcmp("HEX", request->GetId()) == 0) { - this->chars = (char*)request->GetData(); + 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*)request->GetData(), data, chars ? chars : "0123456789abcdef", key); + GenHash((const char*)MD5->GetHashData(), data, chars ? chars : "0123456789abcdef", key); 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; @@ -313,31 +315,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() - { + return Version(1,1,0,1,VF_VENDOR|VF_SERVICEPROVIDER,API_VERSION); } - - virtual Module * CreateModule(InspIRCd* Me) - { - return new ModuleMD5(Me); - } - }; - -extern "C" void * init_module( void ) -{ - return new ModuleMD5Factory; -} +MODULE_INIT(ModuleMD5)