From: Ralph Boehme Date: Mon, 23 Mar 2020 10:36:42 +0000 (+0100) Subject: smbd: add create_internal_dirfsp_at() X-Git-Tag: ldb-2.2.0~1238 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=974ea2ce349627732bfc683598d148da20a5b118;p=thirdparty%2Fsamba.git smbd: add create_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 a9e63192f61..310eab374a6 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -165,6 +165,55 @@ NTSTATUS file_new(struct smb_request *req, connection_struct *conn, return NT_STATUS_OK; } +/* + * 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. + */ +NTSTATUS create_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; + NTSTATUS status; + + SMB_ASSERT(dirfsp == dirfsp->conn->cwd_fsp); + + status = file_new(NULL, conn, &fsp); + if (!NT_STATUS_IS_OK(status)) { + return status; + } + + status = fsp_set_smb_fname(fsp, smb_dname); + if (!NT_STATUS_IS_OK(status)) { + file_free(NULL, fsp); + return status; + } + + if (!VALID_STAT(fsp->fsp_name->st)) { + status = vfs_stat_fsp(fsp); + if (!NT_STATUS_IS_OK(status)) { + return status; + } + } + + if (!S_ISDIR(fsp->fsp_name->st.st_ex_mode)) { + DBG_ERR("%s is not a directory!\n", + smb_fname_str_dbg(smb_dname)); + file_free(NULL, fsp); + return NT_STATUS_NOT_A_DIRECTORY; + } + + fsp->file_id = vfs_file_id_from_sbuf(conn, &fsp->fsp_name->st); + fsp->access_mask = FILE_LIST_DIRECTORY; + fsp->is_directory = true; + + *_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 9f77c956e13..6bfba095210 100644 --- a/source3/smbd/proto.h +++ b/source3/smbd/proto.h @@ -419,6 +419,15 @@ NTSTATUS fsp_set_smb_fname(struct files_struct *fsp, const struct smb_filename *smb_fname_in); size_t fsp_fullbasepath(struct files_struct *fsp, char *buf, size_t buflen); +NTSTATUS create_internal_dirfsp_at(connection_struct *conn, + struct files_struct *dirfsp, + 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); + /* The following definitions come from smbd/ipc.c */ NTSTATUS nt_status_np_pipe(NTSTATUS status);