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