rpcclient: abort shadow-copy set on commmit failure
authorDavid Disseldorp <ddiss@samba.org>
Tue, 30 Apr 2013 21:48:48 +0000 (23:48 +0200)
committerDavid Disseldorp <ddiss@samba.org>
Wed, 8 May 2013 10:21:37 +0000 (12:21 +0200)
Use similar behavour to the diskshadow.exe FSRVP client, which aborts
the shadow-copy set if it receives a failed commit response.

source3/rpcclient/cmd_fss.c

index af194e2f8742add684a82473ddefa0a9d5692fed..89fc3d0b7381f0af3fda8e66a73ff20adcac3517 100644 (file)
@@ -199,6 +199,24 @@ static NTSTATUS cmd_fss_create_expose_parse(TALLOC_CTX *mem_ctx, int argc,
        return NT_STATUS_OK;
 }
 
+static NTSTATUS cmd_fss_abort(TALLOC_CTX *mem_ctx,
+                             struct dcerpc_binding_handle *b,
+                             struct GUID *sc_set_id)
+{
+       NTSTATUS status;
+       struct fss_AbortShadowCopySet r_scset_abort;
+
+       ZERO_STRUCT(r_scset_abort);
+       r_scset_abort.in.ShadowCopySetId = *sc_set_id;
+       status = dcerpc_fss_AbortShadowCopySet_r(b, mem_ctx, &r_scset_abort);
+       if (!NT_STATUS_IS_OK(status) || (r_scset_abort.out.result != 0)) {
+               DEBUG(0, ("AbortShadowCopySet failed: %s result: 0x%x\n",
+                         nt_errstr(status), r_scset_abort.out.result));
+               return NT_STATUS_UNSUCCESSFUL;
+       }
+       return NT_STATUS_OK;
+}
+
 static NTSTATUS cmd_fss_create_expose(struct rpc_pipe_client *cli,
                                     TALLOC_CTX *mem_ctx, int argc,
                                     const char **argv)
@@ -292,7 +310,7 @@ static NTSTATUS cmd_fss_create_expose(struct rpc_pipe_client *cli,
                if (!NT_STATUS_IS_OK(status) || (r_scset_add.out.result != 0)) {
                        DEBUG(0, ("AddToShadowCopySet failed: %s result: 0x%x\n",
                                  nt_errstr(status), r_scset_add.out.result));
-                       goto err_out;
+                       goto err_sc_set_abort;
                }
                printf("%s(%s): %s shadow-copy added to set\n",
                       GUID_string(tmp_ctx, r_scset_start.out.pShadowCopySetId),
@@ -310,7 +328,7 @@ static NTSTATUS cmd_fss_create_expose(struct rpc_pipe_client *cli,
        if (!NT_STATUS_IS_OK(status) || (r_scset_prep.out.result != 0)) {
                DEBUG(0, ("PrepareShadowCopySet failed: %s result: 0x%x\n",
                          nt_errstr(status), r_scset_prep.out.result));
-               goto err_out;
+               goto err_sc_set_abort;
        }
        printf("%s: prepare completed in %llu secs\n",
               GUID_string(tmp_ctx, r_scset_start.out.pShadowCopySetId),
@@ -324,7 +342,7 @@ static NTSTATUS cmd_fss_create_expose(struct rpc_pipe_client *cli,
        if (!NT_STATUS_IS_OK(status) || (r_scset_commit.out.result != 0)) {
                DEBUG(0, ("CommitShadowCopySet failed: %s result: 0x%x\n",
                          nt_errstr(status), r_scset_commit.out.result));
-               goto err_out;
+               goto err_sc_set_abort;
        }
        printf("%s: commit completed in %llu secs\n",
               GUID_string(tmp_ctx, r_scset_start.out.pShadowCopySetId),
@@ -360,6 +378,11 @@ static NTSTATUS cmd_fss_create_expose(struct rpc_pipe_client *cli,
                       map->ShadowCopyShareName, map->ShareNameUNC);
        }
 
+       talloc_free(tmp_ctx);
+       return NT_STATUS_OK;
+
+err_sc_set_abort:
+       cmd_fss_abort(tmp_ctx, b, r_scset_start.out.pShadowCopySetId);
 err_out:
        talloc_free(tmp_ctx);
        return status;