X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_md5.cpp;h=feba027f67a0213dbe173ced5b1d6b26972ed0af;hb=226a95aab09b9e1f43f61e78179bfa1135816c2d;hp=00d3fb1e9260fa1ddcc8247b1b814bfa5c500d29;hpb=7e843c22e16c81054bad18073d24fe1a07026431;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_md5.cpp b/src/modules/m_md5.cpp index 00d3fb1e9..feba027f6 100644 --- a/src/modules/m_md5.cpp +++ b/src/modules/m_md5.cpp @@ -1,24 +1,33 @@ -/* +------------------------------------+ - * | Inspire Internet Relay Chat Daemon | - * +------------------------------------+ +/* + * InspIRCd -- Internet Relay Chat Daemon * - * InspIRCd: (C) 2002-2009 InspIRCd Development Team - * See: http://wiki.inspircd.org/Credits + * Copyright (C) 2009 Daniel De Graaf + * Copyright (C) 2008 Pippijn van Steenhoven + * Copyright (C) 2007-2008 Robin Burchell + * Copyright (C) 2007 Dennis Friis + * Copyright (C) 2006 Craig Edwards * - * This program is free but copyrighted software; see - * the file COPYING for details. + * This file is part of InspIRCd. InspIRCd is free software: you can + * redistribute it and/or modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation, version 2. * - * --------------------------------------------------- + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ + /* $ModDesc: Allows for MD5 encrypted oper passwords */ -/* $ModDep: m_hash.h */ #include "inspircd.h" #ifdef HAS_STDINT #include #endif -#include "m_hash.h" +#include "modules/hash.h" /* The four core functions - F1 is optimized somewhat */ #define F1(x, y, z) (z ^ (x & (y ^ z))) @@ -39,7 +48,7 @@ typedef unsigned char byte; /** An MD5 context, used by m_opermd5 */ -class MD5Context : public classbase +class MD5Context { public: word32 buf[4]; @@ -47,7 +56,7 @@ class MD5Context : public classbase word32 in[16]; }; -class ModuleMD5 : public Module +class MD5Provider : public HashProvider { void byteSwap(word32 *buf, unsigned words) { @@ -149,7 +158,7 @@ class ModuleMD5 : public Module byteSwap(ctx->buf, 4); memcpy(digest, ctx->buf, 16); - memset(ctx, 0, sizeof(ctx)); + memset(ctx, 0, sizeof(*ctx)); } void MD5Transform(word32 buf[4], word32 const in[16]) @@ -258,45 +267,29 @@ class ModuleMD5 : public Module } *dest++ = 0; } - public: - - ModuleMD5() + std::string sum(const std::string& data) { - ServerInstance->Modules->PublishInterface("HashRequest", this); - } - - virtual ~ModuleMD5() - { - ServerInstance->Modules->UnpublishInterface("HashRequest", this); + char res[16]; + MyMD5(res, (void*)data.data(), data.length(), NULL); + return std::string(res, 16); } + 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[33]; - HashRequest& req = static_cast(request); - GenHash(req.data.data(), res, "0123456789abcdef", NULL, req.data.length()); - req.result = res; - } - else if (strcmp("HASH-IV", request.id) == 0) - { - char res[33]; - HashRequestIV& req = static_cast(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(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); } };