From 7008381ae6c2eb1fd67a1cc50b8e78dbc2fc78c6 Mon Sep 17 00:00:00 2001
From: jvergara <jvergara@localhost>
Date: Fri, 20 Jul 2007 17:11:56 +0000
Subject: [PATCH] Fix for issue 2006.

---
 opends/src/server/org/opends/server/tools/InstallDS.java       |   33 ++++++++++++++++
 opends/src/server/org/opends/server/messages/ToolMessages.java |   11 +++++
 opends/src/server/org/opends/server/tools/ConfigureDS.java     |   50 +++++++++++++++++++++++++
 3 files changed, 93 insertions(+), 1 deletions(-)

diff --git a/opends/src/server/org/opends/server/messages/ToolMessages.java b/opends/src/server/org/opends/server/messages/ToolMessages.java
index 8c1094a..adc3cd7 100644
--- a/opends/src/server/org/opends/server/messages/ToolMessages.java
+++ b/opends/src/server/org/opends/server/messages/ToolMessages.java
@@ -9143,7 +9143,13 @@
   public static final int MSGID_DSCFG_ERROR_UNABLE_TO_SET_NAMING_PROPERTY =
        CATEGORY_MASK_TOOLS | SEVERITY_MASK_SEVERE_ERROR | 1210;
 
-
+  /**
+   * The message ID for the message that will be used if the user specifies
+   * the same port for different protocols.  This takes as argument the value of
+   * the culprit port.
+   */
+  public static final int MSGID_CONFIGDS_PORT_ALREADY_SPECIFIED  =
+    CATEGORY_MASK_TOOLS | SEVERITY_MASK_SEVERE_ERROR | 1211;
 
   /**
    * Associates a set of generic messages with the message IDs defined in this
@@ -10476,6 +10482,9 @@
                     "Server configuration:  %s");
     registerMessage(MSGID_CONFIGDS_NO_CONFIG_CHANGES,
                     "ERROR:  No configuration changes were specified");
+    registerMessage(MSGID_CONFIGDS_PORT_ALREADY_SPECIFIED,
+                    "ERROR:  You have specified the value %s for different " +
+                    "ports.");
     registerMessage(MSGID_CONFIGDS_WROTE_UPDATED_CONFIG,
                     "Successfully wrote the updated Directory Server " +
                     "configuration");
diff --git a/opends/src/server/org/opends/server/tools/ConfigureDS.java b/opends/src/server/org/opends/server/tools/ConfigureDS.java
index 9b2bc52..756fc29 100644
--- a/opends/src/server/org/opends/server/tools/ConfigureDS.java
+++ b/opends/src/server/org/opends/server/tools/ConfigureDS.java
@@ -28,7 +28,9 @@
 
 
 
+import java.util.HashSet;
 import java.util.LinkedList;
+import java.util.Set;
 
 import org.opends.server.api.ConfigHandler;
 import org.opends.server.config.BooleanConfigAttribute;
@@ -329,6 +331,54 @@
       return 1;
     }
 
+    try
+    {
+      Set<Integer> ports = new HashSet<Integer>();
+      if (ldapPort.isPresent())
+      {
+        ports.add(ldapPort.getIntValue());
+      }
+      if (ldapsPort.isPresent())
+      {
+        if (ports.contains(ldapsPort.getIntValue()))
+        {
+          int    msgID   = MSGID_CONFIGDS_PORT_ALREADY_SPECIFIED;
+          String message = getMessage(msgID,
+              String.valueOf(ldapsPort.getIntValue()));
+          System.err.println(wrapText(message, MAX_LINE_WIDTH));
+          System.err.println(argParser.getUsage());
+          return 1;
+        }
+        else
+        {
+          ports.add(ldapsPort.getIntValue());
+        }
+      }
+      if (jmxPort.isPresent())
+      {
+        if (ports.contains(jmxPort.getIntValue()))
+        {
+          int    msgID   = MSGID_CONFIGDS_PORT_ALREADY_SPECIFIED;
+          String message = getMessage(msgID,
+              String.valueOf(jmxPort.getIntValue()));
+          System.err.println(wrapText(message, MAX_LINE_WIDTH));
+          System.err.println(argParser.getUsage());
+          return 1;
+        }
+        else
+        {
+          ports.add(jmxPort.getIntValue());
+        }
+      }
+    }
+    catch (ArgumentException ae)
+    {
+      int    msgID   = MSGID_CANNOT_INITIALIZE_ARGS;
+      String message = getMessage(msgID, ae.getMessage());
+      System.err.println(wrapText(message, MAX_LINE_WIDTH));
+      return 1;
+    }
+
 
     // Initialize the Directory Server configuration handler using the
     // information that was provided.
diff --git a/opends/src/server/org/opends/server/tools/InstallDS.java b/opends/src/server/org/opends/server/tools/InstallDS.java
index fcfbf8c..679f741 100644
--- a/opends/src/server/org/opends/server/tools/InstallDS.java
+++ b/opends/src/server/org/opends/server/tools/InstallDS.java
@@ -32,7 +32,9 @@
 import java.io.File;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.HashSet;
 import java.util.LinkedList;
+import java.util.Set;
 
 import org.opends.server.core.DirectoryServer;
 import org.opends.server.extensions.ConfigFileHandler;
@@ -334,6 +336,37 @@
       return 0;
     }
 
+    try
+    {
+      Set<Integer> ports = new HashSet<Integer>();
+      if (ldapPort.isPresent())
+      {
+        ports.add(ldapPort.getIntValue());
+      }
+      if (jmxPort.isPresent())
+      {
+        if (ports.contains(jmxPort.getIntValue()))
+        {
+          int    msgID   = MSGID_CONFIGDS_PORT_ALREADY_SPECIFIED;
+          String message = getMessage(msgID,
+              String.valueOf(jmxPort.getIntValue()));
+          System.err.println(wrapText(message, MAX_LINE_WIDTH));
+          System.err.println(argParser.getUsage());
+          return 1;
+        }
+        else
+        {
+          ports.add(jmxPort.getIntValue());
+        }
+      }
+    }
+    catch (ArgumentException ae)
+    {
+      int    msgID   = MSGID_CANNOT_INITIALIZE_ARGS;
+      String message = getMessage(msgID, ae.getMessage());
+      System.err.println(wrapText(message, MAX_LINE_WIDTH));
+      return 1;
+    }
 
     // Make sure that the user didn't provide conflicting arguments.
     if (addBaseEntry.isPresent())

--
Gitblit v1.10.0