Blob Blame History Raw
From 1787e9ffda09f9ec8518ceaede5cf1ef014c5d17 Mon Sep 17 00:00:00 2001
From: Ludwig Krispenz <lkrispen@redhat.com>
Date: Wed, 27 Sep 2017 10:58:36 +0200
Subject: [PATCH] Ticket: 49180 - backport 1.3.6 errors log filled with
 attrlist_replace - attr_replace

    Bug: If a RUV contains the same URL with different replica IDs the created referrals contain duplicates

    Fix: check duplicate referrals

    Reviewed by: Mark, thanks
---
 ldap/servers/plugins/replication/repl5_ruv.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/ldap/servers/plugins/replication/repl5_ruv.c b/ldap/servers/plugins/replication/repl5_ruv.c
index 39449b6..7f34059 100644
--- a/ldap/servers/plugins/replication/repl5_ruv.c
+++ b/ldap/servers/plugins/replication/repl5_ruv.c
@@ -1502,7 +1502,17 @@ ruv_replica_count (const RUV *ruv)
  * Extract all the referral URL's from the RUV (but self URL),
  * returning them in an array of strings, that
  * the caller must free.
+ * We also check and remove duplicates (caused by unclean RUVs)
  */
+static int
+ruv_referral_exists(unsigned char *purl, char **refs, int count)
+{
+    for (size_t j=0; j<count; j++) {
+        if (0 == slapi_utf8casecmp(purl, (unsigned char *)refs[j]))
+            return 1;
+    }
+    return 0;
+}
 char **
 ruv_get_referrals(const RUV *ruv)
 {
@@ -1525,7 +1535,8 @@ ruv_get_referrals(const RUV *ruv)
 			/* Add URL into referrals if doesn't match self URL */
 			if((replica->replica_purl!=NULL) &&
 			   (slapi_utf8casecmp((unsigned char *)replica->replica_purl,
-								  (unsigned char *)mypurl) != 0))
+                                   (unsigned char *)mypurl) != 0) &&
+			    !ruv_referral_exists((unsigned char *)replica->replica_purl, r, i))
 			{
 		 		r[i]= slapi_ch_strdup(replica->replica_purl);
 				i++;
-- 
2.9.5