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 ) },
113 static const struct berval *write_exop[] = {
114 &slap_EXOP_MODIFY_PASSWD,
119 lastmod_search( Operation *op, SlapReply *rs )
121 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
122 lastmod_info_t *lmi = (lastmod_info_t *)on->on_bi.bi_private;
125 /* if we get here, it must be a success */
126 rs->sr_err = LDAP_SUCCESS;
128 ldap_pvt_thread_mutex_lock( &lmi->lmi_entry_mutex );
130 rc = test_filter( op, lmi->lmi_e, op->oq_search.rs_filter );
131 if ( rc == LDAP_COMPARE_TRUE ) {
132 rs->sr_attrs = op->ors_attrs;
134 rs->sr_entry = lmi->lmi_e;
135 rs->sr_err = send_search_entry( op, rs );
141 ldap_pvt_thread_mutex_unlock( &lmi->lmi_entry_mutex );
143 send_ldap_result( op, rs );
149 lastmod_compare( Operation *op, SlapReply *rs )
151 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
152 lastmod_info_t *lmi = (lastmod_info_t *)on->on_bi.bi_private;
155 ldap_pvt_thread_mutex_lock( &lmi->lmi_entry_mutex );
157 if ( get_assert( op ) &&
158 ( test_filter( op, lmi->lmi_e, get_assertion( op ) ) != LDAP_COMPARE_TRUE ) )
160 rs->sr_err = LDAP_ASSERTION_FAILED;
164 rs->sr_err = access_allowed( op, lmi->lmi_e, op->oq_compare.rs_ava->aa_desc,
165 &op->oq_compare.rs_ava->aa_value, ACL_COMPARE, NULL );
166 if ( ! rs->sr_err ) {
167 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
171 rs->sr_err = LDAP_NO_SUCH_ATTRIBUTE;
173 for ( a = attr_find( lmi->lmi_e->e_attrs, op->oq_compare.rs_ava->aa_desc );
175 a = attr_find( a->a_next, op->oq_compare.rs_ava->aa_desc ) )
177 rs->sr_err = LDAP_COMPARE_FALSE;
179 if ( value_find_ex( op->oq_compare.rs_ava->aa_desc,
180 SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
181 SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
182 a->a_nvals, &op->oq_compare.rs_ava->aa_value, op->o_tmpmemctx ) == 0 )
184 rs->sr_err = LDAP_COMPARE_TRUE;
191 ldap_pvt_thread_mutex_unlock( &lmi->lmi_entry_mutex );
193 send_ldap_result( op, rs );
195 if( rs->sr_err == LDAP_COMPARE_FALSE || rs->sr_err == LDAP_COMPARE_TRUE ) {
196 rs->sr_err = LDAP_SUCCESS;
203 lastmod_exop( Operation *op, SlapReply *rs )
205 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
209 op->o_bd->bd_info = (BackendInfo *)on->on_info;
210 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
211 rs->sr_text = "not allowed within namingContext";
212 send_ldap_result( op, rs );
219 lastmod_modify( Operation *op, SlapReply *rs )
221 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
222 lastmod_info_t *lmi = (lastmod_info_t *)on->on_bi.bi_private;
225 ldap_pvt_thread_mutex_lock( &lmi->lmi_entry_mutex );
227 if ( !acl_check_modlist( op, lmi->lmi_e, op->orm_modlist ) ) {
228 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
232 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
235 if ( ml->sml_desc != lastmod_schema.lms_ad_lastmodEnabled ) {
239 if ( ml->sml_op != LDAP_MOD_REPLACE ) {
240 rs->sr_text = "unsupported mod type";
241 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
245 a = attr_find( lmi->lmi_e->e_attrs, ml->sml_desc );
248 rs->sr_text = "lastmod overlay internal error";
249 rs->sr_err = LDAP_OTHER;
253 ch_free( a->a_vals[ 0 ].bv_val );
254 ber_dupbv( &a->a_vals[ 0 ], &ml->sml_values[ 0 ] );
256 ch_free( a->a_nvals[ 0 ].bv_val );
257 if ( ml->sml_nvalues && !BER_BVISNULL( &ml->sml_nvalues[ 0 ] ) ) {
258 ber_dupbv( &a->a_nvals[ 0 ], &ml->sml_nvalues[ 0 ] );
260 ber_dupbv( &a->a_nvals[ 0 ], &ml->sml_values[ 0 ] );
264 if ( strcmp( ml->sml_values[ 0 ].bv_val, "TRUE" ) == 0 ) {
265 lmi->lmi_enabled = 1;
266 } else if ( strcmp( ml->sml_values[ 0 ].bv_val, "FALSE" ) == 0 ) {
267 lmi->lmi_enabled = 0;
273 rs->sr_err = LDAP_SUCCESS;
276 ldap_pvt_thread_mutex_unlock( &lmi->lmi_entry_mutex );
278 send_ldap_result( op, rs );
285 lastmod_op_func( Operation *op, SlapReply *rs )
287 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
288 lastmod_info_t *lmi = (lastmod_info_t *)on->on_bi.bi_private;
292 if ( dn_match( &op->o_req_ndn, &lmi->lmi_e->e_nname ) ) {
293 switch ( op->o_tag ) {
294 case LDAP_REQ_SEARCH:
295 if ( op->ors_scope != LDAP_SCOPE_BASE ) {
296 goto return_referral;
299 return lastmod_search( op, rs );
301 case LDAP_REQ_COMPARE:
302 return lastmod_compare( op, rs );
304 case LDAP_REQ_EXTENDED:
305 /* if write, reject; otherwise process */
306 for ( i = 0; write_exop[ i ] != NULL; i++ ) {
307 if ( ber_bvcmp( write_exop[ i ], &op->oq_extended.rs_reqoid ) == 0 ) {
308 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
309 rs->sr_text = "not allowed within namingContext";
313 return lastmod_exop( op, rs );
315 case LDAP_REQ_MODIFY:
316 /* if global overlay, modlist is not checked yet */
317 if ( op->orm_modlist->sml_desc == NULL ) {
318 char textbuf[SLAP_TEXT_BUFLEN];
319 size_t textlen = sizeof textbuf;
321 rs->sr_err = slap_mods_check( op->orm_modlist, 0, &rs->sr_text,
322 textbuf, textlen, NULL );
329 /* allow only changes to overlay status */
330 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
331 if ( ad_cmp( ml->sml_desc, slap_schema.si_ad_modifiersName ) != 0
332 && ad_cmp( ml->sml_desc, slap_schema.si_ad_modifyTimestamp ) != 0
333 && ad_cmp( ml->sml_desc, slap_schema.si_ad_entryCSN ) != 0
334 && ad_cmp( ml->sml_desc, lastmod_schema.lms_ad_lastmodEnabled ) != 0 )
336 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
337 rs->sr_text = "not allowed within namingContext";
341 return lastmod_modify( op, rs );
344 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
345 rs->sr_text = "not allowed within namingContext";
350 if ( dnIsSuffix( &op->o_req_ndn, &lmi->lmi_e->e_nname ) ) {
351 goto return_referral;
354 return SLAP_CB_CONTINUE;
357 op->o_bd->bd_info = (BackendInfo *)on->on_info;
358 rs->sr_ref = referral_rewrite( default_referral,
359 NULL, &op->o_req_dn, op->ors_scope );
362 rs->sr_ref = default_referral;
364 rs->sr_err = LDAP_REFERRAL;
365 send_ldap_result( op, rs );
367 if ( rs->sr_ref != default_referral ) {
368 ber_bvarray_free( rs->sr_ref );
375 op->o_bd->bd_info = (BackendInfo *)on->on_info;
376 send_ldap_result( op, rs );
383 best_guess( Operation *op,
384 struct berval *bv_modifyTimestamp, struct berval *bv_nmodifyTimestamp,
385 struct berval *bv_modifiersName, struct berval *bv_nmodifiersName )
387 if ( bv_modifyTimestamp ) {
392 char tmbuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
397 currtime = slap_get_time();
399 /* maybe we better use the time the operation was initiated */
400 currtime = op->o_time;
402 #ifndef HAVE_GMTIME_R
403 ldap_pvt_thread_mutex_lock( &gmtime_mutex );
404 tm = gmtime( &currtime );
405 #else /* HAVE_GMTIME_R */
406 tm = gmtime_r( &currtime, &tm_buf );
407 #endif /* HAVE_GMTIME_R */
408 lutil_gentime( tmbuf, sizeof( tmbuf ), tm );
409 #ifndef HAVE_GMTIME_R
410 ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
413 ber_str2bv( tmbuf, 0, 1, bv_modifyTimestamp );
414 ber_dupbv( bv_nmodifyTimestamp, bv_modifyTimestamp );
417 if ( bv_modifiersName ) {
419 ber_dupbv( bv_modifiersName, &op->o_dn );
420 ber_dupbv( bv_nmodifiersName, &op->o_ndn );
427 lastmod_update( Operation *op, SlapReply *rs )
429 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
430 lastmod_info_t *lmi = (lastmod_info_t *)on->on_bi.bi_private;
432 Modifications *ml = NULL;
433 struct berval bv_modifyTimestamp = BER_BVNULL,
434 bv_nmodifyTimestamp = BER_BVNULL,
435 bv_modifiersName = BER_BVNULL,
436 bv_nmodifiersName = BER_BVNULL,
437 bv_name = BER_BVNULL,
438 bv_nname = BER_BVNULL;
439 enum lastmodType_e lmt = LASTMOD_UNKNOWN;
443 /* FIXME: timestamp? modifier? */
444 switch ( op->o_tag ) {
448 a = attr_find( e->e_attrs, slap_schema.si_ad_modifiersName );
450 ber_dupbv( &bv_modifiersName, &a->a_vals[0] );
451 ber_dupbv( &bv_nmodifiersName, &a->a_nvals[0] );
453 a = attr_find( e->e_attrs, slap_schema.si_ad_modifyTimestamp );
455 ber_dupbv( &bv_modifyTimestamp, &a->a_vals[0] );
456 if ( a->a_nvals && !BER_BVISNULL( &a->a_nvals[0] ) ) {
457 ber_dupbv( &bv_nmodifyTimestamp, &a->a_nvals[0] );
459 ber_dupbv( &bv_nmodifyTimestamp, &a->a_vals[0] );
462 ber_dupbv( &bv_name, &e->e_name );
463 ber_dupbv( &bv_nname, &e->e_nname );
466 case LDAP_REQ_DELETE:
467 lmt = LASTMOD_DELETE;
469 best_guess( op, &bv_modifyTimestamp, &bv_nmodifyTimestamp,
470 &bv_modifiersName, &bv_nmodifiersName );
472 ber_dupbv( &bv_name, &op->o_req_dn );
473 ber_dupbv( &bv_nname, &op->o_req_ndn );
476 case LDAP_REQ_EXTENDED:
479 /* actually, password change is wrapped around a backend
480 * call to modify, so it never shows up as an exop... */
481 best_guess( op, &bv_modifyTimestamp, &bv_nmodifyTimestamp,
482 &bv_modifiersName, &bv_nmodifiersName );
484 ber_dupbv( &bv_name, &op->o_req_dn );
485 ber_dupbv( &bv_nname, &op->o_req_ndn );
488 case LDAP_REQ_MODIFY:
489 lmt = LASTMOD_MODIFY;
491 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
492 if ( ad_cmp( ml->sml_desc , slap_schema.si_ad_modifiersName ) == 0 ) {
493 ber_dupbv( &bv_modifiersName, &ml->sml_values[0] );
494 ber_dupbv( &bv_nmodifiersName, &ml->sml_nvalues[0] );
496 if ( !BER_BVISNULL( &bv_modifyTimestamp ) ) {
500 } else if ( ad_cmp( ml->sml_desc, slap_schema.si_ad_modifyTimestamp ) == 0 ) {
501 ber_dupbv( &bv_modifyTimestamp, &ml->sml_values[0] );
502 if ( ml->sml_nvalues && !BER_BVISNULL( &ml->sml_nvalues[0] ) ) {
503 ber_dupbv( &bv_nmodifyTimestamp, &ml->sml_nvalues[0] );
505 ber_dupbv( &bv_nmodifyTimestamp, &ml->sml_values[0] );
508 if ( !BER_BVISNULL( &bv_modifiersName ) ) {
514 /* if rooted at global overlay, opattrs are not yet in place */
515 if ( BER_BVISNULL( &bv_modifiersName ) ) {
516 best_guess( op, NULL, NULL, &bv_modifiersName, &bv_nmodifiersName );
519 /* if rooted at global overlay, opattrs are not yet in place */
520 if ( BER_BVISNULL( &bv_modifyTimestamp ) ) {
521 best_guess( op, &bv_modifyTimestamp, &bv_nmodifyTimestamp, NULL, NULL );
524 ber_dupbv( &bv_name, &op->o_req_dn );
525 ber_dupbv( &bv_nname, &op->o_req_ndn );
528 case LDAP_REQ_MODRDN:
529 lmt = LASTMOD_MODRDN;
532 if ( op->orr_newSup && !BER_BVISNULL( op->orr_newSup ) ) {
533 build_new_dn( &bv_name, op->orr_newSup, &op->orr_newrdn, NULL );
534 build_new_dn( &bv_nname, op->orr_nnewSup, &op->orr_nnewrdn, NULL );
539 dnParent( &op->o_req_dn, &pdn );
540 build_new_dn( &bv_name, &pdn, &op->orr_newrdn, NULL );
542 dnParent( &op->o_req_ndn, &pdn );
543 build_new_dn( &bv_nname, &pdn, &op->orr_nnewrdn, NULL );
546 if ( on->on_info->oi_orig->bi_entry_get_rw ) {
547 BackendInfo *bi = op->o_bd->bd_info;
550 op->o_bd->bd_info = (BackendInfo *)on->on_info->oi_orig;
551 rc = (*op->o_bd->bd_info->bi_entry_get_rw)( op, &bv_name, NULL, NULL, 0, &e );
552 if ( rc == LDAP_SUCCESS ) {
553 a = attr_find( e->e_attrs, slap_schema.si_ad_modifiersName );
555 ber_dupbv( &bv_modifiersName, &a->a_vals[0] );
556 ber_dupbv( &bv_nmodifiersName, &a->a_nvals[0] );
558 a = attr_find( e->e_attrs, slap_schema.si_ad_modifyTimestamp );
560 ber_dupbv( &bv_modifyTimestamp, &a->a_vals[0] );
561 if ( a->a_nvals && !BER_BVISNULL( &a->a_nvals[0] ) ) {
562 ber_dupbv( &bv_nmodifyTimestamp, &a->a_nvals[0] );
564 ber_dupbv( &bv_nmodifyTimestamp, &a->a_vals[0] );
568 assert( dn_match( &bv_name, &e->e_name ) );
569 assert( dn_match( &bv_nname, &e->e_nname ) );
571 (*op->o_bd->bd_info->bi_entry_release_rw)( op, e, 0 );
574 op->o_bd->bd_info = bi;
578 /* if !bi_entry_get_rw || bi_entry_get_rw failed for any reason... */
580 best_guess( op, &bv_modifyTimestamp, &bv_nmodifyTimestamp,
581 &bv_modifiersName, &bv_nmodifiersName );
590 ldap_pvt_thread_mutex_lock( &lmi->lmi_entry_mutex );
593 fprintf( stderr, "### lastmodDN: %s %s\n", bv_name.bv_val, bv_nname.bv_val );
596 a = attr_find( lmi->lmi_e->e_attrs, lastmod_schema.lms_ad_lastmodDN );
600 ch_free( a->a_vals[0].bv_val );
601 a->a_vals[0] = bv_name;
602 ch_free( a->a_nvals[0].bv_val );
603 a->a_nvals[0] = bv_nname;
606 fprintf( stderr, "### lastmodType: %s %s\n", lastmodType[ lmt ].bv_val, lastmodType[ lmt ].bv_val );
609 a = attr_find( lmi->lmi_e->e_attrs, lastmod_schema.lms_ad_lastmodType );
613 ch_free( a->a_vals[0].bv_val );
614 ber_dupbv( &a->a_vals[0], &lastmodType[ lmt ] );
615 ch_free( a->a_nvals[0].bv_val );
616 ber_dupbv( &a->a_nvals[0], &lastmodType[ lmt ] );
619 fprintf( stderr, "### modifiersName: %s %s\n", bv_modifiersName.bv_val, bv_nmodifiersName.bv_val );
622 a = attr_find( lmi->lmi_e->e_attrs, slap_schema.si_ad_modifiersName );
626 ch_free( a->a_vals[0].bv_val );
627 a->a_vals[0] = bv_modifiersName;
628 ch_free( a->a_nvals[0].bv_val );
629 a->a_nvals[0] = bv_nmodifiersName;
632 fprintf( stderr, "### modifyTimestamp: %s %s\n", bv_nmodifyTimestamp.bv_val, bv_modifyTimestamp.bv_val );
635 a = attr_find( lmi->lmi_e->e_attrs, slap_schema.si_ad_modifyTimestamp );
639 ch_free( a->a_vals[0].bv_val );
640 a->a_vals[0] = bv_modifyTimestamp;
641 ch_free( a->a_nvals[0].bv_val );
642 a->a_nvals[0] = bv_nmodifyTimestamp;
647 ldap_pvt_thread_mutex_unlock( &lmi->lmi_entry_mutex );
653 lastmod_response( Operation *op, SlapReply *rs )
655 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
656 lastmod_info_t *lmi = (lastmod_info_t *)on->on_bi.bi_private;
659 /* don't record failed operations */
660 switch ( rs->sr_err ) {
662 /* FIXME: other cases? */
666 return SLAP_CB_CONTINUE;
669 /* record only write operations */
670 switch ( op->o_tag ) {
672 case LDAP_REQ_MODIFY:
673 case LDAP_REQ_MODRDN:
674 case LDAP_REQ_DELETE:
677 case LDAP_REQ_EXTENDED:
678 /* if write, process */
679 for ( i = 0; write_exop[ i ] != NULL; i++ ) {
680 if ( ber_bvcmp( write_exop[ i ], &op->oq_extended.rs_reqoid ) == 0 ) {
687 return SLAP_CB_CONTINUE;
690 /* skip if disabled */
691 ldap_pvt_thread_mutex_lock( &lmi->lmi_entry_mutex );
692 if ( !lmi->lmi_enabled ) {
693 ldap_pvt_thread_mutex_unlock( &lmi->lmi_entry_mutex );
694 return SLAP_CB_CONTINUE;
696 ldap_pvt_thread_mutex_unlock( &lmi->lmi_entry_mutex );
699 (void)lastmod_update( op, rs );
701 return SLAP_CB_CONTINUE;
709 slap_overinst *on = (slap_overinst *)be->bd_info;
712 if ( lastmod_schema.lms_oc_lastmod == NULL ) {
716 /* schema integration */
717 for ( i = 0; mat[i].name; i++ ) {
718 LDAPAttributeType *at;
721 AttributeDescription **ad;
723 at = ldap_str2attributetype( mat[i].schema, &code,
724 &err, LDAP_SCHEMA_ALLOW_ALL );
727 LDAP_LOG( OPERATION, CRIT, "lastmod_init: "
728 "in AttributeType '%s' %s before %s\n",
729 mat[i].name, ldap_scherr2str(code), err );
731 Debug( LDAP_DEBUG_ANY, "lastmod_init: "
732 "in AttributeType '%s' %s before %s\n",
733 mat[i].name, ldap_scherr2str(code), err );
738 if ( at->at_oid == NULL ) {
740 LDAP_LOG( OPERATION, CRIT, "lastmod_init: "
741 "null OID for attributeType '%s'\n",
744 Debug( LDAP_DEBUG_ANY, "lastmod_init: "
745 "null OID for attributeType '%s'\n",
751 code = at_add(at, &err);
754 LDAP_LOG( OPERATION, CRIT, "lastmod_init: "
755 "%s in attributeType '%s'\n",
756 scherr2str(code), mat[i].name, 0 );
758 Debug( LDAP_DEBUG_ANY, "lastmod_init: "
759 "%s in attributeType '%s'\n",
760 scherr2str(code), mat[i].name, 0 );
766 ad = ((AttributeDescription **)&(((char *)&lastmod_schema)[mat[i].offset]));
768 if ( slap_str2ad( mat[i].name, ad, &text ) ) {
770 LDAP_LOG( OPERATION, CRIT,
771 "lastmod_init: %s\n", text, 0, 0 );
773 Debug( LDAP_DEBUG_ANY,
774 "lastmod_init: %s\n", text, 0, 0 );
779 (*ad)->ad_type->sat_flags |= mat[i].flags;
782 for ( i = 0; moc[i].name; i++ ) {
788 oc = ldap_str2objectclass(moc[i].schema, &code, &err,
789 LDAP_SCHEMA_ALLOW_ALL );
792 LDAP_LOG( OPERATION, CRIT,
793 "unable to parse lastmod objectClass '%s': "
794 "%s before %s\n" , moc[i].name,
795 ldap_scherr2str(code), err );
797 Debug( LDAP_DEBUG_ANY,
798 "unable to parse lastmod objectClass '%s': "
799 "%s before %s\n" , moc[i].name,
800 ldap_scherr2str(code), err );
805 if ( oc->oc_oid == NULL ) {
807 LDAP_LOG( OPERATION, CRIT,
808 "objectClass '%s' has no OID\n" ,
811 Debug( LDAP_DEBUG_ANY,
812 "objectClass '%s' has no OID\n" ,
818 code = oc_add(oc, 0, &err);
821 LDAP_LOG( OPERATION, CRIT,
822 "objectClass '%s': %s \"%s\"\n" ,
823 moc[i].name, scherr2str(code), err );
825 Debug( LDAP_DEBUG_ANY,
826 "objectClass '%s': %s \"%s\"\n" ,
827 moc[i].name, scherr2str(code), err );
834 Oc = oc_find( moc[i].name );
837 LDAP_LOG( OPERATION, CRIT, "lastmod_init: "
838 "unable to find objectClass %s "
839 "(just added)\n", moc[i].name, 0, 0 );
841 Debug( LDAP_DEBUG_ANY, "lastmod_init: "
842 "unable to find objectClass %s "
843 "(just added)\n", moc[i].name, 0, 0 );
848 Oc->soc_flags |= moc[i].flags;
850 ((ObjectClass **)&(((char *)&lastmod_schema)[moc[i].offset]))[0] = Oc;
854 lmi = (lastmod_info_t *)ch_malloc( sizeof( lastmod_info_t ) );
856 memset( lmi, 0, sizeof( lastmod_info_t ) );
857 lmi->lmi_enabled = 1;
859 on->on_bi.bi_private = lmi;
873 slap_overinst *on = (slap_overinst *)be->bd_info;
874 lastmod_info_t *lmi = (lastmod_info_t *)on->on_bi.bi_private;
876 if ( strcasecmp( argv[ 0 ], "lastmod-rdnvalue" ) == 0 ) {
877 if ( lmi->lmi_rdnvalue.bv_val ) {
878 /* already defined! */
879 ch_free( lmi->lmi_rdnvalue.bv_val );
882 ber_str2bv( argv[ 1 ], 0, 1, &lmi->lmi_rdnvalue );
884 } else if ( strcasecmp( argv[ 0 ], "lastmod-enabled" ) == 0 ) {
885 if ( strcasecmp( argv[ 1 ], "yes" ) == 0 ) {
886 lmi->lmi_enabled = 1;
888 } else if ( strcasecmp( argv[ 1 ], "no" ) == 0 ) {
889 lmi->lmi_enabled = 0;
896 return SLAP_CONF_UNKNOWN;
907 slap_overinst *on = (slap_overinst *) be->bd_info;
908 lastmod_info_t *lmi = (lastmod_info_t *)on->on_bi.bi_private;
914 static char tmbuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
916 if ( !SLAP_LASTMOD( be ) ) {
917 fprintf( stderr, "set \"lastmod on\" to make this overlay effective\n" );
924 #ifndef HAVE_GMTIME_R
925 ldap_pvt_thread_mutex_lock( &gmtime_mutex );
926 tms = gmtime( &starttime );
927 #else /* HAVE_GMTIME_R */
928 tms = gmtime_r( &starttime, &tm_buf );
929 #endif /* HAVE_GMTIME_R */
930 lutil_gentime( tmbuf, sizeof(tmbuf), tms );
931 #ifndef HAVE_GMTIME_R
932 ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
935 if ( BER_BVISNULL( &lmi->lmi_rdnvalue ) ) {
936 ber_str2bv( "Lastmod", 0, 1, &lmi->lmi_rdnvalue );
939 snprintf( buf, sizeof( buf ),
942 "structuralObjectClass: %s\n"
944 "description: This object contains the last modification to this database\n"
948 "createTimestamp: %s\n"
950 "modifyTimestamp: %s\n"
951 "modifiersName: %s\n"
952 "hasSubordinates: FALSE\n",
953 lmi->lmi_rdnvalue.bv_val, BER_BVISEMPTY( &be->be_suffix[ 0 ] ) ? "" : ",", be->be_suffix[ 0 ].bv_val,
954 lastmod_schema.lms_oc_lastmod->soc_cname.bv_val,
955 lastmod_schema.lms_oc_lastmod->soc_cname.bv_val,
956 lmi->lmi_rdnvalue.bv_val,
957 lastmod_schema.lms_ad_lastmodDN->ad_cname.bv_val,
958 lmi->lmi_rdnvalue.bv_val, BER_BVISEMPTY( &be->be_suffix[ 0 ] ) ? "" : ",", be->be_suffix[ 0 ].bv_val,
959 lastmod_schema.lms_ad_lastmodType->ad_cname.bv_val, lastmodType[ LASTMOD_ADD ].bv_val,
960 lastmod_schema.lms_ad_lastmodEnabled->ad_cname.bv_val, lmi->lmi_enabled ? "TRUE" : "FALSE",
962 BER_BVISNULL( &be->be_rootdn ) ? SLAPD_ANONYMOUS : be->be_rootdn.bv_val,
964 BER_BVISNULL( &be->be_rootdn ) ? SLAPD_ANONYMOUS : be->be_rootdn.bv_val );
967 fprintf( stderr, "# entry:\n%s\n", buf );
970 lmi->lmi_e = str2entry( buf );
971 if ( lmi->lmi_e == NULL ) {
975 ldap_pvt_thread_mutex_init( &lmi->lmi_entry_mutex );
985 slap_overinst *on = (slap_overinst *)be->bd_info;
986 lastmod_info_t *lmi = (lastmod_info_t *)on->on_bi.bi_private;
989 if ( !BER_BVISNULL( &lmi->lmi_rdnvalue ) ) {
990 ch_free( lmi->lmi_rdnvalue.bv_val );
994 entry_free( lmi->lmi_e );
996 ldap_pvt_thread_mutex_destroy( &lmi->lmi_entry_mutex );
1005 /* This overlay is set up for dynamic loading via moduleload. For static
1006 * configuration, you'll need to arrange for the slap_overinst to be
1007 * initialized and registered by some other function inside slapd.
1010 static slap_overinst lastmod;
1015 lastmod.on_bi.bi_type = "lastmod";
1016 lastmod.on_bi.bi_db_init = lastmod_db_init;
1017 lastmod.on_bi.bi_db_config = lastmod_db_config;
1018 lastmod.on_bi.bi_db_destroy = lastmod_db_destroy;
1019 lastmod.on_bi.bi_db_open = lastmod_db_open;
1021 lastmod.on_bi.bi_op_add = lastmod_op_func;
1022 lastmod.on_bi.bi_op_compare = lastmod_op_func;
1023 lastmod.on_bi.bi_op_delete = lastmod_op_func;
1024 lastmod.on_bi.bi_op_modify = lastmod_op_func;
1025 lastmod.on_bi.bi_op_modrdn = lastmod_op_func;
1026 lastmod.on_bi.bi_op_search = lastmod_op_func;
1027 lastmod.on_bi.bi_extended = lastmod_op_func;
1029 lastmod.on_response = lastmod_response;
1031 return overlay_register( &lastmod );
1034 #if SLAPD_OVER_LASTMOD == SLAPD_MOD_DYNAMIC
1036 init_module( int argc, char *argv[] )
1038 return lastmod_init();
1040 #endif /* SLAPD_OVER_LASTMOD == SLAPD_MOD_DYNAMIC */
1042 #endif /* defined(SLAPD_OVER_LASTMOD) */