From: Miod Vallat Date: Mon, 31 Mar 2025 14:23:32 +0000 (+0200) Subject: Check backend capabilities before attempting some operations. X-Git-Tag: dnsdist-2.0.0-alpha2~96^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=178eef7720f19ae421ce7e58406998d86f69a36b;p=thirdparty%2Fpdns.git Check backend capabilities before attempting some operations. This allows us to give better error messages to the users. Fixes: #15006 --- diff --git a/pdns/pdnsutil.cc b/pdns/pdnsutil.cc index 4bbb0f9b3d..fb7c1c4bcf 100644 --- a/pdns/pdnsutil.cc +++ b/pdns/pdnsutil.cc @@ -304,6 +304,11 @@ static int checkZone(DNSSECKeeper &dk, UeberBackend &B, const DNSName& zone, con } } + if (suppliedrecords == nullptr && (di.backend->getCapabilities() & DNSBackend::CAP_LIST) == 0) { + cout << "Backend for zone '" << zone << "' does not support listing its contents." << endl; + return 1; + } + SOAData sd; try { if (!B.getSOAUncached(zone, sd)) { @@ -1133,6 +1138,11 @@ static int listZone(const DNSName &zone) { cerr << "Zone '" << zone << "' not found!" << endl; return EXIT_FAILURE; } + if ((di.backend->getCapabilities() & DNSBackend::CAP_LIST) == 0) { + cerr << "Backend for zone '" << zone << "' does not support listing its contents," << endl; + return EXIT_FAILURE; + } + di.backend->list(zone, di.id); DNSResourceRecord rr; cout<<"$ORIGIN ."<getCapabilities() & DNSBackend::CAP_LIST) == 0) { + cerr << "Backend for zone '" << zone << "' does not support listing its contents," << endl; + return EXIT_FAILURE; + } if (isatty(STDIN_FILENO) == 0) { cerr << "edit-zone requires a terminal" << endl; @@ -4299,6 +4313,10 @@ static int B2BMigrate(vector& cmds, const std::string_view synopsis) return 1; } + if ((src->getCapabilities() & DNSBackend::CAP_LIST) == 0) { + cerr << "Source backend does not support listing zone contents." << endl; + return 1; + } cout<<"Moving zone(s) from "<getPrefix()<<" to "<getPrefix()< domains; @@ -4347,12 +4365,15 @@ static int B2BMigrate(vector& cmds, const std::string_view synopsis) // move comments nc=0; if (src->listComments(di.id)) { + if ((tgt->getCapabilities() & DNSBackend::CAP_COMMENTS) == 0) { + throw PDNSException("Target backend does not support comments - remove them first"); + } Comment c; // NOLINT(readability-identifier-length) while(src->getComment(c)) { // NOLINTNEXTLINE(bugprone-narrowing-conversions,cppcoreguidelines-narrowing-conversions) c.domain_id = di_new.id; if (!tgt->feedComment(c)) { - throw PDNSException("Target backend does not support comments - remove them first"); + throw PDNSException("Failed to feed zone comments"); } nc++; } @@ -4420,6 +4441,11 @@ static int backendCmd(vector& cmds, const std::string_view synopsis) return 1; } + if ((matchingBackend->getCapabilities() & DNSBackend::CAP_DIRECT) == 0) { + cerr << "Backend '" << cmds.at(1) << "' does not support direct commands" << endl; + return 1; + } + for (auto i = next(begin(cmds), 2); i != end(cmds); ++i) { cerr << "== " << *i << endl; cout << matchingBackend->directBackendCmd(*i);