]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
auth: encapsulate lookup()-cleanup 14597/head
authorChris Hofstaedtler <chris.hofstaedtler@deduktiva.com>
Tue, 27 Aug 2024 17:49:33 +0000 (19:49 +0200)
committerChris Hofstaedtler <chris.hofstaedtler@deduktiva.com>
Tue, 27 Aug 2024 17:49:33 +0000 (19:49 +0200)
pdns/packethandler.cc
pdns/ueberbackend.cc
pdns/ueberbackend.hh

index 797922b38723d0f7df1f5b970fe3a5cfeb2e781d..3d385ed7b54ce6f6996d4762e270fc7a42b37b6f 100644 (file)
@@ -439,7 +439,7 @@ bool PacketHandler::getBestWildcard(DNSPacket& p, const DNSName &target, DNSName
             }
           }
           catch (std::exception &e) {
-            while (B.get(rr)) ;                 // don't leave DB handle in bad state
+            B.lookupEnd();                 // don't leave DB handle in bad state
 
             throw;
           }
@@ -465,7 +465,7 @@ bool PacketHandler::getBestWildcard(DNSPacket& p, const DNSName &target, DNSName
     B.lookup(QType(QType::ANY), subdomain, d_sd.domain_id, &p);
     if (B.get(rr)) {
       DLOG(g_log<<"No wildcard match, ancestor exists"<<endl);
-      while (B.get(rr)) ;
+      B.lookupEnd();
       break;
     }
     wildcard=subdomain;
@@ -501,7 +501,7 @@ DNSName PacketHandler::doAdditionalServiceProcessing(const DNSName &firstTarget,
           break;
         }
         default:
-          while (B.get(rr)) ;              // don't leave DB handle in bad state
+          B.lookupEnd();              // don't leave DB handle in bad state
 
           throw PDNSException("Unknown type (" + QType(qtype).toString() + ") for additional service processing");
       }
@@ -1623,7 +1623,7 @@ std::unique_ptr<DNSPacket> PacketHandler::doQuestion(DNSPacket& p)
             }
           }
           catch(std::exception &e) {
-            while (B.get(rr)) ;              // don't leave DB handle in bad state
+            B.lookupEnd();              // don't leave DB handle in bad state
 
             r=p.replyPacket();
             r->setRcode(RCode::ServFail);
index 79f2b7e47ec678d1f090fc14161ebcdb65f0a96a..a0e986115a56fd18b059178df487eed8da03f18b 100644 (file)
@@ -801,6 +801,20 @@ bool UeberBackend::get(DNSZoneRecord& resourceRecord)
   return false;
 }
 
+void UeberBackend::lookupEnd()
+{
+  if (!d_negcached && !d_cached) {
+    DNSZoneRecord zoneRecord;
+    while (d_handle.get(zoneRecord)) {
+      // Read all answers so the backends will close any database handles they might have allocated.
+      // One day this could be optimized.
+    }
+  }
+
+  d_answers.clear();
+  d_cached = d_negcached = false;
+}
+
 // TSIG
 //
 bool UeberBackend::setTSIGKey(const DNSName& name, const DNSName& algorithm, const string& content)
index be5859c9d47f2aafb26324fa03deaddb7fdde2af..0565abfaea0b2e147d92c9e91b63539497493607 100644 (file)
@@ -94,12 +94,15 @@ public:
   };
 
   void lookup(const QType& qtype, const DNSName& qname, int zoneId, DNSPacket* pkt_p = nullptr);
+  /** Read a single record from a lookup(...) result. */
+  bool get(DNSZoneRecord& resourceRecord);
+  /** Close state created by lookup(...). */
+  void lookupEnd();
 
   /** Determines if we are authoritative for a zone, and at what level */
   bool getAuth(const DNSName& target, const QType& qtype, SOAData* soaData, bool cachedOk = true);
   /** Load SOA info from backends, ignoring the cache.*/
   bool getSOAUncached(const DNSName& domain, SOAData& soaData);
-  bool get(DNSZoneRecord& resourceRecord);
   void getAllDomains(vector<DomainInfo>* domains, bool getSerial, bool include_disabled);
 
   void getUnfreshSecondaryInfos(vector<DomainInfo>* domains);