]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/extra/m_ssl_openssl.cpp
All of insp now builds with -pedantic (theres some warnings to squash in modules...
[user/henk/code/inspircd.git] / src / modules / extra / m_ssl_openssl.cpp
index 8e8b03b85014bc2d241e1858ab2622cc0928c532..5355e18557135f4b6b9f0a2899e02776f5dd6819 100644 (file)
@@ -130,7 +130,7 @@ class ModuleSSLOpenSSL : public Module
        ModuleSSLOpenSSL(InspIRCd* Me)
        : Module(Me), PublicInstance(Me)
        {
-               ServerInstance->Modules->PublishInterface("InspSocketHook", this);
+               ServerInstance->Modules->PublishInterface("BufferedSocketHook", this);
 
                // Not rehashable...because I cba to reduce all the sizes of existing buffers.
                inbufsize = ServerInstance->Config->NetBufferSize;
@@ -152,7 +152,7 @@ class ModuleSSLOpenSSL : public Module
                OnRehash(NULL,"ssl");
        }
 
-       virtual void OnRehash(userrec* user, const std::string &param)
+       virtual void OnRehash(User* user, const std::string &param)
        {
                if (param != "ssl")
                        return;
@@ -301,13 +301,13 @@ class ModuleSSLOpenSSL : public Module
        {
                if (target_type == TYPE_USER)
                {
-                       userrec* user = (userrec*)item;
+                       User* user = (User*)item;
 
                        if (user->GetExt("ssl", dummy) && IS_LOCAL(user) && isin(user->GetPort(), listenports))
                        {
                                // User is using SSL, they're a local user, and they're using one of *our* SSL ports.
                                // Potentially there could be multiple SSL modules loaded at once on different ports.
-                               userrec::QuitUser(ServerInstance, user, "SSL module unloading");
+                               User::QuitUser(ServerInstance, user, "SSL module unloading");
                        }
                        if (user->GetExt("ssl_cert", dummy) && isin(user->GetPort(), listenports))
                        {
@@ -356,7 +356,7 @@ class ModuleSSLOpenSSL : public Module
                        char* ret = "OK";
                        try
                        {
-                               ret = ServerInstance->Config->AddIOHook((Module*)this, (InspSocket*)ISR->Sock) ? (char*)"OK" : NULL;
+                               ret = ServerInstance->Config->AddIOHook((Module*)this, (BufferedSocket*)ISR->Sock) ? (char*)"OK" : NULL;
                        }
                        catch (ModuleException &e)
                        {
@@ -367,11 +367,10 @@ class ModuleSSLOpenSSL : public Module
                }
                else if (strcmp("IS_UNHOOK", request->GetId()) == 0)
                {
-                       return ServerInstance->Config->DelIOHook((InspSocket*)ISR->Sock) ? (char*)"OK" : NULL;
+                       return ServerInstance->Config->DelIOHook((BufferedSocket*)ISR->Sock) ? (char*)"OK" : NULL;
                }
                else if (strcmp("IS_HSDONE", request->GetId()) == 0)
                {
-                       ServerInstance->Log(DEBUG,"Module checking if handshake is done");
                        if (ISR->Sock->GetFd() < 0)
                                return (char*)"OK";
 
@@ -383,7 +382,7 @@ class ModuleSSLOpenSSL : public Module
                        issl_session* session = &sessions[ISR->Sock->GetFd()];
                        if (session->sess)
                        {
-                               VerifyCertificate(session, (InspSocket*)ISR->Sock);
+                               VerifyCertificate(session, (BufferedSocket*)ISR->Sock);
                                return "OK";
                        }
                }
@@ -393,6 +392,10 @@ class ModuleSSLOpenSSL : public Module
 
        virtual void OnRawSocketAccept(int fd, const std::string &ip, int localport)
        {
+               /* Are there any possibilities of an out of range fd? Hope not, but lets be paranoid */
+               if ((fd < 0) || (fd > MAX_DESCRIPTORS))
+                       return;
+
                issl_session* session = &sessions[fd];
 
                session->fd = fd;
@@ -416,6 +419,10 @@ class ModuleSSLOpenSSL : public Module
 
        virtual void OnRawSocketConnect(int fd)
        {
+                /* Are there any possibilities of an out of range fd? Hope not, but lets be paranoid */
+               if ((fd < 0) || (fd > MAX_DESCRIPTORS))
+                       return;
+
                issl_session* session = &sessions[fd];
 
                session->fd = fd;
@@ -439,6 +446,10 @@ class ModuleSSLOpenSSL : public Module
 
        virtual void OnRawSocketClose(int fd)
        {
+               /* Are there any possibilities of an out of range fd? Hope not, but lets be paranoid */
+               if ((fd < 0) || (fd > MAX_DESCRIPTORS))
+                       return;
+
                CloseSession(&sessions[fd]);
 
                EventHandler* user = ServerInstance->SE->GetRef(fd);
@@ -454,6 +465,10 @@ class ModuleSSLOpenSSL : public Module
 
        virtual int OnRawSocketRead(int fd, char* buffer, unsigned int count, int &readresult)
        {
+               /* Are there any possibilities of an out of range fd? Hope not, but lets be paranoid */
+               if ((fd < 0) || (fd > MAX_DESCRIPTORS))
+                       return 0;
+
                issl_session* session = &sessions[fd];
 
                if (!session->sess)
@@ -495,10 +510,6 @@ class ModuleSSLOpenSSL : public Module
                        {
                                int ret = DoRead(session);
 
-                               ServerInstance->Log(DEBUG, "<***> DoRead count: " + ConvToStr(count));
-                               ServerInstance->Log(DEBUG, "<***> DoRead ret: " + ConvToStr(ret));
-                               ServerInstance->Log(DEBUG, "<***> DoRead session->inbufoffset: " + ConvToStr(session->inbufoffset));
-
                                if (ret > 0)
                                {
                                        if (count <= session->inbufoffset)
@@ -520,13 +531,9 @@ class ModuleSSLOpenSSL : public Module
                                                // Zero the offset, as there's nothing there..
                                                session->inbufoffset = 0;
                                        }
-
                                        return 1;
                                }
-                               else
-                               {
-                                       return ret;
-                               }
+                               return ret;
                        }
                }
 
@@ -535,6 +542,10 @@ class ModuleSSLOpenSSL : public Module
 
        virtual int OnRawSocketWrite(int fd, const char* buffer, int count)
        {
+               /* Are there any possibilities of an out of range fd? Hope not, but lets be paranoid */
+               if ((fd < 0) || (fd > MAX_DESCRIPTORS))
+                       return 0;
+
                issl_session* session = &sessions[fd];
 
                if (!session->sess)
@@ -657,7 +668,7 @@ class ModuleSSLOpenSSL : public Module
        }
 
        // :kenny.chatspike.net 320 Om Epy|AFK :is a Secure Connection
-       virtual void OnWhois(userrec* source, userrec* dest)
+       virtual void OnWhois(User* source, User* dest)
        {
                if (!clientactive)
                        return;
@@ -669,7 +680,7 @@ class ModuleSSLOpenSSL : public Module
                }
        }
 
-       virtual void OnSyncUserMetaData(userrec* user, Module* proto, void* opaque, const std::string &extname, bool displayable)
+       virtual void OnSyncUserMetaData(User* user, Module* proto, void* opaque, const std::string &extname, bool displayable)
        {
                // check if the linking module wants to know about OUR metadata
                if (extname == "ssl")
@@ -689,7 +700,7 @@ class ModuleSSLOpenSSL : public Module
                // check if its our metadata key, and its associated with a user
                if ((target_type == TYPE_USER) && (extname == "ssl"))
                {
-                       userrec* dest = (userrec*)target;
+                       User* dest = (User*)target;
                        // if they dont already have an ssl flag, accept the remote server's
                        if (!dest->GetExt(extname, dummy))
                        {
@@ -703,9 +714,7 @@ class ModuleSSLOpenSSL : public Module
                int ret;
 
                if (session->outbound)
-               {
                        ret = SSL_connect(session->sess);
-               }
                else
                        ret = SSL_accept(session->sess);
 
@@ -737,7 +746,7 @@ class ModuleSSLOpenSSL : public Module
                {
                        // Handshake complete.
                        // This will do for setting the ssl flag...it could be done earlier if it's needed. But this seems neater.
-                       userrec* u = ServerInstance->FindDescriptor(session->fd);
+                       User* u = ServerInstance->FindDescriptor(session->fd);
                        if (u)
                        {
                                if (!u->GetExt("ssl", dummy))
@@ -752,10 +761,6 @@ class ModuleSSLOpenSSL : public Module
                }
                else if (ret == 0)
                {
-                       int ssl_err = SSL_get_error(session->sess, ret);
-                       char buf[1024];
-                       ERR_print_errors_fp(stderr);
-                       ServerInstance->Log(DEBUG,"Handshake fail 2: %d: %s", ssl_err, ERR_error_string(ssl_err,buf));
                        CloseSession(session);
                        return true;
                }
@@ -763,10 +768,10 @@ class ModuleSSLOpenSSL : public Module
                return true;
        }
 
-       virtual void OnPostConnect(userrec* user)
+       virtual void OnPostConnect(User* user)
        {
                // This occurs AFTER OnUserConnect so we can be sure the
-               // protocol module has propogated the NICK message.
+               // protocol module has propagated the NICK message.
                if ((user->GetExt("ssl", dummy)) && (IS_LOCAL(user)))
                {
                        // Tell whatever protocol module we're using that we need to inform other servers of this metadata NOW.
@@ -790,14 +795,15 @@ class ModuleSSLOpenSSL : public Module
                //OnRawSocketWrite(session->fd, NULL, 0);
                EventHandler* eh = ServerInstance->FindDescriptor(session->fd);
                if (eh)
+               {
                        ServerInstance->SE->WantWrite(eh);
+               }
        }
 
-       virtual void OnBufferFlushed(userrec* user)
+       virtual void OnBufferFlushed(User* user)
        {
                if (user->GetExt("ssl"))
                {
-                       ServerInstance->Log(DEBUG,"OnBufferFlushed for ssl user");
                        issl_session* session = &sessions[user->GetFd()];
                        if (session && session->outbuf.size())
                                OnRawSocketWrite(user->GetFd(), NULL, 0);
@@ -885,4 +891,4 @@ static int error_callback(const char *str, size_t len, void *u)
        return 0;
 }
 
-MODULE_INIT(ModuleSSLOpenSSL);
+MODULE_INIT(ModuleSSLOpenSSL)