]> git.sur5r.net Git - openldap/blob - servers/slapd/backover.c
5ac9d95f6d0501f55d1e3fe278246566becffdd4
[openldap] / servers / slapd / backover.c
1 /* backover.c - backend overlay routines */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 2003-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 /* Functions to overlay other modules over a backend. */
18
19 #include "portable.h"
20
21 #include <stdio.h>
22
23 #include <ac/string.h>
24 #include <ac/socket.h>
25
26 #define SLAPD_TOOLS
27 #include "slap.h"
28 #include "config.h"
29
30 static slap_overinst *overlays;
31
32 enum db_which {
33         db_open = 0,
34         db_close,
35         db_destroy,
36         db_last
37 };
38
39 static int
40 over_db_func(
41         BackendDB *be,
42         enum db_which which
43 )
44 {
45         slap_overinfo *oi = be->bd_info->bi_private;
46         slap_overinst *on = oi->oi_list;
47         BackendInfo *bi_orig = be->bd_info;
48         BI_db_open **func;
49         int rc = 0;
50
51         func = &oi->oi_orig->bi_db_open;
52         if ( func[which] ) {
53                 be->bd_info = oi->oi_orig;
54                 rc = func[which]( be );
55         }
56
57         for (; on && rc == 0; on=on->on_next) {
58                 be->bd_info = &on->on_bi;
59                 func = &on->on_bi.bi_db_open;
60                 if (func[which]) {
61                         rc = func[which]( be );
62                 }
63         }
64         be->bd_info = bi_orig;
65         return rc;
66 }
67
68 static int
69 over_db_config(
70         BackendDB *be,
71         const char *fname,
72         int lineno,
73         int argc,
74         char **argv
75 )
76 {
77         slap_overinfo *oi = be->bd_info->bi_private;
78         slap_overinst *on = oi->oi_list;
79         BackendInfo *bi_orig = be->bd_info;
80         struct ConfigOCs *be_cf_ocs = be->be_cf_ocs;
81         ConfigArgs ca = {0};
82         int rc = 0;
83
84         if ( oi->oi_orig->bi_db_config ) {
85                 be->bd_info = oi->oi_orig;
86                 be->be_cf_ocs = oi->oi_orig->bi_cf_ocs;
87                 rc = oi->oi_orig->bi_db_config( be, fname, lineno,
88                         argc, argv );
89
90                 if ( be->bd_info != oi->oi_orig ) {
91                         slap_overinfo   *oi2;
92                         slap_overinst   *on2, **onp;
93                         BackendDB       be2 = *be;
94                         int             i;
95
96                         /* a database added an overlay;
97                          * work it around... */
98                         assert( overlay_is_over( be ) );
99                         
100                         oi2 = ( slap_overinfo * )be->bd_info->bi_private;
101                         on2 = oi2->oi_list;
102
103                         /* need to put a uniqueness check here as well;
104                          * note that in principle there could be more than
105                          * one overlay as a result of multiple calls to
106                          * overlay_config() */
107                         be2.bd_info = (BackendInfo *)oi;
108
109                         for ( i = 0, onp = &on2; *onp; i++, onp = &(*onp)->on_next ) {
110                                 if ( overlay_is_inst( &be2, (*onp)->on_bi.bi_type ) ) {
111                                         Debug( LDAP_DEBUG_ANY, "over_db_config(): "
112                                                         "warning, freshly added "
113                                                         "overlay #%d \"%s\" is already in list\n",
114                                                         i, (*onp)->on_bi.bi_type, 0 );
115
116                                         /* NOTE: if the overlay already exists,
117                                          * there is no way to merge the results
118                                          * of the configuration that may have 
119                                          * occurred during bi_db_config(); we
120                                          * just issue a warning, and the 
121                                          * administrator should deal with this */
122                                 }
123                         }
124                         *onp = oi->oi_list;
125
126                         oi->oi_list = on2;
127
128                         ch_free( be->bd_info );
129                 }
130
131                 be->bd_info = (BackendInfo *)oi;
132                 if ( rc != SLAP_CONF_UNKNOWN ) return rc;
133         }
134
135         ca.argv = argv;
136         ca.argc = argc;
137         ca.fname = fname;
138         ca.lineno = lineno;
139         ca.be = be;
140         for (; on; on=on->on_next) {
141                 rc = SLAP_CONF_UNKNOWN;
142                 if (on->on_bi.bi_cf_ocs) {
143                         ConfigTable *ct;
144                         ca.bi = &on->on_bi;
145                         ct = config_find_keyword( on->on_bi.bi_cf_ocs->co_table, &ca );
146                         if ( ct ) {
147                                 rc = config_add_vals( ct, &ca );
148                         }
149                 }
150                 if (on->on_bi.bi_db_config && rc == SLAP_CONF_UNKNOWN) {
151                         be->bd_info = &on->on_bi;
152                         rc = on->on_bi.bi_db_config( be, fname, lineno,
153                                 argc, argv );
154                         if ( rc != SLAP_CONF_UNKNOWN ) break;
155                 }
156         }
157         be->bd_info = bi_orig;
158         be->be_cf_ocs = be_cf_ocs;
159         
160         return rc;
161 }
162
163 static int
164 over_db_open(
165         BackendDB *be
166 )
167 {
168         return over_db_func( be, db_open );
169 }
170
171 static int
172 over_db_close(
173         BackendDB *be
174 )
175 {
176         slap_overinfo *oi = be->bd_info->bi_private;
177         slap_overinst *on = oi->oi_list;
178         BackendInfo *bi_orig = be->bd_info;
179         int rc = 0;
180
181         for (; on && rc == 0; on=on->on_next) {
182                 be->bd_info = &on->on_bi;
183                 if ( be->bd_info->bi_db_close ) {
184                         rc = be->bd_info->bi_db_close( be );
185                 }
186         }
187
188         if ( oi->oi_orig->bi_db_close ) {
189                 be->bd_info = oi->oi_orig;
190                 rc = be->bd_info->bi_db_close( be );
191         }
192
193         be->bd_info = bi_orig;
194         return rc;
195 }
196
197 static int
198 over_db_destroy(
199         BackendDB *be
200 )
201 {
202         slap_overinfo *oi = be->bd_info->bi_private;
203         slap_overinst *on = oi->oi_list, *next;
204         int rc;
205
206         rc = over_db_func( be, db_destroy );
207
208         for (next = on->on_next; on; on=next) {
209                 next = on->on_next;
210                 free( on );
211         }
212         free( oi );
213         return rc;
214 }
215
216 static int
217 over_back_response ( Operation *op, SlapReply *rs )
218 {
219         slap_overinfo *oi = op->o_callback->sc_private;
220         slap_overinst *on = oi->oi_list;
221         int rc = SLAP_CB_CONTINUE;
222         BackendDB *be = op->o_bd, db = *op->o_bd;
223
224         db.be_flags |= SLAP_DBFLAG_OVERLAY;
225         op->o_bd = &db;
226         for (; on; on=on->on_next ) {
227                 if ( on->on_response ) {
228                         db.bd_info = (BackendInfo *)on;
229                         rc = on->on_response( op, rs );
230                         if ( rc != SLAP_CB_CONTINUE ) break;
231                 }
232         }
233         op->o_bd = be;
234         return rc;
235 }
236
237 #ifdef SLAP_OVERLAY_ACCESS
238 static int
239 over_access_allowed(
240         Operation               *op,
241         Entry                   *e,
242         AttributeDescription    *desc,
243         struct berval           *val,
244         slap_access_t           access,
245         AccessControlState      *state,
246         slap_mask_t             *maskp )
247 {
248         slap_overinfo *oi;
249         slap_overinst *on;
250         BackendInfo *bi = op->o_bd->bd_info;
251         BackendDB *be = op->o_bd, db;
252         int rc = SLAP_CB_CONTINUE;
253
254         /* FIXME: used to happen for instance during abandon
255          * when global overlays are used... */
256         assert( op->o_bd != NULL );
257
258         oi = op->o_bd->bd_info->bi_private;
259         on = oi->oi_list;
260
261         for ( ; on; on = on->on_next ) {
262                 if ( on->on_bi.bi_access_allowed ) {
263                         /* NOTE: do not copy the structure until required */
264                         if ( !SLAP_ISOVERLAY( op->o_bd ) ) {
265                                 db = *op->o_bd;
266                                 db.be_flags |= SLAP_DBFLAG_OVERLAY;
267                                 op->o_bd = &db;
268                         }
269
270                         op->o_bd->bd_info = (BackendInfo *)on;
271                         rc = on->on_bi.bi_access_allowed( op, e,
272                                 desc, val, access, state, maskp );
273                         if ( rc != SLAP_CB_CONTINUE ) break;
274                 }
275         }
276
277         if ( rc == SLAP_CB_CONTINUE ) {
278                 BI_access_allowed       *bi_access_allowed;
279
280                 /* if the database structure was changed, o_bd points to a
281                  * copy of the structure; put the original bd_info in place */
282                 if ( SLAP_ISOVERLAY( op->o_bd ) ) {
283                         op->o_bd->bd_info = oi->oi_orig;
284                 }
285
286                 if ( oi->oi_orig->bi_access_allowed ) {
287                         bi_access_allowed = oi->oi_orig->bi_access_allowed;
288                 } else {
289                         bi_access_allowed = slap_access_allowed;
290                 }
291
292                 rc = bi_access_allowed( op, e,
293                         desc, val, access, state, maskp );
294         }
295         /* should not fall thru this far without anything happening... */
296         if ( rc == SLAP_CB_CONTINUE ) {
297                 /* access not allowed */
298                 rc = 0;
299         }
300
301         op->o_bd = be;
302         op->o_bd->bd_info = bi;
303
304         return rc;
305 }
306 #endif /* SLAP_OVERLAY_ACCESS */
307
308 /*
309  * default return code in case of missing backend function
310  * and overlay stack returning SLAP_CB_CONTINUE
311  */
312 static int op_rc[ op_last ] = {
313         LDAP_UNWILLING_TO_PERFORM,      /* bind */
314         LDAP_UNWILLING_TO_PERFORM,      /* unbind */
315         LDAP_UNWILLING_TO_PERFORM,      /* search */
316         SLAP_CB_CONTINUE,               /* compare; pass to frontend */
317         LDAP_UNWILLING_TO_PERFORM,      /* modify */
318         LDAP_UNWILLING_TO_PERFORM,      /* modrdn */
319         LDAP_UNWILLING_TO_PERFORM,      /* add */
320         LDAP_UNWILLING_TO_PERFORM,      /* delete */
321         LDAP_UNWILLING_TO_PERFORM,      /* abandon */
322         LDAP_UNWILLING_TO_PERFORM,      /* cancel */
323         LDAP_UNWILLING_TO_PERFORM,      /* extended */
324         LDAP_SUCCESS,                   /* aux_operational */
325         LDAP_SUCCESS,                   /* aux_chk_referrals */
326         SLAP_CB_CONTINUE                /* aux_chk_controls; pass to frontend */
327 };
328
329 int overlay_op_walk(
330         Operation *op,
331         SlapReply *rs,
332         slap_operation_t which,
333         slap_overinfo *oi,
334         slap_overinst *on
335 )
336 {
337         BI_op_bind **func;
338         int rc = SLAP_CB_CONTINUE;
339
340         for (; on; on=on->on_next ) {
341                 func = &on->on_bi.bi_op_bind;
342                 if ( func[which] ) {
343                         op->o_bd->bd_info = (BackendInfo *)on;
344                         rc = func[which]( op, rs );
345                         if ( rc != SLAP_CB_CONTINUE ) break;
346                 }
347         }
348
349         func = &oi->oi_orig->bi_op_bind;
350         if ( func[which] && rc == SLAP_CB_CONTINUE ) {
351                 op->o_bd->bd_info = oi->oi_orig;
352                 rc = func[which]( op, rs );
353         }
354         /* should not fall thru this far without anything happening... */
355         if ( rc == SLAP_CB_CONTINUE ) {
356                 rc = op_rc[ which ];
357         }
358
359         /* The underlying backend didn't handle the request, make sure
360          * overlay cleanup is processed.
361          */
362         if ( rc == LDAP_UNWILLING_TO_PERFORM ) {
363                 slap_callback *sc_next;
364                 for ( ; op->o_callback && op->o_callback->sc_response !=
365                         over_back_response; op->o_callback = sc_next ) {
366                         sc_next = op->o_callback->sc_next;
367                         if ( op->o_callback->sc_cleanup ) {
368                                 op->o_callback->sc_cleanup( op, rs );
369                         }
370                 }
371         }
372         return rc;
373 }
374
375 static int
376 over_op_func(
377         Operation *op,
378         SlapReply *rs,
379         slap_operation_t which
380 )
381 {
382         slap_overinfo *oi;
383         slap_overinst *on;
384         BI_op_bind **func;
385         BackendDB *be = op->o_bd, db;
386         slap_callback cb = {NULL, over_back_response, NULL, NULL};
387         int rc = SLAP_CB_CONTINUE;
388
389         /* FIXME: used to happen for instance during abandon
390          * when global overlays are used... */
391         assert( op->o_bd != NULL );
392
393         oi = op->o_bd->bd_info->bi_private;
394         on = oi->oi_list;
395
396         if ( !SLAP_ISOVERLAY( op->o_bd )) {
397                 db = *op->o_bd;
398                 db.be_flags |= SLAP_DBFLAG_OVERLAY;
399                 op->o_bd = &db;
400         }
401         cb.sc_next = op->o_callback;
402         cb.sc_private = oi;
403         op->o_callback = &cb;
404
405         rc = overlay_op_walk( op, rs, which, oi, on );
406
407         op->o_bd = be;
408         op->o_callback = cb.sc_next;
409         return rc;
410 }
411
412 static int
413 over_op_bind( Operation *op, SlapReply *rs )
414 {
415         return over_op_func( op, rs, op_bind );
416 }
417
418 static int
419 over_op_unbind( Operation *op, SlapReply *rs )
420 {
421         return over_op_func( op, rs, op_unbind );
422 }
423
424 static int
425 over_op_search( Operation *op, SlapReply *rs )
426 {
427         return over_op_func( op, rs, op_search );
428 }
429
430 static int
431 over_op_compare( Operation *op, SlapReply *rs )
432 {
433         return over_op_func( op, rs, op_compare );
434 }
435
436 static int
437 over_op_modify( Operation *op, SlapReply *rs )
438 {
439         return over_op_func( op, rs, op_modify );
440 }
441
442 static int
443 over_op_modrdn( Operation *op, SlapReply *rs )
444 {
445         return over_op_func( op, rs, op_modrdn );
446 }
447
448 static int
449 over_op_add( Operation *op, SlapReply *rs )
450 {
451         return over_op_func( op, rs, op_add );
452 }
453
454 static int
455 over_op_delete( Operation *op, SlapReply *rs )
456 {
457         return over_op_func( op, rs, op_delete );
458 }
459
460 static int
461 over_op_abandon( Operation *op, SlapReply *rs )
462 {
463         return over_op_func( op, rs, op_abandon );
464 }
465
466 static int
467 over_op_cancel( Operation *op, SlapReply *rs )
468 {
469         return over_op_func( op, rs, op_cancel );
470 }
471
472 static int
473 over_op_extended( Operation *op, SlapReply *rs )
474 {
475         return over_op_func( op, rs, op_extended );
476 }
477
478 static int
479 over_aux_operational( Operation *op, SlapReply *rs )
480 {
481         return over_op_func( op, rs, op_aux_operational );
482 }
483
484 static int
485 over_aux_chk_referrals( Operation *op, SlapReply *rs )
486 {
487         return over_op_func( op, rs, op_aux_chk_referrals );
488 }
489
490 static int
491 over_aux_chk_controls( Operation *op, SlapReply *rs )
492 {
493         return over_op_func( op, rs, op_aux_chk_controls );
494 }
495
496 enum conn_which {
497         conn_init = 0,
498         conn_destroy,
499         conn_last
500 };
501
502 static int
503 over_connection_func(
504         BackendDB       *bd,
505         Connection      *conn,
506         enum conn_which which
507 )
508 {
509         slap_overinfo           *oi;
510         slap_overinst           *on;
511         BackendDB               db;
512         int                     rc = SLAP_CB_CONTINUE;
513         BI_connection_init      **func;
514
515         /* FIXME: used to happen for instance during abandon
516          * when global overlays are used... */
517         assert( bd != NULL );
518
519         oi = bd->bd_info->bi_private;
520         on = oi->oi_list;
521
522         if ( !SLAP_ISOVERLAY( bd ) ) {
523                 db = *bd;
524                 db.be_flags |= SLAP_DBFLAG_OVERLAY;
525                 bd = &db;
526         }
527
528         for ( ; on; on = on->on_next ) {
529                 func = &on->on_bi.bi_connection_init;
530                 if ( func[ which ] ) {
531                         bd->bd_info = (BackendInfo *)on;
532                         rc = func[ which ]( bd, conn );
533                         if ( rc != SLAP_CB_CONTINUE ) break;
534                 }
535         }
536
537         func = &oi->oi_orig->bi_connection_init;
538         if ( func[ which ] && rc == SLAP_CB_CONTINUE ) {
539                 bd->bd_info = oi->oi_orig;
540                 rc = func[ which ]( bd, conn );
541         }
542         /* should not fall thru this far without anything happening... */
543         if ( rc == SLAP_CB_CONTINUE ) {
544                 rc = LDAP_UNWILLING_TO_PERFORM;
545         }
546
547         return rc;
548 }
549
550 static int
551 over_connection_init(
552         BackendDB       *bd,
553         Connection      *conn
554 )
555 {
556         return over_connection_func( bd, conn, conn_init );
557 }
558
559 static int
560 over_connection_destroy(
561         BackendDB       *bd,
562         Connection      *conn
563 )
564 {
565         return over_connection_func( bd, conn, conn_destroy );
566 }
567
568 int
569 overlay_register(
570         slap_overinst *on
571 )
572 {
573         on->on_next = overlays;
574         overlays = on;
575         return 0;
576 }
577
578 /*
579  * iterator on registered overlays; overlay_next( NULL ) returns the first
580  * overlay; * subsequent calls with the previously returned value allow to 
581  * iterate * over the entire list; returns NULL when no more overlays are 
582  * registered.
583  */
584
585 slap_overinst *
586 overlay_next(
587         slap_overinst *on
588 )
589 {
590         if ( on == NULL ) {
591                 return overlays;
592         }
593
594         return on->on_next;
595 }
596
597 /*
598  * returns a specific registered overlay based on the type; NULL if not
599  * registered.
600  */
601
602 slap_overinst *
603 overlay_find( const char *over_type )
604 {
605         slap_overinst *on = overlays;
606
607         assert( over_type != NULL );
608
609         for ( ; on; on = on->on_next ) {
610                 if ( strcmp( on->on_bi.bi_type, over_type ) == 0 ) {
611                         break;
612                 }
613         }
614
615         return on;
616 }
617
618 static const char overtype[] = "over";
619
620 /*
621  * returns TRUE (1) if the database is actually an overlay instance;
622  * FALSE (0) otherwise.
623  */
624
625 int
626 overlay_is_over( BackendDB *be )
627 {
628         return be->bd_info->bi_type == overtype;
629 }
630
631 /*
632  * returns TRUE (1) if the given database is actually an overlay
633  * instance and, somewhere in the list, contains the requested overlay;
634  * FALSE (0) otherwise.
635  */
636
637 int
638 overlay_is_inst( BackendDB *be, const char *over_type )
639 {
640         slap_overinst   *on;
641
642         assert( be != NULL );
643
644         if ( !overlay_is_over( be ) ) {
645                 return 0;
646         }
647         
648         on = ((slap_overinfo *)be->bd_info->bi_private)->oi_list;
649         for ( ; on; on = on->on_next ) {
650                 if ( strcmp( on->on_bi.bi_type, over_type ) == 0 ) {
651                         return 1;
652                 }
653         }
654
655         return 0;
656 }
657
658 int
659 overlay_register_control( BackendDB *be, const char *oid )
660 {
661         int             rc = 0;
662         int             gotit = 0;
663         int             cid;
664
665         if ( slap_find_control_id( oid, &cid ) == LDAP_CONTROL_NOT_FOUND ) {
666                 return -1;
667         }
668
669         if ( SLAP_DBFLAGS( be ) & SLAP_DBFLAG_GLOBAL_OVERLAY ) {
670                 BackendDB *bd;
671                 
672                 /* add to all backends... */
673                 LDAP_STAILQ_FOREACH( bd, &backendDB, be_next ) {
674                         if ( be == bd ) {
675                                 gotit = 1;
676                         }
677
678                         bd->be_ctrls[ cid ] = 1;
679                         bd->be_ctrls[ SLAP_MAX_CIDS ] = 1;
680                 }
681
682         }
683         
684         if ( rc == 0 && !gotit ) {
685                 be->be_ctrls[ cid ] = 1;
686                 be->be_ctrls[ SLAP_MAX_CIDS ] = 1;
687         }
688
689         return rc;
690 }
691
692 void
693 overlay_destroy_one( BackendDB *be, slap_overinst *on )
694 {
695         slap_overinfo *oi = on->on_info;
696         slap_overinst **oidx;
697
698         for ( oidx = &oi->oi_list; *oidx; oidx = &(*oidx)->on_next ) {
699                 if ( *oidx == on ) {
700                         *oidx = on->on_next;
701                         if ( on->on_bi.bi_db_destroy ) {
702                                 BackendInfo *bi_orig = be->bd_info;
703                                 be->bd_info = (BackendInfo *)on;
704                                 on->on_bi.bi_db_destroy( be );
705                                 be->bd_info = bi_orig;
706                         }
707                         free( on );
708                         break;
709                 }
710         }
711 }
712
713 /* add an overlay to a particular backend. */
714 int
715 overlay_config( BackendDB *be, const char *ov )
716 {
717         slap_overinst *on = NULL, *on2 = NULL;
718         slap_overinfo *oi = NULL;
719         BackendInfo *bi = NULL;
720
721         on = overlay_find( ov );
722         if ( !on ) {
723                 Debug( LDAP_DEBUG_ANY, "overlay \"%s\" not found\n", ov, 0, 0 );
724                 return 1;
725         }
726
727         /* If this is the first overlay on this backend, set up the
728          * overlay info structure
729          */
730         if ( !overlay_is_over( be ) ) {
731                 oi = ch_malloc( sizeof( slap_overinfo ) );
732                 oi->oi_orig = be->bd_info;
733                 oi->oi_bi = *be->bd_info;
734
735                 /* NOTE: the first time a global overlay is configured,
736                  * frontendDB gets this flag; it is used later by overlays
737                  * to determine if they're stacked on top of the frontendDB */
738                 if ( oi->oi_orig == frontendDB->bd_info ) {
739                         SLAP_DBFLAGS( be ) |= SLAP_DBFLAG_GLOBAL_OVERLAY;
740                 }
741
742                 /* Save a pointer to ourself in bi_private.
743                  */
744                 oi->oi_bi.bi_private = oi;
745                 oi->oi_list = NULL;
746                 bi = (BackendInfo *)oi;
747
748                 bi->bi_type = (char *)overtype;
749
750                 bi->bi_db_config = over_db_config;
751                 bi->bi_db_open = over_db_open;
752                 bi->bi_db_close = over_db_close;
753                 bi->bi_db_destroy = over_db_destroy;
754
755                 bi->bi_op_bind = over_op_bind;
756                 bi->bi_op_unbind = over_op_unbind;
757                 bi->bi_op_search = over_op_search;
758                 bi->bi_op_compare = over_op_compare;
759                 bi->bi_op_modify = over_op_modify;
760                 bi->bi_op_modrdn = over_op_modrdn;
761                 bi->bi_op_add = over_op_add;
762                 bi->bi_op_delete = over_op_delete;
763                 bi->bi_op_abandon = over_op_abandon;
764                 bi->bi_op_cancel = over_op_cancel;
765
766                 bi->bi_extended = over_op_extended;
767
768                 /*
769                  * this is fine because it has the same
770                  * args of the operations; we need to rework
771                  * all the hooks to share the same args
772                  * of the operations...
773                  */
774                 bi->bi_operational = over_aux_operational;
775                 bi->bi_chk_referrals = over_aux_chk_referrals;
776                 bi->bi_chk_controls = over_aux_chk_controls;
777
778 #ifdef SLAP_OVERLAY_ACCESS
779                 /* this has a specific arglist */
780                 bi->bi_access_allowed = over_access_allowed;
781 #endif /* SLAP_OVERLAY_ACCESS */
782                 
783                 bi->bi_connection_init = over_connection_init;
784                 bi->bi_connection_destroy = over_connection_destroy;
785
786                 be->bd_info = bi;
787
788         } else {
789                 if ( overlay_is_inst( be, ov ) ) {
790                         Debug( LDAP_DEBUG_ANY, "overlay_config(): "
791                                         "warning, overlay \"%s\" "
792                                         "already in list\n", ov, 0, 0 );
793                 }
794
795                 oi = be->bd_info->bi_private;
796         }
797
798         /* Insert new overlay on head of list. Overlays are executed
799          * in reverse of config order...
800          */
801         on2 = ch_calloc( 1, sizeof(slap_overinst) );
802         *on2 = *on;
803         on2->on_info = oi;
804         on2->on_next = oi->oi_list;
805         oi->oi_list = on2;
806
807         /* Any initialization needed? */
808         if ( on->on_bi.bi_db_init ) {
809                 int rc;
810                 be->bd_info = (BackendInfo *)on2;
811                 rc = on2->on_bi.bi_db_init( be );
812                 be->bd_info = (BackendInfo *)oi;
813                 if ( rc ) return rc;
814         }
815
816         return 0;
817 }
818