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;
79 ModuleOperSSLCert(InspIRCd* Me)
83 mycommand = new cmd_fingerprint(ServerInstance);
84 ServerInstance->AddCommand(mycommand);
87 virtual ~ModuleOperSSLCert()
91 void Implements(char* List)
93 List[I_OnPreCommand] = 1;
97 bool OneOfMatches(const char* host, const char* ip, const char* hostlist)
99 std::stringstream hl(hostlist);
103 if (match(host,xhost.c_str()) || match(ip,xhost.c_str(),true))
112 virtual int OnPreCommand(const std::string &command, const char** parameters, int pcnt, userrec *user, bool validated, const std::string &original_line)
114 irc::string cmd = command.c_str();
116 if ((cmd == "OPER") && (validated))
118 char LoginName[MAXBUF];
119 char Password[MAXBUF];
120 char OperType[MAXBUF];
121 char HostName[MAXBUF];
122 char TheHost[MAXBUF];
124 char FingerPrint[MAXBUF];
126 snprintf(TheHost,MAXBUF,"%s@%s",user->ident,user->host);
127 snprintf(TheIP, MAXBUF,"%s@%s",user->ident,user->GetIPString());
129 HasCert = user->GetExt("ssl_cert",cert);
130 ServerInstance->Log(DEBUG,"HasCert=%d",HasCert);
131 for (int i = 0; i < ServerInstance->Config->ConfValueEnum(ServerInstance->Config->config_data, "oper"); i++)
133 ServerInstance->Config->ConfValue(ServerInstance->Config->config_data, "oper", "name", i, LoginName, MAXBUF);
134 ServerInstance->Config->ConfValue(ServerInstance->Config->config_data, "oper", "password", i, Password, MAXBUF);
135 ServerInstance->Config->ConfValue(ServerInstance->Config->config_data, "oper", "type", i, OperType, MAXBUF);
136 ServerInstance->Config->ConfValue(ServerInstance->Config->config_data, "oper", "host", i, HostName, MAXBUF);
137 ServerInstance->Config->ConfValue(ServerInstance->Config->config_data, "oper", "fingerprint", i, FingerPrint, MAXBUF);
141 if ((!strcmp(LoginName,parameters[0])) && (!ServerInstance->OperPassCompare(Password,parameters[1], i)) && (OneOfMatches(TheHost,TheIP,HostName)))
143 /* This oper would match */
144 if ((!cert) || (cert->GetFingerprint() != FingerPrint))
146 user->WriteServ("491 %s :This oper login name requires a matching key fingerprint.",user->nick);
147 ServerInstance->SNO->WriteToSnoMask('o',"'%s' cannot oper, does not match fingerprint", user->nick);
148 ServerInstance->Log(DEFAULT,"OPER: Failed oper attempt by %s!%s@%s: credentials valid, but wrong fingerprint.",user->nick,user->ident,user->host);
158 virtual Version GetVersion()
160 return Version(1,1,0,0,VF_VENDOR,API_VERSION);
164 class ModuleOperSSLCertFactory : public ModuleFactory
167 ModuleOperSSLCertFactory()
171 ~ModuleOperSSLCertFactory()
175 virtual Module * CreateModule(InspIRCd* Me)
177 return new ModuleOperSSLCert(Me);
183 extern "C" void * init_module( void )
185 return new ModuleOperSSLCertFactory;