From: Jeremy Allison Date: Mon, 8 Aug 2022 18:16:17 +0000 (-0700) Subject: s3: smbd: Add dfs_filename_convert(). Simple wrapper around parse_dfs_path(). X-Git-Tag: talloc-2.4.0~1457 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=245d07ab84852b829c029496618e56782d070e83;p=thirdparty%2Fsamba.git s3: smbd: Add dfs_filename_convert(). Simple wrapper around parse_dfs_path(). Not yet used. This is what we will use to replace dfs_redirect() in the filename conversion code. Keep as a wrapper for now as we might want to add some error checking around the 'hostname' and 'service' returns. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15144 Signed-off-by: Jeremy Allison Reviewed-by: Ralph Boehme --- diff --git a/source3/smbd/msdfs.c b/source3/smbd/msdfs.c index fce887de9aa..1b66911faf0 100644 --- a/source3/smbd/msdfs.c +++ b/source3/smbd/msdfs.c @@ -902,6 +902,68 @@ static NTSTATUS dfs_path_lookup(TALLOC_CTX *ctx, return status; } +/***************************************************************** + Decides if a dfs pathname should be redirected or not. + If not, the pathname is converted to a tcon-relative local unix path + This is now a simple wrapper around parse_dfs_path() + as it does all the required checks. +*****************************************************************/ + +NTSTATUS dfs_filename_convert(TALLOC_CTX *ctx, + connection_struct *conn, + uint32_t ucf_flags, + const char *dfs_path_in, + char **pp_path_out) +{ + char *hostname = NULL; + char *servicename = NULL; + char *reqpath = NULL; + NTSTATUS status; + + status = parse_dfs_path(ctx, + conn, + dfs_path_in, + !conn->sconn->using_smb2, + &hostname, + &servicename, + &reqpath); + if (!NT_STATUS_IS_OK(status)) { + return status; + } + + /* + * Caller doesn't care about hostname + * or servicename. + */ + TALLOC_FREE(hostname); + TALLOC_FREE(servicename); + + /* + * If parse_dfs_path fell back to a local path + * after skipping hostname or servicename, ensure + * we still have called check_path_syntax() + * on the full returned local path. check_path_syntax() + * is idempotent so this is safe. + */ + if (ucf_flags & UCF_POSIX_PATHNAMES) { + status = check_path_syntax_posix(reqpath); + } else { + status = check_path_syntax(reqpath); + } + if (!NT_STATUS_IS_OK(status)) { + return status; + } + /* + * Previous (and current logic) just ignores + * the server, share components if a DFS + * path is sent on a non-DFS share except to + * check that they match an existing share. Should + * we tighten this up to return an error here ? + */ + *pp_path_out = reqpath; + return NT_STATUS_OK; +} + /***************************************************************** Decides if a dfs pathname should be redirected or not. If not, the pathname is converted to a tcon-relative local unix path diff --git a/source3/smbd/proto.h b/source3/smbd/proto.h index 33fc222311e..1c10849346e 100644 --- a/source3/smbd/proto.h +++ b/source3/smbd/proto.h @@ -560,6 +560,11 @@ bool remove_msdfs_link(const struct junction_map *jucn, struct junction_map *enum_msdfs_links(TALLOC_CTX *ctx, struct auth_session_info *session_info, size_t *p_num_jn); +NTSTATUS dfs_filename_convert(TALLOC_CTX *ctx, + connection_struct *conn, + uint32_t ucf_flags, + const char *dfs_path_in, + char **pp_path_out); NTSTATUS dfs_redirect(TALLOC_CTX *ctx, connection_struct *conn, const char *name_in,