]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_ident.cpp
Test stuff to fix remote stats brokage
[user/henk/code/inspircd.git] / src / modules / m_ident.cpp
index 53c13260fa295559e3f71341c258d8ef314b8ca2..a0f590f9572f12ee92a2ae6fe8d28ee695334a30 100644 (file)
@@ -2,20 +2,15 @@
  *       | Inspire Internet Relay Chat Daemon |
  *       +------------------------------------+
  *
- *  InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
- *                       E-mail:
- *                <brain@chatspike.net>
- *               <Craig@chatspike.net>
- *     
- * Written by Craig Edwards, Craig McLure, and others.
+ *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
+ * See: http://www.inspircd.org/wiki/index.php/Credits
+ *
  * This program is free but copyrighted software; see
  *            the file COPYING for details.
  *
  * ---------------------------------------------------
  */
 
-using namespace std;
-
 #include <stdio.h>
 #include <string>
 #include "users.h"
@@ -27,12 +22,11 @@ using namespace std;
 
 // Version 1.5.0.0 - Updated to use InspSocket, faster and neater.
 
+/** Handles RFC1413 ident connections to users
+ */
 class RFC1413 : public InspSocket
 {
  protected:
-                        // Server* class used for core communications
-       insp_sockaddr sock_us;   // our port number
-       insp_sockaddr sock_them; // their port number
        socklen_t uslen;         // length of our port number
        socklen_t themlen;       // length of their port number
        char ident_request[128]; // buffer used to make up the request string
@@ -53,7 +47,7 @@ class RFC1413 : public InspSocket
                if (u && (Instance->SE->GetRef(ufd) == u))
                {
                        u->Shrink("ident_data");
-                       u->WriteServ("NOTICE "+std::string(u->nick)+" :*** Could not find your ident, using "+std::string(u->ident)+" instead.");
+                       Instance->next_call = Instance->Time();
                }
        }
 
@@ -86,7 +80,6 @@ class RFC1413 : public InspSocket
                                                                        if (this->Instance->IsIdent(section))
                                                                        {
                                                                                strlcpy(u->ident,section,IDENTMAX);
-                                                                               Instance->Log(DEBUG,"IDENT SET: "+std::string(u->ident));
                                                                                u->WriteServ("NOTICE "+std::string(u->nick)+" :*** Found your ident: "+std::string(u->ident));
                                                                        }
                                                                }
@@ -124,6 +117,7 @@ class RFC1413 : public InspSocket
                // Fixes issue reported by webs, 7 Jun 2006
                if (u && (Instance->SE->GetRef(ufd) == u))
                {
+                       Instance->next_call = Instance->Time();
                        u->Shrink("ident_data");
                }
        }
@@ -132,37 +126,61 @@ class RFC1413 : public InspSocket
        {
                if (u && (Instance->SE->GetRef(ufd) == u))
                {
+                       if (*u->ident == '~')
+                               u->WriteServ("NOTICE "+std::string(u->nick)+" :*** Could not find your ident, using "+std::string(u->ident)+" instead.");
+
+                       Instance->next_call = Instance->Time();
                        u->Shrink("ident_data");
                }
        }
 
        virtual bool OnConnected()
        {
-               Instance->Log(DEBUG,"Ident: connected");
                if (u && (Instance->SE->GetRef(ufd) == u))
                {
-                       uslen = sizeof(sock_us);
-                       themlen = sizeof(sock_them);
-                       if ((getsockname(this->u->GetFd(),(sockaddr*)&sock_us,&uslen) || getpeername(this->u->GetFd(), (sockaddr*)&sock_them, &themlen)))
+                       sockaddr* sock_us = new sockaddr[2];
+                       sockaddr* sock_them = new sockaddr[2];
+                       bool success = false;
+                       uslen = sizeof(sockaddr_in);
+                       themlen = sizeof(sockaddr_in);
+#ifdef IPV6
+                       if (this->u->GetProtocolFamily() == AF_INET6)
+                       {
+                               themlen = sizeof(sockaddr_in6);
+                               uslen = sizeof(sockaddr_in6);
+                               success = ((getsockname(this->u->GetFd(),sock_us,&uslen) || getpeername(this->u->GetFd(), sock_them, &themlen)));
+                       }
+                       else
+                               success = ((getsockname(this->u->GetFd(),sock_us,&uslen) || getpeername(this->u->GetFd(), sock_them, &themlen)));
+#else
+                       success = ((getsockname(this->u->GetFd(),sock_us,&uslen) || getpeername(this->u->GetFd(), sock_them, &themlen)));
+#endif
+                       if (success)
                        {
-                               Instance->Log(DEBUG,"Ident: failed to get socket names, bailing");
+                               delete[] sock_us;
+                               delete[] sock_them;
                                return false;
                        }
                        else
                        {
                                // send the request in the following format: theirsocket,oursocket
 #ifdef IPV6
-                               snprintf(ident_request,127,"%d,%d\r\n",ntohs(sock_them.sin6_port),ntohs(sock_us.sin6_port));
+                               if (this->u->GetProtocolFamily() == AF_INET6)
+                                       snprintf(ident_request,127,"%d,%d\r\n",ntohs(((sockaddr_in6*)sock_them)->sin6_port),ntohs(((sockaddr_in6*)sock_us)->sin6_port));
+                               else
+                                       snprintf(ident_request,127,"%d,%d\r\n",ntohs(((sockaddr_in*)sock_them)->sin_port),ntohs(((sockaddr_in*)sock_us)->sin_port));
 #else
-                               snprintf(ident_request,127,"%d,%d\r\n",ntohs(sock_them.sin_port),ntohs(sock_us.sin_port));
+                               snprintf(ident_request,127,"%d,%d\r\n",ntohs(((sockaddr_in*)sock_them)->sin_port),ntohs(((sockaddr_in*)sock_us)->sin_port));
 #endif
                                this->Write(ident_request);
-                               Instance->Log(DEBUG,"Sent ident request, waiting for reply");
+                               delete[] sock_us;
+                               delete[] sock_them;
                                return true;
                        }
                }
                else
                {
+                       Instance->next_call = Instance->Time();
                        return true;
                }
        }
@@ -172,7 +190,7 @@ class ModuleIdent : public Module
 {
 
        ConfigReader* Conf;
-       
+
        int IdentTimeout;
 
  public:
@@ -188,7 +206,7 @@ class ModuleIdent : public Module
        ModuleIdent(InspIRCd* Me)
                : Module::Module(Me)
        {
-               
+
                ReadSettings();
        }
 
@@ -197,12 +215,12 @@ class ModuleIdent : public Module
                List[I_OnCleanup] = List[I_OnRehash] = List[I_OnUserRegister] = List[I_OnCheckReady] = List[I_OnUserDisconnect] = 1;
        }
 
-       virtual void OnRehash(const std::string &parameter)
+       virtual void OnRehash(userrec* user, const std::string &parameter)
        {
                ReadSettings();
        }
 
-       virtual void OnUserRegister(userrec* user)
+       virtual int OnUserRegister(userrec* user)
        {
                /*
                 * when the new user connects, before they authenticate with USER/NICK/PASS, we do
@@ -210,6 +228,12 @@ class ModuleIdent : public Module
                 * is derived from InspSocket, and inserting it into the socket engine using the
                 * Server::AddSocket() call.
                 */
+               char newident[MAXBUF];
+               strcpy(newident,"~");
+               strlcat(newident,user->ident,IDENTMAX);
+               strlcpy(user->ident,newident,IDENTMAX);
+               
+
                user->WriteServ("NOTICE "+std::string(user->nick)+" :*** Looking up your ident...");
                RFC1413* ident = new RFC1413(ServerInstance, user, IdentTimeout);
                if ((ident->GetState() == I_CONNECTING) || (ident->GetState() == I_CONNECTED))
@@ -217,7 +241,11 @@ class ModuleIdent : public Module
                        user->Extend("ident_data", (char*)ident);
                }
                else
-                       delete ident;
+               {
+                       user->WriteServ("NOTICE "+std::string(user->nick)+" :*** Could not find your ident, using "+std::string(user->ident)+" instead.");
+                       ServerInstance->next_call = ServerInstance->Time();
+               }
+               return 0;
        }
 
        virtual bool OnCheckReady(userrec* user)
@@ -244,6 +272,8 @@ class ModuleIdent : public Module
                                // a user which has now vanished! To prevent this, set ident::u
                                // to NULL and check it so that we dont write users who have gone away.
                                ident->u = NULL;
+                               ServerInstance->SE->DelFd(ident);
+                               //delete ident;
                        }
                }
        }
@@ -262,18 +292,20 @@ class ModuleIdent : public Module
                if (user->GetExt("ident_data", ident))
                {
                        ident->u = NULL;
+                       ServerInstance->SE->DelFd(ident);
                }
        }
-       
+
        virtual ~ModuleIdent()
        {
+               ServerInstance->next_call = ServerInstance->Time();
        }
-       
+
        virtual Version GetVersion()
        {
-               return Version(1,5,0,0,VF_VENDOR,API_VERSION);
+               return Version(1,1,0,0,VF_VENDOR,API_VERSION);
        }
-       
+
 };
 
 class ModuleIdentFactory : public ModuleFactory
@@ -282,16 +314,16 @@ class ModuleIdentFactory : public ModuleFactory
        ModuleIdentFactory()
        {
        }
-       
+
        ~ModuleIdentFactory()
        {
        }
-       
+
        virtual Module * CreateModule(InspIRCd* Me)
        {
                return new ModuleIdent(Me);
        }
-       
+
 };