netlogon: refactor just_change_the_password a bit.
authorGünther Deschner <gd@samba.org>
Sat, 20 Sep 2008 16:20:29 +0000 (18:20 +0200)
committerGünther Deschner <gd@samba.org>
Sun, 21 Sep 2008 20:30:29 +0000 (22:30 +0200)
Guenther

source3/libsmb/trusts_util.c

index 9265c60665d6b7e7956d071dcc8fe53e8ec84cdc..7897d5171784c8ce7e671b1f413f5a4a79af87c6 100644 (file)
@@ -37,6 +37,7 @@ static NTSTATUS just_change_the_password(struct rpc_pipe_client *cli, TALLOC_CTX
 {
        NTSTATUS result;
        uint32_t neg_flags = NETLOGON_NEG_AUTH2_ADS_FLAGS;
+       struct netr_Authenticator clnt_creds, srv_cred;
 
        result = rpccli_netlogon_setup_creds(cli,
                                             cli->desthost, /* server name */
@@ -53,13 +54,12 @@ static NTSTATUS just_change_the_password(struct rpc_pipe_client *cli, TALLOC_CTX
                return result;
        }
 
+       netlogon_creds_client_step(cli->dc, &clnt_creds);
+
        if (neg_flags & NETLOGON_NEG_PASSWORD_SET2) {
 
-               struct netr_Authenticator clnt_creds, srv_cred;
                struct netr_CryptPassword new_password;
 
-               netlogon_creds_client_step(cli->dc, &clnt_creds);
-
                init_netr_CryptPassword(new_trust_pwd_cleartext,
                                        cli->dc->sess_key,
                                        &new_password);
@@ -72,21 +72,15 @@ static NTSTATUS just_change_the_password(struct rpc_pipe_client *cli, TALLOC_CTX
                                                        &clnt_creds,
                                                        &srv_cred,
                                                        &new_password);
-
-               /* Always check returned credentials. */
-               if (!netlogon_creds_client_check(cli->dc, &srv_cred.cred)) {
-                       DEBUG(0,("rpccli_netr_ServerPasswordSet2: "
-                               "credentials chain check failed\n"));
-                       return NT_STATUS_ACCESS_DENIED;
+               if (!NT_STATUS_IS_OK(result)) {
+                       DEBUG(0,("rpccli_netr_ServerPasswordSet2 failed: %s\n",
+                               nt_errstr(result)));
+                       return result;
                }
-
        } else {
 
-               struct netr_Authenticator clnt_creds, srv_cred;
                struct samr_Password new_password;
 
-               netlogon_creds_client_step(cli->dc, &clnt_creds);
-
                cred_hash3(new_password.hash,
                           new_trust_passwd_hash,
                           cli->dc->sess_key, 1);
@@ -99,19 +93,19 @@ static NTSTATUS just_change_the_password(struct rpc_pipe_client *cli, TALLOC_CTX
                                                       &clnt_creds,
                                                       &srv_cred,
                                                       &new_password);
-
-               /* Always check returned credentials. */
-               if (!netlogon_creds_client_check(cli->dc, &srv_cred.cred)) {
-                       DEBUG(0,("rpccli_netr_ServerPasswordSet: "
-                               "credentials chain check failed\n"));
-                       return NT_STATUS_ACCESS_DENIED;
+               if (!NT_STATUS_IS_OK(result)) {
+                       DEBUG(0,("rpccli_netr_ServerPasswordSet failed: %s\n",
+                               nt_errstr(result)));
+                       return result;
                }
        }
 
-       if (!NT_STATUS_IS_OK(result)) {
-               DEBUG(0,("just_change_the_password: unable to change password (%s)!\n",
-                        nt_errstr(result)));
+       /* Always check returned credentials. */
+       if (!netlogon_creds_client_check(cli->dc, &srv_cred.cred)) {
+               DEBUG(0,("credentials chain check failed\n"));
+               return NT_STATUS_ACCESS_DENIED;
        }
+
        return result;
 }