From: Fred Morcos Date: Fri, 3 Jun 2022 10:48:39 +0000 (+0200) Subject: Only add PTR records for the canonical hostname X-Git-Tag: auth-4.8.0-alpha0~63^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9591b646509bab42e620417c8fe9eab27c837c9c;p=thirdparty%2Fpdns.git Only add PTR records for the canonical hostname --- diff --git a/pdns/recursordist/test-reczones-helpers.cc b/pdns/recursordist/test-reczones-helpers.cc index f089c7cb0f..aea3759bfe 100644 --- a/pdns/recursordist/test-reczones-helpers.cc +++ b/pdns/recursordist/test-reczones-helpers.cc @@ -72,7 +72,6 @@ struct Fixture DNSRecord("1.0.168.192.in-addr.arpa", makeLocalhostDRC(), QType::NS), DNSRecord("1.0.168.192.in-addr.arpa", makeLocalhostRootDRC(), QType::SOA), DNSRecord("1.0.168.192.in-addr.arpa", makePtrDRC("foo."), QType::PTR), - DNSRecord("1.0.168.192.in-addr.arpa", makePtrDRC("bar."), QType::PTR), }); addDomainMapFixtureEntry("baz", QType::A, "192.168.0.2"); addDomainMapFixtureEntry( @@ -108,7 +107,6 @@ struct Fixture DNSRecord("b.a.9.8.7.6.5.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa", makeLocalhostDRC(), QType::NS), DNSRecord("b.a.9.8.7.6.5.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa", makeLocalhostRootDRC(), QType::SOA), DNSRecord("b.a.9.8.7.6.5.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa", makePtrDRC("foo6."), QType::PTR), - DNSRecord("b.a.9.8.7.6.5.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa", makePtrDRC("bar6."), QType::PTR), }); addDomainMapFixtureEntry("localhost", QType::AAAA, "::1"); @@ -119,7 +117,6 @@ struct Fixture DNSRecord("1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa", makeLocalhostDRC(), QType::NS), DNSRecord("1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa", makeLocalhostRootDRC(), QType::SOA), DNSRecord("1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa", makePtrDRC("localhost."), QType::PTR), - DNSRecord("1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa", makePtrDRC("self."), QType::PTR), }); addDomainMapFixtureEntry("some", QType::AAAA, "2001:db8::567:89ac"); @@ -131,8 +128,6 @@ struct Fixture DNSRecord("c.a.9.8.7.6.5.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa", makeLocalhostDRC(), QType::NS), DNSRecord("c.a.9.8.7.6.5.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa", makeLocalhostRootDRC(), QType::SOA), DNSRecord("c.a.9.8.7.6.5.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa", makePtrDRC("some.address.somewhere."), QType::PTR), - DNSRecord("c.a.9.8.7.6.5.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa", makePtrDRC("some."), QType::PTR), - DNSRecord("c.a.9.8.7.6.5.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa", makePtrDRC("some.address."), QType::PTR), }); } diff --git a/pdns/reczones-helpers.cc b/pdns/reczones-helpers.cc index c71d2db1ab..8f613ac92f 100644 --- a/pdns/reczones-helpers.cc +++ b/pdns/reczones-helpers.cc @@ -72,7 +72,7 @@ static void addToDomainMap(SyncRes::domainmap_t& newMap, static void makeNameToIPZone(SyncRes::domainmap_t& newMap, const DNSName& hostname, - const ComboAddress& addr, + const ComboAddress& address, Logr::log_t log) { DNSRecord dr; @@ -80,33 +80,30 @@ static void makeNameToIPZone(SyncRes::domainmap_t& newMap, SyncRes::AuthDomain ad = makeSOAAndNSNodes(dr, "localhost."); - auto recType = addr.isIPv6() ? QType::AAAA : QType::A; + auto recType = address.isIPv6() ? QType::AAAA : QType::A; dr.d_type = recType; - dr.d_content = DNSRecordContent::mastermake(recType, 1, addr.toStringNoInterface()); + dr.d_content = DNSRecordContent::mastermake(recType, 1, address.toStringNoInterface()); ad.d_records.insert(dr); addToDomainMap(newMap, ad, dr.d_name, log); } static void makeIPToNamesZone(SyncRes::domainmap_t& newMap, - const ComboAddress& addr, - const std::vector& parts, + const ComboAddress& address, + const std::string& canonicalHostname, Logr::log_t log) { DNSRecord dr; - dr.d_name = DNSName(addr.toStringReversed()); - dr.d_name.appendRawLabel(addr.isIPv4() ? "in-addr" : "ip6"); + dr.d_name = DNSName(address.toStringReversed()); + dr.d_name.appendRawLabel(address.isIPv4() ? "in-addr" : "ip6"); dr.d_name.appendRawLabel("arpa"); SyncRes::AuthDomain ad = makeSOAAndNSNodes(dr, DNSName("localhost.")); - // Go over the hostname and aliases (parts[1], parts[2], etc...) and add PTR entries for - // reverse lookups. + // Add a PTR entry for the primary name for reverse lookups. dr.d_type = QType::PTR; - for (auto name = parts.cbegin() + 1; name != parts.cend(); ++name) { - dr.d_content = DNSRecordContent::mastermake(QType::PTR, 1, DNSName(*name).toString()); - ad.d_records.insert(dr); - } + dr.d_content = DNSRecordContent::mastermake(QType::PTR, 1, DNSName(canonicalHostname).toString()); + ad.d_records.insert(dr); addToDomainMap(newMap, ad, dr.d_name, log, false, true); } @@ -148,8 +145,8 @@ void addForwardAndReverseLookupEntries(SyncRes::domainmap_t& newMap, } } - // Add entries for reverse lookups. - makeIPToNamesZone(newMap, address, parts, log); + // Add entries for the primary name for reverse lookups. + makeIPToNamesZone(newMap, address, parts[1], log); } bool parseEtcHostsLine(std::vector& parts, std::string& line)