]> git.sur5r.net Git - openldap/blob - servers/slapd/backglue.c
9b1a445325d9307872e74e085987e287c7f77cf1
[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         struct berval bv;
298         glue_state gs = {0};
299         slap_callback cb;
300
301         cb.sc_response = glue_back_response;
302         cb.sc_sresult = glue_back_sresult;
303         cb.sc_sendentry = glue_back_sendentry;
304         cb.sc_private = &gs;
305
306         gs.prevcb = op->o_callback;
307
308         if (tlimit) {
309                 stoptime = slap_get_time () + tlimit;
310         }
311
312         switch (scope) {
313         case LDAP_SCOPE_BASE:
314                 be = glue_back_select (b0, ndn->bv_val);
315
316                 if (be && be->be_search) {
317                         rc = be->be_search (be, conn, op, dn, ndn, scope,
318                                    deref, slimit, tlimit, filter, filterstr,
319                                             attrs, attrsonly);
320                 } else {
321                         rc = LDAP_UNWILLING_TO_PERFORM;
322                         send_ldap_result (conn, op, rc, NULL,
323                                       "No search target found", NULL, NULL);
324                 }
325                 return rc;
326
327         case LDAP_SCOPE_ONELEVEL:
328         case LDAP_SCOPE_SUBTREE:
329                 op->o_callback = &cb;
330                 rc = gs.err = LDAP_UNWILLING_TO_PERFORM;
331
332                 /*
333                  * Execute in reverse order, most general first 
334                  */
335                 for (i = gi->nodes-1; i >= 0; i--) {
336                         if (!gi->n[i].be || !gi->n[i].be->be_search)
337                                 continue;
338                         if (tlimit) {
339                                 t2limit = stoptime - slap_get_time ();
340                                 if (t2limit <= 0) {
341                                         rc = gs.err = LDAP_TIMELIMIT_EXCEEDED;
342                                         break;
343                                 }
344                         }
345                         if (slimit) {
346                                 s2limit = slimit - gs.nentries;
347                                 if (s2limit <= 0) {
348                                         rc = gs.err = LDAP_SIZELIMIT_EXCEEDED;
349                                         break;
350                                 }
351                         }
352                         /*
353                          * check for abandon 
354                          */
355                         ldap_pvt_thread_mutex_lock (&op->o_abandonmutex);
356                         rc = op->o_abandon;
357                         ldap_pvt_thread_mutex_unlock (&op->o_abandonmutex);
358                         if (rc) {
359                                 rc = 0;
360                                 goto done;
361                         }
362                         be = gi->n[i].be;
363                         if (scope == LDAP_SCOPE_ONELEVEL && 
364                                 dn_match(&gi->n[i].pdn, ndn)) {
365                                 rc = be->be_search (be, conn, op,
366                                         be->be_suffix[0], be->be_nsuffix[0],
367                                         LDAP_SCOPE_BASE, deref,
368                                         s2limit, t2limit, filter, filterstr,
369                                         attrs, attrsonly);
370
371                         } else if (scope == LDAP_SCOPE_SUBTREE &&
372                                 dnIsSuffix(be->be_nsuffix[0], ndn)) {
373                                 rc = be->be_search (be, conn, op,
374                                         be->be_suffix[0], be->be_nsuffix[0],
375                                         scope, deref,
376                                         s2limit, t2limit, filter, filterstr,
377                                         attrs, attrsonly);
378
379                         } else if (dnIsSuffix(&bv, be->be_nsuffix[0])) {
380                                 rc = be->be_search (be, conn, op, dn, ndn,
381                                         scope, deref,
382                                         s2limit, t2limit, filter, filterstr,
383                                         attrs, attrsonly);
384                         }
385                 }
386                 break;
387         }
388         op->o_callback = gs.prevcb;
389
390         send_search_result (conn, op, gs.err, gs.matched, NULL,
391                 gs.refs, NULL, gs.nentries);
392
393 done:
394         if (gs.matched)
395                 free (gs.matched);
396         if (gs.refs)
397                 ber_bvarray_free(gs.refs);
398         return rc;
399 }
400
401 static int
402 glue_back_bind (
403         BackendDB *b0,
404         Connection *conn,
405         Operation *op,
406         struct berval *dn,
407         struct berval *ndn,
408         int method,
409         struct berval *cred,
410         struct berval *edn
411 )
412 {
413         BackendDB *be;
414         int rc;
415  
416         be = glue_back_select (b0, ndn->bv_val);
417
418         if (be && be->be_bind) {
419                 conn->c_authz_backend = be;
420                 rc = be->be_bind (be, conn, op, dn, ndn, method, cred, edn);
421         } else {
422                 rc = LDAP_UNWILLING_TO_PERFORM;
423                 send_ldap_result (conn, op, rc, NULL, "No bind target found",
424                                   NULL, NULL);
425         }
426         return rc;
427 }
428
429 static int
430 glue_back_compare (
431         BackendDB *b0,
432         Connection *conn,
433         Operation *op,
434         struct berval *dn,
435         struct berval *ndn,
436         AttributeAssertion *ava
437 )
438 {
439         BackendDB *be;
440         int rc;
441
442         be = glue_back_select (b0, ndn->bv_val);
443
444         if (be && be->be_compare) {
445                 rc = be->be_compare (be, conn, op, dn, ndn, ava);
446         } else {
447                 rc = LDAP_UNWILLING_TO_PERFORM;
448                 send_ldap_result (conn, op, rc, NULL, "No compare target found",
449                         NULL, NULL);
450         }
451         return rc;
452 }
453
454 static int
455 glue_back_modify (
456         BackendDB *b0,
457         Connection *conn,
458         Operation *op,
459         struct berval *dn,
460         struct berval *ndn,
461         Modifications *mod
462 )
463 {
464         BackendDB *be;
465         int rc;
466
467         be = glue_back_select (b0, ndn->bv_val);
468
469         if (be && be->be_modify) {
470                 rc = be->be_modify (be, conn, op, dn, ndn, mod);
471         } else {
472                 rc = LDAP_UNWILLING_TO_PERFORM;
473                 send_ldap_result (conn, op, rc, NULL,
474                         "No modify target found", NULL, NULL);
475         }
476         return rc;
477 }
478
479 static int
480 glue_back_modrdn (
481         BackendDB *b0,
482         Connection *conn,
483         Operation *op,
484         struct berval *dn,
485         struct berval *ndn,
486         struct berval *newrdn,
487         struct berval *nnewrdn,
488         int del,
489         struct berval *newsup,
490         struct berval *nnewsup
491 )
492 {
493         BackendDB *be;
494         int rc;
495
496         be = glue_back_select (b0, ndn->bv_val);
497
498         if (be && be->be_modrdn) {
499                 rc = be->be_modrdn (be, conn, op, dn, ndn,
500                         newrdn, nnewrdn, del, newsup, nnewsup );
501         } else {
502                 rc = LDAP_UNWILLING_TO_PERFORM;
503                 send_ldap_result (conn, op, rc, NULL,
504                         "No modrdn target found", NULL, NULL);
505         }
506         return rc;
507 }
508
509 static int
510 glue_back_add (
511         BackendDB *b0,
512         Connection *conn,
513         Operation *op,
514         Entry *e
515 )
516 {
517         BackendDB *be;
518         int rc;
519
520         be = glue_back_select (b0, e->e_ndn);
521
522         if (be && be->be_add) {
523                 rc = be->be_add (be, conn, op, e);
524         } else {
525                 rc = LDAP_UNWILLING_TO_PERFORM;
526                 send_ldap_result (conn, op, rc, NULL, "No add target found",
527                                   NULL, NULL);
528         }
529         return rc;
530 }
531
532 static int
533 glue_back_delete (
534         BackendDB *b0,
535         Connection *conn,
536         Operation *op,
537         struct berval *dn,
538         struct berval *ndn
539 )
540 {
541         BackendDB *be;
542         int rc;
543
544         be = glue_back_select (b0, ndn->bv_val);
545
546         if (be && be->be_delete) {
547                 rc = be->be_delete (be, conn, op, dn, ndn);
548         } else {
549                 rc = LDAP_UNWILLING_TO_PERFORM;
550                 send_ldap_result (conn, op, rc, NULL, "No delete target found",
551                                   NULL, NULL);
552         }
553         return rc;
554 }
555
556 static int
557 glue_back_release_rw (
558         BackendDB *b0,
559         Connection *conn,
560         Operation *op,
561         Entry *e,
562         int rw
563 )
564 {
565         BackendDB *be;
566         int rc;
567
568         be = glue_back_select (b0, e->e_ndn);
569
570         if (be && be->be_release) {
571                 rc = be->be_release (be, conn, op, e, rw);
572         } else {
573                 entry_free (e);
574                 rc = 0;
575         }
576         return rc;
577 }
578
579 static int
580 glue_back_group (
581         BackendDB *b0,
582         Connection *conn,
583         Operation *op,
584         Entry *target,
585         struct berval *ndn,
586         struct berval *ondn,
587         ObjectClass *oc,
588         AttributeDescription * ad
589 )
590 {
591         BackendDB *be;
592         int rc;
593
594         be = glue_back_select (b0, ndn->bv_val);
595
596         if (be && be->be_group) {
597                 rc = be->be_group (be, conn, op, target, ndn, ondn, oc, ad);
598         } else {
599                 rc = LDAP_UNWILLING_TO_PERFORM;
600         }
601         return rc;
602 }
603
604 static int
605 glue_back_attribute (
606         BackendDB *b0,
607         Connection *conn,
608         Operation *op,
609         Entry *target,
610         struct berval *ndn,
611         AttributeDescription *ad,
612         BerVarray *vals
613 )
614 {
615         BackendDB *be;
616         int rc;
617
618         be = glue_back_select (b0, ndn->bv_val);
619
620         if (be && be->be_attribute) {
621                 rc = be->be_attribute (be, conn, op, target, ndn, ad, vals);
622         } else {
623                 rc = LDAP_UNWILLING_TO_PERFORM;
624         }
625         return rc;
626 }
627
628 static int
629 glue_back_referrals (
630         BackendDB *b0,
631         Connection *conn,
632         Operation *op,
633         struct berval *dn,
634         struct berval *ndn,
635         const char **text
636 )
637 {
638         BackendDB *be;
639         int rc;
640
641         be = glue_back_select (b0, ndn->bv_val);
642
643         if (be && be->be_chk_referrals) {
644                 rc = be->be_chk_referrals (be, conn, op, dn, ndn, text);
645         } else {
646                 rc = LDAP_SUCCESS;;
647         }
648         return rc;
649 }
650
651 static int
652 glue_tool_entry_open (
653         BackendDB *b0,
654         int mode
655 )
656 {
657         /* We don't know which backend to talk to yet, so just
658          * remember the mode and move on...
659          */
660
661         glueMode = mode;
662         glueBack = NULL;
663
664         return 0;
665 }
666
667 static int
668 glue_tool_entry_close (
669         BackendDB *b0
670 )
671 {
672         int rc = 0;
673
674         if (glueBack) {
675                 if (!glueBack->be_entry_close)
676                         return 0;
677                 rc = glueBack->be_entry_close (glueBack);
678         }
679         return rc;
680 }
681
682 static ID
683 glue_tool_entry_first (
684         BackendDB *b0
685 )
686 {
687         glueinfo *gi = (glueinfo *) b0->be_private;
688         int i;
689
690         /* If we're starting from scratch, start at the most general */
691         if (!glueBack) {
692                 for (i = gi->nodes-1; i >= 0; i--) {
693                         if (gi->n[i].be->be_entry_open &&
694                             gi->n[i].be->be_entry_first) {
695                                 glueBack = gi->n[i].be;
696                                 break;
697                         }
698                 }
699
700         }
701         if (!glueBack || glueBack->be_entry_open (glueBack, glueMode) != 0)
702                 return NOID;
703
704         return glueBack->be_entry_first (glueBack);
705 }
706
707 static ID
708 glue_tool_entry_next (
709         BackendDB *b0
710 )
711 {
712         glueinfo *gi = (glueinfo *) b0->be_private;
713         int i;
714         ID rc;
715
716         if (!glueBack || !glueBack->be_entry_next)
717                 return NOID;
718
719         rc = glueBack->be_entry_next (glueBack);
720
721         /* If we ran out of entries in one database, move on to the next */
722         if (rc == NOID) {
723                 glueBack->be_entry_close (glueBack);
724                 for (i=0; i<gi->nodes; i++) {
725                         if (gi->n[i].be == glueBack)
726                                 break;
727                 }
728                 if (i == 0) {
729                         glueBack = NULL;
730                         rc = NOID;
731                 } else {
732                         glueBack = gi->n[i-1].be;
733                         rc = glue_tool_entry_first (b0);
734                 }
735         }
736         return rc;
737 }
738
739 static Entry *
740 glue_tool_entry_get (
741         BackendDB *b0,
742         ID id
743 )
744 {
745         if (!glueBack || !glueBack->be_entry_get)
746                 return NULL;
747
748         return glueBack->be_entry_get (glueBack, id);
749 }
750
751 static ID
752 glue_tool_entry_put (
753         BackendDB *b0,
754         Entry *e,
755         struct berval *text
756 )
757 {
758         BackendDB *be;
759         int rc;
760
761         be = glue_back_select (b0, e->e_ndn);
762         if (!be->be_entry_put)
763                 return NOID;
764
765         if (!glueBack) {
766                 rc = be->be_entry_open (be, glueMode);
767                 if (rc != 0)
768                         return NOID;
769         } else if (be != glueBack) {
770                 /* If this entry belongs in a different branch than the
771                  * previous one, close the current database and open the
772                  * new one.
773                  */
774                 glueBack->be_entry_close (glueBack);
775                 rc = be->be_entry_open (be, glueMode);
776                 if (rc != 0)
777                         return NOID;
778         }
779         glueBack = be;
780         return be->be_entry_put (be, e, text);
781 }
782
783 static int
784 glue_tool_entry_reindex (
785         BackendDB *b0,
786         ID id
787 )
788 {
789         if (!glueBack || !glueBack->be_entry_reindex)
790                 return -1;
791
792         return glueBack->be_entry_reindex (glueBack, id);
793 }
794
795 static int
796 glue_tool_sync (
797         BackendDB *b0
798 )
799 {
800         glueinfo *gi = (glueinfo *) b0->be_private;
801         int i;
802
803         /* just sync everyone */
804         for (i = 0; i<gi->nodes; i++)
805                 if (gi->n[i].be->be_sync)
806                         gi->n[i].be->be_sync (gi->n[i].be);
807         return 0;
808 }
809
810 int
811 glue_sub_init( )
812 {
813         int i, j;
814         int cont = num_subordinates;
815         BackendDB *b1, *be;
816         BackendInfo *bi = NULL;
817         glueinfo *gi;
818
819         /* While there are subordinate backends, search backwards through the
820          * backends and connect them to their superior.
821          */
822         for (i = nBackendDB - 1, b1=&backendDB[i]; cont && i>=0; b1--,i--) {
823                 if (b1->be_flags & SLAP_BFLAG_GLUE_SUBORDINATE) {
824                         /* The last database cannot be a subordinate of noone */
825                         if (i == nBackendDB - 1) {
826                                 b1->be_flags ^= SLAP_BFLAG_GLUE_SUBORDINATE;
827                         }
828                         continue;
829                 }
830                 gi = NULL;
831                 for (j = i-1, be=&backendDB[j]; j>=0; be--,j--) {
832                         if (!(be->be_flags & SLAP_BFLAG_GLUE_SUBORDINATE)) {
833                                 continue;
834                         }
835                         /* We will only link it once */
836                         if (be->be_flags & SLAP_BFLAG_GLUE_LINKED) {
837                                 continue;
838                         }
839                         if (!dnIsSuffix(be->be_nsuffix[0], b1->be_nsuffix[0])) {
840                                 continue;
841                         }
842                         cont--;
843                         be->be_flags |= SLAP_BFLAG_GLUE_LINKED;
844                         if (gi == NULL) {
845                                 /* We create a copy of the superior's be
846                                  * structure, pointing to all of its original
847                                  * information. Then we replace elements of
848                                  * the superior's info with our own. The copy
849                                  * is used whenever we have operations to pass
850                                  * down to the real database.
851                                  */
852                                 b1->be_flags |= SLAP_BFLAG_GLUE_INSTANCE;
853                                 gi = (glueinfo *)ch_malloc(sizeof(glueinfo));
854                                 gi->be = (BackendDB *)ch_malloc(
855                                         sizeof(BackendDB) + sizeof(BackendInfo));
856                                 bi = (BackendInfo *)(gi->be+1);
857                                 *gi->be = *b1;
858                                 gi->nodes = 0;
859                                 *bi = *b1->bd_info;
860                                 bi->bi_open = glue_back_open;
861                                 bi->bi_close = glue_back_close;
862                                 bi->bi_db_open = glue_back_db_open;
863                                 bi->bi_db_close = glue_back_db_close;
864                                 bi->bi_db_destroy = glue_back_db_destroy;
865
866                                 bi->bi_op_bind = glue_back_bind;
867                                 bi->bi_op_search = glue_back_search;
868                                 bi->bi_op_compare = glue_back_compare;
869                                 bi->bi_op_modify = glue_back_modify;
870                                 bi->bi_op_modrdn = glue_back_modrdn;
871                                 bi->bi_op_add = glue_back_add;
872                                 bi->bi_op_delete = glue_back_delete;
873
874                                 bi->bi_entry_release_rw = glue_back_release_rw;
875                                 bi->bi_acl_group = glue_back_group;
876                                 bi->bi_acl_attribute = glue_back_attribute;
877                                 bi->bi_chk_referrals = glue_back_referrals;
878
879                                 /*
880                                  * hooks for slap tools
881                                  */
882                                 bi->bi_tool_entry_open = glue_tool_entry_open;
883                                 bi->bi_tool_entry_close = glue_tool_entry_close;
884                                 bi->bi_tool_entry_first = glue_tool_entry_first;
885                                 bi->bi_tool_entry_next = glue_tool_entry_next;
886                                 bi->bi_tool_entry_get = glue_tool_entry_get;
887                                 bi->bi_tool_entry_put = glue_tool_entry_put;
888                                 bi->bi_tool_entry_reindex = glue_tool_entry_reindex;
889                                 bi->bi_tool_sync = glue_tool_sync;
890                         } else {
891                                 gi = (glueinfo *)ch_realloc(gi,
892                                         sizeof(glueinfo) +
893                                         gi->nodes * sizeof(gluenode));
894                         }
895                         gi->n[gi->nodes].be = be;
896                         dnParent( be->be_nsuffix[0], &gi->n[gi->nodes].pdn ); 
897                         gi->nodes++;
898                 }
899                 if (gi) {
900                         /* One more node for the master */
901                         gi = (glueinfo *)ch_realloc(gi,
902                                 sizeof(glueinfo) + gi->nodes * sizeof(gluenode));
903                         gi->n[gi->nodes].be = gi->be;
904                         dnParent( b1->be_nsuffix[0], &gi->n[gi->nodes].pdn );
905                         gi->nodes++;
906                         b1->be_private = gi;
907                         b1->bd_info = bi;
908                 }
909         }
910         /* If there are any unresolved subordinates left, something is wrong */
911         return cont;
912 }