X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_ident.cpp;h=040e856d4d710542fcc6e98c43d836da8e7e7cbf;hb=82243d9beb827fca5708efe9e047ff2fec4bfe8c;hp=781661c4880d1db3d883d6a58a3ddafc415be7b8;hpb=b37a253d962ed7af1ea7a328abf2a1af74f30759;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_ident.cpp b/src/modules/m_ident.cpp index 781661c48..040e856d4 100644 --- a/src/modules/m_ident.cpp +++ b/src/modules/m_ident.cpp @@ -23,10 +23,6 @@ using namespace std; #include "modules.h" #include "inspircd.h" -extern InspIRCd* ServerInstance; - -extern userrec* fd_ref_table[MAX_DESCRIPTORS]; - /* $ModDesc: Provides support for RFC 1413 ident lookups */ // Version 1.5.0.0 - Updated to use InspSocket, faster and neater. @@ -34,7 +30,7 @@ extern userrec* fd_ref_table[MAX_DESCRIPTORS]; class RFC1413 : public InspSocket { protected: - Server* Srv; // Server* class used for core communications + // 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 @@ -45,19 +41,23 @@ class RFC1413 : public InspSocket userrec* u; // user record that the lookup is associated with int ufd; - RFC1413(InspIRCd* SI, userrec* user, int maxtime, Server* S) : InspSocket(SI, user->GetIPString(), 113, false, maxtime), Srv(S), u(user), ufd(user->fd) + RFC1413(InspIRCd* SI, userrec* user, int maxtime) : InspSocket(SI, user->GetIPString(), 113, false, maxtime), u(user) { - log(DEBUG,"Ident: associated."); + ufd = user->GetFd(); } virtual void OnTimeout() { // When we timeout, the connection failed within the allowed timeframe, // so we just display a notice, and tidy off the ident_data. - if (u && (fd_ref_table[ufd] == u)) + if (u && (Instance->SE->GetRef(ufd) == u)) { + char newident[MAXBUF]; u->Shrink("ident_data"); - u->WriteServ("NOTICE "+std::string(u->nick)+" :*** Could not find your ident, using "+std::string(u->ident)+" instead."); + u->WriteServ("NOTICE "+std::string(u->nick)+" :*** Could not find your ident, using ~"+std::string(u->ident)+" instead."); + strcpy(newident,"~"); + strlcat(newident,u->ident,IDENTMAX); + strlcpy(u->ident,newident,IDENTMAX); } } @@ -85,12 +85,12 @@ class RFC1413 : public InspSocket *j = '\0'; // truncate at invalid chars if (*section) { - if (u && (fd_ref_table[ufd] == u)) + if (u && (Instance->SE->GetRef(ufd) == u)) { - if (ServerInstance->IsIdent(section)) + if (this->Instance->IsIdent(section)) { strlcpy(u->ident,section,IDENTMAX); - log(DEBUG,"IDENT SET: "+std::string(u->ident)); + Instance->Log(DEBUG,"IDENT SET: "+std::string(u->ident)); u->WriteServ("NOTICE "+std::string(u->nick)+" :*** Found your ident: "+std::string(u->ident)); } } @@ -126,7 +126,7 @@ class RFC1413 : public InspSocket // descriptor that they were when the lookup began. // // Fixes issue reported by webs, 7 Jun 2006 - if (u && (fd_ref_table[ufd] == u)) + if (u && (Instance->SE->GetRef(ufd) == u)) { u->Shrink("ident_data"); } @@ -134,7 +134,7 @@ class RFC1413 : public InspSocket virtual void OnError(InspSocketError e) { - if (u && (fd_ref_table[ufd] == u)) + if (u && (Instance->SE->GetRef(ufd) == u)) { u->Shrink("ident_data"); } @@ -142,13 +142,14 @@ class RFC1413 : public InspSocket virtual bool OnConnected() { - if (u && (fd_ref_table[ufd] == u)) + Instance->Log(DEBUG,"Ident: connected"); + if (u && (Instance->SE->GetRef(ufd) == u)) { uslen = sizeof(sock_us); themlen = sizeof(sock_them); - if ((getsockname(this->u->fd,(sockaddr*)&sock_us,&uslen) || getpeername(this->u->fd, (sockaddr*)&sock_them, &themlen))) + if ((getsockname(this->u->GetFd(),(sockaddr*)&sock_us,&uslen) || getpeername(this->u->GetFd(), (sockaddr*)&sock_them, &themlen))) { - log(DEBUG,"Ident: failed to get socket names, bailing"); + Instance->Log(DEBUG,"Ident: failed to get socket names, bailing"); return false; } else @@ -160,7 +161,7 @@ class RFC1413 : public InspSocket snprintf(ident_request,127,"%d,%d\r\n",ntohs(sock_them.sin_port),ntohs(sock_us.sin_port)); #endif this->Write(ident_request); - log(DEBUG,"Sent ident request, waiting for reply"); + Instance->Log(DEBUG,"Sent ident request, waiting for reply"); return true; } } @@ -175,13 +176,13 @@ class ModuleIdent : public Module { ConfigReader* Conf; - Server* Srv; + int IdentTimeout; public: void ReadSettings() { - Conf = new ConfigReader; + Conf = new ConfigReader(ServerInstance); IdentTimeout = Conf->ReadInteger("ident","timeout",0,true); if (!IdentTimeout) IdentTimeout = 1; @@ -214,16 +215,19 @@ class ModuleIdent : public Module * Server::AddSocket() call. */ user->WriteServ("NOTICE "+std::string(user->nick)+" :*** Looking up your ident..."); - RFC1413* ident = new RFC1413(ServerInstance, user, IdentTimeout, Srv); - if (ident->GetState() != I_ERROR) + RFC1413* ident = new RFC1413(ServerInstance, user, IdentTimeout); + if ((ident->GetState() == I_CONNECTING) || (ident->GetState() == I_CONNECTED)) { user->Extend("ident_data", (char*)ident); - Srv->AddSocket(ident); } else { - user->WriteServ("NOTICE "+std::string(user->nick)+" :*** Could not find your ident, using "+std::string(user->ident)+" instead."); - DELETE(ident); + char newident[MAXBUF]; + user->WriteServ("NOTICE "+std::string(user->nick)+" :*** Could not find your ident, using ~"+std::string(user->ident)+" instead."); + strcpy(newident,"~"); + strlcat(newident,user->ident,IDENTMAX); + strlcpy(user->ident,newident,IDENTMAX); + delete ident; } } @@ -251,7 +255,6 @@ 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; - Srv->RemoveSocket(ident); } } } @@ -270,7 +273,6 @@ class ModuleIdent : public Module if (user->GetExt("ident_data", ident)) { ident->u = NULL; - Srv->RemoveSocket(ident); } } @@ -280,7 +282,7 @@ class ModuleIdent : public Module virtual Version GetVersion() { - return Version(1,5,0,0,VF_VENDOR); + return Version(1,5,0,0,VF_VENDOR,API_VERSION); } };