[PATCH] Spotlight RPC service: simple fix for handling of spaces search queries

Ralph Böhme slow at samba.org
Tue Jan 9 10:32:40 UTC 2018


Hi!

Attached is a simple fix for bug 12688.

Please review & push if happy. Thanks!

-slow

-- 
Ralph Boehme, Samba Team       https://samba.org/
Samba Developer, SerNet GmbH   https://sernet.de/en/samba/
-------------- next part --------------
From 0c4a0cdff00d75d88b456d4cfc309f97aedaba9a Mon Sep 17 00:00:00 2001
From: Ralph Boehme <slow at samba.org>
Date: Wed, 15 Mar 2017 13:38:19 +0100
Subject: [PATCH] s3/rpc_server: Character Encode Spotlight Queries

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 at gmail.com>
(similar to github.com/netatalk/netatalk/commit/90aa43d)

Signed-off-by: Ralph Boehme <slow at samba.org>
---
 source3/rpc_server/mdssvc/mdssvc.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/source3/rpc_server/mdssvc/mdssvc.c b/source3/rpc_server/mdssvc/mdssvc.c
index 9be0cc48877..5a63d379738 100644
--- a/source3/rpc_server/mdssvc/mdssvc.c
+++ b/source3/rpc_server/mdssvc/mdssvc.c
@@ -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;
 	}
-- 
2.13.6



More information about the samba-technical mailing list