From: Ralph Boehme Date: Tue, 13 Oct 2020 12:38:28 +0000 (+0200) Subject: smbd: pass a dirfsp to fd_open() and rename it to fd_openat() X-Git-Tag: samba-4.14.0rc1~381 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=abc00b959be9ba5e6ca7535405866d771e76bfb3;p=thirdparty%2Fsamba.git smbd: pass a dirfsp to fd_open() and rename it to fd_openat() For now no change in behaviour as all callers still pass conn->cwd_fsp. This just prepared fd_openat() to deal with real dirfsp's pass by callers later on when adding calls to fd_openat(dirfspm ...) in the directory enumeration loop. Signed-off-by: Ralph Boehme Reviewed-by: Jeremy Allison --- diff --git a/source3/smbd/durable.c b/source3/smbd/durable.c index 12a7a6ae84a..d905c7dd552 100644 --- a/source3/smbd/durable.c +++ b/source3/smbd/durable.c @@ -813,7 +813,7 @@ NTSTATUS vfs_default_durable_reconnect(struct connection_struct *conn, flags = O_RDONLY; } - status = fd_open(fsp, flags, 0); + status = fd_openat(conn->cwd_fsp, fsp->fsp_name, fsp, flags, 0); if (!NT_STATUS_IS_OK(status)) { TALLOC_FREE(lck); DEBUG(1, ("vfs_default_durable_reconnect: failed to open " diff --git a/source3/smbd/files.c b/source3/smbd/files.c index cbe09155ab3..b53c5e92433 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -233,7 +233,7 @@ NTSTATUS open_internal_dirfsp(connection_struct *conn, #ifdef O_DIRECTORY open_flags |= O_DIRECTORY; #endif - status = fd_open(fsp, open_flags, 0); + status = fd_openat(conn->cwd_fsp, fsp->fsp_name, fsp, open_flags, 0); 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/open.c b/source3/smbd/open.c index 7f0163ffb7b..bf96584bac9 100644 --- a/source3/smbd/open.c +++ b/source3/smbd/open.c @@ -825,12 +825,13 @@ static int non_widelink_open(files_struct *fsp, fd support routines - attempt to do a dos_open. ****************************************************************************/ -NTSTATUS fd_open(files_struct *fsp, - int flags, - mode_t mode) +NTSTATUS fd_openat(const struct files_struct *dirfsp, + struct smb_filename *smb_fname, + files_struct *fsp, + int flags, + mode_t mode) { struct connection_struct *conn = fsp->conn; - struct smb_filename *smb_fname = fsp->fsp_name; NTSTATUS status = NT_STATUS_OK; int fd; @@ -1095,7 +1096,7 @@ static NTSTATUS fd_open_atomic(files_struct *fsp, /* * We're not creating the file, just pass through. */ - status = fd_open(fsp, flags, mode); + status = fd_openat(fsp->conn->cwd_fsp, fsp->fsp_name, fsp, flags, mode); *file_created = false; return status; } @@ -1104,7 +1105,7 @@ static NTSTATUS fd_open_atomic(files_struct *fsp, /* * Fail if already exists, just pass through. */ - status = fd_open(fsp, flags, mode); + status = fd_openat(fsp->conn->cwd_fsp, fsp->fsp_name, fsp, flags, mode); /* * Here we've opened with O_CREAT|O_EXCL. If that went @@ -1144,7 +1145,7 @@ static NTSTATUS fd_open_atomic(files_struct *fsp, retry_status = NT_STATUS_OBJECT_NAME_COLLISION; } - status = fd_open(fsp, curr_flags, mode); + status = fd_openat(fsp->conn->cwd_fsp, fsp->fsp_name, fsp, curr_flags, mode); if (NT_STATUS_IS_OK(status)) { *file_created = !file_existed; return NT_STATUS_OK; @@ -1163,7 +1164,7 @@ static NTSTATUS fd_open_atomic(files_struct *fsp, curr_flags = flags | O_EXCL; } - status = fd_open(fsp, curr_flags, mode); + status = fd_openat(fsp->conn->cwd_fsp, fsp->fsp_name, fsp, curr_flags, mode); } *file_created = (NT_STATUS_IS_OK(status) && !file_existed); @@ -4496,7 +4497,7 @@ static NTSTATUS open_directory(connection_struct *conn, flags |= O_DIRECTORY; #endif - status = fd_open(fsp, flags, 0); + status = fd_openat(conn->cwd_fsp, fsp->fsp_name, fsp, flags, 0); if (!NT_STATUS_IS_OK(status)) { DBG_INFO("Could not open fd for " "%s (%s)\n", diff --git a/source3/smbd/proto.h b/source3/smbd/proto.h index b768e81afe9..4d7f0488ab4 100644 --- a/source3/smbd/proto.h +++ b/source3/smbd/proto.h @@ -713,8 +713,10 @@ NTSTATUS check_parent_access(struct connection_struct *conn, struct files_struct *dirfsp, struct smb_filename *smb_fname, uint32_t access_mask); -NTSTATUS fd_open(files_struct *fsp, - int flags, mode_t mode); +NTSTATUS fd_openat(const struct files_struct *dirfsp, + struct smb_filename *smb_fname, + 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, diff --git a/source3/smbd/smb2_query_directory.c b/source3/smbd/smb2_query_directory.c index ba10f925a46..1eb2b395d4c 100644 --- a/source3/smbd/smb2_query_directory.c +++ b/source3/smbd/smb2_query_directory.c @@ -387,7 +387,7 @@ static struct tevent_req *smbd_smb2_query_directory_send(TALLOC_CTX *mem_ctx, #ifdef O_DIRECTORY flags |= O_DIRECTORY; #endif - status = fd_open(fsp, flags, 0); + status = fd_openat(conn->cwd_fsp, fsp->fsp_name, fsp, flags, 0); if (tevent_req_nterror(req, status)) { return tevent_req_post(req, ev); }