]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Add the stuff required for the InspSocketHook interface
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>
Sat, 9 Dec 2006 19:25:10 +0000 (19:25 +0000)
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>
Sat, 9 Dec 2006 19:25:10 +0000 (19:25 +0000)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@5890 e03df62e-2008-0410-955e-edbf42e46eb7

include/configreader.h
src/configreader.cpp
src/modules/extra/m_ssl_gnutls.cpp
src/modules/extra/m_ssl_openssl.cpp
src/modules/extra/ssl.h

index 2c048c849ba2598c4de2fb99e667a591db20d854..6c000eb60c35ed0b7b42ecf9ff921a0a933811d2 100644 (file)
@@ -564,7 +564,7 @@ class ServerConfig : public Extensible
        bool AddIOHook(int port, Module* iomod);
        bool DelIOHook(int port);
        Module* GetIOHook(InspSocket* is);
-       bool AddIOHook(InspSocket* is, Module* iomod);
+       bool AddIOHook(Module* iomod, InspSocket* is);
        bool DelIOHook(InspSocket* is);
 
        static std::string GetFullProgDir(char** argv, int argc);
index f7c867544c47c7606e8a783ec102a6bf4664f85c..7729cee6958b37f7788f1726e633feb153acaabe 100644 (file)
@@ -77,7 +77,7 @@ bool ServerConfig::AddIOHook(int port, Module* iomod)
        }
 }
 
-bool ServerConfig::AddIOHook(InspSocket* is, Module* iomod)
+bool ServerConfig::AddIOHook(Module* iomod, InspSocket* is)
 {
        if (!GetIOHook(is))
        {
index f53bea2d554bd4c09a007ed352c786b5968afc37..4f22a5e70421f6cf43e95075d1888268ca1947d5 100644 (file)
@@ -77,6 +77,8 @@ class ModuleSSLGnuTLS : public Module
                
 
                culllist = new CullList(ServerInstance);
+
+               ServerInstance->PublishInterface("InspSocketHook", this);
                
                // Not rehashable...because I cba to reduce all the sizes of existing buffers.
                inbufsize = ServerInstance->Config->NetBufferSize;
@@ -253,9 +255,28 @@ class ModuleSSLGnuTLS : public Module
        void Implements(char* List)
        {
                List[I_OnRawSocketConnect] = List[I_OnRawSocketAccept] = List[I_OnRawSocketClose] = List[I_OnRawSocketRead] = List[I_OnRawSocketWrite] = List[I_OnCleanup] = 1;
-               List[I_OnSyncUserMetaData] = List[I_OnDecodeMetaData] = List[I_OnUnloadModule] = List[I_OnRehash] = List[I_OnWhois] = List[I_OnPostConnect] = 1;
+               List[I_OnRequest] = List[I_OnSyncUserMetaData] = List[I_OnDecodeMetaData] = List[I_OnUnloadModule] = List[I_OnRehash] = List[I_OnWhois] = List[I_OnPostConnect] = 1;
        }
 
+        virtual char* OnRequest(Request* request)
+       {
+               ISHRequest* ISR = (ISHRequest*)request;
+               if (strcmp("IS_NAME", request->GetId()) == 0)
+               {
+                       return "gnutls";
+               }
+               else if (strcmp("IS_HOOK", request->GetId()) == 0)
+               {
+                       return ServerInstance->Config->AddIOHook((Module*)this, (InspSocket*)ISR->Sock) ? (char*)"OK" : NULL;
+               }
+               else if (strcmp("IS_UNHOOK", request->GetId()) == 0)
+               {
+                       return ServerInstance->Config->DelIOHook((InspSocket*)ISR->Sock) ? (char*)"OK" : NULL;
+               }
+               return NULL;
+       }
+
+
        virtual void OnRawSocketAccept(int fd, const std::string &ip, int localport)
        {
                issl_session* session = &sessions[fd];
@@ -633,7 +654,7 @@ class ModuleSSLGnuTLS : public Module
                session->status = ISSL_NONE;
        }
 
-       void VerifyCertificate(issl_session* session, userrec* user)
+       void VerifyCertificate(issl_session* session, Extensible* user)
        {
                unsigned int status;
                const gnutls_datum_t* cert_list;
@@ -743,7 +764,6 @@ class ModuleSSLGnuTLS : public Module
                else
                {
                        certinfo->data.insert(std::make_pair("fingerprint",irc::hex(digest, digest_size)));
-                       user->WriteServ("NOTICE %s :*** Your SSL Certificate fingerprint is: %s", user->nick, irc::hex(digest, digest_size).c_str());
                }
 
                /* Beware here we do not check for errors.
index 338246e279bbb9c8d5ee741e678cb98bc8ee4bad..0da67d6777bffc85e2d67765bafac43253cbdf2a 100644 (file)
@@ -105,6 +105,8 @@ class ModuleSSLOpenSSL : public Module
                : Module::Module(Me)
        {
                culllist = new CullList(ServerInstance);
+
+               ServerInstance->PublishInterface("InspSocketHook", this);
                
                // Not rehashable...because I cba to reduce all the sizes of existing buffers.
                inbufsize = ServerInstance->Config->NetBufferSize;
@@ -288,9 +290,28 @@ class ModuleSSLOpenSSL : public Module
        void Implements(char* List)
        {
                List[I_OnRawSocketConnect] = List[I_OnRawSocketAccept] = List[I_OnRawSocketClose] = List[I_OnRawSocketRead] = List[I_OnRawSocketWrite] = List[I_OnCleanup] = 1;
-               List[I_OnSyncUserMetaData] = List[I_OnDecodeMetaData] = List[I_OnUnloadModule] = List[I_OnRehash] = List[I_OnWhois] = List[I_OnPostConnect] = 1;
+               List[I_OnRequest] = List[I_OnSyncUserMetaData] = List[I_OnDecodeMetaData] = List[I_OnUnloadModule] = List[I_OnRehash] = List[I_OnWhois] = List[I_OnPostConnect] = 1;
+       }
+
+       virtual char* OnRequest(Request* request)
+       {
+               ISHRequest* ISR = (ISHRequest*)request;
+               if (strcmp("IS_NAME", request->GetId()) == 0)
+               {
+                       return "openssl";
+               }
+               else if (strcmp("IS_HOOK", request->GetId()) == 0)
+               {
+                       return ServerInstance->Config->AddIOHook((Module*)this, (InspSocket*)ISR->Sock) ? (char*)"OK" : NULL;
+               }
+               else if (strcmp("IS_UNHOOK", request->GetId()) == 0)
+               {
+                       return ServerInstance->Config->DelIOHook((InspSocket*)ISR->Sock) ? (char*)"OK" : NULL;
+               }
+               return NULL;
        }
 
+
        virtual void OnRawSocketAccept(int fd, const std::string &ip, int localport)
        {
                issl_session* session = &sessions[fd];
@@ -714,7 +735,7 @@ class ModuleSSLOpenSSL : public Module
                session->status = ISSL_NONE;
        }
 
-       void VerifyCertificate(issl_session* session, userrec* user)
+       void VerifyCertificate(issl_session* session, Extensible* user)
        {
                X509* cert;
                ssl_cert* certinfo = new ssl_cert;
@@ -757,8 +778,6 @@ class ModuleSSLOpenSSL : public Module
                        certinfo->data.insert(std::make_pair("fingerprint",irc::hex(md, n)));
                }
 
-               user->WriteServ("NOTICE %s :*** Your SSL Certificate fingerprint is: %s", user->nick, irc::hex(md, n).c_str());
-
                if ((ASN1_UTCTIME_cmp_time_t(X509_get_notAfter(cert), time(NULL)) == -1) || (ASN1_UTCTIME_cmp_time_t(X509_get_notBefore(cert), time(NULL)) == 0))
                {
                        certinfo->data.insert(std::make_pair("error","Not activated, or expired certificate"));
index 6768a31a2c4661b34536e2936f781a00d695a581..e636aad46b379144f243847a36891d47b3b576e7 100644 (file)
@@ -149,5 +149,42 @@ class ssl_cert
        }
 };
 
+class ISHRequest : public Request
+{
+ public:
+       const InspSocket* Sock;
+
+       ISHRequest(Module* Me, Module* Target, const char* rtype, InspSocket* sock) : Request(Me, Target, rtype), Sock(sock)
+       {
+       }
+};
+
+class InspSocketHookRequest : public ISHRequest
+{
+ public:
+       /** Initialize request as a hook message */
+       InspSocketHookRequest(InspSocket* is, Module* Me, Module* Target) : ISHRequest(Me, Target, "IS_HOOK", is)
+       {
+       }
+};
+
+class InspSocketUnhookRequest : public ISHRequest
+{
+ public:
+       /** Initialize request as an unhook message */
+       InspSocketUnhookRequest(InspSocket* is, Module* Me, Module* Target) : ISHRequest(Me, Target, "IS_UNHOOK", is)
+       {
+       }
+};
+
+class InspSocketNameRequest : public ISHRequest
+{
+ public:
+       /** Initialize request as a get name message */
+       InspSocketNameRequest(Module* Me, Module* Target) : ISHRequest(Me, Target, "IS_NAME", NULL)
+       {
+       }
+};
+
 #endif