From: Ralph Boehme Date: Thu, 30 Mar 2023 13:55:53 +0000 (+0200) Subject: s3: smbd: Add utility function smb1_strip_dfs_path(). X-Git-Tag: talloc-2.4.1~1220 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=66d7996dbcf84ded93d480eee7832543ca28580f;p=thirdparty%2Fsamba.git s3: smbd: Add utility function smb1_strip_dfs_path(). Signed-off-by: Ralph Boehme Signed-off-by: Jeremy Allison --- diff --git a/source3/smbd/proto.h b/source3/smbd/proto.h index 4e61dc426d8..61c4f89ca10 100644 --- a/source3/smbd/proto.h +++ b/source3/smbd/proto.h @@ -936,6 +936,9 @@ bool disk_quotas(connection_struct *conn, struct smb_filename *fname, NTSTATUS check_path_syntax(char *path); NTSTATUS check_path_syntax_posix(char *path); NTSTATUS check_path_syntax_smb2(char *path); +NTSTATUS smb1_strip_dfs_path(TALLOC_CTX *mem_ctx, + uint32_t *ucf_flags, + char **in_path); NTSTATUS smb2_strip_dfs_path(const char *in_path, const char **out_path); size_t srvstr_get_path(TALLOC_CTX *ctx, const char *inbuf, diff --git a/source3/smbd/smb1_reply.c b/source3/smbd/smb1_reply.c index 1041e4f843b..46da29e0277 100644 --- a/source3/smbd/smb1_reply.c +++ b/source3/smbd/smb1_reply.c @@ -70,6 +70,78 @@ bool check_fsp_open(connection_struct *conn, struct smb_request *req, return true; } +/**************************************************************************** + SMB1 version of smb2_strip_dfs_path() + Differs from SMB2 in that all Windows path separator '\' characters + have already been converted to '/' by check_path_syntax_internal(). +****************************************************************************/ + +NTSTATUS smb1_strip_dfs_path(TALLOC_CTX *mem_ctx, + uint32_t *_ucf_flags, + char **in_path) +{ + uint32_t ucf_flags = *_ucf_flags; + char *path = *in_path; + char *return_path = NULL; + + if (!(ucf_flags & UCF_DFS_PATHNAME)) { + return NT_STATUS_OK; + } + + /* Stip any leading '/' characters - MacOSX client behavior. */ + while (*path == '/') { + path++; + } + + /* We should now be pointing at the server name. Go past it. */ + for (;;) { + if (*path == '\0') { + /* End of complete path. Exit OK. */ + goto done; + } + if (*path == '/') { + /* End of server name. Go past and break. */ + path++; + break; + } + path++; /* Continue looking for end of server name or string. */ + } + + /* We should now be pointing at the share name. Go past it. */ + for (;;) { + if (*path == '\0') { + /* End of complete path. Exit OK. */ + goto done; + } + if (*path == '/') { + /* End of share name. Go past and break. */ + path++; + break; + } + if (*path == ':') { + /* Only invalid character in sharename. */ + return NT_STATUS_OBJECT_NAME_INVALID; + } + path++; /* Continue looking for end of share name or string. */ + } + + done: + /* path now points at the start of the real filename (if any). */ + /* Duplicate it first. */ + return_path = talloc_strdup(mem_ctx, path); + if (return_path == NULL) { + return NT_STATUS_NO_MEMORY; + } + + /* Now we can free the original (path points to part of this). */ + TALLOC_FREE(*in_path); + + *in_path = return_path; + ucf_flags &= ~UCF_DFS_PATHNAME; + *_ucf_flags = ucf_flags; + return NT_STATUS_OK; +} + /**************************************************************************** Check if we have a correct fsp pointing to a file. ****************************************************************************/