]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_opermd5.cpp
6e779f19b4704da43688ec3b4e4afab76861687d
[user/henk/code/inspircd.git] / src / modules / m_opermd5.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
6  *                       E-mail:
7  *                <brain@chatspike.net>
8  *                <Craig@chatspike.net>
9  *     
10  * Written by Craig Edwards, Craig McLure, and others.
11  * This program is free but copyrighted software; see
12  *            the file COPYING for details.
13  *
14  * ---------------------------------------------------
15  */
16
17 /* $ModDesc: Allows for MD5 encrypted oper passwords */
18 /* $ModDep: m_md5.h */
19
20 using namespace std;
21
22 #include "inspircd_config.h"
23 #include "users.h"
24 #include "channels.h"
25 #include "modules.h"
26 #include "inspircd.h"
27
28 #include "m_md5.h"
29
30 /* Handle /MKPASSWD
31  */
32 class cmd_mkpasswd : public command_t
33 {
34         Module* MD5Provider;
35         Module* Sender;
36  public:
37         cmd_mkpasswd (InspIRCd* Instance, Module* Sender, Module* MD5) : command_t(Instance,"MKPASSWD", 'o', 1), MD5Provider(MD5)
38         {
39                 this->source = "m_opermd5.so";
40                 syntax = "<any-text>";
41         }
42
43         CmdResult Handle (const char** parameters, int pcnt, userrec *user)
44         {
45                 MD5ResetRequest(Sender, MD5Provider).Send();
46                 user->WriteServ("NOTICE %s :MD5 hashed password for %s is %s",user->nick,parameters[0], MD5SumRequest(Sender, MD5Provider, parameters[0]).Send() );
47                 return CMD_SUCCESS;
48         }
49 };
50
51 class ModuleOperMD5 : public Module
52 {
53         
54         cmd_mkpasswd* mycommand;
55         Module* MD5Provider;
56
57  public:
58
59         ModuleOperMD5(InspIRCd* Me)
60                 : Module::Module(Me)
61         {
62                 MD5Provider = ServerInstance->FindModule("m_md5.so");
63                 if (!MD5Provider)
64                         throw ModuleException("Can't find m_md5.so. Please load m_md5.so before m_opermd5.so.");
65
66                 mycommand = new cmd_mkpasswd(ServerInstance, this, MD5Provider);
67                 ServerInstance->AddCommand(mycommand);
68         }
69         
70         virtual ~ModuleOperMD5()
71         {
72         }
73
74         void Implements(char* List)
75         {
76                 List[I_OnOperCompare] = 1;
77         }
78
79         virtual int OnOperCompare(const std::string &data, const std::string &input)
80         {
81                 MD5ResetRequest(this, MD5Provider).Send();
82                 if (data.length() == 32) // if its 32 chars long, try it as an md5
83                 {
84                         if (!strcasecmp(data.c_str(), MD5SumRequest(this, MD5Provider, input.c_str()).Send()))
85                         {
86                                 return 1;
87                         }
88                         else return 0;
89                 }
90                 return 0;
91         }
92         
93         virtual Version GetVersion()
94         {
95                 return Version(1,1,0,1,VF_VENDOR,API_VERSION);
96         }
97 };
98
99
100 class ModuleOperMD5Factory : public ModuleFactory
101 {
102  public:
103         ModuleOperMD5Factory()
104         {
105         }
106         
107         ~ModuleOperMD5Factory()
108         {
109         }
110         
111         virtual Module * CreateModule(InspIRCd* Me)
112         {
113                 return new ModuleOperMD5(Me);
114         }
115         
116 };
117
118
119 extern "C" void * init_module( void )
120 {
121         return new ModuleOperMD5Factory;
122 }