+chdir($subdir) or die "$0: Unable to chdir to restricted dir: $!\n";
+
+my(@opts, @args);
+my $in_options = 1;
+my $last_opt = '';
+my $check_type;
+while ($command =~ /((?:[^\s\\]+|\\.[^\s\\]*)+)/g) {
+ $_ = $1;
+ if ($check_type) {
+ push(@opts, check_arg($last_opt, $_, $check_type));
+ $check_type = 0;
+ } elsif ($in_options) {
+ push(@opts, $_);
+ if ($_ eq '.') {
+ $in_options = 0;
+ } else {
+ next if /^-$short_no_arg+$/o || /^-$short_with_num\d+$/o;
+
+ my($opt,$arg) = /^--([^=]+)(?:=(.*))?$/;
+ my $disabled;
+ if (defined $opt) {
+ my $ct = $long_opt{$opt};
+ last unless defined $ct;
+ next if $ct == 0;
+ if ($ct > 0) {
+ if (!defined $arg) {
+ $check_type = $ct;
+ $last_opt = $opt;
+ next;
+ }
+ $arg = check_arg($opt, $arg, $ct);
+ $opts[-1] =~ s/=.*/=$arg/;
+ next;
+ }
+ $disabled = 1;
+ $opt = "--$opt";
+ } elsif ($short_disabled ne '') {
+ $disabled = /^-$short_no_arg*([$short_disabled])/o;
+ $opt = "-$1";
+ }
+
+ last unless $disabled; # Generate generic failure
+ die "$0: option $opt has been disabled on this server.\n";
+ }
+ } else {
+ if ($subdir ne '/') {
+ # Validate args to ensure they don't try to leave our restricted dir.
+ s#//+#/#g;
+ s#^/##;
+ s#^$#.#;
+ die "Do not use .. in any path!\n" if m#(^|/)\\?\.\\?\.(\\?/|$)#;
+ }
+ push(@args, bsd_glob($_, GLOB_LIMIT|GLOB_NOCHECK|GLOB_BRACE|GLOB_QUOTE));
+ }
+}
+die "$0: invalid rsync-command syntax or options\n" if $in_options;
+
+@args = ( '.' ) if !@args;
+
+if ($write_log) {