vfs_fruit: writing all 0 to AFP_AfpInfo stream
authorRalph Boehme <slow@samba.org>
Thu, 17 Dec 2015 19:08:35 +0000 (20:08 +0100)
committerJeremy Allison <jra@samba.org>
Mon, 21 Dec 2015 22:21:18 +0000 (23:21 +0100)
When writing all 0 to AFP_AfpInfo stream we can remove the underlying
storage object. This beaviour of OS X SMB server was found with a
torture test.

Bug: https://bugzilla.samba.org/show_bug.cgi?id=11347

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

index ff19b6dbead6224ad896de4e4b189d99e918b49c..697783291ccfa60742e4c529db23d42e26dc0dc1 100644 (file)
@@ -2820,6 +2820,23 @@ static ssize_t fruit_pwrite(vfs_handle_struct *handle,
                }
                memcpy(ad_entry(ad, ADEID_FINDERI),
                       &ai->afpi_FinderInfo[0], ADEDLEN_FINDERI);
+               if (empty_finderinfo(ad)) {
+                       /* Discard metadata */
+                       if (config->meta == FRUIT_META_STREAM) {
+                               rc = SMB_VFS_FTRUNCATE(fsp, 0);
+                       } else {
+                               rc = SMB_VFS_REMOVEXATTR(handle->conn,
+                                                        fsp->fsp_name->base_name,
+                                                        AFPINFO_EA_NETATALK);
+                       }
+                       if (rc != 0 && errno != ENOENT && errno != ENOATTR) {
+                               DBG_WARNING("Can't delete metadata for %s: %s\n",
+                                           fsp->fsp_name->base_name, strerror(errno));
+                               goto exit;
+                       }
+                       rc = 0;
+                       goto exit;
+               }
                rc = ad_write(ad, name);
        } else {
                len = SMB_VFS_NEXT_PWRITE(handle, fsp, data, n,