s3-rpcclient: add LSA deletesecret command.
authorGünther Deschner <gd@samba.org>
Fri, 17 Jul 2009 09:58:10 +0000 (11:58 +0200)
committerGünther Deschner <gd@samba.org>
Fri, 17 Jul 2009 11:50:33 +0000 (13:50 +0200)
Guenther

source3/rpcclient/cmd_lsarpc.c

index f1e28d5d8fa7e28c8bde0d81a01d446e54eec325..5fa30c24459c8cac65593a5eaf02c573d5b9b241 100644 (file)
@@ -1399,6 +1399,55 @@ static NTSTATUS cmd_lsa_create_secret(struct rpc_pipe_client *cli,
        return status;
 }
 
+static NTSTATUS cmd_lsa_delete_secret(struct rpc_pipe_client *cli,
+                                     TALLOC_CTX *mem_ctx, int argc,
+                                     const char **argv)
+{
+       NTSTATUS status;
+       struct policy_handle handle, sec_handle;
+       struct lsa_String name;
+
+       if (argc < 2) {
+               printf("Usage: %s name\n", argv[0]);
+               return NT_STATUS_OK;
+       }
+
+       status = rpccli_lsa_open_policy2(cli, mem_ctx,
+                                        true,
+                                        SEC_FLAG_MAXIMUM_ALLOWED,
+                                        &handle);
+       if (!NT_STATUS_IS_OK(status)) {
+               return status;
+       }
+
+       init_lsa_String(&name, argv[1]);
+
+       status = rpccli_lsa_OpenSecret(cli, mem_ctx,
+                                      &handle,
+                                      name,
+                                      SEC_FLAG_MAXIMUM_ALLOWED,
+                                      &sec_handle);
+       if (!NT_STATUS_IS_OK(status)) {
+               goto done;
+       }
+
+       status = rpccli_lsa_DeleteObject(cli, mem_ctx,
+                                        &sec_handle);
+       if (!NT_STATUS_IS_OK(status)) {
+               goto done;
+       }
+
+ done:
+       if (is_valid_policy_hnd(&sec_handle)) {
+               rpccli_lsa_Close(cli, mem_ctx, &sec_handle);
+       }
+       if (is_valid_policy_hnd(&handle)) {
+               rpccli_lsa_Close(cli, mem_ctx, &handle);
+       }
+
+       return status;
+}
+
 /* List of commands exported by this module */
 
 struct cmd_set lsarpc_commands[] = {
@@ -1427,6 +1476,7 @@ struct cmd_set lsarpc_commands[] = {
        { "lsaquerytrustdominfobysid",RPC_RTYPE_NTSTATUS, cmd_lsa_query_trustdominfobysid, NULL, &ndr_table_lsarpc.syntax_id, NULL, "Query LSA trusted domains info (given a SID)", "" },
        { "getusername",          RPC_RTYPE_NTSTATUS, cmd_lsa_get_username, NULL, &ndr_table_lsarpc.syntax_id, NULL, "Get username", "" },
        { "createsecret",         RPC_RTYPE_NTSTATUS, cmd_lsa_create_secret, NULL, &ndr_table_lsarpc.syntax_id, NULL, "Create Secret", "" },
+       { "deletesecret",         RPC_RTYPE_NTSTATUS, cmd_lsa_delete_secret, NULL, &ndr_table_lsarpc.syntax_id, NULL, "Delete Secret", "" },
 
        { NULL }
 };