Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
James Lowden
OpenLDAP
Commits
94fbd968
Commit
94fbd968
authored
Mar 23, 2021
by
Howard Chu
Committed by
Quanah Gibson-Mount
Mar 31, 2021
Browse files
ITS#9513 Change all lutil time structs to use nanoseconds
Instead of microseconds
parent
9ac3909e
Changes
10
Hide whitespace changes
Inline
Side-by-side
configure.ac
View file @
94fbd968
...
...
@@ -2371,6 +2371,7 @@ fi
AC_CHECK_FUNCS( \
bcopy \
clock_gettime \
closesocket \
chroot \
endgrent \
...
...
contrib/slapd-modules/smbk5pwd/smbk5pwd.c
View file @
94fbd968
...
...
@@ -289,7 +289,7 @@ static int k5key_chk(
struct
lutil_tm
tm
;
struct
lutil_timet
tt
;
if
(
lutil_parsetime
(
a
->
a_vals
[
0
].
bv_val
,
&
tm
)
==
0
&&
lutil_tm2time
(
&
tm
,
&
tt
)
==
0
&&
tt
.
tt_
u
sec
<
op
->
o_time
)
{
lutil_tm2time
(
&
tm
,
&
tt
)
==
0
&&
tt
.
tt_sec
<
op
->
o_time
)
{
/* Account is expired */
rc
=
LUTIL_PASSWD_ERR
;
break
;
...
...
include/ac/time.h
View file @
94fbd968
...
...
@@ -29,4 +29,11 @@
# include <time.h>
#endif
#if defined(_WIN32) && !defined(HAVE_CLOCK_GETTIME)
struct
timespec
{
time_t
tv_sec
;
int
tv_nsec
;
};
#endif
#endif
/* _AC_TIME_H */
include/ldap_pvt.h
View file @
94fbd968
...
...
@@ -131,6 +131,13 @@ ldap_pvt_gettime LDAP_P(( struct lutil_tm * ));
struct
timeval
;
LDAP_F
(
int
)
ldap_pvt_gettimeofday
LDAP_P
((
struct
timeval
*
tv
,
void
*
unused
));
#ifndef CLOCK_REALTIME
#define CLOCK_REALTIME 0
#endif
#define clock_gettime(clkid,tv) ldap_pvt_clock_gettime(clkid,tv)
struct
timespec
;
LDAP_F
(
int
)
ldap_pvt_clock_gettime
LDAP_P
((
int
clkid
,
struct
timespec
*
tv
));
#endif
/* use this macro to allocate buffer for ldap_pvt_csnstr */
...
...
include/lutil.h
View file @
94fbd968
...
...
@@ -172,7 +172,7 @@ typedef struct lutil_tm {
int
tm_mday
;
/* day 1-31 */
int
tm_mon
;
/* month 0-11 */
int
tm_year
;
/* year - 1900 */
int
tm_
u
sec
;
/*
micr
oseconds */
int
tm_
n
sec
;
/*
nan
oseconds */
int
tm_usub
;
/* submicro */
}
lutil_tm
;
...
...
@@ -180,7 +180,7 @@ typedef struct lutil_timet {
unsigned
int
tt_sec
;
/* seconds since epoch, 0000 or 1970 */
int
tt_gsec
;
/* seconds since epoch, high 7 bits, maybe sign-flipped */
/* sign flipped to sort properly as unsigned ints */
unsigned
int
tt_
u
sec
;
/*
micr
oseconds */
unsigned
int
tt_
n
sec
;
/*
nan
oseconds */
}
lutil_timet
;
/* Parse a timestamp string into a structure */
...
...
libraries/libldap/util-int.c
View file @
94fbd968
...
...
@@ -178,7 +178,7 @@ static int _ldap_pvt_gt_subs;
#ifdef _WIN32
/* Windows SYSTEMTIME only has 10 millisecond resolution, so we
* also need to use a high resolution timer to get
micr
oseconds.
* also need to use a high resolution timer to get
nan
oseconds.
* This is pretty clunky.
*/
static
LARGE_INTEGER
_ldap_pvt_gt_freq
;
...
...
@@ -187,9 +187,10 @@ static int _ldap_pvt_gt_offset;
#define SEC_TO_UNIX_EPOCH 11644473600LL
#define TICKS_PER_SECOND 10000000
#define BILLION 1000000000L
static
int
ldap_pvt_gettime
u
sec
(
int
*
sec
)
ldap_pvt_gettime
n
sec
(
int
*
sec
)
{
LARGE_INTEGER
count
;
...
...
@@ -200,7 +201,7 @@ ldap_pvt_gettimeusec(int *sec)
*/
LDAP_MUTEX_LOCK
(
&
ldap_int_gettime_mutex
);
/* We assume Windows has at least a vague idea of
* when a second begins. So we align our
micr
osecond count
* when a second begins. So we align our
nan
osecond count
* with the Windows millisecond count using this offset.
* We retain the submillisecond portion of our own count.
*
...
...
@@ -214,7 +215,7 @@ ldap_pvt_gettimeusec(int *sec)
ULARGE_INTEGER
ut
;
FILETIME
ft0
,
ft1
;
long
long
t
;
int
u
sec
;
int
n
sec
;
/* Initialize our offset */
QueryPerformanceFrequency
(
&
_ldap_pvt_gt_freq
);
...
...
@@ -232,13 +233,13 @@ ldap_pvt_gettimeusec(int *sec)
/* get second and fraction portion of counter */
t
=
c2
.
QuadPart
%
(
_ldap_pvt_gt_freq
.
QuadPart
*
10
);
/* convert to
micr
oseconds */
t
*=
1000000
;
u
sec
=
t
/
_ldap_pvt_gt_freq
.
QuadPart
;
/* convert to
nan
oseconds */
t
*=
BILLION
;
n
sec
=
t
/
_ldap_pvt_gt_freq
.
QuadPart
;
ut
.
QuadPart
/=
10
;
ut
.
QuadPart
%=
10
000000
;
_ldap_pvt_gt_offset
=
u
sec
-
ut
.
QuadPart
;
ut
.
QuadPart
%=
(
10
*
BILLION
)
;
_ldap_pvt_gt_offset
=
n
sec
-
ut
.
QuadPart
;
count
=
c2
;
}
if
(
count
.
QuadPart
<=
_ldap_pvt_gt_prev
.
QuadPart
)
{
...
...
@@ -249,28 +250,28 @@ ldap_pvt_gettimeusec(int *sec)
}
LDAP_MUTEX_UNLOCK
(
&
ldap_int_gettime_mutex
);
/* convert to
micr
oseconds */
/* convert to
nan
oseconds */
count
.
QuadPart
%=
_ldap_pvt_gt_freq
.
QuadPart
*
10
;
count
.
QuadPart
*=
1000000
;
count
.
QuadPart
*=
BILLION
;
count
.
QuadPart
/=
_ldap_pvt_gt_freq
.
QuadPart
;
count
.
QuadPart
-=
_ldap_pvt_gt_offset
;
/* We've extracted the 1s and
micr
oseconds.
* The 1sec digit is used to detect wraparound in
micr
osecnds.
/* We've extracted the 1s and
nan
oseconds.
* The 1sec digit is used to detect wraparound in
nan
osecnds.
*/
if
(
count
.
QuadPart
<
0
)
count
.
QuadPart
+=
10
000000
;
else
if
(
count
.
QuadPart
>=
10
000000
)
count
.
QuadPart
-=
10
000000
;
count
.
QuadPart
+=
(
10
*
BILLION
)
;
else
if
(
count
.
QuadPart
>=
(
10
*
BILLION
)
)
count
.
QuadPart
-=
(
10
*
BILLION
)
;
*
sec
=
count
.
QuadPart
/
1000000
;
return
count
.
QuadPart
%
1000000
;
*
sec
=
count
.
QuadPart
/
BILLION
;
return
count
.
QuadPart
%
BILLION
;
}
/* emulate POSIX gettime
ofday
*/
/* emulate POSIX
clock_
gettime */
int
ldap_pvt_gettime
ofday
(
struct
timeval
*
tv
,
void
*
unused
)
ldap_pvt_
clock_
gettime
(
int
clk_id
,
struct
timespec
*
tv
)
{
FILETIME
ft
;
ULARGE_INTEGER
ut
;
...
...
@@ -280,11 +281,11 @@ ldap_pvt_gettimeofday( struct timeval *tv, void *unused )
ut
.
LowPart
=
ft
.
dwLowDateTime
;
ut
.
HighPart
=
ft
.
dwHighDateTime
;
/* convert to
u
sec */
ut
.
QuadPart
/=
(
TICKS_PER_SECOND
/
1000000
)
;
/* convert to sec */
ut
.
QuadPart
/=
TICKS_PER_SECOND
;
tv
->
tv_
u
sec
=
ldap_pvt_gettime
u
sec
(
&
sec
);
tv
->
tv_sec
=
ut
.
QuadPart
/
1000000
-
SEC_TO_UNIX_EPOCH
;
tv
->
tv_
n
sec
=
ldap_pvt_gettime
n
sec
(
&
sec
);
tv
->
tv_sec
=
ut
.
QuadPart
-
SEC_TO_UNIX_EPOCH
;
/* check for carry from microseconds */
sec0
=
tv
->
tv_sec
%
10
;
...
...
@@ -294,7 +295,20 @@ ldap_pvt_gettimeofday( struct timeval *tv, void *unused )
return
0
;
}
/* return a broken out time, with microseconds
/* emulate POSIX gettimeofday */
int
ldap_pvt_gettimeofday
(
struct
timeval
*
tv
,
void
*
unused
)
int
{
struct
timespec
ts
;
ldap_pvt_clock_gettime
(
0
,
&
ts
);
tv
->
tv_sec
=
ts
.
tv_spec
;
tv
->
tv_usec
=
ts
.
tv_nsec
/
1000
;
return
0
;
}
/* return a broken out time, with nanoseconds
*/
void
ldap_pvt_gettime
(
struct
lutil_tm
*
tm
)
...
...
@@ -305,10 +319,10 @@ ldap_pvt_gettime( struct lutil_tm *tm )
31
,
28
,
31
,
30
,
31
,
30
,
31
,
31
,
30
,
31
,
30
,
31
};
GetSystemTime
(
&
st
);
tm
->
tm_
u
sec
=
ldap_pvt_gettime
u
sec
(
&
sec
);
tm
->
tm_
n
sec
=
ldap_pvt_gettime
n
sec
(
&
sec
);
tm
->
tm_usub
=
_ldap_pvt_gt_subs
;
/* any difference larger than
micr
oseconds is
/* any difference larger than
nan
oseconds is
* already reflected in st
*/
tm
->
tm_sec
=
st
.
wSecond
;
...
...
@@ -318,7 +332,7 @@ ldap_pvt_gettime( struct lutil_tm *tm )
tm
->
tm_mon
=
st
.
wMonth
-
1
;
tm
->
tm_year
=
st
.
wYear
-
1900
;
/* check for carry from
micr
oseconds */
/* check for carry from
nan
oseconds */
sec0
=
tm
->
tm_sec
%
10
;
if
(
sec0
<
sec
||
(
sec0
==
9
&&
!
sec
))
{
tm
->
tm_sec
++
;
...
...
@@ -357,23 +371,36 @@ ldap_pvt_gettime( struct lutil_tm *tm )
}
#else
#ifdef HAVE_CLOCK_GETTIME
static
struct
timespec
_ldap_pvt_gt_prevTv
;
#else
static
struct
timeval
_ldap_pvt_gt_prevTv
;
#endif
void
ldap_pvt_gettime
(
struct
lutil_tm
*
ltm
)
{
struct
timeval
tv
;
struct
tm
tm
;
time_t
t
;
#ifdef HAVE_CLOCK_GETTIME
#define FRAC tv_nsec
#define NSECS(x) x
struct
timespec
tv
;
clock_gettime
(
CLOCK_REALTIME
,
&
tv
);
#else
#define FRAC tv_usec
#define NSECS(x) x * 1000
struct
timeval
tv
;
gettimeofday
(
&
tv
,
NULL
);
#endif
t
=
tv
.
tv_sec
;
LDAP_MUTEX_LOCK
(
&
ldap_int_gettime_mutex
);
if
(
tv
.
tv_sec
<
_ldap_pvt_gt_prevTv
.
tv_sec
||
(
tv
.
tv_sec
==
_ldap_pvt_gt_prevTv
.
tv_sec
&&
tv
.
tv_usec
<=
_ldap_pvt_gt_prevTv
.
tv_usec
))
{
&&
tv
.
FRAC
<=
_ldap_pvt_gt_prevTv
.
FRAC
))
{
_ldap_pvt_gt_subs
++
;
}
else
{
_ldap_pvt_gt_subs
=
0
;
...
...
@@ -391,7 +418,7 @@ ldap_pvt_gettime( struct lutil_tm *ltm )
ltm
->
tm_mday
=
tm
.
tm_mday
;
ltm
->
tm_mon
=
tm
.
tm_mon
;
ltm
->
tm_year
=
tm
.
tm_year
;
ltm
->
tm_
u
sec
=
tv
.
tv_usec
;
ltm
->
tm_
n
sec
=
NSECS
(
tv
.
FRAC
)
;
}
#endif
...
...
@@ -406,7 +433,7 @@ ldap_pvt_csnstr(char *buf, size_t len, unsigned int replica, unsigned int mod)
n
=
snprintf
(
buf
,
len
,
"%4d%02d%02d%02d%02d%02d.%06dZ#%06x#%03x#%06x"
,
tm
.
tm_year
+
1900
,
tm
.
tm_mon
+
1
,
tm
.
tm_mday
,
tm
.
tm_hour
,
tm
.
tm_min
,
tm
.
tm_sec
,
tm
.
tm_
u
sec
,
tm
.
tm_usub
,
replica
,
mod
);
tm
.
tm_min
,
tm
.
tm_sec
,
tm
.
tm_
n
sec
/
1000
,
tm
.
tm_usub
,
replica
,
mod
);
if
(
n
<
0
)
return
0
;
return
(
(
size_t
)
n
<
len
)
?
n
:
0
;
...
...
libraries/liblutil/utils.c
View file @
94fbd968
...
...
@@ -159,7 +159,7 @@ int lutil_tm2time( struct lutil_tm *tm, struct lutil_timet *tt )
273
,
304
,
334
};
int
sec
;
tt
->
tt_
u
sec
=
tm
->
tm_
u
sec
;
tt
->
tt_
n
sec
=
tm
->
tm_
n
sec
;
/* special case 0000/01/01+00:00:00 is returned as zero */
if
(
tm
->
tm_year
==
-
1900
&&
tm
->
tm_mon
==
0
&&
tm
->
tm_mday
==
1
&&
...
...
@@ -226,7 +226,7 @@ int lutil_tm2gtime( struct lutil_tm *tm, struct lutil_timet *tt )
int
sec
,
year
;
long
tmp
;
tt
->
tt_
u
sec
=
tm
->
tm_
u
sec
;
tt
->
tt_
n
sec
=
tm
->
tm_
n
sec
;
/* tm->tm_year is years since 1900 */
/* calculate days from 0000 */
...
...
@@ -350,13 +350,13 @@ int lutil_parsetime( char *atm, struct lutil_tm *tm )
i
*=
10
;
i
+=
*
ptr
++
-
'0'
;
fracs
++
;
}
tm
->
tm_
u
sec
=
i
;
tm
->
tm_
n
sec
=
i
;
if
(
i
)
{
for
(
i
=
fracs
;
i
<
6
;
i
++
)
tm
->
tm_
u
sec
*=
10
;
for
(
i
=
fracs
;
i
<
9
;
i
++
)
tm
->
tm_
n
sec
*=
10
;
}
}
else
{
tm
->
tm_
u
sec
=
0
;
tm
->
tm_
n
sec
=
0
;
}
tm
->
tm_usub
=
0
;
...
...
servers/slapd/main.c
View file @
94fbd968
...
...
@@ -382,12 +382,21 @@ static BER_logger *ber_logger;
static
void
debug_print
(
const
char
*
data
)
{
char
buf
[
4136
];
/* 4096 + 40 */
#ifdef HAVE_CLOCK_GETTIME
struct
timespec
tv
;
#define TS "%08x"
#define Tfrac tv.tv_nsec
clock_gettime
(
CLOCK_REALTIME
,
&
tv
);
#else
struct
timeval
tv
;
#define TS "%05x"
#define Tfrac tv.tv_usec
gettimeofday
(
&
tv
,
NULL
);
#endif
buf
[
sizeof
(
buf
)
-
1
]
=
'\0'
;
snprintf
(
buf
,
sizeof
(
buf
)
-
1
,
"%lx.
%05x
%p %s"
,
(
long
)
tv
.
tv_sec
,
tv
.
tv_use
c
,
(
void
*
)
ldap_pvt_thread_self
(),
data
);
snprintf
(
buf
,
sizeof
(
buf
)
-
1
,
"%lx.
"
TS
"
%p %s"
,
(
long
)
tv
.
tv_sec
,
Tfra
c
,
(
void
*
)
ldap_pvt_thread_self
(),
data
);
ber_logger
(
buf
);
}
...
...
servers/slapd/overlays/ppolicy.c
View file @
94fbd968
...
...
@@ -1500,7 +1500,7 @@ ppolicy_bind_response( Operation *op, SlapReply *rs )
strcpy
(
nowstr_usec
,
nowstr
);
timestamp_usec
.
bv_val
=
nowstr_usec
;
timestamp_usec
.
bv_len
=
timestamp
.
bv_len
;
snprintf
(
timestamp_usec
.
bv_val
+
timestamp_usec
.
bv_len
-
1
,
sizeof
(
".123456Z"
),
".%06dZ"
,
now_usec
.
tt_
u
sec
);
snprintf
(
timestamp_usec
.
bv_val
+
timestamp_usec
.
bv_len
-
1
,
sizeof
(
".123456Z"
),
".%06dZ"
,
now_usec
.
tt_
n
sec
/
1000
);
timestamp_usec
.
bv_len
+=
STRLENOF
(
".123456"
);
if
(
rs
->
sr_err
==
LDAP_INVALID_CREDENTIALS
&&
ppb
->
pp
.
pwdMaxRecordedFailure
)
{
...
...
tests/progs/slapd-watcher.c
View file @
94fbd968
...
...
@@ -425,7 +425,7 @@ void get_csns(
if
(
j
<
numservers
)
{
ber_bvreplace
(
&
c
->
vals
[
j
],
&
bvs
[
i
]
);
lutil_parsetime
(
bvs
[
i
].
bv_val
,
&
tm
);
c
->
tvs
[
j
].
tv_usec
=
tm
.
tm_
u
sec
;
c
->
tvs
[
j
].
tv_usec
=
tm
.
tm_
n
sec
/
1000
;
lutil_tm2time
(
&
tm
,
&
tt
);
c
->
tvs
[
j
].
tv_sec
=
tt
.
tt_sec
;
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment