[SCM] Samba Shared Repository - branch v4-8-test updated

Karolin Seeger kseeger at samba.org
Thu Jul 12 15:43:03 UTC 2018


The branch, v4-8-test has been updated
       via  c5680ba s3: smbd/durable: remove dev and inode check from vfs_default_durable_reconnect_check_stat()
       via  6930bb9 libsmbclient: Initialize written in cli_splice_fallback()
       via  40c9784 libsmbclient: Initialize written value before use.
       via  c7bedb9 lib: smb_threads: fix access before init bug
       via  adef988 python: pysmbd: Additional error path leak fix.
       via  425f513 s3:smbd: don't allow renaming basefile if streams are open
       via  dd78d9a s3:locking: add file_has_open_streams()
       via  85571d0 s3:smbd: add private option NTCREATEX_OPTIONS_PRIVATE_STREAM_BASEOPEN
       via  93ec87e s4:torture/vfs/fruit: adjust test testing basefile rename to expect failure
       via  36972fd s4:torture/smb2/streams: try to rename basefile while is has open streams
       via  00b001b selftest: run smb2.streams tests against a share with vfs_streams_xattr
       via  af4cb57 vfs_fruit: delete 0 byte size streams if AAPL is enabled
       via  c88aa5f s4:torture: test setting EOF of a stream to 0 with enabled AAPL extensions
       via  2ea15c5 s4:torture/vfs/fruit: decrease large resource fork size in test from 1 GB to 64 MB
      from  b5d333c ctdb-tests: Avoid segfault by initializing logging

https://git.samba.org/?p=samba.git;a=shortlog;h=v4-8-test


- Log -----------------------------------------------------------------
commit c5680ba4b27b35d403cceb6f34cd383352292428
Author: Ralph Boehme <slow at samba.org>
Date:   Fri Mar 2 15:50:29 2018 +0100

    s3: smbd/durable: remove dev and inode check from vfs_default_durable_reconnect_check_stat()
    
    On a cluster filesystem the device numbers may differ on the cluster
    nodes. We already verify the file_id in vfs_default_durable_reconnect(),
    so we can safely remove the dev/inode checks.
    
    Bug: https://bugzilla.samba.org/show_bug.cgi?id=13318
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>
    (cherry picked from commit 0a91ade5272698c094137fa28d2ad4723b5963cf)
    
    Autobuild-User(v4-8-test): Karolin Seeger <kseeger at samba.org>
    Autobuild-Date(v4-8-test): Thu Jul 12 17:42:50 CEST 2018 on sn-devel-144

commit 6930bb96f5ac2b0a50947478c9bcb79fa58a8b08
Author: Bailey Berro <baileyberro at chromium.org>
Date:   Tue Jun 26 13:13:39 2018 -0700

    libsmbclient: Initialize written in cli_splice_fallback()
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=13511
    
    Signed-off-by: Bailey Berro <baileyberro at chromium.org>
    Reviewed-by: David Mulder <dmulder at suse.com>
    Reviewed-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: David Disseldorp <ddiss at samba.org>
    
    Autobuild-User(master): David Disseldorp <ddiss at samba.org>
    Autobuild-Date(master): Mon Jul  9 21:29:48 CEST 2018 on sn-devel-144
    
    (cherry picked from commit fe25bc793d30a64f06b19f737c652b0c7389ca92)

commit 40c978434cae84b8d762025b954227e0fccfd8e4
Author: Jeremy Allison <jra at samba.org>
Date:   Fri Jul 6 11:46:44 2018 -0700

    libsmbclient: Initialize written value before use.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=13511
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: David Disseldorp <ddiss at samba.org>
    (cherry picked from commit 2e4878a69a62fb59d843ee53a1a9469b987e3a59)

commit c7bedb9c603ebcec339290ba475bc344928fbff5
Author: Ralph Boehme <slow at samba.org>
Date:   Tue Jul 3 15:30:33 2018 +0200

    lib: smb_threads: fix access before init bug
    
    talloc_stackframe_internal() calls SMB_THREAD_GET_TLS(global_ts)  which
    calls smb_get_tls_pthread() in the POSIX pthread wrapper implementation.
    
    If SMB_THREAD_SET_TLS() hasn't been called before, global_ts is NULL and
    smb_get_tls_pthread dereferences it so it crashes.
    
    Bug: https://bugzilla.samba.org/show_bug.cgi?id=13505
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Andreas Schneider <asn at samba.org>
    (cherry picked from commit e311801e0e7171a2b50e39d3e0c2d2137f8b3d7e)

commit adef988e517384f80dd21f187bf63a54efe8efbd
Author: Jeremy Allison <jra at samba.org>
Date:   Wed Jul 11 15:23:09 2018 -0700

    python: pysmbd: Additional error path leak fix.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=13474
    
    Signed-off-by: Jeremy Allison <jra at samba.org>

commit 425f513e98a9446e487dd5cd5d9de7ee58404bff
Author: Ralph Boehme <slow at samba.org>
Date:   Sat May 26 18:32:21 2018 +0200

    s3:smbd: don't allow renaming basefile if streams are open
    
    Bug: https://bugzilla.samba.org/show_bug.cgi?id=13451
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>
    (cherry picked from commit 465b7d07e5db787c3d6330371e5e42ecbb1b57b9)

commit dd78d9a602e2a088b3a3b7ce0f0a9520ce926268
Author: Ralph Boehme <slow at samba.org>
Date:   Sun May 27 13:03:25 2018 +0200

    s3:locking: add file_has_open_streams()
    
    This can be used to check if a file opened by fsp also has stream opens.
    
    Bug: https://bugzilla.samba.org/show_bug.cgi?id=13451
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>
    (cherry picked from commit dd8cf54c79fe8536e34cde15801d60931cd47b8b)

commit 85571d08b2683ee2c9bf8f2abc76af8bc6055a86
Author: Ralph Boehme <slow at samba.org>
Date:   Sun May 27 13:01:50 2018 +0200

    s3:smbd: add private option NTCREATEX_OPTIONS_PRIVATE_STREAM_BASEOPEN
    
    This will be used to mark basefile opens of streams opens. This is
    needed to later implement a function that can determine if a file has
    stream opens.
    
    Bug: https://bugzilla.samba.org/show_bug.cgi?id=13451
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>
    (cherry picked from commit 37e7ff05ab9443c0330e68f5c701ffecedf2d738)

commit 93ec87ec2ae750071f139728c44c951f86c9a728
Author: Ralph Boehme <slow at samba.org>
Date:   Sat May 26 18:33:00 2018 +0200

    s4:torture/vfs/fruit: adjust test testing basefile rename to expect failure
    
    Renaming a basefile that has open streams must fail with
    NT_STATUS_ACCESS_DENIED.
    
    Bug: https://bugzilla.samba.org/show_bug.cgi?id=13451
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>
    (cherry picked from commit f166207fc0344b51879d863857055ab7ff36a09b)

commit 36972fd61d4bf3e1b24575f8ec54610d32d815e1
Author: Ralph Boehme <slow at samba.org>
Date:   Sat May 26 16:07:14 2018 +0200

    s4:torture/smb2/streams: try to rename basefile while is has open streams
    
    This tests the following:
    
    - create a file with a stream
    - open the the stream and keep it open
    - on a second connection, try to rename the basefile, this should fail
      with NT_STATUS_ACCESS_DENIED
    
    Bug: https://bugzilla.samba.org/show_bug.cgi?id=13451
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>
    (cherry picked from commit 00d19bdab15102083b8ba395ede161824c898be1)

commit 00b001b0ce9b606eb4cc8f93747ee70fd0eccfa3
Author: Ralph Boehme <slow at samba.org>
Date:   Sat May 26 16:30:47 2018 +0200

    selftest: run smb2.streams tests against a share with vfs_streams_xattr
    
    The tests are currently only run against streams_depot, where stream IO
    is handle based, compared to streams_xattr which is path
    based. vfs_streams_xattr is also used much more in real world setups, so
    we should run our tests against it.
    
    Bug: https://bugzilla.samba.org/show_bug.cgi?id=13451
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>
    (backported from commit aa096ab70a466388a9947f73a525b2dcbb9821e5)

commit af4cb57d4f713990973f44678dc5e6d2f9cfa984
Author: Ralph Boehme <slow at samba.org>
Date:   Thu May 17 16:48:09 2018 +0200

    vfs_fruit: delete 0 byte size streams if AAPL is enabled
    
    macOS SMB server uses xattrs as storage backend for streams, directly
    exposing xattr get/set characteristics. Setting EOF on a stream to 0
    just deletes the xattr as macOS doesn't support 0-byte sized xattrs.
    
    Note that this does not apply to the AFP_AfpInfo and AFP_Resource
    streams, they have even stranger semantics and we have other tests
    for those.
    
    Bug: https://bugzilla.samba.org/show_bug.cgi?id=13441
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>
    
    Autobuild-User(master): Jeremy Allison <jra at samba.org>
    Autobuild-Date(master): Wed May 30 02:34:29 CEST 2018 on sn-devel-144
    
    (cherry picked from commit 46d127865f3fb14041797d395db3b3234ed3bd6c)

commit c88aa5fb76ae74aefa5ef7a06281f1120d19a8d5
Author: Ralph Boehme <slow at samba.org>
Date:   Thu May 17 16:43:49 2018 +0200

    s4:torture: test setting EOF of a stream to 0 with enabled AAPL extensions
    
    macOS SMB server uses xattrs as storage backend for streams, directly
    exposing xattr get/set characteristics. Setting EOF on a stream to 0
    just deletes the xattr as macOS doesn't support 0-byte sized xattrs.
    
    Note that this does not apply to the AFP_AfpInfo and AFP_Resource
    streams, they have even stranger semantics and we have other tests
    for those.
    
    Bug: https://bugzilla.samba.org/show_bug.cgi?id=13441
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>
    (cherry picked from commit cf5d471544f0cb0d072e4af1ee36798580d32897)

commit 2ea15c55816aa1964c44dcc57d5b363018316502
Author: Ralph Boehme <slow at samba.org>
Date:   Sat May 19 01:36:21 2018 +0200

    s4:torture/vfs/fruit: decrease large resource fork size in test from 1 GB to 64 MB
    
    64 MB is a more realistic value and lets the test pass on FreeBSD with
    fruit:resource=stream and vfs_streams_xattr.
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>
    (cherry picked from commit 2729b4329af0ad0b6a8bd188450b8abd76670d8a)

-----------------------------------------------------------------------

Summary of changes:
 lib/util/smb_threads.h         |   3 +
 selftest/knownfail             |   3 +
 source3/include/smb.h          |   3 +
 source3/libsmb/clireadwrite.c  |   2 +
 source3/libsmb/libsmb_file.c   |   2 +-
 source3/locking/locking.c      |  31 ++++++
 source3/locking/proto.h        |   1 +
 source3/modules/vfs_fruit.c    |   3 +
 source3/selftest/tests.py      |   4 +
 source3/smbd/durable.c         |  24 -----
 source3/smbd/open.c            |   7 +-
 source3/smbd/pysmbd.c          |   1 +
 source3/smbd/reply.c           |   4 +
 source4/torture/smb2/streams.c |  82 +++++++++++++++
 source4/torture/vfs/fruit.c    | 226 ++++++++++++++++++++++++++++++++++++-----
 15 files changed, 347 insertions(+), 49 deletions(-)


Changeset truncated at 500 lines:

diff --git a/lib/util/smb_threads.h b/lib/util/smb_threads.h
index 9a09616..67d05b8 100644
--- a/lib/util/smb_threads.h
+++ b/lib/util/smb_threads.h
@@ -119,6 +119,9 @@ static int smb_set_tls_pthread(void *pkey, const void *pval, const char *locatio
  \
 static void *smb_get_tls_pthread(void *pkey, const char *location) \
 { \
+	if (pkey == NULL) { \
+		return NULL; \
+	} \
         return pthread_getspecific(*(pthread_key_t *)pkey); \
 } \
  \
diff --git a/selftest/knownfail b/selftest/knownfail
index eaddaec..ba16fd7 100644
--- a/selftest/knownfail
+++ b/selftest/knownfail
@@ -177,6 +177,9 @@
 ^samba3.smb2.streams.rename
 ^samba3.smb2.streams.rename2
 ^samba3.smb2.streams.attributes
+^samba3.smb2.streams streams_xattr.rename\(nt4_dc\)
+^samba3.smb2.streams streams_xattr.rename2\(nt4_dc\)
+^samba3.smb2.streams streams_xattr.attributes\(nt4_dc\)
 ^samba3.smb2.getinfo.complex
 ^samba3.smb2.getinfo.fsinfo # quotas don't work yet
 ^samba3.smb2.setinfo.setinfo
diff --git a/source3/include/smb.h b/source3/include/smb.h
index 3316f09..5e83ee9 100644
--- a/source3/include/smb.h
+++ b/source3/include/smb.h
@@ -419,6 +419,9 @@ Offset  Data			length.
 /* Private options for printer support */
 #define NTCREATEX_OPTIONS_PRIVATE_DELETE_ON_CLOSE 0x0008
 
+/* Private option for streams support */
+#define NTCREATEX_OPTIONS_PRIVATE_STREAM_BASEOPEN 0x0010
+
 /* Flag for NT transact rename call. */
 #define RENAME_REPLACE_IF_EXISTS 1
 
diff --git a/source3/libsmb/clireadwrite.c b/source3/libsmb/clireadwrite.c
index 3987477..00ee09e 100644
--- a/source3/libsmb/clireadwrite.c
+++ b/source3/libsmb/clireadwrite.c
@@ -1459,6 +1459,7 @@ static NTSTATUS cli_splice_fallback(TALLOC_CTX *frame,
 	uint8_t *buf = talloc_size(frame, SPLICE_BLOCK_SIZE);
 	size_t nread;
 	off_t remaining = initial_size;
+	*written = 0;
 
 	while (remaining) {
 		status = cli_read(srccli, src_fnum,
@@ -1480,6 +1481,7 @@ static NTSTATUS cli_splice_fallback(TALLOC_CTX *frame,
 		}
 		src_offset += nread;
 		dst_offset += nread;
+		*written += nread;
 		if (remaining < nread) {
 			return NT_STATUS_INTERNAL_ERROR;
 		}
diff --git a/source3/libsmb/libsmb_file.c b/source3/libsmb/libsmb_file.c
index 6b43676..ebd0bfe 100644
--- a/source3/libsmb/libsmb_file.c
+++ b/source3/libsmb/libsmb_file.c
@@ -298,7 +298,7 @@ SMBC_splice_ctx(SMBCCTX *context,
                 int (*splice_cb)(off_t n, void *priv),
                 void *priv)
 {
-	off_t written;
+	off_t written = 0;
 	TALLOC_CTX *frame = talloc_stackframe();
 	NTSTATUS status;
 
diff --git a/source3/locking/locking.c b/source3/locking/locking.c
index 4e9f1bb..f71cd17 100644
--- a/source3/locking/locking.c
+++ b/source3/locking/locking.c
@@ -1318,3 +1318,34 @@ struct timespec get_share_mode_write_time(struct share_mode_lock *lck)
 	}
 	return d->old_write_time;
 }
+
+bool file_has_open_streams(files_struct *fsp)
+{
+	struct share_mode_lock *lock = NULL;
+	struct share_mode_data *d = NULL;
+	uint32_t i;
+
+	lock = get_existing_share_mode_lock(talloc_tos(), fsp->file_id);
+	if (lock == NULL) {
+		return false;
+	}
+	d = lock->data;
+
+	for (i = 0; i < d->num_share_modes; i++) {
+		struct share_mode_entry *e = &d->share_modes[i];
+
+		if (share_mode_stale_pid(d, i)) {
+			continue;
+		}
+
+		if (e->private_options &
+		    NTCREATEX_OPTIONS_PRIVATE_STREAM_BASEOPEN)
+		{
+			TALLOC_FREE(lock);
+			return true;
+		}
+	}
+
+	TALLOC_FREE(lock);
+	return false;
+}
diff --git a/source3/locking/proto.h b/source3/locking/proto.h
index 33184e0..4cd3809 100644
--- a/source3/locking/proto.h
+++ b/source3/locking/proto.h
@@ -205,6 +205,7 @@ bool is_delete_on_close_set(struct share_mode_lock *lck, uint32_t name_hash);
 bool set_sticky_write_time(struct file_id fileid, struct timespec write_time);
 bool set_write_time(struct file_id fileid, struct timespec write_time);
 struct timespec get_share_mode_write_time(struct share_mode_lock *lck);
+bool file_has_open_streams(files_struct *fsp);
 int share_mode_forall(int (*fn)(struct file_id fid,
 				const struct share_mode_data *data,
 				void *private_data),
diff --git a/source3/modules/vfs_fruit.c b/source3/modules/vfs_fruit.c
index 1a05d0b..013dec0 100644
--- a/source3/modules/vfs_fruit.c
+++ b/source3/modules/vfs_fruit.c
@@ -5537,6 +5537,9 @@ static int fruit_ftruncate(struct vfs_handle_struct *handle,
 		  (intmax_t)offset);
 
 	if (fio == NULL) {
+		if (offset == 0 && global_fruit_config.nego_aapl) {
+			return SMB_VFS_NEXT_UNLINK(handle, fsp->fsp_name);
+		}
 		return SMB_VFS_NEXT_FTRUNCATE(handle, fsp, offset);
 	}
 
diff --git a/source3/selftest/tests.py b/source3/selftest/tests.py
index f43d2b1..9092c17 100755
--- a/source3/selftest/tests.py
+++ b/source3/selftest/tests.py
@@ -559,6 +559,10 @@ 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 == "smb2.streams":
+        plansmbtorture4testsuite(t, "nt4_dc", '//$SERVER_IP/tmp -U$USERNAME%$PASSWORD')
+        plansmbtorture4testsuite(t, "ad_dc", '//$SERVER/tmp -U$USERNAME%$PASSWORD')
+        plansmbtorture4testsuite(t, "nt4_dc", '//$SERVER_IP/streams_xattr -U$USERNAME%$PASSWORD', 'streams_xattr')
     else:
         plansmbtorture4testsuite(t, "nt4_dc", '//$SERVER_IP/tmp -U$USERNAME%$PASSWORD')
         plansmbtorture4testsuite(t, "ad_dc", '//$SERVER/tmp -U$USERNAME%$PASSWORD')
diff --git a/source3/smbd/durable.c b/source3/smbd/durable.c
index 602a96e..2a5ddc0 100644
--- a/source3/smbd/durable.c
+++ b/source3/smbd/durable.c
@@ -305,30 +305,6 @@ static bool vfs_default_durable_reconnect_check_stat(
 {
 	int ret;
 
-	if (cookie_st->st_ex_dev != fsp_st->st_ex_dev) {
-		DEBUG(1, ("vfs_default_durable_reconnect (%s): "
-			  "stat_ex.%s differs: "
-			  "cookie:%llu != stat:%llu, "
-			  "denying durable reconnect\n",
-			  name,
-			  "st_ex_dev",
-			  (unsigned long long)cookie_st->st_ex_dev,
-			  (unsigned long long)fsp_st->st_ex_dev));
-		return false;
-	}
-
-	if (cookie_st->st_ex_ino != fsp_st->st_ex_ino) {
-		DEBUG(1, ("vfs_default_durable_reconnect (%s): "
-			  "stat_ex.%s differs: "
-			  "cookie:%llu != stat:%llu, "
-			  "denying durable reconnect\n",
-			  name,
-			  "st_ex_ino",
-			  (unsigned long long)cookie_st->st_ex_ino,
-			  (unsigned long long)fsp_st->st_ex_ino));
-		return false;
-	}
-
 	if (cookie_st->st_ex_mode != fsp_st->st_ex_mode) {
 		DEBUG(1, ("vfs_default_durable_reconnect (%s): "
 			  "stat_ex.%s differs: "
diff --git a/source3/smbd/open.c b/source3/smbd/open.c
index 3708bdd..8a9288d 100644
--- a/source3/smbd/open.c
+++ b/source3/smbd/open.c
@@ -5091,6 +5091,7 @@ static NTSTATUS create_file_unixpath(connection_struct *conn,
 	    && (!(private_flags & NTCREATEX_OPTIONS_PRIVATE_STREAM_DELETE))) {
 		uint32_t base_create_disposition;
 		struct smb_filename *smb_fname_base = NULL;
+		uint32_t base_privflags;
 
 		if (create_options & FILE_DIRECTORY_FILE) {
 			status = NT_STATUS_NOT_A_DIRECTORY;
@@ -5141,13 +5142,17 @@ static NTSTATUS create_file_unixpath(connection_struct *conn,
 			}
 		}
 
+		base_privflags = NTCREATEX_OPTIONS_PRIVATE_STREAM_BASEOPEN;
+
 		/* Open the base file. */
 		status = create_file_unixpath(conn, NULL, smb_fname_base, 0,
 					      FILE_SHARE_READ
 					      | FILE_SHARE_WRITE
 					      | FILE_SHARE_DELETE,
 					      base_create_disposition,
-					      0, 0, 0, NULL, 0, 0, NULL, NULL,
+					      0, 0, 0, NULL, 0,
+					      base_privflags,
+					      NULL, NULL,
 					      &base_fsp, NULL);
 		TALLOC_FREE(smb_fname_base);
 
diff --git a/source3/smbd/pysmbd.c b/source3/smbd/pysmbd.c
index 41b44ad..f1b46be 100644
--- a/source3/smbd/pysmbd.c
+++ b/source3/smbd/pysmbd.c
@@ -396,6 +396,7 @@ static PyObject *py_smbd_set_simple_acl(PyObject *self, PyObject *args, PyObject
 
 	conn = get_conn(frame, service);
 	if (!conn) {
+		TALLOC_FREE(frame);
 		return NULL;
 	}
 
diff --git a/source3/smbd/reply.c b/source3/smbd/reply.c
index 623f83b..2b5bb8f 100644
--- a/source3/smbd/reply.c
+++ b/source3/smbd/reply.c
@@ -6642,6 +6642,10 @@ NTSTATUS rename_internals_fsp(connection_struct *conn,
 		return status;
 	}
 
+	if (file_has_open_streams(fsp)) {
+		return NT_STATUS_ACCESS_DENIED;
+	}
+
 	/* Make a copy of the dst smb_fname structs */
 
 	smb_fname_dst = cp_smb_filename(ctx, smb_fname_dst_in);
diff --git a/source4/torture/smb2/streams.c b/source4/torture/smb2/streams.c
index d302bf9..b39d96d 100644
--- a/source4/torture/smb2/streams.c
+++ b/source4/torture/smb2/streams.c
@@ -1830,6 +1830,86 @@ done:
 	return ret;
 }
 
+static bool test_basefile_rename_with_open_stream(struct torture_context *tctx,
+						  struct smb2_tree *tree)
+{
+	bool ret = true;
+	NTSTATUS status;
+	struct smb2_tree *tree2 = NULL;
+	struct smb2_create create, create2;
+	struct smb2_handle h1 = {{0}}, h2 = {{0}};
+	const char *fname = "test_rename_openfile";
+	const char *sname = "test_rename_openfile:foo";
+	const char *fname_renamed = "test_rename_openfile_renamed";
+	union smb_setfileinfo sinfo;
+	const char *data = "test data";
+
+	ret = torture_smb2_connection(tctx, &tree2);
+	torture_assert_goto(tctx, ret == true, ret, done,
+			    "torture_smb2_connection failed\n");
+
+	torture_comment(tctx, "Creating file with stream\n");
+
+	ZERO_STRUCT(create);
+	create.in.desired_access = SEC_FILE_ALL;
+	create.in.share_access = NTCREATEX_SHARE_ACCESS_MASK;
+	create.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
+	create.in.create_disposition = NTCREATEX_DISP_OPEN_IF;
+	create.in.impersonation_level = SMB2_IMPERSONATION_IMPERSONATION;
+	create.in.fname = sname;
+
+	status = smb2_create(tree, tctx, &create);
+	torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
+					"smb2_create failed\n");
+
+	h1 = create.out.file.handle;
+
+	torture_comment(tctx, "Writing to stream\n");
+
+	status = smb2_util_write(tree, h1, data, 0, strlen(data));
+	torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
+					"smb2_util_write failed\n");
+
+	torture_comment(tctx, "Renaming base file\n");
+
+	ZERO_STRUCT(create2);
+	create2.in.desired_access = SEC_FILE_ALL;
+	create2.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
+	create2.in.share_access = NTCREATEX_SHARE_ACCESS_MASK;
+	create2.in.create_disposition = NTCREATEX_DISP_OPEN;
+	create2.in.impersonation_level = SMB2_IMPERSONATION_IMPERSONATION;
+	create2.in.fname = fname;
+
+	status = smb2_create(tree2, tctx, &create2);
+	torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
+					"smb2_create failed\n");
+
+	h2 = create2.out.file.handle;
+
+	ZERO_STRUCT(sinfo);
+	sinfo.rename_information.level = RAW_SFILEINFO_RENAME_INFORMATION;
+	sinfo.rename_information.in.file.handle = h2;
+	sinfo.rename_information.in.new_name = fname_renamed;
+
+	status = smb2_setinfo_file(tree2, &sinfo);
+	torture_assert_ntstatus_equal_goto(
+		tctx, status, NT_STATUS_ACCESS_DENIED, ret, done,
+		"smb2_setinfo_file didn't return NT_STATUS_ACCESS_DENIED\n");
+
+	smb2_util_close(tree2, h2);
+
+done:
+	if (!smb2_util_handle_empty(h1)) {
+		smb2_util_close(tree, h1);
+	}
+	if (!smb2_util_handle_empty(h2)) {
+		smb2_util_close(tree2, h2);
+	}
+	smb2_util_unlink(tree, fname);
+	smb2_util_unlink(tree, fname_renamed);
+
+	return ret;
+}
 
 /*
    basic testing of streams calls SMB2
@@ -1850,6 +1930,8 @@ struct torture_suite *torture_smb2_streams_init(TALLOC_CTX *ctx)
 	torture_suite_add_1smb2_test(suite, "attributes", test_stream_attributes);
 	torture_suite_add_1smb2_test(suite, "delete", test_stream_delete);
 	torture_suite_add_1smb2_test(suite, "zero-byte", test_zero_byte_stream);
+	torture_suite_add_1smb2_test(suite, "basefile-rename-with-open-stream",
+					test_basefile_rename_with_open_stream);
 
 	suite->description = talloc_strdup(suite, "SMB2-STREAM tests");
 
diff --git a/source4/torture/vfs/fruit.c b/source4/torture/vfs/fruit.c
index 65109cc..1202adb 100644
--- a/source4/torture/vfs/fruit.c
+++ b/source4/torture/vfs/fruit.c
@@ -1594,11 +1594,11 @@ static bool test_write_atalk_rfork_io(struct torture_context *tctx,
 
 	ret &= write_stream(tree, __location__, tctx, mem_ctx,
 			    fname, AFPRESOURCE_STREAM_NAME,
-			    (off_t)1<<32, 10, rfork_content);
+			    (off_t)64*1024*1024, 10, rfork_content);
 
 	ret &= check_stream(tree, __location__, tctx, mem_ctx,
 			    fname, AFPRESOURCE_STREAM_NAME,
-			    (off_t)1<<32, 10, 0, 10, rfork_content);
+			    (off_t)64*1024*1024, 10, 0, 10, rfork_content);
 
 	/* Truncate back to size of 1 byte */
 
@@ -3897,7 +3897,6 @@ static bool test_rename_and_read_rsrc(struct torture_context *tctx,
 	const char *fname_renamed = "test_rename_openfile_renamed";
 	const char *data = "1234567890";
 	union smb_setfileinfo sinfo;
-	struct smb2_read r;
 
 	ret = enable_aapl(tctx, tree);
 	torture_assert_goto(tctx, ret == true, ret, done, "enable_aapl failed");
@@ -3949,28 +3948,12 @@ static bool test_rename_and_read_rsrc(struct torture_context *tctx,
 	sinfo.rename_information.in.new_name = fname_renamed;
 
 	status = smb2_setinfo_file(tree, &sinfo);
-	torture_assert_ntstatus_ok_goto(tctx, status, ret, done, "smb2_setinfo_file failed");
-
-	smb2_util_close(tree, h2);
-
-	ZERO_STRUCT(r);
-	r.in.file.handle = h1;
-	r.in.length      = 10;
-	r.in.offset      = 0;
-
-	torture_comment(tctx, "Read resource fork of renamed file\n");
-
-	status = smb2_read(tree, tree, &r);
-	torture_assert_ntstatus_ok_goto(tctx, status, ret, done, "smb2_read failed");
+	torture_assert_ntstatus_equal_goto(
+		tctx, status, NT_STATUS_ACCESS_DENIED, ret, done,
+		"smb2_setinfo_file failed");
 
 	smb2_util_close(tree, h1);
-
-	torture_assert_goto(tctx, r.out.data.length == 10, ret, done,
-			    talloc_asprintf(tctx, "smb2_read returned %jd bytes, expected 10\n",
-					    (intmax_t)r.out.data.length));
-
-	torture_assert_goto(tctx, memcmp(r.out.data.data, data, 10) == 0, ret, done,
-			    talloc_asprintf(tctx, "Bad data in stream\n"));
+	smb2_util_close(tree, h2);
 
 done:
 	smb2_util_unlink(tree, fname);
@@ -4595,6 +4578,202 @@ done:
 	return ret;
 }
 
+static bool test_setinfo_stream_eof(struct torture_context *tctx,
+				    struct smb2_tree *tree)
+{
+	bool ret = true;
+	NTSTATUS status;
+	struct smb2_create create;
+	union smb_setfileinfo sfinfo;
+	union smb_fileinfo finfo;
+	struct smb2_handle h1;
+	TALLOC_CTX *mem_ctx = talloc_new(tctx);
+	const char *fname = BASEDIR "\\file";
+	const char *sname = BASEDIR "\\file:foo";
+
+	torture_assert_goto(tctx, mem_ctx != NULL, ret, done,
+			    "talloc_new failed\n");
+
+	torture_comment(tctx, "Test setting EOF on a stream\n");
+
+	smb2_deltree(tree, BASEDIR);
+	status = torture_smb2_testdir(tree, BASEDIR, &h1);
+	torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
+					"torture_smb2_testdir\n");
+	smb2_util_close(tree, h1);
+
+	status = torture_smb2_testfile(tree, fname, &h1);
+	torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
+					"torture_smb2_testfile failed\n");
+	smb2_util_close(tree, h1);
+
+	status = torture_smb2_testfile_access(tree, sname, &h1,
+					      SEC_FILE_WRITE_DATA);
+	torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
+					"torture_smb2_testfile failed\n");
+
+	status = smb2_util_write(tree, h1, "1234567890", 0, 10);
+	torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
+					"smb2_util_write failed\n");
+	smb2_util_close(tree, h1);
+
+	/*
+	 * Test setting EOF to 21
+	 */
+
+	torture_comment(tctx, "Setting stream EOF to 21\n");
+
+	status = torture_smb2_testfile_access(tree, sname, &h1,
+					      SEC_FILE_WRITE_DATA);
+	torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
+					"torture_smb2_testfile failed\n");
+
+	ZERO_STRUCT(sfinfo);
+	sfinfo.generic.in.file.handle = h1;
+	sfinfo.generic.level = RAW_SFILEINFO_END_OF_FILE_INFORMATION;
+	sfinfo.position_information.in.position = 21;
+	status = smb2_setinfo_file(tree, &sfinfo);
+	torture_assert_ntstatus_ok_goto(tctx, status,
+					ret, done, "set EOF 21 failed\n");
+
+	smb2_util_close(tree, h1);
+
+	status = torture_smb2_testfile_access(tree, sname, &h1,
+					      SEC_FILE_WRITE_DATA);
+	torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
+					"torture_smb2_testfile failed\n");
+
+	ZERO_STRUCT(finfo);
+	finfo.generic.level = RAW_FILEINFO_STANDARD_INFORMATION;
+	finfo.generic.in.file.handle = h1;
+	status = smb2_getinfo_file(tree, mem_ctx, &finfo);
+	torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
+					"smb2_getinfo_file failed");
+
+	smb2_util_close(tree, h1);
+
+	torture_assert_goto(tctx, finfo.standard_info.out.size == 21,
+			    ret, done, "size != 21\n");
+
+	/*
+	 * Test setting EOF to 0
+	 */
+
+	torture_comment(tctx, "Setting stream EOF to 0\n");
+
+	status = torture_smb2_testfile_access(tree, sname, &h1,
+					      SEC_FILE_WRITE_DATA);
+	torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
+					"torture_smb2_testfile failed\n");
+
+	ZERO_STRUCT(sfinfo);


-- 
Samba Shared Repository



More information about the samba-cvs mailing list