1 /* lastmod.c - returns last modification info */
2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 2004 The OpenLDAP Foundation.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted only as authorized by the OpenLDAP
11 * A copy of this license is available in the file LICENSE in the
12 * top-level directory of the distribution or, alternatively, at
13 * <http://www.OpenLDAP.org/license.html>.
16 * This work was initially developed by Pierangelo Masarati for inclusion in
22 #ifdef SLAPD_OVER_LASTMOD
26 #include <ac/string.h>
27 #include <ac/socket.h>
32 typedef struct lastmod_info_t {
33 struct berval lmi_rdnvalue;
35 ldap_pvt_thread_mutex_t lmi_entry_mutex;
39 struct lastmod_schema_t {
40 ObjectClass *lms_oc_lastmod;
41 AttributeDescription *lms_ad_lastmodDN;
42 AttributeDescription *lms_ad_lastmodType;
43 AttributeDescription *lms_ad_lastmodEnabled;
55 struct berval lastmodType[] = {
71 { "lastmod", "( 1.3.6.1.4.1.4203.666.3.13"
73 "DESC 'OpenLDAP per-database last modification monitoring' "
82 ") )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
83 offsetof( struct lastmod_schema_t, lms_oc_lastmod ) },
86 { "lastmodDN", "( 1.3.6.1.4.1.4203.666.1.28"
88 "DESC 'DN of last modification' "
89 "EQUALITY distinguishedNameMatch "
90 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 "
91 "NO-USER-MODIFICATION "
92 "USAGE directoryOperation )", SLAP_AT_HIDE,
93 offsetof( struct lastmod_schema_t, lms_ad_lastmodDN ) },
94 { "lastmodType", "( 1.3.6.1.4.1.4203.666.1.29"
96 "DESC 'Type of last modification' "
97 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 "
98 "EQUALITY caseIgnoreMatch "
100 "NO-USER-MODIFICATION "
101 "USAGE directoryOperation )", SLAP_AT_HIDE,
102 offsetof( struct lastmod_schema_t, lms_ad_lastmodType ) },
103 { "lastmodEnabled", "( 1.3.6.1.4.1.4203.666.1.30"
104 "NAME 'lastmodEnabled' "
105 "DESC 'Lastmod overlay state' "
106 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 "
107 "EQUALITY booleanMatch "
109 offsetof( struct lastmod_schema_t, lms_ad_lastmodEnabled ) },
114 lastmod_search( Operation *op, SlapReply *rs )
116 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
117 lastmod_info_t *lmi = (lastmod_info_t *)on->on_bi.bi_private;
120 /* if we get here, it must be a success */
121 rs->sr_err = LDAP_SUCCESS;
123 ldap_pvt_thread_mutex_lock( &lmi->lmi_entry_mutex );
125 rc = test_filter( op, lmi->lmi_e, op->oq_search.rs_filter );
126 if ( rc == LDAP_COMPARE_TRUE ) {
127 rs->sr_attrs = op->ors_attrs;
129 rs->sr_entry = lmi->lmi_e;
130 rs->sr_err = send_search_entry( op, rs );
136 ldap_pvt_thread_mutex_unlock( &lmi->lmi_entry_mutex );
138 send_ldap_result( op, rs );
144 lastmod_compare( Operation *op, SlapReply *rs )
146 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
147 lastmod_info_t *lmi = (lastmod_info_t *)on->on_bi.bi_private;
150 ldap_pvt_thread_mutex_lock( &lmi->lmi_entry_mutex );
152 if ( get_assert( op ) &&
153 ( test_filter( op, lmi->lmi_e, get_assertion( op ) ) != LDAP_COMPARE_TRUE ) )
155 rs->sr_err = LDAP_ASSERTION_FAILED;
159 rs->sr_err = access_allowed( op, lmi->lmi_e, op->oq_compare.rs_ava->aa_desc,
160 &op->oq_compare.rs_ava->aa_value, ACL_COMPARE, NULL );
161 if ( ! rs->sr_err ) {
162 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
166 rs->sr_err = LDAP_NO_SUCH_ATTRIBUTE;
168 for ( a = attr_find( lmi->lmi_e->e_attrs, op->oq_compare.rs_ava->aa_desc );
170 a = attr_find( a->a_next, op->oq_compare.rs_ava->aa_desc ) )
172 rs->sr_err = LDAP_COMPARE_FALSE;
174 if ( value_find_ex( op->oq_compare.rs_ava->aa_desc,
175 SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
176 SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
177 a->a_nvals, &op->oq_compare.rs_ava->aa_value, op->o_tmpmemctx ) == 0 )
179 rs->sr_err = LDAP_COMPARE_TRUE;
186 ldap_pvt_thread_mutex_unlock( &lmi->lmi_entry_mutex );
188 send_ldap_result( op, rs );
190 if( rs->sr_err == LDAP_COMPARE_FALSE || rs->sr_err == LDAP_COMPARE_TRUE ) {
191 rs->sr_err = LDAP_SUCCESS;
198 lastmod_exop( Operation *op, SlapReply *rs )
200 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
204 op->o_bd->bd_info = (BackendInfo *)on->on_info;
205 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
206 rs->sr_text = "not allowed within namingContext";
207 send_ldap_result( op, rs );
214 lastmod_modify( Operation *op, SlapReply *rs )
216 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
217 lastmod_info_t *lmi = (lastmod_info_t *)on->on_bi.bi_private;
220 ldap_pvt_thread_mutex_lock( &lmi->lmi_entry_mutex );
222 if ( !acl_check_modlist( op, lmi->lmi_e, op->orm_modlist ) ) {
223 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
227 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
230 if ( ml->sml_desc != lastmod_schema.lms_ad_lastmodEnabled ) {
234 if ( ml->sml_op != LDAP_MOD_REPLACE ) {
235 rs->sr_text = "unsupported mod type";
236 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
240 a = attr_find( lmi->lmi_e->e_attrs, ml->sml_desc );
243 rs->sr_text = "lastmod overlay internal error";
244 rs->sr_err = LDAP_OTHER;
248 ch_free( a->a_vals[ 0 ].bv_val );
249 ber_dupbv( &a->a_vals[ 0 ], &ml->sml_values[ 0 ] );
251 ch_free( a->a_nvals[ 0 ].bv_val );
252 if ( ml->sml_nvalues && !BER_BVISNULL( &ml->sml_nvalues[ 0 ] ) ) {
253 ber_dupbv( &a->a_nvals[ 0 ], &ml->sml_nvalues[ 0 ] );
255 ber_dupbv( &a->a_nvals[ 0 ], &ml->sml_values[ 0 ] );
259 if ( strcmp( ml->sml_values[ 0 ].bv_val, "TRUE" ) == 0 ) {
260 lmi->lmi_enabled = 1;
261 } else if ( strcmp( ml->sml_values[ 0 ].bv_val, "FALSE" ) == 0 ) {
262 lmi->lmi_enabled = 0;
268 rs->sr_err = LDAP_SUCCESS;
271 ldap_pvt_thread_mutex_unlock( &lmi->lmi_entry_mutex );
273 send_ldap_result( op, rs );
280 lastmod_op_func( Operation *op, SlapReply *rs )
282 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
283 lastmod_info_t *lmi = (lastmod_info_t *)on->on_bi.bi_private;
287 if ( dn_match( &op->o_req_ndn, &lmi->lmi_e->e_nname ) ) {
288 switch ( op->o_tag ) {
289 case LDAP_REQ_SEARCH:
290 if ( op->ors_scope != LDAP_SCOPE_BASE ) {
291 goto return_referral;
294 return lastmod_search( op, rs );
296 case LDAP_REQ_COMPARE:
297 return lastmod_compare( op, rs );
299 case LDAP_REQ_EXTENDED:
300 /* if write, reject; otherwise process */
301 if ( exop_is_write( op )) {
302 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
303 rs->sr_text = "not allowed within namingContext";
306 return lastmod_exop( op, rs );
308 case LDAP_REQ_MODIFY:
309 /* if global overlay, modlist is not checked yet */
310 if ( op->orm_modlist->sml_desc == NULL ) {
311 char textbuf[SLAP_TEXT_BUFLEN];
312 size_t textlen = sizeof textbuf;
314 rs->sr_err = slap_mods_check( op->orm_modlist, 0, &rs->sr_text,
315 textbuf, textlen, NULL );
322 /* allow only changes to overlay status */
323 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
324 if ( ad_cmp( ml->sml_desc, slap_schema.si_ad_modifiersName ) != 0
325 && ad_cmp( ml->sml_desc, slap_schema.si_ad_modifyTimestamp ) != 0
326 && ad_cmp( ml->sml_desc, slap_schema.si_ad_entryCSN ) != 0
327 && ad_cmp( ml->sml_desc, lastmod_schema.lms_ad_lastmodEnabled ) != 0 )
329 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
330 rs->sr_text = "not allowed within namingContext";
334 return lastmod_modify( op, rs );
337 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
338 rs->sr_text = "not allowed within namingContext";
343 if ( dnIsSuffix( &op->o_req_ndn, &lmi->lmi_e->e_nname ) ) {
344 goto return_referral;
347 return SLAP_CB_CONTINUE;
350 op->o_bd->bd_info = (BackendInfo *)on->on_info;
351 rs->sr_ref = referral_rewrite( default_referral,
352 NULL, &op->o_req_dn, op->ors_scope );
355 rs->sr_ref = default_referral;
357 rs->sr_err = LDAP_REFERRAL;
358 send_ldap_result( op, rs );
360 if ( rs->sr_ref != default_referral ) {
361 ber_bvarray_free( rs->sr_ref );
368 op->o_bd->bd_info = (BackendInfo *)on->on_info;
369 send_ldap_result( op, rs );
376 best_guess( Operation *op,
377 struct berval *bv_modifyTimestamp, struct berval *bv_nmodifyTimestamp,
378 struct berval *bv_modifiersName, struct berval *bv_nmodifiersName )
380 if ( bv_modifyTimestamp ) {
385 char tmbuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
390 currtime = slap_get_time();
392 /* maybe we better use the time the operation was initiated */
393 currtime = op->o_time;
395 #ifndef HAVE_GMTIME_R
396 ldap_pvt_thread_mutex_lock( &gmtime_mutex );
397 tm = gmtime( &currtime );
398 #else /* HAVE_GMTIME_R */
399 tm = gmtime_r( &currtime, &tm_buf );
400 #endif /* HAVE_GMTIME_R */
401 lutil_gentime( tmbuf, sizeof( tmbuf ), tm );
402 #ifndef HAVE_GMTIME_R
403 ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
406 ber_str2bv( tmbuf, 0, 1, bv_modifyTimestamp );
407 ber_dupbv( bv_nmodifyTimestamp, bv_modifyTimestamp );
410 if ( bv_modifiersName ) {
412 ber_dupbv( bv_modifiersName, &op->o_dn );
413 ber_dupbv( bv_nmodifiersName, &op->o_ndn );
420 lastmod_update( Operation *op, SlapReply *rs )
422 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
423 lastmod_info_t *lmi = (lastmod_info_t *)on->on_bi.bi_private;
425 Modifications *ml = NULL;
426 struct berval bv_modifyTimestamp = BER_BVNULL,
427 bv_nmodifyTimestamp = BER_BVNULL,
428 bv_modifiersName = BER_BVNULL,
429 bv_nmodifiersName = BER_BVNULL,
430 bv_name = BER_BVNULL,
431 bv_nname = BER_BVNULL;
432 enum lastmodType_e lmt = LASTMOD_UNKNOWN;
436 /* FIXME: timestamp? modifier? */
437 switch ( op->o_tag ) {
441 a = attr_find( e->e_attrs, slap_schema.si_ad_modifiersName );
443 ber_dupbv( &bv_modifiersName, &a->a_vals[0] );
444 ber_dupbv( &bv_nmodifiersName, &a->a_nvals[0] );
446 a = attr_find( e->e_attrs, slap_schema.si_ad_modifyTimestamp );
448 ber_dupbv( &bv_modifyTimestamp, &a->a_vals[0] );
449 if ( a->a_nvals && !BER_BVISNULL( &a->a_nvals[0] ) ) {
450 ber_dupbv( &bv_nmodifyTimestamp, &a->a_nvals[0] );
452 ber_dupbv( &bv_nmodifyTimestamp, &a->a_vals[0] );
455 ber_dupbv( &bv_name, &e->e_name );
456 ber_dupbv( &bv_nname, &e->e_nname );
459 case LDAP_REQ_DELETE:
460 lmt = LASTMOD_DELETE;
462 best_guess( op, &bv_modifyTimestamp, &bv_nmodifyTimestamp,
463 &bv_modifiersName, &bv_nmodifiersName );
465 ber_dupbv( &bv_name, &op->o_req_dn );
466 ber_dupbv( &bv_nname, &op->o_req_ndn );
469 case LDAP_REQ_EXTENDED:
472 /* actually, password change is wrapped around a backend
473 * call to modify, so it never shows up as an exop... */
474 best_guess( op, &bv_modifyTimestamp, &bv_nmodifyTimestamp,
475 &bv_modifiersName, &bv_nmodifiersName );
477 ber_dupbv( &bv_name, &op->o_req_dn );
478 ber_dupbv( &bv_nname, &op->o_req_ndn );
481 case LDAP_REQ_MODIFY:
482 lmt = LASTMOD_MODIFY;
484 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
485 if ( ad_cmp( ml->sml_desc , slap_schema.si_ad_modifiersName ) == 0 ) {
486 ber_dupbv( &bv_modifiersName, &ml->sml_values[0] );
487 ber_dupbv( &bv_nmodifiersName, &ml->sml_nvalues[0] );
489 if ( !BER_BVISNULL( &bv_modifyTimestamp ) ) {
493 } else if ( ad_cmp( ml->sml_desc, slap_schema.si_ad_modifyTimestamp ) == 0 ) {
494 ber_dupbv( &bv_modifyTimestamp, &ml->sml_values[0] );
495 if ( ml->sml_nvalues && !BER_BVISNULL( &ml->sml_nvalues[0] ) ) {
496 ber_dupbv( &bv_nmodifyTimestamp, &ml->sml_nvalues[0] );
498 ber_dupbv( &bv_nmodifyTimestamp, &ml->sml_values[0] );
501 if ( !BER_BVISNULL( &bv_modifiersName ) ) {
507 /* if rooted at global overlay, opattrs are not yet in place */
508 if ( BER_BVISNULL( &bv_modifiersName ) ) {
509 best_guess( op, NULL, NULL, &bv_modifiersName, &bv_nmodifiersName );
512 /* if rooted at global overlay, opattrs are not yet in place */
513 if ( BER_BVISNULL( &bv_modifyTimestamp ) ) {
514 best_guess( op, &bv_modifyTimestamp, &bv_nmodifyTimestamp, NULL, NULL );
517 ber_dupbv( &bv_name, &op->o_req_dn );
518 ber_dupbv( &bv_nname, &op->o_req_ndn );
521 case LDAP_REQ_MODRDN:
522 lmt = LASTMOD_MODRDN;
525 if ( op->orr_newSup && !BER_BVISNULL( op->orr_newSup ) ) {
526 build_new_dn( &bv_name, op->orr_newSup, &op->orr_newrdn, NULL );
527 build_new_dn( &bv_nname, op->orr_nnewSup, &op->orr_nnewrdn, NULL );
532 dnParent( &op->o_req_dn, &pdn );
533 build_new_dn( &bv_name, &pdn, &op->orr_newrdn, NULL );
535 dnParent( &op->o_req_ndn, &pdn );
536 build_new_dn( &bv_nname, &pdn, &op->orr_nnewrdn, NULL );
539 if ( on->on_info->oi_orig->bi_entry_get_rw ) {
540 BackendInfo *bi = op->o_bd->bd_info;
543 op->o_bd->bd_info = (BackendInfo *)on->on_info->oi_orig;
544 rc = (*op->o_bd->bd_info->bi_entry_get_rw)( op, &bv_name, NULL, NULL, 0, &e );
545 if ( rc == LDAP_SUCCESS ) {
546 a = attr_find( e->e_attrs, slap_schema.si_ad_modifiersName );
548 ber_dupbv( &bv_modifiersName, &a->a_vals[0] );
549 ber_dupbv( &bv_nmodifiersName, &a->a_nvals[0] );
551 a = attr_find( e->e_attrs, slap_schema.si_ad_modifyTimestamp );
553 ber_dupbv( &bv_modifyTimestamp, &a->a_vals[0] );
554 if ( a->a_nvals && !BER_BVISNULL( &a->a_nvals[0] ) ) {
555 ber_dupbv( &bv_nmodifyTimestamp, &a->a_nvals[0] );
557 ber_dupbv( &bv_nmodifyTimestamp, &a->a_vals[0] );
561 assert( dn_match( &bv_name, &e->e_name ) );
562 assert( dn_match( &bv_nname, &e->e_nname ) );
564 (*op->o_bd->bd_info->bi_entry_release_rw)( op, e, 0 );
567 op->o_bd->bd_info = bi;
571 /* if !bi_entry_get_rw || bi_entry_get_rw failed for any reason... */
573 best_guess( op, &bv_modifyTimestamp, &bv_nmodifyTimestamp,
574 &bv_modifiersName, &bv_nmodifiersName );
583 ldap_pvt_thread_mutex_lock( &lmi->lmi_entry_mutex );
586 fprintf( stderr, "### lastmodDN: %s %s\n", bv_name.bv_val, bv_nname.bv_val );
589 a = attr_find( lmi->lmi_e->e_attrs, lastmod_schema.lms_ad_lastmodDN );
593 ch_free( a->a_vals[0].bv_val );
594 a->a_vals[0] = bv_name;
595 ch_free( a->a_nvals[0].bv_val );
596 a->a_nvals[0] = bv_nname;
599 fprintf( stderr, "### lastmodType: %s %s\n", lastmodType[ lmt ].bv_val, lastmodType[ lmt ].bv_val );
602 a = attr_find( lmi->lmi_e->e_attrs, lastmod_schema.lms_ad_lastmodType );
606 ch_free( a->a_vals[0].bv_val );
607 ber_dupbv( &a->a_vals[0], &lastmodType[ lmt ] );
608 ch_free( a->a_nvals[0].bv_val );
609 ber_dupbv( &a->a_nvals[0], &lastmodType[ lmt ] );
612 fprintf( stderr, "### modifiersName: %s %s\n", bv_modifiersName.bv_val, bv_nmodifiersName.bv_val );
615 a = attr_find( lmi->lmi_e->e_attrs, slap_schema.si_ad_modifiersName );
619 ch_free( a->a_vals[0].bv_val );
620 a->a_vals[0] = bv_modifiersName;
621 ch_free( a->a_nvals[0].bv_val );
622 a->a_nvals[0] = bv_nmodifiersName;
625 fprintf( stderr, "### modifyTimestamp: %s %s\n", bv_nmodifyTimestamp.bv_val, bv_modifyTimestamp.bv_val );
628 a = attr_find( lmi->lmi_e->e_attrs, slap_schema.si_ad_modifyTimestamp );
632 ch_free( a->a_vals[0].bv_val );
633 a->a_vals[0] = bv_modifyTimestamp;
634 ch_free( a->a_nvals[0].bv_val );
635 a->a_nvals[0] = bv_nmodifyTimestamp;
640 ldap_pvt_thread_mutex_unlock( &lmi->lmi_entry_mutex );
646 lastmod_response( Operation *op, SlapReply *rs )
648 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
649 lastmod_info_t *lmi = (lastmod_info_t *)on->on_bi.bi_private;
652 /* don't record failed operations */
653 switch ( rs->sr_err ) {
655 /* FIXME: other cases? */
659 return SLAP_CB_CONTINUE;
662 /* record only write operations */
663 switch ( op->o_tag ) {
665 case LDAP_REQ_MODIFY:
666 case LDAP_REQ_MODRDN:
667 case LDAP_REQ_DELETE:
670 case LDAP_REQ_EXTENDED:
671 /* if write, process */
672 if ( exop_is_write( op ))
677 return SLAP_CB_CONTINUE;
680 /* skip if disabled */
681 ldap_pvt_thread_mutex_lock( &lmi->lmi_entry_mutex );
682 if ( !lmi->lmi_enabled ) {
683 ldap_pvt_thread_mutex_unlock( &lmi->lmi_entry_mutex );
684 return SLAP_CB_CONTINUE;
686 ldap_pvt_thread_mutex_unlock( &lmi->lmi_entry_mutex );
689 (void)lastmod_update( op, rs );
691 return SLAP_CB_CONTINUE;
699 slap_overinst *on = (slap_overinst *)be->bd_info;
702 if ( lastmod_schema.lms_oc_lastmod == NULL ) {
706 /* schema integration */
707 for ( i = 0; mat[i].name; i++ ) {
708 LDAPAttributeType *at;
711 AttributeDescription **ad;
713 at = ldap_str2attributetype( mat[i].schema, &code,
714 &err, LDAP_SCHEMA_ALLOW_ALL );
716 Debug( LDAP_DEBUG_ANY, "lastmod_init: "
717 "in AttributeType '%s' %s before %s\n",
718 mat[i].name, ldap_scherr2str(code), err );
722 if ( at->at_oid == NULL ) {
723 Debug( LDAP_DEBUG_ANY, "lastmod_init: "
724 "null OID for attributeType '%s'\n",
729 code = at_add(at, &err);
731 Debug( LDAP_DEBUG_ANY, "lastmod_init: "
732 "%s in attributeType '%s'\n",
733 scherr2str(code), mat[i].name, 0 );
738 ad = ((AttributeDescription **)&(((char *)&lastmod_schema)[mat[i].offset]));
740 if ( slap_str2ad( mat[i].name, ad, &text ) ) {
741 Debug( LDAP_DEBUG_ANY,
742 "lastmod_init: %s\n", text, 0, 0 );
746 (*ad)->ad_type->sat_flags |= mat[i].flags;
749 for ( i = 0; moc[i].name; i++ ) {
755 oc = ldap_str2objectclass(moc[i].schema, &code, &err,
756 LDAP_SCHEMA_ALLOW_ALL );
758 Debug( LDAP_DEBUG_ANY,
759 "unable to parse lastmod objectClass '%s': "
760 "%s before %s\n" , moc[i].name,
761 ldap_scherr2str(code), err );
765 if ( oc->oc_oid == NULL ) {
766 Debug( LDAP_DEBUG_ANY,
767 "objectClass '%s' has no OID\n" ,
772 code = oc_add(oc, 0, &err);
774 Debug( LDAP_DEBUG_ANY,
775 "objectClass '%s': %s \"%s\"\n" ,
776 moc[i].name, scherr2str(code), err );
782 Oc = oc_find( moc[i].name );
784 Debug( LDAP_DEBUG_ANY, "lastmod_init: "
785 "unable to find objectClass %s "
786 "(just added)\n", moc[i].name, 0, 0 );
790 Oc->soc_flags |= moc[i].flags;
792 ((ObjectClass **)&(((char *)&lastmod_schema)[moc[i].offset]))[0] = Oc;
796 lmi = (lastmod_info_t *)ch_malloc( sizeof( lastmod_info_t ) );
798 memset( lmi, 0, sizeof( lastmod_info_t ) );
799 lmi->lmi_enabled = 1;
801 on->on_bi.bi_private = lmi;
815 slap_overinst *on = (slap_overinst *)be->bd_info;
816 lastmod_info_t *lmi = (lastmod_info_t *)on->on_bi.bi_private;
818 if ( strcasecmp( argv[ 0 ], "lastmod-rdnvalue" ) == 0 ) {
819 if ( lmi->lmi_rdnvalue.bv_val ) {
820 /* already defined! */
821 ch_free( lmi->lmi_rdnvalue.bv_val );
824 ber_str2bv( argv[ 1 ], 0, 1, &lmi->lmi_rdnvalue );
826 } else if ( strcasecmp( argv[ 0 ], "lastmod-enabled" ) == 0 ) {
827 if ( strcasecmp( argv[ 1 ], "yes" ) == 0 ) {
828 lmi->lmi_enabled = 1;
830 } else if ( strcasecmp( argv[ 1 ], "no" ) == 0 ) {
831 lmi->lmi_enabled = 0;
838 return SLAP_CONF_UNKNOWN;
849 slap_overinst *on = (slap_overinst *) be->bd_info;
850 lastmod_info_t *lmi = (lastmod_info_t *)on->on_bi.bi_private;
856 static char tmbuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
858 if ( !SLAP_LASTMOD( be ) ) {
859 fprintf( stderr, "set \"lastmod on\" to make this overlay effective\n" );
866 #ifndef HAVE_GMTIME_R
867 ldap_pvt_thread_mutex_lock( &gmtime_mutex );
868 tms = gmtime( &starttime );
869 #else /* HAVE_GMTIME_R */
870 tms = gmtime_r( &starttime, &tm_buf );
871 #endif /* HAVE_GMTIME_R */
872 lutil_gentime( tmbuf, sizeof(tmbuf), tms );
873 #ifndef HAVE_GMTIME_R
874 ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
877 if ( BER_BVISNULL( &lmi->lmi_rdnvalue ) ) {
878 ber_str2bv( "Lastmod", 0, 1, &lmi->lmi_rdnvalue );
881 snprintf( buf, sizeof( buf ),
884 "structuralObjectClass: %s\n"
886 "description: This object contains the last modification to this database\n"
890 "createTimestamp: %s\n"
892 "modifyTimestamp: %s\n"
893 "modifiersName: %s\n"
894 "hasSubordinates: FALSE\n",
895 lmi->lmi_rdnvalue.bv_val, BER_BVISEMPTY( &be->be_suffix[ 0 ] ) ? "" : ",", be->be_suffix[ 0 ].bv_val,
896 lastmod_schema.lms_oc_lastmod->soc_cname.bv_val,
897 lastmod_schema.lms_oc_lastmod->soc_cname.bv_val,
898 lmi->lmi_rdnvalue.bv_val,
899 lastmod_schema.lms_ad_lastmodDN->ad_cname.bv_val,
900 lmi->lmi_rdnvalue.bv_val, BER_BVISEMPTY( &be->be_suffix[ 0 ] ) ? "" : ",", be->be_suffix[ 0 ].bv_val,
901 lastmod_schema.lms_ad_lastmodType->ad_cname.bv_val, lastmodType[ LASTMOD_ADD ].bv_val,
902 lastmod_schema.lms_ad_lastmodEnabled->ad_cname.bv_val, lmi->lmi_enabled ? "TRUE" : "FALSE",
904 BER_BVISNULL( &be->be_rootdn ) ? SLAPD_ANONYMOUS : be->be_rootdn.bv_val,
906 BER_BVISNULL( &be->be_rootdn ) ? SLAPD_ANONYMOUS : be->be_rootdn.bv_val );
909 fprintf( stderr, "# entry:\n%s\n", buf );
912 lmi->lmi_e = str2entry( buf );
913 if ( lmi->lmi_e == NULL ) {
917 ldap_pvt_thread_mutex_init( &lmi->lmi_entry_mutex );
927 slap_overinst *on = (slap_overinst *)be->bd_info;
928 lastmod_info_t *lmi = (lastmod_info_t *)on->on_bi.bi_private;
931 if ( !BER_BVISNULL( &lmi->lmi_rdnvalue ) ) {
932 ch_free( lmi->lmi_rdnvalue.bv_val );
936 entry_free( lmi->lmi_e );
938 ldap_pvt_thread_mutex_destroy( &lmi->lmi_entry_mutex );
947 /* This overlay is set up for dynamic loading via moduleload. For static
948 * configuration, you'll need to arrange for the slap_overinst to be
949 * initialized and registered by some other function inside slapd.
952 static slap_overinst lastmod;
957 lastmod.on_bi.bi_type = "lastmod";
958 lastmod.on_bi.bi_db_init = lastmod_db_init;
959 lastmod.on_bi.bi_db_config = lastmod_db_config;
960 lastmod.on_bi.bi_db_destroy = lastmod_db_destroy;
961 lastmod.on_bi.bi_db_open = lastmod_db_open;
963 lastmod.on_bi.bi_op_add = lastmod_op_func;
964 lastmod.on_bi.bi_op_compare = lastmod_op_func;
965 lastmod.on_bi.bi_op_delete = lastmod_op_func;
966 lastmod.on_bi.bi_op_modify = lastmod_op_func;
967 lastmod.on_bi.bi_op_modrdn = lastmod_op_func;
968 lastmod.on_bi.bi_op_search = lastmod_op_func;
969 lastmod.on_bi.bi_extended = lastmod_op_func;
971 lastmod.on_response = lastmod_response;
973 return overlay_register( &lastmod );
976 #if SLAPD_OVER_LASTMOD == SLAPD_MOD_DYNAMIC
978 init_module( int argc, char *argv[] )
980 return lastmod_init();
982 #endif /* SLAPD_OVER_LASTMOD == SLAPD_MOD_DYNAMIC */
984 #endif /* defined(SLAPD_OVER_LASTMOD) */