]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Only expose KVS helpers when CDB or LMDB is available
authorRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 12 Nov 2021 14:57:51 +0000 (15:57 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Wed, 22 Dec 2021 08:30:44 +0000 (09:30 +0100)
Idem for DNSCrypt

pdns/dnsdistdist/dnsdist-lua-bindings-dnscrypt.cc
pdns/dnsdistdist/dnsdist-lua-bindings-kvs.cc

index 8de02805e9f14ea986ac37a3152bed39c6d30cd6..cc482777c57353e4ff528e54841db3012bbb497b 100644 (file)
@@ -171,11 +171,9 @@ void setupLuaBindingsDNSCrypt(LuaContext& luaCtx, bool client)
         g_outputBuffer = "Error: " + string(e.what()) + "\n";
       }
     });
-#endif
 
     luaCtx.writeFunction("generateDNSCryptProviderKeys", [client](const std::string& publicKeyFile, const std::string privateKeyFile) {
       setLuaNoSideEffect();
-#ifdef HAVE_DNSCRYPT
       if (client) {
         return;
       }
@@ -203,14 +201,10 @@ void setupLuaBindingsDNSCrypt(LuaContext& luaCtx, bool client)
 
       sodium_memzero(privateKey, sizeof(privateKey));
       sodium_munlock(privateKey, sizeof(privateKey));
-#else
-      g_outputBuffer = "Error: DNSCrypt support is not enabled.\n";
-#endif
     });
 
     luaCtx.writeFunction("printDNSCryptProviderFingerprint", [](const std::string& publicKeyFile) {
       setLuaNoSideEffect();
-#ifdef HAVE_DNSCRYPT
       unsigned char publicKey[DNSCRYPT_PROVIDER_PUBLIC_KEY_SIZE];
 
       try {
@@ -228,8 +222,6 @@ void setupLuaBindingsDNSCrypt(LuaContext& luaCtx, bool client)
         errlog(e.what());
         g_outputBuffer = "Error: " + string(e.what()) + "\n";
       }
-#else
-      g_outputBuffer = "Error: DNSCrypt support is not enabled.\n";
-#endif
     });
+#endif
 }
index b1e0c0fc0f0b09b774bfc35e507fefafc5d47e87..581fec203bbcc411d8d4315a2d1ba80da521550d 100644 (file)
 
 void setupLuaBindingsKVS(LuaContext& luaCtx, bool client)
 {
-  /* Key Value Store objects */
-  luaCtx.writeFunction("KeyValueLookupKeySourceIP", [](boost::optional<uint8_t> v4Mask, boost::optional<uint8_t> v6Mask, boost::optional<bool> includePort) {
-    return std::shared_ptr<KeyValueLookupKey>(new KeyValueLookupKeySourceIP(v4Mask.get_value_or(32), v6Mask.get_value_or(128), includePort.get_value_or(false)));
-  });
-  luaCtx.writeFunction("KeyValueLookupKeyQName", [](boost::optional<bool> wireFormat) {
-    return std::shared_ptr<KeyValueLookupKey>(new KeyValueLookupKeyQName(wireFormat ? *wireFormat : true));
-  });
-  luaCtx.writeFunction("KeyValueLookupKeySuffix", [](boost::optional<size_t> minLabels, boost::optional<bool> wireFormat) {
-    return std::shared_ptr<KeyValueLookupKey>(new KeyValueLookupKeySuffix(minLabels ? *minLabels : 0, wireFormat ? *wireFormat : true));
-  });
-  luaCtx.writeFunction("KeyValueLookupKeyTag", [](const std::string& tag) {
-    return std::shared_ptr<KeyValueLookupKey>(new KeyValueLookupKeyTag(tag));
-  });
-
 #ifdef HAVE_LMDB
   luaCtx.writeFunction("newLMDBKVStore", [client](const std::string& fname, const std::string& dbName, boost::optional<bool> noLock) {
     if (client) {
@@ -57,6 +43,21 @@ void setupLuaBindingsKVS(LuaContext& luaCtx, bool client)
   });
 #endif /* HAVE_CDB */
 
+#if defined(HAVE_LMDB) || defined(HAVE_CDB)
+  /* Key Value Store objects */
+  luaCtx.writeFunction("KeyValueLookupKeySourceIP", [](boost::optional<uint8_t> v4Mask, boost::optional<uint8_t> v6Mask, boost::optional<bool> includePort) {
+    return std::shared_ptr<KeyValueLookupKey>(new KeyValueLookupKeySourceIP(v4Mask.get_value_or(32), v6Mask.get_value_or(128), includePort.get_value_or(false)));
+  });
+  luaCtx.writeFunction("KeyValueLookupKeyQName", [](boost::optional<bool> wireFormat) {
+    return std::shared_ptr<KeyValueLookupKey>(new KeyValueLookupKeyQName(wireFormat ? *wireFormat : true));
+  });
+  luaCtx.writeFunction("KeyValueLookupKeySuffix", [](boost::optional<size_t> minLabels, boost::optional<bool> wireFormat) {
+    return std::shared_ptr<KeyValueLookupKey>(new KeyValueLookupKeySuffix(minLabels ? *minLabels : 0, wireFormat ? *wireFormat : true));
+  });
+  luaCtx.writeFunction("KeyValueLookupKeyTag", [](const std::string& tag) {
+    return std::shared_ptr<KeyValueLookupKey>(new KeyValueLookupKeyTag(tag));
+  });
+
   luaCtx.registerFunction<std::string(std::shared_ptr<KeyValueStore>::*)(const boost::variant<ComboAddress, DNSName, std::string>, boost::optional<bool> wireFormat)>("lookup", [](std::shared_ptr<KeyValueStore>& kvs, const boost::variant<ComboAddress, DNSName, std::string> keyVar, boost::optional<bool> wireFormat) {
     std::string result;
     if (!kvs) {
@@ -112,4 +113,5 @@ void setupLuaBindingsKVS(LuaContext& luaCtx, bool client)
 
     return kvs->reload();
   });
+#endif /* defined(HAVE_LMDB) || defined(HAVE_CDB) */
 }