[PATCH] smbclient and libsmbclient fixes and tests

Andreas Schneider asn at samba.org
Tue Sep 4 15:02:34 UTC 2018


Hi,

attached is patchset to address some issues in smbclient and libsmbclient. It 
also will run libsmbclient tests with NT1 and SMB3.

Please review and push if OK.


Thanks,


	Andreas

-- 
Andreas Schneider                      asn at samba.org
Samba Team                             www.samba.org
GPG-ID:     8DFF53E18F2ABC8D8F3C92237EE0FC4DCC014E3D
-------------- next part --------------
>From 7ad33dcc64f0261e394f984be222b8a8814e362a Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn at samba.org>
Date: Mon, 3 Sep 2018 12:11:39 +0200
Subject: [PATCH 1/6] smbclient: Fix errors printed if we can connect with SMB1

smbclient -L //server

before:

Reconnecting with SMB1 for workgroup listing.
Connection to earth.milkyway.site failed (Error NT_STATUS_RESOURCE_NAME_NOT_FOUND)
Failed to connect with SMB1 -- no workgroup available

after:

Reconnecting with SMB1 for workgroup listing.
Unable to connect with SMB1 -- no workgroup available

Signed-off-by: Andreas Schneider <asn at samba.org>
---
 source3/client/client.c | 2 +-
 source3/libsmb/clidfs.c | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/source3/client/client.c b/source3/client/client.c
index 25ba01d6216..adc3fcab476 100644
--- a/source3/client/client.c
+++ b/source3/client/client.c
@@ -6227,7 +6227,7 @@ static int do_host_query(const char *query_host)
 				     smb_encrypt, max_proto,
 				     NBT_SMB_PORT, name_type, &cli);
 		if (!NT_STATUS_IS_OK(status)) {
-			d_printf("Failed to connect with SMB1 "
+			d_printf("Unable to connect with SMB1 "
 				 "-- no workgroup available\n");
 			return 0;
 		}
diff --git a/source3/libsmb/clidfs.c b/source3/libsmb/clidfs.c
index 0dfb8b33606..6918802396c 100644
--- a/source3/libsmb/clidfs.c
+++ b/source3/libsmb/clidfs.c
@@ -196,9 +196,9 @@ static NTSTATUS do_connect(TALLOC_CTX *ctx,
 		flags, &c);
 
 	if (!NT_STATUS_IS_OK(status)) {
-		d_printf("Connection to %s failed (Error %s)\n",
-				server,
-				nt_errstr(status));
+		DBG_WARNING("Connection to %s failed (Error %s)\n",
+			    server,
+			    nt_errstr(status));
 		return status;
 	}
 
-- 
2.18.0


>From 40cb078b1a6590aebb2ff8fca7f966e7c122819b Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn at samba.org>
Date: Tue, 4 Sep 2018 11:11:49 +0200
Subject: [PATCH 2/6] s3:smbclient: Do not call cli_RNetShareEnum if SMB1 is
 disabled

Signed-off-by: Andreas Schneider <asn at samba.org>
---
 source3/client/client.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/source3/client/client.c b/source3/client/client.c
index adc3fcab476..738739f7909 100644
--- a/source3/client/client.c
+++ b/source3/client/client.c
@@ -4900,7 +4900,6 @@ static bool browse_host_rpc(bool sort)
 
 static bool browse_host(bool sort)
 {
-	int ret;
 	if (!grepable) {
 	        d_printf("\n\tSharename       Type      Comment\n");
 	        d_printf("\t---------       ----      -------\n");
@@ -4910,13 +4909,20 @@ static bool browse_host(bool sort)
 		return true;
 	}
 
-	if((ret = cli_RNetShareEnum(cli, browse_fn, NULL)) == -1) {
-		NTSTATUS status = cli_nt_error(cli);
-		d_printf("Error returning browse list: %s\n",
-			 nt_errstr(status));
+	if (lp_client_min_protocol() <= PROTOCOL_NT1) {
+		int ret;
+
+		ret = cli_RNetShareEnum(cli, browse_fn, NULL);
+		if (ret == -1) {
+			NTSTATUS status = cli_nt_error(cli);
+			d_printf("Error returning browse list: %s\n",
+				 nt_errstr(status));
+		}
+
+		return (ret != -1);
 	}
 
-	return (ret != -1);
+	return false;
 }
 
 /****************************************************************************
-- 
2.18.0


>From 780c133036f5021a965bb472c1f3ecf083c62704 Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn at samba.org>
Date: Tue, 4 Sep 2018 16:08:58 +0200
Subject: [PATCH 3/6] s3:libsmbclient: Do not call cli_RNetShareEnum if SMB1 is
 disabled

Signed-off-by: Andreas Schneider <asn at samba.org>
---
 source3/libsmb/libsmb_dir.c | 35 ++++++++++++++++++-----------------
 1 file changed, 18 insertions(+), 17 deletions(-)

diff --git a/source3/libsmb/libsmb_dir.c b/source3/libsmb/libsmb_dir.c
index ff19ed57f14..886aa626509 100644
--- a/source3/libsmb/libsmb_dir.c
+++ b/source3/libsmb/libsmb_dir.c
@@ -825,6 +825,7 @@ SMBC_opendir_ctx(SMBCCTX *context,
 				}
 			} else if (srv ||
                                    (resolve_name(server, &rem_ss, 0x20, false))) {
+				int rc;
 
                                 /*
                                  * If we hadn't found the server, get one now
@@ -851,24 +852,24 @@ SMBC_opendir_ctx(SMBCCTX *context,
 
                                 /* List the shares ... */
 
-                                if (net_share_enum_rpc(
-                                            srv->cli,
-                                            list_fn,
-                                            (void *) dir) < 0 &&
-                                    cli_RNetShareEnum(
-                                            srv->cli,
-                                            list_fn,
-                                            (void *)dir) < 0) {
-
-                                        errno = cli_errno(srv->cli);
-                                        if (dir) {
-                                                SAFE_FREE(dir->fname);
-                                                SAFE_FREE(dir);
-                                        }
+				rc = net_share_enum_rpc(srv->cli,
+							list_fn,
+							(void *)dir);
+				if (rc != 0 &&
+				    lp_client_min_protocol() <= PROTOCOL_NT1) {
+					rc = cli_RNetShareEnum(srv->cli,
+							       list_fn,
+							       (void *)dir);
+				}
+				if (rc != 0) {
+					errno = cli_errno(srv->cli);
+					if (dir != NULL) {
+						SAFE_FREE(dir->fname);
+						SAFE_FREE(dir);
+					}
 					TALLOC_FREE(frame);
-                                        return NULL;
-
-                                }
+					return NULL;
+				}
                         } else {
                                 /* Neither the workgroup nor server exists */
                                 errno = ECONNREFUSED;
-- 
2.18.0


>From 7a71132f98f8887b5a8eb010fecc43433133ca9d Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn at samba.org>
Date: Tue, 4 Sep 2018 15:48:03 +0200
Subject: [PATCH 4/6] s3:libsmbclient: Add function to set protocol levels

Signed-off-by: Andreas Schneider <asn at samba.org>
---
 source3/include/libsmbclient.h | 19 ++++++++++++++++++-
 source3/libsmb/libsmb_setget.c | 18 ++++++++++++++++++
 source3/libsmb/wscript         |  2 +-
 3 files changed, 37 insertions(+), 2 deletions(-)

diff --git a/source3/include/libsmbclient.h b/source3/include/libsmbclient.h
index ca5c7f87f71..5e4a1715402 100644
--- a/source3/include/libsmbclient.h
+++ b/source3/include/libsmbclient.h
@@ -831,7 +831,24 @@ smbc_getOptionUseNTHash(SMBCCTX *c);
 void
 smbc_setOptionUseNTHash(SMBCCTX *c, smbc_bool b);
 
-
+/**
+ * @brief Set the 'client min protocol' and the 'client max protocol'.
+ *
+ * IMPORTANT: This overrrides the values 'client min protocol' and 'client max
+ * protocol' set in the smb.conf file!
+ *
+ * @param[in]  c  The smbc context to use.
+ *
+ * @param[in]  min_proto  The minimal protocol to use or NULL for leaving it
+ *                        untouched.
+ *
+ * @param[in]  max_proto  The maximum protocol to use or NULL for leaving it
+ *                        untouched.
+ *
+ * @returns true for success, false otherwise
+ */
+smbc_bool
+smbc_setOptionProtocols(SMBCCTX *c, const char *min_proto, const char *max_proto);
 
 /*************************************
  * Getters and setters for FUNCTIONS *
diff --git a/source3/libsmb/libsmb_setget.c b/source3/libsmb/libsmb_setget.c
index 60b822a395c..b1c4ff3b557 100644
--- a/source3/libsmb/libsmb_setget.c
+++ b/source3/libsmb/libsmb_setget.c
@@ -526,6 +526,24 @@ smbc_setOptionUseNTHash(SMBCCTX *c, smbc_bool b)
         }
 }
 
+smbc_bool
+smbc_setOptionProtocols(SMBCCTX *c,
+			const char *min_proto,
+			const char *max_proto)
+{
+	bool ok = true;
+
+	if (min_proto != NULL) {
+		ok = lp_set_cmdline("client min protocol", min_proto);
+	}
+
+	if (max_proto != NULL) {
+		ok &= lp_set_cmdline("client min protocol", max_proto);
+	}
+
+	return ok;
+}
+
 /** Get the function for obtaining authentication data */
 smbc_get_auth_data_fn
 smbc_getFunctionAuthData(SMBCCTX *c)
diff --git a/source3/libsmb/wscript b/source3/libsmb/wscript
index 5482aea7d9c..298afc3c0e3 100644
--- a/source3/libsmb/wscript
+++ b/source3/libsmb/wscript
@@ -27,5 +27,5 @@ def build(bld):
                        public_headers='../include/libsmbclient.h',
                        abi_directory='ABI',
                        abi_match='smbc_*',
-                       vnum='0.4.0',
+                       vnum='0.5.0',
                        pc_files='smbclient.pc')
-- 
2.18.0


>From a33baa48017e271df62c684b6216666935dccbeb Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn at samba.org>
Date: Mon, 3 Sep 2018 16:36:54 +0200
Subject: [PATCH 5/6] s4:torture: Set credentials for libsmbclient correctly

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

diff --git a/source4/torture/libsmbclient/libsmbclient.c b/source4/torture/libsmbclient/libsmbclient.c
index fb27ddd0326..853d002aa8d 100644
--- a/source4/torture/libsmbclient/libsmbclient.c
+++ b/source4/torture/libsmbclient/libsmbclient.c
@@ -40,9 +40,39 @@ static void debug_callback(void *private_ptr, int level, const char *msg)
 	return;
 }
 
+static void auth_callback(const char *srv,
+			  const char *shr,
+			  char *wg, int wglen,
+			  char *un, int unlen,
+			  char *pw, int pwlen)
+{
+	const char *workgroup =
+		cli_credentials_get_domain(popt_get_cmdline_credentials());
+	const char *username =
+		cli_credentials_get_username(popt_get_cmdline_credentials());
+	const char *password =
+		cli_credentials_get_password(popt_get_cmdline_credentials());
+
+	if (workgroup != NULL) {
+		snprintf(wg, wglen, "%s", workgroup);
+	}
+
+	if (username != NULL) {
+		snprintf(un, unlen, "%s", username);
+	}
+
+	if (password != NULL) {
+		snprintf(pw, pwlen, "%s", password);
+	}
+};
+
 bool torture_libsmbclient_init_context(struct torture_context *tctx,
 				       SMBCCTX **ctx_p)
 {
+	const char *workgroup =
+		cli_credentials_get_domain(popt_get_cmdline_credentials());
+	const char *username =
+		cli_credentials_get_username(popt_get_cmdline_credentials());
 	SMBCCTX *ctx = NULL;
 	SMBCCTX *p = NULL;
 	bool ok = true;
@@ -64,8 +94,14 @@ bool torture_libsmbclient_init_context(struct torture_context *tctx,
 	smbc_setDebug(ctx, DEBUGLEVEL);
 	smbc_setOptionDebugToStderr(ctx, 1);
 
-	smbc_setUser(ctx,
-		     cli_credentials_get_username(popt_get_cmdline_credentials()));
+	if (workgroup != NULL) {
+		smbc_setWorkgroup(ctx, workgroup);
+	}
+	if (username != NULL) {
+		smbc_setUser(ctx, username);
+	}
+
+	smbc_setFunctionAuthData(ctx, auth_callback);
 
 	*ctx_p = ctx;
 
-- 
2.18.0


>From a72af76f7ec2d0317ddba62bb5b00014670a1a36 Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn at samba.org>
Date: Mon, 3 Sep 2018 16:55:02 +0200
Subject: [PATCH 6/6] selftest: Run libsmbclient tests with NT1 and SMB3

Signed-off-by: Andreas Schneider <asn at samba.org>
---
 selftest/knownfail                          | 2 +-
 source4/selftest/tests.py                   | 9 ++++++---
 source4/torture/libsmbclient/libsmbclient.c | 6 ++++++
 3 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/selftest/knownfail b/selftest/knownfail
index 93c1a3511ac..eef8134c9f5 100644
--- a/selftest/knownfail
+++ b/selftest/knownfail
@@ -125,7 +125,7 @@
 ^samba4.smb2.acls.*.ACCESSBASED
 ^samba4.ldap.dirsync.python.ad_dc_ntvfs..__main__.ExtendedDirsyncTests.test_dirsync_deleted_items
 #^samba4.ldap.dirsync.python.ad_dc_ntvfs..__main__.ExtendedDirsyncTests.*
-^samba4.libsmbclient.opendir.opendir # This requires netbios browsing
+^samba4.libsmbclient.opendir.(NT1|SMB3).opendir # This requires netbios browsing
 ^samba4.rpc.drsuapi.*.drsuapi.DsGetDomainControllerInfo\(.*\)$
 ^samba4.smb2.oplock.exclusive2\(.*\)$ # samba 4 oplocks are a mess
 ^samba4.smb2.oplock.exclusive5\(.*\)$ # samba 4 oplocks are a mess
diff --git a/source4/selftest/tests.py b/source4/selftest/tests.py
index 1626b9312f4..c1747ddcd50 100755
--- a/source4/selftest/tests.py
+++ b/source4/selftest/tests.py
@@ -332,14 +332,17 @@ for t in base + raw + smb2 + netapi:
     plansmbtorture4testsuite(t, "ad_dc_ntvfs", ['//$SERVER/tmp', '-U$USERNAME%$PASSWORD'] + ntvfsargs)
 
 libsmbclient = smbtorture4_testsuites("libsmbclient.")
+protocols = [ 'NT1', 'SMB3' ]
 for t in libsmbclient:
     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)
+    for proto in protocols:
+        libsmbclient_testargs = ["--option=torture:smburl=" + url,
+                                 "--option=torture:replace_smbconf=%s/testdata/samba3/smb_new.conf" % srcdir(),
+                                 "--option=torture:clientprotocol=%s" % proto]
+        plansmbtorture4testsuite(t, "ad_dc", ['//$SERVER/tmp', '-U$USERNAME%$PASSWORD'] + libsmbclient_testargs, "samba4.%s.%s" % (t, proto))
 
 plansmbtorture4testsuite("raw.qfileinfo.ipc", "ad_dc_ntvfs", '//$SERVER/ipc\$ -U$USERNAME%$PASSWORD')
 
diff --git a/source4/torture/libsmbclient/libsmbclient.c b/source4/torture/libsmbclient/libsmbclient.c
index 853d002aa8d..f9154e8a19c 100644
--- a/source4/torture/libsmbclient/libsmbclient.c
+++ b/source4/torture/libsmbclient/libsmbclient.c
@@ -73,6 +73,8 @@ bool torture_libsmbclient_init_context(struct torture_context *tctx,
 		cli_credentials_get_domain(popt_get_cmdline_credentials());
 	const char *username =
 		cli_credentials_get_username(popt_get_cmdline_credentials());
+	const char *client_proto =
+		torture_setting_string(tctx, "clientprotocol", NULL);
 	SMBCCTX *ctx = NULL;
 	SMBCCTX *p = NULL;
 	bool ok = true;
@@ -103,6 +105,10 @@ bool torture_libsmbclient_init_context(struct torture_context *tctx,
 
 	smbc_setFunctionAuthData(ctx, auth_callback);
 
+	if (client_proto != NULL) {
+		smbc_setOptionProtocols(ctx, client_proto, client_proto);
+	}
+
 	*ctx_p = ctx;
 
 out:
-- 
2.18.0



More information about the samba-technical mailing list