Commit 3f167217 authored by Kirk Webb's avatar Kirk Webb
Browse files

Update the use of realpath across all perl scripts

Change to use the realpath function in the 'Cwd' module instead of
calling realpath via the shell.  The shell command varies in its
reaction to a missing final path component.  On some platforms (Linux,
FBSD10+) realpath reports an error if the final component doesn't exist
on the filesystem.  On others (FBSD < 10), it does not report an error.

The perl function from 'Cwd' emulates the same behavior as FBSD prior to
version 10, which is the behavior the scripts expect.

From here on out, instead of using `realpath`, do the following:

use Cwd qw(realpath);
..
..
my $realpath = realpath($somepath);
parent 1aa8ec9b
......@@ -4,6 +4,7 @@
use strict;
use libinstall;
use installvars;
use Cwd qw(realpath);
sub Install($$$)
{
......@@ -54,7 +55,7 @@ sub Install($$$)
}
foreach my $dir (@dirs) {
if ($dir ne $SHAREROOT) {
my $dir = `realpath $dir`;
my $dir = realpath($dir);
chomp($dir);
my $dev = (stat($dir))[0];
push @{$filesystems{$dev}}, $dir;
......@@ -82,7 +83,7 @@ sub Install($$$)
# but to the control network read-only.
#
if ($SHAREDIR && ISFS($server)) {
my $realdir = `realpath $SHAREROOT`;
my $realdir = realpath($SHAREROOT);
chomp($realdir);
push(@exports_lines,
"$realdir\t$BOSSNODE -maproot=root");
......
......@@ -33,6 +33,7 @@ use Getopt::Std;
use XML::Simple;
use File::Temp qw(tempfile);
use Data::Dumper;
use Cwd qw(realpath);
#
# Create a quick VM.
......@@ -192,7 +193,7 @@ else {
}
# Use realpath to resolve any symlinks.
my $translated = `realpath $xmlfile`;
my $translated = realpath($xmlfile);
if ($translated =~ /^(\/tmp\/[-\w\.\/]+)$/) {
$xmlfile = $1;
}
......
......@@ -34,6 +34,7 @@ use XML::LibXML;
use Data::Dumper;
use Date::Parse;
use Time::Local;
use Cwd qw(realpath);
#
# Verify a GENI credential.
......@@ -148,7 +149,7 @@ else {
fatal("Tainted filename: $xmlfile");
}
# Use realpath to resolve any symlinks.
my $translated = `realpath $xmlfile`;
my $translated = realpath($xmlfile);
if ($translated =~ /^(\/tmp\/[-\w\.\/]+)$/) {
$xmlfile = $1;
}
......
......@@ -30,6 +30,7 @@
use strict;
use English;
use Getopt::Std;
use Cwd qw(realpath);
#
# Update a certificate using the existing private key.
......@@ -116,9 +117,9 @@ sub UpdateCert($$)
{
my ($certfile, $keyfile) = @_;
$keyfile = `realpath $keyfile`;
$keyfile = realpath($keyfile);
chomp($keyfile);
$certfile = `realpath $certfile`;
$certfile = realpath($certfile);
chomp($certfile);
#
......
......@@ -27,6 +27,7 @@ use POSIX qw(isatty setsid);
use POSIX qw(strftime);
use Errno qw(EDQUOT);
use RPC::XML;
use Cwd qw(realpath);
#
# Create an experiment. The experiment is either run immediately, or
......@@ -1006,7 +1007,7 @@ sub ParseArgs()
#
# Use realpath to resolve any symlinks.
#
my $translated = `realpath $tempnsfile`;
my $translated = realpath($tempnsfile);
if ($translated =~ /^([-\w\.\/]+)$/) {
$tempnsfile = $1;
}
......
......@@ -25,6 +25,7 @@
use English;
use Getopt::Std;
use Cwd qw(realpath);
#
# Syntax check an NS file.
......@@ -103,7 +104,7 @@ else {
#
# Use realpath to resolve any symlinks.
#
my $translated = `realpath $tempfile`;
my $translated = realpath($tempfile);
if ($translated =~ /^([-\w\.\/]+)$/) {
$tempfile = $1;
}
......
......@@ -25,6 +25,7 @@ use strict;
use English;
use Getopt::Std;
use POSIX qw(mktime);
use Cwd qw(realpath);
#
# Spew a tar/rpm file to stdout.
......@@ -222,7 +223,7 @@ sub VerifyFile()
# Use realpath to remove any symlinks to make sure we are not going
# to hand out a file outside the appropriate files systems.
#
my $translated = `realpath $file`;
my $translated = realpath($file);
if ($translated =~ /^([-\@\w\.\/]+)$/) {
$translated = $1;
}
......
......@@ -25,6 +25,7 @@ use strict;
use English;
use Getopt::Std;
use POSIX qw(mktime);
use Cwd qw(realpath);
#
# Spew a tar/rpm file to stdout.
......@@ -148,7 +149,7 @@ sub VerifyFile()
# Use realpath to remove any symlinks to make sure we are not going
# to hand out a file outside the appropriate files systems.
#
my $translated = `realpath $file`;
my $translated = realpath($file);
if ($translated =~ /^([-\@\w\.\/]+)$/) {
$translated = $1;
}
......
......@@ -27,6 +27,7 @@ use English;
use Getopt::Std;
use POSIX qw(isatty setsid);
use RPC::XML;
use Cwd qw(realpath);
#
# This gets invoked from the Web interface.
......@@ -286,7 +287,7 @@ if ($inout eq "modify" && @ARGV > 2) {
#
# Use realpath to resolve any symlinks.
#
my $translated = `realpath $tempnsfile`;
my $translated = realpath($tempnsfile);
if ($translated =~ /^([-\w\.\/]+)$/) {
$tempnsfile = $1;
}
......
......@@ -27,6 +27,7 @@ use Getopt::Std;
use POSIX qw(isatty setsid);
use POSIX qw(strftime);
use Errno qw(EDQUOT);
use Cwd qw(realpath);
#
# Create a new experiment template.
......@@ -956,7 +957,7 @@ sub ParseArgs()
#
# Use realpath to resolve any symlinks.
#
my $translated = `realpath $inputfile`;
my $translated = realpath($inputfile);
if ($translated =~ /^([-\w\.\/]+)$/) {
$inputfile = $1;
}
......
......@@ -31,6 +31,7 @@ use XML::Simple;
use File::Find;
use File::stat;
use Data::Dumper;
use Cwd qw(realpath);
#
# Start/Stop/Pause experiment runs ...
......@@ -995,7 +996,7 @@ sub ParseArgs()
#
# Use realpath to resolve any symlinks.
#
my $translated = `realpath $inputfile`;
my $translated = realpath($inputfile);
if ($translated =~ /^([-\w\.\/]+)$/) {
$inputfile = $1;
}
......
......@@ -29,6 +29,7 @@ use POSIX qw(strftime);
use Errno qw(EDQUOT);
use XML::Simple;
use Data::Dumper;
use Cwd qw(realpath);
#
# Create a new experiment template.
......@@ -739,7 +740,7 @@ sub ParseArgs()
#
# Use realpath to resolve any symlinks.
#
my $translated = `realpath $inputfile`;
my $translated = realpath($inputfile);
if ($translated =~ /^([-\w\.\/]+)$/) {
$inputfile = $1;
}
......
......@@ -24,6 +24,7 @@
use English;
use strict;
use Getopt::Std;
use Cwd qw(realpath);
#
# Add metadata to a template.
......@@ -238,7 +239,7 @@ sub ParseArgs()
#
# Use realpath to resolve any symlinks.
#
my $translated = `realpath $inputfile`;
my $translated = realpath($inputfile);
if ($translated =~ /^([-\w\.\/]+)$/) {
$inputfile = $1;
}
......
......@@ -26,6 +26,7 @@ use English;
use Getopt::Std;
use POSIX qw(setsid :sys_wait_h);
use File::Basename;
use Cwd qw(realpath);
#
# Image Creation Tuneables.
......@@ -391,7 +392,7 @@ if ($isglobal && ($filename =~ /^\/usr\/testbed/)) {
#
# Use realpath to resolve any symlinks.
#
my $translated = `realpath $filename`;
my $translated = realpath($filename);
if ($translated =~ /^([-\w\.\/\+]+)$/) {
$filename = $1;
}
......
......@@ -28,6 +28,7 @@ use XML::Simple;
use Data::Dumper;
use Date::Parse;
use Time::Local;
use Cwd qw(realpath);
#
# Add (or update) an emulab site record.
......@@ -117,7 +118,7 @@ else {
}
# Use realpath to resolve any symlinks.
my $translated = `realpath $xmlfile`;
my $translated = realpath($xmlfile);
if ($translated =~ /^(\/tmp\/[-\w\.\/]+)$/) {
$xmlfile = $1;
}
......
......@@ -23,6 +23,7 @@
#
use English;
use File::Basename;
use Cwd qw(realpath);
#
# Forceably chown a directory hierarchy to the real uid of the invoker.
......@@ -88,7 +89,7 @@ else {
die("*** Tainted source: $pathname\n");
}
$pathname = `realpath $pathname`;
$pathname = realpath($pathname);
if ($pathname =~ /^([-\w\/.]+)$/) {
$pathname = $1;
......
......@@ -24,6 +24,7 @@
#
use English;
use Cwd qw(realpath);
#
# Configure variables
......@@ -56,14 +57,14 @@ if (@ARGV != 2) {
usage();
}
$src = `realpath $ARGV[0]`;
$src = realpath($ARGV[0]);
if ($src =~ /^([-\w\/.]+)$/) {
$src = $1;
} else {
die("*** Tainted source: $src\n");
}
$dst = `realpath $ARGV[1]`;
$dst = realpath($ARGV[1]);
if ($dst =~ /^([-\w\/.]+)$/) {
$dst = $1;
} else {
......
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