From 0e5fb20c1dcc4fcac9db77cb96be67631c362f51 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 Reviewed-by: Jeremy Allison (cherry picked from commit c8ee1a059b4484575b03ac76b469df85cdabdd9a) --- 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 17da629..81a5e6a 100644 --- a/source3/modules/vfs_fruit.c +++ b/source3/modules/vfs_fruit.c @@ -103,11 +103,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.5.0 From b7223e60145efd234b0f51b761d9eb126921a828 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 Reviewed-by: Jeremy Allison (cherry picked from commit fedd09662c889fb796135d86836c160171fac68d) --- source3/modules/vfs_fruit.c | 51 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/source3/modules/vfs_fruit.c b/source3/modules/vfs_fruit.c index 81a5e6a..8e24791 100644 --- a/source3/modules/vfs_fruit.c +++ b/source3/modules/vfs_fruit.c @@ -1531,6 +1531,37 @@ 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; + + if (*num_streams == 0) { + return true; + } + + for (i = 0; i < *num_streams; i++) { + if (strequal_m(tmp[i].name, name)) { + break; + } + } + + if (i == *num_streams) { + return true; + } + + TALLOC_FREE(tmp[i].name); + if (*num_streams - 1 > i) { + memmove(&tmp[i], &tmp[i+1], + (*num_streams - i - 1) * sizeof(struct stream_struct)); + } + + *num_streams -= 1; + return true; +} + static bool empty_finderinfo(const struct adouble *ad) { @@ -3107,6 +3138,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); @@ -3155,8 +3187,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.5.0 From 9a9b87e22263ffc4b2041cbd12daa08ad305c0aa 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 off 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 Reviewed-by: Jeremy Allison Autobuild-User(master): Jeremy Allison Autobuild-Date(master): Fri Oct 16 23:27:01 CEST 2015 on sn-devel-104 (cherry picked from commit 2881679e3ecbaf07cdd82ba65af8d55e5e3be800) --- source3/modules/vfs_streams_xattr.c | 39 ++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/source3/modules/vfs_streams_xattr.c b/source3/modules/vfs_streams_xattr.c index 5277741..7ef4279 100644 --- a/source3/modules/vfs_streams_xattr.c +++ b/source3/modules/vfs_streams_xattr.c @@ -106,12 +106,18 @@ 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 +132,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.5.0