From: Miod Vallat Date: Thu, 3 Apr 2025 06:45:47 +0000 (+0200) Subject: Better error report when zone creation is not possible. X-Git-Tag: dnsdist-2.0.0-alpha2~96^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2b94b920c2a020ee4bba634c0390c6797bd786bf;p=thirdparty%2Fpdns.git Better error report when zone creation is not possible. Fixes #5783 Fixes #6954 --- diff --git a/pdns/pdnsutil.cc b/pdns/pdnsutil.cc index fb7c1c4bcf..ae2c0bcb15 100644 --- a/pdns/pdnsutil.cc +++ b/pdns/pdnsutil.cc @@ -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 '"<(), ""); 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& 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 primaries; for (unsigned i=2; i < cmds.size(); i++) { primaries.emplace_back(cmds.at(i), 53); @@ -4317,6 +4332,11 @@ static int B2BMigrate(vector& 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 "<getPrefix()<<" to "<getPrefix()< domains; diff --git a/pdns/ueberbackend.cc b/pdns/ueberbackend.cc index 3d8b41e592..dbeb04ee9c 100644 --- a/pdns/ueberbackend.cc +++ b/pdns/ueberbackend.cc @@ -891,6 +891,15 @@ bool UeberBackend::hasCreatedLocalFiles() return std::any_of(backends.begin(), backends.end(), [](std::unique_ptr& 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() diff --git a/pdns/ueberbackend.hh b/pdns/ueberbackend.hh index 4705868028..2e403c9003 100644 --- a/pdns/ueberbackend.hh +++ b/pdns/ueberbackend.hh @@ -143,6 +143,8 @@ public: bool hasCreatedLocalFiles(); + unsigned int getCapabilities(); + private: handle d_handle; vector d_answers;