]> git.sur5r.net Git - openldap/blob - servers/slapd/backglue.c
Converted ch_malloc, ch_calloc and ch_realloc calls to SLAP_MALLOC,
[openldap] / servers / slapd / backglue.c
1 /* backglue.c - backend glue routines */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 2001-2002 The OpenLDAP Foundation, All Rights Reserved.
5  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
6  */
7
8 /*
9  * Functions to glue a bunch of other backends into a single tree.
10  * All of the glued backends must share a common suffix. E.g., you
11  * can glue o=foo and ou=bar,o=foo but you can't glue o=foo and o=bar.
12  *
13  * This uses the backend structures and routines extensively, but is
14  * not an actual backend of its own. To use it you must add a "subordinate"
15  * keyword to the configuration of other backends. Subordinates will
16  * automatically be connected to their parent backend.
17  *
18  * The purpose of these functions is to allow you to split a single database
19  * into pieces (for load balancing purposes, whatever) but still be able
20  * to treat it as a single database after it's been split. As such, each
21  * of the glued backends should have identical rootdn and rootpw.
22  *
23  * If you need more elaborate configuration, you probably should be using
24  * back-meta instead.
25  *  -- Howard Chu
26  */
27
28 #include "portable.h"
29
30 #include <stdio.h>
31
32 #include <ac/socket.h>
33
34 #define SLAPD_TOOLS
35 #include "slap.h"
36
37 typedef struct gluenode {
38         BackendDB *be;
39         struct berval pdn;
40 } gluenode;
41
42 typedef struct glueinfo {
43         BackendDB *be;
44         int nodes;
45         gluenode n[1];
46 } glueinfo;
47
48 static int glueMode;
49 static BackendDB *glueBack;
50
51 /* Just like select_backend, but only for our backends */
52 static BackendDB *
53 glue_back_select (
54         BackendDB *be,
55         const char *dn
56 )
57 {
58         glueinfo *gi = (glueinfo *) be->be_private;
59         struct berval bv;
60         int i;
61
62         bv.bv_len = strlen(dn);
63         bv.bv_val = (char *) dn;
64
65         for (i = 0; i<gi->nodes; i++) {
66                 if (dnIsSuffix(&bv, &gi->n[i].be->be_nsuffix[0])) {
67                         return gi->n[i].be;
68                 }
69         }
70         return NULL;
71 }
72
73 /* This function will only be called in tool mode */
74 static int
75 glue_back_open (
76         BackendInfo *bi
77 )
78 {
79         int rc = 0;
80         static int glueOpened = 0;
81
82         if (glueOpened) return 0;
83
84         glueOpened = 1;
85
86         /* If we were invoked in tool mode, open all the underlying backends */
87         if (slapMode & SLAP_TOOL_MODE) {
88                 rc = backend_startup (NULL);
89         } /* other case is impossible */
90         return rc;
91 }
92
93 /* This function will only be called in tool mode */
94 static int
95 glue_back_close (
96         BackendInfo *bi
97 )
98 {
99         static int glueClosed = 0;
100         int rc = 0;
101
102         if (glueClosed) return 0;
103
104         glueClosed = 1;
105
106         if (slapMode & SLAP_TOOL_MODE) {
107                 rc = backend_shutdown (NULL);
108         }
109         return rc;
110 }
111
112 static int
113 glue_back_db_open (
114         BackendDB *be
115 )
116 {
117         glueinfo *gi = (glueinfo *)be->be_private;
118         static int glueOpened = 0;
119         int rc = 0;
120
121         if (glueOpened) return 0;
122
123         glueOpened = 1;
124
125         gi->be->be_acl = be->be_acl;
126
127         if (gi->be->bd_info->bi_db_open)
128                 rc = gi->be->bd_info->bi_db_open(gi->be);
129
130         return rc;
131 }
132
133 static int
134 glue_back_db_close (
135         BackendDB *be
136 )
137 {
138         glueinfo *gi = (glueinfo *)be->be_private;
139         static int glueClosed = 0;
140
141         if (glueClosed) return 0;
142
143         glueClosed = 1;
144
145         /* Close the master */
146         if (gi->be->bd_info->bi_db_close)
147                 gi->be->bd_info->bi_db_close( gi->be );
148
149         return 0;
150 }
151
152 static int
153 glue_back_db_destroy (
154         BackendDB *be
155 )
156 {
157         glueinfo *gi = (glueinfo *)be->be_private;
158
159         if (gi->be->bd_info->bi_db_destroy)
160                 gi->be->bd_info->bi_db_destroy( gi->be );
161         free (gi->be);
162         free (gi);
163         return 0;
164 }
165
166 typedef struct glue_state {
167         int err;
168         int nentries;
169         int matchlen;
170         char *matched;
171         int nrefs;
172         BerVarray refs;
173         slap_callback *prevcb;
174 } glue_state;
175
176 static void
177 glue_back_response (
178         Connection *conn,
179         Operation *op,
180         ber_tag_t tag,
181         ber_int_t msgid,
182         ber_int_t err,
183         const char *matched,
184         const char *text,
185         BerVarray ref,
186         const char *resoid,
187         struct berval *resdata,
188         struct berval *sasldata,
189         LDAPControl **ctrls
190 )
191 {
192         glue_state *gs = op->o_callback->sc_private;
193
194         if (err == LDAP_SUCCESS || gs->err != LDAP_SUCCESS)
195                 gs->err = err;
196         if (gs->err == LDAP_SUCCESS && gs->matched) {
197                 free (gs->matched);
198                 gs->matchlen = 0;
199         }
200         if (gs->err != LDAP_SUCCESS && matched) {
201                 int len;
202                 len = strlen (matched);
203                 if (len > gs->matchlen) {
204                         if (gs->matched)
205                                 free (gs->matched);
206                         gs->matched = ch_strdup (matched);
207                         gs->matchlen = len;
208                 }
209         }
210         if (ref) {
211                 int i, j, k;
212                 BerVarray new;
213
214                 for (i=0; ref[i].bv_val; i++);
215
216                 j = gs->nrefs;
217                 if (!j) {
218                         new = ch_malloc ((i+1)*sizeof(struct berval));
219                 } else {
220                         new = ch_realloc(gs->refs,
221                                 (j+i+1)*sizeof(struct berval));
222                 }
223                 for (k=0; k<i; j++,k++) {
224                         ber_dupbv( &new[j], &ref[k] );
225                 }
226                 new[j].bv_val = NULL;
227                 gs->nrefs = j;
228                 gs->refs = new;
229         }
230 }
231
232 static void
233 glue_back_sresult (
234         Connection *c,
235         Operation *op,
236         ber_int_t err,
237         const char *matched,
238         const char *text,
239         BerVarray refs,
240         LDAPControl **ctrls,
241         int nentries
242 )
243 {
244         glue_state *gs = op->o_callback->sc_private;
245
246         gs->nentries += nentries;
247         glue_back_response (c, op, 0, 0, err, matched, text, refs,
248                             NULL, NULL, NULL, ctrls);
249 }
250
251 static int
252 glue_back_sendentry (
253         BackendDB *be,
254         Connection *c,
255         Operation *op,
256         Entry *e,
257         AttributeName *an,
258         int ao,
259         LDAPControl **ctrls
260 )
261 {
262         slap_callback *tmp = op->o_callback;
263         glue_state *gs = tmp->sc_private;
264         int rc;
265
266         op->o_callback = gs->prevcb;
267         if (op->o_callback && op->o_callback->sc_sendentry) {
268                 rc = op->o_callback->sc_sendentry(be, c, op, e, an, ao, ctrls);
269         } else {
270                 rc = send_search_entry(be, c, op, e, an, ao, ctrls);
271         }
272         op->o_callback = tmp;
273         return rc;
274 }
275
276 static int
277 glue_back_search (
278         BackendDB *b0,
279         Connection *conn,
280         Operation *op,
281         struct berval *dn,
282         struct berval *ndn,
283         int scope,
284         int deref,
285         int slimit,
286         int tlimit,
287         Filter *filter,
288         struct berval *filterstr,
289         AttributeName *attrs,
290         int attrsonly
291 )
292 {
293         glueinfo *gi = (glueinfo *)b0->be_private;
294         BackendDB *be;
295         int i, rc = 0, t2limit = 0, s2limit = 0;
296         long stoptime = 0;
297         glue_state gs = {0};
298         slap_callback cb;
299
300         cb.sc_response = glue_back_response;
301         cb.sc_sresult = glue_back_sresult;
302         cb.sc_sendentry = glue_back_sendentry;
303         cb.sc_private = &gs;
304
305         gs.prevcb = op->o_callback;
306
307         if (tlimit) {
308                 stoptime = slap_get_time () + tlimit;
309         }
310
311         switch (scope) {
312         case LDAP_SCOPE_BASE:
313                 be = glue_back_select (b0, ndn->bv_val);
314
315                 if (be && be->be_search) {
316                         rc = be->be_search (be, conn, op, dn, ndn, scope,
317                                    deref, slimit, tlimit, filter, filterstr,
318                                             attrs, attrsonly);
319                 } else {
320                         rc = LDAP_UNWILLING_TO_PERFORM;
321                         send_ldap_result (conn, op, rc, NULL,
322                                       "No search target found", NULL, NULL);
323                 }
324                 return rc;
325
326         case LDAP_SCOPE_ONELEVEL:
327         case LDAP_SCOPE_SUBTREE:
328                 op->o_callback = &cb;
329                 rc = gs.err = LDAP_UNWILLING_TO_PERFORM;
330
331                 /*
332                  * Execute in reverse order, most general first 
333                  */
334                 for (i = gi->nodes-1; i >= 0; i--) {
335                         if (!gi->n[i].be || !gi->n[i].be->be_search)
336                                 continue;
337                         if (tlimit) {
338                                 t2limit = stoptime - slap_get_time ();
339                                 if (t2limit <= 0) {
340                                         rc = gs.err = LDAP_TIMELIMIT_EXCEEDED;
341                                         break;
342                                 }
343                         }
344                         if (slimit) {
345                                 s2limit = slimit - gs.nentries;
346                                 if (s2limit <= 0) {
347                                         rc = gs.err = LDAP_SIZELIMIT_EXCEEDED;
348                                         break;
349                                 }
350                         }
351                         rc = 0;
352                         /*
353                          * check for abandon 
354                          */
355                         if (op->o_abandon) {
356                                 goto done;
357                         }
358                         be = gi->n[i].be;
359                         if (scope == LDAP_SCOPE_ONELEVEL && 
360                                 dn_match(&gi->n[i].pdn, ndn)) {
361                                 rc = be->be_search (be, conn, op,
362                                         &be->be_suffix[0], &be->be_nsuffix[0],
363                                         LDAP_SCOPE_BASE, deref,
364                                         s2limit, t2limit, filter, filterstr,
365                                         attrs, attrsonly);
366
367                         } else if (scope == LDAP_SCOPE_SUBTREE &&
368                                 dnIsSuffix(&be->be_nsuffix[0], ndn)) {
369                                 rc = be->be_search (be, conn, op,
370                                         &be->be_suffix[0], &be->be_nsuffix[0],
371                                         scope, deref,
372                                         s2limit, t2limit, filter, filterstr,
373                                         attrs, attrsonly);
374
375                         } else if (dnIsSuffix(ndn, &be->be_nsuffix[0])) {
376                                 rc = be->be_search (be, conn, op, dn, ndn,
377                                         scope, deref,
378                                         s2limit, t2limit, filter, filterstr,
379                                         attrs, attrsonly);
380                         }
381                 }
382                 break;
383         }
384         op->o_callback = gs.prevcb;
385
386         send_search_result (conn, op, gs.err, gs.matched, NULL,
387                 gs.refs, NULL, gs.nentries);
388
389 done:
390         if (gs.matched)
391                 free (gs.matched);
392         if (gs.refs)
393                 ber_bvarray_free(gs.refs);
394         return rc;
395 }
396
397 static int
398 glue_back_bind (
399         BackendDB *b0,
400         Connection *conn,
401         Operation *op,
402         struct berval *dn,
403         struct berval *ndn,
404         int method,
405         struct berval *cred,
406         struct berval *edn
407 )
408 {
409         BackendDB *be;
410         int rc;
411  
412         be = glue_back_select (b0, ndn->bv_val);
413
414         if (be && be->be_bind) {
415                 rc = be->be_bind (be, conn, op, dn, ndn, method, cred, edn);
416
417                 if( rc == LDAP_SUCCESS ) {
418                         ldap_pvt_thread_mutex_lock( &conn->c_mutex );
419                         if( conn->c_authz_backend == NULL ) {
420                                 conn->c_authz_backend = be;
421                         }
422                         ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
423                 }
424         } else {
425                 rc = LDAP_UNWILLING_TO_PERFORM;
426                 send_ldap_result (conn, op, rc, NULL, "No bind target found",
427                                   NULL, NULL);
428         }
429         return rc;
430 }
431
432 static int
433 glue_back_compare (
434         BackendDB *b0,
435         Connection *conn,
436         Operation *op,
437         struct berval *dn,
438         struct berval *ndn,
439         AttributeAssertion *ava
440 )
441 {
442         BackendDB *be;
443         int rc;
444
445         be = glue_back_select (b0, ndn->bv_val);
446
447         if (be && be->be_compare) {
448                 rc = be->be_compare (be, conn, op, dn, ndn, ava);
449         } else {
450                 rc = LDAP_UNWILLING_TO_PERFORM;
451                 send_ldap_result (conn, op, rc, NULL, "No compare target found",
452                         NULL, NULL);
453         }
454         return rc;
455 }
456
457 static int
458 glue_back_modify (
459         BackendDB *b0,
460         Connection *conn,
461         Operation *op,
462         struct berval *dn,
463         struct berval *ndn,
464         Modifications *mod
465 )
466 {
467         BackendDB *be;
468         int rc;
469
470         be = glue_back_select (b0, ndn->bv_val);
471
472         if (be && be->be_modify) {
473                 rc = be->be_modify (be, conn, op, dn, ndn, mod);
474         } else {
475                 rc = LDAP_UNWILLING_TO_PERFORM;
476                 send_ldap_result (conn, op, rc, NULL,
477                         "No modify target found", NULL, NULL);
478         }
479         return rc;
480 }
481
482 static int
483 glue_back_modrdn (
484         BackendDB *b0,
485         Connection *conn,
486         Operation *op,
487         struct berval *dn,
488         struct berval *ndn,
489         struct berval *newrdn,
490         struct berval *nnewrdn,
491         int del,
492         struct berval *newsup,
493         struct berval *nnewsup
494 )
495 {
496         BackendDB *be;
497         int rc;
498
499         be = glue_back_select (b0, ndn->bv_val);
500
501         if (be && be->be_modrdn) {
502                 rc = be->be_modrdn (be, conn, op, dn, ndn,
503                         newrdn, nnewrdn, del, newsup, nnewsup );
504         } else {
505                 rc = LDAP_UNWILLING_TO_PERFORM;
506                 send_ldap_result (conn, op, rc, NULL,
507                         "No modrdn target found", NULL, NULL);
508         }
509         return rc;
510 }
511
512 static int
513 glue_back_add (
514         BackendDB *b0,
515         Connection *conn,
516         Operation *op,
517         Entry *e
518 )
519 {
520         BackendDB *be;
521         int rc;
522
523         be = glue_back_select (b0, e->e_ndn);
524
525         if (be && be->be_add) {
526                 rc = be->be_add (be, conn, op, e);
527         } else {
528                 rc = LDAP_UNWILLING_TO_PERFORM;
529                 send_ldap_result (conn, op, rc, NULL, "No add target found",
530                                   NULL, NULL);
531         }
532         return rc;
533 }
534
535 static int
536 glue_back_delete (
537         BackendDB *b0,
538         Connection *conn,
539         Operation *op,
540         struct berval *dn,
541         struct berval *ndn
542 )
543 {
544         BackendDB *be;
545         int rc;
546
547         be = glue_back_select (b0, ndn->bv_val);
548
549         if (be && be->be_delete) {
550                 rc = be->be_delete (be, conn, op, dn, ndn);
551         } else {
552                 rc = LDAP_UNWILLING_TO_PERFORM;
553                 send_ldap_result (conn, op, rc, NULL, "No delete target found",
554                                   NULL, NULL);
555         }
556         return rc;
557 }
558
559 static int
560 glue_back_release_rw (
561         BackendDB *b0,
562         Connection *conn,
563         Operation *op,
564         Entry *e,
565         int rw
566 )
567 {
568         BackendDB *be;
569         int rc;
570
571         be = glue_back_select (b0, e->e_ndn);
572
573         if (be && be->be_release) {
574                 rc = be->be_release (be, conn, op, e, rw);
575         } else {
576                 entry_free (e);
577                 rc = 0;
578         }
579         return rc;
580 }
581
582 static int
583 glue_back_group (
584         BackendDB *b0,
585         Connection *conn,
586         Operation *op,
587         Entry *target,
588         struct berval *ndn,
589         struct berval *ondn,
590         ObjectClass *oc,
591         AttributeDescription * ad
592 )
593 {
594         BackendDB *be;
595         int rc;
596
597         be = glue_back_select (b0, ndn->bv_val);
598
599         if (be && be->be_group) {
600                 rc = be->be_group (be, conn, op, target, ndn, ondn, oc, ad);
601         } else {
602                 rc = LDAP_UNWILLING_TO_PERFORM;
603         }
604         return rc;
605 }
606
607 static int
608 glue_back_attribute (
609         BackendDB *b0,
610         Connection *conn,
611         Operation *op,
612         Entry *target,
613         struct berval *ndn,
614         AttributeDescription *ad,
615         BerVarray *vals
616 )
617 {
618         BackendDB *be;
619         int rc;
620
621         be = glue_back_select (b0, ndn->bv_val);
622
623         if (be && be->be_attribute) {
624                 rc = be->be_attribute (be, conn, op, target, ndn, ad, vals);
625         } else {
626                 rc = LDAP_UNWILLING_TO_PERFORM;
627         }
628         return rc;
629 }
630
631 static int
632 glue_back_referrals (
633         BackendDB *b0,
634         Connection *conn,
635         Operation *op,
636         struct berval *dn,
637         struct berval *ndn,
638         const char **text
639 )
640 {
641         BackendDB *be;
642         int rc;
643
644         be = glue_back_select (b0, ndn->bv_val);
645
646         if (be && be->be_chk_referrals) {
647                 rc = be->be_chk_referrals (be, conn, op, dn, ndn, text);
648         } else {
649                 rc = LDAP_SUCCESS;;
650         }
651         return rc;
652 }
653
654 static int
655 glue_tool_entry_open (
656         BackendDB *b0,
657         int mode
658 )
659 {
660         /* We don't know which backend to talk to yet, so just
661          * remember the mode and move on...
662          */
663
664         glueMode = mode;
665         glueBack = NULL;
666
667         return 0;
668 }
669
670 static int
671 glue_tool_entry_close (
672         BackendDB *b0
673 )
674 {
675         int rc = 0;
676
677         if (glueBack) {
678                 if (!glueBack->be_entry_close)
679                         return 0;
680                 rc = glueBack->be_entry_close (glueBack);
681         }
682         return rc;
683 }
684
685 static ID
686 glue_tool_entry_first (
687         BackendDB *b0
688 )
689 {
690         glueinfo *gi = (glueinfo *) b0->be_private;
691         int i;
692
693         /* If we're starting from scratch, start at the most general */
694         if (!glueBack) {
695                 for (i = gi->nodes-1; i >= 0; i--) {
696                         if (gi->n[i].be->be_entry_open &&
697                             gi->n[i].be->be_entry_first) {
698                                 glueBack = gi->n[i].be;
699                                 break;
700                         }
701                 }
702
703         }
704         if (!glueBack || glueBack->be_entry_open (glueBack, glueMode) != 0)
705                 return NOID;
706
707         return glueBack->be_entry_first (glueBack);
708 }
709
710 static ID
711 glue_tool_entry_next (
712         BackendDB *b0
713 )
714 {
715         glueinfo *gi = (glueinfo *) b0->be_private;
716         int i;
717         ID rc;
718
719         if (!glueBack || !glueBack->be_entry_next)
720                 return NOID;
721
722         rc = glueBack->be_entry_next (glueBack);
723
724         /* If we ran out of entries in one database, move on to the next */
725         if (rc == NOID) {
726                 glueBack->be_entry_close (glueBack);
727                 for (i=0; i<gi->nodes; i++) {
728                         if (gi->n[i].be == glueBack)
729                                 break;
730                 }
731                 if (i == 0) {
732                         glueBack = NULL;
733                         rc = NOID;
734                 } else {
735                         glueBack = gi->n[i-1].be;
736                         rc = glue_tool_entry_first (b0);
737                 }
738         }
739         return rc;
740 }
741
742 static Entry *
743 glue_tool_entry_get (
744         BackendDB *b0,
745         ID id
746 )
747 {
748         if (!glueBack || !glueBack->be_entry_get)
749                 return NULL;
750
751         return glueBack->be_entry_get (glueBack, id);
752 }
753
754 static ID
755 glue_tool_entry_put (
756         BackendDB *b0,
757         Entry *e,
758         struct berval *text
759 )
760 {
761         BackendDB *be;
762         int rc;
763
764         be = glue_back_select (b0, e->e_ndn);
765         if (!be->be_entry_put)
766                 return NOID;
767
768         if (!glueBack) {
769                 rc = be->be_entry_open (be, glueMode);
770                 if (rc != 0)
771                         return NOID;
772         } else if (be != glueBack) {
773                 /* If this entry belongs in a different branch than the
774                  * previous one, close the current database and open the
775                  * new one.
776                  */
777                 glueBack->be_entry_close (glueBack);
778                 rc = be->be_entry_open (be, glueMode);
779                 if (rc != 0)
780                         return NOID;
781         }
782         glueBack = be;
783         return be->be_entry_put (be, e, text);
784 }
785
786 static int
787 glue_tool_entry_reindex (
788         BackendDB *b0,
789         ID id
790 )
791 {
792         if (!glueBack || !glueBack->be_entry_reindex)
793                 return -1;
794
795         return glueBack->be_entry_reindex (glueBack, id);
796 }
797
798 static int
799 glue_tool_sync (
800         BackendDB *b0
801 )
802 {
803         glueinfo *gi = (glueinfo *) b0->be_private;
804         int i;
805
806         /* just sync everyone */
807         for (i = 0; i<gi->nodes; i++)
808                 if (gi->n[i].be->be_sync)
809                         gi->n[i].be->be_sync (gi->n[i].be);
810         return 0;
811 }
812
813 int
814 glue_sub_init( )
815 {
816         int i, j;
817         int cont = num_subordinates;
818         BackendDB *b1, *be;
819         BackendInfo *bi = NULL;
820         glueinfo *gi;
821
822         /* While there are subordinate backends, search backwards through the
823          * backends and connect them to their superior.
824          */
825         for (i = nBackendDB - 1, b1=&backendDB[i]; cont && i>=0; b1--,i--) {
826                 if (b1->be_flags & SLAP_BFLAG_GLUE_SUBORDINATE) {
827                         /* The last database cannot be a subordinate of noone */
828                         if (i == nBackendDB - 1) {
829                                 b1->be_flags ^= SLAP_BFLAG_GLUE_SUBORDINATE;
830                         }
831                         continue;
832                 }
833                 gi = NULL;
834                 for (j = i-1, be=&backendDB[j]; j>=0; be--,j--) {
835                         if (!(be->be_flags & SLAP_BFLAG_GLUE_SUBORDINATE)) {
836                                 continue;
837                         }
838                         /* We will only link it once */
839                         if (be->be_flags & SLAP_BFLAG_GLUE_LINKED) {
840                                 continue;
841                         }
842                         if (!dnIsSuffix(&be->be_nsuffix[0], &b1->be_nsuffix[0])) {
843                                 continue;
844                         }
845                         cont--;
846                         be->be_flags |= SLAP_BFLAG_GLUE_LINKED;
847                         if (gi == NULL) {
848                                 /* We create a copy of the superior's be
849                                  * structure, pointing to all of its original
850                                  * information. Then we replace elements of
851                                  * the superior's info with our own. The copy
852                                  * is used whenever we have operations to pass
853                                  * down to the real database.
854                                  */
855                                 b1->be_flags |= SLAP_BFLAG_GLUE_INSTANCE;
856                                 gi = (glueinfo *)ch_malloc(sizeof(glueinfo));
857                                 gi->be = (BackendDB *)ch_malloc(
858                                         sizeof(BackendDB) + sizeof(BackendInfo));
859                                 bi = (BackendInfo *)(gi->be+1);
860                                 *gi->be = *b1;
861                                 gi->nodes = 0;
862                                 *bi = *b1->bd_info;
863                                 bi->bi_open = glue_back_open;
864                                 bi->bi_close = glue_back_close;
865                                 bi->bi_db_open = glue_back_db_open;
866                                 bi->bi_db_close = glue_back_db_close;
867                                 bi->bi_db_destroy = glue_back_db_destroy;
868
869                                 bi->bi_op_bind = glue_back_bind;
870                                 bi->bi_op_search = glue_back_search;
871                                 bi->bi_op_compare = glue_back_compare;
872                                 bi->bi_op_modify = glue_back_modify;
873                                 bi->bi_op_modrdn = glue_back_modrdn;
874                                 bi->bi_op_add = glue_back_add;
875                                 bi->bi_op_delete = glue_back_delete;
876
877                                 bi->bi_entry_release_rw = glue_back_release_rw;
878                                 bi->bi_acl_group = glue_back_group;
879                                 bi->bi_acl_attribute = glue_back_attribute;
880                                 bi->bi_chk_referrals = glue_back_referrals;
881
882                                 /*
883                                  * hooks for slap tools
884                                  */
885                                 bi->bi_tool_entry_open = glue_tool_entry_open;
886                                 bi->bi_tool_entry_close = glue_tool_entry_close;
887                                 bi->bi_tool_entry_first = glue_tool_entry_first;
888                                 bi->bi_tool_entry_next = glue_tool_entry_next;
889                                 bi->bi_tool_entry_get = glue_tool_entry_get;
890                                 bi->bi_tool_entry_put = glue_tool_entry_put;
891                                 bi->bi_tool_entry_reindex = glue_tool_entry_reindex;
892                                 bi->bi_tool_sync = glue_tool_sync;
893                         } else {
894                                 gi = (glueinfo *)ch_realloc(gi,
895                                         sizeof(glueinfo) +
896                                         gi->nodes * sizeof(gluenode));
897                         }
898                         gi->n[gi->nodes].be = be;
899                         dnParent( &be->be_nsuffix[0], &gi->n[gi->nodes].pdn ); 
900                         gi->nodes++;
901                 }
902                 if (gi) {
903                         /* One more node for the master */
904                         gi = (glueinfo *)ch_realloc(gi,
905                                 sizeof(glueinfo) + gi->nodes * sizeof(gluenode));
906                         gi->n[gi->nodes].be = gi->be;
907                         dnParent( &b1->be_nsuffix[0], &gi->n[gi->nodes].pdn );
908                         gi->nodes++;
909                         b1->be_private = gi;
910                         b1->bd_info = bi;
911                 }
912         }
913         /* If there are any unresolved subordinates left, something is wrong */
914         return cont;
915 }