From 8f01668d5cb0b62e1d6ace8660ba32b445dd978a Mon Sep 17 00:00:00 2001
From: jvergara <jvergara@localhost>
Date: Mon, 02 Nov 2009 18:16:31 +0000
Subject: [PATCH] Fix for issue 4332 (Tools fail when instance path contains whitespace) The problem is in the code in charge of checking the install and instance paths and contents.  There are issues both in the scripts and in the code of org.opends.server.tools.configurator.CheckInstance.  Using quotes fixes the issue in the script and using an array of String instead of a single command-line to launch the "ls" process.

---
 opendj-sdk/opends/resource/bin/_script-util.sh                                       |   16 ++++++++--------
 opendj-sdk/opends/src/server/org/opends/server/tools/configurator/CheckInstance.java |   23 +++++++++++++++++------
 2 files changed, 25 insertions(+), 14 deletions(-)

diff --git a/opendj-sdk/opends/resource/bin/_script-util.sh b/opendj-sdk/opends/resource/bin/_script-util.sh
index 47a58b4..d892176 100644
--- a/opendj-sdk/opends/resource/bin/_script-util.sh
+++ b/opendj-sdk/opends/resource/bin/_script-util.sh
@@ -145,18 +145,18 @@
 
 # Configure the appropriate CLASSPATH.
 set_classpath() {
-  CLASSPATH=${INSTANCE_ROOT}/classes
-  for JAR in ${INSTALL_ROOT}/resources/*.jar
+  CLASSPATH="${INSTANCE_ROOT}/classes"
+  for JAR in "${INSTALL_ROOT}/resources/"*.jar
   do
     CLASSPATH=${CLASSPATH}:${JAR}
   done
-  for JAR in ${INSTALL_ROOT}/lib/*.jar
+  for JAR in "${INSTALL_ROOT}/lib/"*.jar
   do
     CLASSPATH=${CLASSPATH}:${JAR}
   done
   if [ "${INSTALL_ROOT}" != "${INSTANCE_ROOT}" ]
   then
-    for JAR in ${INSTANCE_ROOT}/lib/*.jar
+    for JAR in "${INSTANCE_ROOT}/lib/"*.jar
     do
       CLASSPATH=${CLASSPATH}:${JAR}
     done
@@ -192,7 +192,7 @@
 
 if test "${INSTANCE_ROOT}" = ""
 then
-  if [ -f ${INSTALL_ROOT}/configure ]
+  if [ -f "${INSTALL_ROOT}/configure" ]
   then
     if [ -f /etc/opends/instance.loc ]
     then
@@ -218,7 +218,7 @@
       fi
     fi
   else
-    if [ -f ${INSTALL_ROOT}/instance.loc ]
+    if [ -f "${INSTALL_ROOT}/instance.loc" ]
     then
       read location < ${INSTALL_ROOT}/instance.loc
       case `echo ${location}` in
@@ -256,7 +256,7 @@
   set_java_home_and_args
   set_environment_vars
   set_classpath
-elif test "${SCRIPT_UTIL_CMD}" = "set-java-home-and-args"
+ elif test "${SCRIPT_UTIL_CMD}" = "set-java-home-and-args"
 then
   set_java_home_and_args
 elif test "${SCRIPT_UTIL_CMD}" = "set-environment-vars"
@@ -308,7 +308,7 @@
 	  OPT_CHECK_VERSION=""
       fi
   # Launch the CheckInstance process.
-      "${OPENDS_JAVA_BIN}" ${SCRIPT_NAME_ARG} -DINSTALL_ROOT=${INSTALL_ROOT} -DINSTANCE_ROOT=${INSTANCE_ROOT} org.opends.server.tools.configurator.CheckInstance --currentUser ${CURRENT_USER} ${OPT_CHECK_VERSION}
+      "${OPENDS_JAVA_BIN}" ${SCRIPT_NAME_ARG} "-DINSTALL_ROOT=${INSTALL_ROOT}" "-DINSTANCE_ROOT=${INSTANCE_ROOT}" org.opends.server.tools.configurator.CheckInstance --currentUser ${CURRENT_USER} ${OPT_CHECK_VERSION}
   # return part
       RETURN_CODE=$?
       if [ ${RETURN_CODE} -ne 0 ]
diff --git a/opendj-sdk/opends/src/server/org/opends/server/tools/configurator/CheckInstance.java b/opendj-sdk/opends/src/server/org/opends/server/tools/configurator/CheckInstance.java
index b54ab67..7c9474c 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/tools/configurator/CheckInstance.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/tools/configurator/CheckInstance.java
@@ -213,16 +213,24 @@
      if (!isWin) {
     // Check user
     File conf = new File (confDir, Installation.CURRENT_CONFIG_FILE_NAME);
-    String cmd = null;
     Process proc = null;
     int exit = 0;
 
     InputStreamReader reader = null;
     int c;
     StringBuffer sb = new StringBuffer();
-    cmd = "ls -l " + conf.getAbsolutePath();
+    String[] cmdArgs = {"ls", "-l", conf.getAbsolutePath()};
+    StringBuilder cmd = new StringBuilder();
+    for (String arg : cmdArgs)
+    {
+      if (cmd.length() > 0)
+      {
+        cmd.append(" ");
+      }
+      cmd.append(arg);
+    }
     try {
-      proc = Runtime.getRuntime().exec(cmd);
+      proc = Runtime.getRuntime().exec(cmdArgs);
       proc.waitFor();
       reader = new InputStreamReader(proc.getInputStream());
       while (((c = reader.read()) != -1)) {
@@ -231,18 +239,21 @@
       exit = proc.exitValue();
       if (exit != 0) {
         LOG.log(Level.FINEST, cmd + " error= " + exit);
-        System.err.println(ERR_CONFIG_LDIF_NOT_FOUND.get(conf.getAbsolutePath(),
+        System.err.println(ERR_CONFIG_LDIF_NOT_FOUND.get(
+            confDir.getAbsolutePath(),
             installRootFromSystem + File.separator + "instance.loc"));
         System.exit(ReturnCode.APPLICATION_ERROR.getReturnCode());
       }
     } catch (InterruptedException ex) {
       LOG.log(Level.SEVERE, "InterruptedException" + ex.getMessage());
-      System.err.println(ERR_CONFIG_LDIF_NOT_FOUND.get(conf.getAbsolutePath(),
+      System.err.println(
+          ERR_CONFIG_LDIF_NOT_FOUND.get(confDir.getAbsolutePath(),
           installRootFromSystem + File.separator + "instance.loc"));
       System.exit(ReturnCode.APPLICATION_ERROR.getReturnCode());
     } catch (IOException ex) {
       LOG.log(Level.SEVERE, "IOException" + ex.getMessage() );
-      System.err.println(ERR_CONFIG_LDIF_NOT_FOUND.get(conf.getAbsolutePath(),
+      System.err.println(ERR_CONFIG_LDIF_NOT_FOUND.get(
+          confDir.getAbsolutePath(),
           installRootFromSystem + File.separator + "instance.loc"));
       System.exit(ReturnCode.APPLICATION_ERROR.getReturnCode());
     }

--
Gitblit v1.10.0