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"
32 class cmd_mkpasswd : public command_t
35 std::map<std::string, Module*> &hashers;
36 std::deque<std::string> &names;
38 cmd_mkpasswd (InspIRCd* Instance, Module* S, std::map<std::string, Module*> &h, std::deque<std::string> &n)
39 : command_t(Instance,"MKPASSWD", 'o', 2), Sender(S), hashers(h), names(n)
41 this->source = "m_oper_hash.so";
42 syntax = "<hashtype> <any-text>";
45 void MakeHash(userrec* user, const char* algo, const char* stuff)
47 std::map<std::string, Module*>::iterator x = hashers.find(algo);
48 if (x != hashers.end())
50 HashResetRequest(Sender, x->second).Send();
51 user->WriteServ("NOTICE %s :%s hashed password for %s is %s",user->nick, algo, stuff, HashSumRequest(Sender, x->second, stuff).Send() );
55 user->WriteServ("NOTICE %s :Unknown hash type, valid hash types are: %s", user->nick, irc::stringjoiner(",", names, 0, names.size() - 1).GetJoined().c_str() );
59 CmdResult Handle (const char** parameters, int pcnt, userrec *user)
61 MakeHash(user, parameters[0], parameters[1]);
62 /* NOTE: Don't propogate this across the network!
63 * We dont want plaintext passes going all over the place...
64 * To make sure it goes nowhere, return CMD_FAILURE!
70 class ModuleOperHash : public Module
73 cmd_mkpasswd* mycommand;
75 std::map<std::string, Module*> hashers;
76 std::deque<std::string> names;
81 ModuleOperHash(InspIRCd* Me)
87 modulelist* ml = ServerInstance->FindInterface("HashRequest");
91 ServerInstance->Log(DEBUG, "Found interface 'HashRequest' containing %d modules", ml->size());
93 for (modulelist::iterator m = ml->begin(); m != ml->end(); m++)
95 std::string name = HashNameRequest(this, *m).Send();
97 names.push_back(name);
98 ServerInstance->Log(DEBUG, "Found HashRequest interface: '%s' -> '%08x'", name.c_str(), *m);
102 mycommand = new cmd_mkpasswd(ServerInstance, this, hashers, names);
103 ServerInstance->AddCommand(mycommand);
106 virtual ~ModuleOperHash()
110 void Implements(char* List)
112 List[I_OnRehash] = List[I_OnOperCompare] = 1;
115 virtual void OnRehash(const std::string ¶meter)
120 Conf = new ConfigReader(ServerInstance);
123 virtual int OnOperCompare(const std::string &data, const std::string &input, int tagnumber)
125 std::string hashtype = Conf->ReadValue("oper", "hash", tagnumber);
126 std::map<std::string, Module*>::iterator x = hashers.find(hashtype);
128 if (x != hashers.end())
130 HashResetRequest(this, x->second).Send();
131 if (!strcasecmp(data.c_str(), HashSumRequest(this, x->second, input.c_str()).Send()))
139 virtual Version GetVersion()
141 return Version(1,1,0,1,VF_VENDOR,API_VERSION);
146 class ModuleOperHashFactory : public ModuleFactory
149 ModuleOperHashFactory()
153 ~ModuleOperHashFactory()
157 virtual Module * CreateModule(InspIRCd* Me)
159 return new ModuleOperHash(Me);
165 extern "C" void * init_module( void )
167 return new ModuleOperHashFactory;