#!/usr/bin/perl # Name: /usr/local/bin/rrsync (should also have a symlink in /usr/bin) # Purpose: Restricts rsync to subdirectory declared in .ssh/authorized_keys # 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_CONNECTION} || 'unknown'; $host =~ s/ .*//; # Keep only the client's IP addr $host =~ s/^::ffff://; $host = gethostbyaddr(inet_aton($host),AF_INET) || $host; 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: $? $!"; # Note: This assumes that the rsync protocol will not be maliciously hijacked.