summaryrefslogtreecommitdiffstats
path: root/source3/script/tests
diff options
context:
space:
mode:
authorAurélien Aptel <aurelien.aptel@gmail.com>2013-07-16 00:34:41 +0200
committerJim McDonough <jmcd@samba.org>2013-11-05 08:42:42 -0500
commit45bee9901b94e68b86ff50f0e0629522d5b5800a (patch)
treed8b20e111f1f246e6af3039c026e810499121574 /source3/script/tests
parent2f30482e7bb94a1ceb96d337b304bc3eadcd6a45 (diff)
downloadsamba-45bee9901b94e68b86ff50f0e0629522d5b5800a.tar.gz
samba-45bee9901b94e68b86ff50f0e0629522d5b5800a.tar.xz
samba-45bee9901b94e68b86ff50f0e0629522d5b5800a.zip
test_smbclient_tarmode.pl: sanitize input, use File::Temp instead of hardcoding temp dir
Signed-off-by: Aurélien Aptel <aurelien.aptel@gmail.com> Reviewed-by: David Disseldorp <ddiss@samba.org> Reviewed-by: Jim McDonough <jmcd@samba.org>
Diffstat (limited to 'source3/script/tests')
-rwxr-xr-xsource3/script/tests/test_smbclient_tarmode.pl27
1 files changed, 19 insertions, 8 deletions
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 });
}