]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Let pdnsutil always setup a SOA-EDIT-API metadata when creating zones. 15417/head
authorMiod Vallat <miod.vallat@powerdns.com>
Thu, 10 Apr 2025 12:38:00 +0000 (14:38 +0200)
committerMiod Vallat <miod.vallat@powerdns.com>
Wed, 28 May 2025 06:12:01 +0000 (08:12 +0200)
Fixes #9096

docs/upgrading.rst
pdns/pdnsutil.cc
regression-tests/tests/zone-variants/expected_result.lmdb

index b20f0e7c2d8bb7efa8b8383c2b57f4817e282cb6..a2018b6a7ddaac29e93c6998511b11203eeb4d61 100644 (file)
@@ -56,6 +56,10 @@ A few changes of behaviour have been implemented in :doc:`pdnsutil <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
 --------------
index 59bd7c371892aac706b834e502c0bc13985df67f..f1708d3a30c3089e64d9bab15d38db39b97e094e 100644 (file)
@@ -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<ComboAddress>& 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<int>(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 '"<<zone<<"'"<<endl;
-    B.createDomain(zone, DomainInfo::Native, vector<ComboAddress>(), "");
-
-    if(!B.getDomainInfo(zone, di)) {
-      cerr << "Zone '" << zone << "' was not created." << endl;
+    if (!createZoneWithDefaults(B, di, zone, DomainInfo::Native, vector<ComboAddress>())) {
       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 '"<<zone<<"'"<<endl;
-  B.createDomain(zone, DomainInfo::Native, vector<ComboAddress>(), "");
-  if(!B.getDomainInfo(zone, di)) {
-    cerr << "Zone '" << zone << "' was not created." << endl;
+  if (!createZoneWithDefaults(B, di, zone, DomainInfo::Native, vector<ComboAddress>())) {
     return EXIT_FAILURE;
   }
 
@@ -3224,9 +3234,8 @@ static int createSecondaryZone(vector<string>& 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;
index 92f33c2d2e8b96c8d521f6329944774741a3090e..ebe367d1b53d92ca63a1bcc1c5da4d22a7338f60 100644 (file)
@@ -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