]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-monitor/time.c
Changed ldap_pvt_tls_get_my_dn and ldap_pvt_tls_get_peer_dn to store result
[openldap] / servers / slapd / back-monitor / time.c
index 0da78a8318ca7d8122b9cba0de277a5a42474e27..8bd0b8045d4401dbfdc1eb768fd0279b75c19a0c 100644 (file)
 #include "proto-slap.h"
 #include "back-monitor.h"
 
+#ifdef HACK_LOCAL_TIME
+static int
+local_time( const struct tm *ztm, long delta, char *buf, size_t len );
+#endif /* HACK_LOCAL_TIME */
+
 int
 monitor_subsys_time_init(
        BackendDB               *be
@@ -50,8 +55,16 @@ monitor_subsys_time_init(
        
        Entry                   *e, *e_tmp, *e_time;
        struct monitorentrypriv *mp;
-       char                    buf[1024], tmbuf[20];
+       char                    buf[1024], ztmbuf[20];
+       struct tm               *ztm;
+#ifdef HACK_LOCAL_TIME
        struct tm               *ltm;
+       char                    ltmbuf[20];
+#endif
+
+       /*
+        * Note: ltmbuf, ltm are used only if HACK_LOCAL_TIME is defined
+        */
 
        assert( be != NULL );
 
@@ -80,16 +93,27 @@ monitor_subsys_time_init(
         * Start
         */
        ldap_pvt_thread_mutex_lock( &gmtime_mutex );
-       ltm = gmtime( &starttime );
-       strftime( tmbuf, sizeof(tmbuf), "%Y%m%d%H%M%SZ", ltm );
+       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 */
        ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
        snprintf( buf, sizeof( buf ),
                        "dn: cn=Start,%s\n"
                        SLAPD_MONITOR_OBJECTCLASSES
                        "cn: Start\n"
-                       "description: %s",
-                       monitor_subsys[SLAPD_MONITOR_TIME].mss_dn.bv_val,
-                       tmbuf );
+                       "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 */
+                       );
 
        e = str2entry( buf );
        if ( e == NULL ) {
@@ -141,9 +165,16 @@ monitor_subsys_time_init(
                        "dn: cn=Current,%s\n"
                        SLAPD_MONITOR_OBJECTCLASSES
                        "cn: Current\n"
-                       "description: %s",
-                       monitor_subsys[SLAPD_MONITOR_TIME].mss_dn.bv_val,
-                       tmbuf );
+                       "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 */
+                       );
 
        e = str2entry( buf );
        if ( e == NULL ) {
@@ -202,15 +233,27 @@ monitor_subsys_time_update(
        Entry                   *e
 )
 {
-       char            tmbuf[20];
-       struct tm       *ltm;
+       char            ztmbuf[20];
+       struct tm       *ztm;
+#ifdef HACK_LOCAL_TIME
+       char            ltmbuf[20];
+       struct tm       *
+#endif /* HACK_LOCAL_TIME */
        time_t          currenttime;
-       struct berval   bv[ 2 ];
        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
+        */
+
        assert( mi );
        assert( e );
        
@@ -227,21 +270,71 @@ monitor_subsys_time_update(
                return( 0 );
        }
 
+       ldap_pvt_thread_mutex_lock( &gmtime_mutex );
+       ztm = gmtime( &currenttime );
+       strftime( ztmbuf, sizeof( ztmbuf ), "%Y%m%d%H%M%SZ", ztm );
+#ifdef HACK_LOCAL_TIME
+       ltm = localtime( &currenttime );
+       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 );
        }
 
+       len = strlen( ztmbuf );
+       assert( len == a->a_vals[0].bv_len );
+       AC_MEMCPY( a->a_vals[0].bv_val, ztmbuf, len );
 
-       ldap_pvt_thread_mutex_lock( &gmtime_mutex );
-       ltm = gmtime( &currenttime );
-       strftime( tmbuf, sizeof(tmbuf), "%Y%m%d%H%M%SZ", ltm );
-       ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
+#ifdef HACK_LOCAL_TIME
+       if ( ad_local == NULL ) {
+               if ( slap_str2ad( "description;lang-x-local", 
+                                       &ad_local, &text ) != LDAP_SUCCESS ) {
+                       return( -1 );
+               }
+       }
+       a = attr_find( e->e_attrs, ad_local );
+       if ( a == NULL ) {
+               return( -1 );
+       }
 
-       len = strlen( tmbuf );
+       len = strlen( ltmbuf );
        assert( len == a->a_vals[0].bv_len );
-       AC_MEMCPY( a->a_vals[0].bv_val, tmbuf, len );
+       AC_MEMCPY( a->a_vals[0].bv_val, ltmbuf, len );
+#endif /* HACK_LOCAL_TIME */
 
        return( 0 );
 }
 
+#ifdef HACK_LOCAL_TIME
+/*
+ * assumes gmtime_mutex is locked
+ */
+static int
+local_time( const struct tm *ltm, long delta, char *buf, size_t len )
+{
+       char *p;
+
+       if ( len < 20 ) {
+               return -1;
+       }
+       strftime( buf, len, "%Y%m%d%H%M%S", ltm );
+
+       p = buf + 14;
+
+       if ( delta < 0 ) {
+               p[ 0 ] = '-';
+               delta = -delta;
+       } else {
+               p[ 0 ] = '+';
+       }
+       p++;
+
+       snprintf( p, len - 15, "%02ld%02ld", delta / 3600, delta % 3600 );
+       
+       return 0;
+}
+#endif /* HACK_LOCAL_TIME */
+