1 /* time.c - deal with time subsystem */
3 * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
7 * Copyright 2001, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
9 * This work has beed deveolped for the OpenLDAP Foundation
10 * in the hope that it may be useful to the Open Source community,
11 * but WITHOUT ANY WARRANTY.
13 * Permission is granted to anyone to use this software for any purpose
14 * on any computer system, and to alter it and redistribute it, subject
15 * to the following restrictions:
17 * 1. The author and SysNet s.n.c. are not responsible for the consequences
18 * of use of this software, no matter how awful, even if they arise from
21 * 2. The origin of this software must not be misrepresented, either by
22 * explicit claim or by omission. Since few users ever read sources,
23 * credits should appear in the documentation.
25 * 3. Altered versions must be plainly marked as such, and must not be
26 * misrepresented as being the original software. Since few users
27 * ever read sources, credits should appear in the documentation.
28 * SysNet s.n.c. cannot be responsible for the consequences of the
31 * 4. This notice may not be removed or altered.
37 #include <ac/string.h>
43 #include "proto-slap.h"
44 #include "back-monitor.h"
47 monitor_subsys_time_init(
51 struct monitorinfo *mi;
53 Entry *e, *e_tmp, *e_time;
54 struct monitorentrypriv *mp;
55 char buf[ BACKMONITOR_BUFSIZE ];
59 mi = ( struct monitorinfo * )be->be_private;
61 if ( monitor_cache_get( mi,
62 &monitor_subsys[SLAPD_MONITOR_TIME].mss_ndn, &e_time ) ) {
64 LDAP_LOG( OPERATION, CRIT,
65 "monitor_subsys_time_init: "
66 "unable to get entry '%s'\n",
67 monitor_subsys[SLAPD_MONITOR_TIME].mss_ndn.bv_val, 0, 0 );
69 Debug( LDAP_DEBUG_ANY,
70 "monitor_subsys_time_init: "
71 "unable to get entry '%s'\n%s%s",
72 monitor_subsys[SLAPD_MONITOR_TIME].mss_ndn.bv_val,
80 snprintf( buf, sizeof( buf ),
83 "structuralObjectClass: %s\n"
86 "createTimestamp: %s\n"
87 "modifyTimestamp: %s\n",
88 monitor_subsys[SLAPD_MONITOR_TIME].mss_dn.bv_val,
89 mi->mi_oc_monitoredObject->soc_cname.bv_val,
90 mi->mi_oc_monitoredObject->soc_cname.bv_val,
91 mi->mi_ad_monitorTimestamp->ad_cname.bv_val,
92 mi->mi_startTime.bv_val,
93 mi->mi_startTime.bv_val,
94 mi->mi_startTime.bv_val );
99 LDAP_LOG( OPERATION, CRIT,
100 "monitor_subsys_time_init: "
101 "unable to create entry 'cn=Start,%s'\n",
102 monitor_subsys[SLAPD_MONITOR_TIME].mss_ndn.bv_val, 0, 0 );
104 Debug( LDAP_DEBUG_ANY,
105 "monitor_subsys_time_init: "
106 "unable to create entry 'cn=Start,%s'\n%s%s",
107 monitor_subsys[SLAPD_MONITOR_TIME].mss_ndn.bv_val,
113 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
114 e->e_private = ( void * )mp;
116 mp->mp_children = NULL;
117 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_TIME];
118 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_TIME].mss_flags \
119 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
121 if ( monitor_cache_add( mi, e ) ) {
123 LDAP_LOG( OPERATION, CRIT,
124 "monitor_subsys_time_init: "
125 "unable to add entry 'cn=Start,%s'\n",
126 monitor_subsys[SLAPD_MONITOR_TIME].mss_ndn.bv_val, 0, 0 );
128 Debug( LDAP_DEBUG_ANY,
129 "monitor_subsys_time_init: "
130 "unable to add entry 'cn=Start,%s'\n%s%s",
131 monitor_subsys[SLAPD_MONITOR_TIME].mss_ndn.bv_val,
142 snprintf( buf, sizeof( buf ),
143 "dn: cn=Current,%s\n"
145 "structuralObjectClass: %s\n"
148 "createTimestamp: %s\n"
149 "modifyTimestamp: %s\n",
150 monitor_subsys[SLAPD_MONITOR_TIME].mss_dn.bv_val,
151 mi->mi_oc_monitoredObject->soc_cname.bv_val,
152 mi->mi_oc_monitoredObject->soc_cname.bv_val,
153 mi->mi_ad_monitorTimestamp->ad_cname.bv_val,
154 mi->mi_startTime.bv_val,
155 mi->mi_startTime.bv_val,
156 mi->mi_startTime.bv_val );
158 e = str2entry( buf );
161 LDAP_LOG( OPERATION, CRIT,
162 "monitor_subsys_time_init: "
163 "unable to create entry 'cn=Current,%s'\n",
164 monitor_subsys[SLAPD_MONITOR_TIME].mss_ndn.bv_val, 0, 0 );
166 Debug( LDAP_DEBUG_ANY,
167 "monitor_subsys_time_init: "
168 "unable to create entry 'cn=Current,%s'\n%s%s",
169 monitor_subsys[SLAPD_MONITOR_TIME].mss_ndn.bv_val,
175 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
176 e->e_private = ( void * )mp;
178 mp->mp_children = NULL;
179 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_TIME];
180 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_TIME].mss_flags \
181 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
183 if ( monitor_cache_add( mi, e ) ) {
185 LDAP_LOG( OPERATION, CRIT,
186 "monitor_subsys_time_init: "
187 "unable to add entry 'cn=Current,%s'\n",
188 monitor_subsys[SLAPD_MONITOR_TIME].mss_ndn.bv_val, 0, 0 );
190 Debug( LDAP_DEBUG_ANY,
191 "monitor_subsys_time_init: "
192 "unable to add entry 'cn=Current,%s'\n%s%s",
193 monitor_subsys[SLAPD_MONITOR_TIME].mss_ndn.bv_val,
201 mp = ( struct monitorentrypriv * )e_time->e_private;
202 mp->mp_children = e_tmp;
204 monitor_cache_release( mi, e_time );
210 monitor_subsys_time_update(
215 struct monitorinfo *mi = (struct monitorinfo *)op->o_bd->be_private;
220 if ( strncmp( e->e_nname.bv_val, "cn=current",
221 sizeof("cn=current") - 1 ) == 0 ) {
223 char tmbuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
228 currtime = slap_get_time();
230 ldap_pvt_thread_mutex_lock( &gmtime_mutex );
231 #ifdef HACK_LOCAL_TIME
232 tm = localtime( &currtime );
233 lutil_localtime( tmbuf, sizeof( tmbuf ), tm, -timezone );
234 #else /* !HACK_LOCAL_TIME */
235 tm = gmtime( &currtime );
236 lutil_gentime( tmbuf, sizeof( tmbuf ), tm );
237 #endif /* !HACK_LOCAL_TIME */
238 ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
240 len = strlen( tmbuf );
242 a = attr_find( e->e_attrs, mi->mi_ad_monitorTimestamp );
247 assert( len == a->a_vals[0].bv_len );
248 AC_MEMCPY( a->a_vals[0].bv_val, tmbuf, len );