Commit b7da9e3a authored by Leigh B. Stoller's avatar Leigh B. Stoller

Allow local vs upload file specification, and do proper checks to make

sure the file specified is in /proj or /users.
parent deca74d5
......@@ -182,7 +182,8 @@ if ($query_result->numrows == 0) {
# file. The web server is going to delete it once this script returns.
#
if (system("/bin/cp", "$tempfile", "$tempns") != 0) {
fatal("Could not copy $tempfile to $tempns: $!\n");
print STDOUT "Could not copy $tempfile to $tempns.\n";
exit(1);
}
chmod(0770, "$tempns");
......
......@@ -45,7 +45,7 @@ echo "<form enctype=\"multipart/form-data\"
# Select Project
#
echo "<tr>
<td>*Select Project:</td>";
<td colspan=2>*Select Project:</td>";
echo " <td><select name=\"exp_pid\">";
while ($row = mysql_fetch_array($query_result)) {
$project = $row[pid];
......@@ -61,14 +61,14 @@ echo " </td>
# Note DB max length.
#
echo "<tr>
<td>*Name (no blanks):</td>
<td colspan=2>*Name (no blanks):</td>
<td><input type=\"text\" name=\"exp_id\"
size=$TBDB_EIDLEN maxlength=$TBDB_EIDLEN>
</td>
</tr>\n";
echo "<tr>
<td>*Long Name:</td>
<td colspan=2>*Long Name:</td>
<td><input type=\"text\" name=\"exp_name\" size=\"40\">
</td>
</tr>\n";
......@@ -78,14 +78,24 @@ echo "<tr>
# NS file upload.
#
echo "<tr>
<td>*Your NS file:<br>
&nbsp(20K max)</td>
<td><input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"20000\">
<td rowspan>*Your NS file: &nbsp</td>
<td rowspan><center>Upload (20K max)<br>
<br>
Or<br>
<br>
On Server (/proj or /users)
</center></td>
<td rowspan>
<input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"20000\">
<input type=\"file\" name=\"exp_nsfile\" size=\"30\">
<br>
<br>
<input type=\"text\" name=\"exp_localnsfile\" size=\"40\">
</td>
</tr>\n";
#
# Expires, Starts, Ends. Also the hidden Created field.
#
......@@ -100,13 +110,13 @@ if ($month > 12) {
$rest = date("d H:i:s", $utime);
echo "<tr>
<td>Expiration date:</td>
<td colspan=2>Expiration date:</td>
<td><input type=\"text\" value=\"$year:$month:$rest\"
name=\"exp_expires\"></td>
</tr>\n";
echo "<tr>
<td>Experiment starts:</td>
<td colspan=2>Experiment starts:</td>
<td><input type=\"text\" value=\"$year:$thismonth:$rest\"
name=\"exp_start\"></td>
<td><input type=\"hidden\" value=\"$year:$thismonth:$rest\"
......@@ -115,14 +125,14 @@ echo "<tr>
</tr>\n";
echo "<tr>
<td>Experiment ends:</td>
<td colspan=2>Experiment ends:</td>
<td><input type=\"text\" value=\"$year:$month:$rest\"
name=\"exp_end\"></td>
</tr>\n";
?>
<tr>
<td align="center" colspan="2">
<td align="center" colspan="3">
<b><input type="submit" value="Submit"></b></td>
</tr>
</form>
......
......@@ -60,22 +60,68 @@ if (strlen($exp_id) > $TBDB_EIDLEN) {
# Certain of these values must be escaped or otherwise sanitized.
#
$exp_name = addslashes($exp_name);
#
# I am not going to allow shell experiments to be created (No NS file).
#
if (!isset($exp_nsfile) ||
strcmp($exp_nsfile, "") == 0 ||
strcmp($exp_nsfile, "none") == 0) {
# Not allowed to specify both a local and an upload!
#
$speclocal = 0;
$specupload = 0;
if (isset($exp_localnsfile) && strcmp($exp_localnsfile, "")) {
$speclocal = 1;
}
if (isset($exp_nsfile) && strcmp($exp_nsfile, "") &&
strcmp($exp_nsfile, "none")) {
$specupload = 1;
}
if ($speclocal && $specupload) {
USERERROR("You may not specify both an uploaded NS file and an ".
"NS file that is located on the Emulab server", 1);
}
if (!$specupload && strcmp($exp_nsfile_name, "")) {
#
# Catch an invalid filename.
#
USERERROR("The NS file '$exp_nsfile_name' does not appear to be a ".
"valid filename. Please go back and try again.", 1);
}
if ($speclocal) {
#
# Catch an invalid filename and quit now.
# No way to tell from here if this file actually exists, since
# the web server runs as user nobody. The startexp script checks
# for the file before going to ground, so the user will get immediate
# feedback if the filename is bogus.
#
if (strcmp($exp_nsfile_name, "")) {
USERERROR("The NS file '$exp_nsfile_name' does not appear to be a ".
"valid filename. Please go back and try again.", 1);
# Do not allow anything outside of /users or /proj. I don't think there
# is a security worry, but good to enforce it anyway.
#
if (! ereg("^$TBPROJ_DIR/.*" ,$exp_localnsfile) &&
! ereg("^$TBUSER_DIR/.*" ,$exp_localnsfile)) {
USERERROR("You must specify a server resident in file in either ".
"$TBUSER_DIR/ or $TBPROJ_DIR/", 1);
}
$nsfile = $exp_localnsfile;
$nonsfile = 0;
}
elseif ($specupload) {
#
# XXX
# Set the permissions on the NS file so that the scripts can get to it.
# It is owned by nobody, and most likely protected. This leaves the
# script open for a short time. A potential security hazard we should
# deal with at some point.
#
chmod($exp_nsfile, 0666);
$nsfile = $exp_nsfile;
$nonsfile = 0;
}
else {
#
# I am going to allow shell experiments to be created (No NS file).
#
$nonsfile = 1;
}
......@@ -215,15 +261,6 @@ echo "<h2>Starting experiment configuration. Please wait a moment ...
flush();
#
# XXX
# Set the permissions on the NS file so that the scripts can get to it.
# It is owned by nobody, and most likely protected. This leaves the
# script open for a short time. A potential security hazard we should
# deal with at some point.
#
chmod($exp_nsfile, 0666);
#
# Run the scripts. We use a script wrapper to deal with changing
# to the proper directory and to keep most of these details out
......@@ -242,7 +279,7 @@ $last = time();
set_time_limit(0);
$result = exec("$TBSUEXEC_PATH $uid $gid webstartexp $exp_pid ".
"$exp_id $exp_nsfile",
"$exp_id $nsfile",
$output, $retval);
if ($retval) {
......
......@@ -23,7 +23,7 @@ $TBLIST_LEADERS = "$TBLIST_DIR"."/leaders.list";
$TBLIST_USERS = "$TBLIST_DIR"."/users.list";
$TBPROJ_DIR = "/proj";
$TBUSER_DIR = "/users/";
$TBUSER_DIR = "/users";
$TBNSSUBDIR = "nsdir";
$TBAUTHCOOKIE = "HashCookie";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment