Skip to content

[tools] Let pdnsutil always setup a SOA-EDIT-API metadata when creating zones #15417

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/upgrading.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,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
--------------
Expand Down
27 changes: 18 additions & 9 deletions pdns/pdnsutil.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1539,6 +1539,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;
Expand All @@ -1553,10 +1568,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;
}
}
Expand Down Expand Up @@ -1637,9 +1649,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;
}

Expand Down Expand Up @@ -3195,8 +3205,7 @@ 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)) {
if (!createZoneWithDefaults(B, di, zone, DomainInfo::Secondary, primaries)) {
cerr << "Zone '" << zone << "' was not created!" << endl;
return EXIT_FAILURE;
}
Expand Down