1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2007 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
16 UserResolver::UserResolver(InspIRCd* Instance, User* user, std::string to_resolve, QueryType qt, bool &cache) :
17 Resolver(Instance, to_resolve, qt, cache), bound_user(user)
19 this->fwd = (qt == DNS_QUERY_A || qt == DNS_QUERY_AAAA);
20 this->bound_fd = user->GetFd();
23 void UserResolver::OnLookupComplete(const std::string &result, unsigned int ttl, bool cached, int resultnum)
25 /* We are only interested in the first matching result */
29 if ((!this->fwd) && (ServerInstance->SE->GetRef(this->bound_fd) == this->bound_user))
31 this->bound_user->stored_host = result;
34 /* Check we didnt time out */
35 if (this->bound_user->registered != REG_ALL)
39 if (this->bound_user->GetProtocolFamily() == AF_INET6)
41 /* IPV6 forward lookup (with possibility of 4in6) */
42 const char* ip = this->bound_user->GetIPString();
43 bound_user->res_forward = new UserResolver(this->ServerInstance, this->bound_user, result, (!strncmp(ip, "0::ffff:", 8) ? DNS_QUERY_A : DNS_QUERY_AAAA), cached);
46 /* IPV4 lookup (mixed protocol mode) */
48 /* IPV4 lookup (ipv4 only mode) */
49 bound_user->res_forward = new UserResolver(this->ServerInstance, this->bound_user, result, DNS_QUERY_A, cached);
50 this->ServerInstance->AddResolver(bound_user->res_forward, cached);
53 catch (CoreException& e)
55 ServerInstance->Log(DEBUG,"Error in resolver: %s",e.GetReason());
58 else if ((this->fwd) && (ServerInstance->SE->GetRef(this->bound_fd) == this->bound_user))
60 /* Both lookups completed */
61 std::string result2("0::ffff:");
62 result2.append(result);
63 if (this->bound_user->GetIPString() == result || this->bound_user->GetIPString() == result2)
65 std::string hostname = this->bound_user->stored_host;
66 if (hostname.length() < 65)
68 /* Check we didnt time out */
69 if ((this->bound_user->registered != REG_ALL) && (!this->bound_user->dns_done))
71 /* Hostnames starting with : are not a good thing (tm) */
72 if (*(hostname.c_str()) == ':')
73 hostname.insert(0, "0");
75 this->bound_user->WriteServ("NOTICE Auth :*** Found your hostname (%s)%s", hostname.c_str(), (cached ? " -- cached" : ""));
76 this->bound_user->dns_done = true;
77 strlcpy(this->bound_user->dhost, hostname.c_str(),64);
78 strlcpy(this->bound_user->host, hostname.c_str(),64);
79 /* Invalidate cache */
80 this->bound_user->InvalidateCache();
85 if (!this->bound_user->dns_done)
87 this->bound_user->WriteServ("NOTICE Auth :*** Your hostname is longer than the maximum of 64 characters, using your IP address (%s) instead.", this->bound_user->GetIPString());
88 this->bound_user->dns_done = true;
94 if (!this->bound_user->dns_done)
96 this->bound_user->WriteServ("NOTICE Auth :*** Your hostname does not match up with your IP address. Sorry, using your IP address (%s) instead.", this->bound_user->GetIPString());
97 this->bound_user->dns_done = true;
103 void UserResolver::OnError(ResolverError e, const std::string &errormessage)
105 if (ServerInstance->SE->GetRef(this->bound_fd) == this->bound_user)
107 /* Since dns timeout is implemented outside of the resolver, this was a race condition that could result in this message being sent *after*
108 * the user was fully connected. This check fixes that issue - Special */
109 if (!this->bound_user->dns_done)
111 /* Error message here */
112 this->bound_user->WriteServ("NOTICE Auth :*** Could not resolve your hostname: %s; using your IP address (%s) instead.", errormessage.c_str(), this->bound_user->GetIPString());
113 this->bound_user->dns_done = true;