Blob Blame History Raw
From 94bde9f69f10e0811e261b5d53e5bebfcd891820 Mon Sep 17 00:00:00 2001
From: Noriko Hosoi <nhosoi@redhat.com>
Date: Tue, 25 Aug 2015 11:48:31 -0700
Subject: [PATCH 50/52] Ticket #48254 - Shell CLI fails with usage errors if an
 argument containing white spaces is given

Description: In addition to the patch:
  Ticket #48254 - CLI db2index fails with usage errors
  commit 3507c46c9f1156df11b6cf05eba695d81088b416
applying the similar changes to all the shell CLI which could be given
arguments that include white spaces.

https://fedorahosted.org/389/ticket/48254

Reviewed by mreynolds@redhat.com (Thank you, Mark!!)

(cherry picked from commit 5fe28921810a53dcd31525ba1f675582b6aba0f7)
(cherry picked from commit 19b0d4af54e319e3479b16bf1366568271e3daa6)
---
 ldap/admin/src/scripts/bak2db.in          | 10 +++++-----
 ldap/admin/src/scripts/db2bak.in          |  8 ++++----
 ldap/admin/src/scripts/db2index.in        | 10 +++++-----
 ldap/admin/src/scripts/db2ldif.in         | 14 +++++++-------
 ldap/admin/src/scripts/dbverify.in        | 10 +++++-----
 ldap/admin/src/scripts/dn2rdn.in          |  8 ++++----
 ldap/admin/src/scripts/ldif2db.in         | 22 +++++++++++-----------
 ldap/admin/src/scripts/monitor.in         |  8 ++++----
 ldap/admin/src/scripts/suffix2instance.in |  4 ++--
 ldap/admin/src/scripts/upgradedb.in       |  8 ++++----
 ldap/admin/src/scripts/upgradednformat.in | 10 +++++-----
 ldap/admin/src/scripts/vlvindex.in        | 16 ++++++++--------
 12 files changed, 64 insertions(+), 64 deletions(-)

diff --git a/ldap/admin/src/scripts/bak2db.in b/ldap/admin/src/scripts/bak2db.in
index a2e54cc..ab7c6b3 100755
--- a/ldap/admin/src/scripts/bak2db.in
+++ b/ldap/admin/src/scripts/bak2db.in
@@ -44,12 +44,12 @@ do
         h) usage
            exit 0;;
         Z) servid=$OPTARG;; 
-        n) args=$args" -n $OPTARG";;
+        n) args=$args" -n \"$OPTARG\"";;
         q) args=$args" -q";;
-        d) args=$args" -d $OPTARG";;
+        d) args=$args" -d \"$OPTARG\"";;
         v) args=$args" -v";;
-        D) args=$args" -D $OPTARG";;
-        i) args=$args" -i $OPTARG";;
+        D) args=$args" -D \"$OPTARG\"";;
+        i) args=$args" -i \"$OPTARG\"";;
         a) archivedir=$OPTARG;;
         S) args=$args" -S";;
         ?) usage
@@ -76,4 +76,4 @@ else
     archivedir=`pwd`/$archivedir
 fi
 
-@sbindir@/ns-slapd archive2db -D $CONFIG_DIR -a $archivedir $args
+eval @sbindir@/ns-slapd archive2db -D $CONFIG_DIR -a $archivedir $args
diff --git a/ldap/admin/src/scripts/db2bak.in b/ldap/admin/src/scripts/db2bak.in
index 1896c19..adbe30b 100755
--- a/ldap/admin/src/scripts/db2bak.in
+++ b/ldap/admin/src/scripts/db2bak.in
@@ -43,10 +43,10 @@ do
         q) args=$args" -q";;
         v) args=$args" -v";;
         S) args=$args" -S";;
-        D) args=$args" -D $OPTARG";;
-        i) args=$args" -i $OPTARG";;
+        D) args=$args" -D \"$OPTARG\"";;
+        i) args=$args" -i \"$OPTARG\"";;
         a) $bakdir=$OPTARG;;
-        d) args=$args" -d $OPTARG";;
+        d) args=$args" -d \"$OPTARG\"";;
         Z) servid=$OPTARG;;
         ?) usage
            exit 1;;
@@ -72,4 +72,4 @@ then
 fi
 
 echo "Back up directory: $bak_dir"
-@sbindir@/ns-slapd db2archive -D $CONFIG_DIR -a $bak_dir $args
+eval @sbindir@/ns-slapd db2archive -D $CONFIG_DIR -a $bak_dir $args
diff --git a/ldap/admin/src/scripts/db2index.in b/ldap/admin/src/scripts/db2index.in
index 6a0785e..c8e9075 100755
--- a/ldap/admin/src/scripts/db2index.in
+++ b/ldap/admin/src/scripts/db2index.in
@@ -35,15 +35,15 @@ do
         h) usage
            exit 0;;
         Z) servid=$OPTARG;; 
-        n) args=$args" -n $OPTARG"
+        n) args=$args" -n \"$OPTARG\""
            benameopt="set";;
-        s) args=$args" -s $OPTARG"
+        s) args=$args" -s \"$OPTARG\""
            includeSuffix="set";;
         t) args=$args" -t "\"$OPTARG\";;
         T) args=$args" -T "\"$OPTARG\";;
-        d) args=$args" -d $OPTARG";;
-        a) args=$args" -a $OPTARG";;
-        x) args=$args" -x $OPTARG";;
+        d) args=$args" -d \"$OPTARG\"";;
+        a) args=$args" -a \"$OPTARG\"";;
+        x) args=$args" -x \"$OPTARG\"";;
         v) args=$args" -v";;
         S) args=$args" -S";;
         D) args=$args" -D $OPTARG";;
diff --git a/ldap/admin/src/scripts/db2ldif.in b/ldap/admin/src/scripts/db2ldif.in
index fcf73a0..e9f7f7e 100755
--- a/ldap/admin/src/scripts/db2ldif.in
+++ b/ldap/admin/src/scripts/db2ldif.in
@@ -106,12 +106,12 @@ do
         Z) servid=$OPTARG;; 
         n) benameopt="-n $OPTARG"
            required_param="yes";;
-        s) includeSuffix="-s $OPTARG"
+        s) includeSuffix="-s \"$OPTARG\""
            required_param="yes";;
-        x) excludeSuffix="-x $OPTARG";;
-        a) outputFile="-a $OPTARG";;
-        d) args=$args" -d $OPTARG";;
-        D) args=$args" -D $OPTARG";;
+        x) excludeSuffix="-x \"$OPTARG\"";;
+        a) outputFile="-a \"$OPTARG\"";;
+        d) args=$args" -d \"$OPTARG\"";;
+        D) args=$args" -D \"$OPTARG\"";;
         N) args=$args" -N";;
         E) args=$args" -E";;
         S) args=$args" -S";;
@@ -154,7 +154,7 @@ rn=$?
 echo "Exported ldif file: $ldif_file"
 if [ $rn -eq 1 ]
 then
-    @sbindir@/ns-slapd db2ldif -D $CONFIG_DIR $benameopt $includeSuffix $excludeSuffix $outputFile $args
+    eval @sbindir@/ns-slapd db2ldif -D $CONFIG_DIR $benameopt $includeSuffix $excludeSuffix $outputFile $args
 else
-    @sbindir@/ns-slapd db2ldif -D $CONFIG_DIR $benameopt $includeSuffix $excludeSuffix $args -a $ldif_file
+    eval @sbindir@/ns-slapd db2ldif -D $CONFIG_DIR $benameopt $includeSuffix $excludeSuffix $args -a $ldif_file
 fi
diff --git a/ldap/admin/src/scripts/dbverify.in b/ldap/admin/src/scripts/dbverify.in
index bbacc17..b98e9b2 100755
--- a/ldap/admin/src/scripts/dbverify.in
+++ b/ldap/admin/src/scripts/dbverify.in
@@ -33,14 +33,14 @@ do
         h) usage
            exit 0;;
         Z) servid=$OPTARG;;
-        n) args=$args" -n $OPTARG";;
-        d) args=$args" -d $OPTARG";;
+        n) args=$args" -n \"$OPTARG\"";;
+        d) args=$args" -d \"$OPTARG\"";;
         V) args=$args" -V";;
         v) args=$args" -v"
            display_version="yes";;
         f) args=$args" -f";;
-        D) args=$args" -D $OPTARG";;
-        a) args=$args" -a $OPTARG";;
+        D) args=$args" -D \"$OPTARG\"";;
+        a) args=$args" -a \"$OPTARG\"";;
         ?) usage
            exit 1;;
     esac
@@ -57,7 +57,7 @@ fi
 
 . $initfile
 
-@sbindir@/ns-slapd dbverify -D $CONFIG_DIR $args
+eval @sbindir@/ns-slapd dbverify -D $CONFIG_DIR $args
 if [ $display_version = "yes" ]; then
     exit 0
 fi
diff --git a/ldap/admin/src/scripts/dn2rdn.in b/ldap/admin/src/scripts/dn2rdn.in
index 616969a..762e63a 100755
--- a/ldap/admin/src/scripts/dn2rdn.in
+++ b/ldap/admin/src/scripts/dn2rdn.in
@@ -27,12 +27,12 @@ do
         h) usage
            exit 0;;
         Z) servid=$OPTARG;;
-        d) arg=$arg" -d $OPTARG";;
-        a) arg=$arg" -a $OPTARG"
+        d) arg=$arg" -d \"$OPTARG\"";;
+        a) arg=$arg" -a \"$OPTARG\""
            archive="provided";;
         v) arg=$arg" -v";;
         f) arg=$arg" -f";;
-        D) arg=$arg" -D $OPTARG";;
+        D) arg=$arg" -D \"$OPTARG\"";;
         ?) usage
            exit 1;;
     esac
@@ -55,4 +55,4 @@ if [ "$archive" != "provided" ]; then
     args=$args"-a $bak_dir"
 fi
 
-@sbindir@/ns-slapd upgradedb -D $CONFIG_DIR -r $args
+eval @sbindir@/ns-slapd upgradedb -D $CONFIG_DIR -r $args
diff --git a/ldap/admin/src/scripts/ldif2db.in b/ldap/admin/src/scripts/ldif2db.in
index a34241a..3aed469 100755
--- a/ldap/admin/src/scripts/ldif2db.in
+++ b/ldap/admin/src/scripts/ldif2db.in
@@ -59,16 +59,16 @@ do
         h) usage
            exit 0;;
         Z) servid=$OPTARG;;
-        n) args=$args" -n $OPTARG";;
-        i) args=$args" -i $OPTARG";;
-        s) args=$args" -s $OPTARG";;
-        x) args=$args" -x $OPTARG";;
-        c) args=$args" -c $OPTARG";;
-        d) args=$args" -d $OPTARG";;
-        g) args=$args" -g $OPTARG";;
-        G) args=$args" -G $OPTARG";;
-        t) args=$args" -t $OPTARG";;
-        D) args=$args" -D $OPTARG";;
+        n) args=$args" -n \"$OPTARG\"";;
+        i) args=$args" -i \"$OPTARG\"";;
+        s) args=$args" -s \"$OPTARG\"";;
+        x) args=$args" -x \"$OPTARG\"";;
+        c) args=$args" -c \"$OPTARG\"";;
+        d) args=$args" -d \"$OPTARG\"";;
+        g) args=$args" -g \"$OPTARG\"";;
+        G) args=$args" -G \"$OPTARG\"";;
+        t) args=$args" -t \"$OPTARG\"";;
+        D) args=$args" -D \"$OPTARG\"";;
         E) args=$args" -E";;
         v) args=$args" -v";;
         N) args=$args" -N";;
@@ -104,6 +104,6 @@ if [ $quiet -eq 0 ]; then
     echo importing data ...
 fi
 
-@sbindir@/ns-slapd ldif2db -D $CONFIG_DIR $args 2>&1
+eval @sbindir@/ns-slapd ldif2db -D $CONFIG_DIR $args 2>&1
 
 exit $?
diff --git a/ldap/admin/src/scripts/monitor.in b/ldap/admin/src/scripts/monitor.in
index 36a2fc9..e9265a1 100755
--- a/ldap/admin/src/scripts/monitor.in
+++ b/ldap/admin/src/scripts/monitor.in
@@ -73,8 +73,8 @@ fi
 rm $file
 
 if [ -n "$passwd" ]; then
-    dn="-D $rootdn"
-    passwd="-w$passwd"
+    dn="-D \"$rootdn\""
+    passwd="-w \"$passwd\""
 fi
 if [ -n "$ldapiURL" ]
 then
@@ -109,9 +109,9 @@ if [ "$security" = "on" ]; then
             echo "Using the next most secure protocol(STARTTLS)"
         fi
         if [ "$openldap" = "yes" ]; then
-            ldapsearch -x -LLL -ZZ -h $host -p $port -b "$MDN" -s base $dn $passwd "objectClass=*"
+            eval ldapsearch -x -LLL -ZZ -h $host -p $port -b "$MDN" -s base $dn $passwd "objectClass=*"
         else
-            ldapsearch -ZZZ -P $certdir  -h $host -p $port -b "$MDN" -s base $dn $passwd "objectClass=*"
+            eval ldapsearch -ZZZ -P $certdir  -h $host -p $port -b "$MDN" -s base $dn $passwd "objectClass=*"
         fi
         exit $?
     fi
diff --git a/ldap/admin/src/scripts/suffix2instance.in b/ldap/admin/src/scripts/suffix2instance.in
index 7774148..d7c6661 100755
--- a/ldap/admin/src/scripts/suffix2instance.in
+++ b/ldap/admin/src/scripts/suffix2instance.in
@@ -24,7 +24,7 @@ while getopts "Z:s:h" flag
 do
     case $flag in
         Z) servid=$OPTARG;;
-        s) args=$args" -s $OPTARG";;
+        s) args=$args" -s \"$OPTARG\"";;
         h) usage
            exit 0;;
         ?) usage
@@ -55,4 +55,4 @@ then
     exit 1
 fi
 
-@sbindir@/ns-slapd suffix2instance -D $CONFIG_DIR $args 2>&1
+eval @sbindir@/ns-slapd suffix2instance -D $CONFIG_DIR $args 2>&1
diff --git a/ldap/admin/src/scripts/upgradedb.in b/ldap/admin/src/scripts/upgradedb.in
index bf600dd..2b7c79d 100755
--- a/ldap/admin/src/scripts/upgradedb.in
+++ b/ldap/admin/src/scripts/upgradedb.in
@@ -29,10 +29,10 @@ do
         v) args=$args" -v";;
         f) args=$args" -f";;
         r) args=$args" -r";;
-        d) args=$args" -d $OPTARG";;
-        a) args=$args" -a $OPTARG"
+        d) args=$args" -d \"$OPTARG\"";;
+        a) args=$args" -a \"$OPTARG\""
            archive_provided="yes";;
-        D) args=$args" -D $OPTARG";;
+        D) args=$args" -D \"$OPTARG\"";;
         h) usage
            exit 0;;
     esac
@@ -56,4 +56,4 @@ then
 fi
 
 echo upgrade index files ...
-@sbindir@/ns-slapd upgradedb -D $CONFIG_DIR $args
+eval @sbindir@/ns-slapd upgradedb -D $CONFIG_DIR $args
diff --git a/ldap/admin/src/scripts/upgradednformat.in b/ldap/admin/src/scripts/upgradednformat.in
index 51585ae..9de60ea 100755
--- a/ldap/admin/src/scripts/upgradednformat.in
+++ b/ldap/admin/src/scripts/upgradednformat.in
@@ -36,14 +36,14 @@ do
         Z) servid=$OPTARG;;
         v) args=$args" -v";;
         N) args=$args" -N";;
-        d) args=$args" -d $OPTARG";;
-        a) args=$args" -a $OPTARG"
+        d) args=$args" -d \"$OPTARG\"";;
+        a) args=$args" -a \"$OPTARG\""
            dir="set";;
-        n) args=$args" -n $OPTARG"
+        n) args=$args" -n \"$OPTARG\""
            be="set";;
         h) usage
            exit 0;;
-        D) args=$args" -D $OPTARG";;
+        D) args=$args" -D \"$OPTARG\"";;
         ?) usage
            exit 1;;
     esac
@@ -65,7 +65,7 @@ fi
 
 . $initfile
 
-@sbindir@/ns-slapd upgradednformat -D $CONFIG_DIR $args
+eval @sbindir@/ns-slapd upgradednformat -D $CONFIG_DIR $args
 rc=$?
 
 exit $rc
diff --git a/ldap/admin/src/scripts/vlvindex.in b/ldap/admin/src/scripts/vlvindex.in
index 365e32f..a1696bc 100755
--- a/ldap/admin/src/scripts/vlvindex.in
+++ b/ldap/admin/src/scripts/vlvindex.in
@@ -29,14 +29,14 @@ do
     case $flag in
         Z) servid=$OPTARG;;
         v) args=$args" -v";;
-        s) args=$args" -s $OPTARG";;
-        d) args=$args" -d $OPTARG";;
-        a) args=$args" -a $OPTARG";;
-        T) args=$args" -T $OPTARG";;
+        s) args=$args" -s \"$OPTARG\"";;
+        d) args=$args" -d \"$OPTARG\"";;
+        a) args=$args" -a \"$OPTARG\"";;
+        T) args=$args" -T \"$OPTARG\"";;
         S) args=$args" -S";;
-        n) args=$args" -n $OPTARG";;
-        x) args=$args" -x $OPTARG";;
-        D) args=$args" -D $OPTARG";;
+        n) args=$args" -n \"$OPTARG\"";;
+        x) args=$args" -x \"$OPTARG\"";;
+        D) args=$args" -D \"$OPTARG\"";;
         h) usage
            exit 0;;
         ?) usage
@@ -61,4 +61,4 @@ then
     exit 1
 fi
 
-@sbindir@/ns-slapd db2index -D $CONFIG_DIR $args
+eval @sbindir@/ns-slapd db2index -D $CONFIG_DIR $args
-- 
1.9.3