]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
auth: move pdnsutil setNSEC3 checks to DNSSECKeeper
authorPeter Thomassen <peter@desec.io>
Mon, 14 Jul 2025 15:06:15 +0000 (17:06 +0200)
committerPeter Thomassen <peter@desec.io>
Wed, 16 Jul 2025 13:05:46 +0000 (15:05 +0200)
pdns/dbdnsseckeeper.cc
pdns/pdnsutil.cc

index ed5e08e626e47642560024e7fb5a98564016af41..2e834fc4c44c891718150ca388f334c02d98a5a5 100644 (file)
@@ -395,6 +395,13 @@ bool DNSSECKeeper::checkNSEC3PARAM(const NSEC3PARAMRecordContent& ns3p, string&
 
 bool DNSSECKeeper::setNSEC3PARAM(const ZoneName& zname, const NSEC3PARAMRecordContent& ns3p, const bool& narrow)
 {
+  if (auto wirelength = zname.operator const DNSName&().wirelength(); wirelength > 222) {
+    throw runtime_error("Cannot enable NSEC3 for zone '" + zname.toLogString() + "' as it is too long (" + std::to_string(wirelength) + " bytes, maximum is 222 bytes)");
+  }
+  if(ns3p.d_algorithm != 1) {
+    throw runtime_error("NSEC3PARAM algorithm set to '" + std::to_string(ns3p.d_algorithm) + "', but '1' is the only valid value");
+  }
+
   if (d_keymetadb->inTransaction()) {
     d_metaUpdate = true;
   }
index 8d5e91c394f187159eb6ec60288b745ce1380300..abb2e1aa6927ba004630f9f153bf8c7be33f9ce4 100644 (file)
@@ -3595,16 +3595,14 @@ static int setNsec3(vector<string>& cmds, const std::string_view synopsis)
 
   DNSSECKeeper dk; //NOLINT(readability-identifier-length)
   ZoneName zone(cmds.at(1));
-  if (auto wirelength = zone.operator const DNSName&().wirelength(); wirelength > 222) {
-    cerr<<"Cannot enable NSEC3 for " << zone << " as it is too long (" << wirelength << " bytes, maximum is 222 bytes)"<<endl;
-    return 1;
-  }
-  if(ns3pr.d_algorithm != 1) {
-    cerr<<"NSEC3PARAM algorithm set to '"<<std::to_string(ns3pr.d_algorithm)<<"', but '1' is the only valid value"<<endl;
-    return EXIT_FAILURE;
+  try {
+    if (! dk.setNSEC3PARAM(zone, ns3pr, narrow)) {
+      cerr<<"Cannot set NSEC3 param for " << zone << endl;
+      return 1;
+    }
   }
-  if (! dk.setNSEC3PARAM(zone, ns3pr, narrow)) {
-    cerr<<"Cannot set NSEC3 param for " << zone << endl;
+  catch (const runtime_error& err) {
+    cerr << err.what() << endl;
     return 1;
   }