]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/extra/m_sslinfo.cpp
Set errno properly on GnuTLS sessions that die during the SSL handshake
[user/henk/code/inspircd.git] / src / modules / extra / m_sslinfo.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include "inspircd.h"
15 #include "transport.h"
16
17 /* $ModDesc: Provides /sslinfo command used to test who a mask matches */
18 /* $ModDep: transport.h */
19
20 /** Handle /SSLINFO
21  */
22 class CommandSSLInfo : public Command
23 {
24  public:
25         CommandSSLInfo (InspIRCd* Instance) : Command(Instance,"SSLINFO", 0, 1)
26         {
27                 this->source = "m_sslinfo.so";
28                 this->syntax = "<nick>";
29         }
30
31         CmdResult Handle (const std::vector<std::string> &parameters, User *user)
32         {
33                 User* target = ServerInstance->FindNick(parameters[0]);
34                 ssl_cert* cert;
35
36                 if (target)
37                 {
38                         if (target->GetExt("ssl_cert", cert))
39                         {
40                                 if (cert->GetError().length())
41                                 {
42                                         user->WriteServ("NOTICE %s :*** No SSL certificate information for this user (%s).", user->nick.c_str(), cert->GetError().c_str());
43                                 }
44                                 else
45                                 {
46                                         user->WriteServ("NOTICE %s :*** Distinguised Name: %s", user->nick.c_str(), cert->GetDN().c_str());
47                                         user->WriteServ("NOTICE %s :*** Issuer:            %s", user->nick.c_str(), cert->GetIssuer().c_str());
48                                         user->WriteServ("NOTICE %s :*** Key Fingerprint:   %s", user->nick.c_str(), cert->GetFingerprint().c_str());
49                                 }
50                                 return CMD_LOCALONLY;
51                         }
52                         else
53                         {
54                                 user->WriteServ("NOTICE %s :*** No SSL certificate information for this user.", user->nick.c_str());
55                                 return CMD_FAILURE;
56                         }
57                 }
58                 else
59                         user->WriteNumeric(ERR_NOSUCHNICK, "%s %s :No such nickname", user->nick.c_str(), parameters[0].c_str());
60
61                 return CMD_FAILURE;
62         }
63 };
64
65 class ModuleSSLInfo : public Module
66 {
67         CommandSSLInfo* newcommand;
68  public:
69         ModuleSSLInfo(InspIRCd* Me)
70                 : Module(Me)
71         {
72
73                 newcommand = new CommandSSLInfo(ServerInstance);
74                 ServerInstance->AddCommand(newcommand);
75
76         }
77
78
79         virtual ~ModuleSSLInfo()
80         {
81         }
82
83         virtual Version GetVersion()
84         {
85                 return Version("$Id$", VF_VENDOR, API_VERSION);
86         }
87 };
88
89 MODULE_INIT(ModuleSSLInfo)
90