OpenVAS Scanner  7.0.0~git
time.c
Go to the documentation of this file.
1 /* Copyright (C) Andrew Tridgell 1992-2004
2  * Copyright (C) Stefan (metze) Metzmacher 2002
3  * Copyright (C) Jeremy Allison 2007
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21 
27 /*MODIFICATION: minor changes for OpenVAS*/
28 
29 #include "byteorder.h"
30 #include "smb.h"
31 
32 #include <limits.h>
33 #include <sys/time.h>
34 #include <time.h>
35 #include <utime.h>
36 
37 #ifndef uint32
38 #define uint32 uint32_t
39 #endif
40 
46 #ifndef TIME_T_MIN
47 #define TIME_T_MIN \
48  ((time_t) 0 < (time_t) -1 ? (time_t) 0 \
49  : ~(time_t) 0 << (sizeof (time_t) * CHAR_BIT - 1))
50 #endif
51 #ifndef TIME_T_MAX
52 #define TIME_T_MAX LONG_MAX
53 #endif
54 
55 #define NTTIME_INFINITY (NTTIME) 0x8000000000000000LL
56 
57 #define TIME_FIXUP_CONSTANT_INT 11644473600LL
58 
59 /****************************************************************************
60  * Put a 8 byte filetime from a struct timespec. Uses GMT.
61  * ****************************************************************************/
62 
63 void
64 unix_timespec_to_nt_time_ntlmssp (NTTIME *nt, struct timespec ts)
65 {
66  uint64_t d;
67 
68  if (ts.tv_sec == 0 && ts.tv_nsec == 0)
69  {
70  *nt = 0;
71  return;
72  }
73  if (ts.tv_sec == TIME_T_MAX)
74  {
75  *nt = 0x7fffffffffffffffLL;
76  return;
77  }
78  if (ts.tv_sec == (time_t) -1)
79  {
80  *nt = (uint64_t) -1;
81  return;
82  }
83 
84  d = ts.tv_sec;
85  d += (uint64_t) TIME_FIXUP_CONSTANT_INT;
86  d *= 1000 * 1000 * 10;
87  /* d is now in 100ns units. */
88  d += (ts.tv_nsec / 100);
89 
90  *nt = d;
91 }
92 
93 /****************************************************************************
94  * Convert a normalized timespec to a timeval.
95  * ****************************************************************************/
96 
97 /***************************************************************************
98  A gettimeofday wrapper.
99 ****************************************************************************/
100 
101 void
103 {
104  gettimeofday (tval, NULL);
105 }
106 
107 /****************************************************************************
108  Take a Unix time and convert to an NTTIME structure and place in buffer
109  pointed to by p.
110 ****************************************************************************/
111 
112 void
113 put_long_date_timespec_ntlmssp (char *p, struct timespec ts)
114 {
115  NTTIME nt;
117  SIVAL (p, 0, nt & 0xFFFFFFFF);
118  SIVAL (p, 4, nt >> 32);
119 }
120 
121 void
122 put_long_date_ntlmssp (char *p, time_t t)
123 {
124  struct timespec ts;
125  ts.tv_sec = t;
126  ts.tv_nsec = 0;
128 }
GetTimeOfDay_ntlmssp
void GetTimeOfDay_ntlmssp(struct timeval *tval)
Definition: time.c:102
put_long_date_timespec_ntlmssp
void put_long_date_timespec_ntlmssp(char *p, struct timespec ts)
Definition: time.c:113
byteorder.h
Unix SMB/CIFS implementation. SMB Byte handling.
unix_timespec_to_nt_time_ntlmssp
void unix_timespec_to_nt_time_ntlmssp(NTTIME *nt, struct timespec ts)
Definition: time.c:64
timeval
struct timeval timeval(unsigned long val)
Definition: nasl_builtin_synscan.c:105
SIVAL
#define SIVAL(buf, pos, val)
Definition: byteorder.h:130
smb.h
Unix SMB/CIFS implementation.
put_long_date_ntlmssp
void put_long_date_ntlmssp(char *p, time_t t)
Definition: time.c:122
NTTIME
uint64_t NTTIME
Definition: smb.h:183
TIME_T_MAX
#define TIME_T_MAX
Definition: time.c:52
TIME_FIXUP_CONSTANT_INT
#define TIME_FIXUP_CONSTANT_INT
Definition: time.c:57