2371a7
From 1fdca16074247707e80295bba65cbb5fbff9e959 Mon Sep 17 00:00:00 2001
2371a7
From: Jeremy Allison <jra@samba.org>
2371a7
Date: Mon, 1 Jun 2020 13:55:10 -0700
2371a7
Subject: [PATCH 1/7] s3: libsmb: Info level SMB2_FIND_ID_BOTH_DIRECTORY_INFO
2371a7
 encodes attibutes as a uint32, not a uint8.
2371a7
2371a7
Fix the SMB2 parsing code.
2371a7
2371a7
Cast to a uint16_t for now after pulling the information
2371a7
as finfo->mode is currently only 16 bits.
2371a7
2371a7
We will need this to detect FILE_ATTRIBUTE_REPARSE_POINT in a later commit.
2371a7
2371a7
Signed-off-by: Jeremy Allison <jra@samba.org>
2371a7
Reviewed-by: Ralph Boehme <slow@samba.org>
2371a7
(cherry picked from commit 3063e1601ad9e2536651a75a47ebf4921ffddbdc)
2371a7
---
2371a7
 source3/libsmb/cli_smb2_fnum.c | 3 ++-
2371a7
 1 file changed, 2 insertions(+), 1 deletion(-)
2371a7
2371a7
diff --git a/source3/libsmb/cli_smb2_fnum.c b/source3/libsmb/cli_smb2_fnum.c
2371a7
index 8c8b33f49ed..4edeefc117d 100644
2371a7
--- a/source3/libsmb/cli_smb2_fnum.c
2371a7
+++ b/source3/libsmb/cli_smb2_fnum.c
2371a7
@@ -1236,7 +1236,8 @@ static NTSTATUS parse_finfo_id_both_directory_info(uint8_t *dir_data,
2371a7
 	finfo->ctime_ts = interpret_long_date((const char *)dir_data + 32);
2371a7
 	finfo->size = IVAL2_TO_SMB_BIG_UINT(dir_data + 40, 0);
2371a7
 	finfo->allocated_size = IVAL2_TO_SMB_BIG_UINT(dir_data + 48, 0);
2371a7
-	finfo->mode = CVAL(dir_data + 56, 0);
2371a7
+	/* NB. We need to enlarge finfo->mode to be 32-bits. */
2371a7
+	finfo->mode = (uint16_t)IVAL(dir_data + 56, 0);
2371a7
 	finfo->ino = IVAL2_TO_SMB_BIG_UINT(dir_data + 96, 0);
2371a7
 	namelen = IVAL(dir_data + 60,0);
2371a7
 	if (namelen > (dir_data_length - 104)) {
2371a7
-- 
2371a7
2.20.1
2371a7
2371a7
2371a7
From 8d57c6e81986655ccb59189843e0ffa6830eb182 Mon Sep 17 00:00:00 2001
2371a7
From: Jeremy Allison <jra@samba.org>
2371a7
Date: Mon, 1 Jun 2020 11:36:03 -0700
2371a7
Subject: [PATCH 2/7] s3: libsmb: Info level SMB_FIND_FILE_BOTH_DIRECTORY_INFO
2371a7
 encodes attibutes as a uint32, not a uint8.
2371a7
2371a7
Cast to a uint16_t for now after pulling the information
2371a7
as finfo->mode is currently only 16 bits.
2371a7
2371a7
We will need this to detect FILE_ATTRIBUTE_REPARSE_POINT in a later commit.
2371a7
2371a7
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14391
2371a7
2371a7
Signed-off-by: Jeremy Allison <jra@samba.org>
2371a7
Reviewed-by: Ralph Boehme <slow@samba.org>
2371a7
(cherry picked from commit 5e3e6c4c0c70e171607f4b5351bd8ec146730f08)
2371a7
---
2371a7
 source3/libsmb/clilist.c | 3 ++-
2371a7
 1 file changed, 2 insertions(+), 1 deletion(-)
2371a7
2371a7
diff --git a/source3/libsmb/clilist.c b/source3/libsmb/clilist.c
2371a7
index f9444bc401c..a78678f4532 100644
2371a7
--- a/source3/libsmb/clilist.c
2371a7
+++ b/source3/libsmb/clilist.c
2371a7
@@ -257,7 +257,8 @@ static size_t interpret_long_filename(TALLOC_CTX *ctx,
2371a7
 			finfo->size = IVAL2_TO_SMB_BIG_UINT(p,0);
2371a7
 			p += 8;
2371a7
 			p += 8; /* alloc size */
2371a7
-			finfo->mode = CVAL(p,0);
2371a7
+			/* NB. We need to enlarge finfo->mode to be 32-bits. */
2371a7
+			finfo->mode = (uint16_t)IVAL(p,0);
2371a7
 			p += 4;
2371a7
 			namelen = IVAL(p,0);
2371a7
 			p += 4;
2371a7
-- 
2371a7
2.20.1
2371a7
2371a7
2371a7
From 1afa493387e1f8a5f80b9504cf92655d067c9dbc Mon Sep 17 00:00:00 2001
2371a7
From: Jeremy Allison <jra@samba.org>
2371a7
Date: Mon, 1 Jun 2020 12:01:13 -0700
2371a7
Subject: [PATCH 3/7] s3: libsmb: Info level SMB_FIND_INFO_STANDARD encodes
2371a7
 attibutes as a uint16, not a uint8.
2371a7
2371a7
We will need this to detect FILE_ATTRIBUTE_REPARSE_POINT in a later commit.
2371a7
2371a7
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14391
2371a7
2371a7
Signed-off-by: Jeremy Allison <jra@samba.org>
2371a7
Reviewed-by: Ralph Boehme <slow@samba.org>
2371a7
(cherry picked from commit be52f87c376a8f71b2de4aa52f25818cad2b160e)
2371a7
---
2371a7
 source3/libsmb/clilist.c | 2 +-
2371a7
 1 file changed, 1 insertion(+), 1 deletion(-)
2371a7
2371a7
diff --git a/source3/libsmb/clilist.c b/source3/libsmb/clilist.c
2371a7
index a78678f4532..deeb794ffe5 100644
2371a7
--- a/source3/libsmb/clilist.c
2371a7
+++ b/source3/libsmb/clilist.c
2371a7
@@ -152,7 +152,7 @@ static size_t interpret_long_filename(TALLOC_CTX *ctx,
2371a7
 			finfo->mtime_ts = convert_time_t_to_timespec(
2371a7
 				make_unix_date2(p+12, smb1cli_conn_server_time_zone(cli->conn)));
2371a7
 			finfo->size = IVAL(p,16);
2371a7
-			finfo->mode = CVAL(p,24);
2371a7
+			finfo->mode = SVAL(p,24);
2371a7
 			len = CVAL(p, 26);
2371a7
 			p += 27;
2371a7
 			if (recv_flags2 & FLAGS2_UNICODE_STRINGS) {
2371a7
-- 
2371a7
2.20.1
2371a7
2371a7
2371a7
From 0ebb13959479949bc31c3badade02900973f80d5 Mon Sep 17 00:00:00 2001
2371a7
From: Jeremy Allison <jra@samba.org>
2371a7
Date: Mon, 1 Jun 2020 11:33:13 -0700
2371a7
Subject: [PATCH 4/7] s3: libsmb: Info level SMB_FIND_EA_SIZE encodes attibutes
2371a7
 as a uint16, not a uint8.
2371a7
2371a7
We will need this to detect FILE_ATTRIBUTE_REPARSE_POINT in a later commit.
2371a7
2371a7
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14391
2371a7
2371a7
Signed-off-by: Jeremy Allison <jra@samba.org>
2371a7
Reviewed-by: Ralph Boehme <slow@samba.org>
2371a7
(cherry picked from commit 6463f2612a662f217af18455206afde122323375)
2371a7
---
2371a7
 source3/libsmb/clilist.c | 2 +-
2371a7
 1 file changed, 1 insertion(+), 1 deletion(-)
2371a7
2371a7
diff --git a/source3/libsmb/clilist.c b/source3/libsmb/clilist.c
2371a7
index deeb794ffe5..4a32fc45fa6 100644
2371a7
--- a/source3/libsmb/clilist.c
2371a7
+++ b/source3/libsmb/clilist.c
2371a7
@@ -211,7 +211,7 @@ static size_t interpret_long_filename(TALLOC_CTX *ctx,
2371a7
 			finfo->mtime_ts = convert_time_t_to_timespec(
2371a7
 				make_unix_date2(p+12, smb1cli_conn_server_time_zone(cli->conn)));
2371a7
 			finfo->size = IVAL(p,16);
2371a7
-			finfo->mode = CVAL(p,24);
2371a7
+			finfo->mode = SVAL(p,24);
2371a7
 			len = CVAL(p, 30);
2371a7
 			p += 31;
2371a7
 			/* check for unisys! */
2371a7
-- 
2371a7
2.20.1
2371a7
2371a7
2371a7
From 83d0c3f3d8d838be8e40e7f102aa872302442df4 Mon Sep 17 00:00:00 2001
2371a7
From: Jeremy Allison <jra@samba.org>
2371a7
Date: Mon, 1 Jun 2020 12:08:17 -0700
2371a7
Subject: [PATCH 5/7] s3: torture: Add a MSDFS-ATTRIBUTE test.
2371a7
2371a7
Framework to drive comes next.
2371a7
2371a7
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14391
2371a7
2371a7
Signed-off-by: Jeremy Allison <jra@samba.org>
2371a7
Reviewed-by: Ralph Boehme <slow@samba.org>
2371a7
(cherry picked from commit 84134812e3447317125ae08b2a98848a2e4bbd65)
2371a7
---
2371a7
 source3/torture/torture.c | 79 +++++++++++++++++++++++++++++++++++++++
2371a7
 1 file changed, 79 insertions(+)
2371a7
2371a7
diff --git a/source3/torture/torture.c b/source3/torture/torture.c
2371a7
index f07a0adf115..56258d3d2ad 100644
2371a7
--- a/source3/torture/torture.c
2371a7
+++ b/source3/torture/torture.c
2371a7
@@ -11405,6 +11405,81 @@ static bool run_large_readx(int dummy)
2371a7
 	return correct;
2371a7
 }
2371a7
 
2371a7
+static NTSTATUS msdfs_attribute_list_fn(const char *mnt,
2371a7
+				  struct file_info *finfo,
2371a7
+				  const char *mask,
2371a7
+				  void *private_data)
2371a7
+{
2371a7
+	uint16_t *p_mode = (uint16_t *)private_data;
2371a7
+
2371a7
+	if (strequal(finfo->name, test_filename)) {
2371a7
+		*p_mode = finfo->mode;
2371a7
+	}
2371a7
+
2371a7
+	return NT_STATUS_OK;
2371a7
+}
2371a7
+
2371a7
+static bool run_msdfs_attribute(int dummy)
2371a7
+{
2371a7
+	static struct cli_state *cli;
2371a7
+	bool correct = false;
2371a7
+	uint16_t mode = 0;
2371a7
+	NTSTATUS status;
2371a7
+
2371a7
+	printf("Starting MSDFS-ATTRIBUTE test\n");
2371a7
+
2371a7
+	if (test_filename == NULL || test_filename[0] == '\0') {
2371a7
+		printf("MSDFS-ATTRIBUTE test "
2371a7
+			"needs -f filename-of-msdfs-link\n");
2371a7
+		return false;
2371a7
+	}
2371a7
+
2371a7
+	/*
2371a7
+	 * NB. We use torture_open_connection_flags() not
2371a7
+	 * torture_open_connection() as the latter forces
2371a7
+	 * SMB1.
2371a7
+	 */
2371a7
+	if (!torture_open_connection_flags(&cli, 0, 0)) {
2371a7
+		return false;
2371a7
+	}
2371a7
+
2371a7
+	smbXcli_conn_set_sockopt(cli->conn, sockops);
2371a7
+
2371a7
+	status = cli_list(cli,
2371a7
+			"*",
2371a7
+			FILE_ATTRIBUTE_DIRECTORY,
2371a7
+			msdfs_attribute_list_fn,
2371a7
+			&mode);
2371a7
+
2371a7
+	if (!NT_STATUS_IS_OK(status)) {
2371a7
+		printf("cli_list failed with %s\n",
2371a7
+			nt_errstr(status));
2371a7
+		goto out;
2371a7
+	}
2371a7
+	if ((mode & FILE_ATTRIBUTE_REPARSE_POINT) == 0) {
2371a7
+		printf("file %s should have "
2371a7
+			"FILE_ATTRIBUTE_REPARSE_POINT set. attr = 0x%x\n",
2371a7
+			test_filename,
2371a7
+			(unsigned int)mode);
2371a7
+		goto out;
2371a7
+	}
2371a7
+
2371a7
+	if ((mode & FILE_ATTRIBUTE_DIRECTORY) == 0) {
2371a7
+		printf("file %s should have "
2371a7
+			"FILE_ATTRIBUTE_DIRECTORY set. attr = 0x%x\n",
2371a7
+			test_filename,
2371a7
+			(unsigned int)mode);
2371a7
+		goto out;
2371a7
+	}
2371a7
+
2371a7
+	correct = true;
2371a7
+
2371a7
+  out:
2371a7
+
2371a7
+	torture_close_connection(cli);
2371a7
+	return correct;
2371a7
+}
2371a7
+
2371a7
 static bool run_cli_echo(int dummy)
2371a7
 {
2371a7
 	struct cli_state *cli;
2371a7
@@ -14539,6 +14614,10 @@ static struct {
2371a7
 		.name  = "LARGE_READX",
2371a7
 		.fn    = run_large_readx,
2371a7
 	},
2371a7
+	{
2371a7
+		.name  = "MSDFS-ATTRIBUTE",
2371a7
+		.fn    = run_msdfs_attribute,
2371a7
+	},
2371a7
 	{
2371a7
 		.name  = "NTTRANS-CREATE",
2371a7
 		.fn    = run_nttrans_create,
2371a7
-- 
2371a7
2.20.1
2371a7
2371a7
2371a7
From 33fcc76091307005a1ff81b32108dbeefa1a4d28 Mon Sep 17 00:00:00 2001
2371a7
From: Jeremy Allison <jra@samba.org>
2371a7
Date: Mon, 1 Jun 2020 13:45:28 -0700
2371a7
Subject: [PATCH 6/7] s3: torture: Add test for getting attibutes on an MSDFS
2371a7
 link.
2371a7
2371a7
Mark as knownfail for now.
2371a7
2371a7
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14391
2371a7
2371a7
Signed-off-by: Jeremy Allison <jra@samba.org>
2371a7
Reviewed-by: Ralph Boehme <slow@samba.org>
2371a7
(back ported from commit 2a4705129d06b91023bc3fc435fccf91d3939553)
2371a7
---
2371a7
 selftest/knownfail.d/msdfs-attr |  3 +++
2371a7
 source3/selftest/tests.py       | 27 +++++++++++++++++++++++++++
2371a7
 2 files changed, 30 insertions(+)
2371a7
 create mode 100644 selftest/knownfail.d/msdfs-attr
2371a7
2371a7
diff --git a/selftest/knownfail.d/msdfs-attr b/selftest/knownfail.d/msdfs-attr
2371a7
new file mode 100644
2371a7
index 00000000000..a8a77ec2719
2371a7
--- /dev/null
2371a7
+++ b/selftest/knownfail.d/msdfs-attr
2371a7
@@ -0,0 +1,3 @@
2371a7
+samba3.smbtorture_s3.smb2.MSDFS-ATTRIBUTE
2371a7
+samba3.smbtorture_s3.smb1.MSDFS-ATTRIBUTE
2371a7
+
2371a7
diff --git a/source3/selftest/tests.py b/source3/selftest/tests.py
2371a7
index 72bca263c0b..005d6f453b1 100755
2371a7
--- a/source3/selftest/tests.py
2371a7
+++ b/source3/selftest/tests.py
2371a7
@@ -162,6 +162,33 @@ plantestsuite("samba3.smbtorture_s3.hidenewfiles(simpleserver)",
2371a7
                "",
2371a7
                "-l $LOCAL_PATH"])
2371a7
 
2371a7
+#
2371a7
+# MSDFS attribute tests.
2371a7
+#
2371a7
+plantestsuite("samba3.smbtorture_s3.smb2.MSDFS-ATTRIBUTE",
2371a7
+                "fileserver",
2371a7
+                [os.path.join(samba3srcdir,
2371a7
+                              "script/tests/test_smbtorture_s3.sh"),
2371a7
+                'MSDFS-ATTRIBUTE',
2371a7
+                '//$SERVER_IP/msdfs-share',
2371a7
+                '$USERNAME',
2371a7
+                '$PASSWORD',
2371a7
+                smbtorture3,
2371a7
+                "-mSMB2",
2371a7
+                "-f msdfs-src1"])
2371a7
+
2371a7
+plantestsuite("samba3.smbtorture_s3.smb1.MSDFS-ATTRIBUTE",
2371a7
+                "fileserver",
2371a7
+                [os.path.join(samba3srcdir,
2371a7
+                              "script/tests/test_smbtorture_s3.sh"),
2371a7
+                'MSDFS-ATTRIBUTE',
2371a7
+                '//$SERVER_IP/msdfs-share',
2371a7
+                '$USERNAME',
2371a7
+                '$PASSWORD',
2371a7
+                smbtorture3,
2371a7
+                "-mNT1",
2371a7
+                "-f msdfs-src1"])
2371a7
+
2371a7
 shares = [
2371a7
     "vfs_aio_pthread_async_dosmode_default1",
2371a7
     "vfs_aio_pthread_async_dosmode_default2",
2371a7
-- 
2371a7
2.20.1
2371a7
2371a7
2371a7
From adecbf7277e580d9a047f588a301733abd7bae68 Mon Sep 17 00:00:00 2001
2371a7
From: Jeremy Allison <jra@samba.org>
2371a7
Date: Mon, 1 Jun 2020 14:09:54 -0700
2371a7
Subject: [PATCH 7/7] s3: msdfs: Fix missing struct stat return on msdfs links
2371a7
 by doing an LSTAT call.
2371a7
2371a7
This (unfortunately) re-exposes the fact the msdfs links are symlinks,
2371a7
bit fixing this correctly requires a VFS ABI change which we can't
2371a7
do for a released stream.
2371a7
2371a7
Remove the knownfail.d/msdfs-attr file.
2371a7
2371a7
Everything now passes.
2371a7
2371a7
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14391
2371a7
2371a7
Signed-off-by: Jeremy Allison <jra@samba.org>
2371a7
Reviewed-by: Ralph Boehme <slow@samba.org>
2371a7
---
2371a7
 selftest/knownfail.d/msdfs-attr | 3 ---
2371a7
 source3/smbd/msdfs.c            | 7 +++++++
2371a7
 2 files changed, 7 insertions(+), 3 deletions(-)
2371a7
 delete mode 100644 selftest/knownfail.d/msdfs-attr
2371a7
2371a7
diff --git a/selftest/knownfail.d/msdfs-attr b/selftest/knownfail.d/msdfs-attr
2371a7
deleted file mode 100644
2371a7
index a8a77ec2719..00000000000
2371a7
--- a/selftest/knownfail.d/msdfs-attr
2371a7
+++ /dev/null
2371a7
@@ -1,3 +0,0 @@
2371a7
-samba3.smbtorture_s3.smb2.MSDFS-ATTRIBUTE
2371a7
-samba3.smbtorture_s3.smb1.MSDFS-ATTRIBUTE
2371a7
-
2371a7
diff --git a/source3/smbd/msdfs.c b/source3/smbd/msdfs.c
2371a7
index cc32ebc9d29..c57866f7939 100644
2371a7
--- a/source3/smbd/msdfs.c
2371a7
+++ b/source3/smbd/msdfs.c
2371a7
@@ -633,6 +633,13 @@ bool is_msdfs_link(connection_struct *conn,
2371a7
 					smb_fname,
2371a7
 					NULL,
2371a7
 					NULL);
2371a7
+	if (NT_STATUS_IS_OK(status)) {
2371a7
+		int ret;
2371a7
+		ret = SMB_VFS_LSTAT(conn, smb_fname);
2371a7
+		if (ret < 0) {
2371a7
+			status = map_nt_error_from_unix(errno);
2371a7
+		}
2371a7
+	}
2371a7
 	return (NT_STATUS_IS_OK(status));
2371a7
 }
2371a7
 
2371a7
-- 
2371a7
2.20.1
2371a7