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"
2002-08-17 20:05:44 +04:00
/* LSA Request Challenge. Sends our challenge to server, then gets
2005-09-30 21:13:37 +04:00
server response . These are used to generate the credentials .
The sent and received challenges are stored in the netlog pipe
private data . Only call this via rpccli_netlogon_setup_creds ( ) . JRA .
*/
2002-08-17 20:05:44 +04:00
2008-02-16 02:05:45 +03:00
/* instead of rpccli_net_req_chal() we use rpccli_netr_ServerReqChallenge() now - gd */
2005-06-09 02:10:34 +04:00
2005-09-30 21:13:37 +04:00
#if 0
2002-08-17 20:05:44 +04:00
/****************************************************************************
LSA Authenticate 2
Send the client credential , receive back a server credential .
2008-02-17 04:10:43 +03:00
Ensure that the server credential returned matches the session key
2002-08-17 20:05:44 +04:00
encrypt of the server challenge originally received . JRA .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-02-17 04:10:43 +03:00
NTSTATUS rpccli_net_auth2 ( struct rpc_pipe_client * cli ,
uint16 sec_chan ,
2003-04-09 14:10:13 +04:00
uint32 * neg_flags , DOM_CHAL * srv_chal )
2002-08-17 20:05:44 +04:00
{
prs_struct qbuf , rbuf ;
NET_Q_AUTH_2 q ;
NET_R_AUTH_2 r ;
NTSTATUS result = NT_STATUS_UNSUCCESSFUL ;
2004-06-03 22:00:22 +04:00
fstring machine_acct ;
2002-08-17 20:05:44 +04:00
2004-06-03 22:00:22 +04:00
if ( sec_chan = = SEC_CHAN_DOMAIN )
fstr_sprintf ( machine_acct , " %s$ " , lp_workgroup ( ) ) ;
else
fstrcpy ( machine_acct , cli - > mach_acct ) ;
2008-02-17 04:10:43 +03:00
2002-08-17 20:05:44 +04:00
/* create and send a MSRPC command with api NET_AUTH2 */
DEBUG ( 4 , ( " cli_net_auth2: srv:%s acct:%s sc:%x mc: %s chal %s neg: %x \n " ,
2004-06-03 22:00:22 +04:00
cli - > srv_name_slash , machine_acct , sec_chan , global_myname ( ) ,
2003-04-14 09:24:59 +04:00
credstr ( cli - > clnt_cred . challenge . data ) , * neg_flags ) ) ;
2002-08-17 20:05:44 +04:00
/* store the parameters */
2004-06-03 22:00:22 +04:00
2008-02-17 04:10:43 +03:00
init_q_auth_2 ( & q , cli - > srv_name_slash , machine_acct ,
sec_chan , global_myname ( ) , & cli - > clnt_cred . challenge ,
2003-04-09 14:10:13 +04:00
* neg_flags ) ;
2002-08-17 20:05:44 +04:00
/* turn parameters into data stream */
2005-09-30 21:13:37 +04:00
CLI_DO_RPC ( cli , mem_ctx , PI_NETLOGON , NET_AUTH2 ,
q , r ,
qbuf , rbuf ,
net_io_q_auth_2 ,
net_io_r_auth_2 ,
NT_STATUS_UNSUCCESSFUL ) ;
2002-08-17 20:05:44 +04:00
result = r . status ;
if ( NT_STATUS_IS_OK ( result ) ) {
UTIME zerotime ;
2008-02-17 04:10:43 +03:00
2002-08-17 20:05:44 +04:00
/*
* Check the returned value using the initial
* server received challenge .
*/
zerotime . time = 0 ;
2005-09-30 21:13:37 +04:00
if ( cred_assert ( & r . srv_chal , cli - > sess_key , srv_chal , zerotime ) = = 0 ) {
2002-08-17 20:05:44 +04:00
/*
* Server replied with bad credential . Fail .
*/
DEBUG ( 0 , ( " cli_net_auth2: server %s replied with bad credential (bad machine \
2005-09-30 21:13:37 +04:00
password ? ) . \ n " , cli->cli->desthost ));
return NT_STATUS_ACCESS_DENIED ;
2002-08-17 20:05:44 +04:00
}
2003-04-09 14:10:13 +04:00
* neg_flags = r . srv_flgs . neg_flags ;
2002-08-17 20:05:44 +04:00
}
return result ;
}
2005-09-30 21:13:37 +04:00
# endif
/****************************************************************************
LSA Authenticate 2
2002-08-17 20:05:44 +04:00
2005-09-30 21:13:37 +04:00
Send the client credential , receive back a server credential .
2008-02-17 04:10:43 +03:00
The caller * must * ensure that the server credential returned matches the session key
2005-09-30 21:13:37 +04:00
encrypt of the server challenge originally received . JRA .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-02-16 02:05:45 +03:00
/* instead of rpccli_net_auth2() we use rpccli_netr_ServerAuthenticate2() now - gd */
2005-06-09 02:10:34 +04: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
{
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 ;
2005-09-30 21:13:37 +04:00
struct dcinfo * dc ;
2008-04-02 04:29:48 +04:00
bool retried = false ;
2002-08-17 20:05:44 +04:00
2005-09-30 21:13:37 +04:00
SMB_ASSERT ( cli - > pipe_idx = = PI_NETLOGON ) ;
2002-08-17 20:05:44 +04:00
2005-09-30 21:13:37 +04:00
dc = cli - > dc ;
if ( ! dc ) {
return NT_STATUS_INVALID_PARAMETER ;
}
2002-08-17 20:05:44 +04:00
2005-09-30 21:13:37 +04:00
/* Ensure we don't reuse any of this state. */
ZERO_STRUCTP ( dc ) ;
/* Store the machine account password we're going to use. */
memcpy ( dc - > mach_pw , machine_pwd , 16 ) ;
2002-08-17 20:05:44 +04:00
2005-09-30 21:13:37 +04:00
fstrcpy ( dc - > remote_machine , " \\ \\ " ) ;
fstrcat ( dc - > remote_machine , server_name ) ;
2002-08-17 20:05:44 +04:00
2005-09-30 21:13:37 +04:00
fstrcpy ( dc - > domain , domain ) ;
2002-08-17 20:05:44 +04:00
2005-09-30 21:13:37 +04:00
fstr_sprintf ( dc - > mach_acct , " %s$ " , machine_account ) ;
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. */
2008-04-19 20:17:13 +04:00
result = rpccli_netr_ServerReqChallenge ( cli , talloc_tos ( ) ,
2008-02-16 01:57:19 +03:00
dc - > remote_machine ,
clnt_name ,
& clnt_chal_send ,
& srv_chal_recv ) ;
2005-09-30 21:13:37 +04:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
return result ;
}
/* Calculate the session key and client credentials */
2006-02-17 07:22:32 +03:00
creds_client_init ( * neg_flags_inout ,
dc ,
2005-09-30 21:13:37 +04:00
& clnt_chal_send ,
& srv_chal_recv ,
machine_pwd ,
& clnt_chal_send ) ;
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
2008-04-19 20:17:13 +04:00
result = rpccli_netr_ServerAuthenticate2 ( cli , talloc_tos ( ) ,
2008-02-16 01:57:19 +03:00
dc - > remote_machine ,
dc - > mach_acct ,
sec_chan_type ,
clnt_name ,
& clnt_chal_send , /* input. */
& srv_chal_recv , /* output. */
neg_flags_inout ) ;
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 ) {
retried = true ;
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
2008-02-16 01:57:19 +03:00
if ( ! netlogon_creds_client_check ( 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 " ,
cli - > cli - > desthost ) ) ;
return NT_STATUS_ACCESS_DENIED ;
}
DEBUG ( 5 , ( " rpccli_netlogon_setup_creds: server %s credential "
" chain established. \n " ,
cli - > cli - > desthost ) ) ;
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 ,
2005-11-08 09:19:34 +03:00
int logon_type )
2002-08-17 20:05:44 +04:00
{
NTSTATUS result = NT_STATUS_UNSUCCESSFUL ;
2008-02-17 04:10:43 +03:00
struct netr_Authenticator clnt_creds ;
struct netr_Authenticator ret_creds ;
2008-03-27 15:03:12 +03:00
union netr_LogonInfo * logon ;
2008-02-17 04:10:43 +03:00
union netr_Validation validation ;
uint8_t authoritative ;
int validation_level = 3 ;
2005-09-30 21:13:37 +04:00
fstring clnt_name_slash ;
2008-02-17 04:10:43 +03:00
uint8 zeros [ 16 ] ;
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
ZERO_STRUCT ( zeros ) ;
2008-03-27 15:03:12 +03:00
logon = TALLOC_ZERO_P ( mem_ctx , union netr_LogonInfo ) ;
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
2008-02-17 04:10:43 +03:00
netlogon_creds_client_step ( cli - > dc , & clnt_creds ) ;
2002-08-17 20:05:44 +04:00
2008-02-17 04:10:43 +03:00
switch ( logon_type ) {
case INTERACTIVE_LOGON_TYPE : {
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
unsigned char lm_owf_user_pwd [ 16 ] , nt_owf_user_pwd [ 16 ] ;
2002-08-17 20:05:44 +04:00
2008-02-17 04:10:43 +03:00
unsigned char lm_owf [ 16 ] ;
unsigned char nt_owf [ 16 ] ;
unsigned char key [ 16 ] ;
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
2008-02-17 04:10:43 +03:00
nt_lm_owf_gen ( password , nt_owf_user_pwd , lm_owf_user_pwd ) ;
2005-09-30 21:13:37 +04:00
2008-02-17 04:10:43 +03:00
# ifdef DEBUG_PASSWORD
DEBUG ( 100 , ( " lm cypher: " ) ) ;
dump_data ( 100 , lm_owf_user_pwd , 16 ) ;
2002-08-17 20:05:44 +04:00
2008-02-17 04:10:43 +03:00
DEBUG ( 100 , ( " nt cypher: " ) ) ;
dump_data ( 100 , nt_owf_user_pwd , 16 ) ;
# endif
memset ( key , 0 , 16 ) ;
memcpy ( key , cli - > dc - > sess_key , 8 ) ;
2002-08-17 20:05:44 +04:00
2008-02-17 04:10:43 +03:00
memcpy ( lm_owf , lm_owf_user_pwd , 16 ) ;
SamOEMhash ( lm_owf , key , 16 ) ;
memcpy ( nt_owf , nt_owf_user_pwd , 16 ) ;
SamOEMhash ( nt_owf , key , 16 ) ;
1998-04-24 02:45:53 +04:00
2008-02-17 04:10:43 +03:00
# ifdef DEBUG_PASSWORD
DEBUG ( 100 , ( " encrypt of lm owf password: " ) ) ;
dump_data ( 100 , lm_owf , 16 ) ;
2002-08-17 20:05:44 +04:00
2008-02-17 04:10:43 +03:00
DEBUG ( 100 , ( " encrypt of nt owf password: " ) ) ;
dump_data ( 100 , nt_owf , 16 ) ;
# endif
memcpy ( lmpassword . hash , lm_owf , 16 ) ;
memcpy ( ntpassword . hash , nt_owf , 16 ) ;
init_netr_PasswordInfo ( password_info ,
domain ,
logon_parameters ,
0xdead ,
0xbeef ,
username ,
clnt_name_slash ,
lmpassword ,
ntpassword ) ;
logon - > password = password_info ;
break ;
}
case NET_LOGON_TYPE : {
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 ;
init_netr_NetworkInfo ( network_info ,
domain ,
logon_parameters ,
0xdead ,
0xbeef ,
username ,
clnt_name_slash ,
chal ,
nt ,
lm ) ;
logon - > network = network_info ;
break ;
}
default :
DEBUG ( 0 , ( " switch value %d not supported \n " ,
logon_type ) ) ;
return NT_STATUS_INVALID_INFO_CLASS ;
}
result = rpccli_netr_LogonSamLogon ( cli , mem_ctx ,
cli - > dc - > remote_machine ,
global_myname ( ) ,
& clnt_creds ,
& ret_creds ,
logon_type ,
logon ,
validation_level ,
& validation ,
& authoritative ) ;
if ( memcmp ( zeros , & ret_creds . cred . data , sizeof ( ret_creds . cred . data ) ) ! = 0 ) {
2005-09-30 21:13:37 +04:00
/* Check returned credentials if present. */
2008-02-17 04:10:43 +03:00
if ( ! netlogon_creds_client_check ( cli - > dc , & ret_creds . cred ) ) {
2005-09-30 21:13:37 +04:00
DEBUG ( 0 , ( " rpccli_netlogon_sam_logon: credentials chain check failed \n " ) ) ;
return NT_STATUS_ACCESS_DENIED ;
}
}
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
}
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 ] ,
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 ;
int validation_level = 3 ;
2005-09-30 21:13:37 +04:00
const char * workstation_name_slash ;
const char * server_name_slash ;
2007-12-28 19:02:34 +03:00
uint8 zeros [ 16 ] ;
2008-02-17 04:10:43 +03:00
struct netr_Authenticator clnt_creds ;
struct netr_Authenticator ret_creds ;
2008-03-27 15:03:12 +03:00
union netr_LogonInfo * 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 ;
struct netr_UserSessionKey user_session_key ;
struct netr_LMSessionKey lmsesskey ;
* info3 = NULL ;
2007-12-28 19:02:34 +03:00
ZERO_STRUCT ( zeros ) ;
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-03-27 15:03:12 +03:00
logon = TALLOC_ZERO_P ( mem_ctx , union netr_LogonInfo ) ;
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 ;
}
netlogon_creds_client_step ( 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 ;
init_netr_NetworkInfo ( network_info ,
domain ,
logon_parameters ,
0xdead ,
0xbeef ,
username ,
workstation_name_slash ,
( uint8_t * ) chal ,
nt ,
lm ) ;
logon - > network = network_info ;
/* Marshall data and send request */
result = rpccli_netr_LogonSamLogon ( cli , mem_ctx ,
server_name_slash ,
global_myname ( ) ,
& clnt_creds ,
& ret_creds ,
NET_LOGON_TYPE ,
logon ,
validation_level ,
& validation ,
& authoritative ) ;
if ( ! NT_STATUS_IS_OK ( result ) ) {
return result ;
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
}
2008-02-17 04:10:43 +03:00
user_session_key = validation . sam3 - > base . key ;
lmsesskey = validation . sam3 - > base . LMSessKey ;
2004-12-20 14:36:39 +03:00
2008-02-17 04:10:43 +03:00
if ( memcmp ( zeros , user_session_key . key , 16 ) ! = 0 ) {
SamOEMhash ( user_session_key . key , cli - > dc - > sess_key , 16 ) ;
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
}
2003-03-24 12:54:13 +03:00
2008-02-17 04:10:43 +03:00
if ( memcmp ( zeros , lmsesskey . key , 8 ) ! = 0 ) {
SamOEMhash ( lmsesskey . key , cli - > dc - > sess_key , 8 ) ;
}
2002-08-17 20:05:44 +04:00
2008-02-17 04:10:43 +03:00
if ( memcmp ( zeros , ret_creds . cred . data , sizeof ( ret_creds . cred . data ) ) ! = 0 ) {
2005-09-30 21:13:37 +04:00
/* Check returned credentials if present. */
2008-02-17 04:10:43 +03:00
if ( ! netlogon_creds_client_check ( cli - > dc , & ret_creds . cred ) ) {
2005-09-30 21:13:37 +04:00
DEBUG ( 0 , ( " rpccli_netlogon_sam_network_logon: credentials chain check failed \n " ) ) ;
return NT_STATUS_ACCESS_DENIED ;
}
}
2002-08-17 20:05:44 +04:00
2008-02-17 04:10:43 +03:00
* info3 = validation . sam3 ;
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 ] ,
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 ;
int validation_level = 3 ;
const char * workstation_name_slash ;
const char * server_name_slash ;
2007-12-28 19:02:34 +03:00
uint8 zeros [ 16 ] ;
2008-03-27 15:03:12 +03:00
union netr_LogonInfo * 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 ;
struct netr_UserSessionKey user_session_key ;
struct netr_LMSessionKey lmsesskey ;
uint32_t flags = 0 ;
* info3 = NULL ;
2007-12-28 19:02:34 +03:00
ZERO_STRUCT ( zeros ) ;
2008-02-17 04:37:12 +03:00
2008-02-19 03:48:58 +03:00
ZERO_STRUCT ( lm ) ;
ZERO_STRUCT ( nt ) ;
2008-03-27 15:03:12 +03:00
logon = TALLOC_ZERO_P ( mem_ctx , union netr_LogonInfo ) ;
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
2008-02-17 04:37:12 +03:00
init_netr_NetworkInfo ( network_info ,
domain ,
logon_parameters ,
0xdead ,
0xbeef ,
username ,
workstation_name_slash ,
( uint8_t * ) chal ,
nt ,
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 */
2008-02-17 04:37:12 +03:00
result = rpccli_netr_LogonSamLogonEx ( cli , mem_ctx ,
server_name_slash ,
global_myname ( ) ,
NET_LOGON_TYPE ,
logon ,
validation_level ,
& validation ,
& authoritative ,
& flags ) ;
if ( ! NT_STATUS_IS_OK ( result ) ) {
return result ;
2007-05-23 19:17:49 +04:00
}
2008-02-17 04:37:12 +03:00
user_session_key = validation . sam3 - > base . key ;
lmsesskey = validation . sam3 - > base . LMSessKey ;
if ( memcmp ( zeros , user_session_key . key , 16 ) ! = 0 ) {
SamOEMhash ( user_session_key . key , cli - > dc - > sess_key , 16 ) ;
2007-05-23 19:17:49 +04:00
}
2008-02-17 04:37:12 +03:00
if ( memcmp ( zeros , lmsesskey . key , 8 ) ! = 0 ) {
SamOEMhash ( lmsesskey . key , cli - > dc - > sess_key , 8 ) ;
2007-05-23 19:17:49 +04:00
}
2008-02-17 04:37:12 +03:00
* info3 = validation . sam3 ;
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
}