From: Wayne Davison Date: Wed, 12 Jan 2005 19:20:07 +0000 (+0000) Subject: - Allow multiple source paths to be specified (and checked). X-Git-Url: https://mattmccutchen.net/rsync/rsync.git/commitdiff_plain/106a8ad918498850614791736f508dcb2244af56 - Allow multiple source paths to be specified (and checked). - Allow spaces and a few other extra chars in file names. - For safety, disallow any option that takes an arg. This should be improved in the future because it blocks options such as --block-size=N, but without this rule the user could specify something like --files-from=FILE or --backup-dir=DIR and have it affect files outside the desired SUBDIR restriction. - Switched to SSH_CONNECTION from the deprecated SSH_CLIENT. - Strip "::ffff:" from the start of an IP from SSH_CONNECTION. --- diff --git a/support/rrsync b/support/rrsync index 6b50b28e..88bf4f91 100644 --- a/support/rrsync +++ b/support/rrsync @@ -1,12 +1,13 @@ #!/usr/bin/perl -# Name: /usr/local/bin/rrsync Author: Joe Smith 30-Sep-2004 +# Name: /usr/local/bin/rrsync (should also have a symlink in /usr/bin) # Purpose: Restricts rsync to subdirectory declared in .ssh/authorized_keys -# (should have a symlink in /usr/bin) +# Author: Joe Smith 30-Sep-2004 +# Modified by Wayne Davison 12-Jan-2005 use Socket; use constant LOGFILE => 'rrsync.log'; my $Usage = <*?#\$ + s/(\s)/\\$1/g; # Re-escape whitespace + push(@dirs, $_); +} +push(@dirs, $subdir) unless @dirs; +$dir = join(' ', @dirs); if (-f LOGFILE and open LOG,'>>',LOGFILE) { my ($mm,$hh) = (localtime)[1,2]; - my $host = $ENV{SSH_CLIENT} || 'unknown'; + my $host = $ENV{SSH_CONNECTION} || 'unknown'; $host =~ s/ .*//; # Keep only the client's IP addr + $host =~ s/^::ffff://; $host = gethostbyaddr(inet_aton($host),AF_INET) || $host; - $_ = sprintf "%-13s",$host; - print LOG "$hh:$mm $_ [$command] =",($dir eq $orig ? " OK" : "> $dir"),"\n"; + my $dir_result = $dir eq $orig ? " OK" : "> \"$dir\""; + printf LOG "%02d:%02d %-13s [%s] =%s\n", $hh, $mm, $host, $command, $dir_result; close LOG; } -exec "$cmd $dir" or die "exec($cmd $dir) failed: $? $!"; +exec "$cmd \"$dir\"" or die "exec($cmd \"$dir\") failed: $? $!"; # Note: This assumes that the rsync protocol will not be maliciously hijacked.