]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Better error report when zone creation is not possible.
authorMiod Vallat <miod.vallat@powerdns.com>
Thu, 3 Apr 2025 06:45:47 +0000 (08:45 +0200)
committerMiod Vallat <miod.vallat@powerdns.com>
Mon, 7 Apr 2025 10:03:33 +0000 (12:03 +0200)
Fixes #5783
Fixes #6954

pdns/pdnsutil.cc
pdns/ueberbackend.cc
pdns/ueberbackend.hh

index fb7c1c4bcfa49f190236c919a9c33b10f3ba8a61..ae2c0bcb15849310cf8c068efb598b1770fafa79 100644 (file)
@@ -1547,11 +1547,16 @@ static int loadZone(const DNSName& zone, const string& fname) {
     cerr << "Zone '" << zone << "' exists already, replacing contents" << endl;
   }
   else {
+    if ((B.getCapabilities() & DNSBackend::CAP_CREATE) == 0) {
+      cerr << "None of the configured backends support zone creation." << endl;
+      cerr << "Zone '" << zone << "' was not created." << endl;
+      return EXIT_FAILURE;
+    }
     cerr<<"Creating '"<<zone<<"'"<<endl;
     B.createDomain(zone, DomainInfo::Native, vector<ComboAddress>(), "");
 
     if(!B.getDomainInfo(zone, di)) {
-      cerr << "Zone '" << zone << "' was not created - perhaps backend (" << ::arg()["launch"] << ") does not support storing new zones." << endl;
+      cerr << "Zone '" << zone << "' was not created." << endl;
       return EXIT_FAILURE;
     }
   }
@@ -1600,6 +1605,11 @@ static int createZone(const DNSName &zone, const DNSName& nsname) {
     cerr << "Zone '" << zone << "' exists already" << endl;
     return EXIT_FAILURE;
   }
+  if ((B.getCapabilities() & DNSBackend::CAP_CREATE) == 0) {
+    cerr << "None of the configured backends support zone creation." << endl;
+    cerr << "Zone '" << zone << "' was not created." << endl;
+    return EXIT_FAILURE;
+  }
 
   DNSResourceRecord rr;
   rr.qname = zone;
@@ -3175,6 +3185,11 @@ static int createSecondaryZone(vector<string>& cmds, const std::string_view syno
     cerr << "Zone '" << zone << "' exists already" << endl;
     return EXIT_FAILURE;
   }
+  if ((B.getCapabilities() & DNSBackend::CAP_CREATE) == 0) {
+    cerr << "None of the configured backends support zone creation." << endl;
+    cerr << "Zone '" << zone << "' was not created." << endl;
+    return EXIT_FAILURE;
+  }
   vector<ComboAddress> primaries;
   for (unsigned i=2; i < cmds.size(); i++) {
     primaries.emplace_back(cmds.at(i), 53);
@@ -4317,6 +4332,11 @@ static int B2BMigrate(vector<string>& cmds, const std::string_view synopsis)
     cerr << "Source backend does not support listing zone contents." << endl;
     return 1;
   }
+  if ((tgt->getCapabilities() & DNSBackend::CAP_CREATE) == 0) {
+    cerr << "Target backend does not support zone creation." << endl;
+    return 1;
+  }
+
   cout<<"Moving zone(s) from "<<src->getPrefix()<<" to "<<tgt->getPrefix()<<endl;
 
   vector<DomainInfo> domains;
index 3d8b41e592cc594e6c9c5ab377dd9f51a240d747..dbeb04ee9cea8d9a919b4b2ee5b6fce1f699ebf4 100644 (file)
@@ -891,6 +891,15 @@ bool UeberBackend::hasCreatedLocalFiles()
   return std::any_of(backends.begin(), backends.end(), [](std::unique_ptr<DNSBackend>& backend) { return backend->hasCreatedLocalFiles(); });
 }
 
+unsigned int UeberBackend::getCapabilities()
+{
+  unsigned int capabilities{0};
+  for (auto& backend : backends) {
+    capabilities |= backend->getCapabilities();
+  }
+  return capabilities;
+}
+
 AtomicCounter UeberBackend::handle::instances(0);
 
 UeberBackend::handle::handle()
index 47058680287f5297426a83640e886aaa699956e8..2e403c90036d8bd9f284d127d6bc2c0b9681a078 100644 (file)
@@ -143,6 +143,8 @@ public:
 
   bool hasCreatedLocalFiles();
 
+  unsigned int getCapabilities();
+
 private:
   handle d_handle;
   vector<DNSZoneRecord> d_answers;