1 /* time.c - deal with time subsystem */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2001-2006 The OpenLDAP Foundation.
6 * Portions Copyright 2001-2003 Pierangelo Masarati.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted only as authorized by the OpenLDAP
13 * A copy of this license is available in file LICENSE in the
14 * top-level directory of the distribution or, alternatively, at
15 * <http://www.OpenLDAP.org/license.html>.
18 * This work was initially developed by Pierangelo Masarati for inclusion
19 * in OpenLDAP Software.
25 #include <ac/string.h>
31 #include "proto-slap.h"
32 #include "back-monitor.h"
35 monitor_subsys_time_update(
41 monitor_subsys_time_init(
43 monitor_subsys_t *ms )
47 Entry *e, **ep, *e_time;
49 char buf[ BACKMONITOR_BUFSIZE ];
53 ms->mss_update = monitor_subsys_time_update;
55 mi = ( monitor_info_t * )be->be_private;
57 if ( monitor_cache_get( mi,
58 &ms->mss_ndn, &e_time ) ) {
59 Debug( LDAP_DEBUG_ANY,
60 "monitor_subsys_time_init: "
61 "unable to get entry \"%s\"\n",
62 ms->mss_ndn.bv_val, 0, 0 );
66 mp = ( monitor_entry_t * )e_time->e_private;
67 mp->mp_children = NULL;
68 ep = &mp->mp_children;
70 snprintf( buf, sizeof( buf ),
73 "structuralObjectClass: %s\n"
78 "createTimestamp: %s\n"
79 "modifyTimestamp: %s\n",
81 mi->mi_oc_monitoredObject->soc_cname.bv_val,
82 mi->mi_oc_monitoredObject->soc_cname.bv_val,
83 mi->mi_ad_monitorTimestamp->ad_cname.bv_val,
84 mi->mi_startTime.bv_val,
85 mi->mi_creatorsName.bv_val,
86 mi->mi_creatorsName.bv_val,
87 mi->mi_startTime.bv_val,
88 mi->mi_startTime.bv_val );
92 Debug( LDAP_DEBUG_ANY,
93 "monitor_subsys_time_init: "
94 "unable to create entry \"cn=Start,%s\"\n",
95 ms->mss_ndn.bv_val, 0, 0 );
99 mp = monitor_entrypriv_create();
103 e->e_private = ( void * )mp;
105 mp->mp_flags = ms->mss_flags \
106 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
108 if ( monitor_cache_add( mi, e ) ) {
109 Debug( LDAP_DEBUG_ANY,
110 "monitor_subsys_time_init: "
111 "unable to add entry \"cn=Start,%s\"\n",
112 ms->mss_ndn.bv_val, 0, 0 );
122 snprintf( buf, sizeof( buf ),
123 "dn: cn=Current,%s\n"
125 "structuralObjectClass: %s\n"
129 "modifiersName: %s\n"
130 "createTimestamp: %s\n"
131 "modifyTimestamp: %s\n",
133 mi->mi_oc_monitoredObject->soc_cname.bv_val,
134 mi->mi_oc_monitoredObject->soc_cname.bv_val,
135 mi->mi_ad_monitorTimestamp->ad_cname.bv_val,
136 mi->mi_startTime.bv_val,
137 mi->mi_creatorsName.bv_val,
138 mi->mi_creatorsName.bv_val,
139 mi->mi_startTime.bv_val,
140 mi->mi_startTime.bv_val );
142 e = str2entry( buf );
144 Debug( LDAP_DEBUG_ANY,
145 "monitor_subsys_time_init: "
146 "unable to create entry \"cn=Current,%s\"\n",
147 ms->mss_ndn.bv_val, 0, 0 );
151 mp = monitor_entrypriv_create();
155 e->e_private = ( void * )mp;
157 mp->mp_flags = ms->mss_flags \
158 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
160 if ( monitor_cache_add( mi, e ) ) {
161 Debug( LDAP_DEBUG_ANY,
162 "monitor_subsys_time_init: "
163 "unable to add entry \"cn=Current,%s\"\n",
164 ms->mss_ndn.bv_val, 0, 0 );
171 monitor_cache_release( mi, e_time );
177 monitor_subsys_time_update(
182 monitor_info_t *mi = ( monitor_info_t * )op->o_bd->be_private;
183 static struct berval bv_current = BER_BVC( "cn=current" );
186 assert( mi != NULL );
189 dnRdn( &e->e_nname, &rdn );
191 if ( dn_match( &rdn, &bv_current ) ) {
196 char tmbuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
201 currtime = slap_get_time();
203 #ifndef HAVE_GMTIME_R
204 ldap_pvt_thread_mutex_lock( &gmtime_mutex );
206 #ifdef HACK_LOCAL_TIME
207 # ifdef HAVE_LOCALTIME_R
208 tm = localtime_r( &currtime, &tm_buf );
210 tm = localtime( &currtime );
211 # endif /* HAVE_LOCALTIME_R */
212 lutil_localtime( tmbuf, sizeof( tmbuf ), tm, -timezone );
213 #else /* !HACK_LOCAL_TIME */
214 # ifdef HAVE_GMTIME_R
215 tm = gmtime_r( &currtime, &tm_buf );
217 tm = gmtime( &currtime );
218 # endif /* HAVE_GMTIME_R */
219 lutil_gentime( tmbuf, sizeof( tmbuf ), tm );
220 #endif /* !HACK_LOCAL_TIME */
221 #ifndef HAVE_GMTIME_R
222 ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
225 len = strlen( tmbuf );
227 a = attr_find( e->e_attrs, mi->mi_ad_monitorTimestamp );
229 return rs->sr_err = LDAP_OTHER;
232 assert( len == a->a_vals[ 0 ].bv_len );
233 AC_MEMCPY( a->a_vals[ 0 ].bv_val, tmbuf, len );
235 /* FIXME: touch modifyTimestamp? */
238 return SLAP_CB_CONTINUE;