Backport the semantics of when to delete alternate data streams on a file truncate.
authorJeremy Allison <jra@samba.org>
Thu, 19 Feb 2009 19:55:56 +0000 (11:55 -0800)
committerKarolin Seeger <kseeger@samba.org>
Fri, 27 Mar 2009 12:06:49 +0000 (13:06 +0100)
Needed to fully support stream semantics.
Jeremy.
(cherry picked from commit cdcb9bbf47396a7213edafeabb009920bb4e16b7)

source/smbd/close.c
source/smbd/open.c

index 7637ffbcd8035337f814aaefdfd8ad279c3f48b0..9fd5693068a11d7c7e9961cac46d7df4626c70e1 100644 (file)
@@ -167,7 +167,7 @@ static void notify_deferred_opens(struct share_mode_lock *lck)
  Delete all streams
 ****************************************************************************/
 
-static NTSTATUS delete_all_streams(connection_struct *conn, const char *fname)
+NTSTATUS delete_all_streams(connection_struct *conn, const char *fname)
 {
        struct stream_struct *stream_info;
        int i;
index 82098647990749dac19ac7ae37b9a05814fc67b3..58d1f6d44688b9192b822b43d7db63944634ff94 100644 (file)
@@ -1193,6 +1193,7 @@ static NTSTATUS open_file_ntcreate_internal(connection_struct *conn,
        bool def_acl = False;
        bool posix_open = False;
        bool new_file_created = False;
+       bool clear_ads = false;
        struct file_id id;
        NTSTATUS fsp_open = NT_STATUS_ACCESS_DENIED;
        mode_t new_unx_mode = (mode_t)0;
@@ -1325,12 +1326,14 @@ static NTSTATUS open_file_ntcreate_internal(connection_struct *conn,
                        /* If file exists replace/overwrite. If file doesn't
                         * exist create. */
                        flags2 |= (O_CREAT | O_TRUNC);
+                       clear_ads = true;
                        break;
 
                case FILE_OVERWRITE_IF:
                        /* If file exists replace/overwrite. If file doesn't
                         * exist create. */
                        flags2 |= (O_CREAT | O_TRUNC);
+                       clear_ads = true;
                        break;
 
                case FILE_OPEN:
@@ -1355,6 +1358,7 @@ static NTSTATUS open_file_ntcreate_internal(connection_struct *conn,
                                return NT_STATUS_OBJECT_NAME_NOT_FOUND;
                        }
                        flags2 |= O_TRUNC;
+                       clear_ads = true;
                        break;
 
                case FILE_CREATE:
@@ -1787,6 +1791,16 @@ static NTSTATUS open_file_ntcreate_internal(connection_struct *conn,
 
        SMB_ASSERT(lck != NULL);
 
+       /* Delete streams if create_disposition requires it */
+       if (file_existed && clear_ads && !is_ntfs_stream_name(fname)) {
+               status = delete_all_streams(conn, fname);
+               if (!NT_STATUS_IS_OK(status)) {
+                       TALLOC_FREE(lck);
+                       fd_close(fsp);
+                       return status;
+               }
+       }
+
        /* note that we ignore failure for the following. It is
            basically a hack for NFS, and NFS will never set one of
            these only read them. Nobody but Samba can ever set a deny