1 /* backover.c - backend overlay routines */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2003-2007 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;
45 slap_overinfo *oi = be->bd_info->bi_private;
46 slap_overinst *on = oi->oi_list;
47 BackendInfo *bi_orig = be->bd_info;
51 func = &oi->oi_orig->bi_db_open;
53 be->bd_info = oi->oi_orig;
54 rc = func[which]( be );
57 for (; on && rc == 0; on=on->on_next) {
58 be->bd_info = &on->on_bi;
59 func = &on->on_bi.bi_db_open;
61 rc = func[which]( be );
64 be->bd_info = bi_orig;
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;
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,
90 if ( be->bd_info != oi->oi_orig ) {
92 slap_overinst *on2, **onp;
96 /* a database added an overlay;
97 * work it around... */
98 assert( overlay_is_over( be ) );
100 oi2 = ( slap_overinfo * )be->bd_info->bi_private;
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;
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 );
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 */
128 ch_free( be->bd_info );
131 be->bd_info = (BackendInfo *)oi;
132 if ( rc != SLAP_CONF_UNKNOWN ) return rc;
140 snprintf( ca.log, sizeof( ca.log ), "%s: line %d",
141 ca.fname, ca.lineno );
143 for (; on; on=on->on_next) {
144 rc = SLAP_CONF_UNKNOWN;
145 if (on->on_bi.bi_cf_ocs) {
148 ct = config_find_keyword( on->on_bi.bi_cf_ocs->co_table, &ca );
150 rc = config_add_vals( ct, &ca );
151 if ( rc != SLAP_CONF_UNKNOWN )
155 if (on->on_bi.bi_db_config && rc == SLAP_CONF_UNKNOWN) {
156 be->bd_info = &on->on_bi;
157 rc = on->on_bi.bi_db_config( be, fname, lineno,
159 if ( rc != SLAP_CONF_UNKNOWN ) break;
162 be->bd_info = bi_orig;
163 be->be_cf_ocs = be_cf_ocs;
173 return over_db_func( be, db_open );
181 slap_overinfo *oi = be->bd_info->bi_private;
182 slap_overinst *on = oi->oi_list;
183 BackendInfo *bi_orig = be->bd_info;
186 for (; on && rc == 0; on=on->on_next) {
187 be->bd_info = &on->on_bi;
188 if ( be->bd_info->bi_db_close ) {
189 rc = be->bd_info->bi_db_close( be );
193 if ( oi->oi_orig->bi_db_close ) {
194 be->bd_info = oi->oi_orig;
195 rc = be->bd_info->bi_db_close( be );
198 be->bd_info = bi_orig;
207 slap_overinfo *oi = be->bd_info->bi_private;
208 slap_overinst *on = oi->oi_list, *next;
211 rc = over_db_func( be, db_destroy );
214 for (next = on->on_next; on; on=next) {
225 over_back_response ( Operation *op, SlapReply *rs )
227 slap_overinfo *oi = op->o_callback->sc_private;
228 slap_overinst *on = oi->oi_list;
229 int rc = SLAP_CB_CONTINUE;
230 BackendDB *be = op->o_bd, db = *op->o_bd;
232 db.be_flags |= SLAP_DBFLAG_OVERLAY;
234 for (; on; on=on->on_next ) {
235 if ( on->on_response ) {
236 db.bd_info = (BackendInfo *)on;
237 rc = on->on_response( op, rs );
238 if ( rc != SLAP_CB_CONTINUE ) break;
241 /* Bypass the remaining on_response layers, but allow
242 * normal execution to continue.
244 if ( rc == SLAP_CB_BYPASS )
245 rc = SLAP_CB_CONTINUE;
254 AttributeDescription *desc,
256 slap_access_t access,
257 AccessControlState *state,
263 BackendDB *be = op->o_bd, db;
264 int rc = SLAP_CB_CONTINUE;
266 /* FIXME: used to happen for instance during abandon
267 * when global overlays are used... */
268 assert( op->o_bd != NULL );
270 bi = op->o_bd->bd_info;
271 /* Were we invoked on the frontend? */
272 if ( !bi->bi_access_allowed ) {
273 oi = frontendDB->bd_info->bi_private;
275 oi = op->o_bd->bd_info->bi_private;
279 for ( ; on; on = on->on_next ) {
280 if ( on->on_bi.bi_access_allowed ) {
281 /* NOTE: do not copy the structure until required */
282 if ( !SLAP_ISOVERLAY( op->o_bd ) ) {
284 db.be_flags |= SLAP_DBFLAG_OVERLAY;
288 op->o_bd->bd_info = (BackendInfo *)on;
289 rc = on->on_bi.bi_access_allowed( op, e,
290 desc, val, access, state, maskp );
291 if ( rc != SLAP_CB_CONTINUE ) break;
295 if ( rc == SLAP_CB_CONTINUE ) {
296 BI_access_allowed *bi_access_allowed;
298 /* if the database structure was changed, o_bd points to a
299 * copy of the structure; put the original bd_info in place */
300 if ( SLAP_ISOVERLAY( op->o_bd ) ) {
301 op->o_bd->bd_info = oi->oi_orig;
304 if ( oi->oi_orig->bi_access_allowed ) {
305 bi_access_allowed = oi->oi_orig->bi_access_allowed;
307 bi_access_allowed = slap_access_allowed;
310 rc = bi_access_allowed( op, e,
311 desc, val, access, state, maskp );
313 /* should not fall thru this far without anything happening... */
314 if ( rc == SLAP_CB_CONTINUE ) {
315 /* access not allowed */
320 op->o_bd->bd_info = bi;
326 overlay_entry_get_ov(
330 AttributeDescription *ad,
335 slap_overinfo *oi = on->on_info;
336 BackendDB *be = op->o_bd, db;
337 BackendInfo *bi = op->o_bd->bd_info;
338 int rc = SLAP_CB_CONTINUE;
340 for ( ; on; on = on->on_next ) {
341 if ( on->on_bi.bi_entry_get_rw ) {
342 /* NOTE: do not copy the structure until required */
343 if ( !SLAP_ISOVERLAY( op->o_bd ) ) {
345 db.be_flags |= SLAP_DBFLAG_OVERLAY;
349 op->o_bd->bd_info = (BackendInfo *)on;
350 rc = on->on_bi.bi_entry_get_rw( op, dn,
352 if ( rc != SLAP_CB_CONTINUE ) break;
356 if ( rc == SLAP_CB_CONTINUE ) {
357 /* if the database structure was changed, o_bd points to a
358 * copy of the structure; put the original bd_info in place */
359 if ( SLAP_ISOVERLAY( op->o_bd ) ) {
360 op->o_bd->bd_info = oi->oi_orig;
363 if ( oi->oi_orig->bi_entry_get_rw ) {
364 rc = oi->oi_orig->bi_entry_get_rw( op, dn,
368 /* should not fall thru this far without anything happening... */
369 if ( rc == SLAP_CB_CONTINUE ) {
370 rc = LDAP_UNWILLING_TO_PERFORM;
374 op->o_bd->bd_info = bi;
384 AttributeDescription *ad,
391 assert( op->o_bd != NULL );
393 oi = op->o_bd->bd_info->bi_private;
396 return overlay_entry_get_ov( op, dn, oc, ad, rw, e, on );
400 overlay_entry_release_ov(
406 slap_overinfo *oi = on->on_info;
407 BackendDB *be = op->o_bd, db;
408 BackendInfo *bi = op->o_bd->bd_info;
409 int rc = SLAP_CB_CONTINUE;
411 for ( ; on; on = on->on_next ) {
412 if ( on->on_bi.bi_entry_release_rw ) {
413 /* NOTE: do not copy the structure until required */
414 if ( !SLAP_ISOVERLAY( op->o_bd ) ) {
416 db.be_flags |= SLAP_DBFLAG_OVERLAY;
420 op->o_bd->bd_info = (BackendInfo *)on;
421 rc = on->on_bi.bi_entry_release_rw( op, e, rw );
422 if ( rc != SLAP_CB_CONTINUE ) break;
426 if ( rc == SLAP_CB_CONTINUE ) {
427 /* if the database structure was changed, o_bd points to a
428 * copy of the structure; put the original bd_info in place */
429 if ( SLAP_ISOVERLAY( op->o_bd ) ) {
430 op->o_bd->bd_info = oi->oi_orig;
433 if ( oi->oi_orig->bi_entry_release_rw ) {
434 rc = oi->oi_orig->bi_entry_release_rw( op, e, rw );
437 /* should not fall thru this far without anything happening... */
438 if ( rc == SLAP_CB_CONTINUE ) {
444 op->o_bd->bd_info = bi;
450 over_entry_release_rw(
458 assert( op->o_bd != NULL );
460 oi = op->o_bd->bd_info->bi_private;
463 return overlay_entry_release_ov( op, e, rw, on );
470 struct berval *gr_ndn,
471 struct berval *op_ndn,
472 ObjectClass *group_oc,
473 AttributeDescription *group_at )
477 BackendInfo *bi = op->o_bd->bd_info;
478 BackendDB *be = op->o_bd, db;
479 int rc = SLAP_CB_CONTINUE;
481 /* FIXME: used to happen for instance during abandon
482 * when global overlays are used... */
483 assert( op->o_bd != NULL );
485 oi = op->o_bd->bd_info->bi_private;
488 for ( ; on; on = on->on_next ) {
489 if ( on->on_bi.bi_acl_group ) {
490 /* NOTE: do not copy the structure until required */
491 if ( !SLAP_ISOVERLAY( op->o_bd ) ) {
493 db.be_flags |= SLAP_DBFLAG_OVERLAY;
497 op->o_bd->bd_info = (BackendInfo *)on;
498 rc = on->on_bi.bi_acl_group( op, e,
499 gr_ndn, op_ndn, group_oc, group_at );
500 if ( rc != SLAP_CB_CONTINUE ) break;
504 if ( rc == SLAP_CB_CONTINUE ) {
505 BI_acl_group *bi_acl_group;
507 /* if the database structure was changed, o_bd points to a
508 * copy of the structure; put the original bd_info in place */
509 if ( SLAP_ISOVERLAY( op->o_bd ) ) {
510 op->o_bd->bd_info = oi->oi_orig;
513 if ( oi->oi_orig->bi_acl_group ) {
514 bi_acl_group = oi->oi_orig->bi_acl_group;
516 bi_acl_group = backend_group;
519 rc = bi_acl_group( op, e,
520 gr_ndn, op_ndn, group_oc, group_at );
522 /* should not fall thru this far without anything happening... */
523 if ( rc == SLAP_CB_CONTINUE ) {
524 /* access not allowed */
529 op->o_bd->bd_info = bi;
538 struct berval *entry_ndn,
539 AttributeDescription *entry_at,
541 slap_access_t access )
545 BackendInfo *bi = op->o_bd->bd_info;
546 BackendDB *be = op->o_bd, db;
547 int rc = SLAP_CB_CONTINUE;
549 /* FIXME: used to happen for instance during abandon
550 * when global overlays are used... */
551 assert( op->o_bd != NULL );
553 oi = op->o_bd->bd_info->bi_private;
556 for ( ; on; on = on->on_next ) {
557 if ( on->on_bi.bi_acl_attribute ) {
558 /* NOTE: do not copy the structure until required */
559 if ( !SLAP_ISOVERLAY( op->o_bd ) ) {
561 db.be_flags |= SLAP_DBFLAG_OVERLAY;
565 op->o_bd->bd_info = (BackendInfo *)on;
566 rc = on->on_bi.bi_acl_attribute( op, target,
567 entry_ndn, entry_at, vals, access );
568 if ( rc != SLAP_CB_CONTINUE ) break;
572 if ( rc == SLAP_CB_CONTINUE ) {
573 BI_acl_attribute *bi_acl_attribute;
575 /* if the database structure was changed, o_bd points to a
576 * copy of the structure; put the original bd_info in place */
577 if ( SLAP_ISOVERLAY( op->o_bd ) ) {
578 op->o_bd->bd_info = oi->oi_orig;
581 if ( oi->oi_orig->bi_acl_attribute ) {
582 bi_acl_attribute = oi->oi_orig->bi_acl_attribute;
584 bi_acl_attribute = backend_attribute;
587 rc = bi_acl_attribute( op, target,
588 entry_ndn, entry_at, vals, access );
590 /* should not fall thru this far without anything happening... */
591 if ( rc == SLAP_CB_CONTINUE ) {
592 /* access not allowed */
597 op->o_bd->bd_info = bi;
603 * default return code in case of missing backend function
604 * and overlay stack returning SLAP_CB_CONTINUE
606 static int op_rc[ op_last ] = {
607 LDAP_UNWILLING_TO_PERFORM, /* bind */
608 LDAP_UNWILLING_TO_PERFORM, /* unbind */
609 LDAP_UNWILLING_TO_PERFORM, /* search */
610 SLAP_CB_CONTINUE, /* compare; pass to frontend */
611 LDAP_UNWILLING_TO_PERFORM, /* modify */
612 LDAP_UNWILLING_TO_PERFORM, /* modrdn */
613 LDAP_UNWILLING_TO_PERFORM, /* add */
614 LDAP_UNWILLING_TO_PERFORM, /* delete */
615 LDAP_UNWILLING_TO_PERFORM, /* abandon */
616 LDAP_UNWILLING_TO_PERFORM, /* cancel */
617 LDAP_UNWILLING_TO_PERFORM, /* extended */
618 LDAP_SUCCESS, /* aux_operational */
619 LDAP_SUCCESS, /* aux_chk_referrals */
620 SLAP_CB_CONTINUE /* aux_chk_controls; pass to frontend */
626 slap_operation_t which,
632 int rc = SLAP_CB_CONTINUE;
634 for (; on; on=on->on_next ) {
635 func = &on->on_bi.bi_op_bind;
637 op->o_bd->bd_info = (BackendInfo *)on;
638 rc = func[which]( op, rs );
639 if ( rc != SLAP_CB_CONTINUE ) break;
642 if ( rc == SLAP_CB_BYPASS )
643 rc = SLAP_CB_CONTINUE;
645 func = &oi->oi_orig->bi_op_bind;
646 if ( func[which] && rc == SLAP_CB_CONTINUE ) {
647 op->o_bd->bd_info = oi->oi_orig;
648 rc = func[which]( op, rs );
650 /* should not fall thru this far without anything happening... */
651 if ( rc == SLAP_CB_CONTINUE ) {
655 /* The underlying backend didn't handle the request, make sure
656 * overlay cleanup is processed.
658 if ( rc == LDAP_UNWILLING_TO_PERFORM ) {
659 slap_callback *sc_next;
660 for ( ; op->o_callback && op->o_callback->sc_response !=
661 over_back_response; op->o_callback = sc_next ) {
662 sc_next = op->o_callback->sc_next;
663 if ( op->o_callback->sc_cleanup ) {
664 op->o_callback->sc_cleanup( op, rs );
675 slap_operation_t which
680 BackendDB *be = op->o_bd, db;
681 slap_callback cb = {NULL, over_back_response, NULL, NULL};
682 int rc = SLAP_CB_CONTINUE;
684 /* FIXME: used to happen for instance during abandon
685 * when global overlays are used... */
686 assert( op->o_bd != NULL );
688 oi = op->o_bd->bd_info->bi_private;
691 if ( !SLAP_ISOVERLAY( op->o_bd )) {
693 db.be_flags |= SLAP_DBFLAG_OVERLAY;
696 cb.sc_next = op->o_callback;
698 op->o_callback = &cb;
700 rc = overlay_op_walk( op, rs, which, oi, on );
703 op->o_callback = cb.sc_next;
708 over_op_bind( Operation *op, SlapReply *rs )
710 return over_op_func( op, rs, op_bind );
714 over_op_unbind( Operation *op, SlapReply *rs )
716 return over_op_func( op, rs, op_unbind );
720 over_op_search( Operation *op, SlapReply *rs )
722 return over_op_func( op, rs, op_search );
726 over_op_compare( Operation *op, SlapReply *rs )
728 return over_op_func( op, rs, op_compare );
732 over_op_modify( Operation *op, SlapReply *rs )
734 return over_op_func( op, rs, op_modify );
738 over_op_modrdn( Operation *op, SlapReply *rs )
740 return over_op_func( op, rs, op_modrdn );
744 over_op_add( Operation *op, SlapReply *rs )
746 return over_op_func( op, rs, op_add );
750 over_op_delete( Operation *op, SlapReply *rs )
752 return over_op_func( op, rs, op_delete );
756 over_op_abandon( Operation *op, SlapReply *rs )
758 return over_op_func( op, rs, op_abandon );
762 over_op_cancel( Operation *op, SlapReply *rs )
764 return over_op_func( op, rs, op_cancel );
768 over_op_extended( Operation *op, SlapReply *rs )
770 return over_op_func( op, rs, op_extended );
774 over_aux_operational( Operation *op, SlapReply *rs )
776 return over_op_func( op, rs, op_aux_operational );
780 over_aux_chk_referrals( Operation *op, SlapReply *rs )
782 return over_op_func( op, rs, op_aux_chk_referrals );
786 over_aux_chk_controls( Operation *op, SlapReply *rs )
788 return over_op_func( op, rs, op_aux_chk_controls );
798 over_connection_func(
801 enum conn_which which
807 int rc = SLAP_CB_CONTINUE;
808 BI_connection_init **func;
810 /* FIXME: used to happen for instance during abandon
811 * when global overlays are used... */
812 assert( bd != NULL );
814 oi = bd->bd_info->bi_private;
817 if ( !SLAP_ISOVERLAY( bd ) ) {
819 db.be_flags |= SLAP_DBFLAG_OVERLAY;
823 for ( ; on; on = on->on_next ) {
824 func = &on->on_bi.bi_connection_init;
825 if ( func[ which ] ) {
826 bd->bd_info = (BackendInfo *)on;
827 rc = func[ which ]( bd, conn );
828 if ( rc != SLAP_CB_CONTINUE ) break;
832 func = &oi->oi_orig->bi_connection_init;
833 if ( func[ which ] && rc == SLAP_CB_CONTINUE ) {
834 bd->bd_info = oi->oi_orig;
835 rc = func[ which ]( bd, conn );
837 /* should not fall thru this far without anything happening... */
838 if ( rc == SLAP_CB_CONTINUE ) {
839 rc = LDAP_UNWILLING_TO_PERFORM;
846 over_connection_init(
851 return over_connection_func( bd, conn, conn_init );
855 over_connection_destroy(
860 return over_connection_func( bd, conn, conn_destroy );
870 /* FIXME: check for duplicates? */
871 for ( tmp = overlays; tmp != NULL; tmp = tmp->on_next ) {
872 if ( strcmp( on->on_bi.bi_type, tmp->on_bi.bi_type ) == 0 ) {
873 Debug( LDAP_DEBUG_ANY,
874 "overlay_register(\"%s\"): "
875 "name already in use.\n",
876 on->on_bi.bi_type, 0, 0 );
880 if ( on->on_bi.bi_obsolete_names != NULL ) {
883 for ( i = 0; on->on_bi.bi_obsolete_names[ i ] != NULL; i++ ) {
884 if ( strcmp( on->on_bi.bi_obsolete_names[ i ], tmp->on_bi.bi_type ) == 0 ) {
885 Debug( LDAP_DEBUG_ANY,
886 "overlay_register(\"%s\"): "
887 "obsolete name \"%s\" already in use "
888 "by overlay \"%s\".\n",
890 on->on_bi.bi_obsolete_names[ i ],
891 tmp->on_bi.bi_type );
897 if ( tmp->on_bi.bi_obsolete_names != NULL ) {
900 for ( i = 0; tmp->on_bi.bi_obsolete_names[ i ] != NULL; i++ ) {
903 if ( strcmp( on->on_bi.bi_type, tmp->on_bi.bi_obsolete_names[ i ] ) == 0 ) {
904 Debug( LDAP_DEBUG_ANY,
905 "overlay_register(\"%s\"): "
906 "name already in use "
907 "as obsolete by overlay \"%s\".\n",
909 tmp->on_bi.bi_obsolete_names[ i ], 0 );
913 if ( on->on_bi.bi_obsolete_names != NULL ) {
914 for ( j = 0; on->on_bi.bi_obsolete_names[ j ] != NULL; j++ ) {
915 if ( strcmp( on->on_bi.bi_obsolete_names[ j ], tmp->on_bi.bi_obsolete_names[ i ] ) == 0 ) {
916 Debug( LDAP_DEBUG_ANY,
917 "overlay_register(\"%s\"): "
918 "obsolete name \"%s\" already in use "
919 "as obsolete by overlay \"%s\".\n",
921 on->on_bi.bi_obsolete_names[ j ],
922 tmp->on_bi.bi_type );
931 on->on_next = overlays;
937 * iterator on registered overlays; overlay_next( NULL ) returns the first
938 * overlay; subsequent calls with the previously returned value allow to
939 * iterate over the entire list; returns NULL when no more overlays are
956 * returns a specific registered overlay based on the type; NULL if not
961 overlay_find( const char *over_type )
963 slap_overinst *on = overlays;
965 assert( over_type != NULL );
967 for ( ; on; on = on->on_next ) {
968 if ( strcmp( on->on_bi.bi_type, over_type ) == 0 ) {
972 if ( on->on_bi.bi_obsolete_names != NULL ) {
975 for ( i = 0; on->on_bi.bi_obsolete_names[ i ] != NULL; i++ ) {
976 if ( strcmp( on->on_bi.bi_obsolete_names[ i ], over_type ) == 0 ) {
977 Debug( LDAP_DEBUG_ANY,
978 "overlay_find(\"%s\"): "
979 "obsolete name for \"%s\".\n",
980 on->on_bi.bi_obsolete_names[ i ],
981 on->on_bi.bi_type, 0 );
992 static const char overtype[] = "over";
995 * returns TRUE (1) if the database is actually an overlay instance;
996 * FALSE (0) otherwise.
1000 overlay_is_over( BackendDB *be )
1002 return be->bd_info->bi_type == overtype;
1006 * returns TRUE (1) if the given database is actually an overlay
1007 * instance and, somewhere in the list, contains the requested overlay;
1008 * FALSE (0) otherwise.
1012 overlay_is_inst( BackendDB *be, const char *over_type )
1016 assert( be != NULL );
1018 if ( !overlay_is_over( be ) ) {
1022 on = ((slap_overinfo *)be->bd_info->bi_private)->oi_list;
1023 for ( ; on; on = on->on_next ) {
1024 if ( strcmp( on->on_bi.bi_type, over_type ) == 0 ) {
1033 overlay_register_control( BackendDB *be, const char *oid )
1038 if ( slap_find_control_id( oid, &cid ) == LDAP_CONTROL_NOT_FOUND ) {
1042 if ( SLAP_ISGLOBALOVERLAY( be ) ) {
1045 /* add to all backends... */
1046 LDAP_STAILQ_FOREACH( bd, &backendDB, be_next ) {
1051 bd->be_ctrls[ cid ] = 1;
1052 bd->be_ctrls[ SLAP_MAX_CIDS ] = 1;
1058 be->be_ctrls[ cid ] = 1;
1059 be->be_ctrls[ SLAP_MAX_CIDS ] = 1;
1066 overlay_destroy_one( BackendDB *be, slap_overinst *on )
1068 slap_overinfo *oi = on->on_info;
1069 slap_overinst **oidx;
1071 for ( oidx = &oi->oi_list; *oidx; oidx = &(*oidx)->on_next ) {
1072 if ( *oidx == on ) {
1073 *oidx = on->on_next;
1074 if ( on->on_bi.bi_db_destroy ) {
1075 BackendInfo *bi_orig = be->bd_info;
1076 be->bd_info = (BackendInfo *)on;
1077 on->on_bi.bi_db_destroy( be );
1078 be->bd_info = bi_orig;
1087 overlay_insert( BackendDB *be, slap_overinst *on2, slap_overinst ***prev,
1090 slap_overinfo *oi = (slap_overinfo *)be->bd_info;
1093 on2->on_next = oi->oi_list;
1097 slap_overinst *on, *otmp1 = NULL, *otmp2;
1099 /* Since the list is in reverse order and is singly linked,
1100 * we reverse it to find the idx insertion point. Adding
1101 * on overlay at a specific point should be a pretty
1102 * infrequent occurrence.
1104 for ( on = oi->oi_list; on; on=otmp2 ) {
1105 otmp2 = on->on_next;
1106 on->on_next = otmp1;
1110 /* advance to insertion point */
1111 for ( i=0, on = otmp1; i<idx; i++ ) {
1112 otmp1 = on->on_next;
1113 on->on_next = oi->oi_list;
1117 on2->on_next = oi->oi_list;
1120 *prev = &otmp1->on_next;
1121 /* replace remainder of list */
1122 for ( on=otmp1; on; on=otmp1 ) {
1123 otmp1 = on->on_next;
1124 on->on_next = oi->oi_list;
1132 overlay_move( BackendDB *be, slap_overinst *on, int idx )
1134 slap_overinfo *oi = (slap_overinfo *)be->bd_info;
1135 slap_overinst **onp;
1137 for (onp = &oi->oi_list; *onp; onp= &(*onp)->on_next) {
1143 overlay_insert( be, on, &onp, idx );
1146 /* add an overlay to a particular backend. */
1148 overlay_config( BackendDB *be, const char *ov, int idx, BackendInfo **res )
1150 slap_overinst *on = NULL, *on2 = NULL, **prev;
1151 slap_overinfo *oi = NULL;
1152 BackendInfo *bi = NULL;
1157 on = overlay_find( ov );
1159 Debug( LDAP_DEBUG_ANY, "overlay \"%s\" not found\n", ov, 0, 0 );
1163 /* If this is the first overlay on this backend, set up the
1164 * overlay info structure
1166 if ( !overlay_is_over( be ) ) {
1169 /* NOTE: the first time a global overlay is configured,
1170 * frontendDB gets this flag; it is used later by overlays
1171 * to determine if they're stacked on top of the frontendDB */
1172 if ( be->bd_info == frontendDB->bd_info || SLAP_ISGLOBALOVERLAY( be ) ) {
1174 if ( on->on_bi.bi_flags & SLAPO_BFLAG_DBONLY ) {
1175 Debug( LDAP_DEBUG_ANY, "overlay_config(): "
1176 "overlay \"%s\" cannot be global.\n",
1181 } else if ( on->on_bi.bi_flags & SLAPO_BFLAG_GLOBONLY ) {
1182 Debug( LDAP_DEBUG_ANY, "overlay_config(): "
1183 "overlay \"%s\" can only be global.\n",
1188 oi = ch_malloc( sizeof( slap_overinfo ) );
1189 oi->oi_orig = be->bd_info;
1190 oi->oi_bi = *be->bd_info;
1194 SLAP_DBFLAGS( be ) |= SLAP_DBFLAG_GLOBAL_OVERLAY;
1197 /* Save a pointer to ourself in bi_private.
1199 oi->oi_bi.bi_private = oi;
1201 bi = (BackendInfo *)oi;
1203 bi->bi_type = (char *)overtype;
1205 bi->bi_db_config = over_db_config;
1206 bi->bi_db_open = over_db_open;
1207 bi->bi_db_close = over_db_close;
1208 bi->bi_db_destroy = over_db_destroy;
1210 bi->bi_op_bind = over_op_bind;
1211 bi->bi_op_unbind = over_op_unbind;
1212 bi->bi_op_search = over_op_search;
1213 bi->bi_op_compare = over_op_compare;
1214 bi->bi_op_modify = over_op_modify;
1215 bi->bi_op_modrdn = over_op_modrdn;
1216 bi->bi_op_add = over_op_add;
1217 bi->bi_op_delete = over_op_delete;
1218 bi->bi_op_abandon = over_op_abandon;
1219 bi->bi_op_cancel = over_op_cancel;
1221 bi->bi_extended = over_op_extended;
1224 * this is fine because it has the same
1225 * args of the operations; we need to rework
1226 * all the hooks to share the same args
1227 * of the operations...
1229 bi->bi_operational = over_aux_operational;
1230 bi->bi_chk_referrals = over_aux_chk_referrals;
1231 bi->bi_chk_controls = over_aux_chk_controls;
1233 /* these have specific arglists */
1234 bi->bi_entry_get_rw = over_entry_get_rw;
1235 bi->bi_entry_release_rw = over_entry_release_rw;
1236 bi->bi_access_allowed = over_access_allowed;
1237 bi->bi_acl_group = over_acl_group;
1238 bi->bi_acl_attribute = over_acl_attribute;
1240 bi->bi_connection_init = over_connection_init;
1241 bi->bi_connection_destroy = over_connection_destroy;
1246 if ( overlay_is_inst( be, ov ) ) {
1247 Debug( LDAP_DEBUG_ANY, "overlay_config(): "
1248 "overlay \"%s\" already in list\n",
1250 if ( SLAPO_SINGLE( be ) ) {
1255 oi = be->bd_info->bi_private;
1258 /* Insert new overlay into list. By default overlays are
1259 * added to head of list and executed in LIFO order.
1261 on2 = ch_calloc( 1, sizeof(slap_overinst) );
1265 prev = &oi->oi_list;
1266 /* Do we need to find the insertion point? */
1270 /* count current overlays */
1271 for ( i=0, on=oi->oi_list; on; on=on->on_next, i++ );
1273 /* are we just appending a new one? */
1277 overlay_insert( be, on2, &prev, idx );
1279 /* Any initialization needed? */
1280 if ( on2->on_bi.bi_db_init ) {
1282 be->bd_info = (BackendInfo *)on2;
1283 rc = on2->on_bi.bi_db_init( be );
1284 be->bd_info = (BackendInfo *)oi;
1286 *prev = on2->on_next;