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_fetch_props(TALLOC_CTX *mem_ctx,
32 struct mdscli_ctx *ctx,
33 struct mdssvc_blob *blob)
36 uint64_t *uint64p = NULL;
37 sl_array_t *array = NULL;
38 sl_array_t *cmd_array = NULL;
42 d = dalloc_new(mem_ctx);
44 return NT_STATUS_NO_MEMORY;
47 array = dalloc_zero(d, sl_array_t);
50 return NT_STATUS_NO_MEMORY;
53 ret = dalloc_add(d, array, sl_array_t);
56 return NT_STATUS_NO_MEMORY;
59 cmd_array = dalloc_zero(d, sl_array_t);
60 if (cmd_array == NULL) {
62 return NT_STATUS_NO_MEMORY;
65 ret = dalloc_add(array, cmd_array, sl_array_t);
68 return NT_STATUS_NO_MEMORY;
71 ret = dalloc_stradd(cmd_array, "fetchPropertiesForContext:");
74 return NT_STATUS_NO_MEMORY;
77 uint64p = talloc_zero_array(cmd_array, uint64_t, 2);
78 if (uint64p == NULL) {
80 return NT_STATUS_NO_MEMORY;
83 talloc_set_name(uint64p, "uint64_t *");
85 ret = dalloc_add(cmd_array, uint64p, uint64_t *);
88 return NT_STATUS_NO_MEMORY;
91 status = sl_pack_alloc(mem_ctx, d, blob, ctx->max_fragment_size);
93 if (!NT_STATUS_IS_OK(status)) {
99 NTSTATUS mdscli_blob_search(TALLOC_CTX *mem_ctx,
100 struct mdscli_search_ctx *search,
101 struct mdssvc_blob *blob)
103 struct mdscli_ctx *ctx = search->mdscli_ctx;
104 DALLOC_CTX *d = NULL;
105 uint64_t *uint64p = NULL;
106 sl_array_t *array = NULL;
107 sl_array_t *cmd_array = NULL;
108 sl_dict_t *query_dict = NULL;
109 sl_array_t *attr_array = NULL;
110 sl_array_t *scope_array = NULL;
116 d = dalloc_new(mem_ctx);
118 return NT_STATUS_NO_MEMORY;
121 array = dalloc_zero(d, sl_array_t);
124 return NT_STATUS_NO_MEMORY;
127 ret = dalloc_add(d, array, sl_array_t);
130 return NT_STATUS_NO_MEMORY;
133 cmd_array = dalloc_zero(d, sl_array_t);
134 if (cmd_array == NULL) {
136 return NT_STATUS_NO_MEMORY;
139 ret = dalloc_add(array, cmd_array, sl_array_t);
142 return NT_STATUS_NO_MEMORY;
145 ret = dalloc_stradd(cmd_array, "openQueryWithParams:forContext:");
148 return NT_STATUS_NO_MEMORY;
151 uint64p = talloc_zero_array(cmd_array, uint64_t, 2);
152 if (uint64p == NULL) {
154 return NT_STATUS_NO_MEMORY;
157 talloc_set_name(uint64p, "uint64_t *");
159 uint64p[0] = search->ctx_id.id;
160 uint64p[1] = search->ctx_id.connection;
162 ret = dalloc_add(cmd_array, uint64p, uint64_t *);
165 return NT_STATUS_NO_MEMORY;
168 query_dict = dalloc_zero(array, sl_dict_t);
169 if (query_dict == NULL) {
171 return NT_STATUS_NO_MEMORY;
174 ret = dalloc_add(array, query_dict, sl_dict_t);
177 return NT_STATUS_NO_MEMORY;
180 ret = dalloc_stradd(query_dict, "kMDQueryBatchFirstDelay");
183 return NT_STATUS_NO_MEMORY;
186 ret = dalloc_add_copy(query_dict, &dval, double);
189 return NT_STATUS_NO_MEMORY;
192 ret = dalloc_stradd(query_dict, "kMDQueryUniqueId");
195 return NT_STATUS_NO_MEMORY;
197 ret = dalloc_add_copy(query_dict, &search->unique_id, uint64_t);
200 return NT_STATUS_NO_MEMORY;
203 ret = dalloc_stradd(query_dict, "kMDAttributeArray");
206 return NT_STATUS_NO_MEMORY;
208 attr_array = dalloc_zero(query_dict, sl_array_t);
209 if (attr_array == NULL) {
211 return NT_STATUS_NO_MEMORY;
213 ret = dalloc_add(query_dict, attr_array, sl_array_t);
216 return NT_STATUS_NO_MEMORY;
218 ret = dalloc_stradd(attr_array, "kMDItemFSName");
221 return NT_STATUS_NO_MEMORY;
224 ret = dalloc_stradd(query_dict, "kMDQueryBatchFirstCount");
227 return NT_STATUS_NO_MEMORY;
230 ret = dalloc_add_copy(query_dict, &uint64val, uint64_t);
233 return NT_STATUS_NO_MEMORY;
236 ret = dalloc_stradd(query_dict, "kMDQueryBatchUpdateCount");
239 return NT_STATUS_NO_MEMORY;
242 ret = dalloc_add_copy(query_dict, &uint64val, uint64_t);
245 return NT_STATUS_NO_MEMORY;
248 ret = dalloc_stradd(query_dict, "kMDQueryString");
251 return NT_STATUS_NO_MEMORY;
253 ret = dalloc_stradd(query_dict, search->mds_query);
256 return NT_STATUS_NO_MEMORY;
259 ret = dalloc_stradd(query_dict, "kMDScopeArray");
262 return NT_STATUS_NO_MEMORY;
264 scope_array = dalloc_zero(query_dict, sl_array_t);
265 if (scope_array == NULL) {
267 return NT_STATUS_NO_MEMORY;
269 ret = dalloc_add(query_dict, scope_array, sl_array_t);
272 return NT_STATUS_NO_MEMORY;
274 ret = dalloc_stradd(scope_array, search->path_scope);
277 return NT_STATUS_NO_MEMORY;
280 status = sl_pack_alloc(mem_ctx, d, blob, ctx->max_fragment_size);
282 if (!NT_STATUS_IS_OK(status)) {
288 NTSTATUS mdscli_blob_get_results(TALLOC_CTX *mem_ctx,
289 struct mdscli_search_ctx *search,
290 struct mdssvc_blob *blob)
292 struct mdscli_ctx *ctx = search->mdscli_ctx;
293 DALLOC_CTX *d = NULL;
294 uint64_t *uint64p = NULL;
295 sl_array_t *array = NULL;
296 sl_array_t *cmd_array = NULL;
300 d = dalloc_new(mem_ctx);
302 return NT_STATUS_NO_MEMORY;
305 array = dalloc_zero(d, sl_array_t);
308 return NT_STATUS_NO_MEMORY;
311 ret = dalloc_add(d, array, sl_array_t);
314 return NT_STATUS_NO_MEMORY;
317 cmd_array = dalloc_zero(d, sl_array_t);
318 if (cmd_array == NULL) {
320 return NT_STATUS_NO_MEMORY;
323 ret = dalloc_add(array, cmd_array, sl_array_t);
326 return NT_STATUS_NO_MEMORY;
329 ret = dalloc_stradd(cmd_array, "fetchQueryResultsForContext:");
332 return NT_STATUS_NO_MEMORY;
335 uint64p = talloc_zero_array(cmd_array, uint64_t, 2);
336 if (uint64p == NULL) {
338 return NT_STATUS_NO_MEMORY;
341 talloc_set_name(uint64p, "uint64_t *");
343 uint64p[0] = search->ctx_id.id;
344 uint64p[1] = search->ctx_id.connection;
346 ret = dalloc_add(cmd_array, uint64p, uint64_t *);
349 return NT_STATUS_NO_MEMORY;
352 status = sl_pack_alloc(mem_ctx, d, blob, ctx->max_fragment_size);
354 if (!NT_STATUS_IS_OK(status)) {
360 NTSTATUS mdscli_blob_get_path(TALLOC_CTX *mem_ctx,
361 struct mdscli_ctx *ctx,
363 struct mdssvc_blob *blob)
365 struct mdsctx_id ctx_id = mdscli_new_ctx_id(ctx);
366 DALLOC_CTX *d = NULL;
367 uint64_t *uint64var = NULL;
368 sl_array_t *array = NULL;
369 sl_array_t *cmd_array = NULL;
370 sl_array_t *attr_array = NULL;
371 sl_cnids_t *cnids = NULL;
375 d = dalloc_new(mem_ctx);
377 return NT_STATUS_NO_MEMORY;
380 array = dalloc_zero(d, sl_array_t);
383 return NT_STATUS_NO_MEMORY;
386 ret = dalloc_add(d, array, sl_array_t);
389 return NT_STATUS_NO_MEMORY;
392 cmd_array = dalloc_zero(d, sl_array_t);
393 if (cmd_array == NULL) {
395 return NT_STATUS_NO_MEMORY;
398 ret = dalloc_add(array, cmd_array, sl_array_t);
401 return NT_STATUS_NO_MEMORY;
404 ret = dalloc_stradd(cmd_array, "fetchAttributes:forOIDArray:context:");
407 return NT_STATUS_NO_MEMORY;
410 uint64var = talloc_zero_array(cmd_array, uint64_t, 2);
411 if (uint64var == NULL) {
413 return NT_STATUS_NO_MEMORY;
416 talloc_set_name(uint64var, "uint64_t *");
418 uint64var[0] = ctx_id.id;
421 ret = dalloc_add(cmd_array, &uint64var[0], uint64_t *);
424 return NT_STATUS_NO_MEMORY;
427 attr_array = dalloc_zero(d, sl_array_t);
428 if (attr_array == NULL) {
430 return NT_STATUS_NO_MEMORY;
433 ret = dalloc_add(array, attr_array, sl_array_t);
436 return NT_STATUS_NO_MEMORY;
439 ret = dalloc_stradd(attr_array, "kMDItemPath");
442 return NT_STATUS_NO_MEMORY;
446 cnids = talloc_zero(array, sl_cnids_t);
449 return NT_STATUS_NO_MEMORY;
452 cnids->ca_cnids = dalloc_new(cnids);
453 if (cnids->ca_cnids == NULL) {
455 return NT_STATUS_NO_MEMORY;
458 cnids->ca_unkn1 = 0xadd;
459 cnids->ca_context = 0x6b000020;
461 ret = dalloc_add_copy(cnids->ca_cnids, &cnid, uint64_t);
464 return NT_STATUS_NO_MEMORY;
467 ret = dalloc_add(array, cnids, sl_cnids_t);
470 return NT_STATUS_NO_MEMORY;
473 status = sl_pack_alloc(mem_ctx, d, blob, ctx->max_fragment_size);
475 if (!NT_STATUS_IS_OK(status)) {
481 NTSTATUS mdscli_blob_close_search(TALLOC_CTX *mem_ctx,
482 struct mdscli_search_ctx *search,
483 struct mdssvc_blob *blob)
485 struct mdscli_ctx *ctx = search->mdscli_ctx;
486 DALLOC_CTX *d = NULL;
487 uint64_t *uint64p = NULL;
488 sl_array_t *array = NULL;
489 sl_array_t *cmd_array = NULL;
493 d = dalloc_new(mem_ctx);
495 return NT_STATUS_NO_MEMORY;
498 array = dalloc_zero(d, sl_array_t);
501 return NT_STATUS_NO_MEMORY;
504 ret = dalloc_add(d, array, sl_array_t);
507 return NT_STATUS_NO_MEMORY;
510 cmd_array = dalloc_zero(d, sl_array_t);
511 if (cmd_array == NULL) {
513 return NT_STATUS_NO_MEMORY;
516 ret = dalloc_add(array, cmd_array, sl_array_t);
519 return NT_STATUS_NO_MEMORY;
522 ret = dalloc_stradd(cmd_array, "closeQueryForContext:");
525 return NT_STATUS_NO_MEMORY;
528 uint64p = talloc_zero_array(cmd_array, uint64_t, 2);
529 if (uint64p == NULL) {
531 return NT_STATUS_NO_MEMORY;
534 talloc_set_name(uint64p, "uint64_t *");
536 uint64p[0] = search->ctx_id.id;
537 uint64p[1] = search->ctx_id.connection;
539 ret = dalloc_add(cmd_array, uint64p, uint64_t *);
542 return NT_STATUS_NO_MEMORY;
545 status = sl_pack_alloc(mem_ctx, d, blob, ctx->max_fragment_size);
547 if (!NT_STATUS_IS_OK(status)) {