From: Peter van Dijk Date: Tue, 5 Mar 2024 11:34:50 +0000 (+0100) Subject: auth LUA dblookup: switch qtype argument to int X-Git-Tag: dnsdist-1.10.0-alpha0~4^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F13860%2Fhead;p=thirdparty%2Fpdns.git auth LUA dblookup: switch qtype argument to int --- diff --git a/docs/lua-records/functions.rst b/docs/lua-records/functions.rst index 0c578c72d3..8df147fbee 100644 --- a/docs/lua-records/functions.rst +++ b/docs/lua-records/functions.rst @@ -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 diff --git a/pdns/lua-record.cc b/pdns/lua-record.cc index 5f3e7cb615..43620258c0 100644 --- a/pdns/lua-record.cc +++ b/pdns/lua-record.cc @@ -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 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 { diff --git a/regression-tests.auth-py/test_LuaRecords.py b/regression-tests.auth-py/test_LuaRecords.py index 42aac90372..1b6fb70c50 100644 --- a/regression-tests.auth-py/test_LuaRecords.py +++ b/regression-tests.auth-py/test_LuaRecords.py @@ -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}