Commit 44b17a4d authored by Leigh Stoller's avatar Leigh Stoller

Slight change to geni-lib portal wrap; requesting to dump param defs

does not result in immediate termination. Instead we dump the params
defs to a different file now, and continue on to spit the rspec to the
output file. This complicates returning back to ops though, since now we
have two file. So I elected to do a cheesy tar pack/unpack on the return
trip.
parent bca285c2
...@@ -220,8 +220,13 @@ if (defined($options{"B"})) { ...@@ -220,8 +220,13 @@ if (defined($options{"B"})) {
if (!$ofile && exists($ENV{'GENILIB_PORTAL_REQUEST_PATH'})) { if (!$ofile && exists($ENV{'GENILIB_PORTAL_REQUEST_PATH'})) {
$ofile = $ENV{'GENILIB_PORTAL_REQUEST_PATH'}; $ofile = $ENV{'GENILIB_PORTAL_REQUEST_PATH'};
} }
if (!$pfile && exists($ENV{'GENILIB_PORTAL_PARAMS_PATH'})) { if (!$pfile) {
$pfile = $ENV{'GENILIB_PORTAL_PARAMS_PATH'}; if (exists($ENV{'GENILIB_PORTAL_PARAMS_PATH'})) {
$pfile = $ENV{'GENILIB_PORTAL_PARAMS_PATH'};
}
elsif (exists($ENV{'GENILIB_PORTAL_DUMPPARAMS_PATH'})) {
$pfile = $ENV{'GENILIB_PORTAL_DUMPPARAMS_PATH'};
}
} }
if ($action == 4) { if ($action == 4) {
...@@ -348,7 +353,8 @@ if ($action != 1) { ...@@ -348,7 +353,8 @@ if ($action != 1) {
msg("Stashing files"); msg("Stashing files");
if (mysystem("cp -p $ifile $jailrootdir$j_ifile") || if (mysystem("cp -p $ifile $jailrootdir$j_ifile") ||
($pfile && mysystem("cp -p $pfile $jailrootdir$j_pfile")) || ($pfile && -e $pfile &&
mysystem("cp -p $pfile $jailrootdir$j_pfile")) ||
mysystem("chown -R $uid:$gid $jailrootdir$tempdir")) { mysystem("chown -R $uid:$gid $jailrootdir$tempdir")) {
print STDERR "Could not populate jail\n"; print STDERR "Could not populate jail\n";
exit(-1); exit(-1);
...@@ -359,9 +365,9 @@ if ($action != 1) { ...@@ -359,9 +365,9 @@ if ($action != 1) {
# #
$ENV{'GENILIB_PORTAL_REQUEST_PATH'} = $j_ofile; $ENV{'GENILIB_PORTAL_REQUEST_PATH'} = $j_ofile;
if (exists($ENV{'GENILIB_PORTAL_DUMPPARAMS_PATH'})) { if (exists($ENV{'GENILIB_PORTAL_DUMPPARAMS_PATH'})) {
$ENV{'GENILIB_PORTAL_DUMPPARAMS_PATH'} = $j_ofile; $ENV{'GENILIB_PORTAL_DUMPPARAMS_PATH'} = $j_pfile;
} }
if ($pfile) { elsif (exists($ENV{'GENILIB_PORTAL_PARAMS_PATH'})) {
$ENV{'GENILIB_PORTAL_PARAMS_PATH'} = $j_pfile; $ENV{'GENILIB_PORTAL_PARAMS_PATH'} = $j_pfile;
} }
...@@ -456,6 +462,14 @@ if ($action != 1) { ...@@ -456,6 +462,14 @@ if ($action != 1) {
exit(-1); exit(-1);
} }
} }
if (exists($ENV{'GENILIB_PORTAL_DUMPPARAMS_PATH'}) &&
-e "$jailrootdir$j_pfile") {
if (-l "$jailrootdir$j_pfile" ||
mysystem("cp $jailrootdir$j_pfile $pfile")) {
print STDERR "Could not copy back parameter block\n";
exit(-1);
}
}
} else { } else {
print STDERR "Jail '$jailtag' running. Root FS at '$jailrootdir'.\n"; print STDERR "Jail '$jailtag' running. Root FS at '$jailrootdir'.\n";
} }
......
...@@ -46,7 +46,7 @@ sub usage() ...@@ -46,7 +46,7 @@ sub usage()
exit(-1); exit(-1);
} }
my $optlist = "do:pb:W"; my $optlist = "do:pP:b:W";
my $debug = 0; my $debug = 0;
my $getparams = 0; my $getparams = 0;
my $paramfile; my $paramfile;
...@@ -60,6 +60,7 @@ my $TB = "@prefix@"; ...@@ -60,6 +60,7 @@ my $TB = "@prefix@";
my $TBOPS = "@TBOPSEMAIL@"; my $TBOPS = "@TBOPSEMAIL@";
my $CONTROL = "@USERNODE@"; my $CONTROL = "@USERNODE@";
my $MAINSITE = @TBMAINSITE@; my $MAINSITE = @TBMAINSITE@;
my $TAR = "/usr/bin/tar";
# Locals # Locals
my $SAVEUID = $UID; my $SAVEUID = $UID;
...@@ -113,6 +114,17 @@ if (defined($options{"d"})) { ...@@ -113,6 +114,17 @@ if (defined($options{"d"})) {
if (defined($options{"p"})) { if (defined($options{"p"})) {
$getparams = 1; $getparams = 1;
} }
if (defined($options{"P"})) {
$getparams = 1;
$paramfile = $options{"P"};
# Must taint check!
if ($paramfile =~ /^([-\w\/\.]+)$/) {
$paramfile = $1;
}
else {
die("Bad data in argument: $paramfile.");
}
}
if (defined($options{"W"})) { if (defined($options{"W"})) {
$warningsfatal = 1; $warningsfatal = 1;
} }
...@@ -167,7 +179,8 @@ $EUID = $UID; ...@@ -167,7 +179,8 @@ $EUID = $UID;
# are any define_parameter calls. If so, run the script to get the # are any define_parameter calls. If so, run the script to get the
# JSON block. # JSON block.
# #
if ($getparams && system("egrep -q -s 'defineParameter' $file")) { if ($getparams && !$paramfile &&
system("egrep -q -s 'defineParameter' $file")) {
# No parameters, return empty block. # No parameters, return empty block.
if (defined($ofile)) { if (defined($ofile)) {
system("echo '' > $ofile"); system("echo '' > $ofile");
...@@ -204,7 +217,7 @@ $cmdargs .= ($warningsfatal ? " -W " : ""); ...@@ -204,7 +217,7 @@ $cmdargs .= ($warningsfatal ? " -W " : "");
# We want to send over both files via STDIN, so combine them, and pass # We want to send over both files via STDIN, so combine them, and pass
# the first file size with the -b option # the first file size with the -b option
# #
if ($paramfile) { if ($paramfile && !$getparams) {
system("cat $paramfile > $infile") == 0 system("cat $paramfile > $infile") == 0
or fatal("Could not copy $paramfile to $infile"); or fatal("Could not copy $paramfile to $infile");
...@@ -280,6 +293,41 @@ if ($exit_status) { ...@@ -280,6 +293,41 @@ if ($exit_status) {
# vs script error. # vs script error.
exit($exit_status >> 8); exit($exit_status >> 8);
} }
#
# When getting the params, we get back a tar file. First file has the
# paramdefs and the other is the rspec. Break them apart.
#
if ($getparams) {
my $files = `$TAR tf $outfile`;
my ($p,$r) = split(/\n/, $files);
# Taint check.
if ($p =~ /^([-\w\/\.]+)$/) {
$p = $1;
}
else {
fatal("Bad data in argument: $p.");
}
if ($r =~ /^([-\w\/\.]+)$/) {
$r = $1;
}
else {
fatal("Bad data in argument: $r.");
}
my $tfile = tmpnam();
# Suck out params.
system("$TAR -xOf $outfile $p > $tfile");
if ($paramfile) {
system("cat $tfile > $paramfile");
system("$TAR -xOf $outfile $r > $tfile");
system("/bin/mv $tfile $outfile");
# We also write out the rspec below.
}
else {
# Caller wants only the paramfile.
system("/bin/mv $tfile $outfile");
}
}
if (defined($ofile)) { if (defined($ofile)) {
system("cat $outfile > $ofile"); system("cat $outfile > $ofile");
} }
......
...@@ -56,6 +56,7 @@ my $TBOPS = "@TBOPSEMAIL@"; ...@@ -56,6 +56,7 @@ my $TBOPS = "@TBOPSEMAIL@";
my $TESTMODE = 0; my $TESTMODE = 0;
my $GENILIB = "$TB/lib/geni-lib/"; my $GENILIB = "$TB/lib/geni-lib/";
my $JAILPROG = "$TB/libexec/genilib-jail"; my $JAILPROG = "$TB/libexec/genilib-jail";
my $TAR = "/usr/bin/tar";
my $debug = 0; my $debug = 0;
# Locals # Locals
...@@ -215,7 +216,7 @@ chmod(0644, $ifile); ...@@ -215,7 +216,7 @@ chmod(0644, $ifile);
$ENV{'GENILIB_PORTAL_MODE'} = "Yep"; $ENV{'GENILIB_PORTAL_MODE'} = "Yep";
$ENV{'GENILIB_PORTAL_REQUEST_PATH'} = $ofile; $ENV{'GENILIB_PORTAL_REQUEST_PATH'} = $ofile;
if ($getparams) { if ($getparams) {
$ENV{'GENILIB_PORTAL_DUMPPARAMS_PATH'} = $ofile; $ENV{'GENILIB_PORTAL_DUMPPARAMS_PATH'} = $pfile;
} }
elsif (defined($paramsize) && $paramsize) { elsif (defined($paramsize) && $paramsize) {
$ENV{'GENILIB_PORTAL_PARAMS_PATH'} = $pfile; $ENV{'GENILIB_PORTAL_PARAMS_PATH'} = $pfile;
...@@ -322,8 +323,27 @@ elsif (! -s $ofile) { ...@@ -322,8 +323,27 @@ elsif (! -s $ofile) {
$exit_status = 1; $exit_status = 1;
} }
else { else {
# Send the rspec output to stdout (back to boss). if ($getparams) {
system("cat $ofile"); if (! -e $pfile) {
if (system("egrep -q -s 'defineParameter' $ifile")) {
# No parameters
system("touch $pfile");
}
else {
print STDERR
"Cannot find the params, did you call bindParameters?\n";
$exit_status = 1;
}
}
if (!$exit_status) {
# Send back both params and rspec as a tar file.
system("$TAR cf - $pfile $ofile");
}
}
else {
# Send the rspec output to stdout (back to boss).
system("cat $ofile");
}
} }
unless($debug) { unless($debug) {
if (-d $tempdir) { if (-d $tempdir) {
......
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