1 /* backglue.c - backend glue */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2001-2010 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;
55 static BackendDB glueBackDone;
56 #define GLUEBACK_DONE (&glueBackDone)
58 static slap_response glue_op_response;
60 /* Just like select_backend, but only for our backends */
67 slap_overinst *on = (slap_overinst *)be->bd_info;
68 glueinfo *gi = (glueinfo *)on->on_bi.bi_private;
71 for (i = gi->gi_nodes-1; i >= 0; i--) {
72 assert( gi->gi_n[i].gn_be->be_nsuffix != NULL );
74 if (dnIsSuffix(dn, &gi->gi_n[i].gn_be->be_nsuffix[0])) {
75 return gi->gi_n[i].gn_be;
78 be->bd_info = on->on_info->oi_orig;
83 typedef struct glue_state {
94 glue_op_cleanup( Operation *op, SlapReply *rs )
96 /* This is not a final result */
97 if (rs->sr_type == REP_RESULT )
98 rs->sr_type = REP_GLUE_RESULT;
99 return SLAP_CB_CONTINUE;
103 glue_op_response ( Operation *op, SlapReply *rs )
105 glue_state *gs = op->o_callback->sc_private;
107 switch(rs->sr_type) {
110 case REP_INTERMEDIATE:
111 return SLAP_CB_CONTINUE;
114 if (rs->sr_err == LDAP_SUCCESS ||
115 rs->sr_err == LDAP_SIZELIMIT_EXCEEDED ||
116 rs->sr_err == LDAP_TIMELIMIT_EXCEEDED ||
117 rs->sr_err == LDAP_ADMINLIMIT_EXCEEDED ||
118 rs->sr_err == LDAP_NO_SUCH_OBJECT ||
119 gs->err != LDAP_SUCCESS)
120 gs->err = rs->sr_err;
121 if (gs->err == LDAP_SUCCESS && gs->matched) {
122 ch_free (gs->matched);
126 if (gs->err != LDAP_SUCCESS && rs->sr_matched) {
128 len = strlen (rs->sr_matched);
129 if (len > gs->matchlen) {
131 ch_free (gs->matched);
132 gs->matched = ch_strdup (rs->sr_matched);
140 for (i=0; rs->sr_ref[i].bv_val; i++);
144 new = ch_malloc ((i+1)*sizeof(struct berval));
146 new = ch_realloc(gs->refs,
147 (j+i+1)*sizeof(struct berval));
149 for (k=0; k<i; j++,k++) {
150 ber_dupbv( &new[j], &rs->sr_ref[k] );
152 new[j].bv_val = NULL;
158 LDAPControl **newctrls;
160 for (i=0; rs->sr_ctrls[i]; i++);
164 newctrls = ch_malloc((i+1)*sizeof(LDAPControl *));
166 /* Forget old pagedResults response if we're sending
169 if ( get_pagedresults( op ) > SLAP_CONTROL_IGNORED ) {
171 for ( k=0; k<i; k++ ) {
172 if ( !strcmp(rs->sr_ctrls[k]->ldctl_oid,
173 LDAP_CONTROL_PAGEDRESULTS )) {
179 for ( k=0; k<j; k++ ) {
180 if ( !strcmp(gs->ctrls[k]->ldctl_oid,
181 LDAP_CONTROL_PAGEDRESULTS )) {
182 gs->ctrls[k]->ldctl_oid = NULL;
183 ldap_control_free( gs->ctrls[k] );
184 gs->ctrls[k] = gs->ctrls[--j];
191 newctrls = ch_realloc(gs->ctrls,
192 (j+i+1)*sizeof(LDAPControl *));
194 for (k=0; k<i; j++,k++) {
195 newctrls[j] = ch_malloc(sizeof(LDAPControl));
196 *newctrls[j] = *rs->sr_ctrls[k];
197 if ( !BER_BVISNULL( &rs->sr_ctrls[k]->ldctl_value ))
198 ber_dupbv( &newctrls[j]->ldctl_value,
199 &rs->sr_ctrls[k]->ldctl_value );
203 gs->ctrls = newctrls;
210 glue_op_func ( Operation *op, SlapReply *rs )
212 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
213 BackendDB *b0 = op->o_bd;
214 BackendInfo *bi0 = op->o_bd->bd_info;
216 slap_operation_t which = op_bind;
219 op->o_bd = glue_back_select (b0, &op->o_req_ndn);
221 /* If we're on the master backend, let overlay framework handle it */
222 if ( op->o_bd == b0 )
223 return SLAP_CB_CONTINUE;
225 b0->bd_info = on->on_info->oi_orig;
228 case LDAP_REQ_ADD: which = op_add; break;
229 case LDAP_REQ_DELETE: which = op_delete; break;
230 case LDAP_REQ_MODIFY: which = op_modify; break;
231 case LDAP_REQ_MODRDN: which = op_modrdn; break;
232 case LDAP_REQ_EXTENDED: which = op_extended; break;
233 default: assert( 0 ); break;
236 func = &op->o_bd->bd_info->bi_op_bind;
238 rc = func[which]( op, rs );
243 op->o_bd->bd_info = bi0;
248 glue_response ( Operation *op, SlapReply *rs )
250 BackendDB *be = op->o_bd;
251 be = glue_back_select (op->o_bd, &op->o_req_ndn);
253 /* If we're on the master backend, let overlay framework handle it.
254 * Otherwise, bail out.
256 return ( op->o_bd == be ) ? SLAP_CB_CONTINUE : SLAP_CB_BYPASS;
260 glue_chk_referrals ( Operation *op, SlapReply *rs )
262 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
263 BackendDB *b0 = op->o_bd;
264 BackendInfo *bi0 = op->o_bd->bd_info;
267 op->o_bd = glue_back_select (b0, &op->o_req_ndn);
268 if ( op->o_bd == b0 )
269 return SLAP_CB_CONTINUE;
271 b0->bd_info = on->on_info->oi_orig;
273 if ( op->o_bd->bd_info->bi_chk_referrals )
274 rc = ( *op->o_bd->bd_info->bi_chk_referrals )( op, rs );
276 rc = SLAP_CB_CONTINUE;
279 op->o_bd->bd_info = bi0;
284 glue_chk_controls ( Operation *op, SlapReply *rs )
286 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
287 BackendDB *b0 = op->o_bd;
288 BackendInfo *bi0 = op->o_bd->bd_info;
289 int rc = SLAP_CB_CONTINUE;
291 op->o_bd = glue_back_select (b0, &op->o_req_ndn);
292 if ( op->o_bd == b0 )
293 return SLAP_CB_CONTINUE;
295 b0->bd_info = on->on_info->oi_orig;
297 /* if the subordinate database has overlays, the bi_chk_controls()
298 * hook is actually over_aux_chk_controls(); in case it actually
299 * wraps a missing hok, we need to mimic the behavior
300 * of the frontend applied to that database */
301 if ( op->o_bd->bd_info->bi_chk_controls ) {
302 rc = ( *op->o_bd->bd_info->bi_chk_controls )( op, rs );
306 if ( rc == SLAP_CB_CONTINUE ) {
307 rc = backend_check_controls( op, rs );
311 op->o_bd->bd_info = bi0;
315 /* ITS#4615 - overlays configured above the glue overlay should be
316 * invoked for the entire glued tree. Overlays configured below the
317 * glue overlay should only be invoked on the master backend.
318 * So, if we're searching on any subordinates, we need to force the
319 * current overlay chain to stop processing, without stopping the
320 * overall callback flow.
323 glue_sub_search( Operation *op, SlapReply *rs, BackendDB *b0,
326 /* Process any overlays on the master backend */
327 if ( op->o_bd == b0 && on->on_next ) {
328 BackendInfo *bi = op->o_bd->bd_info;
329 int rc = SLAP_CB_CONTINUE;
330 for ( on=on->on_next; on; on=on->on_next ) {
331 op->o_bd->bd_info = (BackendInfo *)on;
332 if ( on->on_bi.bi_op_search ) {
333 rc = on->on_bi.bi_op_search( op, rs );
334 if ( rc != SLAP_CB_CONTINUE )
338 op->o_bd->bd_info = bi;
339 if ( rc != SLAP_CB_CONTINUE )
342 return op->o_bd->be_search( op, rs );
346 glue_op_search ( Operation *op, SlapReply *rs )
348 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
349 glueinfo *gi = (glueinfo *)on->on_bi.bi_private;
350 BackendDB *b0 = op->o_bd;
351 BackendDB *b1 = NULL, *btmp;
352 BackendInfo *bi0 = op->o_bd->bd_info;
354 long stoptime = 0, starttime;
355 glue_state gs = {NULL, NULL, NULL, 0, 0, 0, 0};
356 slap_callback cb = { NULL, glue_op_response, glue_op_cleanup, NULL };
358 struct berval dn, ndn, *pdn;
362 cb.sc_next = op->o_callback;
364 starttime = op->o_time;
365 stoptime = slap_get_time () + op->ors_tlimit;
367 op->o_bd = glue_back_select (b0, &op->o_req_ndn);
368 b0->bd_info = on->on_info->oi_orig;
370 switch (op->ors_scope) {
371 case LDAP_SCOPE_BASE:
372 if ( op->o_bd == b0 )
373 return SLAP_CB_CONTINUE;
375 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
376 if (op->o_bd && op->o_bd->be_search) {
377 rs->sr_err = op->o_bd->be_search( op, rs );
381 case LDAP_SCOPE_ONELEVEL:
382 case LDAP_SCOPE_SUBTREE:
383 case LDAP_SCOPE_SUBORDINATE: /* FIXME */
384 op->o_callback = &cb;
385 rs->sr_err = gs.err = LDAP_UNWILLING_TO_PERFORM;
386 scope0 = op->ors_scope;
387 tlimit0 = op->ors_tlimit;
393 * Execute in reverse order, most specific first
395 for (i = gi->gi_nodes; i >= 0; i--) {
396 if ( i == gi->gi_nodes ) {
400 btmp = gi->gi_n[i].gn_be;
401 pdn = &gi->gi_n[i].gn_pdn;
403 if (!btmp || !btmp->be_search)
405 if (!dnIsSuffix(&btmp->be_nsuffix[0], &b1->be_nsuffix[0]))
407 if (get_no_subordinate_glue(op) && btmp != b1)
409 /* If we remembered which backend we were on before,
410 * skip down to it now
412 if ( get_pagedresults( op ) > SLAP_CONTROL_IGNORED &&
413 op->o_conn->c_pagedresults_state.ps_be &&
414 op->o_conn->c_pagedresults_state.ps_be != btmp )
417 if (tlimit0 != SLAP_NO_LIMIT) {
418 op->o_time = slap_get_time();
419 op->ors_tlimit = stoptime - op->o_time;
420 if (op->ors_tlimit <= 0) {
421 rs->sr_err = gs.err = LDAP_TIMELIMIT_EXCEEDED;
434 assert( op->o_bd->be_suffix != NULL );
435 assert( op->o_bd->be_nsuffix != NULL );
437 if (scope0 == LDAP_SCOPE_ONELEVEL &&
440 struct berval mdn, mndn;
441 op->ors_scope = LDAP_SCOPE_BASE;
442 mdn = op->o_req_dn = op->o_bd->be_suffix[0];
443 mndn = op->o_req_ndn = op->o_bd->be_nsuffix[0];
444 rs->sr_err = op->o_bd->be_search(op, rs);
445 if ( rs->sr_err == LDAP_NO_SUCH_OBJECT ) {
446 gs.err = LDAP_SUCCESS;
448 op->ors_scope = LDAP_SCOPE_ONELEVEL;
449 if ( op->o_req_dn.bv_val == mdn.bv_val )
451 if ( op->o_req_ndn.bv_val == mndn.bv_val )
454 } else if (scope0 == LDAP_SCOPE_SUBTREE &&
455 dn_match(&op->o_bd->be_nsuffix[0], &ndn))
457 rs->sr_err = glue_sub_search( op, rs, b0, on );
459 } else if (scope0 == LDAP_SCOPE_SUBTREE &&
460 dnIsSuffix(&op->o_bd->be_nsuffix[0], &ndn))
462 struct berval mdn, mndn;
463 mdn = op->o_req_dn = op->o_bd->be_suffix[0];
464 mndn = op->o_req_ndn = op->o_bd->be_nsuffix[0];
465 rs->sr_err = glue_sub_search( op, rs, b0, on );
466 if ( rs->sr_err == LDAP_NO_SUCH_OBJECT ) {
467 gs.err = LDAP_SUCCESS;
469 if ( op->o_req_dn.bv_val == mdn.bv_val )
471 if ( op->o_req_ndn.bv_val == mndn.bv_val )
474 } else if (dnIsSuffix(&ndn, &op->o_bd->be_nsuffix[0])) {
475 rs->sr_err = glue_sub_search( op, rs, b0, on );
481 * Add errors that should result in dropping
484 case LDAP_SIZELIMIT_EXCEEDED:
485 case LDAP_TIMELIMIT_EXCEEDED:
486 case LDAP_ADMINLIMIT_EXCEEDED:
487 case LDAP_NO_SUCH_OBJECT:
488 #ifdef LDAP_CONTROL_X_CHAINING_BEHAVIOR
489 case LDAP_X_CANNOT_CHAIN:
490 #endif /* LDAP_CONTROL_X_CHAINING_BEHAVIOR */
494 if ( get_pagedresults( op ) > SLAP_CONTROL_IGNORED ) {
495 PagedResultsState *ps = op->o_pagedresults_state;
497 /* Assume this backend can be forgotten now */
498 op->o_conn->c_pagedresults_state.ps_be = NULL;
500 /* If we have a full page, exit the loop. We may
501 * need to remember this backend so we can continue
502 * from here on a subsequent request.
504 if ( rs->sr_nentries >= ps->ps_size ) {
505 /* Don't bother to remember the first backend.
506 * Only remember the last one if there's more state left.
508 if ( op->o_bd != b0 &&
509 ( op->o_conn->c_pagedresults_state.ps_cookie ||
510 op->o_bd != gi->gi_n[0].gn_be ))
511 op->o_conn->c_pagedresults_state.ps_be = op->o_bd;
515 /* This backend has run out of entries, but more responses
516 * can fit in the page. Fake a reset of the state so the
517 * next backend will start up properly. Only back-[bh]db
518 * and back-sql look at this state info.
520 if ( ps->ps_cookieval.bv_len == sizeof( PagedResultsCookie )) {
522 memset( ps->ps_cookieval.bv_val, 0,
523 sizeof( PagedResultsCookie ));
532 op->ors_scope = scope0;
533 op->ors_tlimit = tlimit0;
534 op->o_time = starttime;
539 op->o_callback = cb.sc_next;
540 if ( op->o_abandon ) {
541 rs->sr_err = SLAPD_ABANDON;
544 rs->sr_matched = gs.matched;
545 rs->sr_ref = gs.refs;
547 rs->sr_ctrls = gs.ctrls;
549 send_ldap_result( op, rs );
552 op->o_bd->bd_info = bi0;
556 ber_bvarray_free(gs.refs);
558 for (i = gs.nctrls; --i >= 0; ) {
559 if (!BER_BVISNULL( &gs.ctrls[i]->ldctl_value ))
560 free(gs.ctrls[i]->ldctl_value.bv_val);
568 static BackendDB toolDB;
571 glue_tool_entry_open (
576 slap_overinfo *oi = (slap_overinfo *)b0->bd_info;
578 /* We don't know which backend to talk to yet, so just
579 * remember the mode and move on...
585 toolDB.bd_info = oi->oi_orig;
591 glue_tool_entry_close (
597 if (glueBack && glueBack != GLUEBACK_DONE) {
598 if (!glueBack->be_entry_close)
600 rc = glueBack->be_entry_close (glueBack);
605 static slap_overinst *
610 slap_overinfo *oi = (slap_overinfo *)bi;
613 for ( on = oi->oi_list; on; on=on->on_next ) {
614 if ( !strcmp( on->on_bi.bi_type, glue.on_bi.bi_type ))
620 /* This function will only be called in tool mode */
626 slap_overinst *on = glue_tool_inst( bi );
627 glueinfo *gi = on->on_bi.bi_private;
628 static int glueOpened = 0;
629 int i, j, same, bsame = 0, rc = 0;
630 ConfigReply cr = {0};
632 if (glueOpened) return 0;
636 /* If we were invoked in tool mode, open all the underlying backends */
637 if (slapMode & SLAP_TOOL_MODE) {
638 for (i = 0; i<gi->gi_nodes; i++) {
640 /* Same bi_open as our main backend? */
641 if ( gi->gi_n[i].gn_be->bd_info->bi_open ==
642 on->on_info->oi_orig->bi_open )
645 /* Loop thru the bd_info's and make sure we only
646 * invoke their bi_open functions once each.
648 for ( j = 0; j<i; j++ ) {
649 if ( gi->gi_n[i].gn_be->bd_info->bi_open ==
650 gi->gi_n[j].gn_be->bd_info->bi_open ) {
655 /* OK, it's unique and non-NULL, call it. */
656 if ( !same && gi->gi_n[i].gn_be->bd_info->bi_open )
657 rc = gi->gi_n[i].gn_be->bd_info->bi_open(
658 gi->gi_n[i].gn_be->bd_info );
659 /* Let backend.c take care of the rest of startup */
661 rc = backend_startup_one( gi->gi_n[i].gn_be, &cr );
664 if ( !rc && !bsame && on->on_info->oi_orig->bi_open )
665 rc = on->on_info->oi_orig->bi_open( on->on_info->oi_orig );
667 } /* other case is impossible */
671 /* This function will only be called in tool mode */
677 static int glueClosed = 0;
680 if (glueClosed) return 0;
684 if (slapMode & SLAP_TOOL_MODE) {
685 rc = backend_shutdown( NULL );
695 AttributeDescription *ad,
700 BackendDB *b0 = op->o_bd;
701 op->o_bd = glue_back_select( b0, dn );
703 if ( op->o_bd->be_fetch ) {
704 rc = op->o_bd->be_fetch( op, dn, oc, ad, rw, e );
706 rc = LDAP_UNWILLING_TO_PERFORM;
713 glue_entry_release_rw (
719 BackendDB *b0 = op->o_bd;
722 op->o_bd = glue_back_select (b0, &e->e_nname);
724 if ( op->o_bd->be_release ) {
725 rc = op->o_bd->be_release( op, e, rw );
728 /* FIXME: mimic be_entry_release_rw
729 * when no be_release() available */
739 glue_tool_entry_first (
743 slap_overinst *on = glue_tool_inst( b0->bd_info );
744 glueinfo *gi = on->on_bi.bi_private;
748 /* If we're starting from scratch, start at the most general */
750 if ( toolDB.be_entry_open && toolDB.be_entry_first ) {
753 for (i = gi->gi_nodes-1; i >= 0; i--) {
754 if (gi->gi_n[i].gn_be->be_entry_open &&
755 gi->gi_n[i].gn_be->be_entry_first) {
756 glueBack = gi->gi_n[i].gn_be;
762 if (!glueBack || !glueBack->be_entry_open || !glueBack->be_entry_first ||
763 glueBack->be_entry_open (glueBack, glueMode) != 0)
766 rc = glueBack->be_entry_first (glueBack);
767 while ( rc == NOID ) {
768 if ( glueBack && glueBack->be_entry_close )
769 glueBack->be_entry_close (glueBack);
770 for (i=0; i<gi->gi_nodes; i++) {
771 if (gi->gi_n[i].gn_be == glueBack)
775 glueBack = GLUEBACK_DONE;
778 glueBack = gi->gi_n[i-1].gn_be;
779 rc = glue_tool_entry_first (b0);
780 if ( glueBack == GLUEBACK_DONE ) {
789 glue_tool_entry_next (
793 slap_overinst *on = glue_tool_inst( b0->bd_info );
794 glueinfo *gi = on->on_bi.bi_private;
798 if (!glueBack || !glueBack->be_entry_next)
801 rc = glueBack->be_entry_next (glueBack);
803 /* If we ran out of entries in one database, move on to the next */
805 if ( glueBack && glueBack->be_entry_close )
806 glueBack->be_entry_close (glueBack);
807 for (i=0; i<gi->gi_nodes; i++) {
808 if (gi->gi_n[i].gn_be == glueBack)
812 glueBack = GLUEBACK_DONE;
815 glueBack = gi->gi_n[i-1].gn_be;
816 rc = glue_tool_entry_first (b0);
817 if ( glueBack == GLUEBACK_DONE ) {
826 glue_tool_dn2id_get (
835 b2.bd_info = (BackendInfo *)glue_tool_inst( b0->bd_info );
836 be = glue_back_select (&b2, dn);
837 if ( be == &b2 ) be = &toolDB;
839 if (!be->be_dn2id_get)
843 if ( be->be_entry_open ) {
844 rc = be->be_entry_open (be, glueMode);
849 } else if (be != glueBack) {
850 /* If this entry belongs in a different branch than the
851 * previous one, close the current database and open the
854 if ( glueBack->be_entry_close ) {
855 glueBack->be_entry_close (glueBack);
857 if ( be->be_entry_open ) {
858 rc = be->be_entry_open (be, glueMode);
865 return be->be_dn2id_get (be, dn);
869 glue_tool_entry_get (
874 if (!glueBack || !glueBack->be_entry_get)
877 return glueBack->be_entry_get (glueBack, id);
881 glue_tool_entry_put (
891 b2.bd_info = (BackendInfo *)glue_tool_inst( b0->bd_info );
892 be = glue_back_select (&b2, &e->e_nname);
893 if ( be == &b2 ) be = &toolDB;
895 if (!be->be_entry_put)
899 if ( be->be_entry_open ) {
900 rc = be->be_entry_open (be, glueMode);
905 } else if (be != glueBack) {
906 /* If this entry belongs in a different branch than the
907 * previous one, close the current database and open the
910 if ( glueBack->be_entry_close ) {
911 glueBack->be_entry_close (glueBack);
913 if ( be->be_entry_open ) {
914 rc = be->be_entry_open (be, glueMode);
921 return be->be_entry_put (be, e, text);
925 glue_tool_entry_modify (
931 if (!glueBack || !glueBack->be_entry_modify)
934 return glueBack->be_entry_modify (glueBack, e, text);
938 glue_tool_entry_reindex (
941 AttributeDescription **adv
944 if (!glueBack || !glueBack->be_entry_reindex)
947 return glueBack->be_entry_reindex (glueBack, id, adv);
955 slap_overinst *on = glue_tool_inst( b0->bd_info );
956 glueinfo *gi = on->on_bi.bi_private;
957 BackendInfo *bi = b0->bd_info;
960 /* just sync everyone */
961 for (i = 0; i<gi->gi_nodes; i++)
962 if (gi->gi_n[i].gn_be->be_sync)
963 gi->gi_n[i].gn_be->be_sync (gi->gi_n[i].gn_be);
964 b0->bd_info = on->on_info->oi_orig;
971 typedef struct glue_Addrec {
972 struct glue_Addrec *ga_next;
976 /* List of added subordinates */
977 static glue_Addrec *ga_list;
978 static int ga_adding;
986 slap_overinst *on = (slap_overinst *)be->bd_info;
987 slap_overinfo *oi = on->on_info;
988 BackendInfo *bi = oi->oi_orig;
991 if ( SLAP_GLUE_SUBORDINATE( be )) {
992 Debug( LDAP_DEBUG_ANY, "glue: backend %s is already subordinate, "
993 "cannot have glue overlay!\n",
994 be->be_suffix[0].bv_val, 0, 0 );
998 gi = ch_calloc( 1, sizeof(glueinfo));
999 on->on_bi.bi_private = gi;
1000 dnParent( be->be_nsuffix, &gi->gi_pdn );
1002 /* Currently the overlay framework doesn't handle these entry points
1003 * but we need them....
1005 oi->oi_bi.bi_open = glue_open;
1006 oi->oi_bi.bi_close = glue_close;
1008 /* Only advertise these if the root DB supports them */
1009 if ( bi->bi_tool_entry_open )
1010 oi->oi_bi.bi_tool_entry_open = glue_tool_entry_open;
1011 if ( bi->bi_tool_entry_close )
1012 oi->oi_bi.bi_tool_entry_close = glue_tool_entry_close;
1013 if ( bi->bi_tool_entry_first )
1014 oi->oi_bi.bi_tool_entry_first = glue_tool_entry_first;
1015 if ( bi->bi_tool_entry_next )
1016 oi->oi_bi.bi_tool_entry_next = glue_tool_entry_next;
1017 if ( bi->bi_tool_entry_get )
1018 oi->oi_bi.bi_tool_entry_get = glue_tool_entry_get;
1019 if ( bi->bi_tool_dn2id_get )
1020 oi->oi_bi.bi_tool_dn2id_get = glue_tool_dn2id_get;
1021 if ( bi->bi_tool_entry_put )
1022 oi->oi_bi.bi_tool_entry_put = glue_tool_entry_put;
1023 if ( bi->bi_tool_entry_reindex )
1024 oi->oi_bi.bi_tool_entry_reindex = glue_tool_entry_reindex;
1025 if ( bi->bi_tool_entry_modify )
1026 oi->oi_bi.bi_tool_entry_modify = glue_tool_entry_modify;
1027 if ( bi->bi_tool_sync )
1028 oi->oi_bi.bi_tool_sync = glue_tool_sync;
1030 SLAP_DBFLAGS( be ) |= SLAP_DBFLAG_GLUE_INSTANCE;
1033 be->bd_info = (BackendInfo *)oi;
1034 glue_sub_attach( 1 );
1046 slap_overinst *on = (slap_overinst *)be->bd_info;
1047 glueinfo *gi = (glueinfo *)on->on_bi.bi_private;
1050 return SLAP_CB_CONTINUE;
1059 slap_overinst *on = (slap_overinst *)be->bd_info;
1061 on->on_info->oi_bi.bi_db_close = 0;
1066 glue_sub_del( BackendDB *b0 )
1071 /* Find the top backend for this subordinate */
1073 while ( (be=LDAP_STAILQ_NEXT( be, be_next )) != NULL ) {
1079 if ( SLAP_GLUE_SUBORDINATE( be ))
1081 if ( !SLAP_GLUE_INSTANCE( be ))
1083 if ( !dnIsSuffix( &b0->be_nsuffix[0], &be->be_nsuffix[0] ))
1086 /* OK, got the right backend, find the overlay */
1087 oi = (slap_overinfo *)be->bd_info;
1088 for ( on=oi->oi_list; on; on=on->on_next ) {
1089 if ( on->on_bi.bi_type == glue.on_bi.bi_type )
1092 assert( on != NULL );
1093 gi = on->on_bi.bi_private;
1094 for ( i=0; i < gi->gi_nodes; i++ ) {
1095 if ( gi->gi_n[i].gn_be == b0 ) {
1098 for (j=i+1; j < gi->gi_nodes; j++)
1099 gi->gi_n[j-1] = gi->gi_n[j];
1106 rc = LDAP_NO_SUCH_OBJECT;
1112 /* Attach all the subordinate backends to their superior */
1114 glue_sub_attach( int online )
1116 glue_Addrec *ga, *gnext = NULL;
1124 /* For all the subordinate backends */
1125 for ( ga=ga_list; ga != NULL; ga = gnext ) {
1128 gnext = ga->ga_next;
1130 /* Find the top backend for this subordinate */
1132 while ( (be=LDAP_STAILQ_NEXT( be, be_next )) != NULL ) {
1137 if ( SLAP_GLUE_SUBORDINATE( be ))
1139 if ( !dnIsSuffix( &ga->ga_be->be_nsuffix[0], &be->be_nsuffix[0] ))
1142 /* If it's not already configured, set up the overlay */
1143 if ( !SLAP_GLUE_INSTANCE( be )) {
1144 rc = overlay_config( be, glue.on_bi.bi_type, -1, NULL, NULL);
1148 /* Find the overlay instance */
1149 oi = (slap_overinfo *)be->bd_info;
1150 for ( on=oi->oi_list; on; on=on->on_next ) {
1151 if ( on->on_bi.bi_type == glue.on_bi.bi_type )
1154 assert( on != NULL );
1155 gi = on->on_bi.bi_private;
1156 gi = (glueinfo *)ch_realloc( gi, sizeof(glueinfo) +
1157 gi->gi_nodes * sizeof(gluenode));
1158 gi->gi_n[gi->gi_nodes].gn_be = ga->ga_be;
1159 dnParent( &ga->ga_be->be_nsuffix[0],
1160 &gi->gi_n[gi->gi_nodes].gn_pdn );
1162 on->on_bi.bi_private = gi;
1163 ga->ga_be->be_flags |= SLAP_DBFLAG_GLUE_LINKED;
1167 Debug( LDAP_DEBUG_ANY, "glue: no superior found for sub %s!\n",
1168 ga->ga_be->be_suffix[0].bv_val, 0, 0 );
1169 /* allow this for now, assume a superior will
1177 rc = LDAP_NO_SUCH_OBJECT;
1191 glue_sub_add( BackendDB *be, int advert, int online )
1196 if ( overlay_is_inst( be, "glue" )) {
1197 Debug( LDAP_DEBUG_ANY, "glue: backend %s already has glue overlay, "
1198 "cannot be a subordinate!\n",
1199 be->be_suffix[0].bv_val, 0, 0 );
1202 SLAP_DBFLAGS( be ) |= SLAP_DBFLAG_GLUE_SUBORDINATE;
1204 SLAP_DBFLAGS( be ) |= SLAP_DBFLAG_GLUE_ADVERTISE;
1206 ga = ch_malloc( sizeof( glue_Addrec ));
1207 ga->ga_next = ga_list;
1212 rc = glue_sub_attach( online );
1220 glue.on_bi.bi_type = "glue";
1222 glue.on_bi.bi_db_init = glue_db_init;
1223 glue.on_bi.bi_db_close = glue_db_close;
1224 glue.on_bi.bi_db_destroy = glue_db_destroy;
1226 glue.on_bi.bi_op_search = glue_op_search;
1227 glue.on_bi.bi_op_modify = glue_op_func;
1228 glue.on_bi.bi_op_modrdn = glue_op_func;
1229 glue.on_bi.bi_op_add = glue_op_func;
1230 glue.on_bi.bi_op_delete = glue_op_func;
1231 glue.on_bi.bi_extended = glue_op_func;
1233 glue.on_bi.bi_chk_referrals = glue_chk_referrals;
1234 glue.on_bi.bi_chk_controls = glue_chk_controls;
1235 glue.on_bi.bi_entry_get_rw = glue_entry_get_rw;
1236 glue.on_bi.bi_entry_release_rw = glue_entry_release_rw;
1238 glue.on_response = glue_response;
1240 return overlay_register( &glue );