From: Ralph Boehme Date: Mon, 16 Mar 2020 17:53:15 +0000 (+0100) Subject: smbd: add open_internal_dirfsp_at() X-Git-Tag: ldb-2.2.0~1232 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=45f62cece038a40892b2a567969313fac75e39c2;p=thirdparty%2Fsamba.git smbd: add open_internal_dirfsp_at() Signed-off-by: Ralph Boehme Reviewed-by: Jeremy Allison --- diff --git a/source3/smbd/files.c b/source3/smbd/files.c index 310eab374a6..433c9b00866 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -169,7 +169,7 @@ NTSTATUS file_new(struct smb_request *req, connection_struct *conn, * Create an internal fsp for an *existing* directory. * * This should only be used by callers in the VFS that need to control the - * opening of the directory. + * opening of the directory. Otherwise use open_internal_dirfsp_at(). */ NTSTATUS create_internal_dirfsp_at(connection_struct *conn, struct files_struct *dirfsp, @@ -214,6 +214,42 @@ NTSTATUS create_internal_dirfsp_at(connection_struct *conn, return NT_STATUS_OK; } +/* + * Open an internal fsp for an *existing* directory. + */ +NTSTATUS open_internal_dirfsp_at(connection_struct *conn, + struct files_struct *dirfsp, + const struct smb_filename *smb_dname, + struct files_struct **_fsp) +{ + struct files_struct *fsp = NULL; + int open_flags = O_RDONLY; + NTSTATUS status; + + SMB_ASSERT(dirfsp == dirfsp->conn->cwd_fsp); + + status = create_internal_dirfsp_at(conn, dirfsp, smb_dname, &fsp); + if (!NT_STATUS_IS_OK(status)) { + return status; + } + +#ifdef O_DIRECTORY + open_flags |= O_DIRECTORY; +#endif + status = fd_open(conn, 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), + nt_errstr(status)); + file_free(NULL, fsp); + return status; + } + + + *_fsp = fsp; + return NT_STATUS_OK; +} + /**************************************************************************** Close all open files for a connection. ****************************************************************************/ diff --git a/source3/smbd/proto.h b/source3/smbd/proto.h index 6bfba095210..c79e82fb69d 100644 --- a/source3/smbd/proto.h +++ b/source3/smbd/proto.h @@ -424,9 +424,10 @@ NTSTATUS create_internal_dirfsp_at(connection_struct *conn, const struct smb_filename *smb_dname, struct files_struct **_fsp); -NTSTATUS open_internal_dir_fsp(connection_struct *conn, - const struct smb_filename *smb_dname, - struct files_struct **_fsp); +NTSTATUS open_internal_dirfsp_at(connection_struct *conn, + struct files_struct *dirfsp, + const struct smb_filename *smb_dname, + struct files_struct **_fsp); /* The following definitions come from smbd/ipc.c */