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 */
23 #include "inspircd_config.h"
31 /** Handle /FINGERPRINT
33 class cmd_fingerprint : public command_t
36 cmd_fingerprint (InspIRCd* Instance) : command_t(Instance,"FINGERPRINT", 0, 1)
38 this->source = "m_ssl_oper_cert.so";
39 syntax = "<nickname>";
42 CmdResult Handle (const char** parameters, int pcnt, userrec *user)
44 userrec* target = ServerInstance->FindNick(parameters[0]);
48 if (target->GetExt("ssl_cert",cert))
50 if (cert->GetFingerprint().length())
52 user->WriteServ("NOTICE %s :Certificate fingerprint for %s is %s",user->nick,target->nick,cert->GetFingerprint().c_str());
57 user->WriteServ("NOTICE %s :Certificate fingerprint for %s does not exist!", user->nick,target->nick);
63 user->WriteServ("NOTICE %s :Certificate fingerprint for %s does not exist!", user->nick, target->nick);
69 user->WriteServ("401 %s %s :No such nickname", user->nick, parameters[0]);
77 class ModuleOperSSLCert : public Module
81 cmd_fingerprint* mycommand;
84 ModuleOperSSLCert(InspIRCd* Me)
88 mycommand = new cmd_fingerprint(ServerInstance);
89 ServerInstance->AddCommand(mycommand);
92 virtual ~ModuleOperSSLCert()
96 void Implements(char* List)
98 List[I_OnPreCommand] = 1;
102 bool OneOfMatches(const char* host, const char* ip, const char* hostlist)
104 std::stringstream hl(hostlist);
108 if (match(host,xhost.c_str()) || match(ip,xhost.c_str(),true))
117 virtual int OnPreCommand(const std::string &command, const char** parameters, int pcnt, userrec *user, bool validated, const std::string &original_line)
119 irc::string cmd = command.c_str();
121 if ((cmd == "OPER") && (validated))
123 char LoginName[MAXBUF];
124 char Password[MAXBUF];
125 char OperType[MAXBUF];
126 char HostName[MAXBUF];
127 char TheHost[MAXBUF];
129 char FingerPrint[MAXBUF];
131 snprintf(TheHost,MAXBUF,"%s@%s",user->ident,user->host);
132 snprintf(TheIP, MAXBUF,"%s@%s",user->ident,user->GetIPString());
134 HasCert = user->GetExt("ssl_cert",cert);
135 ServerInstance->Log(DEBUG,"HasCert=%d",HasCert);
136 for (int i = 0; i < ServerInstance->Config->ConfValueEnum(ServerInstance->Config->config_data, "oper"); i++)
138 ServerInstance->Config->ConfValue(ServerInstance->Config->config_data, "oper", "name", i, LoginName, MAXBUF);
139 ServerInstance->Config->ConfValue(ServerInstance->Config->config_data, "oper", "password", i, Password, MAXBUF);
140 ServerInstance->Config->ConfValue(ServerInstance->Config->config_data, "oper", "type", i, OperType, MAXBUF);
141 ServerInstance->Config->ConfValue(ServerInstance->Config->config_data, "oper", "host", i, HostName, MAXBUF);
142 ServerInstance->Config->ConfValue(ServerInstance->Config->config_data, "oper", "fingerprint", i, FingerPrint, MAXBUF);
146 if ((!strcmp(LoginName,parameters[0])) && (!ServerInstance->OperPassCompare(Password,parameters[1], i)) && (OneOfMatches(TheHost,TheIP,HostName)))
148 /* This oper would match */
149 if ((!cert) || (cert->GetFingerprint() != FingerPrint))
151 user->WriteServ("491 %s :This oper login name requires a matching key fingerprint.",user->nick);
152 ServerInstance->SNO->WriteToSnoMask('o',"'%s' cannot oper, does not match fingerprint", user->nick);
153 ServerInstance->Log(DEFAULT,"OPER: Failed oper attempt by %s!%s@%s: credentials valid, but wrong fingerprint.",user->nick,user->ident,user->host);
163 virtual Version GetVersion()
165 return Version(1,1,0,0,VF_VENDOR,API_VERSION);
169 class ModuleOperSSLCertFactory : public ModuleFactory
172 ModuleOperSSLCertFactory()
176 ~ModuleOperSSLCertFactory()
180 virtual Module * CreateModule(InspIRCd* Me)
182 return new ModuleOperSSLCert(Me);
188 extern "C" void * init_module( void )
190 return new ModuleOperSSLCertFactory;