]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
auth: fix deleteDomain() in lmdb backend 11764/head
authorKees Monshouwer <mind04@monshouwer.org>
Wed, 6 Jul 2022 15:23:38 +0000 (17:23 +0200)
committermind04 <mind04@monshouwer.org>
Wed, 6 Jul 2022 17:01:30 +0000 (19:01 +0200)
modules/lmdbbackend/lmdbbackend.cc

index 92dbb97293369f0abafde474f55cef22b04fd1cd..bab19269634a50ec993fef43cec4341a2d017c3f 100644 (file)
@@ -646,32 +646,48 @@ bool LMDBBackend::upgradeToSchemav3()
 
 bool LMDBBackend::deleteDomain(const DNSName& domain)
 {
-  auto doms = d_tdomains->getRWTransaction();
+  uint32_t id;
 
-  DomainInfo di;
-  auto id = doms.get<0>(domain, di);
-  if (!id)
-    return false;
+  { // get domain id
+    auto txn = d_tdomains->getROTransaction();
 
-  shared_ptr<RecordsRWTransaction> txn;
-  bool needCommit = false;
-  if (d_rwtxn && d_transactiondomainid == id) {
-    txn = d_rwtxn;
-    //    cout<<"Reusing open transaction"<<endl;
+    DomainInfo di;
+    id = txn.get<0>(domain, di);
   }
-  else {
-    //    cout<<"Making a new RW txn for delete domain"<<endl;
-    txn = getRecordsRWTransaction(id);
-    needCommit = true;
+
+  if (!d_rwtxn || d_transactiondomainid != id) {
+    throw DBException(std::string(__PRETTY_FUNCTION__) + " called without a proper transaction");
   }
 
-  doms.del(id);
-  deleteDomainRecords(*txn, id);
+  { // Remove metadata
+    auto txn = d_tmeta->getRWTransaction();
+    auto range = txn.equal_range<0>(domain);
 
-  if (needCommit)
-    txn->txn->commit();
+    for (auto& iter = range.first; iter != range.second; ++iter) {
+      iter.del();
+    }
+
+    txn.commit();
+  }
+
+  { // Remove cryptokeys
+    auto txn = d_tkdb->getRWTransaction();
+    auto range = txn.equal_range<0>(domain);
+
+    for (auto& iter = range.first; iter != range.second; ++iter) {
+      iter.del();
+    }
+
+    txn.commit();
+  }
+
+  // Remove zone
+  auto txn = d_tdomains->getRWTransaction();
+  txn.del(id);
+  txn.commit();
 
-  doms.commit();
+  // Remove records
+  deleteDomainRecords(*d_rwtxn, id);
 
   return true;
 }