From 778f2f3d9d9f519332f6581c98b56adae60d38dd Mon Sep 17 00:00:00 2001 From: Ralph Boehme Date: Mon, 24 Aug 2015 17:42:35 +0200 Subject: [PATCH 1/3] vfs_fruit: add and use define for the Netatalk metadata xattr Bug: https://bugzilla.samba.org/show_bug.cgi?id=11466 Signed-off-by: Ralph Boehme --- source3/modules/vfs_fruit.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/source3/modules/vfs_fruit.c b/source3/modules/vfs_fruit.c index 8ac4ba1..548c3e3 100644 --- a/source3/modules/vfs_fruit.c +++ b/source3/modules/vfs_fruit.c @@ -104,11 +104,12 @@ static int vfs_fruit_debug_level = DBGC_VFS; * REVIEW: * This is hokey, but what else can we do? */ +#define NETATALK_META_XATTR "org.netatalk.Metadata" #if defined(HAVE_ATTROPEN) || defined(FREEBSD) -#define AFPINFO_EA_NETATALK "org.netatalk.Metadata" +#define AFPINFO_EA_NETATALK NETATALK_META_XATTR #define AFPRESOURCE_EA_NETATALK "org.netatalk.ResourceFork" #else -#define AFPINFO_EA_NETATALK "user.org.netatalk.Metadata" +#define AFPINFO_EA_NETATALK "user." NETATALK_META_XATTR #define AFPRESOURCE_EA_NETATALK "user.org.netatalk.ResourceFork" #endif -- 2.1.0 From 43aa7ccb5e762fcdfa6b5b7f43a2a709835bacfd Mon Sep 17 00:00:00 2001 From: Ralph Boehme Date: Mon, 24 Aug 2015 17:43:40 +0200 Subject: [PATCH 2/3] vfs_fruit: hide the Netatalk metadata xattr in streaminfo Bug: https://bugzilla.samba.org/show_bug.cgi?id=11466 Signed-off-by: Ralph Boehme --- source3/modules/vfs_fruit.c | 54 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/source3/modules/vfs_fruit.c b/source3/modules/vfs_fruit.c index 548c3e3..7507cdd 100644 --- a/source3/modules/vfs_fruit.c +++ b/source3/modules/vfs_fruit.c @@ -1521,6 +1521,40 @@ static bool add_fruit_stream(TALLOC_CTX *mem_ctx, unsigned int *num_streams, 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; + int cmp; + + if (*num_streams == 0) { + return true; + } + + for (i = 0; i < *num_streams; i++) { + cmp = strcasecmp_m(tmp[i].name, name); + if (cmp != 0) { + continue; + } + break; + } + + if (cmp != 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 empty_finderinfo(const struct adouble *ad) { @@ -3056,6 +3090,7 @@ static NTSTATUS fruit_streaminfo(vfs_handle_struct *handle, 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); @@ -3104,8 +3139,23 @@ static NTSTATUS fruit_streaminfo(vfs_handle_struct *handle, TALLOC_FREE(smb_fname); - return SMB_VFS_NEXT_STREAMINFO(handle, fsp, fname, mem_ctx, - pnum_streams, pstreams); + status = SMB_VFS_NEXT_STREAMINFO(handle, fsp, fname, mem_ctx, + pnum_streams, pstreams); + if (!NT_STATUS_IS_OK(status)) { + return status; + } + + if (config->meta == FRUIT_META_NETATALK) { + /* Remove the Netatalk xattr from the list */ + if (!del_fruit_stream(mem_ctx, pnum_streams, pstreams, + ":" NETATALK_META_XATTR ":$DATA")) { + TALLOC_FREE(ad); + TALLOC_FREE(smb_fname); + return NT_STATUS_NO_MEMORY; + } + } + + return NT_STATUS_OK; } static int fruit_ntimes(vfs_handle_struct *handle, -- 2.1.0 From 85a7d178ef35a0c604b24dbf9a0c1181a736601b Mon Sep 17 00:00:00 2001 From: Ralph Boehme Date: Mon, 24 Aug 2015 17:45:14 +0200 Subject: [PATCH 3/3] vfs_streams_xattr: fix and simplify streams_xattr_get_name() streams_xattr_get_name() fails to chop of the stream type in case config->store_stream_type is false and the passed stream name contains a stream type. Eg when the passed in stream name is ":mystream:$DATA", but config->store_stream_type is false, we must generate a xattr name of "mystream" or "user.mystream". Bug: https://bugzilla.samba.org/show_bug.cgi?id=11466 Signed-off-by: Ralph Boehme --- source3/modules/vfs_streams_xattr.c | 40 ++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/source3/modules/vfs_streams_xattr.c b/source3/modules/vfs_streams_xattr.c index 92bd1c9..c9ac4ec 100644 --- a/source3/modules/vfs_streams_xattr.c +++ b/source3/modules/vfs_streams_xattr.c @@ -106,12 +106,19 @@ static NTSTATUS streams_xattr_get_name(vfs_handle_struct *handle, const char *stream_name, char **xattr_name) { + char *sname; char *stype; struct streams_xattr_config *config; SMB_VFS_HANDLE_GET_DATA(handle, config, struct streams_xattr_config, return NT_STATUS_UNSUCCESSFUL); + + sname = talloc_strdup(ctx, stream_name + 1); + if (sname == NULL) { + return NT_STATUS_NO_MEMORY; + } + /* * With vfs_fruit option "fruit:encoding = native" we're * already converting stream names that contain illegal NTFS @@ -126,41 +133,34 @@ static NTSTATUS streams_xattr_get_name(vfs_handle_struct *handle, * In check_path_syntax() we've already ensured the streamname * we got from the client is valid. */ - stype = strrchr_m(stream_name + 1, ':'); + stype = strrchr_m(sname, ':'); if (stype) { + /* + * We only support one stream type: "$DATA" + */ if (strcasecmp_m(stype, ":$DATA") != 0) { + talloc_free(sname); return NT_STATUS_INVALID_PARAMETER; } + + /* Split name and type */ + stype[0] = '\0'; } - *xattr_name = talloc_asprintf(ctx, "%s%s", + *xattr_name = talloc_asprintf(ctx, "%s%s%s", config->prefix, - stream_name + 1); + sname, + config->store_stream_type ? ":$DATA" : ""); if (*xattr_name == NULL) { + talloc_free(sname); return NT_STATUS_NO_MEMORY; } - if (stype != NULL) { - /* Normalize the stream type to upercase. */ - if (!strupper_m(strrchr_m(*xattr_name, ':') + 1)) { - return NT_STATUS_INVALID_PARAMETER; - } - } else if (config->store_stream_type) { - /* - * Append an explicit stream type if one wasn't - * specified. - */ - *xattr_name = talloc_asprintf(ctx, "%s%s", - *xattr_name, ":$DATA"); - if (*xattr_name == NULL) { - return NT_STATUS_NO_MEMORY; - } - } - DEBUG(10, ("xattr_name: %s, stream_name: %s\n", *xattr_name, stream_name)); + talloc_free(sname); return NT_STATUS_OK; } -- 2.1.0