From: Volker Lendecke Date: Wed, 19 Mar 2025 16:45:59 +0000 (+0100) Subject: lib: Avoid a VFS_STAT call in "net vfs stream2adouble" X-Git-Tag: tevent-0.17.0~472 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2e0e47d45cea89bcc05247f2f4dbe609aef9b0ff;p=thirdparty%2Fsamba.git lib: Avoid a VFS_STAT call in "net vfs stream2adouble" Call filename_convert_dirfsp() in ad_unconvert, which takes care of proper symlink redirects. This will be used more in further patches. Signed-off-by: Volker Lendecke Reviewed-by: Anoop C S --- diff --git a/source3/lib/adouble.c b/source3/lib/adouble.c index fe1be8e6f36..f7f1a36c30c 100644 --- a/source3/lib/adouble.c +++ b/source3/lib/adouble.c @@ -1986,6 +1986,9 @@ NTSTATUS ad_unconvert(TALLOC_CTX *mem_ctx, struct ad_collect_state state; struct stream_struct *streams = NULL; struct smb_filename *adpath = NULL; + struct files_struct *dirfsp = NULL; + struct smb_filename *fullname = NULL; + struct smb_filename *relname = NULL; struct adouble *ad = NULL; unsigned int num_streams = 0; size_t to_convert = 0; @@ -2010,8 +2013,24 @@ NTSTATUS ad_unconvert(TALLOC_CTX *mem_ctx, TALLOC_FREE(mappings); } + status = filename_convert_dirfsp_rel(frame, + handle->conn, + handle->conn->cwd_fsp, + smb_fname->base_name, + 0, + smb_fname->twrp, + &dirfsp, + &fullname, + &relname); + if (!NT_STATUS_IS_OK(status)) { + return status; + } + if (!VALID_STAT(relname->st)) { + return NT_STATUS_OBJECT_NAME_NOT_FOUND; + } + status = ad_unconvert_get_streams( - handle, smb_fname, frame, &num_streams, &streams); + handle, fullname, frame, &num_streams, &streams); if (!NT_STATUS_IS_OK(status)) { goto out; } @@ -2035,7 +2054,7 @@ NTSTATUS ad_unconvert(TALLOC_CTX *mem_ctx, .adx_data_off = 0, }; - ret = adouble_path(frame, smb_fname, &adpath); + ret = adouble_path(frame, fullname, &adpath); if (ret != 0) { status = NT_STATUS_NO_MEMORY; goto out; @@ -2070,16 +2089,16 @@ NTSTATUS ad_unconvert(TALLOC_CTX *mem_ctx, for (i = 0; i < num_streams; i++) { status = ad_collect_one_stream( - handle, cmaps, smb_fname, &streams[i], ad, &state); + handle, cmaps, fullname, &streams[i], ad, &state); if (!NT_STATUS_IS_OK(status)) { goto out; } } - status = ad_unconvert_open_ad(frame, handle, smb_fname, adpath, &fsp); + status = ad_unconvert_open_ad(frame, handle, fullname, adpath, &fsp); if (!NT_STATUS_IS_OK(status)) { DBG_ERR("Failed to open adfile [%s]\n", - smb_fname_str_dbg(smb_fname)); + smb_fname_str_dbg(fullname)); goto out; } @@ -2097,7 +2116,7 @@ out: status = close_file_free(NULL, &fsp, NORMAL_CLOSE); if (!NT_STATUS_IS_OK(status)) { DBG_ERR("close_file_free() [%s] failed: %s\n", - smb_fname_str_dbg(smb_fname), + smb_fname_str_dbg(fullname), nt_errstr(status)); } } diff --git a/source3/utils/net_vfs.c b/source3/utils/net_vfs.c index da8a7dccce7..b468cf11b80 100644 --- a/source3/utils/net_vfs.c +++ b/source3/utils/net_vfs.c @@ -316,7 +316,6 @@ static bool do_unfruit(const char *path) struct smb_filename *smb_fname = NULL; char *p = NULL; bool converted; - int ret; NTSTATUS status; p = strrchr_m(path, '/'); @@ -336,15 +335,6 @@ static bool do_unfruit(const char *path) return false; } - ret = SMB_VFS_STAT(state.conn_tos->conn, smb_fname); - if (ret != 0) { - fprintf(stderr, "%s: %s\n", path, strerror(errno)); - if (state.c->opt_continue_on_error) { - return true; - } - return false; - } - status = ad_unconvert(state.mem_ctx, state.conn_tos->conn->vfs_handles, macos_string_replace_map,