From: Pieter Lexis Date: Wed, 31 Aug 2016 12:11:15 +0000 (+0200) Subject: Add getZoneCuts() function X-Git-Tag: rec-4.0.4~27^2~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5f4242ed2acebc5ce8bb91f2443e9b9ff0290d89;p=thirdparty%2Fpdns.git Add getZoneCuts() function --- diff --git a/pdns/validate.cc b/pdns/validate.cc index d1fdf4eef7..1a6b9354ee 100644 --- a/pdns/validate.cc +++ b/pdns/validate.cc @@ -79,6 +79,38 @@ static dState getDenial(cspmap_t &validrrsets, DNSName qname, uint16_t qtype) return ret; } +/* + * Finds all the zone-cuts between begin (longest name) and end (shortest name), + * returns them all zone cuts, including end, but (possibly) not begin + */ +vector getZoneCuts(const DNSName& begin, const DNSName& end, DNSRecordOracle& dro) +{ + vector ret; + if(!begin.isPartOf(end)) + throw PDNSException(end.toLogString() + "is not part of " + begin.toString()); + + DNSName qname(end); + vector labelsToAdd = begin.makeRelative(end).getRawLabels(); + + // The shortest name is assumed to a zone cut + ret.push_back(qname); + while(qname != begin) { + qname = DNSName(labelsToAdd.back()) + qname; + labelsToAdd.pop_back(); + bool foundCut = false; + auto records = dro.get(qname, (uint16_t)QType::NS); + for (const auto record : records) { + if(record.d_name != qname || record.d_type != QType::NS) + continue; + foundCut = true; + break; + } + if (foundCut) + ret.push_back(qname); + } + return ret; +} + void validateWithKeySet(const cspmap_t& rrsets, cspmap_t& validated, const keyset_t& keys) { validated.clear();