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 * ---------------------------------------------------
14 /* $Core: libIRCDuserresolver */
18 UserResolver::UserResolver(InspIRCd* Instance, User* user, std::string to_resolve, QueryType qt, bool &cache) :
19 Resolver(Instance, to_resolve, qt, cache), bound_user(user)
21 this->fwd = (qt == DNS_QUERY_A || qt == DNS_QUERY_AAAA);
22 this->bound_fd = user->GetFd();
25 void UserResolver::OnLookupComplete(const std::string &result, unsigned int ttl, bool cached, int resultnum)
27 /* We are only interested in the first matching result */
31 if ((!this->fwd) && (ServerInstance->SE->GetRef(this->bound_fd) == this->bound_user))
33 this->bound_user->stored_host = result;
36 /* Check we didnt time out */
37 if (this->bound_user->registered != REG_ALL)
41 if (this->bound_user->GetProtocolFamily() == AF_INET6)
43 /* IPV6 forward lookup (with possibility of 4in6) */
44 const char* ip = this->bound_user->GetIPString();
45 bound_user->res_forward = new UserResolver(this->ServerInstance, this->bound_user, result, (!strncmp(ip, "0::ffff:", 8) ? DNS_QUERY_A : DNS_QUERY_AAAA), lcached);
48 /* IPV4 lookup (mixed protocol mode) */
50 /* IPV4 lookup (ipv4 only mode) */
51 bound_user->res_forward = new UserResolver(this->ServerInstance, this->bound_user, result, DNS_QUERY_A, lcached);
52 this->ServerInstance->AddResolver(bound_user->res_forward, lcached);
55 catch (CoreException& e)
57 ServerInstance->Log(DEBUG,"Error in resolver: %s",e.GetReason());
60 else if ((this->fwd) && (ServerInstance->SE->GetRef(this->bound_fd) == this->bound_user))
62 /* Both lookups completed */
63 std::string result2("0::ffff:");
64 result2.append(result);
65 if (this->bound_user->GetIPString() == result || this->bound_user->GetIPString() == result2)
67 std::string hostname = this->bound_user->stored_host;
68 if (hostname.length() < 65)
70 /* Check we didnt time out */
71 if ((this->bound_user->registered != REG_ALL) && (!this->bound_user->dns_done))
73 /* Hostnames starting with : are not a good thing (tm) */
74 if (*(hostname.c_str()) == ':')
75 hostname.insert(0, "0");
77 this->bound_user->WriteServ("NOTICE Auth :*** Found your hostname (%s)%s", hostname.c_str(), (cached ? " -- cached" : ""));
78 this->bound_user->dns_done = true;
79 strlcpy(this->bound_user->dhost, hostname.c_str(),64);
80 strlcpy(this->bound_user->host, hostname.c_str(),64);
81 /* Invalidate cache */
82 this->bound_user->InvalidateCache();
87 if (!this->bound_user->dns_done)
89 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());
90 this->bound_user->dns_done = true;
96 if (!this->bound_user->dns_done)
98 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());
99 this->bound_user->dns_done = true;
105 void UserResolver::OnError(ResolverError e, const std::string &errormessage)
107 if (ServerInstance->SE->GetRef(this->bound_fd) == this->bound_user)
109 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());
110 this->bound_user->dns_done = true;
111 ServerInstance->stats->statsDnsBad++;