]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Replace the two lists of metadata keywords with a single list of pairs. 15415/head
authorMiod Vallat <miod.vallat@powerdns.com>
Thu, 10 Apr 2025 05:59:40 +0000 (07:59 +0200)
committerMiod Vallat <miod.vallat@powerdns.com>
Thu, 10 Apr 2025 08:36:00 +0000 (10:36 +0200)
This removes the need for a second search in order to figure out whether
the metadata is write-protected from the API.

pdns/ws-auth.cc

index e1d8312a38158b321964c3b14e04a8075972c231..3d7037dfc3564437b428a049ffcedc951626c1a6 100644 (file)
@@ -22,6 +22,7 @@
 #include "dnsbackend.hh"
 #include "webserver.hh"
 #include <array>
+#include <string_view>
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
@@ -941,59 +942,41 @@ static void updateDomainSettingsFromDocument(UeberBackend& backend, DomainInfo&
 
 static bool isValidMetadataKind(const string& kind, bool readonly)
 {
-  static vector<string> builtinOptions{
-    "ALLOW-AXFR-FROM",
-    "ALLOW-DNSUPDATE-FROM",
-    "ALSO-NOTIFY",
-    "AXFR-MASTER-TSIG",
-    "AXFR-SOURCE",
-    "FORWARD-DNSUPDATE",
-    "GSS-ACCEPTOR-PRINCIPAL",
-    "GSS-ALLOW-AXFR-PRINCIPAL",
-    "IXFR",
-    "LUA-AXFR-SCRIPT",
-    "NOTIFY-DNSUPDATE",
-    "NSEC3NARROW",
-    "NSEC3PARAM",
-    "PRESIGNED",
-    "PUBLISH-CDNSKEY",
-    "PUBLISH-CDS",
-    "SLAVE-RENOTIFY",
-    "SOA-EDIT",
-    "SOA-EDIT-DNSUPDATE",
-    "TSIG-ALLOW-AXFR",
-    "TSIG-ALLOW-DNSUPDATE",
-  };
-
-  // the following options do not allow modifications via API
-  static vector<string> protectedOptions{
-    "AXFR-MASTER-TSIG",
-    "LUA-AXFR-SCRIPT",
-    "NSEC3NARROW",
-    "NSEC3PARAM",
-    "PRESIGNED",
-    "TSIG-ALLOW-AXFR",
+  const static vector<std::pair<std::string_view, bool /* readonly */>> builtinOptions{
+    {"ALLOW-AXFR-FROM", false},
+    {"ALLOW-DNSUPDATE-FROM", false},
+    {"ALSO-NOTIFY", false},
+    {"AXFR-MASTER-TSIG", true},
+    {"AXFR-SOURCE", false},
+    {"FORWARD-DNSUPDATE", false},
+    {"GSS-ACCEPTOR-PRINCIPAL", false},
+    {"GSS-ALLOW-AXFR-PRINCIPAL", false},
+    {"IXFR", false},
+    {"LUA-AXFR-SCRIPT", true},
+    {"NOTIFY-DNSUPDATE", false},
+    {"NSEC3NARROW", true},
+    {"NSEC3PARAM", true},
+    {"PRESIGNED", true},
+    {"PUBLISH-CDNSKEY", false},
+    {"PUBLISH-CDS", false},
+    {"SLAVE-RENOTIFY", false},
+    {"SOA-EDIT", true},
+    {"SOA-EDIT-DNSUPDATE", false},
+    {"TSIG-ALLOW-AXFR", false},
+    {"TSIG-ALLOW-DNSUPDATE", false},
   };
 
   if (kind.find("X-") == 0) {
     return true;
   }
 
-  bool found = false;
-
-  for (const string& builtinOption : builtinOptions) {
-    if (kind == builtinOption) {
-      for (const string& protectedOption : protectedOptions) {
-        if (!readonly && builtinOption == protectedOption) {
-          return false;
-        }
-      }
-      found = true;
-      break;
+  for (const auto& builtinOption : builtinOptions) {
+    if (kind == builtinOption.first) {
+      return readonly || !builtinOption.second;
     }
   }
 
-  return found;
+  return false;
 }
 
 /* Return OpenAPI document describing the supported API.