From 45bee9901b94e68b86ff50f0e0629522d5b5800a Mon Sep 17 00:00:00 2001 From: Aurélien Aptel Date: Tue, 16 Jul 2013 00:34:41 +0200 Subject: test_smbclient_tarmode.pl: sanitize input, use File::Temp instead of hardcoding temp dir MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Aurélien Aptel Reviewed-by: David Disseldorp Reviewed-by: Jim McDonough --- source3/script/tests/test_smbclient_tarmode.pl | 27 ++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'source3/script/tests') diff --git a/source3/script/tests/test_smbclient_tarmode.pl b/source3/script/tests/test_smbclient_tarmode.pl index fd2089f6318..0fed72b790f 100755 --- a/source3/script/tests/test_smbclient_tarmode.pl +++ b/source3/script/tests/test_smbclient_tarmode.pl @@ -49,11 +49,13 @@ use warnings; use Archive::Tar; use Data::Dumper; +use Digest::MD5 qw/md5_hex/; use File::Path qw/make_path remove_tree/; +use File::Temp; use Getopt::Long; use Pod::Usage; use Term::ANSIColor; -use Digest::MD5 qw/md5_hex/; + sub d {print Dumper @_;} # DEFAULTS @@ -65,7 +67,7 @@ our $IP = ''; our $SHARE = 'public'; our $DIR = 'tar_test_dir'; our $LOCALPATH = '/media/data/smb-test'; -our $TMP = '/tmp/smb-tmp'; +our $TMP = File::Temp->newdir(); our $BIN = 'smbclient'; my $SINGLE_TEST = -1; @@ -119,9 +121,6 @@ my @TESTS = ( -l, --local-path PATH path to the root of the samba share on the machine. - -t, --tmp PATH - temporary dir to use - -b, --bin BIN path to the smbclient binary to use @@ -141,7 +140,6 @@ GetOptions('u|user=s' => \$USER, 's|share=s' => \$SHARE, 'd|dir=s' => \$DIR, 'l|local-path=s' => \$LOCALPATH, - 't|tmp=s' => \$TMP, 'b|bin=s' => \$BIN, 'test=i' => \$SINGLE_TEST, @@ -176,6 +174,20 @@ push @SMBARGS, @ARGV; # path to store the downloaded tarball my $TAR = "$TMP/tarmode.tar"; +##### + +# SANITIZATION + +# remove all final slashes from input paths +$LOCALPATH =~ s{[/\\]+$}{}g; +$SHARE =~ s{[/\\]+$}{}g; +$HOST =~ s{[/\\]+$}{}g; +$DIR =~ s{[/\\]+$}{}g; + +if (!-d $LOCALPATH) { + die "Local path '$LOCALPATH' is not a directory.\n"; +} + if ($CLEAN) { # clean the whole root first remove_tree($LOCALPATH, { keep_root => 1 }); @@ -675,8 +687,7 @@ Remove all files in the temp directory C<$TMP> =cut sub reset_tmp { - remove_tree($TMP); - make_path($TMP); + remove_tree($TMP, { keep_root => 1 }); } -- cgit