summaryrefslogtreecommitdiff
path: root/src/modules
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2007-10-18 17:55:51 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2007-10-18 17:55:51 +0000
commitfdd3804828fbd492a1860808b3256ca7153d3c8f (patch)
tree3fadd3ecf5cc714b19feaaa52aff7f66fbfd0ac3 /src/modules
parentbc2a959b4c13c2eb14f745e910797573e64dbbf0 (diff)
This new ident module now seems to work rudimentarily.
Should be safe to backport to 1.1, then make look nicer in 1.2, its pretty neat as it stands though. git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@8223 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/m_ident.cpp42
1 files changed, 37 insertions, 5 deletions
diff --git a/src/modules/m_ident.cpp b/src/modules/m_ident.cpp
index 80f3b7398..d93b0e459 100644
--- a/src/modules/m_ident.cpp
+++ b/src/modules/m_ident.cpp
@@ -79,6 +79,7 @@ class IdentRequestSocket : public EventHandler
((sockaddr_in*)addr)->sin_family = AF_INET;
((sockaddr_in*)addr)->sin_addr = addy;
((sockaddr_in*)addr)->sin_port = htons(113);
+ size = sizeof(sockaddr_in);
inet_aton(bindip.c_str(), &n);
((sockaddr_in*)s)->sin_addr = n;
((sockaddr_in*)s)->sin_port = 0;
@@ -116,6 +117,8 @@ class IdentRequestSocket : public EventHandler
virtual void OnConnected()
{
+ ServerInstance->Log(DEBUG,"OnConnected()");
+
/* Both sockaddr_in and sockaddr_in6 can be safely casted to sockaddr, especially since the
* only members we use are in a part of the struct that should always be identical (at the
* byte level). */
@@ -158,6 +161,8 @@ class IdentRequestSocket : public EventHandler
break;
case EVENT_ERROR:
/* fd error event, ohshi- */
+ ServerInstance->Log(DEBUG,"EVENT_ERROR");
+ Close();
done = true;
break;
}
@@ -165,8 +170,12 @@ class IdentRequestSocket : public EventHandler
void Close()
{
- ServerInstance->SE->Close(GetFd());
- ServerInstance->SE->Shutdown(GetFd(), SHUT_WR);
+ if (GetFd() > -1)
+ {
+ ServerInstance->SE->Close(GetFd());
+ ServerInstance->SE->Shutdown(GetFd(), SHUT_WR);
+ ServerInstance->SE->DelFd(this);
+ }
}
bool HasResult()
@@ -181,6 +190,8 @@ class IdentRequestSocket : public EventHandler
void ReadResponse()
{
+ ServerInstance->Log(DEBUG,"ReadResponse()");
+
// We don't really need to buffer for incomplete replies here, since IDENT replies are
// extremely short - there is *no* sane reason it'd be in more than one packet
@@ -233,6 +244,7 @@ class IdentRequestSocket : public EventHandler
break;
}
+ Close();
done = true;
return;
}
@@ -307,6 +319,7 @@ class ModuleIdent : public Module
}
catch (ModuleException &e)
{
+ ServerInstance->Log(DEBUG,"Ident exception: %s", e.GetReason());
return 0;
}
@@ -316,26 +329,44 @@ class ModuleIdent : public Module
virtual bool OnCheckReady(User *user)
{
+ ServerInstance->Log(DEBUG,"OnCheckReady %s", user->nick);
+
/* Does user have an ident socket attached at all? */
IdentRequestSocket *isock = NULL;
if (!user->GetExt("ident_socket", isock))
+ {
+ ServerInstance->Log(DEBUG, "No ident socket :(");
return true;
+ }
- if (isock->age < ServerInstance->Time() - RequestTimeout)
+ ServerInstance->Log(DEBUG, "Has ident_socket");
+
+ if (isock->age + RequestTimeout > ServerInstance->Time() && !isock->HasResult())
{
/* Ident timeout */
user->WriteServ("NOTICE Auth :*** Ident request timed out.");
+ ServerInstance->Log(DEBUG, "Timeout");
OnUserDisconnect(user);
return true;
}
/* Got a result yet? */
if (!isock->HasResult())
+ {
+ ServerInstance->Log(DEBUG, "No result yet");
return false;
+ }
+
+ ServerInstance->Log(DEBUG, "Yay, result!");
/* wooo, got a result! */
- user->WriteServ("NOTICE Auth :*** Found your ident, '%s'", isock->GetResult());
+ if (*(isock->GetResult()) != '~')
+ user->WriteServ("NOTICE Auth :*** Found your ident, '%s'", isock->GetResult());
+ else
+ user->WriteServ("NOTICE Auth :*** Could not find your ident, using %s instead.", isock->GetResult());
+
strlcpy(user->ident, isock->GetResult(), IDENTMAX+1);
+ OnUserDisconnect(user);
return true;
}
@@ -350,11 +381,12 @@ class ModuleIdent : public Module
{
/* User disconnect (generic socket detatch event) */
IdentRequestSocket *isock = NULL;
- if (user->Extend("ident_socket", isock))
+ if (user->GetExt("ident_socket", isock))
{
isock->Close();
delete isock;
user->Shrink("ident_socket");
+ ServerInstance->Log(DEBUG, "Removed ident socket from %s", user->nick);
}
}
};