From: Miod Vallat Date: Fri, 27 Jun 2025 06:33:32 +0000 (+0200) Subject: Let apiZoneNameToId() also encode the variant name, if any. X-Git-Tag: rec-5.3.0-alpha2~43^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7cd0597006954a2148ed8c0c865889583beea508;p=thirdparty%2Fpdns.git Let apiZoneNameToId() also encode the variant name, if any. Signed-off-by: Miod Vallat --- 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();