webcopy.in 1.35 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
#!/usr/bin/perl -w

#
# EMULAB-COPYRIGHT
# Copyright (c) 2005 University of Utah and the Flux Group.
# All rights reserved.
#

use English;

#
# Configure variables
#
my $TB			= "@prefix@";
my $FSDIR_PROJ		= "@FSDIR_PROJ@";
my $FSDIR_GROUPS	= "@FSDIR_GROUPS@";

use lib "@prefix@/lib";
use libdb;
use libtestbed;

if ($UID == 0) {
    die("*** $0: Cannot be run as root\n");
}

# un-taint path
$ENV{'PATH'} = "/bin:/usr/bin:/usr/local/bin:$TB/bin";
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};

#
# Handle command-line arguments
#
sub usage() {
    warn "Usage: $0 <src> <dst>\n";
    exit(-1);
}

if (@ARGV != 2) {
    usage();
}

$src = `realpath $ARGV[0]`;
if ($src =~ /^([-\w\/.]+)$/) {
    $src = $1;
} else {
    die("*** Tainted source: $src\n");
}

$dst = `realpath $ARGV[1]`;
if ($dst =~ /^([-\w\/.]+)$/) {
    $dst = $1;
} else {
    die("*** Tainted destination: $dst\n");
}

my $tmpdir = $ENV{'TMPDIR'};
57
$tmpdir = "/var/tmp"
58
    if (!defined($tmpdir));
59
if ($src =~ /^($tmpdir\/php[\w]+)$/) {
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
    $src = $1;
} else {
    die("*** Source isn't a php temp file.\n");
}

my $pr = PROJROOT();
my $gr = GROUPROOT();
if ($dst =~ /^(($pr|$FSDIR_PROJ|$gr|$FSDIR_GROUPS)\/[-\w\/.]+)$/) {
    $dst = $1;
} else {
    die("*** Destination must be in " 
	. PROJROOT() . " or " . GROUPROOT() . "\n");
}

system("cp $src $dst");
75
if (-e $dst) {
76 77 78
    chmod(0644, $dst);
}

79
exit $?;