From ed0949c7e73043b91bf9e8c197d98aa5365b3beb Mon Sep 17 00:00:00 2001
From: Pierangelo Masarati <ando@openldap.org>
Date: Sat, 11 Dec 2004 17:36:25 +0000
Subject: [PATCH] work out an issue with chk_referrals and back-relay/rwm; this
 looks like the best compromise

---
 servers/slapd/back-relay/init.c | 10 ++++++++--
 servers/slapd/back-relay/op.c   | 19 +++++++++++++++++++
 2 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/servers/slapd/back-relay/init.c b/servers/slapd/back-relay/init.c
index 85ab6e1da1..290085afbc 100644
--- a/servers/slapd/back-relay/init.c
+++ b/servers/slapd/back-relay/init.c
@@ -37,7 +37,9 @@ relay_back_initialize( BackendInfo *bi )
 	bi->bi_db_init = relay_back_db_init;
 	bi->bi_db_config = relay_back_db_config;
 	bi->bi_db_open = relay_back_db_open;
-	bi->bi_db_close = 0 /* relay_back_db_close */ ;
+#if 0
+	bi->bi_db_close =relay_back_db_close;
+#endif
 	bi->bi_db_destroy = relay_back_db_destroy;
 
 	bi->bi_op_bind = relay_back_op_bind;
@@ -48,12 +50,16 @@ relay_back_initialize( BackendInfo *bi )
 	bi->bi_op_modrdn = relay_back_op_modrdn;
 	bi->bi_op_add = relay_back_op_add;
 	bi->bi_op_delete = relay_back_op_delete;
-	bi->bi_op_abandon = 0 /* relay_back_op_abandon */ ;
+#if 0	/* causes a deadlock */
+	bi->bi_op_abandon = relay_back_op_abandon;
+#endif
 	bi->bi_op_cancel = relay_back_op_cancel;
 	bi->bi_extended = relay_back_op_extended;
 	bi->bi_entry_release_rw = relay_back_entry_release_rw;
 	bi->bi_entry_get_rw = relay_back_entry_get_rw;
+#if 0	/* see comment in op.c */
 	bi->bi_chk_referrals = relay_back_chk_referrals;
+#endif
 	bi->bi_operational = relay_back_operational;
 	bi->bi_has_subordinates = relay_back_has_subordinates;
 
diff --git a/servers/slapd/back-relay/op.c b/servers/slapd/back-relay/op.c
index e80b591a16..669da91f49 100644
--- a/servers/slapd/back-relay/op.c
+++ b/servers/slapd/back-relay/op.c
@@ -522,6 +522,13 @@ relay_back_entry_get_rw( struct slap_op *op, struct berval *ndn,
 
 }
 
+/*
+ * NOTE: even the existence of this function is questionable: we cannot
+ * pass the bi_chk_referrals() call thru the rwm overlay because there
+ * is no way to rewrite the req_dn back; but then relay_back_chk_referrals()
+ * is passing the target database a DN that likely does not belong to its
+ * naming context... mmmh.
+ */
 int
 relay_back_chk_referrals( struct slap_op *op, struct slap_rep *rs )
 {
@@ -529,10 +536,22 @@ relay_back_chk_referrals( struct slap_op *op, struct slap_rep *rs )
 	int			rc = 0;
 
 	bd = relay_back_select_backend( op, rs, LDAP_SUCCESS );
+	/* FIXME: this test only works if there are no overlays, so
+	 * it is nearly useless; if made stricter, no nested back-relays
+	 * can be instantiated... too bad. */
 	if ( bd == NULL || bd == op->o_bd ) {
 		return 0;
 	}
 
+	/* no nested back-relays... */
+	if ( overlay_is_over( bd ) ) {
+		slap_overinfo	*oi = (slap_overinfo *)bd->bd_info->bi_private;
+
+		if ( oi->oi_orig == op->o_bd->bd_info ) {
+			return 0;
+		}
+	}
+
 	if ( bd->be_chk_referrals ) {
 		BackendDB	*be = op->o_bd;
 		slap_callback	cb;
-- 
GitLab