lib: talloc: Test suite for the new destructor reparent logic.
[Samba.git] / source3 / rpcclient / cmd_fss.c
blob972fe9dbd4b6792b00e6df0c9db90e690943796e
1 /*
2 * Unix SMB/CIFS implementation.
4 * File Server Remote VSS Protocol (FSRVP) client
6 * Copyright (C) David Disseldorp 2012
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "includes.h"
23 #include "rpcclient.h"
24 #include "../librpc/gen_ndr/ndr_fsrvp.h"
25 #include "../librpc/gen_ndr/ndr_fsrvp_c.h"
27 struct fss_context_map {
28 uint32_t ctx_val;
29 const char *ctx_str;
30 const char *ctx_desc;
32 struct fss_context_map ctx_map[] = {
34 .ctx_val = FSRVP_CTX_BACKUP,
35 .ctx_str = "backup",
36 .ctx_desc = "auto-release, non-persistent shadow-copy.",
39 .ctx_val = FSRVP_CTX_FILE_SHARE_BACKUP,
40 .ctx_str = "file_share_backup",
41 .ctx_desc = "auto-release, non-persistent shadow-copy created "
42 "without writer involvement.",
45 .ctx_val = FSRVP_CTX_NAS_ROLLBACK,
46 .ctx_str = "nas_rollback",
47 .ctx_desc = "non-auto-release, persistent shadow-copy created "
48 "without writer involvement.",
51 .ctx_val = FSRVP_CTX_APP_ROLLBACK,
52 .ctx_str = "app_rollback",
53 .ctx_desc = "non-auto-release, persistent shadow-copy.",
55 { 0, NULL, NULL },
58 static bool map_fss_ctx_str(const char *ctx_str,
59 uint32_t *ctx_val)
61 int i;
63 for (i = 0; ctx_map[i].ctx_str != NULL; i++) {
64 if (!strcmp(ctx_map[i].ctx_str, ctx_str)) {
65 *ctx_val = ctx_map[i].ctx_val;
66 return true;
69 return false;
72 static void cmd_fss_is_path_sup_usage(const char *script_name)
74 printf("usage: %s [share_name]\n", script_name);
77 static NTSTATUS cmd_fss_is_path_sup(struct rpc_pipe_client *cli,
78 TALLOC_CTX *mem_ctx, int argc,
79 const char **argv)
81 NTSTATUS status;
82 struct fss_IsPathSupported r;
83 struct dcerpc_binding_handle *b = cli->binding_handle;
85 if (argc != 2) {
86 cmd_fss_is_path_sup_usage(argv[0]);
87 return NT_STATUS_UNSUCCESSFUL;
90 ZERO_STRUCT(r);
91 r.in.ShareName = talloc_asprintf(mem_ctx, "%s\\%s\\",
92 cli->srv_name_slash, argv[1]);
93 if (r.in.ShareName == NULL) {
94 return NT_STATUS_NO_MEMORY;
97 status = dcerpc_fss_IsPathSupported_r(b, mem_ctx, &r);
98 if (!NT_STATUS_IS_OK(status)) {
99 DEBUG(0, ("IsPathSupported failed with UNC %s\n",
100 r.in.ShareName));
101 return NT_STATUS_UNSUCCESSFUL;
102 } else if (r.out.result) {
103 DEBUG(0, ("failed IsPathSupported response: 0x%x\n",
104 r.out.result));
105 return NT_STATUS_UNSUCCESSFUL;
107 printf("UNC %s %s shadow copy requests\n", r.in.ShareName,
108 *r.out.SupportedByThisProvider ? "supports" : "does not support");
110 return NT_STATUS_OK;
113 static void cmd_fss_get_sup_version_usage(const char *script_name)
115 printf("usage: %s\n", script_name);
118 static NTSTATUS cmd_fss_get_sup_version(struct rpc_pipe_client *cli,
119 TALLOC_CTX *mem_ctx, int argc,
120 const char **argv)
122 NTSTATUS status;
123 struct fss_GetSupportedVersion r;
124 struct dcerpc_binding_handle *b = cli->binding_handle;
126 if (argc != 1) {
127 cmd_fss_get_sup_version_usage(argv[0]);
128 return NT_STATUS_UNSUCCESSFUL;
131 ZERO_STRUCT(r);
132 status = dcerpc_fss_GetSupportedVersion_r(b, mem_ctx, &r);
133 if (!NT_STATUS_IS_OK(status) || (r.out.result != 0)) {
134 DEBUG(0, ("GetSupportedVersion failed: %s result: 0x%x\n",
135 nt_errstr(status), r.out.result));
136 return NT_STATUS_UNSUCCESSFUL;
138 printf("server %s supports FSRVP versions from %u to %u\n",
139 cli->desthost, *r.out.MinVersion, *r.out.MaxVersion);
141 return NT_STATUS_OK;
144 static void cmd_fss_create_expose_usage(const char *script_name)
146 int i;
148 printf("usage: %s [fss_context] [ro|rw] [share1] <share2> ...\n"
149 "[fss_context] values:\n", script_name);
150 for (i = 0; ctx_map[i].ctx_str != NULL; i++) {
151 printf("\t%s: %s\n", ctx_map[i].ctx_str, ctx_map[i].ctx_desc);
155 static NTSTATUS cmd_fss_create_expose_parse(TALLOC_CTX *mem_ctx, int argc,
156 const char **argv,
157 const char *desthost,
158 uint32_t *fss_ctx_val,
159 int *num_maps,
160 struct fssagent_share_mapping_1 **maps)
162 int num_non_share_args = 3;
163 int num_share_args;
164 int i;
165 struct fssagent_share_mapping_1 *map_array;
167 if (argc < 4) {
168 return NT_STATUS_INVALID_PARAMETER;
171 if (!map_fss_ctx_str(argv[1], fss_ctx_val)) {
172 return NT_STATUS_INVALID_PARAMETER;
175 if (!strcmp(argv[2], "rw")) {
176 /* shadow-copy is created as read-write */
177 *fss_ctx_val |= ATTR_AUTO_RECOVERY;
178 } else if (strcmp(argv[2], "ro")) {
179 return NT_STATUS_INVALID_PARAMETER;
182 num_share_args = argc - num_non_share_args;
183 map_array = talloc_array(mem_ctx, struct fssagent_share_mapping_1,
184 num_share_args);
185 if (map_array == NULL) {
186 return NT_STATUS_NO_MEMORY;
189 for (i = 0; i < num_share_args; i++) {
191 * A trailing slash should to be present in the request UNC,
192 * otherwise Windows Server 2012 FSRVP servers don't append
193 * a '$' to exposed hidden share shadow-copies. E.g.
194 * AddToShadowCopySet(UNC=\\server\hidden$)
195 * CommitShadowCopySet()
196 * ExposeShadowCopySet()
197 * -> new share = \\server\hidden$@{ShadowCopy.ShadowCopyId}
198 * But...
199 * AddToShadowCopySet(UNC=\\server\hidden$\)
200 * CommitShadowCopySet()
201 * ExposeShadowCopySet()
202 * -> new share = \\server\hidden$@{ShadowCopy.ShadowCopyId}$
204 map_array[i].ShareNameUNC = talloc_asprintf(mem_ctx,
205 "\\\\%s\\%s\\",
206 desthost,
207 argv[i + num_non_share_args]);
208 if (map_array[i].ShareNameUNC == NULL) {
209 return NT_STATUS_NO_MEMORY;
212 *num_maps = num_share_args;
213 *maps = map_array;
215 return NT_STATUS_OK;
218 static NTSTATUS cmd_fss_abort(TALLOC_CTX *mem_ctx,
219 struct dcerpc_binding_handle *b,
220 struct GUID *sc_set_id)
222 NTSTATUS status;
223 struct fss_AbortShadowCopySet r_scset_abort;
225 ZERO_STRUCT(r_scset_abort);
226 r_scset_abort.in.ShadowCopySetId = *sc_set_id;
227 status = dcerpc_fss_AbortShadowCopySet_r(b, mem_ctx, &r_scset_abort);
228 if (!NT_STATUS_IS_OK(status) || (r_scset_abort.out.result != 0)) {
229 DEBUG(0, ("AbortShadowCopySet failed: %s result: 0x%x\n",
230 nt_errstr(status), r_scset_abort.out.result));
231 return NT_STATUS_UNSUCCESSFUL;
233 return NT_STATUS_OK;
236 static NTSTATUS cmd_fss_create_expose(struct rpc_pipe_client *cli,
237 TALLOC_CTX *mem_ctx, int argc,
238 const char **argv)
240 NTSTATUS status;
241 struct fss_GetSupportedVersion r_version_get;
242 struct fss_SetContext r_context_set;
243 struct fss_StartShadowCopySet r_scset_start;
244 struct fss_PrepareShadowCopySet r_scset_prep;
245 struct fss_CommitShadowCopySet r_scset_commit;
246 struct fss_ExposeShadowCopySet r_scset_expose;
247 struct dcerpc_binding_handle *b = cli->binding_handle;
248 time_t start_time;
249 TALLOC_CTX *tmp_ctx;
250 uint32_t fss_ctx_val;
251 int num_maps;
252 struct fssagent_share_mapping_1 *req_maps;
253 int i;
255 tmp_ctx = talloc_new(mem_ctx);
256 if (tmp_ctx == NULL) {
257 return NT_STATUS_NO_MEMORY;
260 status = cmd_fss_create_expose_parse(tmp_ctx, argc, argv, cli->desthost,
261 &fss_ctx_val, &num_maps, &req_maps);
262 if (!NT_STATUS_IS_OK(status)) {
263 cmd_fss_create_expose_usage(argv[0]);
264 goto err_out;
268 * PrepareShadowCopySet & CommitShadowCopySet often exceed the default
269 * 60 second dcerpc request timeout against Windows Server "8" Beta.
270 * ACHTUNG! dcerpc_binding_handle_set_timeout() value is interpreted as
271 * seconds on a source4 transport and as msecs here.
273 dcerpc_binding_handle_set_timeout(b, 240 * 1000);
275 for (i = 0; i < num_maps; i++) {
276 struct fss_IsPathSupported r_pathsupport_get;
277 r_pathsupport_get.in.ShareName = req_maps[i].ShareNameUNC;
278 status = dcerpc_fss_IsPathSupported_r(b, tmp_ctx, &r_pathsupport_get);
279 if (!NT_STATUS_IS_OK(status) || (r_pathsupport_get.out.result != 0)) {
280 DEBUG(0, ("IsPathSupported failed: %s result: 0x%x\n",
281 nt_errstr(status), r_pathsupport_get.out.result));
282 goto err_out;
284 if (!r_pathsupport_get.out.SupportedByThisProvider) {
285 printf("path %s does not supported shadow-copies\n",
286 req_maps[i].ShareNameUNC);
287 status = NT_STATUS_NOT_SUPPORTED;
288 goto err_out;
292 ZERO_STRUCT(r_version_get);
293 status = dcerpc_fss_GetSupportedVersion_r(b, tmp_ctx, &r_version_get);
294 if (!NT_STATUS_IS_OK(status) || (r_version_get.out.result != 0)) {
295 DEBUG(0, ("GetSupportedVersion failed: %s result: 0x%x\n",
296 nt_errstr(status), r_version_get.out.result));
297 goto err_out;
300 ZERO_STRUCT(r_context_set);
301 r_context_set.in.Context = fss_ctx_val;
302 status = dcerpc_fss_SetContext_r(b, tmp_ctx, &r_context_set);
303 if (!NT_STATUS_IS_OK(status) || (r_context_set.out.result != 0)) {
304 DEBUG(0, ("SetContext failed: %s result: 0x%x\n",
305 nt_errstr(status), r_context_set.out.result));
306 goto err_out;
309 ZERO_STRUCT(r_scset_start);
310 r_scset_start.in.ClientShadowCopySetId = GUID_random();
311 status = dcerpc_fss_StartShadowCopySet_r(b, tmp_ctx, &r_scset_start);
312 if (!NT_STATUS_IS_OK(status) || (r_scset_start.out.result != 0)) {
313 DEBUG(0, ("StartShadowCopySet failed: %s result: 0x%x\n",
314 nt_errstr(status), r_scset_start.out.result));
315 goto err_out;
317 printf("%s: shadow-copy set created\n",
318 GUID_string(tmp_ctx, r_scset_start.out.pShadowCopySetId));
320 for (i = 0; i < num_maps; i++) {
321 struct fss_AddToShadowCopySet r_scset_add;
322 r_scset_add.in.ClientShadowCopyId = GUID_random();
323 r_scset_add.in.ShadowCopySetId = *r_scset_start.out.pShadowCopySetId;
324 r_scset_add.in.ShareName = req_maps[i].ShareNameUNC;
325 status = dcerpc_fss_AddToShadowCopySet_r(b, tmp_ctx, &r_scset_add);
326 if (!NT_STATUS_IS_OK(status) || (r_scset_add.out.result != 0)) {
327 DEBUG(0, ("AddToShadowCopySet failed: %s result: 0x%x\n",
328 nt_errstr(status), r_scset_add.out.result));
329 goto err_sc_set_abort;
331 printf("%s(%s): %s shadow-copy added to set\n",
332 GUID_string(tmp_ctx, r_scset_start.out.pShadowCopySetId),
333 GUID_string(tmp_ctx, r_scset_add.out.pShadowCopyId),
334 r_scset_add.in.ShareName);
335 req_maps[i].ShadowCopySetId = *r_scset_start.out.pShadowCopySetId;
336 req_maps[i].ShadowCopyId = *r_scset_add.out.pShadowCopyId;
339 start_time = time_mono(NULL);
340 ZERO_STRUCT(r_scset_prep);
341 r_scset_prep.in.ShadowCopySetId = *r_scset_start.out.pShadowCopySetId;
342 r_scset_prep.in.TimeOutInMilliseconds = (240 * 1000);
343 status = dcerpc_fss_PrepareShadowCopySet_r(b, tmp_ctx, &r_scset_prep);
344 if (!NT_STATUS_IS_OK(status) || (r_scset_prep.out.result != 0)) {
345 DEBUG(0, ("PrepareShadowCopySet failed: %s result: 0x%x\n",
346 nt_errstr(status), r_scset_prep.out.result));
347 goto err_sc_set_abort;
349 printf("%s: prepare completed in %llu secs\n",
350 GUID_string(tmp_ctx, r_scset_start.out.pShadowCopySetId),
351 (long long unsigned int)(time_mono(NULL) - start_time));
353 start_time = time_mono(NULL);
354 ZERO_STRUCT(r_scset_commit);
355 r_scset_commit.in.ShadowCopySetId = *r_scset_start.out.pShadowCopySetId;
356 r_scset_commit.in.TimeOutInMilliseconds = (180 * 1000); /* win8 */
357 status = dcerpc_fss_CommitShadowCopySet_r(b, tmp_ctx, &r_scset_commit);
358 if (!NT_STATUS_IS_OK(status) || (r_scset_commit.out.result != 0)) {
359 DEBUG(0, ("CommitShadowCopySet failed: %s result: 0x%x\n",
360 nt_errstr(status), r_scset_commit.out.result));
361 goto err_sc_set_abort;
363 printf("%s: commit completed in %llu secs\n",
364 GUID_string(tmp_ctx, r_scset_start.out.pShadowCopySetId),
365 (long long unsigned int)(time_mono(NULL) - start_time));
367 ZERO_STRUCT(r_scset_expose);
368 r_scset_expose.in.ShadowCopySetId = *r_scset_start.out.pShadowCopySetId;
369 r_scset_expose.in.TimeOutInMilliseconds = (120 * 1000); /* win8 */
370 status = dcerpc_fss_ExposeShadowCopySet_r(b, tmp_ctx, &r_scset_expose);
371 if (!NT_STATUS_IS_OK(status) || (r_scset_expose.out.result != 0)) {
372 DEBUG(0, ("ExposeShadowCopySet failed: %s result: 0x%x\n",
373 nt_errstr(status), r_scset_expose.out.result));
374 goto err_out;
377 for (i = 0; i < num_maps; i++) {
378 struct fss_GetShareMapping r_sharemap_get;
379 struct fssagent_share_mapping_1 *map;
380 r_sharemap_get.in.ShadowCopyId = req_maps[i].ShadowCopyId;
381 r_sharemap_get.in.ShadowCopySetId = req_maps[i].ShadowCopySetId;
382 r_sharemap_get.in.ShareName = req_maps[i].ShareNameUNC;
383 r_sharemap_get.in.Level = 1;
384 status = dcerpc_fss_GetShareMapping_r(b, tmp_ctx, &r_sharemap_get);
385 if (!NT_STATUS_IS_OK(status) || (r_sharemap_get.out.result != 0)) {
386 DEBUG(0, ("GetShareMapping failed: %s result: 0x%x\n",
387 nt_errstr(status), r_sharemap_get.out.result));
388 goto err_out;
390 map = r_sharemap_get.out.ShareMapping->ShareMapping1;
391 printf("%s(%s): share %s exposed as a snapshot of %s\n",
392 GUID_string(tmp_ctx, &map->ShadowCopySetId),
393 GUID_string(tmp_ctx, &map->ShadowCopyId),
394 map->ShadowCopyShareName, map->ShareNameUNC);
397 talloc_free(tmp_ctx);
398 return NT_STATUS_OK;
400 err_sc_set_abort:
401 cmd_fss_abort(tmp_ctx, b, r_scset_start.out.pShadowCopySetId);
402 err_out:
403 talloc_free(tmp_ctx);
404 return status;
407 static void cmd_fss_delete_usage(const char *script_name)
409 printf("usage: %s [base_share] [shadow_copy_set_id] [shadow_copy_id]\n",
410 script_name);
413 static NTSTATUS cmd_fss_delete(struct rpc_pipe_client *cli,
414 TALLOC_CTX *mem_ctx, int argc,
415 const char **argv)
417 struct dcerpc_binding_handle *b = cli->binding_handle;
418 struct fss_DeleteShareMapping r_sharemap_del;
419 const char *sc_set_id;
420 const char *sc_id;
421 NTSTATUS status;
422 TALLOC_CTX *tmp_ctx;
424 if (argc < 4) {
425 cmd_fss_delete_usage(argv[0]);
426 return NT_STATUS_UNSUCCESSFUL;
428 sc_set_id = argv[2];
429 sc_id = argv[3];
431 tmp_ctx = talloc_new(mem_ctx);
432 if (tmp_ctx == NULL) {
433 return NT_STATUS_NO_MEMORY;
436 ZERO_STRUCT(r_sharemap_del);
437 r_sharemap_del.in.ShareName = talloc_asprintf(tmp_ctx, "\\\\%s\\%s\\",
438 cli->desthost, argv[1]);
439 if (r_sharemap_del.in.ShareName == NULL) {
440 status = NT_STATUS_NO_MEMORY;
441 goto err_out;
443 status = GUID_from_string(sc_set_id, &r_sharemap_del.in.ShadowCopySetId);
444 if (!NT_STATUS_IS_OK(status)) {
445 DEBUG(0, ("Invalid shadow_copy_set_id parameter\n"));
446 goto err_out;
448 status = GUID_from_string(sc_id, &r_sharemap_del.in.ShadowCopyId);
449 if (!NT_STATUS_IS_OK(status)) {
450 DEBUG(0, ("Invalid shadow_copy_id parameter\n"));
451 goto err_out;
453 status = dcerpc_fss_DeleteShareMapping_r(b, tmp_ctx, &r_sharemap_del);
454 if (!NT_STATUS_IS_OK(status)) {
455 DEBUG(0, ("DeleteShareMapping failed\n"));
456 goto err_out;
457 } else if (r_sharemap_del.out.result != 0) {
458 DEBUG(0, ("failed DeleteShareMapping response: 0x%x\n",
459 r_sharemap_del.out.result));
460 status = NT_STATUS_UNSUCCESSFUL;
461 goto err_out;
464 printf("%s(%s): %s shadow-copy deleted\n",
465 sc_set_id, sc_id, r_sharemap_del.in.ShareName);
467 err_out:
468 talloc_free(tmp_ctx);
469 return status;
472 static void cmd_fss_is_shadow_copied_usage(const char *script_name)
474 printf("usage: %s [share_name]\n", script_name);
477 static NTSTATUS cmd_fss_is_shadow_copied(struct rpc_pipe_client *cli,
478 TALLOC_CTX *mem_ctx, int argc,
479 const char **argv)
481 NTSTATUS status;
482 struct fss_IsPathShadowCopied r;
483 struct dcerpc_binding_handle *b = cli->binding_handle;
485 if (argc != 2) {
486 cmd_fss_is_shadow_copied_usage(argv[0]);
487 return NT_STATUS_UNSUCCESSFUL;
490 ZERO_STRUCT(r);
491 r.in.ShareName = talloc_asprintf(mem_ctx, "%s\\%s\\",
492 cli->srv_name_slash, argv[1]);
493 if (r.in.ShareName == NULL) {
494 return NT_STATUS_NO_MEMORY;
497 status = dcerpc_fss_IsPathShadowCopied_r(b, mem_ctx, &r);
498 if (!NT_STATUS_IS_OK(status)) {
499 DEBUG(0, ("IsPathShadowCopied failed with UNC %s\n",
500 r.in.ShareName));
501 return NT_STATUS_UNSUCCESSFUL;
502 } else if (r.out.result) {
503 DEBUG(0, ("failed IsPathShadowCopied response: 0x%x\n",
504 r.out.result));
505 return NT_STATUS_UNSUCCESSFUL;
507 printf("UNC %s %s an associated shadow-copy with compatibility 0x%x\n",
508 r.in.ShareName,
509 *r.out.ShadowCopyPresent ? "has" : "does not have",
510 *r.out.ShadowCopyCompatibility);
512 return NT_STATUS_OK;
515 static void cmd_fss_get_mapping_usage(const char *script_name)
517 printf("usage: %s [base_share] [shadow_copy_set_id] [shadow_copy_id]\n",
518 script_name);
521 static NTSTATUS cmd_fss_get_mapping(struct rpc_pipe_client *cli,
522 TALLOC_CTX *mem_ctx, int argc,
523 const char **argv)
525 struct dcerpc_binding_handle *b = cli->binding_handle;
526 struct fss_GetShareMapping r_sharemap_get;
527 const char *sc_set_id;
528 const char *sc_id;
529 struct fssagent_share_mapping_1 *map;
530 NTSTATUS status;
531 TALLOC_CTX *tmp_ctx;
533 if (argc < 4) {
534 cmd_fss_get_mapping_usage(argv[0]);
535 return NT_STATUS_UNSUCCESSFUL;
537 sc_set_id = argv[2];
538 sc_id = argv[3];
540 tmp_ctx = talloc_new(mem_ctx);
541 if (tmp_ctx == NULL) {
542 return NT_STATUS_NO_MEMORY;
545 ZERO_STRUCT(r_sharemap_get);
546 r_sharemap_get.in.ShareName = talloc_asprintf(tmp_ctx, "\\\\%s\\%s\\",
547 cli->desthost, argv[1]);
548 if (r_sharemap_get.in.ShareName == NULL) {
549 status = NT_STATUS_NO_MEMORY;
550 goto err_out;
552 status = GUID_from_string(sc_set_id, &r_sharemap_get.in.ShadowCopySetId);
553 if (!NT_STATUS_IS_OK(status)) {
554 DEBUG(0, ("Invalid shadow_copy_set_id parameter\n"));
555 goto err_out;
557 status = GUID_from_string(sc_id, &r_sharemap_get.in.ShadowCopyId);
558 if (!NT_STATUS_IS_OK(status)) {
559 DEBUG(0, ("Invalid shadow_copy_id parameter\n"));
560 goto err_out;
562 r_sharemap_get.in.Level = 1;
563 status = dcerpc_fss_GetShareMapping_r(b, tmp_ctx, &r_sharemap_get);
564 if (!NT_STATUS_IS_OK(status)) {
565 DEBUG(0, ("GetShareMapping failed\n"));
566 goto err_out;
567 } else if (r_sharemap_get.out.result != 0) {
568 DEBUG(0, ("failed GetShareMapping response: 0x%x\n",
569 r_sharemap_get.out.result));
570 status = NT_STATUS_UNSUCCESSFUL;
571 goto err_out;
574 map = r_sharemap_get.out.ShareMapping->ShareMapping1;
575 printf("%s(%s): share %s is a shadow-copy of %s at %s\n",
576 GUID_string(tmp_ctx, &map->ShadowCopySetId),
577 GUID_string(tmp_ctx, &map->ShadowCopyId),
578 map->ShadowCopyShareName, map->ShareNameUNC,
579 nt_time_string(tmp_ctx, map->tstamp));
581 err_out:
582 talloc_free(tmp_ctx);
583 return status;
586 static void cmd_fss_recov_complete_usage(const char *script_name)
588 printf("usage: %s [shadow_copy_set_id]\n", script_name);
591 static NTSTATUS cmd_fss_recov_complete(struct rpc_pipe_client *cli,
592 TALLOC_CTX *mem_ctx, int argc,
593 const char **argv)
595 NTSTATUS status;
596 struct fss_RecoveryCompleteShadowCopySet r;
597 struct dcerpc_binding_handle *b = cli->binding_handle;
598 const char *sc_set_id;
600 if (argc != 2) {
601 cmd_fss_recov_complete_usage(argv[0]);
602 return NT_STATUS_UNSUCCESSFUL;
604 sc_set_id = argv[1];
606 ZERO_STRUCT(r);
607 status = GUID_from_string(sc_set_id, &r.in.ShadowCopySetId);
608 if (!NT_STATUS_IS_OK(status)) {
609 DEBUG(0, ("Invalid shadow_copy_set_id\n"));
610 return NT_STATUS_INVALID_PARAMETER;
613 status = dcerpc_fss_RecoveryCompleteShadowCopySet_r(b, mem_ctx, &r);
614 if (!NT_STATUS_IS_OK(status) || (r.out.result != 0)) {
615 DEBUG(0, ("RecoveryCompleteShadowCopySet failed: %s "
616 "result: 0x%x\n", nt_errstr(status), r.out.result));
617 return status;
619 printf("%s: shadow-copy set marked recovery complete\n", sc_set_id);
621 return NT_STATUS_OK;
624 /* List of commands exported by this module */
625 struct cmd_set fss_commands[] = {
627 { "FSRVP" },
630 .name = "fss_is_path_sup",
631 .returntype = RPC_RTYPE_NTSTATUS,
632 .ntfn = cmd_fss_is_path_sup,
633 .table = &ndr_table_FileServerVssAgent,
634 .rpc_pipe = NULL,
635 .description = "Check whether a share supports shadow-copy "
636 "requests",
637 .usage = "",
640 .name = "fss_get_sup_version",
641 .returntype = RPC_RTYPE_NTSTATUS,
642 .ntfn = cmd_fss_get_sup_version,
643 .table = &ndr_table_FileServerVssAgent,
644 .rpc_pipe = NULL,
645 .description = "Get supported FSRVP version from server",
646 .usage = "",
649 .name = "fss_create_expose",
650 .returntype = RPC_RTYPE_NTSTATUS,
651 .ntfn = cmd_fss_create_expose,
652 .table = &ndr_table_FileServerVssAgent,
653 .rpc_pipe = NULL,
654 .description = "Request shadow-copy creation and exposure",
655 .usage = "",
658 .name = "fss_delete",
659 .returntype = RPC_RTYPE_NTSTATUS,
660 .ntfn = cmd_fss_delete,
661 .table = &ndr_table_FileServerVssAgent,
662 .rpc_pipe = NULL,
663 .description = "Request shadow-copy share deletion",
664 .usage = "",
667 .name = "fss_has_shadow_copy",
668 .returntype = RPC_RTYPE_NTSTATUS,
669 .ntfn = cmd_fss_is_shadow_copied,
670 .table = &ndr_table_FileServerVssAgent,
671 .rpc_pipe = NULL,
672 .description = "Check for an associated share shadow-copy",
673 .usage = "",
676 .name = "fss_get_mapping",
677 .returntype = RPC_RTYPE_NTSTATUS,
678 .ntfn = cmd_fss_get_mapping,
679 .table = &ndr_table_FileServerVssAgent,
680 .rpc_pipe = NULL,
681 .description = "Get shadow-copy share mapping information",
682 .usage = "",
685 .name = "fss_recovery_complete",
686 .returntype = RPC_RTYPE_NTSTATUS,
687 .ntfn = cmd_fss_recov_complete,
688 .table = &ndr_table_FileServerVssAgent,
689 .rpc_pipe = NULL,
690 .description = "Flag read-write snapshot as recovery complete, "
691 "allowing further shadow-copy requests",
692 .usage = "",
694 { NULL }