Diff for /embedaddon/rsync/support/lsh between versions 1.1.1.1 and 1.1.1.2

version 1.1.1.1, 2012/02/17 15:09:30 version 1.1.1.2, 2013/10/14 07:51:15
Line 1 Line 1
#!/bin/sh#!/usr/bin/perl
 # This script can be used as a "remote shell" command that is only  # This script can be used as a "remote shell" command that is only
 # capable of pretending to connect to "localhost".  This is useful  # capable of pretending to connect to "localhost".  This is useful
 # for testing or for running a local copy where the sender and the  # for testing or for running a local copy where the sender and the
 # receiver needs to use different options (e.g. --fake-super).  If  # receiver needs to use different options (e.g. --fake-super).  If
# we get a -l USER option, we try to use "sudo -u USER" to run the# we get -l USER, we try to become the USER, either directly (must
# command.# be root) or by using "sudo -H -u USER" (requires --sudo option).
   
user=''use strict;
do_cd=y # Default path is user's home dir, just like ssh.use warnings;
 use Getopt::Long;
 use English '-no_match_vars';
   
while : ; do&Getopt::Long::Configure('bundling');
    case "$1" in&Getopt::Long::Configure('require_order');
    -l) user="$2"; shift; shift ;;GetOptions(
    -l*) user=`echo "$1" | sed 's/^-l//'`; shift ;;    'l=s' => \( my $login_name ),
    --no-cd) do_cd=n; shift ;;    '1|2|4|6|A|a|C|f|g|k|M|N|n|q|s|T|t|V|v|X|x|Y' => sub { }, # Ignore
    -*) shift ;;    'b|c|D|e|F|i|L|m|O|o|p|R|S|w=s' => sub { }, # Ignore
    localhost) shift; break ;;    'no-cd' => \( my $no_chdir ),
    *) echo "lsh: unable to connect to host $1" 1>&2; exit 1 ;;    'sudo' => \( my $use_sudo ),
    esac) or &usage;
done&usage unless @ARGV > 1;
   
if [ "$user" ]; thenmy $host = shift;
    prefix=''if ($host =~ s/^([^@]+)\@//) {
    if [ $do_cd = y ]; then    $login_name = $1;
        home=`perl -e "print((getpwnam('$user'))[7])"`}
        prefix="cd '$home' ;"if ($host ne 'localhost') {
    fi    die "lsh: unable to connect to host $host\n";
    sudo -H -u "$user" sh -c "$prefix $*"}
else
    [ $do_cd = y ] && cdmy ($home_dir, @cmd);
    eval "${@}"if ($login_name) {
fi    my ($uid, $gid);
     if ($login_name =~ /\D/) {
         $uid = getpwnam($login_name);
         die "Unknown user: $login_name\n" unless defined $uid;
     } else {
         $uid = $login_name;
     }
     ($login_name, $gid, $home_dir) = (getpwuid($uid))[0,3,7];
     if ($use_sudo) {
         unshift @ARGV, "cd '$home_dir' &&" unless $no_chdir;
         unshift @cmd, qw( sudo -H -u ), $login_name;
         $no_chdir = 1;
     } else {
         my $groups = "$gid $gid";
         while (my ($grgid, $grmembers) = (getgrent)[2,3]) {
             if ($grgid != $gid && $grmembers =~ /(^|\s)\Q$login_name\E(\s|$)/o) {
                 $groups .= " $grgid";
             }
         }
 
         my ($ruid, $euid) = ($UID, $EUID);
         $GID = $EGID = $groups;
         $UID = $EUID = $uid;
         die "Cannot set ruid: $! (use --sudo?)\n" if $UID == $ruid && $ruid != $uid;
         die "Cannot set euid: $! (use --sudo?)\n" if $EUID == $euid && $euid != $uid;
 
         $ENV{USER} = $ENV{USERNAME} = $login_name;
         $ENV{HOME} = $home_dir;
     }
 } else {
     $home_dir = (getpwuid($UID))[7];
 }
 
 unless ($no_chdir) {
     chdir $home_dir or die "Unable to chdir to $home_dir: $!\n";
 }
 
 push @cmd, '/bin/sh', '-c', "@ARGV";
 exec @cmd;
 die "Failed to exec: $!\n";
 
 sub usage
 {
     die <<EOT;
 Usage: lsh [-l user] [--sudo] [--no-cd] localhost COMMAND [...]
 EOT
 }

Removed from v.1.1.1.1  
changed lines
  Added in v.1.1.1.2


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>