From 6d0f7f595c669804ae7055986f58af508ef809bd Mon Sep 17 00:00:00 2001 From: Miod Vallat Date: Fri, 7 Feb 2025 15:23:59 +0100 Subject: [PATCH] Do not allow dangerous operations on secondary zones unless --force. This applies to: add-record, delete-rrset, edit-zone, increase-serial, rectify-zone and replace-rrset. Fixes #11392, #15130 --- pdns/pdnsutil.cc | 71 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 64 insertions(+), 7 deletions(-) diff --git a/pdns/pdnsutil.cc b/pdns/pdnsutil.cc index d3b1700bcd85..e509344b1aa7 100644 --- a/pdns/pdnsutil.cc +++ b/pdns/pdnsutil.cc @@ -61,6 +61,7 @@ string g_programname="pdns"; namespace { bool g_verbose; + bool g_force; } ArgvMap &arg() @@ -264,16 +265,24 @@ static bool rectifyAllZones(DNSSECKeeper &dk, bool quiet = false) bool result = true; B.getAllDomains(&domainInfo, false, false); + size_t processed{0}; for(const DomainInfo& di : domainInfo) { + if (di.isSecondaryType() && !g_force) { + if (!quiet) { + cout << "Skipping non-primary '" << di.zone << "' (use --force to act on it)" << endl; + } + continue; + } if (!quiet) { - cerr<<"Rectifying "<& cmds) { cerr << "Zone '" << zone << "' does not exist" << endl; return EXIT_FAILURE; } + if (di.isSecondaryType() && !g_force) { + throw PDNSException("Operation on a non-primary zone is not allowed unless --force"); + } rr.auth = true; rr.domain_id = di.id; rr.qname = name; @@ -1718,6 +1761,9 @@ static int deleteRRSet(const std::string& zone_, const std::string& name_, const cerr << "Zone '" << zone << "' does not exist" << endl; return EXIT_FAILURE; } + if (di.isSecondaryType() && !g_force) { + throw PDNSException("Operation on a non-primary zone is not allowed unless --force"); + } DNSName name; if(name_=="@") @@ -2296,9 +2342,8 @@ static bool secureZone(DNSSECKeeper& dk, const DNSName& zone) return false; } - if (di.kind == DomainInfo::Secondary) { - cerr << "Warning! This is a secondary zone! If this was a mistake, please run" << endl; - cerr<<"pdnsutil disable-dnssec "<& cmds) cerr << "Syntax: pdnsutil rectify-zone ZONE [ZONE..]"<