2002-01-05 04:55:41 +00:00
/*
2002-01-30 06:08:46 +00:00
Unix SMB / CIFS implementation .
2002-01-05 04:55:41 +00:00
Password and authentication handling
Copyright ( C ) Andrew Bartlett 2001 - 2002
2009-01-20 22:04:53 +01:00
2002-01-05 04:55:41 +00: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 19:25:36 +00:00
the Free Software Foundation ; either version 3 of the License , or
2002-01-05 04:55:41 +00:00
( at your option ) any later version .
2009-01-20 22:04:53 +01:00
2002-01-05 04:55:41 +00: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 .
2009-01-20 22:04:53 +01:00
2002-01-05 04:55:41 +00:00
You should have received a copy of the GNU General Public License
2007-07-10 00:52:41 +00:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2002-01-05 04:55:41 +00:00
*/
# include "includes.h"
2005-04-06 16:28:04 +00:00
extern struct auth_context * negprot_global_auth_context ;
2007-10-18 17:40:25 -07:00
extern bool global_encrypted_passwords_negotiated ;
2005-04-06 16:28:04 +00:00
2002-07-15 10:35:28 +00:00
# undef DBGC_CLASS
# define DBGC_CLASS DBGC_AUTH
2002-01-05 04:55:41 +00:00
/****************************************************************************
2002-04-07 23:41:55 +00:00
COMPATIBILITY INTERFACES :
2002-01-05 04:55:41 +00:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/****************************************************************************
check if a username / password is OK assuming the password is a 24 byte
SMB hash
return True if the password is correct , False otherwise
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-01-20 08:58:21 +00:00
NTSTATUS check_plaintext_password ( const char * smb_name , DATA_BLOB plaintext_password , auth_serversupplied_info * * server_info )
{
struct auth_context * plaintext_auth_context = NULL ;
auth_usersupplied_info * user_info = NULL ;
2009-02-19 23:41:48 +01:00
uint8_t chal [ 8 ] ;
2002-01-20 08:58:21 +00:00
NTSTATUS nt_status ;
if ( ! NT_STATUS_IS_OK ( nt_status = make_auth_context_subsystem ( & plaintext_auth_context ) ) ) {
return nt_status ;
}
2009-01-20 22:04:53 +01:00
2009-02-19 23:41:48 +01:00
plaintext_auth_context - > get_ntlm_challenge ( plaintext_auth_context ,
chal ) ;
2009-01-20 22:04:53 +01:00
2002-01-20 08:58:21 +00:00
if ( ! make_user_info_for_reply ( & user_info ,
smb_name , lp_workgroup ( ) , chal ,
plaintext_password ) ) {
return NT_STATUS_NO_MEMORY ;
}
2009-01-20 22:04:53 +01:00
2002-01-20 08:58:21 +00:00
nt_status = plaintext_auth_context - > check_ntlm_password ( plaintext_auth_context ,
user_info , server_info ) ;
2009-01-20 22:04:53 +01:00
2002-01-20 08:58:21 +00:00
( plaintext_auth_context - > free ) ( & plaintext_auth_context ) ;
free_user_info ( & user_info ) ;
return nt_status ;
}
2009-05-26 12:48:58 +02:00
static NTSTATUS pass_check_smb ( struct auth_context * actx ,
const char * smb_name ,
2002-01-20 08:58:21 +00:00
const char * domain ,
2002-01-05 04:55:41 +00:00
DATA_BLOB lm_pwd ,
DATA_BLOB nt_pwd ,
DATA_BLOB plaintext_password ,
2007-10-18 17:40:25 -07:00
bool encrypted )
2002-01-05 04:55:41 +00:00
{
NTSTATUS nt_status ;
auth_serversupplied_info * server_info = NULL ;
2009-05-26 12:48:58 +02:00
if ( encrypted ) {
2002-01-20 08:58:21 +00:00
auth_usersupplied_info * user_info = NULL ;
2009-05-26 12:48:58 +02:00
if ( actx = = NULL ) {
return NT_STATUS_INTERNAL_ERROR ;
}
2002-01-05 04:55:41 +00:00
make_user_info_for_reply_enc ( & user_info , smb_name ,
domain ,
lm_pwd ,
nt_pwd ) ;
2009-05-26 12:48:58 +02:00
nt_status = actx - > check_ntlm_password ( actx , user_info , & server_info ) ;
2002-01-20 08:58:21 +00:00
free_user_info ( & user_info ) ;
2002-01-05 04:55:41 +00:00
} else {
2002-01-20 08:58:21 +00:00
nt_status = check_plaintext_password ( smb_name , plaintext_password , & server_info ) ;
2002-01-05 04:55:41 +00:00
}
2006-02-20 17:59:58 +00:00
TALLOC_FREE ( server_info ) ;
2002-01-05 04:55:41 +00:00
return nt_status ;
}
/****************************************************************************
check if a username / password pair is ok via the auth subsystem .
return True if the password is correct , False otherwise
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-02-02 22:02:42 +00:00
2009-05-26 12:48:58 +02:00
bool password_ok ( struct auth_context * actx , bool global_encrypted ,
const char * smb_name , DATA_BLOB password_blob )
2002-01-05 04:55:41 +00:00
{
2007-05-14 12:16:20 +00:00
DATA_BLOB null_password = data_blob_null ;
2009-05-26 12:48:58 +02:00
bool encrypted = ( global_encrypted & & ( password_blob . length = = 24 | | password_blob . length > 46 ) ) ;
2009-01-20 22:04:53 +01:00
2002-01-05 04:55:41 +00:00
if ( encrypted ) {
/*
* The password could be either NTLM or plain LM . Try NTLM first ,
* but fall - through as required .
2007-02-02 22:02:42 +00:00
* Vista sends NTLMv2 here - we need to try the client given workgroup .
2002-01-05 04:55:41 +00:00
*/
2007-02-02 22:02:42 +00:00
if ( get_session_workgroup ( ) ) {
2009-05-26 12:48:58 +02:00
if ( NT_STATUS_IS_OK ( pass_check_smb ( actx , smb_name , get_session_workgroup ( ) , null_password , password_blob , null_password , encrypted ) ) ) {
2007-02-02 22:02:42 +00:00
return True ;
}
2009-05-26 12:48:58 +02:00
if ( NT_STATUS_IS_OK ( pass_check_smb ( actx , smb_name , get_session_workgroup ( ) , password_blob , null_password , null_password , encrypted ) ) ) {
2007-02-16 13:40:11 +00:00
return True ;
}
2007-02-02 22:02:42 +00:00
}
2009-05-26 12:48:58 +02:00
if ( NT_STATUS_IS_OK ( pass_check_smb ( actx , smb_name , lp_workgroup ( ) , null_password , password_blob , null_password , encrypted ) ) ) {
2002-01-05 04:55:41 +00:00
return True ;
}
2009-01-20 22:04:53 +01:00
2009-05-26 12:48:58 +02:00
if ( NT_STATUS_IS_OK ( pass_check_smb ( actx , smb_name , lp_workgroup ( ) , password_blob , null_password , null_password , encrypted ) ) ) {
2002-01-05 04:55:41 +00:00
return True ;
}
} else {
2009-05-26 12:48:58 +02:00
if ( NT_STATUS_IS_OK ( pass_check_smb ( actx , smb_name , lp_workgroup ( ) , null_password , null_password , password_blob , encrypted ) ) ) {
2002-01-05 04:55:41 +00:00
return True ;
}
}
return False ;
}