From: Ralph Boehme Date: Tue, 14 Apr 2020 15:44:37 +0000 (+0200) Subject: s3: add full_path_from_dirfsp_atname() X-Git-Tag: samba-4.14.0rc1~386 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a14db893c19734f02d89f3b78f0ea75b79abbd72;p=thirdparty%2Fsamba.git s3: add full_path_from_dirfsp_atname() Signed-off-by: Ralph Boehme Reviewed-by: Jeremy Allison --- diff --git a/source3/include/proto.h b/source3/include/proto.h index 2ce632c5400..6e14ac42777 100644 --- a/source3/include/proto.h +++ b/source3/include/proto.h @@ -788,6 +788,10 @@ struct smb_filename *synthetic_smb_fname(TALLOC_CTX *mem_ctx, const SMB_STRUCT_STAT *psbuf, NTTIME twrp, uint32_t flags); +struct smb_filename *full_path_from_dirfsp_atname( + TALLOC_CTX *mem_ctx, + const struct files_struct *dirfsp, + const struct smb_filename *atname); struct smb_filename *synthetic_smb_fname_split(TALLOC_CTX *ctx, const char *fname, bool posix_path); diff --git a/source3/smbd/filename.c b/source3/smbd/filename.c index 716e10d9914..20e44a76204 100644 --- a/source3/smbd/filename.c +++ b/source3/smbd/filename.c @@ -2034,3 +2034,41 @@ NTSTATUS filename_convert_with_privilege(TALLOC_CTX *ctx, 0, pp_smb_fname); } + +/* + * Build the full path from a dirfsp and dirfsp relative name + */ +struct smb_filename *full_path_from_dirfsp_atname( + TALLOC_CTX *mem_ctx, + const struct files_struct *dirfsp, + const struct smb_filename *atname) +{ + struct smb_filename *fname = NULL; + char *path = NULL; + + if (dirfsp == dirfsp->conn->cwd_fsp || + ISDOT(dirfsp->fsp_name->base_name)) + { + path = talloc_strdup(mem_ctx, atname->base_name); + } else { + path = talloc_asprintf(mem_ctx, "%s/%s", + dirfsp->fsp_name->base_name, + atname->base_name); + } + if (path == NULL) { + return NULL; + } + + fname = synthetic_smb_fname(mem_ctx, + path, + atname->stream_name, + &atname->st, + atname->twrp, + atname->flags); + TALLOC_FREE(path); + if (fname == NULL) { + return NULL; + } + + return fname; +}