From ca58ae9562cf48c4b74968ece554cc318eb20059 Mon Sep 17 00:00:00 2001 From: nnposter Date: Mon, 10 Aug 2020 01:48:19 +0000 Subject: [PATCH] Centralize AFP timestamp conversion to string --- nselib/afp.lua | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/nselib/afp.lua b/nselib/afp.lua index 7404ec4a2..c6e25f58e 100644 --- a/nselib/afp.lua +++ b/nselib/afp.lua @@ -350,6 +350,8 @@ local ERROR_MSG = { [ERROR.FPCallNotSupported] = "Server does not support this command.", } +local TIME_OFFSET = os.time{year=2000, month=1, day=1, hour=0} - os.time{year=1970, month=1, day=1, hour=0} + -- Check if all the bits in flag are set in bitmap. local function flag_is_set(bitmap, flag) return (bitmap & flag) == flag @@ -1761,10 +1763,9 @@ Helper = { local item = response.result.file or response.result.dir - local diff = os.time{year=2000, month=1, day=1, hour=0} - os.time{year=1970, month=1, day=1, hour=0} - local create = datetime.format_timestamp(item.CreationDate + diff) - local backup = datetime.format_timestamp(item.BackupDate ) - local modify = datetime.format_timestamp(item.ModificationDate + diff ) + local create = Util.time_to_string(item.CreationDate) + local backup = Util.time_to_string(item.BackupDate) + local modify = Util.time_to_string(item.ModificationDate) return true, { create = create, backup = backup, modify = modify } end, @@ -1892,6 +1893,15 @@ Util = end, + --- Converts AFP file timestamp to a standard text format + -- + -- @param timestamp value returned by FPEnumerateExt2 or FPGetFileDirParms + -- @return string representing the timestamp + time_to_string = function (timestamp) + return timestamp and datetime.format_timestamp(timestamp + TIME_OFFSET) or nil + end, + + --- Decodes the UnixPrivileges.ua_permissions value -- -- @param privs number containing the UnixPrivileges.ua_permissions value