[PATCH] Add a test for 'net usershare'
Andreas Schneider
asn at samba.org
Fri Jun 23 08:26:41 UTC 2017
On Friday, 23 June 2017 02:49:56 CEST Alexander Bokovoy via samba-technical
wrote:
> On to, 22 kesä 2017, Jeremy Allison via samba-technical wrote:
> > On Thu, Jun 22, 2017 at 04:38:44PM -0700, Jeremy Allison via samba-
technical wrote:
> > > On Thu, Jun 22, 2017 at 05:51:28PM +0200, Andreas Schneider via samba-
technical wrote:
> > > > Hi,
> > > >
> > > > I've tried to understand a customer problem, so I've started to write
> > > > a test for 'net usershare'. Haven't found a bug yet, so here is just
> > > > a test which checks normal functionality.
> > > >
> > > >
> > > > Review and push appreciated.
> > >
> > > RB+. Thanks a *LOT* for the tests on this Andreas !
> >
> > Ah, I spoke too soon. Fails with:
> >
> > /memdisk/jra/a/b230827/samba/source3/script/tests/test_net_usershare.sh:
> > 15: shift: can't shift that many command:
> > /memdisk/jra/a/b230827/samba/source3/script/tests/test_net_usershare.sh
> > $SERVER $SERVER_IP $USERNAME $PASSWORD
> > /memdisk/jra/a/b230827/samba/bin/smbclient 2>&1 |
> > /memdisk/jra/a/b230827/samba/selftest/filter-subunit --fail-on-empty
> > --prefix="samba3.blackbox.net_usershare." --suffix="(fileserver:local)"
> > expanded command:
> > /memdisk/jra/a/b230827/samba/source3/script/tests/test_net_usershare.sh
> > FILESERVER 127.0.0.35 jra fileserver
> > /memdisk/jra/a/b230827/samba/bin/smbclient 2>&1 |
> > /memdisk/jra/a/b230827/samba/selftest/filter-subunit --fail-on-empty
> > --prefix="samba3.blackbox.net_usershare." --suffix="(fileserver:local)"
> > ERROR: Testsuite[samba3.blackbox.net_usershare(fileserver:local)]
> > REASON: Exit code was 1
>
> I've fixed 'shift 6' to 'shift 5' and submitted with my RB+
Please look at the attached updated patchset.
Thanks,
Andreas
--
Andreas Schneider GPG-ID: CC014E3D
Samba Team asn at samba.org
www.samba.org
-------------- next part --------------
>From 410814309185d8471476cecb15f22ccc8342092c 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 c2ea3ad3deef6fe8f5804374749077bb70dbfe47 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 d93d98e3af3..2ecb9e3b33b 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
@@ -767,7 +774,15 @@ sub setup_fileserver($$)
my $smbget_sharedir="$share_dir/smbget";
push(@dirs,$smbget_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 ac861e8ba24..07952e02e39 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