]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/extra/m_ssl_openssl.cpp
delete operator tracking in debug mode (using a macro -- live with it.)
[user/henk/code/inspircd.git] / src / modules / extra / m_ssl_openssl.cpp
index 11e81806aba1bdb4f31b020edb2855aa0d2b0dc3..b1d8af21cdb6dac9fd877461e781f968ed3bf938 100644 (file)
@@ -5,6 +5,7 @@
 #include <openssl/err.h>
 
 #include "inspircd_config.h"
+#include "configreader.h"
 #include "users.h"
 #include "channels.h"
 #include "modules.h"
@@ -86,8 +87,8 @@ class ModuleSSLOpenSSL : public Module
                inbufsize = SrvConf->NetBufferSize;
                
                /* Global SSL library initialization*/
-      SSL_library_init();
-      SSL_load_error_strings();
+               SSL_library_init();
+               SSL_load_error_strings();
                
                /* Build our SSL context*/
                ctx = SSL_CTX_new( SSLv23_server_method() );
@@ -96,7 +97,7 @@ class ModuleSSLOpenSSL : public Module
                OnRehash("ssl");
        }
        
-       virtual void OnRehash(std::string param)
+       virtual void OnRehash(const std::string &param)
        {
                if(param != "ssl")
                        return;
@@ -189,7 +190,7 @@ class ModuleSSLOpenSSL : public Module
                {
                        log(DEFAULT, "m_ssl_openssl.so: Can't read CA list from ", cafile.c_str());
                }
-                               
+
                FILE* dhpfile = fopen(dhfile.c_str(), "r");
                DH* ret;
 
@@ -209,7 +210,7 @@ class ModuleSSLOpenSSL : public Module
                        log(DEFAULT, "m_ssl_openssl.so: Couldn't set DH parameters");
                }
 
-               delete Conf;
+               DELETE(Conf);
        }
 
        virtual ~ModuleSSLOpenSSL()
@@ -233,7 +234,7 @@ class ModuleSSLOpenSSL : public Module
                }
        }
        
-       virtual void OnUnloadModule(Module* mod, std::string name)
+       virtual void OnUnloadModule(Module* mod, const std::string &name)
        {
                if(mod == this)
                {
@@ -254,10 +255,10 @@ class ModuleSSLOpenSSL : public Module
        void Implements(char* List)
        {
                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] = 1;
+               List[I_OnSyncUserMetaData] = List[I_OnDecodeMetaData] = List[I_OnUnloadModule] = List[I_OnRehash] = List[I_OnWhois] = List[I_OnGlobalConnect] = 1;
        }
 
-       virtual void OnRawSocketAccept(int fd, std::string ip, int localport)
+       virtual void OnRawSocketAccept(int fd, const std::string &ip, int localport)
        {
                issl_session* session = &sessions[fd];
        
@@ -362,7 +363,7 @@ class ModuleSSLOpenSSL : public Module
                                                session->inbufoffset = 0;
                                        }
                                
-                                       log(DEBUG, "m_ssl_openssl.so: OnRawSocketRead: Passing %d bytes up to insp:");
+                                       log(DEBUG, "m_ssl_openssl.so: OnRawSocketRead: Passing %d bytes up to insp:", count);
                                        Srv->Log(DEBUG, std::string(buffer, readresult));
                                
                                        return 1;
@@ -528,13 +529,14 @@ class ModuleSSLOpenSSL : public Module
        // :kenny.chatspike.net 320 Om Epy|AFK :is a Secure Connection
        virtual void OnWhois(userrec* source, userrec* dest)
        {
-               if(dest->GetExt("ssl"))
+               // Bugfix, only send this numeric for *our* SSL users
+               if(dest->GetExt("ssl") && isin(dest->port, listenports))
                {
-                       WriteServ(source->fd, "320 %s %s :is a Secure Connection", source->nick, dest->nick);
+                       WriteServ(source->fd, "320 %s %s :is using a secure connection", source->nick, dest->nick);
                }
        }
        
-       virtual void OnSyncUserMetaData(userrec* user, Module* proto, void* opaque, std::string extname)
+       virtual void OnSyncUserMetaData(userrec* user, Module* proto, void* opaque, const std::string &extname)
        {
                // check if the linking module wants to know about OUR metadata
                if(extname == "ssl")
@@ -549,7 +551,7 @@ class ModuleSSLOpenSSL : public Module
                }
        }
        
-       virtual void OnDecodeMetaData(int target_type, void* target, std::string extname, std::string extdata)
+       virtual void OnDecodeMetaData(int target_type, void* target, const std::string &extname, const std::string &extdata)
        {
                // check if its our metadata key, and its associated with a user
                if ((target_type == TYPE_USER) && (extname == "ssl"))
@@ -567,7 +569,7 @@ class ModuleSSLOpenSSL : public Module
        {               
                int ret = SSL_accept(session->sess);
       
-      if(ret < 0)
+               if(ret < 0)
                {
                        int err = SSL_get_error(session->sess, ret);
                                
@@ -598,7 +600,12 @@ class ModuleSSLOpenSSL : public Module
                        log(DEBUG, "m_ssl_openssl.so: Handshake completed");
                        
                        // This will do for setting the ssl flag...it could be done earlier if it's needed. But this seems neater.
-                       Srv->FindDescriptor(session->fd)->Extend("ssl", "ON");
+                       userrec* u = Srv->FindDescriptor(session->fd);
+                       if (u)
+                       {
+                               if (!u->GetExt("ssl"))
+                                       u->Extend("ssl", "ON");
+                       }
                        
                        session->status = ISSL_OPEN;
                        
@@ -608,6 +615,24 @@ class ModuleSSLOpenSSL : public Module
                }
        }
        
+       virtual void OnGlobalConnect(userrec* user)
+       {
+               // This occurs AFTER OnUserConnect so we can be sure the
+               // protocol module has propogated the NICK message.
+               if ((user->GetExt("ssl")) && (IS_LOCAL(user)))
+               {
+                       // Tell whatever protocol module we're using that we need to inform other servers of this metadata NOW.
+                       std::deque<std::string>* metadata = new std::deque<std::string>;
+                       metadata->push_back(user->nick);
+                       metadata->push_back("ssl");             // The metadata id
+                       metadata->push_back("ON");              // The value to send
+                       Event* event = new Event((char*)metadata,(Module*)this,"send_metadata");
+                       event->Send();                          // Trigger the event. We don't care what module picks it up.
+                       DELETE(event);
+                       DELETE(metadata);
+               }
+       }
+       
        void MakePollWrite(issl_session* session)
        {
                OnRawSocketWrite(session->fd, NULL, 0);
@@ -655,4 +680,3 @@ extern "C" void * init_module( void )
 {
        return new ModuleSSLOpenSSLFactory;
 }
-