From 276cc45571b274349f817a5bbc078f84abb385ce Mon Sep 17 00:00:00 2001 From: Wayne Davison Date: Fri, 18 Apr 2008 07:20:30 -0700 Subject: [PATCH] Added a --no-cd option to support/lsh so that the script can be used by 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 | 22 +++++++++++++++++----- testsuite/daemon.test | 17 ++--------------- testsuite/ssh-basic.test | 17 ++--------------- 3 files changed, 21 insertions(+), 35 deletions(-) diff --git a/support/lsh b/support/lsh index 20ebc3d0..20171269 100755 --- a/support/lsh +++ b/support/lsh @@ -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 "${@}" diff --git a/testsuite/daemon.test b/testsuite/daemon.test index 77178439..994a9944 100644 --- a/testsuite/daemon.test +++ b/testsuite/daemon.test @@ -24,20 +24,7 @@ . "$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 diff --git a/testsuite/ssh-basic.test b/testsuite/ssh-basic.test index 7586ae5b..10b2c884 100644 --- a/testsuite/ssh-basic.test +++ b/testsuite/ssh-basic.test @@ -10,20 +10,7 @@ . "$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 -- 2.34.1