2 * Unix SMB/CIFS implementation.
3 * Routines to operate on various trust relationships
4 * Copyright (C) Andrew Bartlett 2001
5 * Copyright (C) Rafal Szczesniak 2003
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, see <http://www.gnu.org/licenses/>.
22 #include "../libcli/auth/libcli_auth.h"
23 #include "rpc_client/cli_netlogon.h"
24 #include "rpc_client/cli_pipe.h"
25 #include "../librpc/gen_ndr/ndr_netlogon.h"
28 #include "libsmb/libsmb.h"
30 /*********************************************************
31 Change the domain password on the PDC.
32 Store the password ourselves, but use the supplied password
33 Caller must have already setup the connection to the NETLOGON pipe
34 **********************************************************/
36 NTSTATUS trust_pw_change_and_store_it(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
38 const char *account_name,
39 unsigned char orig_trust_passwd_hash[16],
40 enum netr_SchannelType sec_channel_type)
42 unsigned char new_trust_passwd_hash[16];
43 char *new_trust_passwd;
46 switch (sec_channel_type) {
51 return NT_STATUS_NOT_SUPPORTED;
54 /* Create a random machine account password */
55 new_trust_passwd = generate_random_password(mem_ctx,
56 DEFAULT_TRUST_ACCOUNT_PASSWORD_LENGTH,
57 DEFAULT_TRUST_ACCOUNT_PASSWORD_LENGTH);
58 if (new_trust_passwd == NULL) {
59 DEBUG(0, ("generate_random_password failed\n"));
60 return NT_STATUS_NO_MEMORY;
63 E_md4hash(new_trust_passwd, new_trust_passwd_hash);
65 nt_status = rpccli_netlogon_set_trust_password(cli, mem_ctx,
67 orig_trust_passwd_hash,
69 new_trust_passwd_hash,
72 if (NT_STATUS_IS_OK(nt_status)) {
73 DEBUG(3,("%s : trust_pw_change_and_store_it: Changed password.\n",
74 current_timestring(talloc_tos(), False)));
76 * Return the result of trying to write the new password
77 * back into the trust account file.
80 switch (sec_channel_type) {
83 if (!secrets_store_machine_password(new_trust_passwd, domain, sec_channel_type)) {
84 nt_status = NT_STATUS_UNSUCCESSFUL;
88 case SEC_CHAN_DOMAIN: {
91 time_t pass_last_set_time;
93 /* we need to get the sid first for the
94 * pdb_set_trusteddom_pw call */
96 if (!pdb_get_trusteddom_pw(domain, &pwd, &sid, &pass_last_set_time)) {
97 nt_status = NT_STATUS_TRUSTED_RELATIONSHIP_FAILURE;
99 if (!pdb_set_trusteddom_pw(domain, new_trust_passwd, &sid)) {
100 nt_status = NT_STATUS_INTERNAL_DB_CORRUPTION;
112 /*********************************************************
113 Change the domain password on the PDC.
114 Do most of the legwork ourselfs. Caller must have
115 already setup the connection to the NETLOGON pipe
116 **********************************************************/
118 NTSTATUS trust_pw_find_change_and_store_it(struct rpc_pipe_client *cli,
122 unsigned char old_trust_passwd_hash[16];
123 enum netr_SchannelType sec_channel_type = SEC_CHAN_NULL;
124 const char *account_name;
126 if (!get_trust_pw_hash(domain, old_trust_passwd_hash, &account_name,
127 &sec_channel_type)) {
128 DEBUG(0, ("could not fetch domain secrets for domain %s!\n", domain));
129 return NT_STATUS_UNSUCCESSFUL;
132 return trust_pw_change_and_store_it(cli, mem_ctx, domain,
134 old_trust_passwd_hash,