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 MD5 encrypted oper passwords */
22 #include "inspircd_config.h"
29 class cmd_fingerprint : public command_t
32 cmd_fingerprint (InspIRCd* Instance) : command_t(Instance,"FINGERPRINT", 0, 1)
34 this->source = "m_ssl_oper_cert.so";
35 syntax = "<nickname>";
38 void Handle (const char** parameters, int pcnt, userrec *user)
40 userrec* target = ServerInstance->FindNick(parameters[0]);
44 if (target->GetExt("ssl_cert",cert))
46 if (cert->GetFingerprint().length())
47 user->WriteServ("NOTICE %s :Certificate fingerprint for %s is %s",user->nick,target->nick,cert->GetFingerprint().c_str());
49 user->WriteServ("NOTICE %s :Certificate fingerprint for %s does not exist!", user->nick,target->nick);
53 user->WriteServ("NOTICE %s :Certificate fingerprint for %s does not exist!", user->nick, target->nick);
58 user->WriteServ("401 %s %s :No such nickname", user->nick, parameters[0]);
64 class ModuleOperSSLCert : public Module
68 cmd_fingerprint* mycommand;
71 ModuleOperSSLCert(InspIRCd* Me)
75 mycommand = new cmd_fingerprint(ServerInstance);
76 ServerInstance->AddCommand(mycommand);
79 virtual ~ModuleOperSSLCert()
83 void Implements(char* List)
85 List[I_OnOperCompare] = List[I_OnPreCommand] = 1;
88 virtual int OnOperCompare(const std::string &data, const std::string &input)
90 ServerInstance->Log(DEBUG,"HasCert=%d, data='%s' input='%s'",HasCert,data.c_str(), input.c_str());
91 if ((HasCert) && ((data.length()) && (data.length() == cert->GetFingerprint().length())))
93 ServerInstance->Log(DEBUG,"Lengths match, cert='%s'",cert->GetFingerprint().c_str());
94 if (data == cert->GetFingerprint())
96 ServerInstance->Log(DEBUG,"Return 1");
101 /* Someones playing silly buggers, and entering in literals asa the oper pass */
102 if (input == cert->GetFingerprint())
105 ServerInstance->Log(DEBUG,"'%s' != '%s'",data.c_str(), cert->GetFingerprint().c_str());
111 ServerInstance->Log(DEBUG,"Lengths dont match");
116 virtual int OnPreCommand(const std::string &command, const char** parameters, int pcnt, userrec *user, bool validated)
118 irc::string cmd = command.c_str();
120 if ((cmd == "OPER") && (validated == 1))
122 HasCert = user->GetExt("ssl_cert",cert);
123 ServerInstance->Log(DEBUG,"HasCert=%d",HasCert);
128 virtual Version GetVersion()
130 return Version(1,1,0,0,VF_VENDOR);
134 class ModuleOperSSLCertFactory : public ModuleFactory
137 ModuleOperSSLCertFactory()
141 ~ModuleOperSSLCertFactory()
145 virtual Module * CreateModule(InspIRCd* Me)
147 return new ModuleOperSSLCert(Me);
153 extern "C" void * init_module( void )
155 return new ModuleOperSSLCertFactory;