mirror of
https://github.com/nmap/nmap.git
synced 2025-12-06 04:31:29 +00:00
Move comma-separated list code to outlib
This commit is contained in:
@@ -17,6 +17,7 @@ local yield = coroutine.yield
|
||||
|
||||
local table = require "table"
|
||||
local sort = table.sort
|
||||
local concat = table.concat
|
||||
|
||||
local setmetatable = setmetatable
|
||||
local ipairs = ipairs
|
||||
@@ -46,4 +47,32 @@ function sorted_by_key(t)
|
||||
return out
|
||||
end
|
||||
|
||||
local commasep = {
|
||||
__tostring = function (t)
|
||||
return concat(t, ", ")
|
||||
end
|
||||
}
|
||||
|
||||
--- Comma-separated list output
|
||||
--
|
||||
-- This adds a <code>__tostring</code> metamethod to a list (integer-indexed
|
||||
-- table) so that it will be formatted as a comma-separated list when converted
|
||||
-- to a string.
|
||||
-- @param t The table to format
|
||||
-- @param sep (Optional) list separator character, default: ", "
|
||||
function list_sep(t, sep)
|
||||
-- Reuse closures and metatables as much as possible
|
||||
local oldmt = getmetatable(t)
|
||||
local newmt = sep and {
|
||||
__tostring = function(tt)
|
||||
return concat(tt, sep)
|
||||
end} or commasep
|
||||
-- Avoid clobbering old metatable or our static commasep table
|
||||
if oldmt and oldmt ~= commasep then
|
||||
oldmt.__tostring = newmt.__tostring
|
||||
else
|
||||
setmetatable(t, newmt)
|
||||
end
|
||||
end
|
||||
|
||||
return _ENV
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
local afp = require "afp"
|
||||
local nmap = require "nmap"
|
||||
local outlib = require "outlib"
|
||||
local shortport = require "shortport"
|
||||
local stdnse = require "stdnse"
|
||||
local table = require "table"
|
||||
@@ -88,12 +89,6 @@ categories = {"default", "discovery", "safe"}
|
||||
|
||||
portrule = shortport.port_or_service(548, "afp")
|
||||
|
||||
local commasep = {
|
||||
__tostring = function (t)
|
||||
return table.concat(t, ", ")
|
||||
end
|
||||
}
|
||||
|
||||
action = function(host, port)
|
||||
|
||||
local socket = nmap.new_socket()
|
||||
@@ -148,11 +143,11 @@ action = function(host, port)
|
||||
|
||||
-- list the supported AFP versions
|
||||
result["AFP Versions"] = response.afp_versions
|
||||
setmetatable(result["AFP Versions"], commasep)
|
||||
outlib.list_sep(result["AFP Versions"])
|
||||
|
||||
-- list the supported UAMs (User Authentication Modules)
|
||||
result["UAMs"] = response.uams
|
||||
setmetatable(result["UAMs"], commasep)
|
||||
outlib.list_sep(result["UAMs"])
|
||||
|
||||
-- server signature, not sure of the format here so just showing a hex string
|
||||
if response.flags.ServerSignature then
|
||||
|
||||
@@ -3,7 +3,9 @@ local dhcp = require "dhcp"
|
||||
local ipOps = require "ipOps"
|
||||
local math = require "math"
|
||||
local nmap = require "nmap"
|
||||
local outlib = require "outlib"
|
||||
local packet = require "packet"
|
||||
local rand = require "rand"
|
||||
local stdnse = require "stdnse"
|
||||
local string = require "string"
|
||||
local table = require "table"
|
||||
@@ -141,12 +143,6 @@ local function dhcp_listener(sock, timeout, xid, result)
|
||||
condvar "signal"
|
||||
end
|
||||
|
||||
local commasep = {
|
||||
__tostring = function (t)
|
||||
return table.concat(t, ", ")
|
||||
end
|
||||
}
|
||||
|
||||
local function fail (err) return stdnse.format_output(false, err) end
|
||||
|
||||
action = function()
|
||||
@@ -230,7 +226,7 @@ action = function()
|
||||
result_table["IP Offered"] = r.yiaddr_str
|
||||
for _, v in ipairs(r.options) do
|
||||
if(type(v.value) == 'table') then
|
||||
setmetatable(v.value, commasep)
|
||||
outlib.list_sep(v.value)
|
||||
end
|
||||
result_table[ v.name ] = v.value
|
||||
end
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
local dhcp = require "dhcp"
|
||||
local rand = require "rand"
|
||||
local nmap = require "nmap"
|
||||
local outlib = require "outlib"
|
||||
local shortport = require "shortport"
|
||||
local stdnse = require "stdnse"
|
||||
local string = require "string"
|
||||
@@ -103,12 +104,6 @@ function portrule(host, port)
|
||||
return shortport.portnumber(67, "udp")(host, port)
|
||||
end
|
||||
|
||||
local commasep = {
|
||||
__tostring = function (t)
|
||||
return table.concat(t, ", ")
|
||||
end
|
||||
}
|
||||
|
||||
action = function(host, port)
|
||||
local dhcptype = (stdnse.get_script_args(SCRIPT_NAME .. ".dhcptype") or "DHCPINFORM"):upper()
|
||||
local dhcptypeid = dhcp.request_types[dhcptype]
|
||||
@@ -185,7 +180,7 @@ action = function(host, port)
|
||||
end
|
||||
for _, v in ipairs(result.options) do
|
||||
if type(v.value) == 'table' then
|
||||
setmetatable(v.value, commasep)
|
||||
outlib.list_sep(v.value)
|
||||
end
|
||||
result_table[ v.name ] = v.value
|
||||
end
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
local dns = require "dns"
|
||||
local ipOps = require "ipOps"
|
||||
local nmap = require "nmap"
|
||||
local outlib = require "outlib"
|
||||
local packet = require "packet"
|
||||
local stdnse = require "stdnse"
|
||||
local string = require "string"
|
||||
@@ -152,12 +153,6 @@ local function stringify_noop(flags, data)
|
||||
return "replied"
|
||||
end
|
||||
|
||||
local commasep = {
|
||||
__tostring = function (t)
|
||||
return table.concat(t, ", ")
|
||||
end
|
||||
}
|
||||
|
||||
-- RFC 4620, section 6.3.
|
||||
local function stringify_nodename(flags, data)
|
||||
local status, names
|
||||
@@ -170,7 +165,7 @@ local function stringify_nodename(flags, data)
|
||||
names[#names+1] = "(parsing error)"
|
||||
end
|
||||
|
||||
setmetatable(names, commasep)
|
||||
outlib.list_sep(names)
|
||||
return names
|
||||
end
|
||||
|
||||
@@ -195,7 +190,7 @@ local function stringify_nodeaddresses(flags, data)
|
||||
addrs[#addrs+1] = "(more omitted for space reasons)"
|
||||
end
|
||||
|
||||
setmetatable(addrs, commasep)
|
||||
outlib.list_sep(addrs)
|
||||
return addrs
|
||||
end
|
||||
|
||||
@@ -217,7 +212,7 @@ local function stringify_nodeipv4addresses(flags, data)
|
||||
-- Check for DNS names.
|
||||
status, names = try_decode_nodenames(data .. "\0\0")
|
||||
if status then
|
||||
setmetatable(names, commasep)
|
||||
outlib.list_sep(names)
|
||||
return names
|
||||
end
|
||||
|
||||
@@ -237,7 +232,7 @@ local function stringify_nodeipv4addresses(flags, data)
|
||||
addrs[#addrs+1] = "(more omitted for space reasons)"
|
||||
end
|
||||
|
||||
setmetatable(addrs, commasep)
|
||||
outlib.list_sep(addrs)
|
||||
return addrs
|
||||
end
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
local ipOps = require "ipOps"
|
||||
local nmap = require "nmap"
|
||||
local outlib = require "outlib"
|
||||
local stdnse = require "stdnse"
|
||||
local table = require "table"
|
||||
local tableaux = require "tableaux"
|
||||
@@ -85,12 +86,6 @@ hostaction = function(host)
|
||||
end
|
||||
end
|
||||
|
||||
local commasep = {
|
||||
__tostring = function (t)
|
||||
return table.concat(t, ", ")
|
||||
end
|
||||
}
|
||||
|
||||
postaction = function()
|
||||
local db = nmap.registry[SCRIPT_NAME]
|
||||
if ( db == nil ) then
|
||||
@@ -108,7 +103,7 @@ postaction = function()
|
||||
local result_entries = ports[port]
|
||||
ipOps.ip_sort(result_entries)
|
||||
if mode == 'horizontal' then
|
||||
setmetatable(result_entries, commasep)
|
||||
outlib.list_sep(result_entries)
|
||||
end
|
||||
results[("%s/%s"):format(port, proto)] = result_entries
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user