vfs_fruit: resource fork open request with flags=O_CREAT|O_RDONLY
authorRalph Boehme <slow@samba.org>
Tue, 7 Feb 2017 06:44:40 +0000 (07:44 +0100)
committerJeremy Allison <jra@samba.org>
Fri, 7 Apr 2017 20:52:24 +0000 (22:52 +0200)
When receiving an SMB create request with read-only access mode and
open_if disposition, we end of calling the open() function with
flags=O_CREAT|O_RDONLY for the ._ AppleDouble file.

If the file doesn't exist, ie there's currently no rsrc stream, we create
it but then we fail to write the AppleDouble header into the file due to
the O_RDONLY open mode, leaving a 0 byte size ._ file.

Running this create requests against macOS SMB server yields an
interesting result: it returns NT_STATUS_OBJECT_NAME_NOT_FOUND even
though create dispotion is open_if. Another instance where the macOS SMB
server just exposes FSA behaviour (ie HFS+) and we have to adapt to be
compatible.

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

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

index 0b5558a4487486a35475ba47b35b431de69a3315..b74714586f6e454317d3e6cb10c1b4ac9aa0256f 100644 (file)
@@ -2970,6 +2970,20 @@ static int fruit_open_rsrc(vfs_handle_struct *handle,
        SMB_VFS_HANDLE_GET_DATA(handle, config,
                                struct fruit_config_data, return -1);
 
+       if (((flags & O_ACCMODE) == O_RDONLY)
+           && (flags & O_CREAT)
+           && !VALID_STAT(fsp->fsp_name->st))
+       {
+               /*
+                * This means the stream doesn't exist. macOS SMB server fails
+                * this with NT_STATUS_OBJECT_NAME_NOT_FOUND, so must we. Cf bug
+                * 12565 and the test for this combination in
+                * test_rfork_create().
+                */
+               errno = ENOENT;
+               return -1;
+       }
+
        switch (config->rsrc) {
        case FRUIT_RSRC_STREAM:
                fd = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);