summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Powell <petpow@saberuk.com>2019-10-21 13:34:09 +0100
committerPeter Powell <petpow@saberuk.com>2019-10-21 13:35:37 +0100
commit93d4ad71961084caf7ac46c22028c79a2fcf461e (patch)
tree1c04f3eb3097636f0fb152dc97b7faccdb3917d4
parentede5d4f612fed4462893aa8c2f67c44e9ec07b25 (diff)
Remove duplicate code in core_hostname_lookup.
- The lookup type is already stored in the question. - core_dns validates hostnames by IsHost already.
-rw-r--r--src/coremods/core_hostname_lookup.cpp33
1 files changed, 5 insertions, 28 deletions
diff --git a/src/coremods/core_hostname_lookup.cpp b/src/coremods/core_hostname_lookup.cpp
index 5bd55f2bd..31f5edd8c 100644
--- a/src/coremods/core_hostname_lookup.cpp
+++ b/src/coremods/core_hostname_lookup.cpp
@@ -29,13 +29,10 @@ namespace
*/
class UserResolver : public DNS::Request
{
+ private:
/** UUID we are looking up */
const std::string uuid;
- /** True if the lookup is forward, false if is a reverse lookup
- */
- const bool fwd;
-
public:
/** Create a resolver.
* @param mgr DNS Manager
@@ -47,7 +44,6 @@ class UserResolver : public DNS::Request
UserResolver(DNS::Manager* mgr, Module* me, LocalUser* user, const std::string& to_resolve, DNS::QueryType qt)
: DNS::Request(mgr, me, to_resolve, qt)
, uuid(user->uuid)
- , fwd(qt == DNS::QUERY_A || qt == DNS::QUERY_AAAA)
{
}
@@ -73,7 +69,7 @@ class UserResolver : public DNS::Request
ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "DNS result for %s: '%s' -> '%s'", uuid.c_str(), ans_record->name.c_str(), ans_record->rdata.c_str());
- if (!fwd)
+ if (this->question.type == DNS::QUERY_PTR)
{
UserResolver* res_forward;
if (bound_user->client_sa.family() == AF_INET6)
@@ -99,7 +95,7 @@ class UserResolver : public DNS::Request
dl->set(bound_user, 0);
}
}
- else
+ else if (this->question.type == DNS::QUERY_A || this->question.type == DNS::QUERY_AAAA)
{
/* Both lookups completed */
@@ -126,27 +122,8 @@ class UserResolver : public DNS::Request
if (rev_match)
{
- std::string* hostname = &(this->question.name);
-
- if (hostname == NULL)
- {
- ServerInstance->Logs->Log(MODNAME, LOG_DEFAULT, "ERROR: User has no hostname attached when doing a forward lookup");
- bound_user->WriteNotice("*** There was an internal error resolving your host, using your IP address (" + bound_user->GetIPString() + ") instead.");
- return;
- }
- else if (hostname->length() <= ServerInstance->Config->Limits.MaxHost)
- {
- /* Hostnames starting with : are not a good thing (tm) */
- if ((*hostname)[0] == ':')
- hostname->insert(0, "0");
-
- bound_user->WriteNotice("*** Found your hostname (" + *hostname + (r->cached ? ") -- cached" : ")"));
- bound_user->ChangeRealHost(hostname->substr(0, ServerInstance->Config->Limits.MaxHost), true);
- }
- else
- {
- bound_user->WriteNotice("*** Your hostname is longer than the maximum of " + ConvToStr(ServerInstance->Config->Limits.MaxHost) + " characters, using your IP address (" + bound_user->GetIPString() + ") instead.");
- }
+ bound_user->WriteNotice("*** Found your hostname (" + this->question.name + (r->cached ? ") -- cached" : ")"));
+ bound_user->ChangeRealHost(this->question.name, true);
}
else
{