Commit 5c80fcb7 authored by Kaarle Ritvanen's avatar Kaarle Ritvanen

host.resolve: properly handle CNAME records

parent 5d7327a3
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
--[[ --[[
Alpine Wall Alpine Wall
Copyright (C) 2012-2018 Kaarle Ritvanen Copyright (C) 2012-2019 Kaarle Ritvanen
See LICENSE file for license details See LICENSE file for license details
]]-- ]]--
...@@ -20,7 +20,7 @@ if not table.unpack then table.unpack = unpack end ...@@ -20,7 +20,7 @@ if not table.unpack then table.unpack = unpack end
function help() function help()
io.stderr:write([[ io.stderr:write([[
Alpine Wall Alpine Wall
Copyright (C) 2012-2018 Kaarle Ritvanen Copyright (C) 2012-2019 Kaarle Ritvanen
This is free software with ABSOLUTELY NO WARRANTY, This is free software with ABSOLUTELY NO WARRANTY,
available under the terms of the GNU General Public License, version 2 available under the terms of the GNU General Public License, version 2
......
--[[ --[[
Host address resolver for Alpine Wall Host address resolver for Alpine Wall
Copyright (C) 2012-2018 Kaarle Ritvanen Copyright (C) 2012-2019 Kaarle Ritvanen
See LICENSE file for license details See LICENSE file for license details
]]-- ]]--
...@@ -30,16 +30,19 @@ function M.resolve(host, context) ...@@ -30,16 +30,19 @@ function M.resolve(host, context)
if not dnscache[host] then if not dnscache[host] then
dnscache[host] = {} dnscache[host] = {}
for family, rtype in pairs{inet='A', inet6='AAAA'} do for family, rtype in pairs{inet='A', inet6='AAAA'} do
local answer
for rec in io.popen('drill '..host..' '..rtype):lines() do for rec in io.popen('drill '..host..' '..rtype):lines() do
local name, addr = rec:match( if answer then
'^('..familypatterns.domain..')%s+%d+%s+IN%s+'..rtype.. if rec == '' then break end
'%s+(.+)' local addr = rec:match(
) '^'..familypatterns.domain..'%s+%d+%s+IN%s+'..rtype..
'%s+(.+)'
if name and name:sub(1, host:len() + 1) == host..'.' then )
assert(getfamily(addr, context) == family) if addr then
table.insert(dnscache[host], {family, addr}) assert(getfamily(addr, context) == family)
end table.insert(dnscache[host], {family, addr})
end
elseif rec == ';; ANSWER SECTION:' then answer = true end
end end
end end
if not dnscache[host][1] then if not dnscache[host][1] then
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment