diff options
author | Kim Alvefur <zash@zash.se> | 2020-01-24 23:27:49 +0100 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2020-01-24 23:27:49 +0100 |
commit | 34603f5da0789d989907d8d596d26b1b31c04aba (patch) | |
tree | ca250c63a8d347111b82801e79f88f44bf8faeac | |
parent | 9185758048972c64ad4cfcd41800dfa4671e7d37 (diff) | |
download | prosody-34603f5da0789d989907d8d596d26b1b31c04aba.tar.gz prosody-34603f5da0789d989907d8d596d26b1b31c04aba.zip |
mod_admin_telnet: Create a DNS resolver per console session (fixes #1492)
This is now the common pattern, eg see mod_s2s.
-rw-r--r-- | plugins/mod_admin_telnet.lua | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/plugins/mod_admin_telnet.lua b/plugins/mod_admin_telnet.lua index 1cbe27a4..59eca28b 100644 --- a/plugins/mod_admin_telnet.lua +++ b/plugins/mod_admin_telnet.lua @@ -1074,36 +1074,49 @@ end def_env.dns = {}; local adns = require"net.adns"; -local dns = require"net.dns"; + +local function get_resolver(session) + local resolver = session.dns_resolver; + if not resolver then + resolver = adns.resolver(); + session.dns_resolver = resolver; + end + return resolver; +end function def_env.dns:lookup(name, typ, class) + local resolver = get_resolver(self.session); local ret = "Query sent"; local print = self.session.print; local function handler(...) ret = "Got response"; print(...); end - adns.lookup(handler, name, typ, class); + resolver:lookup(handler, name, typ, class); return true, ret; end function def_env.dns:addnameserver(...) - dns._resolver:addnameserver(...) + local resolver = get_resolver(self.session); + resolver._resolver:addnameserver(...) return true end function def_env.dns:setnameserver(...) - dns._resolver:setnameserver(...) + local resolver = get_resolver(self.session); + resolver._resolver:setnameserver(...) return true end function def_env.dns:purge() - dns.purge() + local resolver = get_resolver(self.session); + resolver._resolver:purge() return true end function def_env.dns:cache() - return true, "Cache:\n"..tostring(dns.cache()) + local resolver = get_resolver(self.session); + return true, "Cache:\n"..tostring(resolver._resolver.cache) end def_env.http = {}; |