]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
Backport the semantics of when to delete alternate data streams on a file truncate.
authorJeremy Allison <jra@samba.org>
Thu, 19 Feb 2009 19:19:10 +0000 (11:19 -0800)
committerKarolin Seeger <kseeger@samba.org>
Fri, 20 Feb 2009 07:53:30 +0000 (08:53 +0100)
Needed to fully support stream semantics.
Jeremy.
(cherry picked from commit 5a68f1e2c1fd16d315b1e303a90eb6475bbe7b15)

source/include/proto.h
source/smbd/close.c
source/smbd/open.c

index 716f1771072c2839d37ae803da7d140d67563244..edb0009dd9c60e040f2e33fdacf79a12ce6065a5 100644 (file)
@@ -8690,6 +8690,7 @@ void msg_close_file(struct messaging_context *msg_ctx,
                    uint32_t msg_type,
                    struct server_id server_id,
                    DATA_BLOB *data);
+NTSTATUS delete_all_streams(connection_struct *conn, const char *fname);
 
 /* The following definitions come from smbd/conn.c  */
 
index 25552e37ab36eb6d5c12278f931fc67e8d3f7d82..d5861160aa811915f526d0e6bada37048ed73f7e 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 716b9ff492541fc02b9efc348553e10813184964..bbf1b40c2f8a0b067eef9096662f2143062e1970 100644 (file)
@@ -1358,6 +1358,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;
@@ -1490,12 +1491,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:
@@ -1520,6 +1523,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:
@@ -1953,6 +1957,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