Commit 8b1dfd9b authored by Ralph Boehme's avatar Ralph Boehme Committed by Karolin Seeger

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=13958Signed-off-by: 's avatarRalph Boehme <slow@samba.org>
Reviewed-by: 's avatarJeremy Allison <jra@samba.org>
(cherry picked from commit 78a4639b2d06cc69788861618d2e91945e142d2b)

Autobuild-User(v4-9-test): Karolin Seeger <kseeger@samba.org>
Autobuild-Date(v4-9-test): Thu Jun 13 14:25:17 UTC 2019 on sn-devel-144
parent 267e70cb
^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\)
......@@ -1450,27 +1450,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;
}
}
......@@ -1478,15 +1488,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;
}
/**
......@@ -1739,17 +1754,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;
}
......@@ -2137,9 +2141,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)) {
......@@ -2150,7 +2153,6 @@ static bool is_apple_stream(const struct smb_filename *smb_fname)
}
return false;
}
#endif
/**
* Initialize config struct from our smb.conf config parameters
......@@ -6046,6 +6048,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)) {
......@@ -6055,6 +6059,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,
......@@ -6137,6 +6149,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,
......@@ -6148,6 +6161,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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment