/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
- * Copyright 2001-2006 The OpenLDAP Foundation.
+ * Copyright 2001-2007 The OpenLDAP Foundation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
#define SLAPD_TOOLS
#include "slap.h"
+#include "config.h"
typedef struct gluenode {
BackendDB *gn_be;
glueinfo *gi = (glueinfo *)on->on_bi.bi_private;
int i;
- for (i = 0; i<gi->gi_nodes; i++) {
+ for (i = gi->gi_nodes-1; i >= 0; i--) {
assert( gi->gi_n[i].gn_be->be_nsuffix != NULL );
if (dnIsSuffix(dn, &gi->gi_n[i].gn_be->be_nsuffix[0])) {
int nctrls;
} glue_state;
+static int
+glue_op_cleanup( Operation *op, SlapReply *rs )
+{
+ /* This is not a final result */
+ if (rs->sr_type == REP_RESULT )
+ rs->sr_type = REP_GLUE_RESULT;
+ return SLAP_CB_CONTINUE;
+}
+
static int
glue_op_response ( Operation *op, SlapReply *rs )
{
case LDAP_REQ_DELETE: which = op_delete; break;
case LDAP_REQ_MODIFY: which = op_modify; break;
case LDAP_REQ_MODRDN: which = op_modrdn; break;
+ case LDAP_REQ_EXTENDED: which = op_extended; break;
default: assert( 0 ); break;
}
if ( func[which] )
rc = func[which]( op, rs );
else
- rc = SLAP_CB_CONTINUE;
+ rc = SLAP_CB_BYPASS;
op->o_bd = b0;
op->o_bd->bd_info = bi0;
return rc;
}
+static int
+glue_response ( Operation *op, SlapReply *rs )
+{
+ BackendDB *be = op->o_bd;
+ be = glue_back_select (op->o_bd, &op->o_req_ndn);
+
+ /* If we're on the master backend, let overlay framework handle it.
+ * Otherwise, bail out.
+ */
+ return ( op->o_bd == be ) ? SLAP_CB_CONTINUE : SLAP_CB_BYPASS;
+}
+
static int
glue_chk_referrals ( Operation *op, SlapReply *rs )
{
return rc;
}
+/* ITS#4615 - overlays configured above the glue overlay should be
+ * invoked for the entire glued tree. Overlays configured below the
+ * glue overlay should only be invoked on the master backend.
+ * So, if we're searching on any subordinates, we need to force the
+ * current overlay chain to stop processing, without stopping the
+ * overall callback flow.
+ */
static int
glue_sub_search( Operation *op, SlapReply *rs, BackendDB *b0,
slap_overinst *on )
BackendDB *b1 = NULL, *btmp;
BackendInfo *bi0 = op->o_bd->bd_info;
int i;
- long stoptime = 0;
+ long stoptime = 0, starttime;
glue_state gs = {NULL, NULL, NULL, 0, 0, 0, 0};
- slap_callback cb = { NULL, glue_op_response, NULL, NULL };
+ slap_callback cb = { NULL, glue_op_response, glue_op_cleanup, NULL };
int scope0, tlimit0;
struct berval dn, ndn, *pdn;
cb.sc_next = op->o_callback;
+ starttime = op->o_time;
stoptime = slap_get_time () + op->ors_tlimit;
op->o_bd = glue_back_select (b0, &op->o_req_ndn);
b1 = op->o_bd;
/*
- * Execute in reverse order, most general first
+ * Execute in reverse order, most specific first
*/
for (i = gi->gi_nodes; i >= 0; i--) {
if ( i == gi->gi_nodes ) {
continue;
if (!dnIsSuffix(&btmp->be_nsuffix[0], &b1->be_nsuffix[0]))
continue;
+ if (get_no_subordinate_glue(op) && btmp != b1)
+ continue;
+
if (tlimit0 != SLAP_NO_LIMIT) {
- op->ors_tlimit = stoptime - slap_get_time ();
+ op->o_time = slap_get_time();
+ op->ors_tlimit = stoptime - op->o_time;
if (op->ors_tlimit <= 0) {
rs->sr_err = gs.err = LDAP_TIMELIMIT_EXCEEDED;
break;
if ( rs->sr_err == LDAP_NO_SUCH_OBJECT ) {
gs.err = LDAP_SUCCESS;
}
+ op->ors_scope = LDAP_SCOPE_ONELEVEL;
+ op->o_req_dn = dn;
+ op->o_req_ndn = ndn;
} else if (scope0 == LDAP_SCOPE_SUBTREE &&
dn_match(&op->o_bd->be_nsuffix[0], &ndn))
end_of_loop:;
op->ors_scope = scope0;
op->ors_tlimit = tlimit0;
+ op->o_time = starttime;
op->o_req_dn = dn;
op->o_req_ndn = ndn;
gi->gi_n[i].gn_be->bd_info );
/* Let backend.c take care of the rest of startup */
if ( !rc )
- rc = backend_startup_one( gi->gi_n[i].gn_be );
+ rc = backend_startup_one( gi->gi_n[i].gn_be, NULL );
if ( rc ) break;
}
if ( !rc && !bsame && on->on_info->oi_orig->bi_open )
return rc;
}
+static int
+glue_entry_get_rw (
+ Operation *op,
+ struct berval *dn,
+ ObjectClass *oc,
+ AttributeDescription *ad,
+ int rw,
+ Entry **e )
+{
+ int rc;
+ BackendDB *b0 = op->o_bd;
+ op->o_bd = glue_back_select( b0, dn );
+
+ if ( op->o_bd->be_fetch ) {
+ rc = op->o_bd->be_fetch( op, dn, oc, ad, rw, e );
+ } else {
+ rc = LDAP_UNWILLING_TO_PERFORM;
+ }
+ op->o_bd =b0;
+ return rc;
+}
+
static int
glue_entry_release_rw (
Operation *op,
int rw
)
{
- BackendDB *b0, b2;
+ BackendDB *b0 = op->o_bd;
int rc = -1;
- b0 = op->o_bd;
- b2 = *op->o_bd;
- b2.bd_info = (BackendInfo *)glue_tool_inst( op->o_bd->bd_info );
- op->o_bd = glue_back_select (&b2, &e->e_nname);
+ op->o_bd = glue_back_select (b0, &e->e_nname);
if ( op->o_bd->be_release ) {
rc = op->o_bd->be_release( op, e, rw );
static int
glue_tool_entry_reindex (
BackendDB *b0,
- ID id
+ ID id,
+ AttributeDescription **adv
)
{
if (!glueBack || !glueBack->be_entry_reindex)
return -1;
- return glueBack->be_entry_reindex (glueBack, id);
+ return glueBack->be_entry_reindex (glueBack, id, adv);
}
static int
static int
glue_db_init(
- BackendDB *be
+ BackendDB *be,
+ ConfigReply *cr
)
{
slap_overinst *on = (slap_overinst *)be->bd_info;
BackendInfo *bi = oi->oi_orig;
glueinfo *gi;
+ if ( SLAP_GLUE_SUBORDINATE( be )) {
+ Debug( LDAP_DEBUG_ANY, "glue: backend %s is already subordinate, "
+ "cannot have glue overlay!\n",
+ be->be_suffix[0].bv_val, 0, 0 );
+ return LDAP_OTHER;
+ }
+
gi = ch_calloc( 1, sizeof(glueinfo));
on->on_bi.bi_private = gi;
dnParent( be->be_nsuffix, &gi->gi_pdn );
oi->oi_bi.bi_open = glue_open;
oi->oi_bi.bi_close = glue_close;
- oi->oi_bi.bi_entry_release_rw = glue_entry_release_rw;
-
/* Only advertise these if the root DB supports them */
if ( bi->bi_tool_entry_open )
oi->oi_bi.bi_tool_entry_open = glue_tool_entry_open;
/*FIXME : need to add support */
oi->oi_bi.bi_tool_dn2id_get = 0;
- oi->oi_bi.bi_tool_id2entry_get = 0;
oi->oi_bi.bi_tool_entry_modify = 0;
SLAP_DBFLAGS( be ) |= SLAP_DBFLAG_GLUE_INSTANCE;
static int
glue_db_destroy (
- BackendDB *be
+ BackendDB *be,
+ ConfigReply *cr
)
{
slap_overinst *on = (slap_overinst *)be->bd_info;
static int
glue_db_close(
- BackendDB *be
+ BackendDB *be,
+ ConfigReply *cr
)
{
slap_overinst *on = (slap_overinst *)be->bd_info;
/* If it's not already configured, set up the overlay */
if ( !SLAP_GLUE_INSTANCE( be )) {
- rc = overlay_config( be, glue.on_bi.bi_type );
+ rc = overlay_config( be, glue.on_bi.bi_type, -1, NULL );
if ( rc )
break;
}
glue_Addrec *ga;
int rc = 0;
+ if ( overlay_is_inst( be, "glue" )) {
+ Debug( LDAP_DEBUG_ANY, "glue: backend %s already has glue overlay, "
+ "cannot be a subordinate!\n",
+ be->be_suffix[0].bv_val, 0, 0 );
+ return LDAP_OTHER;
+ }
SLAP_DBFLAGS( be ) |= SLAP_DBFLAG_GLUE_SUBORDINATE;
if ( advert )
SLAP_DBFLAGS( be ) |= SLAP_DBFLAG_GLUE_ADVERTISE;
glue.on_bi.bi_op_modrdn = glue_op_func;
glue.on_bi.bi_op_add = glue_op_func;
glue.on_bi.bi_op_delete = glue_op_func;
+ glue.on_bi.bi_extended = glue_op_func;
glue.on_bi.bi_chk_referrals = glue_chk_referrals;
glue.on_bi.bi_chk_controls = glue_chk_controls;
+ glue.on_bi.bi_entry_get_rw = glue_entry_get_rw;
+ glue.on_bi.bi_entry_release_rw = glue_entry_release_rw;
+
+ glue.on_response = glue_response;
return overlay_register( &glue );
}