summaryrefslogtreecommitdiff
path: root/source3/rpc_client/ntclienttrust.c
blob: 0486017181747b0c46f0fcc04c89cf59af43036b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/* 
   Unix SMB/Netbios implementation.
   Version 1.9.
   NT Domain Authentication SMB / MSRPC client
   Copyright (C) Andrew Tridgell 1994-1997
   Copyright (C) Luke Kenneth Casson Leighton 1996-1997
   
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.
   
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
   
   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#ifdef SYSLOG
#undef SYSLOG
#endif

#include "includes.h"
#include "nterr.h"

extern int DEBUGLEVEL;


/************************************************************************
 check workstation trust account status
 ************************************************************************/
BOOL trust_account_check(struct in_addr dest_ip, char *dest_host,
				char *myhostname, char *domain, fstring mach_acct,
				fstring new_mach_pwd)
{
	pstring tmp;
	fstring mach_pwd;
	struct cli_state cli_trust;
	uchar lm_owf_mach_pwd[16];
	uchar nt_owf_mach_pwd[16];
	uchar lm_sess_pwd[24];
	uchar nt_sess_pwd[24];

	BOOL right_error_code = False;
	uint8 err_cls;
	uint32 err_num;

	char *start_mach_pwd;
	char *change_mach_pwd;

	/* initial machine password */
	fstrcpy(mach_pwd, myhostname);
	strlower(mach_pwd);

	slprintf(tmp, sizeof(tmp) - 1,"Enter Workstation Trust Account password for [%s].\nDefault is [%s].\nPassword:",
				mach_acct, mach_pwd);

	start_mach_pwd = (char*)getpass(tmp);

	if (start_mach_pwd[0] != 0)
	{
		fstrcpy(mach_pwd, start_mach_pwd);
	}

	slprintf(tmp, sizeof(tmp)-1, "Enter new Workstation Trust Account password for [%s]\nPress Return to leave at old value.\nNew Password:",
				mach_acct);

	change_mach_pwd = (char*)getpass(tmp);

	if (change_mach_pwd[0] != 0)
	{
		fstrcpy(new_mach_pwd, change_mach_pwd);
	}
	else
	{
		DEBUG(1,("trust_account_check: password change not requested\n"));
		change_mach_pwd[0] = 0;
	}

	DEBUG(1,("initialise cli_trust connection\n"));

	if (!cli_initialise(&cli_trust))
	{
		DEBUG(1,("cli_initialise failed for cli_trust\n"));
		return False;
	}

	DEBUG(1,("server connect for cli_trust\n"));

	if (!server_connect_init(&cli_trust, myhostname, dest_ip, dest_host))
	{
		cli_error(&cli_trust, &err_cls, &err_num);
		DEBUG(1,("server_connect_init failed (%s)\n", cli_errstr(&cli_trust)));

		cli_shutdown(&cli_trust);
		return False;
	}

	DEBUG(1,("server connect cli_trust succeeded\n"));

	nt_lm_owf_gen(mach_pwd, nt_owf_mach_pwd, lm_owf_mach_pwd);

	DEBUG(5,("generating nt owf from initial machine pwd: %s\n", mach_pwd));

#ifdef DEBUG_PASSWORD
	DEBUG(100,("client cryptkey: "));
	dump_data(100, cli_trust.cryptkey, sizeof(cli_trust.cryptkey));
#endif

	SMBencrypt(nt_owf_mach_pwd, cli_trust.cryptkey, nt_sess_pwd);

#ifdef DEBUG_PASSWORD
	DEBUG(100,("nt_owf_mach_pwd: "));
	dump_data(100, nt_owf_mach_pwd, sizeof(lm_owf_mach_pwd));
	DEBUG(100,("nt_sess_pwd: "));
	dump_data(100, nt_sess_pwd, sizeof(nt_sess_pwd));
#endif

	SMBencrypt(lm_owf_mach_pwd, cli_trust.cryptkey, lm_sess_pwd);

#ifdef DEBUG_PASSWORD
	DEBUG(100,("lm_owf_mach_pwd: "));
	dump_data(100, lm_owf_mach_pwd, sizeof(lm_owf_mach_pwd));
	DEBUG(100,("lm_sess_pwd: "));
	dump_data(100, lm_sess_pwd, sizeof(lm_sess_pwd));
#endif

	right_error_code = False;

	if (cli_session_setup(&cli_trust, mach_acct, 
			nt_owf_mach_pwd, sizeof(nt_owf_mach_pwd),
			nt_owf_mach_pwd, sizeof(nt_owf_mach_pwd), domain))
	{
		DEBUG(0,("cli_session_setup: NO ERROR! AAAGH! BUG IN SERVER DETECTED!!!\n"));
		cli_shutdown(&cli_trust);
	
		return False;
	}

	cli_error(&cli_trust, &err_cls, &err_num);

	if (err_num == (0xC0000000 | NT_STATUS_NOLOGON_WORKSTATION_TRUST_ACCOUNT))
	{
		DEBUG(1,("cli_send_tconX: valid workstation trust account exists\n"));
		right_error_code = True;
	}

	if (err_num == (0xC0000000 | NT_STATUS_NO_SUCH_USER))
	{
		DEBUG(1,("cli_send_tconX: workstation trust account does not exist\n"));
		right_error_code = False;
	}

	if (!right_error_code)
	{
		DEBUG(1,("server_validate failed (%s)\n", cli_errstr(&cli_trust)));
	}

	cli_shutdown(&cli_trust);
	return right_error_code;
}