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_md5.h m_sha256.h */
22 #include "inspircd_config.h"
39 class cmd_mkpasswd : public command_t
46 cmd_mkpasswd (InspIRCd* Instance, Module* Sender, Module* MD5Hasher, Module* SHAHasher, int P)
47 : command_t(Instance,"MKPASSWD", 'o', 2), MD5Provider(MD5Hasher), SHAProvider(SHAHasher), Prov(P)
49 this->source = "m_oper_hash.so";
50 syntax = "<hashtype> <any-text>";
53 CmdResult Handle (const char** parameters, int pcnt, userrec *user)
55 if (!strcasecmp(parameters[0], "md5"))
57 if ((Prov & PROV_MD5) > 0)
59 MD5ResetRequest(Sender, Provider).Send();
60 user->WriteServ("NOTICE %s :MD5 hashed password for %s is %s",user->nick, parameters[1], MD5SumRequest(Sender, Provider, parameters[1]).Send() );
64 user->WriteServ("NOTICE %s :MD5 hashing is not available (m_md5.so not loaded)");
67 else if (!strcasecmp(parameters[0], "sha256"))
69 if ((Prov & PROV_SHA) > 0)
71 SHA256ResetRequest(Sender, Provider).Send();
72 user->WriteServ("NOTICE %s :SHA256 hashed password for %s is %s",user->nick, parameters[1], SHA256SumRequest(Sender, Provider, parameters[1]).Send() );
76 user->WriteServ("NOTICE %s :SHA256 hashing is not available (m_sha256.so not loaded)");
81 user->WriteServ("NOTICE %s :Unknown hash type, valid hash types are 'sha256' and 'md5'");
84 /* NOTE: Don't propogate this across the network!
85 * We dont want plaintext passes going all over the place...
86 * To make sure it goes nowhere, return CMD_FAILURE!
92 class ModuleOperHash : public Module
95 cmd_mkpasswd* mycommand;
96 Module* MD5Provider, SHAProvider;
97 std::string providername;
103 ModuleOperHash(InspIRCd* Me)
104 : Module::Module(Me), Conf(NULL)
108 /* Try to find the md5 service provider, bail if it can't be found */
109 MD5Provider = ServerInstance->FindModule("m_md5.so");
113 SHAProvider = ServerInstance->FindModule("m_sha256.so");
117 mycommand = new cmd_mkpasswd(ServerInstance, this, MD5Provider, SHAProvider, ID);
118 ServerInstance->AddCommand(mycommand);
121 virtual ~ModuleOperHash()
125 void Implements(char* List)
127 List[I_OnRehash] = List[I_OnOperCompare] = 1;
130 virtual void OnRehash(const std::string ¶meter)
135 Conf = new ConfigReader(ServerInstance);
138 virtual int OnOperCompare(const std::string &data, const std::string &input, int tagnumber)
140 std::string hashtype = Conf->ReadValue("oper", "hash", tagnumber);
141 if ((hashtype == "sha256") && (data.length() == SHA256_BLOCK_SIZE) && ((ID & PROV_SHA) > 0))
143 SHA256ResetRequest(this, Provider).Send();
144 if (!strcasecmp(data.c_str(), SHA256SumRequest(this, Provider, input.c_str()).Send()))
148 else if ((hashtype == "md5") && (data.length() == 32) && ((ID & PROV_MD5) > 0))
150 MD5ResetRequest(this, Provider).Send();
151 if (!strcasecmp(data.c_str(), MD5SumRequest(this, Provider, input.c_str()).Send()))
158 virtual Version GetVersion()
160 return Version(1,1,0,1,VF_VENDOR,API_VERSION);
165 class ModuleOperHashFactory : public ModuleFactory
168 ModuleOperHashFactory()
172 ~ModuleOperHashFactory()
176 virtual Module * CreateModule(InspIRCd* Me)
178 return new ModuleOperHash(Me);
184 extern "C" void * init_module( void )
186 return new ModuleOperHashFactory;