#!/usr/bin/perl -wT use English; use Getopt::Std; # # This gets invoked from the Web interface. CD into the proper directory # and do the tb stuff. This script cannot do any damage since it can # only create directories where the caller has the permission to do so. # sub usage() { print STDOUT "Usage: mkexpdir \n"; exit(-1); } # # Configure variables # my $TB = "@prefix@"; my $TBOPS = "@TBOPSEMAIL@"; # # Should be configured. # my $projroot = "/proj"; # # Testbed Support libraries # use lib "@prefix@/lib"; use libdb; use libtestbed; my $tbdata = "tbdata"; my @dirlist = ($tbdata, "bin", "tmp", "logs", "tftpboot"); # # Turn off line buffering on output # $| = 1; # # Untaint the path # $ENV{'PATH'} = '/bin:/usr/bin'; delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'}; # # Check args. # if (@ARGV != 3) { usage(); } my $pid = $ARGV[0]; my $gid = $ARGV[1]; my $eid = $ARGV[2]; # # Untaint the arguments. # if ($pid =~ /^([-\@\w.]+)$/) { $pid = $1; } else { die("Tainted project name: $pid!\n"); } if ($eid =~ /^([-\@\w.]+)$/) { $eid = $1; } else { die("Tainted experiment name: $eid!\n"); } if ($gid =~ /^([-\@\w.]+)$/) { $gid = $1; } else { die("Tainted group name: $gid!\n"); } my $piddir = "$projroot/$pid"; my $expdir = "$piddir/exp"; my $eiddir = "$expdir/$eid"; # # Unix info for the group # my $unix_gid; my $unix_name; if (! TBGroupUnixInfo($pid, $gid, \$unix_gid, \$unix_name)) { die("*** No info for project/group $pid/$gid!"); } # # We create a directory structure for the experiment in the project directory. # if (! chdir($expdir)) { print STDOUT "Could not chdir to $expdir: $!\n"; exit(-1); } if (! mkdir($eid, 0770)) { print STDOUT "Could not mkdir $eid in $expdir: $!\n"; exit(-1); } if (! chmod(0770, "$eid")) { print STDOUT "Could not chmod $eid to 0770 in $expdir: $!\n"; rmdir($eid); exit(-1); } if (! chown($UID, $unix_gid, "$eid")) { print STDOUT "Could not chown $eid to $UID/$unix_gid in $expdir: $!\n"; rmdir($eid); exit(-1); } if (! chdir($eid)) { print STDOUT "Could not chdir to $eid in $expdir: $!\n"; rmdir($eid); exit(-1); } # # Create the experiment directory list in the new directory. # foreach $dir (@dirlist) { if (! mkdir($dir, 0770)) { print STDOUT "Could not mkdir $dir in $eiddir: $!\n"; fatal(); } if (! chmod(0770, "$dir")) { print STDOUT "Could not chmod $dir to 0770 in $eiddir: $!\n"; fatal(); } } # # Update the DB. This leaves the decision about where the directory # is created, in this script. # DBQueryFatal("update experiments set path='$eiddir' ". "where pid='$pid' and eid='$eid'"); exit(0); sub fatal() { if (! chdir($expdir)) { print STDOUT "In Fatal: Could not chdir to $expdir!\n"; exit(-1); } system("rm -r $eid"); exit(-1); }