1 /* backover.c - backend overlay routines */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2003-2015 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 )
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( be != NULL );
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 )
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( be != NULL );
558 for ( ; on; on = on->on_next ) {
559 if ( on->on_bi.bi_acl_attribute ) {
560 /* NOTE: do not copy the structure until required */
561 if ( !SLAP_ISOVERLAY( op->o_bd ) ) {
563 db.be_flags |= SLAP_DBFLAG_OVERLAY;
567 op->o_bd->bd_info = (BackendInfo *)on;
568 rc = on->on_bi.bi_acl_attribute( op, target,
569 entry_ndn, entry_at, vals, access );
570 if ( rc != SLAP_CB_CONTINUE ) break;
574 if ( rc == SLAP_CB_CONTINUE ) {
575 BI_acl_attribute *bi_acl_attribute;
577 /* if the database structure was changed, o_bd points to a
578 * copy of the structure; put the original bd_info in place */
579 if ( SLAP_ISOVERLAY( op->o_bd ) ) {
580 op->o_bd->bd_info = oi->oi_orig;
583 if ( oi->oi_orig->bi_acl_attribute ) {
584 bi_acl_attribute = oi->oi_orig->bi_acl_attribute;
586 bi_acl_attribute = backend_attribute;
589 rc = bi_acl_attribute( op, target,
590 entry_ndn, entry_at, vals, access );
592 /* should not fall thru this far without anything happening... */
593 if ( rc == SLAP_CB_CONTINUE ) {
594 /* access not allowed */
599 op->o_bd->bd_info = bi;
605 overlay_callback_after_backover( Operation *op, slap_callback *sc, int append )
609 for ( scp = &op->o_callback; *scp != NULL; scp = &(*scp)->sc_next ) {
610 if ( (*scp)->sc_response == over_back_response ) {
611 sc->sc_next = (*scp)->sc_next;
612 (*scp)->sc_next = sc;
626 * default return code in case of missing backend function
627 * and overlay stack returning SLAP_CB_CONTINUE
629 static int op_rc[ op_last ] = {
630 LDAP_UNWILLING_TO_PERFORM, /* bind */
631 LDAP_UNWILLING_TO_PERFORM, /* unbind */
632 LDAP_UNWILLING_TO_PERFORM, /* search */
633 SLAP_CB_CONTINUE, /* compare; pass to frontend */
634 LDAP_UNWILLING_TO_PERFORM, /* modify */
635 LDAP_UNWILLING_TO_PERFORM, /* modrdn */
636 LDAP_UNWILLING_TO_PERFORM, /* add */
637 LDAP_UNWILLING_TO_PERFORM, /* delete */
638 LDAP_UNWILLING_TO_PERFORM, /* abandon */
639 LDAP_UNWILLING_TO_PERFORM, /* cancel */
640 LDAP_UNWILLING_TO_PERFORM, /* extended */
641 LDAP_SUCCESS, /* aux_operational */
642 LDAP_SUCCESS, /* aux_chk_referrals */
643 SLAP_CB_CONTINUE /* aux_chk_controls; pass to frontend */
649 slap_operation_t which,
655 int rc = SLAP_CB_CONTINUE;
657 for (; on; on=on->on_next ) {
658 func = &on->on_bi.bi_op_bind;
660 op->o_bd->bd_info = (BackendInfo *)on;
661 rc = func[which]( op, rs );
662 if ( rc != SLAP_CB_CONTINUE ) break;
665 if ( rc == SLAP_CB_BYPASS )
666 rc = SLAP_CB_CONTINUE;
668 /* if an overlay halted processing, make sure
669 * any previously set cleanup handlers are run
671 if ( rc != SLAP_CB_CONTINUE )
674 func = &oi->oi_orig->bi_op_bind;
676 op->o_bd->bd_info = oi->oi_orig;
677 rc = func[which]( op, rs );
679 /* should not fall thru this far without anything happening... */
680 if ( rc == SLAP_CB_CONTINUE ) {
684 /* The underlying backend didn't handle the request, make sure
685 * overlay cleanup is processed.
687 if ( rc == LDAP_UNWILLING_TO_PERFORM ) {
688 slap_callback *sc_next;
690 for ( ; op->o_callback && op->o_callback->sc_response !=
691 over_back_response; op->o_callback = sc_next ) {
692 sc_next = op->o_callback->sc_next;
693 if ( op->o_callback->sc_cleanup ) {
694 op->o_callback->sc_cleanup( op, rs );
705 slap_operation_t which
710 BackendDB *be = op->o_bd, db;
711 slap_callback cb = {NULL, over_back_response, NULL, NULL}, **sc;
712 int rc = SLAP_CB_CONTINUE;
714 /* FIXME: used to happen for instance during abandon
715 * when global overlays are used... */
716 assert( op->o_bd != NULL );
718 oi = op->o_bd->bd_info->bi_private;
721 if ( !SLAP_ISOVERLAY( op->o_bd )) {
723 db.be_flags |= SLAP_DBFLAG_OVERLAY;
726 cb.sc_next = op->o_callback;
728 op->o_callback = &cb;
730 rc = overlay_op_walk( op, rs, which, oi, on );
731 for ( sc = &op->o_callback; *sc; sc = &(*sc)->sc_next ) {
743 over_op_bind( Operation *op, SlapReply *rs )
745 return over_op_func( op, rs, op_bind );
749 over_op_unbind( Operation *op, SlapReply *rs )
751 return over_op_func( op, rs, op_unbind );
755 over_op_search( Operation *op, SlapReply *rs )
757 return over_op_func( op, rs, op_search );
761 over_op_compare( Operation *op, SlapReply *rs )
763 return over_op_func( op, rs, op_compare );
767 over_op_modify( Operation *op, SlapReply *rs )
769 return over_op_func( op, rs, op_modify );
773 over_op_modrdn( Operation *op, SlapReply *rs )
775 return over_op_func( op, rs, op_modrdn );
779 over_op_add( Operation *op, SlapReply *rs )
781 return over_op_func( op, rs, op_add );
785 over_op_delete( Operation *op, SlapReply *rs )
787 return over_op_func( op, rs, op_delete );
791 over_op_abandon( Operation *op, SlapReply *rs )
793 return over_op_func( op, rs, op_abandon );
797 over_op_cancel( Operation *op, SlapReply *rs )
799 return over_op_func( op, rs, op_cancel );
803 over_op_extended( Operation *op, SlapReply *rs )
805 return over_op_func( op, rs, op_extended );
809 over_aux_operational( Operation *op, SlapReply *rs )
811 return over_op_func( op, rs, op_aux_operational );
815 over_aux_chk_referrals( Operation *op, SlapReply *rs )
817 return over_op_func( op, rs, op_aux_chk_referrals );
821 over_aux_chk_controls( Operation *op, SlapReply *rs )
823 return over_op_func( op, rs, op_aux_chk_controls );
833 over_connection_func(
836 enum conn_which which
842 int rc = SLAP_CB_CONTINUE;
843 BI_connection_init **func;
845 /* FIXME: used to happen for instance during abandon
846 * when global overlays are used... */
847 assert( bd != NULL );
849 oi = bd->bd_info->bi_private;
852 if ( !SLAP_ISOVERLAY( bd ) ) {
854 db.be_flags |= SLAP_DBFLAG_OVERLAY;
858 for ( ; on; on = on->on_next ) {
859 func = &on->on_bi.bi_connection_init;
860 if ( func[ which ] ) {
861 bd->bd_info = (BackendInfo *)on;
862 rc = func[ which ]( bd, conn );
863 if ( rc != SLAP_CB_CONTINUE ) break;
867 func = &oi->oi_orig->bi_connection_init;
868 if ( func[ which ] && rc == SLAP_CB_CONTINUE ) {
869 bd->bd_info = oi->oi_orig;
870 rc = func[ which ]( bd, conn );
872 /* should not fall thru this far without anything happening... */
873 if ( rc == SLAP_CB_CONTINUE ) {
874 rc = LDAP_UNWILLING_TO_PERFORM;
881 over_connection_init(
886 return over_connection_func( bd, conn, conn_init );
890 over_connection_destroy(
895 return over_connection_func( bd, conn, conn_destroy );
905 /* FIXME: check for duplicates? */
906 for ( tmp = overlays; tmp != NULL; tmp = tmp->on_next ) {
907 if ( strcmp( on->on_bi.bi_type, tmp->on_bi.bi_type ) == 0 ) {
908 Debug( LDAP_DEBUG_ANY,
909 "overlay_register(\"%s\"): "
910 "name already in use.\n",
911 on->on_bi.bi_type, 0, 0 );
915 if ( on->on_bi.bi_obsolete_names != NULL ) {
918 for ( i = 0; on->on_bi.bi_obsolete_names[ i ] != NULL; i++ ) {
919 if ( strcmp( on->on_bi.bi_obsolete_names[ i ], tmp->on_bi.bi_type ) == 0 ) {
920 Debug( LDAP_DEBUG_ANY,
921 "overlay_register(\"%s\"): "
922 "obsolete name \"%s\" already in use "
923 "by overlay \"%s\".\n",
925 on->on_bi.bi_obsolete_names[ i ],
926 tmp->on_bi.bi_type );
932 if ( tmp->on_bi.bi_obsolete_names != NULL ) {
935 for ( i = 0; tmp->on_bi.bi_obsolete_names[ i ] != NULL; i++ ) {
938 if ( strcmp( on->on_bi.bi_type, tmp->on_bi.bi_obsolete_names[ i ] ) == 0 ) {
939 Debug( LDAP_DEBUG_ANY,
940 "overlay_register(\"%s\"): "
941 "name already in use "
942 "as obsolete by overlay \"%s\".\n",
944 tmp->on_bi.bi_obsolete_names[ i ], 0 );
948 if ( on->on_bi.bi_obsolete_names != NULL ) {
949 for ( j = 0; on->on_bi.bi_obsolete_names[ j ] != NULL; j++ ) {
950 if ( strcmp( on->on_bi.bi_obsolete_names[ j ], tmp->on_bi.bi_obsolete_names[ i ] ) == 0 ) {
951 Debug( LDAP_DEBUG_ANY,
952 "overlay_register(\"%s\"): "
953 "obsolete name \"%s\" already in use "
954 "as obsolete by overlay \"%s\".\n",
956 on->on_bi.bi_obsolete_names[ j ],
957 tmp->on_bi.bi_type );
966 on->on_next = overlays;
972 * iterator on registered overlays; overlay_next( NULL ) returns the first
973 * overlay; subsequent calls with the previously returned value allow to
974 * iterate over the entire list; returns NULL when no more overlays are
991 * returns a specific registered overlay based on the type; NULL if not
996 overlay_find( const char *over_type )
998 slap_overinst *on = overlays;
1000 assert( over_type != NULL );
1002 for ( ; on; on = on->on_next ) {
1003 if ( strcmp( on->on_bi.bi_type, over_type ) == 0 ) {
1007 if ( on->on_bi.bi_obsolete_names != NULL ) {
1010 for ( i = 0; on->on_bi.bi_obsolete_names[ i ] != NULL; i++ ) {
1011 if ( strcmp( on->on_bi.bi_obsolete_names[ i ], over_type ) == 0 ) {
1012 Debug( LDAP_DEBUG_ANY,
1013 "overlay_find(\"%s\"): "
1014 "obsolete name for \"%s\".\n",
1015 on->on_bi.bi_obsolete_names[ i ],
1016 on->on_bi.bi_type, 0 );
1027 static const char overtype[] = "over";
1030 * returns TRUE (1) if the database is actually an overlay instance;
1031 * FALSE (0) otherwise.
1035 overlay_is_over( BackendDB *be )
1037 return be->bd_info->bi_type == overtype;
1041 * returns TRUE (1) if the given database is actually an overlay
1042 * instance and, somewhere in the list, contains the requested overlay;
1043 * FALSE (0) otherwise.
1047 overlay_is_inst( BackendDB *be, const char *over_type )
1051 assert( be != NULL );
1053 if ( !overlay_is_over( be ) ) {
1057 on = ((slap_overinfo *)be->bd_info->bi_private)->oi_list;
1058 for ( ; on; on = on->on_next ) {
1059 if ( strcmp( on->on_bi.bi_type, over_type ) == 0 ) {
1068 overlay_register_control( BackendDB *be, const char *oid )
1073 if ( slap_find_control_id( oid, &cid ) == LDAP_CONTROL_NOT_FOUND ) {
1077 if ( SLAP_ISGLOBALOVERLAY( be ) ) {
1080 /* add to all backends... */
1081 LDAP_STAILQ_FOREACH( bd, &backendDB, be_next ) {
1082 if ( bd == be->bd_self ) {
1086 /* overlays can be instanciated multiple times, use
1087 * be_ctrls[ cid ] as an instance counter, so that the
1088 * overlay's controls are only really disabled after the
1089 * last instance called overlay_register_control() */
1090 bd->be_ctrls[ cid ]++;
1091 bd->be_ctrls[ SLAP_MAX_CIDS ] = 1;
1097 /* overlays can be instanciated multiple times, use
1098 * be_ctrls[ cid ] as an instance counter, so that the
1099 * overlay's controls are only really unregistered after the
1100 * last instance called overlay_register_control() */
1101 be->bd_self->be_ctrls[ cid ]++;
1102 be->bd_self->be_ctrls[ SLAP_MAX_CIDS ] = 1;
1108 #ifdef SLAP_CONFIG_DELETE
1110 overlay_unregister_control( BackendDB *be, const char *oid )
1115 if ( slap_find_control_id( oid, &cid ) == LDAP_CONTROL_NOT_FOUND ) {
1119 if ( SLAP_ISGLOBALOVERLAY( be ) ) {
1122 /* remove from all backends... */
1123 LDAP_STAILQ_FOREACH( bd, &backendDB, be_next ) {
1124 if ( bd == be->bd_self ) {
1128 bd->be_ctrls[ cid ]--;
1133 be->bd_self->be_ctrls[ cid ]--;
1136 #endif /* SLAP_CONFIG_DELETE */
1139 overlay_destroy_one( BackendDB *be, slap_overinst *on )
1141 slap_overinfo *oi = on->on_info;
1142 slap_overinst **oidx;
1144 for ( oidx = &oi->oi_list; *oidx; oidx = &(*oidx)->on_next ) {
1145 if ( *oidx == on ) {
1146 *oidx = on->on_next;
1147 if ( on->on_bi.bi_db_destroy ) {
1148 BackendInfo *bi_orig = be->bd_info;
1149 be->bd_info = (BackendInfo *)on;
1150 on->on_bi.bi_db_destroy( be, NULL );
1151 be->bd_info = bi_orig;
1159 #ifdef SLAP_CONFIG_DELETE
1160 typedef struct ov_remove_ctx {
1166 overlay_remove_cb( Operation *op, SlapReply *rs )
1168 ov_remove_ctx *rm_ctx = (ov_remove_ctx*) op->o_callback->sc_private;
1169 BackendInfo *bi_orig = rm_ctx->be->bd_info;
1171 rm_ctx->be->bd_info = (BackendInfo*) rm_ctx->on;
1173 if ( rm_ctx->on->on_bi.bi_db_close ) {
1174 rm_ctx->on->on_bi.bi_db_close( rm_ctx->be, NULL );
1176 if ( rm_ctx->on->on_bi.bi_db_destroy ) {
1177 rm_ctx->on->on_bi.bi_db_destroy( rm_ctx->be, NULL );
1180 /* clean up after removing last overlay */
1181 if ( ! rm_ctx->on->on_info->oi_list ) {
1182 /* reset db flags and bd_info to orig */
1183 SLAP_DBFLAGS( rm_ctx->be ) &= ~SLAP_DBFLAG_GLOBAL_OVERLAY;
1184 rm_ctx->be->bd_info = rm_ctx->on->on_info->oi_orig;
1185 ch_free(rm_ctx->on->on_info);
1187 rm_ctx->be->bd_info = bi_orig;
1190 op->o_tmpfree(rm_ctx, op->o_tmpmemctx);
1191 return SLAP_CB_CONTINUE;
1195 overlay_remove( BackendDB *be, slap_overinst *on, Operation *op )
1197 slap_overinfo *oi = on->on_info;
1198 slap_overinst **oidx;
1199 ov_remove_ctx *rm_ctx;
1200 slap_callback *rm_cb, *cb;
1202 /* remove overlay from oi_list */
1203 for ( oidx = &oi->oi_list; *oidx; oidx = &(*oidx)->on_next ) {
1204 if ( *oidx == on ) {
1205 *oidx = on->on_next;
1210 /* The db_close and db_destroy handlers to cleanup a release
1211 * the overlay's resources are called from the cleanup callback
1213 rm_ctx = op->o_tmpalloc( sizeof( ov_remove_ctx ), op->o_tmpmemctx );
1217 rm_cb = op->o_tmpalloc( sizeof( slap_callback ), op->o_tmpmemctx );
1218 rm_cb->sc_next = NULL;
1219 rm_cb->sc_cleanup = overlay_remove_cb;
1220 rm_cb->sc_response = NULL;
1221 rm_cb->sc_private = (void*) rm_ctx;
1223 /* Append callback to the end of the list */
1224 if ( !op->o_callback ) {
1225 op->o_callback = rm_cb;
1227 for ( cb = op->o_callback; cb->sc_next; cb = cb->sc_next );
1228 cb->sc_next = rm_cb;
1231 #endif /* SLAP_CONFIG_DELETE */
1234 overlay_insert( BackendDB *be, slap_overinst *on2, slap_overinst ***prev,
1237 slap_overinfo *oi = (slap_overinfo *)be->bd_info;
1240 on2->on_next = oi->oi_list;
1244 slap_overinst *on, **prev;
1246 /* Since the list is in reverse order and is singly linked,
1247 * we have to count the overlays and then insert backwards.
1248 * Adding on overlay at a specific point should be a pretty
1249 * infrequent occurrence.
1252 for ( on = oi->oi_list; on; on=on->on_next )
1260 /* advance to insertion point */
1261 prev = &oi->oi_list;
1262 for ( i=0; i<idx; i++ ) {
1264 prev = &on->on_next;
1267 on2->on_next = *prev;
1273 overlay_move( BackendDB *be, slap_overinst *on, int idx )
1275 slap_overinfo *oi = (slap_overinfo *)be->bd_info;
1276 slap_overinst **onp;
1278 for (onp = &oi->oi_list; *onp; onp= &(*onp)->on_next) {
1284 overlay_insert( be, on, &onp, idx );
1287 /* add an overlay to a particular backend. */
1289 overlay_config( BackendDB *be, const char *ov, int idx, BackendInfo **res, ConfigReply *cr )
1291 slap_overinst *on = NULL, *on2 = NULL, **prev;
1292 slap_overinfo *oi = NULL;
1293 BackendInfo *bi = NULL;
1298 on = overlay_find( ov );
1300 Debug( LDAP_DEBUG_ANY, "overlay \"%s\" not found\n", ov, 0, 0 );
1304 /* If this is the first overlay on this backend, set up the
1305 * overlay info structure
1307 if ( !overlay_is_over( be ) ) {
1310 /* NOTE: the first time a global overlay is configured,
1311 * frontendDB gets this flag; it is used later by overlays
1312 * to determine if they're stacked on top of the frontendDB */
1313 if ( be->bd_info == frontendDB->bd_info || SLAP_ISGLOBALOVERLAY( be ) ) {
1315 if ( on->on_bi.bi_flags & SLAPO_BFLAG_DBONLY ) {
1316 Debug( LDAP_DEBUG_ANY, "overlay_config(): "
1317 "overlay \"%s\" cannot be global.\n",
1322 } else if ( on->on_bi.bi_flags & SLAPO_BFLAG_GLOBONLY ) {
1323 Debug( LDAP_DEBUG_ANY, "overlay_config(): "
1324 "overlay \"%s\" can only be global.\n",
1329 oi = ch_malloc( sizeof( slap_overinfo ) );
1330 oi->oi_orig = be->bd_info;
1331 oi->oi_bi = *be->bd_info;
1335 SLAP_DBFLAGS( be ) |= SLAP_DBFLAG_GLOBAL_OVERLAY;
1338 /* Save a pointer to ourself in bi_private.
1340 oi->oi_bi.bi_private = oi;
1342 bi = (BackendInfo *)oi;
1344 bi->bi_type = (char *)overtype;
1346 bi->bi_db_config = over_db_config;
1347 bi->bi_db_open = over_db_open;
1348 bi->bi_db_close = over_db_close;
1349 bi->bi_db_destroy = over_db_destroy;
1351 bi->bi_op_bind = over_op_bind;
1352 bi->bi_op_unbind = over_op_unbind;
1353 bi->bi_op_search = over_op_search;
1354 bi->bi_op_compare = over_op_compare;
1355 bi->bi_op_modify = over_op_modify;
1356 bi->bi_op_modrdn = over_op_modrdn;
1357 bi->bi_op_add = over_op_add;
1358 bi->bi_op_delete = over_op_delete;
1359 bi->bi_op_abandon = over_op_abandon;
1360 bi->bi_op_cancel = over_op_cancel;
1362 bi->bi_extended = over_op_extended;
1365 * this is fine because it has the same
1366 * args of the operations; we need to rework
1367 * all the hooks to share the same args
1368 * of the operations...
1370 bi->bi_operational = over_aux_operational;
1371 bi->bi_chk_referrals = over_aux_chk_referrals;
1372 bi->bi_chk_controls = over_aux_chk_controls;
1374 /* these have specific arglists */
1375 bi->bi_entry_get_rw = over_entry_get_rw;
1376 bi->bi_entry_release_rw = over_entry_release_rw;
1377 bi->bi_access_allowed = over_access_allowed;
1378 bi->bi_acl_group = over_acl_group;
1379 bi->bi_acl_attribute = over_acl_attribute;
1381 bi->bi_connection_init = over_connection_init;
1382 bi->bi_connection_destroy = over_connection_destroy;
1387 if ( overlay_is_inst( be, ov ) ) {
1388 if ( SLAPO_SINGLE( be ) ) {
1389 Debug( LDAP_DEBUG_ANY, "overlay_config(): "
1390 "overlay \"%s\" already in list\n",
1396 oi = be->bd_info->bi_private;
1399 /* Insert new overlay into list. By default overlays are
1400 * added to head of list and executed in LIFO order.
1402 on2 = ch_calloc( 1, sizeof(slap_overinst) );
1406 prev = &oi->oi_list;
1407 /* Do we need to find the insertion point? */
1411 /* count current overlays */
1412 for ( i=0, on=oi->oi_list; on; on=on->on_next, i++ );
1414 /* are we just appending a new one? */
1418 overlay_insert( be, on2, &prev, idx );
1420 /* Any initialization needed? */
1421 if ( on2->on_bi.bi_db_init ) {
1423 be->bd_info = (BackendInfo *)on2;
1424 rc = on2->on_bi.bi_db_init( be, cr);
1425 be->bd_info = (BackendInfo *)oi;
1427 *prev = on2->on_next;