From: Miod Vallat Date: Thu, 10 Apr 2025 12:38:00 +0000 (+0200) Subject: Let pdnsutil always setup a SOA-EDIT-API metadata when creating zones. X-Git-Tag: rec-5.3.0-alpha2~33^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c0afe7d43fade8658a2b15a0bdbeb758175f002c;p=thirdparty%2Fpdns.git Let pdnsutil always setup a SOA-EDIT-API metadata when creating zones. Fixes #9096 --- diff --git a/docs/upgrading.rst b/docs/upgrading.rst index b20f0e7c2d..a2018b6a7d 100644 --- a/docs/upgrading.rst +++ b/docs/upgrading.rst @@ -56,6 +56,10 @@ A few changes of behaviour have been implemented in :doc:`pdnsutil `. * The ``add-record``, ``delete-rrset``, ``edit-zone``, ``increase-serial`` and ``replace-rrset`` operations will now refuse to work on secondary zones unless the ``--force`` option is passed. +* When a zone gets created with either ``create-zone``, + ``create-secondary-zone`` or ``load-zone`` (if the zone wasn't existing + already), a :ref:`metadata-soa-edit-api` metadata with a value of ``DEFAULT`` + will be added to the zone. 4.8.0 to 4.9.0 -------------- diff --git a/pdns/pdnsutil.cc b/pdns/pdnsutil.cc index 59bd7c3718..f1708d3a30 100644 --- a/pdns/pdnsutil.cc +++ b/pdns/pdnsutil.cc @@ -1545,6 +1545,21 @@ static int zonemdVerifyFile(const ZoneName& zone, const string& fname) { return EXIT_FAILURE; } +// Wrapper around UeberBackend::createDomain, which will also set up the +// default metadata, matching the behaviour of the REST API. +static bool createZoneWithDefaults(UtilBackend &backend, DomainInfo &info, const ZoneName& zone, DomainInfo::DomainKind kind, const vector& primaries) +{ + backend.createDomain(zone, kind, primaries, ""); + if (!backend.getDomainInfo(zone, info)) { + cerr << "Zone '" << zone << "' was not created." << endl; + return false; + } + info.backend->startTransaction(zone, static_cast(info.id)); + info.backend->setDomainMetadataOne(zone, "SOA-EDIT-API", "DEFAULT"); + info.backend->commitTransaction(); + return true; +} + static int loadZone(const ZoneName& zone, const string& fname) { UtilBackend B; //NOLINT(readability-identifier-length) DomainInfo di; @@ -1564,10 +1579,7 @@ static int loadZone(const ZoneName& zone, const string& fname) { return EXIT_FAILURE; } cerr<<"Creating '"<(), ""); - - if(!B.getDomainInfo(zone, di)) { - cerr << "Zone '" << zone << "' was not created." << endl; + if (!createZoneWithDefaults(B, di, zone, DomainInfo::Native, vector())) { return EXIT_FAILURE; } } @@ -1653,9 +1665,7 @@ static int createZone(const ZoneName &zone, const DNSName& nsname) { rr.content = makeSOAContent(sd)->getZoneRepresentation(true); cerr<<"Creating empty zone '"<(), ""); - if(!B.getDomainInfo(zone, di)) { - cerr << "Zone '" << zone << "' was not created." << endl; + if (!createZoneWithDefaults(B, di, zone, DomainInfo::Native, vector())) { return EXIT_FAILURE; } @@ -3224,9 +3234,8 @@ static int createSecondaryZone(vector& cmds, const std::string_view syno primaries.emplace_back(cmds.at(i), 53); } cerr << "Creating secondary zone '" << zone << "', with primaries '" << comboAddressVecToString(primaries) << "'" << endl; - B.createDomain(zone, DomainInfo::Secondary, primaries, ""); - if(!B.getDomainInfo(zone, di)) { - cerr << "Zone '" << zone << "' was not created." << endl; + if (!createZoneWithDefaults(B, di, zone, DomainInfo::Secondary, primaries)) { + cerr << "Zone '" << zone << "' was not created!" << endl; return EXIT_FAILURE; } return EXIT_SUCCESS; diff --git a/regression-tests/tests/zone-variants/expected_result.lmdb b/regression-tests/tests/zone-variants/expected_result.lmdb index 92f33c2d2e..ebe367d1b5 100644 --- a/regression-tests/tests/zone-variants/expected_result.lmdb +++ b/regression-tests/tests/zone-variants/expected_result.lmdb @@ -2,18 +2,21 @@ Creating empty zone 'example.com..variant1' This is a Native zone Variant: variant1 Zone is not actively secured -Metadata items: None +Metadata items: + SOA-EDIT-API DEFAULT No keys for zone 'example.com..variant1'. Creating empty zone '..myroot' This is a Native zone Variant: myroot Zone is not actively secured -Metadata items: None +Metadata items: + SOA-EDIT-API DEFAULT No keys for zone '..myroot'. Creating empty zone '.' This is a Native zone Zone is not actively secured -Metadata items: None +Metadata items: + SOA-EDIT-API DEFAULT No keys for zone '.'. . ..myroot