瀏覽代碼

Bug 668909 - Can't modify replication agreement in some cases

https://bugzilla.redhat.com/show_bug.cgi?id=668909

Description: Code to modify nsds5ReplicaPort in replication agreement
was not implemented.  This patch adds it.

When an agreement change is detected in conn_connect, it resets
the values needed to make a connection including the port number.
Noriko Hosoi 14 年之前
父節點
當前提交
34f2f30578

+ 33 - 2
ldap/servers/plugins/replication/repl5_agmt.c

@@ -953,7 +953,7 @@ int
 agmt_set_credentials_from_entry(Repl_Agmt *ra, const Slapi_Entry *e)
 {
 	Slapi_Attr *sattr = NULL;
-	int return_value = 0;
+	int return_value = -1;
 
 	PR_ASSERT(NULL != ra);
 	slapi_entry_attr_find(e, type_nsds5ReplicaCredentials, &sattr);
@@ -970,6 +970,7 @@ agmt_set_credentials_from_entry(Repl_Agmt *ra, const Slapi_Entry *e)
 			ra->creds->bv_val = slapi_ch_calloc(1, bv->bv_len + 1);
 			memcpy(ra->creds->bv_val, bv->bv_val, bv->bv_len);
 			ra->creds->bv_len = bv->bv_len;
+			return_value = 0;
 		}
 	}
 	/* If no credentials set, set to zero-length string */
@@ -988,7 +989,7 @@ int
 agmt_set_binddn_from_entry(Repl_Agmt *ra, const Slapi_Entry *e)
 {
 	Slapi_Attr *sattr = NULL;
-	int return_value = 0;
+	int return_value = -1;
 
 	PR_ASSERT(NULL != ra);
 	slapi_entry_attr_find(e, type_nsds5ReplicaBindDN, &sattr);
@@ -1003,6 +1004,7 @@ agmt_set_binddn_from_entry(Repl_Agmt *ra, const Slapi_Entry *e)
 		{
 			const char *val = slapi_value_get_string(sval);
 			ra->binddn = slapi_ch_strdup(val);
+			return_value = 0;
 		}
 	}
 	/* If no BindDN set, set to zero-length string */
@@ -1014,6 +1016,35 @@ agmt_set_binddn_from_entry(Repl_Agmt *ra, const Slapi_Entry *e)
 	return return_value;
 }
 
+/*
+ * Reset the port number of the remote replica.
+ *
+ * Returns 0 if port set, or -1 if an error occurred.
+ */
+int
+agmt_set_port_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_nsds5ReplicaPort, &sattr);
+	PR_Lock(ra->lock);
+	if (NULL != sattr)
+	{
+		Slapi_Value *sval = NULL;
+		slapi_attr_first_value(sattr, &sval);
+		if (NULL != sval)
+		{
+			ra->port = slapi_value_get_int(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)
 {

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

@@ -372,6 +372,20 @@ 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_nsds5ReplicaPort))
+		{
+			/* New replica port */
+			if (agmt_set_port_from_entry(agmt, e) != 0)
+			{
+				slapi_log_error(SLAPI_LOG_REPL, repl_plugin_name,
+				                "agmtlist_modify_callback: " 
+				                "failed to update port for agreement %s\n",
+				                agmt_get_long_name(agmt));	
+				*returncode = LDAP_OPERATIONS_ERROR;
+				rc = SLAPI_DSE_CALLBACK_ERROR;
+			}
+		}
 		else if (slapi_attr_types_equivalent(mods[i]->mod_type,
 					type_nsds5TransportInfo))
 		{

+ 1 - 0
ldap/servers/plugins/replication/repl5_connection.c

@@ -1020,6 +1020,7 @@ conn_connect(Repl_Connection *conn)
 		conn->transport_flags = agmt_get_transport_flags(conn->agmt);
 		conn->timeout.tv_sec = agmt_get_timeout(conn->agmt);
 		conn->flag_agmt_changed = 0;
+		conn->port = agmt_get_port(conn->agmt); /* port could be updated */
 		slapi_ch_free((void **)&conn->plain);
 	}
 	PR_Unlock(conn->lock);