[SCM] Samba Shared Repository - branch master updated

Jeremy Allison jra at samba.org
Thu Mar 24 17:22:02 UTC 2022


The branch, master has been updated
       via  c4f9c372405 s3: smbd: smbd_smb2_setinfo_send(). All calls to SMB_VFS_FSTAT(fsp, &fsp->fsp_name->st) clobber fsp->fsp_name->st.st_ex_iflags.
       via  7fb2038faca s3: smbd: smbd_smb2_getinfo_send(). All calls to SMB_VFS_FSTAT(fsp, &fsp->fsp_name->st) clobber fsp->fsp_name->st.st_ex_iflags.
       via  23d5c909286 s3: cmd_vfs: cmd_set_nt_acl(). All calls to SMB_VFS_FSTAT(fsp, &fsp->fsp_name->st) clobber fsp->fsp_name->st.st_ex_iflags.
       via  fbc6cdfbeda s3: cmd_vfs: cmd_open(). All calls to SMB_VFS_FSTAT(fsp, &fsp->fsp_name->st) clobber fsp->fsp_name->st.st_ex_iflags.
       via  c4193f11d18 s3: pysmbd.c: init_files_struct(). All calls to SMB_VFS_FSTAT(fsp, &fsp->fsp_name->st) clobber fsp->fsp_name->st.st_ex_iflags.
       via  6a25b6997ff s3: smbd: call_trans2setfilepathinfo(). All calls to SMB_VFS_FSTAT(fsp, &fsp->fsp_name->st) clobber fsp->fsp_name->st.st_ex_iflags.
       via  8d3812daa5b s3: smbd: call_trans2qfilepathinfo(). All calls to SMB_VFS_FSTAT(fsp, &fsp->fsp_name->st) clobber fsp->fsp_name->st.st_ex_iflags.
       via  b53a69f4ffc s3: smbd: rename_internals_fsp(). All calls to SMB_VFS_FSTAT(fsp, &fsp->fsp_name->st) clobber fsp->fsp_name->st.st_ex_iflags.
       via  7f5c484804c s3: smbd: mkdir_internal(). 2 of 2. All calls to SMB_VFS_FSTAT(fsp, &fsp->fsp_name->st) clobber fsp->fsp_name->st.st_ex_iflags.
       via  064c5770deb s3: smbd: mkdir_internal(). 1 of 2. All calls to SMB_VFS_FSTAT(fsp, &fsp->fsp_name->st) clobber fsp->fsp_name->st.st_ex_iflags.
       via  cfadecca802 s3: smbd: open_file(). All calls to SMB_VFS_FSTAT(fsp, &fsp->fsp_name->st) clobber fsp->fsp_name->st.st_ex_iflags.
       via  18694c81cc3 s3: smbd: non_widelink_open(). All calls to SMB_VFS_FSTAT(fsp, &fsp->fsp_name->st) clobber fsp->fsp_name->st.st_ex_iflags.
       via  a604dd02ffb s3: smbd: open_internal_dirfsp(). All calls to SMB_VFS_FSTAT(fsp, &fsp->fsp_name->st) clobber fsp->fsp_name->st.st_ex_iflags.
       via  ec2fb9d2284 s3: smbd: open_internal_dirfsp() add missing file_free() in error path.
       via  2b246dbf687 s3: smbd: mdssvc: All calls to SMB_VFS_FSTAT(fsp, &fsp->fsp_name->st) clobber fsp->fsp_name->st.st_ex_iflags.
       via  d460118be3a s3: VFS: vxfs: All calls to SMB_VFS_FSTAT(fsp, &fsp->fsp_name->st) clobber fsp->fsp_name->st.st_ex_iflags.
       via  2fc0820afcd s3: smbd: In set_ea_dos_attribute(), if we've stored btime and set XATTR_DOSINFO_CREATE_TIME successfully, we need to clear ST_EX_IFLAG_CALCULATED_BTIME.
       via  9f62a149f12 s3: smbd: In set_ea_dos_attribute() cause root fallback code to exit via the same place.
       via  0036617a5c7 s4: torture: Add regression test for re-opening a durable handle after calling SMB2 setinfo (end of file).
      from  d1d65d271ec s4:kdc: Expose samba_kdc_message2entry_keys()

https://git.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit c4f9c372405bea8a7d9c6b39e04cebefa3322a19
Author: Jeremy Allison <jra at samba.org>
Date:   Fri Mar 18 12:30:27 2022 -0700

    s3: smbd: smbd_smb2_setinfo_send(). All calls to SMB_VFS_FSTAT(fsp, &fsp->fsp_name->st) clobber fsp->fsp_name->st.st_ex_iflags.
    
    If doing an SMB_VFS_FSTAT() returning onto the stat struct stored in the fsp,
    we must call vfs_stat_fsp() as this preserves the iflags.
    
    This is the last SMB_VFS_FSTAT that uses fsp->fsp_name->st, so
    remove knownfail.d/durable-v2-setinfo
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15022
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>
    
    Autobuild-User(master): Jeremy Allison <jra at samba.org>
    Autobuild-Date(master): Thu Mar 24 17:21:29 UTC 2022 on sn-devel-184

commit 7fb2038faca256c03c2bd7d982f39f5b1a57f784
Author: Jeremy Allison <jra at samba.org>
Date:   Fri Mar 18 11:45:50 2022 -0700

    s3: smbd: smbd_smb2_getinfo_send(). All calls to SMB_VFS_FSTAT(fsp, &fsp->fsp_name->st) clobber fsp->fsp_name->st.st_ex_iflags.
    
    If doing an SMB_VFS_FSTAT() returning onto the stat struct stored in the fsp,
    we must call vfs_stat_fsp() as this preserves the iflags.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15022
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit 23d5c909286d438534f1a7defb2faacd1877fea1
Author: Jeremy Allison <jra at samba.org>
Date:   Fri Mar 18 15:04:34 2022 -0700

    s3: cmd_vfs: cmd_set_nt_acl(). All calls to SMB_VFS_FSTAT(fsp, &fsp->fsp_name->st) clobber fsp->fsp_name->st.st_ex_iflags.
    
    If doing an SMB_VFS_FSTAT() returning onto the stat struct stored in the fsp,
    we must call vfs_stat_fsp() as this preserves the iflags.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15022
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit fbc6cdfbeda4086851dfb0f91fd23b4fd541e174
Author: Jeremy Allison <jra at samba.org>
Date:   Fri Mar 18 15:01:52 2022 -0700

    s3: cmd_vfs: cmd_open(). All calls to SMB_VFS_FSTAT(fsp, &fsp->fsp_name->st) clobber fsp->fsp_name->st.st_ex_iflags.
    
    If doing an SMB_VFS_FSTAT() returning onto the stat struct stored in the fsp,
    we must call vfs_stat_fsp() as this preserves the iflags.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15022
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit c4193f11d1871051d4cce4521b1f444a083c9189
Author: Jeremy Allison <jra at samba.org>
Date:   Fri Mar 18 14:57:13 2022 -0700

    s3: pysmbd.c: init_files_struct(). All calls to SMB_VFS_FSTAT(fsp, &fsp->fsp_name->st) clobber fsp->fsp_name->st.st_ex_iflags.
    
    If doing an SMB_VFS_FSTAT() returning onto the stat struct stored in the fsp,
    we must call vfs_stat_fsp() as this preserves the iflags.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15022
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit 6a25b6997ff9f99fde309db1e163d16cd70ca5f5
Author: Jeremy Allison <jra at samba.org>
Date:   Fri Mar 18 12:27:53 2022 -0700

    s3: smbd: call_trans2setfilepathinfo(). All calls to SMB_VFS_FSTAT(fsp, &fsp->fsp_name->st) clobber fsp->fsp_name->st.st_ex_iflags.
    
    If doing an SMB_VFS_FSTAT() returning onto the stat struct stored in the fsp,
    we must call vfs_stat_fsp() as this preserves the iflags.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15022
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit 8d3812daa5b0c9eb534515d37498d0d6e1a40ec8
Author: Jeremy Allison <jra at samba.org>
Date:   Fri Mar 18 12:26:27 2022 -0700

    s3: smbd: call_trans2qfilepathinfo(). All calls to SMB_VFS_FSTAT(fsp, &fsp->fsp_name->st) clobber fsp->fsp_name->st.st_ex_iflags.
    
    If doing an SMB_VFS_FSTAT() returning onto the stat struct stored in the fsp,
    we must call vfs_stat_fsp() as this preserves the iflags.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15022
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit b53a69f4ffcaa5ec9b8660152802f5a7b2effc1f
Author: Jeremy Allison <jra at samba.org>
Date:   Fri Mar 18 12:24:27 2022 -0700

    s3: smbd: rename_internals_fsp(). All calls to SMB_VFS_FSTAT(fsp, &fsp->fsp_name->st) clobber fsp->fsp_name->st.st_ex_iflags.
    
    If doing an SMB_VFS_FSTAT() returning onto the stat struct stored in the fsp,
    we must call vfs_stat_fsp() as this preserves the iflags.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15022
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit 7f5c484804c87f37493e1f79d5c7e1738a4e0113
Author: Jeremy Allison <jra at samba.org>
Date:   Fri Mar 18 12:22:26 2022 -0700

    s3: smbd: mkdir_internal(). 2 of 2. All calls to SMB_VFS_FSTAT(fsp, &fsp->fsp_name->st) clobber fsp->fsp_name->st.st_ex_iflags.
    
    If doing an SMB_VFS_FSTAT() returning onto the stat struct stored in the fsp,
    we must call vfs_stat_fsp() as this preserves the iflags.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15022
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit 064c5770deb4307272c60f0b08f6bc137df4b227
Author: Jeremy Allison <jra at samba.org>
Date:   Fri Mar 18 12:19:44 2022 -0700

    s3: smbd: mkdir_internal(). 1 of 2. All calls to SMB_VFS_FSTAT(fsp, &fsp->fsp_name->st) clobber fsp->fsp_name->st.st_ex_iflags.
    
    If doing an SMB_VFS_FSTAT() returning onto the stat struct stored in the fsp,
    we must call vfs_stat_fsp() as this preserves the iflags.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15022
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit cfadecca802600fa9a01fa9781e4df9a0b71fa3c
Author: Jeremy Allison <jra at samba.org>
Date:   Fri Mar 18 12:11:23 2022 -0700

    s3: smbd: open_file(). All calls to SMB_VFS_FSTAT(fsp, &fsp->fsp_name->st) clobber fsp->fsp_name->st.st_ex_iflags.
    
    If doing an SMB_VFS_FSTAT() returning onto the stat struct stored in the fsp,
    we must call vfs_stat_fsp() as this preserves the iflags.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15022
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit 18694c81cc3c3d94dc99e3b11878021052279eb6
Author: Jeremy Allison <jra at samba.org>
Date:   Fri Mar 18 12:09:43 2022 -0700

    s3: smbd: non_widelink_open(). All calls to SMB_VFS_FSTAT(fsp, &fsp->fsp_name->st) clobber fsp->fsp_name->st.st_ex_iflags.
    
    If doing an SMB_VFS_FSTAT() returning onto the stat struct stored in the fsp,
    we must call vfs_stat_fsp() as this preserves the iflags.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15022
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit a604dd02ffb468ba472ac4dd64f06d30ecdcc810
Author: Jeremy Allison <jra at samba.org>
Date:   Fri Mar 18 12:02:35 2022 -0700

    s3: smbd: open_internal_dirfsp(). All calls to SMB_VFS_FSTAT(fsp, &fsp->fsp_name->st) clobber fsp->fsp_name->st.st_ex_iflags.
    
    If doing an SMB_VFS_FSTAT() returning onto the stat struct stored in the fsp,
    we must call vfs_stat_fsp() as this preserves the iflags.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15022
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit ec2fb9d22842332992b8f667a8218f7aaa1be7c4
Author: Jeremy Allison <jra at samba.org>
Date:   Fri Mar 18 12:00:15 2022 -0700

    s3: smbd: open_internal_dirfsp() add missing file_free() in error path.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15022
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit 2b246dbf687cbb6ef1e31e22fd64a95bdca8f4e9
Author: Jeremy Allison <jra at samba.org>
Date:   Fri Mar 18 11:56:53 2022 -0700

    s3: smbd: mdssvc: All calls to SMB_VFS_FSTAT(fsp, &fsp->fsp_name->st) clobber fsp->fsp_name->st.st_ex_iflags.
    
    If doing an SMB_VFS_FSTAT() returning onto the stat struct stored in the fsp,
    we must call vfs_stat_fsp() as this preserves the iflags.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15022
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit d460118be3ad2a3100bb3458f6f0223df12f7c3f
Author: Jeremy Allison <jra at samba.org>
Date:   Fri Mar 18 11:51:00 2022 -0700

    s3: VFS: vxfs: All calls to SMB_VFS_FSTAT(fsp, &fsp->fsp_name->st) clobber fsp->fsp_name->st.st_ex_iflags.
    
    If doing an SMB_VFS_FSTAT() returning onto the stat struct stored in the fsp,
    we must call vfs_stat_fsp() as this preserves the iflags.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15022
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit 2fc0820afcd375594b1d99edcd651420bea6ac91
Author: Jeremy Allison <jra at samba.org>
Date:   Fri Mar 18 11:41:48 2022 -0700

    s3: smbd: In set_ea_dos_attribute(), if we've stored btime and set XATTR_DOSINFO_CREATE_TIME successfully, we need to clear ST_EX_IFLAG_CALCULATED_BTIME.
    
    This is no longer a calculated field, every call to fdos_mode() will
    set it as non-calculated.
    
    https://bugzilla.samba.org/show_bug.cgi?id=15022
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit 9f62a149f12e899dbc2a7bac9458e7a375bf6608
Author: Jeremy Allison <jra at samba.org>
Date:   Fri Mar 18 11:40:04 2022 -0700

    s3: smbd: In set_ea_dos_attribute() cause root fallback code to exit via the same place.
    
    We're going to add another action on success next.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15022
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit 0036617a5c76e6003e3c9a5039c325d77d897709
Author: Jeremy Allison <jra at samba.org>
Date:   Fri Mar 18 14:52:02 2022 -0700

    s4: torture: Add regression test for re-opening a durable handle after calling SMB2 setinfo (end of file).
    
    This is an implementation of a test written by Apple for their
    client. Currently fails to reconnect due to btime being overwritten
    incorrectly in the SMB2 setinfo path.
    
    Add knownfail.d/durable-v2-setinfo
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15022
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

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

Summary of changes:
 source3/modules/vfs_vxfs.c             |   6 +-
 source3/rpc_server/mdssvc/mdssvc.c     |   6 +-
 source3/smbd/dosmode.c                 |  15 +++-
 source3/smbd/files.c                   |   8 +-
 source3/smbd/open.c                    |  24 +++---
 source3/smbd/pysmbd.c                  |   9 +--
 source3/smbd/reply.c                   |   4 +-
 source3/smbd/smb2_getinfo.c            |   6 +-
 source3/smbd/smb2_setinfo.c            |   6 +-
 source3/smbd/trans2.c                  |  15 ++--
 source3/torture/cmd_vfs.c              |  21 ++---
 source4/torture/smb2/durable_v2_open.c | 140 +++++++++++++++++++++++++++++++++
 12 files changed, 203 insertions(+), 57 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source3/modules/vfs_vxfs.c b/source3/modules/vfs_vxfs.c
index 75945cc476c..ddd34ba812a 100644
--- a/source3/modules/vfs_vxfs.c
+++ b/source3/modules/vfs_vxfs.c
@@ -407,6 +407,7 @@ static bool vxfs_compare(struct files_struct *fsp,
 	TALLOC_CTX *mem_ctx = talloc_tos();
 	char *existing_buf = NULL, *new_buf = NULL, *compact_buf = NULL;
 	int status;
+	NTSTATUS ntstatus;
 
 	DEBUG(10, ("vfs_vxfs: Getting existing ACL for %s\n", fsp_str_dbg(fsp)));
 
@@ -424,9 +425,10 @@ static bool vxfs_compare(struct files_struct *fsp,
 		goto out;
 	}
 
-	status = SMB_VFS_FSTAT(fsp, &fsp->fsp_name->st);
-	if (status == -1) {
+	ntstatus = vfs_stat_fsp(fsp);
+	if (!NT_STATUS_IS_OK(ntstatus)) {
 		DEBUG(10, ("vfs_vxfs: stat failed!\n"));
+		errno = map_errno_from_nt_status(ntstatus);
 		goto out;
 	}
 
diff --git a/source3/rpc_server/mdssvc/mdssvc.c b/source3/rpc_server/mdssvc/mdssvc.c
index fa31b55a183..956e097eaf4 100644
--- a/source3/rpc_server/mdssvc/mdssvc.c
+++ b/source3/rpc_server/mdssvc/mdssvc.c
@@ -1354,13 +1354,13 @@ static bool slrpc_fetch_attributes(struct mds_ctx *mds_ctx,
 			return true;
 		}
 
-		result = SMB_VFS_FSTAT(smb_fname->fsp, &smb_fname->st);
-		if (result != 0) {
+		status = vfs_stat_fsp(smb_fname->fsp);
+		if (!NT_STATUS_IS_OK(status)) {
 			TALLOC_FREE(smb_fname);
 			return true;
 		}
 
-		sp = &smb_fname->st;
+		sp = &smb_fname->fsp->fsp_name->st;
 	}
 
 	ok = add_filemeta(mds_ctx, reqinfo, fm_array, path, sp);
diff --git a/source3/smbd/dosmode.c b/source3/smbd/dosmode.c
index 659066642c2..2f45d68ca52 100644
--- a/source3/smbd/dosmode.c
+++ b/source3/smbd/dosmode.c
@@ -525,8 +525,21 @@ NTSTATUS set_ea_dos_attribute(connection_struct *conn,
 			status = NT_STATUS_OK;
 		}
 		unbecome_root();
-		return status;
+		if (!NT_STATUS_IS_OK(status)) {
+			return status;
+		}
 	}
+
+	/*
+	 * We correctly stored the create time.
+	 * We *always* set XATTR_DOSINFO_CREATE_TIME,
+	 * so now it can no longer be considered
+	 * calculated.
+	 */
+	update_stat_ex_create_time(
+		&smb_fname->fsp->fsp_name->st,
+		smb_fname->st.st_ex_btime);
+
 	DEBUG(10,("set_ea_dos_attribute: set EA 0x%x on file %s\n",
 		(unsigned int)dosmode,
 		smb_fname_str_dbg(smb_fname)));
diff --git a/source3/smbd/files.c b/source3/smbd/files.c
index 5c0525441ca..51ad489ef16 100644
--- a/source3/smbd/files.c
+++ b/source3/smbd/files.c
@@ -245,7 +245,6 @@ NTSTATUS open_internal_dirfsp(connection_struct *conn,
 {
 	struct files_struct *fsp = NULL;
 	NTSTATUS status;
-	int ret;
 
 	status = create_internal_dirfsp(conn, smb_dname, &fsp);
 	if (!NT_STATUS_IS_OK(status)) {
@@ -264,9 +263,10 @@ NTSTATUS open_internal_dirfsp(connection_struct *conn,
 		return status;
 	}
 
-	ret = SMB_VFS_FSTAT(fsp, &fsp->fsp_name->st);
-	if (ret != 0) {
-		return map_nt_error_from_unix(errno);
+	status = vfs_stat_fsp(fsp);
+	if (!NT_STATUS_IS_OK(status)) {
+		file_free(NULL, fsp);
+		return status;
 	}
 
 	if (!S_ISDIR(fsp->fsp_name->st.st_ex_mode)) {
diff --git a/source3/smbd/open.c b/source3/smbd/open.c
index 3995a0beb35..0d64e534149 100644
--- a/source3/smbd/open.c
+++ b/source3/smbd/open.c
@@ -811,9 +811,8 @@ static NTSTATUS non_widelink_open(const struct files_struct *dirfsp,
 	}
 
 	if (fd != -1) {
-		ret = SMB_VFS_FSTAT(fsp, &fsp->fsp_name->st);
-		if (ret != 0) {
-			status = map_nt_error_from_unix(errno);
+		status = vfs_stat_fsp(fsp);
+		if (!NT_STATUS_IS_OK(status)) {
 			goto out;
 		}
 		orig_fsp_name->st = fsp->fsp_name->st;
@@ -1545,12 +1544,11 @@ static NTSTATUS open_file(files_struct *fsp,
 			}
 
 			if (need_re_stat) {
-				ret = SMB_VFS_FSTAT(fsp, &smb_fname->st);
+				status = vfs_stat_fsp(fsp);
 				/*
 				 * If we have an fd, this stat should succeed.
 				 */
-				if (ret == -1) {
-					status = map_nt_error_from_unix(errno);
+				if (!NT_STATUS_IS_OK(status)) {
 					DBG_ERR("Error doing fstat on open "
 						"file %s (%s)\n",
 						 smb_fname_str_dbg(smb_fname),
@@ -4354,10 +4352,11 @@ static NTSTATUS mkdir_internal(connection_struct *conn,
 	/* Ensure we're checking for a symlink here.... */
 	/* We don't want to get caught by a symlink racer. */
 
-	if (SMB_VFS_FSTAT(fsp, &smb_dname->st) == -1) {
+	status = vfs_stat_fsp(fsp);
+	if (!NT_STATUS_IS_OK(status)) {
 		DEBUG(2, ("Could not stat directory '%s' just created: %s\n",
-			  smb_fname_str_dbg(smb_dname), strerror(errno)));
-		return map_nt_error_from_unix(errno);
+			  smb_fname_str_dbg(smb_dname), nt_errstr(status)));
+		return status;
 	}
 
 	if (!S_ISDIR(smb_dname->st.st_ex_mode)) {
@@ -4414,10 +4413,11 @@ static NTSTATUS mkdir_internal(connection_struct *conn,
 	}
 
 	if (need_re_stat) {
-		if (SMB_VFS_FSTAT(fsp, &smb_dname->st) == -1) {
+		status = vfs_stat_fsp(fsp);
+		if (!NT_STATUS_IS_OK(status)) {
 			DEBUG(2, ("Could not stat directory '%s' just created: %s\n",
-			  smb_fname_str_dbg(smb_dname), strerror(errno)));
-			return map_nt_error_from_unix(errno);
+			  smb_fname_str_dbg(smb_dname), nt_errstr(status)));
+			return status;
 		}
 	}
 
diff --git a/source3/smbd/pysmbd.c b/source3/smbd/pysmbd.c
index 1f23bdf27e4..5d7302c2027 100644
--- a/source3/smbd/pysmbd.c
+++ b/source3/smbd/pysmbd.c
@@ -170,7 +170,6 @@ static NTSTATUS init_files_struct(TALLOC_CTX *mem_ctx,
 {
 	struct smb_filename *smb_fname = NULL;
 	int fd;
-	int ret;
 	mode_t saved_umask;
 	struct files_struct *fsp;
 	struct files_struct *fspcwd = NULL;
@@ -224,13 +223,13 @@ static NTSTATUS init_files_struct(TALLOC_CTX *mem_ctx,
 	}
 	fsp_set_fd(fsp, fd);
 
-	ret = SMB_VFS_FSTAT(fsp, &smb_fname->st);
-	if (ret == -1) {
+	status = vfs_stat_fsp(fsp);
+	if (!NT_STATUS_IS_OK(status)) {
 		/* If we have an fd, this stat should succeed. */
 		DEBUG(0,("Error doing fstat on open file %s (%s)\n",
 			 smb_fname_str_dbg(smb_fname),
-			 strerror(errno) ));
-		return map_nt_error_from_unix(errno);
+			 nt_errstr(status) ));
+		return status;
 	}
 
 	fsp->file_id = vfs_file_id_from_sbuf(conn, &smb_fname->st);
diff --git a/source3/smbd/reply.c b/source3/smbd/reply.c
index a8bb2d5d333..1677d997fe9 100644
--- a/source3/smbd/reply.c
+++ b/source3/smbd/reply.c
@@ -7499,8 +7499,8 @@ NTSTATUS rename_internals_fsp(connection_struct *conn,
 			 * We must set the archive bit on the newly renamed
 			 * file.
 			 */
-			ret = SMB_VFS_FSTAT(fsp, &fsp->fsp_name->st);
-			if (ret == 0) {
+			status = vfs_stat_fsp(fsp);
+			if (NT_STATUS_IS_OK(status)) {
 				uint32_t old_dosmode;
 				old_dosmode = fdos_mode(fsp);
 				/*
diff --git a/source3/smbd/smb2_getinfo.c b/source3/smbd/smb2_getinfo.c
index a918cc03385..0320dcc5fde 100644
--- a/source3/smbd/smb2_getinfo.c
+++ b/source3/smbd/smb2_getinfo.c
@@ -362,11 +362,11 @@ static struct tevent_req *smbd_smb2_getinfo_send(TALLOC_CTX *mem_ctx,
 			 * Original code - this is an open file.
 			 */
 
-			if (SMB_VFS_FSTAT(fsp, &fsp->fsp_name->st) != 0) {
+			status = vfs_stat_fsp(fsp);
+			if (!NT_STATUS_IS_OK(status)) {
 				DEBUG(3, ("smbd_smb2_getinfo_send: "
 					  "fstat of %s failed (%s)\n",
-					  fsp_fnum_dbg(fsp), strerror(errno)));
-				status = map_nt_error_from_unix(errno);
+					  fsp_fnum_dbg(fsp), nt_errstr(status)));
 				tevent_req_nterror(req, status);
 				return tevent_req_post(req, ev);
 			}
diff --git a/source3/smbd/smb2_setinfo.c b/source3/smbd/smb2_setinfo.c
index e490596a2e0..d3c3ba63d6b 100644
--- a/source3/smbd/smb2_setinfo.c
+++ b/source3/smbd/smb2_setinfo.c
@@ -458,12 +458,12 @@ static struct tevent_req *smbd_smb2_setinfo_send(TALLOC_CTX *mem_ctx,
 			 * Original code - this is an open file.
 			 */
 
-			if (SMB_VFS_FSTAT(fsp, &fsp->fsp_name->st) != 0) {
+			status = vfs_stat_fsp(fsp);
+			if (!NT_STATUS_IS_OK(status)) {
 				DEBUG(3,("smbd_smb2_setinfo_send: fstat "
 					 "of %s failed (%s)\n",
 					 fsp_fnum_dbg(fsp),
-					 strerror(errno)));
-				status = map_nt_error_from_unix(errno);
+					 nt_errstr(status)));
 				tevent_req_nterror(req, status);
 				return tevent_req_post(req, ev);
 			}
diff --git a/source3/smbd/trans2.c b/source3/smbd/trans2.c
index 857007c24fb..56b5c0db902 100644
--- a/source3/smbd/trans2.c
+++ b/source3/smbd/trans2.c
@@ -6031,11 +6031,11 @@ static void call_trans2qfilepathinfo(connection_struct *conn,
 			/*
 			 * Original code - this is an open file.
 			 */
-			if (SMB_VFS_FSTAT(fsp, &smb_fname->st) != 0) {
+			status = vfs_stat_fsp(fsp);
+			if (!NT_STATUS_IS_OK(status)) {
 				DEBUG(3, ("fstat of %s failed (%s)\n",
-					  fsp_fnum_dbg(fsp), strerror(errno)));
-				reply_nterror(req,
-					map_nt_error_from_unix(errno));
+					  fsp_fnum_dbg(fsp), nt_errstr(status)));
+				reply_nterror(req, status);
 				return;
 			}
 			if (lp_smbd_getinfo_ask_sharemode(SNUM(conn))) {
@@ -9333,11 +9333,12 @@ static void call_trans2setfilepathinfo(connection_struct *conn,
 			/*
 			 * Original code - this is an open file.
 			 */
-			if (SMB_VFS_FSTAT(fsp, &smb_fname->st) != 0) {
+			status = vfs_stat_fsp(fsp);
+			if (!NT_STATUS_IS_OK(status)) {
 				DEBUG(3,("call_trans2setfilepathinfo: fstat "
 					 "of %s failed (%s)\n", fsp_fnum_dbg(fsp),
-					 strerror(errno)));
-				reply_nterror(req, map_nt_error_from_unix(errno));
+					 nt_errstr(status)));
+				reply_nterror(req, status);
 				return;
 			}
 		}
diff --git a/source3/torture/cmd_vfs.c b/source3/torture/cmd_vfs.c
index 303d80fc766..470f039c4a3 100644
--- a/source3/torture/cmd_vfs.c
+++ b/source3/torture/cmd_vfs.c
@@ -305,7 +305,6 @@ static NTSTATUS cmd_open(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, c
 	struct files_struct *fspcwd = NULL;
 	struct smb_filename *smb_fname = NULL;
 	NTSTATUS status;
-	int ret;
 	int fd;
 
 	mode = 00400;
@@ -422,15 +421,13 @@ static NTSTATUS cmd_open(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, c
 	}
 	fsp_set_fd(fsp, fd);
 
-	status = NT_STATUS_OK;
-	ret = SMB_VFS_FSTAT(fsp, &smb_fname->st);
-	if (ret == -1) {
+	status = vfs_stat_fsp(fsp);
+	if (!NT_STATUS_IS_OK(status)) {
 		/* If we have an fd, this stat should succeed. */
 		DEBUG(0,("Error doing fstat on open file %s "
 			 "(%s)\n",
 			 smb_fname_str_dbg(smb_fname),
-			 strerror(errno) ));
-		status = map_nt_error_from_unix(errno);
+			 nt_errstr(status) ));
 	} else if (S_ISDIR(smb_fname->st.st_ex_mode)) {
 		errno = EISDIR;
 		status = NT_STATUS_FILE_IS_A_DIRECTORY;
@@ -1715,7 +1712,6 @@ static NTSTATUS cmd_fset_nt_acl(struct vfs_state *vfs, TALLOC_CTX *mem_ctx,
 static NTSTATUS cmd_set_nt_acl(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, const char **argv)
 {
 	int flags;
-	int ret;
 	mode_t mode;
 	files_struct *fsp;
 	struct files_struct *fspcwd = NULL;
@@ -1786,18 +1782,13 @@ static NTSTATUS cmd_set_nt_acl(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int a
 	}
 	fsp_set_fd(fsp, fd);
 
-	status = NT_STATUS_OK;
-	ret = SMB_VFS_FSTAT(fsp, &smb_fname->st);
-	if (ret == -1) {
+	status = vfs_stat_fsp(fsp);
+	if (!NT_STATUS_IS_OK(status)) {
 		/* If we have an fd, this stat should succeed. */
 		DEBUG(0,("Error doing fstat on open file %s "
 			 "(%s)\n",
 			 smb_fname_str_dbg(smb_fname),
-			 strerror(errno) ));
-		status = map_nt_error_from_unix(errno);
-	}
-	
-	if (!NT_STATUS_IS_OK(status)) {
+			 nt_errstr(status) ));
 		goto out;
 	}
 
diff --git a/source4/torture/smb2/durable_v2_open.c b/source4/torture/smb2/durable_v2_open.c
index 8efa2622444..9b9af11124c 100644
--- a/source4/torture/smb2/durable_v2_open.c
+++ b/source4/torture/smb2/durable_v2_open.c
@@ -2010,6 +2010,145 @@ bool test_persistent_open_lease(struct torture_context *tctx,
 	return ret;
 }
 
+/**
+ * setfileinfo test for doing a durable open
+ * create the file with lease and durable handle,
+ * write to it (via set end-of-file), tcp disconnect,
+ * reconnect, do a durable reopen - should succeed.
+ *
+ * BUG: https://bugzilla.samba.org/show_bug.cgi?id=15022
+ */
+bool test_durable_v2_setinfo(struct torture_context *tctx,
+					   struct smb2_tree *tree)
+{
+	NTSTATUS status;
+	TALLOC_CTX *mem_ctx = talloc_new(tctx);
+	char fname[256];
+	struct smb2_handle _h;
+	struct smb2_handle *h = NULL;
+	struct smb2_create io;
+	union smb_setfileinfo si;
+	struct GUID create_guid = GUID_random();
+	struct smb2_lease ls;
+	uint64_t lease_key;
+	bool ret = true;
+	struct smbcli_options options;
+	uint32_t caps;
+
+	caps = smb2cli_conn_server_capabilities(tree->session->transport->conn);
+	if (!(caps & SMB2_CAP_LEASING)) {
+		torture_skip(tctx, "leases are not supported");
+	}
+
+	options = tree->session->transport->options;
+
+	smb2_deltree(tree, __func__);
+	status = torture_smb2_testdir(tree, __func__, &_h);
+	torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
+					"torture_smb2_testdir failed\n");
+	smb2_util_close(tree, _h);
+
+	/* Choose a random name in case the state is left a little funky. */
+	snprintf(fname, 256, "%s\\durable_v2_setinfo%s.dat",
+		 __func__, generate_random_str(tctx, 8));
+
+	smb2_util_unlink(tree, fname);
+
+	lease_key = random();
+	smb2_lease_v2_create(&io, &ls, false /* dir */, fname,
+			     lease_key, 0, /* parent lease key */
+			     smb2_util_lease_state("RWH"), 0 /* lease epoch */);
+	io.in.durable_open = false;
+	io.in.durable_open_v2 = true;
+	io.in.persistent_open = false;
+	io.in.create_guid = create_guid;
+	io.in.timeout = UINT32_MAX;
+
+	status = smb2_create(tree, mem_ctx, &io);
+	CHECK_STATUS(status, NT_STATUS_OK);
+	_h = io.out.file.handle;
+	h = &_h;
+	CHECK_CREATED(&io, CREATED, FILE_ATTRIBUTE_ARCHIVE);
+	CHECK_VAL(io.out.durable_open, false);
+	CHECK_VAL(io.out.durable_open_v2, true);
+	CHECK_VAL(io.out.persistent_open, false);
+	CHECK_VAL(io.out.timeout, 300*1000);
+	CHECK_VAL(io.out.oplock_level, SMB2_OPLOCK_LEVEL_LEASE);
+	CHECK_VAL(io.out.lease_response_v2.lease_key.data[0], lease_key);
+	CHECK_VAL(io.out.lease_response_v2.lease_key.data[1], ~lease_key);
+
+	/*
+	 * Set EOF to 0x100000.
+	 * Mimics an Apple client test, but most importantly
+	 * causes the mtime timestamp on disk to be updated.
+	 */
+	ZERO_STRUCT(si);
+	si.generic.level = SMB_SFILEINFO_END_OF_FILE_INFORMATION;
+	si.generic.in.file.handle = io.out.file.handle;
+	si.end_of_file_info.in.size = 0x100000;
+	status = smb2_setinfo_file(tree, &si);
+	CHECK_STATUS(status, NT_STATUS_OK);
+
+	/* disconnect, reconnect and then do durable reopen */
+	TALLOC_FREE(tree);
+
+	if (!torture_smb2_connection_ext(tctx, 0, &options, &tree)) {
+		torture_warning(tctx, "couldn't reconnect, bailing\n");
+		ret = false;
+		goto done;
+	}
+
+	/*
+	 * Now for a succeeding reconnect:
+	 */
+
+	ZERO_STRUCT(io);
+	io.in.fname = fname;
+	io.in.durable_open_v2 = false;
+	io.in.durable_handle_v2 = h;
+	io.in.create_guid = create_guid;
+	io.in.lease_request_v2 = &ls;
+	io.in.oplock_level = SMB2_OPLOCK_LEVEL_LEASE;
+
+	/* the requested lease state is irrelevant */
+	ls.lease_state = smb2_util_lease_state("");
+
+	h = NULL;
+
+	status = smb2_create(tree, mem_ctx, &io);
+	CHECK_STATUS(status, NT_STATUS_OK);
+
+	CHECK_VAL(io.out.create_action, NTCREATEX_ACTION_EXISTED);
+	CHECK_VAL(io.out.size, 0x100000);				\
+	CHECK_VAL(io.out.durable_open, false);
+	CHECK_VAL(io.out.durable_open_v2, false); /* no dh2q response blob */
+	CHECK_VAL(io.out.persistent_open, false);
+	CHECK_VAL(io.out.oplock_level, SMB2_OPLOCK_LEVEL_LEASE);
+	CHECK_VAL(io.out.lease_response_v2.lease_key.data[0], lease_key);
+	CHECK_VAL(io.out.lease_response_v2.lease_key.data[1], ~lease_key);
+	CHECK_VAL(io.out.lease_response_v2.lease_state,
+		  smb2_util_lease_state("RWH"));
+	CHECK_VAL(io.out.lease_response_v2.lease_flags, 0);
+	CHECK_VAL(io.out.lease_response_v2.lease_duration, 0);
+	_h = io.out.file.handle;
+	h = &_h;
+
+done:
+
+	if (h != NULL) {
+		smb2_util_close(tree, *h);
+	}
+
+	smb2_util_unlink(tree, fname);
+	smb2_deltree(tree, __func__);
+
+	talloc_free(tree);
+
+	talloc_free(mem_ctx);
+
+	return ret;
+}
+
 struct torture_suite *torture_smb2_durable_v2_open_init(TALLOC_CTX *ctx)
 {
 	struct torture_suite *suite =
@@ -2026,6 +2165,7 @@ struct torture_suite *torture_smb2_durable_v2_open_init(TALLOC_CTX *ctx)
 	torture_suite_add_1smb2_test(suite, "reopen2c", test_durable_v2_open_reopen2c);
 	torture_suite_add_1smb2_test(suite, "reopen2-lease", test_durable_v2_open_reopen2_lease);
 	torture_suite_add_1smb2_test(suite, "reopen2-lease-v2", test_durable_v2_open_reopen2_lease_v2);
+	torture_suite_add_1smb2_test(suite, "durable-v2-setinfo", test_durable_v2_setinfo);
 	torture_suite_add_2smb2_test(suite, "app-instance", test_durable_v2_open_app_instance);
 	torture_suite_add_1smb2_test(suite, "persistent-open-oplock", test_persistent_open_oplock);
 	torture_suite_add_1smb2_test(suite, "persistent-open-lease", test_persistent_open_lease);


-- 
Samba Shared Repository



More information about the samba-cvs mailing list