]> git.sur5r.net Git - openldap/blob - servers/slapd/overlays/glue.c
Use a single sessionlog per context, delete sid
[openldap] / servers / slapd / overlays / glue.c
1 /* glue.c - backend glue overlay */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 2001-2005 The OpenLDAP Foundation.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted only as authorized by the OpenLDAP
10  * Public License.
11  *
12  * A copy of this license is available in the file LICENSE in the
13  * top-level directory of the distribution or, alternatively, at
14  * <http://www.OpenLDAP.org/license.html>.
15  */
16
17 /*
18  * Functions to glue a bunch of other backends into a single tree.
19  * All of the glued backends must share a common suffix. E.g., you
20  * can glue o=foo and ou=bar,o=foo but you can't glue o=foo and o=bar.
21  *
22  * The purpose of these functions is to allow you to split a single database
23  * into pieces (for load balancing purposes, whatever) but still be able
24  * to treat it as a single database after it's been split. As such, each
25  * of the glued backends should have identical rootdn.
26  *  -- Howard Chu
27  */
28
29 #include "portable.h"
30
31 #ifdef SLAPD_OVER_GLUE
32
33 #include <stdio.h>
34
35 #include <ac/string.h>
36 #include <ac/socket.h>
37
38 #define SLAPD_TOOLS
39 #include "slap.h"
40
41 typedef struct gluenode {
42         BackendDB *gn_be;
43         int     gn_bx;
44         struct berval gn_pdn;
45         int gn_async;
46 } gluenode;
47
48 typedef struct glueinfo {
49         int gi_nodes;
50         struct berval gi_pdn;
51         gluenode gi_n[1];
52 } glueinfo;
53
54 static slap_overinst    glue;
55
56 static int glueMode;
57 static BackendDB *glueBack;
58
59 static slap_response glue_op_response;
60
61 /* Just like select_backend, but only for our backends */
62 static BackendDB *
63 glue_back_select (
64         BackendDB *be,
65         struct berval *dn
66 )
67 {
68         slap_overinst   *on = (slap_overinst *)be->bd_info;
69         glueinfo                *gi = (glueinfo *)on->on_bi.bi_private;
70         int i;
71
72         for (i = 0; i<gi->gi_nodes; i++) {
73                 assert( gi->gi_n[i].gn_be->be_nsuffix );
74
75                 if (dnIsSuffix(dn, &gi->gi_n[i].gn_be->be_nsuffix[0])) {
76                         return gi->gi_n[i].gn_be;
77                 }
78         }
79         be->bd_info = on->on_info->oi_orig;
80         return be;
81 }
82
83
84 typedef struct glue_state {
85         int err;
86         int slimit;
87         int matchlen;
88         char *matched;
89         int nrefs;
90         BerVarray refs;
91 } glue_state;
92
93 static int
94 glue_op_response ( Operation *op, SlapReply *rs )
95 {
96         glue_state *gs = op->o_callback->sc_private;
97
98         switch(rs->sr_type) {
99         case REP_SEARCH:
100                 if ( gs->slimit != SLAP_NO_LIMIT
101                                 && rs->sr_nentries >= gs->slimit )
102                 {
103                         rs->sr_err = gs->err = LDAP_SIZELIMIT_EXCEEDED;
104                         return -1;
105                 }
106                 /* fallthru */
107         case REP_SEARCHREF:
108                 return SLAP_CB_CONTINUE;
109
110         default:
111                 if (rs->sr_err == LDAP_SUCCESS ||
112                         rs->sr_err == LDAP_SIZELIMIT_EXCEEDED ||
113                         rs->sr_err == LDAP_TIMELIMIT_EXCEEDED ||
114                         rs->sr_err == LDAP_ADMINLIMIT_EXCEEDED ||
115                         rs->sr_err == LDAP_NO_SUCH_OBJECT ||
116                         gs->err != LDAP_SUCCESS)
117                         gs->err = rs->sr_err;
118                 if (gs->err == LDAP_SUCCESS && gs->matched) {
119                         ch_free (gs->matched);
120                         gs->matched = NULL;
121                         gs->matchlen = 0;
122                 }
123                 if (gs->err != LDAP_SUCCESS && rs->sr_matched) {
124                         int len;
125                         len = strlen (rs->sr_matched);
126                         if (len > gs->matchlen) {
127                                 if (gs->matched)
128                                         ch_free (gs->matched);
129                                 gs->matched = ch_strdup (rs->sr_matched);
130                                 gs->matchlen = len;
131                         }
132                 }
133                 if (rs->sr_ref) {
134                         int i, j, k;
135                         BerVarray new;
136
137                         for (i=0; rs->sr_ref[i].bv_val; i++);
138
139                         j = gs->nrefs;
140                         if (!j) {
141                                 new = ch_malloc ((i+1)*sizeof(struct berval));
142                         } else {
143                                 new = ch_realloc(gs->refs,
144                                         (j+i+1)*sizeof(struct berval));
145                         }
146                         for (k=0; k<i; j++,k++) {
147                                 ber_dupbv( &new[j], &rs->sr_ref[k] );
148                         }
149                         new[j].bv_val = NULL;
150                         gs->nrefs = j;
151                         gs->refs = new;
152                 }
153         }
154         return 0;
155 }
156
157 enum glue_which {
158         op_modify = 0,
159         op_modrdn,
160         op_add,
161         op_delete
162 };
163
164 static int
165 glue_op_func ( Operation *op, SlapReply *rs )
166 {
167         slap_overinst   *on = (slap_overinst *)op->o_bd->bd_info;
168         glueinfo                *gi = (glueinfo *)on->on_bi.bi_private;
169         BackendDB *b0 = op->o_bd;
170         BackendInfo *bi0 = op->o_bd->bd_info;
171         BI_op_modify **func;
172         enum glue_which which;
173         int rc;
174
175         op->o_bd = glue_back_select (b0, &op->o_req_ndn);
176         b0->bd_info = on->on_info->oi_orig;
177
178         switch(op->o_tag) {
179         case LDAP_REQ_ADD: which = op_add; break;
180         case LDAP_REQ_DELETE: which = op_delete; break;
181         case LDAP_REQ_MODIFY: which = op_modify; break;
182         case LDAP_REQ_MODRDN: which = op_modrdn; break;
183         }
184
185         func = &op->o_bd->bd_info->bi_op_modify;
186         if ( func[which] )
187                 rc = func[which]( op, rs );
188         else
189                 rc = SLAP_CB_CONTINUE;
190
191         op->o_bd = b0;
192         op->o_bd->bd_info = bi0;
193         return rc;
194 }
195
196 static int
197 glue_op_search ( Operation *op, SlapReply *rs )
198 {
199         slap_overinst   *on = (slap_overinst *)op->o_bd->bd_info;
200         glueinfo                *gi = (glueinfo *)on->on_bi.bi_private;
201         BackendDB *b0 = op->o_bd;
202         BackendDB *b1 = NULL, *btmp;
203         BackendInfo *bi0 = op->o_bd->bd_info;
204         int i;
205         long stoptime = 0;
206         glue_state gs = {0, 0, 0, NULL, 0, NULL};
207         slap_callback cb = { NULL, glue_op_response, NULL, NULL };
208         int scope0, slimit0, tlimit0;
209         struct berval dn, ndn, *pdn;
210
211         cb.sc_private = &gs;
212
213         cb.sc_next = op->o_callback;
214
215         stoptime = slap_get_time () + op->ors_tlimit;
216
217         op->o_bd = glue_back_select (b0, &op->o_req_ndn);
218         b0->bd_info = on->on_info->oi_orig;
219
220         switch (op->ors_scope) {
221         case LDAP_SCOPE_BASE:
222                 return SLAP_CB_CONTINUE;
223
224         case LDAP_SCOPE_ONELEVEL:
225         case LDAP_SCOPE_SUBTREE:
226 #ifdef LDAP_SCOPE_SUBORDINATE
227         case LDAP_SCOPE_SUBORDINATE: /* FIXME */
228 #endif
229
230 #if 0
231                 if ( op->o_sync ) {
232                         if (op->o_bd && op->o_bd->be_search) {
233                                 rs->sr_err = op->o_bd->be_search( op, rs );
234                         } else {
235                                 send_ldap_error(op, rs, LDAP_UNWILLING_TO_PERFORM,
236                                                 "No search target found");
237                         }
238                         return rs->sr_err;
239                 }
240 #endif
241
242                 op->o_callback = &cb;
243                 rs->sr_err = gs.err = LDAP_UNWILLING_TO_PERFORM;
244                 scope0 = op->ors_scope;
245                 slimit0 = gs.slimit = op->ors_slimit;
246                 tlimit0 = op->ors_tlimit;
247                 dn = op->o_req_dn;
248                 ndn = op->o_req_ndn;
249                 b1 = op->o_bd;
250
251                 /*
252                  * Execute in reverse order, most general first 
253                  */
254                 for (i = gi->gi_nodes; i >= 0; i--) {
255                         if ( i == gi->gi_nodes ) {
256                                 btmp = b0;
257                                 pdn = &gi->gi_pdn;
258                         } else {
259                                 btmp = gi->gi_n[i].gn_be;
260                                 pdn = &gi->gi_n[i].gn_pdn;
261                         }
262                         if (!btmp || !btmp->be_search)
263                                 continue;
264                         if (!dnIsSuffix(&btmp->be_nsuffix[0], &b1->be_nsuffix[0]))
265                                 continue;
266                         if (tlimit0 != SLAP_NO_LIMIT) {
267                                 op->ors_tlimit = stoptime - slap_get_time ();
268                                 if (op->ors_tlimit <= 0) {
269                                         rs->sr_err = gs.err = LDAP_TIMELIMIT_EXCEEDED;
270                                         break;
271                                 }
272                         }
273                         if (slimit0 != SLAP_NO_LIMIT) {
274                                 op->ors_slimit = slimit0 - rs->sr_nentries;
275                                 if (op->ors_slimit < 0) {
276                                         rs->sr_err = gs.err = LDAP_SIZELIMIT_EXCEEDED;
277                                         break;
278                                 }
279                         }
280                         rs->sr_err = 0;
281                         /*
282                          * check for abandon 
283                          */
284                         if (op->o_abandon) {
285                                 goto end_of_loop;
286                         }
287                         op->o_bd = btmp;
288
289                         assert( op->o_bd->be_suffix );
290                         assert( op->o_bd->be_nsuffix );
291                         
292                         if (scope0 == LDAP_SCOPE_ONELEVEL && 
293                                 dn_match(pdn, &ndn))
294                         {
295                                 op->ors_scope = LDAP_SCOPE_BASE;
296                                 op->o_req_dn = op->o_bd->be_suffix[0];
297                                 op->o_req_ndn = op->o_bd->be_nsuffix[0];
298                                 rs->sr_err = op->o_bd->be_search(op, rs);
299
300                         } else if (scope0 == LDAP_SCOPE_SUBTREE &&
301                                 dn_match(&op->o_bd->be_nsuffix[0], &ndn))
302                         {
303                                 rs->sr_err = op->o_bd->be_search( op, rs );
304
305                         } else if (scope0 == LDAP_SCOPE_SUBTREE &&
306                                 dnIsSuffix(&op->o_bd->be_nsuffix[0], &ndn))
307                         {
308                                 op->o_req_dn = op->o_bd->be_suffix[0];
309                                 op->o_req_ndn = op->o_bd->be_nsuffix[0];
310                                 rs->sr_err = op->o_bd->be_search( op, rs );
311                                 if ( rs->sr_err == LDAP_NO_SUCH_OBJECT ) {
312                                         gs.err = LDAP_SUCCESS;
313                                 }
314
315                         } else if (dnIsSuffix(&ndn, &op->o_bd->be_nsuffix[0])) {
316                                 rs->sr_err = op->o_bd->be_search( op, rs );
317                         }
318
319                         switch ( gs.err ) {
320
321                         /*
322                          * Add errors that should result in dropping
323                          * the search
324                          */
325                         case LDAP_SIZELIMIT_EXCEEDED:
326                         case LDAP_TIMELIMIT_EXCEEDED:
327                         case LDAP_ADMINLIMIT_EXCEEDED:
328                         case LDAP_NO_SUCH_OBJECT:
329                                 goto end_of_loop;
330                         
331                         default:
332                                 break;
333                         }
334                 }
335 end_of_loop:;
336                 op->ors_scope = scope0;
337                 op->ors_slimit = slimit0;
338                 op->ors_tlimit = tlimit0;
339                 op->o_req_dn = dn;
340                 op->o_req_ndn = ndn;
341
342                 break;
343         }
344         if ( !op->o_abandon ) {
345                 op->o_callback = cb.sc_next;
346                 rs->sr_err = gs.err;
347                 rs->sr_matched = gs.matched;
348                 rs->sr_ref = gs.refs;
349
350                 send_ldap_result( op, rs );
351         }
352
353         op->o_bd = b0;
354         op->o_bd->bd_info = bi0;
355         if (gs.matched)
356                 free (gs.matched);
357         if (gs.refs)
358                 ber_bvarray_free(gs.refs);
359         return rs->sr_err;
360 }
361
362 static BackendDB toolDB;
363
364 static int
365 glue_tool_entry_open (
366         BackendDB *b0,
367         int mode
368 )
369 {
370         slap_overinfo   *oi = (slap_overinfo *)b0->bd_info;
371
372         /* We don't know which backend to talk to yet, so just
373          * remember the mode and move on...
374          */
375
376         glueMode = mode;
377         glueBack = NULL;
378         toolDB = *b0;
379         toolDB.bd_info = oi->oi_orig;
380
381         return 0;
382 }
383
384 static int
385 glue_tool_entry_close (
386         BackendDB *b0
387 )
388 {
389         int rc = 0;
390
391         if (glueBack) {
392                 if (!glueBack->be_entry_close)
393                         return 0;
394                 rc = glueBack->be_entry_close (glueBack);
395         }
396         return rc;
397 }
398
399 static slap_overinst *
400 glue_tool_inst(
401         BackendInfo *bi
402 )
403 {
404         slap_overinfo   *oi = (slap_overinfo *)bi;
405         slap_overinst   *on;
406
407         for ( on = oi->oi_list; on; on=on->on_next ) {
408                 if ( !strcmp( on->on_bi.bi_type, glue.on_bi.bi_type ))
409                         return on;
410         }
411         return NULL;
412 }
413
414 /* This function will only be called in tool mode */
415 static int
416 glue_open (
417         BackendInfo *bi
418 )
419 {
420         slap_overinst *on = glue_tool_inst( bi );
421         glueinfo                *gi = on->on_bi.bi_private;
422         static int glueOpened = 0;
423         int i, rc = 0;
424
425         if (glueOpened) return 0;
426
427         glueOpened = 1;
428
429         /* If we were invoked in tool mode, open all the underlying backends */
430         if (slapMode & SLAP_TOOL_MODE) {
431                 rc = backend_startup( NULL );
432         } /* other case is impossible */
433         return rc;
434 }
435
436 /* This function will only be called in tool mode */
437 static int
438 glue_close (
439         BackendInfo *bi
440 )
441 {
442         slap_overinst *on = glue_tool_inst( bi );
443         glueinfo                *gi = on->on_bi.bi_private;
444         static int glueClosed = 0;
445         int i, rc = 0;
446
447         if (glueClosed) return 0;
448
449         glueClosed = 1;
450
451         if (slapMode & SLAP_TOOL_MODE) {
452                 rc = backend_shutdown( NULL );
453         }
454         return rc;
455 }
456
457 static int
458 glue_entry_release_rw (
459         Operation *op,
460         Entry *e,
461         int rw
462 )
463 {
464         BackendDB *b0, b2;
465         int rc;
466
467         b0 = op->o_bd;
468         b2 = *op->o_bd;
469         b2.bd_info = (BackendInfo *)glue_tool_inst( op->o_bd->bd_info );
470         op->o_bd = glue_back_select (&b2, &e->e_nname);
471
472         rc = op->o_bd->be_release( op, e, rw );
473         op->o_bd = b0;
474         return rc;
475 }
476
477 static ID
478 glue_tool_entry_first (
479         BackendDB *b0
480 )
481 {
482         slap_overinst   *on = glue_tool_inst( b0->bd_info );
483         glueinfo                *gi = on->on_bi.bi_private;
484         int i;
485
486         /* If we're starting from scratch, start at the most general */
487         if (!glueBack) {
488                 if ( toolDB.be_entry_open && toolDB.be_entry_first ) {
489                         glueBack = &toolDB;
490                 } else {
491                         for (i = gi->gi_nodes-1; i >= 0; i--) {
492                                 if (gi->gi_n[i].gn_be->be_entry_open &&
493                                         gi->gi_n[i].gn_be->be_entry_first) {
494                                                 glueBack = gi->gi_n[i].gn_be;
495                                         break;
496                                 }
497                         }
498                 }
499         }
500         if (!glueBack || !glueBack->be_entry_open || !glueBack->be_entry_first ||
501                 glueBack->be_entry_open (glueBack, glueMode) != 0)
502                 return NOID;
503
504         return glueBack->be_entry_first (glueBack);
505 }
506
507 static ID
508 glue_tool_entry_next (
509         BackendDB *b0
510 )
511 {
512         slap_overinst   *on = glue_tool_inst( b0->bd_info );
513         glueinfo                *gi = on->on_bi.bi_private;
514         int i;
515         ID rc;
516
517         if (!glueBack || !glueBack->be_entry_next)
518                 return NOID;
519
520         rc = glueBack->be_entry_next (glueBack);
521
522         /* If we ran out of entries in one database, move on to the next */
523         while (rc == NOID) {
524                 if ( glueBack && glueBack->be_entry_close )
525                         glueBack->be_entry_close (glueBack);
526                 for (i=0; i<gi->gi_nodes; i++) {
527                         if (gi->gi_n[i].gn_be == glueBack)
528                                 break;
529                 }
530                 if (i == 0) {
531                         glueBack = NULL;
532                         break;
533                 } else {
534                         glueBack = gi->gi_n[i-1].gn_be;
535                         rc = glue_tool_entry_first (b0);
536                 }
537         }
538         return rc;
539 }
540
541 static Entry *
542 glue_tool_entry_get (
543         BackendDB *b0,
544         ID id
545 )
546 {
547         if (!glueBack || !glueBack->be_entry_get)
548                 return NULL;
549
550         return glueBack->be_entry_get (glueBack, id);
551 }
552
553 static ID
554 glue_tool_entry_put (
555         BackendDB *b0,
556         Entry *e,
557         struct berval *text
558 )
559 {
560         BackendDB *be, b2;
561         int rc;
562
563         b2 = *b0;
564         b2.bd_info = (BackendInfo *)glue_tool_inst( b0->bd_info );
565         be = glue_back_select (&b2, &e->e_nname);
566         if ( be == &b2 ) be = &toolDB;
567
568         if (!be->be_entry_put)
569                 return NOID;
570
571         if (!glueBack) {
572                 rc = be->be_entry_open (be, glueMode);
573                 if (rc != 0)
574                         return NOID;
575         } else if (be != glueBack) {
576                 /* If this entry belongs in a different branch than the
577                  * previous one, close the current database and open the
578                  * new one.
579                  */
580                 glueBack->be_entry_close (glueBack);
581                 rc = be->be_entry_open (be, glueMode);
582                 if (rc != 0)
583                         return NOID;
584         }
585         glueBack = be;
586         return be->be_entry_put (be, e, text);
587 }
588
589 static int
590 glue_tool_entry_reindex (
591         BackendDB *b0,
592         ID id
593 )
594 {
595         if (!glueBack || !glueBack->be_entry_reindex)
596                 return -1;
597
598         return glueBack->be_entry_reindex (glueBack, id);
599 }
600
601 static int
602 glue_tool_sync (
603         BackendDB *b0
604 )
605 {
606         slap_overinst   *on = glue_tool_inst( b0->bd_info );
607         glueinfo                *gi = on->on_bi.bi_private;
608         BackendInfo             *bi = b0->bd_info;
609         int i;
610
611         /* just sync everyone */
612         for (i = 0; i<gi->gi_nodes; i++)
613                 if (gi->gi_n[i].gn_be->be_sync)
614                         gi->gi_n[i].gn_be->be_sync (gi->gi_n[i].gn_be);
615         b0->bd_info = on->on_info->oi_orig;
616         if ( b0->be_sync )
617                 b0->be_sync( b0 );
618         b0->bd_info = bi;
619         return 0;
620 }
621
622 static int
623 glue_db_init(
624         BackendDB *be
625 )
626 {
627         slap_overinst   *on = (slap_overinst *)be->bd_info;
628         slap_overinfo   *oi = on->on_info;
629         glueinfo *gi;
630
631         gi = ch_calloc( 1, sizeof(glueinfo));
632         on->on_bi.bi_private = gi;
633         dnParent( be->be_nsuffix, &gi->gi_pdn );
634
635         /* Currently the overlay framework doesn't handle these entry points
636          * but we need them....
637          */
638         oi->oi_bi.bi_open = glue_open;
639         oi->oi_bi.bi_close = glue_close;
640
641         oi->oi_bi.bi_entry_release_rw = glue_entry_release_rw;
642
643         oi->oi_bi.bi_tool_entry_open = glue_tool_entry_open;
644         oi->oi_bi.bi_tool_entry_close = glue_tool_entry_close;
645         oi->oi_bi.bi_tool_entry_first = glue_tool_entry_first;
646         oi->oi_bi.bi_tool_entry_next = glue_tool_entry_next;
647         oi->oi_bi.bi_tool_entry_get = glue_tool_entry_get;
648         oi->oi_bi.bi_tool_entry_put = glue_tool_entry_put;
649         oi->oi_bi.bi_tool_entry_reindex = glue_tool_entry_reindex;
650         oi->oi_bi.bi_tool_sync = glue_tool_sync;
651
652         /*FIXME : need to add support */
653         oi->oi_bi.bi_tool_dn2id_get = 0;
654         oi->oi_bi.bi_tool_id2entry_get = 0;
655         oi->oi_bi.bi_tool_entry_modify = 0;
656
657         return 0;
658 }
659
660 static int
661 glue_db_destroy (
662         BackendDB *be
663 )
664 {
665         slap_overinst   *on = (slap_overinst *)be->bd_info;
666         glueinfo                *gi = (glueinfo *)on->on_bi.bi_private;
667
668         free (gi);
669         return SLAP_CB_CONTINUE;
670 }
671
672 static int
673 glue_db_open (
674         BackendDB *be
675 )
676 {
677         slap_overinst   *on = (slap_overinst *)be->bd_info;
678         glueinfo                *gi = (glueinfo *)on->on_bi.bi_private;
679         int i;
680
681         for ( i=0; i<gi->gi_nodes; i++ ) {
682                 gi->gi_n[i].gn_be = backendDB + gi->gi_n[i].gn_bx;
683         }
684         return 0;
685 }
686
687 static int
688 glue_db_close( 
689         BackendDB *be
690 )
691 {
692         slap_overinst   *on = (slap_overinst *)be->bd_info;
693
694         on->on_info->oi_bi.bi_db_close = NULL;
695         return 0;
696 }
697
698 static int
699 glue_db_config(
700         BackendDB       *be,
701         const char      *fname,
702         int             lineno,
703         int             argc,
704         char    **argv
705 )
706 {
707         slap_overinst   *on = (slap_overinst *)be->bd_info;
708         glueinfo                *gi = (glueinfo *)on->on_bi.bi_private;
709
710         if ( strcasecmp( argv[0], "glue-sub" ) == 0 ) {
711                 int async = 0;
712                 BackendDB *b2;
713                 struct berval bv, dn;
714                 gluenode *gn;
715
716                 if ( argc < 2 ) {
717                         fprintf( stderr, "%s: line %d: too few arguments in "
718                                 "\"glue-sub <suffixDN> [async]\"\n", fname, lineno );
719                         return -1;
720                 }
721                 if ( argc == 3 ) {
722                         if ( strcasecmp( argv[2], "async" )) {
723                                 fprintf( stderr, "%s: line %d: unrecognized option "
724                                         "\"%s\" ignored.\n", fname, lineno, argv[2] );
725                         } else {
726                                 async = 1;
727                         }
728                 }
729                 ber_str2bv( argv[1], 0, 0, &bv );
730                 if ( dnNormalize( 0, NULL, NULL, &bv, &dn, NULL )) {
731                         fprintf( stderr, "invalid suffixDN \"%s\"\n", argv[1] );
732                         return -1;
733                 }
734                 b2 = select_backend( &dn, 0, 1 );
735                 if ( !b2 ) {
736                         fprintf( stderr, "%s: line %d: unknown suffix \"%s\"\n",
737                                 fname, lineno, argv[1] );
738                         return -1;
739                 }
740                 SLAP_DBFLAGS(b2) |= SLAP_DBFLAG_GLUE_SUBORDINATE;
741                 gi = (glueinfo *)ch_realloc( gi, sizeof(glueinfo) +
742                         gi->gi_nodes * sizeof(gluenode));
743                 gi->gi_n[gi->gi_nodes].gn_bx = b2 - backendDB;
744                 dnParent( &b2->be_nsuffix[0], &gi->gi_n[gi->gi_nodes].gn_pdn );
745                 gi->gi_n[gi->gi_nodes].gn_async = async;
746                 gi->gi_nodes++;
747                 on->on_bi.bi_private = gi;
748                 return 0;
749         }
750         return SLAP_CONF_UNKNOWN;
751 }
752
753 int
754 glue_init()
755 {
756         glue.on_bi.bi_type = "glue";
757
758         glue.on_bi.bi_db_init = glue_db_init;
759         glue.on_bi.bi_db_config = glue_db_config;
760         glue.on_bi.bi_db_open = glue_db_open;
761         glue.on_bi.bi_db_close = glue_db_close;
762         glue.on_bi.bi_db_destroy = glue_db_destroy;
763
764         glue.on_bi.bi_op_search = glue_op_search;
765         glue.on_bi.bi_op_modify = glue_op_func;
766         glue.on_bi.bi_op_modrdn = glue_op_func;
767         glue.on_bi.bi_op_add = glue_op_func;
768         glue.on_bi.bi_op_delete = glue_op_func;
769
770         return overlay_register( &glue );
771 }
772
773 #if SLAPD_OVER_GLUE == SLAPD_MOD_DYNAMIC
774 int
775 init_module( int argc, char *argv[] )
776 {
777         return glue_init();
778 }
779 #endif  /* SLAPD_OVER_GLUE == SLAPD_MOD_DYNAMIC */
780
781 #endif  /* defined(SLAPD_OVER_GLUE */