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
45 cmd_mkpasswd (InspIRCd* Instance, Module* Sender, Module* Hasher, ProviderType P) : command_t(Instance,"MKPASSWD", 'o', 1), Provider(Hasher), Prov(P)
47 this->source = "m_oper_hash.so";
48 syntax = "<any-text>";
51 CmdResult Handle (const char** parameters, int pcnt, userrec *user)
55 MD5ResetRequest(Sender, Provider).Send();
56 user->WriteServ("NOTICE %s :MD5 hashed password for %s is %s",user->nick,parameters[0], MD5SumRequest(Sender, Provider, parameters[0]).Send() );
60 SHA256ResetRequest(Sender, Provider).Send();
61 user->WriteServ("NOTICE %s :SHA256 hashed password for %s is %s",user->nick,parameters[0], SHA256SumRequest(Sender, Provider, parameters[0]).Send() );
68 class ModuleOperHash : public Module
71 cmd_mkpasswd* mycommand;
73 std::string providername;
78 ModuleOperHash(InspIRCd* Me)
81 ConfigReader Conf(ServerInstance);
82 providername = Conf.ReadValue("operhash","algorithm",0);
84 if (providername.empty())
87 if (providername == "md5")
92 /* Try to find the md5 service provider, bail if it can't be found */
93 Provider = ServerInstance->FindModule(std::string("m_") + providername + ".so");
95 throw ModuleException(std::string("Can't find m_") + providername + ".so. Please load m_" + providername + ".so before m_oper_hash.so.");
97 mycommand = new cmd_mkpasswd(ServerInstance, this, Provider, ID);
98 ServerInstance->AddCommand(mycommand);
101 virtual ~ModuleOperHash()
105 void Implements(char* List)
107 List[I_OnOperCompare] = 1;
110 virtual int OnOperCompare(const std::string &data, const std::string &input)
112 /* always always reset first */
115 MD5ResetRequest(this, Provider).Send();
116 if (data.length() == 32) // if its 32 chars long, try it as an md5
118 /* Does it match the md5 sum? */
119 if (!strcasecmp(data.c_str(), MD5SumRequest(this, Provider, input.c_str()).Send()))
128 SHA256ResetRequest(this, Provider).Send();
129 if (data.length() == SHA256_BLOCK_SIZE)
131 if (!strcasecmp(data.c_str(), SHA256SumRequest(this, Provider, input.c_str()).Send()))
141 virtual Version GetVersion()
143 return Version(1,1,0,1,VF_VENDOR,API_VERSION);
148 class ModuleOperHashFactory : public ModuleFactory
151 ModuleOperHashFactory()
155 ~ModuleOperHashFactory()
159 virtual Module * CreateModule(InspIRCd* Me)
161 return new ModuleOperHash(Me);
167 extern "C" void * init_module( void )
169 return new ModuleOperHashFactory;