From 57a1a2d18386d01af5a3f6d72e63afe2b2954c71 Mon Sep 17 00:00:00 2001
From: neil_a_wilson <neil_a_wilson@localhost>
Date: Thu, 31 Aug 2006 20:31:43 +0000
Subject: [PATCH] Update a number of the client-side tools provided with OpenDS to ensure that they use consistently incrementing message IDs for requests sent to the server. In at least one case, it was possible for the same message ID to be used by the client for two consecutive requests, which could trigger a race condition that caused the server to refuse the second request.
---
opends/src/server/org/opends/server/tools/LDAPModify.java | 23 +++++++++++++++--------
1 files changed, 15 insertions(+), 8 deletions(-)
diff --git a/opends/src/server/org/opends/server/tools/LDAPModify.java b/opends/src/server/org/opends/server/tools/LDAPModify.java
index a72dd8c..c5cc387 100644
--- a/opends/src/server/org/opends/server/tools/LDAPModify.java
+++ b/opends/src/server/org/opends/server/tools/LDAPModify.java
@@ -33,6 +33,7 @@
import java.util.LinkedList;
import java.util.List;
import java.util.StringTokenizer;
+import java.util.concurrent.atomic.AtomicInteger;
import org.opends.server.core.DirectoryServer;
import org.opends.server.protocols.asn1.ASN1Element;
@@ -89,16 +90,20 @@
*/
private static final String CLASS_NAME = "org.opends.server.tools.LDAPModify";
+ // The message ID counter to use for requests.
+ private AtomicInteger nextMessageID;
+
// The LDIF file name.
private String fileName = null;
/**
* Constructor for the LDAPModify object.
*
- * @param fileName The name of the file containing the LDIF data to use for
- * the modifications.
+ * @param fileName The name of the file containing the LDIF data to use
+ * for the modifications.
+ * @param nextMessageID The message ID counter to use for requests.
*/
- public LDAPModify(String fileName)
+ public LDAPModify(String fileName, AtomicInteger nextMessageID)
{
if(fileName == null)
{
@@ -107,6 +112,8 @@
{
this.fileName = fileName;
}
+
+ this.nextMessageID = nextMessageID;
}
@@ -144,10 +151,8 @@
throw new IOException(message);
}
- int messageID = 1;
while (true)
{
- messageID++;
ChangeRecordEntry entry = null;
try
@@ -286,7 +291,8 @@
try
{
LDAPMessage message =
- new LDAPMessage(messageID, protocolOp, controls);
+ new LDAPMessage(nextMessageID.getAndIncrement(), protocolOp,
+ controls);
// int numBytes =
connection.getASN1Writer().writeElement(message.encode());
ASN1Element element = connection.getASN1Reader().readElement();
@@ -882,11 +888,12 @@
connectionOptions.setSSLConnectionFactory(sslConnectionFactory);
}
+ AtomicInteger nextMessageID = new AtomicInteger(1);
connection = new LDAPConnection(hostNameValue, portNumber,
connectionOptions);
- connection.connectToHost(bindDNValue, bindPasswordValue);
+ connection.connectToHost(bindDNValue, bindPasswordValue, nextMessageID);
- LDAPModify ldapModify = new LDAPModify(fileNameValue);
+ LDAPModify ldapModify = new LDAPModify(fileNameValue, nextMessageID);
InputStream is = System.in;
if(fileNameValue != null)
{
--
Gitblit v1.10.0