From: Volker Lendecke Date: Thu, 2 Jan 2025 17:14:43 +0000 (+0100) Subject: smbd: Simplify delete_all_streams() X-Git-Tag: tdb-1.4.13~96 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=09f49fb56a4d89283f4cf12e4bacd043b14917b2;p=thirdparty%2Fsamba.git smbd: Simplify delete_all_streams() In our callers we have the dirfsp around, use that and avoid references to conn->cwd_fsp and deep path-based operations Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison --- diff --git a/source3/smbd/close.c b/source3/smbd/close.c index 3a5f49550fb..c5b6c622d70 100644 --- a/source3/smbd/close.c +++ b/source3/smbd/close.c @@ -150,17 +150,21 @@ static NTSTATUS check_magic(struct files_struct *fsp) Delete all streams ****************************************************************************/ -NTSTATUS delete_all_streams(connection_struct *conn, - const struct smb_filename *smb_fname) +NTSTATUS delete_all_streams(struct files_struct *fsp, + struct files_struct *dirfsp, + struct smb_filename *fsp_atname) { + struct smb_filename *smb_fname = fsp->fsp_name; struct stream_struct *stream_info = NULL; unsigned int i; unsigned int num_streams = 0; TALLOC_CTX *frame = talloc_stackframe(); NTSTATUS status; - status = vfs_fstreaminfo(smb_fname->fsp, talloc_tos(), - &num_streams, &stream_info); + status = vfs_fstreaminfo(fsp, + talloc_tos(), + &num_streams, + &stream_info); if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_IMPLEMENTED)) { DEBUG(10, ("no streams around\n")); @@ -190,25 +194,23 @@ NTSTATUS delete_all_streams(connection_struct *conn, continue; } - status = synthetic_pathref(talloc_tos(), - conn->cwd_fsp, - smb_fname->base_name, - stream_info[i].name, - NULL, - smb_fname->twrp, - (smb_fname->flags & - ~SMB_FILENAME_POSIX_PATH), - &smb_fname_stream); + smb_fname_stream = synthetic_smb_fname( + talloc_tos(), + fsp_atname->base_name, + stream_info[i].name, + NULL, + smb_fname->twrp, + (smb_fname->flags & ~SMB_FILENAME_POSIX_PATH)); if (!NT_STATUS_IS_OK(status)) { DEBUG(0, ("talloc_aprintf failed\n")); status = NT_STATUS_NO_MEMORY; goto fail; } - res = SMB_VFS_UNLINKAT(conn, - conn->cwd_fsp, - smb_fname_stream, - 0); + res = SMB_VFS_UNLINKAT(dirfsp->conn, + dirfsp, + smb_fname_stream, + 0); if (res == -1) { status = map_nt_error_from_unix(errno); @@ -567,7 +569,9 @@ static NTSTATUS close_remove_share_mode(files_struct *fsp, if ((conn->fs_capabilities & FILE_NAMED_STREAMS) && !fsp_is_alternate_stream(fsp)) { - status = delete_all_streams(conn, fsp->fsp_name); + status = delete_all_streams(fsp, + parent_fname->fsp, + base_fname); if (!NT_STATUS_IS_OK(status)) { DEBUG(5, ("delete_all_streams failed: %s\n", @@ -1304,7 +1308,9 @@ static NTSTATUS close_directory(struct smb_request *req, files_struct *fsp, if ((fsp->conn->fs_capabilities & FILE_NAMED_STREAMS) && !is_ntfs_stream_smb_fname(fsp->fsp_name)) { - status = delete_all_streams(fsp->conn, fsp->fsp_name); + status = delete_all_streams(fsp, + parent_fname->fsp, + base_fname); if (!NT_STATUS_IS_OK(status)) { DEBUG(5, ("delete_all_streams failed: %s\n", nt_errstr(status))); diff --git a/source3/smbd/open.c b/source3/smbd/open.c index 6151441c77c..3982c39ed47 100644 --- a/source3/smbd/open.c +++ b/source3/smbd/open.c @@ -4185,7 +4185,9 @@ static NTSTATUS open_file_ntcreate(connection_struct *conn, if (!new_file_created && clear_ads(create_disposition) && !fsp_is_alternate_stream(fsp)) { - status = delete_all_streams(conn, smb_fname); + status = delete_all_streams(fsp, + parent_dir_fname->fsp, + smb_fname_atname); if (!NT_STATUS_IS_OK(status)) { lck_state.cleanup_fn = open_ntcreate_lock_cleanup_entry; diff --git a/source3/smbd/proto.h b/source3/smbd/proto.h index 12f41e7172c..49c3b319da5 100644 --- a/source3/smbd/proto.h +++ b/source3/smbd/proto.h @@ -130,8 +130,9 @@ void msg_close_file(struct messaging_context *msg_ctx, uint32_t msg_type, struct server_id server_id, DATA_BLOB *data); -NTSTATUS delete_all_streams(connection_struct *conn, - const struct smb_filename *smb_fname); +NTSTATUS delete_all_streams(struct files_struct *fsp, + struct files_struct *dirfsp, + struct smb_filename *fsp_atname); NTSTATUS recursive_rmdir(TALLOC_CTX *ctx, connection_struct *conn, struct smb_filename *smb_dname);