smbget's -P option

Christian Ambach ambi at samba.org
Fri Feb 19 07:55:44 UTC 2016


Hi Andreas,

Am 18.02.16 um 10:18 schrieb Andreas Schneider:
> I did some cosmetic changes to the first 3 patches. Then I changed the test to
> use absolute paths and remove dangling files (rcfile).

Thanks for the rework of the path stuff.
Regarding the rcfile removal, your change was wrong as it checks the 
result code of the rm command, not of the smbget command.
I have attached the fixed patch.

> However the tests fail on my box. So I checked with smbclient first.
The test passes on my box and it also passes a private autobuild on 
sn-devel. Not sure what is happening on your machine.

> smb: \> get testfile
> getting file \testfile of size 131072 as testfile (42665,3 KiloBytes/sec)
> (average 42666,7 KiloBytes/sec)
> asn at fileserver:~/workspace/projects/samba> rm testfile
> asn at fileserver:~/workspace/projects/samba> bin/smbget -v -a
> smb://127.0.0.35/smbget/testfile
> Downloaded 0b in 0 seconds
ambi at wanderer:~/git/samba$ chmod 644 st/fileserver/share/smbget/testfile
ambi at wanderer:~/git/samba$ bin/smbget -va smb://127.0.0.35/smbget/testfile
Using workgroup WORKGROUP, guest user
smb://127.0.0.35/smbget/testfile 
 

Downloaded 128.00kB in 0 seconds

Cheers,
Christian


-------------- next part --------------
>From 455a612f38e39ccf0ef739b9aa41eb95d6e971d0 Mon Sep 17 00:00:00 2001
From: Christian Ambach <ambi at samba.org>
Date: Sat, 6 Feb 2016 10:30:29 +0100
Subject: [PATCH] selftest: Add a blackbox test for smbget

Signed-off-by: Christian Ambach <ambi at samba.org>
Reviewed-by: Andreas Schneider <asn at samba.org>
---
 selftest/target/Samba3.pm           |  14 ++-
 source3/script/tests/test_smbget.sh | 236 ++++++++++++++++++++++++++++++++++++
 source3/selftest/tests.py           |   1 +
 3 files changed, 250 insertions(+), 1 deletion(-)
 create mode 100755 source3/script/tests/test_smbget.sh

diff --git a/selftest/target/Samba3.pm b/selftest/target/Samba3.pm
index f3d4454..2dde4ca 100755
--- a/selftest/target/Samba3.pm
+++ b/selftest/target/Samba3.pm
@@ -606,6 +606,9 @@ sub setup_fileserver($$)
 	my $force_user_valid_users_dir = "$share_dir/force_user_valid_users";
 	push(@dirs, $force_user_valid_users_dir);
 
+	my $smbget_sharedir="$share_dir/smbget";
+	push(@dirs,$smbget_sharedir);
+
 	my $fileserver_options = "
 [lowercase]
 	path = $lower_case_share_dir
@@ -641,7 +644,12 @@ sub setup_fileserver($$)
 	force user = force_user
 	force group = everyone
 	write list = force_user
-	";
+
+[smbget]
+	path = $smbget_sharedir
+	comment = smb username is [%U]
+	guest ok = yes
+";
 
 	my $vars = $self->provision($path,
 				    "FILESERVER",
@@ -1299,6 +1307,7 @@ sub provision($$$$$$$$)
 	my ($max_uid, $max_gid);
 	my ($uid_nobody, $uid_root, $uid_pdbtest, $uid_pdbtest2, $uid_userdup);
 	my ($uid_pdbtest_wkn);
+	my ($uid_smbget);
 	my ($uid_force_user);
 	my ($gid_nobody, $gid_nogroup, $gid_root, $gid_domusers, $gid_domadmins);
 	my ($gid_userdup, $gid_everyone);
@@ -1317,6 +1326,7 @@ sub provision($$$$$$$$)
 	$uid_userdup = $max_uid - 5;
 	$uid_pdbtest_wkn = $max_uid - 6;
 	$uid_force_user = $max_uid - 7;
+	$uid_smbget = $max_uid - 8;
 
 	if ($unix_gids[0] < 0xffff - 8) {
 		$max_gid = 0xffff;
@@ -1697,6 +1707,7 @@ pdbtest2:x:$uid_pdbtest2:$gid_nogroup:pdbtest gecos:$prefix_abs:/bin/false
 userdup:x:$uid_userdup:$gid_userdup:userdup gecos:$prefix_abs:/bin/false
 pdbtest_wkn:x:$uid_pdbtest_wkn:$gid_everyone:pdbtest_wkn gecos:$prefix_abs:/bin/false
 force_user:x:$uid_force_user:$gid_force_user:force user gecos:$prefix_abs:/bin/false
+smbget_user:x:$uid_smbget:$gid_domusers:smbget_user gecos:$prefix_abs:/bin/false
 ";
 	if ($unix_uid != 0) {
 		print PASSWD "root:x:$uid_root:$gid_root:root gecos:$prefix_abs:/bin/false
@@ -1770,6 +1781,7 @@ force_user:x:$gid_force_user:
 
 	createuser($self, $unix_name, $password, $conffile) || die("Unable to create user");
 	createuser($self, "force_user", $password, $conffile) || die("Unable to create force_user");
+	createuser($self, "smbget_user", $password, $conffile) || die("Unable to create smbget_user");
 
 	open(DNS_UPDATE_LIST, ">$prefix/dns_update_list") or die("Unable to open $$prefix/dns_update_list");
 	print DNS_UPDATE_LIST "A $server. $server_ip\n";
diff --git a/source3/script/tests/test_smbget.sh b/source3/script/tests/test_smbget.sh
new file mode 100755
index 0000000..f21a131
--- /dev/null
+++ b/source3/script/tests/test_smbget.sh
@@ -0,0 +1,236 @@
+#!/bin/bash
+#
+# Blackbox test for smbget.
+#
+
+if [ $# -lt 7 ]; then
+cat <<EOF
+Usage: test_smbget SERVER SERVER_IP DOMAIN USERNAME PASSWORD WORKDIR SMBGET
+EOF
+exit 1;
+fi
+
+SERVER=${1}
+SERVER_IP=${2}
+DOMAIN=${3}
+USERNAME=${4}
+PASSWORD=${5}
+WORKDIR=${6}
+SMBGET="$VALGRIND ${7}"
+
+TMPDIR="$SRCDIR_ABS/st/tmp"
+
+incdir=`dirname $0`/../../../testprogs/blackbox
+. $incdir/subunit.sh
+
+create_test_data()
+{
+	pushd $WORKDIR
+	dd if=/dev/urandom bs=1024 count=128 of=testfile
+	chmod 644 testfile
+	mkdir dir1
+	dd if=/dev/urandom bs=1024 count=128 of=dir1/testfile1
+	mkdir dir2
+	dd if=/dev/urandom bs=1024 count=128 of=dir2/testfile2
+	popd
+}
+
+remove_test_data()
+{
+	rm -rf dir1 dir2 testfile
+	pushd $WORKDIR
+	rm -rf dir1 dir2 testfile
+	popd
+}
+
+test_singlefile_guest()
+{
+	[ -e testfile ] && rm testfile
+	echo "$SMBGET -v -a smb://$SERVER_IP/smbget/testfile"
+	$SMBGET -v -a smb://$SERVER_IP/smbget/testfile
+	if [ $? -ne 0 ]; then
+		echo 'ERROR: RC does not match, expected: 0'
+		return 1
+	fi
+	cmp --silent $WORKDIR/testfile ./testfile
+	if [ $? -ne 0 ]; then
+		echo 'ERROR: file content does not match'
+		return 1
+	fi
+	return 0
+}
+
+test_singlefile_U()
+{
+	[ -e testfile ] && rm testfile
+	$SMBGET -v -U$USERNAME%$PASSWORD smb://$SERVER_IP/smbget/testfile
+	if [ $? -ne 0 ]; then
+		echo 'ERROR: RC does not match, expected: 0'
+		return 1
+	fi
+	cmp --silent $WORKDIR/testfile ./testfile
+	if [ $? -ne 0 ]; then
+		echo 'ERROR: file content does not match'
+		return 1
+	fi
+	return 0
+}
+
+test_singlefile_smburl()
+{
+	[ -e testfile ] && rm testfile
+	$SMBGET -w $DOMAIN smb://$USERNAME:$PASSWORD@$SERVER_IP/smbget/testfile
+	if [ $? -ne 0 ]; then
+		echo 'ERROR: RC does not match, expected: 0'
+		return 1
+	fi
+	cmp --silent $WORKDIR/testfile ./testfile
+	if [ $? -ne 0 ]; then
+		echo 'ERROR: file content does not match'
+		return 1
+	fi
+	return 0
+}
+
+test_singlefile_rcfile()
+{
+	[ -e testfile ] && rm testfile
+	echo "user $USERNAME%$PASSWORD" > $TMPDIR/rcfile
+	$SMBGET -vn -f $TMPDIR/rcfile smb://$SERVER_IP/smbget/testfile
+	rc=$?
+	rm -f $TMPDIR/rcfile
+	if [ $rc -ne 0 ]; then
+		echo 'ERROR: RC does not match, expected: 0'
+		return 1
+	fi
+	cmp --silent $WORKDIR/testfile ./testfile
+	if [ $? -ne 0 ]; then
+		echo 'ERROR: file content does not match'
+		return 1
+	fi
+	return 0
+}
+
+test_recursive_U()
+{
+	[ -e testfile ] && rm testfile
+	[ -d dir1 ] && rm -rf dir1
+	[ -d dir2 ] && rm -rf dir2
+	$SMBGET -v -R -U$USERNAME%$PASSWORD smb://$SERVER_IP/smbget/
+	if [ $? -ne 0 ]; then
+		echo 'ERROR: RC does not match, expected: 0'
+		return 1
+	fi
+
+	cmp --silent $WORKDIR/testfile ./testfile && \
+	cmp --silent $WORKDIR/dir1/testfile1 ./dir1/testfile1 && \
+	cmp --silent $WORKDIR/dir2/testfile2 ./dir2/testfile2
+	if [ $? -ne 0 ]; then
+		echo 'ERROR: file content does not match'
+		return 1
+	fi
+
+	return 0
+}
+
+test_resume()
+{
+	[ -e testfile ] && rm testfile
+	cp $WORKDIR/testfile .
+	truncate -s 1024 testfile
+	$SMBGET -v -r -U$USERNAME%$PASSWORD smb://$SERVER_IP/smbget/testfile
+	if [ $? -ne 0 ]; then
+		echo 'ERROR: RC does not match, expected: 0'
+		return 1
+	fi
+
+	cmp --silent $WORKDIR/testfile ./testfile
+	if [ $? -ne 0 ]; then
+		echo 'ERROR: file content does not match'
+		return 1
+	fi
+
+	return 0
+}
+
+test_resume_modified()
+{
+	dd if=/dev/urandom bs=1024 count=2 of=testfile
+	$SMBGET -v -r -U$USERNAME%$PASSWORD smb://$SERVER_IP/smbget/testfile
+	if [ $? -ne 1 ]; then
+		echo 'ERROR: RC does not match, expected: 1'
+		return 1
+	fi
+
+	return 0
+}
+
+test_update()
+{
+	[ -e testfile ] && rm testfile
+	$SMBGET -v -U$USERNAME%$PASSWORD smb://$SERVER_IP/smbget/testfile
+	if [ $? -ne 0 ]; then
+		echo 'ERROR: RC does not match, expected: 0'
+		return 1
+	fi
+
+	# secondary download should pass
+	$SMBGET -v -u -U$USERNAME%$PASSWORD smb://$SERVER_IP/smbget/testfile
+	if [ $? -ne 0 ]; then
+		echo 'ERROR: RC does not match, expected: 0'
+		return 1
+	fi
+
+	echo "modified" >> testfile
+	# touch source to trigger new download
+	sleep 2
+	touch -m $WORKDIR/testfile
+	$SMBGET -v -u -U$USERNAME%$PASSWORD smb://$SERVER_IP/smbget/testfile
+	if [ $? -ne 0 ]; then
+		echo 'ERROR: RC does not match, expected: 0'
+		return 1
+	fi
+
+	cmp --silent $WORKDIR/testfile ./testfile
+	if [ $? -ne 0 ]; then
+		echo 'ERROR: file content does not match'
+		return 1
+	fi
+
+	return 0
+}
+
+create_test_data
+
+pushd $TMPDIR
+
+failed=0
+testit "download single file as guest" test_singlefile_guest \
+	|| failed=`expr $failed + 1`
+
+testit "download single file with -U" test_singlefile_U \
+	|| failed=`expr $failed + 1`
+
+testit "download single file with smb URL" test_singlefile_smburl \
+	|| failed=`expr $failed + 1`
+
+testit "download single file with rcfile" test_singlefile_rcfile \
+	|| failed=`expr $failed + 1`
+
+testit "recursive download" test_recursive_U \
+	|| failed=`expr $failed + 1`
+
+testit "resume download" test_resume \
+	|| failed=`expr $failed + 1`
+
+testit "resume download (modified file)" test_resume_modified \
+	|| failed=`expr $failed + 1`
+
+testit "update" test_update \
+	|| failed=`expr $failed + 1`
+
+popd
+
+remove_test_data
+
+exit $failed
diff --git a/source3/selftest/tests.py b/source3/selftest/tests.py
index b2bae75..48e082f 100755
--- a/source3/selftest/tests.py
+++ b/source3/selftest/tests.py
@@ -182,6 +182,7 @@ for env in ["fileserver"]:
     plantestsuite("samba3.blackbox.offline (%s)" % env, env, [os.path.join(samba3srcdir, "script/tests/test_offline.sh"), '$SERVER', '$SERVER_IP', '$DOMAIN', '$USERNAME', '$PASSWORD', '$LOCAL_PATH/offline', smbclient3])
     plantestsuite("samba3.blackbox.shadow_copy2 (%s)" % env, env, [os.path.join(samba3srcdir, "script/tests/test_shadow_copy.sh"), '$SERVER', '$SERVER_IP', '$DOMAIN', '$USERNAME', '$PASSWORD', '$LOCAL_PATH/shadow', smbclient3])
     plantestsuite("samba3.blackbox.smbclient.forceuser_validusers (%s)" % env, env, [os.path.join(samba3srcdir, "script/tests/test_forceuser_validusers.sh"), '$SERVER', '$DOMAIN', '$USERNAME', '$PASSWORD', '$LOCAL_PATH', smbclient3])
+    plantestsuite("samba3.blackbox.smbget (%s)" % env, env, [os.path.join(samba3srcdir, "script/tests/test_smbget.sh"), '$SERVER', '$SERVER_IP', '$DOMAIN', 'smbget_user', '$PASSWORD', '$LOCAL_PATH/smbget', smbget])
 
     #
     # tar command tests
-- 
1.9.1



More information about the samba-technical mailing list