]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_ident.cpp
Move the <disabled> tag out of the core to a new module.
[user/henk/code/inspircd.git] / src / modules / m_ident.cpp
index 0e5aa43aea55b74d5c61a94ff4e3ba06b0e5cd8f..803c19846288e67dd93be7f5fac9a8ce6570a860 100644 (file)
@@ -92,7 +92,7 @@ class IdentRequestSocket : public EventHandler
        {
                age = ServerInstance->Time();
 
-               SetFd(socket(user->server_sa.sa.sa_family, SOCK_STREAM, 0));
+               SetFd(socket(user->server_sa.family(), SOCK_STREAM, 0));
 
                if (GetFd() == -1)
                        throw ModuleException("Could not create socket");
@@ -105,7 +105,7 @@ class IdentRequestSocket : public EventHandler
                memcpy(&bindaddr, &user->server_sa, sizeof(bindaddr));
                memcpy(&connaddr, &user->client_sa, sizeof(connaddr));
 
-               if (connaddr.sa.sa_family == AF_INET6)
+               if (connaddr.family() == AF_INET6)
                {
                        bindaddr.in6.sin6_port = 0;
                        connaddr.in6.sin6_port = htons(113);
@@ -126,7 +126,7 @@ class IdentRequestSocket : public EventHandler
                SocketEngine::NonBlocking(GetFd());
 
                /* Attempt connection (nonblocking) */
-               if (SocketEngine::Connect(this, &connaddr.sa, connaddr.sa_size()) == -1 && errno != EINPROGRESS)
+               if (SocketEngine::Connect(this, connaddr) == -1 && errno != EINPROGRESS)
                {
                        this->Close();
                        throw ModuleException("connect() failed");
@@ -148,7 +148,7 @@ class IdentRequestSocket : public EventHandler
 
                /* Build request in the form 'localport,remoteport\r\n' */
                int req_size;
-               if (user->client_sa.sa.sa_family == AF_INET6)
+               if (user->client_sa.family() == AF_INET6)
                        req_size = snprintf(req, sizeof(req), "%d,%d\r\n",
                                ntohs(user->client_sa.in6.sin6_port), ntohs(user->server_sa.in6.sin6_port));
                else
@@ -271,12 +271,28 @@ class ModuleIdent : public Module
        void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
        {
                ConfigTag* tag = ServerInstance->Config->ConfValue("ident");
-               RequestTimeout = tag->getInt("timeout", 5, 1);
+               RequestTimeout = tag->getDuration("timeout", 5, 1);
                NoLookupPrefix = tag->getBool("nolookupprefix", false);
        }
 
-       void OnUserInit(LocalUser *user) CXX11_OVERRIDE
+       void OnSetUserIP(LocalUser* user) CXX11_OVERRIDE
        {
+               IdentRequestSocket* isock = ext.get(user);
+               if (isock)
+               {
+                       // If an ident lookup request was in progress then cancel it.
+                       isock->Close();
+                       ext.unset(user);
+               }
+
+               // The ident protocol requires that clients are connecting over a protocol with ports.
+               if (user->client_sa.family() != AF_INET && user->client_sa.family() != AF_INET6)
+                       return;
+
+               // We don't want to look this up once the user has connected.
+               if (user->registered == REG_ALL)
+                       return;
+
                ConfigTag* tag = user->MyClass->config;
                if (!tag->getBool("useident", true))
                        return;
@@ -285,7 +301,7 @@ class ModuleIdent : public Module
 
                try
                {
-                       IdentRequestSocket *isock = new IdentRequestSocket(user);
+                       isock = new IdentRequestSocket(user);
                        ext.set(user, isock);
                }
                catch (ModuleException &e)