]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
auth: cleanup auth-catalogzone.cc a bit
authorKees Monshouwer <mind04@monshouwer.org>
Tue, 9 Apr 2024 20:35:24 +0000 (22:35 +0200)
committerKees Monshouwer <mind04@monshouwer.org>
Wed, 11 Mar 2026 13:50:16 +0000 (14:50 +0100)
Signed-off-by: Kees Monshouwer <mind04@monshouwer.org>
modules/lmdbbackend/lmdbbackend.cc
pdns/auth-catalogzone.cc
pdns/backends/gsql/gsqlbackend.cc

index 232d9477c842456014984e5c683cbd7a4ad4186d..22c6a0ef5879e5f00d06ffce6d74a9ee155cce38 100644 (file)
@@ -2405,7 +2405,7 @@ void LMDBBackend::getUpdatedPrimaries(vector<DomainInfo>& updatedDomains, std::u
 
     if (di.kind == DomainInfo::Producer) {
       catalogs.insert(di.zone.operator const DNSName&());
-      catalogHashes[di.zone].process("\0");
+      catalogHashes[di.zone].process("");
       return false; // Producer freshness check is performed elsewhere
     }
 
index ab6e5e62741a61c5da04ce8bb43b9fa6ea1ec208..d200167275412ae86e6c1d50b911e0733729e61d 100644 (file)
@@ -25,6 +25,7 @@
 #endif
 
 #include "dnsbackend.hh"
+#include "json.hh"
 
 void CatalogInfo::fromJson(const std::string& json, CatalogType type)
 {
@@ -32,49 +33,43 @@ void CatalogInfo::fromJson(const std::string& json, CatalogType type)
   if (d_type == CatalogType::None) {
     throw std::runtime_error("CatalogType is set to None");
   }
+
   if (json.empty()) {
     return;
   }
+
   std::string err;
   d_doc = json11::Json::parse(json, err);
-  if (!d_doc.is_null()) {
-    if (!d_doc[getTypeString(d_type)].is_null()) {
-      auto items = d_doc[getTypeString(type)].object_items();
-      if (!items["coo"].is_null()) {
-        if (items["coo"].is_string()) {
-          if (!items["coo"].string_value().empty()) {
-            d_coo = DNSName(items["coo"].string_value());
-          }
-        }
-        else {
-          throw std::out_of_range("Key 'coo' is not a string");
-        }
+  if (d_doc.is_null()) {
+    throw std::runtime_error("Parsing of JSON options failed: " + err);
+  }
+
+  if (!d_doc[getTypeString(d_type)].is_null()) {
+    auto items = d_doc[getTypeString(type)].object_items();
+
+    // coo property
+    if (!items["coo"].is_null()) {
+      d_coo = DNSName(stringFromJson(items, "coo"));
+    }
+
+    // unique property
+    if (!items["unique"].is_null()) {
+      d_unique = DNSName(stringFromJson(items, "unique"));
+      if (d_unique.countLabels() != 1) {
+        throw std::out_of_range("Invalid number of labels in unique value");
       }
-      if (!items["unique"].is_null()) {
-        if (items["unique"].is_string()) {
-          if (!items["unique"].string_value().empty()) {
-            d_unique = DNSName(items["unique"].string_value());
-          }
-        }
-        else {
-          throw std::out_of_range("Key 'unique' is not a string");
-        }
+    }
+
+    // group properties
+    if (!items["group"].is_null()) {
+      if (!items["group"].is_array()) {
+        throw std::out_of_range("Key 'group' is not an array");
       }
-      if (!items["group"].is_null()) {
-        if (items["group"].is_array()) {
-          for (const auto& value : items["group"].array_items()) {
-            d_group.insert(value.string_value());
-          }
-        }
-        else {
-          throw std::out_of_range("Key 'group' is not an array");
-        }
+      for (const auto& value : items["group"].array_items()) {
+        d_group.insert(value.string_value());
       }
     }
   }
-  else {
-    throw std::runtime_error("Parsing of JSON options failed: " + err);
-  }
 }
 
 std::string CatalogInfo::toJson() const
@@ -83,15 +78,21 @@ std::string CatalogInfo::toJson() const
     throw std::runtime_error("CatalogType is set to None");
   }
   json11::Json::object object;
+
+  // coo property
   if (!d_coo.empty()) {
     object["coo"] = d_coo.toString();
   }
+
+  // unique property
   if (!d_unique.empty()) {
-    if (d_unique.countLabels() > 1) {
-      throw std::out_of_range("Multiple labels in a unique value are not allowed");
+    if (d_unique.countLabels() != 1) {
+      throw std::out_of_range("Invalid number of labels in unique value");
     }
     object["unique"] = d_unique.toString();
   }
+
+  // group properties
   if (!d_group.empty()) {
     json11::Json::array entries;
     for (const auto& group : d_group) {
@@ -99,6 +100,7 @@ std::string CatalogInfo::toJson() const
     }
     object["group"] = entries;
   }
+
   auto tmp = d_doc.object_items();
   tmp[getTypeString(d_type)] = object;
   const json11::Json ret = tmp;
@@ -117,7 +119,6 @@ DNSZoneRecord CatalogInfo::getCatalogVersionRecord(const ZoneName& zone)
 {
   DNSZoneRecord dzr;
   dzr.dr.d_name = g_versiondnsname + zone.operator const DNSName&();
-  dzr.dr.d_ttl = 0;
   dzr.dr.d_type = QType::TXT;
   dzr.dr.setContent(std::make_shared<TXTRecordContent>("2"));
   return dzr;
@@ -134,24 +135,24 @@ void CatalogInfo::toDNSZoneRecords(const ZoneName& zone, vector<DNSZoneRecord>&
   }
   prefix += g_zonesdnsname + zone.operator const DNSName&();
 
+  // member zone
   DNSZoneRecord dzr;
   dzr.dr.d_name = prefix;
-  dzr.dr.d_ttl = 0;
   dzr.dr.d_type = QType::PTR;
   dzr.dr.setContent(std::make_shared<PTRRecordContent>(d_zone.operator const DNSName&().toString()));
   dzrs.emplace_back(dzr);
 
+  // coo property
   if (!d_coo.empty()) {
     dzr.dr.d_name = g_coodnsname + prefix;
-    dzr.dr.d_ttl = 0;
     dzr.dr.d_type = QType::PTR;
     dzr.dr.setContent(std::make_shared<PTRRecordContent>(d_coo));
     dzrs.emplace_back(dzr);
   }
 
+  // group properties
   for (const auto& group : d_group) {
     dzr.dr.d_name = g_groupdnsname + prefix;
-    dzr.dr.d_ttl = 0;
     dzr.dr.d_type = QType::TXT;
     dzr.dr.setContent(std::make_shared<TXTRecordContent>("\"" + group + "\""));
     dzrs.emplace_back(dzr);
index 7b69e0dc3ed3a9248a85265463fa83b2b2ee2643..5e2771a3aed4ce14c08f66ced8b96604e1747e69 100644 (file)
@@ -606,7 +606,7 @@ void GSQLBackend::getUpdatedPrimaries(vector<DomainInfo>& updatedDomains, std::u
 
     if (pdns_iequals(row[2], "PRODUCER")) {
       catalogs.insert(di.zone.operator const DNSName&());
-      catalogHashes[di.zone].process("\0");
+      catalogHashes[di.zone].process("");
       continue; // Producer freshness check is performed elsewhere
     }
     else if (!pdns_iequals(row[2], "MASTER")) {