瀏覽代碼

Ticket 47727 - Updating nsds5ReplicaHost attribute in a replication agreement fails with error 53

Description:  Allow the modification of the nsds5ReplicaHost in replication agreements.

https://fedorahosted.org/389/ticket/47727

Reviewed by: nhosoi(Thanks!)
Mark Reynolds 11 年之前
父節點
當前提交
d4e13f59c1

+ 1 - 0
ldap/servers/plugins/replication/repl5.h

@@ -353,6 +353,7 @@ int agmt_set_binddn_from_entry( Repl_Agmt *ra, const Slapi_Entry *e );
 int agmt_set_bind_method_from_entry( Repl_Agmt *ra, const Slapi_Entry *e );
 int agmt_set_transportinfo_from_entry( Repl_Agmt *ra, const Slapi_Entry *e );
 int agmt_set_port_from_entry( Repl_Agmt *ra, const Slapi_Entry *e );
+int agmt_set_host_from_entry(Repl_Agmt *ra, const Slapi_Entry *e);
 const char *agmt_get_long_name(const Repl_Agmt *ra);
 int agmt_initialize_replica(const Repl_Agmt *agmt);
 void agmt_replica_init_done (const Repl_Agmt *agmt);

+ 30 - 0
ldap/servers/plugins/replication/repl5_agmt.c

@@ -1198,6 +1198,36 @@ agmt_set_port_from_entry(Repl_Agmt *ra, const Slapi_Entry *e)
 	return return_value;
 }
 
+/*
+ * Reset the hostname of the remote replica.
+ *
+ * Returns 0 if hostname is set, or -1 if an error occurred.
+ */
+int
+agmt_set_host_from_entry(Repl_Agmt *ra, const Slapi_Entry *e)
+{
+	Slapi_Attr *sattr = NULL;
+	int return_value = -1;
+
+	PR_ASSERT(NULL != ra);
+	slapi_entry_attr_find(e, type_nsds5ReplicaHost, &sattr);
+	PR_Lock(ra->lock);
+	if (NULL != sattr)
+	{
+		Slapi_Value *sval = NULL;
+		slapi_attr_first_value(sattr, &sval);
+		if (NULL != sval)
+		{
+			ra->hostname = (char *)slapi_value_get_string(sval);
+			return_value = 0;
+		}
+	}
+	PR_Unlock(ra->lock);
+	prot_notify_agmt_changed(ra->protocol, ra->long_name);
+
+	return return_value;
+}
+
 static int
 agmt_parse_excluded_attrs_filter(const char *attr_string, size_t *offset)
 {

+ 19 - 0
ldap/servers/plugins/replication/repl5_agmtlist.c

@@ -368,6 +368,25 @@ agmtlist_modify_callback(Slapi_PBlock *pb, Slapi_Entry *entryBefore, Slapi_Entry
                 rc = SLAPI_DSE_CALLBACK_ERROR;
             }
 		}
+		else if (slapi_attr_types_equivalent(mods[i]->mod_type, type_nsds5ReplicaHost))
+		{
+			/* New replica host */
+			if (agmt_set_host_from_entry(agmt, e) != 0)
+			{
+				slapi_log_error(SLAPI_LOG_REPL, repl_plugin_name,
+				                "agmtlist_modify_callback: "
+				                "failed to update host for agreement %s\n",
+				                agmt_get_long_name(agmt));
+				*returncode = LDAP_OPERATIONS_ERROR;
+				rc = SLAPI_DSE_CALLBACK_ERROR;
+			} else {
+				/*
+				 * Changing the host invalidates the agmt maxcsn, so remove it.
+				 * The next update will add the correct maxcsn back to the agmt/local ruv.
+				 */
+				agmt_remove_maxcsn(agmt);
+			}
+		}
 		else if (slapi_attr_types_equivalent(mods[i]->mod_type,
 		                                     type_nsds5ReplicaPort))
 		{