#include "messages.h"
#include "libcli/security/security.h"
#include "../libcli/smb/smb2_create_ctx.h"
-#include "lib/sys_rw.h"
+#include "lib/util/sys_rw.h"
+#include "lib/util/tevent_ntstatus.h"
/*
* Enhanced OS X and Netatalk compatibility
* REVIEW:
* This is hokey, but what else can we do?
*/
+#define NETATALK_META_XATTR "org.netatalk.Metadata"
#if defined(HAVE_ATTROPEN) || defined(FREEBSD)
-#define AFPINFO_EA_NETATALK "org.netatalk.Metadata"
+#define AFPINFO_EA_NETATALK NETATALK_META_XATTR
#define AFPRESOURCE_EA_NETATALK "org.netatalk.ResourceFork"
#else
-#define AFPINFO_EA_NETATALK "user.org.netatalk.Metadata"
+#define AFPINFO_EA_NETATALK "user." NETATALK_META_XATTR
#define AFPRESOURCE_EA_NETATALK "user.org.netatalk.ResourceFork"
#endif
enum fruit_meta meta;
enum fruit_locking locking;
enum fruit_encoding encoding;
- bool use_aapl;
+ bool use_aapl; /* config from smb.conf */
+ bool nego_aapl; /* client negotiated AAPL */
+ bool use_copyfile;
bool readdir_attr_enabled;
bool unix_info_enabled;
+ bool copyfile_enabled;
+ bool veto_appledouble;
/*
- * Additional undocumented options, all enabled by default,
+ * Additional options, all enabled by default,
* possibly useful for analyzing performance. The associated
* operations with each of them may be expensive, so having
* the chance to disable them individually gives a chance
}
RSSVAL(ad->ad_data, ADEDOFF_NENTRIES, nent);
- return 0;
+ return true;
}
/**
/*
* Can't use ad_write() because we might not have a fsp
*/
- rc = ad_pack(ad);
- if (rc != 0) {
+ ok = ad_pack(ad);
+ if (!ok) {
+ rc = -1;
goto exit;
}
/* FIXME: direct sys_pwrite(), don't have an fsp */
{
int rc = 0;
ssize_t len;
+ bool ok;
- rc = ad_pack(ad);
- if (rc != 0) {
- goto exit;
+ ok = ad_pack(ad);
+ if (!ok) {
+ return -1;
}
switch (ad->ad_type) {
}
config->encoding = (enum fruit_encoding)enumval;
- if (lp_parm_bool(-1, FRUIT_PARAM_TYPE_NAME, "aapl", true)) {
- config->use_aapl = true;
- }
+ config->veto_appledouble = lp_parm_bool(
+ SNUM(handle->conn), FRUIT_PARAM_TYPE_NAME,
+ "veto_appledouble", true);
- if (lp_parm_bool(SNUM(handle->conn),
- "readdir_attr", "aapl_rsize", true)) {
- config->readdir_attr_rsize = true;
- }
+ config->use_aapl = lp_parm_bool(
+ -1, FRUIT_PARAM_TYPE_NAME, "aapl", true);
- if (lp_parm_bool(SNUM(handle->conn),
- "readdir_attr", "aapl_finder_info", true)) {
- config->readdir_attr_finder_info = true;
- }
+ config->unix_info_enabled = lp_parm_bool(
+ -1, FRUIT_PARAM_TYPE_NAME, "nfs_aces", true);
- if (lp_parm_bool(SNUM(handle->conn),
- "readdir_attr", "aapl_max_access", true)) {
- config->readdir_attr_max_access = true;
- }
+ config->use_copyfile = lp_parm_bool(-1, FRUIT_PARAM_TYPE_NAME,
+ "copyfile", false);
+
+ config->readdir_attr_rsize = lp_parm_bool(
+ SNUM(handle->conn), "readdir_attr", "aapl_rsize", true);
+
+ config->readdir_attr_finder_info = lp_parm_bool(
+ SNUM(handle->conn), "readdir_attr", "aapl_finder_info", true);
+
+ config->readdir_attr_max_access = lp_parm_bool(
+ SNUM(handle->conn), "readdir_attr", "aapl_max_access", true);
SMB_VFS_HANDLE_SET_DATA(handle, config,
NULL, struct fruit_config_data,
return true;
}
+static bool del_fruit_stream(TALLOC_CTX *mem_ctx, unsigned int *num_streams,
+ struct stream_struct **streams,
+ const char *name)
+{
+ struct stream_struct *tmp = *streams;
+ int i;
+
+ if (*num_streams == 0) {
+ return true;
+ }
+
+ for (i = 0; i < *num_streams; i++) {
+ if (strequal_m(tmp[i].name, name)) {
+ break;
+ }
+ }
+
+ if (i == *num_streams) {
+ return true;
+ }
+
+ TALLOC_FREE(tmp[i].name);
+ if (*num_streams - 1 > i) {
+ memmove(&tmp[i], &tmp[i+1],
+ (*num_streams - i - 1) * sizeof(struct stream_struct));
+ }
+
+ *num_streams -= 1;
+ return true;
+}
+
static bool empty_finderinfo(const struct adouble *ad)
{
}
if (aapl->data.length != 24) {
- DEBUG(1, ("unexpected AAPL ctxt legnth: %ju\n",
+ DEBUG(1, ("unexpected AAPL ctxt length: %ju\n",
(uintmax_t)aapl->data.length));
return NT_STATUS_INVALID_PARAMETER;
}
config->readdir_attr_enabled = true;
}
+ if (config->use_copyfile) {
+ server_caps |= SMB2_CRTCTX_AAPL_SUPPORTS_OSX_COPYFILE;
+ config->copyfile_enabled = true;
+ }
+
/*
* The client doesn't set the flag, so we can't check
* for it and just set it unconditionally
*/
- server_caps |= SMB2_CRTCTX_AAPL_SUPPORTS_NFS_ACE;
- config->unix_info_enabled = true;
+ if (config->unix_info_enabled) {
+ server_caps |= SMB2_CRTCTX_AAPL_SUPPORTS_NFS_ACE;
+ }
SBVAL(p, 0, server_caps);
ok = data_blob_append(req, &blob, p, 8);
out_context_blobs,
SMB2_CREATE_TAG_AAPL,
blob);
+ if (NT_STATUS_IS_OK(status)) {
+ config->nego_aapl = true;
+ }
return status;
}
return rc;
}
- list = lp_veto_files(talloc_tos(), SNUM(handle->conn));
-
- if (list) {
- if (strstr(list, "/" ADOUBLE_NAME_PREFIX "*/") == NULL) {
- newlist = talloc_asprintf(
- list,
- "%s/" ADOUBLE_NAME_PREFIX "*/",
- list);
- lp_do_parameter(SNUM(handle->conn),
- "veto files",
- newlist);
- }
- } else {
- lp_do_parameter(SNUM(handle->conn),
- "veto files",
- "/" ADOUBLE_NAME_PREFIX "*/");
- }
-
- TALLOC_FREE(list);
-
rc = init_fruit_config(handle);
if (rc != 0) {
return rc;
SMB_VFS_HANDLE_GET_DATA(handle, config,
struct fruit_config_data, return -1);
+ if (config->veto_appledouble) {
+ list = lp_veto_files(talloc_tos(), SNUM(handle->conn));
+
+ if (list) {
+ if (strstr(list, "/" ADOUBLE_NAME_PREFIX "*/") == NULL) {
+ newlist = talloc_asprintf(
+ list,
+ "%s/" ADOUBLE_NAME_PREFIX "*/",
+ list);
+ lp_do_parameter(SNUM(handle->conn),
+ "veto files",
+ newlist);
+ }
+ } else {
+ lp_do_parameter(SNUM(handle->conn),
+ "veto files",
+ "/" ADOUBLE_NAME_PREFIX "*/");
+ }
+
+ TALLOC_FREE(list);
+ }
+
if (config->encoding == FRUIT_ENC_NATIVE) {
lp_do_parameter(
SNUM(handle->conn),
{
int rc = -1;
struct fruit_config_data *config = NULL;
- char *adp = NULL;
-
- if (!is_ntfs_stream_smb_fname(smb_fname)) {
- return SMB_VFS_NEXT_UNLINK(handle, smb_fname);
- }
SMB_VFS_HANDLE_GET_DATA(handle, config,
struct fruit_config_data, return -1);
+ if (!is_ntfs_stream_smb_fname(smb_fname)) {
+ char *adp = NULL;
+
+ rc = SMB_VFS_NEXT_UNLINK(handle, smb_fname);
+ if (rc != 0) {
+ return -1;
+ }
+
+ if (config->rsrc != FRUIT_RSRC_ADFILE) {
+ return 0;
+ }
+
+ /*
+ * 0 byte resource fork streams are not listed by
+ * vfs_streaminfo, as a result stream cleanup/deletion of file
+ * deletion doesn't remove the resourcefork stream.
+ */
+ rc = adouble_path(talloc_tos(),
+ smb_fname->base_name, &adp);
+ if (rc != 0) {
+ return -1;
+ }
+
+ /* FIXME: direct unlink(), missing smb_fname */
+ DBG_DEBUG("fruit_unlink: %s\n", adp);
+ rc = unlink(adp);
+ if ((rc == -1) && (errno == ENOENT)) {
+ rc = 0;
+ }
+
+ TALLOC_FREE(adp);
+ return 0;
+ }
+
if (is_afpinfo_stream(smb_fname)) {
if (config->meta == FRUIT_META_STREAM) {
rc = SMB_VFS_NEXT_UNLINK(handle, smb_fname);
smb_fname->base_name,
AFPINFO_EA_NETATALK);
}
- } else if (is_afpresource_stream(smb_fname)) {
- if (config->rsrc == FRUIT_RSRC_ADFILE) {
- rc = adouble_path(talloc_tos(),
- smb_fname->base_name, &adp);
- if (rc != 0) {
- return -1;
- }
- /* FIXME: direct unlink(), missing smb_fname */
- rc = unlink(adp);
- if ((rc == -1) && (errno == ENOENT)) {
- rc = 0;
- }
- } else {
- rc = SMB_VFS_REMOVEXATTR(handle->conn,
- smb_fname->base_name,
- AFPRESOURCE_EA_NETATALK);
- }
- } else {
- rc = SMB_VFS_NEXT_UNLINK(handle, smb_fname);
+
+ return rc;
}
- TALLOC_FREE(adp);
- return rc;
+ if (is_afpresource_stream(smb_fname)) {
+ /* OS X ignores deletes on the AFP_Resource stream */
+ return 0;
+ }
+
+ return SMB_VFS_NEXT_UNLINK(handle, smb_fname);
+
+
+ return 0;
}
static int fruit_chmod(vfs_handle_struct *handle,
return rc;
}
-static int fruit_rmdir(struct vfs_handle_struct *handle, const char *path)
+static int fruit_rmdir(struct vfs_handle_struct *handle,
+ const struct smb_filename *smb_fname)
{
DIR *dh = NULL;
struct dirent *de;
struct fruit_config_data *config;
+ const char *path = smb_fname->base_name;
SMB_VFS_HANDLE_GET_DATA(handle, config,
struct fruit_config_data, return -1);
if (dh) {
closedir(dh);
}
- return SMB_VFS_NEXT_RMDIR(handle, path);
+ return SMB_VFS_NEXT_RMDIR(handle, smb_fname);
}
static ssize_t fruit_pread(vfs_handle_struct *handle,
handle, fsp);
struct fruit_config_data *config = NULL;
AfpInfo *ai = NULL;
- ssize_t len;
+ ssize_t len = -1;
char *name = NULL;
char *tmp_base_name = NULL;
NTSTATUS status;
}
if (ad->ad_type == ADOUBLE_META) {
+ char afpinfo_buf[AFP_INFO_SIZE];
+ size_t to_return;
+
+ /*
+ * OS X has a off-by-1 error in the offset calculation, so we're
+ * bug compatible here. It won't hurt, as any relevant real
+ * world read requests from the AFP_AfpInfo stream will be
+ * offset=0 n=60. offset is ignored anyway, see below.
+ */
+ if ((offset < 0) || (offset >= AFP_INFO_SIZE + 1)) {
+ len = 0;
+ rc = 0;
+ goto exit;
+ }
+
+ to_return = MIN(n, AFP_INFO_SIZE);
+
ai = afpinfo_new(talloc_tos());
if (ai == NULL) {
rc = -1;
memcpy(&ai->afpi_FinderInfo[0],
ad_entry(ad, ADEID_FINDERI),
ADEDLEN_FINDERI);
- len = afpinfo_pack(ai, data);
+ len = afpinfo_pack(ai, afpinfo_buf);
if (len != AFP_INFO_SIZE) {
rc = -1;
goto exit;
}
+
+ /*
+ * OS X ignores offset when reading from AFP_AfpInfo stream!
+ */
+ memcpy(data, afpinfo_buf, to_return);
+ len = to_return;
} else {
len = SMB_VFS_NEXT_PREAD(
handle, fsp, data, n,
}
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,
struct smb_filename *smb_fname,
bool follow_links)
{
+ struct adouble *ad = NULL;
+
+ ad = ad_get(talloc_tos(), handle, smb_fname->base_name, ADOUBLE_META);
+ if (ad == NULL) {
+ DBG_INFO("fruit_stat_meta %s: %s\n",
+ smb_fname_str_dbg(smb_fname), strerror(errno));
+ errno = ENOENT;
+ return -1;
+ }
+ TALLOC_FREE(ad);
+
/* Populate the stat struct with info from the base file. */
if (fruit_stat_base(handle, smb_fname, follow_links) == -1) {
return -1;
struct fruit_config_data *config = NULL;
struct smb_filename *smb_fname = NULL;
struct adouble *ad = NULL;
+ NTSTATUS status;
SMB_VFS_HANDLE_GET_DATA(handle, config, struct fruit_config_data,
return NT_STATUS_UNSUCCESSFUL);
if (config->rsrc != FRUIT_RSRC_STREAM) {
ad = ad_get(talloc_tos(), handle, smb_fname->base_name,
ADOUBLE_RSRC);
- if (ad) {
+ if (ad && (ad_getentrylen(ad, ADEID_RFORK) > 0)) {
if (!add_fruit_stream(
mem_ctx, pnum_streams, pstreams,
AFPRESOURCE_STREAM_NAME,
TALLOC_FREE(smb_fname);
- return SMB_VFS_NEXT_STREAMINFO(handle, fsp, fname, mem_ctx,
- pnum_streams, pstreams);
+ status = SMB_VFS_NEXT_STREAMINFO(handle, fsp, fname, mem_ctx,
+ pnum_streams, pstreams);
+ if (!NT_STATUS_IS_OK(status)) {
+ return status;
+ }
+
+ if (config->meta == FRUIT_META_NETATALK) {
+ /* Remove the Netatalk xattr from the list */
+ if (!del_fruit_stream(mem_ctx, pnum_streams, pstreams,
+ ":" NETATALK_META_XATTR ":$DATA")) {
+ TALLOC_FREE(ad);
+ TALLOC_FREE(smb_fname);
+ return NT_STATUS_NO_MEMORY;
+ }
+ }
+
+ return NT_STATUS_OK;
}
static int fruit_ntimes(vfs_handle_struct *handle,
return -1;
}
+static int fruit_ftruncate_meta(struct vfs_handle_struct *handle,
+ struct files_struct *fsp,
+ off_t offset,
+ struct adouble *ad)
+{
+ struct fruit_config_data *config;
+
+ SMB_VFS_HANDLE_GET_DATA(handle, config,
+ struct fruit_config_data, return -1);
+
+ if (offset > 60) {
+ DBG_WARNING("ftruncate %s to %jd",
+ fsp_str_dbg(fsp), (intmax_t)offset);
+ /* OS X returns NT_STATUS_ALLOTTED_SPACE_EXCEEDED */
+ errno = EOVERFLOW;
+ return -1;
+ }
+
+ DBG_WARNING("ignoring ftruncate %s to %jd",
+ fsp_str_dbg(fsp), (intmax_t)offset);
+ /* OS X returns success but does nothing */
+ return 0;
+}
+
+static int fruit_ftruncate_rsrc(struct vfs_handle_struct *handle,
+ struct files_struct *fsp,
+ off_t offset,
+ struct adouble *ad)
+{
+ int rc;
+ struct fruit_config_data *config;
+
+ SMB_VFS_HANDLE_GET_DATA(handle, config,
+ struct fruit_config_data, return -1);
+
+ if (config->rsrc == FRUIT_RSRC_XATTR && offset == 0) {
+ return SMB_VFS_FREMOVEXATTR(fsp,
+ AFPRESOURCE_EA_NETATALK);
+ }
+
+ rc = SMB_VFS_NEXT_FTRUNCATE(
+ handle, fsp,
+ offset + ad_getentryoff(ad, ADEID_RFORK));
+ if (rc != 0) {
+ return -1;
+ }
+
+ if (config->rsrc == FRUIT_RSRC_ADFILE) {
+ ad_setentrylen(ad, ADEID_RFORK, offset);
+ rc = ad_write(ad, NULL);
+ if (rc != 0) {
+ return -1;
+ }
+ DEBUG(10, ("fruit_ftruncate_rsrc file %s offset %jd\n",
+ fsp_str_dbg(fsp), (intmax_t)offset));
+ }
+
+ return 0;
+}
+
static int fruit_ftruncate(struct vfs_handle_struct *handle,
struct files_struct *fsp,
off_t offset)
int rc = 0;
struct adouble *ad =
(struct adouble *)VFS_FETCH_FSP_EXTENSION(handle, fsp);
- struct fruit_config_data *config;
- DEBUG(10, ("streams_xattr_ftruncate called for file %s offset %.0f\n",
- fsp_str_dbg(fsp), (double)offset));
+ DBG_DEBUG("fruit_ftruncate called for file %s offset %.0f\n",
+ fsp_str_dbg(fsp), (double)offset);
if (ad == NULL) {
return SMB_VFS_NEXT_FTRUNCATE(handle, fsp, offset);
return -1;
}
- SMB_VFS_HANDLE_GET_DATA(handle, config,
- struct fruit_config_data, return -1);
-
switch (ad->ad_type) {
case ADOUBLE_META:
- /*
- * As this request hasn't been seen in the wild,
- * the only sensible use I can imagine is the client
- * truncating the stream to 0 bytes size.
- * We simply remove the metadata on such a request.
- */
- if (offset == 0) {
- rc = SMB_VFS_FREMOVEXATTR(fsp,
- AFPRESOURCE_EA_NETATALK);
- }
+ rc = fruit_ftruncate_meta(handle, fsp, offset, ad);
break;
+
case ADOUBLE_RSRC:
- if (config->rsrc == FRUIT_RSRC_XATTR && offset == 0) {
- rc = SMB_VFS_FREMOVEXATTR(fsp,
- AFPRESOURCE_EA_NETATALK);
- } else {
- rc = SMB_VFS_NEXT_FTRUNCATE(
- handle, fsp,
- offset + ad_getentryoff(ad, ADEID_RFORK));
- if (rc != 0) {
- return -1;
- }
- ad_setentrylen(ad, ADEID_RFORK, offset);
- rc = ad_write(ad, NULL);
- if (rc != 0) {
- return -1;
- }
- }
+ rc = fruit_ftruncate_rsrc(handle, fsp, offset, ad);
break;
+
default:
return -1;
}
{
NTSTATUS status;
struct fruit_config_data *config = NULL;
+ files_struct *fsp = NULL;
status = check_aapl(handle, req, in_context_blobs, out_context_blobs);
if (!NT_STATUS_IS_OK(status)) {
- return status;
+ goto fail;
}
SMB_VFS_HANDLE_GET_DATA(handle, config, struct fruit_config_data,
return status;
}
+ fsp = *result;
+
+ if (config->nego_aapl) {
+ if (config->copyfile_enabled) {
+ /*
+ * Set a flag in the fsp. Gets used in
+ * copychunk to check whether the special
+ * Apple copyfile semantics for copychunk
+ * should be allowed in a copychunk request
+ * with a count of 0.
+ */
+ fsp->aapl_copyfile_supported = true;
+ }
+
+ if (fsp->is_directory) {
+ /*
+ * Enable POSIX directory rename behaviour
+ */
+ fsp->posix_flags |= FSP_POSIX_FLAGS_RENAME;
+ }
+ }
+
+ /*
+ * If this is a plain open for existing files, opening an 0
+ * byte size resource fork MUST fail with
+ * NT_STATUS_OBJECT_NAME_NOT_FOUND.
+ *
+ * Cf the vfs_fruit torture tests in test_rfork_create().
+ */
+ if (is_afpresource_stream(fsp->fsp_name) &&
+ create_disposition == FILE_OPEN)
+ {
+ if (fsp->fsp_name->st.st_ex_size == 0) {
+ status = NT_STATUS_OBJECT_NAME_NOT_FOUND;
+ goto fail;
+ }
+ }
+
if (is_ntfs_stream_smb_fname(smb_fname)
- || (*result == NULL)
- || ((*result)->is_directory)) {
+ || fsp->is_directory) {
return status;
}
return status;
fail:
- DEBUG(1, ("fruit_create_file: %s\n", nt_errstr(status)));
+ DEBUG(10, ("fruit_create_file: %s\n", nt_errstr(status)));
- if (*result) {
- close_file(req, *result, ERROR_CLOSE);
- *result = NULL;
+ if (fsp) {
+ close_file(req, fsp, ERROR_CLOSE);
+ *result = fsp = NULL;
}
return status;
mode_t ms_nfs_mode;
int result;
- DEBUG(1, ("fruit_fset_nt_acl: %s\n", fsp_str_dbg(fsp)));
+ DBG_DEBUG("fruit_fset_nt_acl: %s\n", fsp_str_dbg(fsp));
status = check_ms_nfs(handle, fsp, psd, &ms_nfs_mode, &do_chmod);
if (!NT_STATUS_IS_OK(status)) {
if (do_chmod) {
if (fsp->fh->fd != -1) {
- DEBUG(1, ("fchmod: %s\n", fsp_str_dbg(fsp)));
result = SMB_VFS_FCHMOD(fsp, ms_nfs_mode);
} else {
- DEBUG(1, ("chmod: %s\n", fsp_str_dbg(fsp)));
result = SMB_VFS_CHMOD(fsp->conn,
fsp->fsp_name->base_name,
ms_nfs_mode);
return NT_STATUS_OK;
}
+struct fruit_copy_chunk_state {
+ struct vfs_handle_struct *handle;
+ off_t copied;
+ struct files_struct *src_fsp;
+ struct files_struct *dst_fsp;
+ bool is_copyfile;
+};
+
+static void fruit_copy_chunk_done(struct tevent_req *subreq);
+static struct tevent_req *fruit_copy_chunk_send(struct vfs_handle_struct *handle,
+ TALLOC_CTX *mem_ctx,
+ struct tevent_context *ev,
+ struct files_struct *src_fsp,
+ off_t src_off,
+ struct files_struct *dest_fsp,
+ off_t dest_off,
+ off_t num)
+{
+ struct tevent_req *req, *subreq;
+ struct fruit_copy_chunk_state *fruit_copy_chunk_state;
+ NTSTATUS status;
+ struct fruit_config_data *config;
+ off_t to_copy = num;
+
+ DEBUG(10,("soff: %ju, doff: %ju, len: %ju\n",
+ (uintmax_t)src_off, (uintmax_t)dest_off, (uintmax_t)num));
+
+ SMB_VFS_HANDLE_GET_DATA(handle, config,
+ struct fruit_config_data,
+ return NULL);
+
+ req = tevent_req_create(mem_ctx, &fruit_copy_chunk_state,
+ struct fruit_copy_chunk_state);
+ if (req == NULL) {
+ return NULL;
+ }
+ fruit_copy_chunk_state->handle = handle;
+ fruit_copy_chunk_state->src_fsp = src_fsp;
+ fruit_copy_chunk_state->dst_fsp = dest_fsp;
+
+ /*
+ * Check if this a OS X copyfile style copychunk request with
+ * a requested chunk count of 0 that was translated to a
+ * copy_chunk_send VFS call overloading the parameters src_off
+ * = dest_off = num = 0.
+ */
+ if ((src_off == 0) && (dest_off == 0) && (num == 0) &&
+ src_fsp->aapl_copyfile_supported &&
+ dest_fsp->aapl_copyfile_supported)
+ {
+ status = vfs_stat_fsp(src_fsp);
+ if (tevent_req_nterror(req, status)) {
+ return tevent_req_post(req, ev);
+ }
+
+ to_copy = src_fsp->fsp_name->st.st_ex_size;
+ fruit_copy_chunk_state->is_copyfile = true;
+ }
+
+ subreq = SMB_VFS_NEXT_COPY_CHUNK_SEND(handle,
+ mem_ctx,
+ ev,
+ src_fsp,
+ src_off,
+ dest_fsp,
+ dest_off,
+ to_copy);
+ if (tevent_req_nomem(subreq, req)) {
+ return tevent_req_post(req, ev);
+ }
+
+ tevent_req_set_callback(subreq, fruit_copy_chunk_done, req);
+ return req;
+}
+
+static void fruit_copy_chunk_done(struct tevent_req *subreq)
+{
+ struct tevent_req *req = tevent_req_callback_data(
+ subreq, struct tevent_req);
+ struct fruit_copy_chunk_state *state = tevent_req_data(
+ req, struct fruit_copy_chunk_state);
+ NTSTATUS status;
+ unsigned int num_streams = 0;
+ struct stream_struct *streams = NULL;
+ int i;
+ struct smb_filename *src_fname_tmp = NULL;
+ struct smb_filename *dst_fname_tmp = NULL;
+
+ status = SMB_VFS_NEXT_COPY_CHUNK_RECV(state->handle,
+ subreq,
+ &state->copied);
+ TALLOC_FREE(subreq);
+ if (tevent_req_nterror(req, status)) {
+ return;
+ }
+
+ if (!state->is_copyfile) {
+ tevent_req_done(req);
+ return;
+ }
+
+ /*
+ * Now copy all reamining streams. We know the share supports
+ * streams, because we're in vfs_fruit. We don't do this async
+ * because streams are few and small.
+ */
+ status = vfs_streaminfo(state->handle->conn, NULL,
+ state->src_fsp->fsp_name->base_name,
+ req, &num_streams, &streams);
+ if (tevent_req_nterror(req, status)) {
+ return;
+ }
+
+ if (num_streams == 1) {
+ /* There is always one stream, ::$DATA. */
+ tevent_req_done(req);
+ return;
+ }
+
+ for (i = 0; i < num_streams; i++) {
+ DEBUG(10, ("%s: stream: '%s'/%ju\n",
+ __func__, streams[i].name,
+ (uintmax_t)streams[i].size));
+
+ src_fname_tmp = synthetic_smb_fname(
+ req,
+ state->src_fsp->fsp_name->base_name,
+ streams[i].name,
+ NULL);
+ if (tevent_req_nomem(src_fname_tmp, req)) {
+ return;
+ }
+
+ if (is_ntfs_default_stream_smb_fname(src_fname_tmp)) {
+ TALLOC_FREE(src_fname_tmp);
+ continue;
+ }
+
+ dst_fname_tmp = synthetic_smb_fname(
+ req,
+ state->dst_fsp->fsp_name->base_name,
+ streams[i].name,
+ NULL);
+ if (tevent_req_nomem(dst_fname_tmp, req)) {
+ TALLOC_FREE(src_fname_tmp);
+ return;
+ }
+
+ status = copy_file(req,
+ state->handle->conn,
+ src_fname_tmp,
+ dst_fname_tmp,
+ OPENX_FILE_CREATE_IF_NOT_EXIST,
+ 0, false);
+ if (!NT_STATUS_IS_OK(status)) {
+ DEBUG(1, ("%s: copy %s to %s failed: %s\n", __func__,
+ smb_fname_str_dbg(src_fname_tmp),
+ smb_fname_str_dbg(dst_fname_tmp),
+ nt_errstr(status)));
+ TALLOC_FREE(src_fname_tmp);
+ TALLOC_FREE(dst_fname_tmp);
+ tevent_req_nterror(req, status);
+ return;
+ }
+
+ TALLOC_FREE(src_fname_tmp);
+ TALLOC_FREE(dst_fname_tmp);
+ }
+
+ TALLOC_FREE(streams);
+ TALLOC_FREE(src_fname_tmp);
+ TALLOC_FREE(dst_fname_tmp);
+ tevent_req_done(req);
+}
+
+static NTSTATUS fruit_copy_chunk_recv(struct vfs_handle_struct *handle,
+ struct tevent_req *req,
+ off_t *copied)
+{
+ struct fruit_copy_chunk_state *fruit_copy_chunk_state = tevent_req_data(
+ req, struct fruit_copy_chunk_state);
+ NTSTATUS status;
+
+ if (tevent_req_is_nterror(req, &status)) {
+ DEBUG(1, ("server side copy chunk failed: %s\n",
+ nt_errstr(status)));
+ *copied = 0;
+ tevent_req_received(req);
+ return status;
+ }
+
+ *copied = fruit_copy_chunk_state->copied;
+ tevent_req_received(req);
+
+ return NT_STATUS_OK;
+}
+
static struct vfs_fn_pointers vfs_fruit_fns = {
.connect_fn = fruit_connect,
.fallocate_fn = fruit_fallocate,
.create_file_fn = fruit_create_file,
.readdir_attr_fn = fruit_readdir_attr,
+ .copy_chunk_send_fn = fruit_copy_chunk_send,
+ .copy_chunk_recv_fn = fruit_copy_chunk_recv,
/* NT ACL operations */
.fget_nt_acl_fn = fruit_fget_nt_acl,