]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Let apiZoneNameToId() also encode the variant name, if any.
authorMiod Vallat <miod.vallat@powerdns.com>
Fri, 27 Jun 2025 06:33:32 +0000 (08:33 +0200)
committerMiod Vallat <miod.vallat@powerdns.com>
Fri, 27 Jun 2025 08:15:09 +0000 (10:15 +0200)
Signed-off-by: Miod Vallat <miod.vallat@powerdns.com>
pdns/ws-api.cc

index d57c39677a5dcc7ac36e7a290c628d4610d06835..71d792847fc50b2a560f37483fd0d86d3b90eb65 100644 (file)
@@ -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();