#include "smbd/globals.h"
#include "messages.h"
#include "libcli/security/security.h"
+#include "../libcli/smb/smb2_create_ctx.h"
+#include "lib/util/sys_rw.h"
+#include "lib/util/tevent_ntstatus.h"
/*
* Enhanced OS X and Netatalk compatibility
*
* The AFP_Resource stream is stored in an AppleDouble file prepending
* "._" to the filename. On Solaris with ZFS the stream is optionally
- * stored in an EA "org.netatalk.ressource".
+ * stored in an EA "org.netatalk.resource".
*
*
* Extended Attributes
#define FRUIT_PARAM_TYPE_NAME "fruit"
#define ADOUBLE_NAME_PREFIX "._"
-/*
- * REVIEW:
- * This is hokey, but what else can we do?
- */
-#if defined(HAVE_ATTROPEN) || defined(FREEBSD)
-#define AFPINFO_EA_NETATALK "org.netatalk.Metadata"
-#define AFPRESOURCE_EA_NETATALK "org.netatalk.ResourceFork"
+#define NETATALK_META_XATTR "org.netatalk.Metadata"
+#define NETATALK_RSRC_XATTR "org.netatalk.ResourceFork"
+
+#if defined(HAVE_ATTROPEN)
+#define AFPINFO_EA_NETATALK NETATALK_META_XATTR
+#define AFPRESOURCE_EA_NETATALK NETATALK_RSRC_XATTR
#else
-#define AFPINFO_EA_NETATALK "user.org.netatalk.Metadata"
-#define AFPRESOURCE_EA_NETATALK "user.org.netatalk.ResourceFork"
+#define AFPINFO_EA_NETATALK "user." NETATALK_META_XATTR
+#define AFPRESOURCE_EA_NETATALK "user." NETATALK_RSRC_XATTR
#endif
enum apple_fork {APPLE_FORK_DATA, APPLE_FORK_RSRC};
enum fruit_meta meta;
enum fruit_locking locking;
enum fruit_encoding encoding;
+ 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;
+ bool posix_rename;
+
+ /*
+ * 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
+ * tweaking the setup for the particular usecase.
+ */
+ bool readdir_attr_rsize;
+ bool readdir_attr_finder_info;
+ bool readdir_attr_max_access;
};
static const struct enum_list fruit_rsrc[] = {
#define ad_getentryoff(ad,eid) ((ad)->ad_eid[(eid)].ade_off)
#define ad_setentrylen(ad,eid,len) ((ad)->ad_eid[(eid)].ade_len = (len))
#define ad_setentryoff(ad,eid,off) ((ad)->ad_eid[(eid)].ade_off = (off))
-#define ad_entry(ad,eid) ((ad)->ad_data + ad_getentryoff((ad),(eid)))
struct ad_entry {
size_t ade_off;
{0, 0, 0}
};
-/* AppleDouble ressource fork file (the ones prefixed by "._") */
+/* AppleDouble resource fork file (the ones prefixed by "._") */
static const
struct ad_entry_order entry_order_dot_und[ADEID_NUM_DOT_UND + 1] = {
{ADEID_FINDERI, ADEDOFF_FINDERI_DOT_UND, ADEDLEN_FINDERI},
};
/*
- * Fake AppleDouble entry oder for ressource fork xattr. The xattr
- * isn't an AppleDouble file, it simply contains the ressource data,
+ * Fake AppleDouble entry oder for resource fork xattr. The xattr
+ * isn't an AppleDouble file, it simply contains the resource data,
* but in order to be able to use some API calls like ad_getentryoff()
* we build a fake/helper struct adouble with this entry order struct.
*/
static int ad_write(struct adouble *ad, const char *path);
static int adouble_path(TALLOC_CTX *ctx, const char *path_in, char **path_out);
+/**
+ * Return a pointer to an AppleDouble entry
+ *
+ * Returns NULL if the entry is not present
+ **/
+static char *ad_get_entry(const struct adouble *ad, int eid)
+{
+ off_t off = ad_getentryoff(ad, eid);
+ size_t len = ad_getentrylen(ad, eid);
+
+ if (off == 0 || len == 0) {
+ return NULL;
+ }
+
+ return ad->ad_data + off;
+}
+
/**
* Get a date
**/
uint32_t *date)
{
bool xlate = (dateoff & AD_DATE_UNIX);
+ char *p = NULL;
dateoff &= AD_DATE_MASK;
- if (!ad_getentryoff(ad, ADEID_FILEDATESI)) {
+ p = ad_get_entry(ad, ADEID_FILEDATESI);
+ if (p == NULL) {
return -1;
}
if (dateoff > AD_DATE_ACCESS) {
return -1;
}
- memcpy(date,
- ad_entry(ad, ADEID_FILEDATESI) + dateoff,
- sizeof(uint32_t));
+
+ memcpy(date, p + dateoff, sizeof(uint32_t));
if (xlate) {
*date = AD_DATE_TO_UNIX(*date);
static int ad_setdate(struct adouble *ad, unsigned int dateoff, uint32_t date)
{
bool xlate = (dateoff & AD_DATE_UNIX);
+ char *p = NULL;
- if (!ad_getentryoff(ad, ADEID_FILEDATESI)) {
- return 0;
+ p = ad_get_entry(ad, ADEID_FILEDATESI);
+ if (p == NULL) {
+ return -1;
}
dateoff &= AD_DATE_MASK;
return -1;
}
- memcpy(ad_entry(ad, ADEID_FILEDATESI) + dateoff, &date, sizeof(date));
+ memcpy(p + dateoff, &date, sizeof(date));
return 0;
}
offset += ADEDLEN_NENTRIES;
for (eid = 0, nent = 0; eid < ADEID_MAX; eid++) {
- if ((ad->ad_eid[eid].ade_off == 0)) {
+ if (ad->ad_eid[eid].ade_off == 0) {
/*
* ade_off is also used as indicator whether a
* specific entry is used or not
}
RSSVAL(ad->ad_data, ADEDOFF_NENTRIES, nent);
- return 0;
+ return true;
}
/**
* Unpack an AppleDouble blob into a struct adoble
**/
-static bool ad_unpack(struct adouble *ad, const int nentries)
+static bool ad_unpack(struct adouble *ad, const size_t nentries,
+ size_t filesize)
{
size_t bufsize = talloc_get_size(ad->ad_data);
- int adentries, i;
+ size_t adentries, i;
uint32_t eid, len, off;
/*
adentries = RSVAL(ad->ad_data, ADEDOFF_NENTRIES);
if (adentries != nentries) {
- DEBUG(1, ("invalid number of entries: %d\n", adentries));
+ DEBUG(1, ("invalid number of entries: %zu\n",
+ adentries));
return false;
}
return false;
}
+ /*
+ * All entries other than the resource fork are
+ * expected to be read into the ad_data buffer, so
+ * ensure the specified offset is within that bound
+ */
if ((off > bufsize) && (eid != ADEID_RFORK)) {
DEBUG(1, ("bogus eid %d: off: %" PRIu32 ", len: %" PRIu32 "\n",
eid, off, len));
return false;
}
+
+ /*
+ * All entries besides FinderInfo and resource fork
+ * must fit into the buffer. FinderInfo is special as
+ * it may be larger then the default 32 bytes (if it
+ * contains marshalled xattrs), but we will fixup that
+ * in ad_convert(). And the resource fork is never
+ * accessed directly by the ad_data buf (also see
+ * comment above) anyway.
+ */
if ((eid != ADEID_RFORK) &&
(eid != ADEID_FINDERI) &&
((off + len) > bufsize)) {
return false;
}
+ /*
+ * That would be obviously broken
+ */
+ if (off > filesize) {
+ DEBUG(1, ("bogus eid %d: off: %" PRIu32 ", len: %" PRIu32 "\n",
+ eid, off, len));
+ return false;
+ }
+
+ /*
+ * Check for any entry that has its end beyond the
+ * filesize.
+ */
+ if (off + len < off) {
+ DEBUG(1, ("offset wrap in eid %d: off: %" PRIu32
+ ", len: %" PRIu32 "\n",
+ eid, off, len));
+ return false;
+
+ }
+ if (off + len > filesize) {
+ /*
+ * If this is the resource fork entry, we fix
+ * up the length, for any other entry we bail
+ * out.
+ */
+ if (eid != ADEID_RFORK) {
+ DEBUG(1, ("bogus eid %d: off: %" PRIu32
+ ", len: %" PRIu32 "\n",
+ eid, off, len));
+ return false;
+ }
+
+ /*
+ * Fixup the resource fork entry by limiting
+ * the size to entryoffset - filesize.
+ */
+ len = filesize - off;
+ DEBUG(1, ("Limiting ADEID_RFORK: off: %" PRIu32
+ ", len: %" PRIu32 "\n", off, len));
+ }
+
ad->ad_eid[eid].ade_off = off;
ad->ad_eid[eid].ade_len = len;
}
* bytes containing packed xattrs. Netatalk can't deal with that, so
* we simply discard the packed xattrs.
*
- * @return -1 in case an error occured, 0 if no conversion was done, 1
+ * @return -1 in case an error occurred, 0 if no conversion was done, 1
* otherwise
**/
static int ad_convert(struct adouble *ad, int fd)
ad_getentrylen(ad, ADEID_RFORK);
/* FIXME: direct use of mmap(), vfs_aio_fork does it too */
- map = mmap(NULL, origlen, PROT_WRITE, MAP_SHARED, fd, 0);
+ map = mmap(NULL, origlen, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
if (map == MAP_FAILED) {
DEBUG(2, ("mmap AppleDouble: %s\n", strerror(errno)));
rc = -1;
goto exit;
}
- memmove(map + ad_getentryoff(ad, ADEID_FINDERI) + ADEDLEN_FINDERI,
- map + ad_getentryoff(ad, ADEID_RFORK),
- ad_getentrylen(ad, ADEID_RFORK));
+ if (ad_getentrylen(ad, ADEID_RFORK) > 0) {
+ memmove(map + ad_getentryoff(ad, ADEID_FINDERI) + ADEDLEN_FINDERI,
+ map + ad_getentryoff(ad, ADEID_RFORK),
+ ad_getentrylen(ad, ADEID_RFORK));
+ }
ad_setentrylen(ad, ADEID_FINDERI, ADEDLEN_FINDERI);
ad_setentryoff(ad, ADEID_RFORK,
}
/* Now parse entries */
- ok = ad_unpack(ad, ADEID_NUM_XATTR);
+ ok = ad_unpack(ad, ADEID_NUM_XATTR, AD_DATASZ_XATTR);
if (!ok) {
DEBUG(2, ("invalid AppleDouble metadata xattr\n"));
errno = EINVAL;
struct adouble *meta_ad = NULL;
SMB_STRUCT_STAT sbuf;
bool ok;
- int saved_errno;
+ int saved_errno = 0;
SMB_VFS_HANDLE_GET_DATA(ad->ad_handle, config,
struct fruit_config_data, return -1);
+ /* Try rw first so we can use the fd in ad_convert() */
+ mode = O_RDWR;
+
if (ad->ad_fsp && ad->ad_fsp->fh && (ad->ad_fsp->fh->fd != -1)) {
fd = ad->ad_fsp->fh->fd;
} else {
}
}
- /* Try rw first so we can use the fd in ad_convert() */
- mode = O_RDWR;
-
retry:
if (config->rsrc == FRUIT_RSRC_XATTR) {
#ifndef HAVE_ATTROPEN
lp_fake_directory_create_times(
SNUM(ad->ad_handle->conn)));
if (rc != 0) {
- rc = -1;
goto exit;
}
- ad_setentrylen(ad, ADEID_RFORK, sbuf.st_ex_size);
+ len = sbuf.st_ex_size;
+ ad_setentrylen(ad, ADEID_RFORK, len);
} else {
/* FIXME: direct sys_pread(), don't have an fsp */
len = sys_pread(fd, ad->ad_data, AD_DATASZ_DOT_UND, 0);
goto exit;
}
+ /* FIXME: direct sys_fstat(), we don't have an fsp */
+ rc = sys_fstat(fd, &sbuf,
+ lp_fake_directory_create_times(
+ SNUM(ad->ad_handle->conn)));
+ if (rc != 0) {
+ goto exit;
+ }
+
/* Now parse entries */
- ok = ad_unpack(ad, ADEID_NUM_DOT_UND);
+ ok = ad_unpack(ad, ADEID_NUM_DOT_UND, sbuf.st_ex_size);
if (!ok) {
- DEBUG(1, ("invalid AppleDouble ressource %s\n", path));
+ DEBUG(1, ("invalid AppleDouble resource %s\n", path));
errno = EINVAL;
rc = -1;
goto exit;
< ADEDLEN_FINDERI)
|| (ad_getentryoff(ad, ADEID_RFORK)
< ADEDOFF_RFORK_DOT_UND)) {
- DEBUG(2, ("invalid AppleDouble ressource %s\n", path));
+ DEBUG(2, ("invalid AppleDouble resource %s\n", path));
errno = EINVAL;
rc = -1;
goto exit;
if ((mode == O_RDWR)
&& (ad_getentrylen(ad, ADEID_FINDERI) > ADEDLEN_FINDERI)) {
+ char *p_ad = NULL;
+ char *p_meta_ad = NULL;
+
rc = ad_convert(ad, fd);
if (rc != 0) {
rc = -1;
/*
* 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 */
goto exit;
}
- memcpy(ad_entry(meta_ad, ADEID_FINDERI),
- ad_entry(ad, ADEID_FINDERI),
- ADEDLEN_FINDERI);
+ p_ad = ad_get_entry(ad, ADEID_FINDERI);
+ if (p_ad == NULL) {
+ rc = -1;
+ goto exit;
+ }
+ p_meta_ad = ad_get_entry(meta_ad, ADEID_FINDERI);
+ if (p_meta_ad == NULL) {
+ rc = -1;
+ goto exit;
+ }
+
+ memcpy(p_meta_ad, p_ad, ADEDLEN_FINDERI);
rc = ad_write(meta_ad, path);
if (rc != 0) {
* Set AppleDouble metadata on a file or directory
*
* @param[in] ad adouble handle
- * @param[in] path pathname to file or directory
+
+ * @param[in] path pathname to file or directory, may be NULL for a
+ * resource fork
*
* @return status code, 0 means success
**/
{
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) {
len = sys_pwrite(ad->ad_fsp->fh->fd, ad->ad_data,
talloc_get_size(ad->ad_data), 0);
if (len != talloc_get_size(ad->ad_data)) {
- DEBUG(1, ("short write on %s: %zd", path, len));
+ DEBUG(1, ("short write on %s: %zd",
+ fsp_str_dbg(ad->ad_fsp), len));
rc = -1;
goto exit;
}
return -1;
}
+ /*
+ * Versions up to Samba 4.5.x had a spelling bug in the
+ * fruit:resource option calling lp_parm_enum with
+ * "res*s*ource" (ie two s).
+ *
+ * In Samba 4.6 we accept both the wrong and the correct
+ * spelling, in Samba 4.7 the bad spelling will be removed.
+ */
enumval = lp_parm_enum(SNUM(handle->conn), FRUIT_PARAM_TYPE_NAME,
"ressource", fruit_rsrc, FRUIT_RSRC_ADFILE);
if (enumval == -1) {
- DEBUG(1, ("value for %s: ressource type unknown\n",
+ DEBUG(1, ("value for %s: resource type unknown\n",
+ FRUIT_PARAM_TYPE_NAME));
+ return -1;
+ }
+ config->rsrc = (enum fruit_rsrc)enumval;
+
+ enumval = lp_parm_enum(SNUM(handle->conn), FRUIT_PARAM_TYPE_NAME,
+ "resource", fruit_rsrc, enumval);
+ if (enumval == -1) {
+ DEBUG(1, ("value for %s: resource type unknown\n",
FRUIT_PARAM_TYPE_NAME));
return -1;
}
}
config->encoding = (enum fruit_encoding)enumval;
+ config->veto_appledouble = lp_parm_bool(
+ SNUM(handle->conn), FRUIT_PARAM_TYPE_NAME,
+ "veto_appledouble", true);
+
+ config->use_aapl = lp_parm_bool(
+ -1, FRUIT_PARAM_TYPE_NAME, "aapl", true);
+
+ config->unix_info_enabled = lp_parm_bool(
+ -1, FRUIT_PARAM_TYPE_NAME, "nfs_aces", true);
+
+ config->use_copyfile = lp_parm_bool(-1, FRUIT_PARAM_TYPE_NAME,
+ "copyfile", false);
+
+ config->posix_rename = lp_parm_bool(
+ SNUM(handle->conn), FRUIT_PARAM_TYPE_NAME, "posix_rename", true);
+
+ 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 -1);
static int adouble_path(TALLOC_CTX *ctx, const char *path_in, char **path_out)
{
char *parent;
- const char *basename;
+ const char *base;
- if (!parent_dirname(ctx, path_in, &parent, &basename)) {
+ if (!parent_dirname(ctx, path_in, &parent, &base)) {
return -1;
}
- *path_out = talloc_asprintf(ctx, "%s/._%s", parent, basename);
+ *path_out = talloc_asprintf(ctx, "%s/._%s", parent, base);
if (*path_out == NULL) {
return -1;
}
return true;
}
-static bool empty_finderinfo(const struct adouble *ad)
+static bool filter_empty_rsrc_stream(unsigned int *num_streams,
+ struct stream_struct **streams)
{
+ struct stream_struct *tmp = *streams;
+ unsigned int i;
- char emptybuf[ADEDLEN_FINDERI] = {0};
- if (memcmp(emptybuf,
- ad_entry(ad, ADEID_FINDERI),
- ADEDLEN_FINDERI) == 0) {
+ if (*num_streams == 0) {
return true;
}
- return false;
+
+ for (i = 0; i < *num_streams; i++) {
+ if (strequal_m(tmp[i].name, AFPRESOURCE_STREAM)) {
+ break;
+ }
+ }
+
+ if (i == *num_streams) {
+ return true;
+ }
+
+ if (tmp[i].size > 0) {
+ 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 del_fruit_stream(TALLOC_CTX *mem_ctx, unsigned int *num_streams,
+ struct stream_struct **streams,
+ const char *name)
+{
+ struct stream_struct *tmp = *streams;
+ unsigned 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 ad_empty_finderinfo(const struct adouble *ad)
+{
+ int cmp;
+ char emptybuf[ADEDLEN_FINDERI] = {0};
+ char *fi = NULL;
+
+ fi = ad_get_entry(ad, ADEID_FINDERI);
+ if (fi == NULL) {
+ DBG_ERR("Missing FinderInfo in struct adouble [%p]\n", ad);
+ return false;
+ }
+
+ cmp = memcmp(emptybuf, fi, ADEDLEN_FINDERI);
+ return (cmp == 0);
+}
+
+static bool ai_empty_finderinfo(const AfpInfo *ai)
+{
+ int cmp;
+ char emptybuf[ADEDLEN_FINDERI] = {0};
+
+ cmp = memcmp(emptybuf, &ai->afpi_FinderInfo[0], ADEDLEN_FINDERI);
+ return (cmp == 0);
}
/**
uint32_t t;
struct timespec creation_time = {0};
struct adouble *ad;
+ struct fruit_config_data *config = NULL;
+
+ SMB_VFS_HANDLE_GET_DATA(handle, config, struct fruit_config_data,
+ return);
+
+ switch (config->meta) {
+ case FRUIT_META_STREAM:
+ return;
+ case FRUIT_META_NETATALK:
+ /* Handled below */
+ break;
+ default:
+ DBG_ERR("Unexpected meta config [%d]\n", config->meta);
+ return;
+ }
ad = ad_get(talloc_tos(), handle, smb_fname->base_name, ADOUBLE_META);
if (ad == NULL) {
/**
* Map an access mask to a Netatalk single byte byte range lock
**/
-static off_t access_to_netatalk_brl(enum apple_fork fork,
+static off_t access_to_netatalk_brl(enum apple_fork fork_type,
uint32_t access_mask)
{
off_t offset;
break;
}
- if (fork == APPLE_FORK_RSRC) {
+ if (fork_type == APPLE_FORK_RSRC) {
if (offset == AD_FILELOCK_OPEN_NONE) {
offset = AD_FILELOCK_RSRC_OPEN_NONE;
} else {
/**
* Map a deny mode to a Netatalk brl
**/
-static off_t denymode_to_netatalk_brl(enum apple_fork fork,
+static off_t denymode_to_netatalk_brl(enum apple_fork fork_type,
uint32_t deny_mode)
{
off_t offset;
smb_panic("denymode_to_netatalk_brl: bad deny mode\n");
}
- if (fork == APPLE_FORK_RSRC) {
+ if (fork_type == APPLE_FORK_RSRC) {
offset += 2;
}
* Call fcntl() with an exclusive F_GETLK request in order to
* determine if there's an exisiting shared lock
*
- * @return true if the requested lock was found or any error occured
+ * @return true if the requested lock was found or any error occurred
* false if the lock was not found
**/
static bool test_netatalk_lock(files_struct *fsp, off_t in_offset)
struct byte_range_lock *br_lck = NULL;
bool open_for_reading, open_for_writing, deny_read, deny_write;
off_t off;
+ bool have_read = false;
+ int flags;
/* FIXME: hardcoded data fork, add resource fork */
- enum apple_fork fork = APPLE_FORK_DATA;
+ enum apple_fork fork_type = APPLE_FORK_DATA;
DEBUG(10, ("fruit_check_access: %s, am: %s/%s, dm: %s/%s\n",
fsp_str_dbg(fsp),
deny_mode & DENY_READ ? "DENY_READ" : "-",
deny_mode & DENY_WRITE ? "DENY_WRITE" : "-"));
+ if (fsp->fh->fd == -1) {
+ return NT_STATUS_OK;
+ }
+
+ flags = fcntl(fsp->fh->fd, F_GETFL);
+ if (flags == -1) {
+ DBG_ERR("fcntl get flags [%s] fd [%d] failed [%s]\n",
+ fsp_str_dbg(fsp), fsp->fh->fd, strerror(errno));
+ return map_nt_error_from_unix(errno);
+ }
+
+ if (flags & (O_RDONLY|O_RDWR)) {
+ /*
+ * Applying fcntl read locks requires an fd opened for
+ * reading. This means we won't be applying locks for
+ * files openend write-only, but what can we do...
+ */
+ have_read = true;
+ }
+
/*
* Check read access and deny read mode
*/
if ((access_mask & FILE_READ_DATA) || (deny_mode & DENY_READ)) {
/* Check access */
open_for_reading = test_netatalk_lock(
- fsp, access_to_netatalk_brl(fork, FILE_READ_DATA));
+ fsp, access_to_netatalk_brl(fork_type, FILE_READ_DATA));
deny_read = test_netatalk_lock(
- fsp, denymode_to_netatalk_brl(fork, DENY_READ));
+ fsp, denymode_to_netatalk_brl(fork_type, DENY_READ));
DEBUG(10, ("read: %s, deny_write: %s\n",
open_for_reading == true ? "yes" : "no",
}
/* Set locks */
- if (access_mask & FILE_READ_DATA) {
- off = access_to_netatalk_brl(fork, FILE_READ_DATA);
+ if ((access_mask & FILE_READ_DATA) && have_read) {
+ off = access_to_netatalk_brl(fork_type, FILE_READ_DATA);
br_lck = do_lock(
handle->conn->sconn->msg_ctx, fsp,
fsp->op->global->open_persistent_id, 1, off,
TALLOC_FREE(br_lck);
}
- if (deny_mode & DENY_READ) {
- off = denymode_to_netatalk_brl(fork, DENY_READ);
+ if ((deny_mode & DENY_READ) && have_read) {
+ off = denymode_to_netatalk_brl(fork_type, DENY_READ);
br_lck = do_lock(
handle->conn->sconn->msg_ctx, fsp,
fsp->op->global->open_persistent_id, 1, off,
if ((access_mask & FILE_WRITE_DATA) || (deny_mode & DENY_WRITE)) {
/* Check access */
open_for_writing = test_netatalk_lock(
- fsp, access_to_netatalk_brl(fork, FILE_WRITE_DATA));
+ fsp, access_to_netatalk_brl(fork_type, FILE_WRITE_DATA));
deny_write = test_netatalk_lock(
- fsp, denymode_to_netatalk_brl(fork, DENY_WRITE));
+ fsp, denymode_to_netatalk_brl(fork_type, DENY_WRITE));
DEBUG(10, ("write: %s, deny_write: %s\n",
open_for_writing == true ? "yes" : "no",
}
/* Set locks */
- if (access_mask & FILE_WRITE_DATA) {
- off = access_to_netatalk_brl(fork, FILE_WRITE_DATA);
+ if ((access_mask & FILE_WRITE_DATA) && have_read) {
+ off = access_to_netatalk_brl(fork_type, FILE_WRITE_DATA);
br_lck = do_lock(
handle->conn->sconn->msg_ctx, fsp,
fsp->op->global->open_persistent_id, 1, off,
TALLOC_FREE(br_lck);
}
- if (deny_mode & DENY_WRITE) {
- off = denymode_to_netatalk_brl(fork, DENY_WRITE);
+ if ((deny_mode & DENY_WRITE) && have_read) {
+ off = denymode_to_netatalk_brl(fork_type, DENY_WRITE);
br_lck = do_lock(
handle->conn->sconn->msg_ctx, fsp,
fsp->op->global->open_persistent_id, 1, off,
return status;
}
-/****************************************************************************
- * VFS ops
- ****************************************************************************/
-
-static int fruit_connect(vfs_handle_struct *handle,
- const char *service,
- const char *user)
+static NTSTATUS check_aapl(vfs_handle_struct *handle,
+ struct smb_request *req,
+ const struct smb2_create_blobs *in_context_blobs,
+ struct smb2_create_blobs *out_context_blobs)
{
- int rc;
- char *list = NULL, *newlist = NULL;
struct fruit_config_data *config;
+ NTSTATUS status;
+ struct smb2_create_blob *aapl = NULL;
+ uint32_t cmd;
+ bool ok;
+ uint8_t p[16];
+ DATA_BLOB blob = data_blob_talloc(req, NULL, 0);
+ uint64_t req_bitmap, client_caps;
+ uint64_t server_caps = SMB2_CRTCTX_AAPL_UNIX_BASED;
+ smb_ucs2_t *model;
+ size_t modellen;
- DEBUG(10, ("fruit_connect\n"));
+ SMB_VFS_HANDLE_GET_DATA(handle, config, struct fruit_config_data,
+ return NT_STATUS_UNSUCCESSFUL);
- rc = SMB_VFS_NEXT_CONNECT(handle, service, user);
- if (rc < 0) {
- return rc;
+ if (!config->use_aapl
+ || in_context_blobs == NULL
+ || out_context_blobs == NULL) {
+ return NT_STATUS_OK;
}
- 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 "*/");
+ aapl = smb2_create_blob_find(in_context_blobs,
+ SMB2_CREATE_TAG_AAPL);
+ if (aapl == NULL) {
+ return NT_STATUS_OK;
}
- TALLOC_FREE(list);
+ if (aapl->data.length != 24) {
+ DEBUG(1, ("unexpected AAPL ctxt length: %ju\n",
+ (uintmax_t)aapl->data.length));
+ return NT_STATUS_INVALID_PARAMETER;
+ }
- rc = init_fruit_config(handle);
- if (rc != 0) {
- return rc;
+ cmd = IVAL(aapl->data.data, 0);
+ if (cmd != SMB2_CRTCTX_AAPL_SERVER_QUERY) {
+ DEBUG(1, ("unsupported AAPL cmd: %d\n", cmd));
+ return NT_STATUS_INVALID_PARAMETER;
}
- SMB_VFS_HANDLE_GET_DATA(handle, config,
- struct fruit_config_data, return -1);
+ req_bitmap = BVAL(aapl->data.data, 8);
+ client_caps = BVAL(aapl->data.data, 16);
- if (config->encoding == FRUIT_ENC_NATIVE) {
- lp_do_parameter(
- SNUM(handle->conn),
- "catia:mappings",
- "0x22:0xf020,0x2a:0xf021,0x3a:0xf022,0x3c:0xf023,"
- "0x3e:0xf024,0x3f:0xf025,0x5c:0xf026,0x7c:0xf027,"
- "0x0d:0xf00d");
+ SIVAL(p, 0, SMB2_CRTCTX_AAPL_SERVER_QUERY);
+ SIVAL(p, 4, 0);
+ SBVAL(p, 8, req_bitmap);
+ ok = data_blob_append(req, &blob, p, 16);
+ if (!ok) {
+ return NT_STATUS_UNSUCCESSFUL;
}
- return rc;
-}
+ if (req_bitmap & SMB2_CRTCTX_AAPL_SERVER_CAPS) {
+ if ((client_caps & SMB2_CRTCTX_AAPL_SUPPORTS_READ_DIR_ATTR) &&
+ (handle->conn->tcon->compat->fs_capabilities & FILE_NAMED_STREAMS)) {
+ server_caps |= SMB2_CRTCTX_AAPL_SUPPORTS_READ_DIR_ATTR;
+ config->readdir_attr_enabled = true;
+ }
-static int fruit_open_meta(vfs_handle_struct *handle,
- struct smb_filename *smb_fname,
- files_struct *fsp, int flags, mode_t mode)
-{
- int rc = 0;
- struct fruit_config_data *config = NULL;
- struct smb_filename *smb_fname_base = NULL;
- int baseflags;
- int hostfd = -1;
- struct adouble *ad = NULL;
+ if (config->use_copyfile) {
+ server_caps |= SMB2_CRTCTX_AAPL_SUPPORTS_OSX_COPYFILE;
+ config->copyfile_enabled = true;
+ }
- DEBUG(10, ("fruit_open_meta for %s\n", smb_fname_str_dbg(smb_fname)));
+ /*
+ * The client doesn't set the flag, so we can't check
+ * for it and just set it unconditionally
+ */
+ if (config->unix_info_enabled) {
+ server_caps |= SMB2_CRTCTX_AAPL_SUPPORTS_NFS_ACE;
+ }
- SMB_VFS_HANDLE_GET_DATA(handle, config,
- struct fruit_config_data, return -1);
+ SBVAL(p, 0, server_caps);
+ ok = data_blob_append(req, &blob, p, 8);
+ if (!ok) {
+ return NT_STATUS_UNSUCCESSFUL;
+ }
+ }
- if (config->meta == FRUIT_META_STREAM) {
- return SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
+ if (req_bitmap & SMB2_CRTCTX_AAPL_VOLUME_CAPS) {
+ SBVAL(p, 0,
+ lp_case_sensitive(SNUM(handle->conn->tcon->compat)) ?
+ SMB2_CRTCTX_AAPL_CASE_SENSITIVE : 0);
+ ok = data_blob_append(req, &blob, p, 8);
+ if (!ok) {
+ return NT_STATUS_UNSUCCESSFUL;
+ }
}
- /* Create an smb_filename with stream_name == NULL. */
- smb_fname_base = synthetic_smb_fname(talloc_tos(),
- smb_fname->base_name, NULL, NULL);
+ if (req_bitmap & SMB2_CRTCTX_AAPL_MODEL_INFO) {
+ ok = convert_string_talloc(req,
+ CH_UNIX, CH_UTF16LE,
+ "Samba", strlen("Samba"),
+ &model, &modellen);
+ if (!ok) {
+ return NT_STATUS_UNSUCCESSFUL;
+ }
- if (smb_fname_base == NULL) {
- errno = ENOMEM;
- rc = -1;
- goto exit;
+ SIVAL(p, 0, 0);
+ SIVAL(p + 4, 0, modellen);
+ ok = data_blob_append(req, &blob, p, 8);
+ if (!ok) {
+ talloc_free(model);
+ return NT_STATUS_UNSUCCESSFUL;
+ }
+
+ ok = data_blob_append(req, &blob, model, modellen);
+ talloc_free(model);
+ if (!ok) {
+ return NT_STATUS_UNSUCCESSFUL;
+ }
}
- /*
- * We use baseflags to turn off nasty side-effects when opening the
- * underlying file.
- */
- baseflags = flags;
- baseflags &= ~O_TRUNC;
- baseflags &= ~O_EXCL;
- baseflags &= ~O_CREAT;
+ status = smb2_create_blob_add(out_context_blobs,
+ out_context_blobs,
+ SMB2_CREATE_TAG_AAPL,
+ blob);
+ if (NT_STATUS_IS_OK(status)) {
+ config->nego_aapl = true;
+ }
- hostfd = SMB_VFS_OPEN(handle->conn, smb_fname_base, fsp,
- baseflags, mode);
+ return status;
+}
- /*
- * It is legit to open a stream on a directory, but the base
- * fd has to be read-only.
- */
- if ((hostfd == -1) && (errno == EISDIR)) {
- baseflags &= ~O_ACCMODE;
- baseflags |= O_RDONLY;
- hostfd = SMB_VFS_OPEN(handle->conn, smb_fname_base, fsp,
- baseflags, mode);
+static bool readdir_attr_meta_finderi_stream(
+ struct vfs_handle_struct *handle,
+ const struct smb_filename *smb_fname,
+ AfpInfo *ai)
+{
+ struct smb_filename *stream_name = NULL;
+ files_struct *fsp = NULL;
+ ssize_t nread;
+ NTSTATUS status;
+ int ret;
+ bool ok;
+ uint8_t buf[AFP_INFO_SIZE];
+
+ stream_name = synthetic_smb_fname(talloc_tos(),
+ smb_fname->base_name,
+ AFPINFO_STREAM_NAME,
+ NULL, smb_fname->flags);
+ if (stream_name == NULL) {
+ return false;
}
- TALLOC_FREE(smb_fname_base);
+ ret = SMB_VFS_STAT(handle->conn, stream_name);
+ if (ret != 0) {
+ return false;
+ }
- if (hostfd == -1) {
- rc = -1;
- goto exit;
+ status = SMB_VFS_CREATE_FILE(
+ handle->conn, /* conn */
+ NULL, /* req */
+ 0, /* root_dir_fid */
+ stream_name, /* fname */
+ FILE_READ_DATA, /* access_mask */
+ (FILE_SHARE_READ | FILE_SHARE_WRITE | /* share_access */
+ FILE_SHARE_DELETE),
+ FILE_OPEN, /* create_disposition*/
+ 0, /* create_options */
+ 0, /* file_attributes */
+ INTERNAL_OPEN_ONLY, /* oplock_request */
+ NULL, /* lease */
+ 0, /* allocation_size */
+ 0, /* private_flags */
+ NULL, /* sd */
+ NULL, /* ea_list */
+ &fsp, /* result */
+ NULL, /* pinfo */
+ NULL, NULL); /* create context */
+
+ TALLOC_FREE(stream_name);
+
+ if (!NT_STATUS_IS_OK(status)) {
+ return false;
+ }
+
+ nread = SMB_VFS_PREAD(fsp, &buf[0], AFP_INFO_SIZE, 0);
+ if (nread != AFP_INFO_SIZE) {
+ DBG_ERR("short read [%s] [%zd/%d]\n",
+ smb_fname_str_dbg(stream_name), nread, AFP_INFO_SIZE);
+ ok = false;
+ goto fail;
+ }
+
+ memcpy(&ai->afpi_FinderInfo[0], &buf[AFP_OFF_FinderInfo],
+ AFP_FinderSize);
+
+ ok = true;
+
+fail:
+ if (fsp != NULL) {
+ close_file(NULL, fsp, NORMAL_CLOSE);
+ }
+
+ return ok;
+}
+
+static bool readdir_attr_meta_finderi_netatalk(
+ struct vfs_handle_struct *handle,
+ const struct smb_filename *smb_fname,
+ AfpInfo *ai)
+{
+ struct adouble *ad = NULL;
+ char *p = NULL;
+
+ ad = ad_get(talloc_tos(), handle, smb_fname->base_name, ADOUBLE_META);
+ if (ad == NULL) {
+ return false;
+ }
+
+ p = ad_get_entry(ad, ADEID_FINDERI);
+ if (p == NULL) {
+ DBG_ERR("No ADEID_FINDERI for [%s]\n", smb_fname->base_name);
+ TALLOC_FREE(ad);
+ return false;
+ }
+
+ memcpy(&ai->afpi_FinderInfo[0], p, AFP_FinderSize);
+ TALLOC_FREE(ad);
+ return true;
+}
+
+static bool readdir_attr_meta_finderi(struct vfs_handle_struct *handle,
+ const struct smb_filename *smb_fname,
+ struct readdir_attr_data *attr_data)
+{
+ struct fruit_config_data *config = NULL;
+ uint32_t date_added;
+ AfpInfo ai = {0};
+ bool ok;
+
+ SMB_VFS_HANDLE_GET_DATA(handle, config,
+ struct fruit_config_data,
+ return false);
+
+ switch (config->meta) {
+ case FRUIT_META_NETATALK:
+ ok = readdir_attr_meta_finderi_netatalk(
+ handle, smb_fname, &ai);
+ break;
+
+ case FRUIT_META_STREAM:
+ ok = readdir_attr_meta_finderi_stream(
+ handle, smb_fname, &ai);
+ break;
+
+ default:
+ DBG_ERR("Unexpected meta config [%d]\n", config->meta);
+ return false;
+ }
+
+ if (!ok) {
+ /* Don't bother with errors, it's likely ENOENT */
+ return true;
+ }
+
+ if (S_ISREG(smb_fname->st.st_ex_mode)) {
+ /* finder_type */
+ memcpy(&attr_data->attr_data.aapl.finder_info[0],
+ &ai.afpi_FinderInfo[0], 4);
+
+ /* finder_creator */
+ memcpy(&attr_data->attr_data.aapl.finder_info[0] + 4,
+ &ai.afpi_FinderInfo[4], 4);
+ }
+
+ /* finder_flags */
+ memcpy(&attr_data->attr_data.aapl.finder_info[0] + 8,
+ &ai.afpi_FinderInfo[8], 2);
+
+ /* finder_ext_flags */
+ memcpy(&attr_data->attr_data.aapl.finder_info[0] + 10,
+ &ai.afpi_FinderInfo[24], 2);
+
+ /* creation date */
+ date_added = convert_time_t_to_uint32_t(
+ smb_fname->st.st_ex_btime.tv_sec - AD_DATE_DELTA);
+
+ RSIVAL(&attr_data->attr_data.aapl.finder_info[0], 12, date_added);
+
+ return true;
+}
+
+static uint64_t readdir_attr_rfork_size_adouble(
+ struct vfs_handle_struct *handle,
+ const struct smb_filename *smb_fname)
+{
+ struct adouble *ad = NULL;
+ uint64_t rfork_size;
+
+ ad = ad_get(talloc_tos(), handle, smb_fname->base_name,
+ ADOUBLE_RSRC);
+ if (ad == NULL) {
+ return 0;
+ }
+
+ rfork_size = ad_getentrylen(ad, ADEID_RFORK);
+ TALLOC_FREE(ad);
+
+ return rfork_size;
+}
+
+static uint64_t readdir_attr_rfork_size_stream(
+ struct vfs_handle_struct *handle,
+ const struct smb_filename *smb_fname)
+{
+ struct smb_filename *stream_name = NULL;
+ int ret;
+ uint64_t rfork_size;
+
+ stream_name = synthetic_smb_fname(talloc_tos(),
+ smb_fname->base_name,
+ AFPRESOURCE_STREAM_NAME,
+ NULL, 0);
+ if (stream_name == NULL) {
+ return 0;
+ }
+
+ ret = SMB_VFS_STAT(handle->conn, stream_name);
+ if (ret != 0) {
+ TALLOC_FREE(stream_name);
+ return 0;
+ }
+
+ rfork_size = stream_name->st.st_ex_size;
+ TALLOC_FREE(stream_name);
+
+ return rfork_size;
+}
+
+static uint64_t readdir_attr_rfork_size(struct vfs_handle_struct *handle,
+ const struct smb_filename *smb_fname)
+{
+ struct fruit_config_data *config = NULL;
+ uint64_t rfork_size;
+
+ SMB_VFS_HANDLE_GET_DATA(handle, config,
+ struct fruit_config_data,
+ return 0);
+
+ switch (config->rsrc) {
+ case FRUIT_RSRC_ADFILE:
+ case FRUIT_RSRC_XATTR:
+ rfork_size = readdir_attr_rfork_size_adouble(handle,
+ smb_fname);
+ break;
+
+ case FRUIT_META_STREAM:
+ rfork_size = readdir_attr_rfork_size_stream(handle,
+ smb_fname);
+ break;
+
+ default:
+ DBG_ERR("Unexpected rsrc config [%d]\n", config->rsrc);
+ rfork_size = 0;
+ break;
+ }
+
+ return rfork_size;
+}
+
+static NTSTATUS readdir_attr_macmeta(struct vfs_handle_struct *handle,
+ const struct smb_filename *smb_fname,
+ struct readdir_attr_data *attr_data)
+{
+ NTSTATUS status = NT_STATUS_OK;
+ struct fruit_config_data *config = NULL;
+ bool ok;
+
+ SMB_VFS_HANDLE_GET_DATA(handle, config,
+ struct fruit_config_data,
+ return NT_STATUS_UNSUCCESSFUL);
+
+
+ /* Ensure we return a default value in the creation_date field */
+ RSIVAL(&attr_data->attr_data.aapl.finder_info, 12, AD_DATE_START);
+
+ /*
+ * Resource fork length
+ */
+
+ if (config->readdir_attr_rsize) {
+ uint64_t rfork_size;
+
+ rfork_size = readdir_attr_rfork_size(handle, smb_fname);
+ attr_data->attr_data.aapl.rfork_size = rfork_size;
+ }
+
+ /*
+ * FinderInfo
+ */
+
+ if (config->readdir_attr_finder_info) {
+ ok = readdir_attr_meta_finderi(handle, smb_fname, attr_data);
+ if (!ok) {
+ status = NT_STATUS_INTERNAL_ERROR;
+ }
+ }
+
+ return status;
+}
+
+/* Search MS NFS style ACE with UNIX mode */
+static NTSTATUS check_ms_nfs(vfs_handle_struct *handle,
+ files_struct *fsp,
+ const struct security_descriptor *psd,
+ mode_t *pmode,
+ bool *pdo_chmod)
+{
+ uint32_t i;
+ struct fruit_config_data *config = NULL;
+
+ *pdo_chmod = false;
+
+ SMB_VFS_HANDLE_GET_DATA(handle, config,
+ struct fruit_config_data,
+ return NT_STATUS_UNSUCCESSFUL);
+
+ if (psd->dacl == NULL || !config->unix_info_enabled) {
+ return NT_STATUS_OK;
+ }
+
+ for (i = 0; i < psd->dacl->num_aces; i++) {
+ if (dom_sid_compare_domain(
+ &global_sid_Unix_NFS_Mode,
+ &psd->dacl->aces[i].trustee) == 0) {
+ *pmode = (mode_t)psd->dacl->aces[i].trustee.sub_auths[2];
+ *pmode &= (S_IRWXU | S_IRWXG | S_IRWXO);
+ *pdo_chmod = true;
+
+ DEBUG(10, ("MS NFS chmod request %s, %04o\n",
+ fsp_str_dbg(fsp), (unsigned)(*pmode)));
+ break;
+ }
+ }
+
+ return NT_STATUS_OK;
+}
+
+/****************************************************************************
+ * VFS ops
+ ****************************************************************************/
+
+static int fruit_connect(vfs_handle_struct *handle,
+ const char *service,
+ const char *user)
+{
+ int rc;
+ char *list = NULL, *newlist = NULL;
+ struct fruit_config_data *config;
+
+ DEBUG(10, ("fruit_connect\n"));
+
+ rc = SMB_VFS_NEXT_CONNECT(handle, service, user);
+ if (rc < 0) {
+ return rc;
+ }
+
+ 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),
+ "catia:mappings",
+ "0x01:0xf001,0x02:0xf002,0x03:0xf003,0x04:0xf004,"
+ "0x05:0xf005,0x06:0xf006,0x07:0xf007,0x08:0xf008,"
+ "0x09:0xf009,0x0a:0xf00a,0x0b:0xf00b,0x0c:0xf00c,"
+ "0x0d:0xf00d,0x0e:0xf00e,0x0f:0xf00f,0x10:0xf010,"
+ "0x11:0xf011,0x12:0xf012,0x13:0xf013,0x14:0xf014,"
+ "0x15:0xf015,0x16:0xf016,0x17:0xf017,0x18:0xf018,"
+ "0x19:0xf019,0x1a:0xf01a,0x1b:0xf01b,0x1c:0xf01c,"
+ "0x1d:0xf01d,0x1e:0xf01e,0x1f:0xf01f,"
+ "0x22:0xf020,0x2a:0xf021,0x3a:0xf022,0x3c:0xf023,"
+ "0x3e:0xf024,0x3f:0xf025,0x5c:0xf026,0x7c:0xf027,"
+ "0x0d:0xf00d");
+ }
+
+ return rc;
+}
+
+static int fruit_open_meta_stream(vfs_handle_struct *handle,
+ struct smb_filename *smb_fname,
+ files_struct *fsp,
+ int flags,
+ mode_t mode)
+{
+ AfpInfo *ai = NULL;
+ char afpinfo_buf[AFP_INFO_SIZE];
+ ssize_t len, written;
+ int hostfd = -1;
+ int rc = -1;
+
+ hostfd = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
+ if (hostfd == -1) {
+ return -1;
+ }
+
+ if (!(flags & (O_CREAT | O_TRUNC))) {
+ return hostfd;
+ }
+
+ ai = afpinfo_new(talloc_tos());
+ if (ai == NULL) {
+ rc = -1;
+ goto fail;
+ }
+
+ len = afpinfo_pack(ai, afpinfo_buf);
+ if (len != AFP_INFO_SIZE) {
+ rc = -1;
+ goto fail;
+ }
+
+ /* Set fd, needed in SMB_VFS_NEXT_PWRITE() */
+ fsp->fh->fd = hostfd;
+
+ written = SMB_VFS_NEXT_PWRITE(handle, fsp, afpinfo_buf,
+ AFP_INFO_SIZE, 0);
+ fsp->fh->fd = -1;
+ if (written != AFP_INFO_SIZE) {
+ DBG_ERR("bad write [%zd/%d]\n", written, AFP_INFO_SIZE);
+ rc = -1;
+ goto fail;
+ }
+
+ rc = 0;
+
+fail:
+ DBG_DEBUG("rc=%d, fd=%d\n", rc, hostfd);
+
+ if (rc != 0) {
+ int saved_errno = errno;
+ if (hostfd >= 0) {
+ fsp->fh->fd = hostfd;
+ SMB_VFS_NEXT_CLOSE(handle, fsp);
+ }
+ hostfd = -1;
+ errno = saved_errno;
+ }
+ return hostfd;
+}
+
+static int fruit_open_meta_netatalk(vfs_handle_struct *handle,
+ struct smb_filename *smb_fname,
+ files_struct *fsp,
+ int flags,
+ mode_t mode)
+{
+ int rc = 0;
+ struct smb_filename *smb_fname_base = NULL;
+ int baseflags;
+ int hostfd = -1;
+ struct adouble *ad = NULL;
+
+ /* Create an smb_filename with stream_name == NULL. */
+ smb_fname_base = synthetic_smb_fname(talloc_tos(),
+ smb_fname->base_name,
+ NULL,
+ NULL,
+ smb_fname->flags);
+
+ if (smb_fname_base == NULL) {
+ errno = ENOMEM;
+ rc = -1;
+ goto exit;
+ }
+
+ /*
+ * We use baseflags to turn off nasty side-effects when opening the
+ * underlying file.
+ */
+ baseflags = flags;
+ baseflags &= ~O_TRUNC;
+ baseflags &= ~O_EXCL;
+ baseflags &= ~O_CREAT;
+
+ hostfd = SMB_VFS_NEXT_OPEN(handle, smb_fname_base, fsp,
+ baseflags, mode);
+
+ /*
+ * It is legit to open a stream on a directory, but the base
+ * fd has to be read-only.
+ */
+ if ((hostfd == -1) && (errno == EISDIR)) {
+ baseflags &= ~O_ACCMODE;
+ baseflags |= O_RDONLY;
+ hostfd = SMB_VFS_NEXT_OPEN(handle, smb_fname_base, fsp,
+ baseflags, mode);
+ }
+
+ TALLOC_FREE(smb_fname_base);
+
+ if (hostfd == -1) {
+ rc = -1;
+ goto exit;
}
if (flags & (O_CREAT | O_TRUNC)) {
* full fsp yet
*/
fsp->fh->fd = hostfd;
- SMB_VFS_CLOSE(fsp);
+ SMB_VFS_NEXT_CLOSE(handle, fsp);
}
hostfd = -1;
errno = saved_errno;
return hostfd;
}
-static int fruit_open_rsrc(vfs_handle_struct *handle,
+static int fruit_open_meta(vfs_handle_struct *handle,
struct smb_filename *smb_fname,
files_struct *fsp, int flags, mode_t mode)
{
- int rc = 0;
+ int rc;
struct fruit_config_data *config = NULL;
- struct adouble *ad = NULL;
- struct smb_filename *smb_fname_base = NULL;
- char *adpath = NULL;
- int hostfd = -1;
- DEBUG(10, ("fruit_open_rsrc for %s\n", smb_fname_str_dbg(smb_fname)));
+ DBG_DEBUG("path [%s]\n", smb_fname_str_dbg(smb_fname));
SMB_VFS_HANDLE_GET_DATA(handle, config,
struct fruit_config_data, return -1);
- switch (config->rsrc) {
- case FRUIT_RSRC_STREAM:
- return SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
- case FRUIT_RSRC_XATTR:
-#ifdef HAVE_ATTROPEN
- hostfd = attropen(smb_fname->base_name,
- AFPRESOURCE_EA_NETATALK, flags, mode);
- if (hostfd == -1) {
- return -1;
- }
- ad = ad_init(VFS_MEMCTX_FSP_EXTENSION(handle, fsp),
- handle, ADOUBLE_RSRC, fsp);
- if (ad == NULL) {
- rc = -1;
- goto exit;
- }
- goto exit;
-#else
- errno = ENOTSUP;
- return -1;
-#endif
- default:
+ switch (config->meta) {
+ case FRUIT_META_STREAM:
+ rc = fruit_open_meta_stream(handle, smb_fname,
+ fsp, flags, mode);
+ break;
+
+ case FRUIT_META_NETATALK:
+ rc = fruit_open_meta_netatalk(handle, smb_fname,
+ fsp, flags, mode);
break;
+
+ default:
+ DBG_ERR("Unexpected meta config [%d]\n", config->meta);
+ return -1;
}
+ DBG_DEBUG("path [%s] rc [%d]\n", smb_fname_str_dbg(smb_fname), rc);
+ return rc;
+}
+
+static int fruit_open_rsrc_adouble(vfs_handle_struct *handle,
+ struct smb_filename *smb_fname,
+ files_struct *fsp,
+ int flags,
+ mode_t mode)
+{
+ int rc = 0;
+ struct adouble *ad = NULL;
+ struct smb_filename *smb_fname_base = NULL;
+ char *adpath = NULL;
+ int hostfd = -1;
+
if (!(flags & O_CREAT) && !VALID_STAT(smb_fname->st)) {
rc = SMB_VFS_NEXT_STAT(handle, smb_fname);
if (rc != 0) {
/* Create an smb_filename with stream_name == NULL. */
smb_fname_base = synthetic_smb_fname(talloc_tos(),
- adpath, NULL, NULL);
+ adpath,
+ NULL,
+ NULL,
+ smb_fname->flags);
if (smb_fname_base == NULL) {
errno = ENOMEM;
rc = -1;
flags |= O_RDWR;
}
- hostfd = SMB_VFS_OPEN(handle->conn, smb_fname_base, fsp,
- flags, mode);
+ hostfd = SMB_VFS_NEXT_OPEN(handle, smb_fname_base, fsp,
+ flags, mode);
if (hostfd == -1) {
rc = -1;
goto exit;
hostfd = -1;
errno = saved_errno;
}
- return hostfd;
+ return hostfd;
+}
+
+static int fruit_open_rsrc_xattr(vfs_handle_struct *handle,
+ struct smb_filename *smb_fname,
+ files_struct *fsp,
+ int flags,
+ mode_t mode)
+{
+#ifdef HAVE_ATTROPEN
+ int fd = -1;
+ struct adouble *ad = NULL;
+
+ ad = ad_init(VFS_MEMCTX_FSP_EXTENSION(handle, fsp),
+ handle, ADOUBLE_RSRC, fsp);
+ if (ad == NULL) {
+ return -1;
+ }
+
+ fd = attropen(smb_fname->base_name,
+ AFPRESOURCE_EA_NETATALK, flags, mode);
+ if (fd == -1) {
+ return -1;
+ }
+
+ return fd;
+
+#else
+ errno = ENOSYS;
+ return -1;
+#endif
+}
+
+static int fruit_open_rsrc(vfs_handle_struct *handle,
+ struct smb_filename *smb_fname,
+ files_struct *fsp, int flags, mode_t mode)
+{
+ int fd;
+ struct fruit_config_data *config = NULL;
+
+ DBG_DEBUG("Path [%s]\n", smb_fname_str_dbg(smb_fname));
+
+ SMB_VFS_HANDLE_GET_DATA(handle, config,
+ struct fruit_config_data, return -1);
+
+ switch (config->rsrc) {
+ case FRUIT_RSRC_STREAM:
+ fd = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
+ break;
+
+ case FRUIT_RSRC_ADFILE:
+ fd = fruit_open_rsrc_adouble(handle, smb_fname,
+ fsp, flags, mode);
+ break;
+
+ case FRUIT_RSRC_XATTR:
+ fd = fruit_open_rsrc_xattr(handle, smb_fname,
+ fsp, flags, mode);
+ break;
+
+ default:
+ DBG_ERR("Unexpected rsrc config [%d]\n", config->rsrc);
+ return -1;
+ }
+
+ DBG_DEBUG("Path [%s] fd [%d]\n", smb_fname_str_dbg(smb_fname), fd);
+ return fd;
}
static int fruit_open(vfs_handle_struct *handle,
char *src_adouble_path = NULL;
char *dst_adouble_path = NULL;
struct fruit_config_data *config = NULL;
+ struct smb_filename *src_adp_smb_fname = NULL;
+ struct smb_filename *dst_adp_smb_fname = NULL;
- rc = SMB_VFS_NEXT_RENAME(handle, smb_fname_src, smb_fname_dst);
+ SMB_VFS_HANDLE_GET_DATA(handle, config,
+ struct fruit_config_data, return -1);
- if (!VALID_STAT(smb_fname_src->st)
- || !S_ISREG(smb_fname_src->st.st_ex_mode)) {
- return rc;
+ if (!VALID_STAT(smb_fname_src->st)) {
+ DBG_ERR("Need valid stat for [%s]\n",
+ smb_fname_str_dbg(smb_fname_src));
+ return -1;
}
- SMB_VFS_HANDLE_GET_DATA(handle, config,
- struct fruit_config_data, return -1);
+ rc = SMB_VFS_NEXT_RENAME(handle, smb_fname_src, smb_fname_dst);
+ if (rc != 0) {
+ return -1;
+ }
- if (config->rsrc == FRUIT_RSRC_XATTR) {
- return rc;
+ if ((config->rsrc != FRUIT_RSRC_ADFILE) ||
+ (!S_ISREG(smb_fname_src->st.st_ex_mode)))
+ {
+ return 0;
}
rc = adouble_path(talloc_tos(), smb_fname_src->base_name,
if (rc != 0) {
goto done;
}
+ src_adp_smb_fname = synthetic_smb_fname(talloc_tos(),
+ src_adouble_path,
+ NULL, NULL,
+ smb_fname_src->flags);
+ TALLOC_FREE(src_adouble_path);
+ if (src_adp_smb_fname == NULL) {
+ rc = -1;
+ goto done;
+ }
+
rc = adouble_path(talloc_tos(), smb_fname_dst->base_name,
&dst_adouble_path);
if (rc != 0) {
goto done;
}
+ dst_adp_smb_fname = synthetic_smb_fname(talloc_tos(),
+ dst_adouble_path,
+ NULL, NULL,
+ smb_fname_dst->flags);
+ TALLOC_FREE(dst_adouble_path);
+ if (dst_adp_smb_fname == NULL) {
+ rc = -1;
+ goto done;
+ }
- DEBUG(10, ("fruit_rename: %s -> %s\n",
- src_adouble_path, dst_adouble_path));
+ DBG_DEBUG("%s -> %s\n",
+ smb_fname_str_dbg(src_adp_smb_fname),
+ smb_fname_str_dbg(dst_adp_smb_fname));
- rc = rename(src_adouble_path, dst_adouble_path);
+ rc = SMB_VFS_NEXT_RENAME(handle, src_adp_smb_fname, dst_adp_smb_fname);
if (errno == ENOENT) {
rc = 0;
}
- TALLOC_FREE(src_adouble_path);
- TALLOC_FREE(dst_adouble_path);
-
done:
+ TALLOC_FREE(src_adp_smb_fname);
+ TALLOC_FREE(dst_adp_smb_fname);
return rc;
}
-static int fruit_unlink(vfs_handle_struct *handle,
- const struct smb_filename *smb_fname)
+static int fruit_unlink_meta_stream(vfs_handle_struct *handle,
+ const struct smb_filename *smb_fname)
+{
+ return SMB_VFS_NEXT_UNLINK(handle, smb_fname);
+}
+
+static int fruit_unlink_meta_netatalk(vfs_handle_struct *handle,
+ const struct smb_filename *smb_fname)
+{
+ return SMB_VFS_REMOVEXATTR(handle->conn,
+ smb_fname->base_name,
+ AFPINFO_EA_NETATALK);
+}
+
+static int fruit_unlink_meta(vfs_handle_struct *handle,
+ const struct smb_filename *smb_fname)
{
- int rc = -1;
struct fruit_config_data *config = NULL;
+ int rc;
+
+ SMB_VFS_HANDLE_GET_DATA(handle, config,
+ struct fruit_config_data, return -1);
+
+ switch (config->meta) {
+ case FRUIT_META_STREAM:
+ rc = fruit_unlink_meta_stream(handle, smb_fname);
+ break;
+
+ case FRUIT_META_NETATALK:
+ rc = fruit_unlink_meta_netatalk(handle, smb_fname);
+ break;
+
+ default:
+ DBG_ERR("Unsupported meta config [%d]\n", config->meta);
+ return -1;
+ }
+
+ return rc;
+}
+
+static int fruit_unlink_rsrc_stream(vfs_handle_struct *handle,
+ const struct smb_filename *smb_fname,
+ bool force_unlink)
+{
+ int ret;
+
+ if (!force_unlink) {
+ struct smb_filename *smb_fname_cp = NULL;
+ off_t size;
+
+ smb_fname_cp = cp_smb_filename(talloc_tos(), smb_fname);
+ if (smb_fname_cp == NULL) {
+ return -1;
+ }
+
+ /*
+ * 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.
+ */
+
+ ret = SMB_VFS_NEXT_STAT(handle, smb_fname_cp);
+ if (ret != 0) {
+ TALLOC_FREE(smb_fname_cp);
+ DBG_ERR("stat [%s] failed [%s]\n",
+ smb_fname_str_dbg(smb_fname_cp), strerror(errno));
+ return -1;
+ }
+
+ size = smb_fname_cp->st.st_ex_size;
+ TALLOC_FREE(smb_fname_cp);
+
+ if (size > 0) {
+ /* OS X ignores resource fork stream delete requests */
+ return 0;
+ }
+ }
+
+ ret = SMB_VFS_NEXT_UNLINK(handle, smb_fname);
+ if ((ret != 0) && (errno == ENOENT) && force_unlink) {
+ ret = 0;
+ }
+
+ return ret;
+}
+
+static int fruit_unlink_rsrc_adouble(vfs_handle_struct *handle,
+ const struct smb_filename *smb_fname,
+ bool force_unlink)
+{
+ int rc;
char *adp = NULL;
+ struct adouble *ad = NULL;
+ struct smb_filename *adp_smb_fname = NULL;
- if (!is_ntfs_stream_smb_fname(smb_fname)) {
- return SMB_VFS_NEXT_UNLINK(handle, smb_fname);
+ if (!force_unlink) {
+ ad = ad_get(talloc_tos(), handle, smb_fname->base_name,
+ ADOUBLE_RSRC);
+ if (ad == NULL) {
+ errno = ENOENT;
+ return -1;
+ }
+
+
+ /*
+ * 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.
+ */
+
+ if (ad_getentrylen(ad, ADEID_RFORK) > 0) {
+ /* OS X ignores resource fork stream delete requests */
+ TALLOC_FREE(ad);
+ return 0;
+ }
+
+ TALLOC_FREE(ad);
+ }
+
+ rc = adouble_path(talloc_tos(), smb_fname->base_name, &adp);
+ if (rc != 0) {
+ return -1;
+ }
+
+ adp_smb_fname = synthetic_smb_fname(talloc_tos(), adp,
+ NULL, NULL,
+ smb_fname->flags);
+ TALLOC_FREE(adp);
+ if (adp_smb_fname == NULL) {
+ return -1;
+ }
+
+ rc = SMB_VFS_NEXT_UNLINK(handle, adp_smb_fname);
+ TALLOC_FREE(adp_smb_fname);
+ if ((rc != 0) && (errno == ENOENT) && force_unlink) {
+ rc = 0;
+ }
+
+ return rc;
+}
+
+static int fruit_unlink_rsrc_xattr(vfs_handle_struct *handle,
+ const struct smb_filename *smb_fname,
+ bool force_unlink)
+{
+ /*
+ * OS X ignores resource fork stream delete requests, so nothing to do
+ * here. Removing the file will remove the xattr anyway, so we don't
+ * have to take care of removing 0 byte resource forks that could be
+ * left behind.
+ */
+ return 0;
+}
+
+static int fruit_unlink_rsrc(vfs_handle_struct *handle,
+ const struct smb_filename *smb_fname,
+ bool force_unlink)
+{
+ struct fruit_config_data *config = NULL;
+ int rc;
+
+ SMB_VFS_HANDLE_GET_DATA(handle, config,
+ struct fruit_config_data, return -1);
+
+ switch (config->rsrc) {
+ case FRUIT_RSRC_STREAM:
+ rc = fruit_unlink_rsrc_stream(handle, smb_fname, force_unlink);
+ break;
+
+ case FRUIT_RSRC_ADFILE:
+ rc = fruit_unlink_rsrc_adouble(handle, smb_fname, force_unlink);
+ break;
+
+ case FRUIT_RSRC_XATTR:
+ rc = fruit_unlink_rsrc_xattr(handle, smb_fname, force_unlink);
+ break;
+
+ default:
+ DBG_ERR("Unsupported rsrc config [%d]\n", config->rsrc);
+ return -1;
}
+ return rc;
+}
+
+static int fruit_unlink(vfs_handle_struct *handle,
+ const struct smb_filename *smb_fname)
+{
+ int rc;
+ struct fruit_config_data *config = NULL;
+ struct smb_filename *rsrc_smb_fname = NULL;
+
SMB_VFS_HANDLE_GET_DATA(handle, config,
struct fruit_config_data, return -1);
if (is_afpinfo_stream(smb_fname)) {
- if (config->meta == FRUIT_META_STREAM) {
- rc = SMB_VFS_NEXT_UNLINK(handle, smb_fname);
- } else {
- rc = SMB_VFS_REMOVEXATTR(handle->conn,
- smb_fname->base_name,
- AFPINFO_EA_NETATALK);
- }
+ return fruit_unlink_meta(handle, smb_fname);
} 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 fruit_unlink_rsrc(handle, smb_fname, false);
+ } if (is_ntfs_stream_smb_fname(smb_fname)) {
+ return SMB_VFS_NEXT_UNLINK(handle, smb_fname);
}
- TALLOC_FREE(adp);
- return rc;
+ /*
+ * A request to delete the base file. Because 0 byte resource
+ * fork streams are not listed by fruit_streaminfo,
+ * delete_all_streams() can't remove 0 byte resource fork
+ * streams, so we have to cleanup this here.
+ */
+ rsrc_smb_fname = synthetic_smb_fname(talloc_tos(),
+ smb_fname->base_name,
+ AFPRESOURCE_STREAM_NAME,
+ NULL,
+ smb_fname->flags);
+ if (rsrc_smb_fname == NULL) {
+ return -1;
+ }
+
+ rc = fruit_unlink_rsrc(handle, rsrc_smb_fname, true);
+ if ((rc != 0) && (errno != ENOENT)) {
+ DBG_ERR("Forced unlink of [%s] failed [%s]\n",
+ smb_fname_str_dbg(rsrc_smb_fname), strerror(errno));
+ TALLOC_FREE(rsrc_smb_fname);
+ return -1;
+ }
+ TALLOC_FREE(rsrc_smb_fname);
+
+ return SMB_VFS_NEXT_UNLINK(handle, smb_fname);
}
static int fruit_chmod(vfs_handle_struct *handle,
- const char *path,
+ const struct smb_filename *smb_fname,
mode_t mode)
{
int rc = -1;
char *adp = NULL;
struct fruit_config_data *config = NULL;
- SMB_STRUCT_STAT sb;
+ const char *path = smb_fname->base_name;
+ struct smb_filename *smb_fname_adp = NULL;
- rc = SMB_VFS_NEXT_CHMOD(handle, path, mode);
+ rc = SMB_VFS_NEXT_CHMOD(handle, smb_fname, mode);
if (rc != 0) {
return rc;
}
SMB_VFS_HANDLE_GET_DATA(handle, config,
struct fruit_config_data, return -1);
- if (config->rsrc == FRUIT_RSRC_XATTR) {
+ if (config->rsrc != FRUIT_RSRC_ADFILE) {
return 0;
}
- /* FIXME: direct sys_lstat(), missing smb_fname */
- rc = sys_lstat(path, &sb, false);
- if (rc != 0 || !S_ISREG(sb.st_ex_mode)) {
- return rc;
+ if (!VALID_STAT(smb_fname->st)) {
+ return 0;
+ }
+
+ if (!S_ISREG(smb_fname->st.st_ex_mode)) {
+ return 0;
}
rc = adouble_path(talloc_tos(), path, &adp);
DEBUG(10, ("fruit_chmod: %s\n", adp));
- rc = SMB_VFS_NEXT_CHMOD(handle, adp, mode);
+ smb_fname_adp = synthetic_smb_fname(talloc_tos(),
+ adp,
+ NULL,
+ NULL,
+ smb_fname->flags);
+ if (smb_fname_adp == NULL) {
+ TALLOC_FREE(adp);
+ errno = ENOMEM;
+ return -1;
+ }
+
+ rc = SMB_VFS_NEXT_CHMOD(handle, smb_fname_adp, mode);
if (errno == ENOENT) {
rc = 0;
}
+ TALLOC_FREE(smb_fname_adp);
TALLOC_FREE(adp);
return rc;
}
static int fruit_chown(vfs_handle_struct *handle,
- const char *path,
+ const struct smb_filename *smb_fname,
uid_t uid,
gid_t gid)
{
int rc = -1;
char *adp = NULL;
struct fruit_config_data *config = NULL;
- SMB_STRUCT_STAT sb;
+ struct smb_filename *adp_smb_fname = NULL;
- rc = SMB_VFS_NEXT_CHOWN(handle, path, uid, gid);
+ rc = SMB_VFS_NEXT_CHOWN(handle, smb_fname, uid, gid);
if (rc != 0) {
return rc;
}
SMB_VFS_HANDLE_GET_DATA(handle, config,
struct fruit_config_data, return -1);
- if (config->rsrc == FRUIT_RSRC_XATTR) {
- return rc;
+ if (config->rsrc != FRUIT_RSRC_ADFILE) {
+ return 0;
}
- /* FIXME: direct sys_lstat(), missing smb_fname */
- rc = sys_lstat(path, &sb, false);
- if (rc != 0 || !S_ISREG(sb.st_ex_mode)) {
- return rc;
+ if (!VALID_STAT(smb_fname->st)) {
+ return 0;
}
- rc = adouble_path(talloc_tos(), path, &adp);
+ if (!S_ISREG(smb_fname->st.st_ex_mode)) {
+ return 0;
+ }
+
+ rc = adouble_path(talloc_tos(), smb_fname->base_name, &adp);
if (rc != 0) {
goto done;
}
DEBUG(10, ("fruit_chown: %s\n", adp));
- rc = SMB_VFS_NEXT_CHOWN(handle, adp, uid, gid);
+ adp_smb_fname = synthetic_smb_fname(talloc_tos(),
+ adp,
+ NULL,
+ NULL,
+ smb_fname->flags);
+ if (adp_smb_fname == NULL) {
+ errno = ENOMEM;
+ rc = -1;
+ goto done;
+ }
+
+ rc = SMB_VFS_NEXT_CHOWN(handle, adp_smb_fname, uid, gid);
if (errno == ENOENT) {
rc = 0;
}
done:
TALLOC_FREE(adp);
+ TALLOC_FREE(adp_smb_fname);
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;
SMB_VFS_HANDLE_GET_DATA(handle, config,
struct fruit_config_data, return -1);
- if (!handle->conn->cwd || !path || (config->rsrc == FRUIT_RSRC_XATTR)) {
+ if (config->rsrc != FRUIT_RSRC_ADFILE) {
goto exit_rmdir;
}
* Due to there is no way to change bDeleteVetoFiles variable
* from this module, need to clean up ourselves
*/
- dh = opendir(path);
+
+ dh = SMB_VFS_OPENDIR(handle->conn, smb_fname, NULL, 0);
if (dh == NULL) {
goto exit_rmdir;
}
- while ((de = readdir(dh)) != NULL) {
- if ((strncmp(de->d_name,
- ADOUBLE_NAME_PREFIX,
- strlen(ADOUBLE_NAME_PREFIX))) == 0) {
- char *p = talloc_asprintf(talloc_tos(),
- "%s/%s",
- path, de->d_name);
- if (p == NULL) {
- goto exit_rmdir;
- }
- DEBUG(10, ("fruit_rmdir: delete %s\n", p));
- (void)unlink(p);
+ while ((de = SMB_VFS_READDIR(handle->conn, dh, NULL)) != NULL) {
+ int match;
+ struct adouble *ad = NULL;
+ char *p = NULL;
+ struct smb_filename *ad_smb_fname = NULL;
+ int ret;
+
+ match = strncmp(de->d_name,
+ ADOUBLE_NAME_PREFIX,
+ strlen(ADOUBLE_NAME_PREFIX));
+ if (match != 0) {
+ continue;
+ }
+
+ p = talloc_asprintf(talloc_tos(), "%s/%s",
+ smb_fname->base_name, de->d_name);
+ if (p == NULL) {
+ DBG_ERR("talloc_asprintf failed\n");
+ return -1;
+ }
+
+ /*
+ * Check whether it's a valid AppleDouble file, if
+ * yes, delete it, ignore it otherwise.
+ */
+ ad = ad_get(talloc_tos(), handle, p, ADOUBLE_RSRC);
+ if (ad == NULL) {
TALLOC_FREE(p);
+ continue;
+ }
+ TALLOC_FREE(ad);
+
+ ad_smb_fname = synthetic_smb_fname(talloc_tos(), p,
+ NULL, NULL,
+ smb_fname->flags);
+ TALLOC_FREE(p);
+ if (ad_smb_fname == NULL) {
+ DBG_ERR("synthetic_smb_fname failed\n");
+ return -1;
+ }
+
+ ret = SMB_VFS_NEXT_UNLINK(handle, ad_smb_fname);
+ TALLOC_FREE(ad_smb_fname);
+ if (ret != 0) {
+ DBG_ERR("Deleting [%s] failed\n",
+ smb_fname_str_dbg(ad_smb_fname));
}
}
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;
- char *name = NULL;
- char *tmp_base_name = NULL;
- NTSTATUS status;
+ ssize_t len = -1;
+ size_t to_return = n;
DEBUG(10, ("fruit_pread: offset=%d, size=%d\n", (int)offset, (int)n));
SMB_VFS_HANDLE_GET_DATA(handle, config,
struct fruit_config_data, return -1);
- /* fsp_name is not converted with vfs_catia */
- tmp_base_name = fsp->base_fsp->fsp_name->base_name;
- status = SMB_VFS_TRANSLATE_NAME(handle->conn,
- fsp->base_fsp->fsp_name->base_name,
- vfs_translate_to_unix,
- talloc_tos(), &name);
- if (!NT_STATUS_IS_OK(status)) {
- errno = map_errno_from_nt_status(status);
- rc = -1;
- goto exit;
+ if (is_afpinfo_stream(fsp->fsp_name)) {
+ /*
+ * 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);
+
+ /* Yes, macOS always reads from offset 0 */
+ offset = 0;
}
- fsp->base_fsp->fsp_name->base_name = name;
if (ad == NULL) {
- len = SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
+ len = SMB_VFS_NEXT_PREAD(handle, fsp, data, to_return, offset);
if (len == -1) {
rc = -1;
goto exit;
}
if (ad->ad_type == ADOUBLE_META) {
+ char afpinfo_buf[AFP_INFO_SIZE];
+ char *p = NULL;
+
ai = afpinfo_new(talloc_tos());
if (ai == NULL) {
rc = -1;
goto exit;
}
- memcpy(&ai->afpi_FinderInfo[0],
- ad_entry(ad, ADEID_FINDERI),
- ADEDLEN_FINDERI);
- len = afpinfo_pack(ai, data);
+ p = ad_get_entry(ad, ADEID_FINDERI);
+ if (p == NULL) {
+ DBG_ERR("No ADEID_FINDERI for [%s]\n",
+ fsp->fsp_name->base_name);
+ rc = -1;
+ goto exit;
+ }
+
+ memcpy(&ai->afpi_FinderInfo[0], p, ADEDLEN_FINDERI);
+
+ 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,
}
}
exit:
- fsp->base_fsp->fsp_name->base_name = tmp_base_name;
- TALLOC_FREE(name);
TALLOC_FREE(ai);
if (rc != 0) {
len = -1;
struct fruit_config_data *config = NULL;
AfpInfo *ai = NULL;
ssize_t len;
- char *name = NULL;
- char *tmp_base_name = NULL;
- NTSTATUS status;
DEBUG(10, ("fruit_pwrite: offset=%d, size=%d\n", (int)offset, (int)n));
return SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
}
- SMB_VFS_HANDLE_GET_DATA(handle, config,
- struct fruit_config_data, return -1);
+ SMB_VFS_HANDLE_GET_DATA(handle, config,
+ struct fruit_config_data, return -1);
+
+ if (is_afpinfo_stream(fsp->fsp_name)) {
+ /*
+ * Writing an all 0 blob to the metadata stream
+ * results in the stream being removed on a macOS
+ * server. This ensures we behave the same and it
+ * verified by the "delete AFP_AfpInfo by writing all
+ * 0" test.
+ */
+ if (n != AFP_INFO_SIZE || offset != 0) {
+ DEBUG(1, ("unexpected offset=%jd or size=%jd\n",
+ (intmax_t)offset, (intmax_t)n));
+ rc = -1;
+ goto exit;
+ }
+ ai = afpinfo_unpack(talloc_tos(), data);
+ if (ai == NULL) {
+ rc = -1;
+ goto exit;
+ }
+
+ if (ai_empty_finderinfo(ai)) {
+ switch (config->meta) {
+ case FRUIT_META_STREAM:
+ rc = SMB_VFS_UNLINK(handle->conn, fsp->fsp_name);
+ break;
+
+ case FRUIT_META_NETATALK:
+ rc = SMB_VFS_REMOVEXATTR(
+ handle->conn,
+ fsp->fsp_name->base_name,
+ AFPINFO_EA_NETATALK);
+ break;
- tmp_base_name = fsp->base_fsp->fsp_name->base_name;
- status = SMB_VFS_TRANSLATE_NAME(handle->conn,
- fsp->base_fsp->fsp_name->base_name,
- vfs_translate_to_unix,
- talloc_tos(), &name);
- if (!NT_STATUS_IS_OK(status)) {
- errno = map_errno_from_nt_status(status);
- rc = -1;
- goto exit;
+ default:
+ DBG_ERR("Unexpected meta config [%d]\n",
+ config->meta);
+ rc = -1;
+ goto exit;
+ }
+
+ 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;
+ }
}
- fsp->base_fsp->fsp_name->base_name = name;
if (ad == NULL) {
len = SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
}
if (ad->ad_type == ADOUBLE_META) {
- if (n != AFP_INFO_SIZE || offset != 0) {
- DEBUG(1, ("unexpected offset=%jd or size=%jd\n",
- (intmax_t)offset, (intmax_t)n));
- rc = -1;
- goto exit;
- }
- ai = afpinfo_unpack(talloc_tos(), data);
- if (ai == NULL) {
+ char *p = NULL;
+
+ p = ad_get_entry(ad, ADEID_FINDERI);
+ if (p == NULL) {
+ DBG_ERR("No ADEID_FINDERI for [%s]\n",
+ fsp->fsp_name->base_name);
rc = -1;
goto exit;
}
- memcpy(ad_entry(ad, ADEID_FINDERI),
- &ai->afpi_FinderInfo[0], ADEDLEN_FINDERI);
- rc = ad_write(ad, name);
+
+ memcpy(p, &ai->afpi_FinderInfo[0], ADEDLEN_FINDERI);
+ rc = ad_write(ad, fsp->base_fsp->fsp_name->base_name);
} else {
len = SMB_VFS_NEXT_PWRITE(handle, fsp, data, n,
offset + ad_getentryoff(ad, ADEID_RFORK));
}
if (config->rsrc == FRUIT_RSRC_ADFILE) {
- rc = ad_read(ad, name);
+ rc = ad_read(ad, fsp->base_fsp->fsp_name->base_name);
if (rc == -1) {
goto exit;
}
if ((len + offset) > ad_getentrylen(ad, ADEID_RFORK)) {
ad_setentrylen(ad, ADEID_RFORK, len + offset);
- rc = ad_write(ad, name);
+ rc = ad_write(ad, fsp->base_fsp->fsp_name->base_name);
}
}
}
exit:
- fsp->base_fsp->fsp_name->base_name = tmp_base_name;
- TALLOC_FREE(name);
TALLOC_FREE(ai);
if (rc != 0) {
return -1;
return rc;
}
-static int fruit_stat_meta(vfs_handle_struct *handle,
- struct smb_filename *smb_fname,
- bool follow_links)
+static int fruit_stat_meta_stream(vfs_handle_struct *handle,
+ struct smb_filename *smb_fname,
+ bool follow_links)
+{
+ int ret;
+
+ if (follow_links) {
+ ret = SMB_VFS_NEXT_STAT(handle, smb_fname);
+ } else {
+ ret = SMB_VFS_NEXT_LSTAT(handle, smb_fname);
+ }
+
+ return ret;
+}
+
+static int fruit_stat_meta_netatalk(vfs_handle_struct *handle,
+ 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;
return 0;
}
-static int fruit_stat_rsrc(vfs_handle_struct *handle,
+static int fruit_stat_meta(vfs_handle_struct *handle,
struct smb_filename *smb_fname,
bool follow_links)
+{
+ struct fruit_config_data *config = NULL;
+ int ret;
+
+ SMB_VFS_HANDLE_GET_DATA(handle, config,
+ struct fruit_config_data, return -1);
+
+ switch (config->meta) {
+ case FRUIT_META_STREAM:
+ ret = fruit_stat_meta_stream(handle, smb_fname, follow_links);
+ break;
+
+ case FRUIT_META_NETATALK:
+ ret = fruit_stat_meta_netatalk(handle, smb_fname, follow_links);
+ break;
+
+ default:
+ DBG_ERR("Unexpected meta config [%d]\n", config->meta);
+ return -1;
+ }
+
+ return ret;
+}
+static int fruit_stat_rsrc_netatalk(vfs_handle_struct *handle,
+ struct smb_filename *smb_fname,
+ bool follow_links)
{
struct adouble *ad = NULL;
-
- DEBUG(10, ("fruit_stat_rsrc called for %s\n",
- smb_fname_str_dbg(smb_fname)));
+ int ret;
ad = ad_get(talloc_tos(), handle, smb_fname->base_name, ADOUBLE_RSRC);
if (ad == NULL) {
}
/* Populate the stat struct with info from the base file. */
- if (fruit_stat_base(handle, smb_fname, follow_links) == -1) {
+ ret = fruit_stat_base(handle, smb_fname, follow_links);
+ if (ret != 0) {
TALLOC_FREE(ad);
return -1;
}
return 0;
}
+static int fruit_stat_rsrc_stream(vfs_handle_struct *handle,
+ struct smb_filename *smb_fname,
+ bool follow_links)
+{
+ int ret;
+
+ if (follow_links) {
+ ret = SMB_VFS_NEXT_STAT(handle, smb_fname);
+ } else {
+ ret = SMB_VFS_NEXT_LSTAT(handle, smb_fname);
+ }
+
+ return ret;
+}
+
+static int fruit_stat_rsrc_xattr(vfs_handle_struct *handle,
+ struct smb_filename *smb_fname,
+ bool follow_links)
+{
+#ifdef HAVE_ATTROPEN
+ int ret;
+ int fd = -1;
+
+ /* Populate the stat struct with info from the base file. */
+ ret = fruit_stat_base(handle, smb_fname, follow_links);
+ if (ret != 0) {
+ return -1;
+ }
+
+ fd = attropen(smb_fname->base_name,
+ AFPRESOURCE_EA_NETATALK,
+ O_RDONLY);
+ if (fd == -1) {
+ return 0;
+ }
+
+ ret = sys_fstat(fd, &smb_fname->st, false);
+ if (ret != 0) {
+ close(fd);
+ DBG_ERR("fstat [%s:%s] failed\n", smb_fname->base_name,
+ AFPRESOURCE_EA_NETATALK);
+ return -1;
+ }
+ close(fd);
+ fd = -1;
+
+ smb_fname->st.st_ex_ino = fruit_inode(&smb_fname->st,
+ smb_fname->stream_name);
+
+ return ret;
+
+#else
+ errno = ENOSYS;
+ return -1;
+#endif
+}
+
+static int fruit_stat_rsrc(vfs_handle_struct *handle,
+ struct smb_filename *smb_fname,
+ bool follow_links)
+{
+ struct fruit_config_data *config = NULL;
+ int ret;
+
+ DBG_DEBUG("Path [%s]\n", smb_fname_str_dbg(smb_fname));
+
+ SMB_VFS_HANDLE_GET_DATA(handle, config,
+ struct fruit_config_data, return -1);
+
+ switch (config->rsrc) {
+ case FRUIT_RSRC_STREAM:
+ ret = fruit_stat_rsrc_stream(handle, smb_fname, follow_links);
+ break;
+
+ case FRUIT_RSRC_XATTR:
+ ret = fruit_stat_rsrc_xattr(handle, smb_fname, follow_links);
+ break;
+
+ case FRUIT_RSRC_ADFILE:
+ ret = fruit_stat_rsrc_netatalk(handle, smb_fname, follow_links);
+ break;
+
+ default:
+ DBG_ERR("Unexpected rsrc config [%d]\n", config->rsrc);
+ return -1;
+ }
+
+ return ret;
+}
+
static int fruit_stat(vfs_handle_struct *handle,
struct smb_filename *smb_fname)
{
SMB_STRUCT_STAT *sbuf)
{
int rc;
- char *name = NULL;
- char *tmp_base_name = NULL;
- NTSTATUS status;
struct adouble *ad = (struct adouble *)
VFS_FETCH_FSP_EXTENSION(handle, fsp);
DEBUG(10, ("fruit_fstat called for %s\n",
smb_fname_str_dbg(fsp->fsp_name)));
- if (fsp->base_fsp) {
- tmp_base_name = fsp->fsp_name->base_name;
- /* fsp_name is not converted with vfs_catia */
- status = SMB_VFS_TRANSLATE_NAME(
- handle->conn,
- fsp->base_fsp->fsp_name->base_name,
- vfs_translate_to_unix,
- talloc_tos(), &name);
-
- if (!NT_STATUS_IS_OK(status)) {
- errno = map_errno_from_nt_status(status);
- rc = -1;
- goto exit;
- }
- fsp->base_fsp->fsp_name->base_name = name;
- }
-
if (ad == NULL || fsp->base_fsp == NULL) {
rc = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
goto exit;
DEBUG(10, ("fruit_fstat %s, size: %zd\n",
smb_fname_str_dbg(fsp->fsp_name),
(ssize_t)sbuf->st_ex_size));
- if (tmp_base_name) {
- fsp->base_fsp->fsp_name->base_name = tmp_base_name;
- }
- TALLOC_FREE(name);
return rc;
}
+static NTSTATUS fruit_streaminfo_meta_stream(
+ vfs_handle_struct *handle,
+ struct files_struct *fsp,
+ const struct smb_filename *smb_fname,
+ TALLOC_CTX *mem_ctx,
+ unsigned int *pnum_streams,
+ struct stream_struct **pstreams)
+{
+ return NT_STATUS_OK;
+}
+
+static NTSTATUS fruit_streaminfo_meta_netatalk(
+ vfs_handle_struct *handle,
+ struct files_struct *fsp,
+ const struct smb_filename *smb_fname,
+ TALLOC_CTX *mem_ctx,
+ unsigned int *pnum_streams,
+ struct stream_struct **pstreams)
+{
+ struct adouble *ad = NULL;
+ bool is_fi_empty;
+ bool ok;
+
+ /* Remove the Netatalk xattr from the list */
+ ok = del_fruit_stream(mem_ctx, pnum_streams, pstreams,
+ ":" NETATALK_META_XATTR ":$DATA");
+ if (!ok) {
+ return NT_STATUS_NO_MEMORY;
+ }
+
+ ad = ad_get(talloc_tos(), handle,
+ smb_fname->base_name, ADOUBLE_META);
+ if (ad == NULL) {
+ return NT_STATUS_OK;
+ }
+
+ is_fi_empty = ad_empty_finderinfo(ad);
+ TALLOC_FREE(ad);
+
+ if (is_fi_empty) {
+ return NT_STATUS_OK;
+ }
+
+ ok = add_fruit_stream(mem_ctx, pnum_streams, pstreams,
+ AFPINFO_STREAM_NAME, AFP_INFO_SIZE,
+ smb_roundup(handle->conn, AFP_INFO_SIZE));
+ if (!ok) {
+ return NT_STATUS_NO_MEMORY;
+ }
+
+ return NT_STATUS_OK;
+}
+
+static NTSTATUS fruit_streaminfo_meta(vfs_handle_struct *handle,
+ struct files_struct *fsp,
+ const struct smb_filename *smb_fname,
+ TALLOC_CTX *mem_ctx,
+ unsigned int *pnum_streams,
+ struct stream_struct **pstreams)
+{
+ struct fruit_config_data *config = NULL;
+ NTSTATUS status;
+
+ SMB_VFS_HANDLE_GET_DATA(handle, config, struct fruit_config_data,
+ return NT_STATUS_INTERNAL_ERROR);
+
+ switch (config->meta) {
+ case FRUIT_META_NETATALK:
+ status = fruit_streaminfo_meta_netatalk(handle, fsp, smb_fname,
+ mem_ctx, pnum_streams,
+ pstreams);
+ break;
+
+ case FRUIT_META_STREAM:
+ status = fruit_streaminfo_meta_stream(handle, fsp, smb_fname,
+ mem_ctx, pnum_streams,
+ pstreams);
+ break;
+
+ default:
+ return NT_STATUS_INTERNAL_ERROR;
+ }
+
+ return status;
+}
+
+static NTSTATUS fruit_streaminfo_rsrc_stream(
+ vfs_handle_struct *handle,
+ struct files_struct *fsp,
+ const struct smb_filename *smb_fname,
+ TALLOC_CTX *mem_ctx,
+ unsigned int *pnum_streams,
+ struct stream_struct **pstreams)
+{
+ bool ok;
+
+ ok = filter_empty_rsrc_stream(pnum_streams, pstreams);
+ if (!ok) {
+ DBG_ERR("Filtering resource stream failed\n");
+ return NT_STATUS_INTERNAL_ERROR;
+ }
+ return NT_STATUS_OK;
+}
+
+static NTSTATUS fruit_streaminfo_rsrc_xattr(
+ vfs_handle_struct *handle,
+ struct files_struct *fsp,
+ const struct smb_filename *smb_fname,
+ TALLOC_CTX *mem_ctx,
+ unsigned int *pnum_streams,
+ struct stream_struct **pstreams)
+{
+ bool ok;
+
+ ok = filter_empty_rsrc_stream(pnum_streams, pstreams);
+ if (!ok) {
+ DBG_ERR("Filtering resource stream failed\n");
+ return NT_STATUS_INTERNAL_ERROR;
+ }
+ return NT_STATUS_OK;
+}
+
+static NTSTATUS fruit_streaminfo_rsrc_adouble(
+ vfs_handle_struct *handle,
+ struct files_struct *fsp,
+ const struct smb_filename *smb_fname,
+ TALLOC_CTX *mem_ctx,
+ unsigned int *pnum_streams,
+ struct stream_struct **pstreams)
+{
+ struct stream_struct *stream = *pstreams;
+ unsigned int num_streams = *pnum_streams;
+ struct adouble *ad = NULL;
+ bool ok;
+ size_t rlen;
+ int i;
+
+ /*
+ * Check if there's a AFPRESOURCE_STREAM from the VFS streams backend
+ * and if yes, remove it from the list
+ */
+ for (i = 0; i < num_streams; i++) {
+ if (strequal_m(stream[i].name, AFPRESOURCE_STREAM)) {
+ break;
+ }
+ }
+
+ if (i < num_streams) {
+ DBG_WARNING("Unexpected AFPRESOURCE_STREAM on [%s]\n",
+ smb_fname_str_dbg(smb_fname));
+
+ ok = del_fruit_stream(mem_ctx, pnum_streams, pstreams,
+ AFPRESOURCE_STREAM);
+ if (!ok) {
+ return NT_STATUS_INTERNAL_ERROR;
+ }
+ }
+
+ ad = ad_get(talloc_tos(), handle, smb_fname->base_name,
+ ADOUBLE_RSRC);
+ if (ad == NULL) {
+ return NT_STATUS_OK;
+ }
+
+ rlen = ad_getentrylen(ad, ADEID_RFORK);
+ TALLOC_FREE(ad);
+
+ if (rlen == 0) {
+ return NT_STATUS_OK;
+ }
+
+ ok = add_fruit_stream(mem_ctx, pnum_streams, pstreams,
+ AFPRESOURCE_STREAM_NAME, rlen,
+ smb_roundup(handle->conn, rlen));
+ if (!ok) {
+ return NT_STATUS_NO_MEMORY;
+ }
+
+ return NT_STATUS_OK;
+}
+
+static NTSTATUS fruit_streaminfo_rsrc(vfs_handle_struct *handle,
+ struct files_struct *fsp,
+ const struct smb_filename *smb_fname,
+ TALLOC_CTX *mem_ctx,
+ unsigned int *pnum_streams,
+ struct stream_struct **pstreams)
+{
+ struct fruit_config_data *config = NULL;
+ NTSTATUS status;
+
+ SMB_VFS_HANDLE_GET_DATA(handle, config, struct fruit_config_data,
+ return NT_STATUS_INTERNAL_ERROR);
+
+ switch (config->rsrc) {
+ case FRUIT_RSRC_STREAM:
+ status = fruit_streaminfo_rsrc_stream(handle, fsp, smb_fname,
+ mem_ctx, pnum_streams,
+ pstreams);
+ break;
+
+ case FRUIT_RSRC_XATTR:
+ status = fruit_streaminfo_rsrc_xattr(handle, fsp, smb_fname,
+ mem_ctx, pnum_streams,
+ pstreams);
+ break;
+
+ case FRUIT_RSRC_ADFILE:
+ status = fruit_streaminfo_rsrc_adouble(handle, fsp, smb_fname,
+ mem_ctx, pnum_streams,
+ pstreams);
+ break;
+
+ default:
+ return NT_STATUS_INTERNAL_ERROR;
+ }
+
+ return status;
+}
+
static NTSTATUS fruit_streaminfo(vfs_handle_struct *handle,
struct files_struct *fsp,
- const char *fname,
+ const struct smb_filename *smb_fname,
TALLOC_CTX *mem_ctx,
unsigned int *pnum_streams,
struct stream_struct **pstreams)
{
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);
- DEBUG(10, ("fruit_streaminfo called for %s\n", fname));
- smb_fname = synthetic_smb_fname(talloc_tos(), fname, NULL, NULL);
- if (smb_fname == NULL) {
- return NT_STATUS_NO_MEMORY;
- }
+ DBG_DEBUG("Path [%s]\n", smb_fname_str_dbg(smb_fname));
- if (config->meta == FRUIT_META_NETATALK) {
- ad = ad_get(talloc_tos(), handle,
- smb_fname->base_name, ADOUBLE_META);
- if (ad && !empty_finderinfo(ad)) {
- if (!add_fruit_stream(
- mem_ctx, pnum_streams, pstreams,
- AFPINFO_STREAM_NAME, AFP_INFO_SIZE,
- smb_roundup(handle->conn,
- AFP_INFO_SIZE))) {
- TALLOC_FREE(ad);
- TALLOC_FREE(smb_fname);
- return NT_STATUS_NO_MEMORY;
- }
- }
- TALLOC_FREE(ad);
+ status = SMB_VFS_NEXT_STREAMINFO(handle, fsp, smb_fname, mem_ctx,
+ pnum_streams, pstreams);
+ if (!NT_STATUS_IS_OK(status)) {
+ return status;
}
- if (config->rsrc != FRUIT_RSRC_STREAM) {
- ad = ad_get(talloc_tos(), handle, smb_fname->base_name,
- ADOUBLE_RSRC);
- if (ad) {
- if (!add_fruit_stream(
- mem_ctx, pnum_streams, pstreams,
- AFPRESOURCE_STREAM_NAME,
- ad_getentrylen(ad, ADEID_RFORK),
- smb_roundup(handle->conn,
- ad_getentrylen(
- ad, ADEID_RFORK)))) {
- TALLOC_FREE(ad);
- TALLOC_FREE(smb_fname);
- return NT_STATUS_NO_MEMORY;
- }
- }
- TALLOC_FREE(ad);
+ status = fruit_streaminfo_meta(handle, fsp, smb_fname,
+ mem_ctx, pnum_streams, pstreams);
+ if (!NT_STATUS_IS_OK(status)) {
+ return status;
}
- TALLOC_FREE(smb_fname);
+ status = fruit_streaminfo_rsrc(handle, fsp, smb_fname,
+ mem_ctx, pnum_streams, pstreams);
+ if (!NT_STATUS_IS_OK(status)) {
+ return status;
+ }
- return SMB_VFS_NEXT_STREAMINFO(handle, fsp, fname, mem_ctx,
- pnum_streams, pstreams);
+ return NT_STATUS_OK;
}
static int fruit_ntimes(vfs_handle_struct *handle,
{
int rc = 0;
struct adouble *ad = NULL;
+ struct fruit_config_data *config = NULL;
- if (null_timespec(ft->create_time)) {
- goto exit;
+ SMB_VFS_HANDLE_GET_DATA(handle, config, struct fruit_config_data,
+ return -1);
+
+ if ((config->meta != FRUIT_META_NETATALK) ||
+ null_timespec(ft->create_time))
+ {
+ return SMB_VFS_NEXT_NTIMES(handle, smb_fname, ft);
}
DEBUG(10,("set btime for %s to %s\n", smb_fname_str_dbg(smb_fname),
static int fruit_fallocate(struct vfs_handle_struct *handle,
struct files_struct *fsp,
- enum vfs_fallocate_mode mode,
+ uint32_t mode,
off_t offset,
off_t len)
{
}
if (!fruit_fsp_recheck(ad, fsp)) {
- return errno;
+ return -1;
}
/* Let the pwrite code path handle it. */
- return ENOSYS;
+ errno = ENOSYS;
+ return -1;
}
-static int fruit_ftruncate(struct vfs_handle_struct *handle,
- struct files_struct *fsp,
- off_t offset)
+static int fruit_ftruncate_rsrc_xattr(struct vfs_handle_struct *handle,
+ struct files_struct *fsp,
+ off_t offset)
{
- int rc = 0;
+ if (offset == 0) {
+ return SMB_VFS_FREMOVEXATTR(fsp, AFPRESOURCE_EA_NETATALK);
+ }
+
+#ifdef HAVE_ATTROPEN
+ return SMB_VFS_NEXT_FTRUNCATE(handle, fsp, offset);
+#endif
+ return 0;
+}
+
+static int fruit_ftruncate_rsrc_adouble(struct vfs_handle_struct *handle,
+ struct files_struct *fsp,
+ off_t offset)
+{
+ int rc;
struct adouble *ad =
(struct adouble *)VFS_FETCH_FSP_EXTENSION(handle, fsp);
- struct fruit_config_data *config;
+ off_t ad_off = ad_getentryoff(ad, ADEID_RFORK);
- DEBUG(10, ("streams_xattr_ftruncate called for file %s offset %.0f\n",
- fsp_str_dbg(fsp), (double)offset));
+ if (!fruit_fsp_recheck(ad, fsp)) {
+ return -1;
+ }
- if (ad == NULL) {
- return SMB_VFS_NEXT_FTRUNCATE(handle, fsp, offset);
+ rc = SMB_VFS_NEXT_FTRUNCATE(handle, fsp, offset + ad_off);
+ if (rc != 0) {
+ return -1;
}
- if (!fruit_fsp_recheck(ad, fsp)) {
+ ad_setentrylen(ad, ADEID_RFORK, offset);
+
+ rc = ad_write(ad, NULL);
+ if (rc != 0) {
+ DBG_ERR("ad_write [%s] failed [%s]\n",
+ fsp_str_dbg(fsp), strerror(errno));
return -1;
}
+ DBG_DEBUG("Path [%s] offset [%jd]\n",
+ fsp_str_dbg(fsp), (intmax_t)offset);
+
+ return 0;
+}
+
+static int fruit_ftruncate_rsrc_stream(struct vfs_handle_struct *handle,
+ struct files_struct *fsp,
+ off_t offset)
+{
+ if (offset == 0) {
+ return SMB_VFS_NEXT_UNLINK(handle, fsp->fsp_name);
+ }
+
+ return SMB_VFS_NEXT_FTRUNCATE(handle, fsp, offset);
+}
+
+static int fruit_ftruncate_rsrc(struct vfs_handle_struct *handle,
+ struct files_struct *fsp,
+ off_t offset)
+{
+ int ret;
+ struct fruit_config_data *config;
+
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);
- }
+ switch (config->rsrc) {
+ case FRUIT_RSRC_XATTR:
+ ret = fruit_ftruncate_rsrc_xattr(handle, fsp, offset);
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));
- }
+
+ case FRUIT_RSRC_ADFILE:
+ ret = fruit_ftruncate_rsrc_adouble(handle, fsp, offset);
break;
+
+ case FRUIT_RSRC_STREAM:
+ ret = fruit_ftruncate_rsrc_stream(handle, fsp, offset);
+ break;
+
default:
+ DBG_ERR("Unexpected rsrc config [%d]\n", config->rsrc);
return -1;
}
- return rc;
+
+ return ret;
+}
+
+static int fruit_ftruncate(struct vfs_handle_struct *handle,
+ struct files_struct *fsp,
+ off_t offset)
+{
+ DBG_DEBUG("fruit_ftruncate called for file %s offset %.0f\n",
+ fsp_str_dbg(fsp), (double)offset);
+
+ if (is_afpinfo_stream(fsp->fsp_name)) {
+ 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;
+ }
+
+ if (is_afpresource_stream(fsp->fsp_name)) {
+ return fruit_ftruncate_rsrc(handle, fsp, offset);
+ }
+
+ return SMB_VFS_NEXT_FTRUNCATE(handle, fsp, offset);
}
static NTSTATUS fruit_create_file(vfs_handle_struct *handle,
struct security_descriptor *sd,
struct ea_list *ea_list,
files_struct **result,
- int *pinfo)
+ int *pinfo,
+ const struct smb2_create_blobs *in_context_blobs,
+ struct smb2_create_blobs *out_context_blobs)
{
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)) {
+ goto fail;
+ }
+
+ SMB_VFS_HANDLE_GET_DATA(handle, config, struct fruit_config_data,
+ return NT_STATUS_UNSUCCESSFUL);
status = SMB_VFS_NEXT_CREATE_FILE(
handle, req, root_dir_fid, smb_fname,
lease,
allocation_size, private_flags,
sd, ea_list, result,
- pinfo);
-
+ pinfo, in_context_blobs, out_context_blobs);
if (!NT_STATUS_IS_OK(status)) {
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 (config->posix_rename && 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;
}
- SMB_VFS_HANDLE_GET_DATA(handle, config, struct fruit_config_data,
- return NT_STATUS_UNSUCCESSFUL);
-
if (config->locking == FRUIT_LOCKING_NETATALK) {
status = fruit_check_access(
handle, *result,
return status;
fail:
- DEBUG(1, ("fruit_create_file: %s\n", nt_errstr(status)));
+ DEBUG(10, ("fruit_create_file: %s\n", nt_errstr(status)));
+
+ if (fsp) {
+ close_file(req, fsp, ERROR_CLOSE);
+ *result = fsp = NULL;
+ }
+
+ return status;
+}
+
+static NTSTATUS fruit_readdir_attr(struct vfs_handle_struct *handle,
+ const struct smb_filename *fname,
+ TALLOC_CTX *mem_ctx,
+ struct readdir_attr_data **pattr_data)
+{
+ struct fruit_config_data *config = NULL;
+ struct readdir_attr_data *attr_data;
+ NTSTATUS status;
+
+ SMB_VFS_HANDLE_GET_DATA(handle, config,
+ struct fruit_config_data,
+ return NT_STATUS_UNSUCCESSFUL);
+
+ if (!config->nego_aapl) {
+ return SMB_VFS_NEXT_READDIR_ATTR(handle, fname, mem_ctx, pattr_data);
+ }
+
+ DEBUG(10, ("fruit_readdir_attr %s\n", fname->base_name));
+
+ *pattr_data = talloc_zero(mem_ctx, struct readdir_attr_data);
+ if (*pattr_data == NULL) {
+ return NT_STATUS_UNSUCCESSFUL;
+ }
+ attr_data = *pattr_data;
+ attr_data->type = RDATTR_AAPL;
+
+ /*
+ * Mac metadata: compressed FinderInfo, resource fork length
+ * and creation date
+ */
+ status = readdir_attr_macmeta(handle, fname, attr_data);
+ if (!NT_STATUS_IS_OK(status)) {
+ /*
+ * Error handling is tricky: if we return failure from
+ * this function, the corresponding directory entry
+ * will to be passed to the client, so we really just
+ * want to error out on fatal errors.
+ */
+ if (!NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
+ goto fail;
+ }
+ }
+
+ /*
+ * UNIX mode
+ */
+ if (config->unix_info_enabled) {
+ attr_data->attr_data.aapl.unix_mode = fname->st.st_ex_mode;
+ }
- if (*result) {
- close_file(req, *result, ERROR_CLOSE);
- *result = NULL;
+ /*
+ * max_access
+ */
+ if (!config->readdir_attr_max_access) {
+ attr_data->attr_data.aapl.max_access = FILE_GENERIC_ALL;
+ } else {
+ status = smbd_calculate_access_mask(
+ handle->conn,
+ fname,
+ false,
+ SEC_FLAG_MAXIMUM_ALLOWED,
+ &attr_data->attr_data.aapl.max_access);
+ if (!NT_STATUS_IS_OK(status)) {
+ goto fail;
+ }
}
+ return NT_STATUS_OK;
+
+fail:
+ DEBUG(1, ("fruit_readdir_attr %s, error: %s\n",
+ fname->base_name, nt_errstr(status)));
+ TALLOC_FREE(*pattr_data);
return status;
}
+static NTSTATUS fruit_fget_nt_acl(vfs_handle_struct *handle,
+ files_struct *fsp,
+ uint32_t security_info,
+ TALLOC_CTX *mem_ctx,
+ struct security_descriptor **ppdesc)
+{
+ NTSTATUS status;
+ struct security_ace ace;
+ struct dom_sid sid;
+ struct fruit_config_data *config;
+
+ SMB_VFS_HANDLE_GET_DATA(handle, config,
+ struct fruit_config_data,
+ return NT_STATUS_UNSUCCESSFUL);
+
+ status = SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info,
+ mem_ctx, ppdesc);
+ if (!NT_STATUS_IS_OK(status)) {
+ return status;
+ }
+
+ /*
+ * Add MS NFS style ACEs with uid, gid and mode
+ */
+ if (!config->unix_info_enabled) {
+ return NT_STATUS_OK;
+ }
+
+ /* MS NFS style mode */
+ sid_compose(&sid, &global_sid_Unix_NFS_Mode, fsp->fsp_name->st.st_ex_mode);
+ init_sec_ace(&ace, &sid, SEC_ACE_TYPE_ACCESS_DENIED, 0, 0);
+ status = security_descriptor_dacl_add(*ppdesc, &ace);
+ if (!NT_STATUS_IS_OK(status)) {
+ DEBUG(1,("failed to add MS NFS style ACE\n"));
+ return status;
+ }
+
+ /* MS NFS style uid */
+ sid_compose(&sid, &global_sid_Unix_NFS_Users, fsp->fsp_name->st.st_ex_uid);
+ init_sec_ace(&ace, &sid, SEC_ACE_TYPE_ACCESS_DENIED, 0, 0);
+ status = security_descriptor_dacl_add(*ppdesc, &ace);
+ if (!NT_STATUS_IS_OK(status)) {
+ DEBUG(1,("failed to add MS NFS style ACE\n"));
+ return status;
+ }
+
+ /* MS NFS style gid */
+ sid_compose(&sid, &global_sid_Unix_NFS_Groups, fsp->fsp_name->st.st_ex_gid);
+ init_sec_ace(&ace, &sid, SEC_ACE_TYPE_ACCESS_DENIED, 0, 0);
+ status = security_descriptor_dacl_add(*ppdesc, &ace);
+ if (!NT_STATUS_IS_OK(status)) {
+ DEBUG(1,("failed to add MS NFS style ACE\n"));
+ return status;
+ }
+
+ return NT_STATUS_OK;
+}
+
+static NTSTATUS fruit_fset_nt_acl(vfs_handle_struct *handle,
+ files_struct *fsp,
+ uint32_t security_info_sent,
+ const struct security_descriptor *psd)
+{
+ NTSTATUS status;
+ bool do_chmod;
+ mode_t ms_nfs_mode = 0;
+ int result;
+
+ 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)) {
+ DEBUG(1, ("fruit_fset_nt_acl: check_ms_nfs failed%s\n", fsp_str_dbg(fsp)));
+ return status;
+ }
+
+ status = SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp, security_info_sent, psd);
+ if (!NT_STATUS_IS_OK(status)) {
+ DEBUG(1, ("fruit_fset_nt_acl: SMB_VFS_NEXT_FSET_NT_ACL failed%s\n", fsp_str_dbg(fsp)));
+ return status;
+ }
+
+ if (do_chmod) {
+ if (fsp->fh->fd != -1) {
+ result = SMB_VFS_FCHMOD(fsp, ms_nfs_mode);
+ } else {
+ result = SMB_VFS_CHMOD(fsp->conn,
+ fsp->fsp_name,
+ ms_nfs_mode);
+ }
+
+ if (result != 0) {
+ DEBUG(1, ("chmod: %s, result: %d, %04o error %s\n", fsp_str_dbg(fsp),
+ result, (unsigned)ms_nfs_mode,
+ strerror(errno)));
+ status = map_nt_error_from_unix(errno);
+ return status;
+ }
+ }
+
+ 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;
+ unsigned 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 remaining 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, state->src_fsp,
+ state->src_fsp->fsp_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'/%zu\n",
+ __func__, streams[i].name, (size_t)streams[i].size));
+
+ src_fname_tmp = synthetic_smb_fname(
+ req,
+ state->src_fsp->fsp_name->base_name,
+ streams[i].name,
+ NULL,
+ state->src_fsp->fsp_name->flags);
+ 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,
+ state->dst_fsp->fsp_name->flags);
+ 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,
.fstat_fn = fruit_fstat,
.streaminfo_fn = fruit_streaminfo,
.ntimes_fn = fruit_ntimes,
- .unlink_fn = fruit_unlink,
.ftruncate_fn = fruit_ftruncate,
.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,
+ .fset_nt_acl_fn = fruit_fset_nt_acl,
};
NTSTATUS vfs_fruit_init(void);