1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2008 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 * ---------------------------------------------------
17 UserResolver::UserResolver(InspIRCd* Instance, User* user, std::string to_resolve, QueryType qt, bool &cache) :
18 Resolver(Instance, to_resolve, qt, cache), bound_user(user)
20 this->fwd = (qt == DNS_QUERY_A || qt == DNS_QUERY_AAAA);
21 this->bound_fd = user->GetFd();
24 void UserResolver::OnLookupComplete(const std::string &result, unsigned int ttl, bool cached, int resultnum)
26 /* We are only interested in the first matching result */
30 UserResolver *res_forward; // for forward-resolution
32 if ((!this->fwd) && (ServerInstance->SE->GetRef(this->bound_fd) == this->bound_user))
34 this->bound_user->stored_host = result;
37 /* Check we didnt time out */
38 if (this->bound_user->registered != REG_ALL)
42 if (this->bound_user->GetProtocolFamily() == AF_INET6)
44 /* IPV6 forward lookup (with possibility of 4in6) */
45 const char* ip = this->bound_user->GetIPString();
46 res_forward = new UserResolver(this->ServerInstance, this->bound_user, result, (!strncmp(ip, "0::ffff:", 8) ? DNS_QUERY_A : DNS_QUERY_AAAA), lcached);
49 /* IPV4 lookup (mixed protocol mode) */
52 /* IPV4 lookup (ipv4 only mode) */
53 res_forward = new UserResolver(this->ServerInstance, this->bound_user, result, DNS_QUERY_A, lcached);
55 this->ServerInstance->AddResolver(res_forward, lcached);
58 catch (CoreException& e)
60 ServerInstance->Logs->Log("RESOLVER", DEBUG,"Error in resolver: %s",e.GetReason());
63 else if ((this->fwd) && (ServerInstance->SE->GetRef(this->bound_fd) == this->bound_user))
65 /* Both lookups completed */
66 std::string result2("0::ffff:");
67 result2.append(result);
68 if (this->bound_user->GetIPString() == result || this->bound_user->GetIPString() == result2)
70 std::string hostname = this->bound_user->stored_host;
71 if (hostname.length() < 65)
73 /* Check we didnt time out */
74 if ((this->bound_user->registered != REG_ALL) && (!this->bound_user->dns_done))
76 /* Hostnames starting with : are not a good thing (tm) */
77 if (hostname[0] == ':')
78 hostname.insert(0, "0");
80 this->bound_user->WriteServ("NOTICE Auth :*** Found your hostname (%s)%s", hostname.c_str(), (cached ? " -- cached" : ""));
81 this->bound_user->dns_done = true;
82 this->bound_user->dhost.assign(hostname, 0, 64);
83 this->bound_user->host.assign(hostname, 0, 64);
84 /* Invalidate cache */
85 this->bound_user->InvalidateCache();
90 if (!this->bound_user->dns_done)
92 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());
93 this->bound_user->dns_done = true;
99 if (!this->bound_user->dns_done)
101 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());
102 this->bound_user->dns_done = true;
108 void UserResolver::OnError(ResolverError e, const std::string &errormessage)
110 if (ServerInstance->SE->GetRef(this->bound_fd) == this->bound_user)
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;
114 ServerInstance->stats->statsDnsBad++;