s3/rpc_server: Character Encode Spotlight Queries
authorRalph Boehme <slow@samba.org>
Wed, 15 Mar 2017 12:38:19 +0000 (13:38 +0100)
committerJeremy Allison <jra@samba.org>
Tue, 10 Jul 2018 21:17:20 +0000 (23:17 +0200)
Fix path escaping in Spotlight so paths with spaces or special
characters can be properly matched to tracker paths.

Bug: https://bugzilla.samba.org/show_bug.cgi?id=12688

Based-on-a-patch-from: Mike M Pestorich <mmpestorich@gmail.com>
(similar to github.com/netatalk/netatalk/commit/90aa43d)

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): Tue Jul 10 23:17:20 CEST 2018 on sn-devel-144

source3/rpc_server/mdssvc/mdssvc.c

index 9be0cc488776cb535dca3242292dd6931751cb84..5a63d3797388ce95c4ba2f7536f655258e1c8660 100644 (file)
@@ -1136,6 +1136,8 @@ static bool slrpc_open_query(struct mds_ctx *mds_ctx,
        struct sl_query *slq = NULL;
        int result;
        char *querystring;
+       char *scope = NULL;
+       char *escaped_scope = NULL;
 
        array = dalloc_zero(reply, sl_array_t);
        if (array == NULL) {
@@ -1214,12 +1216,20 @@ static bool slrpc_open_query(struct mds_ctx *mds_ctx,
                goto error;
        }
 
-       slq->path_scope = dalloc_get(path_scope, "char *", 0);
-       if (slq->path_scope == NULL) {
+       scope = dalloc_get(path_scope, "char *", 0);
+       if (scope == NULL) {
+               goto error;
+       }
+
+       escaped_scope = g_uri_escape_string(scope,
+                                           G_URI_RESERVED_CHARS_ALLOWED_IN_PATH,
+                                           TRUE);
+       if (escaped_scope == NULL) {
                goto error;
        }
 
-       slq->path_scope = talloc_strdup(slq, slq->path_scope);
+       slq->path_scope = talloc_strdup(slq, escaped_scope);
+       g_free(escaped_scope);
        if (slq->path_scope == NULL) {
                goto error;
        }