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