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/LDAPDelete.java | 31 +++++++++++++++++++------------
1 files changed, 19 insertions(+), 12 deletions(-)
diff --git a/opends/src/server/org/opends/server/tools/LDAPDelete.java b/opends/src/server/org/opends/server/tools/LDAPDelete.java
index af38362..e3479f7 100644
--- a/opends/src/server/org/opends/server/tools/LDAPDelete.java
+++ b/opends/src/server/org/opends/server/tools/LDAPDelete.java
@@ -33,6 +33,7 @@
import java.io.Reader;
import java.util.ArrayList;
import java.util.LinkedList;
+import java.util.concurrent.atomic.AtomicInteger;
import org.opends.server.core.DirectoryServer;
import org.opends.server.protocols.asn1.ASN1Element;
@@ -71,12 +72,21 @@
*/
private static final String CLASS_NAME = "org.opends.server.tools.LDAPDelete";
+
+
+ // The message ID counter to use for requests.
+ private AtomicInteger nextMessageID;
+
+
+
/**
* Constructor for the LDAPDelete object.
*
+ * @param nextMessageID The next message ID to use for requests.
*/
- public LDAPDelete()
+ public LDAPDelete(AtomicInteger nextMessageID)
{
+ this.nextMessageID = nextMessageID;
}
/**
@@ -96,11 +106,9 @@
LDAPDeleteOptions deleteOptions)
throws IOException, LDAPException
{
- int messageID = 1;
for(String line : lines)
{
- executeDelete(connection, line, messageID, deleteOptions);
- messageID++;
+ executeDelete(connection, line, deleteOptions);
}
}
@@ -121,14 +129,12 @@
LDAPDeleteOptions deleteOptions)
throws IOException, LDAPException
{
- int messageID = 1;
BufferedReader in = new BufferedReader(reader);
String line = null;
while ((line = in.readLine()) != null)
{
- executeDelete(connection, line, messageID, deleteOptions);
- messageID++;
+ executeDelete(connection, line, deleteOptions);
}
in.close();
}
@@ -139,7 +145,6 @@
*
* @param connection The connection to use to execute the request.
* @param line The DN to delete.
- * @param messageID The messageID for the request.
* @param deleteOptions The list of constraints for this request.
*
* @throws IOException If a problem occurs while attempting to communicate
@@ -148,7 +153,7 @@
* @throws LDAPException If the Directory Server returns an error response.
*/
private void executeDelete(LDAPConnection connection, String line,
- int messageID, LDAPDeleteOptions deleteOptions)
+ LDAPDeleteOptions deleteOptions)
throws IOException, LDAPException
{
ArrayList<LDAPControl> controls = deleteOptions.getControls();
@@ -160,7 +165,8 @@
System.out.println(getMessage(msgID, "DELETE", asn1OctetStr));
if(!deleteOptions.showOperations())
{
- LDAPMessage message = new LDAPMessage(messageID, protocolOp, controls);
+ LDAPMessage message = new LDAPMessage(nextMessageID.getAndIncrement(),
+ protocolOp, controls);
LDAPMessage responseMessage = null;
try
{
@@ -547,11 +553,12 @@
connectionOptions.setSSLConnectionFactory(sslConnectionFactory);
}
+ AtomicInteger nextMessageID = new AtomicInteger(1);
connection = new LDAPConnection(hostNameValue, portNumber,
connectionOptions);
- connection.connectToHost(bindDNValue, bindPasswordValue);
+ connection.connectToHost(bindDNValue, bindPasswordValue, nextMessageID);
- LDAPDelete ldapDelete = new LDAPDelete();
+ LDAPDelete ldapDelete = new LDAPDelete(nextMessageID);
if(fileNameValue == null && dnStrings.isEmpty())
{
// Read from stdin.
--
Gitblit v1.10.0