From 75246531ed1096d967b8a75f82091e7ac99bee43 Mon Sep 17 00:00:00 2001 From: Kees Monshouwer Date: Thu, 22 Dec 2022 21:21:20 +0100 Subject: [PATCH] auth: pdnsutil, implement list-member-zones --- docs/manpages/pdnsutil.1.rst | 2 ++ pdns/pdnsutil.cc | 49 ++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/docs/manpages/pdnsutil.1.rst b/docs/manpages/pdnsutil.1.rst index f306dd4f80..2de83ce0df 100644 --- a/docs/manpages/pdnsutil.1.rst +++ b/docs/manpages/pdnsutil.1.rst @@ -220,6 +220,8 @@ list-keys [*ZONE*] list-all-zones: List all active zone names. --verbose or -v will also include disabled or empty zones. +list-member-zones *CATALOG* + List all members of catalog zone *CATALOG*" list-zone *ZONE* Show all records for *ZONE*. load-zone *ZONE* *FILE* diff --git a/pdns/pdnsutil.cc b/pdns/pdnsutil.cc index efa69265dc..6799edf427 100644 --- a/pdns/pdnsutil.cc +++ b/pdns/pdnsutil.cc @@ -1775,6 +1775,47 @@ static int listAllZones(const string &type="") { return 0; } +static int listMemberZones(const string& catalog) +{ + + UeberBackend B("default"); + + DNSName catz(catalog); + DomainInfo di; + if (!B.getDomainInfo(catz, di)) { + cerr << "Zone '" << catz << "' not found" << endl; + return EXIT_FAILURE; + } + if (!di.isCatalogType()) { + cerr << "Zone '" << catz << "' is not a catalog zone" << endl; + return EXIT_FAILURE; + } + + CatalogInfo::CatalogType type; + if (di.kind == DomainInfo::Producer) { + type = CatalogInfo::Producer; + } + else { + type = CatalogInfo::Consumer; + } + + vector members; + if (!di.backend->getCatalogMembers(catz, members, type)) { + cerr << "Backend does not support catalog zones" << endl; + return EXIT_FAILURE; + } + + for (const auto& ci : members) { + cout << ci.d_zone << endl; + } + + if (g_verbose) { + cout << "All zonecount: " << members.size() << endl; + } + + return EXIT_SUCCESS; +} + static bool testAlgorithm(int algo) { return DNSCryptoKeyEngine::testOne(algo); @@ -2563,6 +2604,7 @@ try cout << "list-zone ZONE List zone contents" << endl; cout << "list-all-zones [primary|secondary|native|producer|consumer]" << endl; cout << " List all active zone names. --verbose or -v will also include disabled or empty zones" << endl; + cout << "list-member-zones CATALOG List all members of catalog zone CATALOG" << endl; cout << "list-tsig-keys List all TSIG keys" << endl; cout << "publish-zone-key ZONE KEY-ID Publish the zone key with key id KEY-ID in ZONE" << endl; @@ -2791,6 +2833,13 @@ try return listAllZones(cmds.at(1)); return listAllZones(); } + else if (cmds.at(0) == "list-member-zones") { + if (cmds.size() != 2) { + cerr << "Syntax: pdnsutil list-member-zones CATALOG" << endl; + return 0; + } + return listMemberZones(cmds.at(1)); + } else if (cmds.at(0) == "test-zone") { cerr << "Did you mean check-zone?"<