1 /* refint.c - referential integrity module */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2004-2010 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;
60 typedef struct dependents_s {
61 struct dependents_s *next;
62 BerValue dn; /* target dn */
67 typedef struct refint_q {
68 struct refint_q *next;
69 struct refint_data_s *rdata;
70 dependent_data *attrs; /* entries and attrs returned from callback */
78 typedef struct refint_data_s {
79 struct refint_attrs_s *attrs; /* list of known attrs */
80 BerValue dn; /* basedn in parent, */
81 BerValue nothing; /* the nothing value, if needed */
82 BerValue nnothing; /* normalized nothingness */
83 BerValue refint_dn; /* modifier's name */
84 BerValue refint_ndn; /* normalized modifier's name */
88 ldap_pvt_thread_mutex_t qmutex;
91 #define RUNQ_INTERVAL 36000 /* a long time */
93 static MatchingRule *mr_dnSubtreeMatch;
101 static ConfigDriver refint_cf_gen;
103 static ConfigTable refintcfg[] = {
104 { "refint_attributes", "attribute...", 2, 0, 0,
105 ARG_MAGIC|REFINT_ATTRS, refint_cf_gen,
106 "( OLcfgOvAt:11.1 NAME 'olcRefintAttribute' "
107 "DESC 'Attributes for referential integrity' "
108 "EQUALITY caseIgnoreMatch "
109 "SYNTAX OMsDirectoryString )", NULL, NULL },
110 { "refint_nothing", "string", 2, 2, 0,
111 ARG_DN|ARG_MAGIC|REFINT_NOTHING, refint_cf_gen,
112 "( OLcfgOvAt:11.2 NAME 'olcRefintNothing' "
113 "DESC 'Replacement DN to supply when needed' "
114 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
115 { "refint_modifiersName", "DN", 2, 2, 0,
116 ARG_DN|ARG_MAGIC|REFINT_MODIFIERSNAME, refint_cf_gen,
117 "( OLcfgOvAt:11.3 NAME 'olcRefintModifiersName' "
118 "DESC 'The DN to use as modifiersName' "
119 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
120 { NULL, NULL, 0, 0, 0, ARG_IGNORED }
123 static ConfigOCs refintocs[] = {
124 { "( OLcfgOvOc:11.1 "
125 "NAME 'olcRefintConfig' "
126 "DESC 'Referential integrity configuration' "
127 "SUP olcOverlayConfig "
128 "MAY ( olcRefintAttribute "
129 "$ olcRefintNothing "
130 "$ olcRefintModifiersName "
132 Cft_Overlay, refintcfg },
137 refint_cf_gen(ConfigArgs *c)
139 slap_overinst *on = (slap_overinst *)c->bi;
140 refint_data *dd = (refint_data *)on->on_bi.bi_private;
141 refint_attrs *ip, *pip, **pipp = NULL;
142 AttributeDescription *ad;
144 int rc = ARG_BAD_CONF;
148 case SLAP_CONFIG_EMIT:
153 value_add_one( &c->rvalue_vals,
154 &ip->attr->ad_cname );
160 if ( !BER_BVISEMPTY( &dd->nothing )) {
161 rc = value_add_one( &c->rvalue_vals,
164 rc = value_add_one( &c->rvalue_nvals,
170 case REFINT_MODIFIERSNAME:
171 if ( !BER_BVISEMPTY( &dd->refint_dn )) {
172 rc = value_add_one( &c->rvalue_vals,
175 rc = value_add_one( &c->rvalue_nvals,
185 case LDAP_MOD_DELETE:
198 /* delete from linked list */
199 for ( i=0; i < c->valx; ++i ) {
200 pipp = &(*pipp)->next;
203 *pipp = (*pipp)->next;
205 /* AttributeDescriptions are global so
206 * shouldn't be freed here... */
212 ch_free( dd->nothing.bv_val );
213 ch_free( dd->nnothing.bv_val );
214 BER_BVZERO( &dd->nothing );
215 BER_BVZERO( &dd->nnothing );
218 case REFINT_MODIFIERSNAME:
219 ch_free( dd->refint_dn.bv_val );
220 ch_free( dd->refint_ndn.bv_val );
221 BER_BVZERO( &dd->refint_dn );
222 BER_BVZERO( &dd->refint_ndn );
229 case SLAP_CONFIG_ADD:
230 /* fallthrough to LDAP_MOD_ADD */
235 for ( i=1; i < c->argc; ++i ) {
237 if ( slap_str2ad ( c->argv[i], &ad, &text )
240 sizeof ( refint_attrs ) );
242 ip->next = dd->attrs;
245 snprintf( c->cr_msg, sizeof( c->cr_msg ),
246 "%s <%s>: %s", c->argv[0], c->argv[i], text );
247 Debug ( LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE,
248 "%s: %s\n", c->log, c->cr_msg, 0 );
254 if ( !BER_BVISNULL( &c->value_ndn )) {
255 ch_free ( dd->nothing.bv_val );
256 ch_free ( dd->nnothing.bv_val );
257 dd->nothing = c->value_dn;
258 dd->nnothing = c->value_ndn;
264 case REFINT_MODIFIERSNAME:
265 if ( !BER_BVISNULL( &c->value_ndn )) {
266 ch_free( &dd->refint_dn.bv_val );
267 ch_free( &dd->refint_ndn.bv_val );
268 dd->refint_dn = c->value_dn;
269 dd->refint_ndn = c->value_ndn;
287 ** allocate new refint_data;
288 ** store in on_bi.bi_private;
298 slap_overinst *on = (slap_overinst *)be->bd_info;
299 refint_data *id = ch_calloc(1,sizeof(refint_data));
301 on->on_bi.bi_private = id;
302 ldap_pvt_thread_mutex_init( &id->qmutex );
312 slap_overinst *on = (slap_overinst *)be->bd_info;
314 if ( on->on_bi.bi_private ) {
315 refint_data *id = on->on_bi.bi_private;
316 on->on_bi.bi_private = NULL;
317 ldap_pvt_thread_mutex_destroy( &id->qmutex );
324 ** initialize, copy basedn if not already set
334 slap_overinst *on = (slap_overinst *)be->bd_info;
335 refint_data *id = on->on_bi.bi_private;
337 if ( BER_BVISNULL( &id->dn )) {
338 if ( BER_BVISNULL( &be->be_nsuffix[0] ))
340 ber_dupbv( &id->dn, &be->be_nsuffix[0] );
342 if ( BER_BVISNULL( &id->refint_dn ) ) {
343 ber_dupbv( &id->refint_dn, &refint_dn );
344 ber_dupbv( &id->refint_ndn, &refint_ndn );
351 ** foreach configured attribute:
354 ** reset on_bi.bi_private;
355 ** free our config data;
365 slap_overinst *on = (slap_overinst *) be->bd_info;
366 refint_data *id = on->on_bi.bi_private;
367 refint_attrs *ii, *ij;
369 for(ii = id->attrs; ii; ii = ij) {
375 ch_free( id->dn.bv_val );
376 BER_BVZERO( &id->dn );
377 ch_free( id->nothing.bv_val );
378 BER_BVZERO( &id->nothing );
379 ch_free( id->nnothing.bv_val );
380 BER_BVZERO( &id->nnothing );
381 ch_free( id->refint_dn.bv_val );
382 BER_BVZERO( &id->refint_dn );
383 ch_free( id->refint_ndn.bv_val );
384 BER_BVZERO( &id->refint_ndn );
391 ** generates a list of Attributes from search results
402 refint_q *rq = op->o_callback->sc_private;
403 refint_data *dd = rq->rdata;
404 refint_attrs *ia, *da = dd->attrs, *na;
408 Debug(LDAP_DEBUG_TRACE, "refint_search_cb <%s>\n",
409 rs->sr_entry ? rs->sr_entry->e_name.bv_val : "NOTHING", 0, 0);
411 if (rs->sr_type != REP_SEARCH || !rs->sr_entry) return(0);
414 ** foreach configured attribute type:
415 ** if this attr exists in the search result,
416 ** and it has a value matching the target:
418 ** if this is a delete and there's only one value:
419 ** allocate the same attr again;
423 ip = op->o_tmpalloc(sizeof(dependent_data), op->o_tmpmemctx );
424 ber_dupbv_x( &ip->dn, &rs->sr_entry->e_name, op->o_tmpmemctx );
425 ber_dupbv_x( &ip->ndn, &rs->sr_entry->e_nname, op->o_tmpmemctx );
426 ip->next = rq->attrs;
429 for(ia = da; ia; ia = ia->next) {
430 if ( (a = attr_find(rs->sr_entry->e_attrs, ia->attr) ) ) {
431 int first = -1, count = 0, deleted = 0;
435 for(i = 0, b = a->a_nvals; b[i].bv_val; i++) {
438 if(dnIsSuffix(&b[i], &rq->oldndn)) {
439 /* first match? create structure */
441 na = op->o_tmpcalloc( 1,
442 sizeof( refint_attrs ),
444 na->next = ip->attrs;
448 /* delete, or exact match? note it's first match */
449 if ( BER_BVISEMPTY( &rq->newdn ) &&
450 b[i].bv_len == rq->oldndn.bv_len )
456 /* if it's a rename, or a subordinate match,
457 * save old and build new dn */
458 if ( !BER_BVISEMPTY( &rq->newdn ) &&
459 b[i].bv_len != rq->oldndn.bv_len )
461 struct berval newsub, newdn, olddn, oldndn;
463 /* if not first, save first as well */
466 ber_dupbv_x( &olddn, &a->a_vals[first], op->o_tmpmemctx );
467 ber_bvarray_add_x( &na->old_vals, &olddn, op->o_tmpmemctx );
468 ber_dupbv_x( &oldndn, &a->a_nvals[first], op->o_tmpmemctx );
469 ber_bvarray_add_x( &na->old_nvals, &oldndn, op->o_tmpmemctx );
472 newsub = a->a_vals[first];
473 newsub.bv_len -= rq->olddn.bv_len + 1;
475 build_new_dn( &newdn, &rq->newdn, &newsub, op->o_tmpmemctx );
477 ber_bvarray_add_x( &na->new_vals, &newdn, op->o_tmpmemctx );
479 newsub = a->a_nvals[first];
480 newsub.bv_len -= rq->oldndn.bv_len + 1;
482 build_new_dn( &newdn, &rq->newndn, &newsub, op->o_tmpmemctx );
484 ber_bvarray_add_x( &na->new_nvals, &newdn, op->o_tmpmemctx );
489 ber_dupbv_x( &olddn, &a->a_vals[i], op->o_tmpmemctx );
490 ber_bvarray_add_x( &na->old_vals, &olddn, op->o_tmpmemctx );
491 ber_dupbv_x( &oldndn, &a->a_nvals[i], op->o_tmpmemctx );
492 ber_bvarray_add_x( &na->old_nvals, &oldndn, op->o_tmpmemctx );
495 newsub = a->a_vals[i];
496 newsub.bv_len -= rq->olddn.bv_len + 1;
498 build_new_dn( &newdn, &rq->newdn, &newsub, op->o_tmpmemctx );
500 ber_bvarray_add_x( &na->new_vals, &newdn, op->o_tmpmemctx );
502 newsub = a->a_nvals[i];
503 newsub.bv_len -= rq->oldndn.bv_len + 1;
505 build_new_dn( &newdn, &rq->newndn, &newsub, op->o_tmpmemctx );
507 ber_bvarray_add_x( &na->new_nvals, &newdn, op->o_tmpmemctx );
511 if ( BER_BVISEMPTY( &rq->newdn ) ) {
516 /* If this is a delete and no value would be left, and
517 * we have a nothing DN configured, allocate the attr again.
519 if ( count == deleted && !BER_BVISNULL(&dd->nothing) )
521 na = op->o_tmpcalloc( 1,
522 sizeof( refint_attrs ),
524 na->next = ip->attrs;
529 Debug( LDAP_DEBUG_TRACE, "refint_search_cb: %s: %s (#%d)\n",
530 a->a_desc->ad_cname.bv_val, rq->olddn.bv_val, count );
548 op->o_callback->sc_response = refint_search_cb;
549 op->o_req_dn = op->o_bd->be_suffix[ 0 ];
550 op->o_req_ndn = op->o_bd->be_nsuffix[ 0 ];
551 op->o_dn = op->o_bd->be_rootdn;
552 op->o_ndn = op->o_bd->be_rootndn;
555 rc = op->o_bd->be_search( op, rs );
557 if ( rc != LDAP_SUCCESS ) {
558 Debug( LDAP_DEBUG_TRACE,
559 "refint_repair: search failed: %d\n",
564 /* safety? paranoid just in case */
565 if ( op->o_callback->sc_private == NULL ) {
566 Debug( LDAP_DEBUG_TRACE,
567 "refint_repair: callback wiped out sc_private?!\n",
572 /* Set up the Modify requests */
573 op->o_callback->sc_response = &slap_null_cb;
576 * [our search callback builds a list of attrs]
578 * make sure its dn has a backend;
579 * build Modification* chain;
580 * call the backend modify function;
584 for ( dp = rq->attrs; dp; dp = dp->next ) {
586 SlapReply rs2 = { 0 };
590 op2.o_tag = LDAP_REQ_MODIFY;
591 op2.orm_modlist = NULL;
592 op2.o_req_dn = dp->dn;
593 op2.o_req_ndn = dp->ndn;
594 op2.o_bd = select_backend( &dp->ndn, 1 );
596 Debug( LDAP_DEBUG_TRACE,
597 "refint_repair: no backend for DN %s!\n",
598 dp->dn.bv_val, 0, 0 );
602 rs2.sr_type = REP_RESULT;
603 for ( ra = dp->attrs; ra; ra = ra->next ) {
606 /* Set our ModifiersName */
607 if ( SLAP_LASTMOD( op->o_bd ) ) {
608 m = op2.o_tmpalloc( sizeof(Modifications) +
609 4*sizeof(BerValue), op2.o_tmpmemctx );
610 m->sml_next = op2.orm_modlist;
612 m->sml_op = LDAP_MOD_REPLACE;
613 m->sml_flags = SLAP_MOD_INTERNAL;
614 m->sml_desc = slap_schema.si_ad_modifiersName;
615 m->sml_type = m->sml_desc->ad_cname;
617 m->sml_values = (BerVarray)(m+1);
618 m->sml_nvalues = m->sml_values+2;
619 BER_BVZERO( &m->sml_values[1] );
620 BER_BVZERO( &m->sml_nvalues[1] );
621 m->sml_values[0] = id->refint_dn;
622 m->sml_nvalues[0] = id->refint_ndn;
624 if ( !BER_BVISEMPTY( &rq->newdn ) || ( ra->next &&
625 ra->attr == ra->next->attr ) )
627 len = sizeof(Modifications);
629 if ( ra->new_vals == NULL ) {
630 len += 4*sizeof(BerValue);
633 m = op2.o_tmpalloc( len, op2.o_tmpmemctx );
634 m->sml_next = op2.orm_modlist;
636 m->sml_op = LDAP_MOD_ADD;
638 m->sml_desc = ra->attr;
639 m->sml_type = ra->attr->ad_cname;
640 if ( ra->new_vals == NULL ) {
641 m->sml_values = (BerVarray)(m+1);
642 m->sml_nvalues = m->sml_values+2;
643 BER_BVZERO( &m->sml_values[1] );
644 BER_BVZERO( &m->sml_nvalues[1] );
646 if ( BER_BVISEMPTY( &rq->newdn ) ) {
647 m->sml_values[0] = id->nothing;
648 m->sml_nvalues[0] = id->nnothing;
650 m->sml_values[0] = rq->newdn;
651 m->sml_nvalues[0] = rq->newndn;
654 m->sml_values = ra->new_vals;
655 m->sml_nvalues = ra->new_nvals;
656 m->sml_numvals = ra->ra_numvals;
660 len = sizeof(Modifications);
661 if ( ra->old_vals == NULL ) {
662 len += 4*sizeof(BerValue);
665 m = op2.o_tmpalloc( len, op2.o_tmpmemctx );
666 m->sml_next = op2.orm_modlist;
668 m->sml_op = LDAP_MOD_DELETE;
670 m->sml_desc = ra->attr;
671 m->sml_type = ra->attr->ad_cname;
672 if ( ra->old_vals == NULL ) {
674 m->sml_values = (BerVarray)(m+1);
675 m->sml_nvalues = m->sml_values+2;
676 m->sml_values[0] = rq->olddn;
677 m->sml_nvalues[0] = rq->oldndn;
678 BER_BVZERO( &m->sml_values[1] );
679 BER_BVZERO( &m->sml_nvalues[1] );
681 m->sml_values = ra->old_vals;
682 m->sml_nvalues = ra->old_nvals;
683 m->sml_numvals = ra->ra_numvals;
687 op2.o_dn = op2.o_bd->be_rootdn;
688 op2.o_ndn = op2.o_bd->be_rootndn;
689 slap_op_time( &op2.o_time, &op2.o_tincr );
690 if ( ( rc = op2.o_bd->be_modify( &op2, &rs2 ) ) != LDAP_SUCCESS ) {
691 Debug( LDAP_DEBUG_TRACE,
692 "refint_repair: dependent modify failed: %d\n",
696 while ( ( m = op2.orm_modlist ) ) {
697 op2.orm_modlist = m->sml_next;
698 op2.o_tmpfree( m, op2.o_tmpmemctx );
706 refint_qtask( void *ctx, void *arg )
708 struct re_s *rtask = arg;
709 refint_data *id = rtask->arg;
710 Connection conn = {0};
711 OperationBuffer opbuf;
713 SlapReply rs = {REP_RESULT};
714 slap_callback cb = { NULL, NULL, NULL, NULL };
719 connection_fake_init( &conn, &opbuf, ctx );
723 ** build a search filter for all configured attributes;
724 ** populate our Operation;
725 ** pass our data (attr list, dn) to backend via sc_private;
726 ** call the backend search function;
727 ** nb: (|(one=thing)) is valid, but do smart formatting anyway;
728 ** nb: 16 is arbitrarily a dozen or so extra bytes;
732 ftop.f_choice = LDAP_FILTER_OR;
735 op->ors_filter = &ftop;
736 for(ip = id->attrs; ip; ip = ip->next) {
737 fptr = op->o_tmpcalloc( sizeof(Filter) + sizeof(MatchingRuleAssertion),
738 1, op->o_tmpmemctx );
739 /* Use (attr:dnSubtreeMatch:=value) to catch subtree rename
740 * and subtree delete where supported */
741 fptr->f_choice = LDAP_FILTER_EXT;
742 fptr->f_mra = (MatchingRuleAssertion *)(fptr+1);
743 fptr->f_mr_rule = mr_dnSubtreeMatch;
744 fptr->f_mr_rule_text = mr_dnSubtreeMatch->smr_bvoid;
745 fptr->f_mr_desc = ip->attr;
746 fptr->f_mr_dnattrs = 0;
747 fptr->f_next = ftop.f_or;
752 dependent_data *dp, *dp_next;
753 refint_attrs *ra, *ra_next;
756 ldap_pvt_thread_mutex_lock( &id->qmutex );
759 id->qhead = rq->next;
763 ldap_pvt_thread_mutex_unlock( &id->qmutex );
767 for (fptr = ftop.f_or; fptr; fptr = fptr->f_next )
768 fptr->f_mr_value = rq->oldndn;
770 filter2bv_x( op, op->ors_filter, &op->ors_filterstr );
772 /* callback gets the searched dn instead */
774 cb.sc_response = refint_search_cb;
775 op->o_callback = &cb;
776 op->o_tag = LDAP_REQ_SEARCH;
777 op->ors_scope = LDAP_SCOPE_SUBTREE;
778 op->ors_deref = LDAP_DEREF_NEVER;
779 op->ors_limit = NULL;
780 op->ors_slimit = SLAP_NO_LIMIT;
781 op->ors_tlimit = SLAP_NO_LIMIT;
784 op->ors_attrs = slap_anlist_no_attrs;
786 slap_op_time( &op->o_time, &op->o_tincr );
788 if ( rq->db != NULL ) {
790 refint_repair( op, &rs, id, rq );
795 LDAP_STAILQ_FOREACH( be, &backendDB, be_next ) {
796 /* we may want to skip cn=config */
797 if ( be == LDAP_STAILQ_FIRST(&backendDB) ) {
801 if ( be->be_search && be->be_modify ) {
803 refint_repair( op, &rs, id, rq );
808 for ( dp = rq->attrs; dp; dp = dp_next ) {
810 for ( ra = dp->attrs; ra; ra = ra_next ) {
812 ber_bvarray_free_x( ra->new_nvals, op->o_tmpmemctx );
813 ber_bvarray_free_x( ra->new_vals, op->o_tmpmemctx );
814 ber_bvarray_free_x( ra->old_nvals, op->o_tmpmemctx );
815 ber_bvarray_free_x( ra->old_vals, op->o_tmpmemctx );
816 op->o_tmpfree( ra, op->o_tmpmemctx );
818 op->o_tmpfree( dp->ndn.bv_val, op->o_tmpmemctx );
819 op->o_tmpfree( dp->dn.bv_val, op->o_tmpmemctx );
820 op->o_tmpfree( dp, op->o_tmpmemctx );
822 op->o_tmpfree( op->ors_filterstr.bv_val, op->o_tmpmemctx );
824 if ( !BER_BVISNULL( &rq->newndn )) {
825 ch_free( rq->newndn.bv_val );
826 ch_free( rq->newdn.bv_val );
828 ch_free( rq->oldndn.bv_val );
829 ch_free( rq->olddn.bv_val );
834 for ( fptr = ftop.f_or; fptr; ) {
835 Filter *f_next = fptr->f_next;
836 op->o_tmpfree( fptr, op->o_tmpmemctx );
840 /* wait until we get explicitly scheduled again */
841 ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
842 ldap_pvt_runqueue_stoptask( &slapd_rq, id->qtask );
843 ldap_pvt_runqueue_resched( &slapd_rq,id->qtask, 1 );
844 ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
851 ** search for matching records and modify them
860 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
861 refint_data *id = on->on_bi.bi_private;
865 BackendDB *db = NULL;
868 /* If the main op failed or is not a Delete or ModRdn, ignore it */
869 if (( op->o_tag != LDAP_REQ_DELETE && op->o_tag != LDAP_REQ_MODRDN ) ||
870 rs->sr_err != LDAP_SUCCESS )
871 return SLAP_CB_CONTINUE;
874 ** validate (and count) the list of attrs;
878 for(ip = id->attrs, ac = 0; ip; ip = ip->next, ac++);
880 Debug( LDAP_DEBUG_TRACE,
881 "refint_response called without any attributes\n", 0, 0, 0 );
882 return SLAP_CB_CONTINUE;
886 ** find the backend that matches our configured basedn;
887 ** make sure it exists and has search and modify methods;
891 if ( on->on_info->oi_origdb != frontendDB ) {
892 db = select_backend(&id->dn, 1);
895 if ( !db->be_search || !db->be_modify ) {
896 Debug( LDAP_DEBUG_TRACE,
897 "refint_response: backend missing search and/or modify\n",
899 return SLAP_CB_CONTINUE;
902 Debug( LDAP_DEBUG_TRACE,
903 "refint_response: no backend for our baseDN %s??\n",
904 id->dn.bv_val, 0, 0 );
905 return SLAP_CB_CONTINUE;
909 rq = ch_calloc( 1, sizeof( refint_q ));
910 ber_dupbv( &rq->olddn, &op->o_req_dn );
911 ber_dupbv( &rq->oldndn, &op->o_req_ndn );
915 if ( op->o_tag == LDAP_REQ_MODRDN ) {
916 if ( op->oq_modrdn.rs_newSup ) {
917 pdn = *op->oq_modrdn.rs_newSup;
919 dnParent( &op->o_req_dn, &pdn );
921 build_new_dn( &rq->newdn, &pdn, &op->orr_newrdn, NULL );
922 if ( op->oq_modrdn.rs_nnewSup ) {
923 pdn = *op->oq_modrdn.rs_nnewSup;
925 dnParent( &op->o_req_ndn, &pdn );
927 build_new_dn( &rq->newndn, &pdn, &op->orr_nnewrdn, NULL );
930 ldap_pvt_thread_mutex_lock( &id->qmutex );
932 id->qtail->next = rq;
937 ldap_pvt_thread_mutex_unlock( &id->qmutex );
940 ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
942 id->qtask = ldap_pvt_runqueue_insert( &slapd_rq, RUNQ_INTERVAL,
943 refint_qtask, id, "refint_qtask",
944 op->o_bd->be_suffix[0].bv_val );
947 if ( !ldap_pvt_runqueue_isrunning( &slapd_rq, id->qtask ) &&
948 !id->qtask->next_sched.tv_sec ) {
949 id->qtask->interval.tv_sec = 0;
950 ldap_pvt_runqueue_resched( &slapd_rq, id->qtask, 0 );
951 id->qtask->interval.tv_sec = RUNQ_INTERVAL;
955 ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
957 slap_wake_listener();
959 return SLAP_CB_CONTINUE;
963 ** init_module is last so the symbols resolve "for free" --
964 ** it expects to be called automagically during dynamic module initialization
967 int refint_initialize() {
970 mr_dnSubtreeMatch = mr_find( "dnSubtreeMatch" );
971 if ( mr_dnSubtreeMatch == NULL ) {
972 Debug( LDAP_DEBUG_ANY, "refint_initialize: "
973 "unable to find MatchingRule 'dnSubtreeMatch'.\n",
978 /* statically declared just after the #includes at top */
979 refint.on_bi.bi_type = "refint";
980 refint.on_bi.bi_db_init = refint_db_init;
981 refint.on_bi.bi_db_destroy = refint_db_destroy;
982 refint.on_bi.bi_db_open = refint_open;
983 refint.on_bi.bi_db_close = refint_close;
984 refint.on_response = refint_response;
986 refint.on_bi.bi_cf_ocs = refintocs;
987 rc = config_register_schema ( refintcfg, refintocs );
990 return(overlay_register(&refint));
993 #if SLAPD_OVER_REFINT == SLAPD_MOD_DYNAMIC && defined(PIC)
994 int init_module(int argc, char *argv[]) {
995 return refint_initialize();
999 #endif /* SLAPD_OVER_REFINT */