1 /* backglue.c - backend glue */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2001-2009 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 struct berval mdn, mndn;
439 op->ors_scope = LDAP_SCOPE_BASE;
440 mdn = op->o_req_dn = op->o_bd->be_suffix[0];
441 mndn = op->o_req_ndn = op->o_bd->be_nsuffix[0];
442 rs->sr_err = op->o_bd->be_search(op, rs);
443 if ( rs->sr_err == LDAP_NO_SUCH_OBJECT ) {
444 gs.err = LDAP_SUCCESS;
446 op->ors_scope = LDAP_SCOPE_ONELEVEL;
447 if ( op->o_req_dn.bv_val == mdn.bv_val )
449 if ( op->o_req_ndn.bv_val == mndn.bv_val )
452 } else if (scope0 == LDAP_SCOPE_SUBTREE &&
453 dn_match(&op->o_bd->be_nsuffix[0], &ndn))
455 rs->sr_err = glue_sub_search( op, rs, b0, on );
457 } else if (scope0 == LDAP_SCOPE_SUBTREE &&
458 dnIsSuffix(&op->o_bd->be_nsuffix[0], &ndn))
460 struct berval mdn, mndn;
461 mdn = op->o_req_dn = op->o_bd->be_suffix[0];
462 mndn = op->o_req_ndn = op->o_bd->be_nsuffix[0];
463 rs->sr_err = glue_sub_search( op, rs, b0, on );
464 if ( rs->sr_err == LDAP_NO_SUCH_OBJECT ) {
465 gs.err = LDAP_SUCCESS;
467 if ( op->o_req_dn.bv_val == mdn.bv_val )
469 if ( op->o_req_ndn.bv_val == mndn.bv_val )
472 } else if (dnIsSuffix(&ndn, &op->o_bd->be_nsuffix[0])) {
473 rs->sr_err = glue_sub_search( op, rs, b0, on );
479 * Add errors that should result in dropping
482 case LDAP_SIZELIMIT_EXCEEDED:
483 case LDAP_TIMELIMIT_EXCEEDED:
484 case LDAP_ADMINLIMIT_EXCEEDED:
485 case LDAP_NO_SUCH_OBJECT:
486 #ifdef LDAP_CONTROL_X_CHAINING_BEHAVIOR
487 case LDAP_X_CANNOT_CHAIN:
488 #endif /* LDAP_CONTROL_X_CHAINING_BEHAVIOR */
492 if ( get_pagedresults( op ) > SLAP_CONTROL_IGNORED ) {
493 PagedResultsState *ps = op->o_pagedresults_state;
495 /* Assume this backend can be forgotten now */
496 op->o_conn->c_pagedresults_state.ps_be = NULL;
498 /* If we have a full page, exit the loop. We may
499 * need to remember this backend so we can continue
500 * from here on a subsequent request.
502 if ( rs->sr_nentries >= ps->ps_size ) {
503 /* Don't bother to remember the first backend.
504 * Only remember the last one if there's more state left.
506 if ( op->o_bd != b0 &&
507 ( op->o_conn->c_pagedresults_state.ps_cookie ||
508 op->o_bd != gi->gi_n[0].gn_be ))
509 op->o_conn->c_pagedresults_state.ps_be = op->o_bd;
513 /* This backend has run out of entries, but more responses
514 * can fit in the page. Fake a reset of the state so the
515 * next backend will start up properly. Only back-[bh]db
516 * and back-sql look at this state info.
518 if ( ps->ps_cookieval.bv_len == sizeof( PagedResultsCookie )) {
520 memset( ps->ps_cookieval.bv_val, 0,
521 sizeof( PagedResultsCookie ));
530 op->ors_scope = scope0;
531 op->ors_tlimit = tlimit0;
532 op->o_time = starttime;
536 if ( op->o_abandon ) {
537 rs->sr_err = SLAPD_ABANDON;
539 op->o_callback = cb.sc_next;
541 rs->sr_matched = gs.matched;
542 rs->sr_ref = gs.refs;
543 rs->sr_ctrls = gs.ctrls;
545 send_ldap_result( op, rs );
549 op->o_bd->bd_info = bi0;
553 ber_bvarray_free(gs.refs);
555 for (i = gs.nctrls; --i >= 0; ) {
556 if (!BER_BVISNULL( &gs.ctrls[i]->ldctl_value ))
557 free(gs.ctrls[i]->ldctl_value.bv_val);
565 static BackendDB toolDB;
568 glue_tool_entry_open (
573 slap_overinfo *oi = (slap_overinfo *)b0->bd_info;
575 /* We don't know which backend to talk to yet, so just
576 * remember the mode and move on...
582 toolDB.bd_info = oi->oi_orig;
588 glue_tool_entry_close (
595 if (!glueBack->be_entry_close)
597 rc = glueBack->be_entry_close (glueBack);
602 static slap_overinst *
607 slap_overinfo *oi = (slap_overinfo *)bi;
610 for ( on = oi->oi_list; on; on=on->on_next ) {
611 if ( !strcmp( on->on_bi.bi_type, glue.on_bi.bi_type ))
617 /* This function will only be called in tool mode */
623 slap_overinst *on = glue_tool_inst( bi );
624 glueinfo *gi = on->on_bi.bi_private;
625 static int glueOpened = 0;
626 int i, j, same, bsame = 0, rc = 0;
627 ConfigReply cr = {0};
629 if (glueOpened) return 0;
633 /* If we were invoked in tool mode, open all the underlying backends */
634 if (slapMode & SLAP_TOOL_MODE) {
635 for (i = 0; i<gi->gi_nodes; i++) {
637 /* Same bi_open as our main backend? */
638 if ( gi->gi_n[i].gn_be->bd_info->bi_open ==
639 on->on_info->oi_orig->bi_open )
642 /* Loop thru the bd_info's and make sure we only
643 * invoke their bi_open functions once each.
645 for ( j = 0; j<i; j++ ) {
646 if ( gi->gi_n[i].gn_be->bd_info->bi_open ==
647 gi->gi_n[j].gn_be->bd_info->bi_open ) {
652 /* OK, it's unique and non-NULL, call it. */
653 if ( !same && gi->gi_n[i].gn_be->bd_info->bi_open )
654 rc = gi->gi_n[i].gn_be->bd_info->bi_open(
655 gi->gi_n[i].gn_be->bd_info );
656 /* Let backend.c take care of the rest of startup */
658 rc = backend_startup_one( gi->gi_n[i].gn_be, &cr );
661 if ( !rc && !bsame && on->on_info->oi_orig->bi_open )
662 rc = on->on_info->oi_orig->bi_open( on->on_info->oi_orig );
664 } /* other case is impossible */
668 /* This function will only be called in tool mode */
674 static int glueClosed = 0;
677 if (glueClosed) return 0;
681 if (slapMode & SLAP_TOOL_MODE) {
682 rc = backend_shutdown( NULL );
692 AttributeDescription *ad,
697 BackendDB *b0 = op->o_bd;
698 op->o_bd = glue_back_select( b0, dn );
700 if ( op->o_bd->be_fetch ) {
701 rc = op->o_bd->be_fetch( op, dn, oc, ad, rw, e );
703 rc = LDAP_UNWILLING_TO_PERFORM;
710 glue_entry_release_rw (
716 BackendDB *b0 = op->o_bd;
719 op->o_bd = glue_back_select (b0, &e->e_nname);
721 if ( op->o_bd->be_release ) {
722 rc = op->o_bd->be_release( op, e, rw );
725 /* FIXME: mimic be_entry_release_rw
726 * when no be_release() available */
736 glue_tool_entry_first (
740 slap_overinst *on = glue_tool_inst( b0->bd_info );
741 glueinfo *gi = on->on_bi.bi_private;
744 /* If we're starting from scratch, start at the most general */
746 if ( toolDB.be_entry_open && toolDB.be_entry_first ) {
749 for (i = gi->gi_nodes-1; i >= 0; i--) {
750 if (gi->gi_n[i].gn_be->be_entry_open &&
751 gi->gi_n[i].gn_be->be_entry_first) {
752 glueBack = gi->gi_n[i].gn_be;
758 if (!glueBack || !glueBack->be_entry_open || !glueBack->be_entry_first ||
759 glueBack->be_entry_open (glueBack, glueMode) != 0)
762 return glueBack->be_entry_first (glueBack);
766 glue_tool_entry_next (
770 slap_overinst *on = glue_tool_inst( b0->bd_info );
771 glueinfo *gi = on->on_bi.bi_private;
775 if (!glueBack || !glueBack->be_entry_next)
778 rc = glueBack->be_entry_next (glueBack);
780 /* If we ran out of entries in one database, move on to the next */
782 if ( glueBack && glueBack->be_entry_close )
783 glueBack->be_entry_close (glueBack);
784 for (i=0; i<gi->gi_nodes; i++) {
785 if (gi->gi_n[i].gn_be == glueBack)
792 glueBack = gi->gi_n[i-1].gn_be;
793 rc = glue_tool_entry_first (b0);
800 glue_tool_dn2id_get (
809 b2.bd_info = (BackendInfo *)glue_tool_inst( b0->bd_info );
810 be = glue_back_select (&b2, dn);
811 if ( be == &b2 ) be = &toolDB;
813 if (!be->be_dn2id_get)
817 if ( be->be_entry_open ) {
818 rc = be->be_entry_open (be, glueMode);
823 } else if (be != glueBack) {
824 /* If this entry belongs in a different branch than the
825 * previous one, close the current database and open the
828 if ( glueBack->be_entry_close ) {
829 glueBack->be_entry_close (glueBack);
831 if ( be->be_entry_open ) {
832 rc = be->be_entry_open (be, glueMode);
839 return be->be_dn2id_get (be, dn);
843 glue_tool_entry_get (
848 if (!glueBack || !glueBack->be_entry_get)
851 return glueBack->be_entry_get (glueBack, id);
855 glue_tool_entry_put (
865 b2.bd_info = (BackendInfo *)glue_tool_inst( b0->bd_info );
866 be = glue_back_select (&b2, &e->e_nname);
867 if ( be == &b2 ) be = &toolDB;
869 if (!be->be_entry_put)
873 if ( be->be_entry_open ) {
874 rc = be->be_entry_open (be, glueMode);
879 } else if (be != glueBack) {
880 /* If this entry belongs in a different branch than the
881 * previous one, close the current database and open the
884 if ( glueBack->be_entry_close ) {
885 glueBack->be_entry_close (glueBack);
887 if ( be->be_entry_open ) {
888 rc = be->be_entry_open (be, glueMode);
895 return be->be_entry_put (be, e, text);
899 glue_tool_entry_modify (
905 if (!glueBack || !glueBack->be_entry_modify)
908 return glueBack->be_entry_modify (glueBack, e, text);
912 glue_tool_entry_reindex (
915 AttributeDescription **adv
918 if (!glueBack || !glueBack->be_entry_reindex)
921 return glueBack->be_entry_reindex (glueBack, id, adv);
929 slap_overinst *on = glue_tool_inst( b0->bd_info );
930 glueinfo *gi = on->on_bi.bi_private;
931 BackendInfo *bi = b0->bd_info;
934 /* just sync everyone */
935 for (i = 0; i<gi->gi_nodes; i++)
936 if (gi->gi_n[i].gn_be->be_sync)
937 gi->gi_n[i].gn_be->be_sync (gi->gi_n[i].gn_be);
938 b0->bd_info = on->on_info->oi_orig;
951 slap_overinst *on = (slap_overinst *)be->bd_info;
952 slap_overinfo *oi = on->on_info;
953 BackendInfo *bi = oi->oi_orig;
956 if ( SLAP_GLUE_SUBORDINATE( be )) {
957 Debug( LDAP_DEBUG_ANY, "glue: backend %s is already subordinate, "
958 "cannot have glue overlay!\n",
959 be->be_suffix[0].bv_val, 0, 0 );
963 gi = ch_calloc( 1, sizeof(glueinfo));
964 on->on_bi.bi_private = gi;
965 dnParent( be->be_nsuffix, &gi->gi_pdn );
967 /* Currently the overlay framework doesn't handle these entry points
968 * but we need them....
970 oi->oi_bi.bi_open = glue_open;
971 oi->oi_bi.bi_close = glue_close;
973 /* Only advertise these if the root DB supports them */
974 if ( bi->bi_tool_entry_open )
975 oi->oi_bi.bi_tool_entry_open = glue_tool_entry_open;
976 if ( bi->bi_tool_entry_close )
977 oi->oi_bi.bi_tool_entry_close = glue_tool_entry_close;
978 if ( bi->bi_tool_entry_first )
979 oi->oi_bi.bi_tool_entry_first = glue_tool_entry_first;
980 if ( bi->bi_tool_entry_next )
981 oi->oi_bi.bi_tool_entry_next = glue_tool_entry_next;
982 if ( bi->bi_tool_entry_get )
983 oi->oi_bi.bi_tool_entry_get = glue_tool_entry_get;
984 if ( bi->bi_tool_dn2id_get )
985 oi->oi_bi.bi_tool_dn2id_get = glue_tool_dn2id_get;
986 if ( bi->bi_tool_entry_put )
987 oi->oi_bi.bi_tool_entry_put = glue_tool_entry_put;
988 if ( bi->bi_tool_entry_reindex )
989 oi->oi_bi.bi_tool_entry_reindex = glue_tool_entry_reindex;
990 if ( bi->bi_tool_entry_modify )
991 oi->oi_bi.bi_tool_entry_modify = glue_tool_entry_modify;
992 if ( bi->bi_tool_sync )
993 oi->oi_bi.bi_tool_sync = glue_tool_sync;
995 SLAP_DBFLAGS( be ) |= SLAP_DBFLAG_GLUE_INSTANCE;
1006 slap_overinst *on = (slap_overinst *)be->bd_info;
1007 glueinfo *gi = (glueinfo *)on->on_bi.bi_private;
1010 return SLAP_CB_CONTINUE;
1019 slap_overinst *on = (slap_overinst *)be->bd_info;
1021 on->on_info->oi_bi.bi_db_close = 0;
1026 glue_sub_del( BackendDB *b0 )
1031 /* Find the top backend for this subordinate */
1033 while ( (be=LDAP_STAILQ_NEXT( be, be_next )) != NULL ) {
1039 if ( SLAP_GLUE_SUBORDINATE( be ))
1041 if ( !SLAP_GLUE_INSTANCE( be ))
1043 if ( !dnIsSuffix( &b0->be_nsuffix[0], &be->be_nsuffix[0] ))
1046 /* OK, got the right backend, find the overlay */
1047 oi = (slap_overinfo *)be->bd_info;
1048 for ( on=oi->oi_list; on; on=on->on_next ) {
1049 if ( on->on_bi.bi_type == glue.on_bi.bi_type )
1052 assert( on != NULL );
1053 gi = on->on_bi.bi_private;
1054 for ( i=0; i < gi->gi_nodes; i++ ) {
1055 if ( gi->gi_n[i].gn_be == b0 ) {
1058 for (j=i+1; j < gi->gi_nodes; j++)
1059 gi->gi_n[j-1] = gi->gi_n[j];
1066 rc = LDAP_NO_SUCH_OBJECT;
1071 typedef struct glue_Addrec {
1072 struct glue_Addrec *ga_next;
1076 /* List of added subordinates */
1077 static glue_Addrec *ga_list;
1079 /* Attach all the subordinate backends to their superior */
1083 glue_Addrec *ga, *gnext = NULL;
1086 /* For all the subordinate backends */
1087 for ( ga=ga_list; ga != NULL; ga = gnext ) {
1090 gnext = ga->ga_next;
1092 /* Find the top backend for this subordinate */
1094 while ( (be=LDAP_STAILQ_NEXT( be, be_next )) != NULL ) {
1099 if ( SLAP_GLUE_SUBORDINATE( be ))
1101 if ( !dnIsSuffix( &ga->ga_be->be_nsuffix[0], &be->be_nsuffix[0] ))
1104 /* If it's not already configured, set up the overlay */
1105 if ( !SLAP_GLUE_INSTANCE( be )) {
1106 rc = overlay_config( be, glue.on_bi.bi_type, -1, NULL, NULL);
1110 /* Find the overlay instance */
1111 oi = (slap_overinfo *)be->bd_info;
1112 for ( on=oi->oi_list; on; on=on->on_next ) {
1113 if ( on->on_bi.bi_type == glue.on_bi.bi_type )
1116 assert( on != NULL );
1117 gi = on->on_bi.bi_private;
1118 gi = (glueinfo *)ch_realloc( gi, sizeof(glueinfo) +
1119 gi->gi_nodes * sizeof(gluenode));
1120 gi->gi_n[gi->gi_nodes].gn_be = ga->ga_be;
1121 dnParent( &ga->ga_be->be_nsuffix[0],
1122 &gi->gi_n[gi->gi_nodes].gn_pdn );
1124 on->on_bi.bi_private = gi;
1128 Debug( LDAP_DEBUG_ANY, "glue: no superior found for sub %s!\n",
1129 ga->ga_be->be_suffix[0].bv_val, 0, 0 );
1130 rc = LDAP_NO_SUCH_OBJECT;
1142 glue_sub_add( BackendDB *be, int advert, int online )
1147 if ( overlay_is_inst( be, "glue" )) {
1148 Debug( LDAP_DEBUG_ANY, "glue: backend %s already has glue overlay, "
1149 "cannot be a subordinate!\n",
1150 be->be_suffix[0].bv_val, 0, 0 );
1153 SLAP_DBFLAGS( be ) |= SLAP_DBFLAG_GLUE_SUBORDINATE;
1155 SLAP_DBFLAGS( be ) |= SLAP_DBFLAG_GLUE_ADVERTISE;
1157 ga = ch_malloc( sizeof( glue_Addrec ));
1158 ga->ga_next = ga_list;
1163 rc = glue_sub_attach();
1171 glue.on_bi.bi_type = "glue";
1173 glue.on_bi.bi_db_init = glue_db_init;
1174 glue.on_bi.bi_db_close = glue_db_close;
1175 glue.on_bi.bi_db_destroy = glue_db_destroy;
1177 glue.on_bi.bi_op_search = glue_op_search;
1178 glue.on_bi.bi_op_modify = glue_op_func;
1179 glue.on_bi.bi_op_modrdn = glue_op_func;
1180 glue.on_bi.bi_op_add = glue_op_func;
1181 glue.on_bi.bi_op_delete = glue_op_func;
1182 glue.on_bi.bi_extended = glue_op_func;
1184 glue.on_bi.bi_chk_referrals = glue_chk_referrals;
1185 glue.on_bi.bi_chk_controls = glue_chk_controls;
1186 glue.on_bi.bi_entry_get_rw = glue_entry_get_rw;
1187 glue.on_bi.bi_entry_release_rw = glue_entry_release_rw;
1189 glue.on_response = glue_response;
1191 return overlay_register( &glue );