From e37e08cc3e556fb78be9d69f2c1ac8e2399189dd Mon Sep 17 00:00:00 2001
From: lutoff <lutoff@localhost>
Date: Thu, 14 Jun 2007 13:08:47 +0000
Subject: [PATCH] Add bindPassword Argument 

---
 opends/src/server/org/opends/server/admin/client/cli/DsServiceCliMain.java       |    8 ++++
 opends/src/server/org/opends/server/admin/client/cli/DsServiceCliReturnCode.java |    8 +++
 opends/src/server/org/opends/server/admin/client/cli/DsServiceCliParser.java     |   59 +++++++++++++++++++++++++++++
 3 files changed, 74 insertions(+), 1 deletions(-)

diff --git a/opends/src/server/org/opends/server/admin/client/cli/DsServiceCliMain.java b/opends/src/server/org/opends/server/admin/client/cli/DsServiceCliMain.java
index 5cf9a8c..a753bdc 100644
--- a/opends/src/server/org/opends/server/admin/client/cli/DsServiceCliMain.java
+++ b/opends/src/server/org/opends/server/admin/client/cli/DsServiceCliMain.java
@@ -208,6 +208,14 @@
       return ReturnCode.ERROR_PARSING_ARGS.getReturnCode();
     }
 
+    // Validate args
+    int ret = argParser.validateGlobalOption(err);
+    if (ret != ReturnCode.SUCCESSFUL_NOP.getReturnCode())
+    {
+      return ret;
+    }
+
+
     // Get connection parameters
     String host = argParser.getHostName() ;
     String port = argParser.getPort() ;
diff --git a/opends/src/server/org/opends/server/admin/client/cli/DsServiceCliParser.java b/opends/src/server/org/opends/server/admin/client/cli/DsServiceCliParser.java
index dc8466a..e9aeade 100644
--- a/opends/src/server/org/opends/server/admin/client/cli/DsServiceCliParser.java
+++ b/opends/src/server/org/opends/server/admin/client/cli/DsServiceCliParser.java
@@ -92,6 +92,11 @@
   private FileBasedArgument bindPasswordFileArg = null;
 
   /**
+   * The 'bindPassword' global argument.
+   */
+  private StringArgument bindPasswordArg = null;
+
+  /**
    * The 'verbose' global argument.
    */
   private BooleanArgument verboseArg = null;
@@ -190,6 +195,11 @@
         "cn=Directory Manager", null, MSGID_DESCRIPTION_BINDDN);
     addGlobalArgument(bindDnArg);
 
+    bindPasswordArg = new StringArgument("bindPassword",
+        OPTION_SHORT_BINDPWD, OPTION_LONG_BINDPWD, false, false, true,
+        OPTION_VALUE_BINDPWD, null, null, MSGID_DESCRIPTION_BINDPASSWORD);
+    addGlobalArgument(bindPasswordArg);
+
     bindPasswordFileArg = new FileBasedArgument("bindPasswordFile",
         OPTION_SHORT_BINDPWD_FILE, OPTION_LONG_BINDPWD_FILE, false, false,
         OPTION_VALUE_BINDPWD_FILE, null, null,
@@ -272,6 +282,30 @@
    */
   public String getBindPassword(String dn, PrintStream out, PrintStream err)
   {
+    if (bindPasswordArg.isPresent())
+    {
+      String bindPasswordValue = bindPasswordArg.getValue();
+      if(bindPasswordValue != null && bindPasswordValue.equals("-"))
+      {
+        // read the password from the stdin.
+        try
+        {
+          out.print(getMessage(MSGID_LDAPAUTH_PASSWORD_PROMPT, dn));
+          char[] pwChars = PasswordReader.readPassword();
+          bindPasswordValue = new String(pwChars);
+        } catch(Exception ex)
+        {
+          if (debugEnabled())
+          {
+            TRACER.debugCaught(DebugLogLevel.ERROR, ex);
+          }
+          err.println(wrapText(ex.getMessage(), MAX_LINE_WIDTH));
+          return null;
+        }
+      }
+      return bindPasswordValue;
+    }
+    else
     if (bindPasswordFileArg.isPresent())
     {
       return bindPasswordFileArg.getValue();
@@ -348,4 +382,29 @@
       return false ;
     }
   }
+
+  /**
+   * Indication if provided global options are validate.
+   *
+   * @param err the stream to be used to print error message.
+   *
+   * @return return code.
+   */
+  public int validateGlobalOption(PrintStream err)
+  {
+    ReturnCode returnCode = ReturnCode.SUCCESSFUL_NOP;
+
+    // Couldn't have at the same time bindPassword and bibdPasswordFile
+    if(bindPasswordArg.isPresent() && bindPasswordFileArg.isPresent())
+    {
+      int    msgID   = MSGID_TOOL_CONFLICTING_ARGS;
+      String message = getMessage(msgID, bindPasswordArg.getLongIdentifier(),
+                                  bindPasswordFileArg.getLongIdentifier());
+      err.println(wrapText(message, MAX_LINE_WIDTH));
+      return returnCode.CONFLICTING_ARGS.getReturnCode();
+    }
+
+    return ReturnCode.SUCCESSFUL_NOP.getReturnCode();
+  }
+
 }
diff --git a/opends/src/server/org/opends/server/admin/client/cli/DsServiceCliReturnCode.java b/opends/src/server/org/opends/server/admin/client/cli/DsServiceCliReturnCode.java
index 202ca4d..cc9290b 100644
--- a/opends/src/server/org/opends/server/admin/client/cli/DsServiceCliReturnCode.java
+++ b/opends/src/server/org/opends/server/admin/client/cli/DsServiceCliReturnCode.java
@@ -27,6 +27,7 @@
 package org.opends.server.admin.client.cli;
 
 import static org.opends.server.messages.AdminMessages.*;
+import static org.opends.server.messages.ToolMessages.*;
 
 import java.util.HashMap;
 
@@ -136,7 +137,12 @@
     /**
      * Unexpected error (potential bug).
      */
-    ERROR_UNEXPECTED(17, MSGID_ADMIN_ERROR_UNEXPECTED);
+    ERROR_UNEXPECTED(17, MSGID_ADMIN_ERROR_UNEXPECTED),
+
+    /**
+     * Unexpected error (potential bug).
+     */
+    CONFLICTING_ARGS(18, MSGID_ADMIN_NO_MESSAGE);
 
     // The retunCodevalue of the value.
     private final int returnCode;

--
Gitblit v1.10.0