Removed global_myworkgroup, global_myname, global_myscope. Added liberal
[kai/samba.git] / source / libsmb / passchange.c
1 /* 
2    Unix SMB/CIFS implementation.
3    SMB client password change routine
4    Copyright (C) Andrew Tridgell 1994-1998
5    
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
10    
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15    
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21 #include "includes.h"
22
23 /*************************************************************
24 change a password on a remote machine using IPC calls
25 *************************************************************/
26 BOOL remote_password_change(const char *remote_machine, const char *user_name, 
27                             const char *old_passwd, const char *new_passwd,
28                             char *err_str, size_t err_str_len)
29 {
30         struct nmb_name calling, called;
31         struct cli_state cli;
32         struct in_addr ip;
33
34         *err_str = '\0';
35
36         if(!resolve_name( remote_machine, &ip, 0x20)) {
37                 slprintf(err_str, err_str_len-1, "unable to find an IP address for machine %s.\n",
38                         remote_machine );
39                 return False;
40         }
41  
42         ZERO_STRUCT(cli);
43  
44         if (!cli_initialise(&cli) || !cli_connect(&cli, remote_machine, &ip)) {
45                 slprintf(err_str, err_str_len-1, "unable to connect to SMB server on machine %s. Error was : %s.\n",
46                         remote_machine, cli_errstr(&cli) );
47                 return False;
48         }
49   
50         make_nmb_name(&calling, global_myname() , 0x0);
51         make_nmb_name(&called , remote_machine, 0x20);
52         
53         if (!cli_session_request(&cli, &calling, &called)) {
54                 slprintf(err_str, err_str_len-1, "machine %s rejected the session setup. Error was : %s.\n",
55                         remote_machine, cli_errstr(&cli) );
56                 cli_shutdown(&cli);
57                 return False;
58         }
59   
60         cli.protocol = PROTOCOL_NT1;
61
62         if (!cli_negprot(&cli)) {
63                 slprintf(err_str, err_str_len-1, "machine %s rejected the negotiate protocol. Error was : %s.\n",        
64                         remote_machine, cli_errstr(&cli) );
65                 cli_shutdown(&cli);
66                 return False;
67         }
68   
69         /*
70          * We should connect as the anonymous user here, in case
71          * the server has "must change password" checked...
72          * Thanks to <Nicholas.S.Jenkins@cdc.com> for this fix.
73          */
74
75         if (!cli_session_setup(&cli, "", "", 0, "", 0, "")) {
76                 slprintf(err_str, err_str_len-1, "machine %s rejected the session setup. Error was : %s.\n",        
77                         remote_machine, cli_errstr(&cli) );
78                 cli_shutdown(&cli);
79                 return False;
80         }               
81
82         if (!cli_send_tconX(&cli, "IPC$", "IPC", "", 1)) {
83                 slprintf(err_str, err_str_len-1, "machine %s rejected the tconX on the IPC$ share. Error was : %s.\n",
84                         remote_machine, cli_errstr(&cli) );
85                 cli_shutdown(&cli);
86                 return False;
87         }
88
89         if(!cli_oem_change_password(&cli, user_name, new_passwd, old_passwd)) {
90                 slprintf(err_str, err_str_len-1, "machine %s rejected the password change: Error was : %s.\n",
91                         remote_machine, cli_errstr(&cli) );
92                 cli_shutdown(&cli);
93                 return False;
94         }
95         
96         cli_shutdown(&cli);
97         return True;
98 }