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/LDAPConnection.java |   33 +++++++++++++++++++++++++--------
 1 files changed, 25 insertions(+), 8 deletions(-)

diff --git a/opends/src/server/org/opends/server/tools/LDAPConnection.java b/opends/src/server/org/opends/server/tools/LDAPConnection.java
index 712a518..c156934 100644
--- a/opends/src/server/org/opends/server/tools/LDAPConnection.java
+++ b/opends/src/server/org/opends/server/tools/LDAPConnection.java
@@ -99,19 +99,37 @@
    * Connects to the directory server instance running on specified hostname
    * and port number.
    *
-   * @param bindDN               The DN to bind with.
-   *
-   * @param bindPassword         The password to bind with.
+   * @param  bindDN        The DN to bind with.
+   * @param  bindPassword  The password to bind with.
    *
    * @throws  LDAPConnectionException  If a problem occurs while attempting to
    *                                   establish the connection to the server.
    */
   public void connectToHost(String bindDN, String bindPassword)
+         throws LDAPConnectionException
+  {
+    connectToHost(bindDN, bindPassword, new AtomicInteger(1));
+  }
+
+  /**
+   * Connects to the directory server instance running on specified hostname
+   * and port number.
+   *
+   * @param  bindDN         The DN to bind with.
+   * @param  bindPassword   The password to bind with.
+   * @param  nextMessageID  The message ID counter that should be used for
+   *                        operations performed while establishing the
+   *                        connection.
+   *
+   * @throws  LDAPConnectionException  If a problem occurs while attempting to
+   *                                   establish the connection to the server.
+   */
+  public void connectToHost(String bindDN, String bindPassword,
+                            AtomicInteger nextMessageID)
                             throws LDAPConnectionException
   {
     Socket socket = null;
     Socket startTLSSocket = null;
-    int messageID = 1;
     int resultCode = -1;
     ArrayList<LDAPControl> requestControls = new ArrayList<LDAPControl> ();
     ArrayList<LDAPControl> responseControls = new ArrayList<LDAPControl> ();
@@ -143,11 +161,11 @@
       ExtendedRequestProtocolOp extendedRequest =
            new ExtendedRequestProtocolOp(OID_START_TLS_REQUEST);
 
-      LDAPMessage msg = new LDAPMessage(messageID, extendedRequest);
+      LDAPMessage msg = new LDAPMessage(nextMessageID.getAndIncrement(),
+                                        extendedRequest);
       try
       {
         asn1Writer.writeElement(msg.encode());
-        messageID++;
 
         // Read the response from the server.
         msg = LDAPMessage.decode(asn1Reader.readElement().decodeAsSequence());
@@ -216,8 +234,7 @@
     }
 
     LDAPAuthenticationHandler handler = new LDAPAuthenticationHandler(
-            asn1Reader, asn1Writer, hostName,
-            new AtomicInteger(messageID));
+            asn1Reader, asn1Writer, hostName, nextMessageID);
     try
     {
       ASN1OctetString bindPW;

--
Gitblit v1.10.0