From 985c1be5ccf40d0f5c85f42bc0d9bd0a15a86b59 Mon Sep 17 00:00:00 2001 From: Ralph Boehme Date: Wed, 25 Nov 2020 12:29:40 +0100 Subject: [PATCH] smbd: use vfs_stat() in more places This replaces the code in a bunch of places where we choose between stat() and lstat() based on req->posix_pathname. The new code inside vfs_stat() is based on checking the smb_fname flag SMB_FILENAME_POSIX_PATH. req->posix_pathname is inherited from the global POSIX pathnames state and the smb_fname flags is also inherited from that indirectly via the UCF flags. Tl;dr: no change in behaviour. :) Signed-off-by: Ralph Boehme Reviewed-by: Jeremy Allison --- source3/modules/vfs_acl_tdb.c | 7 +----- source3/modules/vfs_default.c | 6 +----- source3/modules/vfs_streams_xattr.c | 6 +----- source3/smbd/filename.c | 28 ++++-------------------- source3/smbd/open.c | 7 +----- source3/smbd/reply.c | 33 +++++++---------------------- source3/smbd/smb2_setinfo.c | 31 ++++++++------------------- source3/smbd/trans2.c | 7 +----- 8 files changed, 26 insertions(+), 99 deletions(-) diff --git a/source3/modules/vfs_acl_tdb.c b/source3/modules/vfs_acl_tdb.c index 57c2439a4bd..2fb03c03efc 100644 --- a/source3/modules/vfs_acl_tdb.c +++ b/source3/modules/vfs_acl_tdb.c @@ -261,12 +261,7 @@ static int unlinkat_acl_tdb(vfs_handle_struct *handle, goto out; } - if (smb_fname_tmp->flags & SMB_FILENAME_POSIX_PATH) { - ret = SMB_VFS_LSTAT(handle->conn, smb_fname_tmp); - } else { - ret = SMB_VFS_STAT(handle->conn, smb_fname_tmp); - } - + ret = vfs_stat(handle->conn, smb_fname_tmp); if (ret == -1) { goto out; } diff --git a/source3/modules/vfs_default.c b/source3/modules/vfs_default.c index 074de0960c0..21075d725a9 100644 --- a/source3/modules/vfs_default.c +++ b/source3/modules/vfs_default.c @@ -3064,11 +3064,7 @@ static NTSTATUS vfswrap_streaminfo(vfs_handle_struct *handle, return NT_STATUS_NO_MEMORY; } - if (smb_fname_cp->flags & SMB_FILENAME_POSIX_PATH) { - ret = SMB_VFS_LSTAT(handle->conn, smb_fname_cp); - } else { - ret = SMB_VFS_STAT(handle->conn, smb_fname_cp); - } + ret = vfs_stat(handle->conn, smb_fname_cp); sbuf = smb_fname_cp->st; TALLOC_FREE(smb_fname_cp); } diff --git a/source3/modules/vfs_streams_xattr.c b/source3/modules/vfs_streams_xattr.c index 1d3f3ca14a7..47580a7a53d 100644 --- a/source3/modules/vfs_streams_xattr.c +++ b/source3/modules/vfs_streams_xattr.c @@ -226,11 +226,7 @@ static int streams_xattr_fstat(vfs_handle_struct *handle, files_struct *fsp, return -1; } - if (smb_fname_base->flags & SMB_FILENAME_POSIX_PATH) { - ret = SMB_VFS_LSTAT(handle->conn, smb_fname_base); - } else { - ret = SMB_VFS_STAT(handle->conn, smb_fname_base); - } + ret = vfs_stat(handle->conn, smb_fname_base); *sbuf = smb_fname_base->st; if (ret == -1) { diff --git a/source3/smbd/filename.c b/source3/smbd/filename.c index 937fc3c0f63..748d1effc16 100644 --- a/source3/smbd/filename.c +++ b/source3/smbd/filename.c @@ -662,11 +662,7 @@ static NTSTATUS unix_convert_step_stat(struct uc_state *state) DBG_DEBUG("smb_fname [%s]\n", smb_fname_str_dbg(state->smb_fname)); - if (state->posix_pathnames) { - ret = SMB_VFS_LSTAT(state->conn, state->smb_fname); - } else { - ret = SMB_VFS_STAT(state->conn, state->smb_fname); - } + ret = vfs_stat(state->conn, state->smb_fname); if (ret == 0) { /* * It exists. it must either be a directory or this must @@ -826,12 +822,7 @@ static NTSTATUS unix_convert_step_stat(struct uc_state *state) * if it exists. JRA. */ - if (state->posix_pathnames) { - ret = SMB_VFS_LSTAT(state->conn, state->smb_fname); - } else { - ret = SMB_VFS_STAT(state->conn, state->smb_fname); - } - + ret = vfs_stat(state->conn, state->smb_fname); if (ret != 0) { SET_STAT_INVALID(state->smb_fname->st); } @@ -1177,12 +1168,7 @@ NTSTATUS unix_convert(TALLOC_CTX *mem_ctx, * there was one) and be done! */ - if (state->posix_pathnames) { - ret = SMB_VFS_LSTAT(state->conn, state->smb_fname); - } else { - ret = SMB_VFS_STAT(state->conn, state->smb_fname); - } - + ret = vfs_stat(state->conn, state->smb_fname); if (ret == 0) { status = check_for_dot_component(state->smb_fname); if (!NT_STATUS_IS_OK(status)) { @@ -1267,13 +1253,7 @@ NTSTATUS unix_convert(TALLOC_CTX *mem_ctx, status = NT_STATUS_NO_MEMORY; goto fail; } - if (state->posix_pathnames) { - ret = SMB_VFS_LSTAT(state->conn, - parent_fname); - } else { - ret = SMB_VFS_STAT(state->conn, - parent_fname); - } + ret = vfs_stat(state->conn, parent_fname); TALLOC_FREE(parent_fname); if (ret == -1) { if (errno == ENOTDIR || diff --git a/source3/smbd/open.c b/source3/smbd/open.c index 857643ddacf..e05bd9ace35 100644 --- a/source3/smbd/open.c +++ b/source3/smbd/open.c @@ -6159,12 +6159,7 @@ NTSTATUS create_file_default(connection_struct *conn, status = NT_STATUS_NOT_A_DIRECTORY; goto fail; } - if (req != NULL && req->posix_pathnames) { - ret = SMB_VFS_LSTAT(conn, smb_fname); - } else { - ret = SMB_VFS_STAT(conn, smb_fname); - } - + ret = vfs_stat(conn, smb_fname); if (ret == 0 && VALID_STAT_OF_DIR(smb_fname->st)) { status = NT_STATUS_FILE_IS_A_DIRECTORY; goto fail; diff --git a/source3/smbd/reply.c b/source3/smbd/reply.c index 6fcca84b496..43e23635ba9 100644 --- a/source3/smbd/reply.c +++ b/source3/smbd/reply.c @@ -1826,11 +1826,7 @@ void reply_search(struct smb_request *req) * so FILE_OPEN disposition knows the directory * exists. */ - if (req->posix_pathnames) { - ret = SMB_VFS_LSTAT(conn, smb_dname); - } else { - ret = SMB_VFS_STAT(conn, smb_dname); - } + ret = vfs_stat(conn, smb_dname); if (ret == -1) { nt_status = map_nt_error_from_unix(errno); reply_nterror(req, nt_status); @@ -3138,7 +3134,6 @@ static NTSTATUS do_unlink(connection_struct *conn, uint32_t dirtype_orig = dirtype; NTSTATUS status; int ret; - bool posix_paths = (req != NULL && req->posix_pathnames); struct smb2_create_blobs *posx = NULL; DEBUG(10,("do_unlink: %s, dirtype = %d\n", @@ -3149,11 +3144,7 @@ static NTSTATUS do_unlink(connection_struct *conn, return NT_STATUS_MEDIA_WRITE_PROTECTED; } - if (posix_paths) { - ret = SMB_VFS_LSTAT(conn, smb_fname); - } else { - ret = SMB_VFS_STAT(conn, smb_fname); - } + ret = vfs_stat(conn, smb_fname); if (ret != 0) { return map_nt_error_from_unix(errno); } @@ -3211,7 +3202,7 @@ static NTSTATUS do_unlink(connection_struct *conn, return NT_STATUS_OBJECT_NAME_INVALID; #endif /* JRATEST */ - if (posix_paths) { + if (smb_fname->flags & SMB_FILENAME_POSIX_PATH) { status = make_smb2_posix_create_ctx( talloc_tos(), &posx, 0777); if (!NT_STATUS_IS_OK(status)) { @@ -7898,7 +7889,6 @@ NTSTATUS rename_internals(TALLOC_CTX *ctx, char *talloced = NULL; long offset = 0; int create_options = 0; - bool posix_pathnames = (req != NULL && req->posix_pathnames); struct smb2_create_blobs *posx = NULL; int rc; bool src_has_wild = false; @@ -7921,7 +7911,7 @@ NTSTATUS rename_internals(TALLOC_CTX *ctx, goto out; } - if (req != NULL && !req->posix_pathnames) { + if (!(smb_fname_src->flags & SMB_FILENAME_POSIX_PATH)) { /* * Check the wildcard mask *before* * unmangling. As mangling is done @@ -7955,7 +7945,7 @@ NTSTATUS rename_internals(TALLOC_CTX *ctx, } } - if (posix_pathnames) { + if (smb_fname_src->flags & SMB_FILENAME_POSIX_PATH) { status = make_smb2_posix_create_ctx(talloc_tos(), &posx, 0777); if (!NT_STATUS_IS_OK(status)) { DBG_WARNING("make_smb2_posix_create_ctx failed: %s\n", @@ -8017,11 +8007,8 @@ NTSTATUS rename_internals(TALLOC_CTX *ctx, } ZERO_STRUCT(smb_fname_src->st); - if (posix_pathnames) { - rc = SMB_VFS_LSTAT(conn, smb_fname_src); - } else { - rc = SMB_VFS_STAT(conn, smb_fname_src); - } + + rc = vfs_stat(conn, smb_fname_src); if (rc == -1) { status = map_nt_error_from_unix_common(errno); goto out; @@ -8193,11 +8180,7 @@ NTSTATUS rename_internals(TALLOC_CTX *ctx, smb_fname_dst->base_name = destname; ZERO_STRUCT(smb_fname_src->st); - if (posix_pathnames) { - SMB_VFS_LSTAT(conn, smb_fname_src); - } else { - SMB_VFS_STAT(conn, smb_fname_src); - } + vfs_stat(conn, smb_fname_src); status = openat_pathref_fsp(conn->cwd_fsp, smb_fname_src); if (NT_STATUS_EQUAL(status, NT_STATUS_STOPPED_ON_SYMLINK)) { diff --git a/source3/smbd/smb2_setinfo.c b/source3/smbd/smb2_setinfo.c index 83706b44c92..646e009a746 100644 --- a/source3/smbd/smb2_setinfo.c +++ b/source3/smbd/smb2_setinfo.c @@ -379,6 +379,7 @@ static struct tevent_req *smbd_smb2_setinfo_send(TALLOC_CTX *mem_ctx, connection_struct *conn = smb2req->tcon->compat; struct share_mode_lock *lck = NULL; NTSTATUS status; + int ret; req = tevent_req_create(mem_ctx, &state, struct smbd_smb2_setinfo_state); @@ -421,27 +422,14 @@ static struct tevent_req *smbd_smb2_setinfo_send(TALLOC_CTX *mem_ctx, * handle (returned from an NT SMB). NT5.0 seems * to do this call. JRA. */ - if (fsp->fsp_name->flags & SMB_FILENAME_POSIX_PATH) { - /* Always do lstat for UNIX calls. */ - if (SMB_VFS_LSTAT(conn, fsp->fsp_name)) { - DEBUG(3,("smbd_smb2_setinfo_send: " - "SMB_VFS_LSTAT of %s failed " - "(%s)\n", fsp_str_dbg(fsp), - strerror(errno))); - status = map_nt_error_from_unix(errno); - tevent_req_nterror(req, status); - return tevent_req_post(req, ev); - } - } else { - if (SMB_VFS_STAT(conn, fsp->fsp_name) != 0) { - DEBUG(3,("smbd_smb2_setinfo_send: " - "fileinfo of %s failed (%s)\n", - fsp_str_dbg(fsp), - strerror(errno))); - status = map_nt_error_from_unix(errno); - tevent_req_nterror(req, status); - return tevent_req_post(req, ev); - } + ret = vfs_stat(fsp->conn, fsp->fsp_name); + if (ret != 0) { + DBG_WARNING("vfs_stat() of %s failed (%s)\n", + fsp_str_dbg(fsp), + strerror(errno)); + status = map_nt_error_from_unix(errno); + tevent_req_nterror(req, status); + return tevent_req_post(req, ev); } } else if (fsp->print_file) { /* @@ -586,7 +574,6 @@ static struct tevent_req *smbd_smb2_setinfo_send(TALLOC_CTX *mem_ctx, struct file_quota_information info = {0}; SMB_NTQUOTA_STRUCT qt = {0}; enum ndr_err_code err; - int ret; if (!fsp->fake_file_handle) { tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER); diff --git a/source3/smbd/trans2.c b/source3/smbd/trans2.c index 6023f444660..a188641e347 100644 --- a/source3/smbd/trans2.c +++ b/source3/smbd/trans2.c @@ -2952,12 +2952,7 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd * so FILE_OPEN disposition knows the directory * exists. */ - if (req->posix_pathnames) { - ret = SMB_VFS_LSTAT(conn, smb_dname); - } else { - ret = SMB_VFS_STAT(conn, smb_dname); - } - + ret = vfs_stat(conn, smb_dname); if (ret == -1) { ntstatus = map_nt_error_from_unix(errno); reply_nterror(req, ntstatus); -- 2.47.3