40bb257072d965e6323d6ed7c36ac6255c12d3f3
[samba.git] / source3 / 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         BOOL res = True;
47
48         /* machine account passwords */
49         pstring new_mach_pwd;
50
51         /* initialisation */
52         new_mach_pwd[0] = 0;
53
54         DEBUG(5,("do_nt_login_test: %d\n", __LINE__));
55
56 #if 0
57         /* check whether the user wants to change their machine password */
58         res = res ? trust_account_check(info->dest_ip, info->dest_host,
59                                         info->myhostname, smb_cli->domain,
60                                         info->mach_acct, new_mach_pwd) : False;
61 #endif
62         /* open NETLOGON session.  negotiate credentials */
63         res = res ? do_nt_session_open(smb_cli, 
64                                   info->dest_host, info->myhostname,
65                                   info->mach_acct,
66                                   smb_cli->user_name, smb_cli->domain,
67                                   info->dom.sess_key, &info->dom.clnt_cred) : False;
68
69         /* change the machine password? */
70         if (new_mach_pwd != NULL && new_mach_pwd[0] != 0)
71         {
72                 res = res ? do_nt_srv_pwset(smb_cli, info->dom.lsarpc_fnum,
73                                    info->dom.sess_key, &info->dom.clnt_cred, &info->dom.rtn_cred,
74                                    new_mach_pwd,
75                                    info->dest_host, info->mach_acct, info->myhostname) : False;
76         }
77
78         /* create the user-identification info */
79         make_nt_login_interactive(&info->dom.ctr,
80                          info->dom.sess_key,
81                          smb_cli->domain, info->myhostname,
82                          getuid(), smb_cli->user_name);
83
84         /* do an NT login */
85         res = res ? do_nt_login(smb_cli, info->dom.lsarpc_fnum,
86                                 info->dom.sess_key, &info->dom.clnt_cred, &info->dom.rtn_cred,
87                                 &info->dom.ctr, info->dest_host, info->myhostname, &info->dom.user_info3) : False;
88
89         /* ok!  you're logged in!  do anything you like, then... */
90            
91         /* do an NT logout */
92         res = res ? do_nt_logoff(smb_cli, info->dom.lsarpc_fnum,
93                                  info->dom.sess_key, &info->dom.clnt_cred, &info->dom.rtn_cred,
94                                  &info->dom.ctr, info->dest_host, info->myhostname) : False;
95
96         /* close the session */
97         cli_nt_session_close(smb_cli);
98
99         if (res)
100         {
101                 DEBUG(5,("cmd_nt_login: login test succeeded\n"));
102         }
103         else
104         {
105                 DEBUG(5,("cmd_nt_login: login test failed\n"));
106         }
107 }
108