mirror of
https://git.openldap.org/openldap/openldap.git
synced 2025-12-20 22:59:34 -05:00
wrap gmtime for reentrancy (ITS#6262)
This commit is contained in:
parent
959fd98408
commit
f3cdcadf89
26 changed files with 296 additions and 368 deletions
|
|
@ -1859,6 +1859,7 @@ dnl ----------------------------------------------------------------
|
||||||
dnl Tests for reentrant functions necessary to build -lldap_r
|
dnl Tests for reentrant functions necessary to build -lldap_r
|
||||||
AC_CHECK_FUNCS( \
|
AC_CHECK_FUNCS( \
|
||||||
ctime_r \
|
ctime_r \
|
||||||
|
gmtime_r localtime_r \
|
||||||
gethostbyname_r gethostbyaddr_r \
|
gethostbyname_r gethostbyaddr_r \
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -367,7 +367,7 @@ best_guess( Operation *op,
|
||||||
struct berval *bv_modifiersName, struct berval *bv_nmodifiersName )
|
struct berval *bv_modifiersName, struct berval *bv_nmodifiersName )
|
||||||
{
|
{
|
||||||
if ( bv_entryCSN ) {
|
if ( bv_entryCSN ) {
|
||||||
char csnbuf[ LDAP_LUTIL_CSNSTR_BUFSIZE ];
|
char csnbuf[ LDAP_PVT_CSNSTR_BUFSIZE ];
|
||||||
struct berval entryCSN;
|
struct berval entryCSN;
|
||||||
|
|
||||||
entryCSN.bv_val = csnbuf;
|
entryCSN.bv_val = csnbuf;
|
||||||
|
|
@ -836,7 +836,7 @@ lastmod_db_open(
|
||||||
char buf[ 8192 ];
|
char buf[ 8192 ];
|
||||||
static char tmbuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
|
static char tmbuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
|
||||||
|
|
||||||
char csnbuf[ LDAP_LUTIL_CSNSTR_BUFSIZE ];
|
char csnbuf[ LDAP_PVT_CSNSTR_BUFSIZE ];
|
||||||
struct berval entryCSN;
|
struct berval entryCSN;
|
||||||
struct berval timestamp;
|
struct berval timestamp;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -91,6 +91,43 @@ ldap_pvt_ctime LDAP_P((
|
||||||
const time_t *tp,
|
const time_t *tp,
|
||||||
char *buf ));
|
char *buf ));
|
||||||
|
|
||||||
|
# if defined( HAVE_GMTIME_R )
|
||||||
|
# define USE_GMTIME_R
|
||||||
|
# define ldap_pvt_gmtime_lock() (0)
|
||||||
|
# define ldap_pvt_gmtime_unlock() (0)
|
||||||
|
# define ldap_pvt_gmtime(timep, result) gmtime_r((timep), (result))
|
||||||
|
# else
|
||||||
|
LDAP_F( int )
|
||||||
|
ldap_pvt_gmtime_lock LDAP_P(( void ));
|
||||||
|
|
||||||
|
LDAP_F( int )
|
||||||
|
ldap_pvt_gmtime_unlock LDAP_P(( void ));
|
||||||
|
|
||||||
|
LDAP_F( struct tm * )
|
||||||
|
ldap_pvt_gmtime LDAP_P((
|
||||||
|
LDAP_CONST time_t *timep,
|
||||||
|
struct tm *result ));
|
||||||
|
#endif
|
||||||
|
|
||||||
|
# if defined( HAVE_LOCALTIME_R )
|
||||||
|
# define USE_LOCALTIME_R
|
||||||
|
# define ldap_pvt_localtime(timep, result) localtime_r((timep), (result))
|
||||||
|
# else
|
||||||
|
LDAP_F( struct tm * )
|
||||||
|
ldap_pvt_localtime LDAP_P((
|
||||||
|
LDAP_CONST time_t *timep,
|
||||||
|
struct tm *result ));
|
||||||
|
# endif
|
||||||
|
|
||||||
|
/* Get current time as a structured time */
|
||||||
|
LDAP_F( void )
|
||||||
|
ldap_pvt_gettime LDAP_P(( struct lutil_tm * ));
|
||||||
|
|
||||||
|
/* use this macro to allocate buffer for ldap_pvt_csnstr */
|
||||||
|
#define LDAP_PVT_CSNSTR_BUFSIZE 64
|
||||||
|
LDAP_F( size_t )
|
||||||
|
ldap_pvt_csnstr( char *buf, size_t len, unsigned int replica, unsigned int mod );
|
||||||
|
|
||||||
LDAP_F( char *) ldap_pvt_get_fqdn LDAP_P(( char * ));
|
LDAP_F( char *) ldap_pvt_get_fqdn LDAP_P(( char * ));
|
||||||
|
|
||||||
struct hostent; /* avoid pulling in <netdb.h> */
|
struct hostent; /* avoid pulling in <netdb.h> */
|
||||||
|
|
|
||||||
|
|
@ -177,10 +177,6 @@ LDAP_LUTIL_F( int )
|
||||||
lutil_tm2time LDAP_P((
|
lutil_tm2time LDAP_P((
|
||||||
struct lutil_tm *, struct lutil_timet * ));
|
struct lutil_tm *, struct lutil_timet * ));
|
||||||
|
|
||||||
/* Get current time as a structured time */
|
|
||||||
LDAP_LUTIL_F( void )
|
|
||||||
lutil_gettime LDAP_P(( struct lutil_tm * ));
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
LDAP_LUTIL_F( void )
|
LDAP_LUTIL_F( void )
|
||||||
lutil_slashpath LDAP_P(( char* path ));
|
lutil_slashpath LDAP_P(( char* path ));
|
||||||
|
|
@ -229,12 +225,6 @@ lutil_uuidstr_from_normalized(
|
||||||
char *buf,
|
char *buf,
|
||||||
size_t buflen );
|
size_t buflen );
|
||||||
|
|
||||||
/* csn.c */
|
|
||||||
/* use this macro to allocate buffer for lutil_csnstr */
|
|
||||||
#define LDAP_LUTIL_CSNSTR_BUFSIZE 64
|
|
||||||
LDAP_LUTIL_F( size_t )
|
|
||||||
lutil_csnstr( char *buf, size_t len, unsigned int replica, unsigned int mod );
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Sometimes not all declarations in a header file are needed.
|
* Sometimes not all declarations in a header file are needed.
|
||||||
* An indicator to this is whether or not the symbol's type has
|
* An indicator to this is whether or not the symbol's type has
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "../liblber/lber-int.h"
|
#include "../liblber/lber-int.h"
|
||||||
|
#include "lutil.h"
|
||||||
|
|
||||||
#ifdef LDAP_R_COMPILE
|
#ifdef LDAP_R_COMPILE
|
||||||
#include <ldap_pvt_thread.h>
|
#include <ldap_pvt_thread.h>
|
||||||
|
|
|
||||||
|
|
@ -66,6 +66,15 @@ extern int h_errno;
|
||||||
static ldap_pvt_thread_mutex_t ldap_int_ctime_mutex;
|
static ldap_pvt_thread_mutex_t ldap_int_ctime_mutex;
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
|
/* USE_GMTIME_R and USE_LOCALTIME_R defined in ldap_pvt.h */
|
||||||
|
|
||||||
|
#if !defined( USE_GMTIME_R ) || !defined( USE_LOCALTIME_R )
|
||||||
|
/* we use the same mutex for gmtime(3) and localtime(3)
|
||||||
|
* because implementations may use the same buffer
|
||||||
|
* for both functions */
|
||||||
|
static ldap_pvt_thread_mutex_t ldap_int_gmtime_mutex;
|
||||||
|
#endif
|
||||||
|
|
||||||
# if defined(HAVE_GETHOSTBYNAME_R) && \
|
# if defined(HAVE_GETHOSTBYNAME_R) && \
|
||||||
(GETHOSTBYNAME_R_NARGS < 5) || (6 < GETHOSTBYNAME_R_NARGS)
|
(GETHOSTBYNAME_R_NARGS < 5) || (6 < GETHOSTBYNAME_R_NARGS)
|
||||||
/* Don't know how to handle this version, pretend it's not there */
|
/* Don't know how to handle this version, pretend it's not there */
|
||||||
|
|
@ -107,6 +116,204 @@ char *ldap_pvt_ctime( const time_t *tp, char *buf )
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef USE_GMTIME_R
|
||||||
|
int
|
||||||
|
ldap_pvt_gmtime_lock( void )
|
||||||
|
{
|
||||||
|
# ifndef LDAP_R_COMPILE
|
||||||
|
return 0;
|
||||||
|
# else /* LDAP_R_COMPILE */
|
||||||
|
return ldap_pvt_thread_mutex_lock( &ldap_int_gmtime_mutex );
|
||||||
|
# endif /* LDAP_R_COMPILE */
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
ldap_pvt_gmtime_unlock( void )
|
||||||
|
{
|
||||||
|
# ifndef LDAP_R_COMPILE
|
||||||
|
return 0;
|
||||||
|
# else /* LDAP_R_COMPILE */
|
||||||
|
return ldap_pvt_thread_mutex_unlock( &ldap_int_gmtime_mutex );
|
||||||
|
# endif /* LDAP_R_COMPILE */
|
||||||
|
}
|
||||||
|
|
||||||
|
struct tm *
|
||||||
|
ldap_pvt_gmtime( const time_t *timep, struct tm *result )
|
||||||
|
{
|
||||||
|
struct tm *tm_ptr;
|
||||||
|
|
||||||
|
# ifdef LDAP_R_COMPILE
|
||||||
|
ldap_pvt_thread_mutex_lock( &ldap_int_gmtime_mutex );
|
||||||
|
# endif /* LDAP_R_COMPILE */
|
||||||
|
|
||||||
|
tm_ptr = gmtime( timep );
|
||||||
|
if ( tm_ptr != NULL ) {
|
||||||
|
*result = *tm_ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
# ifdef LDAP_R_COMPILE
|
||||||
|
ldap_pvt_thread_mutex_unlock( &ldap_int_gmtime_mutex );
|
||||||
|
# endif /* LDAP_R_COMPILE */
|
||||||
|
|
||||||
|
return tm_ptr;
|
||||||
|
}
|
||||||
|
#endif /* !USE_GMTIME_R */
|
||||||
|
|
||||||
|
#ifndef USE_LOCALTIME_R
|
||||||
|
struct tm *
|
||||||
|
ldap_pvt_localtime( const time_t *timep, struct tm *result )
|
||||||
|
{
|
||||||
|
struct tm *tm_ptr;
|
||||||
|
|
||||||
|
# ifdef LDAP_R_COMPILE
|
||||||
|
ldap_pvt_thread_mutex_lock( &ldap_int_gmtime_mutex );
|
||||||
|
# endif /* LDAP_R_COMPILE */
|
||||||
|
|
||||||
|
tm_ptr = localtime( timep );
|
||||||
|
if ( tm_ptr != NULL ) {
|
||||||
|
*result = *tm_ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
# ifdef LDAP_R_COMPILE
|
||||||
|
ldap_pvt_thread_mutex_unlock( &ldap_int_gmtime_mutex );
|
||||||
|
# endif /* LDAP_R_COMPILE */
|
||||||
|
|
||||||
|
return tm_ptr;
|
||||||
|
}
|
||||||
|
#endif /* !USE_LOCALTIME_R */
|
||||||
|
|
||||||
|
/* return a broken out time, with microseconds
|
||||||
|
* Must be mutex-protected.
|
||||||
|
*/
|
||||||
|
#ifdef _WIN32
|
||||||
|
/* Windows SYSTEMTIME only has 10 millisecond resolution, so we
|
||||||
|
* also need to use a high resolution timer to get microseconds.
|
||||||
|
* This is pretty clunky.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
ldap_pvt_gettime( struct lutil_tm *tm )
|
||||||
|
{
|
||||||
|
static LARGE_INTEGER cFreq;
|
||||||
|
static LARGE_INTEGER prevCount;
|
||||||
|
static int subs;
|
||||||
|
static int offset;
|
||||||
|
LARGE_INTEGER count;
|
||||||
|
SYSTEMTIME st;
|
||||||
|
|
||||||
|
GetSystemTime( &st );
|
||||||
|
QueryPerformanceCounter( &count );
|
||||||
|
|
||||||
|
/* It shouldn't ever go backwards, but multiple CPUs might
|
||||||
|
* be able to hit in the same tick.
|
||||||
|
*/
|
||||||
|
if ( count.QuadPart <= prevCount.QuadPart ) {
|
||||||
|
subs++;
|
||||||
|
} else {
|
||||||
|
subs = 0;
|
||||||
|
prevCount = count;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* We assume Windows has at least a vague idea of
|
||||||
|
* when a second begins. So we align our microsecond count
|
||||||
|
* with the Windows millisecond count using this offset.
|
||||||
|
* We retain the submillisecond portion of our own count.
|
||||||
|
*
|
||||||
|
* Note - this also assumes that the relationship between
|
||||||
|
* the PerformanceCouunter and SystemTime stays constant;
|
||||||
|
* that assumption breaks if the SystemTime is adjusted by
|
||||||
|
* an external action.
|
||||||
|
*/
|
||||||
|
if ( !cFreq.QuadPart ) {
|
||||||
|
long long t;
|
||||||
|
int usec;
|
||||||
|
QueryPerformanceFrequency( &cFreq );
|
||||||
|
|
||||||
|
/* just get sub-second portion of counter */
|
||||||
|
t = count.QuadPart % cFreq.QuadPart;
|
||||||
|
|
||||||
|
/* convert to microseconds */
|
||||||
|
t *= 1000000;
|
||||||
|
usec = t / cFreq.QuadPart;
|
||||||
|
|
||||||
|
offset = usec - st.wMilliseconds * 1000;
|
||||||
|
}
|
||||||
|
|
||||||
|
tm->tm_usub = subs;
|
||||||
|
|
||||||
|
/* convert to microseconds */
|
||||||
|
count.QuadPart %= cFreq.QuadPart;
|
||||||
|
count.QuadPart *= 1000000;
|
||||||
|
count.QuadPart /= cFreq.QuadPart;
|
||||||
|
count.QuadPart -= offset;
|
||||||
|
|
||||||
|
tm->tm_usec = count.QuadPart % 1000000;
|
||||||
|
if ( tm->tm_usec < 0 )
|
||||||
|
tm->tm_usec += 1000000;
|
||||||
|
|
||||||
|
/* any difference larger than microseconds is
|
||||||
|
* already reflected in st
|
||||||
|
*/
|
||||||
|
|
||||||
|
tm->tm_sec = st.wSecond;
|
||||||
|
tm->tm_min = st.wMinute;
|
||||||
|
tm->tm_hour = st.wHour;
|
||||||
|
tm->tm_mday = st.wDay;
|
||||||
|
tm->tm_mon = st.wMonth - 1;
|
||||||
|
tm->tm_year = st.wYear - 1900;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
void
|
||||||
|
ldap_pvt_gettime( struct lutil_tm *ltm )
|
||||||
|
{
|
||||||
|
struct timeval tv;
|
||||||
|
static struct timeval prevTv;
|
||||||
|
static int subs;
|
||||||
|
|
||||||
|
struct tm tm;
|
||||||
|
time_t t;
|
||||||
|
|
||||||
|
gettimeofday( &tv, NULL );
|
||||||
|
t = tv.tv_sec;
|
||||||
|
|
||||||
|
if ( tv.tv_sec < prevTv.tv_sec
|
||||||
|
|| ( tv.tv_sec == prevTv.tv_sec && tv.tv_usec == prevTv.tv_usec )) {
|
||||||
|
subs++;
|
||||||
|
} else {
|
||||||
|
subs = 0;
|
||||||
|
prevTv = tv;
|
||||||
|
}
|
||||||
|
|
||||||
|
ltm->tm_usub = subs;
|
||||||
|
|
||||||
|
ldap_pvt_gmtime( &t, &tm );
|
||||||
|
|
||||||
|
ltm->tm_sec = tm.tm_sec;
|
||||||
|
ltm->tm_min = tm.tm_min;
|
||||||
|
ltm->tm_hour = tm.tm_hour;
|
||||||
|
ltm->tm_mday = tm.tm_mday;
|
||||||
|
ltm->tm_mon = tm.tm_mon;
|
||||||
|
ltm->tm_year = tm.tm_year;
|
||||||
|
ltm->tm_usec = tv.tv_usec;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
size_t
|
||||||
|
ldap_pvt_csnstr(char *buf, size_t len, unsigned int replica, unsigned int mod)
|
||||||
|
{
|
||||||
|
struct lutil_tm tm;
|
||||||
|
int n;
|
||||||
|
|
||||||
|
ldap_pvt_gettime( &tm );
|
||||||
|
|
||||||
|
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_usec, tm.tm_usub, replica, mod );
|
||||||
|
|
||||||
|
if( n < 0 ) return 0;
|
||||||
|
return ( (size_t) n < len ) ? n : 0;
|
||||||
|
}
|
||||||
|
|
||||||
#define BUFSTART (1024-32)
|
#define BUFSTART (1024-32)
|
||||||
#define BUFMAX (32*1024-32)
|
#define BUFMAX (32*1024-32)
|
||||||
|
|
||||||
|
|
@ -405,6 +612,9 @@ void ldap_int_utils_init( void )
|
||||||
#ifdef LDAP_R_COMPILE
|
#ifdef LDAP_R_COMPILE
|
||||||
#if !defined( USE_CTIME_R ) && !defined( HAVE_REENTRANT_FUNCTIONS )
|
#if !defined( USE_CTIME_R ) && !defined( HAVE_REENTRANT_FUNCTIONS )
|
||||||
ldap_pvt_thread_mutex_init( &ldap_int_ctime_mutex );
|
ldap_pvt_thread_mutex_init( &ldap_int_ctime_mutex );
|
||||||
|
#endif
|
||||||
|
#if !defined( USE_GMTIME_R ) && !defined( USE_LOCALTIME_R )
|
||||||
|
ldap_pvt_thread_mutex_init( &ldap_int_gmtime_mutex );
|
||||||
#endif
|
#endif
|
||||||
ldap_pvt_thread_mutex_init( &ldap_int_resolv_mutex );
|
ldap_pvt_thread_mutex_init( &ldap_int_resolv_mutex );
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,14 +27,14 @@ UNIX_OBJS = detach.o
|
||||||
|
|
||||||
XLIBS = $(LIBRARY) $(LDAP_LIBLBER_LA)
|
XLIBS = $(LIBRARY) $(LDAP_LIBLBER_LA)
|
||||||
|
|
||||||
SRCS = base64.c csn.c entropy.c sasl.c signal.c hash.c passfile.c \
|
SRCS = base64.c entropy.c sasl.c signal.c hash.c passfile.c \
|
||||||
md5.c passwd.c sha1.c getpass.c lockf.c utils.c uuid.c sockpair.c \
|
md5.c passwd.c sha1.c getpass.c lockf.c utils.c uuid.c sockpair.c \
|
||||||
avl.c tavl.c ldif.c fetch.c \
|
avl.c tavl.c ldif.c fetch.c \
|
||||||
testavl.c \
|
testavl.c \
|
||||||
meter.c \
|
meter.c \
|
||||||
@LIBSRCS@ $(@PLAT@_SRCS)
|
@LIBSRCS@ $(@PLAT@_SRCS)
|
||||||
|
|
||||||
OBJS = base64.o csn.o entropy.o sasl.o signal.o hash.o passfile.o \
|
OBJS = base64.o entropy.o sasl.o signal.o hash.o passfile.o \
|
||||||
md5.o passwd.o sha1.o getpass.o lockf.o utils.o uuid.o sockpair.o \
|
md5.o passwd.o sha1.o getpass.o lockf.o utils.o uuid.o sockpair.o \
|
||||||
avl.o tavl.o ldif.o fetch.o \
|
avl.o tavl.o ldif.o fetch.o \
|
||||||
meter.o \
|
meter.o \
|
||||||
|
|
|
||||||
|
|
@ -1,82 +0,0 @@
|
||||||
/* csn.c - Change Sequence Number routines */
|
|
||||||
/* $OpenLDAP$ */
|
|
||||||
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
|
|
||||||
*
|
|
||||||
* Copyright 2000-2009 The OpenLDAP Foundation.
|
|
||||||
* Portions Copyright 2000-2003 Kurt D. Zeilenga.
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted only as authorized by the OpenLDAP
|
|
||||||
* Public License.
|
|
||||||
*
|
|
||||||
* A copy of this license is available in the file LICENSE in the
|
|
||||||
* top-level directory of the distribution or, alternatively, at
|
|
||||||
* <http://www.OpenLDAP.org/license.html>.
|
|
||||||
*/
|
|
||||||
/* Portions Copyright 2000, John E. Schimmel, All rights reserved.
|
|
||||||
* This software is not subject to any license of Mirapoint, Inc.
|
|
||||||
*
|
|
||||||
* This is free software; you can redistribute and use it
|
|
||||||
* under the same terms as OpenLDAP itself.
|
|
||||||
*/
|
|
||||||
/* This work was developed by John E. Schimmel and adapted for
|
|
||||||
* inclusion in OpenLDAP Software by Kurt D. Zeilenga.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* This file contains routines to generate a change sequence number.
|
|
||||||
* Every add, delete, and modification is given a unique identifier
|
|
||||||
* for use in resolving conflicts during replication operations.
|
|
||||||
*
|
|
||||||
* These routines are (loosly) based upon draft-ietf-ldup-model-03.txt,
|
|
||||||
* A WORK IN PROGRESS. The format will likely change.
|
|
||||||
*
|
|
||||||
* The format of a CSN string is: yyyymmddhhmmssz#s#r#c
|
|
||||||
* where s is a counter of operations within a timeslice, r is
|
|
||||||
* the replica id (normally zero), and c is a counter of
|
|
||||||
* modifications within this operation. s, r, and c are
|
|
||||||
* represented in hex and zero padded to lengths of 6, 3, and
|
|
||||||
* 6, respectively. (In previous implementations r was only 2 digits.)
|
|
||||||
*
|
|
||||||
* Calls to this routine MUST be serialized with other calls
|
|
||||||
* to gmtime().
|
|
||||||
*/
|
|
||||||
#include "portable.h"
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <ac/time.h>
|
|
||||||
|
|
||||||
#include <lutil.h>
|
|
||||||
|
|
||||||
/* Must be mutex-protected, because lutil_gettime needs mutex protection */
|
|
||||||
size_t
|
|
||||||
lutil_csnstr(char *buf, size_t len, unsigned int replica, unsigned int mod)
|
|
||||||
{
|
|
||||||
struct lutil_tm tm;
|
|
||||||
int n;
|
|
||||||
|
|
||||||
lutil_gettime( &tm );
|
|
||||||
|
|
||||||
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_usec, tm.tm_usub, replica, mod );
|
|
||||||
|
|
||||||
if( n < 0 ) return 0;
|
|
||||||
return ( (size_t) n < len ) ? n : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef TEST
|
|
||||||
int
|
|
||||||
main(int argc, char **argv)
|
|
||||||
{
|
|
||||||
char buf[ LDAP_LUTIL_CSNSTR_BUFSIZE ];
|
|
||||||
|
|
||||||
if ( ! lutil_csnstr( buf, (size_t) 10, 0, 0 ) ) {
|
|
||||||
fprintf(stderr, "failed lutil_csnstr\n");
|
|
||||||
}
|
|
||||||
if ( ! lutil_csnstr( buf, sizeof(buf), 0, 0 ) ) {
|
|
||||||
fprintf(stderr, "failed lutil_csnstr\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
@ -282,128 +282,6 @@ int lutil_parsetime( char *atm, struct lutil_tm *tm )
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* return a broken out time, with microseconds
|
|
||||||
* Must be mutex-protected.
|
|
||||||
*/
|
|
||||||
#ifdef _WIN32
|
|
||||||
/* Windows SYSTEMTIME only has 10 millisecond resolution, so we
|
|
||||||
* also need to use a high resolution timer to get microseconds.
|
|
||||||
* This is pretty clunky.
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
lutil_gettime( struct lutil_tm *tm )
|
|
||||||
{
|
|
||||||
static LARGE_INTEGER cFreq;
|
|
||||||
static LARGE_INTEGER prevCount;
|
|
||||||
static int subs;
|
|
||||||
static int offset;
|
|
||||||
LARGE_INTEGER count;
|
|
||||||
SYSTEMTIME st;
|
|
||||||
|
|
||||||
GetSystemTime( &st );
|
|
||||||
QueryPerformanceCounter( &count );
|
|
||||||
|
|
||||||
/* It shouldn't ever go backwards, but multiple CPUs might
|
|
||||||
* be able to hit in the same tick.
|
|
||||||
*/
|
|
||||||
if ( count.QuadPart <= prevCount.QuadPart ) {
|
|
||||||
subs++;
|
|
||||||
} else {
|
|
||||||
subs = 0;
|
|
||||||
prevCount = count;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* We assume Windows has at least a vague idea of
|
|
||||||
* when a second begins. So we align our microsecond count
|
|
||||||
* with the Windows millisecond count using this offset.
|
|
||||||
* We retain the submillisecond portion of our own count.
|
|
||||||
*
|
|
||||||
* Note - this also assumes that the relationship between
|
|
||||||
* the PerformanceCouunter and SystemTime stays constant;
|
|
||||||
* that assumption breaks if the SystemTime is adjusted by
|
|
||||||
* an external action.
|
|
||||||
*/
|
|
||||||
if ( !cFreq.QuadPart ) {
|
|
||||||
long long t;
|
|
||||||
int usec;
|
|
||||||
QueryPerformanceFrequency( &cFreq );
|
|
||||||
|
|
||||||
/* just get sub-second portion of counter */
|
|
||||||
t = count.QuadPart % cFreq.QuadPart;
|
|
||||||
|
|
||||||
/* convert to microseconds */
|
|
||||||
t *= 1000000;
|
|
||||||
usec = t / cFreq.QuadPart;
|
|
||||||
|
|
||||||
offset = usec - st.wMilliseconds * 1000;
|
|
||||||
}
|
|
||||||
|
|
||||||
tm->tm_usub = subs;
|
|
||||||
|
|
||||||
/* convert to microseconds */
|
|
||||||
count.QuadPart %= cFreq.QuadPart;
|
|
||||||
count.QuadPart *= 1000000;
|
|
||||||
count.QuadPart /= cFreq.QuadPart;
|
|
||||||
count.QuadPart -= offset;
|
|
||||||
|
|
||||||
tm->tm_usec = count.QuadPart % 1000000;
|
|
||||||
if ( tm->tm_usec < 0 )
|
|
||||||
tm->tm_usec += 1000000;
|
|
||||||
|
|
||||||
/* any difference larger than microseconds is
|
|
||||||
* already reflected in st
|
|
||||||
*/
|
|
||||||
|
|
||||||
tm->tm_sec = st.wSecond;
|
|
||||||
tm->tm_min = st.wMinute;
|
|
||||||
tm->tm_hour = st.wHour;
|
|
||||||
tm->tm_mday = st.wDay;
|
|
||||||
tm->tm_mon = st.wMonth - 1;
|
|
||||||
tm->tm_year = st.wYear - 1900;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
void
|
|
||||||
lutil_gettime( struct lutil_tm *ltm )
|
|
||||||
{
|
|
||||||
struct timeval tv;
|
|
||||||
static struct timeval prevTv;
|
|
||||||
static int subs;
|
|
||||||
|
|
||||||
#ifdef HAVE_GMTIME_R
|
|
||||||
struct tm tm_buf;
|
|
||||||
#endif
|
|
||||||
struct tm *tm;
|
|
||||||
time_t t;
|
|
||||||
|
|
||||||
gettimeofday( &tv, NULL );
|
|
||||||
t = tv.tv_sec;
|
|
||||||
|
|
||||||
if ( tv.tv_sec < prevTv.tv_sec
|
|
||||||
|| ( tv.tv_sec == prevTv.tv_sec && tv.tv_usec == prevTv.tv_usec )) {
|
|
||||||
subs++;
|
|
||||||
} else {
|
|
||||||
subs = 0;
|
|
||||||
prevTv = tv;
|
|
||||||
}
|
|
||||||
|
|
||||||
ltm->tm_usub = subs;
|
|
||||||
|
|
||||||
#ifdef HAVE_GMTIME_R
|
|
||||||
tm = gmtime_r( &t, &tm_buf );
|
|
||||||
#else
|
|
||||||
tm = gmtime( &t );
|
|
||||||
#endif
|
|
||||||
|
|
||||||
ltm->tm_sec = tm->tm_sec;
|
|
||||||
ltm->tm_min = tm->tm_min;
|
|
||||||
ltm->tm_hour = tm->tm_hour;
|
|
||||||
ltm->tm_mday = tm->tm_mday;
|
|
||||||
ltm->tm_mon = tm->tm_mon;
|
|
||||||
ltm->tm_year = tm->tm_year;
|
|
||||||
ltm->tm_usec = tv.tv_usec;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* strcopy is like strcpy except it returns a pointer to the trailing NUL of
|
/* strcopy is like strcpy except it returns a pointer to the trailing NUL of
|
||||||
* the result string. This allows fast construction of catenated strings
|
* the result string. This allows fast construction of catenated strings
|
||||||
* without the overhead of strlen/strcat.
|
* without the overhead of strlen/strcat.
|
||||||
|
|
|
||||||
|
|
@ -592,7 +592,7 @@ int slap_add_opattrs(
|
||||||
struct berval name, timestamp, csn = BER_BVNULL;
|
struct berval name, timestamp, csn = BER_BVNULL;
|
||||||
struct berval nname, tmp;
|
struct berval nname, tmp;
|
||||||
char timebuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
|
char timebuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
|
||||||
char csnbuf[ LDAP_LUTIL_CSNSTR_BUFSIZE ];
|
char csnbuf[ LDAP_PVT_CSNSTR_BUFSIZE ];
|
||||||
Attribute *a;
|
Attribute *a;
|
||||||
|
|
||||||
if ( SLAP_LASTMOD( op->o_bd ) ) {
|
if ( SLAP_LASTMOD( op->o_bd ) ) {
|
||||||
|
|
|
||||||
|
|
@ -101,7 +101,7 @@ txnReturn:
|
||||||
/* allocate CSN */
|
/* allocate CSN */
|
||||||
if ( BER_BVISNULL( &op->o_csn ) ) {
|
if ( BER_BVISNULL( &op->o_csn ) ) {
|
||||||
struct berval csn;
|
struct berval csn;
|
||||||
char csnbuf[LDAP_LUTIL_CSNSTR_BUFSIZE];
|
char csnbuf[LDAP_PVT_CSNSTR_BUFSIZE];
|
||||||
|
|
||||||
csn.bv_val = csnbuf;
|
csn.bv_val = csnbuf;
|
||||||
csn.bv_len = sizeof(csnbuf);
|
csn.bv_len = sizeof(csnbuf);
|
||||||
|
|
|
||||||
|
|
@ -1306,7 +1306,7 @@ ldif_back_delete( Operation *op, SlapReply *rs )
|
||||||
|
|
||||||
if ( BER_BVISEMPTY( &op->o_csn )) {
|
if ( BER_BVISEMPTY( &op->o_csn )) {
|
||||||
struct berval csn;
|
struct berval csn;
|
||||||
char csnbuf[LDAP_LUTIL_CSNSTR_BUFSIZE];
|
char csnbuf[LDAP_PVT_CSNSTR_BUFSIZE];
|
||||||
|
|
||||||
csn.bv_val = csnbuf;
|
csn.bv_val = csnbuf;
|
||||||
csn.bv_len = sizeof( csnbuf );
|
csn.bv_len = sizeof( csnbuf );
|
||||||
|
|
|
||||||
|
|
@ -266,72 +266,27 @@ conn_create(
|
||||||
monitor_subsys_t *ms )
|
monitor_subsys_t *ms )
|
||||||
{
|
{
|
||||||
monitor_entry_t *mp;
|
monitor_entry_t *mp;
|
||||||
struct tm *tm;
|
struct tm tm;
|
||||||
char buf[ BACKMONITOR_BUFSIZE ];
|
char buf[ BACKMONITOR_BUFSIZE ];
|
||||||
char buf2[ LDAP_LUTIL_GENTIME_BUFSIZE ];
|
char buf2[ LDAP_LUTIL_GENTIME_BUFSIZE ];
|
||||||
char buf3[ LDAP_LUTIL_GENTIME_BUFSIZE ];
|
char buf3[ LDAP_LUTIL_GENTIME_BUFSIZE ];
|
||||||
|
|
||||||
struct berval bv, ctmbv, mtmbv, bv2, bv3;
|
struct berval bv, ctmbv, mtmbv;
|
||||||
struct berval bv_unknown= BER_BVC("unknown");
|
struct berval bv_unknown= BER_BVC("unknown");
|
||||||
|
|
||||||
Entry *e;
|
Entry *e;
|
||||||
|
|
||||||
#ifdef HACK_LOCAL_TIME
|
|
||||||
char ctmbuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
|
|
||||||
char mtmbuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_GMTIME_R
|
|
||||||
struct tm tm_buf;
|
|
||||||
#endif /* HAVE_GMTIME_R */
|
|
||||||
|
|
||||||
assert( c != NULL );
|
assert( c != NULL );
|
||||||
assert( ep != NULL );
|
assert( ep != NULL );
|
||||||
|
|
||||||
#ifndef HAVE_GMTIME_R
|
ldap_pvt_gmtime( &c->c_starttime, &tm );
|
||||||
ldap_pvt_thread_mutex_lock( &gmtime_mutex );
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef HAVE_GMTIME_R
|
ctmbv.bv_len = lutil_gentime( buf2, sizeof( buf2 ), &tm );
|
||||||
tm = gmtime_r( &c->c_starttime, &tm_buf );
|
ctmbv.bv_val = buf2;
|
||||||
#else
|
|
||||||
tm = gmtime( &c->c_starttime );
|
|
||||||
#endif
|
|
||||||
bv2.bv_len = lutil_gentime( buf2, sizeof( buf2 ), tm );
|
|
||||||
bv2.bv_val = buf2;
|
|
||||||
#ifdef HACK_LOCAL_TIME
|
|
||||||
# ifdef HAVE_LOCALTIME_R
|
|
||||||
tm = localtime_r( &c->c_starttime, &tm_buf );
|
|
||||||
# else
|
|
||||||
tm = localtime( &c->c_starttime );
|
|
||||||
# endif
|
|
||||||
ctmbv.bv_len = lutil_localtime( ctmbuf, sizeof( ctmbuf ), tm, -timezone );
|
|
||||||
ctmbv.bv_val = ctmbuf;
|
|
||||||
#else /* !HACK_LOCAL_TIME */
|
|
||||||
ctmbv = bv2;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef HAVE_GMTIME_R
|
ldap_pvt_gmtime( &c->c_activitytime, &tm );
|
||||||
tm = gmtime_r( &c->c_activitytime, &tm_buf );
|
mtmbv.bv_len = lutil_gentime( buf3, sizeof( buf3 ), &tm );
|
||||||
#else
|
mtmbv.bv_val = buf3;
|
||||||
tm = gmtime( &c->c_activitytime );
|
|
||||||
#endif
|
|
||||||
bv3.bv_len = lutil_gentime( buf3, sizeof( buf3 ), tm );
|
|
||||||
bv3.bv_val = buf3;
|
|
||||||
#ifdef HACK_LOCAL_TIME
|
|
||||||
# ifdef HAVE_LOCALTIME_R
|
|
||||||
tm = localtime_r( &c->c_activitytime, &tm_buf );
|
|
||||||
# else
|
|
||||||
tm = localtime( &c->c_activitytime );
|
|
||||||
# endif /* HAVE_LOCALTIME_R */
|
|
||||||
mtmbv.bv_len = lutil_localtime( mtmbuf, sizeof( mtmbuf ), tm, -timezone );
|
|
||||||
mtmbv.bv_val = mtmbuf;
|
|
||||||
#else /* !HACK_LOCAL_TIME */
|
|
||||||
mtmbv = bv3;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef HAVE_GMTIME_R
|
|
||||||
ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
|
|
||||||
#endif
|
|
||||||
|
|
||||||
bv.bv_len = snprintf( buf, sizeof( buf ),
|
bv.bv_len = snprintf( buf, sizeof( buf ),
|
||||||
"cn=Connection %ld", c->c_connid );
|
"cn=Connection %ld", c->c_connid );
|
||||||
|
|
@ -450,9 +405,9 @@ conn_create(
|
||||||
attr_merge_normalize_one( e, mi->mi_ad_monitorConnectionLocalAddress,
|
attr_merge_normalize_one( e, mi->mi_ad_monitorConnectionLocalAddress,
|
||||||
&c->c_sock_name, NULL );
|
&c->c_sock_name, NULL );
|
||||||
|
|
||||||
attr_merge_normalize_one( e, mi->mi_ad_monitorConnectionStartTime, &bv2, NULL );
|
attr_merge_normalize_one( e, mi->mi_ad_monitorConnectionStartTime, &ctmbv, NULL );
|
||||||
|
|
||||||
attr_merge_normalize_one( e, mi->mi_ad_monitorConnectionActivityTime, &bv3, NULL );
|
attr_merge_normalize_one( e, mi->mi_ad_monitorConnectionActivityTime, &mtmbv, NULL );
|
||||||
|
|
||||||
mp = monitor_entrypriv_create();
|
mp = monitor_entrypriv_create();
|
||||||
if ( mp == NULL ) {
|
if ( mp == NULL ) {
|
||||||
|
|
|
||||||
|
|
@ -2207,10 +2207,7 @@ monitor_back_db_open(
|
||||||
monitor_entry_t *mp;
|
monitor_entry_t *mp;
|
||||||
int i;
|
int i;
|
||||||
struct berval bv, rdn = BER_BVC(SLAPD_MONITOR_DN);
|
struct berval bv, rdn = BER_BVC(SLAPD_MONITOR_DN);
|
||||||
struct tm *tms;
|
struct tm tms;
|
||||||
#ifdef HAVE_GMTIME_R
|
|
||||||
struct tm tm_buf;
|
|
||||||
#endif
|
|
||||||
static char tmbuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
|
static char tmbuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
|
||||||
struct berval desc[] = {
|
struct berval desc[] = {
|
||||||
BER_BVC("This subtree contains monitoring/managing objects."),
|
BER_BVC("This subtree contains monitoring/managing objects."),
|
||||||
|
|
@ -2229,27 +2226,8 @@ monitor_back_db_open(
|
||||||
/*
|
/*
|
||||||
* Start
|
* Start
|
||||||
*/
|
*/
|
||||||
#ifndef HAVE_GMTIME_R
|
ldap_pvt_gmtime( &starttime, &tms );
|
||||||
ldap_pvt_thread_mutex_lock( &gmtime_mutex );
|
lutil_gentime( tmbuf, sizeof(tmbuf), &tms );
|
||||||
#endif
|
|
||||||
#ifdef HACK_LOCAL_TIME
|
|
||||||
# ifdef HAVE_LOCALTIME_R
|
|
||||||
tms = localtime_r( &starttime, &tm_buf );
|
|
||||||
# else
|
|
||||||
tms = localtime( &starttime );
|
|
||||||
# endif /* HAVE_LOCALTIME_R */
|
|
||||||
lutil_localtime( tmbuf, sizeof(tmbuf), tms, -timezone );
|
|
||||||
#else /* !HACK_LOCAL_TIME */
|
|
||||||
# ifdef HAVE_GMTIME_R
|
|
||||||
tms = gmtime_r( &starttime, &tm_buf );
|
|
||||||
# else
|
|
||||||
tms = gmtime( &starttime );
|
|
||||||
# endif /* HAVE_GMTIME_R */
|
|
||||||
lutil_gentime( tmbuf, sizeof(tmbuf), tms );
|
|
||||||
#endif /* !HACK_LOCAL_TIME */
|
|
||||||
#ifndef HAVE_GMTIME_R
|
|
||||||
ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
|
|
||||||
#endif
|
|
||||||
|
|
||||||
mi->mi_startTime.bv_val = tmbuf;
|
mi->mi_startTime.bv_val = tmbuf;
|
||||||
mi->mi_startTime.bv_len = strlen( tmbuf );
|
mi->mi_startTime.bv_len = strlen( tmbuf );
|
||||||
|
|
|
||||||
|
|
@ -195,10 +195,7 @@ monitor_subsys_time_update(
|
||||||
dnRdn( &e->e_nname, &rdn );
|
dnRdn( &e->e_nname, &rdn );
|
||||||
|
|
||||||
if ( dn_match( &rdn, &bv_current ) ) {
|
if ( dn_match( &rdn, &bv_current ) ) {
|
||||||
struct tm *tm;
|
struct tm tm;
|
||||||
#ifdef HAVE_GMTIME_R
|
|
||||||
struct tm tm_buf;
|
|
||||||
#endif
|
|
||||||
char tmbuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
|
char tmbuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
|
||||||
Attribute *a;
|
Attribute *a;
|
||||||
ber_len_t len;
|
ber_len_t len;
|
||||||
|
|
@ -206,27 +203,8 @@ monitor_subsys_time_update(
|
||||||
|
|
||||||
currtime = slap_get_time();
|
currtime = slap_get_time();
|
||||||
|
|
||||||
#ifndef HAVE_GMTIME_R
|
ldap_pvt_gmtime( &currtime, &tm );
|
||||||
ldap_pvt_thread_mutex_lock( &gmtime_mutex );
|
lutil_gentime( tmbuf, sizeof( tmbuf ), &tm );
|
||||||
#endif
|
|
||||||
#ifdef HACK_LOCAL_TIME
|
|
||||||
# ifdef HAVE_LOCALTIME_R
|
|
||||||
tm = localtime_r( &currtime, &tm_buf );
|
|
||||||
# else
|
|
||||||
tm = localtime( &currtime );
|
|
||||||
# endif /* HAVE_LOCALTIME_R */
|
|
||||||
lutil_localtime( tmbuf, sizeof( tmbuf ), tm, -timezone );
|
|
||||||
#else /* !HACK_LOCAL_TIME */
|
|
||||||
# ifdef HAVE_GMTIME_R
|
|
||||||
tm = gmtime_r( &currtime, &tm_buf );
|
|
||||||
# else
|
|
||||||
tm = gmtime( &currtime );
|
|
||||||
# endif /* HAVE_GMTIME_R */
|
|
||||||
lutil_gentime( tmbuf, sizeof( tmbuf ), tm );
|
|
||||||
#endif /* !HACK_LOCAL_TIME */
|
|
||||||
#ifndef HAVE_GMTIME_R
|
|
||||||
ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
|
|
||||||
#endif
|
|
||||||
|
|
||||||
len = strlen( tmbuf );
|
len = strlen( tmbuf );
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,7 @@ ndb_back_delete( Operation *op, SlapReply *rs )
|
||||||
/* allocate CSN */
|
/* allocate CSN */
|
||||||
if ( BER_BVISNULL( &op->o_csn ) ) {
|
if ( BER_BVISNULL( &op->o_csn ) ) {
|
||||||
struct berval csn;
|
struct berval csn;
|
||||||
char csnbuf[LDAP_LUTIL_CSNSTR_BUFSIZE];
|
char csnbuf[LDAP_PVT_CSNSTR_BUFSIZE];
|
||||||
|
|
||||||
csn.bv_val = csnbuf;
|
csn.bv_val = csnbuf;
|
||||||
csn.bv_len = sizeof(csnbuf);
|
csn.bv_len = sizeof(csnbuf);
|
||||||
|
|
|
||||||
|
|
@ -939,7 +939,7 @@ backsql_add( Operation *op, SlapReply *rs )
|
||||||
* NOTE: fake successful result to force contextCSN to be bumped up
|
* NOTE: fake successful result to force contextCSN to be bumped up
|
||||||
*/
|
*/
|
||||||
if ( op->o_sync ) {
|
if ( op->o_sync ) {
|
||||||
char buf[ LDAP_LUTIL_CSNSTR_BUFSIZE ];
|
char buf[ LDAP_PVT_CSNSTR_BUFSIZE ];
|
||||||
struct berval csn;
|
struct berval csn;
|
||||||
|
|
||||||
csn.bv_val = buf;
|
csn.bv_val = buf;
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,7 @@ backsql_operational_entryUUID( backsql_info *bi, backsql_entryID *id )
|
||||||
Attribute *
|
Attribute *
|
||||||
backsql_operational_entryCSN( Operation *op )
|
backsql_operational_entryCSN( Operation *op )
|
||||||
{
|
{
|
||||||
char csnbuf[ LDAP_LUTIL_CSNSTR_BUFSIZE ];
|
char csnbuf[ LDAP_PVT_CSNSTR_BUFSIZE ];
|
||||||
struct berval entryCSN;
|
struct berval entryCSN;
|
||||||
Attribute *a;
|
Attribute *a;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@
|
||||||
|
|
||||||
int slap_serverID;
|
int slap_serverID;
|
||||||
|
|
||||||
/* maxcsn->bv_val must point to a char buf[LDAP_LUTIL_CSNSTR_BUFSIZE] */
|
/* maxcsn->bv_val must point to a char buf[LDAP_PVT_CSNSTR_BUFSIZE] */
|
||||||
void
|
void
|
||||||
slap_get_commit_csn(
|
slap_get_commit_csn(
|
||||||
Operation *op,
|
Operation *op,
|
||||||
|
|
@ -42,7 +42,7 @@ slap_get_commit_csn(
|
||||||
|
|
||||||
if ( maxcsn ) {
|
if ( maxcsn ) {
|
||||||
assert( maxcsn->bv_val != NULL );
|
assert( maxcsn->bv_val != NULL );
|
||||||
assert( maxcsn->bv_len >= LDAP_LUTIL_CSNSTR_BUFSIZE );
|
assert( maxcsn->bv_len >= LDAP_PVT_CSNSTR_BUFSIZE );
|
||||||
}
|
}
|
||||||
if ( foundit ) {
|
if ( foundit ) {
|
||||||
*foundit = 0;
|
*foundit = 0;
|
||||||
|
|
@ -167,13 +167,9 @@ slap_get_csn(
|
||||||
{
|
{
|
||||||
if ( csn == NULL ) return LDAP_OTHER;
|
if ( csn == NULL ) return LDAP_OTHER;
|
||||||
|
|
||||||
/* gmtime doesn't always need a mutex, but lutil_csnstr does */
|
csn->bv_len = ldap_pvt_csnstr( csn->bv_val, csn->bv_len, slap_serverID, 0 );
|
||||||
ldap_pvt_thread_mutex_lock( &gmtime_mutex );
|
|
||||||
csn->bv_len = lutil_csnstr( csn->bv_val, csn->bv_len, slap_serverID, 0 );
|
|
||||||
if ( manage_ctxcsn )
|
if ( manage_ctxcsn )
|
||||||
slap_queue_csn( op, csn );
|
slap_queue_csn( op, csn );
|
||||||
|
|
||||||
ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
|
|
||||||
|
|
||||||
return LDAP_SUCCESS;
|
return LDAP_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,6 @@ BerVarray default_referral = NULL;
|
||||||
ldap_pvt_thread_pool_t connection_pool;
|
ldap_pvt_thread_pool_t connection_pool;
|
||||||
int connection_pool_max = SLAP_MAX_WORKER_THREADS;
|
int connection_pool_max = SLAP_MAX_WORKER_THREADS;
|
||||||
int slap_tool_thread_max = 1;
|
int slap_tool_thread_max = 1;
|
||||||
ldap_pvt_thread_mutex_t gmtime_mutex;
|
|
||||||
|
|
||||||
slap_counters_t slap_counters, *slap_counters_list;
|
slap_counters_t slap_counters, *slap_counters_list;
|
||||||
|
|
||||||
|
|
@ -145,7 +144,6 @@ slap_init( int mode, const char *name )
|
||||||
LDAP_STAILQ_INIT( &slapd_rq.task_list );
|
LDAP_STAILQ_INIT( &slapd_rq.task_list );
|
||||||
LDAP_STAILQ_INIT( &slapd_rq.run_list );
|
LDAP_STAILQ_INIT( &slapd_rq.run_list );
|
||||||
|
|
||||||
ldap_pvt_thread_mutex_init( &gmtime_mutex );
|
|
||||||
slap_passwd_init();
|
slap_passwd_init();
|
||||||
|
|
||||||
rc = slap_sasl_init();
|
rc = slap_sasl_init();
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ slap_compose_sync_cookie(
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( numcsn == 0 || rid == -1 ) {
|
if ( numcsn == 0 || rid == -1 ) {
|
||||||
char cookiestr[ LDAP_LUTIL_CSNSTR_BUFSIZE + 20 ];
|
char cookiestr[ LDAP_PVT_CSNSTR_BUFSIZE + 20 ];
|
||||||
if ( rid == -1 ) {
|
if ( rid == -1 ) {
|
||||||
cookiestr[0] = '\0';
|
cookiestr[0] = '\0';
|
||||||
len = 0;
|
len = 0;
|
||||||
|
|
@ -289,14 +289,14 @@ slap_init_sync_cookie_ctxcsn(
|
||||||
struct sync_cookie *cookie
|
struct sync_cookie *cookie
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
char csnbuf[ LDAP_LUTIL_CSNSTR_BUFSIZE + 4 ];
|
char csnbuf[ LDAP_PVT_CSNSTR_BUFSIZE + 4 ];
|
||||||
struct berval octet_str = BER_BVNULL;
|
struct berval octet_str = BER_BVNULL;
|
||||||
struct berval ctxcsn = BER_BVNULL;
|
struct berval ctxcsn = BER_BVNULL;
|
||||||
|
|
||||||
if ( cookie == NULL )
|
if ( cookie == NULL )
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
octet_str.bv_len = snprintf( csnbuf, LDAP_LUTIL_CSNSTR_BUFSIZE + 4,
|
octet_str.bv_len = snprintf( csnbuf, LDAP_PVT_CSNSTR_BUFSIZE + 4,
|
||||||
"csn=%4d%02d%02d%02d%02d%02dZ#%06x#%02x#%06x",
|
"csn=%4d%02d%02d%02d%02d%02dZ#%06x#%02x#%06x",
|
||||||
1900, 1, 1, 0, 0, 0, 0, 0, 0 );
|
1900, 1, 1, 0, 0, 0, 0, 0, 0 );
|
||||||
octet_str.bv_val = csnbuf;
|
octet_str.bv_val = csnbuf;
|
||||||
|
|
|
||||||
|
|
@ -848,21 +848,11 @@ slap_sort_vals(
|
||||||
*/
|
*/
|
||||||
void slap_timestamp( time_t *tm, struct berval *bv )
|
void slap_timestamp( time_t *tm, struct berval *bv )
|
||||||
{
|
{
|
||||||
struct tm *ltm;
|
struct tm ltm;
|
||||||
#ifdef HAVE_GMTIME_R
|
|
||||||
struct tm ltm_buf;
|
|
||||||
|
|
||||||
ltm = gmtime_r( tm, <m_buf );
|
ldap_pvt_gmtime( tm, <m );
|
||||||
#else
|
|
||||||
ldap_pvt_thread_mutex_lock( &gmtime_mutex );
|
|
||||||
ltm = gmtime( tm );
|
|
||||||
#endif
|
|
||||||
|
|
||||||
bv->bv_len = lutil_gentime( bv->bv_val, bv->bv_len, ltm );
|
bv->bv_len = lutil_gentime( bv->bv_val, bv->bv_len, <m );
|
||||||
|
|
||||||
#ifndef HAVE_GMTIME_R
|
|
||||||
ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Called for all modify and modrdn ops. If the current op was replicated
|
/* Called for all modify and modrdn ops. If the current op was replicated
|
||||||
|
|
@ -876,7 +866,7 @@ void slap_mods_opattrs(
|
||||||
struct berval name, timestamp, csn = BER_BVNULL;
|
struct berval name, timestamp, csn = BER_BVNULL;
|
||||||
struct berval nname;
|
struct berval nname;
|
||||||
char timebuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
|
char timebuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
|
||||||
char csnbuf[ LDAP_LUTIL_CSNSTR_BUFSIZE ];
|
char csnbuf[ LDAP_PVT_CSNSTR_BUFSIZE ];
|
||||||
Modifications *mod, **modtail, *modlast;
|
Modifications *mod, **modtail, *modlast;
|
||||||
int gotcsn = 0, gotmname = 0, gotmtime = 0;
|
int gotcsn = 0, gotmname = 0, gotmtime = 0;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -615,7 +615,7 @@ accesslog_purge( void *ctx, void *arg )
|
||||||
AttributeAssertion ava = ATTRIBUTEASSERTION_INIT;
|
AttributeAssertion ava = ATTRIBUTEASSERTION_INIT;
|
||||||
purge_data pd = {0};
|
purge_data pd = {0};
|
||||||
char timebuf[LDAP_LUTIL_GENTIME_BUFSIZE];
|
char timebuf[LDAP_LUTIL_GENTIME_BUFSIZE];
|
||||||
char csnbuf[LDAP_LUTIL_CSNSTR_BUFSIZE];
|
char csnbuf[LDAP_PVT_CSNSTR_BUFSIZE];
|
||||||
time_t old = slap_get_time();
|
time_t old = slap_get_time();
|
||||||
|
|
||||||
connection_fake_init( &conn, &opbuf, ctx );
|
connection_fake_init( &conn, &opbuf, ctx );
|
||||||
|
|
|
||||||
|
|
@ -582,8 +582,8 @@ syncprov_findcsn( Operation *op, find_csn_t mode )
|
||||||
slap_callback cb = {0};
|
slap_callback cb = {0};
|
||||||
Operation fop;
|
Operation fop;
|
||||||
SlapReply frs = { REP_RESULT };
|
SlapReply frs = { REP_RESULT };
|
||||||
char buf[LDAP_LUTIL_CSNSTR_BUFSIZE + STRLENOF("(entryCSN<=)")];
|
char buf[LDAP_PVT_CSNSTR_BUFSIZE + STRLENOF("(entryCSN<=)")];
|
||||||
char cbuf[LDAP_LUTIL_CSNSTR_BUFSIZE];
|
char cbuf[LDAP_PVT_CSNSTR_BUFSIZE];
|
||||||
struct berval maxcsn;
|
struct berval maxcsn;
|
||||||
Filter cf;
|
Filter cf;
|
||||||
AttributeAssertion eq = ATTRIBUTEASSERTION_INIT;
|
AttributeAssertion eq = ATTRIBUTEASSERTION_INIT;
|
||||||
|
|
@ -1468,7 +1468,7 @@ syncprov_playlog( Operation *op, SlapReply *rs, sessionlog *sl,
|
||||||
slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
|
slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
|
||||||
slog_entry *se;
|
slog_entry *se;
|
||||||
int i, j, ndel, num, nmods, mmods;
|
int i, j, ndel, num, nmods, mmods;
|
||||||
char cbuf[LDAP_LUTIL_CSNSTR_BUFSIZE];
|
char cbuf[LDAP_PVT_CSNSTR_BUFSIZE];
|
||||||
BerVarray uuids;
|
BerVarray uuids;
|
||||||
struct berval delcsn[2];
|
struct berval delcsn[2];
|
||||||
|
|
||||||
|
|
@ -1643,7 +1643,7 @@ syncprov_op_response( Operation *op, SlapReply *rs )
|
||||||
if ( rs->sr_err == LDAP_SUCCESS )
|
if ( rs->sr_err == LDAP_SUCCESS )
|
||||||
{
|
{
|
||||||
struct berval maxcsn;
|
struct berval maxcsn;
|
||||||
char cbuf[LDAP_LUTIL_CSNSTR_BUFSIZE];
|
char cbuf[LDAP_PVT_CSNSTR_BUFSIZE];
|
||||||
int do_check = 0, have_psearches, foundit, csn_changed = 0;
|
int do_check = 0, have_psearches, foundit, csn_changed = 0;
|
||||||
|
|
||||||
/* Update our context CSN */
|
/* Update our context CSN */
|
||||||
|
|
@ -2786,7 +2786,7 @@ sp_cf_gen(ConfigArgs *c)
|
||||||
}
|
}
|
||||||
sl = si->si_logs;
|
sl = si->si_logs;
|
||||||
if ( !sl ) {
|
if ( !sl ) {
|
||||||
sl = ch_malloc( sizeof( sessionlog ) + LDAP_LUTIL_CSNSTR_BUFSIZE );
|
sl = ch_malloc( sizeof( sessionlog ) + LDAP_PVT_CSNSTR_BUFSIZE );
|
||||||
sl->sl_mincsn.bv_val = (char *)(sl+1);
|
sl->sl_mincsn.bv_val = (char *)(sl+1);
|
||||||
sl->sl_mincsn.bv_len = 0;
|
sl->sl_mincsn.bv_len = 0;
|
||||||
sl->sl_num = 0;
|
sl->sl_num = 0;
|
||||||
|
|
@ -2886,7 +2886,7 @@ syncprov_db_open(
|
||||||
|
|
||||||
/* Didn't find a contextCSN, should we generate one? */
|
/* Didn't find a contextCSN, should we generate one? */
|
||||||
if ( !si->si_ctxcsn ) {
|
if ( !si->si_ctxcsn ) {
|
||||||
char csnbuf[ LDAP_LUTIL_CSNSTR_BUFSIZE ];
|
char csnbuf[ LDAP_PVT_CSNSTR_BUFSIZE ];
|
||||||
struct berval csn;
|
struct berval csn;
|
||||||
|
|
||||||
if ( SLAP_SYNC_SHADOW( op->o_bd )) {
|
if ( SLAP_SYNC_SHADOW( op->o_bd )) {
|
||||||
|
|
|
||||||
|
|
@ -1977,8 +1977,6 @@ LDAP_SLAPD_V (int) slap_tool_thread_max;
|
||||||
|
|
||||||
LDAP_SLAPD_V (ldap_pvt_thread_mutex_t) entry2str_mutex;
|
LDAP_SLAPD_V (ldap_pvt_thread_mutex_t) entry2str_mutex;
|
||||||
|
|
||||||
LDAP_SLAPD_V (ldap_pvt_thread_mutex_t) gmtime_mutex;
|
|
||||||
|
|
||||||
LDAP_SLAPD_V (ldap_pvt_thread_mutex_t) ad_undef_mutex;
|
LDAP_SLAPD_V (ldap_pvt_thread_mutex_t) ad_undef_mutex;
|
||||||
LDAP_SLAPD_V (ldap_pvt_thread_mutex_t) oc_undef_mutex;
|
LDAP_SLAPD_V (ldap_pvt_thread_mutex_t) oc_undef_mutex;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -40,8 +40,8 @@
|
||||||
|
|
||||||
#include "slapcommon.h"
|
#include "slapcommon.h"
|
||||||
|
|
||||||
static char csnbuf[ LDAP_LUTIL_CSNSTR_BUFSIZE ];
|
static char csnbuf[ LDAP_PVT_CSNSTR_BUFSIZE ];
|
||||||
static char maxcsnbuf[ LDAP_LUTIL_CSNSTR_BUFSIZE * ( SLAP_SYNC_SID_MAX + 1 ) ];
|
static char maxcsnbuf[ LDAP_PVT_CSNSTR_BUFSIZE * ( SLAP_SYNC_SID_MAX + 1 ) ];
|
||||||
|
|
||||||
int
|
int
|
||||||
slapadd( int argc, char **argv )
|
slapadd( int argc, char **argv )
|
||||||
|
|
@ -120,7 +120,7 @@ slapadd( int argc, char **argv )
|
||||||
if ( update_ctxcsn ) {
|
if ( update_ctxcsn ) {
|
||||||
maxcsn[ 0 ].bv_val = maxcsnbuf;
|
maxcsn[ 0 ].bv_val = maxcsnbuf;
|
||||||
for ( sid = 1; sid <= SLAP_SYNC_SID_MAX; sid++ ) {
|
for ( sid = 1; sid <= SLAP_SYNC_SID_MAX; sid++ ) {
|
||||||
maxcsn[ sid ].bv_val = maxcsn[ sid - 1 ].bv_val + LDAP_LUTIL_CSNSTR_BUFSIZE;
|
maxcsn[ sid ].bv_val = maxcsn[ sid - 1 ].bv_val + LDAP_PVT_CSNSTR_BUFSIZE;
|
||||||
maxcsn[ sid ].bv_len = 0;
|
maxcsn[ sid ].bv_len = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -286,7 +286,7 @@ slapadd( int argc, char **argv )
|
||||||
nvals[1].bv_len = 0;
|
nvals[1].bv_len = 0;
|
||||||
nvals[1].bv_val = NULL;
|
nvals[1].bv_val = NULL;
|
||||||
|
|
||||||
csn.bv_len = lutil_csnstr( csnbuf, sizeof( csnbuf ), csnsid, 0 );
|
csn.bv_len = ldap_pvt_csnstr( csnbuf, sizeof( csnbuf ), csnsid, 0 );
|
||||||
csn.bv_val = csnbuf;
|
csn.bv_val = csnbuf;
|
||||||
|
|
||||||
timestamp.bv_val = timebuf;
|
timestamp.bv_val = timebuf;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue