From 984f6bfc5db9e4a6f63cd1ee16c2e9702c5d5fcf Mon Sep 17 00:00:00 2001 From: Otto Moerbeek Date: Wed, 8 Dec 2021 14:00:53 +0100 Subject: [PATCH] Add test for new APIs and reformat --- pdns/lua-recursor4-ffi.hh | 2 -- pdns/lua-recursor4.cc | 3 ++- regression-tests.recursor-dnssec/test_Lua.py | 27 +++++++++++++++++--- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/pdns/lua-recursor4-ffi.hh b/pdns/lua-recursor4-ffi.hh index 95c93c0fc7..f5785bdf7b 100644 --- a/pdns/lua-recursor4-ffi.hh +++ b/pdns/lua-recursor4-ffi.hh @@ -128,5 +128,3 @@ extern "C" const char* pdns_postresolve_ffi_handle_get_authip(pdns_postresolve_ffi_handle_t* ref) __attribute__((visibility("default"))); void pdns_postresolve_ffi_handle_get_authip_raw(pdns_postresolve_ffi_handle_t* ref, const void** addr, size_t* addrSize) __attribute__((visibility("default"))); } - -#undef PDNS_VISIBILITY diff --git a/pdns/lua-recursor4.cc b/pdns/lua-recursor4.cc index 0d1a745df8..b0731d4822 100644 --- a/pdns/lua-recursor4.cc +++ b/pdns/lua-recursor4.cc @@ -1113,7 +1113,8 @@ bool pdns_postresolve_ffi_handle_get_record(pdns_postresolve_ffi_handle_t* ref, const auto& storage = r.d_name.getStorage(); record->name = storage.data(); record->name_len = storage.size(); - } else { + } + else { std::string name = r.d_name.toStringNoDot(); record->name_len = name.size(); record->name = ref->insert(std::move(name))->c_str(); diff --git a/regression-tests.recursor-dnssec/test_Lua.py b/regression-tests.recursor-dnssec/test_Lua.py index 13081f051b..a0fb67a87d 100644 --- a/regression-tests.recursor-dnssec/test_Lua.py +++ b/regression-tests.recursor-dnssec/test_Lua.py @@ -832,13 +832,22 @@ function postresolve_ffi(ref) if qname == "example" and qtype == pdns.SOA then local addr = ffi.string(ffi.C.pdns_postresolve_ffi_handle_get_authip(ref)) - pdnslog("XXXX "..addr) if string.sub(addr, -3) ~= ".10" and string.sub(addr, -3) ~= ".18" then -- signal error by clearing all ffi.C.pdns_postresolve_ffi_handle_clear_records(ref) end - -- as a bonug check from which auth the data came + local qaddr = ffi.new("const char *[1]") + local qlen = ffi.new("size_t [1]") + ffi.C.pdns_postresolve_ffi_handle_get_qname_raw(ref, qaddr, qlen) + local q = ffi.string(qaddr[0], qlen[0]) + if tohex(q) ~= "076578616D706C6500" + then + -- pdnslog("Error "..tohex(q)) + -- signal error by clearing all + ffi.C.pdns_postresolve_ffi_handle_clear_records(ref) + end + -- as a bonus check from which auth the data came local addr = ffi.new("const void *[1]") local len = ffi.new("size_t [1]") ffi.C.pdns_postresolve_ffi_handle_get_authip_raw(ref, addr, len) @@ -848,7 +857,6 @@ function postresolve_ffi(ref) -- signal error by clearing all ffi.C.pdns_postresolve_ffi_handle_clear_records(ref) end - ffi.C.pdns_postresolve_ffi_handle_set_appliedpolicy_kind(ref, "pdns_policy_kind_noaction") return true end @@ -899,6 +907,19 @@ function postresolve_ffi(ref) end i = i + 1 end + -- loop again using raw + i = 0 + while ffi.C.pdns_postresolve_ffi_handle_get_record(ref, i, record, true) + do + local content = ffi.string(record.content, record.content_len) + local name = ffi.string(record.name, record.name_len) + --pdnslog("R "..tohex(name)) + if tohex(name) ~= "0F706F73747265736F6C76655F666669076578616D706C6500" + then + ffi.C.pdns_postresolve_ffi_handle_clear_records(ref) + end + i = i + 1 + end return true end """ -- 2.47.2