1 /* backover.c - backend overlay routines */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2003-2009 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
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>.
17 /* Functions to overlay other modules over a backend. */
23 #include <ac/string.h>
24 #include <ac/socket.h>
30 static slap_overinst *overlays;
41 slap_overinfo *oi = be->bd_info->bi_private;
42 slap_overinst *on = oi->oi_list;
43 BackendInfo *bi_orig = be->bd_info;
44 struct ConfigOCs *be_cf_ocs = be->be_cf_ocs;
48 if ( oi->oi_orig->bi_db_config ) {
49 be->bd_info = oi->oi_orig;
50 be->be_cf_ocs = oi->oi_orig->bi_cf_ocs;
51 rc = oi->oi_orig->bi_db_config( be, fname, lineno,
54 if ( be->bd_info != oi->oi_orig ) {
56 slap_overinst *on2, **onp;
60 /* a database added an overlay;
61 * work it around... */
62 assert( overlay_is_over( be ) );
64 oi2 = ( slap_overinfo * )be->bd_info->bi_private;
67 /* need to put a uniqueness check here as well;
68 * note that in principle there could be more than
69 * one overlay as a result of multiple calls to
71 be2.bd_info = (BackendInfo *)oi;
73 for ( i = 0, onp = &on2; *onp; i++, onp = &(*onp)->on_next ) {
74 if ( overlay_is_inst( &be2, (*onp)->on_bi.bi_type ) ) {
75 Debug( LDAP_DEBUG_ANY, "over_db_config(): "
76 "warning, freshly added "
77 "overlay #%d \"%s\" is already in list\n",
78 i, (*onp)->on_bi.bi_type, 0 );
80 /* NOTE: if the overlay already exists,
81 * there is no way to merge the results
82 * of the configuration that may have
83 * occurred during bi_db_config(); we
84 * just issue a warning, and the
85 * administrator should deal with this */
92 ch_free( be->bd_info );
95 be->bd_info = (BackendInfo *)oi;
96 if ( rc != SLAP_CONF_UNKNOWN ) return rc;
104 snprintf( ca.log, sizeof( ca.log ), "%s: line %d",
105 ca.fname, ca.lineno );
106 ca.op = SLAP_CONFIG_ADD;
109 for (; on; on=on->on_next) {
110 rc = SLAP_CONF_UNKNOWN;
111 if (on->on_bi.bi_cf_ocs) {
114 ct = config_find_keyword( on->on_bi.bi_cf_ocs->co_table, &ca );
116 ca.table = on->on_bi.bi_cf_ocs->co_type;
117 rc = config_add_vals( ct, &ca );
118 if ( rc != SLAP_CONF_UNKNOWN )
122 if (on->on_bi.bi_db_config && rc == SLAP_CONF_UNKNOWN) {
123 be->bd_info = &on->on_bi;
124 rc = on->on_bi.bi_db_config( be, fname, lineno,
126 if ( rc != SLAP_CONF_UNKNOWN ) break;
129 be->bd_info = bi_orig;
130 be->be_cf_ocs = be_cf_ocs;
141 slap_overinfo *oi = be->bd_info->bi_private;
142 slap_overinst *on = oi->oi_list;
143 BackendInfo *bi_orig = be->bd_info;
146 be->be_flags |= SLAP_DBFLAG_OVERLAY;
147 be->bd_info = oi->oi_orig;
148 if ( be->bd_info->bi_db_open ) {
149 rc = be->bd_info->bi_db_open( be, cr );
152 for (; on && rc == 0; on=on->on_next) {
153 be->bd_info = &on->on_bi;
154 if ( be->bd_info->bi_db_open ) {
155 rc = be->bd_info->bi_db_open( be, cr );
159 be->bd_info = bi_orig;
160 be->be_flags ^= SLAP_DBFLAG_OVERLAY;
171 slap_overinfo *oi = be->bd_info->bi_private;
172 slap_overinst *on = oi->oi_list;
173 BackendInfo *bi_orig = be->bd_info;
176 for (; on && rc == 0; on=on->on_next) {
177 be->bd_info = &on->on_bi;
178 if ( be->bd_info->bi_db_close ) {
179 rc = be->bd_info->bi_db_close( be, cr );
183 if ( oi->oi_orig->bi_db_close ) {
184 be->bd_info = oi->oi_orig;
185 rc = be->bd_info->bi_db_close( be, cr );
188 be->bd_info = bi_orig;
198 slap_overinfo *oi = be->bd_info->bi_private;
199 slap_overinst *on = oi->oi_list, *next;
200 BackendInfo *bi_orig = be->bd_info;
203 be->bd_info = oi->oi_orig;
204 if ( be->bd_info->bi_db_destroy ) {
205 rc = be->bd_info->bi_db_destroy( be, cr );
208 for (; on && rc == 0; on=on->on_next) {
209 be->bd_info = &on->on_bi;
210 if ( be->bd_info->bi_db_destroy ) {
211 rc = be->bd_info->bi_db_destroy( be, cr );
217 for (next = on->on_next; on; on=next) {
222 be->bd_info = bi_orig;
228 over_back_response ( Operation *op, SlapReply *rs )
230 slap_overinfo *oi = op->o_callback->sc_private;
231 slap_overinst *on = oi->oi_list;
232 int rc = SLAP_CB_CONTINUE;
233 BackendDB *be = op->o_bd, db = *op->o_bd;
235 db.be_flags |= SLAP_DBFLAG_OVERLAY;
237 for (; on; on=on->on_next ) {
238 if ( on->on_response ) {
239 db.bd_info = (BackendInfo *)on;
240 rc = on->on_response( op, rs );
241 if ( rc != SLAP_CB_CONTINUE ) break;
244 /* Bypass the remaining on_response layers, but allow
245 * normal execution to continue.
247 if ( rc == SLAP_CB_BYPASS )
248 rc = SLAP_CB_CONTINUE;
257 AttributeDescription *desc,
259 slap_access_t access,
260 AccessControlState *state,
266 BackendDB *be = op->o_bd, db;
267 int rc = SLAP_CB_CONTINUE;
269 /* FIXME: used to happen for instance during abandon
270 * when global overlays are used... */
271 assert( op->o_bd != NULL );
273 bi = op->o_bd->bd_info;
274 /* Were we invoked on the frontend? */
275 if ( !bi->bi_access_allowed ) {
276 oi = frontendDB->bd_info->bi_private;
278 oi = op->o_bd->bd_info->bi_private;
282 for ( ; on; on = on->on_next ) {
283 if ( on->on_bi.bi_access_allowed ) {
284 /* NOTE: do not copy the structure until required */
285 if ( !SLAP_ISOVERLAY( op->o_bd ) ) {
287 db.be_flags |= SLAP_DBFLAG_OVERLAY;
291 op->o_bd->bd_info = (BackendInfo *)on;
292 rc = on->on_bi.bi_access_allowed( op, e,
293 desc, val, access, state, maskp );
294 if ( rc != SLAP_CB_CONTINUE ) break;
298 if ( rc == SLAP_CB_CONTINUE ) {
299 BI_access_allowed *bi_access_allowed;
301 /* if the database structure was changed, o_bd points to a
302 * copy of the structure; put the original bd_info in place */
303 if ( SLAP_ISOVERLAY( op->o_bd ) ) {
304 op->o_bd->bd_info = oi->oi_orig;
307 if ( oi->oi_orig->bi_access_allowed ) {
308 bi_access_allowed = oi->oi_orig->bi_access_allowed;
310 bi_access_allowed = slap_access_allowed;
313 rc = bi_access_allowed( op, e,
314 desc, val, access, state, maskp );
316 /* should not fall thru this far without anything happening... */
317 if ( rc == SLAP_CB_CONTINUE ) {
318 /* access not allowed */
323 op->o_bd->bd_info = bi;
329 overlay_entry_get_ov(
333 AttributeDescription *ad,
338 slap_overinfo *oi = on->on_info;
339 BackendDB *be = op->o_bd, db;
340 BackendInfo *bi = op->o_bd->bd_info;
341 int rc = SLAP_CB_CONTINUE;
343 for ( ; on; on = on->on_next ) {
344 if ( on->on_bi.bi_entry_get_rw ) {
345 /* NOTE: do not copy the structure until required */
346 if ( !SLAP_ISOVERLAY( op->o_bd ) ) {
348 db.be_flags |= SLAP_DBFLAG_OVERLAY;
352 op->o_bd->bd_info = (BackendInfo *)on;
353 rc = on->on_bi.bi_entry_get_rw( op, dn,
355 if ( rc != SLAP_CB_CONTINUE ) break;
359 if ( rc == SLAP_CB_CONTINUE ) {
360 /* if the database structure was changed, o_bd points to a
361 * copy of the structure; put the original bd_info in place */
362 if ( SLAP_ISOVERLAY( op->o_bd ) ) {
363 op->o_bd->bd_info = oi->oi_orig;
366 if ( oi->oi_orig->bi_entry_get_rw ) {
367 rc = oi->oi_orig->bi_entry_get_rw( op, dn,
371 /* should not fall thru this far without anything happening... */
372 if ( rc == SLAP_CB_CONTINUE ) {
373 rc = LDAP_UNWILLING_TO_PERFORM;
377 op->o_bd->bd_info = bi;
387 AttributeDescription *ad,
394 assert( op->o_bd != NULL );
396 oi = op->o_bd->bd_info->bi_private;
399 return overlay_entry_get_ov( op, dn, oc, ad, rw, e, on );
403 overlay_entry_release_ov(
409 slap_overinfo *oi = on->on_info;
410 BackendDB *be = op->o_bd, db;
411 BackendInfo *bi = op->o_bd->bd_info;
412 int rc = SLAP_CB_CONTINUE;
414 for ( ; on; on = on->on_next ) {
415 if ( on->on_bi.bi_entry_release_rw ) {
416 /* NOTE: do not copy the structure until required */
417 if ( !SLAP_ISOVERLAY( op->o_bd ) ) {
419 db.be_flags |= SLAP_DBFLAG_OVERLAY;
423 op->o_bd->bd_info = (BackendInfo *)on;
424 rc = on->on_bi.bi_entry_release_rw( op, e, rw );
425 if ( rc != SLAP_CB_CONTINUE ) break;
429 if ( rc == SLAP_CB_CONTINUE ) {
430 /* if the database structure was changed, o_bd points to a
431 * copy of the structure; put the original bd_info in place */
432 if ( SLAP_ISOVERLAY( op->o_bd ) ) {
433 op->o_bd->bd_info = oi->oi_orig;
436 if ( oi->oi_orig->bi_entry_release_rw ) {
437 rc = oi->oi_orig->bi_entry_release_rw( op, e, rw );
440 /* should not fall thru this far without anything happening... */
441 if ( rc == SLAP_CB_CONTINUE ) {
447 op->o_bd->bd_info = bi;
453 over_entry_release_rw(
461 assert( op->o_bd != NULL );
463 oi = op->o_bd->bd_info->bi_private;
466 return overlay_entry_release_ov( op, e, rw, on );
473 struct berval *gr_ndn,
474 struct berval *op_ndn,
475 ObjectClass *group_oc,
476 AttributeDescription *group_at )
480 BackendInfo *bi = op->o_bd->bd_info;
481 BackendDB *be = op->o_bd, db;
482 int rc = SLAP_CB_CONTINUE;
484 /* FIXME: used to happen for instance during abandon
485 * when global overlays are used... */
486 assert( op->o_bd != NULL );
488 oi = op->o_bd->bd_info->bi_private;
491 for ( ; on; on = on->on_next ) {
492 if ( on->on_bi.bi_acl_group ) {
493 /* NOTE: do not copy the structure until required */
494 if ( !SLAP_ISOVERLAY( op->o_bd ) ) {
496 db.be_flags |= SLAP_DBFLAG_OVERLAY;
500 op->o_bd->bd_info = (BackendInfo *)on;
501 rc = on->on_bi.bi_acl_group( op, e,
502 gr_ndn, op_ndn, group_oc, group_at );
503 if ( rc != SLAP_CB_CONTINUE ) break;
507 if ( rc == SLAP_CB_CONTINUE ) {
508 BI_acl_group *bi_acl_group;
510 /* if the database structure was changed, o_bd points to a
511 * copy of the structure; put the original bd_info in place */
512 if ( SLAP_ISOVERLAY( op->o_bd ) ) {
513 op->o_bd->bd_info = oi->oi_orig;
516 if ( oi->oi_orig->bi_acl_group ) {
517 bi_acl_group = oi->oi_orig->bi_acl_group;
519 bi_acl_group = backend_group;
522 rc = bi_acl_group( op, e,
523 gr_ndn, op_ndn, group_oc, group_at );
525 /* should not fall thru this far without anything happening... */
526 if ( rc == SLAP_CB_CONTINUE ) {
527 /* access not allowed */
532 op->o_bd->bd_info = bi;
541 struct berval *entry_ndn,
542 AttributeDescription *entry_at,
544 slap_access_t access )
548 BackendInfo *bi = op->o_bd->bd_info;
549 BackendDB *be = op->o_bd, db;
550 int rc = SLAP_CB_CONTINUE;
552 /* FIXME: used to happen for instance during abandon
553 * when global overlays are used... */
554 assert( op->o_bd != NULL );
556 oi = op->o_bd->bd_info->bi_private;
559 for ( ; on; on = on->on_next ) {
560 if ( on->on_bi.bi_acl_attribute ) {
561 /* NOTE: do not copy the structure until required */
562 if ( !SLAP_ISOVERLAY( op->o_bd ) ) {
564 db.be_flags |= SLAP_DBFLAG_OVERLAY;
568 op->o_bd->bd_info = (BackendInfo *)on;
569 rc = on->on_bi.bi_acl_attribute( op, target,
570 entry_ndn, entry_at, vals, access );
571 if ( rc != SLAP_CB_CONTINUE ) break;
575 if ( rc == SLAP_CB_CONTINUE ) {
576 BI_acl_attribute *bi_acl_attribute;
578 /* if the database structure was changed, o_bd points to a
579 * copy of the structure; put the original bd_info in place */
580 if ( SLAP_ISOVERLAY( op->o_bd ) ) {
581 op->o_bd->bd_info = oi->oi_orig;
584 if ( oi->oi_orig->bi_acl_attribute ) {
585 bi_acl_attribute = oi->oi_orig->bi_acl_attribute;
587 bi_acl_attribute = backend_attribute;
590 rc = bi_acl_attribute( op, target,
591 entry_ndn, entry_at, vals, access );
593 /* should not fall thru this far without anything happening... */
594 if ( rc == SLAP_CB_CONTINUE ) {
595 /* access not allowed */
600 op->o_bd->bd_info = bi;
606 overlay_callback_after_backover( Operation *op, slap_callback *sc, int append )
610 for ( scp = &op->o_callback; *scp != NULL; scp = &(*scp)->sc_next ) {
611 if ( (*scp)->sc_response == over_back_response ) {
612 sc->sc_next = (*scp)->sc_next;
613 (*scp)->sc_next = sc;
627 * default return code in case of missing backend function
628 * and overlay stack returning SLAP_CB_CONTINUE
630 static int op_rc[ op_last ] = {
631 LDAP_UNWILLING_TO_PERFORM, /* bind */
632 LDAP_UNWILLING_TO_PERFORM, /* unbind */
633 LDAP_UNWILLING_TO_PERFORM, /* search */
634 SLAP_CB_CONTINUE, /* compare; pass to frontend */
635 LDAP_UNWILLING_TO_PERFORM, /* modify */
636 LDAP_UNWILLING_TO_PERFORM, /* modrdn */
637 LDAP_UNWILLING_TO_PERFORM, /* add */
638 LDAP_UNWILLING_TO_PERFORM, /* delete */
639 LDAP_UNWILLING_TO_PERFORM, /* abandon */
640 LDAP_UNWILLING_TO_PERFORM, /* cancel */
641 LDAP_UNWILLING_TO_PERFORM, /* extended */
642 LDAP_SUCCESS, /* aux_operational */
643 LDAP_SUCCESS, /* aux_chk_referrals */
644 SLAP_CB_CONTINUE /* aux_chk_controls; pass to frontend */
650 slap_operation_t which,
656 int rc = SLAP_CB_CONTINUE;
658 for (; on; on=on->on_next ) {
659 func = &on->on_bi.bi_op_bind;
661 op->o_bd->bd_info = (BackendInfo *)on;
662 rc = func[which]( op, rs );
663 if ( rc != SLAP_CB_CONTINUE ) break;
666 if ( rc == SLAP_CB_BYPASS )
667 rc = SLAP_CB_CONTINUE;
669 func = &oi->oi_orig->bi_op_bind;
670 if ( func[which] && rc == SLAP_CB_CONTINUE ) {
671 op->o_bd->bd_info = oi->oi_orig;
672 rc = func[which]( op, rs );
674 /* should not fall thru this far without anything happening... */
675 if ( rc == SLAP_CB_CONTINUE ) {
679 /* The underlying backend didn't handle the request, make sure
680 * overlay cleanup is processed.
682 if ( rc == LDAP_UNWILLING_TO_PERFORM ) {
683 slap_callback *sc_next;
684 for ( ; op->o_callback && op->o_callback->sc_response !=
685 over_back_response; op->o_callback = sc_next ) {
686 sc_next = op->o_callback->sc_next;
687 if ( op->o_callback->sc_cleanup ) {
688 op->o_callback->sc_cleanup( op, rs );
699 slap_operation_t which
704 BackendDB *be = op->o_bd, db;
705 slap_callback cb = {NULL, over_back_response, NULL, NULL};
706 int rc = SLAP_CB_CONTINUE;
708 /* FIXME: used to happen for instance during abandon
709 * when global overlays are used... */
710 assert( op->o_bd != NULL );
712 oi = op->o_bd->bd_info->bi_private;
715 if ( !SLAP_ISOVERLAY( op->o_bd )) {
717 db.be_flags |= SLAP_DBFLAG_OVERLAY;
720 cb.sc_next = op->o_callback;
722 op->o_callback = &cb;
724 rc = overlay_op_walk( op, rs, which, oi, on );
727 op->o_callback = cb.sc_next;
732 over_op_bind( Operation *op, SlapReply *rs )
734 return over_op_func( op, rs, op_bind );
738 over_op_unbind( Operation *op, SlapReply *rs )
740 return over_op_func( op, rs, op_unbind );
744 over_op_search( Operation *op, SlapReply *rs )
746 return over_op_func( op, rs, op_search );
750 over_op_compare( Operation *op, SlapReply *rs )
752 return over_op_func( op, rs, op_compare );
756 over_op_modify( Operation *op, SlapReply *rs )
758 return over_op_func( op, rs, op_modify );
762 over_op_modrdn( Operation *op, SlapReply *rs )
764 return over_op_func( op, rs, op_modrdn );
768 over_op_add( Operation *op, SlapReply *rs )
770 return over_op_func( op, rs, op_add );
774 over_op_delete( Operation *op, SlapReply *rs )
776 return over_op_func( op, rs, op_delete );
780 over_op_abandon( Operation *op, SlapReply *rs )
782 return over_op_func( op, rs, op_abandon );
786 over_op_cancel( Operation *op, SlapReply *rs )
788 return over_op_func( op, rs, op_cancel );
792 over_op_extended( Operation *op, SlapReply *rs )
794 return over_op_func( op, rs, op_extended );
798 over_aux_operational( Operation *op, SlapReply *rs )
800 return over_op_func( op, rs, op_aux_operational );
804 over_aux_chk_referrals( Operation *op, SlapReply *rs )
806 return over_op_func( op, rs, op_aux_chk_referrals );
810 over_aux_chk_controls( Operation *op, SlapReply *rs )
812 return over_op_func( op, rs, op_aux_chk_controls );
822 over_connection_func(
825 enum conn_which which
831 int rc = SLAP_CB_CONTINUE;
832 BI_connection_init **func;
834 /* FIXME: used to happen for instance during abandon
835 * when global overlays are used... */
836 assert( bd != NULL );
838 oi = bd->bd_info->bi_private;
841 if ( !SLAP_ISOVERLAY( bd ) ) {
843 db.be_flags |= SLAP_DBFLAG_OVERLAY;
847 for ( ; on; on = on->on_next ) {
848 func = &on->on_bi.bi_connection_init;
849 if ( func[ which ] ) {
850 bd->bd_info = (BackendInfo *)on;
851 rc = func[ which ]( bd, conn );
852 if ( rc != SLAP_CB_CONTINUE ) break;
856 func = &oi->oi_orig->bi_connection_init;
857 if ( func[ which ] && rc == SLAP_CB_CONTINUE ) {
858 bd->bd_info = oi->oi_orig;
859 rc = func[ which ]( bd, conn );
861 /* should not fall thru this far without anything happening... */
862 if ( rc == SLAP_CB_CONTINUE ) {
863 rc = LDAP_UNWILLING_TO_PERFORM;
870 over_connection_init(
875 return over_connection_func( bd, conn, conn_init );
879 over_connection_destroy(
884 return over_connection_func( bd, conn, conn_destroy );
894 /* FIXME: check for duplicates? */
895 for ( tmp = overlays; tmp != NULL; tmp = tmp->on_next ) {
896 if ( strcmp( on->on_bi.bi_type, tmp->on_bi.bi_type ) == 0 ) {
897 Debug( LDAP_DEBUG_ANY,
898 "overlay_register(\"%s\"): "
899 "name already in use.\n",
900 on->on_bi.bi_type, 0, 0 );
904 if ( on->on_bi.bi_obsolete_names != NULL ) {
907 for ( i = 0; on->on_bi.bi_obsolete_names[ i ] != NULL; i++ ) {
908 if ( strcmp( on->on_bi.bi_obsolete_names[ i ], tmp->on_bi.bi_type ) == 0 ) {
909 Debug( LDAP_DEBUG_ANY,
910 "overlay_register(\"%s\"): "
911 "obsolete name \"%s\" already in use "
912 "by overlay \"%s\".\n",
914 on->on_bi.bi_obsolete_names[ i ],
915 tmp->on_bi.bi_type );
921 if ( tmp->on_bi.bi_obsolete_names != NULL ) {
924 for ( i = 0; tmp->on_bi.bi_obsolete_names[ i ] != NULL; i++ ) {
927 if ( strcmp( on->on_bi.bi_type, tmp->on_bi.bi_obsolete_names[ i ] ) == 0 ) {
928 Debug( LDAP_DEBUG_ANY,
929 "overlay_register(\"%s\"): "
930 "name already in use "
931 "as obsolete by overlay \"%s\".\n",
933 tmp->on_bi.bi_obsolete_names[ i ], 0 );
937 if ( on->on_bi.bi_obsolete_names != NULL ) {
938 for ( j = 0; on->on_bi.bi_obsolete_names[ j ] != NULL; j++ ) {
939 if ( strcmp( on->on_bi.bi_obsolete_names[ j ], tmp->on_bi.bi_obsolete_names[ i ] ) == 0 ) {
940 Debug( LDAP_DEBUG_ANY,
941 "overlay_register(\"%s\"): "
942 "obsolete name \"%s\" already in use "
943 "as obsolete by overlay \"%s\".\n",
945 on->on_bi.bi_obsolete_names[ j ],
946 tmp->on_bi.bi_type );
955 on->on_next = overlays;
961 * iterator on registered overlays; overlay_next( NULL ) returns the first
962 * overlay; subsequent calls with the previously returned value allow to
963 * iterate over the entire list; returns NULL when no more overlays are
980 * returns a specific registered overlay based on the type; NULL if not
985 overlay_find( const char *over_type )
987 slap_overinst *on = overlays;
989 assert( over_type != NULL );
991 for ( ; on; on = on->on_next ) {
992 if ( strcmp( on->on_bi.bi_type, over_type ) == 0 ) {
996 if ( on->on_bi.bi_obsolete_names != NULL ) {
999 for ( i = 0; on->on_bi.bi_obsolete_names[ i ] != NULL; i++ ) {
1000 if ( strcmp( on->on_bi.bi_obsolete_names[ i ], over_type ) == 0 ) {
1001 Debug( LDAP_DEBUG_ANY,
1002 "overlay_find(\"%s\"): "
1003 "obsolete name for \"%s\".\n",
1004 on->on_bi.bi_obsolete_names[ i ],
1005 on->on_bi.bi_type, 0 );
1016 static const char overtype[] = "over";
1019 * returns TRUE (1) if the database is actually an overlay instance;
1020 * FALSE (0) otherwise.
1024 overlay_is_over( BackendDB *be )
1026 return be->bd_info->bi_type == overtype;
1030 * returns TRUE (1) if the given database is actually an overlay
1031 * instance and, somewhere in the list, contains the requested overlay;
1032 * FALSE (0) otherwise.
1036 overlay_is_inst( BackendDB *be, const char *over_type )
1040 assert( be != NULL );
1042 if ( !overlay_is_over( be ) ) {
1046 on = ((slap_overinfo *)be->bd_info->bi_private)->oi_list;
1047 for ( ; on; on = on->on_next ) {
1048 if ( strcmp( on->on_bi.bi_type, over_type ) == 0 ) {
1057 overlay_register_control( BackendDB *be, const char *oid )
1062 if ( slap_find_control_id( oid, &cid ) == LDAP_CONTROL_NOT_FOUND ) {
1066 if ( SLAP_ISGLOBALOVERLAY( be ) ) {
1069 /* add to all backends... */
1070 LDAP_STAILQ_FOREACH( bd, &backendDB, be_next ) {
1071 if ( bd == be->bd_self ) {
1075 bd->be_ctrls[ cid ] = 1;
1076 bd->be_ctrls[ SLAP_MAX_CIDS ] = 1;
1082 be->bd_self->be_ctrls[ cid ] = 1;
1083 be->bd_self->be_ctrls[ SLAP_MAX_CIDS ] = 1;
1090 overlay_destroy_one( BackendDB *be, slap_overinst *on )
1092 slap_overinfo *oi = on->on_info;
1093 slap_overinst **oidx;
1095 for ( oidx = &oi->oi_list; *oidx; oidx = &(*oidx)->on_next ) {
1096 if ( *oidx == on ) {
1097 *oidx = on->on_next;
1098 if ( on->on_bi.bi_db_destroy ) {
1099 BackendInfo *bi_orig = be->bd_info;
1100 be->bd_info = (BackendInfo *)on;
1101 on->on_bi.bi_db_destroy( be, NULL );
1102 be->bd_info = bi_orig;
1110 #ifdef SLAP_CONFIG_DELETE
1112 overlay_remove( BackendDB *be, slap_overinst *on )
1114 slap_overinfo *oi = on->on_info;
1115 slap_overinst **oidx;
1116 BackendInfo *bi_orig;
1118 /* remove overlay from oi_list an call db_close and db_destroy
1120 for ( oidx = &oi->oi_list; *oidx; oidx = &(*oidx)->on_next ) {
1121 if ( *oidx == on ) {
1122 *oidx = on->on_next;
1123 bi_orig = be->bd_info;
1124 be->bd_info = (BackendInfo *)on;
1125 if ( on->on_bi.bi_db_close ) {
1126 on->on_bi.bi_db_close( be, NULL );
1128 if ( on->on_bi.bi_db_destroy ) {
1129 on->on_bi.bi_db_destroy( be, NULL );
1131 be->bd_info = bi_orig;
1137 /* clean up after removing last overlay */
1138 if ( ! oi->oi_list )
1140 /* reset db flags and bd_info to orig */
1141 SLAP_DBFLAGS( be ) &= ~SLAP_DBFLAG_GLOBAL_OVERLAY;
1142 be->bd_info = oi->oi_orig;
1146 #endif /* SLAP_CONFIG_DELETE */
1149 overlay_insert( BackendDB *be, slap_overinst *on2, slap_overinst ***prev,
1152 slap_overinfo *oi = (slap_overinfo *)be->bd_info;
1155 on2->on_next = oi->oi_list;
1159 slap_overinst *on, *otmp1 = NULL, *otmp2;
1161 /* Since the list is in reverse order and is singly linked,
1162 * we reverse it to find the idx insertion point. Adding
1163 * on overlay at a specific point should be a pretty
1164 * infrequent occurrence.
1166 for ( on = oi->oi_list; on; on=otmp2 ) {
1167 otmp2 = on->on_next;
1168 on->on_next = otmp1;
1172 /* advance to insertion point */
1173 for ( i=0, on = otmp1; i<idx; i++ ) {
1174 otmp1 = on->on_next;
1175 on->on_next = oi->oi_list;
1179 on2->on_next = oi->oi_list;
1182 *prev = &otmp1->on_next;
1183 /* replace remainder of list */
1184 for ( on=otmp1; on; on=otmp1 ) {
1185 otmp1 = on->on_next;
1186 on->on_next = oi->oi_list;
1194 overlay_move( BackendDB *be, slap_overinst *on, int idx )
1196 slap_overinfo *oi = (slap_overinfo *)be->bd_info;
1197 slap_overinst **onp;
1199 for (onp = &oi->oi_list; *onp; onp= &(*onp)->on_next) {
1205 overlay_insert( be, on, &onp, idx );
1208 /* add an overlay to a particular backend. */
1210 overlay_config( BackendDB *be, const char *ov, int idx, BackendInfo **res, ConfigReply *cr )
1212 slap_overinst *on = NULL, *on2 = NULL, **prev;
1213 slap_overinfo *oi = NULL;
1214 BackendInfo *bi = NULL;
1219 on = overlay_find( ov );
1221 Debug( LDAP_DEBUG_ANY, "overlay \"%s\" not found\n", ov, 0, 0 );
1225 /* If this is the first overlay on this backend, set up the
1226 * overlay info structure
1228 if ( !overlay_is_over( be ) ) {
1231 /* NOTE: the first time a global overlay is configured,
1232 * frontendDB gets this flag; it is used later by overlays
1233 * to determine if they're stacked on top of the frontendDB */
1234 if ( be->bd_info == frontendDB->bd_info || SLAP_ISGLOBALOVERLAY( be ) ) {
1236 if ( on->on_bi.bi_flags & SLAPO_BFLAG_DBONLY ) {
1237 Debug( LDAP_DEBUG_ANY, "overlay_config(): "
1238 "overlay \"%s\" cannot be global.\n",
1243 } else if ( on->on_bi.bi_flags & SLAPO_BFLAG_GLOBONLY ) {
1244 Debug( LDAP_DEBUG_ANY, "overlay_config(): "
1245 "overlay \"%s\" can only be global.\n",
1250 oi = ch_malloc( sizeof( slap_overinfo ) );
1251 oi->oi_orig = be->bd_info;
1252 oi->oi_bi = *be->bd_info;
1256 SLAP_DBFLAGS( be ) |= SLAP_DBFLAG_GLOBAL_OVERLAY;
1259 /* Save a pointer to ourself in bi_private.
1261 oi->oi_bi.bi_private = oi;
1263 bi = (BackendInfo *)oi;
1265 bi->bi_type = (char *)overtype;
1267 bi->bi_db_config = over_db_config;
1268 bi->bi_db_open = over_db_open;
1269 bi->bi_db_close = over_db_close;
1270 bi->bi_db_destroy = over_db_destroy;
1272 bi->bi_op_bind = over_op_bind;
1273 bi->bi_op_unbind = over_op_unbind;
1274 bi->bi_op_search = over_op_search;
1275 bi->bi_op_compare = over_op_compare;
1276 bi->bi_op_modify = over_op_modify;
1277 bi->bi_op_modrdn = over_op_modrdn;
1278 bi->bi_op_add = over_op_add;
1279 bi->bi_op_delete = over_op_delete;
1280 bi->bi_op_abandon = over_op_abandon;
1281 bi->bi_op_cancel = over_op_cancel;
1283 bi->bi_extended = over_op_extended;
1286 * this is fine because it has the same
1287 * args of the operations; we need to rework
1288 * all the hooks to share the same args
1289 * of the operations...
1291 bi->bi_operational = over_aux_operational;
1292 bi->bi_chk_referrals = over_aux_chk_referrals;
1293 bi->bi_chk_controls = over_aux_chk_controls;
1295 /* these have specific arglists */
1296 bi->bi_entry_get_rw = over_entry_get_rw;
1297 bi->bi_entry_release_rw = over_entry_release_rw;
1298 bi->bi_access_allowed = over_access_allowed;
1299 bi->bi_acl_group = over_acl_group;
1300 bi->bi_acl_attribute = over_acl_attribute;
1302 bi->bi_connection_init = over_connection_init;
1303 bi->bi_connection_destroy = over_connection_destroy;
1308 if ( overlay_is_inst( be, ov ) ) {
1309 if ( SLAPO_SINGLE( be ) ) {
1310 Debug( LDAP_DEBUG_ANY, "overlay_config(): "
1311 "overlay \"%s\" already in list\n",
1317 oi = be->bd_info->bi_private;
1320 /* Insert new overlay into list. By default overlays are
1321 * added to head of list and executed in LIFO order.
1323 on2 = ch_calloc( 1, sizeof(slap_overinst) );
1327 prev = &oi->oi_list;
1328 /* Do we need to find the insertion point? */
1332 /* count current overlays */
1333 for ( i=0, on=oi->oi_list; on; on=on->on_next, i++ );
1335 /* are we just appending a new one? */
1339 overlay_insert( be, on2, &prev, idx );
1341 /* Any initialization needed? */
1342 if ( on2->on_bi.bi_db_init ) {
1344 be->bd_info = (BackendInfo *)on2;
1345 rc = on2->on_bi.bi_db_init( be, cr);
1346 be->bd_info = (BackendInfo *)oi;
1348 *prev = on2->on_next;