smbget's -P option
Christian Ambach
ambi at samba.org
Sun Feb 21 00:02:29 UTC 2016
Am 19.02.16 um 08:55 schrieb Christian Ambach:
>> 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.
I was able to determine the difference between sn-devel and Andreas'
machine. The problem is located in the popt package we bundle in the
source tree and make use of if there is no system popt lib (or when
instructed via configure option). Making use of the configure option, I
was able to recreate the problem.
Debian and Ubuntu ship with a version of popt that fixes the problem we
are hitting in smbget (see
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=217602).
Patch 7 in the patchset applies the same change to our copy of popt.
While looking into this, I found another problem with the option parsing
of smbget that I also included a patch for.
So some patches in the set need review, the others are included for
completeness and so they can all be pushed together.
Regards,
Christian
-------------- next part --------------
From bbe27671db3190d8a24d2781aa2865cf978860bb 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 01/11] s3:utils/smbget another int -> bool conversion
Signed-off-by: Christian Ambach <ambi at samba.org>
Reviewed-by: Andreas Schneider <asn at samba.org>
---
source3/utils/smbget.c | 26 ++++++++++++--------------
1 file changed, 12 insertions(+), 14 deletions(-)
diff --git a/source3/utils/smbget.c b/source3/utils/smbget.c
index 91809d1..24f26b0 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 ok = 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,28 +204,28 @@ 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:
- ret = smb_download_dir(base, newname, resume);
+ ok = smb_download_dir(base, newname, resume);
break;
case SMBC_WORKGROUP:
- ret = smb_download_dir("smb://", dirent->name, resume);
+ ok = smb_download_dir("smb://", dirent->name, resume);
break;
case SMBC_SERVER:
- ret = smb_download_dir("smb://", dirent->name, resume);
+ ok = smb_download_dir("smb://", dirent->name, resume);
break;
case SMBC_FILE:
- ret = smb_download_file(base, newname, true, resume,
+ ok = smb_download_file(base, newname, true, resume,
false, NULL);
break;
case SMBC_FILE_SHARE:
- ret = smb_download_dir(base, newname, resume);
+ ok = smb_download_dir(base, newname, resume);
break;
case SMBC_PRINTER_SHARE:
@@ -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,12 +272,12 @@ 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;
}
}
smbc_closedir(dirhandle);
- return ret;
+ return ok;
}
static char *print_time(long t)
--
1.9.1
From 760eaa4143585c1531fea2227510e98fb5c4613f 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 02/11] s3:utils/smbget abort recursive download on error
Signed-off-by: Christian Ambach <ambi at samba.org>
Reviewed-by: Andreas Schneider <asn 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 24f26b0..7957417 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 (!ok) {
+ fprintf(stderr, "Failed to download %s: %s\n",
+ newname, strerror(errno));
+ return false;
+ }
free(newname);
}
free(tmpname);
--
1.9.1
From 2b61ed12eacf0fb9d35dcfb28769f6f57d974958 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 03/11] 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>
Reviewed-by: Andreas Schneider <asn at samba.org>
---
source3/utils/smbget.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/source3/utils/smbget.c b/source3/utils/smbget.c
index 7957417..998761f 100644
--- a/source3/utils/smbget.c
+++ b/source3/utils/smbget.c
@@ -600,9 +600,10 @@ static bool smb_download_file(const char *base, const char *name,
/* Now, download all bytes from offset_download to the end */
for (curpos = offset_download; curpos < remotestat.st_size;
curpos += opt.blocksize) {
- ssize_t bytesread = smbc_read(remotehandle,
- readbuf,
- opt.blocksize);
+ ssize_t bytesread;
+ ssize_t byteswritten;
+
+ bytesread = smbc_read(remotehandle, readbuf, opt.blocksize);
if(bytesread < 0) {
fprintf(stderr,
"Can't read %zu bytes at offset %jd, file %s\n",
@@ -617,7 +618,8 @@ static bool smb_download_file(const char *base, const char *name,
total_bytes += bytesread;
- if(write(localhandle, readbuf, bytesread) < 0) {
+ byteswritten = write(localhandle, readbuf, bytesread);
+ if (byteswritten != bytesread) {
fprintf(stderr,
"Can't write %zd bytes to local file %s at "
"offset %jd\n", bytesread, path,
--
1.9.1
From a9d79ba17fc3c93307d6ae885b86354a772240cd 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 04/11] 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>
Reviewed-by: Andreas Schneider <asn 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 998761f..5ee73db 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 ok = 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 ok;
}
@@ -657,17 +637,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);
@@ -802,7 +771,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 c4eeecf8a3a7f65233ef889ea5743be448410259 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 05/11] s3:utils/smbget update manpage with -P option removal
Signed-off-by: Christian Ambach <ambi at samba.org>
Reviewed-by: Andreas Schneider <asn 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 4f7a7328d1bb3bf67d506e23fcbc5369d1468e0b 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 06/11] WHATSNEW: document removal of -P in smbget
Signed-off-by: Christian Ambach <ambi at samba.org>
Reviewed-by: Andreas Schneider <asn 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 d7cb25ed691fb0077af1fce214288ac29328232e Mon Sep 17 00:00:00 2001
From: Christian Ambach <ambi at samba.org>
Date: Sat, 20 Feb 2016 21:22:38 +0100
Subject: [PATCH 07/11] third_party/popt disable alignment checks that can fail
on some platforms
remove the alignment checks for integers and longs.
They fail on Ubuntu 14.04 x86_64 and potentially other platforms
Debian und Ubuntu ship their system libpopt versions with the same changes, see
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=217602
Signed-off-by: Christian Ambach <ambi at samba.org>
---
third_party/popt/popt.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/third_party/popt/popt.c b/third_party/popt/popt.c
index d9e8411..7046514 100644
--- a/third_party/popt/popt.c
+++ b/third_party/popt/popt.c
@@ -632,8 +632,12 @@ static void poptStripArg(/*@special@*/ poptContext con, int which)
int poptSaveLong(long * arg, int argInfo, long aLong)
{
+#if 0
/* XXX Check alignment, may fail on funky platforms. */
if (arg == NULL || (((unsigned long)arg) & (sizeof(*arg)-1)))
+#else
+ if (arg == NULL)
+#endif
return POPT_ERROR_NULLARG;
if (argInfo & POPT_ARGFLAG_NOT)
@@ -660,8 +664,12 @@ int poptSaveLong(long * arg, int argInfo, long aLong)
int poptSaveInt(/*@null@*/ int * arg, int argInfo, long aLong)
{
+#if 0
/* XXX Check alignment, may fail on funky platforms. */
if (arg == NULL || (((unsigned long)arg) & (sizeof(*arg)-1)))
+#else
+ if (arg == NULL)
+#endif
return POPT_ERROR_NULLARG;
if (argInfo & POPT_ARGFLAG_NOT)
--
1.9.1
From 52c23f6a8f07849a10d50a15d80a727b8d5dc69f Mon Sep 17 00:00:00 2001
From: Christian Ambach <ambi at samba.org>
Date: Sat, 20 Feb 2016 21:11:51 +0100
Subject: [PATCH 08/11] s3:utils/smbget fix option parsing
* use proper values for val in poptOption
* abort when option parsing reported errors
Signed-off-by: Christian Ambach <ambi at samba.org>
---
source3/utils/smbget.c | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)
diff --git a/source3/utils/smbget.c b/source3/utils/smbget.c
index 5ee73db..0a5392a 100644
--- a/source3/utils/smbget.c
+++ b/source3/utils/smbget.c
@@ -764,7 +764,7 @@ int main(int argc, char **argv)
{"user", 'U', POPT_ARG_STRING, &opt.username, 'U', "Username to use" },
{"guest", 'a', POPT_ARG_NONE, NULL, 'a', "Work as user guest" },
- {"nonprompt", 'n', POPT_ARG_NONE, &opt.nonprompt, 'n', "Don't ask anything (non-interactive)" },
+ {"nonprompt", 'n', POPT_ARG_NONE, &opt.nonprompt, 0, "Don't ask anything (non-interactive)" },
{"debuglevel", 'd', POPT_ARG_INT, &opt.debuglevel, 'd', "Debuglevel to use" },
{"encrypt", 'e', POPT_ARG_NONE, NULL, 'e', "Encrypt SMB transport" },
@@ -774,10 +774,10 @@ int main(int argc, char **argv)
{"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" },
- {"stdout", 'O', POPT_ARG_NONE, &opt.send_stdout, 'O', "Write data to stdout" },
- {"dots", 'D', POPT_ARG_NONE, &opt.dots, 'D', "Show dots as progress indication" },
- {"quiet", 'q', POPT_ARG_NONE, &opt.quiet, 'q', "Be quiet" },
- {"verbose", 'v', POPT_ARG_NONE, &opt.verbose, 'v', "Be verbose" },
+ {"stdout", 'O', POPT_ARG_NONE, &opt.send_stdout, 0, "Write data to stdout" },
+ {"dots", 'D', POPT_ARG_NONE, &opt.dots, 0, "Show dots as progress indication" },
+ {"quiet", 'q', POPT_ARG_NONE, &opt.quiet, 0, "Be quiet" },
+ {"verbose", 'v', POPT_ARG_NONE, &opt.verbose, 0, "Be verbose" },
{"rcfile", 'f', POPT_ARG_STRING, NULL, 'f', "Use specified rc file"},
POPT_TABLEEND
@@ -803,7 +803,7 @@ int main(int argc, char **argv)
pc = poptGetContext(argv[0], argc, argv_const, long_options, 0);
- while ((c = poptGetNextOpt(pc)) >= 0) {
+ while ((c = poptGetNextOpt(pc)) > 0) {
switch (c) {
case 'f':
readrcfile(poptGetOptArg(pc), long_options);
@@ -830,6 +830,13 @@ int main(int argc, char **argv)
}
}
+ if (c < -1) {
+ fprintf(stderr, "%s: %s\n",
+ poptBadOption(pc, POPT_BADOPTION_NOALIAS),
+ poptStrerror(c));
+ return 1;
+ }
+
if ((opt.send_stdout || resume || opt.outputfile) && opt.update) {
fprintf(stderr, "The -o, -R or -O and -U options can not be "
"used together.\n");
--
1.9.1
From f3ac0d9e8fc15f6dc893a4a0c976fd6b45ff61cf 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 09/11] selftest: reduce code duplication
factor out a createuser sub
Signed-off-by: Christian Ambach <ambi at samba.org>
Reviewed-by: Andreas Schneider <asn 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 37a3a1ba1ee7f7e5701654c98c353d40c380b551 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 10/11] selftest: add a helper for the smbget binary
Signed-off-by: Christian Ambach <ambi at samba.org>
Reviewed-by: Andreas Schneider <asn 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 6731d7737367d85915e1394167cd40969e6ba8aa 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 11/11] 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