Skip to content

Commit

Permalink
pdnsutil {add-record,delete-rrset}: Don't append ZONE if NAME ends wi…
Browse files Browse the repository at this point in the history
…th . or ZONE

If a NAME ends with a . it is to be understood as an absolute name and
appending the zone is not intuitive then.

Note this changes behaviour for calls like:

	pdnsutil --config-dir=configs/auth add-record example.net . NS 1.2.3.4

which added the NS record to the zone's apex before and is likely an
error now.

Also make both

	pdnsutil --config-dir=configs/auth add-record example.net www.example.net A 1.2.3.5
	pdnsutil --config-dir=configs/auth add-record example.net www A 1.2.3.5

add www.example.net. to the example.net zone.

Closes: PowerDNS#8595
  • Loading branch information
ukleinek committed Jan 13, 2025
1 parent 2a1e55f commit 761be48
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions pdns/pdnsutil.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1597,10 +1597,14 @@ static int addOrReplaceRecord(bool addOrReplace, const vector<string>& cmds) {
vector<DNSResourceRecord> newrrs;
DNSName zone(cmds.at(1));
DNSName name;
if (cmds.at(2) == "@")
name=zone;
else
if (cmds.at(2) == "@") {
name = zone;
} else if (isCanonical(cmds.at(2)) || boost::ends_with(cmds.at(2), zone)) {
name = DNSName(cmds.at(2));
} else {
cerr << "Name " << cmds.at(2) << "' does not fit into zone '" << zone << "'. Interpreting as relative name." << endl;
name = DNSName(cmds.at(2)) + zone;
}

rr.qtype = DNSRecordContent::TypeToNumber(cmds.at(3));
rr.ttl = ::arg().asNum("default-ttl");
Expand Down Expand Up @@ -1735,10 +1739,14 @@ static int deleteRRSet(const std::string& zone_, const std::string& name_, const
}

DNSName name;
if(name_=="@")
name=zone;
else
name=DNSName(name_)+zone;
if (name_ == "@") {
name = zone;
} else if (isCanonical(name_) || boost::ends_with(name_, zone)) {
name = DNSName(name_);
} else {
cerr << "Name " << name_ << "' does not fit into zone '" << zone << "'. Interpreting as relative name." << endl;
name = DNSName(name_) + zone;
}

QType qt(QType::chartocode(type_.c_str()));
di.backend->startTransaction(zone, -1);
Expand Down

0 comments on commit 761be48

Please sign in to comment.