vfs_streams_xattr: fix and simplify streams_xattr_get_name()
authorRalph Boehme <slow@samba.org>
Mon, 24 Aug 2015 15:45:14 +0000 (17:45 +0200)
committerKarolin Seeger <kseeger@samba.org>
Wed, 6 Jan 2016 09:06:29 +0000 (10:06 +0100)
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 <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
Autobuild-User(master): Jeremy Allison <jra@samba.org>
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

index 92bd1c9bce75979dc2715cde21da1533a1f3fd56..b54809f134e50afea074f6a660f42ee35412a9f8 100644 (file)
@@ -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;
 }