]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
auth: avoid metadata cache polution in the dnsupdate code
authorKees Monshouwer <mind04@monshouwer.org>
Wed, 26 Aug 2020 15:03:10 +0000 (17:03 +0200)
committermind04 <mind04@monshouwer.org>
Sun, 30 Aug 2020 20:42:57 +0000 (22:42 +0200)
pdns/packethandler.hh
pdns/rfc2136handler.cc

index b196d984da35659819161ac071367ec351983bbd..c4c38018c155152f9839dbb10362b4a7b847e68a 100644 (file)
@@ -85,7 +85,7 @@ private:
   uint performUpdate(const string &msgPrefix, const DNSRecord *rr, DomainInfo *di, bool isPresigned, bool* narrow, bool* haveNSEC3, NSEC3PARAMRecordContent *ns3pr, bool *updatedSerial);
   int checkUpdatePrescan(const DNSRecord *rr);
   int checkUpdatePrerequisites(const DNSRecord *rr, DomainInfo *di);
-  void increaseSerial(const string &msgPrefix, const DomainInfo *di, bool haveNSEC3, bool narrow, const NSEC3PARAMRecordContent *ns3pr);
+  void increaseSerial(const string &msgPrefix, const DomainInfo *di, const string& soaEditSetting, bool haveNSEC3, bool narrow, const NSEC3PARAMRecordContent *ns3pr);
 
   void makeNXDomain(DNSPacket& p, std::unique_ptr<DNSPacket>& r, const DNSName& target, const DNSName& wildcard, const SOAData& sd);
   void makeNOError(DNSPacket& p, std::unique_ptr<DNSPacket>& r, const DNSName& target, const DNSName& wildcard, const SOAData& sd, int mode);
index 15902766d44c75a379ced3011436673621a7c456..1d8cf6750b75daca7290d109347ced7b0b7cea1f 100644 (file)
@@ -122,11 +122,10 @@ uint PacketHandler::performUpdate(const string &msgPrefix, const DNSRecord *rr,
     if (rrType == QType::NSEC3PARAM) {
       g_log<<Logger::Notice<<msgPrefix<<"Adding/updating NSEC3PARAM for zone, resetting ordernames."<<endl;
 
-      NSEC3PARAMRecordContent nsec3param(rr->d_content->getZoneRepresentation(), di->zone.toString() /* FIXME400 huh */);
+      *ns3pr = NSEC3PARAMRecordContent(rr->d_content->getZoneRepresentation(), di->zone.toString() /* FIXME400 huh */);
       *narrow = false; // adding a NSEC3 will cause narrow mode to be dropped, as you cannot specify that in a NSEC3PARAM record
-      d_dk.setNSEC3PARAM(di->zone, nsec3param, (*narrow));
-
-      *haveNSEC3 = d_dk.getNSEC3PARAM(di->zone, ns3pr, narrow);
+      d_dk.setNSEC3PARAM(di->zone, *ns3pr, (*narrow));
+      *haveNSEC3 = true;
 
       vector<DNSResourceRecord> rrs;
       set<DNSName> qnames, nssets, dssets;
@@ -401,15 +400,16 @@ uint PacketHandler::performUpdate(const string &msgPrefix, const DNSRecord *rr,
         d_dk.unsetNSEC3PARAM(rr->d_name);
       else if (rr->d_class == QClass::NONE) {
         NSEC3PARAMRecordContent nsec3rr(rr->d_content->getZoneRepresentation(), di->zone.toString() /* FIXME400 huh */);
-        if (ns3pr->getZoneRepresentation() == nsec3rr.getZoneRepresentation())
+        if (*haveNSEC3 && ns3pr->getZoneRepresentation() == nsec3rr.getZoneRepresentation())
           d_dk.unsetNSEC3PARAM(rr->d_name);
         else
           return 0;
       } else
         return 0;
 
-      // We retrieve new values, other RR's in this update package might need it as well.
-      *haveNSEC3 = d_dk.getNSEC3PARAM(di->zone, ns3pr, narrow);
+      // Update NSEC3 variables, other RR's in this update package might need them as well.
+      *haveNSEC3 = false;
+      *narrow = false;
 
       vector<DNSResourceRecord> rrs;
       set<DNSName> qnames, nssets, dssets, ents;
@@ -910,6 +910,8 @@ int PacketHandler::processUpdate(DNSPacket& p) {
     bool narrow=false;
     bool haveNSEC3 = d_dk.getNSEC3PARAM(di.zone, &ns3pr, &narrow);
     bool isPresigned = d_dk.isPresigned(di.zone);
+    string soaEditSetting;
+    d_dk.getSoaEdit(di.zone, soaEditSetting);
 
     // 3.4.2 - Perform the updates.
     // There's a special condition where deleting the last NS record at zone apex is never deleted (3.4.2.4)
@@ -1012,7 +1014,7 @@ int PacketHandler::processUpdate(DNSPacket& p) {
 
     // Section 3.6 - Update the SOA serial - outside of performUpdate because we do a SOA update for the complete update message
     if (changedRecords > 0 && !updatedSerial) {
-      increaseSerial(msgPrefix, &di, haveNSEC3, narrow, &ns3pr);
+      increaseSerial(msgPrefix, &di, soaEditSetting, haveNSEC3, narrow, &ns3pr);
       changedRecords++;
     }
 
@@ -1024,6 +1026,7 @@ int PacketHandler::processUpdate(DNSPacket& p) {
 
       S.deposit("dnsupdate-changes", changedRecords);
 
+      d_dk.clearMetaCache(di.zone);
       // Purge the records!
       string zone(di.zone.toString());
       zone.append("$");
@@ -1073,7 +1076,7 @@ int PacketHandler::processUpdate(DNSPacket& p) {
   }
 }
 
-void PacketHandler::increaseSerial(const string &msgPrefix, const DomainInfo *di, bool haveNSEC3, bool narrow, const NSEC3PARAMRecordContent *ns3pr) {
+void PacketHandler::increaseSerial(const string &msgPrefix, const DomainInfo *di, const string& soaEditSetting,  bool haveNSEC3, bool narrow, const NSEC3PARAMRecordContent *ns3pr) {
   SOAData sd;
   if (!di->backend->getSOA(di->zone, sd)) {
     throw PDNSException("SOA-Serial update failed because there was no SOA. Wowie.");
@@ -1088,8 +1091,6 @@ void PacketHandler::increaseSerial(const string &msgPrefix, const DomainInfo *di
   if (!soaEdit2136Setting.empty()) {
     soaEdit2136 = soaEdit2136Setting[0];
     if (pdns_iequals(soaEdit2136, "SOA-EDIT") || pdns_iequals(soaEdit2136,"SOA-EDIT-INCREASE") ){
-      string soaEditSetting;
-      d_dk.getSoaEdit(di->zone, soaEditSetting);
       if (soaEditSetting.empty()) {
         g_log<<Logger::Error<<msgPrefix<<"Using "<<soaEdit2136<<" for SOA-EDIT-DNSUPDATE increase on DNS update, but SOA-EDIT is not set for domain \""<< di->zone <<"\". Using DEFAULT for SOA-EDIT-DNSUPDATE"<<endl;
         soaEdit2136 = "DEFAULT";