trying to get HEAD building again. If you want the code
[Samba.git] / source / smbd / change_trust_pw.c
blob4993e285cac929620d451e69b16edc768c03413d
1 /*
2 * Unix SMB/CIFS implementation.
3 * Periodic Trust account password changing.
4 * Copyright (C) Andrew Tridgell 1992-1997,
5 * Copyright (C) Luke Kenneth Casson Leighton 1996-1997,
6 * Copyright (C) Paul Ashton 1997.
7 * Copyright (C) Jeremy Allison 1998.
8 * Copyright (C) Andrew Bartlett 2001.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #include "includes.h"
27 /************************************************************************
28 Change the trust account password for a domain.
29 ************************************************************************/
31 NTSTATUS change_trust_account_password( const char *domain, const char *remote_machine)
33 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
34 struct in_addr pdc_ip;
35 fstring dc_name;
36 struct cli_state *cli;
38 if (remote_machine == NULL || !strcmp(remote_machine, "*")) {
39 /* Use the PDC *only* for this */
41 if ( !get_pdc_ip(domain, &pdc_ip) ) {
42 DEBUG(0,("Can't get IP for PDC for domain %s\n", domain));
43 goto failed;
46 if ( !name_status_find( domain, 0x1b, 0x20, pdc_ip, dc_name) )
47 goto failed;
49 /* supoport old deprecated "smbpasswd -j DOMAIN -r MACHINE" behavior */
50 else {
51 fstrcpy( dc_name, remote_machine );
54 /* if this next call fails, then give up. We can't do
55 password changes on BDC's --jerry */
57 if (!NT_STATUS_IS_OK(cli_full_connection(&cli, global_myname(), remote_machine,
58 NULL, 0,
59 "IPC$", "IPC",
60 "", "",
61 "", 0, NULL)))
63 DEBUG(0,("modify_trust_password: Connection to %s failed!\n", remote_machine));
64 nt_status = NT_STATUS_UNSUCCESSFUL;
65 goto failed;
69 * Ok - we have an anonymous connection to the IPC$ share.
70 * Now start the NT Domain stuff :-).
73 if(cli_nt_session_open(cli, PI_NETLOGON) == False) {
74 DEBUG(0,("modify_trust_password: unable to open the domain client session to machine %s. Error was : %s.\n",
75 remote_machine, cli_errstr(cli)));
76 cli_nt_session_close(cli);
77 cli_ulogoff(cli);
78 cli_shutdown(cli);
79 nt_status = NT_STATUS_UNSUCCESSFUL;
80 goto failed;
83 nt_status = trust_pw_find_change_and_store_it(cli, cli->mem_ctx,
84 domain);
86 cli_nt_session_close(cli);
87 cli_ulogoff(cli);
88 cli_shutdown(cli);
90 failed:
91 if (!NT_STATUS_IS_OK(nt_status)) {
92 DEBUG(0,("%s : change_trust_account_password: Failed to change password for domain %s.\n",
93 timestring(False), domain));
96 return nt_status;