From 4287153a2c0323d20e6619c4ea52fa8057ff946d Mon Sep 17 00:00:00 2001
From: coulbeck <coulbeck@localhost>
Date: Wed, 25 Jul 2007 17:31:32 +0000
Subject: [PATCH] Fix for issue #1015: ldapsearch --verbose option doesn't work. This change causes ldapsearch and ldapmodify verbose options to trace the contents of incoming and outgoing LDAP messages and ASN.1 elements to standard error stream. It excludes search-result-entry messages from the trace since this would be rather too verbose and not very useful. The main use for verbose output is to investigate connection problems, referral following and such. A possible improvement would be to use a separate option for the ASN.1 tracing, and add session related output such as connection details, security context details and auth details as well as referral chasing details (all this must currently be derived from the protocol trace).

---
 opends/src/server/org/opends/server/tools/LDAPConnection.java |   53 ++++++++++++++++++++++++++---------------------------
 1 files changed, 26 insertions(+), 27 deletions(-)

diff --git a/opends/src/server/org/opends/server/tools/LDAPConnection.java b/opends/src/server/org/opends/server/tools/LDAPConnection.java
index 0145bba..af2ba8a 100644
--- a/opends/src/server/org/opends/server/tools/LDAPConnection.java
+++ b/opends/src/server/org/opends/server/tools/LDAPConnection.java
@@ -39,8 +39,6 @@
 import org.opends.server.controls.PasswordPolicyResponseControl;
 import org.opends.server.controls.PasswordPolicyWarningType;
 import org.opends.server.protocols.asn1.ASN1OctetString;
-import org.opends.server.protocols.asn1.ASN1Reader;
-import org.opends.server.protocols.asn1.ASN1Writer;
 import org.opends.server.protocols.ldap.ExtendedRequestProtocolOp;
 import org.opends.server.protocols.ldap.ExtendedResponseProtocolOp;
 import org.opends.server.protocols.ldap.LDAPControl;
@@ -80,8 +78,8 @@
   private int portNumber = 389;
 
   private LDAPConnectionOptions connectionOptions = null;
-  private ASN1Writer asn1Writer;
-  private ASN1Reader asn1Reader;
+  private LDAPWriter ldapWriter;
+  private LDAPReader ldapReader;
   private int versionNumber = 3;
 
   private PrintStream out;
@@ -154,19 +152,21 @@
                             AtomicInteger nextMessageID)
                             throws LDAPConnectionException
   {
-    Socket socket = null;
+    Socket socket;
     Socket startTLSSocket = null;
-    int resultCode = -1;
+    int resultCode;
     ArrayList<LDAPControl> requestControls = new ArrayList<LDAPControl> ();
     ArrayList<LDAPControl> responseControls = new ArrayList<LDAPControl> ();
 
+    VerboseTracer tracer =
+         new VerboseTracer(connectionOptions.isVerbose(), err);
     if(connectionOptions.useStartTLS())
     {
       try
       {
         startTLSSocket = new Socket(hostName, portNumber);
-        asn1Writer = new ASN1Writer(startTLSSocket);
-        asn1Reader = new ASN1Reader(startTLSSocket);
+        ldapWriter = new LDAPWriter(startTLSSocket, tracer);
+        ldapReader = new LDAPReader(startTLSSocket, tracer);
       } catch(UnknownHostException uhe)
       {
         int msgID = MSGID_RESULT_CLIENT_SIDE_CONNECT_ERROR;
@@ -196,10 +196,10 @@
                                         extendedRequest);
       try
       {
-        asn1Writer.writeElement(msg.encode());
+        ldapWriter.writeMessage(msg);
 
         // Read the response from the server.
-        msg = LDAPMessage.decode(asn1Reader.readElement().decodeAsSequence());
+        msg = ldapReader.readMessage();
       } catch (Exception ex1)
       {
         if (debugEnabled())
@@ -236,8 +236,8 @@
       {
         socket = new Socket(hostName, portNumber);
       }
-      asn1Writer = new ASN1Writer(socket);
-      asn1Reader = new ASN1Reader(socket);
+      ldapWriter = new LDAPWriter(socket, tracer);
+      ldapReader = new LDAPReader(socket, tracer);
     } catch(UnknownHostException uhe)
     {
       int msgID = MSGID_RESULT_CLIENT_SIDE_CONNECT_ERROR;
@@ -285,7 +285,7 @@
     }
 
     LDAPAuthenticationHandler handler = new LDAPAuthenticationHandler(
-            asn1Reader, asn1Writer, hostName, nextMessageID);
+         ldapReader, ldapWriter, hostName, nextMessageID);
     try
     {
       ASN1OctetString bindPW;
@@ -441,7 +441,7 @@
    */
   public void close(AtomicInteger nextMessageID)
   {
-    if(asn1Writer != null)
+    if(ldapWriter != null)
     {
       if (nextMessageID != null)
       {
@@ -449,38 +449,37 @@
         {
           LDAPMessage message = new LDAPMessage(nextMessageID.getAndIncrement(),
                                                 new UnbindRequestProtocolOp());
-          asn1Writer.writeElement(message.encode());
+          ldapWriter.writeMessage(message);
         } catch (Exception e) {}
       }
 
-      asn1Writer.close();
+      ldapWriter.close();
     }
-    if(asn1Reader != null)
+    if(ldapReader != null)
     {
-      asn1Reader.close();
+      ldapReader.close();
     }
   }
 
   /**
-   * Get the underlying ASN1 writer.
+   * Get the underlying LDAP writer.
    *
-   * @return  The underlying ASN.1 writer.
+   * @return  The underlying LDAP writer.
    */
-  public ASN1Writer getASN1Writer()
+  public LDAPWriter getLDAPWriter()
   {
-    return asn1Writer;
+    return ldapWriter;
   }
 
   /**
-   * Get the underlying ASN1 reader.
+   * Get the underlying LDAP reader.
    *
-   * @return  The underlying ASN.1 reader.
+   * @return  The underlying LDAP reader.
    */
-  public ASN1Reader getASN1Reader()
+  public LDAPReader getLDAPReader()
   {
-    return asn1Reader;
+    return ldapReader;
   }
 
-
 }
 

--
Gitblit v1.10.0