From 90f127472dc447d797ed09da4b496320f8411157 Mon Sep 17 00:00:00 2001 From: Pierangelo Masarati Date: Thu, 25 Jul 2002 09:49:02 +0000 Subject: [PATCH] fix normalization bug; change time stamping by using createTimestamp and modifyTimestamp (related to ITS#1984) --- servers/slapd/back-monitor/time.c | 159 ++++++++++++++---------------- 1 file changed, 75 insertions(+), 84 deletions(-) diff --git a/servers/slapd/back-monitor/time.c b/servers/slapd/back-monitor/time.c index ea76d6ee8d..9d2490ff51 100644 --- a/servers/slapd/back-monitor/time.c +++ b/servers/slapd/back-monitor/time.c @@ -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; - - } else if ( strncmp( e->e_nname.bv_val, "cn=CURRENT", - sizeof("cn=CURRENT")-1 ) == 0 ) { - currenttime = slap_get_time(); + if ( strncmp( e->e_nname.bv_val, "cn=start", + sizeof("cn=start")-1 ) == 0 ) { + entry = ENTRY_START; + if ( init_start == 1 ) { + return( 0 ); + } - } 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 ); - ztm = gmtime( ¤ttime ); - strftime( ztmbuf, sizeof( ztmbuf ), "%Y%m%d%H%M%SZ", ztm ); + if ( init_start == 0 ) { #ifdef HACK_LOCAL_TIME - ltm = localtime( ¤ttime ); - local_time( ltm, -timezone, ltmbuf, sizeof( ltmbuf ) ); -#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 ); + 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 */ } - len = strlen( ztmbuf ); - assert( len == a->a_vals[0].bv_len ); - AC_MEMCPY( a->a_vals[0].bv_val, ztmbuf, len ); - + if ( entry == ENTRY_CURRENT ) { + time_t currentTime = slap_get_time(); #ifdef HACK_LOCAL_TIME - if ( ad_local == NULL ) { - if ( slap_str2ad( "description;lang-x-local", - &ad_local, &text ) != LDAP_SUCCESS ) { + ctm = localtime( ¤tTime ); + local_time( ctm, -timezone, ctmbuf, sizeof( ctmbuf ) ); +#else /* !HACK_LOCAL_TIME */ + ctm = gmtime( ¤tTime ); + strftime( ctmbuf, sizeof( ctmbuf ), "%Y%m%d%H%M%SZ", ctm ); +#endif /* !HACK_LOCAL_TIME */ + } + ldap_pvt_thread_mutex_unlock( &gmtime_mutex ); + + 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 ); } -- 2.39.5