[SCM] Samba Shared Repository - branch master updated

Ralph Böhme slow at samba.org
Thu Oct 5 14:01:01 UTC 2023


The branch, master has been updated
       via  d1846452e96 vfs: Add VFS_OPEN_HOW_WITH_BACKUP_INTENT
       via  f701faf6677 smbd: Remove "flags2" from open_file_ntcreate()
       via  02d9321ce0c smbd: Pass struct vfs_open_how to open_file()
       via  7c356769870 smbd: Remove "local_flags" from open_file()
       via  6ec031b2d14 smbd: Make open_file() a bit safer
       via  884b9926b9c smbd: Simplify open_file()
       via  814b37bdcf7 smbd: Simplify open_file()
       via  f8645c7a101 smbd: Simplify open_file()
       via  df78af98936 smbd: Simplify an if-condition in open_file()
       via  45005d4b71c smbd: Simplify open_file()
       via  ad7b119b8be smbd: Don't change incoming flags in open_file()
       via  3f4c937dcf9 smbd: Remove variable "accmode" from open_file()
       via  236df26a1f4 smbd: Slightly simplify open_file()
       via  2a53fdeb449 smbd: Pass "struct vfs_open_how" to reopen_from_fsp()
       via  7996c07bd8e smbd: Pass "struct vfs_open_how" to fd_open_atomic()
       via  4b376fff032 smbd: Pass "struct vfs_open_how" to reopen_from_procfd()
      from  cb89ea70b1f libsmb: Use pidl generated parsing for posix file info

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


- Log -----------------------------------------------------------------
commit d1846452e96217695c8cb2537f071f287ab210d4
Author: Volker Lendecke <vl at samba.org>
Date:   Fri Sep 1 14:51:47 2023 +0200

    vfs: Add VFS_OPEN_HOW_WITH_BACKUP_INTENT
    
    Indicate BACKUP_INTENT to vfs_openat(). Why? I have a customer request
    who wants to add O_NOATIME in this case to avoid metadata updates when
    a backup or virus-checking application comes along.
    
    This does not fully handle BACKUP_INTENT correctly, this would require
    become_root() appropriately. We might want to do that later after a
    lot of careful security audit, but this patch independently might
    already provide some infrastructure for it.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>
    
    Autobuild-User(master): Ralph Böhme <slow at samba.org>
    Autobuild-Date(master): Thu Oct  5 14:00:33 UTC 2023 on atb-devel-224

commit f701faf6677100bef6cbcf7f3d5c973f76a6bb49
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Sep 5 15:55:26 2023 +0200

    smbd: Remove "flags2" from open_file_ntcreate()
    
    "flags" carried just the O_ACCMODE bits, "flags2" everything
    else. Unify them.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit 02d9321ce0c9fd5b5968ca950cfa3b2eb2a768fc
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Sep 5 15:36:01 2023 +0200

    smbd: Pass struct vfs_open_how to open_file()
    
    We want to pass BACKUP_INTENT down into reopen_from_fsp, and the
    elegant way is to do this via vfs_open_how.resolve.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit 7c35676987053fa4e51c1fc2ee2cfb1951aad708
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Sep 5 15:27:46 2023 +0200

    smbd: Remove "local_flags" from open_file()
    
    This needs close review. I could not see where we were actually
    referencing the original flags in a way that would not be available in
    local_flags. The reason for this patch is that I want to pass in
    vfs_open_how into open_file(), and the distinction between flags and
    local_flags made this significantly harder to understand for me.
    
    The only place where we really used both versions is the DBG_NOTICE in
    the last hunk, and this will come back in the next patch.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit 6ec031b2d146962a414da69694d298c00df0c517
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Sep 5 15:25:07 2023 +0200

    smbd: Make open_file() a bit safer
    
    Move adding O_RDWR before the check for read only shares. I haven't
    been able to pass this condition through SMB, but in any case we
    should not accidentially open with O_RDWR in the !CAN_WRITE(conn)
    case.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit 884b9926b9ce5176e861bffd3ab62dec642ee786
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Sep 5 14:59:29 2023 +0200

    smbd: Simplify open_file()
    
    Simplify an if-condition:
    
    We have to return NT_STATUS_OBJECT_NAME_INVALID even if we're not
    creating. In fact, we probably should not end up in open_file() if
    we're open a Windows file with a wildcard.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit 814b37bdcf7eec3c68f1574028dc9c417029e80f
Author: Volker Lendecke <vl at samba.org>
Date:   Fri Sep 1 16:33:04 2023 +0200

    smbd: Simplify open_file()
    
    We have extracted FSP_POSIX_FLAGS_PATHNAMES above.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit f8645c7a1014a2d3f655c453ae833de3c83776b9
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Sep 5 14:53:18 2023 +0200

    smbd: Simplify open_file()
    
    We handle O_TRUNC further down anyway by passing local_flags&~O_TRUNC to
    reopen_from_fsp(). No need for this FIFO special case.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit df78af98936774cc1c01729eb4280877cbc05ff6
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Sep 5 14:50:05 2023 +0200

    smbd: Simplify an if-condition in open_file()
    
    We use the plain (flags&O_TRUNC) a few lines above, make the
    if-condition a bit more readable.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit 45005d4b71cfed06fad2f12ee17f2b8c82eb16ac
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Sep 5 14:46:21 2023 +0200

    smbd: Simplify open_file()
    
    We can unconditionally just and-out O_CREAT from local_flags, so
    remove an if-condition.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit ad7b119b8be325c8d140676f535042f87aecf1ae
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Sep 5 14:44:37 2023 +0200

    smbd: Don't change incoming flags in open_file()
    
    This will be part of a const struct vfs_open_how soon. Further down in
    this function we don't look at O_CREAT or O_EXCL of "flags" anymore
    anyway.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit 3f4c937dcf92fb875bb178a142526b31502cd180
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Sep 5 14:40:30 2023 +0200

    smbd: Remove variable "accmode" from open_file()
    
    We directly look at the flags in many other places in this function,
    so do this also for O_ACCMODE for clarity.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit 236df26a1f4451f5e7fd66fe52ce7fda77bc9abf
Author: Volker Lendecke <vl at samba.org>
Date:   Fri Sep 1 16:31:03 2023 +0200

    smbd: Slightly simplify open_file()
    
    Replace "truncating" variable reference with what it was defined
    as. We use "(flags & O_TRUNC)" a few lines above, so it can't be that
    bad.
    
    After we set it to "false" further down, it was never used again.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit 2a53fdeb449f4a8521ee0f82026dfbdf8b38928b
Author: Volker Lendecke <vl at samba.org>
Date:   Thu Aug 31 16:26:57 2023 +0200

    smbd: Pass "struct vfs_open_how" to reopen_from_fsp()
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit 7996c07bd8e943bbc75da0beaca849eff8c87aa0
Author: Volker Lendecke <vl at samba.org>
Date:   Thu Aug 31 15:04:18 2023 +0200

    smbd: Pass "struct vfs_open_how" to fd_open_atomic()
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit 4b376fff0320f63db73b4754ea86d7f85cb3a2c9
Author: Volker Lendecke <vl at samba.org>
Date:   Thu Aug 31 14:59:47 2023 +0200

    smbd: Pass "struct vfs_open_how" to reopen_from_procfd()
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

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

Summary of changes:
 source3/include/vfs.h         |   1 +
 source3/modules/vfs_default.c |   3 +-
 source3/smbd/open.c           | 258 +++++++++++++++++++++---------------------
 3 files changed, 131 insertions(+), 131 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source3/include/vfs.h b/source3/include/vfs.h
index 8ada8d8aadf..1e2e88d65ce 100644
--- a/source3/include/vfs.h
+++ b/source3/include/vfs.h
@@ -908,6 +908,7 @@ struct vfs_aio_state {
 };
 
 #define VFS_OPEN_HOW_RESOLVE_NO_SYMLINKS 1
+#define VFS_OPEN_HOW_WITH_BACKUP_INTENT 2
 
 struct vfs_open_how {
 	int flags;
diff --git a/source3/modules/vfs_default.c b/source3/modules/vfs_default.c
index 1d4b9b1a840..7fa6872d171 100644
--- a/source3/modules/vfs_default.c
+++ b/source3/modules/vfs_default.c
@@ -664,7 +664,8 @@ static int vfswrap_openat(vfs_handle_struct *handle,
 
 	START_PROFILE(syscall_openat);
 
-	if (how->resolve & ~VFS_OPEN_HOW_RESOLVE_NO_SYMLINKS) {
+	if (how->resolve & ~(VFS_OPEN_HOW_RESOLVE_NO_SYMLINKS |
+			     VFS_OPEN_HOW_WITH_BACKUP_INTENT)) {
 		errno = ENOSYS;
 		result = -1;
 		goto out;
diff --git a/source3/smbd/open.c b/source3/smbd/open.c
index 87719eec06e..d912acbb409 100644
--- a/source3/smbd/open.c
+++ b/source3/smbd/open.c
@@ -1113,11 +1113,10 @@ static NTSTATUS change_dir_owner_to_parent_fsp(struct files_struct *parent_fsp,
 static NTSTATUS fd_open_atomic(struct files_struct *dirfsp,
 			       struct smb_filename *smb_fname,
 			       files_struct *fsp,
-			       int flags,
-			       mode_t mode,
+			       const struct vfs_open_how *_how,
 			       bool *file_created)
 {
-	struct vfs_open_how how = { .flags = flags, .mode = mode, };
+	struct vfs_open_how how = *_how;
 	NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
 	NTSTATUS retry_status;
 	bool file_existed = VALID_STAT(smb_fname->st);
@@ -1168,10 +1167,10 @@ static NTSTATUS fd_open_atomic(struct files_struct *dirfsp,
 	 */
 
 	if (file_existed) {
-		how.flags = flags & ~(O_CREAT);
+		how.flags = _how->flags & ~(O_CREAT);
 		retry_status = NT_STATUS_OBJECT_NAME_NOT_FOUND;
 	} else {
-		how.flags = flags | O_EXCL;
+		how.flags = _how->flags | O_EXCL;
 		retry_status = NT_STATUS_OBJECT_NAME_COLLISION;
 	}
 
@@ -1189,9 +1188,9 @@ static NTSTATUS fd_open_atomic(struct files_struct *dirfsp,
 			  file_existed ? "existed" : "did not exist");
 
 		if (file_existed) {
-			how.flags = flags & ~(O_CREAT);
+			how.flags = _how->flags & ~(O_CREAT);
 		} else {
-			how.flags = flags | O_EXCL;
+			how.flags = _how->flags | O_EXCL;
 		}
 
 		status = fd_openat(dirfsp, smb_fname, fsp, &how);
@@ -1202,10 +1201,8 @@ static NTSTATUS fd_open_atomic(struct files_struct *dirfsp,
 }
 
 static NTSTATUS reopen_from_procfd(struct files_struct *fsp,
-				   int flags,
-				   mode_t mode)
+				   const struct vfs_open_how *how)
 {
-	struct vfs_open_how how = { .flags = flags, .mode = mode };
 	struct smb_filename proc_fname;
 	const char *p = NULL;
 	char buf[PATH_MAX];
@@ -1246,7 +1243,7 @@ static NTSTATUS reopen_from_procfd(struct files_struct *fsp,
 				fsp->conn->cwd_fsp,
 				&proc_fname,
 				fsp,
-				&how);
+				how);
 	if (new_fd == -1) {
 		status = map_nt_error_from_unix(errno);
 		fd_close(fsp);
@@ -1265,8 +1262,7 @@ static NTSTATUS reopen_from_procfd(struct files_struct *fsp,
 static NTSTATUS reopen_from_fsp(struct files_struct *dirfsp,
 				struct smb_filename *smb_fname,
 				struct files_struct *fsp,
-				int flags,
-				mode_t mode,
+				const struct vfs_open_how *how,
 				bool *p_file_created)
 {
 	bool __unused_file_created = false;
@@ -1281,9 +1277,7 @@ static NTSTATUS reopen_from_fsp(struct files_struct *dirfsp,
 	 *       SMB_VFS_REOPEN_FSP()?
 	 */
 
-	status = reopen_from_procfd(fsp,
-				    flags,
-				    mode);
+	status = reopen_from_procfd(fsp, how);
 	if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
 		return status;
 	}
@@ -1299,13 +1293,7 @@ static NTSTATUS reopen_from_fsp(struct files_struct *dirfsp,
 
 	fsp->fsp_flags.is_pathref = false;
 
-	status = fd_open_atomic(
-		dirfsp,
-		smb_fname,
-		fsp,
-		flags,
-		mode,
-		p_file_created);
+	status = fd_open_atomic(dirfsp, smb_fname, fsp, how, p_file_created);
 	return status;
 }
 
@@ -1313,22 +1301,21 @@ static NTSTATUS reopen_from_fsp(struct files_struct *dirfsp,
  Open a file.
 ****************************************************************************/
 
-static NTSTATUS open_file(struct smb_request *req,
-			  struct files_struct *dirfsp,
-			  struct smb_filename *smb_fname_atname,
-			  files_struct *fsp,
-			  int flags,
-			  mode_t unx_mode,
-			  uint32_t access_mask, /* client requested access mask. */
-			  uint32_t open_access_mask, /* what we're actually using in the open. */
-			  uint32_t private_flags,
-			  bool *p_file_created)
+static NTSTATUS open_file(
+	struct smb_request *req,
+	struct files_struct *dirfsp,
+	struct smb_filename *smb_fname_atname,
+	files_struct *fsp,
+	const struct vfs_open_how *_how,
+	uint32_t access_mask,	   /* client requested access mask. */
+	uint32_t open_access_mask, /* what we're actually using in the open. */
+	uint32_t private_flags,
+	bool *p_file_created)
 {
 	connection_struct *conn = fsp->conn;
 	struct smb_filename *smb_fname = fsp->fsp_name;
+	struct vfs_open_how how = *_how;
 	NTSTATUS status = NT_STATUS_OK;
-	int accmode = (flags & O_ACCMODE);
-	int local_flags = flags;
 	bool file_existed = VALID_STAT(fsp->fsp_name->st);
 	const uint32_t need_fd_mask =
 		FILE_READ_DATA |
@@ -1336,8 +1323,7 @@ static NTSTATUS open_file(struct smb_request *req,
 		FILE_APPEND_DATA |
 		FILE_EXECUTE |
 		SEC_FLAG_SYSTEM_SECURITY;
-	bool creating = !file_existed && (flags & O_CREAT);
-	bool truncating = (flags & O_TRUNC);
+	bool creating = !file_existed && (how.flags & O_CREAT);
 	bool open_fd = false;
 	bool posix_open = (fsp->posix_flags & FSP_POSIX_FLAGS_OPEN);
 
@@ -1349,6 +1335,24 @@ static NTSTATUS open_file(struct smb_request *req,
 		return NT_STATUS_FILE_IS_A_DIRECTORY;
 	}
 
+	/*
+	 * This little piece of insanity is inspired by the
+	 * fact that an NT client can open a file for O_RDONLY,
+	 * but set the create disposition to FILE_EXISTS_TRUNCATE.
+	 * If the client *can* write to the file, then it expects to
+	 * truncate the file, even though it is opening for readonly.
+	 * Quicken uses this stupid trick in backup file creation...
+	 * Thanks *greatly* to "David W. Chapman Jr." <dwcjr at inethouston.net>
+	 * for helping track this one down. It didn't bite us in 2.0.x
+	 * as we always opened files read-write in that release. JRA.
+	 */
+
+	if (((how.flags & O_ACCMODE) == O_RDONLY) && (how.flags & O_TRUNC)) {
+		DBG_DEBUG("truncate requested on read-only open for file %s\n",
+			  smb_fname_str_dbg(smb_fname));
+		how.flags = (how.flags & ~O_ACCMODE) | O_RDWR;
+	}
+
 	/* Check permissions */
 
 	/*
@@ -1363,45 +1367,26 @@ static NTSTATUS open_file(struct smb_request *req,
 
 	if (!CAN_WRITE(conn)) {
 		/* It's a read-only share - fail if we wanted to write. */
-		if(accmode != O_RDONLY || (flags & O_TRUNC) || (flags & O_APPEND)) {
+		if ((how.flags & O_ACCMODE) != O_RDONLY ||
+		    (how.flags & O_TRUNC) || (how.flags & O_APPEND)) {
 			DEBUG(3,("Permission denied opening %s\n",
 				 smb_fname_str_dbg(smb_fname)));
 			return NT_STATUS_ACCESS_DENIED;
 		}
-		if (flags & O_CREAT) {
-			/* We don't want to write - but we must make sure that
-			   O_CREAT doesn't create the file if we have write
-			   access into the directory.
-			*/
-			flags &= ~(O_CREAT|O_EXCL);
-			local_flags &= ~(O_CREAT|O_EXCL);
-		}
-	}
-
-	/*
-	 * This little piece of insanity is inspired by the
-	 * fact that an NT client can open a file for O_RDONLY,
-	 * but set the create disposition to FILE_EXISTS_TRUNCATE.
-	 * If the client *can* write to the file, then it expects to
-	 * truncate the file, even though it is opening for readonly.
-	 * Quicken uses this stupid trick in backup file creation...
-	 * Thanks *greatly* to "David W. Chapman Jr." <dwcjr at inethouston.net>
-	 * for helping track this one down. It didn't bite us in 2.0.x
-	 * as we always opened files read-write in that release. JRA.
-	 */
-
-	if ((accmode == O_RDONLY) && ((flags & O_TRUNC) == O_TRUNC)) {
-		DEBUG(10,("open_file: truncate requested on read-only open "
-			  "for file %s\n", smb_fname_str_dbg(smb_fname)));
-		local_flags = (flags & ~O_ACCMODE)|O_RDWR;
+		/*
+		 * We don't want to write - but we must make sure that
+		 * O_CREAT doesn't create the file if we have write
+		 * access into the directory.
+		 */
+		how.flags &= ~(O_CREAT | O_EXCL);
 	}
 
-	if ((open_access_mask & need_fd_mask) || creating || truncating) {
+	if ((open_access_mask & need_fd_mask) || creating ||
+	    (how.flags & O_TRUNC)) {
 		open_fd = true;
 	}
 
 	if (open_fd) {
-		const char *wild;
 		int ret;
 
 #if defined(O_NONBLOCK) && defined(S_ISFIFO)
@@ -1412,26 +1397,26 @@ static NTSTATUS open_file(struct smb_request *req,
 		 */
 
 		if (file_existed && S_ISFIFO(smb_fname->st.st_ex_mode)) {
-			local_flags &= ~O_TRUNC; /* Can't truncate a FIFO. */
-			local_flags |= O_NONBLOCK;
-			truncating = false;
+			how.flags |= O_NONBLOCK;
 		}
 #endif
 
-		/* Don't create files with Microsoft wildcard characters. */
-		if (fsp_is_alternate_stream(fsp)) {
+		if (!posix_open) {
+			const char *wild = smb_fname->base_name;
 			/*
-			 * wildcard characters are allowed in stream names
-			 * only test the basefilename
+			 * Don't open files with Microsoft wildcard characters.
 			 */
-			wild = fsp->base_fsp->fsp_name->base_name;
-		} else {
-			wild = smb_fname->base_name;
-		}
-		if ((local_flags & O_CREAT) && !file_existed &&
-		    !(fsp->posix_flags & FSP_POSIX_FLAGS_PATHNAMES) &&
-		    ms_has_wild(wild))  {
-			return NT_STATUS_OBJECT_NAME_INVALID;
+			if (fsp_is_alternate_stream(fsp)) {
+				/*
+				 * wildcard characters are allowed in stream
+				 * names only test the basefilename
+				 */
+				wild = fsp->base_fsp->fsp_name->base_name;
+			}
+
+			if (ms_has_wild(wild)) {
+				return NT_STATUS_OBJECT_NAME_INVALID;
+			}
 		}
 
 		/* Can we access this file ? */
@@ -1471,7 +1456,7 @@ static NTSTATUS open_file(struct smb_request *req,
 			}
 
 			if (!file_existed) {
-				if (!(local_flags & O_CREAT)) {
+				if (!(how.flags & O_CREAT)) {
 					/* File didn't exist and no O_CREAT. */
 					return NT_STATUS_OBJECT_NAME_NOT_FOUND;
 				}
@@ -1496,11 +1481,11 @@ static NTSTATUS open_file(struct smb_request *req,
 		 * Actually do the open - if O_TRUNC is needed handle it
 		 * below under the share mode lock.
 		 */
+		how.flags &= ~O_TRUNC;
 		status = reopen_from_fsp(dirfsp,
 					 smb_fname_atname,
 					 fsp,
-					 local_flags & ~O_TRUNC,
-					 unx_mode,
+					 &how,
 					 p_file_created);
 		if (NT_STATUS_EQUAL(status, NT_STATUS_STOPPED_ON_SYMLINK)) {
 			/*
@@ -1513,13 +1498,16 @@ static NTSTATUS open_file(struct smb_request *req,
 			status = NT_STATUS_OBJECT_NAME_NOT_FOUND;
 		}
 		if (!NT_STATUS_IS_OK(status)) {
-			DEBUG(3,("Error opening file %s (%s) (local_flags=%d) "
-				 "(flags=%d)\n", smb_fname_str_dbg(smb_fname),
-				 nt_errstr(status),local_flags,flags));
+			DBG_NOTICE("Error opening file %s (%s) (in_flags=%d) "
+				   "(flags=%d)\n",
+				   smb_fname_str_dbg(smb_fname),
+				   nt_errstr(status),
+				   _how->flags,
+				   how.flags);
 			return status;
 		}
 
-		if (local_flags & O_NONBLOCK) {
+		if (how.flags & O_NONBLOCK) {
 			/*
 			 * GPFS can return ETIMEDOUT for pread on
 			 * nonblocking file descriptors when files
@@ -1551,7 +1539,7 @@ static NTSTATUS open_file(struct smb_request *req,
 				inherit_access_posix_acl(conn,
 							 dirfsp,
 							 smb_fname,
-							 unx_mode);
+							 how.mode);
 				need_re_stat = true;
 			}
 
@@ -3789,7 +3777,6 @@ static NTSTATUS open_file_ntcreate(connection_struct *conn,
 {
 	struct smb_filename *smb_fname = fsp->fsp_name;
 	int flags=0;
-	int flags2=0;
 	bool file_existed = VALID_STAT(smb_fname->st);
 	bool def_acl = False;
 	bool posix_open = False;
@@ -3977,7 +3964,7 @@ static NTSTATUS open_file_ntcreate(connection_struct *conn,
 			return NT_STATUS_INVALID_PARAMETER;
 	}
 
-	flags2 = disposition_to_open_flags(create_disposition);
+	flags = disposition_to_open_flags(create_disposition);
 
 	/* We only care about matching attributes on file exists and
 	 * overwrite. */
@@ -4014,7 +4001,7 @@ static NTSTATUS open_file_ntcreate(connection_struct *conn,
 
 	open_access_mask = access_mask;
 
-	if (flags2 & O_TRUNC) {
+	if (flags & O_TRUNC) {
 		open_access_mask |= FILE_WRITE_DATA; /* This will cause oplock breaks. */
 	}
 
@@ -4044,7 +4031,7 @@ static NTSTATUS open_file_ntcreate(connection_struct *conn,
 	 * mean the same thing under DOS and Unix.
 	 */
 
-	flags = calculate_open_access_flags(access_mask, private_flags);
+	flags |= calculate_open_access_flags(access_mask, private_flags);
 
 	/*
 	 * Currently we only look at FILE_WRITE_THROUGH for create options.
@@ -4052,12 +4039,12 @@ static NTSTATUS open_file_ntcreate(connection_struct *conn,
 
 #if defined(O_SYNC)
 	if ((create_options & FILE_WRITE_THROUGH) && lp_strict_sync(SNUM(conn))) {
-		flags2 |= O_SYNC;
+		flags |= O_SYNC;
 	}
 #endif /* O_SYNC */
 
 	if (posix_open && (access_mask & FILE_APPEND_DATA)) {
-		flags2 |= O_APPEND;
+		flags |= O_APPEND;
 	}
 
 	if (!posix_open && !CAN_WRITE(conn)) {
@@ -4066,7 +4053,7 @@ static NTSTATUS open_file_ntcreate(connection_struct *conn,
 		 * O_CREAT or O_TRUNC are set, but for compatibility with
 		 * older versions of Samba we just AND them out.
 		 */
-		flags2 &= ~(O_CREAT|O_TRUNC);
+		flags &= ~(O_CREAT | O_TRUNC);
 	}
 
 	/*
@@ -4081,13 +4068,13 @@ static NTSTATUS open_file_ntcreate(connection_struct *conn,
 	 * oplock we must periodically poll for available open
 	 * using O_NONBLOCK.
 	 */
-	flags2 |= O_NONBLOCK;
+	flags |= O_NONBLOCK;
 
 	/*
 	 * Ensure we can't write on a read-only share or file.
 	 */
 
-	if (flags != O_RDONLY && file_existed &&
+	if (((flags & O_ACCMODE) != O_RDONLY) && file_existed &&
 	    (!CAN_WRITE(conn) || IS_DOS_READONLY(existing_dos_attributes))) {
 		DEBUG(5,("open_file_ntcreate: write access requested for "
 			 "file %s on read only %s\n",
@@ -4113,9 +4100,8 @@ static NTSTATUS open_file_ntcreate(connection_struct *conn,
 		fsp->posix_flags |= FSP_POSIX_FLAGS_ALL;
 	}
 
-	if ((create_options & FILE_DELETE_ON_CLOSE) &&
-			(flags2 & O_CREAT) &&
-			!file_existed) {
+	if ((create_options & FILE_DELETE_ON_CLOSE) && (flags & O_CREAT) &&
+	    !file_existed) {
 		/* Delete on close semantics for new files. */
 		status = can_set_delete_on_close(fsp,
 						new_dos_attributes);
@@ -4129,28 +4115,39 @@ static NTSTATUS open_file_ntcreate(connection_struct *conn,
 	 * Ensure we pay attention to default ACLs on directories if required.
 	 */
 
-        if ((flags2 & O_CREAT) && lp_inherit_acls(SNUM(conn)) &&
-	    (def_acl = directory_has_default_acl_fsp(parent_dir_fname->fsp)))
-	{
+	if ((flags & O_CREAT) && lp_inherit_acls(SNUM(conn)) &&
+	    (def_acl = directory_has_default_acl_fsp(parent_dir_fname->fsp))) {
 		unx_mode = (0777 & lp_create_mask(SNUM(conn)));
 	}
 
-	DEBUG(4,("calling open_file with flags=0x%X flags2=0x%X mode=0%o, "
-		"access_mask = 0x%x, open_access_mask = 0x%x\n",
-		 (unsigned int)flags, (unsigned int)flags2,
-		 (unsigned int)unx_mode, (unsigned int)access_mask,
-		 (unsigned int)open_access_mask));
-
-	fsp_open = open_file(req,
-			     parent_dir_fname->fsp,
-			     smb_fname_atname,
-			     fsp,
-			     flags|flags2,
-			     unx_mode,
-			     access_mask,
-			     open_access_mask,
-			     private_flags,
-			     &new_file_created);
+	DEBUG(4,
+	      ("calling open_file with flags=0x%X mode=0%o, "
+	       "access_mask = 0x%x, open_access_mask = 0x%x\n",
+	       (unsigned int)flags,
+	       (unsigned int)unx_mode,
+	       (unsigned int)access_mask,
+	       (unsigned int)open_access_mask));
+
+	{
+		struct vfs_open_how how = {
+			.flags = flags,
+			.mode = unx_mode,
+		};
+
+		if (create_options & FILE_OPEN_FOR_BACKUP_INTENT) {
+			how.resolve |= VFS_OPEN_HOW_WITH_BACKUP_INTENT;
+		}
+
+		fsp_open = open_file(req,
+				     parent_dir_fname->fsp,
+				     smb_fname_atname,
+				     fsp,
+				     &how,
+				     access_mask,
+				     open_access_mask,
+				     private_flags,
+				     &new_file_created);
+	}
 	if (NT_STATUS_EQUAL(fsp_open, NT_STATUS_NETWORK_BUSY)) {
 		if (file_existed && S_ISFIFO(fsp->fsp_name->st.st_ex_mode)) {
 			DEBUG(10, ("FIFO busy\n"));
@@ -4262,7 +4259,7 @@ static NTSTATUS open_file_ntcreate(connection_struct *conn,
 	if (new_file_created) {
 		info = FILE_WAS_CREATED;
 	} else {
-		if (flags2 & O_TRUNC) {
+		if (flags & O_TRUNC) {
 			info = FILE_WAS_OVERWRITTEN;
 		} else {


-- 
Samba Shared Repository



More information about the samba-cvs mailing list