netlogon: move password change code out to rpccli_netlogon_set_trust_password.
authorGünther Deschner <gd@samba.org>
Sun, 21 Sep 2008 16:57:26 +0000 (18:57 +0200)
committerGünther Deschner <gd@samba.org>
Sun, 21 Sep 2008 20:30:39 +0000 (22:30 +0200)
Guenther

source3/include/proto.h
source3/libsmb/trusts_util.c
source3/rpc_client/cli_netlogon.c

index bec5f10f3c86a6707bc0876a97bce2ca6cb6d410..194548c0820e10fa7ff257a97973b2b2644fa8b7 100644 (file)
@@ -7049,6 +7049,12 @@ NTSTATUS rpccli_netlogon_sam_network_logon_ex(struct rpc_pipe_client *cli,
                                              DATA_BLOB lm_response,
                                              DATA_BLOB nt_response,
                                              struct netr_SamInfo3 **info3);
+NTSTATUS rpccli_netlogon_set_trust_password(struct rpc_pipe_client *cli,
+                                           TALLOC_CTX *mem_ctx,
+                                           const unsigned char orig_trust_passwd_hash[16],
+                                           const char *new_trust_pwd_cleartext,
+                                           const unsigned char new_trust_passwd_hash[16],
+                                           uint32_t sec_channel_type);
 
 /* The following definitions come from rpc_client/cli_pipe.c  */
 
index 7897d5171784c8ce7e671b1f413f5a4a79af87c6..2f336f14e6d58b41380a53cda23e34eb1d4585db 100644 (file)
 
 #include "includes.h"
 
-/*********************************************************
- Change the domain password on the PDC.
-
- Just changes the password betwen the two values specified.
-
- Caller must have the cli connected to the netlogon pipe
- already.
-**********************************************************/
-
-static NTSTATUS just_change_the_password(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx, 
-                                        const unsigned char orig_trust_passwd_hash[16],
-                                        const char *new_trust_pwd_cleartext,
-                                        const unsigned char new_trust_passwd_hash[16],
-                                        uint32 sec_channel_type)
-{
-       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 */
-                                            lp_workgroup(), /* domain */
-                                            global_myname(), /* client name */
-                                            global_myname(), /* machine account name */
-                                            orig_trust_passwd_hash,
-                                            sec_channel_type,
-                                            &neg_flags);
-
-       if (!NT_STATUS_IS_OK(result)) {
-               DEBUG(3,("just_change_the_password: unable to setup creds (%s)!\n",
-                        nt_errstr(result)));
-               return result;
-       }
-
-       netlogon_creds_client_step(cli->dc, &clnt_creds);
-
-       if (neg_flags & NETLOGON_NEG_PASSWORD_SET2) {
-
-               struct netr_CryptPassword new_password;
-
-               init_netr_CryptPassword(new_trust_pwd_cleartext,
-                                       cli->dc->sess_key,
-                                       &new_password);
-
-               result = rpccli_netr_ServerPasswordSet2(cli, mem_ctx,
-                                                       cli->dc->remote_machine,
-                                                       cli->dc->mach_acct,
-                                                       sec_channel_type,
-                                                       global_myname(),
-                                                       &clnt_creds,
-                                                       &srv_cred,
-                                                       &new_password);
-               if (!NT_STATUS_IS_OK(result)) {
-                       DEBUG(0,("rpccli_netr_ServerPasswordSet2 failed: %s\n",
-                               nt_errstr(result)));
-                       return result;
-               }
-       } else {
-
-               struct samr_Password new_password;
-
-               cred_hash3(new_password.hash,
-                          new_trust_passwd_hash,
-                          cli->dc->sess_key, 1);
-
-               result = rpccli_netr_ServerPasswordSet(cli, mem_ctx,
-                                                      cli->dc->remote_machine,
-                                                      cli->dc->mach_acct,
-                                                      sec_channel_type,
-                                                      global_myname(),
-                                                      &clnt_creds,
-                                                      &srv_cred,
-                                                      &new_password);
-               if (!NT_STATUS_IS_OK(result)) {
-                       DEBUG(0,("rpccli_netr_ServerPasswordSet failed: %s\n",
-                               nt_errstr(result)));
-                       return 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;
-}
-
 /*********************************************************
  Change the domain password on the PDC.
  Store the password ourselves, but use the supplied password
@@ -135,11 +46,11 @@ NTSTATUS trust_pw_change_and_store_it(struct rpc_pipe_client *cli, TALLOC_CTX *m
        
        E_md4hash(new_trust_passwd, new_trust_passwd_hash);
 
-       nt_status = just_change_the_password(cli, mem_ctx,
-                                            orig_trust_passwd_hash,
-                                            new_trust_passwd,
-                                            new_trust_passwd_hash,
-                                            sec_channel_type);
+       nt_status = rpccli_netlogon_set_trust_password(cli, mem_ctx,
+                                                      orig_trust_passwd_hash,
+                                                      new_trust_passwd,
+                                                      new_trust_passwd_hash,
+                                                      sec_channel_type);
        
        if (NT_STATUS_IS_OK(nt_status)) {
                DEBUG(3,("%s : trust_pw_change_and_store_it: Changed password.\n", 
index df87ed13d132ddd97bbd3f2da255e5516d3cdc06..23618efd9fc9482a4a5037ed23176976e5fcc461 100644 (file)
@@ -538,3 +538,94 @@ NTSTATUS rpccli_netlogon_sam_network_logon_ex(struct rpc_pipe_client *cli,
 
        return result;
 }
+
+/*********************************************************
+ Change the domain password on the PDC.
+
+ Just changes the password betwen the two values specified.
+
+ Caller must have the cli connected to the netlogon pipe
+ already.
+**********************************************************/
+
+NTSTATUS rpccli_netlogon_set_trust_password(struct rpc_pipe_client *cli,
+                                           TALLOC_CTX *mem_ctx,
+                                           const unsigned char orig_trust_passwd_hash[16],
+                                           const char *new_trust_pwd_cleartext,
+                                           const unsigned char new_trust_passwd_hash[16],
+                                           uint32_t sec_channel_type)
+{
+       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 */
+                                            lp_workgroup(), /* domain */
+                                            global_myname(), /* client name */
+                                            global_myname(), /* machine account name */
+                                            orig_trust_passwd_hash,
+                                            sec_channel_type,
+                                            &neg_flags);
+
+       if (!NT_STATUS_IS_OK(result)) {
+               DEBUG(3,("rpccli_netlogon_set_trust_password: unable to setup creds (%s)!\n",
+                        nt_errstr(result)));
+               return result;
+       }
+
+       netlogon_creds_client_step(cli->dc, &clnt_creds);
+
+       if (neg_flags & NETLOGON_NEG_PASSWORD_SET2) {
+
+               struct netr_CryptPassword new_password;
+
+               init_netr_CryptPassword(new_trust_pwd_cleartext,
+                                       cli->dc->sess_key,
+                                       &new_password);
+
+               result = rpccli_netr_ServerPasswordSet2(cli, mem_ctx,
+                                                       cli->dc->remote_machine,
+                                                       cli->dc->mach_acct,
+                                                       sec_channel_type,
+                                                       global_myname(),
+                                                       &clnt_creds,
+                                                       &srv_cred,
+                                                       &new_password);
+               if (!NT_STATUS_IS_OK(result)) {
+                       DEBUG(0,("rpccli_netr_ServerPasswordSet2 failed: %s\n",
+                               nt_errstr(result)));
+                       return result;
+               }
+       } else {
+
+               struct samr_Password new_password;
+
+               cred_hash3(new_password.hash,
+                          new_trust_passwd_hash,
+                          cli->dc->sess_key, 1);
+
+               result = rpccli_netr_ServerPasswordSet(cli, mem_ctx,
+                                                      cli->dc->remote_machine,
+                                                      cli->dc->mach_acct,
+                                                      sec_channel_type,
+                                                      global_myname(),
+                                                      &clnt_creds,
+                                                      &srv_cred,
+                                                      &new_password);
+               if (!NT_STATUS_IS_OK(result)) {
+                       DEBUG(0,("rpccli_netr_ServerPasswordSet failed: %s\n",
+                               nt_errstr(result)));
+                       return 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;
+}
+