]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
auth: ignore broken SOA content in getAllDomains(),
authorKees Monshouwer <mind04@monshouwer.org>
Thu, 30 Sep 2021 20:46:28 +0000 (22:46 +0200)
committermind04 <mind04@monshouwer.org>
Tue, 5 Oct 2021 08:22:29 +0000 (10:22 +0200)
avoid unnecessary parsing of SOA content

21 files changed:
modules/bindbackend/bindbackend2.cc
modules/bindbackend/bindbackend2.hh
modules/geoipbackend/geoipbackend.cc
modules/geoipbackend/geoipbackend.hh
modules/lmdbbackend/lmdbbackend.cc
modules/lmdbbackend/lmdbbackend.hh
modules/lua2backend/lua2api2.hh
modules/remotebackend/remotebackend.cc
modules/remotebackend/remotebackend.hh
modules/remotebackend/test-remotebackend.cc
modules/tinydnsbackend/tinydnsbackend.cc
modules/tinydnsbackend/tinydnsbackend.hh
pdns/backends/gsql/gsqlbackend.cc
pdns/backends/gsql/gsqlbackend.hh
pdns/dnsbackend.cc
pdns/dnsbackend.hh
pdns/dynhandler.cc
pdns/pdnsutil.cc
pdns/ueberbackend.cc
pdns/ueberbackend.hh
pdns/ws-auth.cc

index 933302b7262189d369a93a87b4905730d388a180..1443681a39b7494f56a58bef0bdd78d7cc7ace64 100644 (file)
@@ -363,7 +363,7 @@ void Bind2Backend::getUpdatedMasters(vector<DomainInfo>* changedDomains)
   }
 }
 
-void Bind2Backend::getAllDomains(vector<DomainInfo>* domains, bool include_disabled)
+void Bind2Backend::getAllDomains(vector<DomainInfo>* domains, bool getSerial, bool include_disabled)
 {
   SOAData soadata;
 
@@ -384,17 +384,19 @@ void Bind2Backend::getAllDomains(vector<DomainInfo>* domains, bool include_disab
     };
   }
 
-  for (DomainInfo& di : *domains) {
-    // do not corrupt di if domain supplied by another backend.
-    if (di.backend != this)
-      continue;
-    try {
-      this->getSOA(di.zone, soadata);
-    }
-    catch (...) {
-      continue;
+  if (getSerial) {
+    for (DomainInfo& di : *domains) {
+      // do not corrupt di if domain supplied by another backend.
+      if (di.backend != this)
+        continue;
+      try {
+        this->getSOA(di.zone, soadata);
+      }
+      catch (...) {
+        continue;
+      }
+      di.serial = soadata.serial;
     }
-    di.serial = soadata.serial;
   }
 }
 
index 62cd063a896baa6c32ac6310989bb1c829885b20..db65ff266feec551a8df2bdea17cb62da5f9ee3e 100644 (file)
@@ -194,7 +194,7 @@ public:
   void lookup(const QType&, const DNSName& qdomain, int zoneId, DNSPacket* p = nullptr) override;
   bool list(const DNSName& target, int id, bool include_disabled = false) override;
   bool get(DNSResourceRecord&) override;
-  void getAllDomains(vector<DomainInfo>* domains, bool include_disabled = false) override;
+  void getAllDomains(vector<DomainInfo>* domains, bool getSerial, bool include_disabled = false) override;
 
   static DNSBackend* maker();
   static std::mutex s_startup_lock;
index 3d563eab218bdb34e6a9ea8d23a80a2a6ae4a422..e1a2312a6c42bb3249a5ae5b1727ffa505401bd6 100644 (file)
@@ -850,7 +850,7 @@ bool GeoIPBackend::getDomainInfo(const DNSName& domain, DomainInfo& di, bool get
   return false;
 }
 
-void GeoIPBackend::getAllDomains(vector<DomainInfo>* domains, bool include_disabled)
+void GeoIPBackend::getAllDomains(vector<DomainInfo>* domains, bool getSerial, bool include_disabled)
 {
   ReadLock rl(&s_state_lock);
 
index cb463cc08010165de1a4defd3f00da508802fdcd..470da9bdb03e033c2b94dbd0ff85b67c320ad7e8 100644 (file)
@@ -55,7 +55,7 @@ public:
   void reload() override;
   void rediscover(string* status = 0) override;
   bool getDomainInfo(const DNSName& domain, DomainInfo& di, bool getSerial = true) override;
-  void getAllDomains(vector<DomainInfo>* domains, bool include_disabled = false) override;
+  void getAllDomains(vector<DomainInfo>* domains, bool getSerial, bool include_disabled) override;
 
   // dnssec support
   bool doesDNSSEC() override { return d_dnssec; };
index 37458daf19c95a2c6ace254e023e9f9a6562f9fc..7c33213610f995fc8cb74d4c38c7d476c03c0047 100644 (file)
@@ -982,7 +982,7 @@ bool LMDBBackend::createDomain(const DNSName& domain, const DomainInfo::DomainKi
   return true;
 }
 
-void LMDBBackend::getAllDomains(vector<DomainInfo>* domains, bool include_disabled)
+void LMDBBackend::getAllDomains(vector<DomainInfo>* domains, bool doSerial, bool include_disabled)
 {
   domains->clear();
   auto txn = d_tdomains->getROTransaction();
index a489770b6c5d81849eef01fa80f855ae89792080..33399f31d70bb42350edbb61cabe7f0f1f40b6aa 100644 (file)
@@ -69,7 +69,7 @@ public:
   bool feedEnts3(int domain_id, const DNSName& domain, map<DNSName, bool>& nonterm, const NSEC3PARAMRecordContent& ns3prc, bool narrow) override;
   bool replaceRRSet(uint32_t domain_id, const DNSName& qname, const QType& qt, const vector<DNSResourceRecord>& rrset) override;
 
-  void getAllDomains(vector<DomainInfo>* domains, bool include_disabled = false) override;
+  void getAllDomains(vector<DomainInfo>* domains, bool doSerial, bool include_disabled) override;
   void lookup(const QType& type, const DNSName& qdomain, int zoneId, DNSPacket* p = nullptr) override;
   bool get(DNSResourceRecord& rr) override;
   bool get(DNSZoneRecord& dzr) override;
index 301086cb62e6c4d5abad7f4e99a83329febd489b..aaedf1a9d666ea4d17ab8eb95925eba7f9997186 100644 (file)
@@ -298,7 +298,7 @@ public:
     return true;
   }
 
-  void getAllDomains(vector<DomainInfo>* domains, bool include_disabled = false) override
+  void getAllDomains(vector<DomainInfo>* domains, bool getSerial, bool include_disabled) override
   {
     if (f_get_all_domains == nullptr)
       return;
index 8e1c802446fafde4d2d5f7bf09f032168a78f2b4..764deee33d3780eecf6f62f26ceb54557be41f63 100644 (file)
@@ -858,7 +858,7 @@ bool RemoteBackend::searchComments(const string& pattern, int maxResults, vector
   return false;
 }
 
-void RemoteBackend::getAllDomains(vector<DomainInfo>* domains, bool include_disabled)
+void RemoteBackend::getAllDomains(vector<DomainInfo>* domains, bool getSerial, bool include_disabled)
 {
   Json query = Json::object{
     {"method", "getAllDomains"},
index 7832682a1c6cb0cff4259eece7b135cca09f98af..08811fe078ea7e6036272d93ed1242fd1a857b1f 100644 (file)
@@ -198,7 +198,7 @@ public:
   string directBackendCmd(const string& querystr) override;
   bool searchRecords(const string& pattern, int maxResults, vector<DNSResourceRecord>& result) override;
   bool searchComments(const string& pattern, int maxResults, vector<Comment>& result) override;
-  void getAllDomains(vector<DomainInfo>* domains, bool include_disabled = false) override;
+  void getAllDomains(vector<DomainInfo>* domains, bool getSerial, bool include_disabled) override;
   void getUpdatedMasters(vector<DomainInfo>* domains) override;
   void alsoNotifies(const DNSName& domain, set<string>* ips) override;
   void getUnfreshSlaveInfos(vector<DomainInfo>* domains) override;
index 084ce1ada3a8a8a03b4c1d8149499b299694b2dc..06ebeb596eb207a205b178e8cddb6d36ab759209 100644 (file)
@@ -253,7 +253,7 @@ BOOST_AUTO_TEST_CASE(test_method_getAllDomains)
   BOOST_TEST_MESSAGE("Testing getAllDomains method");
   vector<DomainInfo> result;
 
-  be->getAllDomains(&result, true);
+  be->getAllDomains(&result, true, true);
 
   di = result[0];
   BOOST_CHECK_EQUAL(di.zone.toString(), "unit.test.");
index 54f433b46676e6e1be14dae1f190d361ef190274..510f2b7273c29c3fcbb1391c28a3947556b9f940 100644 (file)
@@ -99,7 +99,7 @@ void TinyDNSBackend::getUpdatedMasters(vector<DomainInfo>* retDomains)
   TDI_t* domains = &(*domainInfo)[d_suffix];
 
   vector<DomainInfo> allDomains;
-  getAllDomains(&allDomains);
+  getAllDomains(&allDomains, true, false);
   if (domains->size() == 0 && !mustDo("notify-on-startup")) {
     for (vector<DomainInfo>::iterator di = allDomains.begin(); di != allDomains.end(); ++di) {
       di->notified_serial = 0;
@@ -151,7 +151,7 @@ void TinyDNSBackend::setNotified(uint32_t id, uint32_t serial)
   (*domainInfo)[d_suffix] = *domains;
 }
 
-void TinyDNSBackend::getAllDomains(vector<DomainInfo>* domains, bool include_disabled)
+void TinyDNSBackend::getAllDomains(vector<DomainInfo>* domains, bool getSerial, bool include_disabled)
 {
   d_isAxfr = true;
   d_isGetDomains = true;
@@ -171,17 +171,25 @@ void TinyDNSBackend::getAllDomains(vector<DomainInfo>* domains, bool include_dis
 
   while (get(rr)) {
     if (rr.qtype.getCode() == QType::SOA && dupcheck.insert(rr.qname).second) {
-      SOAData sd;
-      fillSOAData(rr.content, sd);
-
       DomainInfo di;
       di.id = -1; //TODO: Check if this is ok.
       di.backend = this;
       di.zone = rr.qname;
-      di.serial = sd.serial;
-      di.notified_serial = sd.serial;
       di.kind = DomainInfo::Master;
       di.last_check = time(0);
+
+      if (getSerial) {
+        SOAData sd;
+        try {
+          fillSOAData(rr.content, sd);
+          di.serial = sd.serial;
+        }
+        catch (const PDNSException& e) {
+          di.serial = 0;
+        }
+      }
+
+      di.notified_serial = di.serial;
       domains->push_back(di);
     }
   }
index 04792dffa66237717c84a305f6e917a0f4384975..10ee5527825c8e7564989af73b1ffa51d47c05f8 100644 (file)
@@ -70,7 +70,7 @@ public:
   void lookup(const QType& qtype, const DNSName& qdomain, int zoneId, DNSPacket* pkt_p = nullptr) override;
   bool list(const DNSName& target, int domain_id, bool include_disabled = false) override;
   bool get(DNSResourceRecord& rr) override;
-  void getAllDomains(vector<DomainInfo>* domains, bool include_disabled = false) override;
+  void getAllDomains(vector<DomainInfo>* domains, bool getSerial, bool include_disabled) override;
 
   //Master mode operation
   void getUpdatedMasters(vector<DomainInfo>* domains) override;
index 51cece2f4717052e1e9a7c4777d657bd4a3d968d..83ac518f8913f462d9617df1293f5a0c55e0a7d5 100644 (file)
@@ -1397,7 +1397,7 @@ bool GSQLBackend::deleteDomain(const DNSName &domain)
   return true;
 }
 
-void GSQLBackend::getAllDomains(vector<DomainInfo> *domains, bool include_disabled)
+void GSQLBackend::getAllDomains(vector<DomainInfo>* domains, bool getSerial, bool include_disabled)
 {
   DLOG(g_log<<"GSQLBackend retrieving all domains."<<endl);
 
@@ -1443,21 +1443,28 @@ void GSQLBackend::getAllDomains(vector<DomainInfo> *domains, bool include_disabl
         }
       }
 
-      if(!row[2].empty()) {
+      if (getSerial && !row[2].empty()) {
         SOAData sd;
-        fillSOAData(row[2], sd);
-        di.serial = sd.serial;
+        try {
+          fillSOAData(row[2], sd);
+          di.serial = sd.serial;
+        }
+        catch (const PDNSException& e) {
+          di.serial = 0;
+        }
       }
+
       try {
         di.notified_serial = pdns_stou(row[5]);
         di.last_check = pdns_stou(row[6]);
       } catch(...) {
         continue;
       }
+
       di.account = row[7];
 
       di.backend = this;
-  
+
       domains->push_back(di);
     }
     d_getAllDomainsQuery_stmt->reset();
index 49dde605088898c4ac2f24374af683263981d8c3..66fc76757909f5e844f1244b977aea2c389eaa90 100644 (file)
@@ -185,7 +185,7 @@ public:
   void lookup(const QType &, const DNSName &qdomain, int zoneId, DNSPacket *p=nullptr) override;
   bool list(const DNSName &target, int domain_id, bool include_disabled=false) override;
   bool get(DNSResourceRecord &r) override;
-  void getAllDomains(vector<DomainInfo> *domains, bool include_disabled=false) override;
+  void getAllDomains(vector<DomainInfo>* domains, bool getSerial, bool include_disabled) override;
   void alsoNotifies(const DNSName &domain, set<string> *ips) override;
   bool startTransaction(const DNSName &domain, int domain_id=-1) override;
   bool commitTransaction() override;
index f2c86729c881bcde953d4bbd29f4acef0f8a39d7..312c4c837863344eacda7b7a11dd131f81e1cdab 100644 (file)
@@ -298,7 +298,7 @@ bool DNSBackend::getBeforeAndAfterNames(uint32_t id, const DNSName& zonename, co
   return ret;
 }
 
-void DNSBackend::getAllDomains(vector<DomainInfo>* domains, bool include_disabled)
+void DNSBackend::getAllDomains(vector<DomainInfo>* domains, bool getSerial, bool include_disabled)
 {
   if (g_zoneCache.isEnabled()) {
     g_log << Logger::Error << "One of the backends does not support zone caching. Put zone-cache-refresh-interval=0 in the config file to disable this cache." << endl;
index f768515fea089870c570daedaa48b53bc3b012f0..c63033d7484e6685e481bb70a9649bb826090484 100644 (file)
@@ -173,7 +173,7 @@ public:
     return setDomainMetadata(name, kind, meta);
   }
 
-  virtual void getAllDomains(vector<DomainInfo>* domains, bool include_disabled = false);
+  virtual void getAllDomains(vector<DomainInfo>* domains, bool getSerial, bool include_disabled);
 
   /** Determines if we are authoritative for a zone, and at what level */
   virtual bool getAuth(const DNSName &target, SOAData *sd);
index a456464bcc69dd7b0358d201ec3bbb5a46089ac3..31869cb1f8059495206bb4bd0459e9a49d121b3f 100644 (file)
@@ -323,7 +323,7 @@ string DLNotifyHandler(const vector<string>&parts, Utility::pid_t ppid)
 
   if (parts[1] == "*") {
     vector<DomainInfo> domains;
-    B.getAllDomains(&domains);
+    B.getAllDomains(&domains, true, false);
 
     int total = 0;
     int notified = 0;
@@ -380,7 +380,7 @@ string DLListZones(const vector<string>&parts, Utility::pid_t ppid)
   UeberBackend B;
   g_log<<Logger::Notice<<"Received request to list zones."<<endl;
   vector<DomainInfo> domains;
-  B.getAllDomains(&domains);
+  B.getAllDomains(&domains, false, false);
   ostringstream ret;
   int kindFilter = -1;
   if (parts.size() > 1) {
index a4ed9a819575cffed6d9eceadde368174f1655e7..93c7859ceedcc979d333f9e5fe3e6a2d3ce191e5 100644 (file)
@@ -230,7 +230,7 @@ static bool rectifyAllZones(DNSSECKeeper &dk, bool quiet = false)
   vector<DomainInfo> domainInfo;
   bool result = true;
 
-  B.getAllDomains(&domainInfo);
+  B.getAllDomains(&domainInfo, false, false);
   for(const DomainInfo& di :  domainInfo) {
     if (!quiet) {
       cerr<<"Rectifying "<<di.zone<<": ";
@@ -846,7 +846,7 @@ static int checkAllZones(DNSSECKeeper &dk, bool exitOnError)
   auto& seenNames = seenInfos.get<0>();
   auto& seenIds = seenInfos.get<1>();
 
-  B.getAllDomains(&domainInfo, true);
+  B.getAllDomains(&domainInfo, true, true);
   int errors=0;
   for(auto di : domainInfo) {
     if (checkZone(dk, B, di.zone) > 0) {
@@ -1031,7 +1031,7 @@ static int listKeys(const string &zname, DNSSECKeeper& dk){
     listKey(di, dk);
   } else {
     vector<DomainInfo> domainInfo;
-    B.getAllDomains(&domainInfo, g_verbose);
+    B.getAllDomains(&domainInfo, false, g_verbose);
     bool printHeader = true;
     for (const auto& di : domainInfo) {
       listKey(di, dk, printHeader);
@@ -1636,7 +1636,7 @@ static int listAllZones(const string &type="") {
   UeberBackend B("default");
 
   vector<DomainInfo> domains;
-  B.getAllDomains(&domains, g_verbose);
+  B.getAllDomains(&domains, false, g_verbose);
 
   int count = 0;
   for (const auto& di: domains) {
@@ -2948,7 +2948,7 @@ try
     UeberBackend B("default");
 
     vector<DomainInfo> domainInfo;
-    B.getAllDomains(&domainInfo);
+    B.getAllDomains(&domainInfo, false, false);
 
     unsigned int zonesSecured=0, zoneErrors=0;
     for(const DomainInfo& di :  domainInfo) {
@@ -3724,11 +3724,11 @@ try
 
     vector<DomainInfo> domains;
 
-    tgt->getAllDomains(&domains, true);
+    tgt->getAllDomains(&domains, false, true);
     if (domains.size()>0)
       throw PDNSException("Target backend has zone(s), please clean it first");
 
-    src->getAllDomains(&domains, true);
+    src->getAllDomains(&domains, false, true);
     // iterate zones
     for(const DomainInfo& di: domains) {
       size_t nr,nc,nm,nk;
index 499f2547bc05b8dd09ade3f13597bf540a1ed784..3f5f684c819f3fbe36c9e2eff922d8e114323c5c 100644 (file)
@@ -284,7 +284,7 @@ void UeberBackend::updateZoneCache() {
   for (vector<DNSBackend*>::iterator i = backends.begin(); i != backends.end(); ++i )
   {
     vector<DomainInfo> zones;
-    (*i)->getAllDomains(&zones, true);
+    (*i)->getAllDomains(&zones, false, true);
     for(auto& di: zones) {
       zone_indices.push_back({std::move(di.zone), (int)di.id});  // this cast should not be necessary
     }
@@ -665,10 +665,11 @@ void UeberBackend::lookup(const QType &qtype,const DNSName &qname, int zoneId, D
   d_handle.parent=this;
 }
 
-void UeberBackend::getAllDomains(vector<DomainInfo> *domains, bool include_disabled) {
+void UeberBackend::getAllDomains(vector<DomainInfo>* domains, bool getSerial, bool include_disabled)
+{
   for (auto & backend : backends)
   {
-    backend->getAllDomains(domains, include_disabled);
+    backend->getAllDomains(domains, getSerial, include_disabled);
   }
 }
 
index 59b5c2d2d0278e4766805254863d7d7d02e60606..53e1e8de63d3ab6160954bb08354f6763b2748f4 100644 (file)
@@ -101,7 +101,7 @@ public:
   /** Load SOA info from backends, ignoring the cache.*/
   bool getSOAUncached(const DNSName &domain, SOAData &sd);
   bool get(DNSZoneRecord &r);
-  void getAllDomains(vector<DomainInfo> *domains, bool include_disabled=false);
+  void getAllDomains(vector<DomainInfo>* domains, bool getSerial, bool include_disabled);
 
   void getUnfreshSlaveInfos(vector<DomainInfo>* domains);
   void getUpdatedMasters(vector<DomainInfo>* domains);
index 2aae0c300cecc784dc1a2fce72d607ff6b5b3b4e..603e6ae0850cbbac1a37d36509ef87b0d9ce4140 100644 (file)
@@ -1773,7 +1773,7 @@ static void apiServerZones(HttpRequest* req, HttpResponse* resp) {
     }
   } else {
     try {
-      B.getAllDomains(&domains, true); // incl. disabled
+      B.getAllDomains(&domains, true, true); // incl. serial and disabled
     } catch(const PDNSException &e) {
       throw HttpInternalServerErrorException("Could not retrieve all domain information: " + e.reason);
     }
@@ -2190,7 +2190,7 @@ static void apiServerSearchData(HttpRequest* req, HttpResponse* resp) {
   map<int,DomainInfo>::iterator val;
   Json::array doc;
 
-  B.getAllDomains(&domains, true);
+  B.getAllDomains(&domains, false, true);
 
   for(const DomainInfo& di: domains)
   {