1 /* lastmod.c - returns last modification info */
2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 2004-2005 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 ) },
112 /* FIXME: what about UUID of last modified entry? */
116 lastmod_search( Operation *op, SlapReply *rs )
118 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
119 lastmod_info_t *lmi = (lastmod_info_t *)on->on_bi.bi_private;
122 /* if we get here, it must be a success */
123 rs->sr_err = LDAP_SUCCESS;
125 ldap_pvt_thread_mutex_lock( &lmi->lmi_entry_mutex );
127 rc = test_filter( op, lmi->lmi_e, op->oq_search.rs_filter );
128 if ( rc == LDAP_COMPARE_TRUE ) {
129 rs->sr_attrs = op->ors_attrs;
131 rs->sr_entry = lmi->lmi_e;
132 rs->sr_err = send_search_entry( op, rs );
138 ldap_pvt_thread_mutex_unlock( &lmi->lmi_entry_mutex );
140 send_ldap_result( op, rs );
146 lastmod_compare( Operation *op, SlapReply *rs )
148 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
149 lastmod_info_t *lmi = (lastmod_info_t *)on->on_bi.bi_private;
152 ldap_pvt_thread_mutex_lock( &lmi->lmi_entry_mutex );
154 if ( get_assert( op ) &&
155 ( test_filter( op, lmi->lmi_e, get_assertion( op ) ) != LDAP_COMPARE_TRUE ) )
157 rs->sr_err = LDAP_ASSERTION_FAILED;
161 rs->sr_err = access_allowed( op, lmi->lmi_e, op->oq_compare.rs_ava->aa_desc,
162 &op->oq_compare.rs_ava->aa_value, ACL_COMPARE, NULL );
163 if ( ! rs->sr_err ) {
164 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
168 rs->sr_err = LDAP_NO_SUCH_ATTRIBUTE;
170 for ( a = attr_find( lmi->lmi_e->e_attrs, op->oq_compare.rs_ava->aa_desc );
172 a = attr_find( a->a_next, op->oq_compare.rs_ava->aa_desc ) )
174 rs->sr_err = LDAP_COMPARE_FALSE;
176 if ( value_find_ex( op->oq_compare.rs_ava->aa_desc,
177 SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
178 SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
179 a->a_nvals, &op->oq_compare.rs_ava->aa_value, op->o_tmpmemctx ) == 0 )
181 rs->sr_err = LDAP_COMPARE_TRUE;
188 ldap_pvt_thread_mutex_unlock( &lmi->lmi_entry_mutex );
190 send_ldap_result( op, rs );
192 if( rs->sr_err == LDAP_COMPARE_FALSE || rs->sr_err == LDAP_COMPARE_TRUE ) {
193 rs->sr_err = LDAP_SUCCESS;
200 lastmod_exop( Operation *op, SlapReply *rs )
202 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
206 op->o_bd->bd_info = (BackendInfo *)on->on_info;
207 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
208 rs->sr_text = "not allowed within namingContext";
209 send_ldap_result( op, rs );
216 lastmod_modify( Operation *op, SlapReply *rs )
218 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
219 lastmod_info_t *lmi = (lastmod_info_t *)on->on_bi.bi_private;
222 ldap_pvt_thread_mutex_lock( &lmi->lmi_entry_mutex );
224 if ( !acl_check_modlist( op, lmi->lmi_e, op->orm_modlist ) ) {
225 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
229 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
232 if ( ml->sml_desc != lastmod_schema.lms_ad_lastmodEnabled ) {
236 if ( ml->sml_op != LDAP_MOD_REPLACE ) {
237 rs->sr_text = "unsupported mod type";
238 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
242 a = attr_find( lmi->lmi_e->e_attrs, ml->sml_desc );
245 rs->sr_text = "lastmod overlay internal error";
246 rs->sr_err = LDAP_OTHER;
250 ch_free( a->a_vals[ 0 ].bv_val );
251 ber_dupbv( &a->a_vals[ 0 ], &ml->sml_values[ 0 ] );
253 ch_free( a->a_nvals[ 0 ].bv_val );
254 if ( ml->sml_nvalues && !BER_BVISNULL( &ml->sml_nvalues[ 0 ] ) ) {
255 ber_dupbv( &a->a_nvals[ 0 ], &ml->sml_nvalues[ 0 ] );
257 ber_dupbv( &a->a_nvals[ 0 ], &ml->sml_values[ 0 ] );
261 if ( strcmp( ml->sml_values[ 0 ].bv_val, "TRUE" ) == 0 ) {
262 lmi->lmi_enabled = 1;
263 } else if ( strcmp( ml->sml_values[ 0 ].bv_val, "FALSE" ) == 0 ) {
264 lmi->lmi_enabled = 0;
270 rs->sr_err = LDAP_SUCCESS;
273 ldap_pvt_thread_mutex_unlock( &lmi->lmi_entry_mutex );
275 send_ldap_result( op, rs );
282 lastmod_op_func( Operation *op, SlapReply *rs )
284 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
285 lastmod_info_t *lmi = (lastmod_info_t *)on->on_bi.bi_private;
289 if ( dn_match( &op->o_req_ndn, &lmi->lmi_e->e_nname ) ) {
290 switch ( op->o_tag ) {
291 case LDAP_REQ_SEARCH:
292 if ( op->ors_scope != LDAP_SCOPE_BASE ) {
293 goto return_referral;
296 return lastmod_search( op, rs );
298 case LDAP_REQ_COMPARE:
299 return lastmod_compare( op, rs );
301 case LDAP_REQ_EXTENDED:
302 /* if write, reject; otherwise process */
303 if ( exop_is_write( op )) {
304 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
305 rs->sr_text = "not allowed within namingContext";
308 return lastmod_exop( op, rs );
310 case LDAP_REQ_MODIFY:
311 /* allow only changes to overlay status */
312 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
313 if ( ad_cmp( ml->sml_desc, slap_schema.si_ad_modifiersName ) != 0
314 && ad_cmp( ml->sml_desc, slap_schema.si_ad_modifyTimestamp ) != 0
315 && ad_cmp( ml->sml_desc, slap_schema.si_ad_entryCSN ) != 0
316 && ad_cmp( ml->sml_desc, lastmod_schema.lms_ad_lastmodEnabled ) != 0 )
318 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
319 rs->sr_text = "not allowed within namingContext";
323 return lastmod_modify( op, rs );
326 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
327 rs->sr_text = "not allowed within namingContext";
332 if ( dnIsSuffix( &op->o_req_ndn, &lmi->lmi_e->e_nname ) ) {
333 goto return_referral;
336 return SLAP_CB_CONTINUE;
339 op->o_bd->bd_info = (BackendInfo *)on->on_info;
340 rs->sr_ref = referral_rewrite( default_referral,
341 NULL, &op->o_req_dn, op->ors_scope );
344 rs->sr_ref = default_referral;
346 rs->sr_err = LDAP_REFERRAL;
347 send_ldap_result( op, rs );
349 if ( rs->sr_ref != default_referral ) {
350 ber_bvarray_free( rs->sr_ref );
357 op->o_bd->bd_info = (BackendInfo *)on->on_info;
358 send_ldap_result( op, rs );
365 best_guess( Operation *op,
366 struct berval *bv_entryCSN, struct berval *bv_nentryCSN,
367 struct berval *bv_modifyTimestamp, struct berval *bv_nmodifyTimestamp,
368 struct berval *bv_modifiersName, struct berval *bv_nmodifiersName )
371 char csnbuf[ LDAP_LUTIL_CSNSTR_BUFSIZE ];
372 struct berval entryCSN;
374 slap_get_csn( NULL, csnbuf, sizeof(csnbuf), &entryCSN, 0 );
376 ber_dupbv( bv_entryCSN, &entryCSN );
377 ber_dupbv( bv_nentryCSN, &entryCSN );
380 if ( bv_modifyTimestamp ) {
381 char tmbuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
382 struct berval timestamp;
387 currtime = slap_get_time();
389 /* maybe we better use the time the operation was initiated */
390 currtime = op->o_time;
392 timestamp.bv_val = tmbuf;
393 timestamp.bv_len = sizeof(tmbuf);
394 slap_timestamp( &currtime, ×tamp );
396 ber_dupbv( bv_modifyTimestamp, ×tamp );
397 ber_dupbv( bv_nmodifyTimestamp, bv_modifyTimestamp );
400 if ( bv_modifiersName ) {
402 ber_dupbv( bv_modifiersName, &op->o_dn );
403 ber_dupbv( bv_nmodifiersName, &op->o_ndn );
410 lastmod_update( Operation *op, SlapReply *rs )
412 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
413 lastmod_info_t *lmi = (lastmod_info_t *)on->on_bi.bi_private;
415 Modifications *ml = NULL;
416 struct berval bv_entryCSN = BER_BVNULL,
417 bv_nentryCSN = BER_BVNULL,
418 bv_modifyTimestamp = BER_BVNULL,
419 bv_nmodifyTimestamp = BER_BVNULL,
420 bv_modifiersName = BER_BVNULL,
421 bv_nmodifiersName = BER_BVNULL,
422 bv_name = BER_BVNULL,
423 bv_nname = BER_BVNULL;
424 enum lastmodType_e lmt = LASTMOD_UNKNOWN;
428 /* FIXME: timestamp? modifier? */
429 switch ( op->o_tag ) {
433 a = attr_find( e->e_attrs, slap_schema.si_ad_entryCSN );
435 ber_dupbv( &bv_entryCSN, &a->a_vals[0] );
436 if ( a->a_nvals && !BER_BVISNULL( &a->a_nvals[0] ) ) {
437 ber_dupbv( &bv_nentryCSN, &a->a_nvals[0] );
439 ber_dupbv( &bv_nentryCSN, &a->a_vals[0] );
442 a = attr_find( e->e_attrs, slap_schema.si_ad_modifyTimestamp );
444 ber_dupbv( &bv_modifyTimestamp, &a->a_vals[0] );
445 if ( a->a_nvals && !BER_BVISNULL( &a->a_nvals[0] ) ) {
446 ber_dupbv( &bv_nmodifyTimestamp, &a->a_nvals[0] );
448 ber_dupbv( &bv_nmodifyTimestamp, &a->a_vals[0] );
451 a = attr_find( e->e_attrs, slap_schema.si_ad_modifiersName );
453 ber_dupbv( &bv_modifiersName, &a->a_vals[0] );
454 ber_dupbv( &bv_nmodifiersName, &a->a_nvals[0] );
456 ber_dupbv( &bv_name, &e->e_name );
457 ber_dupbv( &bv_nname, &e->e_nname );
460 case LDAP_REQ_DELETE:
461 lmt = LASTMOD_DELETE;
463 best_guess( op, &bv_entryCSN, &bv_nentryCSN,
464 &bv_modifyTimestamp, &bv_nmodifyTimestamp,
465 &bv_modifiersName, &bv_nmodifiersName );
467 ber_dupbv( &bv_name, &op->o_req_dn );
468 ber_dupbv( &bv_nname, &op->o_req_ndn );
471 case LDAP_REQ_EXTENDED:
474 /* actually, password change is wrapped around a backend
475 * call to modify, so it never shows up as an exop... */
476 best_guess( op, &bv_entryCSN, &bv_nentryCSN,
477 &bv_modifyTimestamp, &bv_nmodifyTimestamp,
478 &bv_modifiersName, &bv_nmodifiersName );
480 ber_dupbv( &bv_name, &op->o_req_dn );
481 ber_dupbv( &bv_nname, &op->o_req_ndn );
484 case LDAP_REQ_MODIFY:
485 lmt = LASTMOD_MODIFY;
488 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
489 if ( ad_cmp( ml->sml_desc , slap_schema.si_ad_modifiersName ) == 0 ) {
490 ber_dupbv( &bv_modifiersName, &ml->sml_values[0] );
491 ber_dupbv( &bv_nmodifiersName, &ml->sml_nvalues[0] );
498 } else if ( ad_cmp( ml->sml_desc, slap_schema.si_ad_entryCSN ) == 0 ) {
499 ber_dupbv( &bv_entryCSN, &ml->sml_values[0] );
500 if ( ml->sml_nvalues && !BER_BVISNULL( &ml->sml_nvalues[0] ) ) {
501 ber_dupbv( &bv_nentryCSN, &ml->sml_nvalues[0] );
503 ber_dupbv( &bv_nentryCSN, &ml->sml_values[0] );
511 } else if ( ad_cmp( ml->sml_desc, slap_schema.si_ad_modifyTimestamp ) == 0 ) {
512 ber_dupbv( &bv_modifyTimestamp, &ml->sml_values[0] );
513 if ( ml->sml_nvalues && !BER_BVISNULL( &ml->sml_nvalues[0] ) ) {
514 ber_dupbv( &bv_nmodifyTimestamp, &ml->sml_nvalues[0] );
516 ber_dupbv( &bv_nmodifyTimestamp, &ml->sml_values[0] );
526 /* if rooted at global overlay, opattrs are not yet in place */
527 if ( BER_BVISNULL( &bv_modifiersName ) ) {
528 best_guess( op, NULL, NULL, NULL, NULL, &bv_modifiersName, &bv_nmodifiersName );
531 if ( BER_BVISNULL( &bv_entryCSN ) ) {
532 best_guess( op, &bv_entryCSN, &bv_nentryCSN, NULL, NULL, NULL, NULL );
535 if ( BER_BVISNULL( &bv_modifyTimestamp ) ) {
536 best_guess( op, NULL, NULL, &bv_modifyTimestamp, &bv_nmodifyTimestamp, NULL, NULL );
539 ber_dupbv( &bv_name, &op->o_req_dn );
540 ber_dupbv( &bv_nname, &op->o_req_ndn );
543 case LDAP_REQ_MODRDN:
544 lmt = LASTMOD_MODRDN;
547 if ( op->orr_newSup && !BER_BVISNULL( op->orr_newSup ) ) {
548 build_new_dn( &bv_name, op->orr_newSup, &op->orr_newrdn, NULL );
549 build_new_dn( &bv_nname, op->orr_nnewSup, &op->orr_nnewrdn, NULL );
554 dnParent( &op->o_req_dn, &pdn );
555 build_new_dn( &bv_name, &pdn, &op->orr_newrdn, NULL );
557 dnParent( &op->o_req_ndn, &pdn );
558 build_new_dn( &bv_nname, &pdn, &op->orr_nnewrdn, NULL );
561 if ( on->on_info->oi_orig->bi_entry_get_rw ) {
562 BackendInfo *bi = op->o_bd->bd_info;
565 op->o_bd->bd_info = (BackendInfo *)on->on_info->oi_orig;
566 rc = (*op->o_bd->bd_info->bi_entry_get_rw)( op, &bv_name, NULL, NULL, 0, &e );
567 if ( rc == LDAP_SUCCESS ) {
568 a = attr_find( e->e_attrs, slap_schema.si_ad_modifiersName );
570 ber_dupbv( &bv_modifiersName, &a->a_vals[0] );
571 ber_dupbv( &bv_nmodifiersName, &a->a_nvals[0] );
573 a = attr_find( e->e_attrs, slap_schema.si_ad_entryCSN );
575 ber_dupbv( &bv_entryCSN, &a->a_vals[0] );
576 if ( a->a_nvals && !BER_BVISNULL( &a->a_nvals[0] ) ) {
577 ber_dupbv( &bv_nentryCSN, &a->a_nvals[0] );
579 ber_dupbv( &bv_nentryCSN, &a->a_vals[0] );
582 a = attr_find( e->e_attrs, slap_schema.si_ad_modifyTimestamp );
584 ber_dupbv( &bv_modifyTimestamp, &a->a_vals[0] );
585 if ( a->a_nvals && !BER_BVISNULL( &a->a_nvals[0] ) ) {
586 ber_dupbv( &bv_nmodifyTimestamp, &a->a_nvals[0] );
588 ber_dupbv( &bv_nmodifyTimestamp, &a->a_vals[0] );
592 assert( dn_match( &bv_name, &e->e_name ) );
593 assert( dn_match( &bv_nname, &e->e_nname ) );
595 (*op->o_bd->bd_info->bi_entry_release_rw)( op, e, 0 );
598 op->o_bd->bd_info = bi;
602 /* if !bi_entry_get_rw || bi_entry_get_rw failed for any reason... */
604 best_guess( op, &bv_entryCSN, &bv_nentryCSN,
605 &bv_modifyTimestamp, &bv_nmodifyTimestamp,
606 &bv_modifiersName, &bv_nmodifiersName );
615 ldap_pvt_thread_mutex_lock( &lmi->lmi_entry_mutex );
618 fprintf( stderr, "### lastmodDN: %s %s\n", bv_name.bv_val, bv_nname.bv_val );
621 a = attr_find( lmi->lmi_e->e_attrs, lastmod_schema.lms_ad_lastmodDN );
625 ch_free( a->a_vals[0].bv_val );
626 a->a_vals[0] = bv_name;
627 ch_free( a->a_nvals[0].bv_val );
628 a->a_nvals[0] = bv_nname;
631 fprintf( stderr, "### lastmodType: %s %s\n", lastmodType[ lmt ].bv_val, lastmodType[ lmt ].bv_val );
634 a = attr_find( lmi->lmi_e->e_attrs, lastmod_schema.lms_ad_lastmodType );
638 ch_free( a->a_vals[0].bv_val );
639 ber_dupbv( &a->a_vals[0], &lastmodType[ lmt ] );
640 ch_free( a->a_nvals[0].bv_val );
641 ber_dupbv( &a->a_nvals[0], &lastmodType[ lmt ] );
644 fprintf( stderr, "### modifiersName: %s %s\n", bv_modifiersName.bv_val, bv_nmodifiersName.bv_val );
647 a = attr_find( lmi->lmi_e->e_attrs, slap_schema.si_ad_modifiersName );
651 ch_free( a->a_vals[0].bv_val );
652 a->a_vals[0] = bv_modifiersName;
653 ch_free( a->a_nvals[0].bv_val );
654 a->a_nvals[0] = bv_nmodifiersName;
657 fprintf( stderr, "### modifyTimestamp: %s %s\n", bv_nmodifyTimestamp.bv_val, bv_modifyTimestamp.bv_val );
660 a = attr_find( lmi->lmi_e->e_attrs, slap_schema.si_ad_modifyTimestamp );
664 ch_free( a->a_vals[0].bv_val );
665 a->a_vals[0] = bv_modifyTimestamp;
666 ch_free( a->a_nvals[0].bv_val );
667 a->a_nvals[0] = bv_nmodifyTimestamp;
670 fprintf( stderr, "### entryCSN: %s %s\n", bv_nentryCSN.bv_val, bv_entryCSN.bv_val );
673 a = attr_find( lmi->lmi_e->e_attrs, slap_schema.si_ad_entryCSN );
677 ch_free( a->a_vals[0].bv_val );
678 a->a_vals[0] = bv_entryCSN;
679 ch_free( a->a_nvals[0].bv_val );
680 a->a_nvals[0] = bv_nentryCSN;
685 ldap_pvt_thread_mutex_unlock( &lmi->lmi_entry_mutex );
691 lastmod_response( Operation *op, SlapReply *rs )
693 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
694 lastmod_info_t *lmi = (lastmod_info_t *)on->on_bi.bi_private;
697 /* don't record failed operations */
698 switch ( rs->sr_err ) {
700 /* FIXME: other cases? */
704 return SLAP_CB_CONTINUE;
707 /* record only write operations */
708 switch ( op->o_tag ) {
710 case LDAP_REQ_MODIFY:
711 case LDAP_REQ_MODRDN:
712 case LDAP_REQ_DELETE:
715 case LDAP_REQ_EXTENDED:
716 /* if write, process */
717 if ( exop_is_write( op ))
722 return SLAP_CB_CONTINUE;
725 /* skip if disabled */
726 ldap_pvt_thread_mutex_lock( &lmi->lmi_entry_mutex );
727 if ( !lmi->lmi_enabled ) {
728 ldap_pvt_thread_mutex_unlock( &lmi->lmi_entry_mutex );
729 return SLAP_CB_CONTINUE;
731 ldap_pvt_thread_mutex_unlock( &lmi->lmi_entry_mutex );
734 (void)lastmod_update( op, rs );
736 return SLAP_CB_CONTINUE;
744 slap_overinst *on = (slap_overinst *)be->bd_info;
747 if ( lastmod_schema.lms_oc_lastmod == NULL ) {
751 /* schema integration */
752 for ( i = 0; mat[i].name; i++ ) {
753 LDAPAttributeType *at;
756 AttributeDescription **ad;
758 at = ldap_str2attributetype( mat[i].schema, &code,
759 &err, LDAP_SCHEMA_ALLOW_ALL );
761 Debug( LDAP_DEBUG_ANY, "lastmod_init: "
762 "in AttributeType '%s' %s before %s\n",
763 mat[i].name, ldap_scherr2str(code), err );
767 if ( at->at_oid == NULL ) {
768 Debug( LDAP_DEBUG_ANY, "lastmod_init: "
769 "null OID for attributeType '%s'\n",
774 code = at_add(at, 0, NULL, &err);
776 Debug( LDAP_DEBUG_ANY, "lastmod_init: "
777 "%s in attributeType '%s'\n",
778 scherr2str(code), mat[i].name, 0 );
783 ad = ((AttributeDescription **)&(((char *)&lastmod_schema)[mat[i].offset]));
785 if ( slap_str2ad( mat[i].name, ad, &text ) ) {
786 Debug( LDAP_DEBUG_ANY,
787 "lastmod_init: %s\n", text, 0, 0 );
791 (*ad)->ad_type->sat_flags |= mat[i].flags;
794 for ( i = 0; moc[i].name; i++ ) {
800 oc = ldap_str2objectclass(moc[i].schema, &code, &err,
801 LDAP_SCHEMA_ALLOW_ALL );
803 Debug( LDAP_DEBUG_ANY,
804 "unable to parse lastmod objectClass '%s': "
805 "%s before %s\n" , moc[i].name,
806 ldap_scherr2str(code), err );
810 if ( oc->oc_oid == NULL ) {
811 Debug( LDAP_DEBUG_ANY,
812 "objectClass '%s' has no OID\n" ,
817 code = oc_add(oc, 0, NULL, &err);
819 Debug( LDAP_DEBUG_ANY,
820 "objectClass '%s': %s \"%s\"\n" ,
821 moc[i].name, scherr2str(code), err );
827 Oc = oc_find( moc[i].name );
829 Debug( LDAP_DEBUG_ANY, "lastmod_init: "
830 "unable to find objectClass %s "
831 "(just added)\n", moc[i].name, 0, 0 );
835 Oc->soc_flags |= moc[i].flags;
837 ((ObjectClass **)&(((char *)&lastmod_schema)[moc[i].offset]))[0] = Oc;
841 lmi = (lastmod_info_t *)ch_malloc( sizeof( lastmod_info_t ) );
843 memset( lmi, 0, sizeof( lastmod_info_t ) );
844 lmi->lmi_enabled = 1;
846 on->on_bi.bi_private = lmi;
860 slap_overinst *on = (slap_overinst *)be->bd_info;
861 lastmod_info_t *lmi = (lastmod_info_t *)on->on_bi.bi_private;
863 if ( strcasecmp( argv[ 0 ], "lastmod-rdnvalue" ) == 0 ) {
864 if ( lmi->lmi_rdnvalue.bv_val ) {
865 /* already defined! */
866 ch_free( lmi->lmi_rdnvalue.bv_val );
869 ber_str2bv( argv[ 1 ], 0, 1, &lmi->lmi_rdnvalue );
871 } else if ( strcasecmp( argv[ 0 ], "lastmod-enabled" ) == 0 ) {
872 if ( strcasecmp( argv[ 1 ], "yes" ) == 0 ) {
873 lmi->lmi_enabled = 1;
875 } else if ( strcasecmp( argv[ 1 ], "no" ) == 0 ) {
876 lmi->lmi_enabled = 0;
883 return SLAP_CONF_UNKNOWN;
894 slap_overinst *on = (slap_overinst *) be->bd_info;
895 lastmod_info_t *lmi = (lastmod_info_t *)on->on_bi.bi_private;
897 static char tmbuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
899 char csnbuf[ LDAP_LUTIL_CSNSTR_BUFSIZE ];
900 struct berval entryCSN;
901 struct berval timestamp;
903 if ( !SLAP_LASTMOD( be ) ) {
904 fprintf( stderr, "set \"lastmod on\" to make this overlay effective\n" );
911 timestamp.bv_val = tmbuf;
912 timestamp.bv_len = sizeof(tmbuf);
913 slap_timestamp( &starttime, ×tamp );
915 slap_get_csn( NULL, csnbuf, sizeof(csnbuf), &entryCSN, 0 );
917 if ( BER_BVISNULL( &lmi->lmi_rdnvalue ) ) {
918 ber_str2bv( "Lastmod", 0, 1, &lmi->lmi_rdnvalue );
921 snprintf( buf, sizeof( buf ),
924 "structuralObjectClass: %s\n"
926 "description: This object contains the last modification to this database\n"
930 "createTimestamp: %s\n"
933 "modifyTimestamp: %s\n"
934 "modifiersName: %s\n"
935 "hasSubordinates: FALSE\n",
936 lmi->lmi_rdnvalue.bv_val, BER_BVISEMPTY( &be->be_suffix[ 0 ] ) ? "" : ",", be->be_suffix[ 0 ].bv_val,
937 lastmod_schema.lms_oc_lastmod->soc_cname.bv_val,
938 lastmod_schema.lms_oc_lastmod->soc_cname.bv_val,
939 lmi->lmi_rdnvalue.bv_val,
940 lastmod_schema.lms_ad_lastmodDN->ad_cname.bv_val,
941 lmi->lmi_rdnvalue.bv_val, BER_BVISEMPTY( &be->be_suffix[ 0 ] ) ? "" : ",", be->be_suffix[ 0 ].bv_val,
942 lastmod_schema.lms_ad_lastmodType->ad_cname.bv_val, lastmodType[ LASTMOD_ADD ].bv_val,
943 lastmod_schema.lms_ad_lastmodEnabled->ad_cname.bv_val, lmi->lmi_enabled ? "TRUE" : "FALSE",
945 BER_BVISNULL( &be->be_rootdn ) ? SLAPD_ANONYMOUS : be->be_rootdn.bv_val,
948 BER_BVISNULL( &be->be_rootdn ) ? SLAPD_ANONYMOUS : be->be_rootdn.bv_val );
951 fprintf( stderr, "# entry:\n%s\n", buf );
954 lmi->lmi_e = str2entry( buf );
955 if ( lmi->lmi_e == NULL ) {
959 ldap_pvt_thread_mutex_init( &lmi->lmi_entry_mutex );
969 slap_overinst *on = (slap_overinst *)be->bd_info;
970 lastmod_info_t *lmi = (lastmod_info_t *)on->on_bi.bi_private;
973 if ( !BER_BVISNULL( &lmi->lmi_rdnvalue ) ) {
974 ch_free( lmi->lmi_rdnvalue.bv_val );
978 entry_free( lmi->lmi_e );
980 ldap_pvt_thread_mutex_destroy( &lmi->lmi_entry_mutex );
989 /* This overlay is set up for dynamic loading via moduleload. For static
990 * configuration, you'll need to arrange for the slap_overinst to be
991 * initialized and registered by some other function inside slapd.
994 static slap_overinst lastmod;
999 lastmod.on_bi.bi_type = "lastmod";
1000 lastmod.on_bi.bi_db_init = lastmod_db_init;
1001 lastmod.on_bi.bi_db_config = lastmod_db_config;
1002 lastmod.on_bi.bi_db_destroy = lastmod_db_destroy;
1003 lastmod.on_bi.bi_db_open = lastmod_db_open;
1005 lastmod.on_bi.bi_op_add = lastmod_op_func;
1006 lastmod.on_bi.bi_op_compare = lastmod_op_func;
1007 lastmod.on_bi.bi_op_delete = lastmod_op_func;
1008 lastmod.on_bi.bi_op_modify = lastmod_op_func;
1009 lastmod.on_bi.bi_op_modrdn = lastmod_op_func;
1010 lastmod.on_bi.bi_op_search = lastmod_op_func;
1011 lastmod.on_bi.bi_extended = lastmod_op_func;
1013 lastmod.on_response = lastmod_response;
1015 return overlay_register( &lastmod );
1018 #if SLAPD_OVER_LASTMOD == SLAPD_MOD_DYNAMIC
1020 init_module( int argc, char *argv[] )
1022 return lastmod_init();
1024 #endif /* SLAPD_OVER_LASTMOD == SLAPD_MOD_DYNAMIC */
1026 #endif /* defined(SLAPD_OVER_LASTMOD) */