From 410976bab30165c84a399fb45e692ffb615cfafd Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 29 Aug 2011 16:47:16 -0700 Subject: [PATCH] Fix bug 8412 - Microsoft Office 2007 (Microsoft Word) fails to save as on a Samba share with SMB2. (cherry picked from commit dec3b21cd1737b317749e7ebced5aa1c2115ebdf) --- source3/smbd/reply.c | 46 +++++++++++++++++++++++++++++++++++++++++++ source3/smbd/smb2_setinfo.c | 6 ----- 2 files changed, 46 insertions(+), 6 deletions(-) diff --git a/source3/smbd/reply.c b/source3/smbd/reply.c index 4178f3f..ac450bb 100644 --- a/source3/smbd/reply.c +++ b/source3/smbd/reply.c @@ -5936,6 +5936,47 @@ static void notify_rename(connection_struct *conn, bool is_dir, } /**************************************************************************** + Returns an error if the parent directory for a filename is open in an + incompatible way. +****************************************************************************/ + +static NTSTATUS parent_dirname_compatible_open(connection_struct *conn, + const struct smb_filename *smb_fname_dst_in) +{ + char *parent_dir = NULL; + struct smb_filename smb_fname_parent; + struct file_id id; + files_struct *fsp = NULL; + int ret; + + if (!parent_dirname(talloc_tos(), smb_fname_dst_in->base_name, + &parent_dir, NULL)) { + return NT_STATUS_NO_MEMORY; + } + ZERO_STRUCT(smb_fname_parent); + smb_fname_parent.base_name = parent_dir; + + ret = SMB_VFS_LSTAT(conn, &smb_fname_parent); + if (ret == -1) { + return map_nt_error_from_unix(errno); + } + + /* + * We're only checking on this smbd here, mostly good + * enough.. and will pass tests. + */ + + id = vfs_file_id_from_sbuf(conn, &smb_fname_parent.st); + for (fsp = file_find_di_first(conn->sconn, id); fsp; + fsp = file_find_di_next(fsp)) { + if (fsp->access_mask & DELETE_ACCESS) { + return NT_STATUS_SHARING_VIOLATION; + } + } + return NT_STATUS_OK; +} + +/**************************************************************************** Rename an open file - given an fsp. ****************************************************************************/ @@ -5956,6 +5997,11 @@ NTSTATUS rename_internals_fsp(connection_struct *conn, return status; } + status = parent_dirname_compatible_open(conn, smb_fname_dst_in); + if (!NT_STATUS_IS_OK(status)) { + return status; + } + /* Make a copy of the dst smb_fname structs */ status = copy_smb_filename(ctx, smb_fname_dst_in, &smb_fname_dst); diff --git a/source3/smbd/smb2_setinfo.c b/source3/smbd/smb2_setinfo.c index e114940..96b44aa 100644 --- a/source3/smbd/smb2_setinfo.c +++ b/source3/smbd/smb2_setinfo.c @@ -219,12 +219,6 @@ static struct tevent_req *smbd_smb2_setinfo_send(TALLOC_CTX *mem_ctx, if (file_info_level == SMB_FILE_RENAME_INFORMATION) { /* SMB2_FILE_RENAME_INFORMATION_INTERNAL == 0xFF00 + in_file_info_class */ file_info_level = SMB2_FILE_RENAME_INFORMATION_INTERNAL; - if (fsp->oplock_type != FAKE_LEVEL_II_OPLOCK && - fsp->oplock_type != NO_OPLOCK) { - /* No break, but error. */ - tevent_req_nterror(req, NT_STATUS_SHARING_VIOLATION); - return tevent_req_post(req, ev); - } } if (fsp->fh->fd == -1) { -- 1.7.3.1