s3: smbd: Add utility function smb1_strip_dfs_path().
authorRalph Boehme <slow@samba.org>
Thu, 30 Mar 2023 13:55:53 +0000 (15:55 +0200)
committerRalph Boehme <slow@samba.org>
Fri, 31 Mar 2023 05:12:32 +0000 (05:12 +0000)
Signed-off-by: Ralph Boehme <slow@samba.org>
Signed-off-by: Jeremy Allison <jra@samba.org>
source3/smbd/proto.h
source3/smbd/smb1_reply.c

index 4e61dc426d89f573d6ae2d88559e374982673231..61c4f89ca10a4e4b32eff7e8e0840c91f978a843 100644 (file)
@@ -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,
index 1041e4f843bc78126cf132cfe4eae44975e679c9..46da29e027782ebaaad37e2558ba2a01e6f3f583 100644 (file)
@@ -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.
 ****************************************************************************/