From: Ralph Boehme Date: Thu, 21 Jan 2021 14:04:57 +0000 (+0100) Subject: smbd: add synthetic_pathref() X-Git-Url: http://git.samba.org/samba.git/?a=commitdiff_plain;h=d9f95b8cefe2d1c8020592434481025aa1045e2f;p=gd%2Fsamba-autobuild%2F.git smbd: add synthetic_pathref() Similar to synthetic_smb_fname(), but also opens a pathref fsp. Signed-off-by: Ralph Boehme Reviewed-by: Jeremy Allison --- diff --git a/source3/smbd/files.c b/source3/smbd/files.c index f60d5979f53..eceeaf2c6af 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -622,6 +622,58 @@ NTSTATUS move_smb_fname_fsp_link(struct smb_filename *smb_fname_dst, return NT_STATUS_OK; } +/** + * Create an smb_fname and open smb_fname->fsp pathref + **/ +NTSTATUS synthetic_pathref(TALLOC_CTX *mem_ctx, + struct files_struct *dirfsp, + const char *base_name, + const char *stream_name, + const SMB_STRUCT_STAT *psbuf, + NTTIME twrp, + uint32_t flags, + struct smb_filename **_smb_fname) +{ + struct smb_filename *smb_fname = NULL; + NTSTATUS status; + int ret; + + smb_fname = synthetic_smb_fname(mem_ctx, + base_name, + stream_name, + psbuf, + twrp, + flags); + if (smb_fname == NULL) { + return NT_STATUS_NO_MEMORY; + } + + if (!VALID_STAT(smb_fname->st)) { + ret = vfs_stat(dirfsp->conn, smb_fname); + if (ret != 0) { + DBG_ERR("stat [%s] failed: %s", + smb_fname_str_dbg(smb_fname), + strerror(errno)); + TALLOC_FREE(smb_fname); + return map_nt_error_from_unix(errno); + } + } + + status = openat_pathref_fsp(dirfsp, smb_fname); + if (NT_STATUS_EQUAL(status, NT_STATUS_STOPPED_ON_SYMLINK)) { + status = NT_STATUS_OBJECT_NAME_NOT_FOUND; + } + if (!NT_STATUS_IS_OK(status)) { + DBG_ERR("opening [%s] failed\n", + smb_fname_str_dbg(smb_fname)); + TALLOC_FREE(smb_fname); + return status; + } + + *_smb_fname = smb_fname; + return NT_STATUS_OK; +} + /**************************************************************************** Close all open files for a connection. ****************************************************************************/ diff --git a/source3/smbd/proto.h b/source3/smbd/proto.h index 2e181a94e91..a65c786c24d 100644 --- a/source3/smbd/proto.h +++ b/source3/smbd/proto.h @@ -468,6 +468,15 @@ void smb_fname_fsp_unlink(struct smb_filename *smb_fname); NTSTATUS move_smb_fname_fsp_link(struct smb_filename *smb_fname_dst, struct smb_filename *smb_fname_src); +NTSTATUS synthetic_pathref(TALLOC_CTX *mem_ctx, + struct files_struct *dirfsp, + const char *base_name, + const char *stream_name, + const SMB_STRUCT_STAT *psbuf, + NTTIME twrp, + uint32_t flags, + struct smb_filename **_smb_fname); + /* The following definitions come from smbd/ipc.c */ NTSTATUS nt_status_np_pipe(NTSTATUS status);