]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
auth LUA dblookup: switch qtype argument to int 13860/head
authorPeter van Dijk <peter.van.dijk@powerdns.com>
Tue, 5 Mar 2024 11:34:50 +0000 (12:34 +0100)
committerPeter van Dijk <peter.van.dijk@powerdns.com>
Tue, 5 Mar 2024 11:34:50 +0000 (12:34 +0100)
docs/lua-records/functions.rst
pdns/lua-record.cc
regression-tests.auth-py/test_LuaRecords.py

index 0c578c72d3834c1945aef1f1b9864b8572161153..8df147fbeef531857c5f8dc9632bce8f89884f8d 100644 (file)
@@ -504,17 +504,19 @@ Helper functions
 
 .. function:: dblookup(name, type)
 
+  .. versionadded:: 4.9.0
+
   Does a database lookup for name and type, and returns a (possibly empty) array of string results.
 
   Please keep the following in mind:
 
   * it does not evaluate any LUA code found
-  * if you needed just one string, perhaps you want ``dblookup('www.example.org', 'A')[1]`` to take the first item from the array
+  * if you needed just one string, perhaps you want ``dblookup('www.example.org', pdns.A)[1]`` to take the first item from the array
   * some things, like ifurlup, don't like empty tables, so be careful not to accidentally look up a name that does not have any records of that type, if you are going to use the result in ``ifurlup``
 
   Example usage: ::
 
-    www IN LUA A "ifurlup('https://www.example.com/', {dblookup('www1.example.com', 'A'), dblookup('www2.example.com', 'A'), dblookup('www3.example.com', 'A')})"
+    www IN LUA A "ifurlup('https://www.example.com/', {dblookup('www1.example.com', pdns.A), dblookup('www2.example.com', pdns.A), dblookup('www3.example.com', pdns.A)})"
 
   :param string name: Name to look up in the database
-  :param string type: DNS type to look for
+  :param int type: DNS type to look for
index 5f3e7cb6156b717e76d58d4d5a1a81afffc42f1c..43620258c02b7a0123123fa19734b14ad4150060 100644 (file)
@@ -1334,19 +1334,14 @@ static void setupLuaRecords(LuaContext& lua) // NOLINT(readability-function-cogn
       return result;
     });
 
-  lua.writeFunction("dblookup", [](const string& record, const string& type) {
+  lua.writeFunction("dblookup", [](const string& record, uint16_t qtype) {
     DNSName rec;
-    QType qtype;
     vector<string> ret;
     try {
       rec = DNSName(record);
-      qtype = type;
-      if (qtype.getCode() == 0) {
-        throw std::invalid_argument("unknown type");
-      }
     }
     catch (const std::exception& e) {
-      g_log << Logger::Error << "DB lookup cannot be performed, the name (" << record << ") or type (" << type << ") is malformed: " << e.what() << endl;
+      g_log << Logger::Error << "DB lookup cannot be performed, the name (" << record << ") is malformed: " << e.what() << endl;
       return ret;
     }
     try {
index 42aac90372a838b4fa9ff5ffd4abbf70d6a384bc..1b6fb70c502a79407c05b8d3d60aca740fb8b56a 100644 (file)
@@ -154,7 +154,7 @@ newcafromraw     IN    LUA    AAAA "newCAFromRaw('ABCD020340506070'):toString()"
 counter          IN    LUA    TXT  ";counter = counter or 0 counter=counter+1 return tostring(counter)"
 
 lookmeup         IN           A  192.0.2.5
-dblookup         IN    LUA    A  "dblookup('lookmeup.example.org', 'A')[1]"
+dblookup         IN    LUA    A  "dblookup('lookmeup.example.org', pdns.A)[1]"
         """,
         'createforward6.example.org': """
 createforward6.example.org.                 3600 IN SOA  {soa}