[SCM] Samba Shared Repository - branch master updated

Jeremy Allison jra at samba.org
Sat Aug 10 00:08:02 UTC 2019


The branch, master has been updated
       via  fe26ff6e911 smbd: Simplify fd_open_atomic()
       via  16b56549d2c smbd: FTRUNCATE regular files only
       via  2c20954af5d smbd: Make "lease" const in SMB_VFS_CREATE_FILE()
       via  c2a779f50e8 smbd: Make "lease" const in create_file_default()
       via  665e3f022f2 smbd: Make "lease" const in create_file_unixpath()
       via  bfa604541ed smbd: Make "lease_key" const in lease_match()
       via  91b479fb6cf smbd: Make "lease" const in open_file_ntcreate()
       via  d2aaef2e9c9 smbd: Make "lease" const in grant_fsp_oplock_type()
       via  e2572242986 smbd: Nobody uses the changed "lease" from grant_fsp_oplock_type
      from  64e594e5dc7 s3: VFS: vfs_ceph_snapshots: Make setxattr return errno = EROFS on a shadow copy path.

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


- Log -----------------------------------------------------------------
commit fe26ff6e911f835808ac3f465822f86260407020
Author: Volker Lendecke <vl at samba.org>
Date:   Wed Jul 24 17:39:59 2019 +0200

    smbd: Simplify fd_open_atomic()
    
    * Assign *file_created on every exit.
    
    * Directly assign curr_flags without &= / |=
    
    Both of these changes make the routine easier to understand for me,
    less jumping around in the code to see where the values came from.
    
    * Do the retry in a "positive" if-clause
    
    Normally I'm a big fan of early returns, but this single retry is so
    simple that to me it's easier to understand this way.
    
    Overall, 13 lines less code. YMMV :-)
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>
    
    Autobuild-User(master): Jeremy Allison <jra at samba.org>
    Autobuild-Date(master): Sat Aug 10 00:07:28 UTC 2019 on sn-devel-184

commit 16b56549d2ca6aad68467116ca08829c1144a41b
Author: Volker Lendecke <vl at samba.org>
Date:   Wed Jul 24 15:48:50 2019 +0200

    smbd: FTRUNCATE regular files only
    
    I don't really have a test case, but to me a positive test for a
    regular file makes more sense here than just ruling out FIFOs. While
    we probably only ever hit regular files (or FIFOs), there might be
    more that we catch and don't properly handle.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 2c20954af5d55ed3537de7d3b22340c8305ad1a3
Author: Volker Lendecke <vl at samba.org>
Date:   Wed Aug 7 22:00:11 2019 +0200

    smbd: Make "lease" const in SMB_VFS_CREATE_FILE()
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit c2a779f50e8694f20fb06b6e05bc24678d47b7d6
Author: Volker Lendecke <vl at samba.org>
Date:   Wed Aug 7 21:41:22 2019 +0200

    smbd: Make "lease" const in create_file_default()
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 665e3f022f215ea7dcaabedee950be134039cd7a
Author: Volker Lendecke <vl at samba.org>
Date:   Wed Aug 7 21:37:31 2019 +0200

    smbd: Make "lease" const in create_file_unixpath()
    
    This is the one place where *lease actually got modified. We can
    easily make a copy, "struct smb2_lease" is not too large, and this
    case is pretty rare anyway.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit bfa604541edeea4aa91c81f510716d5bb476a3f7
Author: Volker Lendecke <vl at samba.org>
Date:   Wed Aug 7 21:36:25 2019 +0200

    smbd: Make "lease_key" const in lease_match()
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 91b479fb6cf7bc7bc2287e8f5cd835e4b1894458
Author: Volker Lendecke <vl at samba.org>
Date:   Wed Aug 7 21:30:56 2019 +0200

    smbd: Make "lease" const in open_file_ntcreate()
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit d2aaef2e9c90b35e52369e8f229591b06c75bb27
Author: Volker Lendecke <vl at samba.org>
Date:   Wed Aug 7 21:29:14 2019 +0200

    smbd: Make "lease" const in grant_fsp_oplock_type()
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit e2572242986903b1d7e8468dc9528ba4a74ea6bc
Author: Volker Lendecke <vl at samba.org>
Date:   Wed Aug 7 21:27:42 2019 +0200

    smbd: Nobody uses the changed "lease" from grant_fsp_oplock_type
    
    .. except for the DEBUG message
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

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

Summary of changes:
 examples/VFS/skel_opaque.c            |  2 +-
 examples/VFS/skel_transparent.c       |  2 +-
 source3/include/vfs.h                 |  7 ++--
 source3/modules/vfs_default.c         |  2 +-
 source3/modules/vfs_fruit.c           |  2 +-
 source3/modules/vfs_full_audit.c      |  2 +-
 source3/modules/vfs_media_harmony.c   |  2 +-
 source3/modules/vfs_not_implemented.c |  2 +-
 source3/modules/vfs_time_audit.c      |  2 +-
 source3/modules/vfs_unityed_media.c   |  2 +-
 source3/modules/vfs_worm.c            |  2 +-
 source3/smbd/open.c                   | 73 +++++++++++++++--------------------
 source3/smbd/proto.h                  |  2 +-
 source3/smbd/vfs.c                    |  2 +-
 14 files changed, 47 insertions(+), 57 deletions(-)


Changeset truncated at 500 lines:

diff --git a/examples/VFS/skel_opaque.c b/examples/VFS/skel_opaque.c
index 4b2b11a1aaa..55b576302a1 100644
--- a/examples/VFS/skel_opaque.c
+++ b/examples/VFS/skel_opaque.c
@@ -203,7 +203,7 @@ static NTSTATUS skel_create_file(struct vfs_handle_struct *handle,
 				 uint32_t create_options,
 				 uint32_t file_attributes,
 				 uint32_t oplock_request,
-				 struct smb2_lease *lease,
+				 const struct smb2_lease *lease,
 				 uint64_t allocation_size,
 				 uint32_t private_flags,
 				 struct security_descriptor *sd,
diff --git a/examples/VFS/skel_transparent.c b/examples/VFS/skel_transparent.c
index 0de01ac9d54..eae2e9d5027 100644
--- a/examples/VFS/skel_transparent.c
+++ b/examples/VFS/skel_transparent.c
@@ -198,7 +198,7 @@ static NTSTATUS skel_create_file(struct vfs_handle_struct *handle,
 				 uint32_t create_options,
 				 uint32_t file_attributes,
 				 uint32_t oplock_request,
-				 struct smb2_lease *lease,
+				 const struct smb2_lease *lease,
 				 uint64_t allocation_size,
 				 uint32_t private_flags,
 				 struct security_descriptor *sd,
diff --git a/source3/include/vfs.h b/source3/include/vfs.h
index 268f286916c..aec9546681b 100644
--- a/source3/include/vfs.h
+++ b/source3/include/vfs.h
@@ -271,6 +271,7 @@
 /* Version 41 - Remove "msg_ctx" parameter from SMB_VFS_BRL_UNLOCK_WINDOWS */
 /* Bump to version 42, Samba 4.12 will ship with that */
 /* Version 42 - Remove share_access member from struct files_struct */
+/* Version 42 - Make "lease" a const* in create_file_fn */
 
 #define SMB_VFS_INTERFACE_VERSION 42
 
@@ -714,7 +715,7 @@ struct vfs_fn_pointers {
 				   uint32_t create_options,
 				   uint32_t file_attributes,
 				   uint32_t oplock_request,
-				   struct smb2_lease *lease,
+				   const struct smb2_lease *lease,
 				   uint64_t allocation_size,
 				   uint32_t private_flags,
 				   struct security_descriptor *sd,
@@ -1211,7 +1212,7 @@ NTSTATUS smb_vfs_call_create_file(struct vfs_handle_struct *handle,
 				  uint32_t create_options,
 				  uint32_t file_attributes,
 				  uint32_t oplock_request,
-				  struct smb2_lease *lease,
+				  const struct smb2_lease *lease,
 				  uint64_t allocation_size,
 				  uint32_t private_flags,
 				  struct security_descriptor *sd,
@@ -1649,7 +1650,7 @@ NTSTATUS vfs_not_implemented_create_file(struct vfs_handle_struct *handle,
 				uint32_t create_options,
 				uint32_t file_attributes,
 				uint32_t oplock_request,
-				struct smb2_lease *lease,
+				const struct smb2_lease *lease,
 				uint64_t allocation_size,
 				uint32_t private_flags,
 				struct security_descriptor *sd,
diff --git a/source3/modules/vfs_default.c b/source3/modules/vfs_default.c
index 84c22bb1517..6580a05bbd6 100644
--- a/source3/modules/vfs_default.c
+++ b/source3/modules/vfs_default.c
@@ -569,7 +569,7 @@ static NTSTATUS vfswrap_create_file(vfs_handle_struct *handle,
 				    uint32_t create_options,
 				    uint32_t file_attributes,
 				    uint32_t oplock_request,
-				    struct smb2_lease *lease,
+				    const struct smb2_lease *lease,
 				    uint64_t allocation_size,
 				    uint32_t private_flags,
 				    struct security_descriptor *sd,
diff --git a/source3/modules/vfs_fruit.c b/source3/modules/vfs_fruit.c
index 8289be3b3ca..2960aed12c4 100644
--- a/source3/modules/vfs_fruit.c
+++ b/source3/modules/vfs_fruit.c
@@ -3939,7 +3939,7 @@ static NTSTATUS fruit_create_file(vfs_handle_struct *handle,
 				  uint32_t create_options,
 				  uint32_t file_attributes,
 				  uint32_t oplock_request,
-				  struct smb2_lease *lease,
+				  const struct smb2_lease *lease,
 				  uint64_t allocation_size,
 				  uint32_t private_flags,
 				  struct security_descriptor *sd,
diff --git a/source3/modules/vfs_full_audit.c b/source3/modules/vfs_full_audit.c
index f6e11516970..bc644c8f8ed 100644
--- a/source3/modules/vfs_full_audit.c
+++ b/source3/modules/vfs_full_audit.c
@@ -1059,7 +1059,7 @@ static NTSTATUS smb_full_audit_create_file(vfs_handle_struct *handle,
 				      uint32_t create_options,
 				      uint32_t file_attributes,
 				      uint32_t oplock_request,
-				      struct smb2_lease *lease,
+				      const struct smb2_lease *lease,
 				      uint64_t allocation_size,
 				      uint32_t private_flags,
 				      struct security_descriptor *sd,
diff --git a/source3/modules/vfs_media_harmony.c b/source3/modules/vfs_media_harmony.c
index ea49eff6d8f..9523c6fca57 100644
--- a/source3/modules/vfs_media_harmony.c
+++ b/source3/modules/vfs_media_harmony.c
@@ -1198,7 +1198,7 @@ static NTSTATUS mh_create_file(vfs_handle_struct *handle,
 		uint32_t create_options,
 		uint32_t file_attributes,
 		uint32_t oplock_request,
-		struct smb2_lease *lease,
+		const struct smb2_lease *lease,
 		uint64_t allocation_size,
 		uint32_t private_flags,
 		struct security_descriptor *sd,
diff --git a/source3/modules/vfs_not_implemented.c b/source3/modules/vfs_not_implemented.c
index e3a39d57ca2..a29ce9c3353 100644
--- a/source3/modules/vfs_not_implemented.c
+++ b/source3/modules/vfs_not_implemented.c
@@ -201,7 +201,7 @@ NTSTATUS vfs_not_implemented_create_file(struct vfs_handle_struct *handle,
 				uint32_t create_options,
 				uint32_t file_attributes,
 				uint32_t oplock_request,
-				struct smb2_lease *lease,
+				const struct smb2_lease *lease,
 				uint64_t allocation_size,
 				uint32_t private_flags,
 				struct security_descriptor *sd,
diff --git a/source3/modules/vfs_time_audit.c b/source3/modules/vfs_time_audit.c
index 2fb847b1b34..1d82ffe454f 100644
--- a/source3/modules/vfs_time_audit.c
+++ b/source3/modules/vfs_time_audit.c
@@ -598,7 +598,7 @@ static NTSTATUS smb_time_audit_create_file(vfs_handle_struct *handle,
 					   uint32_t create_options,
 					   uint32_t file_attributes,
 					   uint32_t oplock_request,
-					   struct smb2_lease *lease,
+					   const struct smb2_lease *lease,
 					   uint64_t allocation_size,
 					   uint32_t private_flags,
 					   struct security_descriptor *sd,
diff --git a/source3/modules/vfs_unityed_media.c b/source3/modules/vfs_unityed_media.c
index 43285191cd2..cc531d46701 100644
--- a/source3/modules/vfs_unityed_media.c
+++ b/source3/modules/vfs_unityed_media.c
@@ -907,7 +907,7 @@ static NTSTATUS um_create_file(vfs_handle_struct *handle,
 			       uint32_t create_options,
 			       uint32_t file_attributes,
 			       uint32_t oplock_request,
-			       struct smb2_lease *lease,
+			       const struct smb2_lease *lease,
 			       uint64_t allocation_size,
 			       uint32_t private_flags,
 			       struct security_descriptor *sd,
diff --git a/source3/modules/vfs_worm.c b/source3/modules/vfs_worm.c
index a956911591c..9b1a5facae7 100644
--- a/source3/modules/vfs_worm.c
+++ b/source3/modules/vfs_worm.c
@@ -32,7 +32,7 @@ static NTSTATUS vfs_worm_create_file(vfs_handle_struct *handle,
 				     uint32_t create_options,
 				     uint32_t file_attributes,
 				     uint32_t oplock_request,
-				     struct smb2_lease *lease,
+				     const struct smb2_lease *lease,
 				     uint64_t allocation_size,
 				     uint32_t private_flags,
 				     struct security_descriptor *sd,
diff --git a/source3/smbd/open.c b/source3/smbd/open.c
index e33c7874883..13a7d7237c7 100644
--- a/source3/smbd/open.c
+++ b/source3/smbd/open.c
@@ -1051,13 +1051,13 @@ static NTSTATUS fd_open_atomic(struct connection_struct *conn,
 	bool file_existed = VALID_STAT(fsp->fsp_name->st);
 	int curr_flags;
 
-	*file_created = false;
-
 	if (!(flags & O_CREAT)) {
 		/*
 		 * We're not creating the file, just pass through.
 		 */
-		return fd_open(conn, fsp, flags, mode);
+		status = fd_open(conn, fsp, flags, mode);
+		*file_created = false;
+		return status;
 	}
 
 	if (flags & O_EXCL) {
@@ -1096,50 +1096,37 @@ static NTSTATUS fd_open_atomic(struct connection_struct *conn,
 	 * mapped from the ELOOP POSIX error.
 	 */
 
-	curr_flags = flags;
-
 	if (file_existed) {
-		curr_flags &= ~(O_CREAT);
+		curr_flags = flags & ~(O_CREAT);
 		retry_status = NT_STATUS_OBJECT_NAME_NOT_FOUND;
 	} else {
-		curr_flags |= O_EXCL;
+		curr_flags = flags | O_EXCL;
 		retry_status = NT_STATUS_OBJECT_NAME_COLLISION;
 	}
 
 	status = fd_open(conn, fsp, curr_flags, mode);
 	if (NT_STATUS_IS_OK(status)) {
-		if (!file_existed) {
-			*file_created = true;
-		}
+		*file_created = !file_existed;
 		return NT_STATUS_OK;
 	}
-	if (!NT_STATUS_EQUAL(status, retry_status)) {
-		return status;
-	}
+	if (NT_STATUS_EQUAL(status, retry_status)) {
 
-	curr_flags = flags;
+		file_existed = !file_existed;
 
-	/*
-	 * Keep file_existed up to date for clarity.
-	 */
-	if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
-		file_existed = false;
-		curr_flags |= O_EXCL;
-		DBG_DEBUG("file %s did not exist. Retry.\n",
-			smb_fname_str_dbg(fsp->fsp_name));
-	} else {
-		file_existed = true;
-		curr_flags &= ~(O_CREAT);
-		DBG_DEBUG("file %s existed. Retry.\n",
-			smb_fname_str_dbg(fsp->fsp_name));
-	}
+		DBG_DEBUG("File %s %s. Retry.\n",
+			  fsp_str_dbg(fsp),
+			  file_existed ? "existed" : "did not exist");
 
-	status = fd_open(conn, fsp, curr_flags, mode);
+		if (file_existed) {
+			curr_flags = flags & ~(O_CREAT);
+		} else {
+			curr_flags = flags | O_EXCL;
+		}
 
-	if (NT_STATUS_IS_OK(status) && (!file_existed)) {
-		*file_created = true;
+		status = fd_open(conn, fsp, curr_flags, mode);
 	}
 
+	*file_created = (NT_STATUS_IS_OK(status) && !file_existed);
 	return status;
 }
 
@@ -2220,7 +2207,7 @@ static NTSTATUS grant_fsp_oplock_type(struct smb_request *req,
 				      struct files_struct *fsp,
 				      struct share_mode_lock *lck,
 				      int oplock_request,
-				      struct smb2_lease *lease,
+				      const struct smb2_lease *lease,
 				      uint32_t share_access,
 				      uint32_t access_mask)
 {
@@ -2324,9 +2311,8 @@ static NTSTATUS grant_fsp_oplock_type(struct smb_request *req,
 			return status;
 
 		}
-		*lease = fsp->lease->lease;
 
-		DEBUG(10, ("lease_state=%d\n", lease->lease_state));
+		DBG_DEBUG("lease_state=%d\n", fsp->lease->lease.lease_state);
 	} else {
 		if (got_handle_lease) {
 			granted = SMB2_LEASE_NONE;
@@ -2965,7 +2951,7 @@ static NTSTATUS open_file_ntcreate(connection_struct *conn,
 			    uint32_t create_options,	/* options such as delete on close. */
 			    uint32_t new_dos_attributes,	/* attributes used for new file. */
 			    int oplock_request, 	/* internal Samba oplock codes. */
-			    struct smb2_lease *lease,
+			    const struct smb2_lease *lease,
 				 			/* Information (FILE_EXISTS etc.) */
 			    uint32_t private_flags,     /* Samba specific flags. */
 			    int *pinfo,
@@ -3515,7 +3501,7 @@ static NTSTATUS open_file_ntcreate(connection_struct *conn,
 	/* 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))) {
+	    (S_ISREG(fsp->fsp_name->st.st_ex_mode))) {
 		int ret;
 
 		ret = SMB_VFS_FTRUNCATE(fsp, 0);
@@ -4818,7 +4804,7 @@ static void lease_match_parser(
 
 static NTSTATUS lease_match(connection_struct *conn,
 			    struct smb_request *req,
-			    struct smb2_lease_key *lease_key,
+			    const struct smb2_lease_key *lease_key,
 			    const char *servicepath,
 			    const struct smb_filename *fname,
 			    uint16_t *p_version,
@@ -4962,7 +4948,7 @@ static NTSTATUS create_file_unixpath(connection_struct *conn,
 				     uint32_t create_options,
 				     uint32_t file_attributes,
 				     uint32_t oplock_request,
-				     struct smb2_lease *lease,
+				     const struct smb2_lease *lease,
 				     uint64_t allocation_size,
 				     uint32_t private_flags,
 				     struct security_descriptor *sd,
@@ -4971,6 +4957,7 @@ static NTSTATUS create_file_unixpath(connection_struct *conn,
 				     files_struct **result,
 				     int *pinfo)
 {
+	struct smb2_lease none_lease;
 	int info = FILE_WAS_OPENED;
 	files_struct *base_fsp = NULL;
 	files_struct *fsp = NULL;
@@ -5024,9 +5011,11 @@ static NTSTATUS create_file_unixpath(connection_struct *conn,
 				&epoch);
 		if (NT_STATUS_EQUAL(status, NT_STATUS_OPLOCK_NOT_GRANTED)) {
 			/* Dynamic share file. No leases and update epoch... */
-			lease->lease_state = SMB2_LEASE_NONE;
-			lease->lease_epoch = epoch;
-			lease->lease_version = version;
+			none_lease = *lease;
+			none_lease.lease_state = SMB2_LEASE_NONE;
+			none_lease.lease_epoch = epoch;
+			none_lease.lease_version = version;
+			lease = &none_lease;
 		} else if (!NT_STATUS_IS_OK(status)) {
 			goto fail;
 		}
@@ -5510,7 +5499,7 @@ NTSTATUS create_file_default(connection_struct *conn,
 			     uint32_t create_options,
 			     uint32_t file_attributes,
 			     uint32_t oplock_request,
-			     struct smb2_lease *lease,
+			     const struct smb2_lease *lease,
 			     uint64_t allocation_size,
 			     uint32_t private_flags,
 			     struct security_descriptor *sd,
diff --git a/source3/smbd/proto.h b/source3/smbd/proto.h
index 0fde9b78fb0..5947d9ab6f2 100644
--- a/source3/smbd/proto.h
+++ b/source3/smbd/proto.h
@@ -703,7 +703,7 @@ NTSTATUS create_file_default(connection_struct *conn,
 			     uint32_t create_options,
 			     uint32_t file_attributes,
 			     uint32_t oplock_request,
-			     struct smb2_lease *lease,
+			     const struct smb2_lease *lease,
 			     uint64_t allocation_size,
 			     uint32_t private_flags,
 			     struct security_descriptor *sd,
diff --git a/source3/smbd/vfs.c b/source3/smbd/vfs.c
index 51a4aeb0f22..b8b482e758e 100644
--- a/source3/smbd/vfs.c
+++ b/source3/smbd/vfs.c
@@ -1613,7 +1613,7 @@ NTSTATUS smb_vfs_call_create_file(struct vfs_handle_struct *handle,
 				  uint32_t create_options,
 				  uint32_t file_attributes,
 				  uint32_t oplock_request,
-				  struct smb2_lease *lease,
+				  const struct smb2_lease *lease,
 				  uint64_t allocation_size,
 				  uint32_t private_flags,
 				  struct security_descriptor *sd,


-- 
Samba Shared Repository



More information about the samba-cvs mailing list