smbget's -P option

Christian Ambach ambi at samba.org
Thu Feb 18 00:09:20 UTC 2016


Am 16.02.16 um 08:26 schrieb Andreas Schneider:
>> So before spending more time fixing the issues with the option, I would
>> rather tend to remove it (as part of the smbget renovation efforts for 4.4).
>> Data migration (including ACLs) is outside of the scope of this tool and
>> talking about permissions in the docs creates false expectations.
>
> I would vote for removing it. If things are not clear and the user doesn't
> easily understand it it will create more problems than we can resolve with it.
>

Okay, then let's remove it.
The attached patchset contains
* a few more fixes
* the removal of the -P option (code and docs)
* a blackbox test for smbget that achieves 62% line coverage.

Review and push appreciated.

Thanks,
Christian



-------------- next part --------------
>From e90c61726e941f1940f667ebc68122578f88090b Mon Sep 17 00:00:00 2001
From: Christian Ambach <ambi at samba.org>
Date: Mon, 8 Feb 2016 23:24:36 +0100
Subject: [PATCH 1/9] s3:utils/smbget another int -> bool conversion

Signed-off-by: Christian Ambach <ambi at samba.org>
---
 source3/utils/smbget.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/source3/utils/smbget.c b/source3/utils/smbget.c
index 91809d1..f66acf9 100644
--- a/source3/utils/smbget.c
+++ b/source3/utils/smbget.c
@@ -163,9 +163,7 @@ static void get_auth_data(const char *srv, const char *shr, char *wg, int wglen,
 	}
 }
 
-/* Return 1 on error, 0 on success. */
-
-static int smb_download_dir(const char *base, const char *name, int resume)
+static bool smb_download_dir(const char *base, const char *name, int resume)
 {
 	char path[SMB_MAXPATHLEN];
 	int dirhandle;
@@ -173,7 +171,7 @@ static int smb_download_dir(const char *base, const char *name, int resume)
 	const char *relname = name;
 	char *tmpname;
 	struct stat remotestat;
-	int ret = 0;
+	bool ret = false;
 
 	snprintf(path, SMB_MAXPATHLEN-1, "%s%s%s", base,
 		 (base[0] && name[0] && name[0] != '/' &&
@@ -189,7 +187,7 @@ static int smb_download_dir(const char *base, const char *name, int resume)
 		}
 		fprintf(stderr, "Can't open directory %s: %s\n", path,
 			strerror(errno));
-		return 1;
+		return false;
 	}
 
 	while (*relname == '/') {
@@ -206,7 +204,7 @@ static int smb_download_dir(const char *base, const char *name, int resume)
 		}
 		if (asprintf(&newname, "%s/%s", tmpname, dirent->name) == -1) {
 			free(tmpname);
-			return 1;
+			return false;
 		}
 		switch (dirent->smbc_type) {
 		case SMBC_DIR:
@@ -266,7 +264,7 @@ static int smb_download_dir(const char *base, const char *name, int resume)
 				"Unable to get stats on %s on remote server\n",
 				path);
 			smbc_closedir(dirhandle);
-			return 1;
+			return false;
 		}
 
 		if (chmod(relname, remotestat.st_mode) < 0) {
@@ -274,7 +272,7 @@ static int smb_download_dir(const char *base, const char *name, int resume)
 				"Unable to change mode of local dir %s to %o\n",
 				relname, (unsigned int)remotestat.st_mode);
 			smbc_closedir(dirhandle);
-			return 1;
+			return false;
 		}
 	}
 
-- 
1.9.1


>From 8baaac02b3abe35dbd9078f38643c7b17751cbae Mon Sep 17 00:00:00 2001
From: Christian Ambach <ambi at samba.org>
Date: Mon, 8 Feb 2016 23:25:04 +0100
Subject: [PATCH 2/9] s3:utils/smbget abort recursive download on error

Signed-off-by: Christian Ambach <ambi at samba.org>
---
 source3/utils/smbget.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/source3/utils/smbget.c b/source3/utils/smbget.c
index f66acf9..98eaf7a 100644
--- a/source3/utils/smbget.c
+++ b/source3/utils/smbget.c
@@ -254,6 +254,12 @@ static bool smb_download_dir(const char *base, const char *name, int resume)
 				newname, dirent->smbc_type);
 			break;
 		}
+
+		if (!ret) {
+			fprintf(stderr, "Failed to download %s: %s\n",
+				newname, strerror(errno));
+			return false;
+		}
 		free(newname);
 	}
 	free(tmpname);
-- 
1.9.1


>From b09bc2c1b1981aa5e661fef8a076ce8a0e7c8a5f Mon Sep 17 00:00:00 2001
From: Christian Ambach <ambi at samba.org>
Date: Mon, 8 Feb 2016 23:27:09 +0100
Subject: [PATCH 3/9] s3:utils/smbget improve check of write() result

check that all bytes in the buffer have been written

Signed-off-by: Christian Ambach <ambi at samba.org>
---
 source3/utils/smbget.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/source3/utils/smbget.c b/source3/utils/smbget.c
index 98eaf7a..f0215e9 100644
--- a/source3/utils/smbget.c
+++ b/source3/utils/smbget.c
@@ -617,7 +617,7 @@ static bool smb_download_file(const char *base, const char *name,
 
 		total_bytes += bytesread;
 
-		if(write(localhandle, readbuf, bytesread) < 0) {
+		if (write(localhandle, readbuf, bytesread) != bytesread) {
 			fprintf(stderr,
 				"Can't write %zd bytes to local file %s at "
 				"offset %jd\n", bytesread, path,
-- 
1.9.1


>From bfc8f9de28c6571c5bbb288135eac80bb0269d86 Mon Sep 17 00:00:00 2001
From: Christian Ambach <ambi at samba.org>
Date: Mon, 15 Feb 2016 22:25:11 +0100
Subject: [PATCH 4/9] s3:utils/smbget remove -P option

as agreed on samba-technical list.
It does not really provide a useful function but can cause confusion

Signed-off-by: Christian Ambach <ambi at samba.org>
---
 source3/utils/smbget.c | 32 --------------------------------
 1 file changed, 32 deletions(-)

diff --git a/source3/utils/smbget.c b/source3/utils/smbget.c
index f0215e9..f9c3969 100644
--- a/source3/utils/smbget.c
+++ b/source3/utils/smbget.c
@@ -51,7 +51,6 @@ struct opt {
 	bool nonprompt;
 	bool quiet;
 	bool dots;
-	bool keep_permissions;
 	bool verbose;
 	bool send_stdout;
 	bool update;
@@ -170,7 +169,6 @@ static bool smb_download_dir(const char *base, const char *name, int resume)
 	struct smbc_dirent *dirent;
 	const char *relname = name;
 	char *tmpname;
-	struct stat remotestat;
 	bool ret = false;
 
 	snprintf(path, SMB_MAXPATHLEN-1, "%s%s%s", base,
@@ -264,24 +262,6 @@ static bool smb_download_dir(const char *base, const char *name, int resume)
 	}
 	free(tmpname);
 
-	if (opt.keep_permissions) {
-		if (smbc_fstat(dirhandle, &remotestat) < 0) {
-			fprintf(stderr,
-				"Unable to get stats on %s on remote server\n",
-				path);
-			smbc_closedir(dirhandle);
-			return false;
-		}
-
-		if (chmod(relname, remotestat.st_mode) < 0) {
-			fprintf(stderr,
-				"Unable to change mode of local dir %s to %o\n",
-				relname, (unsigned int)remotestat.st_mode);
-			smbc_closedir(dirhandle);
-			return false;
-		}
-	}
-
 	smbc_closedir(dirhandle);
 	return ret;
 }
@@ -655,17 +635,6 @@ static bool smb_download_file(const char *base, const char *name,
 		fputc('\n', stderr);
 	}
 
-	if (opt.keep_permissions && !opt.send_stdout) {
-		if (fchmod(localhandle, remotestat.st_mode) < 0) {
-			fprintf(stderr, "Unable to change mode of local "
-				"file %s to %o\n",
-				path, (unsigned int)remotestat.st_mode);
-			smbc_close(remotehandle);
-			close(localhandle);
-			return false;
-		}
-	}
-
 	smbc_close(remotehandle);
 	if (localhandle != STDOUT_FILENO) {
 		close(localhandle);
@@ -800,7 +769,6 @@ int main(int argc, char **argv)
 		{"resume",     'r', POPT_ARG_NONE,   &resume,           0,  "Automatically resume aborted files" },
 		{"update",     'u', POPT_ARG_NONE,   &opt.update,       0,  "Download only when remote file is newer than local file or local file is missing"},
 		{"recursive",  'R', POPT_ARG_NONE,   &recursive,        0,  "Recursively download files" },
-		{"keep-permissions", 'P', POPT_ARG_NONE, &opt.keep_permissions, 'P', "Keep permissions" },
 		{"blocksize",  'b', POPT_ARG_INT,    &opt.blocksize,   'b', "Change number of bytes in a block"},
 
 		{"outputfile", 'o', POPT_ARG_STRING, &opt.outputfile,  'o', "Write downloaded data to specified file" },
-- 
1.9.1


>From 1ecbfc0fd3465023a141925815d4f008f68b1fda Mon Sep 17 00:00:00 2001
From: Christian Ambach <ambi at samba.org>
Date: Wed, 17 Feb 2016 19:25:59 +0100
Subject: [PATCH 5/9] s3:utils/smbget update manpage with -P option removal

Signed-off-by: Christian Ambach <ambi at samba.org>
---
 docs-xml/manpages/smbget.1.xml | 6 ------
 1 file changed, 6 deletions(-)

diff --git a/docs-xml/manpages/smbget.1.xml b/docs-xml/manpages/smbget.1.xml
index 59e2ffe..d77cb8e 100644
--- a/docs-xml/manpages/smbget.1.xml
+++ b/docs-xml/manpages/smbget.1.xml
@@ -27,7 +27,6 @@
 		<arg choice="opt">-n, --nonprompt</arg>
 		<arg choice="opt">-d, --debuglevel=INT</arg>
 		<arg choice="opt">-D, --dots</arg>
-		<arg choice="opt">-P, --keep-permissions</arg>
 		<arg choice="opt">-o, --outputfile</arg>
 		<arg choice="opt">-f, --rcfile</arg>
 		<arg choice="opt">-q, --quiet</arg>
@@ -102,11 +101,6 @@
 	</varlistentry>
 
 	<varlistentry>
-		<term>-P, --keep-permissions</term>
-		<listitem><para>Set same permissions on local file as are set on remote file.</para></listitem>
-	</varlistentry>
-
-	<varlistentry>
 		<term>-o, --outputfile</term>
 		<listitem><para>Write the file that is being downloaded to the specified file. Can not be used together with -R.</para></listitem>
 	</varlistentry>
-- 
1.9.1


>From 670b0237a898360fb4fc5a394eaaee6e065963dd Mon Sep 17 00:00:00 2001
From: Christian Ambach <ambi at samba.org>
Date: Wed, 17 Feb 2016 22:57:59 +0100
Subject: [PATCH 6/9] WHATSNEW: document removal of -P in smbget

Signed-off-by: Christian Ambach <ambi at samba.org>
---
 WHATSNEW.txt | 1 +
 1 file changed, 1 insertion(+)

diff --git a/WHATSNEW.txt b/WHATSNEW.txt
index 7c748c2..d81e1ed6 100644
--- a/WHATSNEW.txt
+++ b/WHATSNEW.txt
@@ -71,6 +71,7 @@ The -u and -p options for user and password were replaced by the -U option that
 accepts username[%password] as in many other tools of the Samba suite.
 Similary, smbgetrc files do not accept username and password options any more,
 only a single "user" option which also accepts user%password combinations.
+The -P option was removed.
 
 s4-rpc_server
 -------------
-- 
1.9.1


>From 7856a399d76c691f1b4195b9b1cdb7e4d918633f Mon Sep 17 00:00:00 2001
From: Christian Ambach <ambi at samba.org>
Date: Thu, 18 Feb 2016 00:48:04 +0100
Subject: [PATCH 7/9] selftest: reduce code duplication

factor out a createuser sub

Signed-off-by: Christian Ambach <ambi at samba.org>
---
 selftest/target/Samba3.pm | 41 ++++++++++++++++++-----------------------
 1 file changed, 18 insertions(+), 23 deletions(-)

diff --git a/selftest/target/Samba3.pm b/selftest/target/Samba3.pm
index cb9ee08..f3d4454 100755
--- a/selftest/target/Samba3.pm
+++ b/selftest/target/Samba3.pm
@@ -1061,6 +1061,22 @@ sub check_or_start($$$$$) {
 	return $self->wait_for_start($env_vars, $nmbd, $winbindd, $smbd);
 }
 
+sub createuser($$$$)
+{
+	my ($self, $username, $password, $conffile) = @_;
+	my $cmd = "UID_WRAPPER_ROOT=1 " . Samba::bindir_path($self, "smbpasswd")." -c $conffile -L -s -a $username > /dev/null";
+	unless (open(PWD, "|$cmd")) {
+	    warn("Unable to set password for $username account\n$cmd");
+	    return undef;
+	}
+	print PWD "$password\n$password\n";
+	unless (close(PWD)) {
+	    warn("Unable to set password for $username account\n$cmd");
+	    return undef;
+	}
+	print "DONE\n";
+}
+
 sub provision($$$$$$$$)
 {
 	my ($self, $prefix, $server, $password, $extra_options, $dc_server_ip, $dc_server_ipv6, $no_delete_prefix) = @_;
@@ -1752,29 +1768,8 @@ force_user:x:$gid_force_user:
 		$ENV{RESOLV_WRAPPER_HOSTS} = $dns_host_file;
 	}
 
-        my $cmd = "UID_WRAPPER_ROOT=1 " . Samba::bindir_path($self, "smbpasswd")." -c $conffile -L -s -a $unix_name > /dev/null";
-	unless (open(PWD, "|$cmd")) {
-             warn("Unable to set password for test account\n$cmd");
-             return undef;
-        }
-	print PWD "$password\n$password\n";
-	unless (close(PWD)) {
-             warn("Unable to set password for test account\n$cmd");
-             return undef; 
-        }
-
-	# Add another user named: force_user
-        my $cmd = "UID_WRAPPER_ROOT=1 " . Samba::bindir_path($self, "smbpasswd")." -c $conffile -L -s -a force_user > /dev/null";
-	unless (open(PWD, "|$cmd")) {
-             warn("Unable to set password for test account force_user\n$cmd");
-             return undef;
-        }
-	print PWD "$password\n$password\n";
-	unless (close(PWD)) {
-             warn("Unable to set password for test account force_user\n$cmd");
-             return undef;
-        }
-	print "DONE\n";
+	createuser($self, $unix_name, $password, $conffile) || die("Unable to create user");
+	createuser($self, "force_user", $password, $conffile) || die("Unable to create force_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";
-- 
1.9.1


>From de0dcfa1ce84e4de4e560e826bb828d5b7b34b40 Mon Sep 17 00:00:00 2001
From: Christian Ambach <ambi at samba.org>
Date: Thu, 4 Feb 2016 21:41:08 +0100
Subject: [PATCH 8/9] selftest: add a helper for the smbget binary

Signed-off-by: Christian Ambach <ambi at samba.org>
---
 selftest/selftesthelpers.py | 1 +
 1 file changed, 1 insertion(+)

diff --git a/selftest/selftesthelpers.py b/selftest/selftesthelpers.py
index a5ab3f9..42499b0 100644
--- a/selftest/selftesthelpers.py
+++ b/selftest/selftesthelpers.py
@@ -184,3 +184,4 @@ wbinfo = binpath('wbinfo')
 dbwrap_tool = binpath('dbwrap_tool')
 vfstest = binpath('vfstest')
 smbcquotas = binpath('smbcquotas')
+smbget = binpath('smbget')
-- 
1.9.1


>From 706ea0528be66204384a9a99fa2e19f8e940896f 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 9/9] selftest: add a blackbox test for smbget

Signed-off-by: Christian Ambach <ambi at samba.org>
---
 selftest/target/Samba3.pm           |  14 ++-
 source3/script/tests/test_smbget.sh | 230 ++++++++++++++++++++++++++++++++++++
 source3/selftest/tests.py           |   1 +
 3 files changed, 244 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..ad74dfd
--- /dev/null
+++ b/source3/script/tests/test_smbget.sh
@@ -0,0 +1,230 @@
+#!/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}"
+
+incdir=`dirname $0`/../../../testprogs/blackbox
+. $incdir/subunit.sh
+
+create_test_data()
+{
+	cd $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
+	cd -
+}
+
+remove_test_data()
+{
+	rm -rf dir1 dir2 testfile
+	cd $WORKDIR
+	rm -rf dir1 dir2 testfile
+	cd -
+}
+
+test_singlefile_guest()
+{
+	[ -e testfile ] && rm 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" > rcfile
+	$SMBGET -vn -f rcfile 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_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
+
+cd st/tmp
+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`
+
+cd -
+
+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