removed nt_pipe_fnum from struct cli_state. need to be able to call
[tprouty/samba.git] / source / rpcclient / cmd_netlogon.c
1 /* 
2    Unix SMB/Netbios implementation.
3    Version 1.9.
4    NT Domain Authentication SMB / MSRPC client
5    Copyright (C) Andrew Tridgell 1994-1997
6    Copyright (C) Luke Kenneth Casson Leighton 1996-1997
7    
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
12    
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17    
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23
24
25 #ifdef SYSLOG
26 #undef SYSLOG
27 #endif
28
29 #include "includes.h"
30 #include "nterr.h"
31
32 extern int DEBUGLEVEL;
33
34 #define DEBUG_TESTING
35
36 extern struct cli_state *smb_cli;
37
38 extern FILE* out_hnd;
39
40
41 /****************************************************************************
42 experimental nt login.
43 ****************************************************************************/
44 void cmd_netlogon_login_test(struct client_info *info)
45 {
46         uint16 nt_pipe_fnum;
47         extern BOOL global_machine_password_needs_changing;
48
49         fstring nt_user_name;
50         fstring password;
51         BOOL res = True;
52         char *nt_password;
53         unsigned char trust_passwd[16];
54
55 #if 0
56         /* machine account passwords */
57         pstring new_mach_pwd;
58
59         /* initialisation */
60         new_mach_pwd[0] = 0;
61 #endif
62
63         if (!next_token(NULL, nt_user_name, NULL, sizeof(nt_user_name)))
64         {
65                 fstrcpy(nt_user_name, smb_cli->user_name);
66                 if (nt_user_name[0] == 0)
67                 {
68                         fprintf(out_hnd,"ntlogin: must specify username with anonymous connection\n");
69                         return;
70                 }
71         }
72
73         if (next_token(NULL, password, NULL, sizeof(password)))
74         {
75                 nt_password = password;
76         }
77         else
78         {
79                 nt_password = getpass("Enter NT Login password:");
80         }
81
82         DEBUG(5,("do_nt_login_test: username %s\n", nt_user_name));
83
84         res = res ? trust_get_passwd(trust_passwd, smb_cli->domain, info->myhostname) : False;
85
86 #if 0
87         /* check whether the user wants to change their machine password */
88         res = res ? trust_account_check(info->dest_ip, info->dest_host,
89                                         info->myhostname, smb_cli->domain,
90                                         info->mach_acct, new_mach_pwd) : False;
91 #endif
92         /* open NETLOGON session.  negotiate credentials */
93         res = res ? cli_nt_session_open(smb_cli, PIPE_NETLOGON, &nt_pipe_fnum) : False;
94
95         res = res ? cli_nt_setup_creds(smb_cli, nt_pipe_fnum, trust_passwd) : False;
96
97         /* change the machine password? */
98         if (global_machine_password_needs_changing)
99         {
100                 unsigned char new_trust_passwd[16];
101                 generate_random_buffer(new_trust_passwd, 16, True);
102                 res = res ? cli_nt_srv_pwset(smb_cli, nt_pipe_fnum, new_trust_passwd) : False;
103
104                 if (res)
105                 {
106                         global_machine_password_needs_changing = !set_trust_account_password(new_trust_passwd);
107                 }
108
109                 memset(new_trust_passwd, 0, 16);
110         }
111
112         memset(trust_passwd, 0, 16);
113
114         /* do an NT login */
115         res = res ? cli_nt_login_interactive(smb_cli, nt_pipe_fnum,
116                          smb_cli->domain, nt_user_name,
117                          getuid(), nt_password,
118                          &info->dom.ctr, &info->dom.user_info3) : False;
119
120         /*** clear out the password ***/
121         memset(password, 0, sizeof(password));
122
123         /* ok!  you're logged in!  do anything you like, then... */
124
125         /* do an NT logout */
126         res = res ? cli_nt_logoff(smb_cli, nt_pipe_fnum, &info->dom.ctr) : False;
127
128         /* close the session */
129         cli_nt_session_close(smb_cli, nt_pipe_fnum);
130
131         fprintf(out_hnd,"cmd_nt_login: login (%s) test succeeded: %s\n",
132                 nt_user_name, BOOLSTR(res));
133 }
134