From: Miod Vallat Date: Thu, 10 Apr 2025 05:59:40 +0000 (+0200) Subject: Replace the two lists of metadata keywords with a single list of pairs. X-Git-Tag: dnsdist-2.0.0-alpha2~89^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F15415%2Fhead;p=thirdparty%2Fpdns.git Replace the two lists of metadata keywords with a single list of pairs. This removes the need for a second search in order to figure out whether the metadata is write-protected from the API. --- diff --git a/pdns/ws-auth.cc b/pdns/ws-auth.cc index e1d8312a38..3d7037dfc3 100644 --- a/pdns/ws-auth.cc +++ b/pdns/ws-auth.cc @@ -22,6 +22,7 @@ #include "dnsbackend.hh" #include "webserver.hh" #include +#include #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 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 protectedOptions{ - "AXFR-MASTER-TSIG", - "LUA-AXFR-SCRIPT", - "NSEC3NARROW", - "NSEC3PARAM", - "PRESIGNED", - "TSIG-ALLOW-AXFR", + const static vector> 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.