[SCM] Samba Shared Repository - branch master updated - release-4-0-0alpha7-2289-g808721f

Jeremy Allison jra at samba.org
Fri Jun 12 20:40:31 GMT 2009


The branch, master has been updated
       via  808721f7bb8c87fd80f60054cca1ef202d6c403a (commit)
       via  1be1a33e251b5ac2e6ff071d4faa352879f49a04 (commit)
      from  9b5d905ebe13bb9eb8d21120cd7fab3296f8fa82 (commit)

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


- Log -----------------------------------------------------------------
commit 808721f7bb8c87fd80f60054cca1ef202d6c403a
Author: Volker Lendecke <vl at samba.org>
Date:   Sat Jun 6 23:27:31 2009 +0200

    Fix bug 6440
    
    Don't ignore the close error of the output file in check_magic()

commit 1be1a33e251b5ac2e6ff071d4faa352879f49a04
Author: Volker Lendecke <vl at samba.org>
Date:   Sat Jun 6 23:20:44 2009 +0200

    Simplify close_normal_file()

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

Summary of changes:
 source3/smbd/close.c |   73 +++++++++++++++++++++++++++----------------------
 1 files changed, 40 insertions(+), 33 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source3/smbd/close.c b/source3/smbd/close.c
index 9aab3a7..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;
 }
 
 /****************************************************************************
@@ -514,6 +521,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 +541,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 +551,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 +563,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,42 +583,35 @@ 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) {
-		check_magic(fsp);
+		tmp = check_magic(fsp);
+		status = ntstatus_keeperror(status, tmp);
 	}
 
 	/*
 	 * 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,


-- 
Samba Shared Repository


More information about the samba-cvs mailing list