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;
146 db.be_flags |= SLAP_DBFLAG_OVERLAY;
147 db.bd_info = oi->oi_orig;
148 if ( db.bd_info->bi_db_open ) {
149 rc = db.bd_info->bi_db_open( &db, cr );
152 for (; on && rc == 0; on=on->on_next) {
153 db.bd_info = &on->on_bi;
154 if ( db.bd_info->bi_db_open ) {
155 rc = db.bd_info->bi_db_open( &db, cr );
168 slap_overinfo *oi = be->bd_info->bi_private;
169 slap_overinst *on = oi->oi_list;
170 BackendInfo *bi_orig = be->bd_info;
173 for (; on && rc == 0; on=on->on_next) {
174 be->bd_info = &on->on_bi;
175 if ( be->bd_info->bi_db_close ) {
176 rc = be->bd_info->bi_db_close( be, cr );
180 if ( oi->oi_orig->bi_db_close ) {
181 be->bd_info = oi->oi_orig;
182 rc = be->bd_info->bi_db_close( be, cr );
185 be->bd_info = bi_orig;
195 slap_overinfo *oi = be->bd_info->bi_private;
196 slap_overinst *on = oi->oi_list, *next;
197 BackendInfo *bi_orig = be->bd_info;
200 be->bd_info = oi->oi_orig;
201 if ( be->bd_info->bi_db_destroy ) {
202 rc = be->bd_info->bi_db_destroy( be, cr );
205 for (; on && rc == 0; on=on->on_next) {
206 be->bd_info = &on->on_bi;
207 if ( be->bd_info->bi_db_destroy ) {
208 rc = be->bd_info->bi_db_destroy( be, cr );
214 for (next = on->on_next; on; on=next) {
219 be->bd_info = bi_orig;
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 overlay_callback_after_backover( Operation *op, slap_callback *sc, int append )
607 for ( scp = &op->o_callback; *scp != NULL; scp = &(*scp)->sc_next ) {
608 if ( (*scp)->sc_response == over_back_response ) {
609 sc->sc_next = (*scp)->sc_next;
610 (*scp)->sc_next = sc;
624 * default return code in case of missing backend function
625 * and overlay stack returning SLAP_CB_CONTINUE
627 static int op_rc[ op_last ] = {
628 LDAP_UNWILLING_TO_PERFORM, /* bind */
629 LDAP_UNWILLING_TO_PERFORM, /* unbind */
630 LDAP_UNWILLING_TO_PERFORM, /* search */
631 SLAP_CB_CONTINUE, /* compare; pass to frontend */
632 LDAP_UNWILLING_TO_PERFORM, /* modify */
633 LDAP_UNWILLING_TO_PERFORM, /* modrdn */
634 LDAP_UNWILLING_TO_PERFORM, /* add */
635 LDAP_UNWILLING_TO_PERFORM, /* delete */
636 LDAP_UNWILLING_TO_PERFORM, /* abandon */
637 LDAP_UNWILLING_TO_PERFORM, /* cancel */
638 LDAP_UNWILLING_TO_PERFORM, /* extended */
639 LDAP_SUCCESS, /* aux_operational */
640 LDAP_SUCCESS, /* aux_chk_referrals */
641 SLAP_CB_CONTINUE /* aux_chk_controls; pass to frontend */
647 slap_operation_t which,
653 int rc = SLAP_CB_CONTINUE;
655 for (; on; on=on->on_next ) {
656 func = &on->on_bi.bi_op_bind;
658 op->o_bd->bd_info = (BackendInfo *)on;
659 rc = func[which]( op, rs );
660 if ( rc != SLAP_CB_CONTINUE ) break;
663 if ( rc == SLAP_CB_BYPASS )
664 rc = SLAP_CB_CONTINUE;
666 func = &oi->oi_orig->bi_op_bind;
667 if ( func[which] && rc == SLAP_CB_CONTINUE ) {
668 op->o_bd->bd_info = oi->oi_orig;
669 rc = func[which]( op, rs );
671 /* should not fall thru this far without anything happening... */
672 if ( rc == SLAP_CB_CONTINUE ) {
676 /* The underlying backend didn't handle the request, make sure
677 * overlay cleanup is processed.
679 if ( rc == LDAP_UNWILLING_TO_PERFORM ) {
680 slap_callback *sc_next;
681 for ( ; op->o_callback && op->o_callback->sc_response !=
682 over_back_response; op->o_callback = sc_next ) {
683 sc_next = op->o_callback->sc_next;
684 if ( op->o_callback->sc_cleanup ) {
685 op->o_callback->sc_cleanup( op, rs );
696 slap_operation_t which
701 BackendDB *be = op->o_bd, db;
702 slap_callback cb = {NULL, over_back_response, NULL, NULL};
703 int rc = SLAP_CB_CONTINUE;
705 /* FIXME: used to happen for instance during abandon
706 * when global overlays are used... */
707 assert( op->o_bd != NULL );
709 oi = op->o_bd->bd_info->bi_private;
712 if ( !SLAP_ISOVERLAY( op->o_bd )) {
714 db.be_flags |= SLAP_DBFLAG_OVERLAY;
717 cb.sc_next = op->o_callback;
719 op->o_callback = &cb;
721 rc = overlay_op_walk( op, rs, which, oi, on );
724 op->o_callback = cb.sc_next;
729 over_op_bind( Operation *op, SlapReply *rs )
731 return over_op_func( op, rs, op_bind );
735 over_op_unbind( Operation *op, SlapReply *rs )
737 return over_op_func( op, rs, op_unbind );
741 over_op_search( Operation *op, SlapReply *rs )
743 return over_op_func( op, rs, op_search );
747 over_op_compare( Operation *op, SlapReply *rs )
749 return over_op_func( op, rs, op_compare );
753 over_op_modify( Operation *op, SlapReply *rs )
755 return over_op_func( op, rs, op_modify );
759 over_op_modrdn( Operation *op, SlapReply *rs )
761 return over_op_func( op, rs, op_modrdn );
765 over_op_add( Operation *op, SlapReply *rs )
767 return over_op_func( op, rs, op_add );
771 over_op_delete( Operation *op, SlapReply *rs )
773 return over_op_func( op, rs, op_delete );
777 over_op_abandon( Operation *op, SlapReply *rs )
779 return over_op_func( op, rs, op_abandon );
783 over_op_cancel( Operation *op, SlapReply *rs )
785 return over_op_func( op, rs, op_cancel );
789 over_op_extended( Operation *op, SlapReply *rs )
791 return over_op_func( op, rs, op_extended );
795 over_aux_operational( Operation *op, SlapReply *rs )
797 return over_op_func( op, rs, op_aux_operational );
801 over_aux_chk_referrals( Operation *op, SlapReply *rs )
803 return over_op_func( op, rs, op_aux_chk_referrals );
807 over_aux_chk_controls( Operation *op, SlapReply *rs )
809 return over_op_func( op, rs, op_aux_chk_controls );
819 over_connection_func(
822 enum conn_which which
828 int rc = SLAP_CB_CONTINUE;
829 BI_connection_init **func;
831 /* FIXME: used to happen for instance during abandon
832 * when global overlays are used... */
833 assert( bd != NULL );
835 oi = bd->bd_info->bi_private;
838 if ( !SLAP_ISOVERLAY( bd ) ) {
840 db.be_flags |= SLAP_DBFLAG_OVERLAY;
844 for ( ; on; on = on->on_next ) {
845 func = &on->on_bi.bi_connection_init;
846 if ( func[ which ] ) {
847 bd->bd_info = (BackendInfo *)on;
848 rc = func[ which ]( bd, conn );
849 if ( rc != SLAP_CB_CONTINUE ) break;
853 func = &oi->oi_orig->bi_connection_init;
854 if ( func[ which ] && rc == SLAP_CB_CONTINUE ) {
855 bd->bd_info = oi->oi_orig;
856 rc = func[ which ]( bd, conn );
858 /* should not fall thru this far without anything happening... */
859 if ( rc == SLAP_CB_CONTINUE ) {
860 rc = LDAP_UNWILLING_TO_PERFORM;
867 over_connection_init(
872 return over_connection_func( bd, conn, conn_init );
876 over_connection_destroy(
881 return over_connection_func( bd, conn, conn_destroy );
891 /* FIXME: check for duplicates? */
892 for ( tmp = overlays; tmp != NULL; tmp = tmp->on_next ) {
893 if ( strcmp( on->on_bi.bi_type, tmp->on_bi.bi_type ) == 0 ) {
894 Debug( LDAP_DEBUG_ANY,
895 "overlay_register(\"%s\"): "
896 "name already in use.\n",
897 on->on_bi.bi_type, 0, 0 );
901 if ( on->on_bi.bi_obsolete_names != NULL ) {
904 for ( i = 0; on->on_bi.bi_obsolete_names[ i ] != NULL; i++ ) {
905 if ( strcmp( on->on_bi.bi_obsolete_names[ i ], tmp->on_bi.bi_type ) == 0 ) {
906 Debug( LDAP_DEBUG_ANY,
907 "overlay_register(\"%s\"): "
908 "obsolete name \"%s\" already in use "
909 "by overlay \"%s\".\n",
911 on->on_bi.bi_obsolete_names[ i ],
912 tmp->on_bi.bi_type );
918 if ( tmp->on_bi.bi_obsolete_names != NULL ) {
921 for ( i = 0; tmp->on_bi.bi_obsolete_names[ i ] != NULL; i++ ) {
924 if ( strcmp( on->on_bi.bi_type, tmp->on_bi.bi_obsolete_names[ i ] ) == 0 ) {
925 Debug( LDAP_DEBUG_ANY,
926 "overlay_register(\"%s\"): "
927 "name already in use "
928 "as obsolete by overlay \"%s\".\n",
930 tmp->on_bi.bi_obsolete_names[ i ], 0 );
934 if ( on->on_bi.bi_obsolete_names != NULL ) {
935 for ( j = 0; on->on_bi.bi_obsolete_names[ j ] != NULL; j++ ) {
936 if ( strcmp( on->on_bi.bi_obsolete_names[ j ], tmp->on_bi.bi_obsolete_names[ i ] ) == 0 ) {
937 Debug( LDAP_DEBUG_ANY,
938 "overlay_register(\"%s\"): "
939 "obsolete name \"%s\" already in use "
940 "as obsolete by overlay \"%s\".\n",
942 on->on_bi.bi_obsolete_names[ j ],
943 tmp->on_bi.bi_type );
952 on->on_next = overlays;
958 * iterator on registered overlays; overlay_next( NULL ) returns the first
959 * overlay; subsequent calls with the previously returned value allow to
960 * iterate over the entire list; returns NULL when no more overlays are
977 * returns a specific registered overlay based on the type; NULL if not
982 overlay_find( const char *over_type )
984 slap_overinst *on = overlays;
986 assert( over_type != NULL );
988 for ( ; on; on = on->on_next ) {
989 if ( strcmp( on->on_bi.bi_type, over_type ) == 0 ) {
993 if ( on->on_bi.bi_obsolete_names != NULL ) {
996 for ( i = 0; on->on_bi.bi_obsolete_names[ i ] != NULL; i++ ) {
997 if ( strcmp( on->on_bi.bi_obsolete_names[ i ], over_type ) == 0 ) {
998 Debug( LDAP_DEBUG_ANY,
999 "overlay_find(\"%s\"): "
1000 "obsolete name for \"%s\".\n",
1001 on->on_bi.bi_obsolete_names[ i ],
1002 on->on_bi.bi_type, 0 );
1013 static const char overtype[] = "over";
1016 * returns TRUE (1) if the database is actually an overlay instance;
1017 * FALSE (0) otherwise.
1021 overlay_is_over( BackendDB *be )
1023 return be->bd_info->bi_type == overtype;
1027 * returns TRUE (1) if the given database is actually an overlay
1028 * instance and, somewhere in the list, contains the requested overlay;
1029 * FALSE (0) otherwise.
1033 overlay_is_inst( BackendDB *be, const char *over_type )
1037 assert( be != NULL );
1039 if ( !overlay_is_over( be ) ) {
1043 on = ((slap_overinfo *)be->bd_info->bi_private)->oi_list;
1044 for ( ; on; on = on->on_next ) {
1045 if ( strcmp( on->on_bi.bi_type, over_type ) == 0 ) {
1054 overlay_register_control( BackendDB *be, const char *oid )
1059 if ( slap_find_control_id( oid, &cid ) == LDAP_CONTROL_NOT_FOUND ) {
1063 if ( SLAP_ISGLOBALOVERLAY( be ) ) {
1066 /* add to all backends... */
1067 LDAP_STAILQ_FOREACH( bd, &backendDB, be_next ) {
1068 if ( bd == be->bd_self ) {
1072 bd->be_ctrls[ cid ] = 1;
1073 bd->be_ctrls[ SLAP_MAX_CIDS ] = 1;
1079 be->bd_self->be_ctrls[ cid ] = 1;
1080 be->bd_self->be_ctrls[ SLAP_MAX_CIDS ] = 1;
1087 overlay_destroy_one( BackendDB *be, slap_overinst *on )
1089 slap_overinfo *oi = on->on_info;
1090 slap_overinst **oidx;
1092 for ( oidx = &oi->oi_list; *oidx; oidx = &(*oidx)->on_next ) {
1093 if ( *oidx == on ) {
1094 *oidx = on->on_next;
1095 if ( on->on_bi.bi_db_destroy ) {
1096 BackendInfo *bi_orig = be->bd_info;
1097 be->bd_info = (BackendInfo *)on;
1098 on->on_bi.bi_db_destroy( be, NULL );
1099 be->bd_info = bi_orig;
1107 #ifdef SLAP_CONFIG_DELETE
1109 overlay_remove( BackendDB *be, slap_overinst *on )
1111 slap_overinfo *oi = on->on_info;
1112 slap_overinst **oidx;
1113 BackendInfo *bi_orig;
1115 /* remove overlay from oi_list an call db_close and db_destroy
1117 for ( oidx = &oi->oi_list; *oidx; oidx = &(*oidx)->on_next ) {
1118 if ( *oidx == on ) {
1119 *oidx = on->on_next;
1120 bi_orig = be->bd_info;
1121 be->bd_info = (BackendInfo *)on;
1122 if ( on->on_bi.bi_db_close ) {
1123 on->on_bi.bi_db_close( be, NULL );
1125 if ( on->on_bi.bi_db_destroy ) {
1126 on->on_bi.bi_db_destroy( be, NULL );
1128 be->bd_info = bi_orig;
1134 /* clean up after removing last overlay */
1135 if ( ! oi->oi_list )
1137 /* reset db flags and bd_info to orig */
1138 SLAP_DBFLAGS( be ) &= ~SLAP_DBFLAG_GLOBAL_OVERLAY;
1139 be->bd_info = oi->oi_orig;
1143 #endif /* SLAP_CONFIG_DELETE */
1146 overlay_insert( BackendDB *be, slap_overinst *on2, slap_overinst ***prev,
1149 slap_overinfo *oi = (slap_overinfo *)be->bd_info;
1152 on2->on_next = oi->oi_list;
1156 slap_overinst *on, *otmp1 = NULL, *otmp2;
1158 /* Since the list is in reverse order and is singly linked,
1159 * we reverse it to find the idx insertion point. Adding
1160 * on overlay at a specific point should be a pretty
1161 * infrequent occurrence.
1163 for ( on = oi->oi_list; on; on=otmp2 ) {
1164 otmp2 = on->on_next;
1165 on->on_next = otmp1;
1169 /* advance to insertion point */
1170 for ( i=0, on = otmp1; i<idx; i++ ) {
1171 otmp1 = on->on_next;
1172 on->on_next = oi->oi_list;
1176 on2->on_next = oi->oi_list;
1179 *prev = &otmp1->on_next;
1180 /* replace remainder of list */
1181 for ( on=otmp1; on; on=otmp1 ) {
1182 otmp1 = on->on_next;
1183 on->on_next = oi->oi_list;
1191 overlay_move( BackendDB *be, slap_overinst *on, int idx )
1193 slap_overinfo *oi = (slap_overinfo *)be->bd_info;
1194 slap_overinst **onp;
1196 for (onp = &oi->oi_list; *onp; onp= &(*onp)->on_next) {
1202 overlay_insert( be, on, &onp, idx );
1205 /* add an overlay to a particular backend. */
1207 overlay_config( BackendDB *be, const char *ov, int idx, BackendInfo **res, ConfigReply *cr )
1209 slap_overinst *on = NULL, *on2 = NULL, **prev;
1210 slap_overinfo *oi = NULL;
1211 BackendInfo *bi = NULL;
1216 on = overlay_find( ov );
1218 Debug( LDAP_DEBUG_ANY, "overlay \"%s\" not found\n", ov, 0, 0 );
1222 /* If this is the first overlay on this backend, set up the
1223 * overlay info structure
1225 if ( !overlay_is_over( be ) ) {
1228 /* NOTE: the first time a global overlay is configured,
1229 * frontendDB gets this flag; it is used later by overlays
1230 * to determine if they're stacked on top of the frontendDB */
1231 if ( be->bd_info == frontendDB->bd_info || SLAP_ISGLOBALOVERLAY( be ) ) {
1233 if ( on->on_bi.bi_flags & SLAPO_BFLAG_DBONLY ) {
1234 Debug( LDAP_DEBUG_ANY, "overlay_config(): "
1235 "overlay \"%s\" cannot be global.\n",
1240 } else if ( on->on_bi.bi_flags & SLAPO_BFLAG_GLOBONLY ) {
1241 Debug( LDAP_DEBUG_ANY, "overlay_config(): "
1242 "overlay \"%s\" can only be global.\n",
1247 oi = ch_malloc( sizeof( slap_overinfo ) );
1248 oi->oi_orig = be->bd_info;
1249 oi->oi_bi = *be->bd_info;
1253 SLAP_DBFLAGS( be ) |= SLAP_DBFLAG_GLOBAL_OVERLAY;
1256 /* Save a pointer to ourself in bi_private.
1258 oi->oi_bi.bi_private = oi;
1260 bi = (BackendInfo *)oi;
1262 bi->bi_type = (char *)overtype;
1264 bi->bi_db_config = over_db_config;
1265 bi->bi_db_open = over_db_open;
1266 bi->bi_db_close = over_db_close;
1267 bi->bi_db_destroy = over_db_destroy;
1269 bi->bi_op_bind = over_op_bind;
1270 bi->bi_op_unbind = over_op_unbind;
1271 bi->bi_op_search = over_op_search;
1272 bi->bi_op_compare = over_op_compare;
1273 bi->bi_op_modify = over_op_modify;
1274 bi->bi_op_modrdn = over_op_modrdn;
1275 bi->bi_op_add = over_op_add;
1276 bi->bi_op_delete = over_op_delete;
1277 bi->bi_op_abandon = over_op_abandon;
1278 bi->bi_op_cancel = over_op_cancel;
1280 bi->bi_extended = over_op_extended;
1283 * this is fine because it has the same
1284 * args of the operations; we need to rework
1285 * all the hooks to share the same args
1286 * of the operations...
1288 bi->bi_operational = over_aux_operational;
1289 bi->bi_chk_referrals = over_aux_chk_referrals;
1290 bi->bi_chk_controls = over_aux_chk_controls;
1292 /* these have specific arglists */
1293 bi->bi_entry_get_rw = over_entry_get_rw;
1294 bi->bi_entry_release_rw = over_entry_release_rw;
1295 bi->bi_access_allowed = over_access_allowed;
1296 bi->bi_acl_group = over_acl_group;
1297 bi->bi_acl_attribute = over_acl_attribute;
1299 bi->bi_connection_init = over_connection_init;
1300 bi->bi_connection_destroy = over_connection_destroy;
1305 if ( overlay_is_inst( be, ov ) ) {
1306 if ( SLAPO_SINGLE( be ) ) {
1307 Debug( LDAP_DEBUG_ANY, "overlay_config(): "
1308 "overlay \"%s\" already in list\n",
1314 oi = be->bd_info->bi_private;
1317 /* Insert new overlay into list. By default overlays are
1318 * added to head of list and executed in LIFO order.
1320 on2 = ch_calloc( 1, sizeof(slap_overinst) );
1324 prev = &oi->oi_list;
1325 /* Do we need to find the insertion point? */
1329 /* count current overlays */
1330 for ( i=0, on=oi->oi_list; on; on=on->on_next, i++ );
1332 /* are we just appending a new one? */
1336 overlay_insert( be, on2, &prev, idx );
1338 /* Any initialization needed? */
1339 if ( on2->on_bi.bi_db_init ) {
1341 be->bd_info = (BackendInfo *)on2;
1342 rc = on2->on_bi.bi_db_init( be, cr);
1343 be->bd_info = (BackendInfo *)oi;
1345 *prev = on2->on_next;