From 03660778f07879baa31f9bd47d89db58a0b2718b Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 16 May 2023 11:13:35 +0200 Subject: [PATCH] smbd: Lift up conn->cwd from openat_pathref_dirfsp_nosymlink() The goal of this patch is to make the next patches smaller. Next patches will also make openat_pathref_dirfsp_nosymlink() open real files, not only directories. Signed-off-by: Volker Lendecke Reviewed-by: Ralph Boehme --- source3/smbd/files.c | 50 ++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 14 deletions(-) diff --git a/source3/smbd/files.c b/source3/smbd/files.c index 7092d10d9a8..aa6c66a3d81 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -800,17 +800,18 @@ static bool full_path_extend(char **dir, const char *atname) return (*dir) != NULL; } -NTSTATUS openat_pathref_dirfsp_nosymlink( - TALLOC_CTX *mem_ctx, - struct connection_struct *conn, - const char *path_in, - NTTIME twrp, - bool posix, - struct smb_filename **_smb_fname, - size_t *unparsed, - char **substitute) +static NTSTATUS +openat_pathref_fsp_nosymlink_internal(TALLOC_CTX *mem_ctx, + struct connection_struct *conn, + struct files_struct *in_dirfsp, + const char *path_in, + NTTIME twrp, + bool posix, + struct smb_filename **_smb_fname, + size_t *unparsed, + char **substitute) { - struct files_struct *dirfsp = conn->cwd_fsp; + struct files_struct *dirfsp = in_dirfsp; struct smb_filename full_fname = { .base_name = NULL, .twrp = twrp, @@ -1099,14 +1100,14 @@ next: if (next != NULL) { struct files_struct *tmp = NULL; - if (dirfsp != conn->cwd_fsp) { + if (dirfsp != in_dirfsp) { fd_close(dirfsp); } tmp = dirfsp; dirfsp = fsp; - if (tmp == conn->cwd_fsp) { + if (tmp == in_dirfsp) { status = fsp_new(conn, conn, &fsp); if (!NT_STATUS_IS_OK(status)) { DBG_DEBUG("fsp_new() failed: %s\n", @@ -1123,7 +1124,7 @@ next: goto next; } - if (dirfsp != conn->cwd_fsp) { + if (dirfsp != in_dirfsp) { SMB_ASSERT(fsp_get_pathref_fd(dirfsp) != -1); fd_close(dirfsp); dirfsp->fsp_name = NULL; @@ -1187,7 +1188,7 @@ fail: fsp = NULL; } - if ((dirfsp != NULL) && (dirfsp != conn->cwd_fsp)) { + if ((dirfsp != NULL) && (dirfsp != in_dirfsp)) { SMB_ASSERT(fsp_get_pathref_fd(dirfsp) != -1); fd_close(dirfsp); dirfsp->fsp_name = NULL; @@ -1199,6 +1200,27 @@ fail: return status; } +NTSTATUS openat_pathref_dirfsp_nosymlink(TALLOC_CTX *mem_ctx, + struct connection_struct *conn, + const char *path_in, + NTTIME twrp, + bool posix, + struct smb_filename **_smb_fname, + size_t *unparsed, + char **substitute) +{ + NTSTATUS status = openat_pathref_fsp_nosymlink_internal(mem_ctx, + conn, + conn->cwd_fsp, + path_in, + twrp, + posix, + _smb_fname, + unparsed, + substitute); + return status; +} + void smb_fname_fsp_unlink(struct smb_filename *smb_fname) { talloc_set_destructor(smb_fname, NULL); -- 2.11.4.GIT