OpenVAS Scanner 23.32.3
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
13
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
33
34#ifndef TIME_T_MIN
35#define TIME_T_MIN \
36 ((time_t) 0 < (time_t) - 1 \
37 ? (time_t) 0 \
38 : ~(time_t) 0 << (sizeof (time_t) * CHAR_BIT - 1))
39#endif
40#ifndef TIME_T_MAX
41#define TIME_T_MAX LONG_MAX
42#endif
43
44#define NTTIME_INFINITY (NTTIME) 0x8000000000000000LL
45
46#define TIME_FIXUP_CONSTANT_INT 11644473600LL
47
48/****************************************************************************
49 * Put a 8 byte filetime from a struct timespec. Uses GMT.
50 * ****************************************************************************/
51
52static void
54{
55 uint64_t d;
56
57 if (ts.tv_sec == 0 && ts.tv_nsec == 0)
58 {
59 *nt = 0;
60 return;
61 }
62 if (ts.tv_sec == TIME_T_MAX)
63 {
64 *nt = 0x7fffffffffffffffLL;
65 return;
66 }
67 if (ts.tv_sec == (time_t) -1)
68 {
69 *nt = (uint64_t) -1;
70 return;
71 }
72
73 d = ts.tv_sec;
74 d += (uint64_t) TIME_FIXUP_CONSTANT_INT;
75 d *= 1000 * 1000 * 10;
76 /* d is now in 100ns units. */
77 d += (ts.tv_nsec / 100);
78
79 *nt = d;
80}
81
82/****************************************************************************
83 * Convert a normalized timespec to a timeval.
84 * ****************************************************************************/
85
86/***************************************************************************
87 A gettimeofday wrapper.
88****************************************************************************/
89
90void
92{
93 gettimeofday (tval, NULL);
94}
95
96/****************************************************************************
97 Take a Unix time and convert to an NTTIME structure and place in buffer
98 pointed to by p.
99****************************************************************************/
100
101static void
102put_long_date_timespec_ntlmssp (char *p, struct timespec ts)
103{
104 NTTIME nt;
106 SIVAL (p, 0, nt & 0xFFFFFFFF);
107 SIVAL (p, 4, nt >> 32);
108}
109
110void
111put_long_date_ntlmssp (char *p, time_t t)
112{
113 struct timespec ts;
114 ts.tv_sec = t;
115 ts.tv_nsec = 0;
117}
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:41
void GetTimeOfDay_ntlmssp(struct timeval *tval)
Definition time.c:91
static void put_long_date_timespec_ntlmssp(char *p, struct timespec ts)
Definition time.c:102
void put_long_date_ntlmssp(char *p, time_t t)
Definition time.c:111
#define TIME_FIXUP_CONSTANT_INT
Definition time.c:46
static void unix_timespec_to_nt_time_ntlmssp(NTTIME *nt, struct timespec ts)
Definition time.c:53