From 6112ad611b2331fee31b2a2f3a93f3999cf93aca Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 18 Mar 2022 11:40:04 -0700 Subject: [PATCH 01/15] s3: smbd: In set_ea_dos_attribute() cause success paths 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 --- source3/smbd/dosmode.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/source3/smbd/dosmode.c b/source3/smbd/dosmode.c index 659066642c2..7e28cf598cf 100644 --- a/source3/smbd/dosmode.c +++ b/source3/smbd/dosmode.c @@ -525,8 +525,14 @@ NTSTATUS set_ea_dos_attribute(connection_struct *conn, status = NT_STATUS_OK; } unbecome_root(); + if (NT_STATUS_IS_OK(status)) { + goto out; + } return status; } + + out: + DEBUG(10,("set_ea_dos_attribute: set EA 0x%x on file %s\n", (unsigned int)dosmode, smb_fname_str_dbg(smb_fname))); -- 2.32.0 From e98de97b218a64c990f768a475c058574f0ae5d9 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 18 Mar 2022 11:41:48 -0700 Subject: [PATCH 02/15] 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 --- source3/smbd/dosmode.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/source3/smbd/dosmode.c b/source3/smbd/dosmode.c index 7e28cf598cf..811fc8919a3 100644 --- a/source3/smbd/dosmode.c +++ b/source3/smbd/dosmode.c @@ -533,6 +533,16 @@ NTSTATUS set_ea_dos_attribute(connection_struct *conn, out: + /* + * 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))); -- 2.32.0 From df89df0f6c7df20bc228cd1d7bbe84dac6fe52e8 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 18 Mar 2022 11:51:00 -0700 Subject: [PATCH 03/15] 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 --- source3/modules/vfs_vxfs.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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; } -- 2.32.0 From b885da643071f161c525a4c775b07513519d3a30 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 18 Mar 2022 11:56:53 -0700 Subject: [PATCH 04/15] 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 --- source3/rpc_server/mdssvc/mdssvc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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); -- 2.32.0 From 40e189103b97bc67c83b3997e7df3188d55ed840 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 18 Mar 2022 12:00:15 -0700 Subject: [PATCH 05/15] 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 --- source3/smbd/files.c | 1 + 1 file changed, 1 insertion(+) diff --git a/source3/smbd/files.c b/source3/smbd/files.c index 5c0525441ca..6062a41902f 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -266,6 +266,7 @@ NTSTATUS open_internal_dirfsp(connection_struct *conn, ret = SMB_VFS_FSTAT(fsp, &fsp->fsp_name->st); if (ret != 0) { + file_free(NULL, fsp); return map_nt_error_from_unix(errno); } -- 2.32.0 From 9537648dfb046756cea282c1a9d638734fca9ecb Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 18 Mar 2022 12:02:35 -0700 Subject: [PATCH 06/15] 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 --- source3/smbd/files.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/source3/smbd/files.c b/source3/smbd/files.c index 6062a41902f..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,10 +263,10 @@ NTSTATUS open_internal_dirfsp(connection_struct *conn, return status; } - ret = SMB_VFS_FSTAT(fsp, &fsp->fsp_name->st); - if (ret != 0) { + status = vfs_stat_fsp(fsp); + if (!NT_STATUS_IS_OK(status)) { file_free(NULL, fsp); - return map_nt_error_from_unix(errno); + return status; } if (!S_ISDIR(fsp->fsp_name->st.st_ex_mode)) { -- 2.32.0 From 159a2ab5b4325dbfff59ec087de64d395b129c96 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 18 Mar 2022 12:09:43 -0700 Subject: [PATCH 07/15] 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 --- source3/smbd/open.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/source3/smbd/open.c b/source3/smbd/open.c index d01b5ae65f4..0cff2cb8eef 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; -- 2.32.0 From 37cb1e2b96c5c05cec080ec412c365e1b6965202 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 18 Mar 2022 12:11:23 -0700 Subject: [PATCH 08/15] 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 --- source3/smbd/open.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/source3/smbd/open.c b/source3/smbd/open.c index 0cff2cb8eef..c279b7354ca 100644 --- a/source3/smbd/open.c +++ b/source3/smbd/open.c @@ -1543,12 +1543,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), -- 2.32.0 From 5382df086e8e6ca3491958cc25fc4d89468a576c Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 18 Mar 2022 12:19:44 -0700 Subject: [PATCH 09/15] 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 --- source3/smbd/open.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/source3/smbd/open.c b/source3/smbd/open.c index c279b7354ca..d8d5d0f020b 100644 --- a/source3/smbd/open.c +++ b/source3/smbd/open.c @@ -4351,10 +4351,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)) { -- 2.32.0 From 528dffc0b13020c3956a4908500ffbe801804cbf Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 18 Mar 2022 12:22:26 -0700 Subject: [PATCH 10/15] 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 --- source3/smbd/open.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/source3/smbd/open.c b/source3/smbd/open.c index d8d5d0f020b..27e4284b801 100644 --- a/source3/smbd/open.c +++ b/source3/smbd/open.c @@ -4412,10 +4412,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; } } -- 2.32.0 From 906f2e33e2b32ded35159dfdffaeca5e663e1f7b Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 18 Mar 2022 12:24:27 -0700 Subject: [PATCH 11/15] 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 --- source3/smbd/reply.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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); /* -- 2.32.0 From 8ba63a3f808aed4a799f36e924840d00b4c5f885 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 18 Mar 2022 12:26:27 -0700 Subject: [PATCH 12/15] 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 --- source3/smbd/trans2.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/source3/smbd/trans2.c b/source3/smbd/trans2.c index 857007c24fb..d44599ed00a 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))) { -- 2.32.0 From e8a8497eceeea24d8d5b7bb73bf52912604b1afd Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 18 Mar 2022 12:27:53 -0700 Subject: [PATCH 13/15] 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 --- source3/smbd/trans2.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/source3/smbd/trans2.c b/source3/smbd/trans2.c index d44599ed00a..56b5c0db902 100644 --- a/source3/smbd/trans2.c +++ b/source3/smbd/trans2.c @@ -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; } } -- 2.32.0 From 8a16ab357058e97fb095b04eb982c0534bcb1415 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 18 Mar 2022 11:45:50 -0700 Subject: [PATCH 14/15] 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 --- source3/smbd/smb2_getinfo.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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); } -- 2.32.0 From 8f862210cd4fcbcffcf3cbe93806fdd42690a964 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 18 Mar 2022 12:30:27 -0700 Subject: [PATCH 15/15] 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. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15022 Signed-off-by: Jeremy Allison --- source3/smbd/smb2_setinfo.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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); } -- 2.32.0