From 78a4639b2d06cc69788861618d2e91945e142d2b Mon Sep 17 00:00:00 2001 From: Ralph Boehme Date: Tue, 21 May 2019 16:00:53 +0200 Subject: [PATCH] vfs_fruit: change trigger points of AppleDouble conversion This moves the trigger points where AppleDouble file conversion is run by ad_convert() from deep down the callchain in ad_read_rsrc_adouble() to high level VFS entry points. Currently ad_convert() will be triggered as part of open_file_ntcreate(..., "file:AFP_AfpResource", ...): after SMB_VFS_OPEN() has been called with O_CREAT, what created the file, we call SMB_VFS_FSTAT() on the just created filehandle. This ends up in ad_convert(), finds the resource fork empty and thus deletes the file. This commit moves calling of the conversion funtion to the high level VFS entry points where the converted metadata is needed: o for directory enumerations SMB_VFS_READDIR_ATTR() is called to fill in the repurposed fields in the directory entry metadata o obviously for SMB_VFS_CREATE_FILE() on an macOS stream Bug: https://bugzilla.samba.org/show_bug.cgi?id=13958 Signed-off-by: Ralph Boehme Reviewed-by: Jeremy Allison --- selftest/knownfail.d/samba3.vfs.fruit | 13 ------ source3/modules/vfs_fruit.c | 61 ++++++++++++++++++--------- 2 files changed, 40 insertions(+), 34 deletions(-) diff --git a/selftest/knownfail.d/samba3.vfs.fruit b/selftest/knownfail.d/samba3.vfs.fruit index b1a28bedff6..6307e2b3404 100644 --- a/selftest/knownfail.d/samba3.vfs.fruit +++ b/selftest/knownfail.d/samba3.vfs.fruit @@ -1,15 +1,2 @@ ^samba3.vfs.fruit streams_depot.OS X AppleDouble file conversion\(nt4_dc\) ^samba3.vfs.fruit streams_depot.OS X AppleDouble file conversion without embedded xattr\(nt4_dc\) -^samba3.vfs.fruit fruit_delete_empty_adfiles.copyfile\(nt4_dc\) -^samba3.vfs.fruit fruit_delete_empty_adfiles.resource fork IO\(nt4_dc\) -^samba3.vfs.fruit fruit_delete_empty_adfiles.SMB2/CREATE context AAPL\(nt4_dc\) -^samba3.vfs.fruit fruit_delete_empty_adfiles.truncate resource fork to 0 bytes\(nt4_dc\) -^samba3.vfs.fruit fruit_delete_empty_adfiles.opening and creating resource fork\(nt4_dc\) -^samba3.vfs.fruit fruit_delete_empty_adfiles.create delete-on-close AFP_AfpResource\(nt4_dc\) -^samba3.vfs.fruit fruit_delete_empty_adfiles.setinfo delete-on-close AFP_AfpResource\(nt4_dc\) -^samba3.vfs.fruit fruit_delete_empty_adfiles.delete\(nt4_dc\) -^samba3.vfs.fruit fruit_delete_empty_adfiles.read open rsrc after rename\(nt4_dc\) -^samba3.vfs.fruit fruit_delete_empty_adfiles.readdir_attr with names with illegal ntfs characters\(nt4_dc\) -^samba3.vfs.fruit fruit_delete_empty_adfiles.copy-chunk streams\(nt4_dc\) -^samba3.vfs.fruit fruit_delete_empty_adfiles.empty_stream\(nt4_dc\) -^samba3.vfs.fruit fruit_delete_empty_adfiles.setinfo eof AFP_AfpResource\(nt4_dc\) diff --git a/source3/modules/vfs_fruit.c b/source3/modules/vfs_fruit.c index bf592c91050..9e22a1338ae 100644 --- a/source3/modules/vfs_fruit.c +++ b/source3/modules/vfs_fruit.c @@ -1452,27 +1452,37 @@ static bool ad_convert_delete_adfile(struct adouble *ad, * @return -1 in case an error occurred, 0 if no conversion was done, 1 * otherwise **/ -static int ad_convert(struct adouble *ad, +static int ad_convert(struct vfs_handle_struct *handle, const struct smb_filename *smb_fname) { + struct adouble *ad = NULL; bool ok; bool converted_xattr = false; bool blank; + int ret; + + ad = ad_get(talloc_tos(), handle, smb_fname, ADOUBLE_RSRC); + if (ad == NULL) { + return 0; + } ok = ad_convert_xattr(ad, smb_fname, &converted_xattr); if (!ok) { - return -1; + ret = -1; + goto done; } ok = ad_convert_blank_rfork(ad, &blank); if (!ok) { - return -1; + ret = -1; + goto done; } if (converted_xattr || blank) { ok = ad_convert_truncate(ad, smb_fname); if (!ok) { - return -1; + ret = -1; + goto done; } } @@ -1480,15 +1490,20 @@ static int ad_convert(struct adouble *ad, if (!ok) { DBG_ERR("Failed to convert [%s]\n", smb_fname_str_dbg(smb_fname)); - return -1; + ret = -1; + goto done; } ok = ad_convert_delete_adfile(ad, smb_fname); if (!ok) { - return -1; + ret = -1; + goto done; } - return 0; + ret = 0; +done: + TALLOC_FREE(ad); + return ret; } /** @@ -1741,17 +1756,6 @@ static ssize_t ad_read_rsrc_adouble(struct adouble *ad, return -1; } - /* - * Try to fixup AppleDouble files created by OS X with xattrs - * appended to the ADEID_FINDERI entry. - */ - - ret = ad_convert(ad, smb_fname); - if (ret != 0) { - DBG_WARNING("Failed to convert [%s]\n", smb_fname->base_name); - return len; - } - return len; } @@ -2139,9 +2143,8 @@ static bool is_afpresource_stream(const struct smb_filename *smb_fname) } /** - * Test whether stream is an Apple stream, not used atm + * Test whether stream is an Apple stream. **/ -#if 0 static bool is_apple_stream(const struct smb_filename *smb_fname) { if (is_afpinfo_stream(smb_fname)) { @@ -2152,7 +2155,6 @@ static bool is_apple_stream(const struct smb_filename *smb_fname) } return false; } -#endif /** * Initialize config struct from our smb.conf config parameters @@ -6074,6 +6076,8 @@ static NTSTATUS fruit_create_file(vfs_handle_struct *handle, struct fruit_config_data *config = NULL; files_struct *fsp = NULL; struct fio *fio = NULL; + bool internal_open = (oplock_request & INTERNAL_OPEN_ONLY); + int ret; status = check_aapl(handle, req, in_context_blobs, out_context_blobs); if (!NT_STATUS_IS_OK(status)) { @@ -6083,6 +6087,14 @@ static NTSTATUS fruit_create_file(vfs_handle_struct *handle, SMB_VFS_HANDLE_GET_DATA(handle, config, struct fruit_config_data, return NT_STATUS_UNSUCCESSFUL); + if (is_apple_stream(smb_fname) && !internal_open) { + ret = ad_convert(handle, smb_fname); + if (ret != 0) { + DBG_ERR("ad_convert() failed\n"); + return NT_STATUS_UNSUCCESSFUL; + } + } + status = SMB_VFS_NEXT_CREATE_FILE( handle, req, root_dir_fid, smb_fname, access_mask, share_access, @@ -6165,6 +6177,7 @@ static NTSTATUS fruit_readdir_attr(struct vfs_handle_struct *handle, struct fruit_config_data *config = NULL; struct readdir_attr_data *attr_data; NTSTATUS status; + int ret; SMB_VFS_HANDLE_GET_DATA(handle, config, struct fruit_config_data, @@ -6176,6 +6189,12 @@ static NTSTATUS fruit_readdir_attr(struct vfs_handle_struct *handle, DEBUG(10, ("fruit_readdir_attr %s\n", fname->base_name)); + ret = ad_convert(handle, fname); + if (ret != 0) { + DBG_ERR("ad_convert() failed\n"); + return NT_STATUS_UNSUCCESSFUL; + } + *pattr_data = talloc_zero(mem_ctx, struct readdir_attr_data); if (*pattr_data == NULL) { return NT_STATUS_UNSUCCESSFUL; -- 2.34.1