1998-09-25 21:01:52 +00:00
/*
2002-01-30 06:08:46 +00:00
Unix SMB / CIFS implementation .
1998-09-25 21:01:52 +00:00
Password cacheing . obfuscation is planned
Copyright ( C ) Luke Kenneth Casson Leighton 1996 - 1998
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 0213 9 , USA .
*/
# include "includes.h"
/****************************************************************************
2001-11-15 19:40:00 +00:00
Initialises a password structure .
1998-09-25 21:01:52 +00:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2001-11-15 19:40:00 +00:00
2002-07-15 10:35:28 +00:00
static void pwd_init ( struct pwd_info * pwd )
1998-09-25 21:01:52 +00:00
{
1999-12-13 13:27:58 +00:00
memset ( ( char * ) pwd - > password , ' \0 ' , sizeof ( pwd - > password ) ) ;
memset ( ( char * ) pwd - > smb_lm_pwd , ' \0 ' , sizeof ( pwd - > smb_lm_pwd ) ) ;
memset ( ( char * ) pwd - > smb_nt_pwd , ' \0 ' , sizeof ( pwd - > smb_nt_pwd ) ) ;
memset ( ( char * ) pwd - > smb_lm_owf , ' \0 ' , sizeof ( pwd - > smb_lm_owf ) ) ;
memset ( ( char * ) pwd - > smb_nt_owf , ' \0 ' , sizeof ( pwd - > smb_nt_owf ) ) ;
1998-09-25 21:01:52 +00:00
pwd - > null_pwd = True ; /* safest option... */
pwd - > cleartext = False ;
pwd - > crypted = False ;
}
2000-07-03 04:24:31 +00:00
/****************************************************************************
2002-07-15 10:35:28 +00:00
Makes lm and nt hashed passwords .
1998-09-25 21:01:52 +00:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2001-11-15 19:40:00 +00:00
2002-11-12 23:20:50 +00:00
static void pwd_make_lm_nt_16 ( struct pwd_info * pwd , const char * clr )
1998-09-25 21:01:52 +00:00
{
2002-07-15 10:35:28 +00:00
pstring dos_passwd ;
1998-09-25 21:01:52 +00:00
pwd_init ( pwd ) ;
2002-07-15 10:35:28 +00:00
push_ascii_pstring ( dos_passwd , clr ) ;
1998-09-25 21:01:52 +00:00
2002-07-15 10:35:28 +00:00
nt_lm_owf_gen ( dos_passwd , pwd - > smb_nt_pwd , pwd - > smb_lm_pwd ) ;
pwd - > null_pwd = False ;
1998-09-25 21:01:52 +00:00
pwd - > cleartext = False ;
2002-07-15 10:35:28 +00:00
pwd - > crypted = False ;
1998-09-25 21:01:52 +00:00
}
/****************************************************************************
2001-11-15 19:40:00 +00:00
Stores a cleartext password .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-11-12 23:20:50 +00:00
void pwd_set_cleartext ( struct pwd_info * pwd , const char * clr )
1998-09-25 21:01:52 +00:00
{
pwd_init ( pwd ) ;
2001-07-04 07:15:53 +00:00
push_ascii_fstring ( pwd - > password , clr ) ;
1998-09-25 21:01:52 +00:00
pwd - > cleartext = True ;
pwd - > null_pwd = False ;
pwd - > crypted = False ;
2001-12-04 05:03:03 +00:00
pwd_make_lm_nt_16 ( pwd , clr ) ;
1998-09-25 21:01:52 +00:00
}
/****************************************************************************
2001-11-15 19:40:00 +00:00
Gets a cleartext password .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-07-15 10:35:28 +00:00
void pwd_get_cleartext ( struct pwd_info * pwd , fstring clr )
1998-09-25 21:01:52 +00:00
{
2001-11-15 19:40:00 +00:00
if ( pwd - > cleartext )
1998-09-25 21:01:52 +00:00
fstrcpy ( clr , pwd - > password ) ;
2001-11-15 19:40:00 +00:00
else
1998-09-25 21:01:52 +00:00
clr [ 0 ] = 0 ;
2001-12-04 05:03:03 +00:00
1998-09-25 21:01:52 +00:00
}
/****************************************************************************
2001-11-15 19:40:00 +00:00
Gets lm and nt hashed passwords .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1999-12-13 13:27:58 +00:00
void pwd_get_lm_nt_16 ( struct pwd_info * pwd , uchar lm_pwd [ 16 ] , uchar nt_pwd [ 16 ] )
1998-09-25 21:01:52 +00:00
{
1998-10-08 23:57:46 +00:00
if ( lm_pwd ! = NULL )
memcpy ( lm_pwd , pwd - > smb_lm_pwd , 16 ) ;
if ( nt_pwd ! = NULL )
memcpy ( nt_pwd , pwd - > smb_nt_pwd , 16 ) ;
1998-09-25 21:01:52 +00:00
}
/****************************************************************************
2001-11-15 19:40:00 +00:00
Makes lm and nt OWF crypts .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1999-12-13 13:27:58 +00:00
void pwd_make_lm_nt_owf ( struct pwd_info * pwd , uchar cryptkey [ 8 ] )
1998-09-25 21:01:52 +00:00
{
# ifdef DEBUG_PASSWORD
1999-12-13 13:27:58 +00:00
DEBUG ( 100 , ( " client cryptkey: " ) ) ;
dump_data ( 100 , ( char * ) cryptkey , 8 ) ;
1998-09-25 21:01:52 +00:00
# endif
1999-06-29 18:47:06 +00:00
1999-12-13 13:27:58 +00:00
SMBOWFencrypt ( pwd - > smb_nt_pwd , cryptkey , pwd - > smb_nt_owf ) ;
1999-06-29 18:47:06 +00:00
1999-10-07 22:10:29 +00:00
# ifdef DEBUG_PASSWORD
1999-12-13 13:27:58 +00:00
DEBUG ( 100 , ( " nt_owf_passwd: " ) ) ;
dump_data ( 100 , ( char * ) pwd - > smb_nt_owf , sizeof ( pwd - > smb_nt_owf ) ) ;
DEBUG ( 100 , ( " nt_sess_pwd: " ) ) ;
dump_data ( 100 , ( char * ) pwd - > smb_nt_pwd , sizeof ( pwd - > smb_nt_pwd ) ) ;
1999-10-07 22:10:29 +00:00
# endif
1998-09-25 21:01:52 +00:00
SMBOWFencrypt ( pwd - > smb_lm_pwd , cryptkey , pwd - > smb_lm_owf ) ;
1999-11-21 19:59:56 +00:00
1998-09-25 21:01:52 +00:00
# ifdef DEBUG_PASSWORD
DEBUG ( 100 , ( " lm_owf_passwd: " ) ) ;
1999-12-13 13:27:58 +00:00
dump_data ( 100 , ( char * ) pwd - > smb_lm_owf , sizeof ( pwd - > smb_lm_owf ) ) ;
1998-09-25 21:01:52 +00:00
DEBUG ( 100 , ( " lm_sess_pwd: " ) ) ;
1999-12-13 13:27:58 +00:00
dump_data ( 100 , ( char * ) pwd - > smb_lm_pwd , sizeof ( pwd - > smb_lm_pwd ) ) ;
1998-09-25 21:01:52 +00:00
# endif
pwd - > crypted = True ;
}
/****************************************************************************
2001-11-15 19:40:00 +00:00
Gets lm and nt crypts .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1999-12-13 13:27:58 +00:00
void pwd_get_lm_nt_owf ( struct pwd_info * pwd , uchar lm_owf [ 24 ] , uchar nt_owf [ 24 ] )
1998-09-25 21:01:52 +00:00
{
1998-10-08 23:57:46 +00:00
if ( lm_owf ! = NULL )
memcpy ( lm_owf , pwd - > smb_lm_owf , 24 ) ;
if ( nt_owf ! = NULL )
1999-12-13 13:27:58 +00:00
memcpy ( nt_owf , pwd - > smb_nt_owf , 24 ) ;
1998-09-25 21:01:52 +00:00
}