[PATCH] Fix bug 12968 - smbclient tarmode doesn't work with SMB2/3.

Jeremy Allison jra at samba.org
Wed Aug 16 22:54:12 UTC 2017


As Metze points out in the bug report, cli_chkpath()
is missing an SMB2 implementation.

Please review and push if happy !

Jeremy.
-------------- next part --------------
From 680c8eca8b814cd4846a435c40aefc20f82576e8 Mon Sep 17 00:00:00 2001
From: Jeremy Allison <jra at samba.org>
Date: Wed, 16 Aug 2017 15:48:01 -0700
Subject: [PATCH 1/2] s3: libsmb: Add cli_smb2_chkpath().

BUG: https://bugzilla.samba.org/show_bug.cgi?id=12968

Signed-off-by: Jeremy Allison <jra at samba.org>
---
 source3/libsmb/cli_smb2_fnum.c | 50 ++++++++++++++++++++++++++++++++++++++++++
 source3/libsmb/cli_smb2_fnum.h |  2 ++
 2 files changed, 52 insertions(+)

diff --git a/source3/libsmb/cli_smb2_fnum.c b/source3/libsmb/cli_smb2_fnum.c
index 2d2667e4bb3..313cec53459 100644
--- a/source3/libsmb/cli_smb2_fnum.c
+++ b/source3/libsmb/cli_smb2_fnum.c
@@ -1100,6 +1100,56 @@ NTSTATUS cli_smb2_qpathinfo_basic(struct cli_state *cli,
 	return status;
 }
 
+/***************************************************************
+ Wrapper that allows SMB2 to check if a path is a directory.
+ Synchronous only.
+***************************************************************/
+
+NTSTATUS cli_smb2_chkpath(struct cli_state *cli,
+				const char *name)
+{
+	NTSTATUS status;
+	uint16_t fnum = 0xffff;
+	size_t namelen = strlen(name);
+
+	if (smbXcli_conn_has_async_calls(cli->conn)) {
+		/*
+		 * Can't use sync call while an async call is in flight
+		 */
+		return NT_STATUS_INVALID_PARAMETER;
+	}
+
+	if (smbXcli_conn_protocol(cli->conn) < PROTOCOL_SMB2_02) {
+		return NT_STATUS_INVALID_PARAMETER;
+	}
+
+	/* SMB2 is pickier about pathnames. Ensure it doesn't
+	   end in a '\' */
+	if (namelen > 0 && name[namelen-1] == '\\') {
+		char *modname = talloc_strdup(talloc_tos(), name);
+		modname[namelen-1] = '\0';
+		name = modname;
+	}
+
+	/* Ensure this is a directory. */
+	status = cli_smb2_create_fnum(cli,
+			name,
+			0,			/* create_flags */
+			FILE_READ_ATTRIBUTES,	/* desired_access */
+			FILE_ATTRIBUTE_DIRECTORY, /* file attributes */
+			FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access */
+			FILE_OPEN,		/* create_disposition */
+			FILE_DIRECTORY_FILE,	/* create_options */
+			&fnum,
+			NULL);
+
+	if (!NT_STATUS_IS_OK(status)) {
+		return status;
+	}
+
+	return cli_smb2_close_fnum(cli, fnum);
+}
+
 /***************************************************************
  Helper function for pathname operations.
 ***************************************************************/
diff --git a/source3/libsmb/cli_smb2_fnum.h b/source3/libsmb/cli_smb2_fnum.h
index 402801bd18a..a6c36275eb8 100644
--- a/source3/libsmb/cli_smb2_fnum.h
+++ b/source3/libsmb/cli_smb2_fnum.h
@@ -79,6 +79,8 @@ NTSTATUS cli_smb2_qpathinfo_basic(struct cli_state *cli,
 NTSTATUS cli_smb2_qpathinfo_alt_name(struct cli_state *cli,
 			const char *name,
 			fstring alt_name);
+NTSTATUS cli_smb2_chkpath(struct cli_state *cli,
+			const char *name);
 NTSTATUS cli_smb2_qfileinfo_basic(struct cli_state *cli,
 			uint16_t fnum,
 			uint16_t *mode,
-- 
2.14.1.480.gb18f417b89-goog


From 218c0c3248a9ab9d81501181a1f1cde80e5f22a6 Mon Sep 17 00:00:00 2001
From: Jeremy Allison <jra at samba.org>
Date: Wed, 16 Aug 2017 15:48:29 -0700
Subject: [PATCH 2/2] s3: libsmb: And use cli_smb2_chkpath() inside
 cli_chkpath().

BUG: https://bugzilla.samba.org/show_bug.cgi?id=12968

Signed-off-by: Jeremy Allison <jra at samba.org>
---
 source3/libsmb/clifile.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/source3/libsmb/clifile.c b/source3/libsmb/clifile.c
index 828448f2d5a..a6a0bafa2cd 100644
--- a/source3/libsmb/clifile.c
+++ b/source3/libsmb/clifile.c
@@ -4233,12 +4233,18 @@ NTSTATUS cli_chkpath_recv(struct tevent_req *req)
 
 NTSTATUS cli_chkpath(struct cli_state *cli, const char *path)
 {
-	TALLOC_CTX *frame = talloc_stackframe();
+	TALLOC_CTX *frame = NULL;
 	struct tevent_context *ev = NULL;
 	struct tevent_req *req = NULL;
 	char *path2 = NULL;
 	NTSTATUS status = NT_STATUS_OK;
 
+	if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) {
+		return cli_smb2_chkpath(cli, path);
+	}
+
+	frame = talloc_stackframe();
+
 	if (smbXcli_conn_has_async_calls(cli->conn)) {
 		/*
 		 * Can't use sync call while an async call is in flight
-- 
2.14.1.480.gb18f417b89-goog



More information about the samba-technical mailing list