1 /* backglue.c - backend glue */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2001-2008 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
18 * Functions to glue a bunch of other backends into a single tree.
19 * All of the glued backends must share a common suffix. E.g., you
20 * can glue o=foo and ou=bar,o=foo but you can't glue o=foo and o=bar.
22 * The purpose of these functions is to allow you to split a single database
23 * into pieces (for load balancing purposes, whatever) but still be able
24 * to treat it as a single database after it's been split. As such, each
25 * of the glued backends should have identical rootdn.
33 #include <ac/string.h>
34 #include <ac/socket.h>
40 typedef struct gluenode {
45 typedef struct glueinfo {
51 static slap_overinst glue;
54 static BackendDB *glueBack;
56 static slap_response glue_op_response;
58 /* Just like select_backend, but only for our backends */
65 slap_overinst *on = (slap_overinst *)be->bd_info;
66 glueinfo *gi = (glueinfo *)on->on_bi.bi_private;
69 for (i = gi->gi_nodes-1; i >= 0; i--) {
70 assert( gi->gi_n[i].gn_be->be_nsuffix != NULL );
72 if (dnIsSuffix(dn, &gi->gi_n[i].gn_be->be_nsuffix[0])) {
73 return gi->gi_n[i].gn_be;
76 be->bd_info = on->on_info->oi_orig;
81 typedef struct glue_state {
92 glue_op_cleanup( Operation *op, SlapReply *rs )
94 /* This is not a final result */
95 if (rs->sr_type == REP_RESULT )
96 rs->sr_type = REP_GLUE_RESULT;
97 return SLAP_CB_CONTINUE;
101 glue_op_response ( Operation *op, SlapReply *rs )
103 glue_state *gs = op->o_callback->sc_private;
105 switch(rs->sr_type) {
108 case REP_INTERMEDIATE:
109 return SLAP_CB_CONTINUE;
112 if (rs->sr_err == LDAP_SUCCESS ||
113 rs->sr_err == LDAP_SIZELIMIT_EXCEEDED ||
114 rs->sr_err == LDAP_TIMELIMIT_EXCEEDED ||
115 rs->sr_err == LDAP_ADMINLIMIT_EXCEEDED ||
116 rs->sr_err == LDAP_NO_SUCH_OBJECT ||
117 gs->err != LDAP_SUCCESS)
118 gs->err = rs->sr_err;
119 if (gs->err == LDAP_SUCCESS && gs->matched) {
120 ch_free (gs->matched);
124 if (gs->err != LDAP_SUCCESS && rs->sr_matched) {
126 len = strlen (rs->sr_matched);
127 if (len > gs->matchlen) {
129 ch_free (gs->matched);
130 gs->matched = ch_strdup (rs->sr_matched);
138 for (i=0; rs->sr_ref[i].bv_val; i++);
142 new = ch_malloc ((i+1)*sizeof(struct berval));
144 new = ch_realloc(gs->refs,
145 (j+i+1)*sizeof(struct berval));
147 for (k=0; k<i; j++,k++) {
148 ber_dupbv( &new[j], &rs->sr_ref[k] );
150 new[j].bv_val = NULL;
156 LDAPControl **newctrls;
158 for (i=0; rs->sr_ctrls[i]; i++);
162 newctrls = ch_malloc((i+1)*sizeof(LDAPControl *));
164 /* Forget old pagedResults response if we're sending
167 if ( get_pagedresults( op ) > SLAP_CONTROL_IGNORED ) {
169 for ( k=0; k<i; k++ ) {
170 if ( !strcmp(rs->sr_ctrls[k]->ldctl_oid,
171 LDAP_CONTROL_PAGEDRESULTS )) {
177 for ( k=0; k<j; k++ ) {
178 if ( !strcmp(gs->ctrls[k]->ldctl_oid,
179 LDAP_CONTROL_PAGEDRESULTS )) {
180 gs->ctrls[k]->ldctl_oid = NULL;
181 ldap_control_free( gs->ctrls[k] );
182 gs->ctrls[k] = gs->ctrls[--j];
189 newctrls = ch_realloc(gs->ctrls,
190 (j+i+1)*sizeof(LDAPControl *));
192 for (k=0; k<i; j++,k++) {
193 newctrls[j] = ch_malloc(sizeof(LDAPControl));
194 *newctrls[j] = *rs->sr_ctrls[k];
195 if ( !BER_BVISNULL( &rs->sr_ctrls[k]->ldctl_value ))
196 ber_dupbv( &newctrls[j]->ldctl_value,
197 &rs->sr_ctrls[k]->ldctl_value );
201 gs->ctrls = newctrls;
208 glue_op_func ( Operation *op, SlapReply *rs )
210 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
211 BackendDB *b0 = op->o_bd;
212 BackendInfo *bi0 = op->o_bd->bd_info;
214 slap_operation_t which = op_bind;
217 op->o_bd = glue_back_select (b0, &op->o_req_ndn);
219 /* If we're on the master backend, let overlay framework handle it */
220 if ( op->o_bd == b0 )
221 return SLAP_CB_CONTINUE;
223 b0->bd_info = on->on_info->oi_orig;
226 case LDAP_REQ_ADD: which = op_add; break;
227 case LDAP_REQ_DELETE: which = op_delete; break;
228 case LDAP_REQ_MODIFY: which = op_modify; break;
229 case LDAP_REQ_MODRDN: which = op_modrdn; break;
230 case LDAP_REQ_EXTENDED: which = op_extended; break;
231 default: assert( 0 ); break;
234 func = &op->o_bd->bd_info->bi_op_bind;
236 rc = func[which]( op, rs );
241 op->o_bd->bd_info = bi0;
246 glue_response ( Operation *op, SlapReply *rs )
248 BackendDB *be = op->o_bd;
249 be = glue_back_select (op->o_bd, &op->o_req_ndn);
251 /* If we're on the master backend, let overlay framework handle it.
252 * Otherwise, bail out.
254 return ( op->o_bd == be ) ? SLAP_CB_CONTINUE : SLAP_CB_BYPASS;
258 glue_chk_referrals ( Operation *op, SlapReply *rs )
260 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
261 BackendDB *b0 = op->o_bd;
262 BackendInfo *bi0 = op->o_bd->bd_info;
265 op->o_bd = glue_back_select (b0, &op->o_req_ndn);
266 if ( op->o_bd == b0 )
267 return SLAP_CB_CONTINUE;
269 b0->bd_info = on->on_info->oi_orig;
271 if ( op->o_bd->bd_info->bi_chk_referrals )
272 rc = ( *op->o_bd->bd_info->bi_chk_referrals )( op, rs );
274 rc = SLAP_CB_CONTINUE;
277 op->o_bd->bd_info = bi0;
282 glue_chk_controls ( Operation *op, SlapReply *rs )
284 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
285 BackendDB *b0 = op->o_bd;
286 BackendInfo *bi0 = op->o_bd->bd_info;
287 int rc = SLAP_CB_CONTINUE;
289 op->o_bd = glue_back_select (b0, &op->o_req_ndn);
290 if ( op->o_bd == b0 )
291 return SLAP_CB_CONTINUE;
293 b0->bd_info = on->on_info->oi_orig;
295 /* if the subordinate database has overlays, the bi_chk_controls()
296 * hook is actually over_aux_chk_controls(); in case it actually
297 * wraps a missing hok, we need to mimic the behavior
298 * of the frontend applied to that database */
299 if ( op->o_bd->bd_info->bi_chk_controls ) {
300 rc = ( *op->o_bd->bd_info->bi_chk_controls )( op, rs );
304 if ( rc == SLAP_CB_CONTINUE ) {
305 rc = backend_check_controls( op, rs );
309 op->o_bd->bd_info = bi0;
313 /* ITS#4615 - overlays configured above the glue overlay should be
314 * invoked for the entire glued tree. Overlays configured below the
315 * glue overlay should only be invoked on the master backend.
316 * So, if we're searching on any subordinates, we need to force the
317 * current overlay chain to stop processing, without stopping the
318 * overall callback flow.
321 glue_sub_search( Operation *op, SlapReply *rs, BackendDB *b0,
324 /* Process any overlays on the master backend */
325 if ( op->o_bd == b0 && on->on_next ) {
326 BackendInfo *bi = op->o_bd->bd_info;
327 int rc = SLAP_CB_CONTINUE;
328 for ( on=on->on_next; on; on=on->on_next ) {
329 op->o_bd->bd_info = (BackendInfo *)on;
330 if ( on->on_bi.bi_op_search ) {
331 rc = on->on_bi.bi_op_search( op, rs );
332 if ( rc != SLAP_CB_CONTINUE )
336 op->o_bd->bd_info = bi;
337 if ( rc != SLAP_CB_CONTINUE )
340 return op->o_bd->be_search( op, rs );
344 glue_op_search ( Operation *op, SlapReply *rs )
346 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
347 glueinfo *gi = (glueinfo *)on->on_bi.bi_private;
348 BackendDB *b0 = op->o_bd;
349 BackendDB *b1 = NULL, *btmp;
350 BackendInfo *bi0 = op->o_bd->bd_info;
352 long stoptime = 0, starttime;
353 glue_state gs = {NULL, NULL, NULL, 0, 0, 0, 0};
354 slap_callback cb = { NULL, glue_op_response, glue_op_cleanup, NULL };
356 struct berval dn, ndn, *pdn;
360 cb.sc_next = op->o_callback;
362 starttime = op->o_time;
363 stoptime = slap_get_time () + op->ors_tlimit;
365 op->o_bd = glue_back_select (b0, &op->o_req_ndn);
366 b0->bd_info = on->on_info->oi_orig;
368 switch (op->ors_scope) {
369 case LDAP_SCOPE_BASE:
370 if ( op->o_bd == b0 )
371 return SLAP_CB_CONTINUE;
373 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
374 if (op->o_bd && op->o_bd->be_search) {
375 rs->sr_err = op->o_bd->be_search( op, rs );
379 case LDAP_SCOPE_ONELEVEL:
380 case LDAP_SCOPE_SUBTREE:
381 case LDAP_SCOPE_SUBORDINATE: /* FIXME */
382 op->o_callback = &cb;
383 rs->sr_err = gs.err = LDAP_UNWILLING_TO_PERFORM;
384 scope0 = op->ors_scope;
385 tlimit0 = op->ors_tlimit;
391 * Execute in reverse order, most specific first
393 for (i = gi->gi_nodes; i >= 0; i--) {
394 if ( i == gi->gi_nodes ) {
398 btmp = gi->gi_n[i].gn_be;
399 pdn = &gi->gi_n[i].gn_pdn;
401 if (!btmp || !btmp->be_search)
403 if (!dnIsSuffix(&btmp->be_nsuffix[0], &b1->be_nsuffix[0]))
405 if (get_no_subordinate_glue(op) && btmp != b1)
407 /* If we remembered which backend we were on before,
408 * skip down to it now
410 if ( get_pagedresults( op ) > SLAP_CONTROL_IGNORED &&
411 op->o_conn->c_pagedresults_state.ps_be &&
412 op->o_conn->c_pagedresults_state.ps_be != btmp )
415 if (tlimit0 != SLAP_NO_LIMIT) {
416 op->o_time = slap_get_time();
417 op->ors_tlimit = stoptime - op->o_time;
418 if (op->ors_tlimit <= 0) {
419 rs->sr_err = gs.err = LDAP_TIMELIMIT_EXCEEDED;
432 assert( op->o_bd->be_suffix != NULL );
433 assert( op->o_bd->be_nsuffix != NULL );
435 if (scope0 == LDAP_SCOPE_ONELEVEL &&
438 op->ors_scope = LDAP_SCOPE_BASE;
439 op->o_req_dn = op->o_bd->be_suffix[0];
440 op->o_req_ndn = op->o_bd->be_nsuffix[0];
441 rs->sr_err = op->o_bd->be_search(op, rs);
442 if ( rs->sr_err == LDAP_NO_SUCH_OBJECT ) {
443 gs.err = LDAP_SUCCESS;
445 op->ors_scope = LDAP_SCOPE_ONELEVEL;
449 } else if (scope0 == LDAP_SCOPE_SUBTREE &&
450 dn_match(&op->o_bd->be_nsuffix[0], &ndn))
452 rs->sr_err = glue_sub_search( op, rs, b0, on );
454 } else if (scope0 == LDAP_SCOPE_SUBTREE &&
455 dnIsSuffix(&op->o_bd->be_nsuffix[0], &ndn))
457 op->o_req_dn = op->o_bd->be_suffix[0];
458 op->o_req_ndn = op->o_bd->be_nsuffix[0];
459 rs->sr_err = glue_sub_search( op, rs, b0, on );
460 if ( rs->sr_err == LDAP_NO_SUCH_OBJECT ) {
461 gs.err = LDAP_SUCCESS;
466 } else if (dnIsSuffix(&ndn, &op->o_bd->be_nsuffix[0])) {
467 rs->sr_err = glue_sub_search( op, rs, b0, on );
473 * Add errors that should result in dropping
476 case LDAP_SIZELIMIT_EXCEEDED:
477 case LDAP_TIMELIMIT_EXCEEDED:
478 case LDAP_ADMINLIMIT_EXCEEDED:
479 case LDAP_NO_SUCH_OBJECT:
480 #ifdef LDAP_CONTROL_X_CHAINING_BEHAVIOR
481 case LDAP_X_CANNOT_CHAIN:
482 #endif /* LDAP_CONTROL_X_CHAINING_BEHAVIOR */
486 if ( get_pagedresults( op ) > SLAP_CONTROL_IGNORED ) {
487 PagedResultsState *ps = op->o_pagedresults_state;
489 /* Assume this backend can be forgotten now */
490 op->o_conn->c_pagedresults_state.ps_be = NULL;
492 /* If we have a full page, exit the loop. We may
493 * need to remember this backend so we can continue
494 * from here on a subsequent request.
496 if ( rs->sr_nentries >= ps->ps_size ) {
497 /* Don't bother to remember the first backend.
498 * Only remember the last one if there's more state left.
500 if ( op->o_bd != b0 &&
501 ( op->o_conn->c_pagedresults_state.ps_cookie ||
502 op->o_bd != gi->gi_n[0].gn_be ))
503 op->o_conn->c_pagedresults_state.ps_be = op->o_bd;
507 /* This backend has run out of entries, but more responses
508 * can fit in the page. Fake a reset of the state so the
509 * next backend will start up properly. Only back-[bh]db
510 * and back-sql look at this state info.
512 if ( ps->ps_cookieval.bv_len == sizeof( PagedResultsCookie )) {
514 memset( ps->ps_cookieval.bv_val, 0,
515 sizeof( PagedResultsCookie ));
524 op->ors_scope = scope0;
525 op->ors_tlimit = tlimit0;
526 op->o_time = starttime;
532 if ( op->o_abandon ) {
533 rs->sr_err = SLAPD_ABANDON;
535 op->o_callback = cb.sc_next;
537 rs->sr_matched = gs.matched;
538 rs->sr_ref = gs.refs;
539 rs->sr_ctrls = gs.ctrls;
541 send_ldap_result( op, rs );
545 op->o_bd->bd_info = bi0;
549 ber_bvarray_free(gs.refs);
551 for (i = gs.nctrls; --i >= 0; ) {
552 if (!BER_BVISNULL( &gs.ctrls[i]->ldctl_value ))
553 free(gs.ctrls[i]->ldctl_value.bv_val);
561 static BackendDB toolDB;
564 glue_tool_entry_open (
569 slap_overinfo *oi = (slap_overinfo *)b0->bd_info;
571 /* We don't know which backend to talk to yet, so just
572 * remember the mode and move on...
578 toolDB.bd_info = oi->oi_orig;
584 glue_tool_entry_close (
591 if (!glueBack->be_entry_close)
593 rc = glueBack->be_entry_close (glueBack);
598 static slap_overinst *
603 slap_overinfo *oi = (slap_overinfo *)bi;
606 for ( on = oi->oi_list; on; on=on->on_next ) {
607 if ( !strcmp( on->on_bi.bi_type, glue.on_bi.bi_type ))
613 /* This function will only be called in tool mode */
619 slap_overinst *on = glue_tool_inst( bi );
620 glueinfo *gi = on->on_bi.bi_private;
621 static int glueOpened = 0;
622 int i, j, same, bsame = 0, rc = 0;
624 if (glueOpened) return 0;
628 /* If we were invoked in tool mode, open all the underlying backends */
629 if (slapMode & SLAP_TOOL_MODE) {
630 for (i = 0; i<gi->gi_nodes; i++) {
632 /* Same bi_open as our main backend? */
633 if ( gi->gi_n[i].gn_be->bd_info->bi_open ==
634 on->on_info->oi_orig->bi_open )
637 /* Loop thru the bd_info's and make sure we only
638 * invoke their bi_open functions once each.
640 for ( j = 0; j<i; j++ ) {
641 if ( gi->gi_n[i].gn_be->bd_info->bi_open ==
642 gi->gi_n[j].gn_be->bd_info->bi_open ) {
647 /* OK, it's unique and non-NULL, call it. */
648 if ( !same && gi->gi_n[i].gn_be->bd_info->bi_open )
649 rc = gi->gi_n[i].gn_be->bd_info->bi_open(
650 gi->gi_n[i].gn_be->bd_info );
651 /* Let backend.c take care of the rest of startup */
653 rc = backend_startup_one( gi->gi_n[i].gn_be, NULL );
656 if ( !rc && !bsame && on->on_info->oi_orig->bi_open )
657 rc = on->on_info->oi_orig->bi_open( on->on_info->oi_orig );
659 } /* other case is impossible */
663 /* This function will only be called in tool mode */
669 static int glueClosed = 0;
672 if (glueClosed) return 0;
676 if (slapMode & SLAP_TOOL_MODE) {
677 rc = backend_shutdown( NULL );
687 AttributeDescription *ad,
692 BackendDB *b0 = op->o_bd;
693 op->o_bd = glue_back_select( b0, dn );
695 if ( op->o_bd->be_fetch ) {
696 rc = op->o_bd->be_fetch( op, dn, oc, ad, rw, e );
698 rc = LDAP_UNWILLING_TO_PERFORM;
705 glue_entry_release_rw (
711 BackendDB *b0 = op->o_bd;
714 op->o_bd = glue_back_select (b0, &e->e_nname);
716 if ( op->o_bd->be_release ) {
717 rc = op->o_bd->be_release( op, e, rw );
720 /* FIXME: mimic be_entry_release_rw
721 * when no be_release() available */
731 glue_tool_entry_first (
735 slap_overinst *on = glue_tool_inst( b0->bd_info );
736 glueinfo *gi = on->on_bi.bi_private;
739 /* If we're starting from scratch, start at the most general */
741 if ( toolDB.be_entry_open && toolDB.be_entry_first ) {
744 for (i = gi->gi_nodes-1; i >= 0; i--) {
745 if (gi->gi_n[i].gn_be->be_entry_open &&
746 gi->gi_n[i].gn_be->be_entry_first) {
747 glueBack = gi->gi_n[i].gn_be;
753 if (!glueBack || !glueBack->be_entry_open || !glueBack->be_entry_first ||
754 glueBack->be_entry_open (glueBack, glueMode) != 0)
757 return glueBack->be_entry_first (glueBack);
761 glue_tool_entry_next (
765 slap_overinst *on = glue_tool_inst( b0->bd_info );
766 glueinfo *gi = on->on_bi.bi_private;
770 if (!glueBack || !glueBack->be_entry_next)
773 rc = glueBack->be_entry_next (glueBack);
775 /* If we ran out of entries in one database, move on to the next */
777 if ( glueBack && glueBack->be_entry_close )
778 glueBack->be_entry_close (glueBack);
779 for (i=0; i<gi->gi_nodes; i++) {
780 if (gi->gi_n[i].gn_be == glueBack)
787 glueBack = gi->gi_n[i-1].gn_be;
788 rc = glue_tool_entry_first (b0);
795 glue_tool_entry_get (
800 if (!glueBack || !glueBack->be_entry_get)
803 return glueBack->be_entry_get (glueBack, id);
807 glue_tool_entry_put (
817 b2.bd_info = (BackendInfo *)glue_tool_inst( b0->bd_info );
818 be = glue_back_select (&b2, &e->e_nname);
819 if ( be == &b2 ) be = &toolDB;
821 if (!be->be_entry_put)
825 if ( be->be_entry_open ) {
826 rc = be->be_entry_open (be, glueMode);
831 } else if (be != glueBack) {
832 /* If this entry belongs in a different branch than the
833 * previous one, close the current database and open the
836 if ( glueBack->be_entry_close ) {
837 glueBack->be_entry_close (glueBack);
839 if ( be->be_entry_open ) {
840 rc = be->be_entry_open (be, glueMode);
847 return be->be_entry_put (be, e, text);
851 glue_tool_entry_reindex (
854 AttributeDescription **adv
857 if (!glueBack || !glueBack->be_entry_reindex)
860 return glueBack->be_entry_reindex (glueBack, id, adv);
868 slap_overinst *on = glue_tool_inst( b0->bd_info );
869 glueinfo *gi = on->on_bi.bi_private;
870 BackendInfo *bi = b0->bd_info;
873 /* just sync everyone */
874 for (i = 0; i<gi->gi_nodes; i++)
875 if (gi->gi_n[i].gn_be->be_sync)
876 gi->gi_n[i].gn_be->be_sync (gi->gi_n[i].gn_be);
877 b0->bd_info = on->on_info->oi_orig;
890 slap_overinst *on = (slap_overinst *)be->bd_info;
891 slap_overinfo *oi = on->on_info;
892 BackendInfo *bi = oi->oi_orig;
895 if ( SLAP_GLUE_SUBORDINATE( be )) {
896 Debug( LDAP_DEBUG_ANY, "glue: backend %s is already subordinate, "
897 "cannot have glue overlay!\n",
898 be->be_suffix[0].bv_val, 0, 0 );
902 gi = ch_calloc( 1, sizeof(glueinfo));
903 on->on_bi.bi_private = gi;
904 dnParent( be->be_nsuffix, &gi->gi_pdn );
906 /* Currently the overlay framework doesn't handle these entry points
907 * but we need them....
909 oi->oi_bi.bi_open = glue_open;
910 oi->oi_bi.bi_close = glue_close;
912 /* Only advertise these if the root DB supports them */
913 if ( bi->bi_tool_entry_open )
914 oi->oi_bi.bi_tool_entry_open = glue_tool_entry_open;
915 if ( bi->bi_tool_entry_close )
916 oi->oi_bi.bi_tool_entry_close = glue_tool_entry_close;
917 if ( bi->bi_tool_entry_first )
918 oi->oi_bi.bi_tool_entry_first = glue_tool_entry_first;
919 if ( bi->bi_tool_entry_next )
920 oi->oi_bi.bi_tool_entry_next = glue_tool_entry_next;
921 if ( bi->bi_tool_entry_get )
922 oi->oi_bi.bi_tool_entry_get = glue_tool_entry_get;
923 if ( bi->bi_tool_entry_put )
924 oi->oi_bi.bi_tool_entry_put = glue_tool_entry_put;
925 if ( bi->bi_tool_entry_reindex )
926 oi->oi_bi.bi_tool_entry_reindex = glue_tool_entry_reindex;
927 if ( bi->bi_tool_sync )
928 oi->oi_bi.bi_tool_sync = glue_tool_sync;
930 /*FIXME : need to add support */
931 oi->oi_bi.bi_tool_dn2id_get = 0;
932 oi->oi_bi.bi_tool_entry_modify = 0;
934 SLAP_DBFLAGS( be ) |= SLAP_DBFLAG_GLUE_INSTANCE;
945 slap_overinst *on = (slap_overinst *)be->bd_info;
946 glueinfo *gi = (glueinfo *)on->on_bi.bi_private;
949 return SLAP_CB_CONTINUE;
958 slap_overinst *on = (slap_overinst *)be->bd_info;
960 on->on_info->oi_bi.bi_db_close = 0;
965 glue_sub_del( BackendDB *b0 )
970 /* Find the top backend for this subordinate */
972 while ( (be=LDAP_STAILQ_NEXT( be, be_next )) != NULL ) {
978 if ( SLAP_GLUE_SUBORDINATE( be ))
980 if ( !SLAP_GLUE_INSTANCE( be ))
982 if ( !dnIsSuffix( &b0->be_nsuffix[0], &be->be_nsuffix[0] ))
985 /* OK, got the right backend, find the overlay */
986 oi = (slap_overinfo *)be->bd_info;
987 for ( on=oi->oi_list; on; on=on->on_next ) {
988 if ( on->on_bi.bi_type == glue.on_bi.bi_type )
991 assert( on != NULL );
992 gi = on->on_bi.bi_private;
993 for ( i=0; i < gi->gi_nodes; i++ ) {
994 if ( gi->gi_n[i].gn_be == b0 ) {
997 for (j=i+1; j < gi->gi_nodes; j++)
998 gi->gi_n[j-1] = gi->gi_n[j];
1005 rc = LDAP_NO_SUCH_OBJECT;
1010 typedef struct glue_Addrec {
1011 struct glue_Addrec *ga_next;
1015 /* List of added subordinates */
1016 static glue_Addrec *ga_list;
1018 /* Attach all the subordinate backends to their superior */
1022 glue_Addrec *ga, *gnext = NULL;
1025 /* For all the subordinate backends */
1026 for ( ga=ga_list; ga != NULL; ga = gnext ) {
1029 gnext = ga->ga_next;
1031 /* Find the top backend for this subordinate */
1033 while ( (be=LDAP_STAILQ_NEXT( be, be_next )) != NULL ) {
1038 if ( SLAP_GLUE_SUBORDINATE( be ))
1040 if ( !dnIsSuffix( &ga->ga_be->be_nsuffix[0], &be->be_nsuffix[0] ))
1043 /* If it's not already configured, set up the overlay */
1044 if ( !SLAP_GLUE_INSTANCE( be )) {
1045 rc = overlay_config( be, glue.on_bi.bi_type, -1, NULL );
1049 /* Find the overlay instance */
1050 oi = (slap_overinfo *)be->bd_info;
1051 for ( on=oi->oi_list; on; on=on->on_next ) {
1052 if ( on->on_bi.bi_type == glue.on_bi.bi_type )
1055 assert( on != NULL );
1056 gi = on->on_bi.bi_private;
1057 gi = (glueinfo *)ch_realloc( gi, sizeof(glueinfo) +
1058 gi->gi_nodes * sizeof(gluenode));
1059 gi->gi_n[gi->gi_nodes].gn_be = ga->ga_be;
1060 dnParent( &ga->ga_be->be_nsuffix[0],
1061 &gi->gi_n[gi->gi_nodes].gn_pdn );
1063 on->on_bi.bi_private = gi;
1067 Debug( LDAP_DEBUG_ANY, "glue: no superior found for sub %s!\n",
1068 ga->ga_be->be_suffix[0].bv_val, 0, 0 );
1069 rc = LDAP_NO_SUCH_OBJECT;
1081 glue_sub_add( BackendDB *be, int advert, int online )
1086 if ( overlay_is_inst( be, "glue" )) {
1087 Debug( LDAP_DEBUG_ANY, "glue: backend %s already has glue overlay, "
1088 "cannot be a subordinate!\n",
1089 be->be_suffix[0].bv_val, 0, 0 );
1092 SLAP_DBFLAGS( be ) |= SLAP_DBFLAG_GLUE_SUBORDINATE;
1094 SLAP_DBFLAGS( be ) |= SLAP_DBFLAG_GLUE_ADVERTISE;
1096 ga = ch_malloc( sizeof( glue_Addrec ));
1097 ga->ga_next = ga_list;
1102 rc = glue_sub_attach();
1110 glue.on_bi.bi_type = "glue";
1112 glue.on_bi.bi_db_init = glue_db_init;
1113 glue.on_bi.bi_db_close = glue_db_close;
1114 glue.on_bi.bi_db_destroy = glue_db_destroy;
1116 glue.on_bi.bi_op_search = glue_op_search;
1117 glue.on_bi.bi_op_modify = glue_op_func;
1118 glue.on_bi.bi_op_modrdn = glue_op_func;
1119 glue.on_bi.bi_op_add = glue_op_func;
1120 glue.on_bi.bi_op_delete = glue_op_func;
1121 glue.on_bi.bi_extended = glue_op_func;
1123 glue.on_bi.bi_chk_referrals = glue_chk_referrals;
1124 glue.on_bi.bi_chk_controls = glue_chk_controls;
1125 glue.on_bi.bi_entry_get_rw = glue_entry_get_rw;
1126 glue.on_bi.bi_entry_release_rw = glue_entry_release_rw;
1128 glue.on_response = glue_response;
1130 return overlay_register( &glue );