OpenVAS Scanner 22.7.9
time.c
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Greenbone AG
2 * SPDX-FileCopyrightText: 2007 Jeremy Allison
3 * SPDX-FileCopyrightText: 2002 Stefan (metze) Metzmacher
4 * SPDX-FileCopyrightText: 1992-2004 Andrew Tridgell
5 *
6 * SPDX-License-Identifier: GPL-2.0-or-later
7 */
8
14/*MODIFICATION: minor changes for OpenVAS*/
15
16#include "byteorder.h"
17#include "proto.h"
18#include "smb.h"
19
20#include <limits.h>
21#include <sys/time.h>
22#include <time.h>
23#include <utime.h>
24
25#ifndef uint32
26#define uint32 uint32_t
27#endif
28
34#ifndef TIME_T_MIN
35#define TIME_T_MIN \
36 ((time_t) 0 < (time_t) -1 ? (time_t) 0 \
37 : ~(time_t) 0 << (sizeof (time_t) * CHAR_BIT - 1))
38#endif
39#ifndef TIME_T_MAX
40#define TIME_T_MAX LONG_MAX
41#endif
42
43#define NTTIME_INFINITY (NTTIME) 0x8000000000000000LL
44
45#define TIME_FIXUP_CONSTANT_INT 11644473600LL
46
47/****************************************************************************
48 * Put a 8 byte filetime from a struct timespec. Uses GMT.
49 * ****************************************************************************/
50
51static void
53{
54 uint64_t d;
55
56 if (ts.tv_sec == 0 && ts.tv_nsec == 0)
57 {
58 *nt = 0;
59 return;
60 }
61 if (ts.tv_sec == TIME_T_MAX)
62 {
63 *nt = 0x7fffffffffffffffLL;
64 return;
65 }
66 if (ts.tv_sec == (time_t) -1)
67 {
68 *nt = (uint64_t) -1;
69 return;
70 }
71
72 d = ts.tv_sec;
73 d += (uint64_t) TIME_FIXUP_CONSTANT_INT;
74 d *= 1000 * 1000 * 10;
75 /* d is now in 100ns units. */
76 d += (ts.tv_nsec / 100);
77
78 *nt = d;
79}
80
81/****************************************************************************
82 * Convert a normalized timespec to a timeval.
83 * ****************************************************************************/
84
85/***************************************************************************
86 A gettimeofday wrapper.
87****************************************************************************/
88
89void
91{
92 gettimeofday (tval, NULL);
93}
94
95/****************************************************************************
96 Take a Unix time and convert to an NTTIME structure and place in buffer
97 pointed to by p.
98****************************************************************************/
99
100static void
101put_long_date_timespec_ntlmssp (char *p, struct timespec ts)
102{
103 NTTIME nt;
105 SIVAL (p, 0, nt & 0xFFFFFFFF);
106 SIVAL (p, 4, nt >> 32);
107}
108
109void
110put_long_date_ntlmssp (char *p, time_t t)
111{
112 struct timespec ts;
113 ts.tv_sec = t;
114 ts.tv_nsec = 0;
116}
Unix SMB/CIFS implementation. SMB Byte handling.
#define SIVAL(buf, pos, val)
Definition: byteorder.h:117
static struct timeval timeval(unsigned long val)
Unix SMB/CIFS implementation.
uint64_t NTTIME
Definition: smb.h:170
#define TIME_T_MAX
Definition: time.c:40
void GetTimeOfDay_ntlmssp(struct timeval *tval)
Definition: time.c:90
static void put_long_date_timespec_ntlmssp(char *p, struct timespec ts)
Definition: time.c:101
void put_long_date_ntlmssp(char *p, time_t t)
Definition: time.c:110
#define TIME_FIXUP_CONSTANT_INT
Definition: time.c:45
static void unix_timespec_to_nt_time_ntlmssp(NTTIME *nt, struct timespec ts)
Definition: time.c:52