]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/extra/m_ssl_openssl.cpp
fix warnings
[user/henk/code/inspircd.git] / src / modules / extra / m_ssl_openssl.cpp
index c4bc180e5f49b209ce9b802003e407f535a92754..ed38933db19a923477949718731e0082a3864f9f 100644 (file)
@@ -107,7 +107,7 @@ class ModuleSSLOpenSSL : public Module
        std::vector<std::string> listenports;
 
        int inbufsize;
-       issl_session sessions[MAX_DESCRIPTORS];
+       issl_session* sessions;
 
        SSL_CTX* ctx;
        SSL_CTX* clictx;
@@ -133,6 +133,8 @@ class ModuleSSLOpenSSL : public Module
        {
                ServerInstance->Modules->PublishInterface("BufferedSocketHook", this);
 
+               sessions = new issl_session[ServerInstance->SE->GetMaxFds()];
+
                // Not rehashable...because I cba to reduce all the sizes of existing buffers.
                inbufsize = ServerInstance->Config->NetBufferSize;
 
@@ -195,13 +197,13 @@ class ModuleSSLOpenSSL : public Module
                                                 for (size_t i = 0; i < ServerInstance->Config->ports.size(); i++)
                                                         if ((ServerInstance->Config->ports[i]->GetPort() == portno) && (ServerInstance->Config->ports[i]->GetIP() == addr))
                                                                 ServerInstance->Config->ports[i]->SetDescription("ssl");
-                                                ServerInstance->Logs->Log("m_ssl_openssl",DEFAULT, "m_ssl_gnutls.so: Enabling SSL for port %d", portno);
+                                                ServerInstance->Logs->Log("m_ssl_openssl",DEFAULT, "m_ssl_gnutls.so: Enabling SSL for port %ld", portno);
 
                                                 sslports.append((addr.empty() ? "*" : addr)).append(":").append(ConvToStr(portno)).append(";");
                                         }
                                         catch (ModuleException &e)
                                         {
-                                                ServerInstance->Logs->Log("m_ssl_openssl",DEFAULT, "m_ssl_gnutls.so: FAILED to enable SSL on port %d: %s. Maybe it's already hooked by the same port on a different IP, or you have an other SSL or similar module loaded?", portno, e.GetReason());
+                                                ServerInstance->Logs->Log("m_ssl_openssl",DEFAULT, "m_ssl_gnutls.so: FAILED to enable SSL on port %ld: %s. Maybe it's already hooked by the same port on a different IP, or you have an other SSL or similar module loaded?", portno, e.GetReason());
                                         }
                                 }
                         }
@@ -302,6 +304,8 @@ class ModuleSSLOpenSSL : public Module
        {
                SSL_CTX_free(ctx);
                SSL_CTX_free(clictx);
+               ServerInstance->Modules->UnpublishInterface("BufferedSocketHook", this);
+               delete[] sessions;
        }
 
        virtual void OnCleanup(int target_type, void* item)
@@ -396,7 +400,7 @@ 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))
+               if ((fd < 0) || (fd > ServerInstance->SE->GetMaxFds() - 1))
                        return;
 
                issl_session* session = &sessions[fd];
@@ -423,7 +427,7 @@ 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))
+               if ((fd < 0) || (fd > ServerInstance->SE->GetMaxFds() -1))
                        return;
 
                issl_session* session = &sessions[fd];
@@ -450,7 +454,7 @@ 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))
+               if ((fd < 0) || (fd > ServerInstance->SE->GetMaxFds() - 1))
                        return;
 
                CloseSession(&sessions[fd]);
@@ -469,7 +473,7 @@ 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))
+               if ((fd < 0) || (fd > ServerInstance->SE->GetMaxFds() - 1))
                        return 0;
 
                issl_session* session = &sessions[fd];
@@ -546,7 +550,7 @@ 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))
+               if ((fd < 0) || (fd > ServerInstance->SE->GetMaxFds() - 1))
                        return 0;
 
                issl_session* session = &sessions[fd];
@@ -778,14 +782,7 @@ class ModuleSSLOpenSSL : public Module
                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.
-                       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(ServerInstance);            // Trigger the event. We don't care what module picks it up.
-                       delete event;
-                       delete metadata;
+                       ServerInstance->PI->SendMetaData(user, TYPE_USER, "SSL", "on");
 
                        VerifyCertificate(&sessions[user->GetFd()], user);
                        if (sessions[user->GetFd()].sess)
@@ -885,6 +882,13 @@ class ModuleSSLOpenSSL : public Module
 
                X509_free(cert);
        }
+
+       void Prioritize()
+       {
+               Module* server = ServerInstance->Modules->Find("m_spanningtree.so");
+               ServerInstance->Modules->SetPriority(this, I_OnPostConnect, PRIO_AFTER, &server);
+       }
+
 };
 
 static int error_callback(const char *str, size_t len, void *u)