vfs_streams_depot: support real dirfsps in streams_depot_unlink_internal()
authorRalph Boehme <slow@samba.org>
Thu, 21 Jan 2021 15:06:21 +0000 (16:06 +0100)
committerJeremy Allison <jra@samba.org>
Thu, 28 Jan 2021 08:11:49 +0000 (08:11 +0000)
Also remove the smb_fname_base variable, just use full_fname. If
is_named_stream(full_fname)) returns false, full_fname->stream_name will be
NULL.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/modules/vfs_streams_depot.c

index 91e23311b4e12b7515a0e0affa25bb8f5bbc7c87..e1f17afff74882c0a5b0eb4d005170f982a761fc 100644 (file)
@@ -693,27 +693,35 @@ static int streams_depot_unlink_internal(vfs_handle_struct *handle,
                                const struct smb_filename *smb_fname,
                                int flags)
 {
-       struct smb_filename *smb_fname_base = NULL;
+       struct smb_filename *full_fname = NULL;
        char *dirname = NULL;
        int ret = -1;
 
+       full_fname = full_path_from_dirfsp_atname(talloc_tos(),
+                                                 dirfsp,
+                                                 smb_fname);
+       if (full_fname == NULL) {
+               return -1;
+       }
+
        DEBUG(10, ("streams_depot_unlink called for %s\n",
-                  smb_fname_str_dbg(smb_fname)));
+                  smb_fname_str_dbg(full_fname)));
 
        /* If there is a valid stream, just unlink the stream and return. */
-       if (is_named_stream(smb_fname)) {
+       if (is_named_stream(full_fname)) {
                struct smb_filename *smb_fname_stream = NULL;
                NTSTATUS status;
 
-               status = stream_smb_fname(handle, smb_fname, &smb_fname_stream,
+               status = stream_smb_fname(handle, full_fname, &smb_fname_stream,
                                          false);
+               TALLOC_FREE(full_fname);
                if (!NT_STATUS_IS_OK(status)) {
                        errno = map_errno_from_nt_status(status);
                        return -1;
                }
 
                ret = SMB_VFS_NEXT_UNLINKAT(handle,
-                               dirfsp,
+                               dirfsp->conn->cwd_fsp,
                                smb_fname_stream,
                                0);
 
@@ -725,25 +733,13 @@ static int streams_depot_unlink_internal(vfs_handle_struct *handle,
         * We potentially need to delete the per-inode streams directory
         */
 
-       smb_fname_base = synthetic_smb_fname(talloc_tos(),
-                                       smb_fname->base_name,
-                                       NULL,
-                                       NULL,
-                                       smb_fname->twrp,
-                                       smb_fname->flags);
-       if (smb_fname_base == NULL) {
-               errno = ENOMEM;
-               return -1;
-       }
-
-       if (smb_fname_base->flags & SMB_FILENAME_POSIX_PATH) {
-               ret = SMB_VFS_NEXT_LSTAT(handle, smb_fname_base);
+       if (full_fname->flags & SMB_FILENAME_POSIX_PATH) {
+               ret = SMB_VFS_NEXT_LSTAT(handle, full_fname);
        } else {
-               ret = SMB_VFS_NEXT_STAT(handle, smb_fname_base);
+               ret = SMB_VFS_NEXT_STAT(handle, full_fname);
        }
-
        if (ret == -1) {
-               TALLOC_FREE(smb_fname_base);
+               TALLOC_FREE(full_fname);
                return -1;
        }
 
@@ -753,9 +749,10 @@ static int streams_depot_unlink_internal(vfs_handle_struct *handle,
         * file *after* the streams.
         */
        dirname = stream_dir(handle,
-                            smb_fname_base,
-                            &smb_fname_base->st,
+                            full_fname,
+                            &full_fname->st,
                             false);
+       TALLOC_FREE(full_fname);
        if (dirname != NULL) {
                struct smb_filename *smb_fname_dir = NULL;
 
@@ -766,14 +763,13 @@ static int streams_depot_unlink_internal(vfs_handle_struct *handle,
                                                    smb_fname->twrp,
                                                    smb_fname->flags);
                if (smb_fname_dir == NULL) {
-                       TALLOC_FREE(smb_fname_base);
                        TALLOC_FREE(dirname);
                        errno = ENOMEM;
                        return -1;
                }
 
                SMB_VFS_NEXT_UNLINKAT(handle,
-                                     dirfsp,
+                                     dirfsp->conn->cwd_fsp,
                                      smb_fname_dir,
                                      AT_REMOVEDIR);
                TALLOC_FREE(smb_fname_dir);
@@ -784,7 +780,6 @@ static int streams_depot_unlink_internal(vfs_handle_struct *handle,
                                dirfsp,
                                smb_fname,
                                flags);
-       TALLOC_FREE(smb_fname_base);
        return ret;
 }