ASNMTAP
view release on metacpan or search on metacpan
applications/tools/templates/master/rsync-wrapper-failover-template.sh view on Meta::CPAN
# ------------------------------------------------------------------------------
# DON'T TOUCH BELOW HERE UNLESS YOU KNOW WHAT YOU ARE DOING!
# ------------------------------------------------------------------------------
my @options = ('-logDtpr', '-nlogDtpr', '-vlogDtpr', '-vnlogDtpr',
'-logDtprz', '-nlogDtprz', '-vlogDtprz', '-vnlogDtprz',
'-logDtprc', '-nlogDtprc', '-vlogDtprc', '-vnlogDtprc',
'-logDtprcz', '-nlogDtprcz', '-vlogDtprcz', '-vnlogDtprcz',
'-logDtprcze.s', '-nlogDtprcze.s', '-vlogDtprcze.s', '-vnlogDtprcze.s',
'-logDtprcze.is', '-nlogDtprcze.is', '-vlogDtprcze.is', '-vnlogDtprcze.is');
my $TRUE = (0 == 0);
my $FALSE = (0 == 1);
my $debug = $FALSE;
# ------------------------------------------------------------------------------
my ($rvOpen, $dummy, $argPos);
$rvOpen = open (SSHOUT, "+>>$filename");
unless ( $rvOpen ) {
print STDERR "Couldn't open log '$filename'!\n";
exit 0;
}
my $now = localtime;
# Unset the path, so all commands must have the full path. This avoids any path attacks.
delete $ENV{PATH};
# Since this script is called as a forced command, need to get the original rsync command given by the client.
(my $command = $ENV{SSH_ORIGINAL_COMMAND}) || print SSHOUT ("$now environment variable SSH_ORIGINAL_COMMAND not set\n");
unless ( $command ) { print "$now $denyString\n"; close (SSHOUT); exit 1; }
# Log the command for tracking and debugging purposes
print SSHOUT ("$now EVALUATING: $command\n") if ($debug);
# Split the command string to make an argument list
# Evaluate each argument separately for exactness this will allow easy addition of future rsync calls
my @rsync_argv = split /[ \t]+/, $command;
my $ok = $TRUE;
print SSHOUT ("ARG0 = $rsync_argv[0]\n") if ($debug);
print SSHOUT ("ARG1 = $rsync_argv[1]\n") if ($debug);
print SSHOUT ("ARG2 = $rsync_argv[2]\n") if ($debug);
print SSHOUT ("ARG3 = $rsync_argv[3]\n") if ($debug);
print SSHOUT ("ARG4 = $rsync_argv[4]\n") if ($debug);
if ( $rsync_version_2_6_7_or_higher ) {
print SSHOUT ("ARG5 = $rsync_argv[5]\n") if ($debug && $rsync_argv[2] eq '--sender');
} else {
print SSHOUT ("ARG5 = $rsync_argv[5]\n") if ($debug);
print SSHOUT ("ARG6 = $rsync_argv[6]\n") if ($debug);
print SSHOUT ("ARG7 = $rsync_argv[7]\n") if ($debug && $rsync_argv[2] eq '--sender');
}
# ARG[0] Complain if the command is not 'rsync'.
unless ($rsync_argv[0] =~ 'rsync') {
print SSHOUT ("ssh authorized_key account restricted: only rsync allowed\n");
$ok = $FALSE;
}
# ARG[1] Complain if this arg is not --server
unless ($rsync_argv[1] eq '--server') {
print SSHOUT ("ARG[1] <$rsync_argv[1]> Failure: this arg is not --server\n");
$ok = $FALSE;
}
# ARG[2] Check if this arg is --sender
if ($rsync_argv[2] eq '--sender') {
$argPos = 3;
} else {
$argPos = 2;
}
# ARG[$argPos] Complain if this arg is not in @options
my $option;
my $teller = 0;
foreach $option (@options) { if ($rsync_argv[$argPos] eq $option) { $teller++; } }
unless ( $teller != 0 ) {
print SSHOUT ("ARG[$argPos] <$rsync_argv[$argPos]> Failure: this arg is not in \@options\n");
$ok = $FALSE;
}
unless ( $rsync_version_2_6_7_or_higher ) {
# ARG[$argPos] Complain if this arg is not --delete
( run in 0.479 second using v1.01-cache-2.11-cpan-39bf76dae61 )