2008-02-17 04:10:43 +03:00
/*
2002-08-17 20:05:44 +04:00
Unix SMB / CIFS implementation .
NT Domain Authentication SMB / MSRPC client
Copyright ( C ) Andrew Tridgell 1992 - 2000
Copyright ( C ) Jeremy Allison 1998.
2005-09-30 21:13:37 +04:00
Largely re - written by Jeremy Allison ( C ) 2005.
2008-02-27 21:38:48 +03:00
Copyright ( C ) Guenther Deschner 2008.
2005-09-30 21:13:37 +04:00
2002-08-17 20:05:44 +04:00
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
2007-07-09 23:25:36 +04:00
the Free Software Foundation ; either version 3 of the License , or
2002-08-17 20:05:44 +04:00
( at your option ) any later version .
2008-02-17 04:10:43 +03:00
2002-08-17 20:05:44 +04:00
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 .
2008-02-17 04:10:43 +03:00
2002-08-17 20:05:44 +04:00
You should have received a copy of the GNU General Public License
2007-07-10 04:52:41 +04:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2002-08-17 20:05:44 +04:00
*/
1998-03-12 00:11:04 +03:00
# include "includes.h"
2011-04-13 16:32:16 +04:00
# include "rpc_client/rpc_client.h"
2009-03-16 13:27:58 +03:00
# include "../libcli/auth/libcli_auth.h"
2011-01-12 13:36:06 +03:00
# include "../librpc/gen_ndr/ndr_netlogon_c.h"
2010-05-18 20:26:03 +04:00
# include "rpc_client/cli_netlogon.h"
2010-05-28 03:19:25 +04:00
# include "rpc_client/init_netlogon.h"
2011-01-07 19:28:29 +03:00
# include "rpc_client/util_netlogon.h"
# include "../libcli/security/security.h"
1998-03-12 00:11:04 +03:00
2005-09-30 21:13:37 +04:00
/****************************************************************************
Wrapper function that uses the auth and auth2 calls to set up a NETLOGON
credentials chain . Stores the credentials in the struct dcinfo in the
netlogon pipe struct .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-08-17 20:05:44 +04:00
2005-09-30 21:13:37 +04:00
NTSTATUS rpccli_netlogon_setup_creds ( struct rpc_pipe_client * cli ,
2008-02-16 01:57:19 +03:00
const char * server_name ,
const char * domain ,
const char * clnt_name ,
const char * machine_account ,
const unsigned char machine_pwd [ 16 ] ,
enum netr_SchannelType sec_chan_type ,
uint32_t * neg_flags_inout )
2002-08-17 20:05:44 +04:00
{
2011-01-12 13:36:06 +03:00
NTSTATUS status ;
2005-10-27 22:06:29 +04:00
NTSTATUS result = NT_STATUS_UNSUCCESSFUL ;
2008-02-16 01:57:19 +03:00
struct netr_Credential clnt_chal_send ;
struct netr_Credential srv_chal_recv ;
2009-04-06 16:56:13 +04:00
struct samr_Password password ;
2008-04-02 04:29:48 +04:00
bool retried = false ;
2009-04-06 16:56:13 +04:00
fstring mach_acct ;
2010-02-20 01:22:40 +03:00
uint32_t neg_flags = * neg_flags_inout ;
2011-01-12 13:36:06 +03:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
2002-08-17 20:05:44 +04:00
2009-04-22 18:44:11 +04:00
if ( ! ndr_syntax_id_equal ( & cli - > abstract_syntax ,
& ndr_table_netlogon . syntax_id ) ) {
return NT_STATUS_INVALID_PARAMETER ;
}
2002-08-17 20:05:44 +04:00
2008-07-20 12:40:43 +04:00
TALLOC_FREE ( cli - > dc ) ;
2005-09-30 21:13:37 +04:00
/* Store the machine account password we're going to use. */
2009-04-06 16:56:13 +04:00
memcpy ( password . hash , machine_pwd , 16 ) ;
2002-08-17 20:05:44 +04:00
2009-04-06 16:56:13 +04:00
fstr_sprintf ( mach_acct , " %s$ " , machine_account ) ;
2005-09-30 21:13:37 +04:00
2008-04-02 04:29:48 +04:00
again :
2005-09-30 21:13:37 +04:00
/* Create the client challenge. */
generate_random_buffer ( clnt_chal_send . data , 8 ) ;
/* Get the server challenge. */
2011-01-12 13:36:06 +03:00
status = dcerpc_netr_ServerReqChallenge ( b , talloc_tos ( ) ,
2009-04-06 16:56:13 +04:00
cli - > srv_name_slash ,
2008-02-16 01:57:19 +03:00
clnt_name ,
& clnt_chal_send ,
2011-01-12 13:36:06 +03:00
& srv_chal_recv ,
& result ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return status ;
}
2005-09-30 21:13:37 +04:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
return result ;
}
/* Calculate the session key and client credentials */
2011-02-03 23:47:42 +03:00
2009-04-06 16:56:13 +04:00
cli - > dc = netlogon_creds_client_init ( cli ,
2009-04-24 05:09:20 +04:00
mach_acct ,
2009-04-06 16:56:13 +04:00
clnt_name ,
& clnt_chal_send ,
& srv_chal_recv ,
& password ,
& clnt_chal_send ,
2010-02-20 01:22:40 +03:00
neg_flags ) ;
2009-04-06 16:56:13 +04:00
if ( ! cli - > dc ) {
return NT_STATUS_NO_MEMORY ;
}
2002-08-17 20:05:44 +04:00
2008-02-17 04:10:43 +03:00
/*
* Send client auth - 2 challenge and receive server repy .
*/
2005-09-30 21:13:37 +04:00
2011-01-12 13:36:06 +03:00
status = dcerpc_netr_ServerAuthenticate2 ( b , talloc_tos ( ) ,
2009-04-06 16:56:13 +04:00
cli - > srv_name_slash ,
cli - > dc - > account_name ,
2008-02-16 01:57:19 +03:00
sec_chan_type ,
2009-04-06 16:56:13 +04:00
cli - > dc - > computer_name ,
2008-02-16 01:57:19 +03:00
& clnt_chal_send , /* input. */
& srv_chal_recv , /* output. */
2011-01-12 13:36:06 +03:00
& neg_flags ,
& result ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return status ;
}
2008-04-02 04:29:48 +04:00
/* we might be talking to NT4, so let's downgrade in that case and retry
* with the returned neg_flags - gd */
if ( NT_STATUS_EQUAL ( result , NT_STATUS_ACCESS_DENIED ) & & ! retried ) {
2009-04-24 05:09:20 +04:00
retried = true ;
2009-04-06 16:56:13 +04:00
TALLOC_FREE ( cli - > dc ) ;
2008-04-02 04:29:48 +04:00
goto again ;
}
2005-09-30 21:13:37 +04:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
return result ;
2002-09-25 19:19:00 +04:00
}
2002-08-17 20:05:44 +04:00
2005-09-30 21:13:37 +04:00
/*
* Check the returned value using the initial
* server received challenge .
*/
2002-08-17 20:05:44 +04:00
2009-04-06 16:56:13 +04:00
if ( ! netlogon_creds_client_check ( cli - > dc , & srv_chal_recv ) ) {
2005-09-30 21:13:37 +04:00
/*
* Server replied with bad credential . Fail .
*/
DEBUG ( 0 , ( " rpccli_netlogon_setup_creds: server %s "
" replied with bad credential \n " ,
2008-04-19 23:56:43 +04:00
cli - > desthost ) ) ;
2005-09-30 21:13:37 +04:00
return NT_STATUS_ACCESS_DENIED ;
}
DEBUG ( 5 , ( " rpccli_netlogon_setup_creds: server %s credential "
" chain established. \n " ,
2008-04-19 23:56:43 +04:00
cli - > desthost ) ) ;
2005-09-30 21:13:37 +04:00
2010-02-20 01:22:40 +03:00
cli - > dc - > negotiate_flags = neg_flags ;
* neg_flags_inout = neg_flags ;
2005-09-30 21:13:37 +04:00
return NT_STATUS_OK ;
2002-08-17 20:05:44 +04:00
}
/* Logon domain user */
2005-09-30 21:13:37 +04:00
NTSTATUS rpccli_netlogon_sam_logon ( struct rpc_pipe_client * cli ,
2005-11-08 09:19:34 +03:00
TALLOC_CTX * mem_ctx ,
uint32 logon_parameters ,
const char * domain ,
const char * username ,
const char * password ,
2007-01-23 13:51:35 +03:00
const char * workstation ,
2011-01-21 18:58:32 +03:00
uint16_t validation_level ,
2005-11-08 09:19:34 +03:00
int logon_type )
2002-08-17 20:05:44 +04:00
{
NTSTATUS result = NT_STATUS_UNSUCCESSFUL ;
2011-01-12 13:36:06 +03:00
NTSTATUS status ;
2008-02-17 04:10:43 +03:00
struct netr_Authenticator clnt_creds ;
struct netr_Authenticator ret_creds ;
2008-10-15 18:14:15 +04:00
union netr_LogonLevel * logon ;
2008-02-17 04:10:43 +03:00
union netr_Validation validation ;
uint8_t authoritative ;
2005-09-30 21:13:37 +04:00
fstring clnt_name_slash ;
2011-01-12 13:36:06 +03:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
2002-08-17 20:05:44 +04:00
2005-09-30 21:13:37 +04:00
ZERO_STRUCT ( ret_creds ) ;
2008-02-17 04:10:43 +03:00
2008-10-15 18:14:15 +04:00
logon = TALLOC_ZERO_P ( mem_ctx , union netr_LogonLevel ) ;
2008-02-17 04:10:43 +03:00
if ( ! logon ) {
return NT_STATUS_NO_MEMORY ;
}
2002-08-17 20:05:44 +04:00
2007-01-23 13:51:35 +03:00
if ( workstation ) {
fstr_sprintf ( clnt_name_slash , " \\ \\ %s " , workstation ) ;
} else {
fstr_sprintf ( clnt_name_slash , " \\ \\ %s " , global_myname ( ) ) ;
}
2002-08-17 20:05:44 +04:00
2008-02-17 04:10:43 +03:00
/* Initialise input parameters */
2002-08-17 20:05:44 +04:00
2009-04-06 16:56:13 +04:00
netlogon_creds_client_authenticator ( cli - > dc , & clnt_creds ) ;
2002-08-17 20:05:44 +04:00
2008-02-17 04:10:43 +03:00
switch ( logon_type ) {
2008-10-15 18:14:15 +04:00
case NetlogonInteractiveInformation : {
2002-08-17 20:05:44 +04:00
2008-02-17 04:10:43 +03:00
struct netr_PasswordInfo * password_info ;
2002-08-17 20:05:44 +04:00
2008-02-17 04:10:43 +03:00
struct samr_Password lmpassword ;
struct samr_Password ntpassword ;
2002-08-17 20:05:44 +04:00
2008-02-17 04:10:43 +03:00
password_info = TALLOC_ZERO_P ( mem_ctx , struct netr_PasswordInfo ) ;
if ( ! password_info ) {
return NT_STATUS_NO_MEMORY ;
}
2002-08-17 20:05:44 +04:00
2009-04-06 16:56:13 +04:00
nt_lm_owf_gen ( password , ntpassword . hash , lmpassword . hash ) ;
2002-08-17 20:05:44 +04:00
2009-04-06 16:56:13 +04:00
if ( cli - > dc - > negotiate_flags & NETLOGON_NEG_ARCFOUR ) {
netlogon_creds_arcfour_crypt ( cli - > dc , lmpassword . hash , 16 ) ;
netlogon_creds_arcfour_crypt ( cli - > dc , ntpassword . hash , 16 ) ;
} else {
netlogon_creds_des_encrypt ( cli - > dc , & lmpassword ) ;
netlogon_creds_des_encrypt ( cli - > dc , & ntpassword ) ;
}
2008-02-17 04:10:43 +03:00
2009-06-25 18:38:39 +04:00
password_info - > identity_info . domain_name . string = domain ;
password_info - > identity_info . parameter_control = logon_parameters ;
password_info - > identity_info . logon_id_low = 0xdead ;
password_info - > identity_info . logon_id_high = 0xbeef ;
password_info - > identity_info . account_name . string = username ;
password_info - > identity_info . workstation . string = clnt_name_slash ;
password_info - > lmpassword = lmpassword ;
password_info - > ntpassword = ntpassword ;
2008-02-17 04:10:43 +03:00
logon - > password = password_info ;
break ;
}
2008-10-15 18:14:15 +04:00
case NetlogonNetworkInformation : {
2008-02-17 04:10:43 +03:00
struct netr_NetworkInfo * network_info ;
uint8 chal [ 8 ] ;
unsigned char local_lm_response [ 24 ] ;
unsigned char local_nt_response [ 24 ] ;
struct netr_ChallengeResponse lm ;
struct netr_ChallengeResponse nt ;
2008-02-19 03:48:58 +03:00
ZERO_STRUCT ( lm ) ;
ZERO_STRUCT ( nt ) ;
2008-02-17 04:10:43 +03:00
network_info = TALLOC_ZERO_P ( mem_ctx , struct netr_NetworkInfo ) ;
if ( ! network_info ) {
return NT_STATUS_NO_MEMORY ;
}
generate_random_buffer ( chal , 8 ) ;
SMBencrypt ( password , chal , local_lm_response ) ;
SMBNTencrypt ( password , chal , local_nt_response ) ;
lm . length = 24 ;
lm . data = local_lm_response ;
1998-04-24 02:45:53 +04:00
2008-02-17 04:10:43 +03:00
nt . length = 24 ;
nt . data = local_nt_response ;
2009-06-25 18:38:39 +04:00
network_info - > identity_info . domain_name . string = domain ;
network_info - > identity_info . parameter_control = logon_parameters ;
network_info - > identity_info . logon_id_low = 0xdead ;
network_info - > identity_info . logon_id_high = 0xbeef ;
network_info - > identity_info . account_name . string = username ;
network_info - > identity_info . workstation . string = clnt_name_slash ;
memcpy ( network_info - > challenge , chal , 8 ) ;
network_info - > nt = nt ;
network_info - > lm = lm ;
2008-02-17 04:10:43 +03:00
logon - > network = network_info ;
break ;
}
default :
DEBUG ( 0 , ( " switch value %d not supported \n " ,
logon_type ) ) ;
return NT_STATUS_INVALID_INFO_CLASS ;
}
2011-01-12 13:36:06 +03:00
status = dcerpc_netr_LogonSamLogon ( b , mem_ctx ,
2009-04-06 16:56:13 +04:00
cli - > srv_name_slash ,
2008-02-17 04:10:43 +03:00
global_myname ( ) ,
& clnt_creds ,
& ret_creds ,
logon_type ,
logon ,
validation_level ,
& validation ,
2011-01-12 13:36:06 +03:00
& authoritative ,
& result ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return status ;
}
2008-02-17 04:10:43 +03:00
2009-04-06 16:56:13 +04:00
/* Always check returned credentials */
if ( ! netlogon_creds_client_check ( cli - > dc , & ret_creds . cred ) ) {
DEBUG ( 0 , ( " rpccli_netlogon_sam_logon: credentials chain check failed \n " ) ) ;
return NT_STATUS_ACCESS_DENIED ;
2005-09-30 21:13:37 +04:00
}
2002-08-17 20:05:44 +04:00
2008-02-17 04:10:43 +03:00
return result ;
2001-02-24 03:42:41 +03:00
}
2011-01-07 19:28:29 +03:00
static NTSTATUS map_validation_to_info3 ( TALLOC_CTX * mem_ctx ,
uint16_t validation_level ,
union netr_Validation * validation ,
struct netr_SamInfo3 * * info3_p )
{
struct netr_SamInfo3 * info3 ;
NTSTATUS status ;
if ( validation = = NULL ) {
return NT_STATUS_INVALID_PARAMETER ;
}
switch ( validation_level ) {
case 3 :
if ( validation - > sam3 = = NULL ) {
return NT_STATUS_INVALID_PARAMETER ;
}
info3 = talloc_move ( mem_ctx , & validation - > sam3 ) ;
break ;
case 6 :
if ( validation - > sam6 = = NULL ) {
return NT_STATUS_INVALID_PARAMETER ;
}
info3 = talloc_zero ( mem_ctx , struct netr_SamInfo3 ) ;
if ( info3 = = NULL ) {
return NT_STATUS_NO_MEMORY ;
}
status = copy_netr_SamBaseInfo ( info3 , & validation - > sam6 - > base , & info3 - > base ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
TALLOC_FREE ( info3 ) ;
return status ;
}
info3 - > sidcount = validation - > sam6 - > sidcount ;
info3 - > sids = talloc_move ( info3 , & validation - > sam6 - > sids ) ;
break ;
default :
return NT_STATUS_BAD_VALIDATION_CLASS ;
}
* info3_p = info3 ;
return NT_STATUS_OK ;
}
2001-02-24 03:42:41 +03:00
2008-02-17 04:10:43 +03:00
/**
* Logon domain user with an ' network ' SAM logon
2002-08-17 20:05:44 +04:00
*
* @ param info3 Pointer to a NET_USER_INFO_3 already allocated by the caller .
* */
2005-06-09 02:10:34 +04:00
NTSTATUS rpccli_netlogon_sam_network_logon ( struct rpc_pipe_client * cli ,
TALLOC_CTX * mem_ctx ,
2005-11-08 09:19:34 +03:00
uint32 logon_parameters ,
2005-09-30 21:13:37 +04:00
const char * server ,
2005-06-09 02:10:34 +04:00
const char * username ,
const char * domain ,
2008-02-17 04:10:43 +03:00
const char * workstation ,
const uint8 chal [ 8 ] ,
2011-01-07 19:28:29 +03:00
uint16_t validation_level ,
2005-06-09 02:10:34 +04:00
DATA_BLOB lm_response ,
DATA_BLOB nt_response ,
2008-02-17 04:10:43 +03:00
struct netr_SamInfo3 * * info3 )
2001-02-24 03:42:41 +03:00
{
2002-08-17 20:05:44 +04:00
NTSTATUS result = NT_STATUS_UNSUCCESSFUL ;
2011-01-12 13:36:06 +03:00
NTSTATUS status ;
2005-09-30 21:13:37 +04:00
const char * workstation_name_slash ;
const char * server_name_slash ;
2008-02-17 04:10:43 +03:00
struct netr_Authenticator clnt_creds ;
struct netr_Authenticator ret_creds ;
2008-10-15 18:14:15 +04:00
union netr_LogonLevel * logon = NULL ;
2008-02-17 04:10:43 +03:00
struct netr_NetworkInfo * network_info ;
uint8_t authoritative ;
union netr_Validation validation ;
struct netr_ChallengeResponse lm ;
struct netr_ChallengeResponse nt ;
2011-01-12 13:36:06 +03:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
2008-02-17 04:10:43 +03:00
* info3 = NULL ;
2007-12-28 19:02:34 +03:00
2005-09-30 21:13:37 +04:00
ZERO_STRUCT ( ret_creds ) ;
2001-02-24 03:42:41 +03:00
2008-02-19 03:48:58 +03:00
ZERO_STRUCT ( lm ) ;
ZERO_STRUCT ( nt ) ;
2008-10-15 18:14:15 +04:00
logon = TALLOC_ZERO_P ( mem_ctx , union netr_LogonLevel ) ;
2008-02-17 04:10:43 +03:00
if ( ! logon ) {
return NT_STATUS_NO_MEMORY ;
}
network_info = TALLOC_ZERO_P ( mem_ctx , struct netr_NetworkInfo ) ;
if ( ! network_info ) {
return NT_STATUS_NO_MEMORY ;
}
2009-04-06 16:56:13 +04:00
netlogon_creds_client_authenticator ( cli - > dc , & clnt_creds ) ;
2005-09-30 21:13:37 +04:00
if ( server [ 0 ] ! = ' \\ ' & & server [ 1 ] ! = ' \\ ' ) {
server_name_slash = talloc_asprintf ( mem_ctx , " \\ \\ %s " , server ) ;
} else {
server_name_slash = server ;
2002-08-17 20:05:44 +04:00
}
2001-02-24 03:42:41 +03:00
2005-09-30 21:13:37 +04:00
if ( workstation [ 0 ] ! = ' \\ ' & & workstation [ 1 ] ! = ' \\ ' ) {
workstation_name_slash = talloc_asprintf ( mem_ctx , " \\ \\ %s " , workstation ) ;
} else {
workstation_name_slash = workstation ;
}
2001-02-24 03:42:41 +03:00
2005-09-30 21:13:37 +04:00
if ( ! workstation_name_slash | | ! server_name_slash ) {
DEBUG ( 0 , ( " talloc_asprintf failed! \n " ) ) ;
return NT_STATUS_NO_MEMORY ;
}
2001-02-24 03:42:41 +03:00
2002-08-17 20:05:44 +04:00
/* Initialise input parameters */
2001-02-24 03:42:41 +03:00
2008-02-17 04:10:43 +03:00
lm . data = lm_response . data ;
lm . length = lm_response . length ;
nt . data = nt_response . data ;
nt . length = nt_response . length ;
2009-06-25 18:38:39 +04:00
network_info - > identity_info . domain_name . string = domain ;
network_info - > identity_info . parameter_control = logon_parameters ;
network_info - > identity_info . logon_id_low = 0xdead ;
network_info - > identity_info . logon_id_high = 0xbeef ;
network_info - > identity_info . account_name . string = username ;
network_info - > identity_info . workstation . string = workstation_name_slash ;
memcpy ( network_info - > challenge , chal , 8 ) ;
network_info - > nt = nt ;
network_info - > lm = lm ;
2008-02-17 04:10:43 +03:00
logon - > network = network_info ;
/* Marshall data and send request */
2011-01-12 13:36:06 +03:00
status = dcerpc_netr_LogonSamLogon ( b , mem_ctx ,
2008-02-17 04:10:43 +03:00
server_name_slash ,
global_myname ( ) ,
& clnt_creds ,
& ret_creds ,
2008-10-15 18:14:15 +04:00
NetlogonNetworkInformation ,
2008-02-17 04:10:43 +03:00
logon ,
validation_level ,
& validation ,
2011-01-12 13:36:06 +03:00
& authoritative ,
& result ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return status ;
Changes all over the shop, but all towards:
- NTLM2 support in the server
- KEY_EXCH support in the server
- variable length session keys.
In detail:
- NTLM2 is an extension of NTLMv1, that is compatible with existing
domain controllers (unlike NTLMv2, which requires a DC upgrade).
* This is known as 'NTLMv2 session security' *
(This is not yet implemented on the RPC pipes however, so there may
well still be issues for PDC setups, particuarly around password
changes. We do not fully understand the sign/seal implications of
NTLM2 on RPC pipes.)
This requires modifications to our authentication subsystem, as we
must handle the 'challege' input into the challenge-response algorithm
being changed. This also needs to be turned off for
'security=server', which does not support this.
- KEY_EXCH is another 'security' mechanism, whereby the session key
actually used by the server is sent by the client, rather than being
the shared-secret directly or indirectly.
- As both these methods change the session key, the auth subsystem
needed to be changed, to 'override' session keys provided by the
backend.
- There has also been a major overhaul of the NTLMSSP subsystem, to merge the 'client' and 'server' functions, so they both operate on a single structure. This should help the SPNEGO implementation.
- The 'names blob' in NTLMSSP is always in unicode - never in ascii.
Don't make an ascii version ever.
- The other big change is to allow variable length session keys. We
have always assumed that session keys are 16 bytes long - and padded
to this length if shorter. However, Kerberos session keys are 8 bytes
long, when the krb5 login uses DES.
* This fix allows SMB signging on machines not yet running MIT KRB5 1.3.1. *
- Add better DEBUG() messages to ntlm_auth, warning administrators of
misconfigurations that prevent access to the privileged pipe. This
should help reduce some of the 'it just doesn't work' issues.
- Fix data_blob_talloc() to behave the same way data_blob() does when
passed a NULL data pointer. (just allocate)
REMEMBER to make clean after this commit - I have changed plenty of data structures...
(This used to be commit f3bbc87b0dac63426cda6fac7a295d3aad810ecc)
2003-11-22 16:19:38 +03:00
}
2009-04-06 16:56:13 +04:00
/* Always check returned credentials. */
if ( ! netlogon_creds_client_check ( cli - > dc , & ret_creds . cred ) ) {
DEBUG ( 0 , ( " rpccli_netlogon_sam_network_logon: credentials chain check failed \n " ) ) ;
return NT_STATUS_ACCESS_DENIED ;
2008-02-17 04:10:43 +03:00
}
2002-08-17 20:05:44 +04:00
2011-01-12 13:36:06 +03:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
return result ;
}
2009-04-06 16:56:13 +04:00
netlogon_creds_decrypt_samlogon ( cli - > dc , validation_level , & validation ) ;
2002-08-17 20:05:44 +04:00
2011-01-07 19:28:29 +03:00
result = map_validation_to_info3 ( mem_ctx , validation_level , & validation , info3 ) ;
if ( ! NT_STATUS_IS_OK ( result ) ) {
return result ;
}
2008-02-17 04:10:43 +03:00
return result ;
2002-08-17 20:05:44 +04:00
}
2007-05-23 19:17:49 +04:00
NTSTATUS rpccli_netlogon_sam_network_logon_ex ( struct rpc_pipe_client * cli ,
TALLOC_CTX * mem_ctx ,
uint32 logon_parameters ,
const char * server ,
const char * username ,
const char * domain ,
2008-02-17 04:10:43 +03:00
const char * workstation ,
const uint8 chal [ 8 ] ,
2011-01-07 19:28:29 +03:00
uint16_t validation_level ,
2007-05-23 19:17:49 +04:00
DATA_BLOB lm_response ,
DATA_BLOB nt_response ,
2008-02-17 04:37:12 +03:00
struct netr_SamInfo3 * * info3 )
2007-05-23 19:17:49 +04:00
{
NTSTATUS result = NT_STATUS_UNSUCCESSFUL ;
2011-01-12 13:36:06 +03:00
NTSTATUS status ;
2007-05-23 19:17:49 +04:00
const char * workstation_name_slash ;
const char * server_name_slash ;
2008-10-15 18:14:15 +04:00
union netr_LogonLevel * logon = NULL ;
2008-02-17 04:37:12 +03:00
struct netr_NetworkInfo * network_info ;
uint8_t authoritative ;
union netr_Validation validation ;
struct netr_ChallengeResponse lm ;
struct netr_ChallengeResponse nt ;
uint32_t flags = 0 ;
2011-01-12 13:36:06 +03:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
2008-02-17 04:37:12 +03:00
* info3 = NULL ;
2007-12-28 19:02:34 +03:00
2008-02-19 03:48:58 +03:00
ZERO_STRUCT ( lm ) ;
ZERO_STRUCT ( nt ) ;
2008-10-15 18:14:15 +04:00
logon = TALLOC_ZERO_P ( mem_ctx , union netr_LogonLevel ) ;
2008-02-17 04:37:12 +03:00
if ( ! logon ) {
return NT_STATUS_NO_MEMORY ;
}
network_info = TALLOC_ZERO_P ( mem_ctx , struct netr_NetworkInfo ) ;
if ( ! network_info ) {
return NT_STATUS_NO_MEMORY ;
}
2007-05-23 19:17:49 +04:00
if ( server [ 0 ] ! = ' \\ ' & & server [ 1 ] ! = ' \\ ' ) {
server_name_slash = talloc_asprintf ( mem_ctx , " \\ \\ %s " , server ) ;
} else {
server_name_slash = server ;
}
if ( workstation [ 0 ] ! = ' \\ ' & & workstation [ 1 ] ! = ' \\ ' ) {
workstation_name_slash = talloc_asprintf ( mem_ctx , " \\ \\ %s " , workstation ) ;
} else {
workstation_name_slash = workstation ;
}
if ( ! workstation_name_slash | | ! server_name_slash ) {
DEBUG ( 0 , ( " talloc_asprintf failed! \n " ) ) ;
return NT_STATUS_NO_MEMORY ;
}
/* Initialise input parameters */
2008-02-17 04:37:12 +03:00
lm . data = lm_response . data ;
lm . length = lm_response . length ;
nt . data = nt_response . data ;
nt . length = nt_response . length ;
2008-02-17 04:10:43 +03:00
2009-06-25 18:38:39 +04:00
network_info - > identity_info . domain_name . string = domain ;
network_info - > identity_info . parameter_control = logon_parameters ;
network_info - > identity_info . logon_id_low = 0xdead ;
network_info - > identity_info . logon_id_high = 0xbeef ;
network_info - > identity_info . account_name . string = username ;
network_info - > identity_info . workstation . string = workstation_name_slash ;
memcpy ( network_info - > challenge , chal , 8 ) ;
network_info - > nt = nt ;
network_info - > lm = lm ;
2007-05-23 19:17:49 +04:00
2008-02-17 04:37:12 +03:00
logon - > network = network_info ;
2007-05-23 19:17:49 +04:00
/* Marshall data and send request */
2011-01-12 13:36:06 +03:00
status = dcerpc_netr_LogonSamLogonEx ( b , mem_ctx ,
2008-02-17 04:37:12 +03:00
server_name_slash ,
global_myname ( ) ,
2008-10-15 18:14:15 +04:00
NetlogonNetworkInformation ,
2008-02-17 04:37:12 +03:00
logon ,
validation_level ,
& validation ,
& authoritative ,
2011-01-12 13:36:06 +03:00
& flags ,
& result ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return status ;
}
2008-02-17 04:37:12 +03:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
return result ;
2007-05-23 19:17:49 +04:00
}
2009-04-06 16:56:13 +04:00
netlogon_creds_decrypt_samlogon ( cli - > dc , validation_level , & validation ) ;
2007-05-23 19:17:49 +04:00
2011-01-07 19:28:29 +03:00
result = map_validation_to_info3 ( mem_ctx , validation_level , & validation , info3 ) ;
if ( ! NT_STATUS_IS_OK ( result ) ) {
return result ;
}
2007-05-23 19:17:49 +04:00
2008-02-17 04:37:12 +03:00
return result ;
2007-05-23 19:17:49 +04:00
}
2008-09-21 20:57:26 +04:00
/*********************************************************
Change the domain password on the PDC .
Just changes the password betwen the two values specified .
Caller must have the cli connected to the netlogon pipe
already .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
NTSTATUS rpccli_netlogon_set_trust_password ( struct rpc_pipe_client * cli ,
TALLOC_CTX * mem_ctx ,
2009-10-08 02:34:05 +04:00
const char * account_name ,
2008-09-21 20:57:26 +04:00
const unsigned char orig_trust_passwd_hash [ 16 ] ,
const char * new_trust_pwd_cleartext ,
const unsigned char new_trust_passwd_hash [ 16 ] ,
2009-10-13 12:15:34 +04:00
enum netr_SchannelType sec_channel_type )
2008-09-21 20:57:26 +04:00
{
2011-01-12 13:36:06 +03:00
NTSTATUS result , status ;
2008-09-21 20:57:26 +04:00
struct netr_Authenticator clnt_creds , srv_cred ;
2011-01-12 13:36:06 +03:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
2008-09-21 20:57:26 +04:00
2009-10-05 19:04:52 +04:00
if ( ! cli - > dc ) {
2009-10-16 20:01:19 +04:00
uint32_t neg_flags = NETLOGON_NEG_AUTH2_ADS_FLAGS ;
2009-10-05 19:04:52 +04:00
result = rpccli_netlogon_setup_creds ( cli ,
cli - > desthost , /* server name */
lp_workgroup ( ) , /* domain */
global_myname ( ) , /* client name */
2009-10-08 02:34:05 +04:00
account_name , /* machine account name */
2009-10-05 19:04:52 +04:00
orig_trust_passwd_hash ,
sec_channel_type ,
& neg_flags ) ;
if ( ! NT_STATUS_IS_OK ( result ) ) {
DEBUG ( 3 , ( " rpccli_netlogon_set_trust_password: unable to setup creds (%s)! \n " ,
nt_errstr ( result ) ) ) ;
return result ;
}
2009-10-06 00:14:06 +04:00
}
2009-04-06 16:56:13 +04:00
netlogon_creds_client_authenticator ( cli - > dc , & clnt_creds ) ;
2008-09-21 20:57:26 +04:00
2009-10-16 20:01:19 +04:00
if ( cli - > dc - > negotiate_flags & NETLOGON_NEG_PASSWORD_SET2 ) {
2008-09-21 20:57:26 +04:00
struct netr_CryptPassword new_password ;
init_netr_CryptPassword ( new_trust_pwd_cleartext ,
2009-04-06 16:56:13 +04:00
cli - > dc - > session_key ,
2008-09-21 20:57:26 +04:00
& new_password ) ;
2011-01-12 13:36:06 +03:00
status = dcerpc_netr_ServerPasswordSet2 ( b , mem_ctx ,
2009-04-06 16:56:13 +04:00
cli - > srv_name_slash ,
cli - > dc - > account_name ,
2008-09-21 20:57:26 +04:00
sec_channel_type ,
2009-04-06 16:56:13 +04:00
cli - > dc - > computer_name ,
2008-09-21 20:57:26 +04:00
& clnt_creds ,
& srv_cred ,
2011-01-12 13:36:06 +03:00
& new_password ,
& result ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
DEBUG ( 0 , ( " dcerpc_netr_ServerPasswordSet2 failed: %s \n " ,
nt_errstr ( status ) ) ) ;
return status ;
2008-09-21 20:57:26 +04:00
}
} else {
struct samr_Password new_password ;
2009-04-06 16:56:13 +04:00
memcpy ( new_password . hash , new_trust_passwd_hash , sizeof ( new_password . hash ) ) ;
netlogon_creds_des_encrypt ( cli - > dc , & new_password ) ;
2008-09-21 20:57:26 +04:00
2011-01-12 13:36:06 +03:00
status = dcerpc_netr_ServerPasswordSet ( b , mem_ctx ,
2009-04-06 16:56:13 +04:00
cli - > srv_name_slash ,
cli - > dc - > account_name ,
2008-09-21 20:57:26 +04:00
sec_channel_type ,
2009-04-06 16:56:13 +04:00
cli - > dc - > computer_name ,
2008-09-21 20:57:26 +04:00
& clnt_creds ,
& srv_cred ,
2011-01-12 13:36:06 +03:00
& new_password ,
& result ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
DEBUG ( 0 , ( " dcerpc_netr_ServerPasswordSet failed: %s \n " ,
nt_errstr ( status ) ) ) ;
return status ;
2008-09-21 20:57:26 +04:00
}
}
/* Always check returned credentials. */
if ( ! netlogon_creds_client_check ( cli - > dc , & srv_cred . cred ) ) {
DEBUG ( 0 , ( " credentials chain check failed \n " ) ) ;
return NT_STATUS_ACCESS_DENIED ;
}
2011-01-12 13:36:06 +03:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
DEBUG ( 0 , ( " dcerpc_netr_ServerPasswordSet{2} failed: %s \n " ,
nt_errstr ( result ) ) ) ;
return result ;
}
2008-09-21 20:57:26 +04:00
return result ;
}