From 20d38a91e38805cf0460db23b33dfe55ca87f6b1 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Mon, 1 Jun 2015 12:16:45 +0200 Subject: [PATCH] ... stream_depot_sort_streams... BUG #11303 --- source3/modules/vfs_streams_depot.c | 44 +++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/source3/modules/vfs_streams_depot.c b/source3/modules/vfs_streams_depot.c index 5964852..aec1c6c 100644 --- a/source3/modules/vfs_streams_depot.c +++ b/source3/modules/vfs_streams_depot.c @@ -838,6 +838,48 @@ static bool collect_one_stream(const char *dirname, return ret; } +static int stream_depot_sort_streams(struct stream_struct *s1, + struct stream_struct *s2) +{ + size_t len1 = (s1->name != NULL) ? strlen(s1->name): 0; + size_t len2 = (s2->name != NULL) ? strlen(s2->name): 0; + char _n1[len1+3]; + char _n2[len2+3]; + char *n1 = _n1; + char *n2 = _n2; + char *p; + + memset(_n1, 0, len1+3); + memset(_n2, 0, len2+3); + +//::$DATA '' +//:stream:$DATA 'stream' + + if (s1->name != NULL) { + memcpy(_n1, s1->name, len1); + if (n1[0] == ':') { + n1++; + } + p = strchr_m(n1, ':'); + if (p != NULL) { + p[0] = '\0'; + } + } + + if (s2->name != NULL) { + memcpy(_n2, s2->name, len2); + if (n2[0] == ':') { + n2++; + } + p = strchr_m(n2, ':'); + if (p != NULL) { + p[0] = '\0'; + } + } + + return strcasecmp_m(n1, n2); +} + static NTSTATUS streams_depot_streaminfo(vfs_handle_struct *handle, struct files_struct *fsp, const char *fname, @@ -906,6 +948,8 @@ static NTSTATUS streams_depot_streaminfo(vfs_handle_struct *handle, *pstreams = state.streams; status = SMB_VFS_NEXT_STREAMINFO(handle, fsp, fname, mem_ctx, pnum_streams, pstreams); + TYPESAFE_QSORT(*pstreams, *pnum_streams, stream_depot_sort_streams); + out: TALLOC_FREE(smb_fname_base); return status; -- 2.1.0