diff options
Diffstat (limited to 'source3/smbd/open.c')
-rw-r--r-- | source3/smbd/open.c | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/source3/smbd/open.c b/source3/smbd/open.c index 5f7bff9a8d3..16d43077c5a 100644 --- a/source3/smbd/open.c +++ b/source3/smbd/open.c @@ -839,8 +839,11 @@ static NTSTATUS open_file(files_struct *fsp, } } - /* Actually do the open */ - status = fd_open_atomic(conn, fsp, local_flags, + /* + * Actually do the open - if O_TRUNC is needed handle it + * below under the share mode lock. + */ + status = fd_open_atomic(conn, fsp, local_flags & ~O_TRUNC, unx_mode, p_file_created); if (!NT_STATUS_IS_OK(status)) { DEBUG(3,("Error opening file %s (%s) (local_flags=%d) " @@ -2646,6 +2649,21 @@ static NTSTATUS open_file_ntcreate(connection_struct *conn, return status; } + /* Should we atomically (to the client at least) truncate ? */ + if ((!new_file_created) && + (flags2 & O_TRUNC) && + (!S_ISFIFO(fsp->fsp_name->st.st_ex_mode))) { + int ret; + + ret = vfs_set_filelen(fsp, 0); + if (ret != 0) { + status = map_nt_error_from_unix(errno); + TALLOC_FREE(lck); + fd_close(fsp); + return status; + } + } + grant_fsp_oplock_type(fsp, oplock_request, got_level2_oplock, |