#!/usr/bin/perl # Name: /usr/local/bin/rrsync (should have a symlink in /usr/bin) # Purpose: Restricts rsync to subdirectory declared in .ssh/authorized_keys # # The client uses "rsync -av -e ssh src/ server:dir/", and sshd on the server # executes this program when .ssh/authorized_keys has 'command="..."'. # For example: # command="rrsync logs/client" ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAIEAzGhEeNlPr... # command="rrsync -ro results" ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAIEAmkHG1WCjC... # The former limits the remote client to a specific subdirectory of "logs" # and the latter allows read-only access to a different dirctory. use Socket; use constant LOGFILE => 'rrsync.log'; my $Usage = <>',LOGFILE) { my $hhmm = sprintf "%02d:%02d",(localtime)[2,1]; my $host = $ENV{SSH_CLIENT} || 'unknown'; $host =~ s/ .*//; # Keep only the client's IP addr $host = gethostbyaddr(inet_aton($host),AF_INET) || $host; $_ = sprintf "%-13s",$host; print LOG "$hhmm $_ [$command] =",($forced ? "> $target" : ' OK'),"\n"; close LOG; } exec "$cmd $target" or die "exec($cmd $target) failed: $? $!"; # Note: This assumes that the rsync protocol will not be maliciously hijacked.