s3: Remove is_ntfs_stream_name() and split_ntfs_stream_name()
[samba.git] / source3 / modules / vfs_streams_xattr.c
index 77ffff5fb5a70642990e3538a9c5479d178301cb..eccc2379c9b1eacd5d64956c677b4a78a8a16f6b 100644 (file)
@@ -42,17 +42,17 @@ static SMB_INO_T stream_inode(const SMB_STRUCT_STAT *sbuf, const char *sname)
        char *upper_sname;
 
        DEBUG(10, ("stream_inode called for %lu/%lu [%s]\n",
-                  (unsigned long)sbuf->st_dev,
-                  (unsigned long)sbuf->st_ino, sname));
+                  (unsigned long)sbuf->st_ex_dev,
+                  (unsigned long)sbuf->st_ex_ino, sname));
 
        upper_sname = talloc_strdup_upper(talloc_tos(), sname);
        SMB_ASSERT(upper_sname != NULL);
 
         MD5Init(&ctx);
-        MD5Update(&ctx, (unsigned char *)&(sbuf->st_dev),
-                 sizeof(sbuf->st_dev));
-        MD5Update(&ctx, (unsigned char *)&(sbuf->st_ino),
-                 sizeof(sbuf->st_ino));
+        MD5Update(&ctx, (unsigned char *)&(sbuf->st_ex_dev),
+                 sizeof(sbuf->st_ex_dev));
+        MD5Update(&ctx, (unsigned char *)&(sbuf->st_ex_ino),
+                 sizeof(sbuf->st_ex_ino));
         MD5Update(&ctx, (unsigned char *)upper_sname,
                  talloc_get_size(upper_sname)-1);
         MD5Final(hash, &ctx);
@@ -88,32 +88,69 @@ static ssize_t get_xattr_size(connection_struct *conn,
        return result;
 }
 
+/**
+ * Given a stream name, populate xattr_name with the xattr name to use for
+ * accessing the stream.
+ */
+static NTSTATUS streams_xattr_get_name(TALLOC_CTX *ctx,
+                                      const char *stream_name,
+                                      char **xattr_name)
+{
+       char *stype;
+
+       stype = strchr_m(stream_name + 1, ':');
+
+       *xattr_name = talloc_asprintf(ctx, "%s%s",
+                                     SAMBA_XATTR_DOSSTREAM_PREFIX,
+                                     stream_name + 1);
+       if (*xattr_name == NULL) {
+               return NT_STATUS_NO_MEMORY;
+       }
+
+       if (stype == NULL) {
+               /* Append an explicit stream type if one wasn't specified. */
+               *xattr_name = talloc_asprintf(ctx, "%s:$DATA",
+                                              *xattr_name);
+               if (*xattr_name == NULL) {
+                       return NT_STATUS_NO_MEMORY;
+               }
+       } else {
+               /* Normalize the stream type to upercase. */
+               strupper_m(strrchr_m(*xattr_name, ':') + 1);
+       }
+
+       DEBUG(10, ("xattr_name: %s, stream_name: %s\n", *xattr_name,
+                  stream_name));
+
+       return NT_STATUS_OK;
+}
+
 static bool streams_xattr_recheck(struct stream_io *sio)
 {
        NTSTATUS status;
-       char *base = NULL;
-       char *sname = NULL;
+       struct smb_filename *smb_fname = NULL;
        char *xattr_name = NULL;
 
        if (sio->fsp->fsp_name == sio->fsp_name_ptr) {
                return true;
        }
 
-       status = split_ntfs_stream_name(talloc_tos(), sio->fsp->fsp_name,
-                                       &base, &sname);
+       status = create_synthetic_smb_fname_split(talloc_tos(),
+                                                 sio->fsp->fsp_name, NULL,
+                                                 &smb_fname);
        if (!NT_STATUS_IS_OK(status)) {
                return false;
        }
 
-       if (sname == NULL) {
+       if (smb_fname->stream_name == NULL) {
                /* how can this happen */
                errno = EINVAL;
                return false;
        }
 
-       xattr_name = talloc_asprintf(talloc_tos(), "%s%s",
-                                    SAMBA_XATTR_DOSSTREAM_PREFIX, sname);
-       if (xattr_name == NULL) {
+       status = streams_xattr_get_name(talloc_tos(), smb_fname->stream_name,
+                                       &xattr_name);
+       if (!NT_STATUS_IS_OK(status)) {
                return false;
        }
 
@@ -122,9 +159,12 @@ static bool streams_xattr_recheck(struct stream_io *sio)
        sio->xattr_name = talloc_strdup(VFS_MEMCTX_FSP_EXTENSION(sio->handle, sio->fsp),
                                        xattr_name);
        sio->base = talloc_strdup(VFS_MEMCTX_FSP_EXTENSION(sio->handle, sio->fsp),
-                                 base);
+                                 smb_fname->base_name);
        sio->fsp_name_ptr = sio->fsp->fsp_name;
 
+       TALLOC_FREE(smb_fname);
+       TALLOC_FREE(xattr_name);
+
        if ((sio->xattr_name == NULL) || (sio->base == NULL)) {
                return false;
        }
@@ -132,9 +172,33 @@ static bool streams_xattr_recheck(struct stream_io *sio)
        return true;
 }
 
+/**
+ * Helper to stat/lstat the base file of an smb_fname.
+ */
+static int streams_xattr_stat_base(vfs_handle_struct *handle,
+                                  struct smb_filename *smb_fname,
+                                  bool follow_links)
+{
+       char *tmp_stream_name;
+       int result;
+
+       tmp_stream_name = smb_fname->stream_name;
+       smb_fname->stream_name = NULL;
+       if (follow_links) {
+               result = SMB_VFS_NEXT_STAT(handle, smb_fname);
+       } else {
+               result = SMB_VFS_NEXT_LSTAT(handle, smb_fname);
+       }
+       smb_fname->stream_name = tmp_stream_name;
+       return result;
+}
+
 static int streams_xattr_fstat(vfs_handle_struct *handle, files_struct *fsp,
                               SMB_STRUCT_STAT *sbuf)
 {
+       struct smb_filename *smb_fname_base = NULL;
+       NTSTATUS status;
+       int ret = -1;
        struct stream_io *io = (struct stream_io *)
                VFS_FETCH_FSP_EXTENSION(handle, fsp);
 
@@ -148,165 +212,195 @@ static int streams_xattr_fstat(vfs_handle_struct *handle, files_struct *fsp,
                return -1;
        }
 
-       if (SMB_VFS_STAT(handle->conn, io->base, sbuf) == -1) {
+       /* Create an smb_filename with stream_name == NULL. */
+       status = create_synthetic_smb_fname(talloc_tos(),
+                                           io->base,
+                                           NULL, NULL,
+                                           &smb_fname_base);
+       if (!NT_STATUS_IS_OK(status)) {
+               errno = map_errno_from_nt_status(status);
+               return -1;
+       }
+
+       if (lp_posix_pathnames()) {
+               ret = SMB_VFS_LSTAT(handle->conn, smb_fname_base);
+       } else {
+               ret = SMB_VFS_STAT(handle->conn, smb_fname_base);
+       }
+       *sbuf = smb_fname_base->st;
+       TALLOC_FREE(smb_fname_base);
+
+       if (ret == -1) {
                return -1;
        }
 
-       sbuf->st_size = get_xattr_size(handle->conn, fsp->base_fsp,
+       sbuf->st_ex_size = get_xattr_size(handle->conn, fsp->base_fsp,
                                        io->base, io->xattr_name);
-       if (sbuf->st_size == -1) {
+       if (sbuf->st_ex_size == -1) {
                return -1;
        }
 
-       DEBUG(10, ("sbuf->st_size = %d\n", (int)sbuf->st_size));
+       DEBUG(10, ("sbuf->st_ex_size = %d\n", (int)sbuf->st_ex_size));
 
-       sbuf->st_ino = stream_inode(sbuf, io->xattr_name);
-       sbuf->st_mode &= ~S_IFMT;
-        sbuf->st_mode |= S_IFREG;
-        sbuf->st_blocks = sbuf->st_size % STAT_ST_BLOCKSIZE + 1;
+       sbuf->st_ex_ino = stream_inode(sbuf, io->xattr_name);
+       sbuf->st_ex_mode &= ~S_IFMT;
+        sbuf->st_ex_mode |= S_IFREG;
+        sbuf->st_ex_blocks = sbuf->st_ex_size % STAT_ST_BLOCKSIZE + 1;
 
        return 0;
 }
 
-static int streams_xattr_stat(vfs_handle_struct *handle, const char *fname,
-                             SMB_STRUCT_STAT *sbuf)
+static int streams_xattr_stat(vfs_handle_struct *handle,
+                             struct smb_filename *smb_fname)
 {
        NTSTATUS status;
-       char *base = NULL, *sname = NULL;
        int result = -1;
-       char *xattr_name;
-
-       if (!is_ntfs_stream_name(fname)) {
-               return SMB_VFS_NEXT_STAT(handle, fname, sbuf);
-       }
+       char *xattr_name = NULL;
 
-       status = split_ntfs_stream_name(talloc_tos(), fname, &base, &sname);
-       if (!NT_STATUS_IS_OK(status)) {
-               errno = EINVAL;
-               return -1;
+       if (!is_ntfs_stream_smb_fname(smb_fname)) {
+               return SMB_VFS_NEXT_STAT(handle, smb_fname);
        }
 
-       if (sname == NULL){
-               return SMB_VFS_NEXT_STAT(handle, base, sbuf);
+       /* If the default stream is requested, just stat the base file. */
+       if (is_ntfs_default_stream_smb_fname(smb_fname)) {
+               return streams_xattr_stat_base(handle, smb_fname, true);
        }
 
-       if (SMB_VFS_STAT(handle->conn, base, sbuf) == -1) {
-               goto fail;
+       /* Populate the stat struct with info from the base file. */
+       if (streams_xattr_stat_base(handle, smb_fname, true) == -1) {
+               return -1;
        }
 
-       xattr_name = talloc_asprintf(talloc_tos(), "%s%s",
-                                    SAMBA_XATTR_DOSSTREAM_PREFIX, sname);
-       if (xattr_name == NULL) {
-               errno = ENOMEM;
-               goto fail;
+       /* Derive the xattr name to lookup. */
+       status = streams_xattr_get_name(talloc_tos(), smb_fname->stream_name,
+                                       &xattr_name);
+       if (!NT_STATUS_IS_OK(status)) {
+               errno = map_errno_from_nt_status(status);
+               return -1;
        }
 
-       sbuf->st_size = get_xattr_size(handle->conn, NULL, base, xattr_name);
-       if (sbuf->st_size == -1) {
+       /* Augment the base file's stat information before returning. */
+       smb_fname->st.st_ex_size = get_xattr_size(handle->conn, NULL,
+                                                 smb_fname->base_name,
+                                                 xattr_name);
+       if (smb_fname->st.st_ex_size == -1) {
                errno = ENOENT;
+               result = -1;
                goto fail;
        }
 
-       sbuf->st_ino = stream_inode(sbuf, xattr_name);
-       sbuf->st_mode &= ~S_IFMT;
-        sbuf->st_mode |= S_IFREG;
-        sbuf->st_blocks = sbuf->st_size % STAT_ST_BLOCKSIZE + 1;
+       smb_fname->st.st_ex_ino = stream_inode(&smb_fname->st, xattr_name);
+       smb_fname->st.st_ex_mode &= ~S_IFMT;
+        smb_fname->st.st_ex_mode |= S_IFREG;
+        smb_fname->st.st_ex_blocks =
+           smb_fname->st.st_ex_size % STAT_ST_BLOCKSIZE + 1;
 
        result = 0;
  fail:
-       TALLOC_FREE(base);
-       TALLOC_FREE(sname);
+       TALLOC_FREE(xattr_name);
        return result;
 }
 
-static int streams_xattr_lstat(vfs_handle_struct *handle, const char *fname,
-                              SMB_STRUCT_STAT *sbuf)
+static int streams_xattr_lstat(vfs_handle_struct *handle,
+                              struct smb_filename *smb_fname)
 {
        NTSTATUS status;
-       char *base, *sname;
        int result = -1;
-       char *xattr_name;
+       char *xattr_name = NULL;
 
-       if (!is_ntfs_stream_name(fname)) {
-               return SMB_VFS_NEXT_LSTAT(handle, fname, sbuf);
+       if (!is_ntfs_stream_smb_fname(smb_fname)) {
+               return SMB_VFS_NEXT_LSTAT(handle, smb_fname);
        }
 
-       status = split_ntfs_stream_name(talloc_tos(), fname, &base, &sname);
-       if (!NT_STATUS_IS_OK(status)) {
-               errno = EINVAL;
-               goto fail;
-       }
-
-       if (sname == NULL){
-               return SMB_VFS_NEXT_LSTAT(handle, base, sbuf);
+               /* If the default stream is requested, just stat the base file. */
+       if (is_ntfs_default_stream_smb_fname(smb_fname)) {
+               return streams_xattr_stat_base(handle, smb_fname, false);
        }
 
-       if (SMB_VFS_LSTAT(handle->conn, base, sbuf) == -1) {
-               goto fail;
+       /* Populate the stat struct with info from the base file. */
+       if (streams_xattr_stat_base(handle, smb_fname, false) == -1) {
+               return -1;
        }
 
-       xattr_name = talloc_asprintf(talloc_tos(), "%s%s",
-                                    SAMBA_XATTR_DOSSTREAM_PREFIX, sname);
-       if (xattr_name == NULL) {
-               errno = ENOMEM;
-               goto fail;
+       /* Derive the xattr name to lookup. */
+       status = streams_xattr_get_name(talloc_tos(), smb_fname->stream_name,
+                                       &xattr_name);
+       if (!NT_STATUS_IS_OK(status)) {
+               errno = map_errno_from_nt_status(status);
+               return -1;
        }
 
-       sbuf->st_size = get_xattr_size(handle->conn, NULL, base, xattr_name);
-       if (sbuf->st_size == -1) {
+       /* Augment the base file's stat information before returning. */
+       smb_fname->st.st_ex_size = get_xattr_size(handle->conn, NULL,
+                                                 smb_fname->base_name,
+                                                 xattr_name);
+       if (smb_fname->st.st_ex_size == -1) {
                errno = ENOENT;
+               result = -1;
                goto fail;
        }
 
-       sbuf->st_ino = stream_inode(sbuf, xattr_name);
-       sbuf->st_mode &= ~S_IFMT;
-        sbuf->st_mode |= S_IFREG;
-        sbuf->st_blocks = sbuf->st_size % STAT_ST_BLOCKSIZE + 1;
+       smb_fname->st.st_ex_ino = stream_inode(&smb_fname->st, xattr_name);
+       smb_fname->st.st_ex_mode &= ~S_IFMT;
+        smb_fname->st.st_ex_mode |= S_IFREG;
+        smb_fname->st.st_ex_blocks =
+           smb_fname->st.st_ex_size % STAT_ST_BLOCKSIZE + 1;
 
        result = 0;
+
  fail:
-       TALLOC_FREE(base);
-       TALLOC_FREE(sname);
+       TALLOC_FREE(xattr_name);
        return result;
 }
 
-static int streams_xattr_open(vfs_handle_struct *handle,  const char *fname,
+static int streams_xattr_open(vfs_handle_struct *handle,
+                             struct smb_filename *smb_fname,
                              files_struct *fsp, int flags, mode_t mode)
 {
-       TALLOC_CTX *frame;
        NTSTATUS status;
+       struct smb_filename *smb_fname_base = NULL;
        struct stream_io *sio;
-       char *base, *sname;
        struct ea_struct ea;
-       char *xattr_name;
+       char *xattr_name = NULL;
        int baseflags;
        int hostfd = -1;
 
-       DEBUG(10, ("streams_xattr_open called for %s\n", fname));
+       DEBUG(10, ("streams_xattr_open called for %s\n",
+                  smb_fname_str_dbg(smb_fname)));
 
-       if (!is_ntfs_stream_name(fname)) {
-               return SMB_VFS_NEXT_OPEN(handle, fname, fsp, flags, mode);
+       if (!is_ntfs_stream_smb_fname(smb_fname)) {
+               return SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
        }
 
-       frame = talloc_stackframe();
+       /* If the default stream is requested, just open the base file. */
+       if (is_ntfs_default_stream_smb_fname(smb_fname)) {
+               char *tmp_stream_name;
+               int ret;
 
-       status = split_ntfs_stream_name(talloc_tos(), fname,
-                                       &base, &sname);
-       if (!NT_STATUS_IS_OK(status)) {
-               errno = EINVAL;
-               goto fail;
+               tmp_stream_name = smb_fname->stream_name;
+               smb_fname->stream_name = NULL;
+
+               ret = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
+
+               smb_fname->stream_name = tmp_stream_name;
+
+               return ret;
        }
 
-       if (sname == NULL) {
-               hostfd = SMB_VFS_NEXT_OPEN(handle, base, fsp, flags, mode);
-               talloc_free(frame);
-               return hostfd;
+       status = streams_xattr_get_name(talloc_tos(), smb_fname->stream_name,
+                                       &xattr_name);
+       if (!NT_STATUS_IS_OK(status)) {
+               errno = map_errno_from_nt_status(status);
+               goto fail;
        }
 
-       xattr_name = talloc_asprintf(talloc_tos(), "%s%s",
-                                    SAMBA_XATTR_DOSSTREAM_PREFIX, sname);
-       if (xattr_name == NULL) {
-               errno = ENOMEM;
+       /* Create an smb_filename with stream_name == NULL. */
+       status = create_synthetic_smb_fname(talloc_tos(),
+                                           smb_fname->base_name,
+                                           NULL, NULL,
+                                           &smb_fname_base);
+       if (!NT_STATUS_IS_OK(status)) {
+               errno = map_errno_from_nt_status(status);
                goto fail;
        }
 
@@ -319,7 +413,10 @@ static int streams_xattr_open(vfs_handle_struct *handle,  const char *fname,
         baseflags &= ~O_EXCL;
         baseflags &= ~O_CREAT;
 
-        hostfd = SMB_VFS_OPEN(handle->conn, base, fsp, baseflags, mode);
+        hostfd = SMB_VFS_OPEN(handle->conn, smb_fname_base, fsp,
+                             baseflags, mode);
+
+       TALLOC_FREE(smb_fname_base);
 
         /* It is legit to open a stream on a directory, but the base
          * fd has to be read-only.
@@ -327,7 +424,7 @@ static int streams_xattr_open(vfs_handle_struct *handle,  const char *fname,
         if ((hostfd == -1) && (errno == EISDIR)) {
                 baseflags &= ~O_ACCMODE;
                 baseflags |= O_RDONLY;
-                hostfd = SMB_VFS_OPEN(handle->conn, fname, fsp, baseflags,
+                hostfd = SMB_VFS_OPEN(handle->conn, smb_fname, fsp, baseflags,
                                      mode);
         }
 
@@ -335,8 +432,8 @@ static int streams_xattr_open(vfs_handle_struct *handle,  const char *fname,
                goto fail;
         }
 
-       status = get_ea_value(talloc_tos(), handle->conn, NULL, base,
-                             xattr_name, &ea);
+       status = get_ea_value(talloc_tos(), handle->conn, NULL,
+                             smb_fname->base_name, xattr_name, &ea);
 
        DEBUG(10, ("get_ea_value returned %s\n", nt_errstr(status)));
 
@@ -348,7 +445,7 @@ static int streams_xattr_open(vfs_handle_struct *handle,  const char *fname,
                 * file for us.
                 */
                DEBUG(10, ("streams_xattr_open: base file %s not around, "
-                          "returning ENOENT\n", base));
+                          "returning ENOENT\n", smb_fname->base_name));
                errno = ENOENT;
                goto fail;
        }
@@ -365,7 +462,7 @@ static int streams_xattr_open(vfs_handle_struct *handle,  const char *fname,
                         char null = '\0';
 
                        DEBUG(10, ("creating attribute %s on file %s\n",
-                                  xattr_name, base));
+                                  xattr_name, smb_fname->base_name));
 
                        if (fsp->base_fsp->fh->fd != -1) {
                                if (SMB_VFS_FSETXATTR(
@@ -376,8 +473,8 @@ static int streams_xattr_open(vfs_handle_struct *handle,  const char *fname,
                                }
                        } else {
                                if (SMB_VFS_SETXATTR(
-                                       handle->conn, base, xattr_name,
-                                       &null, sizeof(null),
+                                       handle->conn, smb_fname->base_name,
+                                       xattr_name, &null, sizeof(null),
                                        flags & O_EXCL ? XATTR_CREATE : 0) == -1) {
                                        goto fail;
                                }
@@ -396,8 +493,8 @@ static int streams_xattr_open(vfs_handle_struct *handle,  const char *fname,
                        }
                } else {
                        if (SMB_VFS_SETXATTR(
-                                       handle->conn, base, xattr_name,
-                                       &null, sizeof(null),
+                                       handle->conn, smb_fname->base_name,
+                                       xattr_name, &null, sizeof(null),
                                        flags & O_EXCL ? XATTR_CREATE : 0) == -1) {
                                goto fail;
                        }
@@ -415,7 +512,7 @@ static int streams_xattr_open(vfs_handle_struct *handle,  const char *fname,
         sio->xattr_name = talloc_strdup(VFS_MEMCTX_FSP_EXTENSION(handle, fsp),
                                        xattr_name);
         sio->base = talloc_strdup(VFS_MEMCTX_FSP_EXTENSION(handle, fsp),
-                                 base);
+                                 smb_fname->base_name);
        sio->fsp_name_ptr = fsp->fsp_name;
        sio->handle = handle;
        sio->fsp = fsp;
@@ -425,7 +522,6 @@ static int streams_xattr_open(vfs_handle_struct *handle,  const char *fname,
                goto fail;
        }
 
-       TALLOC_FREE(frame);
        return hostfd;
 
  fail:
@@ -437,40 +533,45 @@ static int streams_xattr_open(vfs_handle_struct *handle,  const char *fname,
                SMB_VFS_CLOSE(fsp);
        }
 
-       TALLOC_FREE(frame);
        return -1;
 }
 
-static int streams_xattr_unlink(vfs_handle_struct *handle,  const char *fname)
+static int streams_xattr_unlink(vfs_handle_struct *handle,
+                               const struct smb_filename *smb_fname)
 {
        NTSTATUS status;
-       char *base = NULL;
-       char *sname = NULL;
        int ret = -1;
        char *xattr_name;
 
-       if (!is_ntfs_stream_name(fname)) {
-               return SMB_VFS_NEXT_UNLINK(handle, fname);
+       if (!is_ntfs_stream_smb_fname(smb_fname)) {
+               return SMB_VFS_NEXT_UNLINK(handle, smb_fname);
        }
 
-       status = split_ntfs_stream_name(talloc_tos(), fname, &base, &sname);
-       if (!NT_STATUS_IS_OK(status)) {
-               errno = EINVAL;
-               goto fail;
-       }
+       /* If the default stream is requested, just open the base file. */
+       if (is_ntfs_default_stream_smb_fname(smb_fname)) {
+               struct smb_filename *smb_fname_base = NULL;
+
+               status = copy_smb_filename(talloc_tos(), smb_fname,
+                                           &smb_fname_base);
+               if (!NT_STATUS_IS_OK(status)) {
+                       errno = map_errno_from_nt_status(status);
+                       return -1;
+               }
 
-       if (sname == NULL){
-               return SMB_VFS_NEXT_UNLINK(handle, base);
+               ret = SMB_VFS_NEXT_UNLINK(handle, smb_fname_base);
+
+               TALLOC_FREE(smb_fname_base);
+               return ret;
        }
 
-       xattr_name = talloc_asprintf(talloc_tos(), "%s%s",
-                                    SAMBA_XATTR_DOSSTREAM_PREFIX, sname);
-       if (xattr_name == NULL) {
-               errno = ENOMEM;
+       status = streams_xattr_get_name(talloc_tos(), smb_fname->stream_name,
+                                       &xattr_name);
+       if (!NT_STATUS_IS_OK(status)) {
+               errno = map_errno_from_nt_status(status);
                goto fail;
        }
 
-       ret = SMB_VFS_REMOVEXATTR(handle->conn, base, xattr_name);
+       ret = SMB_VFS_REMOVEXATTR(handle->conn, smb_fname->base_name, xattr_name);
 
        if ((ret == -1) && (errno == ENOATTR)) {
                errno = ENOENT;
@@ -480,97 +581,72 @@ static int streams_xattr_unlink(vfs_handle_struct *handle,  const char *fname)
        ret = 0;
 
  fail:
-       TALLOC_FREE(base);
-       TALLOC_FREE(sname);
+       TALLOC_FREE(xattr_name);
        return ret;
 }
 
 static int streams_xattr_rename(vfs_handle_struct *handle,
-                               const char *oldname,
-                               const char *newname)
+                               const struct smb_filename *smb_fname_src,
+                               const struct smb_filename *smb_fname_dst)
 {
        NTSTATUS status;
-       TALLOC_CTX *frame = NULL;
-       char *obase;
-       char *ostream;
-       char *nbase;
-       char *nstream;
-       const char *base;
        int ret = -1;
-       char *oxattr_name;
-       char *nxattr_name;
-       bool o_is_stream;
-       bool n_is_stream;
+       char *src_xattr_name = NULL;
+       char *dst_xattr_name = NULL;
+       bool src_is_stream, dst_is_stream;
        ssize_t oret;
        ssize_t nret;
        struct ea_struct ea;
 
-       o_is_stream = is_ntfs_stream_name(oldname);
-       n_is_stream = is_ntfs_stream_name(newname);
+       src_is_stream = is_ntfs_stream_smb_fname(smb_fname_src);
+       dst_is_stream = is_ntfs_stream_smb_fname(smb_fname_dst);
 
-       if (!o_is_stream && !n_is_stream) {
-               return SMB_VFS_NEXT_RENAME(handle, oldname, newname);
+       if (!src_is_stream && !dst_is_stream) {
+               return SMB_VFS_NEXT_RENAME(handle, smb_fname_src,
+                                          smb_fname_dst);
        }
 
-       frame = talloc_stackframe();
-       if (!frame) {
-               goto fail;
-       }
-
-       status = split_ntfs_stream_name(talloc_tos(), oldname, &obase, &ostream);
-       if (!NT_STATUS_IS_OK(status)) {
-               errno = EINVAL;
-               goto fail;
-       }
-
-       status = split_ntfs_stream_name(talloc_tos(), newname, &nbase, &nstream);
-       if (!NT_STATUS_IS_OK(status)) {
-               errno = EINVAL;
-               goto fail;
-       }
-
-       /*TODO: maybe call SMB_VFS_NEXT_RENAME() both streams are NULL (::$DATA) */
-       if (ostream == NULL) {
-               errno = ENOSYS;
-               goto fail;
-       }
-
-       if (nstream == NULL) {
+       /* For now don't allow renames from or to the default stream. */
+       if (is_ntfs_default_stream_smb_fname(smb_fname_src) ||
+           is_ntfs_default_stream_smb_fname(smb_fname_dst)) {
                errno = ENOSYS;
-               goto fail;
+               goto done;
        }
 
-       if (StrCaseCmp(ostream, nstream) == 0) {
+       /* Don't rename if the streams are identical. */
+       if (StrCaseCmp(smb_fname_src->stream_name,
+                      smb_fname_dst->stream_name) == 0) {
                goto done;
        }
 
-       base = obase;
-
-       oxattr_name = talloc_asprintf(talloc_tos(), "%s%s",
-                                     SAMBA_XATTR_DOSSTREAM_PREFIX, ostream);
-       if (oxattr_name == NULL) {
-               errno = ENOMEM;
+       /* Get the xattr names. */
+       status = streams_xattr_get_name(talloc_tos(),
+                                       smb_fname_src->stream_name,
+                                       &src_xattr_name);
+       if (!NT_STATUS_IS_OK(status)) {
+               errno = map_errno_from_nt_status(status);
                goto fail;
        }
-
-       nxattr_name = talloc_asprintf(talloc_tos(), "%s%s",
-                                     SAMBA_XATTR_DOSSTREAM_PREFIX, nstream);
-       if (nxattr_name == NULL) {
-               errno = ENOMEM;
+       status = streams_xattr_get_name(talloc_tos(),
+                                       smb_fname_dst->stream_name,
+                                       &dst_xattr_name);
+       if (!NT_STATUS_IS_OK(status)) {
+               errno = map_errno_from_nt_status(status);
                goto fail;
        }
 
        /* read the old stream */
        status = get_ea_value(talloc_tos(), handle->conn, NULL,
-                             base, oxattr_name, &ea);
+                             smb_fname_src->base_name, src_xattr_name, &ea);
        if (!NT_STATUS_IS_OK(status)) {
                errno = ENOENT;
                goto fail;
        }
 
        /* (over)write the new stream */
-       nret = SMB_VFS_SETXATTR(handle->conn, base, nxattr_name,
-                               ea.value.data, ea.value.length, 0);
+       nret = SMB_VFS_SETXATTR(handle->conn, smb_fname_src->base_name,
+                               dst_xattr_name, ea.value.data, ea.value.length,
+                               0);
        if (nret < 0) {
                if (errno == ENOATTR) {
                        errno = ENOENT;
@@ -579,7 +655,8 @@ static int streams_xattr_rename(vfs_handle_struct *handle,
        }
 
        /* remove the old stream */
-       oret = SMB_VFS_REMOVEXATTR(handle->conn, base, oxattr_name);
+       oret = SMB_VFS_REMOVEXATTR(handle->conn, smb_fname_src->base_name,
+                                  src_xattr_name);
        if (oret < 0) {
                if (errno == ENOATTR) {
                        errno = ENOENT;
@@ -591,7 +668,8 @@ static int streams_xattr_rename(vfs_handle_struct *handle,
        errno = 0;
        ret = 0;
  fail:
-       TALLOC_FREE(frame);
+       TALLOC_FREE(src_xattr_name);
+       TALLOC_FREE(dst_xattr_name);
        return ret;
 }
 
@@ -710,16 +788,22 @@ static NTSTATUS streams_xattr_streaminfo(vfs_handle_struct *handle,
        struct streaminfo_state state;
 
        if ((fsp != NULL) && (fsp->fh->fd != -1)) {
-               if (is_ntfs_stream_name(fsp->fsp_name)) {
-                       return NT_STATUS_INVALID_PARAMETER;
-               }
                ret = SMB_VFS_FSTAT(fsp, &sbuf);
        }
        else {
-               if (is_ntfs_stream_name(fname)) {
-                       return NT_STATUS_INVALID_PARAMETER;
+               struct smb_filename *smb_fname = NULL;
+               status = create_synthetic_smb_fname(talloc_tos(), fname, NULL,
+                                                   NULL, &smb_fname);
+               if (!NT_STATUS_IS_OK(status)) {
+                       return status;
+               }
+               if (lp_posix_pathnames()) {
+                       ret = SMB_VFS_LSTAT(handle->conn, smb_fname);
+               } else {
+                       ret = SMB_VFS_STAT(handle->conn, smb_fname);
                }
-               ret = SMB_VFS_STAT(handle->conn, fname, &sbuf);
+               sbuf = smb_fname->st;
+               TALLOC_FREE(smb_fname);
        }
 
        if (ret == -1) {
@@ -729,10 +813,10 @@ static NTSTATUS streams_xattr_streaminfo(vfs_handle_struct *handle,
        state.streams = NULL;
        state.num_streams = 0;
 
-       if (!S_ISDIR(sbuf.st_mode)) {
+       if (!S_ISDIR(sbuf.st_ex_mode)) {
                if (!add_one_stream(mem_ctx,
                                    &state.num_streams, &state.streams,
-                                   "::$DATA", sbuf.st_size,
+                                   "::$DATA", sbuf.st_ex_size,
                                    SMB_VFS_GET_ALLOC_SIZE(handle->conn, fsp,
                                                           &sbuf))) {
                        return NT_STATUS_NO_MEMORY;