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/LDAPSearch.java |   23 ++++++++++++++++-------
 1 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/opends/src/server/org/opends/server/tools/LDAPSearch.java b/opends/src/server/org/opends/server/tools/LDAPSearch.java
index 44478c2..af09d4a 100644
--- a/opends/src/server/org/opends/server/tools/LDAPSearch.java
+++ b/opends/src/server/org/opends/server/tools/LDAPSearch.java
@@ -34,6 +34,7 @@
 import java.util.LinkedHashSet;
 import java.util.LinkedList;
 import java.util.StringTokenizer;
+import java.util.concurrent.atomic.AtomicInteger;
 
 import org.opends.server.controls.AccountUsableResponseControl;
 import org.opends.server.controls.EntryChangeNotificationControl;
@@ -87,12 +88,21 @@
    */
   private static final String CLASS_NAME = "org.opends.server.tools.LDAPSearch";
 
+
+
+  // The message ID counter to use for requests.
+  private AtomicInteger nextMessageID;
+
+
+
   /**
    * Constructor for the LDAPSearch object.
    *
+   * @param  nextMessageID  The message ID counter to use for requests.
    */
-  public LDAPSearch()
+  public LDAPSearch(AtomicInteger nextMessageID)
   {
+    this.nextMessageID = nextMessageID;
   }
 
 
@@ -118,11 +128,8 @@
                             int wrapColumn )
          throws IOException, LDAPException
   {
-    int messageID = 1;
     for (LDAPFilter filter: filters)
     {
-      messageID++;
-
       ASN1OctetString asn1OctetStr = new ASN1OctetString(baseDN);
 
       SearchRequestProtocolOp protocolOp =
@@ -135,7 +142,8 @@
       try
       {
         boolean typesOnly = searchOptions.getTypesOnly();
-        LDAPMessage message = new LDAPMessage(messageID, protocolOp,
+        LDAPMessage message = new LDAPMessage(nextMessageID.getAndIncrement(),
+                                              protocolOp,
                                               searchOptions.getControls());
         int numBytes =
             connection.getASN1Writer().writeElement(message.encode());
@@ -1091,11 +1099,12 @@
         connectionOptions.setSSLConnectionFactory(sslConnectionFactory);
       }
 
+      AtomicInteger nextMessageID = new AtomicInteger(1);
       connection = new LDAPConnection(hostNameValue, portNumber,
                                       connectionOptions);
-      connection.connectToHost(bindDNValue, bindPasswordValue);
+      connection.connectToHost(bindDNValue, bindPasswordValue, nextMessageID);
 
-      LDAPSearch ldapSearch = new LDAPSearch();
+      LDAPSearch ldapSearch = new LDAPSearch(nextMessageID);
       ldapSearch.executeSearch(connection, baseDNValue, filters, attributes,
                                searchOptions, wrapColumn);
 

--
Gitblit v1.10.0