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/LDAPCompare.java | 29 +++++++++++++++++------------
1 files changed, 17 insertions(+), 12 deletions(-)
diff --git a/opends/src/server/org/opends/server/tools/LDAPCompare.java b/opends/src/server/org/opends/server/tools/LDAPCompare.java
index 36e6acf..2bfd6b6 100644
--- a/opends/src/server/org/opends/server/tools/LDAPCompare.java
+++ b/opends/src/server/org/opends/server/tools/LDAPCompare.java
@@ -34,6 +34,7 @@
import java.text.ParseException;
import java.util.ArrayList;
import java.util.LinkedList;
+import java.util.concurrent.atomic.AtomicInteger;
import org.opends.server.protocols.asn1.ASN1Element;
import org.opends.server.protocols.asn1.ASN1Exception;
@@ -76,12 +77,19 @@
"org.opends.server.tools.LDAPCompare";
+ // The message ID counter to use for requests.
+ private AtomicInteger nextMessageID;
+
+
+
/**
* Constructor for the LDAPCompare object.
*
+ * @param nextMessageID The message ID counter to use for requests.
*/
- public LDAPCompare()
+ public LDAPCompare(AtomicInteger nextMessageID)
{
+ this.nextMessageID = nextMessageID;
}
/**
@@ -103,12 +111,10 @@
LDAPCompareOptions compareOptions)
throws IOException, LDAPException
{
- int messageID = 1;
for(String line : lines)
{
executeCompare(connection, attributeType, attributeVal, line,
- messageID, compareOptions);
- messageID++;
+ compareOptions);
}
}
@@ -133,15 +139,13 @@
LDAPCompareOptions compareOptions)
throws IOException, LDAPException
{
- int messageID = 1;
BufferedReader in = new BufferedReader(reader);
String line = null;
while ((line = in.readLine()) != null)
{
executeCompare(connection, attributeType, attributeVal, line,
- messageID, compareOptions);
- messageID++;
+ compareOptions);
}
in.close();
}
@@ -154,7 +158,6 @@
* @param attributeType The attribute type to compare.
* @param attributeVal The attribute value to compare.
* @param line The DN to compare attribute in.
- * @param messageID The messageID for the request.
* @param compareOptions The constraints for the compare request.
*
* @throws IOException If a problem occurs while communicating with the
@@ -163,7 +166,7 @@
* @throws LDAPException If the server returns an error response.
*/
private void executeCompare(LDAPConnection connection, String attributeType,
- byte[] attributeVal, String line, int messageID,
+ byte[] attributeVal, String line,
LDAPCompareOptions compareOptions)
throws IOException, LDAPException
{
@@ -183,7 +186,8 @@
LDAPMessage responseMessage = null;
try
{
- LDAPMessage message = new LDAPMessage(messageID, protocolOp, controls);
+ LDAPMessage message = new LDAPMessage(nextMessageID.getAndIncrement(),
+ protocolOp, controls);
int numBytes =
connection.getASN1Writer().writeElement(message.encode());
ASN1Element element = connection.getASN1Reader().readElement();
@@ -651,12 +655,13 @@
connectionOptions.setSSLConnectionFactory(sslConnectionFactory);
}
+ AtomicInteger nextMessageID = new AtomicInteger(1);
connection = new LDAPConnection(hostNameValue, portNumber,
connectionOptions);
- connection.connectToHost(bindDNValue, bindPasswordValue);
+ connection.connectToHost(bindDNValue, bindPasswordValue, nextMessageID);
- LDAPCompare ldapCompare = new LDAPCompare();
+ LDAPCompare ldapCompare = new LDAPCompare(nextMessageID);
if(fileNameValue == null && dnStrings.isEmpty())
{
// Read from stdin.
--
Gitblit v1.10.0