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 ca.table = on->on_bi.bi_cf_ocs->co_type;
151 rc = config_add_vals( ct, &ca );
152 if ( rc != SLAP_CONF_UNKNOWN )
156 if (on->on_bi.bi_db_config && rc == SLAP_CONF_UNKNOWN) {
157 be->bd_info = &on->on_bi;
158 rc = on->on_bi.bi_db_config( be, fname, lineno,
160 if ( rc != SLAP_CONF_UNKNOWN ) break;
163 be->bd_info = bi_orig;
164 be->be_cf_ocs = be_cf_ocs;
174 return over_db_func( be, db_open );
182 slap_overinfo *oi = be->bd_info->bi_private;
183 slap_overinst *on = oi->oi_list;
184 BackendInfo *bi_orig = be->bd_info;
187 for (; on && rc == 0; on=on->on_next) {
188 be->bd_info = &on->on_bi;
189 if ( be->bd_info->bi_db_close ) {
190 rc = be->bd_info->bi_db_close( be );
194 if ( oi->oi_orig->bi_db_close ) {
195 be->bd_info = oi->oi_orig;
196 rc = be->bd_info->bi_db_close( be );
199 be->bd_info = bi_orig;
208 slap_overinfo *oi = be->bd_info->bi_private;
209 slap_overinst *on = oi->oi_list, *next;
212 rc = over_db_func( be, db_destroy );
215 for (next = on->on_next; on; on=next) {
226 over_back_response ( Operation *op, SlapReply *rs )
228 slap_overinfo *oi = op->o_callback->sc_private;
229 slap_overinst *on = oi->oi_list;
230 int rc = SLAP_CB_CONTINUE;
231 BackendDB *be = op->o_bd, db = *op->o_bd;
233 db.be_flags |= SLAP_DBFLAG_OVERLAY;
235 for (; on; on=on->on_next ) {
236 if ( on->on_response ) {
237 db.bd_info = (BackendInfo *)on;
238 rc = on->on_response( op, rs );
239 if ( rc != SLAP_CB_CONTINUE ) break;
242 /* Bypass the remaining on_response layers, but allow
243 * normal execution to continue.
245 if ( rc == SLAP_CB_BYPASS )
246 rc = SLAP_CB_CONTINUE;
255 AttributeDescription *desc,
257 slap_access_t access,
258 AccessControlState *state,
264 BackendDB *be = op->o_bd, db;
265 int rc = SLAP_CB_CONTINUE;
267 /* FIXME: used to happen for instance during abandon
268 * when global overlays are used... */
269 assert( op->o_bd != NULL );
271 bi = op->o_bd->bd_info;
272 /* Were we invoked on the frontend? */
273 if ( !bi->bi_access_allowed ) {
274 oi = frontendDB->bd_info->bi_private;
276 oi = op->o_bd->bd_info->bi_private;
280 for ( ; on; on = on->on_next ) {
281 if ( on->on_bi.bi_access_allowed ) {
282 /* NOTE: do not copy the structure until required */
283 if ( !SLAP_ISOVERLAY( op->o_bd ) ) {
285 db.be_flags |= SLAP_DBFLAG_OVERLAY;
289 op->o_bd->bd_info = (BackendInfo *)on;
290 rc = on->on_bi.bi_access_allowed( op, e,
291 desc, val, access, state, maskp );
292 if ( rc != SLAP_CB_CONTINUE ) break;
296 if ( rc == SLAP_CB_CONTINUE ) {
297 BI_access_allowed *bi_access_allowed;
299 /* if the database structure was changed, o_bd points to a
300 * copy of the structure; put the original bd_info in place */
301 if ( SLAP_ISOVERLAY( op->o_bd ) ) {
302 op->o_bd->bd_info = oi->oi_orig;
305 if ( oi->oi_orig->bi_access_allowed ) {
306 bi_access_allowed = oi->oi_orig->bi_access_allowed;
308 bi_access_allowed = slap_access_allowed;
311 rc = bi_access_allowed( op, e,
312 desc, val, access, state, maskp );
314 /* should not fall thru this far without anything happening... */
315 if ( rc == SLAP_CB_CONTINUE ) {
316 /* access not allowed */
321 op->o_bd->bd_info = bi;
327 overlay_entry_get_ov(
331 AttributeDescription *ad,
336 slap_overinfo *oi = on->on_info;
337 BackendDB *be = op->o_bd, db;
338 BackendInfo *bi = op->o_bd->bd_info;
339 int rc = SLAP_CB_CONTINUE;
341 for ( ; on; on = on->on_next ) {
342 if ( on->on_bi.bi_entry_get_rw ) {
343 /* NOTE: do not copy the structure until required */
344 if ( !SLAP_ISOVERLAY( op->o_bd ) ) {
346 db.be_flags |= SLAP_DBFLAG_OVERLAY;
350 op->o_bd->bd_info = (BackendInfo *)on;
351 rc = on->on_bi.bi_entry_get_rw( op, dn,
353 if ( rc != SLAP_CB_CONTINUE ) break;
357 if ( rc == SLAP_CB_CONTINUE ) {
358 /* if the database structure was changed, o_bd points to a
359 * copy of the structure; put the original bd_info in place */
360 if ( SLAP_ISOVERLAY( op->o_bd ) ) {
361 op->o_bd->bd_info = oi->oi_orig;
364 if ( oi->oi_orig->bi_entry_get_rw ) {
365 rc = oi->oi_orig->bi_entry_get_rw( op, dn,
369 /* should not fall thru this far without anything happening... */
370 if ( rc == SLAP_CB_CONTINUE ) {
371 rc = LDAP_UNWILLING_TO_PERFORM;
375 op->o_bd->bd_info = bi;
385 AttributeDescription *ad,
392 assert( op->o_bd != NULL );
394 oi = op->o_bd->bd_info->bi_private;
397 return overlay_entry_get_ov( op, dn, oc, ad, rw, e, on );
401 overlay_entry_release_ov(
407 slap_overinfo *oi = on->on_info;
408 BackendDB *be = op->o_bd, db;
409 BackendInfo *bi = op->o_bd->bd_info;
410 int rc = SLAP_CB_CONTINUE;
412 for ( ; on; on = on->on_next ) {
413 if ( on->on_bi.bi_entry_release_rw ) {
414 /* NOTE: do not copy the structure until required */
415 if ( !SLAP_ISOVERLAY( op->o_bd ) ) {
417 db.be_flags |= SLAP_DBFLAG_OVERLAY;
421 op->o_bd->bd_info = (BackendInfo *)on;
422 rc = on->on_bi.bi_entry_release_rw( op, e, rw );
423 if ( rc != SLAP_CB_CONTINUE ) break;
427 if ( rc == SLAP_CB_CONTINUE ) {
428 /* if the database structure was changed, o_bd points to a
429 * copy of the structure; put the original bd_info in place */
430 if ( SLAP_ISOVERLAY( op->o_bd ) ) {
431 op->o_bd->bd_info = oi->oi_orig;
434 if ( oi->oi_orig->bi_entry_release_rw ) {
435 rc = oi->oi_orig->bi_entry_release_rw( op, e, rw );
438 /* should not fall thru this far without anything happening... */
439 if ( rc == SLAP_CB_CONTINUE ) {
445 op->o_bd->bd_info = bi;
451 over_entry_release_rw(
459 assert( op->o_bd != NULL );
461 oi = op->o_bd->bd_info->bi_private;
464 return overlay_entry_release_ov( op, e, rw, on );
471 struct berval *gr_ndn,
472 struct berval *op_ndn,
473 ObjectClass *group_oc,
474 AttributeDescription *group_at )
478 BackendInfo *bi = op->o_bd->bd_info;
479 BackendDB *be = op->o_bd, db;
480 int rc = SLAP_CB_CONTINUE;
482 /* FIXME: used to happen for instance during abandon
483 * when global overlays are used... */
484 assert( op->o_bd != NULL );
486 oi = op->o_bd->bd_info->bi_private;
489 for ( ; on; on = on->on_next ) {
490 if ( on->on_bi.bi_acl_group ) {
491 /* NOTE: do not copy the structure until required */
492 if ( !SLAP_ISOVERLAY( op->o_bd ) ) {
494 db.be_flags |= SLAP_DBFLAG_OVERLAY;
498 op->o_bd->bd_info = (BackendInfo *)on;
499 rc = on->on_bi.bi_acl_group( op, e,
500 gr_ndn, op_ndn, group_oc, group_at );
501 if ( rc != SLAP_CB_CONTINUE ) break;
505 if ( rc == SLAP_CB_CONTINUE ) {
506 BI_acl_group *bi_acl_group;
508 /* if the database structure was changed, o_bd points to a
509 * copy of the structure; put the original bd_info in place */
510 if ( SLAP_ISOVERLAY( op->o_bd ) ) {
511 op->o_bd->bd_info = oi->oi_orig;
514 if ( oi->oi_orig->bi_acl_group ) {
515 bi_acl_group = oi->oi_orig->bi_acl_group;
517 bi_acl_group = backend_group;
520 rc = bi_acl_group( op, e,
521 gr_ndn, op_ndn, group_oc, group_at );
523 /* should not fall thru this far without anything happening... */
524 if ( rc == SLAP_CB_CONTINUE ) {
525 /* access not allowed */
530 op->o_bd->bd_info = bi;
539 struct berval *entry_ndn,
540 AttributeDescription *entry_at,
542 slap_access_t access )
546 BackendInfo *bi = op->o_bd->bd_info;
547 BackendDB *be = op->o_bd, db;
548 int rc = SLAP_CB_CONTINUE;
550 /* FIXME: used to happen for instance during abandon
551 * when global overlays are used... */
552 assert( op->o_bd != NULL );
554 oi = op->o_bd->bd_info->bi_private;
557 for ( ; on; on = on->on_next ) {
558 if ( on->on_bi.bi_acl_attribute ) {
559 /* NOTE: do not copy the structure until required */
560 if ( !SLAP_ISOVERLAY( op->o_bd ) ) {
562 db.be_flags |= SLAP_DBFLAG_OVERLAY;
566 op->o_bd->bd_info = (BackendInfo *)on;
567 rc = on->on_bi.bi_acl_attribute( op, target,
568 entry_ndn, entry_at, vals, access );
569 if ( rc != SLAP_CB_CONTINUE ) break;
573 if ( rc == SLAP_CB_CONTINUE ) {
574 BI_acl_attribute *bi_acl_attribute;
576 /* if the database structure was changed, o_bd points to a
577 * copy of the structure; put the original bd_info in place */
578 if ( SLAP_ISOVERLAY( op->o_bd ) ) {
579 op->o_bd->bd_info = oi->oi_orig;
582 if ( oi->oi_orig->bi_acl_attribute ) {
583 bi_acl_attribute = oi->oi_orig->bi_acl_attribute;
585 bi_acl_attribute = backend_attribute;
588 rc = bi_acl_attribute( op, target,
589 entry_ndn, entry_at, vals, access );
591 /* should not fall thru this far without anything happening... */
592 if ( rc == SLAP_CB_CONTINUE ) {
593 /* access not allowed */
598 op->o_bd->bd_info = bi;
604 * default return code in case of missing backend function
605 * and overlay stack returning SLAP_CB_CONTINUE
607 static int op_rc[ op_last ] = {
608 LDAP_UNWILLING_TO_PERFORM, /* bind */
609 LDAP_UNWILLING_TO_PERFORM, /* unbind */
610 LDAP_UNWILLING_TO_PERFORM, /* search */
611 SLAP_CB_CONTINUE, /* compare; pass to frontend */
612 LDAP_UNWILLING_TO_PERFORM, /* modify */
613 LDAP_UNWILLING_TO_PERFORM, /* modrdn */
614 LDAP_UNWILLING_TO_PERFORM, /* add */
615 LDAP_UNWILLING_TO_PERFORM, /* delete */
616 LDAP_UNWILLING_TO_PERFORM, /* abandon */
617 LDAP_UNWILLING_TO_PERFORM, /* cancel */
618 LDAP_UNWILLING_TO_PERFORM, /* extended */
619 LDAP_SUCCESS, /* aux_operational */
620 LDAP_SUCCESS, /* aux_chk_referrals */
621 SLAP_CB_CONTINUE /* aux_chk_controls; pass to frontend */
627 slap_operation_t which,
633 int rc = SLAP_CB_CONTINUE;
635 for (; on; on=on->on_next ) {
636 func = &on->on_bi.bi_op_bind;
638 op->o_bd->bd_info = (BackendInfo *)on;
639 rc = func[which]( op, rs );
640 if ( rc != SLAP_CB_CONTINUE ) break;
643 if ( rc == SLAP_CB_BYPASS )
644 rc = SLAP_CB_CONTINUE;
646 func = &oi->oi_orig->bi_op_bind;
647 if ( func[which] && rc == SLAP_CB_CONTINUE ) {
648 op->o_bd->bd_info = oi->oi_orig;
649 rc = func[which]( op, rs );
651 /* should not fall thru this far without anything happening... */
652 if ( rc == SLAP_CB_CONTINUE ) {
656 /* The underlying backend didn't handle the request, make sure
657 * overlay cleanup is processed.
659 if ( rc == LDAP_UNWILLING_TO_PERFORM ) {
660 slap_callback *sc_next;
661 for ( ; op->o_callback && op->o_callback->sc_response !=
662 over_back_response; op->o_callback = sc_next ) {
663 sc_next = op->o_callback->sc_next;
664 if ( op->o_callback->sc_cleanup ) {
665 op->o_callback->sc_cleanup( op, rs );
676 slap_operation_t which
681 BackendDB *be = op->o_bd, db;
682 slap_callback cb = {NULL, over_back_response, NULL, NULL};
683 int rc = SLAP_CB_CONTINUE;
685 /* FIXME: used to happen for instance during abandon
686 * when global overlays are used... */
687 assert( op->o_bd != NULL );
689 oi = op->o_bd->bd_info->bi_private;
692 if ( !SLAP_ISOVERLAY( op->o_bd )) {
694 db.be_flags |= SLAP_DBFLAG_OVERLAY;
697 cb.sc_next = op->o_callback;
699 op->o_callback = &cb;
701 rc = overlay_op_walk( op, rs, which, oi, on );
704 op->o_callback = cb.sc_next;
709 over_op_bind( Operation *op, SlapReply *rs )
711 return over_op_func( op, rs, op_bind );
715 over_op_unbind( Operation *op, SlapReply *rs )
717 return over_op_func( op, rs, op_unbind );
721 over_op_search( Operation *op, SlapReply *rs )
723 return over_op_func( op, rs, op_search );
727 over_op_compare( Operation *op, SlapReply *rs )
729 return over_op_func( op, rs, op_compare );
733 over_op_modify( Operation *op, SlapReply *rs )
735 return over_op_func( op, rs, op_modify );
739 over_op_modrdn( Operation *op, SlapReply *rs )
741 return over_op_func( op, rs, op_modrdn );
745 over_op_add( Operation *op, SlapReply *rs )
747 return over_op_func( op, rs, op_add );
751 over_op_delete( Operation *op, SlapReply *rs )
753 return over_op_func( op, rs, op_delete );
757 over_op_abandon( Operation *op, SlapReply *rs )
759 return over_op_func( op, rs, op_abandon );
763 over_op_cancel( Operation *op, SlapReply *rs )
765 return over_op_func( op, rs, op_cancel );
769 over_op_extended( Operation *op, SlapReply *rs )
771 return over_op_func( op, rs, op_extended );
775 over_aux_operational( Operation *op, SlapReply *rs )
777 return over_op_func( op, rs, op_aux_operational );
781 over_aux_chk_referrals( Operation *op, SlapReply *rs )
783 return over_op_func( op, rs, op_aux_chk_referrals );
787 over_aux_chk_controls( Operation *op, SlapReply *rs )
789 return over_op_func( op, rs, op_aux_chk_controls );
799 over_connection_func(
802 enum conn_which which
808 int rc = SLAP_CB_CONTINUE;
809 BI_connection_init **func;
811 /* FIXME: used to happen for instance during abandon
812 * when global overlays are used... */
813 assert( bd != NULL );
815 oi = bd->bd_info->bi_private;
818 if ( !SLAP_ISOVERLAY( bd ) ) {
820 db.be_flags |= SLAP_DBFLAG_OVERLAY;
824 for ( ; on; on = on->on_next ) {
825 func = &on->on_bi.bi_connection_init;
826 if ( func[ which ] ) {
827 bd->bd_info = (BackendInfo *)on;
828 rc = func[ which ]( bd, conn );
829 if ( rc != SLAP_CB_CONTINUE ) break;
833 func = &oi->oi_orig->bi_connection_init;
834 if ( func[ which ] && rc == SLAP_CB_CONTINUE ) {
835 bd->bd_info = oi->oi_orig;
836 rc = func[ which ]( bd, conn );
838 /* should not fall thru this far without anything happening... */
839 if ( rc == SLAP_CB_CONTINUE ) {
840 rc = LDAP_UNWILLING_TO_PERFORM;
847 over_connection_init(
852 return over_connection_func( bd, conn, conn_init );
856 over_connection_destroy(
861 return over_connection_func( bd, conn, conn_destroy );
871 /* FIXME: check for duplicates? */
872 for ( tmp = overlays; tmp != NULL; tmp = tmp->on_next ) {
873 if ( strcmp( on->on_bi.bi_type, tmp->on_bi.bi_type ) == 0 ) {
874 Debug( LDAP_DEBUG_ANY,
875 "overlay_register(\"%s\"): "
876 "name already in use.\n",
877 on->on_bi.bi_type, 0, 0 );
881 if ( on->on_bi.bi_obsolete_names != NULL ) {
884 for ( i = 0; on->on_bi.bi_obsolete_names[ i ] != NULL; i++ ) {
885 if ( strcmp( on->on_bi.bi_obsolete_names[ i ], tmp->on_bi.bi_type ) == 0 ) {
886 Debug( LDAP_DEBUG_ANY,
887 "overlay_register(\"%s\"): "
888 "obsolete name \"%s\" already in use "
889 "by overlay \"%s\".\n",
891 on->on_bi.bi_obsolete_names[ i ],
892 tmp->on_bi.bi_type );
898 if ( tmp->on_bi.bi_obsolete_names != NULL ) {
901 for ( i = 0; tmp->on_bi.bi_obsolete_names[ i ] != NULL; i++ ) {
904 if ( strcmp( on->on_bi.bi_type, tmp->on_bi.bi_obsolete_names[ i ] ) == 0 ) {
905 Debug( LDAP_DEBUG_ANY,
906 "overlay_register(\"%s\"): "
907 "name already in use "
908 "as obsolete by overlay \"%s\".\n",
910 tmp->on_bi.bi_obsolete_names[ i ], 0 );
914 if ( on->on_bi.bi_obsolete_names != NULL ) {
915 for ( j = 0; on->on_bi.bi_obsolete_names[ j ] != NULL; j++ ) {
916 if ( strcmp( on->on_bi.bi_obsolete_names[ j ], tmp->on_bi.bi_obsolete_names[ i ] ) == 0 ) {
917 Debug( LDAP_DEBUG_ANY,
918 "overlay_register(\"%s\"): "
919 "obsolete name \"%s\" already in use "
920 "as obsolete by overlay \"%s\".\n",
922 on->on_bi.bi_obsolete_names[ j ],
923 tmp->on_bi.bi_type );
932 on->on_next = overlays;
938 * iterator on registered overlays; overlay_next( NULL ) returns the first
939 * overlay; subsequent calls with the previously returned value allow to
940 * iterate over the entire list; returns NULL when no more overlays are
957 * returns a specific registered overlay based on the type; NULL if not
962 overlay_find( const char *over_type )
964 slap_overinst *on = overlays;
966 assert( over_type != NULL );
968 for ( ; on; on = on->on_next ) {
969 if ( strcmp( on->on_bi.bi_type, over_type ) == 0 ) {
973 if ( on->on_bi.bi_obsolete_names != NULL ) {
976 for ( i = 0; on->on_bi.bi_obsolete_names[ i ] != NULL; i++ ) {
977 if ( strcmp( on->on_bi.bi_obsolete_names[ i ], over_type ) == 0 ) {
978 Debug( LDAP_DEBUG_ANY,
979 "overlay_find(\"%s\"): "
980 "obsolete name for \"%s\".\n",
981 on->on_bi.bi_obsolete_names[ i ],
982 on->on_bi.bi_type, 0 );
993 static const char overtype[] = "over";
996 * returns TRUE (1) if the database is actually an overlay instance;
997 * FALSE (0) otherwise.
1001 overlay_is_over( BackendDB *be )
1003 return be->bd_info->bi_type == overtype;
1007 * returns TRUE (1) if the given database is actually an overlay
1008 * instance and, somewhere in the list, contains the requested overlay;
1009 * FALSE (0) otherwise.
1013 overlay_is_inst( BackendDB *be, const char *over_type )
1017 assert( be != NULL );
1019 if ( !overlay_is_over( be ) ) {
1023 on = ((slap_overinfo *)be->bd_info->bi_private)->oi_list;
1024 for ( ; on; on = on->on_next ) {
1025 if ( strcmp( on->on_bi.bi_type, over_type ) == 0 ) {
1034 overlay_register_control( BackendDB *be, const char *oid )
1039 if ( slap_find_control_id( oid, &cid ) == LDAP_CONTROL_NOT_FOUND ) {
1043 if ( SLAP_ISGLOBALOVERLAY( be ) ) {
1046 /* add to all backends... */
1047 LDAP_STAILQ_FOREACH( bd, &backendDB, be_next ) {
1052 bd->be_ctrls[ cid ] = 1;
1053 bd->be_ctrls[ SLAP_MAX_CIDS ] = 1;
1059 be->be_ctrls[ cid ] = 1;
1060 be->be_ctrls[ SLAP_MAX_CIDS ] = 1;
1067 overlay_destroy_one( BackendDB *be, slap_overinst *on )
1069 slap_overinfo *oi = on->on_info;
1070 slap_overinst **oidx;
1072 for ( oidx = &oi->oi_list; *oidx; oidx = &(*oidx)->on_next ) {
1073 if ( *oidx == on ) {
1074 *oidx = on->on_next;
1075 if ( on->on_bi.bi_db_destroy ) {
1076 BackendInfo *bi_orig = be->bd_info;
1077 be->bd_info = (BackendInfo *)on;
1078 on->on_bi.bi_db_destroy( be );
1079 be->bd_info = bi_orig;
1088 overlay_insert( BackendDB *be, slap_overinst *on2, slap_overinst ***prev,
1091 slap_overinfo *oi = (slap_overinfo *)be->bd_info;
1094 on2->on_next = oi->oi_list;
1098 slap_overinst *on, *otmp1 = NULL, *otmp2;
1100 /* Since the list is in reverse order and is singly linked,
1101 * we reverse it to find the idx insertion point. Adding
1102 * on overlay at a specific point should be a pretty
1103 * infrequent occurrence.
1105 for ( on = oi->oi_list; on; on=otmp2 ) {
1106 otmp2 = on->on_next;
1107 on->on_next = otmp1;
1111 /* advance to insertion point */
1112 for ( i=0, on = otmp1; i<idx; i++ ) {
1113 otmp1 = on->on_next;
1114 on->on_next = oi->oi_list;
1118 on2->on_next = oi->oi_list;
1121 *prev = &otmp1->on_next;
1122 /* replace remainder of list */
1123 for ( on=otmp1; on; on=otmp1 ) {
1124 otmp1 = on->on_next;
1125 on->on_next = oi->oi_list;
1133 overlay_move( BackendDB *be, slap_overinst *on, int idx )
1135 slap_overinfo *oi = (slap_overinfo *)be->bd_info;
1136 slap_overinst **onp;
1138 for (onp = &oi->oi_list; *onp; onp= &(*onp)->on_next) {
1144 overlay_insert( be, on, &onp, idx );
1147 /* add an overlay to a particular backend. */
1149 overlay_config( BackendDB *be, const char *ov, int idx, BackendInfo **res )
1151 slap_overinst *on = NULL, *on2 = NULL, **prev;
1152 slap_overinfo *oi = NULL;
1153 BackendInfo *bi = NULL;
1158 on = overlay_find( ov );
1160 Debug( LDAP_DEBUG_ANY, "overlay \"%s\" not found\n", ov, 0, 0 );
1164 /* If this is the first overlay on this backend, set up the
1165 * overlay info structure
1167 if ( !overlay_is_over( be ) ) {
1170 /* NOTE: the first time a global overlay is configured,
1171 * frontendDB gets this flag; it is used later by overlays
1172 * to determine if they're stacked on top of the frontendDB */
1173 if ( be->bd_info == frontendDB->bd_info || SLAP_ISGLOBALOVERLAY( be ) ) {
1175 if ( on->on_bi.bi_flags & SLAPO_BFLAG_DBONLY ) {
1176 Debug( LDAP_DEBUG_ANY, "overlay_config(): "
1177 "overlay \"%s\" cannot be global.\n",
1182 } else if ( on->on_bi.bi_flags & SLAPO_BFLAG_GLOBONLY ) {
1183 Debug( LDAP_DEBUG_ANY, "overlay_config(): "
1184 "overlay \"%s\" can only be global.\n",
1189 oi = ch_malloc( sizeof( slap_overinfo ) );
1190 oi->oi_orig = be->bd_info;
1191 oi->oi_bi = *be->bd_info;
1195 SLAP_DBFLAGS( be ) |= SLAP_DBFLAG_GLOBAL_OVERLAY;
1198 /* Save a pointer to ourself in bi_private.
1200 oi->oi_bi.bi_private = oi;
1202 bi = (BackendInfo *)oi;
1204 bi->bi_type = (char *)overtype;
1206 bi->bi_db_config = over_db_config;
1207 bi->bi_db_open = over_db_open;
1208 bi->bi_db_close = over_db_close;
1209 bi->bi_db_destroy = over_db_destroy;
1211 bi->bi_op_bind = over_op_bind;
1212 bi->bi_op_unbind = over_op_unbind;
1213 bi->bi_op_search = over_op_search;
1214 bi->bi_op_compare = over_op_compare;
1215 bi->bi_op_modify = over_op_modify;
1216 bi->bi_op_modrdn = over_op_modrdn;
1217 bi->bi_op_add = over_op_add;
1218 bi->bi_op_delete = over_op_delete;
1219 bi->bi_op_abandon = over_op_abandon;
1220 bi->bi_op_cancel = over_op_cancel;
1222 bi->bi_extended = over_op_extended;
1225 * this is fine because it has the same
1226 * args of the operations; we need to rework
1227 * all the hooks to share the same args
1228 * of the operations...
1230 bi->bi_operational = over_aux_operational;
1231 bi->bi_chk_referrals = over_aux_chk_referrals;
1232 bi->bi_chk_controls = over_aux_chk_controls;
1234 /* these have specific arglists */
1235 bi->bi_entry_get_rw = over_entry_get_rw;
1236 bi->bi_entry_release_rw = over_entry_release_rw;
1237 bi->bi_access_allowed = over_access_allowed;
1238 bi->bi_acl_group = over_acl_group;
1239 bi->bi_acl_attribute = over_acl_attribute;
1241 bi->bi_connection_init = over_connection_init;
1242 bi->bi_connection_destroy = over_connection_destroy;
1247 if ( overlay_is_inst( be, ov ) ) {
1248 Debug( LDAP_DEBUG_ANY, "overlay_config(): "
1249 "overlay \"%s\" already in list\n",
1251 if ( SLAPO_SINGLE( be ) ) {
1256 oi = be->bd_info->bi_private;
1259 /* Insert new overlay into list. By default overlays are
1260 * added to head of list and executed in LIFO order.
1262 on2 = ch_calloc( 1, sizeof(slap_overinst) );
1266 prev = &oi->oi_list;
1267 /* Do we need to find the insertion point? */
1271 /* count current overlays */
1272 for ( i=0, on=oi->oi_list; on; on=on->on_next, i++ );
1274 /* are we just appending a new one? */
1278 overlay_insert( be, on2, &prev, idx );
1280 /* Any initialization needed? */
1281 if ( on2->on_bi.bi_db_init ) {
1283 be->bd_info = (BackendInfo *)on2;
1284 rc = on2->on_bi.bi_db_init( be );
1285 be->bd_info = (BackendInfo *)oi;
1287 *prev = on2->on_next;