[PATCH] Add a test for 'net usershare'
Andreas Schneider
asn at samba.org
Mon Jun 26 21:24:42 UTC 2017
On Friday, 23 June 2017 17:21:08 CEST Alexander Bokovoy via samba-technical
wrote:
> >
> > Please look at the attached updated patchset.
>
> Thanks. Pushed again.
And it failed again. The reason was the the test_smbclient_tarmode.pl test
operated on "$LOCAL_PATH" an recuresivly removed all the content. So
everything we set up with setup_fileserver() got removed and we ended up with
a wiped environment.
The test should not operate on "$LOCAL_PATH".
Took me the whole day to nail it down ...
See attached patch.
Andreas
--
Andreas Schneider GPG-ID: CC014E3D
Samba Team asn at samba.org
www.samba.org
-------------- next part --------------
>From 698bb8250c7e3f16aa20305ba2bbe95abd2f275e Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn at samba.org>
Date: Thu, 22 Jun 2017 16:13:12 +0200
Subject: [PATCH 1/2] s3:param: Allow to add usershare if uid_wrapper is loaded
Signed-off-by: Andreas Schneider <asn at samba.org>
---
source3/param/loadparm.c | 19 +++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)
diff --git a/source3/param/loadparm.c b/source3/param/loadparm.c
index 297a7e9175a..91fa85ea7b0 100644
--- a/source3/param/loadparm.c
+++ b/source3/param/loadparm.c
@@ -3513,6 +3513,19 @@ static bool usershare_exists(int iService, struct timespec *last_mod)
return true;
}
+static bool usershare_directory_is_root(uid_t uid)
+{
+ if (uid == 0) {
+ return true;
+ }
+
+ if (uid_wrapper_enabled()) {
+ return true;
+ }
+
+ return false;
+}
+
/***************************************************************************
Load a usershare service by name. Returns a valid servicenumber or -1.
***************************************************************************/
@@ -3546,9 +3559,11 @@ int load_usershare_service(const char *servicename)
*/
#ifdef S_ISVTX
- if (sbuf.st_ex_uid != 0 || !(sbuf.st_ex_mode & S_ISVTX) || (sbuf.st_ex_mode & S_IWOTH)) {
+ if (!usershare_directory_is_root(sbuf.st_ex_uid) ||
+ !(sbuf.st_ex_mode & S_ISVTX) || (sbuf.st_ex_mode & S_IWOTH)) {
#else
- if (sbuf.st_ex_uid != 0 || (sbuf.st_ex_mode & S_IWOTH)) {
+ if (!usershare_directory_is_root(sbuf.st_ex_uid) ||
+ (sbuf.st_ex_mode & S_IWOTH)) {
#endif
DEBUG(0,("load_usershare_service: directory %s is not owned by root "
"or does not have the sticky bit 't' set or is writable by anyone.\n",
--
2.13.1
>From 2fe7921e735b7ce4834664909e47751e6e0444eb Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn at samba.org>
Date: Thu, 22 Jun 2017 14:17:07 +0200
Subject: [PATCH 2/2] s3:tests: Add blackbox test for 'net usershare'
Signed-off-by: Andreas Schneider <asn at samba.org>
---
selftest/target/Samba3.pm | 15 ++++++
source3/script/tests/test_net_usershare.sh | 82 ++++++++++++++++++++++++++++++
source3/selftest/tests.py | 2 +
3 files changed, 99 insertions(+)
create mode 100755 source3/script/tests/test_net_usershare.sh
diff --git a/selftest/target/Samba3.pm b/selftest/target/Samba3.pm
index 20b8d894479..978273a8616 100755
--- a/selftest/target/Samba3.pm
+++ b/selftest/target/Samba3.pm
@@ -10,6 +10,7 @@ use Cwd qw(abs_path);
use FindBin qw($RealBin);
use POSIX;
use target::Samba;
+use File::Path 'remove_tree';
sub have_ads($) {
my ($self) = @_;
@@ -740,6 +741,12 @@ sub setup_fileserver($$)
mkdir($prefix_abs, 0777);
+ my $usershare_dir="$prefix_abs/lib/usershare";
+
+ mkdir("$prefix_abs/lib", 0755);
+ remove_tree($usershare_dir);
+ mkdir($usershare_dir, 01770);
+
my $share_dir="$prefix_abs/share";
# Create share directory structure
@@ -770,7 +777,15 @@ sub setup_fileserver($$)
my $tarmode_sharedir="$share_dir/tarmode";
push(@dirs,$tarmode_sharedir);
+ my $usershare_sharedir="$share_dir/usershares";
+ push(@dirs,$usershare_sharedir);
+
my $fileserver_options = "
+ usershare path = $usershare_dir
+ usershare max shares = 10
+ usershare allow guests = yes
+ usershare prefix allow list = $usershare_sharedir
+
[lowercase]
path = $lower_case_share_dir
comment = smb username is [%U]
diff --git a/source3/script/tests/test_net_usershare.sh b/source3/script/tests/test_net_usershare.sh
new file mode 100755
index 00000000000..bc19fe84706
--- /dev/null
+++ b/source3/script/tests/test_net_usershare.sh
@@ -0,0 +1,82 @@
+#!/bin/sh
+
+if [ $# -lt 5 ]; then
+cat <<EOF
+Usage: test_net_usershare.sh SERVER SERVER_IP DOMAIN USERNAME PASSWORD SMBCLIENT <smbclient arguments>
+EOF
+exit 1;
+fi
+
+SERVER="$1"
+SERVER_IP="$2"
+USERNAME="$3"
+PASSWORD="$4"
+smbclient="$5"
+shift 5
+ADDARGS="$@"
+
+failed=0
+
+samba_bindir="$BINDIR"
+samba_net="$samba_bindir/net"
+samba_smbcontrol="$samba_bindir/smbcontrol"
+
+samba_share_dir="$LOCAL_PATH"
+samba_usershare_dir="$samba_share_dir/usershares"
+
+incdir=`dirname $0`/../../../testprogs/blackbox
+. $incdir/subunit.sh
+
+
+test_smbclient() {
+ name="$1"
+ share="$2"
+ cmd="$3"
+ shift 3
+ echo "test: $name"
+ $VALGRIND $smbclient $CONFIGURATION //$SERVER/$share -c "$cmd" "$@"
+ status=$?
+ if [ x$status = x0 ]; then
+ echo "success: $name"
+ else
+ echo "failure: $name"
+ fi
+ return $status
+}
+
+test_net_usershare() {
+ name="$1"
+ cmd="$2"
+ shift
+ shift
+ echo "test: $name"
+ $VALGRIND $samba_net usershare "$cmd" "$@"
+ status=$?
+ if [ x$status = x0 ]; then
+ echo "success: $name"
+ else
+ echo "failure: $name"
+ fi
+ return $status
+}
+
+###########################################################
+# Check if we can add and delete a usershare
+###########################################################
+
+samba_usershare_name="test_usershare_1"
+samba_usershare_path="$samba_usershare_dir/$samba_usershare_name"
+
+testit "create usershare dir for $samba_usershare_name" mkdir --mode=0755 --verbose $samba_usershare_path || failed=`expr $failed + 1`
+
+test_net_usershare "net usershare add $samba_usershare_name" "add" "$samba_usershare_name" "$samba_usershare_path" "$samba_usershare_name"
+
+test_net_usershare "net usershare info $samba_usershare_name" "info" "$samba_usershare_name"
+
+test_smbclient "smbclient to $samba_usershare_name" "$samba_usershare_name" 'ls' -U$USERNAME%$PASSWORD || failed=`expr $failed + 1`
+
+# CLEANUP
+test_net_usershare "net usershare delete $samba_usershare_name" "delete" "$samba_usershare_name"
+testit "remove usershare dir for $samba_usershare_name" rm -rf $samba_usershare_path || failed=`expr $failed + 1`
+
+exit $failed
diff --git a/source3/selftest/tests.py b/source3/selftest/tests.py
index f23428cb787..7b514084aee 100755
--- a/source3/selftest/tests.py
+++ b/source3/selftest/tests.py
@@ -258,6 +258,8 @@ for env in ["fileserver"]:
'-d', '$PREFIX', '-b', smbclient3,
'--subunit', '--', configuration])
+plantestsuite("samba3.blackbox.net_usershare", "fileserver:local", [os.path.join(samba3srcdir, "script/tests/test_net_usershare.sh"), '$SERVER', '$SERVER_IP', '$USERNAME', '$PASSWORD', smbclient3])
+
#TODO encrypted against member, with member creds, and with DC creds
plantestsuite("samba3.blackbox.net.misc", "nt4_dc:local",
[os.path.join(samba3srcdir, "script/tests/test_net_misc.sh"),
--
2.13.1
More information about the samba-technical
mailing list