mirror of
https://github.com/nmap/nmap.git
synced 2025-12-06 04:31:29 +00:00
Handle large dates on platforms that can't. Fixes #1303
This commit is contained in:
@@ -130,7 +130,6 @@ local math = require "math"
|
||||
local match = require "match"
|
||||
local netbios = require "netbios"
|
||||
local nmap = require "nmap"
|
||||
local os = require "os"
|
||||
local smbauth = require "smbauth"
|
||||
local stdnse = require "stdnse"
|
||||
local string = require "string"
|
||||
@@ -1050,7 +1049,7 @@ function negotiate_v1(smb, overrides)
|
||||
|
||||
-- Convert the time and timezone to more useful values
|
||||
smb['time'] = (smb['time'] // 10000000) - 11644473600
|
||||
smb['date'] = os.date("%Y-%m-%d %H:%M:%S", smb['time'])
|
||||
smb['date'] = stdnse.format_timestamp(smb['time'])
|
||||
smb['timezone'] = -(smb['timezone'] / 60)
|
||||
if(smb['timezone'] == 0) then
|
||||
smb['timezone_str'] = "UTC+0"
|
||||
@@ -2862,7 +2861,7 @@ function find_files(smbstate, fname, options)
|
||||
|
||||
local time = fe.created
|
||||
time = (time // 10000000) - 11644473600
|
||||
fe.created = os.date("%Y-%m-%d %H:%M:%S", time)
|
||||
fe.created = stdnse.format_timestamp(time)
|
||||
|
||||
-- TODO: cleanup fe.s_fname
|
||||
pos, fe.fname = bin.unpack("A" .. f_len, response.data, pos)
|
||||
|
||||
@@ -16,7 +16,6 @@ local stdnse = require "stdnse"
|
||||
local nmap = require "nmap"
|
||||
local table = require "table"
|
||||
local match = require "match"
|
||||
local os = require "os"
|
||||
|
||||
_ENV = stdnse.module("smb2", stdnse.seeall)
|
||||
|
||||
@@ -389,12 +388,12 @@ function negotiate_v2(smb, overrides)
|
||||
|
||||
-- Convert the time and timezone to human readable values (taken from smb.lua)
|
||||
smb['time'] = (smb['time'] // 10000000) - 11644473600
|
||||
smb['date'] = os.date("%Y-%m-%d %H:%M:%S", smb['time'])
|
||||
smb['date'] = stdnse.format_timestamp(smb['time'])
|
||||
|
||||
-- Samba does not report the boot time
|
||||
if smb['start_time'] ~= 0 then
|
||||
smb['start_time'] = (smb['start_time'] // 10000000) - 11644473600
|
||||
smb['start_date'] = os.date("%Y-%m-%d %H:%M:%S", smb['start_time'])
|
||||
smb['start_date'] = stdnse.format_timestamp(smb['start_time'])
|
||||
else
|
||||
smb['start_date'] = "N/A"
|
||||
end
|
||||
|
||||
@@ -27,6 +27,7 @@ local tonumber = tonumber;
|
||||
local tostring = tostring;
|
||||
local print = print;
|
||||
local type = type
|
||||
local pcall = pcall
|
||||
|
||||
local ceil = math.ceil
|
||||
local floor = math.floor
|
||||
@@ -578,7 +579,25 @@ function format_timestamp(t, offset)
|
||||
else
|
||||
local tz_string = format_tz(offset)
|
||||
offset = offset or 0
|
||||
return date("!%Y-%m-%dT%H:%M:%S", floor(t + offset)) .. tz_string
|
||||
local status, result = pcall(date, "!%Y-%m-%dT%H:%M:%S", floor(t + offset))
|
||||
if not status then
|
||||
local tmp = floor(t + offset)
|
||||
if tmp > 0xffffffff then
|
||||
-- Maybe too far in the future?
|
||||
local seconds_in_year = 31556926
|
||||
local extra_years = (tmp - 0xffffffff) // seconds_in_year + 1
|
||||
tmp = tmp - extra_years * seconds_in_year
|
||||
status, result = pcall(date, "!*t", tmp)
|
||||
if status then
|
||||
-- seconds_in_year is imprecise, so we truncate to date only
|
||||
result = format("%d-%02d-%02d", result.year + extra_years, result.month, result.day)
|
||||
end
|
||||
end
|
||||
end
|
||||
if not status then
|
||||
return ("Invalid timestamp: %s"):format(t)
|
||||
end
|
||||
return result .. tz_string
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user