[PATCH] Add libsmbclient list shares test

Andreas Schneider asn at samba.org
Wed Aug 29 08:03:08 UTC 2018


On Wednesday, 29 August 2018 01:30:38 CEST Jeremy Allison wrote:
> On Mon, Aug 27, 2018 at 05:29:22PM +0200, Andreas Schneider via samba-
technical wrote:
> > Hi,
> > 
> > the attached patch adds a test for listing shares using libsmbclient and
> > fixes teh tests to run against a target with smbd.
> > 
> > 
> > Please review and push if OK.
> 
> OK Andreas, with the following additional (attached) diff I
> can get this to pass a local:
> 
> make test TESTS=libsmbclient
> 
> I'll leave it to you to merge this into your
> patchset.

Thanks for looking into this. That works, attached is a new patchset for 
review.

I think the next step is to run these tests with NT1 only, SMB2 only and SMB3 
only. However the question is if you can use --option to overwrite smbconf 
options.


Thanks,


	Andreas

-- 
Andreas Schneider                      asn at samba.org
Samba Team                             www.samba.org
GPG-ID:     8DFF53E18F2ABC8D8F3C92237EE0FC4DCC014E3D
-------------- next part --------------
>From dc9a521402131851c1de6f44abb609cff4ad678c Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn at samba.org>
Date: Thu, 23 Aug 2018 14:00:29 +0200
Subject: [PATCH 1/3] s4:torture: Improve torture_libsmbclient_init_context()

Signed-off-by: Andreas Schneider <asn at samba.org>
---
 source4/torture/libsmbclient/libsmbclient.c | 25 +++++++++++++++++----
 1 file changed, 21 insertions(+), 4 deletions(-)

diff --git a/source4/torture/libsmbclient/libsmbclient.c b/source4/torture/libsmbclient/libsmbclient.c
index e84ce018a69..b8fab225d90 100644
--- a/source4/torture/libsmbclient/libsmbclient.c
+++ b/source4/torture/libsmbclient/libsmbclient.c
@@ -43,11 +43,23 @@ static void debug_callback(void *private_ptr, int level, const char *msg)
 bool torture_libsmbclient_init_context(struct torture_context *tctx,
 				       SMBCCTX **ctx_p)
 {
-	SMBCCTX *ctx;
+	SMBCCTX *ctx = NULL;
+	SMBCCTX *p = NULL;
+	bool ok = true;
 
 	ctx = smbc_new_context();
-	torture_assert(tctx, ctx, "failed to get new context");
-	torture_assert(tctx, smbc_init_context(ctx), "failed to init context");
+	torture_assert_not_null_goto(tctx,
+				     ctx,
+				     ok,
+				     out,
+				     "Failed to create new context");
+
+	p = smbc_init_context(ctx);
+	torture_assert_not_null_goto(tctx,
+				     p,
+				     ok,
+				     out,
+				     "Failed to initialize context");
 
 	smbc_setDebug(ctx, DEBUGLEVEL);
 	smbc_setOptionDebugToStderr(ctx, 1);
@@ -57,7 +69,12 @@ bool torture_libsmbclient_init_context(struct torture_context *tctx,
 
 	*ctx_p = ctx;
 
-	return true;
+out:
+	if (!ok) {
+		smbc_free_context(ctx, 1);
+	}
+
+	return ok;
 }
 
 static bool torture_libsmbclient_version(struct torture_context *tctx)
-- 
2.18.0


>From eebf3c113dab78901c551e6ad4c0c709f4f98901 Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn at samba.org>
Date: Thu, 23 Aug 2018 14:12:43 +0200
Subject: [PATCH 2/3] selftest: Schedule libsmbclient tests against ad_dc

Signed-off-by: Andreas Schneider <asn at samba.org>
---
 source4/selftest/tests.py | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/source4/selftest/tests.py b/source4/selftest/tests.py
index f884d272cc7..b0584928c3a 100755
--- a/source4/selftest/tests.py
+++ b/source4/selftest/tests.py
@@ -322,12 +322,14 @@ base = smbtorture4_testsuites("base.")
 
 netapi = smbtorture4_testsuites("netapi.")
 
-libsmbclient = smbtorture4_testsuites("libsmbclient.")
-libsmbclient_testargs = ["--option=torture:smburl=smb://$USERNAME:$PASSWORD@$SERVER/tmp",
-                         "--option=torture:replace_smbconf=%s/testdata/samba3/smb_new.conf" % srcdir()]
+for t in base + raw + smb2 + netapi:
+    plansmbtorture4testsuite(t, "ad_dc_ntvfs", ['//$SERVER/tmp', '-U$USERNAME%$PASSWORD'] + ntvfsargs)
 
-for t in base + raw + smb2 + netapi + libsmbclient:
-    plansmbtorture4testsuite(t, "ad_dc_ntvfs", ['//$SERVER/tmp', '-U$USERNAME%$PASSWORD'] + ntvfsargs + libsmbclient_testargs)
+libsmbclient = smbtorture4_testsuites("libsmbclient.")
+for t in libsmbclient:
+    libsmbclient_testargs = ["--option=torture:smburl=smb://$USERNAME:$PASSWORD@$SERVER/tmp",
+                             "--option=torture:replace_smbconf=%s/testdata/samba3/smb_new.conf" % srcdir()]
+    plansmbtorture4testsuite(t, "ad_dc", ['//$SERVER/tmp', '-U$USERNAME%$PASSWORD'] + libsmbclient_testargs)
 
 plansmbtorture4testsuite("raw.qfileinfo.ipc", "ad_dc_ntvfs", '//$SERVER/ipc\$ -U$USERNAME%$PASSWORD')
 
-- 
2.18.0


>From 613249df92d955e5abf7376b1a4a2cf65412e40d Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn at samba.org>
Date: Mon, 27 Aug 2018 15:59:59 +0200
Subject: [PATCH 3/3] s4:torture: Add a test for listing shares

Signed-off-by: Andreas Schneider <asn at samba.org>
---
 source3/selftest/tests.py                   | 19 ++++---
 source4/selftest/tests.py                   |  6 ++-
 source4/torture/libsmbclient/libsmbclient.c | 57 +++++++++++++++++++++
 3 files changed, 75 insertions(+), 7 deletions(-)

diff --git a/source3/selftest/tests.py b/source3/selftest/tests.py
index ed241f002da..3b6735231de 100755
--- a/source3/selftest/tests.py
+++ b/source3/selftest/tests.py
@@ -431,7 +431,10 @@ unix = ["unix.info2", "unix.whoami"]
 
 nbt = ["nbt.dgram"]
 
-libsmbclient = ["libsmbclient"]
+libsmbclient = ["libsmbclient.version", "libsmbclient.initialize",
+		"libsmbclient.configuration", "libsmbclient.setConfiguration",
+		"libsmbclient.options", "libsmbclient.opendir",
+		"libsmbclient.list_shares", "libsmbclient.readdirplus"]
 
 vfs = ["vfs.fruit", "vfs.acl_xattr", "vfs.fruit_netatalk", "vfs.fruit_file_id", "vfs.fruit_timemachine"]
 
@@ -579,13 +582,17 @@ for t in tests:
     elif t == "rpc.samba3.netlogon" or t == "rpc.samba3.sessionkey":
         plansmbtorture4testsuite(t, "nt4_dc", '//$SERVER_IP/tmp -U$USERNAME%$PASSWORD --option=torture:wksname=samba3rpctest')
         plansmbtorture4testsuite(t, "ad_dc", '//$SERVER/tmp -U$USERNAME%$PASSWORD --option=torture:wksname=samba3rpctest')
-    elif t == "libsmbclient":
+    elif t.startswith("libsmbclient"):
+	url = "smb://$USERNAME:$PASSWORD@$SERVER/tmp"
+	if t == "libsmbclient.list_shares":
+		url = "smb://$USERNAME:$PASSWORD@$SERVER"
+
         plansmbtorture4testsuite(t, "nt4_dc", '//$SERVER_IP/tmp -U$USERNAME%%$PASSWORD '
-                                    '--option=torture:smburl=smb://$USERNAME:$PASSWORD@$SERVER/tmp '
-                                    '--option=torture:replace_smbconf=%s' % os.path.join(srcdir(), "testdata/samba3/smb_new.conf"))
+                                    '--option=torture:smburl=' + url +
+                                    ' --option=torture:replace_smbconf=%s' % os.path.join(srcdir(), "testdata/samba3/smb_new.conf"))
         plansmbtorture4testsuite(t, "ad_dc", '//$SERVER/tmp -U$USERNAME%%$PASSWORD '
-                                    '--option=torture:smburl=smb://$USERNAME:$PASSWORD@$SERVER/tmp '
-                                    '--option=torture:replace_smbconf=%s' % os.path.join(srcdir(), "testdata/samba3/smb_new.conf"))
+                                    '--option=torture:smburl=' + url +
+                                    ' --option=torture:replace_smbconf=%s' % os.path.join(srcdir(), "testdata/samba3/smb_new.conf"))
     elif t == "smb2.streams":
         plansmbtorture4testsuite(t, "nt4_dc", '//$SERVER_IP/tmp -U$USERNAME%$PASSWORD')
         plansmbtorture4testsuite(t, "ad_dc", '//$SERVER/tmp -U$USERNAME%$PASSWORD')
diff --git a/source4/selftest/tests.py b/source4/selftest/tests.py
index b0584928c3a..eb85fecbcc6 100755
--- a/source4/selftest/tests.py
+++ b/source4/selftest/tests.py
@@ -327,7 +327,11 @@ for t in base + raw + smb2 + netapi:
 
 libsmbclient = smbtorture4_testsuites("libsmbclient.")
 for t in libsmbclient:
-    libsmbclient_testargs = ["--option=torture:smburl=smb://$USERNAME:$PASSWORD@$SERVER/tmp",
+    url = "smb://$USERNAME:$PASSWORD@$SERVER/tmp"
+    if t == "libsmbclient.list_shares":
+        url = "smb://$USERNAME:$PASSWORD@$SERVER"
+
+    libsmbclient_testargs = ["--option=torture:smburl=" + url,
                              "--option=torture:replace_smbconf=%s/testdata/samba3/smb_new.conf" % srcdir()]
     plansmbtorture4testsuite(t, "ad_dc", ['//$SERVER/tmp', '-U$USERNAME%$PASSWORD'] + libsmbclient_testargs)
 
diff --git a/source4/torture/libsmbclient/libsmbclient.c b/source4/torture/libsmbclient/libsmbclient.c
index b8fab225d90..fb27ddd0326 100644
--- a/source4/torture/libsmbclient/libsmbclient.c
+++ b/source4/torture/libsmbclient/libsmbclient.c
@@ -522,6 +522,62 @@ done:
 	return ok;
 }
 
+static bool torture_libsmbclient_list_shares(struct torture_context *tctx)
+{
+	const char *smburl = torture_setting_string(tctx, "smburl", NULL);
+	struct smbc_dirent *dirent = NULL;
+	SMBCCTX *ctx = NULL;
+	int dhandle = -1;
+	bool ipc_share_found = false;
+	bool ok = true;
+
+	if (smburl == NULL) {
+		torture_fail(tctx,
+			     "option --option=torture:smburl="
+			     "smb://user:password@server missing\n");
+	}
+
+	ok = torture_libsmbclient_init_context(tctx, &ctx);
+	torture_assert_goto(tctx,
+			    ok,
+			    ok,
+			    out,
+			    "Failed to init context");
+	smbc_set_context(ctx);
+
+	torture_comment(tctx, "Listing: %s\n", smburl);
+	dhandle = smbc_opendir(smburl);
+	torture_assert_int_not_equal_goto(tctx,
+					  dhandle,
+					  -1,
+					  ok,
+					  out,
+					  "Failed to open smburl");
+
+	while((dirent = smbc_readdir(dhandle)) != NULL) {
+		torture_comment(tctx, "DIR: %s\n", dirent->name);
+		torture_assert_not_null_goto(tctx,
+					     dirent->name,
+					     ok,
+					     out,
+					     "Failed to read name");
+
+		if (strequal(dirent->name, "IPC$")) {
+			ipc_share_found = true;
+		}
+	}
+
+	torture_assert_goto(tctx,
+			    ipc_share_found,
+			    ok,
+			    out,
+			    "Failed to list IPC$ share");
+
+out:
+	smbc_closedir(dhandle);
+	return ok;
+}
+
 NTSTATUS torture_libsmbclient_init(TALLOC_CTX *ctx)
 {
 	struct torture_suite *suite;
@@ -534,6 +590,7 @@ NTSTATUS torture_libsmbclient_init(TALLOC_CTX *ctx)
 	torture_suite_add_simple_test(suite, "setConfiguration", torture_libsmbclient_setConfiguration);
 	torture_suite_add_simple_test(suite, "options", torture_libsmbclient_options);
 	torture_suite_add_simple_test(suite, "opendir", torture_libsmbclient_opendir);
+	torture_suite_add_simple_test(suite, "list_shares", torture_libsmbclient_list_shares);
 	torture_suite_add_simple_test(suite, "readdirplus",
 		torture_libsmbclient_readdirplus);
 
-- 
2.18.0



More information about the samba-technical mailing list