]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Add and use lua-global-include-path setting
authorAki Tuomi <cmouse@cmouse.fi>
Fri, 3 Jun 2022 10:16:04 +0000 (13:16 +0300)
committerAki Tuomi <cmouse@cmouse.fi>
Thu, 25 Jul 2024 04:43:41 +0000 (07:43 +0300)
docs/settings.rst
modules/lua2backend/lua2api2.hh
pdns/auth-main.cc
pdns/auth-secondarycommunicator.cc
pdns/lua-record.cc
pdns/packethandler.cc
pdns/recursordist/settings/table.py

index a8f7c07f704e18feeb34c0b8714488e9dd4bdd59..2cb26b4eadac1b639201f5b2027fee93fdd53d7d 100644 (file)
@@ -1046,6 +1046,18 @@ Amount of time (in seconds) between subsequent cleanup routines for pre-computed
 
 Amount of time (in seconds) a pre-computed hash entry will be considered as expired when unused. See :func:`pickchashed()`.
 
+.. _setting-lua-global-include-dir:
+
+``lua-global-include-dir``
+---------------------------
+
+-  String
+-  Default: empty
+-  Example: ``/etc/pdns/lua-global/``
+
+When creating a Lua context, scan this directory for additional lua files. All files that end with
+.lua are loaded in order using ``POSIX`` as locale with Lua scripts.
+
 .. _setting-lua-health-checks-expire-delay:
 
 ``lua-health-checks-expire-delay``
index b2f298cfcec46cdcce107277ee9d1f3fe35e6220..857fb1782c4a6073996a2d44109849e951999c3e 100644 (file)
@@ -68,6 +68,7 @@ private:
 public:
   Lua2BackendAPIv2(const string& suffix)
   {
+    d_include_path = ::arg()["lua-global-include-dir"];
     setArgPrefix("lua2" + suffix);
     d_debug_log = mustDo("query-logging");
     prepareContext();
index 86ffca40c5d016ab618d908508bcdd21734e4098..691242143f2ea41804c49dd17cac2f892b8571c8 100644 (file)
@@ -291,6 +291,7 @@ static void declareArguments()
 
   ::arg().set("lua-prequery-script", "Lua script with prequery handler (DO NOT USE)") = "";
   ::arg().set("lua-dnsupdate-policy-script", "Lua script with DNS update policy handler") = "";
+  ::arg().set("lua-global-include-dir", "Include *.lua files from this directory into Lua contexts") = "";
 
   ::arg().setSwitch("traceback-handler", "Enable the traceback handler (Linux only)") = "yes";
   ::arg().setSwitch("direct-dnskey", "Fetch DNSKEY, CDS and CDNSKEY RRs from backend during DNSKEY or CDS/CDNSKEY synthesis") = "no";
index 9f21e81256b6cbe17f20eccd59fe8f710db40e6a..93ccc184e67f65ea0721e2a878146df3e12415d4 100644 (file)
@@ -689,8 +689,8 @@ void CommunicatorClass::suck(const DNSName& domain, const ComboAddress& remote,
 
     unique_ptr<AuthLua4> pdl{nullptr};
     vector<string> scripts;
-    string script = ::arg()["lua-axfr-script"];
-    if (B.getDomainMetadata(domain, "LUA-AXFR-SCRIPT", scripts) && !scripts.empty()) {
+    string script= ::arg()["lua-axfr-script"];
+    if(B.getDomainMetadata(domain, "LUA-AXFR-SCRIPT", scripts) && !scripts.empty()) {
       if (pdns_iequals(scripts[0], "NONE")) {
         script.clear();
       }
@@ -700,7 +700,7 @@ void CommunicatorClass::suck(const DNSName& domain, const ComboAddress& remote,
     }
     if (!script.empty()) {
       try {
-        pdl = make_unique<AuthLua4>();
+        pdl = make_unique<AuthLua4>(::arg()["lua-global-include-dir"]);
         pdl->loadFile(script);
         g_log << Logger::Info << logPrefix << "loaded Lua script '" << script << "'" << endl;
       }
index e9b08e662387219560a0ff5603323bcb93946677..6c33cf3d515efb8e04417372f59114b312dde388 100644 (file)
@@ -1391,7 +1391,7 @@ std::vector<shared_ptr<DNSRecordContent>> luaSynth(const std::string& code, cons
 {
   if(!LUA ||                  // we don't have a Lua state yet
      !g_LuaRecordSharedState) { // or we want a new one even if we had one
-    LUA = make_unique<AuthLua4>();
+    LUA = make_unique<AuthLua4>(::arg()["lua-global-include-dir"]);
     setupLuaRecords(*LUA->getLua());
   }
 
index 087834afed655eecb7ce795911e7eea473078ab7..797922b38723d0f7df1f5b970fe3a5cfeb2e781d 100644 (file)
@@ -71,14 +71,15 @@ PacketHandler::PacketHandler():B(g_programname), d_dk(&B)
   d_doExpandALIAS = ::arg().mustDo("expand-alias");
   d_logDNSDetails= ::arg().mustDo("log-dns-details");
   string fname= ::arg()["lua-prequery-script"];
+
   if(fname.empty())
   {
     d_pdl = nullptr;
   }
   else
   {
-    d_pdl = std::make_unique<AuthLua4>();
-    d_pdl->loadFile(fname); // XXX exception handling?
+    d_pdl = std::make_unique<AuthLua4>(::arg()["lua-global-include-dir"]);
+    d_pdl->loadFile(fname);
   }
   fname = ::arg()["lua-dnsupdate-policy-script"];
   if (fname.empty())
@@ -87,11 +88,12 @@ PacketHandler::PacketHandler():B(g_programname), d_dk(&B)
   }
   else
   {
-    d_update_policy_lua = std::make_unique<AuthLua4>();
     try {
+      d_update_policy_lua = std::make_unique<AuthLua4>();
       d_update_policy_lua->loadFile(fname);
     }
-    catch (const std::runtime_error&) {
+    catch (const std::runtime_error& e) {
+      g_log<<Logger::Warning<<"Failed to load update policy - disabling: "<<e.what()<<endl;
       d_update_policy_lua = nullptr;
     }
   }
index ece2c9543e804d99458cb8d663ca578a8a82c6f3..5c8fe6eed9390be7d50267c80108c0f4d3c24aeb 100644 (file)
@@ -1355,6 +1355,16 @@ Setting ``lowercase-outgoing`` to 'yes' makes the PowerDNS Recursor lowercase al
         'doc' : '''
 If set, and Lua support is compiled in, this will load an additional configuration file for newer features and more complicated setups.
 See :doc:`lua-config/index` for the options that can be set in this file.
+ ''',
+    },
+    {
+        'name' : 'lua_global_include_dir',
+        'section' : 'recursor',
+        'type' : LType.String,
+        'default' : '',
+        'help' : 'More powerful configuration options',
+        'doc' : '''
+ When creating a Lua context, all *.lua files in the directory are loaded to the Lua context.
  ''',
     },
     {