1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2007 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
14 /* $ModDesc: Allows for MD5 encrypted oper passwords */
15 /* $ModDep: transport.h */
18 #include "inspircd_config.h"
23 #include "transport.h"
26 /** Handle /FINGERPRINT
28 class cmd_fingerprint : public command_t
31 cmd_fingerprint (InspIRCd* Instance) : command_t(Instance,"FINGERPRINT", 0, 1)
33 this->source = "m_ssl_oper_cert.so";
34 syntax = "<nickname>";
37 CmdResult Handle (const char** parameters, int pcnt, userrec *user)
39 userrec* target = ServerInstance->FindNick(parameters[0]);
43 if (target->GetExt("ssl_cert",cert))
45 if (cert->GetFingerprint().length())
47 user->WriteServ("NOTICE %s :Certificate fingerprint for %s is %s",user->nick,target->nick,cert->GetFingerprint().c_str());
52 user->WriteServ("NOTICE %s :Certificate fingerprint for %s does not exist!", user->nick,target->nick);
58 user->WriteServ("NOTICE %s :Certificate fingerprint for %s does not exist!", user->nick, target->nick);
64 user->WriteServ("401 %s %s :No such nickname", user->nick, parameters[0]);
72 class ModuleOperSSLCert : public Module
76 cmd_fingerprint* mycommand;
80 ModuleOperSSLCert(InspIRCd* Me)
83 mycommand = new cmd_fingerprint(ServerInstance);
84 ServerInstance->AddCommand(mycommand);
85 cf = new ConfigReader(ServerInstance);
88 virtual ~ModuleOperSSLCert()
93 void Implements(char* List)
95 List[I_OnPreCommand] = List[I_OnRehash] = 1;
98 virtual void OnRehash(userrec* user, const std::string ¶meter)
101 cf = new ConfigReader(ServerInstance);
104 bool OneOfMatches(const char* host, const char* ip, const char* hostlist)
106 std::stringstream hl(hostlist);
110 if (match(host,xhost.c_str()) || match(ip,xhost.c_str(),true))
119 virtual int OnPreCommand(const std::string &command, const char** parameters, int pcnt, userrec *user, bool validated, const std::string &original_line)
121 irc::string cmd = command.c_str();
123 if ((cmd == "OPER") && (validated))
125 char TheHost[MAXBUF];
127 std::string LoginName;
128 std::string Password;
129 std::string OperType;
130 std::string HostName;
131 std::string FingerPrint;
135 snprintf(TheHost,MAXBUF,"%s@%s",user->ident,user->host);
136 snprintf(TheIP, MAXBUF,"%s@%s",user->ident,user->GetIPString());
138 HasCert = user->GetExt("ssl_cert",cert);
140 for (int i = 0; i < cf->Enumerate("oper"); i++)
142 LoginName = cf->ReadValue("oper", "name", i);
143 Password = cf->ReadValue("oper", "password", i);
144 OperType = cf->ReadValue("oper", "type", i);
145 HostName = cf->ReadValue("oper", "host", i);
146 FingerPrint = cf->ReadValue("oper", "fingerprint", i);
147 SSLOnly = cf->ReadFlag("oper", "sslonly", i);
149 if (SSLOnly || !FingerPrint.empty())
151 if ((!strcmp(LoginName.c_str(),parameters[0])) && (!ServerInstance->OperPassCompare(Password.c_str(),parameters[1],i)) && (OneOfMatches(TheHost,TheIP,HostName.c_str())))
153 if (SSLOnly && !user->GetExt("ssl", dummy))
155 user->WriteServ("491 %s :This oper login name requires an SSL connection.", user->nick);
159 /* This oper would match */
160 if ((!cert) || (cert->GetFingerprint() != FingerPrint))
162 user->WriteServ("491 %s :This oper login name requires a matching key fingerprint.",user->nick);
163 ServerInstance->SNO->WriteToSnoMask('o',"'%s' cannot oper, does not match fingerprint", user->nick);
164 ServerInstance->Log(DEFAULT,"OPER: Failed oper attempt by %s!%s@%s: credentials valid, but wrong fingerprint.",user->nick,user->ident,user->host);
174 virtual Version GetVersion()
176 return Version(1,1,0,0,VF_VENDOR,API_VERSION);
180 class ModuleOperSSLCertFactory : public ModuleFactory
183 ModuleOperSSLCertFactory()
187 ~ModuleOperSSLCertFactory()
191 virtual Module * CreateModule(InspIRCd* Me)
193 return new ModuleOperSSLCert(Me);
199 extern "C" void * init_module( void )
201 return new ModuleOperSSLCertFactory;