*
* 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?
- */
#define NETATALK_META_XATTR "org.netatalk.Metadata"
-#if defined(HAVE_ATTROPEN) || defined(FREEBSD)
+#define NETATALK_RSRC_XATTR "org.netatalk.ResourceFork"
+
+#if defined(HAVE_ATTROPEN)
#define AFPINFO_EA_NETATALK NETATALK_META_XATTR
-#define AFPRESOURCE_EA_NETATALK "org.netatalk.ResourceFork"
+#define AFPRESOURCE_EA_NETATALK NETATALK_RSRC_XATTR
#else
#define AFPINFO_EA_NETATALK "user." NETATALK_META_XATTR
-#define AFPRESOURCE_EA_NETATALK "user.org.netatalk.ResourceFork"
+#define AFPRESOURCE_EA_NETATALK "user." NETATALK_RSRC_XATTR
#endif
enum apple_fork {APPLE_FORK_DATA, APPLE_FORK_RSRC};
bool unix_info_enabled;
bool copyfile_enabled;
bool veto_appledouble;
+ bool posix_rename;
/*
* Additional options, all enabled by default,
#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;
}
/**
* Unpack an AppleDouble blob into a struct adoble
**/
-static bool ad_unpack(struct adouble *ad, const int nentries, size_t filesize)
+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;
}
* 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)
/* Now parse entries */
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;
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) {
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->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);
return true;
}
+static bool filter_empty_rsrc_stream(unsigned int *num_streams,
+ struct stream_struct **streams)
+{
+ 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, 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;
- int i;
+ unsigned int i;
if (*num_streams == 0) {
return true;
return true;
}
-static bool empty_finderinfo(const struct adouble *ad)
+static bool ad_empty_finderinfo(const struct adouble *ad)
{
-
+ int cmp;
char emptybuf[ADEDLEN_FINDERI] = {0};
- if (memcmp(emptybuf,
- ad_entry(ad, ADEID_FINDERI),
- ADEDLEN_FINDERI) == 0) {
- return true;
+ 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;
}
- 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) {
* 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_type = APPLE_FORK_DATA;
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
*/
}
/* Set locks */
- if (access_mask & 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,
TALLOC_FREE(br_lck);
}
- if (deny_mode & 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,
}
/* Set locks */
- if (access_mask & 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,
TALLOC_FREE(br_lck);
}
- if (deny_mode & 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,
return status;
}
+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;
+ }
+
+ ret = SMB_VFS_STAT(handle->conn, stream_name);
+ if (ret != 0) {
+ return false;
+ }
+
+ 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;
- uint32_t date_added;
- struct adouble *ad = NULL;
struct fruit_config_data *config = NULL;
+ bool ok;
SMB_VFS_HANDLE_GET_DATA(handle, config,
struct fruit_config_data,
*/
if (config->readdir_attr_rsize) {
- ad = ad_get(talloc_tos(), handle, smb_fname->base_name,
- ADOUBLE_RSRC);
- if (ad) {
- attr_data->attr_data.aapl.rfork_size = ad_getentrylen(
- ad, ADEID_RFORK);
- TALLOC_FREE(ad);
- }
+ uint64_t rfork_size;
+
+ rfork_size = readdir_attr_rfork_size(handle, smb_fname);
+ attr_data->attr_data.aapl.rfork_size = rfork_size;
}
/*
*/
if (config->readdir_attr_finder_info) {
- ad = ad_get(talloc_tos(), handle, smb_fname->base_name,
- ADOUBLE_META);
- if (ad) {
- if (S_ISREG(smb_fname->st.st_ex_mode)) {
- /* finder_type */
- memcpy(&attr_data->attr_data.aapl.finder_info[0],
- ad_entry(ad, ADEID_FINDERI), 4);
-
- /* finder_creator */
- memcpy(&attr_data->attr_data.aapl.finder_info[0] + 4,
- ad_entry(ad, ADEID_FINDERI) + 4, 4);
- }
-
- /* finder_flags */
- memcpy(&attr_data->attr_data.aapl.finder_info[0] + 8,
- ad_entry(ad, ADEID_FINDERI) + 8, 2);
-
- /* finder_ext_flags */
- memcpy(&attr_data->attr_data.aapl.finder_info[0] + 10,
- ad_entry(ad, ADEID_FINDERI) + 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);
-
- TALLOC_FREE(ad);
+ ok = readdir_attr_meta_finderi(handle, smb_fname, attr_data);
+ if (!ok) {
+ status = NT_STATUS_INTERNAL_ERROR;
}
}
- TALLOC_FREE(ad);
return status;
}
mode_t *pmode,
bool *pdo_chmod)
{
- int i;
+ uint32_t i;
struct fruit_config_data *config = NULL;
*pdo_chmod = false;
return rc;
}
-static int fruit_open_meta(vfs_handle_struct *handle,
- struct smb_filename *smb_fname,
- files_struct *fsp, int flags, mode_t mode)
+static int fruit_open_meta_stream(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;
+ AfpInfo *ai = NULL;
+ char afpinfo_buf[AFP_INFO_SIZE];
+ ssize_t len, written;
int hostfd = -1;
- struct adouble *ad = NULL;
+ int rc = -1;
- DEBUG(10, ("fruit_open_meta for %s\n", smb_fname_str_dbg(smb_fname)));
+ hostfd = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
+ if (hostfd == -1) {
+ return -1;
+ }
- SMB_VFS_HANDLE_GET_DATA(handle, config,
- struct fruit_config_data, return -1);
+ if (!(flags & (O_CREAT | O_TRUNC))) {
+ return hostfd;
+ }
- if (config->meta == FRUIT_META_STREAM) {
- return SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
+ ai = afpinfo_new(talloc_tos());
+ if (ai == NULL) {
+ rc = -1;
+ goto fail;
}
- /* Create an smb_filename with stream_name == NULL. */
- smb_fname_base = synthetic_smb_fname(talloc_tos(),
- smb_fname->base_name, NULL, NULL);
+ len = afpinfo_pack(ai, afpinfo_buf);
+ if (len != AFP_INFO_SIZE) {
+ rc = -1;
+ goto fail;
+ }
- if (smb_fname_base == NULL) {
- errno = ENOMEM;
+ /* 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 exit;
+ 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;
}
/*
baseflags &= ~O_EXCL;
baseflags &= ~O_CREAT;
- hostfd = SMB_VFS_OPEN(handle->conn, smb_fname_base, fsp,
- baseflags, mode);
+ 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
if ((hostfd == -1) && (errno == EISDIR)) {
baseflags &= ~O_ACCMODE;
baseflags |= O_RDONLY;
- hostfd = SMB_VFS_OPEN(handle->conn, smb_fname_base, fsp,
- baseflags, mode);
+ hostfd = SMB_VFS_NEXT_OPEN(handle, smb_fname_base, fsp,
+ baseflags, mode);
}
TALLOC_FREE(smb_fname_base);
* 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;
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,
struct smb_filename *smb_fname,
files_struct *fsp, int flags, mode_t mode)
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);
- if (!is_ntfs_stream_smb_fname(smb_fname)) {
- char *adp = NULL;
+ switch (config->meta) {
+ case FRUIT_META_STREAM:
+ rc = fruit_unlink_meta_stream(handle, smb_fname);
+ break;
- rc = SMB_VFS_NEXT_UNLINK(handle, smb_fname);
- if (rc != 0) {
- return -1;
- }
+ case FRUIT_META_NETATALK:
+ rc = fruit_unlink_meta_netatalk(handle, smb_fname);
+ break;
- if (config->rsrc != FRUIT_RSRC_ADFILE) {
- return 0;
+ 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;
}
/*
* 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) {
+
+ 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;
}
- /* FIXME: direct unlink(), missing smb_fname */
- DEBUG(1,("fruit_unlink: %s\n", adp));
- rc = unlink(adp);
- if ((rc == -1) && (errno == ENOENT)) {
- rc = 0;
+ 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;
}
+ }
- TALLOC_FREE(adp);
- return 0;
+ ret = SMB_VFS_NEXT_UNLINK(handle, smb_fname);
+ if ((ret != 0) && (errno == ENOENT) && force_unlink) {
+ ret = 0;
}
- 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 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 (!force_unlink) {
+ ad = ad_get(talloc_tos(), handle, smb_fname->base_name,
+ ADOUBLE_RSRC);
+ if (ad == NULL) {
+ errno = ENOENT;
+ return -1;
}
- return rc;
- }
- if (is_afpresource_stream(smb_fname)) {
- if (config->rsrc == FRUIT_RSRC_ADFILE) {
- char *adp = NULL;
+ /*
+ * 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 */
- rc = unlink(adp);
- if ((rc == -1) && (errno == ENOENT)) {
- rc = 0;
- }
- TALLOC_FREE(adp);
- } else {
- rc = SMB_VFS_REMOVEXATTR(handle->conn,
- smb_fname->base_name,
- AFPRESOURCE_EA_NETATALK);
+ if (ad_getentrylen(ad, ADEID_RFORK) > 0) {
+ /* OS X ignores resource fork stream delete requests */
+ TALLOC_FREE(ad);
+ return 0;
}
- return rc;
+ TALLOC_FREE(ad);
}
- return SMB_VFS_NEXT_UNLINK(handle, smb_fname);
+ 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)) {
+ return fruit_unlink_meta(handle, smb_fname);
+ } else if (is_afpresource_stream(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);
+ }
+
+ /*
+ * 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_EQUAL(status, NT_STATUS_NONE_MAPPED)) {
- name = talloc_strdup(talloc_tos(), tmp_base_name);
- if (name == NULL) {
- rc = -1;
+ 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;
}
- } else if (!NT_STATUS_IS_OK(status)) {
- errno = map_errno_from_nt_status(status);
- rc = -1;
- 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];
- size_t to_return;
-
- if ((offset < 0) || (offset >= AFP_INFO_SIZE)) {
- len = 0;
- rc = 0;
- goto exit;
- }
-
- to_return = AFP_INFO_SIZE - offset;
+ char *p = NULL;
ai = afpinfo_new(talloc_tos());
if (ai == NULL) {
goto exit;
}
- memcpy(&ai->afpi_FinderInfo[0],
- ad_entry(ad, ADEID_FINDERI),
- ADEDLEN_FINDERI);
+ 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;
}
- memcpy(data, afpinfo_buf + offset, to_return);
+ /*
+ * 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(
}
}
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));
SMB_VFS_HANDLE_GET_DATA(handle, config,
struct fruit_config_data, return -1);
- 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_EQUAL(status, NT_STATUS_NONE_MAPPED)) {
- name = talloc_strdup(talloc_tos(), tmp_base_name);
- if (name == NULL) {
+ 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;
}
- } else if (!NT_STATUS_IS_OK(status)) {
- errno = map_errno_from_nt_status(status);
- 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;
+
+ 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_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;
+ }
+ smb_fname->st.st_ex_size = AFP_INFO_SIZE;
+ smb_fname->st.st_ex_ino = fruit_inode(&smb_fname->st,
+ smb_fname->stream_name);
+ return 0;
+}
+
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;
+ int ret;
+
+ ad = ad_get(talloc_tos(), handle, smb_fname->base_name, ADOUBLE_RSRC);
+ if (ad == NULL) {
+ errno = ENOENT;
+ return -1;
+ }
+
/* 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;
}
- smb_fname->st.st_ex_size = AFP_INFO_SIZE;
+
+ smb_fname->st.st_ex_size = ad_getentrylen(ad, ADEID_RFORK);
smb_fname->st.st_ex_ino = fruit_inode(&smb_fname->st,
smb_fname->stream_name);
+ TALLOC_FREE(ad);
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 adouble *ad = NULL;
+ struct fruit_config_data *config = NULL;
+ int ret;
- DEBUG(10, ("fruit_stat_rsrc called for %s\n",
- smb_fname_str_dbg(smb_fname)));
+ DBG_DEBUG("Path [%s]\n", smb_fname_str_dbg(smb_fname));
- ad = ad_get(talloc_tos(), handle, smb_fname->base_name, ADOUBLE_RSRC);
- if (ad == NULL) {
- errno = ENOENT;
- return -1;
- }
+ SMB_VFS_HANDLE_GET_DATA(handle, config,
+ struct fruit_config_data, return -1);
- /* Populate the stat struct with info from the base file. */
- if (fruit_stat_base(handle, smb_fname, follow_links) == -1) {
- TALLOC_FREE(ad);
+ 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;
}
- smb_fname->st.st_ex_size = ad_getentrylen(ad, ADEID_RFORK);
- smb_fname->st.st_ex_ino = fruit_inode(&smb_fname->st,
- smb_fname->stream_name);
- TALLOC_FREE(ad);
- return 0;
+ return ret;
}
static int fruit_stat(vfs_handle_struct *handle,
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->base_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_EQUAL(status, NT_STATUS_NONE_MAPPED)) {
- name = talloc_strdup(talloc_tos(), tmp_base_name);
- if (name == NULL) {
- rc = -1;
- goto exit;
- }
- } else 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(vfs_handle_struct *handle,
- struct files_struct *fsp,
- const char *fname,
- TALLOC_CTX *mem_ctx,
- unsigned int *pnum_streams,
- struct stream_struct **pstreams)
+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 fruit_config_data *config = NULL;
- struct smb_filename *smb_fname = NULL;
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_UNSUCCESSFUL);
- DEBUG(10, ("fruit_streaminfo called for %s\n", fname));
+ return NT_STATUS_INTERNAL_ERROR);
- smb_fname = synthetic_smb_fname(talloc_tos(), fname, NULL, NULL);
- if (smb_fname == NULL) {
- return NT_STATUS_NO_MEMORY;
+ 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;
}
- 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;
- }
+ 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;
}
- TALLOC_FREE(ad);
}
- if (config->rsrc != FRUIT_RSRC_STREAM) {
- ad = ad_get(talloc_tos(), handle, smb_fname->base_name,
- ADOUBLE_RSRC);
- if (ad && (ad_getentrylen(ad, ADEID_RFORK) > 0)) {
- 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;
- }
+ 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;
}
- TALLOC_FREE(ad);
}
- TALLOC_FREE(smb_fname);
+ 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 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;
- status = SMB_VFS_NEXT_STREAMINFO(handle, fsp, fname, mem_ctx,
+ SMB_VFS_HANDLE_GET_DATA(handle, config, struct fruit_config_data,
+ return NT_STATUS_UNSUCCESSFUL);
+
+ DBG_DEBUG("Path [%s]\n", smb_fname_str_dbg(smb_fname));
+
+ status = SMB_VFS_NEXT_STREAMINFO(handle, fsp, smb_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;
- }
+ status = fruit_streaminfo_meta(handle, fsp, smb_fname,
+ mem_ctx, pnum_streams, pstreams);
+ if (!NT_STATUS_IS_OK(status)) {
+ return status;
+ }
+
+ status = fruit_streaminfo_rsrc(handle, fsp, smb_fname,
+ mem_ctx, pnum_streams, pstreams);
+ if (!NT_STATUS_IS_OK(status)) {
+ return status;
}
return NT_STATUS_OK;
{
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),
return -1;
}
-static int fruit_ftruncate_meta(struct vfs_handle_struct *handle,
- struct files_struct *fsp,
- off_t offset,
- struct adouble *ad)
+static int fruit_ftruncate_rsrc_xattr(struct vfs_handle_struct *handle,
+ struct files_struct *fsp,
+ off_t offset)
{
- /*
- * 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) {
- DBG_WARNING("ftruncate %s to %jd",
- fsp_str_dbg(fsp), (intmax_t)offset);
- return -1;
+ if (offset == 0) {
+ return SMB_VFS_FREMOVEXATTR(fsp, AFPRESOURCE_EA_NETATALK);
}
- 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(struct vfs_handle_struct *handle,
- struct files_struct *fsp,
- off_t offset,
- struct adouble *ad)
+static int fruit_ftruncate_rsrc_adouble(struct vfs_handle_struct *handle,
+ struct files_struct *fsp,
+ off_t offset)
{
int rc;
- struct fruit_config_data *config;
-
- SMB_VFS_HANDLE_GET_DATA(handle, config,
- struct fruit_config_data, return -1);
+ struct adouble *ad =
+ (struct adouble *)VFS_FETCH_FSP_EXTENSION(handle, fsp);
+ off_t ad_off = ad_getentryoff(ad, ADEID_RFORK);
- if (config->rsrc == FRUIT_RSRC_XATTR && offset == 0) {
- return SMB_VFS_FREMOVEXATTR(fsp,
- AFPRESOURCE_EA_NETATALK);
+ if (!fruit_fsp_recheck(ad, fsp)) {
+ return -1;
}
- rc = SMB_VFS_NEXT_FTRUNCATE(
- handle, fsp,
- offset + ad_getentryoff(ad, ADEID_RFORK));
+ rc = SMB_VFS_NEXT_FTRUNCATE(handle, fsp, offset + ad_off);
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));
+ 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(struct vfs_handle_struct *handle,
- struct files_struct *fsp,
- off_t offset)
+static int fruit_ftruncate_rsrc_stream(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);
+ if (offset == 0) {
+ return SMB_VFS_NEXT_UNLINK(handle, fsp->fsp_name);
+ }
- DEBUG(10, ("streams_xattr_ftruncate called for file %s offset %.0f\n",
- fsp_str_dbg(fsp), (double)offset));
+ return SMB_VFS_NEXT_FTRUNCATE(handle, fsp, offset);
+}
- if (ad == NULL) {
- 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;
- if (!fruit_fsp_recheck(ad, fsp)) {
- return -1;
- }
+ SMB_VFS_HANDLE_GET_DATA(handle, config,
+ struct fruit_config_data, return -1);
- switch (ad->ad_type) {
- case ADOUBLE_META:
- rc = fruit_ftruncate_meta(handle, fsp, offset, ad);
+ switch (config->rsrc) {
+ case FRUIT_RSRC_XATTR:
+ ret = fruit_ftruncate_rsrc_xattr(handle, fsp, offset);
break;
- case ADOUBLE_RSRC:
- rc = fruit_ftruncate_rsrc(handle, fsp, offset, ad);
+ 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,
fsp->aapl_copyfile_supported = true;
}
- if (fsp->is_directory) {
+ if (config->posix_rename && fsp->is_directory) {
/*
* Enable POSIX directory rename behaviour
*/
struct fruit_config_data,
return NT_STATUS_UNSUCCESSFUL);
- if (!config->use_aapl) {
+ if (!config->nego_aapl) {
return SMB_VFS_NEXT_READDIR_ATTR(handle, fname, mem_ctx, pattr_data);
}
{
NTSTATUS status;
bool do_chmod;
- mode_t ms_nfs_mode;
+ mode_t ms_nfs_mode = 0;
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,
+ fsp->fsp_name,
ms_nfs_mode);
}
NTSTATUS status;
unsigned int num_streams = 0;
struct stream_struct *streams = NULL;
- int i;
+ unsigned int i;
struct smb_filename *src_fname_tmp = NULL;
struct smb_filename *dst_fname_tmp = NULL;
}
/*
- * Now copy all reamining streams. We know the share supports
+ * 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, NULL,
- state->src_fsp->fsp_name->base_name,
+ 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;
}
for (i = 0; i < num_streams; i++) {
- DEBUG(10, ("%s: stream: '%s'/%ju\n",
- __func__, streams[i].name,
- (uintmax_t)streams[i].size));
+ 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);
+ NULL,
+ state->src_fsp->fsp_name->flags);
if (tevent_req_nomem(src_fname_tmp, req)) {
return;
}
req,
state->dst_fsp->fsp_name->base_name,
streams[i].name,
- NULL);
+ NULL,
+ state->dst_fsp->fsp_name->flags);
if (tevent_req_nomem(dst_fname_tmp, req)) {
TALLOC_FREE(src_fname_tmp);
return;