fix normalization bug; change time stamping by using createTimestamp and modifyTimestamp (related to ITS#1984)

This commit is contained in:
Pierangelo Masarati 2002-07-25 09:49:02 +00:00
parent 7e81297147
commit 90f127472d

View File

@ -55,12 +55,9 @@ monitor_subsys_time_init(
Entry *e, *e_tmp, *e_time;
struct monitorentrypriv *mp;
char buf[1024], ztmbuf[20];
struct tm *ztm;
#ifdef HACK_LOCAL_TIME
struct tm *ltm;
char ltmbuf[20];
#endif
char buf[1024];
struct tm *tms;
char tmbuf[20];
/*
* Note: ltmbuf, ltm are used only if HACK_LOCAL_TIME is defined
@ -93,27 +90,21 @@ monitor_subsys_time_init(
* Start
*/
ldap_pvt_thread_mutex_lock( &gmtime_mutex );
ztm = gmtime( &starttime );
strftime( ztmbuf, sizeof(ztmbuf), "%Y%m%d%H%M%SZ", ztm );
#ifdef HACK_LOCAL_TIME
ltm = localtime( &starttime );
local_time( ltm, -timezone, ltmbuf, sizeof( ltmbuf ) );
#endif /* HACK_LOCAL_TIME */
tms = localtime( &starttime );
local_time( tms, -timezone, tmbuf, sizeof( tmbuf ) );
#else /* !HACK_LOCAL_TIME */
tms = gmtime( &starttime );
strftime( tmbuf, sizeof(tmbuf), "%Y%m%d%H%M%SZ", tms );
#endif /* !HACK_LOCAL_TIME */
ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
snprintf( buf, sizeof( buf ),
"dn: cn=Start,%s\n"
SLAPD_MONITOR_OBJECTCLASSES
"cn: Start\n"
"description: %s\n"
#ifdef HACK_LOCAL_TIME
"description;lang-x-local: %s"
#endif /* HACK_LOCAL_TIME */
, monitor_subsys[SLAPD_MONITOR_TIME].mss_dn.bv_val,
ztmbuf
#ifdef HACK_LOCAL_TIME
, ltmbuf
#endif /* HACK_LOCAL_TIME */
);
"createTimestamp: %s",
monitor_subsys[SLAPD_MONITOR_TIME].mss_dn.bv_val,
tmbuf );
e = str2entry( buf );
if ( e == NULL ) {
@ -165,16 +156,10 @@ monitor_subsys_time_init(
"dn: cn=Current,%s\n"
SLAPD_MONITOR_OBJECTCLASSES
"cn: Current\n"
"description: %s\n"
#ifdef HACK_LOCAL_TIME
"description;lang-x-local: %s"
#endif /* HACK_LOCAL_TIME */
, monitor_subsys[SLAPD_MONITOR_TIME].mss_dn.bv_val,
ztmbuf
#ifdef HACK_LOCAL_TIME
, ltmbuf
#endif /* HACK_LOCAL_TIME */
);
"createTimestamp: %s\n"
"modifyTimestamp: %s",
monitor_subsys[SLAPD_MONITOR_TIME].mss_dn.bv_val,
tmbuf, tmbuf );
e = str2entry( buf );
if ( e == NULL ) {
@ -233,77 +218,83 @@ monitor_subsys_time_update(
Entry *e
)
{
char ztmbuf[20];
struct tm *ztm;
#ifdef HACK_LOCAL_TIME
char ltmbuf[20];
struct tm *
#endif /* HACK_LOCAL_TIME */
time_t currenttime;
char stmbuf[20], ctmbuf[20];
struct tm *stm, *ctm;
Attribute *a;
#ifdef HACK_LOCAL_TIME
static AttributeDescription *ad_local = NULL;
const char *text = NULL;
#endif /* HACK_LOCAL_TIME */
ber_len_t len;
static int init_start = 0;
/*
* Note: ltmbuf, ltm, ad_local, text are used only if HACK_LOCAL_TIME
* is defined
*/
static int init_start = 0, init_current = 0;
#define ENTRY_TIME 0
#define ENTRY_START 1
#define ENTRY_CURRENT 2
int entry = ENTRY_TIME;
assert( mi );
assert( e );
if ( init_start == 0 && strncmp( e->e_nname.bv_val, "cn=START",
sizeof("cn=START")-1 ) == 0 ) {
currenttime = starttime;
init_start = 1;
if ( strncmp( e->e_nname.bv_val, "cn=start",
sizeof("cn=start")-1 ) == 0 ) {
entry = ENTRY_START;
if ( init_start == 1 ) {
return( 0 );
}
} else if ( strncmp( e->e_nname.bv_val, "cn=CURRENT",
sizeof("cn=CURRENT")-1 ) == 0 ) {
currenttime = slap_get_time();
} else {
return( 0 );
} else if ( strncmp( e->e_nname.bv_val, "cn=current",
sizeof("cn=current")-1 ) == 0 ) {
entry = ENTRY_CURRENT;
}
ldap_pvt_thread_mutex_lock( &gmtime_mutex );
if ( init_start == 0 ) {
#ifdef HACK_LOCAL_TIME
stm = localtime( &starttime );
local_time( stm, -timezone, stmbuf, sizeof( stmbuf ) );
#else /* !HACK_LOCAL_TIME */
stm = gmtime( &starttime );
strftime( stmbuf, sizeof( stmbuf ), "%Y%m%d%H%M%SZ", stm );
#endif /* !HACK_LOCAL_TIME */
}
ldap_pvt_thread_mutex_lock( &gmtime_mutex );
ztm = gmtime( &currenttime );
strftime( ztmbuf, sizeof( ztmbuf ), "%Y%m%d%H%M%SZ", ztm );
if ( entry == ENTRY_CURRENT ) {
time_t currentTime = slap_get_time();
#ifdef HACK_LOCAL_TIME
ltm = localtime( &currenttime );
local_time( ltm, -timezone, ltmbuf, sizeof( ltmbuf ) );
#endif /* HACK_LOCAL_TIME */
ctm = localtime( &currentTime );
local_time( ctm, -timezone, ctmbuf, sizeof( ctmbuf ) );
#else /* !HACK_LOCAL_TIME */
ctm = gmtime( &currentTime );
strftime( ctmbuf, sizeof( ctmbuf ), "%Y%m%d%H%M%SZ", ctm );
#endif /* !HACK_LOCAL_TIME */
}
ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
a = attr_find( e->e_attrs, monitor_ad_desc );
if ( a == NULL ) {
return( -1 );
}
len = strlen( ztmbuf );
assert( len == a->a_vals[0].bv_len );
AC_MEMCPY( a->a_vals[0].bv_val, ztmbuf, len );
#ifdef HACK_LOCAL_TIME
if ( ad_local == NULL ) {
if ( slap_str2ad( "description;lang-x-local",
&ad_local, &text ) != LDAP_SUCCESS ) {
if ( ( entry == ENTRY_START && init_start == 0 )
|| ( entry == ENTRY_CURRENT && init_current == 0 ) ) {
a = attr_find( e->e_attrs, slap_schema.si_ad_createTimestamp );
if ( a == NULL ) {
return( -1 );
}
}
a = attr_find( e->e_attrs, ad_local );
if ( a == NULL ) {
return( -1 );
len = strlen( stmbuf );
assert( len == a->a_vals[0].bv_len );
AC_MEMCPY( a->a_vals[0].bv_val, stmbuf, len );
if ( entry == ENTRY_START ) {
init_start = 1;
} else if ( entry == ENTRY_CURRENT ) {
init_current = 1;
}
}
len = strlen( ltmbuf );
assert( len == a->a_vals[0].bv_len );
AC_MEMCPY( a->a_vals[0].bv_val, ltmbuf, len );
#endif /* HACK_LOCAL_TIME */
if ( entry == ENTRY_CURRENT ) {
a = attr_find( e->e_attrs, slap_schema.si_ad_modifyTimestamp );
if ( a == NULL ) {
return( -1 );
}
len = strlen( ctmbuf );
assert( len == a->a_vals[0].bv_len );
AC_MEMCPY( a->a_vals[0].bv_val, ctmbuf, len );
}
return( 0 );
}