2 Unix SMB/CIFS implementation.
3 Main metadata server / Spotlight client functions
5 Copyright (C) Ralph Boehme 2019
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "rpc_client.h"
23 #include "librpc/gen_ndr/mdssvc.h"
24 #include "cli_mdssvc.h"
25 #include "cli_mdssvc_private.h"
26 #include "cli_mdssvc_util.h"
27 #include "lib/util/tevent_ntstatus.h"
28 #include "rpc_server/mdssvc/dalloc.h"
29 #include "rpc_server/mdssvc/marshalling.h"
31 NTSTATUS
mdscli_blob_search(TALLOC_CTX
*mem_ctx
,
32 struct mdscli_search_ctx
*search
,
33 struct mdssvc_blob
*blob
)
35 struct mdscli_ctx
*ctx
= search
->mdscli_ctx
;
37 uint64_t *uint64p
= NULL
;
38 sl_array_t
*array
= NULL
;
39 sl_array_t
*cmd_array
= NULL
;
40 sl_dict_t
*query_dict
= NULL
;
41 sl_array_t
*attr_array
= NULL
;
42 sl_array_t
*scope_array
= NULL
;
48 d
= dalloc_new(mem_ctx
);
50 return NT_STATUS_NO_MEMORY
;
53 array
= dalloc_zero(d
, sl_array_t
);
56 return NT_STATUS_NO_MEMORY
;
59 ret
= dalloc_add(d
, array
, sl_array_t
);
62 return NT_STATUS_NO_MEMORY
;
65 cmd_array
= dalloc_zero(d
, sl_array_t
);
66 if (cmd_array
== NULL
) {
68 return NT_STATUS_NO_MEMORY
;
71 ret
= dalloc_add(array
, cmd_array
, sl_array_t
);
74 return NT_STATUS_NO_MEMORY
;
77 ret
= dalloc_stradd(cmd_array
, "openQueryWithParams:forContext:");
80 return NT_STATUS_NO_MEMORY
;
83 uint64p
= talloc_zero_array(cmd_array
, uint64_t, 2);
84 if (uint64p
== NULL
) {
86 return NT_STATUS_NO_MEMORY
;
89 talloc_set_name(uint64p
, "uint64_t *");
91 uint64p
[0] = search
->ctx_id
.id
;
92 uint64p
[1] = search
->ctx_id
.connection
;
94 ret
= dalloc_add(cmd_array
, uint64p
, uint64_t *);
97 return NT_STATUS_NO_MEMORY
;
100 query_dict
= dalloc_zero(array
, sl_dict_t
);
101 if (query_dict
== NULL
) {
103 return NT_STATUS_NO_MEMORY
;
106 ret
= dalloc_add(array
, query_dict
, sl_dict_t
);
109 return NT_STATUS_NO_MEMORY
;
112 ret
= dalloc_stradd(query_dict
, "kMDQueryBatchFirstDelay");
115 return NT_STATUS_NO_MEMORY
;
118 ret
= dalloc_add_copy(query_dict
, &dval
, double);
121 return NT_STATUS_NO_MEMORY
;
124 ret
= dalloc_stradd(query_dict
, "kMDQueryUniqueId");
127 return NT_STATUS_NO_MEMORY
;
129 ret
= dalloc_add_copy(query_dict
, &search
->unique_id
, uint64_t);
132 return NT_STATUS_NO_MEMORY
;
135 ret
= dalloc_stradd(query_dict
, "kMDAttributeArray");
138 return NT_STATUS_NO_MEMORY
;
140 attr_array
= dalloc_zero(query_dict
, sl_array_t
);
141 if (attr_array
== NULL
) {
143 return NT_STATUS_NO_MEMORY
;
145 ret
= dalloc_add(query_dict
, attr_array
, sl_array_t
);
148 return NT_STATUS_NO_MEMORY
;
150 ret
= dalloc_stradd(attr_array
, "kMDItemFSName");
153 return NT_STATUS_NO_MEMORY
;
156 ret
= dalloc_stradd(query_dict
, "kMDQueryBatchFirstCount");
159 return NT_STATUS_NO_MEMORY
;
162 ret
= dalloc_add_copy(query_dict
, &uint64val
, uint64_t);
165 return NT_STATUS_NO_MEMORY
;
168 ret
= dalloc_stradd(query_dict
, "kMDQueryBatchUpdateCount");
171 return NT_STATUS_NO_MEMORY
;
174 ret
= dalloc_add_copy(query_dict
, &uint64val
, uint64_t);
177 return NT_STATUS_NO_MEMORY
;
180 ret
= dalloc_stradd(query_dict
, "kMDQueryString");
183 return NT_STATUS_NO_MEMORY
;
185 ret
= dalloc_stradd(query_dict
, search
->mds_query
);
188 return NT_STATUS_NO_MEMORY
;
191 ret
= dalloc_stradd(query_dict
, "kMDScopeArray");
194 return NT_STATUS_NO_MEMORY
;
196 scope_array
= dalloc_zero(query_dict
, sl_array_t
);
197 if (scope_array
== NULL
) {
199 return NT_STATUS_NO_MEMORY
;
201 ret
= dalloc_add(query_dict
, scope_array
, sl_array_t
);
204 return NT_STATUS_NO_MEMORY
;
206 ret
= dalloc_stradd(scope_array
, search
->path_scope
);
209 return NT_STATUS_NO_MEMORY
;
212 blob
->spotlight_blob
= talloc_array(d
,
214 ctx
->max_fragment_size
);
215 if (blob
->spotlight_blob
== NULL
) {
217 return NT_STATUS_NO_MEMORY
;
219 blob
->size
= ctx
->max_fragment_size
;
221 len
= sl_pack(d
, (char *)blob
->spotlight_blob
, blob
->size
);
224 return NT_STATUS_NO_MEMORY
;
232 NTSTATUS
mdscli_blob_get_results(TALLOC_CTX
*mem_ctx
,
233 struct mdscli_search_ctx
*search
,
234 struct mdssvc_blob
*blob
)
236 struct mdscli_ctx
*ctx
= search
->mdscli_ctx
;
237 DALLOC_CTX
*d
= NULL
;
238 uint64_t *uint64p
= NULL
;
239 sl_array_t
*array
= NULL
;
240 sl_array_t
*cmd_array
= NULL
;
244 d
= dalloc_new(mem_ctx
);
246 return NT_STATUS_NO_MEMORY
;
249 array
= dalloc_zero(d
, sl_array_t
);
252 return NT_STATUS_NO_MEMORY
;
255 ret
= dalloc_add(d
, array
, sl_array_t
);
258 return NT_STATUS_NO_MEMORY
;
261 cmd_array
= dalloc_zero(d
, sl_array_t
);
262 if (cmd_array
== NULL
) {
264 return NT_STATUS_NO_MEMORY
;
267 ret
= dalloc_add(array
, cmd_array
, sl_array_t
);
270 return NT_STATUS_NO_MEMORY
;
273 ret
= dalloc_stradd(cmd_array
, "fetchQueryResultsForContext:");
276 return NT_STATUS_NO_MEMORY
;
279 uint64p
= talloc_zero_array(cmd_array
, uint64_t, 2);
280 if (uint64p
== NULL
) {
282 return NT_STATUS_NO_MEMORY
;
285 talloc_set_name(uint64p
, "uint64_t *");
287 uint64p
[0] = search
->ctx_id
.id
;
288 uint64p
[1] = search
->ctx_id
.connection
;
290 ret
= dalloc_add(cmd_array
, uint64p
, uint64_t *);
293 return NT_STATUS_NO_MEMORY
;
296 blob
->spotlight_blob
= talloc_array(d
,
298 ctx
->max_fragment_size
);
299 if (blob
->spotlight_blob
== NULL
) {
301 return NT_STATUS_NO_MEMORY
;
303 blob
->size
= ctx
->max_fragment_size
;
305 len
= sl_pack(d
, (char *)blob
->spotlight_blob
, blob
->size
);
308 return NT_STATUS_NO_MEMORY
;
316 NTSTATUS
mdscli_blob_get_path(TALLOC_CTX
*mem_ctx
,
317 struct mdscli_ctx
*ctx
,
319 struct mdssvc_blob
*blob
)
321 struct mdsctx_id ctx_id
= mdscli_new_ctx_id(ctx
);
322 DALLOC_CTX
*d
= NULL
;
323 uint64_t *uint64var
= NULL
;
324 sl_array_t
*array
= NULL
;
325 sl_array_t
*cmd_array
= NULL
;
326 sl_array_t
*attr_array
= NULL
;
327 sl_cnids_t
*cnids
= NULL
;
331 d
= dalloc_new(mem_ctx
);
333 return NT_STATUS_NO_MEMORY
;
336 array
= dalloc_zero(d
, sl_array_t
);
339 return NT_STATUS_NO_MEMORY
;
342 ret
= dalloc_add(d
, array
, sl_array_t
);
345 return NT_STATUS_NO_MEMORY
;
348 cmd_array
= dalloc_zero(d
, sl_array_t
);
349 if (cmd_array
== NULL
) {
351 return NT_STATUS_NO_MEMORY
;
354 ret
= dalloc_add(array
, cmd_array
, sl_array_t
);
357 return NT_STATUS_NO_MEMORY
;
360 ret
= dalloc_stradd(cmd_array
, "fetchAttributes:forOIDArray:context:");
363 return NT_STATUS_NO_MEMORY
;
366 uint64var
= talloc_zero_array(cmd_array
, uint64_t, 2);
367 if (uint64var
== NULL
) {
369 return NT_STATUS_NO_MEMORY
;
372 talloc_set_name(uint64var
, "uint64_t *");
374 uint64var
[0] = ctx_id
.id
;
377 ret
= dalloc_add(cmd_array
, &uint64var
[0], uint64_t *);
380 return NT_STATUS_NO_MEMORY
;
383 attr_array
= dalloc_zero(d
, sl_array_t
);
384 if (attr_array
== NULL
) {
386 return NT_STATUS_NO_MEMORY
;
389 ret
= dalloc_add(array
, attr_array
, sl_array_t
);
392 return NT_STATUS_NO_MEMORY
;
395 ret
= dalloc_stradd(attr_array
, "kMDItemPath");
398 return NT_STATUS_NO_MEMORY
;
402 cnids
= talloc_zero(array
, sl_cnids_t
);
405 return NT_STATUS_NO_MEMORY
;
408 cnids
->ca_cnids
= dalloc_new(cnids
);
409 if (cnids
->ca_cnids
== NULL
) {
411 return NT_STATUS_NO_MEMORY
;
414 cnids
->ca_unkn1
= 0xadd;
415 cnids
->ca_context
= 0x6b000020;
417 ret
= dalloc_add_copy(cnids
->ca_cnids
, &cnid
, uint64_t);
420 return NT_STATUS_NO_MEMORY
;
423 ret
= dalloc_add(array
, cnids
, sl_cnids_t
);
426 return NT_STATUS_NO_MEMORY
;
429 blob
->spotlight_blob
= talloc_array(d
,
431 ctx
->max_fragment_size
);
432 if (blob
->spotlight_blob
== NULL
) {
434 return NT_STATUS_NO_MEMORY
;
436 blob
->size
= ctx
->max_fragment_size
;
438 len
= sl_pack(d
, (char *)blob
->spotlight_blob
, blob
->size
);
441 return NT_STATUS_NO_MEMORY
;
449 NTSTATUS
mdscli_blob_close_search(TALLOC_CTX
*mem_ctx
,
450 struct mdscli_search_ctx
*search
,
451 struct mdssvc_blob
*blob
)
453 struct mdscli_ctx
*ctx
= search
->mdscli_ctx
;
454 DALLOC_CTX
*d
= NULL
;
455 uint64_t *uint64p
= NULL
;
456 sl_array_t
*array
= NULL
;
457 sl_array_t
*cmd_array
= NULL
;
461 d
= dalloc_new(mem_ctx
);
463 return NT_STATUS_NO_MEMORY
;
466 array
= dalloc_zero(d
, sl_array_t
);
469 return NT_STATUS_NO_MEMORY
;
472 ret
= dalloc_add(d
, array
, sl_array_t
);
475 return NT_STATUS_NO_MEMORY
;
478 cmd_array
= dalloc_zero(d
, sl_array_t
);
479 if (cmd_array
== NULL
) {
481 return NT_STATUS_NO_MEMORY
;
484 ret
= dalloc_add(array
, cmd_array
, sl_array_t
);
487 return NT_STATUS_NO_MEMORY
;
490 ret
= dalloc_stradd(cmd_array
, "closeQueryForContext:");
493 return NT_STATUS_NO_MEMORY
;
496 uint64p
= talloc_zero_array(cmd_array
, uint64_t, 2);
497 if (uint64p
== NULL
) {
499 return NT_STATUS_NO_MEMORY
;
502 talloc_set_name(uint64p
, "uint64_t *");
504 uint64p
[0] = search
->ctx_id
.id
;
505 uint64p
[1] = search
->ctx_id
.connection
;
507 ret
= dalloc_add(cmd_array
, uint64p
, uint64_t *);
510 return NT_STATUS_NO_MEMORY
;
513 blob
->spotlight_blob
= talloc_array(d
,
515 ctx
->max_fragment_size
);
516 if (blob
->spotlight_blob
== NULL
) {
518 return NT_STATUS_NO_MEMORY
;
520 blob
->size
= ctx
->max_fragment_size
;
522 len
= sl_pack(d
, (char *)blob
->spotlight_blob
, blob
->size
);
525 return NT_STATUS_NO_MEMORY
;