2 Unix SMB/Netbios implementation.
4 NT Domain Authentication SMB / MSRPC client
5 Copyright (C) Andrew Tridgell 1994-1997
6 Copyright (C) Luke Kenneth Casson Leighton 1996-1997
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.
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.
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.
32 extern int DEBUGLEVEL;
36 extern struct user_credentials *usr_creds;
41 /****************************************************************************
42 experimental nt login.
43 ****************************************************************************/
44 void cmd_netlogon_login_test(struct client_info *info, int argc, char *argv[])
47 extern BOOL global_machine_password_needs_changing;
54 unsigned char trust_passwd[16];
58 fstrcpy(srv_name, "\\\\");
59 fstrcat(srv_name, info->dest_host);
63 /* machine account passwords */
75 fstrcpy(nt_user_name, usr_creds->user_name);
76 if (nt_user_name[0] == 0)
78 report(out_hnd,"ntlogin: must specify username with anonymous connection\n");
84 fstrcpy(nt_user_name, argv[0]);
92 nt_password = argv[0];
96 nt_password = getpass("Enter NT Login password:");
99 DEBUG(5,("do_nt_login_test: username %s from: %s\n",
100 nt_user_name, info->myhostname));
102 fstrcpy(trust_acct, info->myhostname);
103 fstrcat(trust_acct, "$");
105 res = res ? trust_get_passwd(trust_passwd, usr_creds->domain, info->myhostname) : False;
108 /* check whether the user wants to change their machine password */
109 res = res ? trust_account_check(info->dest_ip, info->dest_host,
110 info->myhostname, usr_creds->domain,
111 info->mach_acct, new_mach_pwd) : False;
114 res = res ? cli_nt_setup_creds(srv_name, info->myhostname,
116 trust_passwd, SEC_CHAN_WKSTA) == 0x0 : False;
119 /* change the machine password? */
120 if (global_machine_password_needs_changing)
122 unsigned char new_trust_passwd[16];
123 generate_random_buffer(new_trust_passwd, 16, True);
124 res = res ? cli_nt_srv_pwset(srv_name, info->myhostname, new_trust_passwd, SEC_CHAN_WKSTA) : False;
128 global_machine_password_needs_changing = !set_trust_account_password(new_trust_passwd);
131 memset(new_trust_passwd, 0, 16);
135 memset(trust_passwd, 0, 16);
138 res = res ? cli_nt_login_interactive(srv_name, info->myhostname,
139 usr_creds->domain, nt_user_name,
140 getuid(), nt_password,
141 &info->dom.ctr, &info->dom.user_info3) : False;
143 /*** clear out the password ***/
144 memset(password, 0, sizeof(password));
146 /* ok! you're logged in! do anything you like, then... */
148 /* do an NT logout */
149 res = res ? cli_nt_logoff(srv_name, info->myhostname, &info->dom.ctr) : False;
151 report(out_hnd,"cmd_nt_login: login (%s) test succeeded: %s\n",
152 nt_user_name, BOOLSTR(res));
155 /****************************************************************************
156 experimental nt login.
157 ****************************************************************************/
158 void cmd_netlogon_domain_test(struct client_info *info, int argc, char *argv[])
162 unsigned char trust_passwd[16];
163 fstring inter_dom_acct;
166 fstrcpy(srv_name, "\\\\");
167 fstrcat(srv_name, info->dest_host);
172 report(out_hnd,"domtest: must specify domain name\n");
176 nt_trust_dom = argv[1];
178 DEBUG(5,("do_nt_login_test: domain %s\n", nt_trust_dom));
180 fstrcpy(inter_dom_acct, nt_trust_dom);
181 fstrcat(inter_dom_acct, "$");
183 res = res ? trust_get_passwd(trust_passwd, usr_creds->domain, nt_trust_dom) : False;
185 res = res ? cli_nt_setup_creds(srv_name, info->myhostname, inter_dom_acct,
187 SEC_CHAN_DOMAIN) == 0x0 : False;
189 memset(trust_passwd, 0, 16);
191 report(out_hnd,"cmd_nt_login: credentials (%s) test succeeded: %s\n",
192 nt_trust_dom, BOOLSTR(res));
195 /****************************************************************************
196 experimental SAM synchronisation.
197 ****************************************************************************/
198 void cmd_sam_sync(struct client_info *info, int argc, char *argv[])
200 SAM_DELTA_HDR hdr_deltas[MAX_SAM_DELTAS];
201 SAM_DELTA_CTR deltas[MAX_SAM_DELTAS];
203 uchar trust_passwd[16];
207 fstrcpy(srv_name, "\\\\");
208 fstrcat(srv_name, info->dest_host);
211 fstrcpy(trust_acct, info->myhostname);
212 fstrcat(trust_acct, "$");
214 if (!trust_get_passwd(trust_passwd, usr_creds->domain, info->myhostname))
216 report(out_hnd, "cmd_sam_sync: no trust account password\n");
220 if (net_sam_sync(srv_name, info->myhostname,
221 trust_acct, trust_passwd,
222 hdr_deltas, deltas, &num))
224 display_sam_sync(out_hnd, ACTION_HEADER , hdr_deltas, deltas, num);
225 display_sam_sync(out_hnd, ACTION_ENUMERATE, hdr_deltas, deltas, num);
226 display_sam_sync(out_hnd, ACTION_FOOTER , hdr_deltas, deltas, num);