diff options
author | Günther Deschner <gd@samba.org> | 2008-06-25 11:50:50 +0200 |
---|---|---|
committer | Günther Deschner <gd@samba.org> | 2008-06-25 23:58:50 +0200 |
commit | 7139745b018a3d2304aff24a5baef97ec750256a (patch) | |
tree | 45f9f1aa09e0d5ddf0359579e6d8338e6f9ba679 | |
parent | 402733b518dada3ffd3a9cb622a8f994ed35a9ac (diff) | |
download | samba-7139745b018a3d2304aff24a5baef97ec750256a.tar.gz samba-7139745b018a3d2304aff24a5baef97ec750256a.tar.bz2 samba-7139745b018a3d2304aff24a5baef97ec750256a.zip |
rpcclient: add samr chgpasswd command.
Guenther
(This used to be commit b90ae343722eb73c5874d875aa439e4ef92ed06a)
-rw-r--r-- | source3/rpcclient/cmd_samr.c | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/source3/rpcclient/cmd_samr.c b/source3/rpcclient/cmd_samr.c index a3e8e9bb6b..e25a358cd3 100644 --- a/source3/rpcclient/cmd_samr.c +++ b/source3/rpcclient/cmd_samr.c @@ -2424,6 +2424,98 @@ done: /* Change user password */ +static NTSTATUS cmd_samr_chgpasswd(struct rpc_pipe_client *cli, + TALLOC_CTX *mem_ctx, + int argc, const char **argv) +{ + POLICY_HND connect_pol, domain_pol, user_pol; + NTSTATUS result = NT_STATUS_UNSUCCESSFUL; + const char *user, *oldpass, *newpass; + uint32 access_mask = MAXIMUM_ALLOWED_ACCESS; + struct samr_Ids rids, types; + struct lsa_String lsa_acct_name; + + if (argc < 3) { + printf("Usage: %s username oldpass newpass\n", argv[0]); + return NT_STATUS_INVALID_PARAMETER; + } + + user = argv[1]; + oldpass = argv[2]; + newpass = argv[3]; + + /* Get sam policy handle */ + + result = rpccli_try_samr_connects(cli, mem_ctx, + MAXIMUM_ALLOWED_ACCESS, + &connect_pol); + + if (!NT_STATUS_IS_OK(result)) { + goto done; + } + + /* Get domain policy handle */ + + result = rpccli_samr_OpenDomain(cli, mem_ctx, + &connect_pol, + access_mask, + &domain_sid, + &domain_pol); + + if (!NT_STATUS_IS_OK(result)) { + goto done; + } + + init_lsa_String(&lsa_acct_name, user); + + result = rpccli_samr_LookupNames(cli, mem_ctx, + &domain_pol, + 1, + &lsa_acct_name, + &rids, + &types); + + if (!NT_STATUS_IS_OK(result)) { + goto done; + } + + result = rpccli_samr_OpenUser(cli, mem_ctx, + &domain_pol, + access_mask, + rids.ids[0], + &user_pol); + + if (!NT_STATUS_IS_OK(result)) { + goto done; + } + + /* Change user password */ + result = rpccli_samr_chgpasswd_user(cli, mem_ctx, + &user_pol, + newpass, + oldpass); + + if (!NT_STATUS_IS_OK(result)) { + goto done; + } + + done: + if (is_valid_policy_hnd(&user_pol)) { + rpccli_samr_Close(cli, mem_ctx, &user_pol); + } + if (is_valid_policy_hnd(&domain_pol)) { + rpccli_samr_Close(cli, mem_ctx, &domain_pol); + } + if (is_valid_policy_hnd(&connect_pol)) { + rpccli_samr_Close(cli, mem_ctx, &connect_pol); + } + + return result; +} + + +/* Change user password */ + static NTSTATUS cmd_samr_chgpasswd2(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx, int argc, const char **argv) @@ -2663,6 +2755,7 @@ struct cmd_set samr_commands[] = { { "getusrdompwinfo", RPC_RTYPE_NTSTATUS, cmd_samr_get_usrdom_pwinfo, NULL, PI_SAMR, NULL, "Retrieve user domain password info", "" }, { "lookupdomain", RPC_RTYPE_NTSTATUS, cmd_samr_lookup_domain, NULL, PI_SAMR, NULL, "Lookup Domain Name", "" }, + { "chgpasswd", RPC_RTYPE_NTSTATUS, cmd_samr_chgpasswd, NULL, PI_SAMR, NULL, "Change user password", "" }, { "chgpasswd2", RPC_RTYPE_NTSTATUS, cmd_samr_chgpasswd2, NULL, PI_SAMR, NULL, "Change user password", "" }, { "chgpasswd3", RPC_RTYPE_NTSTATUS, cmd_samr_chgpasswd3, NULL, PI_SAMR, NULL, "Change user password", "" }, { "getdispinfoidx", RPC_RTYPE_NTSTATUS, cmd_samr_get_dispinfo_idx, NULL, PI_SAMR, NULL, "Get Display Information Index", "" }, |