1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
7 * <brain@chatspike.net>
8 * <Craig@chatspike.net>
10 * Written by Craig Edwards, Craig McLure, and others.
11 * This program is free but copyrighted software; see
12 * the file COPYING for details.
14 * ---------------------------------------------------
17 /* $ModDesc: Allows for hashed oper passwords */
18 /* $ModDep: m_hash.h */
22 #include "inspircd_config.h"
38 class cmd_mkpasswd : public command_t
45 cmd_mkpasswd (InspIRCd* Instance, Module* Sender, Module* MD5Hasher, Module* SHAHasher, int P)
46 : command_t(Instance,"MKPASSWD", 'o', 2), MD5Provider(MD5Hasher), SHAProvider(SHAHasher), Prov(P)
48 this->source = "m_oper_hash.so";
49 syntax = "<hashtype> <any-text>";
52 void MakeHash(userrec* user, Module* ProviderMod, const char* algo, const char* stuff)
54 HashResetRequest(Sender, ProviderMod).Send();
55 user->WriteServ("NOTICE %s :%s hashed password for %s is %s",user->nick, algo, stuff, HashSumRequest(Sender, ProviderMod, stuff).Send() );
58 CmdResult Handle (const char** parameters, int pcnt, userrec *user)
60 if ((!strcasecmp(parameters[0], "MD5")) && ((Prov & PROV_MD5) > 0))
62 MakeHash(user, MD5Provider, "MD5", parameters[1]);
64 else if ((!strcasecmp(parameters[0], "SHA256")) && ((Prov & PROV_SHA) > 0))
66 MakeHash(user, SHAProvider, "SHA256", parameters[1]);
70 user->WriteServ("NOTICE %s :Unknown hash type, valid hash types are:%s%s", user->nick, ((Prov & PROV_MD5) > 0) ? " MD5" : "", ((Prov & PROV_SHA) > 0) ? " SHA256" : "");
73 /* NOTE: Don't propogate this across the network!
74 * We dont want plaintext passes going all over the place...
75 * To make sure it goes nowhere, return CMD_FAILURE!
81 class ModuleOperHash : public Module
84 cmd_mkpasswd* mycommand;
87 std::string providername;
93 ModuleOperHash(InspIRCd* Me)
100 modulelist* ml = ServerInstance->FindInterface("HashRequest");
104 ServerInstance->Log(DEBUG, "Found interface 'HashRequest' containing %d modules", ml->size());
107 /* Try to find the md5 service provider, bail if it can't be found */
108 MD5Provider = ServerInstance->FindModule("m_md5.so");
112 SHAProvider = ServerInstance->FindModule("m_sha256.so");
116 mycommand = new cmd_mkpasswd(ServerInstance, this, MD5Provider, SHAProvider, ID);
117 ServerInstance->AddCommand(mycommand);
120 virtual ~ModuleOperHash()
124 void Implements(char* List)
126 List[I_OnRehash] = List[I_OnOperCompare] = 1;
129 virtual void OnRehash(const std::string ¶meter)
134 Conf = new ConfigReader(ServerInstance);
137 virtual int OnOperCompare(const std::string &data, const std::string &input, int tagnumber)
139 std::string hashtype = Conf->ReadValue("oper", "hash", tagnumber);
140 Module* ModPtr = NULL;
142 if ((hashtype == "sha256") && (data.length() == SHA256_BLOCK_SIZE) && ((ID & PROV_SHA) > 0))
144 ModPtr = SHAProvider;
146 else if ((hashtype == "md5") && (data.length() == 32) && ((ID & PROV_MD5) > 0))
148 ModPtr = MD5Provider;
152 HashResetRequest(this, ModPtr).Send();
153 if (!strcasecmp(data.c_str(), HashSumRequest(this, ModPtr, input.c_str()).Send()))
161 virtual Version GetVersion()
163 return Version(1,1,0,1,VF_VENDOR,API_VERSION);
168 class ModuleOperHashFactory : public ModuleFactory
171 ModuleOperHashFactory()
175 ~ModuleOperHashFactory()
179 virtual Module * CreateModule(InspIRCd* Me)
181 return new ModuleOperHash(Me);
187 extern "C" void * init_module( void )
189 return new ModuleOperHashFactory;