1
0
mirror of https://github.com/nmap/nmap.git synced 2026-01-05 22:19:03 +00:00

Remove trailing whitespace in lua files

Whitespace is not significant, so this should not be a problem.
https://secwiki.org/w/Nmap/Code_Standards
This commit is contained in:
dmiller
2014-01-23 21:51:58 +00:00
parent 86ac3c0a19
commit 620f9fdb34
499 changed files with 11134 additions and 11134 deletions

View File

@@ -14,7 +14,7 @@ local table = require "table"
_ENV = stdnse.module("ndmp", stdnse.seeall)
NDMP = {
-- Message types
MessageType = {
CONFIG_GET_HOST_INFO = 0x00000100,
@@ -23,24 +23,24 @@ NDMP = {
CONFIG_GET_SERVER_INFO = 0x00000108,
CONNECT_CLIENT_AUTH = 0x00000901,
},
-- The fragment header, 4 bytes where the highest bit is used to determine
-- whether the fragment is the last or not.
-- whether the fragment is the last or not.
FragmentHeader = {
size = 4,
-- Creates a new instance of fragment header
-- @return o instance of Class
new = function(self)
local o = {
local o = {
last = true,
length = 24,
}
setmetatable(o, self)
self.__index = self
return o
return o
end,
-- Parse data stream and create a new instance of this class
-- @param data opaque string
-- @return fh new instance of FragmentHeader class
@@ -51,7 +51,7 @@ NDMP = {
fh.last= bit.rshift(tmp, 31)
return fh
end,
-- Serializes the instance to an opaque string
-- @return str string containing the serialized class
__tostring = function(self)
@@ -62,9 +62,9 @@ NDMP = {
tmp = tmp + self.length
return bin.pack(">I", tmp)
end,
},
-- The ndmp 24 byte header
Header = {
size = 24,
@@ -72,7 +72,7 @@ NDMP = {
-- creates a new instance of Header
-- @return o instance of Header
new = function(self)
local o = {
local o = {
seq = 0,
time = os.time(),
type = 0,
@@ -82,9 +82,9 @@ NDMP = {
}
setmetatable(o, self)
self.__index = self
return o
return o
end,
-- Create a Header instance from opaque data string
-- @param data opaque string
-- @return hdr new instance of Header
@@ -94,16 +94,16 @@ NDMP = {
pos, hdr.seq, hdr.time, hdr.type, hdr.msg, hdr.reply_seq, hdr.error = bin.unpack(">IIIIII", data)
return hdr
end,
-- Serializes the instance to an opaque string
-- @return str string containing the serialized class instance
__tostring = function(self)
return bin.pack(">IIIIII", self.seq, self.time, self.type, self.msg, self.reply_seq, self.error)
end,
},
}
NDMP.Message = {}
NDMP.Message.ConfigGetServerInfo = {
@@ -119,9 +119,9 @@ NDMP.Message.ConfigGetServerInfo = {
o.header.msg = NDMP.MessageType.CONFIG_GET_SERVER_INFO
setmetatable(o, self)
self.__index = self
return o
return o
end,
-- Create a ConfigGetServerInfo instance from opaque data string
-- @param data opaque string
-- @return msg new instance of ConfigGetServerInfo
@@ -131,7 +131,7 @@ NDMP.Message.ConfigGetServerInfo = {
data = data:sub(NDMP.FragmentHeader.size + 1)
msg.header = NDMP.Header.parse(data)
msg.data = data:sub(NDMP.Header.size + 1)
msg.serverinfo = {}
local pos, err = bin.unpack(">I", msg.data)
pos, msg.serverinfo.vendor = Util.parseString(msg.data, pos)
@@ -144,7 +144,7 @@ NDMP.Message.ConfigGetServerInfo = {
-- @return str string containing the serialized class instance
__tostring = function(self)
return tostring(self.frag_header) .. tostring(self.header) .. tostring(self.data or "")
end,
end,
}
@@ -158,7 +158,7 @@ NDMP.Message.ConfigGetHostInfo = {
o.header.msg = NDMP.MessageType.CONFIG_GET_HOST_INFO
setmetatable(o, self)
self.__index = self
return o
return o
end,
parse = function(data)
@@ -167,19 +167,19 @@ NDMP.Message.ConfigGetHostInfo = {
data = data:sub(NDMP.FragmentHeader.size + 1)
msg.header = NDMP.Header.parse(data)
msg.data = data:sub(NDMP.Header.size + 1)
msg.hostinfo = {}
local pos, err = bin.unpack(">I", msg.data)
pos, msg.hostinfo.hostname = Util.parseString(msg.data, pos)
pos, msg.hostinfo.ostype = Util.parseString(msg.data, pos)
pos, msg.hostinfo.osver = Util.parseString(msg.data, pos)
pos, msg.hostinfo.hostid = Util.parseString(msg.data, pos)
pos, msg.hostinfo.hostid = Util.parseString(msg.data, pos)
return msg
end,
__tostring = function(self)
return tostring(self.frag_header) .. tostring(self.header) .. tostring(self.data or "")
end,
end,
}
NDMP.Message.ConfigGetFsInfo = {
@@ -194,16 +194,16 @@ NDMP.Message.ConfigGetFsInfo = {
o.header.msg = NDMP.MessageType.CONFIG_GET_FS_INFO
setmetatable(o, self)
self.__index = self
return o
return o
end,
parse = function(data)
local msg = NDMP.Message.ConfigGetFsInfo:new()
msg.frag_header = NDMP.FragmentHeader.parse(data)
data = data:sub(NDMP.FragmentHeader.size + 1)
msg.header = NDMP.Header.parse(data)
msg.data = data:sub(NDMP.Header.size + 1)
local pos, err, count = bin.unpack(">II", msg.data)
for i=1, count do
local item = {}
@@ -217,19 +217,19 @@ NDMP.Message.ConfigGetFsInfo = {
pos, item.total_inodes = bin.unpack(">L", msg.data, pos)
pos, item.used_inodes = bin.unpack(">L", msg.data, pos)
pos, item.fs_env = Util.parseString(msg.data, pos)
pos, item.fs_status = Util.parseString(msg.data, pos)
pos, item.fs_status = Util.parseString(msg.data, pos)
table.insert(msg.fsinfo, item)
end
return msg
end,
__tostring = function(self)
return tostring(self.frag_header) .. tostring(self.header) .. tostring(self.data or "")
end,
end,
}
NDMP.Message.UnhandledMessage = {
new = function(self)
local o = {
frag_header = NDMP.FragmentHeader:new(),
@@ -238,9 +238,9 @@ NDMP.Message.UnhandledMessage = {
}
setmetatable(o, self)
self.__index = self
return o
return o
end,
parse = function(data)
local msg = NDMP.Message.ConfigGetFsInfo:new()
msg.frag_header = NDMP.FragmentHeader.parse(data)
@@ -249,22 +249,22 @@ NDMP.Message.UnhandledMessage = {
msg.data = data:sub(NDMP.Header.size + 1)
return msg
end,
__tostring = function(self)
return tostring(self.frag_header) .. tostring(self.header) .. tostring(self.data or "")
end
}
Util = {
parseString = function(data, pos)
local pos, str = bin.unpack(">a", data, pos)
local pad = ( 4 - ( #str % 4 ) ~= 4 ) and 4 - ( #str % 4 ) or 0
return pos + pad, str
end,
}
NDMP.TypeToMessage = {
@@ -275,7 +275,7 @@ NDMP.TypeToMessage = {
-- Handles the communication with the NDMP service
Comm = {
-- Creates new Comm instance
-- @param host table as received by the action method
-- @param port table as receuved by the action method
@@ -290,9 +290,9 @@ Comm = {
}
setmetatable(o, self)
self.__index = self
return o
return o
end,
-- Connects to the NDMP server
-- @return status true on success, false on failure
connect = function(self)
@@ -300,11 +300,11 @@ Comm = {
self.socket:set_timeout(10000)
return self.socket:connect(self.host, self.port)
end,
-- Receives a message from the server
-- @return status true on success, false on failure
-- @return msg NDMP message when a parser exists, otherwise nil
sock_recv = function(self)
sock_recv = function(self)
local status, frag_data = self.socket:receive_buf(match.numbytes(4), true)
if ( not(status) ) then
return false, "Failed to read NDMP 4-byte fragment header"
@@ -321,20 +321,20 @@ Comm = {
if ( not(status) ) then
return false, "Failed to read NDMP data"
end
if ( NDMP.TypeToMessage[header.msg] ) then
return true, NDMP.TypeToMessage[header.msg].parse(frag_data .. header_data .. data)
end
return true, NDMP.Message.UnhandledMessage.parse(frag_data .. header_data .. data)
end,
recv = function(self)
if ( #self.in_queue > 0 ) then
return true, table.remove(self.in_queue, 1)
end
return self:sock_recv()
end,
-- Sends a message to the server
-- @param msg NDMP message
-- @return status true on success, false on failure
@@ -344,8 +344,8 @@ Comm = {
msg.header.seq = self.seq
return self.socket:send(tostring(msg))
end,
exch = function(self, msg)
local status, err = self:send(msg)
if ( not(status) ) then
@@ -363,50 +363,50 @@ Comm = {
local reply
status, reply = self:sock_recv()
if ( not(status) ) then
return false, "Failed to receive msg from server"
return false, "Failed to receive msg from server"
elseif ( reply and reply.header and reply.header.reply_seq == s_seq ) then
return true, reply
else
table.insert(self.in_queue, reply)
end
end
end
end,
close = function(self) return self.socket:close() end,
}
Helper = {
new = function(self, host, port)
local o = { comm = Comm:new(host, port) }
setmetatable(o, self)
self.__index = self
return o
return o
end,
connect = function(self)
return self.comm:connect()
end,
getFsInfo = function(self)
return self.comm:exch(NDMP.Message.ConfigGetFsInfo:new())
end,
getHostInfo = function(self)
return self.comm:exch(NDMP.Message.ConfigGetHostInfo:new())
end,
getServerInfo = function(self)
return self.comm:exch(NDMP.Message.ConfigGetServerInfo:new())
end,
close = function(self)
return self.comm:close()
end
}
return _ENV;