1 /* refint.c - referential integrity module */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2004-2017 The OpenLDAP Foundation.
6 * Portions Copyright 2004 Symas Corporation.
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 the 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 Symas Corp. for inclusion in
19 * OpenLDAP Software. This work was sponsored by Hewlett-Packard.
24 /* This module maintains referential integrity for a set of
25 * DN-valued attributes by searching for all references to a given
26 * DN whenever the DN is changed or its entry is deleted, and making
27 * the appropriate update.
29 * Updates are performed using the database rootdn in a separate task
30 * to allow the original operation to complete immediately.
33 #ifdef SLAPD_OVER_REFINT
37 #include <ac/string.h>
38 #include <ac/socket.h>
44 static slap_overinst refint;
46 /* The DN to use in the ModifiersName for all refint updates */
47 static BerValue refint_dn = BER_BVC("cn=Referential Integrity Overlay");
48 static BerValue refint_ndn = BER_BVC("cn=referential integrity overlay");
50 typedef struct refint_attrs_s {
51 struct refint_attrs_s *next;
52 AttributeDescription *attr;
61 typedef struct dependents_s {
62 struct dependents_s *next;
63 BerValue dn; /* target dn */
68 typedef struct refint_q {
69 struct refint_q *next;
70 struct refint_data_s *rdata;
71 dependent_data *attrs; /* entries and attrs returned from callback */
80 typedef struct refint_data_s {
81 struct refint_attrs_s *attrs; /* list of known attrs */
82 BerValue dn; /* basedn in parent, */
83 BerValue nothing; /* the nothing value, if needed */
84 BerValue nnothing; /* normalized nothingness */
85 BerValue refint_dn; /* modifier's name */
86 BerValue refint_ndn; /* normalized modifier's name */
91 ldap_pvt_thread_mutex_t qmutex;
94 typedef struct refint_pre_s {
99 #define RUNQ_INTERVAL 36000 /* a long time */
101 static MatchingRule *mr_dnSubtreeMatch;
109 static ConfigDriver refint_cf_gen;
111 static ConfigTable refintcfg[] = {
112 { "refint_attributes", "attribute...", 2, 0, 0,
113 ARG_MAGIC|REFINT_ATTRS, refint_cf_gen,
114 "( OLcfgOvAt:11.1 NAME 'olcRefintAttribute' "
115 "DESC 'Attributes for referential integrity' "
116 "EQUALITY caseIgnoreMatch "
117 "SYNTAX OMsDirectoryString )", NULL, NULL },
118 { "refint_nothing", "string", 2, 2, 0,
119 ARG_DN|ARG_MAGIC|REFINT_NOTHING, refint_cf_gen,
120 "( OLcfgOvAt:11.2 NAME 'olcRefintNothing' "
121 "DESC 'Replacement DN to supply when needed' "
122 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
123 { "refint_modifiersName", "DN", 2, 2, 0,
124 ARG_DN|ARG_MAGIC|REFINT_MODIFIERSNAME, refint_cf_gen,
125 "( OLcfgOvAt:11.3 NAME 'olcRefintModifiersName' "
126 "DESC 'The DN to use as modifiersName' "
127 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
128 { NULL, NULL, 0, 0, 0, ARG_IGNORED }
131 static ConfigOCs refintocs[] = {
132 { "( OLcfgOvOc:11.1 "
133 "NAME 'olcRefintConfig' "
134 "DESC 'Referential integrity configuration' "
135 "SUP olcOverlayConfig "
136 "MAY ( olcRefintAttribute "
137 "$ olcRefintNothing "
138 "$ olcRefintModifiersName "
140 Cft_Overlay, refintcfg },
145 refint_cf_gen(ConfigArgs *c)
147 slap_overinst *on = (slap_overinst *)c->bi;
148 refint_data *dd = (refint_data *)on->on_bi.bi_private;
149 refint_attrs *ip, *pip, **pipp = NULL;
150 AttributeDescription *ad;
152 int rc = ARG_BAD_CONF;
156 case SLAP_CONFIG_EMIT:
161 value_add_one( &c->rvalue_vals,
162 &ip->attr->ad_cname );
168 if ( !BER_BVISEMPTY( &dd->nothing )) {
169 rc = value_add_one( &c->rvalue_vals,
172 rc = value_add_one( &c->rvalue_nvals,
178 case REFINT_MODIFIERSNAME:
179 if ( !BER_BVISEMPTY( &dd->refint_dn )) {
180 rc = value_add_one( &c->rvalue_vals,
183 rc = value_add_one( &c->rvalue_nvals,
193 case LDAP_MOD_DELETE:
206 /* delete from linked list */
207 for ( i=0; i < c->valx; ++i ) {
208 pipp = &(*pipp)->next;
211 *pipp = (*pipp)->next;
213 /* AttributeDescriptions are global so
214 * shouldn't be freed here... */
220 ch_free( dd->nothing.bv_val );
221 ch_free( dd->nnothing.bv_val );
222 BER_BVZERO( &dd->nothing );
223 BER_BVZERO( &dd->nnothing );
226 case REFINT_MODIFIERSNAME:
227 ch_free( dd->refint_dn.bv_val );
228 ch_free( dd->refint_ndn.bv_val );
229 BER_BVZERO( &dd->refint_dn );
230 BER_BVZERO( &dd->refint_ndn );
237 case SLAP_CONFIG_ADD:
238 /* fallthru to LDAP_MOD_ADD */
243 for ( i=1; i < c->argc; ++i ) {
245 if ( slap_str2ad ( c->argv[i], &ad, &text )
248 sizeof ( refint_attrs ) );
250 ip->next = dd->attrs;
253 snprintf( c->cr_msg, sizeof( c->cr_msg ),
254 "%s <%s>: %s", c->argv[0], c->argv[i], text );
255 Debug ( LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE,
256 "%s: %s\n", c->log, c->cr_msg, 0 );
262 if ( !BER_BVISNULL( &c->value_ndn )) {
263 ch_free ( dd->nothing.bv_val );
264 ch_free ( dd->nnothing.bv_val );
265 dd->nothing = c->value_dn;
266 dd->nnothing = c->value_ndn;
272 case REFINT_MODIFIERSNAME:
273 if ( !BER_BVISNULL( &c->value_ndn )) {
274 ch_free( dd->refint_dn.bv_val );
275 ch_free( dd->refint_ndn.bv_val );
276 dd->refint_dn = c->value_dn;
277 dd->refint_ndn = c->value_ndn;
295 ** allocate new refint_data;
296 ** store in on_bi.bi_private;
306 slap_overinst *on = (slap_overinst *)be->bd_info;
307 refint_data *id = ch_calloc(1,sizeof(refint_data));
309 on->on_bi.bi_private = id;
310 ldap_pvt_thread_mutex_init( &id->qmutex );
320 slap_overinst *on = (slap_overinst *)be->bd_info;
322 if ( on->on_bi.bi_private ) {
323 refint_data *id = on->on_bi.bi_private;
324 refint_attrs *ii, *ij;
326 on->on_bi.bi_private = NULL;
327 ldap_pvt_thread_mutex_destroy( &id->qmutex );
329 for(ii = id->attrs; ii; ii = ij) {
334 ch_free( id->nothing.bv_val );
335 BER_BVZERO( &id->nothing );
336 ch_free( id->nnothing.bv_val );
337 BER_BVZERO( &id->nnothing );
345 ** initialize, copy basedn if not already set
355 slap_overinst *on = (slap_overinst *)be->bd_info;
356 refint_data *id = on->on_bi.bi_private;
358 if ( BER_BVISNULL( &id->dn )) {
359 if ( BER_BVISNULL( &be->be_nsuffix[0] ))
361 ber_dupbv( &id->dn, &be->be_nsuffix[0] );
363 if ( BER_BVISNULL( &id->refint_dn ) ) {
364 ber_dupbv( &id->refint_dn, &refint_dn );
365 ber_dupbv( &id->refint_ndn, &refint_ndn );
369 ** find the backend that matches our configured basedn;
370 ** make sure it exists and has search and modify methods;
374 if ( on->on_info->oi_origdb != frontendDB ) {
375 BackendDB *db = select_backend(&id->dn, 1);
380 bi = on->on_info->oi_orig;
383 if ( !bi->bi_op_search || !bi->bi_op_modify ) {
384 Debug( LDAP_DEBUG_CONFIG,
385 "refint_response: backend missing search and/or modify\n",
391 Debug( LDAP_DEBUG_CONFIG,
392 "refint_response: no backend for our baseDN %s??\n",
393 id->dn.bv_val, 0, 0 );
413 slap_overinst *on = (slap_overinst *) be->bd_info;
414 refint_data *id = on->on_bi.bi_private;
416 ch_free( id->dn.bv_val );
417 BER_BVZERO( &id->dn );
418 ch_free( id->refint_dn.bv_val );
419 BER_BVZERO( &id->refint_dn );
420 ch_free( id->refint_ndn.bv_val );
421 BER_BVZERO( &id->refint_ndn );
428 ** generates a list of Attributes from search results
439 refint_q *rq = op->o_callback->sc_private;
440 refint_data *dd = rq->rdata;
441 refint_attrs *ia, *da = dd->attrs, *na;
445 Debug(LDAP_DEBUG_TRACE, "refint_search_cb <%s>\n",
446 rs->sr_entry ? rs->sr_entry->e_name.bv_val : "NOTHING", 0, 0);
448 if (rs->sr_type != REP_SEARCH || !rs->sr_entry) return(0);
451 ** foreach configured attribute type:
452 ** if this attr exists in the search result,
453 ** and it has a value matching the target:
455 ** save/build DNs of any subordinate matches;
456 ** handle special case: found exact + subordinate match;
457 ** handle olcRefintNothing;
461 ip = op->o_tmpalloc(sizeof(dependent_data), op->o_tmpmemctx );
462 ber_dupbv_x( &ip->dn, &rs->sr_entry->e_name, op->o_tmpmemctx );
463 ber_dupbv_x( &ip->ndn, &rs->sr_entry->e_nname, op->o_tmpmemctx );
464 ip->next = rq->attrs;
467 for(ia = da; ia; ia = ia->next) {
468 if ( (a = attr_find(rs->sr_entry->e_attrs, ia->attr) ) ) {
469 int exact = -1, is_exact;
473 /* Are we doing subtree matching or simple equality? */
475 for(i = 0, b = a->a_nvals; b[i].bv_val; i++) {
476 if(dnIsSuffix(&b[i], &rq->oldndn)) {
477 is_exact = b[i].bv_len == rq->oldndn.bv_len;
479 /* Paranoia: skip buggy duplicate exact match,
480 * it would break ra_numvals
482 if ( is_exact && exact >= 0 )
485 /* first match? create structure */
487 na = op->o_tmpcalloc( 1,
488 sizeof( refint_attrs ),
490 na->next = ip->attrs;
498 /* Exact match: refint_repair will deduce the DNs */
502 /* Subordinate match */
503 struct berval newsub, newdn, olddn, oldndn;
506 ber_dupbv_x( &olddn, &a->a_vals[i], op->o_tmpmemctx );
507 ber_bvarray_add_x( &na->old_vals, &olddn, op->o_tmpmemctx );
509 ber_dupbv_x( &oldndn, &a->a_nvals[i], op->o_tmpmemctx );
510 ber_bvarray_add_x( &na->old_nvals, &oldndn, op->o_tmpmemctx );
512 if ( BER_BVISEMPTY( &rq->newdn ) )
515 /* Rename subordinate match: Build new DN */
516 newsub = a->a_vals[i];
517 newsub.bv_len -= rq->olddn.bv_len + 1;
518 build_new_dn( &newdn, &rq->newdn, &newsub, op->o_tmpmemctx );
519 ber_bvarray_add_x( &na->new_vals, &newdn, op->o_tmpmemctx );
521 newsub = a->a_nvals[i];
522 newsub.bv_len -= rq->oldndn.bv_len + 1;
523 build_new_dn( &newdn, &rq->newndn, &newsub, op->o_tmpmemctx );
524 ber_bvarray_add_x( &na->new_nvals, &newdn, op->o_tmpmemctx );
529 /* If we got both subordinate and exact match,
530 * refint_repair won't special-case the exact match */
531 if ( exact >= 0 && na->old_vals ) {
534 ber_dupbv_x( &dn, &a->a_vals[exact], op->o_tmpmemctx );
535 ber_bvarray_add_x( &na->old_vals, &dn, op->o_tmpmemctx );
536 ber_dupbv_x( &dn, &a->a_nvals[exact], op->o_tmpmemctx );
537 ber_bvarray_add_x( &na->old_nvals, &dn, op->o_tmpmemctx );
539 if ( !BER_BVISEMPTY( &rq->newdn ) ) {
540 ber_dupbv_x( &dn, &rq->newdn, op->o_tmpmemctx );
541 ber_bvarray_add_x( &na->new_vals, &dn, op->o_tmpmemctx );
542 ber_dupbv_x( &dn, &rq->newndn, op->o_tmpmemctx );
543 ber_bvarray_add_x( &na->new_nvals, &dn, op->o_tmpmemctx );
547 /* entry has no children, just equality matching */
548 is_exact = attr_valfind( a,
549 SLAP_MR_EQUALITY|SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH|
550 SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH, &rq->oldndn, &i, NULL );
551 if ( is_exact == LDAP_SUCCESS ) {
552 na = op->o_tmpcalloc( 1,
553 sizeof( refint_attrs ),
555 na->next = ip->attrs;
562 /* Deleting/replacing all values and a nothing DN is configured? */
563 if ( na && na->ra_numvals == a->a_numvals && !BER_BVISNULL(&dd->nothing) )
566 Debug( LDAP_DEBUG_TRACE, "refint_search_cb: %s: %s (#%d)\n",
567 a->a_desc->ad_cname.bv_val, rq->olddn.bv_val, i );
581 SlapReply rs = {REP_RESULT};
587 op->o_callback->sc_response = refint_search_cb;
588 op->o_req_dn = op->o_bd->be_suffix[ 0 ];
589 op->o_req_ndn = op->o_bd->be_nsuffix[ 0 ];
590 op->o_dn = op->o_bd->be_rootdn;
591 op->o_ndn = op->o_bd->be_rootndn;
592 cache = op->o_do_not_cache;
593 op->o_do_not_cache = 1;
596 rc = op->o_bd->be_search( op, &rs );
597 op->o_do_not_cache = cache;
599 if ( rc != LDAP_SUCCESS ) {
600 Debug( LDAP_DEBUG_TRACE,
601 "refint_repair: search failed: %d\n",
606 /* safety? paranoid just in case */
607 if ( op->o_callback->sc_private == NULL ) {
608 Debug( LDAP_DEBUG_TRACE,
609 "refint_repair: callback wiped out sc_private?!\n",
614 /* Set up the Modify requests */
615 op->o_callback->sc_response = &slap_null_cb;
618 * [our search callback builds a list of attrs]
620 * make sure its dn has a backend;
621 * build Modification* chain;
622 * call the backend modify function;
628 for ( dp = rq->attrs; dp; dp = dp->next ) {
629 SlapReply rs2 = {REP_RESULT};
633 if ( dp->attrs == NULL ) continue; /* TODO: Is this needed? */
635 op2.o_bd = select_backend( &dp->ndn, 1 );
637 Debug( LDAP_DEBUG_TRACE,
638 "refint_repair: no backend for DN %s!\n",
639 dp->dn.bv_val, 0, 0 );
642 op2.o_tag = LDAP_REQ_MODIFY;
643 op2.orm_modlist = NULL;
644 op2.o_req_dn = dp->dn;
645 op2.o_req_ndn = dp->ndn;
646 /* Internal ops, never replicate these */
647 op2.orm_no_opattrs = 1;
648 op2.o_dont_replicate = 1;
651 /* Set our ModifiersName */
652 if ( SLAP_LASTMOD( op->o_bd ) ) {
653 m = op2.o_tmpalloc( sizeof(Modifications) +
654 4*sizeof(BerValue), op2.o_tmpmemctx );
655 m->sml_next = op2.orm_modlist;
657 m->sml_op = LDAP_MOD_REPLACE;
658 m->sml_flags = SLAP_MOD_INTERNAL;
659 m->sml_desc = slap_schema.si_ad_modifiersName;
660 m->sml_type = m->sml_desc->ad_cname;
662 m->sml_values = (BerVarray)(m+1);
663 m->sml_nvalues = m->sml_values+2;
664 BER_BVZERO( &m->sml_values[1] );
665 BER_BVZERO( &m->sml_nvalues[1] );
666 m->sml_values[0] = id->refint_dn;
667 m->sml_nvalues[0] = id->refint_ndn;
670 for ( ra = dp->attrs; ra; ra = ra->next ) {
674 if ( ra->dont_empty || !BER_BVISEMPTY( &rq->newdn ) ) {
675 len = sizeof(Modifications);
677 if ( ra->new_vals == NULL ) {
678 len += 4*sizeof(BerValue);
681 m = op2.o_tmpalloc( len, op2.o_tmpmemctx );
682 m->sml_next = op2.orm_modlist;
684 m->sml_op = LDAP_MOD_ADD;
686 m->sml_desc = ra->attr;
687 m->sml_type = ra->attr->ad_cname;
688 if ( ra->new_vals == NULL ) {
689 m->sml_values = (BerVarray)(m+1);
690 m->sml_nvalues = m->sml_values+2;
691 BER_BVZERO( &m->sml_values[1] );
692 BER_BVZERO( &m->sml_nvalues[1] );
694 if ( BER_BVISEMPTY( &rq->newdn ) ) {
695 m->sml_values[0] = id->nothing;
696 m->sml_nvalues[0] = id->nnothing;
698 m->sml_values[0] = rq->newdn;
699 m->sml_nvalues[0] = rq->newndn;
702 m->sml_values = ra->new_vals;
703 m->sml_nvalues = ra->new_nvals;
704 m->sml_numvals = ra->ra_numvals;
709 len = sizeof(Modifications);
710 if ( ra->old_vals == NULL ) {
711 len += 4*sizeof(BerValue);
713 m = op2.o_tmpalloc( len, op2.o_tmpmemctx );
714 m->sml_next = op2.orm_modlist;
716 m->sml_op = LDAP_MOD_DELETE;
718 m->sml_desc = ra->attr;
719 m->sml_type = ra->attr->ad_cname;
720 if ( ra->old_vals == NULL ) {
722 m->sml_values = (BerVarray)(m+1);
723 m->sml_nvalues = m->sml_values+2;
724 m->sml_values[0] = rq->olddn;
725 m->sml_nvalues[0] = rq->oldndn;
726 BER_BVZERO( &m->sml_values[1] );
727 BER_BVZERO( &m->sml_nvalues[1] );
729 m->sml_values = ra->old_vals;
730 m->sml_nvalues = ra->old_nvals;
731 m->sml_numvals = ra->ra_numvals;
735 op2.o_dn = op2.o_bd->be_rootdn;
736 op2.o_ndn = op2.o_bd->be_rootndn;
737 rc = op2.o_bd->be_modify( &op2, &rs2 );
738 if ( rc != LDAP_SUCCESS ) {
739 Debug( LDAP_DEBUG_TRACE,
740 "refint_repair: dependent modify failed: %d\n",
744 while ( ( m = op2.orm_modlist ) ) {
745 op2.orm_modlist = m->sml_next;
746 op2.o_tmpfree( m, op2.o_tmpmemctx );
755 refint_qtask( void *ctx, void *arg )
757 struct re_s *rtask = arg;
758 refint_data *id = rtask->arg;
759 Connection conn = {0};
760 OperationBuffer opbuf;
762 slap_callback cb = { NULL, NULL, NULL, NULL };
766 int pausing = 0, rc = 0;
768 connection_fake_init( &conn, &opbuf, ctx );
772 ** build a search filter for all configured attributes;
773 ** populate our Operation;
774 ** pass our data (attr list, dn) to backend via sc_private;
775 ** call the backend search function;
776 ** nb: (|(one=thing)) is valid, but do smart formatting anyway;
777 ** nb: 16 is arbitrarily a dozen or so extra bytes;
781 ftop.f_choice = LDAP_FILTER_OR;
784 op->ors_filter = &ftop;
785 for(ip = id->attrs; ip; ip = ip->next) {
786 /* this filter can be either EQUALITY or EXT */
787 fptr = op->o_tmpcalloc( sizeof(Filter) + sizeof(MatchingRuleAssertion),
788 1, op->o_tmpmemctx );
789 fptr->f_mra = (MatchingRuleAssertion *)(fptr+1);
790 fptr->f_mr_rule = mr_dnSubtreeMatch;
791 fptr->f_mr_rule_text = mr_dnSubtreeMatch->smr_bvoid;
792 fptr->f_mr_desc = ip->attr;
793 fptr->f_mr_dnattrs = 0;
794 fptr->f_next = ftop.f_or;
799 dependent_data *dp, *dp_next;
800 refint_attrs *ra, *ra_next;
802 if ( ldap_pvt_thread_pool_pausing( &connection_pool ) > 0 ) {
808 ldap_pvt_thread_mutex_lock( &id->qmutex );
811 id->qhead = rq->next;
815 ldap_pvt_thread_mutex_unlock( &id->qmutex );
819 for (fptr = ftop.f_or; fptr; fptr = fptr->f_next ) {
820 fptr->f_mr_value = rq->oldndn;
821 /* Use (attr:dnSubtreeMatch:=value) to catch subtree rename
822 * and subtree delete where supported */
824 fptr->f_choice = LDAP_FILTER_EXT;
826 fptr->f_choice = LDAP_FILTER_EQUALITY;
829 filter2bv_x( op, op->ors_filter, &op->ors_filterstr );
831 /* callback gets the searched dn instead */
833 cb.sc_response = refint_search_cb;
834 op->o_callback = &cb;
835 op->o_tag = LDAP_REQ_SEARCH;
836 op->ors_scope = LDAP_SCOPE_SUBTREE;
837 op->ors_deref = LDAP_DEREF_NEVER;
838 op->ors_limit = NULL;
839 op->ors_slimit = SLAP_NO_LIMIT;
840 op->ors_tlimit = SLAP_NO_LIMIT;
843 op->ors_attrs = slap_anlist_no_attrs;
845 slap_op_time( &op->o_time, &op->o_tincr );
847 if ( rq->db != NULL ) {
849 rc = refint_repair( op, id, rq );
854 LDAP_STAILQ_FOREACH( be, &backendDB, be_next ) {
855 /* we may want to skip cn=config */
856 if ( be == LDAP_STAILQ_FIRST(&backendDB) ) {
860 if ( be->be_search && be->be_modify ) {
862 rc = refint_repair( op, id, rq );
867 for ( dp = rq->attrs; dp; dp = dp_next ) {
869 for ( ra = dp->attrs; ra; ra = ra_next ) {
871 ber_bvarray_free_x( ra->new_nvals, op->o_tmpmemctx );
872 ber_bvarray_free_x( ra->new_vals, op->o_tmpmemctx );
873 ber_bvarray_free_x( ra->old_nvals, op->o_tmpmemctx );
874 ber_bvarray_free_x( ra->old_vals, op->o_tmpmemctx );
875 op->o_tmpfree( ra, op->o_tmpmemctx );
877 op->o_tmpfree( dp->ndn.bv_val, op->o_tmpmemctx );
878 op->o_tmpfree( dp->dn.bv_val, op->o_tmpmemctx );
879 op->o_tmpfree( dp, op->o_tmpmemctx );
881 op->o_tmpfree( op->ors_filterstr.bv_val, op->o_tmpmemctx );
882 if ( rc == LDAP_BUSY ) {
884 /* re-queue this op */
885 ldap_pvt_thread_mutex_lock( &id->qmutex );
886 rq->next = id->qhead;
890 ldap_pvt_thread_mutex_unlock( &id->qmutex );
894 if ( !BER_BVISNULL( &rq->newndn )) {
895 ch_free( rq->newndn.bv_val );
896 ch_free( rq->newdn.bv_val );
898 ch_free( rq->oldndn.bv_val );
899 ch_free( rq->olddn.bv_val );
904 for ( fptr = ftop.f_or; fptr; ) {
905 Filter *f_next = fptr->f_next;
906 op->o_tmpfree( fptr, op->o_tmpmemctx );
910 /* wait until we get explicitly scheduled again */
911 ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
912 ldap_pvt_runqueue_stoptask( &slapd_rq, id->qtask );
914 /* try to run again as soon as the pause is done */
915 id->qtask->interval.tv_sec = 0;
916 ldap_pvt_runqueue_resched( &slapd_rq, id->qtask, 0 );
917 id->qtask->interval.tv_sec = RUNQ_INTERVAL;
919 ldap_pvt_runqueue_resched( &slapd_rq,id->qtask, 1 );
921 ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
928 ** search for matching records and modify them
945 /* If the main op failed or is not a Delete or ModRdn, ignore it */
946 if (( op->o_tag != LDAP_REQ_DELETE && op->o_tag != LDAP_REQ_MODRDN ) ||
947 rs->sr_err != LDAP_SUCCESS )
948 return SLAP_CB_CONTINUE;
950 rp = op->o_callback->sc_private;
952 id = on->on_bi.bi_private;
954 rq = ch_calloc( 1, sizeof( refint_q ));
955 ber_dupbv( &rq->olddn, &op->o_req_dn );
956 ber_dupbv( &rq->oldndn, &op->o_req_ndn );
959 rq->do_sub = rp->do_sub;
961 if ( op->o_tag == LDAP_REQ_MODRDN ) {
962 if ( op->oq_modrdn.rs_newSup ) {
963 pdn = *op->oq_modrdn.rs_newSup;
965 dnParent( &op->o_req_dn, &pdn );
967 build_new_dn( &rq->newdn, &pdn, &op->orr_newrdn, NULL );
968 if ( op->oq_modrdn.rs_nnewSup ) {
969 pdn = *op->oq_modrdn.rs_nnewSup;
971 dnParent( &op->o_req_ndn, &pdn );
973 build_new_dn( &rq->newndn, &pdn, &op->orr_nnewrdn, NULL );
976 ldap_pvt_thread_mutex_lock( &id->qmutex );
978 id->qtail->next = rq;
983 ldap_pvt_thread_mutex_unlock( &id->qmutex );
986 ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
988 id->qtask = ldap_pvt_runqueue_insert( &slapd_rq, RUNQ_INTERVAL,
989 refint_qtask, id, "refint_qtask",
990 op->o_bd->be_suffix[0].bv_val );
993 if ( !ldap_pvt_runqueue_isrunning( &slapd_rq, id->qtask ) &&
994 !id->qtask->next_sched.tv_sec ) {
995 id->qtask->interval.tv_sec = 0;
996 ldap_pvt_runqueue_resched( &slapd_rq, id->qtask, 0 );
997 id->qtask->interval.tv_sec = RUNQ_INTERVAL;
1001 ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
1003 slap_wake_listener();
1005 return SLAP_CB_CONTINUE;
1008 /* Check if the target entry exists and has children.
1009 * Do nothing if target doesn't exist.
1017 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
1018 refint_data *id = on->on_bi.bi_private;
1022 /* are any attrs configured? */
1024 return SLAP_CB_CONTINUE;
1026 rc = overlay_entry_get_ov( op, &op->o_req_ndn, NULL, NULL, 0, &e, on );
1027 if ( rc == LDAP_SUCCESS ) {
1028 slap_callback *sc = op->o_tmpcalloc( 1,
1029 sizeof(slap_callback)+sizeof(refint_pre), op->o_tmpmemctx );
1030 refint_pre *rp = (refint_pre *)(sc+1);
1032 rp->do_sub = 1; /* assume there are children */
1033 if ( op->o_bd->be_has_subordinates ) {
1035 rc = op->o_bd->be_has_subordinates( op, e, &has );
1036 /* there definitely are not children */
1037 if ( rc == LDAP_SUCCESS && has == LDAP_COMPARE_FALSE )
1040 overlay_entry_release_ov( op, e, 0, on );
1041 sc->sc_response = refint_response;
1042 sc->sc_private = rp;
1043 sc->sc_next = op->o_callback;
1044 op->o_callback = sc;
1046 return SLAP_CB_CONTINUE;
1050 ** init_module is last so the symbols resolve "for free" --
1051 ** it expects to be called automagically during dynamic module initialization
1054 int refint_initialize() {
1057 mr_dnSubtreeMatch = mr_find( "dnSubtreeMatch" );
1058 if ( mr_dnSubtreeMatch == NULL ) {
1059 Debug( LDAP_DEBUG_ANY, "refint_initialize: "
1060 "unable to find MatchingRule 'dnSubtreeMatch'.\n",
1065 /* statically declared just after the #includes at top */
1066 refint.on_bi.bi_type = "refint";
1067 refint.on_bi.bi_db_init = refint_db_init;
1068 refint.on_bi.bi_db_destroy = refint_db_destroy;
1069 refint.on_bi.bi_db_open = refint_open;
1070 refint.on_bi.bi_db_close = refint_close;
1071 refint.on_bi.bi_op_delete = refint_preop;
1072 refint.on_bi.bi_op_modrdn = refint_preop;
1074 refint.on_bi.bi_cf_ocs = refintocs;
1075 rc = config_register_schema ( refintcfg, refintocs );
1076 if ( rc ) return rc;
1078 return(overlay_register(&refint));
1081 #if SLAPD_OVER_REFINT == SLAPD_MOD_DYNAMIC && defined(PIC)
1082 int init_module(int argc, char *argv[]) {
1083 return refint_initialize();
1087 #endif /* SLAPD_OVER_REFINT */