From 75dc4f53880f72397a818a48721a3edcba92b311 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 6 Jun 2009 23:20:44 +0200 Subject: [PATCH] Simplify close_normal_file() --- source3/smbd/close.c | 43 +++++++++++++++++++++---------------------- 1 files changed, 21 insertions(+), 22 deletions(-) diff --git a/source3/smbd/close.c b/source3/smbd/close.c index 9aab3a7..aebbe39 100644 --- a/source3/smbd/close.c +++ b/source3/smbd/close.c @@ -514,6 +514,14 @@ static NTSTATUS update_write_time_on_close(struct files_struct *fsp) return NT_STATUS_OK; } +static NTSTATUS ntstatus_keeperror(NTSTATUS s1, NTSTATUS s2) +{ + if (!NT_STATUS_IS_OK(s1)) { + return s1; + } + return s2; +} + /**************************************************************************** Close a file. @@ -526,10 +534,7 @@ static NTSTATUS close_normal_file(struct smb_request *req, files_struct *fsp, enum file_close_type close_type) { NTSTATUS status = NT_STATUS_OK; - NTSTATUS saved_status1 = NT_STATUS_OK; - NTSTATUS saved_status2 = NT_STATUS_OK; - NTSTATUS saved_status3 = NT_STATUS_OK; - NTSTATUS saved_status4 = NT_STATUS_OK; + NTSTATUS tmp; connection_struct *conn = fsp->conn; if (fsp->aio_write_behind) { @@ -539,7 +544,8 @@ static NTSTATUS close_normal_file(struct smb_request *req, files_struct *fsp, */ int ret = wait_for_aio_completion(fsp); if (ret) { - saved_status1 = map_nt_error_from_unix(ret); + status = ntstatus_keeperror( + status, map_nt_error_from_unix(ret)); } } else { cancel_aio_by_fsp(fsp); @@ -550,7 +556,8 @@ static NTSTATUS close_normal_file(struct smb_request *req, files_struct *fsp, * error here, we must remember this. */ - saved_status2 = close_filestruct(fsp); + tmp = close_filestruct(fsp); + status = ntstatus_keeperror(status, tmp); if (fsp->print_file) { print_fsp_end(fsp, close_type); @@ -569,12 +576,14 @@ static NTSTATUS close_normal_file(struct smb_request *req, files_struct *fsp, if (fsp->fh->ref_count == 1) { /* Should we return on error here... ? */ - saved_status3 = close_remove_share_mode(fsp, close_type); + tmp = close_remove_share_mode(fsp, close_type); + status = ntstatus_keeperror(status, tmp); } locking_close_file(smbd_messaging_context(), fsp); - status = fd_close(fsp); + tmp = fd_close(fsp); + status = ntstatus_keeperror(status, tmp); /* check for magic scripts */ if (close_type == NORMAL_CLOSE) { @@ -585,26 +594,16 @@ static NTSTATUS close_normal_file(struct smb_request *req, files_struct *fsp, * Ensure pending modtime is set after close. */ - saved_status4 = update_write_time_on_close(fsp); - if (NT_STATUS_EQUAL(saved_status4, NT_STATUS_OBJECT_NAME_NOT_FOUND)) { + tmp = update_write_time_on_close(fsp); + if (NT_STATUS_EQUAL(tmp, NT_STATUS_OBJECT_NAME_NOT_FOUND)) { /* Someone renamed the file or a parent directory containing * this file. We can't do anything about this, we don't have * an "update timestamp by fd" call in POSIX. Eat the error. */ - saved_status4 = NT_STATUS_OK; + tmp = NT_STATUS_OK; } - if (NT_STATUS_IS_OK(status)) { - if (!NT_STATUS_IS_OK(saved_status1)) { - status = saved_status1; - } else if (!NT_STATUS_IS_OK(saved_status2)) { - status = saved_status2; - } else if (!NT_STATUS_IS_OK(saved_status3)) { - status = saved_status3; - } else if (!NT_STATUS_IS_OK(saved_status4)) { - status = saved_status4; - } - } + status = ntstatus_keeperror(status, tmp); DEBUG(2,("%s closed file %s (numopen=%d) %s\n", conn->server_info->unix_name,fsp->fsp_name, -- 1.5.5 From eb803e34b014a9c0e24d1f1d190d9d6d5300f8ed Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 6 Jun 2009 23:27:31 +0200 Subject: [PATCH] Fix bug 6440 Don't ignore the close error of the output file in check_magic() --- source3/smbd/close.c | 30 +++++++++++++++++++----------- 1 files changed, 19 insertions(+), 11 deletions(-) diff --git a/source3/smbd/close.c b/source3/smbd/close.c index aebbe39..bc54bac 100644 --- a/source3/smbd/close.c +++ b/source3/smbd/close.c @@ -27,7 +27,7 @@ extern struct current_user current_user; Run a file if it is a magic script. ****************************************************************************/ -static void check_magic(struct files_struct *fsp) +static NTSTATUS check_magic(struct files_struct *fsp) { int ret; const char *magic_output = NULL; @@ -38,7 +38,7 @@ static void check_magic(struct files_struct *fsp) struct connection_struct *conn = fsp->conn; if (!*lp_magicscript(SNUM(conn))) { - return; + return NT_STATUS_OK; } DEBUG(5,("checking magic for %s\n",fsp->fsp_name)); @@ -50,7 +50,7 @@ static void check_magic(struct files_struct *fsp) } if (!strequal(lp_magicscript(SNUM(conn)),p)) { - return; + return NT_STATUS_OK; } ctx = talloc_stackframe(); @@ -64,19 +64,19 @@ static void check_magic(struct files_struct *fsp) } if (!magic_output) { TALLOC_FREE(ctx); - return; + return NT_STATUS_NO_MEMORY; } /* Ensure we don't depend on user's PATH. */ p = talloc_asprintf(ctx, "./%s", fsp->fsp_name); if (!p) { TALLOC_FREE(ctx); - return; + return NT_STATUS_NO_MEMORY; } if (chmod(fsp->fsp_name,0755) == -1) { TALLOC_FREE(ctx); - return; + return map_nt_error_from_unix(errno); } ret = smbrun(p,&tmp_fd); DEBUG(3,("Invoking magic command %s gave %d\n", @@ -88,25 +88,32 @@ static void check_magic(struct files_struct *fsp) close(tmp_fd); } TALLOC_FREE(ctx); - return; + return NT_STATUS_UNSUCCESSFUL; } outfd = open(magic_output, O_CREAT|O_EXCL|O_RDWR, 0600); if (outfd == -1) { + int err = errno; close(tmp_fd); TALLOC_FREE(ctx); - return; + return map_nt_error_from_unix(err); } if (sys_fstat(tmp_fd,&st) == -1) { + int err = errno; close(tmp_fd); close(outfd); - return; + TALLOC_FREE(ctx); + return map_nt_error_from_unix(err); } transfer_file(tmp_fd,outfd,(SMB_OFF_T)st.st_ex_size); close(tmp_fd); - close(outfd); + if (close(outfd) == -1) { + TALLOC_FREE(ctx); + return map_nt_error_from_unix(errno); + } TALLOC_FREE(ctx); + return NT_STATUS_OK; } /**************************************************************************** @@ -587,7 +594,8 @@ static NTSTATUS close_normal_file(struct smb_request *req, files_struct *fsp, /* check for magic scripts */ if (close_type == NORMAL_CLOSE) { - check_magic(fsp); + tmp = check_magic(fsp); + status = ntstatus_keeperror(status, tmp); } /* -- 1.5.5