From: Jeremy Allison Date: Fri, 5 Aug 2022 19:16:44 +0000 (-0700) Subject: s3: smbd: Add new function check_path_syntax_smb2_msdfs() for SMB2 MSDFS paths. X-Git-Tag: talloc-2.4.0~1468 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=bcba5502282eb6dcc346d7c63aa3218cda2f9bb0;p=thirdparty%2Fsamba.git s3: smbd: Add new function check_path_syntax_smb2_msdfs() for SMB2 MSDFS paths. #ifdef'ed out as static and not yet used. We can't just call check_path_syntax() on these as they are of the form hostname\share[\extrapath] (where [\extrapath] is optional). hostname here can be an IPv6 ':' separated address, which check_path_syntax() fails on due to the streamname processing. NB. This also has to cope with out existing (broken) libsmbclient libraries that sometimes set the DFS flag and then send a local pathname. Cope by just calling the normal check_path_syntax() on the whole pathname in that case. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15144 Signed-off-by: Jeremy Allison Reviewed-by: Ralph Boehme --- diff --git a/source3/smbd/smb2_reply.c b/source3/smbd/smb2_reply.c index 870c3bcb898..6052f94354a 100644 --- a/source3/smbd/smb2_reply.c +++ b/source3/smbd/smb2_reply.c @@ -243,6 +243,44 @@ NTSTATUS check_path_syntax_posix(char *path) return check_path_syntax_internal(path, true); } +#if 0 +/**************************************************************************** + Check the path for an SMB2 DFS path. + SMB2 DFS paths look like hostname\share (followed by a possible \extrapath. + Path returned from here must look like: + hostname/share (followed by a possible /extrapath). +****************************************************************************/ + +static NTSTATUS check_path_syntax_smb2_msdfs(char *path) +{ + char *share = NULL; + char *remaining_path = NULL; + /* No SMB2 names can start with '\\' */ + if (path[0] == '\\') { + return NT_STATUS_OBJECT_NAME_INVALID; + } + /* + * smbclient libraries sometimes set the DFS flag and send + * local pathnames. Cope with this by just calling + * check_path_syntax() on the whole path if it doesn't + * look like a DFS path, similar to what parse_dfs_path() does. + */ + /* servername should be at path[0] */ + share = strchr(path, '\\'); + if (share == NULL) { + return check_path_syntax(path); + } + *share++ = '/'; + remaining_path = strchr(share, '\\'); + if (remaining_path == NULL) { + /* Only hostname\share. We're done. */ + return NT_STATUS_OK; + } + *remaining_path++ = '/'; + return check_path_syntax(remaining_path); +} +#endif + /**************************************************************************** Pull a string and check the path allowing a wildcard - provide for error return. Passes in posix flag.