]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/extra/m_ssl_openssl.cpp
Whos been commiting a quarter of a fix?
[user/henk/code/inspircd.git] / src / modules / extra / m_ssl_openssl.cpp
index 4691b874e439188a82331929dacfb7b002cbe56e..0c9307ae4e8e525b66adde5e3f187f695180eaab 100644 (file)
@@ -162,7 +162,7 @@ class ModuleSSLOpenSSL : public Module
                ServerInstance->Modules->Attach(eventlist, this, 16);
        }
 
-        virtual void OnHookUserIO(User* user, const std::string &targetip)
+       virtual void OnHookUserIO(User* user, const std::string &targetip)
        {
                if (!user->io && isin(targetip,user->GetPort(), listenports))
                {
@@ -175,43 +175,43 @@ class ModuleSSLOpenSSL : public Module
        {
                ConfigReader Conf(ServerInstance);
 
-                listenports.clear();
-                clientactive = 0;
-                sslports.clear();
-
-                for(int index = 0; index < Conf.Enumerate("bind"); index++)
-                {
-                        // For each <bind> tag
-                        std::string x = Conf.ReadValue("bind", "type", index);
-                        if(((x.empty()) || (x == "clients")) && (Conf.ReadValue("bind", "ssl", index) == "openssl"))
-                        {
-                                // Get the port we're meant to be listening on with SSL
-                                std::string port = Conf.ReadValue("bind", "port", index);
-                                std::string addr = Conf.ReadValue("bind", "address", index);
-
-                                irc::portparser portrange(port, false);
-                                long portno = -1;
-                                while ((portno = portrange.GetToken()))
-                                {
-                                        clientactive++;
-                                        try
-                                        {
-                                                listenports.push_back(addr + ":" + ConvToStr(portno));
-
-                                                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 %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 %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());
-                                        }
-                                }
-                        }
-                }
+               listenports.clear();
+               clientactive = 0;
+               sslports.clear();
+
+               for(int index = 0; index < Conf.Enumerate("bind"); index++)
+               {
+                       // For each <bind> tag
+                       std::string x = Conf.ReadValue("bind", "type", index);
+                       if(((x.empty()) || (x == "clients")) && (Conf.ReadValue("bind", "ssl", index) == "openssl"))
+                       {
+                               // Get the port we're meant to be listening on with SSL
+                               std::string port = Conf.ReadValue("bind", "port", index);
+                               std::string addr = Conf.ReadValue("bind", "address", index);
+
+                               irc::portparser portrange(port, false);
+                               long portno = -1;
+                               while ((portno = portrange.GetToken()))
+                               {
+                                       clientactive++;
+                                       try
+                                       {
+                                               listenports.push_back(addr + ":" + ConvToStr(portno));
+
+                                               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 %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 %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());
+                                       }
+                               }
+                       }
+               }
 
                if (!sslports.empty())
                        sslports.erase(sslports.end() - 1);
@@ -244,16 +244,16 @@ class ModuleSSLOpenSSL : public Module
                        dhfile = "dhparams.pem";
 
                // Prepend relative paths with the path to the config directory.
-               if (cafile[0] != '/')
+               if ((cafile[0] != '/') && (!ServerInstance->Config->StartsWithWindowsDriveLetter(cafile)))
                        cafile = confdir + cafile;
 
-               if (certfile[0] != '/')
+               if ((certfile[0] != '/') && (!ServerInstance->Config->StartsWithWindowsDriveLetter(certfile)))
                        certfile = confdir + certfile;
 
-               if (keyfile[0] != '/')
+               if ((keyfile[0] != '/') && (!ServerInstance->Config->StartsWithWindowsDriveLetter(keyfile)))
                        keyfile = confdir + keyfile;
 
-               if (dhfile[0] != '/')
+               if ((dhfile[0] != '/') && (!ServerInstance->Config->StartsWithWindowsDriveLetter(dhfile)))
                        dhfile = confdir + dhfile;
 
                /* Load our keys and certificates
@@ -430,7 +430,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 */
+               /* Are there any possibilities of an out of range fd? Hope not, but lets be paranoid */
                if ((fd < 0) || (fd > ServerInstance->SE->GetMaxFds() -1))
                        return;
 
@@ -525,9 +525,9 @@ class ModuleSSLOpenSSL : public Module
                                {
                                        if (count <= session->inbufoffset)
                                        {
-                                               memcpy(buffer, session->inbuf, count);
+                                               memmove(buffer, session->inbuf, count);
                                                // Move the stuff left in inbuf to the beginning of it
-                                               memcpy(session->inbuf, session->inbuf + count, (session->inbufoffset - count));
+                                               memmove(session->inbuf, session->inbuf + count, (session->inbufoffset - count));
                                                // Now we need to set session->inbufoffset to the amount of data still waiting to be handed to insp.
                                                session->inbufoffset -= count;
                                                // Insp uses readresult as the count of how much data there is in buffer, so:
@@ -536,7 +536,7 @@ class ModuleSSLOpenSSL : public Module
                                        else
                                        {
                                                // There's not as much in the inbuf as there is space in the buffer, so just copy the whole thing.
-                                               memcpy(buffer, session->inbuf, session->inbufoffset);
+                                               memmove(buffer, session->inbuf, session->inbufoffset);
 
                                                readresult = session->inbufoffset;
                                                // Zero the offset, as there's nothing there..
@@ -636,7 +636,7 @@ class ModuleSSLOpenSSL : public Module
        {
                // Is this right? Not sure if the unencrypted data is garaunteed to be the same length.
                // Read into the inbuffer, offset from the beginning by the amount of data we have that insp hasn't taken yet.
-               
+
                int ret = SSL_read(session->sess, session->inbuf + session->inbufoffset, inbufsize - session->inbufoffset);
 
                if (ret == 0)
@@ -687,7 +687,7 @@ class ModuleSSLOpenSSL : public Module
                // Bugfix, only send this numeric for *our* SSL users
                if (dest->GetExt("ssl", dummy) || ((IS_LOCAL(dest) && dest->io == this)))
                {
-                       ServerInstance->SendWhoisLine(source, dest, 320, "%s %s :is using a secure connection", source->nick, dest->nick);
+                       ServerInstance->SendWhoisLine(source, dest, 320, "%s %s :is using a secure connection", source->nick.c_str(), dest->nick.c_str());
                }
        }
 
@@ -790,7 +790,7 @@ class ModuleSSLOpenSSL : public Module
 
                        VerifyCertificate(&sessions[user->GetFd()], user);
                        if (sessions[user->GetFd()].sess)
-                               user->WriteServ("NOTICE %s :*** You are connected using SSL cipher \"%s\"", user->nick, SSL_get_cipher(sessions[user->GetFd()].sess));
+                               user->WriteServ("NOTICE %s :*** You are connected using SSL cipher \"%s\"", user->nick.c_str(), SSL_get_cipher(sessions[user->GetFd()].sess));
                }
        }
 
@@ -899,6 +899,16 @@ static int error_callback(const char *str, size_t len, void *u)
 {
        ModuleSSLOpenSSL* mssl = (ModuleSSLOpenSSL*)u;
        mssl->PublicInstance->Logs->Log("m_ssl_openssl",DEFAULT, "SSL error: " + std::string(str, len - 1));
+
+       //
+       // XXX: Remove this line, it causes valgrind warnings...
+       //
+       // MD_update(&m, buf, j);
+       //
+       //
+       // ... ONLY JOKING! :-)
+       //
+
        return 0;
 }