From 7cd0597006954a2148ed8c0c865889583beea508 Mon Sep 17 00:00:00 2001 From: Miod Vallat Date: Fri, 27 Jun 2025 08:33:32 +0200 Subject: [PATCH] Let apiZoneNameToId() also encode the variant name, if any. Signed-off-by: Miod Vallat --- pdns/ws-api.cc | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/pdns/ws-api.cc b/pdns/ws-api.cc index d57c39677a..71d792847f 100644 --- a/pdns/ws-api.cc +++ b/pdns/ws-api.cc @@ -341,12 +341,7 @@ ZoneName apiZoneIdToName(const string& identifier) } } -string apiZoneNameToId(const ZoneName& dname) -{ - return apiNameToId(dname.toString()); -} - -string apiNameToId(const string& name) +static string encodeName(const string& name) { ostringstream outputStringStream; @@ -359,14 +354,34 @@ string apiNameToId(const string& name) } } - string identifier = outputStringStream.str(); + return outputStringStream.str(); +} + +string apiZoneNameToId(const ZoneName& dname) +{ +#if defined(PDNS_AUTH) + std::string ret = apiNameToId(dname.operator const DNSName&().toString()); + // Add the variant, if any + if (dname.hasVariant()) { + ret += "."; + ret += encodeName(dname.getVariant()); + } + return ret; +#else + return apiNameToId(dname.toString()); +#endif +} + +string apiNameToId(const string& name) +{ + string identifier = encodeName(name); // add trailing dot if (identifier.empty() || identifier.substr(identifier.size() - 1) != ".") { identifier += "."; } - // special handling for the root zone, as a dot on it's own doesn't work + // special handling for the root zone, as a dot on its own doesn't work // everywhere. if (identifier == ".") { identifier = (boost::format("=%02X") % (int)('.')).str(); -- 2.47.2