Added a --no-cd option to support/lsh so that the script can be used by
authorWayne Davison <wayned@samba.org>
Fri, 18 Apr 2008 14:20:30 +0000 (07:20 -0700)
committerWayne Davison <wayned@samba.org>
Sat, 19 Apr 2008 02:41:57 +0000 (19:41 -0700)
the testsuite.  Improved the home-directory-changing code and added an
error message when "localhost" is not the hostname specified.  Use the
updated script in the testsuite instead of creating a pretend-ssh script
in a couple spots.

support/lsh
testsuite/daemon.test
testsuite/ssh-basic.test

index 20ebc3d..2017126 100755 (executable)
@@ -6,18 +6,30 @@
 # we get a -l USER option, we try to use "sudo -u USER" to run the
 # command.
 
+user=''
 prefix=''
-
-cd # Default path is home dir, just like ssh.
+do_cd=y # Default path is user's home dir, just like ssh.
 
 while : ; do
     case "$1" in
-    -l) shift ; prefix="sudo -u $1"; shift ;;
-    -l*) prefix=`echo $1 | sed 's/-l/sudo -u /'`; shift ;;
+    -l) user="$2"; shift; shift ;;
+    -l*) user=`echo $1 | sed 's/^-l//'`; shift ;;
+    --no-cd) do_cd=n; shift ;;
     -*) shift ;;
     localhost) shift; break ;;
-    *) exit 1 ;;
+    *) echo "lsh: unable to connect to host $1" 1>&2; exit 1 ;;
     esac
 done
 
+if [ "$user" ]; then
+    prefix="sudo -H -u $user"
+    if [ $do_cd = y ]; then
+       home=`perl -e "print((getpwnam("$user"))[7])"`
+       # Yeah, this may fail, but attempts to get sudo to cd are harder.
+       cd $home
+    fi
+elif [ $do_cd = y ]; then
+    cd
+fi
+
 eval $prefix "${@}"
index 7717843..994a994 100644 (file)
 
 . "$suitedir/rsync.fns"
 
-SSH="$scratchdir/pretend-ssh"
-
-cat >"$SSH" <<'EOT'
-while : ; do
-    case "$1" in
-    -*) shift ;;
-    localhost) shift; break ;;
-    *) exit 1 ;;
-    esac
-done
-
-eval "${@}"
-EOT
-chmod +x "$SSH"
+SSH="src/support/lsh --no-cd"
 
 build_rsyncd_conf
 
@@ -54,7 +41,7 @@ case `id -u` in
     ;;
 esac
 
-$RSYNC -ve $SSH --rsync-path="$RSYNC$confopt" localhost::
+$RSYNC -ve "$SSH" --rsync-path="$RSYNC$confopt" localhost::
 
 RSYNC_CONNECT_PROG="$RSYNC --config=$conf --daemon"
 export RSYNC_CONNECT_PROG
index 7586ae5..10b2c88 100644 (file)
 
 . "$suitedir/rsync.fns"
 
-SSH="$scratchdir/pretend-ssh"
-
-cat >"$SSH" <<'EOT'
-while : ; do
-    case "$1" in
-    -*) shift ;;
-    localhost) shift; break ;;
-    *) exit 1 ;;
-    esac
-done
-
-eval "${@}"
-EOT
-chmod +x "$SSH"
+SSH=support/lsh
 
 if test x"$rsync_enable_ssh_tests" = xyes; then
     if type ssh >/dev/null ; then
@@ -31,7 +18,7 @@ if test x"$rsync_enable_ssh_tests" = xyes; then
     fi
 fi
 
-if ! [ "`"$SSH" -o'BatchMode yes' localhost echo yes`" = "yes" ]; then
+if ! [ "`$SSH -o'BatchMode yes' localhost echo yes`" = "yes" ]; then
     test_skipped "Skipping SSH tests because ssh conection to localhost not authorised"
 fi