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