Improve lsh's handling of -l user option w/cd.
authorWayne Davison <wayned@samba.org>
Sat, 9 Apr 2011 15:33:55 +0000 (08:33 -0700)
committerWayne Davison <wayned@samba.org>
Sat, 9 Apr 2011 15:51:26 +0000 (08:51 -0700)
support/lsh

index 65488dc..8ccc5a2 100755 (executable)
@@ -7,7 +7,6 @@
 # command.
 
 user=''
 # command.
 
 user=''
-prefix=''
 do_cd=y # Default path is user's home dir, just like ssh.
 
 while : ; do
 do_cd=y # Default path is user's home dir, just like ssh.
 
 while : ; do
@@ -22,14 +21,13 @@ while : ; do
 done
 
 if [ "$user" ]; then
 done
 
 if [ "$user" ]; then
-    prefix="sudo -H -u '$user'"
+    prefix=''
     if [ $do_cd = y ]; then
        home=`perl -e "print((getpwnam('$user'))[7])"`
     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
+       prefix="cd '$home' ;"
     fi
     fi
-elif [ $do_cd = y ]; then
-    cd
+    sudo -H -u "$user" sh -c "$prefix $*"
+else
+    [ $do_cd = y ] && cd
+    eval "${@}"
 fi
 fi
-
-eval $prefix "${@}"