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