[SCM] Samba Shared Repository - branch master updated

Ralph Böhme slow at samba.org
Fri Jun 18 17:22:01 UTC 2021


The branch, master has been updated
       via  5ae2d4e4d0f s3: smbd: Optimization in non_widelink_open(). Don't need to vfs_ChDir(parent_dir_fname) if parent is "."
       via  c8e8633b98a s3: smbd: change_file_owner_to_parent_fsp(). Don't re-stat the pathref.
       via  bdc749ca7e2 s3: smbd: Change change_file_owner_to_parent() -> change_file_owner_to_parent_fsp().
       via  d6f6e5f7eb9 s3: smbd: Make change_file_owner_to_parent() static.
       via  f9022f658ba s3: smbd: change_dir_owner_to_parent_fsp(). Don't re-stat the pathref.
       via  610c3ff8744 s3: smbd: Change change_dir_owner_to_parent() -> change_dir_owner_to_parent_fsp().
       via  21d4aec1ad3 s3: smbd: open_directory(). Cleanup. We don't need 'int flags' here.
      from  4711ad9e813 util/charset: warn loudly on unexpected E2BIG

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


- Log -----------------------------------------------------------------
commit 5ae2d4e4d0fa3403bd571dbbbbf01cf84ddfa8f2
Author: Jeremy Allison <jra at samba.org>
Date:   Wed Jun 16 15:10:37 2021 -0700

    s3: smbd: Optimization in non_widelink_open(). Don't need to vfs_ChDir(parent_dir_fname) if parent is "."
    
    Save several system calls if we're operating at the root of the share.
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>
    
    Autobuild-User(master): Ralph Böhme <slow at samba.org>
    Autobuild-Date(master): Fri Jun 18 17:21:31 UTC 2021 on sn-devel-184

commit c8e8633b98a2d68e51b0b271bf6f0ee36ddb6283
Author: Jeremy Allison <jra at samba.org>
Date:   Wed Jun 9 16:43:04 2021 -0700

    s3: smbd: change_file_owner_to_parent_fsp(). Don't re-stat the pathref.
    
    Optimization now becomes clear. We already have a valid stat of the parent
    directory so we don't need to re-do a system call.
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit bdc749ca7e27b173f0c6e9f319d90097c5413b9a
Author: Jeremy Allison <jra at samba.org>
Date:   Wed Jun 9 12:28:42 2021 -0700

    s3: smbd: Change change_file_owner_to_parent() -> change_file_owner_to_parent_fsp().
    
    Same changes as for change_dir_owner_to_parent_fsp().
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit d6f6e5f7eb9943486ca6964777d981aeae7919b7
Author: Jeremy Allison <jra at samba.org>
Date:   Wed Jun 9 12:15:42 2021 -0700

    s3: smbd: Make change_file_owner_to_parent() static.
    
    Only used inside open.c.
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit f9022f658ba9925af894719197ad9cf224cac05a
Author: Jeremy Allison <jra at samba.org>
Date:   Wed Jun 9 16:40:08 2021 -0700

    s3: smbd: change_dir_owner_to_parent_fsp(). Don't re-stat the pathref.
    
    Optimization now becomes clear. We already have a valid stat of the parent
    directory so we don't need to re-do a system call.
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit 610c3ff8744eafea5f98d4e335660c77a3a3caa1
Author: Jeremy Allison <jra at samba.org>
Date:   Wed Jun 9 12:13:38 2021 -0700

    s3: smbd: Change change_dir_owner_to_parent() -> change_dir_owner_to_parent_fsp().
    
    Operate on handles only.
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit 21d4aec1ad34c0a34f5024ff9d8c11213ff030e9
Author: Jeremy Allison <jra at samba.org>
Date:   Wed Jun 9 12:01:03 2021 -0700

    s3: smbd: open_directory(). Cleanup. We don't need 'int flags' here.
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

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

Summary of changes:
 source3/smbd/open.c  | 131 +++++++++++++++++++++------------------------------
 source3/smbd/proto.h |   3 --
 2 files changed, 54 insertions(+), 80 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source3/smbd/open.c b/source3/smbd/open.c
index 3e48a9f35de..9527b939f88 100644
--- a/source3/smbd/open.c
+++ b/source3/smbd/open.c
@@ -703,16 +703,18 @@ static NTSTATUS non_widelink_open(const struct files_struct *dirfsp,
 			}
 		}
 
-		oldwd_fname = vfs_GetWd(talloc_tos(), conn);
-		if (oldwd_fname == NULL) {
-			status = map_nt_error_from_unix(errno);
-			goto out;
-		}
+		if (!ISDOT(parent_dir_fname->base_name)) {
+			oldwd_fname = vfs_GetWd(talloc_tos(), conn);
+			if (oldwd_fname == NULL) {
+				status = map_nt_error_from_unix(errno);
+				goto out;
+			}
 
-		/* Pin parent directory in place. */
-		if (vfs_ChDir(conn, parent_dir_fname) == -1) {
-			status = map_nt_error_from_unix(errno);
-			goto out;
+			/* Pin parent directory in place. */
+			if (vfs_ChDir(conn, parent_dir_fname) == -1) {
+				status = map_nt_error_from_unix(errno);
+				goto out;
+			}
 		}
 
 		/* Ensure the relative path is below the share. */
@@ -939,95 +941,79 @@ NTSTATUS fd_close(files_struct *fsp)
  Do this by fd if possible.
 ****************************************************************************/
 
-void change_file_owner_to_parent(connection_struct *conn,
-				 struct smb_filename *smb_fname_parent,
-				 files_struct *fsp)
+static void change_file_owner_to_parent_fsp(struct files_struct *parent_fsp,
+					    struct files_struct *fsp)
 {
 	int ret;
 
-	ret = SMB_VFS_STAT(conn, smb_fname_parent);
-	if (ret == -1) {
-		DEBUG(0,("change_file_owner_to_parent: failed to stat parent "
-			 "directory %s. Error was %s\n",
-			 smb_fname_str_dbg(smb_fname_parent),
-			 strerror(errno)));
-		return;
-	}
-
-	if (smb_fname_parent->st.st_ex_uid == fsp->fsp_name->st.st_ex_uid) {
+	if (parent_fsp->fsp_name->st.st_ex_uid == fsp->fsp_name->st.st_ex_uid) {
 		/* Already this uid - no need to change. */
-		DEBUG(10,("change_file_owner_to_parent: file %s "
-			"is already owned by uid %d\n",
+		DBG_DEBUG("file %s is already owned by uid %u\n",
 			fsp_str_dbg(fsp),
-			(int)fsp->fsp_name->st.st_ex_uid ));
-		return;
+			(unsigned int)fsp->fsp_name->st.st_ex_uid);
+                return;
 	}
 
 	become_root();
-	ret = SMB_VFS_FCHOWN(fsp, smb_fname_parent->st.st_ex_uid, (gid_t)-1);
+	ret = SMB_VFS_FCHOWN(fsp,
+			     parent_fsp->fsp_name->st.st_ex_uid,
+			     (gid_t)-1);
 	unbecome_root();
 	if (ret == -1) {
-		DEBUG(0,("change_file_owner_to_parent: failed to fchown "
-			 "file %s to parent directory uid %u. Error "
-			 "was %s\n", fsp_str_dbg(fsp),
-			 (unsigned int)smb_fname_parent->st.st_ex_uid,
-			 strerror(errno) ));
+		DBG_ERR("failed to fchown "
+			"file %s to parent directory uid %u. Error "
+			"was %s\n",
+			fsp_str_dbg(fsp),
+			(unsigned int)parent_fsp->fsp_name->st.st_ex_uid,
+			strerror(errno));
 	} else {
-		DEBUG(10,("change_file_owner_to_parent: changed new file %s to "
-			"parent directory uid %u.\n", fsp_str_dbg(fsp),
-			(unsigned int)smb_fname_parent->st.st_ex_uid));
+		DBG_DEBUG("changed new file %s to "
+			  "parent directory uid %u.\n",
+			  fsp_str_dbg(fsp),
+			  (unsigned int)parent_fsp->fsp_name->st.st_ex_uid);
 		/* Ensure the uid entry is updated. */
-		fsp->fsp_name->st.st_ex_uid = smb_fname_parent->st.st_ex_uid;
+		fsp->fsp_name->st.st_ex_uid =
+			parent_fsp->fsp_name->st.st_ex_uid;
 	}
 }
 
-static NTSTATUS change_dir_owner_to_parent(connection_struct *conn,
-					struct smb_filename *smb_fname_parent,
-					struct smb_filename *smb_dname,
-					SMB_STRUCT_STAT *psbuf)
+static NTSTATUS change_dir_owner_to_parent_fsp(struct files_struct *parent_fsp,
+					       struct files_struct *fsp)
 {
+	NTSTATUS status;
 	int ret;
 
-	ret = SMB_VFS_STAT(conn, smb_fname_parent);
-	if (ret == -1) {
-		DEBUG(0,("change_dir_owner_to_parent: failed to stat parent "
-			 "directory %s. Error was %s\n",
-			 smb_fname_str_dbg(smb_fname_parent),
-			 strerror(errno)));
-		return map_nt_error_from_unix(errno);
-	}
-
-	if (smb_fname_parent->st.st_ex_uid == smb_dname->st.st_ex_uid) {
+	if (parent_fsp->fsp_name->st.st_ex_uid == fsp->fsp_name->st.st_ex_uid) {
 		/* Already this uid - no need to change. */
-		DEBUG(10,("change_dir_owner_to_parent: directory %s "
-			"is already owned by uid %d\n",
-			smb_dname->base_name,
-			(int)smb_dname->st.st_ex_uid ));
+		DBG_DEBUG("directory %s is already owned by uid %u\n",
+			fsp_str_dbg(fsp),
+			(unsigned int)fsp->fsp_name->st.st_ex_uid);
 		return NT_STATUS_OK;
 	}
 
 	become_root();
-	ret = SMB_VFS_FCHOWN(smb_dname->fsp,
-			     smb_fname_parent->st.st_ex_uid,
+	ret = SMB_VFS_FCHOWN(fsp,
+			     parent_fsp->fsp_name->st.st_ex_uid,
 			     (gid_t)-1);
 	unbecome_root();
 	if (ret == -1) {
-		DEBUG(10,("change_dir_owner_to_parent: failed to chown "
+		status = map_nt_error_from_unix(errno);
+		DBG_ERR("failed to chown "
 			  "directory %s to parent directory uid %u. "
 			  "Error was %s\n",
-			  smb_dname->base_name,
-			  (unsigned int)smb_fname_parent->st.st_ex_uid,
-			  strerror(errno) ));
-		return map_nt_error_from_unix(errno);
+			  fsp_str_dbg(fsp),
+			  (unsigned int)parent_fsp->fsp_name->st.st_ex_uid,
+			  nt_errstr(status));
+		return status;
 	}
 
 	DBG_DEBUG("changed ownership of new "
 		  "directory %s to parent directory uid %u.\n",
-		  smb_dname->base_name,
-		  (unsigned int)smb_fname_parent->st.st_ex_uid);
+		  fsp_str_dbg(fsp),
+		  (unsigned int)parent_fsp->fsp_name->st.st_ex_uid);
 
 	/* Ensure the uid entry is updated. */
-	psbuf->st_ex_uid = smb_fname_parent->st.st_ex_uid;
+	fsp->fsp_name->st.st_ex_uid = parent_fsp->fsp_name->st.st_ex_uid;
 
 	return NT_STATUS_OK;
 }
@@ -1480,8 +1466,7 @@ static NTSTATUS open_file(files_struct *fsp,
 
 			/* Change the owner if required. */
 			if (lp_inherit_owner(SNUM(conn)) != INHERIT_OWNER_NO) {
-				change_file_owner_to_parent(conn,
-							    parent_dir,
+				change_file_owner_to_parent_fsp(parent_dir->fsp,
 							    fsp);
 				need_re_stat = true;
 			}
@@ -4344,9 +4329,8 @@ static NTSTATUS mkdir_internal(connection_struct *conn,
 
 	/* Change the owner if required. */
 	if (lp_inherit_owner(SNUM(conn)) != INHERIT_OWNER_NO) {
-		change_dir_owner_to_parent(conn, parent_dir_fname,
-					   smb_dname,
-					   &smb_dname->st);
+		change_dir_owner_to_parent_fsp(parent_dir_fname->fsp,
+					       fsp);
 		need_re_stat = true;
 	}
 
@@ -4386,7 +4370,6 @@ static NTSTATUS open_directory(connection_struct *conn,
 	NTSTATUS status;
 	struct timespec mtimespec;
 	int info = 0;
-	int flags;
 	bool ok;
 
 	if (is_ntfs_stream_smb_fname(smb_dname)) {
@@ -4580,13 +4563,7 @@ static NTSTATUS open_directory(connection_struct *conn,
 	*/
 	mtimespec = make_omit_timespec();
 
-	/* POSIX allows us to open a directory with O_RDONLY. */
-	flags = O_RDONLY;
-#ifdef O_DIRECTORY
-	flags |= O_DIRECTORY;
-#endif
-
-	status = reopen_from_fsp(fsp, flags, 0, NULL);
+	status = reopen_from_fsp(fsp, O_RDONLY|O_DIRECTORY, 0, NULL);
 	if (!NT_STATUS_IS_OK(status)) {
 		DBG_INFO("Could not open fd for%s (%s)\n",
 			 smb_fname_str_dbg(smb_dname),
diff --git a/source3/smbd/proto.h b/source3/smbd/proto.h
index e10ffa5110e..488a0745c9d 100644
--- a/source3/smbd/proto.h
+++ b/source3/smbd/proto.h
@@ -744,9 +744,6 @@ NTSTATUS fd_openat(const struct files_struct *dirfsp,
 		   files_struct *fsp,
 		   int flags, mode_t mode);
 NTSTATUS fd_close(files_struct *fsp);
-void change_file_owner_to_parent(connection_struct *conn,
-				 struct smb_filename *inherit_from_dir,
-				 files_struct *fsp);
 bool is_oplock_stat_open(uint32_t access_mask);
 bool is_lease_stat_open(uint32_t access_mask);
 NTSTATUS send_break_message(struct messaging_context *msg_ctx,


-- 
Samba Shared Repository



More information about the samba-cvs mailing list