]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Replace the bool argument of checkRRSet with an enum, to allow future growth.
authorMiod Vallat <miod.vallat@powerdns.com>
Wed, 21 Jan 2026 13:04:54 +0000 (14:04 +0100)
committerMiod Vallat <miod.vallat@powerdns.com>
Wed, 21 Jan 2026 14:18:00 +0000 (15:18 +0100)
Signed-off-by: Miod Vallat <miod.vallat@powerdns.com>
pdns/check-zone.cc
pdns/check-zone.hh
pdns/pdnsutil.cc
pdns/ws-auth.cc

index 9044cf546792feef69c64a1672865b97727c477f..64d854029ee75ede78967dba9559492ea462fcfb 100644 (file)
@@ -53,7 +53,7 @@ bool validateViewName(std::string_view name, std::string& error)
   return true;
 }
 
-void checkRRSet(const vector<DNSResourceRecord>& oldrrs, vector<DNSResourceRecord>& allrrs, const ZoneName& zone, bool allowUnderscores, vector<pair<DNSResourceRecord, string>>& errors)
+void checkRRSet(const vector<DNSResourceRecord>& oldrrs, vector<DNSResourceRecord>& allrrs, const ZoneName& zone, RRSetFlags flags, vector<pair<DNSResourceRecord, string>>& errors)
 {
   // QTypes that MUST NOT have multiple records of the same type in a given RRset.
   static const std::set<uint16_t> onlyOneEntryTypes = {QType::CNAME, QType::DNAME, QType::SOA};
@@ -108,6 +108,7 @@ void checkRRSet(const vector<DNSResourceRecord>& oldrrs, vector<DNSResourceRecor
     }
 
     // Check if the DNSNames that should be hostnames, are hostnames
+    bool allowUnderscores = (flags & RRSET_ALLOW_UNDERSCORES) != 0;
     try {
       checkHostnameCorrectness(rec, allowUnderscores);
     }
index 91acacbbe54ba1a959e50dec8066b966518ee67e..9e63d87f7c21c422f0ec279b60c3500053f1c57f 100644 (file)
@@ -34,6 +34,11 @@ namespace Check
 // whitespace or a leading dot forbidden.
 bool validateViewName(std::string_view name, std::string& error);
 
+enum RRSetFlags : unsigned int
+{
+  RRSET_ALLOW_UNDERSCORES = 1 << 0, // Allow underscore in names
+};
+
 // Returns the list of errors found for new records which violate RRset
 // constraints.
 // NOTE: sorts records in-place.
@@ -42,6 +47,6 @@ bool validateViewName(std::string_view name, std::string& error);
 //   *) no exact duplicates
 //   *) no duplicates for QTypes that can only be present once per RRset
 //   *) hostnames are hostnames
-void checkRRSet(const vector<DNSResourceRecord>& oldrrs, vector<DNSResourceRecord>& allrrs, const ZoneName& zone, bool allowUnderscores, vector<pair<DNSResourceRecord, string>>& errors);
+void checkRRSet(const vector<DNSResourceRecord>& oldrrs, vector<DNSResourceRecord>& allrrs, const ZoneName& zone, RRSetFlags flags, vector<pair<DNSResourceRecord, string>>& errors);
 
 } // namespace Check
index 4603c3f40859c1c17b81130df8c583a092c459ac..5361d29eb25f25557434e26024bcc109918c17d6 100644 (file)
@@ -2770,7 +2770,11 @@ static int addOrReplaceRecord(bool isAdd, const vector<string>& cmds)
   }
 
   std::vector<std::pair<DNSResourceRecord, string>> errors;
-  Check::checkRRSet(oldrrs, newrrs, zone, allowUnderscores, errors);
+  Check::RRSetFlags flags{0};
+  if (allowUnderscores) {
+    flags = Check::RRSET_ALLOW_UNDERSCORES;
+  }
+  Check::checkRRSet(oldrrs, newrrs, zone, flags, errors);
   oldrrs.clear(); // no longer needed
   if (!errors.empty()) {
     for (const auto& error : errors) {
index bb50fbc0137b90613e7c14c927aa992cc2bb8915..1ab78613febb5736e6979864e77fde17dfebf4e2 100644 (file)
@@ -1689,7 +1689,11 @@ static bool checkNewRecords(HttpResponse* resp, vector<DNSResourceRecord>& recor
 {
   std::vector<std::pair<DNSResourceRecord, string>> errors;
 
-  Check::checkRRSet({}, records, zone, allowUnderscores, errors);
+  Check::RRSetFlags flags{0};
+  if (allowUnderscores) {
+    flags = Check::RRSET_ALLOW_UNDERSCORES;
+  }
+  Check::checkRRSet({}, records, zone, flags, errors);
   if (errors.empty()) {
     return true;
   }