summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/users.h20
-rw-r--r--src/cmd_nick.cpp2
-rw-r--r--src/inspircd.cpp2
-rw-r--r--src/users.cpp43
4 files changed, 65 insertions, 2 deletions
diff --git a/include/users.h b/include/users.h
index c91b2635a..f1184ea24 100644
--- a/include/users.h
+++ b/include/users.h
@@ -29,6 +29,7 @@
#include "inspstring.h"
#include "connection.h"
#include "hashcomp.h"
+#include "dns.h"
#include "cull_list.h"
enum ChanStatus {
@@ -68,6 +69,18 @@ class Invited : public classbase
irc::string channel;
};
+class UserResolver : public Resolver
+{
+ private:
+ userrec* bound_user;
+ int bound_fd;
+ public:
+ UserResolver(userrec* user, std::string to_resolve, bool forward) : Resolver(to_resolve, forward), bound_user(user) { };
+
+ void OnLookupComplete(const std::string &result);
+ void OnError(ResolverError e);
+};
+
/** Holds information relevent to <connect allow> and <connect deny> tags in the config file.
*/
@@ -146,6 +159,13 @@ class userrec : public connection
*/
InvitedList invites;
public:
+ /** Resolvers for looking up this users hostname
+ */
+ UserResolver* res_forward;
+ UserResolver* res_reverse;
+ std::string stored_host;
+
+ void StartDNSLookup();
/** The users nickname.
* An invalid nickname indicates an unregistered connection prior to the NICK command.
diff --git a/src/cmd_nick.cpp b/src/cmd_nick.cpp
index ddcb04940..17da0e8c8 100644
--- a/src/cmd_nick.cpp
+++ b/src/cmd_nick.cpp
@@ -149,7 +149,7 @@ void cmd_nick::Handle (const char** parameters, int pcnt, userrec *user)
}
else
{
- user->dns_done = (!lookup_dns(user->nick));
+ user->StartDNSLookup();
if (user->dns_done)
log(DEBUG,"Aborting dns lookup of %s because dns server experienced a failure.",user->nick);
}
diff --git a/src/inspircd.cpp b/src/inspircd.cpp
index a72ee2534..7b298418e 100644
--- a/src/inspircd.cpp
+++ b/src/inspircd.cpp
@@ -827,7 +827,7 @@ void InspIRCd::DoOneIteration(bool process_module_sockets)
case X_LISTEN:
- log(DEBUG,"Type: X_LISTEN_MODULE: fd=%d",activefds[activefd]);
+ log(DEBUG,"Type: X_LISTEN: fd=%d",activefds[activefd]);
/* It's a listener */
uslen = sizeof(sock_us);
diff --git a/src/users.cpp b/src/users.cpp
index 83d62ecf7..b6317a3f0 100644
--- a/src/users.cpp
+++ b/src/users.cpp
@@ -137,6 +137,48 @@ bool userrec::ProcessNoticeMasks(const char *sm)
return true;
}
+void userrec::StartDNSLookup()
+{
+ log(DEBUG,"Commencing forward lookup");
+ res_reverse = new UserResolver(this, insp_ntoa(this->ip4), false);
+}
+
+void UserResolver::OnLookupComplete(const std::string &result)
+{
+ if ((!this->fwd) && (fd_ref_table[this->bound_fd] == this->bound_user))
+ {
+ log(DEBUG,"Commencing reverse lookup");
+ this->bound_user->stored_host = result;
+ bound_user->res_reverse = new UserResolver(this->bound_user, result, true);
+ }
+ else if ((this->fwd) && (fd_ref_table[this->bound_fd] == this->bound_user))
+ {
+ /* Both lookups completed */
+ if (insp_ntoa(this->bound_user->ip4) == result)
+ {
+ std::string hostname = this->bound_user->stored_host;
+ if (hostname.length() < 64)
+ {
+ WriteServ(this->bound_fd, "*** Found your hostname (%s)", this->bound_user->stored_host.c_str());
+ this->bound_user->dns_done = true;
+ strlcpy(this->bound_user->dhost, hostname.c_str(),64);
+ strlcpy(this->bound_user->host, hostname.c_str(),64);
+ }
+ }
+ }
+}
+
+void UserResolver::OnError(ResolverError e)
+{
+ if (fd_ref_table[this->bound_fd] == this->bound_user)
+ {
+ /* Error message here */
+ WriteServ(this->bound_fd, "*** Could not resolve your hostname, using your IP address (%s) instead.", insp_ntoa(this->bound_user->ip4));
+ this->bound_user->dns_done = true;
+ }
+}
+
+
bool userrec::IsNoticeMaskSet(unsigned char sm)
{
return (snomasks[sm-65]);
@@ -198,6 +240,7 @@ userrec::userrec()
haspassed = dns_done = false;
recvq = "";
sendq = "";
+ res_forward = res_reverse = NULL;
chans.clear();
invites.clear();
chans.resize(MAXCHANS);