From df6f678f98d9a9b0239b6d571d4b4a2b964eb440 Mon Sep 17 00:00:00 2001 From: Miod Vallat Date: Mon, 21 Jul 2025 14:36:59 +0200 Subject: [PATCH] Factor pdnsutil code responsible for printing a record as text. Signed-off-by: Miod Vallat --- pdns/pdnsutil.cc | 28 +++++++++++++++---- .../tests/zone-variants/expected_result.lmdb | 2 +- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/pdns/pdnsutil.cc b/pdns/pdnsutil.cc index b8fd891652..74efa6a788 100644 --- a/pdns/pdnsutil.cc +++ b/pdns/pdnsutil.cc @@ -729,6 +729,22 @@ static int usage(const std::string_view synopsis) return EXIT_FAILURE; } +// Build a string with the record textual (bind-style) representation, +// with explicit trailing dots. +static std::string formatRecord(const DNSRecord& rec, std::string_view separator = "\t") +{ + std::string ret = rec.d_name.toString(); + ret.append(separator); + ret.append(std::to_string(rec.d_ttl)); + ret.append(separator); + ret.append(QClass(rec.d_class).toString()); + ret.append(separator); + ret.append(DNSRecordContent::NumberToType(rec.d_type)); + ret.append(separator); + ret.append(rec.getContent()->getZoneRepresentation(true)); + return ret; +} + static bool rectifyZone(DNSSECKeeper& dsk, const ZoneName& zone, bool quiet = false, bool rectifyTransaction = true) { string output; @@ -1858,7 +1874,7 @@ static std::vectorfillTempZoneFile(int& tmpfd, const char* tmpnam, Do sort(records.begin(), records.end(), DNSRecord::prettyCompare); for (const auto& rec : records) { ostringstream oss; - oss<getZoneRepresentation(true)<getZoneRepresentation(true) << col.rst() <getZoneRepresentation(true) << col.rst() <getZoneRepresentation(true) << col.rst() <getZoneRepresentation(true) << col.rst() <& cmds, const std::string_view synopsis) bool found = false; DNSZoneRecord resultZoneRecord; while (matchingBackend->get(resultZoneRecord)) { - cout << resultZoneRecord.dr.d_name.toString() << "\t" << std::to_string(resultZoneRecord.dr.d_ttl) << "\t" << QClass(resultZoneRecord.dr.d_class).toString() << "\t" << DNSRecordContent::NumberToType(resultZoneRecord.dr.d_type, resultZoneRecord.dr.d_class) << "\t" << resultZoneRecord.dr.getContent()->getZoneRepresentation(); + cout << formatRecord(resultZoneRecord.dr, " "); if (resultZoneRecord.scopeMask > 0) { clientNetmask.setBits(resultZoneRecord.scopeMask); cout << "\t" << "; " << clientNetmask.toString(); diff --git a/regression-tests/tests/zone-variants/expected_result.lmdb b/regression-tests/tests/zone-variants/expected_result.lmdb index ebe367d1b5..9fbb87d32c 100644 --- a/regression-tests/tests/zone-variants/expected_result.lmdb +++ b/regression-tests/tests/zone-variants/expected_result.lmdb @@ -43,4 +43,4 @@ tsig.com wtest.com New rrset: uniquename.example.com. 3600 IN A 1.2.3.4 -uniquename.example.com. 3600 IN A 1.2.3.4 +uniquename.example.com. 3600 IN A 1.2.3.4 -- 2.47.3