From f0a3fdf82ccf5f588dbeb09f4b493469cb358449 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sat, 29 Aug 2009 19:31:02 -0400 Subject: [PATCH] Fix for bug #6584 --- source3/libsmb/passchange.c | 27 ++++++++++++++++++++------- 1 files changed, 20 insertions(+), 7 deletions(-) diff --git a/source3/libsmb/passchange.c b/source3/libsmb/passchange.c index bb70386..4e315ec 100644 --- a/source3/libsmb/passchange.c +++ b/source3/libsmb/passchange.c @@ -31,10 +31,24 @@ NTSTATUS remote_password_change(const char *remote_machine, const char *user_nam struct cli_state *cli; struct rpc_pipe_client *pipe_hnd; struct sockaddr_storage ss; + char *user, *domain, *p; NTSTATUS result; bool pass_must_change = False; + user = talloc_strdup(talloc_tos(), user_name); + SMB_ASSERT(user != NULL); + domain = talloc_strdup(talloc_tos(), ""); + SMB_ASSERT(domain != NULL); + + /* allow usernames of the form domain\\user or domain/user */ + if ((p = strchr_m(user,'\\')) || (p = strchr_m(user,'/')) || + (p = strchr_m(user,*lp_winbind_separator()))) { + *p = 0; + user = p+1; + domain = user; + } + *err_str = NULL; if(!resolve_name( remote_machine, &ss, 0x20, false)) { @@ -139,7 +153,7 @@ NTSTATUS remote_password_change(const char *remote_machine, const char *user_nam return result; } } else { - result = cli_init_creds(cli, user_name, "", old_passwd); + result = cli_init_creds(cli, user, domain, old_passwd); if (!NT_STATUS_IS_OK(result)) { cli_shutdown(cli); return result; @@ -163,8 +177,7 @@ NTSTATUS remote_password_change(const char *remote_machine, const char *user_nam result = cli_rpc_pipe_open_ntlmssp(cli, &ndr_table_samr.syntax_id, PIPE_AUTH_LEVEL_PRIVACY, - "", /* what domain... ? */ - user_name, + domain, user, old_passwd, &pipe_hnd); } else { @@ -183,7 +196,7 @@ NTSTATUS remote_password_change(const char *remote_machine, const char *user_nam if (!NT_STATUS_IS_OK(result)) { if (lp_client_lanman_auth()) { /* Use the old RAP method. */ - if (!cli_oem_change_password(cli, user_name, new_passwd, old_passwd)) { + if (!cli_oem_change_password(cli, user, new_passwd, old_passwd)) { if (asprintf(err_str, "machine %s rejected the " "password change: Error was : %s.\n", remote_machine, cli_errstr(cli)) == -1) { @@ -207,7 +220,7 @@ NTSTATUS remote_password_change(const char *remote_machine, const char *user_nam } result = rpccli_samr_chgpasswd_user2(pipe_hnd, talloc_tos(), - user_name, new_passwd, old_passwd); + user, new_passwd, old_passwd); if (NT_STATUS_IS_OK(result)) { /* Great - it all worked! */ cli_shutdown(cli); @@ -244,7 +257,7 @@ NTSTATUS remote_password_change(const char *remote_machine, const char *user_nam if ( NT_STATUS_IS_OK(result) && (NT_STATUS_IS_OK(result = rpccli_samr_chgpasswd_user2( - pipe_hnd, talloc_tos(), user_name, + pipe_hnd, talloc_tos(), user, new_passwd, old_passwd)))) { /* Great - it all worked! */ cli_shutdown(cli); @@ -269,7 +282,7 @@ NTSTATUS remote_password_change(const char *remote_machine, const char *user_nam if (lp_client_lanman_auth()) { /* Use the old RAP method. */ - if (cli_oem_change_password(cli, user_name, new_passwd, old_passwd)) { + if (cli_oem_change_password(cli, user, new_passwd, old_passwd)) { /* SAMR failed, but the old LanMan protocol worked! */ cli_shutdown(cli); -- 1.6.0.6