2001-10-15 11:50:21 +04:00
/*
2002-01-30 09:08:46 +03:00
Unix SMB / CIFS implementation .
2001-10-15 11:50:21 +04:00
handle SMBsessionsetup
Copyright ( C ) Andrew Tridgell 1998 - 2001
Copyright ( C ) Andrew Bartlett 2001
2003-08-01 19:30:44 +04:00
Copyright ( C ) Jim McDonough < jmcd @ us . ibm . com > 2002
2003-03-18 01:45:16 +03:00
Copyright ( C ) Luke Howard 2003
2001-10-15 11:50:21 +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
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-09 01:19:01 +03:00
uint32 global_client_caps = 0 ;
2003-01-28 15:07:02 +03:00
static struct auth_ntlmssp_state * global_ntlmssp_state ;
2001-11-09 01:19:01 +03:00
2001-12-20 12:06:53 +03:00
/*
on a logon error possibly map the error to success if " map to guest "
is set approriately
*/
static NTSTATUS do_map_to_guest ( NTSTATUS status , auth_serversupplied_info * * server_info ,
const char * user , const char * domain )
{
if ( NT_STATUS_EQUAL ( status , NT_STATUS_NO_SUCH_USER ) ) {
if ( ( lp_map_to_guest ( ) = = MAP_TO_GUEST_ON_BAD_USER ) | |
( lp_map_to_guest ( ) = = MAP_TO_GUEST_ON_BAD_PASSWORD ) ) {
DEBUG ( 3 , ( " No such user %s [%s] - using guest account \n " ,
user , domain ) ) ;
2003-03-18 01:45:16 +03:00
status = make_server_info_guest ( server_info ) ;
2001-12-20 12:06:53 +03:00
}
}
if ( NT_STATUS_EQUAL ( status , NT_STATUS_WRONG_PASSWORD ) ) {
if ( lp_map_to_guest ( ) = = MAP_TO_GUEST_ON_BAD_PASSWORD ) {
DEBUG ( 3 , ( " Registered username %s for guest access \n " , user ) ) ;
2003-03-18 01:45:16 +03:00
status = make_server_info_guest ( server_info ) ;
2001-12-20 12:06:53 +03:00
}
}
return status ;
}
2001-11-12 03:08:30 +03:00
/****************************************************************************
2001-11-12 23:14:18 +03:00
Add the standard ' Samba ' signature to the end of the session setup .
2001-11-12 03:08:30 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2003-07-16 03:05:57 +04:00
2003-05-27 20:30:02 +04:00
static int add_signature ( char * outbuf , char * p )
2001-11-12 03:08:30 +03:00
{
2003-05-27 20:30:02 +04:00
char * start = p ;
2003-04-29 17:28:48 +04:00
fstring lanman ;
2003-08-20 21:13:38 +04:00
fstr_sprintf ( lanman , " Samba %s " , SAMBA_VERSION_STRING ) ;
2003-04-29 17:28:48 +04:00
2001-11-12 03:08:30 +03:00
p + = srvstr_push ( outbuf , p , " Unix " , - 1 , STR_TERMINATE ) ;
2003-04-29 17:28:48 +04:00
p + = srvstr_push ( outbuf , p , lanman , - 1 , STR_TERMINATE ) ;
2001-11-12 03:08:30 +03:00
p + = srvstr_push ( outbuf , p , lp_workgroup ( ) , - 1 , STR_TERMINATE ) ;
2003-05-21 02:54:58 +04:00
2003-05-27 20:30:02 +04:00
return PTR_DIFF ( p , start ) ;
2001-11-12 03:08:30 +03:00
}
2003-01-28 15:07:02 +03:00
/****************************************************************************
2003-07-16 03:05:57 +04:00
Send a security blob via a session setup reply .
2003-01-28 15:07:02 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2003-07-16 03:05:57 +04:00
2003-01-28 15:07:02 +03:00
static BOOL reply_sesssetup_blob ( connection_struct * conn , char * outbuf ,
DATA_BLOB blob , NTSTATUS nt_status )
{
char * p ;
set_message ( outbuf , 4 , 0 , True ) ;
nt_status = nt_status_squash ( nt_status ) ;
SIVAL ( outbuf , smb_rcls , NT_STATUS_V ( nt_status ) ) ;
SSVAL ( outbuf , smb_vwv0 , 0xFF ) ; /* no chaining possible */
SSVAL ( outbuf , smb_vwv3 , blob . length ) ;
p = smb_buf ( outbuf ) ;
/* should we cap this? */
memcpy ( p , blob . data , blob . length ) ;
p + = blob . length ;
2003-05-27 20:30:02 +04:00
p + = add_signature ( outbuf , p ) ;
2003-05-21 02:54:58 +04:00
2003-01-28 15:07:02 +03:00
set_message_end ( outbuf , p ) ;
return send_smb ( smbd_server_fd ( ) , outbuf ) ;
}
This is another rather major change to the samba authenticaion
subystem.
The particular aim is to modularized the interface - so that we
can have arbitrary password back-ends.
This code adds one such back-end, a 'winbind' module to authenticate
against the winbind_auth_crap functionality. While fully-functional
this code is mainly useful as a demonstration, because we don't get
back the info3 as we would for direct ntdomain authentication.
This commit introduced the new 'auth methods' parameter, in the
spirit of the 'auth order' discussed on the lists. It is renamed
because not all the methods may be consulted, even if previous
methods fail - they may not have a suitable challenge for example.
Also, we have a 'local' authentication method, for old-style
'unix if plaintext, sam if encrypted' authentication and a
'guest' module to handle guest logins in a single place.
While this current design is not ideal, I feel that it does
provide a better infrastructure than the current design, and can
be built upon.
The following parameters have changed:
- use rhosts =
This has been replaced by the 'rhosts' authentication method,
and can be specified like 'auth methods = guest rhosts'
- hosts equiv =
This needs both this parameter and an 'auth methods' entry
to be effective. (auth methods = guest hostsequiv ....)
- plaintext to smbpasswd =
This is replaced by specifying 'sam' rather than 'local'
in the auth methods.
The security = parameter is unchanged, and now provides defaults
for the 'auth methods' parameter.
The available auth methods are:
guest
rhosts
hostsequiv
sam (passdb direct hash access)
unix (PAM, crypt() etc)
local (the combination of the above, based on encryption)
smbserver (old security=server)
ntdomain (old security=domain)
winbind (use winbind to cache DC connections)
Assistance in testing, or the production of new and interesting
authentication modules is always appreciated.
Andrew Bartlett
(This used to be commit 8d31eae52a9757739711dbb82035a4dfe6b40c99)
2001-11-24 15:12:38 +03:00
/****************************************************************************
Do a ' guest ' logon , getting back the
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2003-07-16 03:05:57 +04:00
This is another rather major change to the samba authenticaion
subystem.
The particular aim is to modularized the interface - so that we
can have arbitrary password back-ends.
This code adds one such back-end, a 'winbind' module to authenticate
against the winbind_auth_crap functionality. While fully-functional
this code is mainly useful as a demonstration, because we don't get
back the info3 as we would for direct ntdomain authentication.
This commit introduced the new 'auth methods' parameter, in the
spirit of the 'auth order' discussed on the lists. It is renamed
because not all the methods may be consulted, even if previous
methods fail - they may not have a suitable challenge for example.
Also, we have a 'local' authentication method, for old-style
'unix if plaintext, sam if encrypted' authentication and a
'guest' module to handle guest logins in a single place.
While this current design is not ideal, I feel that it does
provide a better infrastructure than the current design, and can
be built upon.
The following parameters have changed:
- use rhosts =
This has been replaced by the 'rhosts' authentication method,
and can be specified like 'auth methods = guest rhosts'
- hosts equiv =
This needs both this parameter and an 'auth methods' entry
to be effective. (auth methods = guest hostsequiv ....)
- plaintext to smbpasswd =
This is replaced by specifying 'sam' rather than 'local'
in the auth methods.
The security = parameter is unchanged, and now provides defaults
for the 'auth methods' parameter.
The available auth methods are:
guest
rhosts
hostsequiv
sam (passdb direct hash access)
unix (PAM, crypt() etc)
local (the combination of the above, based on encryption)
smbserver (old security=server)
ntdomain (old security=domain)
winbind (use winbind to cache DC connections)
Assistance in testing, or the production of new and interesting
authentication modules is always appreciated.
Andrew Bartlett
(This used to be commit 8d31eae52a9757739711dbb82035a4dfe6b40c99)
2001-11-24 15:12:38 +03:00
static NTSTATUS check_guest_password ( auth_serversupplied_info * * server_info )
{
2002-01-05 07:55:41 +03:00
struct auth_context * auth_context ;
This is another rather major change to the samba authenticaion
subystem.
The particular aim is to modularized the interface - so that we
can have arbitrary password back-ends.
This code adds one such back-end, a 'winbind' module to authenticate
against the winbind_auth_crap functionality. While fully-functional
this code is mainly useful as a demonstration, because we don't get
back the info3 as we would for direct ntdomain authentication.
This commit introduced the new 'auth methods' parameter, in the
spirit of the 'auth order' discussed on the lists. It is renamed
because not all the methods may be consulted, even if previous
methods fail - they may not have a suitable challenge for example.
Also, we have a 'local' authentication method, for old-style
'unix if plaintext, sam if encrypted' authentication and a
'guest' module to handle guest logins in a single place.
While this current design is not ideal, I feel that it does
provide a better infrastructure than the current design, and can
be built upon.
The following parameters have changed:
- use rhosts =
This has been replaced by the 'rhosts' authentication method,
and can be specified like 'auth methods = guest rhosts'
- hosts equiv =
This needs both this parameter and an 'auth methods' entry
to be effective. (auth methods = guest hostsequiv ....)
- plaintext to smbpasswd =
This is replaced by specifying 'sam' rather than 'local'
in the auth methods.
The security = parameter is unchanged, and now provides defaults
for the 'auth methods' parameter.
The available auth methods are:
guest
rhosts
hostsequiv
sam (passdb direct hash access)
unix (PAM, crypt() etc)
local (the combination of the above, based on encryption)
smbserver (old security=server)
ntdomain (old security=domain)
winbind (use winbind to cache DC connections)
Assistance in testing, or the production of new and interesting
authentication modules is always appreciated.
Andrew Bartlett
(This used to be commit 8d31eae52a9757739711dbb82035a4dfe6b40c99)
2001-11-24 15:12:38 +03:00
auth_usersupplied_info * user_info = NULL ;
NTSTATUS nt_status ;
2001-12-31 16:46:26 +03:00
unsigned char chal [ 8 ] ;
This is another rather major change to the samba authenticaion
subystem.
The particular aim is to modularized the interface - so that we
can have arbitrary password back-ends.
This code adds one such back-end, a 'winbind' module to authenticate
against the winbind_auth_crap functionality. While fully-functional
this code is mainly useful as a demonstration, because we don't get
back the info3 as we would for direct ntdomain authentication.
This commit introduced the new 'auth methods' parameter, in the
spirit of the 'auth order' discussed on the lists. It is renamed
because not all the methods may be consulted, even if previous
methods fail - they may not have a suitable challenge for example.
Also, we have a 'local' authentication method, for old-style
'unix if plaintext, sam if encrypted' authentication and a
'guest' module to handle guest logins in a single place.
While this current design is not ideal, I feel that it does
provide a better infrastructure than the current design, and can
be built upon.
The following parameters have changed:
- use rhosts =
This has been replaced by the 'rhosts' authentication method,
and can be specified like 'auth methods = guest rhosts'
- hosts equiv =
This needs both this parameter and an 'auth methods' entry
to be effective. (auth methods = guest hostsequiv ....)
- plaintext to smbpasswd =
This is replaced by specifying 'sam' rather than 'local'
in the auth methods.
The security = parameter is unchanged, and now provides defaults
for the 'auth methods' parameter.
The available auth methods are:
guest
rhosts
hostsequiv
sam (passdb direct hash access)
unix (PAM, crypt() etc)
local (the combination of the above, based on encryption)
smbserver (old security=server)
ntdomain (old security=domain)
winbind (use winbind to cache DC connections)
Assistance in testing, or the production of new and interesting
authentication modules is always appreciated.
Andrew Bartlett
(This used to be commit 8d31eae52a9757739711dbb82035a4dfe6b40c99)
2001-11-24 15:12:38 +03:00
ZERO_STRUCT ( chal ) ;
DEBUG ( 3 , ( " Got anonymous request \n " ) ) ;
2002-01-05 07:55:41 +03:00
if ( ! NT_STATUS_IS_OK ( nt_status = make_auth_context_fixed ( & auth_context , chal ) ) ) {
return nt_status ;
}
if ( ! make_user_info_guest ( & user_info ) ) {
2002-01-09 10:52:51 +03:00
( auth_context - > free ) ( & auth_context ) ;
2002-01-05 07:55:41 +03:00
return NT_STATUS_NO_MEMORY ;
}
This is another rather major change to the samba authenticaion
subystem.
The particular aim is to modularized the interface - so that we
can have arbitrary password back-ends.
This code adds one such back-end, a 'winbind' module to authenticate
against the winbind_auth_crap functionality. While fully-functional
this code is mainly useful as a demonstration, because we don't get
back the info3 as we would for direct ntdomain authentication.
This commit introduced the new 'auth methods' parameter, in the
spirit of the 'auth order' discussed on the lists. It is renamed
because not all the methods may be consulted, even if previous
methods fail - they may not have a suitable challenge for example.
Also, we have a 'local' authentication method, for old-style
'unix if plaintext, sam if encrypted' authentication and a
'guest' module to handle guest logins in a single place.
While this current design is not ideal, I feel that it does
provide a better infrastructure than the current design, and can
be built upon.
The following parameters have changed:
- use rhosts =
This has been replaced by the 'rhosts' authentication method,
and can be specified like 'auth methods = guest rhosts'
- hosts equiv =
This needs both this parameter and an 'auth methods' entry
to be effective. (auth methods = guest hostsequiv ....)
- plaintext to smbpasswd =
This is replaced by specifying 'sam' rather than 'local'
in the auth methods.
The security = parameter is unchanged, and now provides defaults
for the 'auth methods' parameter.
The available auth methods are:
guest
rhosts
hostsequiv
sam (passdb direct hash access)
unix (PAM, crypt() etc)
local (the combination of the above, based on encryption)
smbserver (old security=server)
ntdomain (old security=domain)
winbind (use winbind to cache DC connections)
Assistance in testing, or the production of new and interesting
authentication modules is always appreciated.
Andrew Bartlett
(This used to be commit 8d31eae52a9757739711dbb82035a4dfe6b40c99)
2001-11-24 15:12:38 +03:00
2002-01-05 07:55:41 +03:00
nt_status = auth_context - > check_ntlm_password ( auth_context , user_info , server_info ) ;
2002-01-09 10:52:51 +03:00
( auth_context - > free ) ( & auth_context ) ;
2001-11-27 06:54:15 +03:00
free_user_info ( & user_info ) ;
This is another rather major change to the samba authenticaion
subystem.
The particular aim is to modularized the interface - so that we
can have arbitrary password back-ends.
This code adds one such back-end, a 'winbind' module to authenticate
against the winbind_auth_crap functionality. While fully-functional
this code is mainly useful as a demonstration, because we don't get
back the info3 as we would for direct ntdomain authentication.
This commit introduced the new 'auth methods' parameter, in the
spirit of the 'auth order' discussed on the lists. It is renamed
because not all the methods may be consulted, even if previous
methods fail - they may not have a suitable challenge for example.
Also, we have a 'local' authentication method, for old-style
'unix if plaintext, sam if encrypted' authentication and a
'guest' module to handle guest logins in a single place.
While this current design is not ideal, I feel that it does
provide a better infrastructure than the current design, and can
be built upon.
The following parameters have changed:
- use rhosts =
This has been replaced by the 'rhosts' authentication method,
and can be specified like 'auth methods = guest rhosts'
- hosts equiv =
This needs both this parameter and an 'auth methods' entry
to be effective. (auth methods = guest hostsequiv ....)
- plaintext to smbpasswd =
This is replaced by specifying 'sam' rather than 'local'
in the auth methods.
The security = parameter is unchanged, and now provides defaults
for the 'auth methods' parameter.
The available auth methods are:
guest
rhosts
hostsequiv
sam (passdb direct hash access)
unix (PAM, crypt() etc)
local (the combination of the above, based on encryption)
smbserver (old security=server)
ntdomain (old security=domain)
winbind (use winbind to cache DC connections)
Assistance in testing, or the production of new and interesting
authentication modules is always appreciated.
Andrew Bartlett
(This used to be commit 8d31eae52a9757739711dbb82035a4dfe6b40c99)
2001-11-24 15:12:38 +03:00
return nt_status ;
}
2001-11-29 02:54:07 +03:00
# ifdef HAVE_KRB5
2001-10-18 14:26:06 +04:00
/****************************************************************************
reply to a session setup spnego negotiate packet for kerberos
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2001-10-20 10:31:25 +04:00
static int reply_spnego_kerberos ( connection_struct * conn ,
char * inbuf , char * outbuf ,
int length , int bufsize ,
2001-10-18 14:26:06 +04:00
DATA_BLOB * secblob )
{
DATA_BLOB ticket ;
2004-01-04 14:51:31 +03:00
char * client , * p , * domain ;
fstring netbios_domain_name ;
2004-03-16 19:41:54 +03:00
struct passwd * pw ;
2001-10-20 10:31:25 +04:00
char * user ;
int sess_vuid ;
2001-11-24 17:16:41 +03:00
NTSTATUS ret ;
DATA_BLOB auth_data ;
2003-03-18 01:45:16 +03:00
DATA_BLOB ap_rep , ap_rep_wrapped , response ;
2001-10-31 15:37:56 +03:00
auth_serversupplied_info * server_info = NULL ;
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
DATA_BLOB session_key ;
2003-03-18 01:45:16 +03:00
uint8 tok_id [ 2 ] ;
2003-02-24 05:35:54 +03:00
BOOL foreign = False ;
2003-07-18 04:53:34 +04:00
DATA_BLOB nullblob = data_blob ( NULL , 0 ) ;
2004-03-16 19:41:54 +03:00
fstring real_username ;
2001-10-18 14:26:06 +04:00
2003-05-01 22:11:24 +04:00
ZERO_STRUCT ( ticket ) ;
ZERO_STRUCT ( auth_data ) ;
ZERO_STRUCT ( ap_rep ) ;
ZERO_STRUCT ( ap_rep_wrapped ) ;
ZERO_STRUCT ( response ) ;
2003-03-18 01:45:16 +03:00
if ( ! spnego_parse_krb5_wrap ( * secblob , & ticket , tok_id ) ) {
2001-10-18 14:26:06 +04:00
return ERROR_NT ( NT_STATUS_LOGON_FAILURE ) ;
}
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
ret = ads_verify_ticket ( lp_realm ( ) , & ticket , & client , & auth_data , & ap_rep , & session_key ) ;
2003-08-25 13:13:54 +04:00
data_blob_free ( & ticket ) ;
2001-11-24 17:16:41 +03:00
if ( ! NT_STATUS_IS_OK ( ret ) ) {
2001-11-29 09:21:56 +03:00
DEBUG ( 1 , ( " Failed to verify incoming ticket! \n " ) ) ;
2001-10-18 14:26:06 +04:00
return ERROR_NT ( NT_STATUS_LOGON_FAILURE ) ;
}
2003-02-24 05:35:54 +03:00
data_blob_free ( & auth_data ) ;
2001-10-18 14:26:06 +04:00
DEBUG ( 3 , ( " Ticket name is [%s] \n " , client ) ) ;
2001-10-20 10:31:25 +04:00
p = strchr_m ( client , ' @ ' ) ;
if ( ! p ) {
2001-10-22 00:51:27 +04:00
DEBUG ( 3 , ( " Doesn't look like a valid principal \n " ) ) ;
2003-03-18 01:45:16 +03:00
data_blob_free ( & ap_rep ) ;
2003-08-15 05:46:09 +04:00
SAFE_FREE ( client ) ;
2001-10-20 10:31:25 +04:00
return ERROR_NT ( NT_STATUS_LOGON_FAILURE ) ;
}
* p = 0 ;
2003-10-23 03:38:20 +04:00
if ( ! strequal ( p + 1 , lp_realm ( ) ) ) {
2001-12-19 12:53:30 +03:00
DEBUG ( 3 , ( " Ticket for foreign realm %s@%s \n " , client , p + 1 ) ) ;
if ( ! lp_allow_trusted_domains ( ) ) {
2003-03-18 01:45:16 +03:00
data_blob_free ( & ap_rep ) ;
2003-08-15 05:46:09 +04:00
SAFE_FREE ( client ) ;
2001-12-19 12:53:30 +03:00
return ERROR_NT ( NT_STATUS_LOGON_FAILURE ) ;
}
2003-02-24 05:35:54 +03:00
foreign = True ;
}
/* this gives a fully qualified user name (ie. with full realm).
that leads to very long usernames , but what else can we do ? */
2004-01-04 14:51:31 +03:00
domain = p + 1 ;
{
/* If we have winbind running, we can (and must) shorten the
username by using the short netbios name . Otherwise we will
have inconsistent user names . With Kerberos , we get the
fully qualified realm , with ntlmssp we get the short
name . And even w2k3 does use ntlmssp if you for example
connect to an ip address . */
struct winbindd_request wb_request ;
struct winbindd_response wb_response ;
NSS_STATUS wb_result ;
ZERO_STRUCT ( wb_request ) ;
ZERO_STRUCT ( wb_response ) ;
DEBUG ( 10 , ( " Mapping [%s] to short name \n " , domain ) ) ;
fstrcpy ( wb_request . domain_name , domain ) ;
wb_result = winbindd_request ( WINBINDD_DOMAIN_INFO ,
& wb_request , & wb_response ) ;
if ( wb_result = = NSS_STATUS_SUCCESS ) {
fstrcpy ( netbios_domain_name ,
wb_response . data . domain_info . name ) ;
domain = netbios_domain_name ;
DEBUG ( 10 , ( " Mapped to [%s] \n " , domain ) ) ;
} else {
DEBUG ( 3 , ( " Could not find short name -- winbind "
" not running? \n " ) ) ;
}
}
asprintf ( & user , " %s%c%s " , domain , * lp_winbind_separator ( ) , client ) ;
2003-02-24 05:35:54 +03:00
2004-03-16 19:41:54 +03:00
/* lookup the passwd struct, create a new user if necessary */
pw = smb_getpwnam ( user , real_username , True ) ;
2003-10-20 20:49:45 +04:00
2001-10-20 10:31:25 +04:00
if ( ! pw ) {
DEBUG ( 1 , ( " Username %s is invalid on this system \n " , user ) ) ;
2004-01-07 22:55:01 +03:00
SAFE_FREE ( user ) ;
SAFE_FREE ( client ) ;
2003-03-18 01:45:16 +03:00
data_blob_free ( & ap_rep ) ;
2003-08-19 03:48:03 +04:00
return ERROR_NT ( NT_STATUS_LOGON_FAILURE ) ;
2001-10-20 10:31:25 +04:00
}
2001-10-31 15:37:56 +03:00
2003-10-20 20:49:45 +04:00
/* setup the string used by %U */
2004-03-16 19:41:54 +03:00
sub_set_smb_name ( real_username ) ;
2003-10-20 20:49:45 +04:00
reload_services ( True ) ;
2004-03-16 19:41:54 +03:00
if ( ! NT_STATUS_IS_OK ( ret = make_server_info_pw ( & server_info , real_username , pw ) ) )
{
2001-10-31 15:37:56 +03:00
DEBUG ( 1 , ( " make_server_info_from_pw failed! \n " ) ) ;
2004-01-07 22:55:01 +03:00
SAFE_FREE ( user ) ;
SAFE_FREE ( client ) ;
2003-03-18 01:45:16 +03:00
data_blob_free ( & ap_rep ) ;
2002-09-25 19:19:00 +04:00
return ERROR_NT ( ret ) ;
2001-10-31 15:37:56 +03:00
}
2003-03-18 01:45:16 +03:00
2004-01-15 20:17:58 +03:00
/* make_server_info_pw does not set the domain. Without this we end up
* with the local netbios name in substitutions for % D . */
if ( server_info - > sam_account ! = NULL ) {
pdb_set_domain ( server_info - > sam_account , domain , PDB_SET ) ;
}
2003-02-24 05:35:54 +03:00
/* register_vuid keeps the server info */
2004-01-07 22:55:01 +03:00
sess_vuid = register_vuid ( server_info , session_key , nullblob , client ) ;
2001-10-31 15:37:56 +03:00
2004-01-07 22:55:01 +03:00
SAFE_FREE ( user ) ;
SAFE_FREE ( client ) ;
2001-10-20 10:31:25 +04:00
if ( sess_vuid = = - 1 ) {
2003-03-18 01:45:16 +03:00
ret = NT_STATUS_LOGON_FAILURE ;
} else {
2004-03-20 01:06:54 +03:00
/* current_user_info is changed on new vuid */
reload_services ( True ) ;
2003-03-18 01:45:16 +03:00
set_message ( outbuf , 4 , 0 , True ) ;
SSVAL ( outbuf , smb_vwv3 , 0 ) ;
if ( server_info - > guest ) {
SSVAL ( outbuf , smb_vwv2 , 1 ) ;
}
SSVAL ( outbuf , smb_uid , sess_vuid ) ;
2003-07-18 04:53:34 +04:00
2004-03-27 10:33:59 +03:00
if ( ! server_info - > guest & & ! srv_signing_started ( ) ) {
2003-07-26 03:43:22 +04:00
/* We need to start the signing engine
* here but a W2K client sends the old
* " BSRSPYL " signature instead of the
* correct one . Subsequent packets will
* be correct .
*/
2004-03-27 10:33:59 +03:00
srv_check_sign_mac ( inbuf , False ) ;
2003-07-18 04:53:34 +04:00
}
2001-10-20 10:31:25 +04:00
}
2003-03-18 01:45:16 +03:00
/* wrap that up in a nice GSS-API wrapping */
if ( NT_STATUS_IS_OK ( ret ) ) {
ap_rep_wrapped = spnego_gen_krb5_wrap ( ap_rep , TOK_ID_KRB_AP_REP ) ;
} else {
ap_rep_wrapped = data_blob ( NULL , 0 ) ;
}
response = spnego_gen_auth_response ( & ap_rep_wrapped , ret , OID_KERBEROS5_OLD ) ;
reply_sesssetup_blob ( conn , outbuf , response , ret ) ;
data_blob_free ( & ap_rep ) ;
data_blob_free ( & ap_rep_wrapped ) ;
data_blob_free ( & response ) ;
return - 1 ; /* already replied */
2001-10-18 14:26:06 +04:00
}
# endif
2001-10-17 12:54:19 +04:00
/****************************************************************************
2003-07-16 03:05:57 +04:00
Send a session setup reply , wrapped in SPNEGO .
Get vuid and check first .
End the NTLMSSP exchange context if we are OK / complete fail
2003-01-28 15:07:02 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2003-07-16 03:05:57 +04:00
2003-07-18 04:53:34 +04:00
static BOOL reply_spnego_ntlmssp ( connection_struct * conn , char * inbuf , char * outbuf ,
2003-01-28 15:07:02 +03:00
AUTH_NTLMSSP_STATE * * auth_ntlmssp_state ,
DATA_BLOB * ntlmssp_blob , NTSTATUS nt_status )
2001-10-17 12:54:19 +04:00
{
2003-01-28 15:07:02 +03:00
BOOL ret ;
DATA_BLOB response ;
2003-03-18 01:45:16 +03:00
struct auth_serversupplied_info * server_info = NULL ;
2001-10-17 12:54:19 +04:00
2003-03-18 01:45:16 +03:00
if ( NT_STATUS_IS_OK ( nt_status ) ) {
server_info = ( * auth_ntlmssp_state ) - > server_info ;
} else {
2003-01-28 15:07:02 +03:00
nt_status = do_map_to_guest ( nt_status ,
& server_info ,
( * auth_ntlmssp_state ) - > ntlmssp_state - > user ,
( * auth_ntlmssp_state ) - > ntlmssp_state - > domain ) ;
}
2001-10-17 12:54:19 +04:00
2003-01-28 15:07:02 +03:00
if ( NT_STATUS_IS_OK ( nt_status ) ) {
int sess_vuid ;
2003-07-18 04:53:34 +04:00
DATA_BLOB nullblob = data_blob ( NULL , 0 ) ;
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
DATA_BLOB session_key = data_blob ( ( * auth_ntlmssp_state ) - > ntlmssp_state - > session_key . data , ( * auth_ntlmssp_state ) - > ntlmssp_state - > session_key . length ) ;
2003-07-18 04:53:34 +04:00
2003-02-24 05:35:54 +03:00
/* register_vuid keeps the server info */
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
sess_vuid = register_vuid ( server_info , session_key , nullblob , ( * auth_ntlmssp_state ) - > ntlmssp_state - > user ) ;
2003-02-24 05:35:54 +03:00
( * auth_ntlmssp_state ) - > server_info = NULL ;
2003-01-28 15:07:02 +03:00
if ( sess_vuid = = - 1 ) {
nt_status = NT_STATUS_LOGON_FAILURE ;
} else {
2004-03-20 01:06:54 +03:00
/* current_user_info is changed on new vuid */
reload_services ( True ) ;
2003-01-28 15:07:02 +03:00
set_message ( outbuf , 4 , 0 , True ) ;
SSVAL ( outbuf , smb_vwv3 , 0 ) ;
2003-02-24 05:35:54 +03:00
if ( server_info - > guest ) {
2003-01-28 15:07:02 +03:00
SSVAL ( outbuf , smb_vwv2 , 1 ) ;
}
SSVAL ( outbuf , smb_uid , sess_vuid ) ;
2003-07-18 04:53:34 +04:00
2004-03-27 10:33:59 +03:00
if ( ! server_info - > guest & & ! srv_signing_started ( ) ) {
2003-07-24 08:25:37 +04:00
/* We need to start the signing engine
* here but a W2K client sends the old
* " BSRSPYL " signature instead of the
* correct one . Subsequent packets will
* be correct .
*/
2004-03-27 10:33:59 +03:00
srv_check_sign_mac ( inbuf , False ) ;
2003-07-18 04:53:34 +04:00
}
2003-01-28 15:07:02 +03:00
}
}
2001-10-17 12:54:19 +04:00
2003-03-18 01:45:16 +03:00
response = spnego_gen_auth_response ( ntlmssp_blob , nt_status , OID_NTLMSSP ) ;
2003-01-28 15:07:02 +03:00
ret = reply_sesssetup_blob ( conn , outbuf , response , nt_status ) ;
data_blob_free ( & response ) ;
2003-04-22 16:28:30 +04:00
/* NT_STATUS_MORE_PROCESSING_REQUIRED from our NTLMSSP code tells us,
and the other end , that we are not finished yet . */
2003-01-28 15:07:02 +03:00
if ( ! ret | | ! NT_STATUS_EQUAL ( nt_status , NT_STATUS_MORE_PROCESSING_REQUIRED ) ) {
2003-02-24 05:35:54 +03:00
auth_ntlmssp_end ( auth_ntlmssp_state ) ;
2003-01-28 15:07:02 +03:00
}
return ret ;
2001-10-17 12:54:19 +04:00
}
/****************************************************************************
2003-07-16 03:05:57 +04:00
Reply to a session setup spnego negotiate packet .
2001-10-17 12:54:19 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2003-07-16 03:05:57 +04:00
2001-10-20 10:31:25 +04:00
static int reply_spnego_negotiate ( connection_struct * conn ,
char * inbuf ,
char * outbuf ,
int length , int bufsize ,
2001-10-17 12:54:19 +04:00
DATA_BLOB blob1 )
{
char * OIDs [ ASN1_MAX_OIDS ] ;
DATA_BLOB secblob ;
int i ;
2003-01-28 15:07:02 +03:00
DATA_BLOB chal ;
2001-10-18 14:26:06 +04:00
BOOL got_kerberos = False ;
2002-01-05 07:55:41 +03:00
NTSTATUS nt_status ;
2001-10-17 12:54:19 +04:00
/* parse out the OIDs and the first sec blob */
if ( ! parse_negTokenTarg ( blob1 , OIDs , & secblob ) ) {
return ERROR_NT ( NT_STATUS_LOGON_FAILURE ) ;
}
2003-07-31 23:01:22 +04:00
/* only look at the first OID for determining the mechToken --
accoirding to RFC2478 , we should choose the one we want
and renegotiate , but i smell a client bug here . .
Problem observed when connecting to a member ( samba box )
of an AD domain as a user in a Samba domain . Samba member
server sent back krb5 / mskrb5 / ntlmssp as mechtypes , but the
client ( 2 ksp3 ) replied with ntlmssp / mskrb5 / krb5 and an
NTLMSSP mechtoken . - - jerry */
2001-10-17 12:54:19 +04:00
2003-07-31 23:01:22 +04:00
if ( strcmp ( OID_KERBEROS5 , OIDs [ 0 ] ) = = 0 | |
strcmp ( OID_KERBEROS5_OLD , OIDs [ 0 ] ) = = 0 ) {
got_kerberos = True ;
}
2001-10-17 12:54:19 +04:00
for ( i = 0 ; OIDs [ i ] ; i + + ) {
DEBUG ( 3 , ( " Got OID %s \n " , OIDs [ i ] ) ) ;
free ( OIDs [ i ] ) ;
}
2003-07-25 08:24:40 +04:00
DEBUG ( 3 , ( " Got secblob of size %lu \n " , ( unsigned long ) secblob . length ) ) ;
2001-10-17 12:54:19 +04:00
2001-11-29 02:54:07 +03:00
# ifdef HAVE_KRB5
2002-08-17 19:27:10 +04:00
if ( got_kerberos & & ( SEC_ADS = = lp_security ( ) ) ) {
2001-10-20 10:31:25 +04:00
int ret = reply_spnego_kerberos ( conn , inbuf , outbuf ,
length , bufsize , & secblob ) ;
2001-10-18 14:26:06 +04:00
data_blob_free ( & secblob ) ;
return ret ;
}
# endif
2003-01-28 15:07:02 +03:00
if ( global_ntlmssp_state ) {
auth_ntlmssp_end ( & global_ntlmssp_state ) ;
2002-01-05 07:55:41 +03:00
}
2003-01-28 15:07:02 +03:00
nt_status = auth_ntlmssp_start ( & global_ntlmssp_state ) ;
if ( ! NT_STATUS_IS_OK ( nt_status ) ) {
2002-01-05 07:55:41 +03:00
return ERROR_NT ( nt_status ) ;
2001-10-18 14:26:06 +04:00
}
2001-10-17 12:54:19 +04:00
2003-01-28 15:07:02 +03:00
nt_status = auth_ntlmssp_update ( global_ntlmssp_state ,
secblob , & chal ) ;
2001-10-17 12:54:19 +04:00
2003-01-28 15:07:02 +03:00
data_blob_free ( & secblob ) ;
2001-10-17 12:54:19 +04:00
2003-07-18 04:53:34 +04:00
reply_spnego_ntlmssp ( conn , inbuf , outbuf , & global_ntlmssp_state ,
2003-01-28 15:07:02 +03:00
& chal , nt_status ) ;
2001-10-17 12:54:19 +04:00
data_blob_free ( & chal ) ;
2003-01-28 15:07:02 +03:00
/* already replied */
2001-10-17 12:54:19 +04:00
return - 1 ;
}
/****************************************************************************
2003-07-16 03:05:57 +04:00
Reply to a session setup spnego auth packet .
2001-10-17 12:54:19 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2003-07-16 03:05:57 +04:00
2001-10-17 12:54:19 +04:00
static int reply_spnego_auth ( connection_struct * conn , char * inbuf , char * outbuf ,
int length , int bufsize ,
DATA_BLOB blob1 )
{
2003-01-28 15:07:02 +03:00
DATA_BLOB auth , auth_reply ;
2003-03-18 01:45:16 +03:00
NTSTATUS nt_status = NT_STATUS_INVALID_PARAMETER ;
2002-07-15 14:35:28 +04:00
2001-10-17 12:54:19 +04:00
if ( ! spnego_parse_auth ( blob1 , & auth ) ) {
2001-10-17 14:46:46 +04:00
#if 0
2001-10-17 12:54:19 +04:00
file_save ( " auth.dat " , blob1 . data , blob1 . length ) ;
2001-10-17 14:46:46 +04:00
# endif
2003-03-18 01:45:16 +03:00
return ERROR_NT ( NT_STATUS_INVALID_PARAMETER ) ;
2001-10-17 12:54:19 +04:00
}
2003-03-18 01:45:16 +03:00
if ( ! global_ntlmssp_state ) {
/* auth before negotiatiate? */
return ERROR_NT ( NT_STATUS_INVALID_PARAMETER ) ;
2003-03-15 02:06:06 +03:00
}
2003-03-18 01:45:16 +03:00
nt_status = auth_ntlmssp_update ( global_ntlmssp_state ,
auth , & auth_reply ) ;
2001-10-17 12:54:19 +04:00
data_blob_free ( & auth ) ;
2001-12-20 12:06:53 +03:00
2003-07-18 04:53:34 +04:00
reply_spnego_ntlmssp ( conn , inbuf , outbuf , & global_ntlmssp_state ,
2003-01-28 15:07:02 +03:00
& auth_reply , nt_status ) ;
data_blob_free ( & auth_reply ) ;
2002-08-17 19:27:10 +04:00
/* and tell smbd that we have already replied to this packet */
return - 1 ;
2001-10-17 12:54:19 +04:00
}
/****************************************************************************
2003-07-16 03:05:57 +04:00
Reply to a session setup command .
2001-10-17 12:54:19 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2003-07-16 03:05:57 +04:00
2003-01-28 15:07:02 +03:00
static int reply_sesssetup_and_X_spnego ( connection_struct * conn , char * inbuf ,
char * outbuf ,
2001-10-17 12:54:19 +04:00
int length , int bufsize )
{
uint8 * p ;
DATA_BLOB blob1 ;
int ret ;
2003-01-28 15:07:02 +03:00
size_t bufrem ;
2003-12-06 00:51:51 +03:00
fstring native_os , native_lanman , primary_domain ;
2003-03-15 02:06:06 +03:00
char * p2 ;
uint16 data_blob_len = SVAL ( inbuf , smb_vwv7 ) ;
enum remote_arch_types ra_type = get_remote_arch ( ) ;
2001-10-17 12:54:19 +04:00
2001-10-31 13:46:25 +03:00
DEBUG ( 3 , ( " Doing spnego session setup \n " ) ) ;
2001-10-21 07:27:13 +04:00
2001-10-17 12:54:19 +04:00
if ( global_client_caps = = 0 ) {
global_client_caps = IVAL ( inbuf , smb_vwv10 ) ;
2003-12-01 05:25:56 +03:00
2003-12-01 09:19:17 +03:00
if ( ! ( global_client_caps & CAP_STATUS32 ) ) {
remove_from_common_flags2 ( FLAGS2_32_BIT_ERROR_CODES ) ;
2003-12-01 05:25:56 +03:00
}
2001-10-17 12:54:19 +04:00
}
2001-10-23 23:10:30 +04:00
p = ( uint8 * ) smb_buf ( inbuf ) ;
2001-10-17 12:54:19 +04:00
2003-03-15 02:06:06 +03:00
if ( data_blob_len = = 0 ) {
2003-01-28 15:07:02 +03:00
/* an invalid request */
return ERROR_NT ( NT_STATUS_LOGON_FAILURE ) ;
2001-10-20 15:47:44 +04:00
}
2003-01-28 15:07:02 +03:00
bufrem = smb_bufrem ( inbuf , p ) ;
2001-10-17 12:54:19 +04:00
/* pull the spnego blob */
2003-03-15 02:06:06 +03:00
blob1 = data_blob ( p , MIN ( bufrem , data_blob_len ) ) ;
2001-10-20 15:47:44 +04:00
2001-10-18 14:26:06 +04:00
#if 0
file_save ( " negotiate.dat " , blob1 . data , blob1 . length ) ;
# endif
2003-03-15 02:06:06 +03:00
p2 = inbuf + smb_vwv13 + data_blob_len ;
p2 + = srvstr_pull_buf ( inbuf , native_os , p2 , sizeof ( native_os ) , STR_TERMINATE ) ;
p2 + = srvstr_pull_buf ( inbuf , native_lanman , p2 , sizeof ( native_lanman ) , STR_TERMINATE ) ;
2003-12-06 00:51:51 +03:00
p2 + = srvstr_pull_buf ( inbuf , primary_domain , p2 , sizeof ( primary_domain ) , STR_TERMINATE ) ;
DEBUG ( 3 , ( " NativeOS=[%s] NativeLanMan=[%s] PrimaryDomain=[%s] \n " ,
native_os , native_lanman , primary_domain ) ) ;
2003-03-15 02:06:06 +03:00
2003-12-06 00:51:51 +03:00
if ( ra_type = = RA_WIN2K ) {
/* Windows 2003 doesn't set the native lanman string,
but does set primary domain which is a bug I think */
if ( ! strlen ( native_lanman ) )
ra_lanman_string ( primary_domain ) ;
else
ra_lanman_string ( native_lanman ) ;
}
2001-10-17 12:54:19 +04:00
if ( blob1 . data [ 0 ] = = ASN1_APPLICATION ( 0 ) ) {
/* its a negTokenTarg packet */
2001-10-20 10:31:25 +04:00
ret = reply_spnego_negotiate ( conn , inbuf , outbuf , length , bufsize , blob1 ) ;
2001-10-17 12:54:19 +04:00
data_blob_free ( & blob1 ) ;
return ret ;
}
if ( blob1 . data [ 0 ] = = ASN1_CONTEXT ( 1 ) ) {
/* its a auth packet */
ret = reply_spnego_auth ( conn , inbuf , outbuf , length , bufsize , blob1 ) ;
data_blob_free ( & blob1 ) ;
return ret ;
}
/* what sort of packet is this? */
DEBUG ( 1 , ( " Unknown packet in reply_sesssetup_and_X_spnego \n " ) ) ;
data_blob_free ( & blob1 ) ;
return ERROR_NT ( NT_STATUS_LOGON_FAILURE ) ;
}
2003-05-28 01:55:10 +04:00
/****************************************************************************
On new VC = = 0 , shutdown * all * old connections and users .
2003-05-28 05:00:58 +04:00
It seems that only NT4 . x does this . At W2K and above ( XP etc . ) .
a new session setup with VC = = 0 is ignored .
2003-05-28 01:55:10 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static void setup_new_vc_session ( void )
{
2003-05-28 05:00:58 +04:00
DEBUG ( 2 , ( " setup_new_vc_session: New VC == 0, if NT4.x compatible we would close all old resources. \n " ) ) ;
#if 0
2003-05-28 01:55:10 +04:00
conn_close_all ( ) ;
invalidate_all_vuids ( ) ;
2003-05-28 05:00:58 +04:00
# endif
2003-05-28 01:55:10 +04:00
}
2001-10-17 12:54:19 +04:00
2001-10-15 11:50:21 +04:00
/****************************************************************************
2003-07-16 03:05:57 +04:00
Reply to a session setup command .
2001-10-15 11:50:21 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2003-07-16 03:05:57 +04:00
2001-10-15 11:50:21 +04:00
int reply_sesssetup_and_X ( connection_struct * conn , char * inbuf , char * outbuf ,
int length , int bufsize )
{
int sess_vuid ;
int smb_bufsize ;
2001-10-31 13:46:25 +03:00
DATA_BLOB lm_resp ;
DATA_BLOB nt_resp ;
DATA_BLOB plaintext_password ;
2003-01-02 23:43:17 +03:00
fstring user ;
fstring sub_user ; /* Sainitised username for substituion */
2001-10-15 11:50:21 +04:00
fstring domain ;
fstring native_os ;
fstring native_lanman ;
2003-12-06 00:51:51 +03:00
fstring primary_domain ;
2001-10-15 11:50:21 +04:00
static BOOL done_sesssetup = False ;
extern BOOL global_encrypted_passwords_negotiated ;
2001-10-30 16:54:54 +03:00
extern BOOL global_spnego_negotiated ;
2001-10-15 11:50:21 +04:00
extern int Protocol ;
extern int max_send ;
2001-10-31 13:46:25 +03:00
auth_usersupplied_info * user_info = NULL ;
2002-01-05 07:55:41 +03:00
extern struct auth_context * negprot_global_auth_context ;
2001-10-31 13:46:25 +03:00
auth_serversupplied_info * server_info = NULL ;
2001-11-09 01:19:01 +03:00
NTSTATUS nt_status ;
2001-10-15 11:50:21 +04:00
BOOL doencrypt = global_encrypted_passwords_negotiated ;
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
DATA_BLOB session_key ;
2002-09-25 19:19:00 +04:00
2001-10-15 11:50:21 +04:00
START_PROFILE ( SMBsesssetupX ) ;
2001-10-21 07:27:13 +04:00
2001-10-31 13:46:25 +03:00
ZERO_STRUCT ( lm_resp ) ;
ZERO_STRUCT ( nt_resp ) ;
ZERO_STRUCT ( plaintext_password ) ;
2001-10-21 07:27:13 +04:00
DEBUG ( 3 , ( " wct=%d flg2=0x%x \n " , CVAL ( inbuf , smb_wct ) , SVAL ( inbuf , smb_flg2 ) ) ) ;
2001-12-08 05:12:17 +03:00
2001-10-21 07:27:13 +04:00
/* a SPNEGO session setup has 12 command words, whereas a normal
NT1 session setup has 13. See the cifs spec . */
2001-10-30 16:54:54 +03:00
if ( CVAL ( inbuf , smb_wct ) = = 12 & &
2001-10-21 07:27:13 +04:00
( SVAL ( inbuf , smb_flg2 ) & FLAGS2_EXTENDED_SECURITY ) ) {
2001-12-08 05:12:17 +03:00
if ( ! global_spnego_negotiated ) {
DEBUG ( 0 , ( " reply_sesssetup_and_X: Rejecting attempt at SPNEGO session setup when it was not negoitiated. \n " ) ) ;
return ERROR_NT ( NT_STATUS_UNSUCCESSFUL ) ;
}
2003-05-28 01:55:10 +04:00
if ( SVAL ( inbuf , smb_vwv4 ) = = 0 ) {
setup_new_vc_session ( ) ;
}
2001-10-17 12:54:19 +04:00
return reply_sesssetup_and_X_spnego ( conn , inbuf , outbuf , length , bufsize ) ;
}
2001-10-15 11:50:21 +04:00
smb_bufsize = SVAL ( inbuf , smb_vwv2 ) ;
2001-10-31 13:46:25 +03:00
2001-10-15 11:50:21 +04:00
if ( Protocol < PROTOCOL_NT1 ) {
2001-10-31 13:46:25 +03:00
uint16 passlen1 = SVAL ( inbuf , smb_vwv7 ) ;
2002-08-17 19:27:10 +04:00
if ( ( passlen1 > MAX_PASS_LEN ) | | ( passlen1 > smb_bufrem ( inbuf , smb_buf ( inbuf ) ) ) ) {
return ERROR_NT ( NT_STATUS_INVALID_PARAMETER ) ;
2001-10-15 11:50:21 +04:00
}
2001-10-31 13:46:25 +03:00
if ( doencrypt ) {
lm_resp = data_blob ( smb_buf ( inbuf ) , passlen1 ) ;
} else {
plaintext_password = data_blob ( smb_buf ( inbuf ) , passlen1 + 1 ) ;
This is another rather major change to the samba authenticaion
subystem.
The particular aim is to modularized the interface - so that we
can have arbitrary password back-ends.
This code adds one such back-end, a 'winbind' module to authenticate
against the winbind_auth_crap functionality. While fully-functional
this code is mainly useful as a demonstration, because we don't get
back the info3 as we would for direct ntdomain authentication.
This commit introduced the new 'auth methods' parameter, in the
spirit of the 'auth order' discussed on the lists. It is renamed
because not all the methods may be consulted, even if previous
methods fail - they may not have a suitable challenge for example.
Also, we have a 'local' authentication method, for old-style
'unix if plaintext, sam if encrypted' authentication and a
'guest' module to handle guest logins in a single place.
While this current design is not ideal, I feel that it does
provide a better infrastructure than the current design, and can
be built upon.
The following parameters have changed:
- use rhosts =
This has been replaced by the 'rhosts' authentication method,
and can be specified like 'auth methods = guest rhosts'
- hosts equiv =
This needs both this parameter and an 'auth methods' entry
to be effective. (auth methods = guest hostsequiv ....)
- plaintext to smbpasswd =
This is replaced by specifying 'sam' rather than 'local'
in the auth methods.
The security = parameter is unchanged, and now provides defaults
for the 'auth methods' parameter.
The available auth methods are:
guest
rhosts
hostsequiv
sam (passdb direct hash access)
unix (PAM, crypt() etc)
local (the combination of the above, based on encryption)
smbserver (old security=server)
ntdomain (old security=domain)
winbind (use winbind to cache DC connections)
Assistance in testing, or the production of new and interesting
authentication modules is always appreciated.
Andrew Bartlett
(This used to be commit 8d31eae52a9757739711dbb82035a4dfe6b40c99)
2001-11-24 15:12:38 +03:00
/* Ensure null termination */
plaintext_password . data [ passlen1 ] = 0 ;
2001-10-15 11:50:21 +04:00
}
2001-10-31 13:46:25 +03:00
2002-07-15 14:35:28 +04:00
srvstr_pull_buf ( inbuf , user , smb_buf ( inbuf ) + passlen1 , sizeof ( user ) , STR_TERMINATE ) ;
This is another rather major change to the samba authenticaion
subystem.
The particular aim is to modularized the interface - so that we
can have arbitrary password back-ends.
This code adds one such back-end, a 'winbind' module to authenticate
against the winbind_auth_crap functionality. While fully-functional
this code is mainly useful as a demonstration, because we don't get
back the info3 as we would for direct ntdomain authentication.
This commit introduced the new 'auth methods' parameter, in the
spirit of the 'auth order' discussed on the lists. It is renamed
because not all the methods may be consulted, even if previous
methods fail - they may not have a suitable challenge for example.
Also, we have a 'local' authentication method, for old-style
'unix if plaintext, sam if encrypted' authentication and a
'guest' module to handle guest logins in a single place.
While this current design is not ideal, I feel that it does
provide a better infrastructure than the current design, and can
be built upon.
The following parameters have changed:
- use rhosts =
This has been replaced by the 'rhosts' authentication method,
and can be specified like 'auth methods = guest rhosts'
- hosts equiv =
This needs both this parameter and an 'auth methods' entry
to be effective. (auth methods = guest hostsequiv ....)
- plaintext to smbpasswd =
This is replaced by specifying 'sam' rather than 'local'
in the auth methods.
The security = parameter is unchanged, and now provides defaults
for the 'auth methods' parameter.
The available auth methods are:
guest
rhosts
hostsequiv
sam (passdb direct hash access)
unix (PAM, crypt() etc)
local (the combination of the above, based on encryption)
smbserver (old security=server)
ntdomain (old security=domain)
winbind (use winbind to cache DC connections)
Assistance in testing, or the production of new and interesting
authentication modules is always appreciated.
Andrew Bartlett
(This used to be commit 8d31eae52a9757739711dbb82035a4dfe6b40c99)
2001-11-24 15:12:38 +03:00
* domain = 0 ;
2003-05-28 01:55:10 +04:00
2001-10-15 11:50:21 +04:00
} else {
uint16 passlen1 = SVAL ( inbuf , smb_vwv7 ) ;
uint16 passlen2 = SVAL ( inbuf , smb_vwv8 ) ;
enum remote_arch_types ra_type = get_remote_arch ( ) ;
char * p = smb_buf ( inbuf ) ;
2003-12-06 00:51:51 +03:00
char * save_p = smb_buf ( inbuf ) ;
uint16 byte_count ;
2001-10-31 13:46:25 +03:00
2003-12-01 05:25:56 +03:00
if ( global_client_caps = = 0 ) {
2001-10-15 11:50:21 +04:00
global_client_caps = IVAL ( inbuf , smb_vwv11 ) ;
2003-12-01 09:19:17 +03:00
if ( ! ( global_client_caps & CAP_STATUS32 ) ) {
remove_from_common_flags2 ( FLAGS2_32_BIT_ERROR_CODES ) ;
2003-12-01 05:25:56 +03:00
}
/* client_caps is used as final determination if client is NT or Win95.
This is needed to return the correct error codes in some
circumstances .
*/
2001-10-15 11:50:21 +04:00
2003-12-01 05:25:56 +03:00
if ( ra_type = = RA_WINNT | | ra_type = = RA_WIN2K | | ra_type = = RA_WIN95 ) {
if ( ! ( global_client_caps & ( CAP_NT_SMBS | CAP_STATUS32 ) ) ) {
set_remote_arch ( RA_WIN95 ) ;
}
2001-10-15 11:50:21 +04:00
}
}
2003-03-18 01:45:16 +03:00
2001-10-15 11:50:21 +04:00
if ( ! doencrypt ) {
/* both Win95 and WinNT stuff up the password lengths for
non - encrypting systems . Uggh .
if passlen1 = = 24 its a win95 system , and its setting the
password length incorrectly . Luckily it still works with the
default code because Win95 will null terminate the password
anyway
if passlen1 > 0 and passlen2 > 0 then maybe its a NT box and its
setting passlen2 to some random value which really stuffs
things up . we need to fix that one . */
if ( passlen1 > 0 & & passlen2 > 0 & & passlen2 ! = 24 & & passlen2 ! = 1 )
passlen2 = 0 ;
}
2002-08-17 19:27:10 +04:00
/* check for nasty tricks */
if ( passlen1 > MAX_PASS_LEN | | passlen1 > smb_bufrem ( inbuf , p ) ) {
return ERROR_NT ( NT_STATUS_INVALID_PARAMETER ) ;
}
if ( passlen2 > MAX_PASS_LEN | | passlen2 > smb_bufrem ( inbuf , p + passlen1 ) ) {
return ERROR_NT ( NT_STATUS_INVALID_PARAMETER ) ;
}
2001-10-15 11:50:21 +04:00
/* Save the lanman2 password and the NT md4 password. */
2001-10-31 13:46:25 +03:00
if ( ( doencrypt ) & & ( passlen1 ! = 0 ) & & ( passlen1 ! = 24 ) ) {
doencrypt = False ;
}
2002-08-17 19:27:10 +04:00
2001-10-31 13:46:25 +03:00
if ( doencrypt ) {
lm_resp = data_blob ( p , passlen1 ) ;
nt_resp = data_blob ( p + passlen1 , passlen2 ) ;
} else {
2002-08-17 19:27:10 +04:00
pstring pass ;
2003-12-13 01:54:43 +03:00
BOOL unic = SVAL ( inbuf , smb_flg2 ) & FLAGS2_UNICODE_STRINGS ;
if ( ( ra_type = = RA_WINNT ) & & ( passlen2 = = 0 ) & & unic & & passlen1 ) {
/* NT4.0 stuffs up plaintext unicode password lengths... */
srvstr_pull ( inbuf , pass , smb_buf ( inbuf ) + 1 ,
sizeof ( pass ) , passlen1 , STR_TERMINATE ) ;
} else {
srvstr_pull ( inbuf , pass , smb_buf ( inbuf ) ,
sizeof ( pass ) , unic ? passlen2 : passlen1 ,
STR_TERMINATE ) ;
}
2002-08-17 19:27:10 +04:00
plaintext_password = data_blob ( pass , strlen ( pass ) + 1 ) ;
2001-10-15 11:50:21 +04:00
}
p + = passlen1 + passlen2 ;
2002-07-15 14:35:28 +04:00
p + = srvstr_pull_buf ( inbuf , user , p , sizeof ( user ) , STR_TERMINATE ) ;
p + = srvstr_pull_buf ( inbuf , domain , p , sizeof ( domain ) , STR_TERMINATE ) ;
p + = srvstr_pull_buf ( inbuf , native_os , p , sizeof ( native_os ) , STR_TERMINATE ) ;
p + = srvstr_pull_buf ( inbuf , native_lanman , p , sizeof ( native_lanman ) , STR_TERMINATE ) ;
2003-02-28 00:22:36 +03:00
2003-12-06 00:51:51 +03:00
/* not documented or decoded by Ethereal but there is one more string
in the extra bytes which is the same as the PrimaryDomain when using
extended security . Windows NT 4 and 2003 use this string to store
the native lanman string . Windows 9 x does not include a string here
at all so we have to check if we have any extra bytes left */
byte_count = SVAL ( inbuf , smb_vwv13 ) ;
if ( PTR_DIFF ( p , save_p ) < byte_count )
p + = srvstr_pull_buf ( inbuf , primary_domain , p , sizeof ( primary_domain ) , STR_TERMINATE ) ;
else
fstrcpy ( primary_domain , " null " ) ;
DEBUG ( 3 , ( " Domain=[%s] NativeOS=[%s] NativeLanMan=[%s] PrimaryDomain=[%s] \n " ,
domain , native_os , native_lanman , primary_domain ) ) ;
if ( ra_type = = RA_WIN2K ) {
if ( strlen ( native_lanman ) = = 0 )
ra_lanman_string ( primary_domain ) ;
else
ra_lanman_string ( native_lanman ) ;
}
2003-02-28 00:22:36 +03:00
2001-10-15 11:50:21 +04:00
}
2003-12-01 05:25:56 +03:00
2003-05-28 01:55:10 +04:00
if ( SVAL ( inbuf , smb_vwv4 ) = = 0 ) {
setup_new_vc_session ( ) ;
}
2002-08-17 19:27:10 +04:00
DEBUG ( 3 , ( " sesssetupX:name=[%s] \\ [%s]@[%s] \n " , domain , user , get_remote_machine_name ( ) ) ) ;
2001-10-31 13:46:25 +03:00
2001-11-09 01:19:01 +03:00
if ( * user ) {
2002-01-06 04:37:14 +03:00
if ( global_spnego_negotiated ) {
2003-05-14 04:46:43 +04:00
/* This has to be here, because this is a perfectly valid behaviour for guest logons :-( */
2002-01-06 04:37:14 +03:00
DEBUG ( 0 , ( " reply_sesssetup_and_X: Rejecting attempt at 'normal' session setup after negotiating spnego. \n " ) ) ;
return ERROR_NT ( NT_STATUS_UNSUCCESSFUL ) ;
}
2003-01-02 23:43:17 +03:00
fstrcpy ( sub_user , user ) ;
2002-11-20 03:53:24 +03:00
/* setup the string used by %U */
sub_set_smb_name ( user ) ;
2001-11-09 01:19:01 +03:00
} else {
2003-01-02 23:43:17 +03:00
fstrcpy ( sub_user , lp_guestaccount ( ) ) ;
2001-11-09 01:19:01 +03:00
}
2003-02-24 05:35:54 +03:00
sub_set_smb_name ( sub_user ) ;
2001-10-31 13:46:25 +03:00
reload_services ( True ) ;
if ( lp_security ( ) = = SEC_SHARE ) {
/* in share level we should ignore any passwords */
data_blob_free ( & lm_resp ) ;
data_blob_free ( & nt_resp ) ;
2001-11-01 08:02:41 +03:00
data_blob_clear_free ( & plaintext_password ) ;
2001-10-15 11:50:21 +04:00
2001-11-09 01:19:01 +03:00
map_username ( sub_user ) ;
add_session_user ( sub_user ) ;
/* Then force it to null for the benfit of the code below */
* user = 0 ;
2001-10-31 13:46:25 +03:00
}
2001-10-15 11:50:21 +04:00
This is another rather major change to the samba authenticaion
subystem.
The particular aim is to modularized the interface - so that we
can have arbitrary password back-ends.
This code adds one such back-end, a 'winbind' module to authenticate
against the winbind_auth_crap functionality. While fully-functional
this code is mainly useful as a demonstration, because we don't get
back the info3 as we would for direct ntdomain authentication.
This commit introduced the new 'auth methods' parameter, in the
spirit of the 'auth order' discussed on the lists. It is renamed
because not all the methods may be consulted, even if previous
methods fail - they may not have a suitable challenge for example.
Also, we have a 'local' authentication method, for old-style
'unix if plaintext, sam if encrypted' authentication and a
'guest' module to handle guest logins in a single place.
While this current design is not ideal, I feel that it does
provide a better infrastructure than the current design, and can
be built upon.
The following parameters have changed:
- use rhosts =
This has been replaced by the 'rhosts' authentication method,
and can be specified like 'auth methods = guest rhosts'
- hosts equiv =
This needs both this parameter and an 'auth methods' entry
to be effective. (auth methods = guest hostsequiv ....)
- plaintext to smbpasswd =
This is replaced by specifying 'sam' rather than 'local'
in the auth methods.
The security = parameter is unchanged, and now provides defaults
for the 'auth methods' parameter.
The available auth methods are:
guest
rhosts
hostsequiv
sam (passdb direct hash access)
unix (PAM, crypt() etc)
local (the combination of the above, based on encryption)
smbserver (old security=server)
ntdomain (old security=domain)
winbind (use winbind to cache DC connections)
Assistance in testing, or the production of new and interesting
authentication modules is always appreciated.
Andrew Bartlett
(This used to be commit 8d31eae52a9757739711dbb82035a4dfe6b40c99)
2001-11-24 15:12:38 +03:00
if ( ! * user ) {
nt_status = check_guest_password ( & server_info ) ;
} else if ( doencrypt ) {
2003-01-28 15:07:02 +03:00
if ( ! negprot_global_auth_context ) {
DEBUG ( 0 , ( " reply_sesssetup_and_X: Attempted encrypted session setup without negprot denied! \n " ) ) ;
return ERROR_NT ( NT_STATUS_LOGON_FAILURE ) ;
}
2002-09-25 19:19:00 +04:00
nt_status = make_user_info_for_reply_enc ( & user_info , user , domain ,
lm_resp , nt_resp ) ;
if ( NT_STATUS_IS_OK ( nt_status ) ) {
2002-01-05 07:55:41 +03:00
nt_status = negprot_global_auth_context - > check_ntlm_password ( negprot_global_auth_context ,
user_info ,
& server_info ) ;
This is another rather major change to the samba authenticaion
subystem.
The particular aim is to modularized the interface - so that we
can have arbitrary password back-ends.
This code adds one such back-end, a 'winbind' module to authenticate
against the winbind_auth_crap functionality. While fully-functional
this code is mainly useful as a demonstration, because we don't get
back the info3 as we would for direct ntdomain authentication.
This commit introduced the new 'auth methods' parameter, in the
spirit of the 'auth order' discussed on the lists. It is renamed
because not all the methods may be consulted, even if previous
methods fail - they may not have a suitable challenge for example.
Also, we have a 'local' authentication method, for old-style
'unix if plaintext, sam if encrypted' authentication and a
'guest' module to handle guest logins in a single place.
While this current design is not ideal, I feel that it does
provide a better infrastructure than the current design, and can
be built upon.
The following parameters have changed:
- use rhosts =
This has been replaced by the 'rhosts' authentication method,
and can be specified like 'auth methods = guest rhosts'
- hosts equiv =
This needs both this parameter and an 'auth methods' entry
to be effective. (auth methods = guest hostsequiv ....)
- plaintext to smbpasswd =
This is replaced by specifying 'sam' rather than 'local'
in the auth methods.
The security = parameter is unchanged, and now provides defaults
for the 'auth methods' parameter.
The available auth methods are:
guest
rhosts
hostsequiv
sam (passdb direct hash access)
unix (PAM, crypt() etc)
local (the combination of the above, based on encryption)
smbserver (old security=server)
ntdomain (old security=domain)
winbind (use winbind to cache DC connections)
Assistance in testing, or the production of new and interesting
authentication modules is always appreciated.
Andrew Bartlett
(This used to be commit 8d31eae52a9757739711dbb82035a4dfe6b40c99)
2001-11-24 15:12:38 +03:00
}
} else {
2002-01-05 07:55:41 +03:00
struct auth_context * plaintext_auth_context = NULL ;
const uint8 * chal ;
if ( NT_STATUS_IS_OK ( nt_status = make_auth_context_subsystem ( & plaintext_auth_context ) ) ) {
chal = plaintext_auth_context - > get_ntlm_challenge ( plaintext_auth_context ) ;
if ( ! make_user_info_for_reply ( & user_info ,
user , domain , chal ,
plaintext_password ) ) {
nt_status = NT_STATUS_NO_MEMORY ;
}
This is another rather major change to the samba authenticaion
subystem.
The particular aim is to modularized the interface - so that we
can have arbitrary password back-ends.
This code adds one such back-end, a 'winbind' module to authenticate
against the winbind_auth_crap functionality. While fully-functional
this code is mainly useful as a demonstration, because we don't get
back the info3 as we would for direct ntdomain authentication.
This commit introduced the new 'auth methods' parameter, in the
spirit of the 'auth order' discussed on the lists. It is renamed
because not all the methods may be consulted, even if previous
methods fail - they may not have a suitable challenge for example.
Also, we have a 'local' authentication method, for old-style
'unix if plaintext, sam if encrypted' authentication and a
'guest' module to handle guest logins in a single place.
While this current design is not ideal, I feel that it does
provide a better infrastructure than the current design, and can
be built upon.
The following parameters have changed:
- use rhosts =
This has been replaced by the 'rhosts' authentication method,
and can be specified like 'auth methods = guest rhosts'
- hosts equiv =
This needs both this parameter and an 'auth methods' entry
to be effective. (auth methods = guest hostsequiv ....)
- plaintext to smbpasswd =
This is replaced by specifying 'sam' rather than 'local'
in the auth methods.
The security = parameter is unchanged, and now provides defaults
for the 'auth methods' parameter.
The available auth methods are:
guest
rhosts
hostsequiv
sam (passdb direct hash access)
unix (PAM, crypt() etc)
local (the combination of the above, based on encryption)
smbserver (old security=server)
ntdomain (old security=domain)
winbind (use winbind to cache DC connections)
Assistance in testing, or the production of new and interesting
authentication modules is always appreciated.
Andrew Bartlett
(This used to be commit 8d31eae52a9757739711dbb82035a4dfe6b40c99)
2001-11-24 15:12:38 +03:00
2002-01-05 07:55:41 +03:00
if ( NT_STATUS_IS_OK ( nt_status ) ) {
nt_status = plaintext_auth_context - > check_ntlm_password ( plaintext_auth_context ,
user_info ,
& server_info ) ;
2002-01-09 10:52:51 +03:00
( plaintext_auth_context - > free ) ( & plaintext_auth_context ) ;
2002-01-05 07:55:41 +03:00
}
}
2001-11-09 01:19:01 +03:00
}
This is another rather major change to the samba authenticaion
subystem.
The particular aim is to modularized the interface - so that we
can have arbitrary password back-ends.
This code adds one such back-end, a 'winbind' module to authenticate
against the winbind_auth_crap functionality. While fully-functional
this code is mainly useful as a demonstration, because we don't get
back the info3 as we would for direct ntdomain authentication.
This commit introduced the new 'auth methods' parameter, in the
spirit of the 'auth order' discussed on the lists. It is renamed
because not all the methods may be consulted, even if previous
methods fail - they may not have a suitable challenge for example.
Also, we have a 'local' authentication method, for old-style
'unix if plaintext, sam if encrypted' authentication and a
'guest' module to handle guest logins in a single place.
While this current design is not ideal, I feel that it does
provide a better infrastructure than the current design, and can
be built upon.
The following parameters have changed:
- use rhosts =
This has been replaced by the 'rhosts' authentication method,
and can be specified like 'auth methods = guest rhosts'
- hosts equiv =
This needs both this parameter and an 'auth methods' entry
to be effective. (auth methods = guest hostsequiv ....)
- plaintext to smbpasswd =
This is replaced by specifying 'sam' rather than 'local'
in the auth methods.
The security = parameter is unchanged, and now provides defaults
for the 'auth methods' parameter.
The available auth methods are:
guest
rhosts
hostsequiv
sam (passdb direct hash access)
unix (PAM, crypt() etc)
local (the combination of the above, based on encryption)
smbserver (old security=server)
ntdomain (old security=domain)
winbind (use winbind to cache DC connections)
Assistance in testing, or the production of new and interesting
authentication modules is always appreciated.
Andrew Bartlett
(This used to be commit 8d31eae52a9757739711dbb82035a4dfe6b40c99)
2001-11-24 15:12:38 +03:00
2001-11-09 01:19:01 +03:00
free_user_info ( & user_info ) ;
if ( ! NT_STATUS_IS_OK ( nt_status ) ) {
2001-12-20 12:06:53 +03:00
nt_status = do_map_to_guest ( nt_status , & server_info , user , domain ) ;
2001-10-15 11:50:21 +04:00
}
2001-11-09 01:19:01 +03:00
if ( ! NT_STATUS_IS_OK ( nt_status ) ) {
2003-07-18 04:53:34 +04:00
data_blob_free ( & nt_resp ) ;
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
data_blob_free ( & lm_resp ) ;
data_blob_clear_free ( & plaintext_password ) ;
2001-11-09 01:19:01 +03:00
return ERROR_NT ( nt_status_squash ( nt_status ) ) ;
}
2003-07-18 04:53:34 +04:00
2004-04-06 12:11:16 +04:00
if ( server_info - > user_session_key . data ) {
session_key = data_blob ( server_info - > user_session_key . data , server_info - > user_session_key . length ) ;
2004-01-26 05:19:44 +03:00
} else {
session_key = data_blob ( NULL , 0 ) ;
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
}
data_blob_clear_free ( & plaintext_password ) ;
2001-10-15 11:50:21 +04:00
/* it's ok - setup a reply */
2003-01-28 15:07:02 +03:00
set_message ( outbuf , 3 , 0 , True ) ;
if ( Protocol > = PROTOCOL_NT1 ) {
2003-05-21 02:54:58 +04:00
char * p = smb_buf ( outbuf ) ;
2003-05-27 20:30:02 +04:00
p + = add_signature ( outbuf , p ) ;
2003-05-21 02:54:58 +04:00
set_message_end ( outbuf , p ) ;
2001-10-15 11:50:21 +04:00
/* perhaps grab OS version here?? */
}
2001-11-09 01:19:01 +03:00
if ( server_info - > guest ) {
2001-10-31 13:46:25 +03:00
SSVAL ( outbuf , smb_vwv2 , 1 ) ;
2001-10-15 11:50:21 +04:00
}
2001-10-31 13:46:25 +03:00
2001-10-15 11:50:21 +04:00
/* register the name and uid as being validated, so further connections
to a uid can get through without a password , on the same VC */
2001-10-31 13:46:25 +03:00
2003-02-24 05:35:54 +03:00
/* register_vuid keeps the server info */
2004-04-05 18:27:23 +04:00
sess_vuid = register_vuid ( server_info , session_key , nt_resp . data ? nt_resp : lm_resp , sub_user ) ;
2003-07-18 04:53:34 +04:00
data_blob_free ( & nt_resp ) ;
2004-04-05 18:27:23 +04:00
data_blob_free ( & lm_resp ) ;
2003-07-18 04:53:34 +04:00
2001-10-15 11:50:21 +04:00
if ( sess_vuid = = - 1 ) {
return ERROR_NT ( NT_STATUS_LOGON_FAILURE ) ;
}
2004-03-20 01:06:54 +03:00
/* current_user_info is changed on new vuid */
reload_services ( True ) ;
2004-03-27 10:33:59 +03:00
if ( ! server_info - > guest & & ! srv_signing_started ( ) & & ! srv_check_sign_mac ( inbuf , True ) ) {
2003-07-18 04:53:34 +04:00
exit_server ( " reply_sesssetup_and_X: bad smb signature " ) ;
}
2001-10-15 11:50:21 +04:00
SSVAL ( outbuf , smb_uid , sess_vuid ) ;
SSVAL ( inbuf , smb_uid , sess_vuid ) ;
if ( ! done_sesssetup )
max_send = MIN ( max_send , smb_bufsize ) ;
done_sesssetup = True ;
END_PROFILE ( SMBsesssetupX ) ;
return chain_reply ( inbuf , outbuf , length , bufsize ) ;
}