2007-08-24 01:34:08 +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
2007-08-02 22:28:41 +04:00
Copyright ( C ) Volker Lendecke 2007
2007-08-21 06:04:24 +04:00
Copyright ( C ) Jeremy Allison 2007
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
2007-07-09 23:25:36 +04:00
the Free Software Foundation ; either version 3 of the License , or
2001-10-15 11:50:21 +04:00
( at your option ) any later version .
2007-08-21 06:04:24 +04:00
2001-10-15 11:50:21 +04:00
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
2007-08-21 06:04:24 +04:00
2001-10-15 11:50:21 +04:00
You should have received a copy of the GNU General Public License
2007-07-10 04:52:41 +04:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2001-10-15 11:50:21 +04:00
*/
# include "includes.h"
2006-12-12 20:38:42 +03:00
extern struct auth_context * negprot_global_auth_context ;
2007-10-19 04:40:25 +04:00
extern bool global_encrypted_passwords_negotiated ;
extern bool global_spnego_negotiated ;
2006-12-12 20:38:42 +03:00
extern enum protocol_types Protocol ;
extern int max_send ;
2001-11-09 01:19:01 +03:00
uint32 global_client_caps = 0 ;
2003-01-28 15:07:02 +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
*/
2007-08-21 06:04:24 +04:00
static NTSTATUS do_map_to_guest ( NTSTATUS status ,
auth_serversupplied_info * * server_info ,
2001-12-20 12:06:53 +03:00
const char * user , const char * domain )
{
if ( NT_STATUS_EQUAL ( status , NT_STATUS_NO_SUCH_USER ) ) {
2007-08-21 06:04:24 +04:00
if ( ( lp_map_to_guest ( ) = = MAP_TO_GUEST_ON_BAD_USER ) | |
2001-12-20 12:06:53 +03:00
( lp_map_to_guest ( ) = = MAP_TO_GUEST_ON_BAD_PASSWORD ) ) {
DEBUG ( 3 , ( " No such user %s [%s] - using guest account \n " ,
user , domain ) ) ;
2008-05-06 19:26:49 +04:00
status = make_server_info_guest ( NULL , 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 ) {
2007-08-21 06:04:24 +04:00
DEBUG ( 3 , ( " Registered username %s for guest access \n " ,
user ) ) ;
2008-05-06 19:26:49 +04:00
status = make_server_info_guest ( NULL , 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
2007-07-26 20:01:12 +04:00
static int push_signature ( uint8 * * outbuf )
2001-11-12 03:08:30 +03:00
{
2007-07-26 20:01:12 +04:00
char * lanman ;
int result , tmp ;
2003-04-29 17:28:48 +04:00
2007-07-26 20:01:12 +04:00
result = 0 ;
2003-04-29 17:28:48 +04:00
2007-07-26 20:01:12 +04:00
tmp = message_push_string ( outbuf , " Unix " , STR_TERMINATE ) ;
2003-05-21 02:54:58 +04:00
2007-07-26 20:01:12 +04:00
if ( tmp = = - 1 ) return - 1 ;
result + = tmp ;
if ( asprintf ( & lanman , " Samba %s " , SAMBA_VERSION_STRING ) ! = - 1 ) {
tmp = message_push_string ( outbuf , lanman , STR_TERMINATE ) ;
SAFE_FREE ( lanman ) ;
}
else {
tmp = message_push_string ( outbuf , " Samba " , STR_TERMINATE ) ;
}
if ( tmp = = - 1 ) return - 1 ;
result + = tmp ;
tmp = message_push_string ( outbuf , lp_workgroup ( ) , STR_TERMINATE ) ;
if ( tmp = = - 1 ) return - 1 ;
result + = tmp ;
return result ;
2001-11-12 03:08:30 +03:00
}
2006-02-22 02:21:28 +03:00
/****************************************************************************
Start the signing engine if needed . Don ' t fail signing here .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-08-21 06:04:24 +04:00
static void sessionsetup_start_signing_engine (
const auth_serversupplied_info * server_info ,
const uint8 * inbuf )
2006-02-22 02:21:28 +03:00
{
if ( ! server_info - > guest & & ! srv_signing_started ( ) ) {
/* 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 .
*/
2007-08-21 06:04:24 +04:00
srv_check_sign_mac ( ( char * ) inbuf , False ) ;
2006-02-22 02:21:28 +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
2008-01-05 02:37:24 +03:00
static void reply_sesssetup_blob ( struct smb_request * req ,
2007-07-26 20:01:12 +04:00
DATA_BLOB blob ,
NTSTATUS nt_status )
2003-01-28 15:07:02 +03:00
{
2007-07-26 20:01:12 +04:00
if ( ! NT_STATUS_IS_OK ( nt_status ) & &
! NT_STATUS_EQUAL ( nt_status , NT_STATUS_MORE_PROCESSING_REQUIRED ) ) {
reply_nterror ( req , nt_status_squash ( nt_status ) ) ;
2008-10-22 19:01:28 +04:00
return ;
}
nt_status = nt_status_squash ( nt_status ) ;
SIVAL ( req - > outbuf , smb_rcls , NT_STATUS_V ( nt_status ) ) ;
SSVAL ( req - > outbuf , smb_vwv0 , 0xFF ) ; /* no chaining possible */
SSVAL ( req - > outbuf , smb_vwv3 , blob . length ) ;
if ( ( message_push_blob ( & req - > outbuf , blob ) = = - 1 )
| | ( push_signature ( & req - > outbuf ) = = - 1 ) ) {
reply_nterror ( req , NT_STATUS_NO_MEMORY ) ;
2006-04-18 07:45:09 +04:00
}
2003-01-28 15:07:02 +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
/****************************************************************************
2007-08-21 06:04:24 +04:00
Do a ' guest ' logon , getting back the
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
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2003-07-16 03:05:57 +04:00
2007-08-21 06:04:24 +04:00
static NTSTATUS check_guest_password ( auth_serversupplied_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
{
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 ;
2007-08-21 06:04:24 +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
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 " ) ) ;
2007-08-21 06:04:24 +04:00
if ( ! NT_STATUS_IS_OK ( nt_status = make_auth_context_fixed ( & auth_context ,
chal ) ) ) {
2002-01-05 07:55:41 +03:00
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 ;
}
2007-08-21 06:04:24 +04: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
2007-03-15 22:18:18 +03:00
#if 0
/* Experiment that failed. See "only happens with a KDC" comment below. */
2001-10-18 14:26:06 +04:00
/****************************************************************************
2007-03-15 22:18:18 +03:00
Cerate a clock skew error blob for a Windows client .
2001-10-18 14:26:06 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-03-15 22:18:18 +03:00
2007-10-19 04:40:25 +04:00
static bool make_krb5_skew_error ( DATA_BLOB * pblob_out )
2007-03-15 22:18:18 +03:00
{
krb5_context context = NULL ;
krb5_error_code kerr = 0 ;
krb5_data reply ;
krb5_principal host_princ = NULL ;
char * host_princ_s = NULL ;
2007-10-19 04:40:25 +04:00
bool ret = False ;
2007-03-15 22:18:18 +03:00
2007-05-14 16:16:20 +04:00
* pblob_out = data_blob_null ;
2007-03-15 22:18:18 +03:00
2007-03-16 00:53:53 +03:00
initialize_krb5_error_table ( ) ;
2007-03-15 22:18:18 +03:00
kerr = krb5_init_context ( & context ) ;
if ( kerr ) {
return False ;
}
/* Create server principal. */
asprintf ( & host_princ_s , " %s$@%s " , global_myname ( ) , lp_realm ( ) ) ;
if ( ! host_princ_s ) {
goto out ;
}
strlower_m ( host_princ_s ) ;
kerr = smb_krb5_parse_name ( context , host_princ_s , & host_princ ) ;
if ( kerr ) {
2007-08-21 06:04:24 +04:00
DEBUG ( 10 , ( " make_krb5_skew_error: smb_krb5_parse_name failed "
" for name %s: Error %s \n " ,
2007-03-15 22:18:18 +03:00
host_princ_s , error_message ( kerr ) ) ) ;
goto out ;
}
2007-08-21 06:04:24 +04:00
kerr = smb_krb5_mk_error ( context , KRB5KRB_AP_ERR_SKEW ,
host_princ , & reply ) ;
2007-03-15 22:18:18 +03:00
if ( kerr ) {
2007-08-21 06:04:24 +04:00
DEBUG ( 10 , ( " make_krb5_skew_error: smb_krb5_mk_error "
" failed: Error %s \n " ,
2007-03-15 22:18:18 +03:00
error_message ( kerr ) ) ) ;
goto out ;
}
* pblob_out = data_blob ( reply . data , reply . length ) ;
kerberos_free_data_contents ( context , & reply ) ;
ret = True ;
out :
if ( host_princ_s ) {
SAFE_FREE ( host_princ_s ) ;
}
if ( host_princ ) {
krb5_free_principal ( context , host_princ ) ;
}
krb5_free_context ( context ) ;
return ret ;
}
# endif
/****************************************************************************
Reply to a session setup spnego negotiate packet for kerberos .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-01-05 02:37:24 +03:00
static void reply_spnego_kerberos ( struct smb_request * req ,
2007-07-26 20:01:12 +04:00
DATA_BLOB * secblob ,
2008-04-08 02:02:56 +04:00
const char * mechOID ,
2007-07-26 20:01:12 +04:00
uint16 vuid ,
2007-10-19 04:40:25 +04:00
bool * p_invalidate_vuid )
2001-10-18 14:26:06 +04:00
{
2005-09-30 21:13:37 +04:00
TALLOC_CTX * mem_ctx ;
2001-10-18 14:26:06 +04:00
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 ;
2005-06-08 18:23:49 +04:00
fstring user ;
2007-08-26 14:50:39 +04:00
int sess_vuid = req - > vuid ;
2007-08-21 05:43:22 +04:00
NTSTATUS ret = NT_STATUS_OK ;
2008-02-16 20:55:08 +03:00
struct PAC_DATA * pac_data = NULL ;
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 ;
2007-05-14 16:16:20 +04:00
DATA_BLOB session_key = data_blob_null ;
2003-03-18 01:45:16 +03:00
uint8 tok_id [ 2 ] ;
2007-05-14 16:16:20 +04:00
DATA_BLOB nullblob = data_blob_null ;
2004-03-16 19:41:54 +03:00
fstring real_username ;
2007-10-19 04:40:25 +04:00
bool map_domainuser_to_guest = False ;
bool username_was_mapped ;
2008-02-16 20:55:08 +03:00
struct PAC_LOGON_INFO * logon_info = NULL ;
2001-10-18 14:26:06 +04:00
2003-05-01 22:11:24 +04:00
ZERO_STRUCT ( ticket ) ;
ZERO_STRUCT ( ap_rep ) ;
ZERO_STRUCT ( ap_rep_wrapped ) ;
ZERO_STRUCT ( response ) ;
2007-03-15 22:18:18 +03:00
/* Normally we will always invalidate the intermediate vuid. */
* p_invalidate_vuid = True ;
2005-09-30 21:13:37 +04:00
mem_ctx = talloc_init ( " reply_spnego_kerberos " ) ;
2007-03-15 22:18:18 +03:00
if ( mem_ctx = = NULL ) {
2007-07-26 20:01:12 +04:00
reply_nterror ( req , nt_status_squash ( NT_STATUS_NO_MEMORY ) ) ;
return ;
2007-03-15 22:18:18 +03:00
}
2005-09-30 21:13:37 +04:00
2003-03-18 01:45:16 +03:00
if ( ! spnego_parse_krb5_wrap ( * secblob , & ticket , tok_id ) ) {
2005-11-22 13:22:59 +03:00
talloc_destroy ( mem_ctx ) ;
2007-07-26 20:01:12 +04:00
reply_nterror ( req , nt_status_squash ( NT_STATUS_LOGON_FAILURE ) ) ;
return ;
2001-10-18 14:26:06 +04:00
}
2007-08-21 06:04:24 +04:00
ret = ads_verify_ticket ( mem_ctx , lp_realm ( ) , 0 , & ticket ,
& client , & pac_data , & ap_rep ,
2007-06-14 00:49:20 +04:00
& session_key , True ) ;
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 ) ) {
2007-03-15 22:18:18 +03:00
#if 0
2007-08-21 06:04:24 +04:00
/* Experiment that failed.
* See " only happens with a KDC " comment below . */
2007-03-15 22:18:18 +03:00
if ( NT_STATUS_EQUAL ( ret , NT_STATUS_TIME_DIFFERENCE_AT_DC ) ) {
/*
2007-08-21 06:04:24 +04:00
* Windows in this case returns
* NT_STATUS_MORE_PROCESSING_REQUIRED
* with a negTokenTarg blob containing an krb5_error
* struct ASN1 encoded containing KRB5KRB_AP_ERR_SKEW .
* The client then fixes its clock and continues rather
* than giving an error . JRA .
2007-03-15 22:18:18 +03:00
* - - Looks like this only happens with a KDC . JRA .
*/
2007-10-19 04:40:25 +04:00
bool ok = make_krb5_skew_error ( & ap_rep ) ;
2007-03-15 22:18:18 +03:00
if ( ! ok ) {
talloc_destroy ( mem_ctx ) ;
2007-08-21 06:04:24 +04:00
return ERROR_NT ( nt_status_squash (
NT_STATUS_LOGON_FAILURE ) ) ;
2007-03-15 22:18:18 +03:00
}
2007-08-21 06:04:24 +04:00
ap_rep_wrapped = spnego_gen_krb5_wrap ( ap_rep ,
TOK_ID_KRB_ERROR ) ;
response = spnego_gen_auth_response ( & ap_rep_wrapped ,
ret , OID_KERBEROS5_OLD ) ;
reply_sesssetup_blob ( conn , inbuf , outbuf , response ,
NT_STATUS_MORE_PROCESSING_REQUIRED ) ;
2007-03-15 22:18:18 +03:00
/*
2007-08-21 06:04:24 +04:00
* In this one case we don ' t invalidate the
* intermediate vuid as we ' re expecting the client
* to re - use it for the next sessionsetupX packet . JRA .
2007-03-15 22:18:18 +03:00
*/
* p_invalidate_vuid = False ;
data_blob_free ( & ap_rep ) ;
data_blob_free ( & ap_rep_wrapped ) ;
data_blob_free ( & response ) ;
talloc_destroy ( mem_ctx ) ;
return - 1 ; /* already replied */
}
# else
if ( ! NT_STATUS_EQUAL ( ret , NT_STATUS_TIME_DIFFERENCE_AT_DC ) ) {
ret = NT_STATUS_LOGON_FAILURE ;
}
# endif
2007-08-21 06:04:24 +04:00
DEBUG ( 1 , ( " Failed to verify incoming ticket with error %s! \n " ,
nt_errstr ( ret ) ) ) ;
2005-11-22 13:22:59 +03:00
talloc_destroy ( mem_ctx ) ;
2007-07-26 20:01:12 +04:00
reply_nterror ( req , nt_status_squash ( ret ) ) ;
return ;
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 ) ;
2004-05-20 01:49:58 +04:00
data_blob_free ( & session_key ) ;
2003-08-15 05:46:09 +04:00
SAFE_FREE ( client ) ;
2005-11-22 13:22:59 +03:00
talloc_destroy ( mem_ctx ) ;
2007-07-26 20:01:12 +04:00
reply_nterror ( req , nt_status_squash ( NT_STATUS_LOGON_FAILURE ) ) ;
return ;
2001-10-20 10:31:25 +04:00
}
* p = 0 ;
2005-11-11 06:03:41 +03:00
/* save the PAC data if we have it */
if ( pac_data ) {
logon_info = get_logon_info_from_pac ( pac_data ) ;
2006-03-30 03:45:08 +04:00
if ( logon_info ) {
netsamlogon_cache_store ( client , & logon_info - > info3 ) ;
}
2005-11-11 06:03:41 +03:00
}
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 ) ;
2004-05-20 01:49:58 +04:00
data_blob_free ( & session_key ) ;
2003-08-15 05:46:09 +04:00
SAFE_FREE ( client ) ;
2005-11-22 13:22:59 +03:00
talloc_destroy ( mem_ctx ) ;
2007-07-26 20:01:12 +04:00
reply_nterror ( req , nt_status_squash (
NT_STATUS_LOGON_FAILURE ) ) ;
return ;
2001-12-19 12:53:30 +03:00
}
2003-02-24 05:35:54 +03:00
}
/* 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 ;
2008-02-16 20:55:08 +03:00
if ( logon_info & & logon_info - > info3 . base . domain . string ) {
fstrcpy ( netbios_domain_name ,
logon_info - > info3 . base . domain . string ) ;
2005-09-30 21:13:37 +04:00
domain = netbios_domain_name ;
DEBUG ( 10 , ( " Mapped to [%s] (using PAC) \n " , domain ) ) ;
} else {
2004-01-04 14:51:31 +03:00
/* 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 . */
2008-02-04 15:47:15 +03:00
wbcErr wbc_status ;
struct wbcDomainInfo * info = NULL ;
2004-01-04 14:51:31 +03:00
DEBUG ( 10 , ( " Mapping [%s] to short name \n " , domain ) ) ;
2008-02-04 15:47:15 +03:00
wbc_status = wbcDomainInfo ( domain , & info ) ;
2004-01-04 14:51:31 +03:00
2008-02-04 15:47:15 +03:00
if ( WBC_ERROR_IS_OK ( wbc_status ) ) {
2004-01-04 14:51:31 +03:00
fstrcpy ( netbios_domain_name ,
2008-02-04 15:47:15 +03:00
info - > short_name ) ;
2004-01-04 14:51:31 +03:00
2008-02-04 15:47:15 +03:00
wbcFreeMemory ( info ) ;
domain = netbios_domain_name ;
2005-09-30 21:13:37 +04:00
DEBUG ( 10 , ( " Mapped to [%s] (using Winbind) \n " , domain ) ) ;
2004-01-04 14:51:31 +03:00
} else {
2008-02-04 15:47:15 +03:00
DEBUG ( 3 , ( " Could not find short name: %s \n " ,
wbcErrorString ( wbc_status ) ) ) ;
2004-01-04 14:51:31 +03:00
}
}
2005-06-08 18:23:49 +04:00
fstr_sprintf ( user , " %s%c%s " , domain , * lp_winbind_separator ( ) , client ) ;
2007-08-21 06:04:24 +04:00
2004-03-16 19:41:54 +03:00
/* lookup the passwd struct, create a new user if necessary */
2006-05-06 23:24:35 +04:00
username_was_mapped = map_username ( user ) ;
2004-07-07 01:43:12 +04:00
2006-02-04 01:19:41 +03:00
pw = smb_getpwnam ( mem_ctx , user , real_username , True ) ;
2006-12-01 18:06:34 +03:00
if ( pw ) {
/* if a real user check pam account restrictions */
/* only really perfomed if "obey pam restriction" is true */
2008-04-30 14:58:40 +04:00
/* do this before an eventual mapping to guest occurs */
2006-12-01 18:06:34 +03:00
ret = smb_pam_accountcheck ( pw - > pw_name ) ;
if ( ! NT_STATUS_IS_OK ( ret ) ) {
2007-08-21 06:04:24 +04:00
DEBUG ( 1 , ( " PAM account restriction "
" prevents user login \n " ) ) ;
2006-12-01 18:06:34 +03:00
data_blob_free ( & ap_rep ) ;
data_blob_free ( & session_key ) ;
2006-12-01 19:13:06 +03:00
TALLOC_FREE ( mem_ctx ) ;
2007-07-26 20:01:12 +04:00
reply_nterror ( req , nt_status_squash ( ret ) ) ;
return ;
2006-12-01 18:06:34 +03:00
}
}
2001-10-20 10:31:25 +04:00
if ( ! pw ) {
2005-06-08 18:23:49 +04:00
/* this was originally the behavior of Samba 2.2, if a user
2007-08-21 06:04:24 +04:00
did not have a local uid but has been authenticated , then
2005-06-08 18:23:49 +04:00
map them to a guest account */
2007-08-21 06:04:24 +04:00
if ( lp_map_to_guest ( ) = = MAP_TO_GUEST_ON_BAD_UID ) {
2005-06-08 18:23:49 +04:00
map_domainuser_to_guest = True ;
fstrcpy ( user , lp_guestaccount ( ) ) ;
2006-02-04 01:19:41 +03:00
pw = smb_getpwnam ( mem_ctx , user , real_username , True ) ;
2007-08-21 06:04:24 +04:00
}
2005-06-08 18:23:49 +04:00
/* extra sanity check that the guest account is valid */
if ( ! pw ) {
2007-08-21 06:04:24 +04:00
DEBUG ( 1 , ( " Username %s is invalid on this system \n " ,
user ) ) ;
2005-06-08 18:23:49 +04:00
SAFE_FREE ( client ) ;
data_blob_free ( & ap_rep ) ;
data_blob_free ( & session_key ) ;
2006-12-01 19:13:06 +03:00
TALLOC_FREE ( mem_ctx ) ;
2007-07-26 20:01:12 +04:00
reply_nterror ( req , nt_status_squash (
NT_STATUS_LOGON_FAILURE ) ) ;
return ;
2005-06-08 18:23:49 +04:00
}
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 */
2007-08-21 06:04:24 +04:00
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 ) ;
2006-08-29 19:42:09 +04:00
2005-06-08 18:23:49 +04:00
if ( map_domainuser_to_guest ) {
2008-05-06 19:26:49 +04:00
make_server_info_guest ( NULL , & server_info ) ;
2005-09-30 21:13:37 +04:00
} else if ( logon_info ) {
2007-08-21 06:04:24 +04:00
/* pass the unmapped username here since map_username()
2006-08-29 19:42:09 +04:00
will be called again from inside make_server_info_info3 ( ) */
2007-08-21 06:04:24 +04:00
ret = make_server_info_info3 ( mem_ctx , client , domain ,
2006-03-10 11:43:32 +03:00
& server_info , & logon_info - > info3 ) ;
2005-09-30 21:13:37 +04:00
if ( ! NT_STATUS_IS_OK ( ret ) ) {
2006-03-10 11:43:32 +03:00
DEBUG ( 1 , ( " make_server_info_info3 failed: %s! \n " ,
2006-02-04 01:19:41 +03:00
nt_errstr ( ret ) ) ) ;
2005-09-30 21:13:37 +04:00
SAFE_FREE ( client ) ;
data_blob_free ( & ap_rep ) ;
data_blob_free ( & session_key ) ;
2006-12-01 18:04:53 +03:00
TALLOC_FREE ( mem_ctx ) ;
2007-07-26 20:01:12 +04:00
reply_nterror ( req , nt_status_squash ( ret ) ) ;
return ;
2005-09-30 21:13:37 +04:00
}
2005-06-08 18:23:49 +04:00
} else {
ret = make_server_info_pw ( & server_info , real_username , pw ) ;
2005-09-30 21:13:37 +04:00
2005-06-08 18:23:49 +04:00
if ( ! NT_STATUS_IS_OK ( ret ) ) {
2006-02-04 01:19:41 +03:00
DEBUG ( 1 , ( " make_server_info_pw failed: %s! \n " ,
nt_errstr ( ret ) ) ) ;
2005-06-08 18:23:49 +04:00
SAFE_FREE ( client ) ;
data_blob_free ( & ap_rep ) ;
data_blob_free ( & session_key ) ;
2006-12-01 18:04:53 +03:00
TALLOC_FREE ( mem_ctx ) ;
2007-07-26 20:01:12 +04:00
reply_nterror ( req , nt_status_squash ( ret ) ) ;
return ;
2005-06-08 18:23:49 +04:00
}
2005-09-30 21:13:37 +04:00
2006-02-04 01:19:41 +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 . */
2005-09-30 21:13:37 +04:00
if ( server_info - > sam_account ! = NULL ) {
2007-08-21 06:04:24 +04:00
pdb_set_domain ( server_info - > sam_account ,
domain , PDB_SET ) ;
2005-09-30 21:13:37 +04:00
}
2001-10-31 15:37:56 +03:00
}
2006-05-06 23:24:35 +04:00
2008-05-06 19:37:00 +04:00
server_info - > nss_token | = username_was_mapped ;
2007-08-21 06:04:24 +04:00
2006-03-10 01:31:37 +03:00
/* we need to build the token for the user. make_server_info_guest()
already does this */
2007-08-21 06:04:24 +04:00
2006-03-10 01:31:37 +03:00
if ( ! server_info - > ptok ) {
ret = create_local_token ( server_info ) ;
if ( ! NT_STATUS_IS_OK ( ret ) ) {
2008-03-06 14:24:37 +03:00
DEBUG ( 10 , ( " failed to create local token: %s \n " ,
nt_errstr ( ret ) ) ) ;
2006-03-10 01:31:37 +03:00
SAFE_FREE ( client ) ;
data_blob_free ( & ap_rep ) ;
data_blob_free ( & session_key ) ;
TALLOC_FREE ( mem_ctx ) ;
TALLOC_FREE ( server_info ) ;
2007-07-26 20:01:12 +04:00
reply_nterror ( req , nt_status_squash ( ret ) ) ;
return ;
2006-03-10 01:31:37 +03:00
}
}
2003-03-18 01:45:16 +03:00
2007-08-21 05:43:22 +04:00
/* register_existing_vuid keeps the server info */
/* register_existing_vuid takes ownership of session_key on success,
* no need to free after this on success . A better interface would copy
* it . . . . */
if ( ! is_partial_auth_vuid ( sess_vuid ) ) {
sess_vuid = register_initial_vuid ( ) ;
}
2008-04-30 16:26:16 +04:00
data_blob_free ( & server_info - > user_session_key ) ;
server_info - > user_session_key = session_key ;
session_key = data_blob_null ;
2007-08-21 05:43:22 +04:00
sess_vuid = register_existing_vuid ( sess_vuid ,
server_info ,
nullblob ,
client ) ;
2001-10-31 15:37:56 +03:00
2004-01-07 22:55:01 +03:00
SAFE_FREE ( client ) ;
2001-10-20 10:31:25 +04:00
2007-07-26 20:01:12 +04:00
reply_outbuf ( req , 4 , 0 ) ;
2007-08-21 05:43:22 +04:00
SSVAL ( req - > outbuf , smb_uid , sess_vuid ) ;
2007-07-26 20:01:12 +04:00
2006-03-10 01:31:37 +03:00
if ( sess_vuid = = UID_FIELD_INVALID ) {
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 ) ;
2007-07-26 20:01:12 +04:00
SSVAL ( req - > outbuf , smb_vwv3 , 0 ) ;
2007-08-21 06:04:24 +04:00
2003-03-18 01:45:16 +03:00
if ( server_info - > guest ) {
2007-07-26 20:01:12 +04:00
SSVAL ( req - > outbuf , smb_vwv2 , 1 ) ;
2003-03-18 01:45:16 +03:00
}
2007-08-21 06:04:24 +04:00
2007-07-26 20:01:12 +04:00
SSVAL ( req - > outbuf , smb_uid , sess_vuid ) ;
2003-07-18 04:53:34 +04:00
2007-07-26 20:01:12 +04:00
sessionsetup_start_signing_engine ( server_info , req - > inbuf ) ;
2007-08-21 05:43:22 +04:00
/* Successful logon. Keep this vuid. */
* p_invalidate_vuid = False ;
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 ) ) {
2007-08-21 06:04:24 +04:00
ap_rep_wrapped = spnego_gen_krb5_wrap ( ap_rep ,
TOK_ID_KRB_AP_REP ) ;
2003-03-18 01:45:16 +03:00
} else {
2007-05-14 16:16:20 +04:00
ap_rep_wrapped = data_blob_null ;
2003-03-18 01:45:16 +03:00
}
2007-08-21 06:04:24 +04:00
response = spnego_gen_auth_response ( & ap_rep_wrapped , ret ,
2008-04-08 02:02:56 +04:00
mechOID ) ;
2008-01-05 02:37:24 +03:00
reply_sesssetup_blob ( req , response , ret ) ;
2003-03-18 01:45:16 +03:00
data_blob_free ( & ap_rep ) ;
data_blob_free ( & ap_rep_wrapped ) ;
data_blob_free ( & response ) ;
2006-12-01 18:04:53 +03:00
TALLOC_FREE ( mem_ctx ) ;
2001-10-18 14:26:06 +04:00
}
2007-07-26 20:01:12 +04:00
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
2005-09-30 21:13:37 +04:00
This should be split into two functions , one to handle each
leg of the NTLM auth steps .
2003-01-28 15:07:02 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2003-07-16 03:05:57 +04:00
2008-01-05 02:37:24 +03:00
static void reply_spnego_ntlmssp ( struct smb_request * req ,
2005-07-14 18:39:27 +04:00
uint16 vuid ,
2003-01-28 15:07:02 +03:00
AUTH_NTLMSSP_STATE * * auth_ntlmssp_state ,
2007-07-26 20:01:12 +04:00
DATA_BLOB * ntlmssp_blob , NTSTATUS nt_status ,
2008-02-15 05:10:50 +03:00
const char * OID ,
2007-10-19 04:40:25 +04:00
bool wrap )
2001-10-17 12:54:19 +04:00
{
2003-01-28 15:07:02 +03:00
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 {
2007-08-21 06:04:24 +04:00
nt_status = do_map_to_guest ( nt_status ,
& server_info ,
( * auth_ntlmssp_state ) - > ntlmssp_state - > user ,
( * auth_ntlmssp_state ) - > ntlmssp_state - > domain ) ;
2003-01-28 15:07:02 +03:00
}
2001-10-17 12:54:19 +04:00
2007-07-26 20:01:12 +04:00
reply_outbuf ( req , 4 , 0 ) ;
SSVAL ( req - > outbuf , smb_uid , vuid ) ;
2003-01-28 15:07:02 +03:00
if ( NT_STATUS_IS_OK ( nt_status ) ) {
2007-05-14 16:16:20 +04:00
DATA_BLOB nullblob = data_blob_null ;
2003-07-18 04:53:34 +04:00
2007-08-21 05:43:22 +04:00
if ( ! is_partial_auth_vuid ( vuid ) ) {
nt_status = NT_STATUS_LOGON_FAILURE ;
goto out ;
}
2008-04-30 16:26:16 +04:00
data_blob_free ( & server_info - > user_session_key ) ;
server_info - > user_session_key =
2008-05-11 02:23:01 +04:00
data_blob_talloc (
server_info ,
2008-04-30 16:26:16 +04:00
( * auth_ntlmssp_state ) - > ntlmssp_state - > session_key . data ,
( * auth_ntlmssp_state ) - > ntlmssp_state - > session_key . length ) ;
2007-08-21 05:43:22 +04:00
/* register_existing_vuid keeps the server info */
if ( register_existing_vuid ( vuid ,
2008-04-30 16:26:16 +04:00
server_info , nullblob ,
2007-08-21 05:43:22 +04:00
( * auth_ntlmssp_state ) - > ntlmssp_state - > user ) ! =
vuid ) {
nt_status = NT_STATUS_LOGON_FAILURE ;
goto out ;
}
2003-02-24 05:35:54 +03:00
( * auth_ntlmssp_state ) - > server_info = NULL ;
2007-08-21 05:43:22 +04:00
/* current_user_info is changed on new vuid */
reload_services ( True ) ;
2004-03-20 01:06:54 +03:00
2007-08-21 05:43:22 +04:00
SSVAL ( req - > outbuf , smb_vwv3 , 0 ) ;
2003-07-18 04:53:34 +04:00
2007-08-21 05:43:22 +04:00
if ( server_info - > guest ) {
SSVAL ( req - > outbuf , smb_vwv2 , 1 ) ;
2003-01-28 15:07:02 +03:00
}
2007-08-21 05:43:22 +04:00
2007-08-26 14:50:39 +04:00
sessionsetup_start_signing_engine ( server_info ,
( uint8 * ) req - > inbuf ) ;
2003-01-28 15:07:02 +03:00
}
2001-10-17 12:54:19 +04:00
2007-08-21 05:43:22 +04:00
out :
2005-08-02 10:36:42 +04:00
if ( wrap ) {
2007-08-21 06:04:24 +04:00
response = spnego_gen_auth_response ( ntlmssp_blob ,
2008-02-15 05:10:50 +03:00
nt_status , OID ) ;
2005-08-02 10:36:42 +04:00
} else {
response = * ntlmssp_blob ;
}
2008-01-05 02:37:24 +03:00
reply_sesssetup_blob ( req , response , nt_status ) ;
2005-08-02 10:36:42 +04:00
if ( wrap ) {
data_blob_free ( & response ) ;
}
2003-01-28 15:07:02 +03:00
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 . */
2007-07-26 20:01:12 +04:00
if ( ! NT_STATUS_EQUAL ( nt_status , NT_STATUS_MORE_PROCESSING_REQUIRED ) ) {
2005-09-30 21:13:37 +04:00
/* NB. This is *NOT* an error case. JRA */
2003-02-24 05:35:54 +03:00
auth_ntlmssp_end ( auth_ntlmssp_state ) ;
2007-08-21 05:43:22 +04:00
if ( ! NT_STATUS_IS_OK ( nt_status ) ) {
/* Kill the intermediate vuid */
invalidate_vuid ( vuid ) ;
}
2003-01-28 15:07:02 +03:00
}
2001-10-17 12:54:19 +04:00
}
/****************************************************************************
2007-03-15 22:18:18 +03:00
Is this a krb5 mechanism ?
2001-10-17 12:54:19 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2003-07-16 03:05:57 +04:00
2008-04-08 02:02:56 +04:00
NTSTATUS parse_spnego_mechanisms ( DATA_BLOB blob_in ,
DATA_BLOB * pblob_out ,
char * * kerb_mechOID )
2001-10-17 12:54:19 +04:00
{
char * OIDs [ ASN1_MAX_OIDS ] ;
int i ;
2008-04-08 02:02:56 +04:00
NTSTATUS ret = NT_STATUS_OK ;
2001-10-17 12:54:19 +04:00
2008-04-08 02:02:56 +04:00
* kerb_mechOID = NULL ;
2005-07-14 18:39:27 +04:00
2007-03-15 22:18:18 +03:00
/* parse out the OIDs and the first sec blob */
if ( ! parse_negTokenTarg ( blob_in , OIDs , pblob_out ) ) {
return NT_STATUS_LOGON_FAILURE ;
2001-10-17 12:54:19 +04:00
}
2003-07-31 23:01:22 +04:00
/* only look at the first OID for determining the mechToken --
2007-08-21 06:04:24 +04:00
according 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
2003-07-31 23:01:22 +04:00
NTLMSSP mechtoken . - - jerry */
2005-03-22 18:12:50 +03:00
2007-08-21 06:04:24 +04:00
# ifdef HAVE_KRB5
2003-07-31 23:01:22 +04:00
if ( strcmp ( OID_KERBEROS5 , OIDs [ 0 ] ) = = 0 | |
strcmp ( OID_KERBEROS5_OLD , OIDs [ 0 ] ) = = 0 ) {
2008-04-08 02:02:56 +04:00
* kerb_mechOID = SMB_STRDUP ( OIDs [ 0 ] ) ;
if ( * kerb_mechOID = = NULL ) {
ret = NT_STATUS_NO_MEMORY ;
}
2003-07-31 23:01:22 +04:00
}
2005-03-22 18:12:50 +03:00
# endif
2007-08-21 06:04:24 +04:00
2001-10-17 12:54:19 +04:00
for ( i = 0 ; OIDs [ i ] ; i + + ) {
2007-03-15 22:18:18 +03:00
DEBUG ( 5 , ( " parse_spnego_mechanisms: Got OID %s \n " , OIDs [ i ] ) ) ;
2001-10-17 12:54:19 +04:00
free ( OIDs [ i ] ) ;
}
2008-04-08 02:02:56 +04:00
return ret ;
2007-03-15 22:18:18 +03:00
}
2008-02-15 05:10:50 +03:00
/****************************************************************************
Fall back from krb5 to NTLMSSP .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static void reply_spnego_downgrade_to_ntlmssp ( struct smb_request * req ,
uint16 vuid )
{
DATA_BLOB response ;
reply_outbuf ( req , 4 , 0 ) ;
SSVAL ( req - > outbuf , smb_uid , vuid ) ;
DEBUG ( 3 , ( " reply_spnego_downgrade_to_ntlmssp: Got krb5 ticket in SPNEGO "
" but set to downgrade to NTLMSSP \n " ) ) ;
response = spnego_gen_auth_response ( NULL ,
NT_STATUS_MORE_PROCESSING_REQUIRED ,
OID_NTLMSSP ) ;
reply_sesssetup_blob ( req , response , NT_STATUS_MORE_PROCESSING_REQUIRED ) ;
data_blob_free ( & response ) ;
}
2007-03-15 22:18:18 +03:00
/****************************************************************************
Reply to a session setup spnego negotiate packet .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-01-05 02:37:24 +03:00
static void reply_spnego_negotiate ( struct smb_request * req ,
2007-07-26 20:01:12 +04:00
uint16 vuid ,
DATA_BLOB blob1 ,
AUTH_NTLMSSP_STATE * * auth_ntlmssp_state )
2007-03-15 22:18:18 +03:00
{
DATA_BLOB secblob ;
DATA_BLOB chal ;
2008-04-08 02:02:56 +04:00
char * kerb_mech = NULL ;
2007-03-15 22:18:18 +03:00
NTSTATUS status ;
2008-04-08 02:02:56 +04:00
status = parse_spnego_mechanisms ( blob1 , & secblob , & kerb_mech ) ;
2007-03-15 22:18:18 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
/* Kill the intermediate vuid */
invalidate_vuid ( vuid ) ;
2007-07-26 20:01:12 +04:00
reply_nterror ( req , nt_status_squash ( status ) ) ;
return ;
2007-03-15 22:18:18 +03:00
}
2007-08-21 06:04:24 +04:00
DEBUG ( 3 , ( " reply_spnego_negotiate: 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
2008-04-08 02:02:56 +04:00
if ( kerb_mech & & ( ( lp_security ( ) = = SEC_ADS ) | |
2007-08-21 06:04:24 +04:00
lp_use_kerberos_keytab ( ) ) ) {
2007-10-19 04:40:25 +04:00
bool destroy_vuid = True ;
2008-04-08 02:02:56 +04:00
reply_spnego_kerberos ( req , & secblob , kerb_mech ,
vuid , & destroy_vuid ) ;
2001-10-18 14:26:06 +04:00
data_blob_free ( & secblob ) ;
2007-03-15 22:18:18 +03:00
if ( destroy_vuid ) {
/* Kill the intermediate vuid */
invalidate_vuid ( vuid ) ;
}
2008-04-08 02:02:56 +04:00
SAFE_FREE ( kerb_mech ) ;
2007-07-26 20:01:12 +04:00
return ;
2001-10-18 14:26:06 +04:00
}
# endif
2005-07-14 18:39:27 +04:00
if ( * auth_ntlmssp_state ) {
auth_ntlmssp_end ( auth_ntlmssp_state ) ;
2002-01-05 07:55:41 +03:00
}
2008-04-08 02:02:56 +04:00
if ( kerb_mech ) {
2008-02-15 05:10:50 +03:00
data_blob_free ( & secblob ) ;
/* The mechtoken is a krb5 ticket, but
* we need to fall back to NTLM . */
2008-04-08 02:02:56 +04:00
reply_spnego_downgrade_to_ntlmssp ( req , vuid ) ;
SAFE_FREE ( kerb_mech ) ;
2008-02-15 05:10:50 +03:00
return ;
}
2007-03-15 22:18:18 +03:00
status = auth_ntlmssp_start ( auth_ntlmssp_state ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
2005-07-14 18:39:27 +04:00
/* Kill the intermediate vuid */
invalidate_vuid ( vuid ) ;
2007-07-26 20:01:12 +04:00
reply_nterror ( req , nt_status_squash ( status ) ) ;
return ;
2001-10-18 14:26:06 +04:00
}
2001-10-17 12:54:19 +04:00
2007-08-21 06:04:24 +04:00
status = auth_ntlmssp_update ( * auth_ntlmssp_state ,
2003-01-28 15:07:02 +03:00
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
2008-01-05 02:37:24 +03:00
reply_spnego_ntlmssp ( req , vuid , auth_ntlmssp_state ,
2008-02-15 05:10:50 +03:00
& chal , status , OID_NTLMSSP , true ) ;
2005-08-02 10:36:42 +04:00
2001-10-17 12:54:19 +04:00
data_blob_free ( & chal ) ;
2003-01-28 15:07:02 +03:00
/* already replied */
2007-07-26 20:01:12 +04:00
return ;
2001-10-17 12:54:19 +04:00
}
2007-03-15 22:18:18 +03:00
2001-10-17 12:54:19 +04:00
/****************************************************************************
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
2008-01-05 02:37:24 +03:00
static void reply_spnego_auth ( struct smb_request * req ,
2007-07-26 20:01:12 +04:00
uint16 vuid ,
DATA_BLOB blob1 ,
AUTH_NTLMSSP_STATE * * auth_ntlmssp_state )
2001-10-17 12:54:19 +04:00
{
2007-05-14 16:16:20 +04:00
DATA_BLOB auth = data_blob_null ;
DATA_BLOB auth_reply = data_blob_null ;
DATA_BLOB secblob = data_blob_null ;
2008-02-15 05:10:50 +03:00
NTSTATUS status = NT_STATUS_LOGON_FAILURE ;
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
2005-07-14 18:39:27 +04:00
/* Kill the intermediate vuid */
invalidate_vuid ( vuid ) ;
2007-07-26 20:01:12 +04:00
reply_nterror ( req , nt_status_squash (
2008-02-15 05:10:50 +03:00
NT_STATUS_LOGON_FAILURE ) ) ;
2007-07-26 20:01:12 +04:00
return ;
2001-10-17 12:54:19 +04:00
}
2007-03-15 22:18:18 +03:00
if ( auth . data [ 0 ] = = ASN1_APPLICATION ( 0 ) ) {
/* Might be a second negTokenTarg packet */
2008-04-08 02:02:56 +04:00
char * kerb_mech = NULL ;
2007-03-15 22:18:18 +03:00
2008-04-08 02:02:56 +04:00
status = parse_spnego_mechanisms ( auth , & secblob , & kerb_mech ) ;
2008-02-15 05:10:50 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
/* Kill the intermediate vuid */
invalidate_vuid ( vuid ) ;
reply_nterror ( req , nt_status_squash ( status ) ) ;
return ;
}
DEBUG ( 3 , ( " reply_spnego_auth: Got secblob of size %lu \n " ,
( unsigned long ) secblob . length ) ) ;
2007-03-15 22:18:18 +03:00
# ifdef HAVE_KRB5
2008-04-08 02:02:56 +04:00
if ( kerb_mech & & ( ( lp_security ( ) = = SEC_ADS ) | |
2008-02-15 05:10:50 +03:00
lp_use_kerberos_keytab ( ) ) ) {
bool destroy_vuid = True ;
2008-04-08 02:02:56 +04:00
reply_spnego_kerberos ( req , & secblob , kerb_mech ,
2008-02-15 05:10:50 +03:00
vuid , & destroy_vuid ) ;
data_blob_free ( & secblob ) ;
data_blob_free ( & auth ) ;
if ( destroy_vuid ) {
/* Kill the intermediate vuid */
invalidate_vuid ( vuid ) ;
2007-03-15 22:18:18 +03:00
}
2008-04-08 02:02:56 +04:00
SAFE_FREE ( kerb_mech ) ;
2008-02-15 05:10:50 +03:00
return ;
}
2007-03-15 22:18:18 +03:00
# endif
2008-02-15 05:10:50 +03:00
/* Can't blunder into NTLMSSP auth if we have
* a krb5 ticket . */
2008-04-08 02:02:56 +04:00
if ( kerb_mech ) {
2008-02-15 05:10:50 +03:00
/* Kill the intermediate vuid */
invalidate_vuid ( vuid ) ;
DEBUG ( 3 , ( " reply_spnego_auth: network "
" misconfiguration, client sent us a "
" krb5 ticket and kerberos security "
" not enabled " ) ) ;
reply_nterror ( req , nt_status_squash (
NT_STATUS_LOGON_FAILURE ) ) ;
2008-04-08 02:02:56 +04:00
SAFE_FREE ( kerb_mech ) ;
2007-03-15 22:18:18 +03:00
}
}
/* If we get here it wasn't a negTokenTarg auth packet. */
data_blob_free ( & secblob ) ;
2007-08-21 06:04:24 +04:00
2005-07-14 18:39:27 +04:00
if ( ! * auth_ntlmssp_state ) {
2008-02-15 05:10:50 +03:00
status = auth_ntlmssp_start ( auth_ntlmssp_state ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
/* Kill the intermediate vuid */
invalidate_vuid ( vuid ) ;
reply_nterror ( req , nt_status_squash ( status ) ) ;
return ;
}
2003-03-15 02:06:06 +03:00
}
2007-08-21 06:04:24 +04:00
status = auth_ntlmssp_update ( * auth_ntlmssp_state ,
2005-07-14 18:39:27 +04:00
auth , & auth_reply ) ;
2001-10-17 12:54:19 +04:00
data_blob_free ( & auth ) ;
2001-12-20 12:06:53 +03:00
2008-02-15 05:10:50 +03:00
/* Don't send the mechid as we've already sent this (RFC4178). */
2008-01-05 02:37:24 +03:00
reply_spnego_ntlmssp ( req , vuid ,
2005-07-14 18:39:27 +04:00
auth_ntlmssp_state ,
2008-02-15 05:10:50 +03:00
& auth_reply , status , NULL , true ) ;
2007-08-21 06:04:24 +04:00
2003-01-28 15:07:02 +03:00
data_blob_free ( & auth_reply ) ;
2002-08-17 19:27:10 +04:00
/* and tell smbd that we have already replied to this packet */
2007-07-26 20:01:12 +04:00
return ;
2001-10-17 12:54:19 +04:00
}
2007-02-20 09:22:20 +03:00
/****************************************************************************
List to store partial SPNEGO auth fragments .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static struct pending_auth_data * pd_list ;
/****************************************************************************
Delete an entry on the list .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static void delete_partial_auth ( struct pending_auth_data * pad )
{
2007-02-21 05:15:23 +03:00
if ( ! pad ) {
return ;
}
2007-02-20 09:22:20 +03:00
DLIST_REMOVE ( pd_list , pad ) ;
data_blob_free ( & pad - > partial_data ) ;
SAFE_FREE ( pad ) ;
}
/****************************************************************************
Search for a partial SPNEGO auth fragment matching an smbpid .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static struct pending_auth_data * get_pending_auth_data ( uint16 smbpid )
{
struct pending_auth_data * pad ;
for ( pad = pd_list ; pad ; pad = pad - > next ) {
if ( pad - > smbpid = = smbpid ) {
break ;
}
}
return pad ;
}
/****************************************************************************
2007-08-21 06:04:24 +04:00
Check the size of an SPNEGO blob . If we need more return
NT_STATUS_MORE_PROCESSING_REQUIRED , else return NT_STATUS_OK . Don ' t allow
the blob to be more than 64 k .
2007-02-20 09:22:20 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-08-21 06:04:24 +04:00
static NTSTATUS check_spnego_blob_complete ( uint16 smbpid , uint16 vuid ,
DATA_BLOB * pblob )
2007-02-20 09:22:20 +03:00
{
2007-02-21 05:15:23 +03:00
struct pending_auth_data * pad = NULL ;
2007-02-20 09:22:20 +03:00
ASN1_DATA data ;
size_t needed_len = 0 ;
2007-02-21 05:15:23 +03:00
pad = get_pending_auth_data ( smbpid ) ;
2007-02-20 09:22:20 +03:00
/* Ensure we have some data. */
if ( pblob - > length = = 0 ) {
/* Caller can cope. */
DEBUG ( 2 , ( " check_spnego_blob_complete: zero blob length ! \n " ) ) ;
delete_partial_auth ( pad ) ;
return NT_STATUS_OK ;
}
/* Were we waiting for more data ? */
if ( pad ) {
DATA_BLOB tmp_blob ;
2007-02-21 02:56:46 +03:00
size_t copy_len = MIN ( 65536 , pblob - > length ) ;
2007-02-20 09:22:20 +03:00
/* Integer wrap paranoia.... */
2007-08-21 06:04:24 +04:00
if ( pad - > partial_data . length + copy_len <
pad - > partial_data . length | |
2007-02-21 02:56:46 +03:00
pad - > partial_data . length + copy_len < copy_len ) {
2007-02-20 09:22:20 +03:00
DEBUG ( 2 , ( " check_spnego_blob_complete: integer wrap "
" pad->partial_data.length = %u, "
2007-02-21 02:56:46 +03:00
" copy_len = %u \n " ,
2007-02-20 09:22:20 +03:00
( unsigned int ) pad - > partial_data . length ,
2007-02-21 02:56:46 +03:00
( unsigned int ) copy_len ) ) ;
2007-02-20 09:22:20 +03:00
delete_partial_auth ( pad ) ;
return NT_STATUS_INVALID_PARAMETER ;
}
DEBUG ( 10 , ( " check_spnego_blob_complete: "
" pad->partial_data.length = %u, "
" pad->needed_len = %u, "
2007-02-21 02:56:46 +03:00
" copy_len = %u, "
2007-02-20 09:22:20 +03:00
" pblob->length = %u, \n " ,
( unsigned int ) pad - > partial_data . length ,
( unsigned int ) pad - > needed_len ,
2007-02-21 02:56:46 +03:00
( unsigned int ) copy_len ,
2007-02-20 09:22:20 +03:00
( unsigned int ) pblob - > length ) ) ;
tmp_blob = data_blob ( NULL ,
2007-02-21 02:56:46 +03:00
pad - > partial_data . length + copy_len ) ;
2007-02-20 09:22:20 +03:00
2007-02-21 02:56:46 +03:00
/* Concatenate the two (up to copy_len) bytes. */
2007-02-20 09:22:20 +03:00
memcpy ( tmp_blob . data ,
pad - > partial_data . data ,
pad - > partial_data . length ) ;
memcpy ( tmp_blob . data + pad - > partial_data . length ,
pblob - > data ,
2007-02-21 02:56:46 +03:00
copy_len ) ;
2007-02-20 09:22:20 +03:00
/* Replace the partial data. */
data_blob_free ( & pad - > partial_data ) ;
pad - > partial_data = tmp_blob ;
ZERO_STRUCT ( tmp_blob ) ;
/* Are we done ? */
if ( pblob - > length > = pad - > needed_len ) {
/* Yes, replace pblob. */
data_blob_free ( pblob ) ;
* pblob = pad - > partial_data ;
ZERO_STRUCT ( pad - > partial_data ) ;
delete_partial_auth ( pad ) ;
return NT_STATUS_OK ;
}
/* Still need more data. */
2007-02-21 02:56:46 +03:00
pad - > needed_len - = copy_len ;
2007-02-20 09:22:20 +03:00
return NT_STATUS_MORE_PROCESSING_REQUIRED ;
}
if ( ( pblob - > data [ 0 ] ! = ASN1_APPLICATION ( 0 ) ) & &
( pblob - > data [ 0 ] ! = ASN1_CONTEXT ( 1 ) ) ) {
/* Not something we can determine the
* length of .
*/
return NT_STATUS_OK ;
}
/* This is a new SPNEGO sessionsetup - see if
* the data given in this blob is enough .
*/
asn1_load ( & data , * pblob ) ;
asn1_start_tag ( & data , pblob - > data [ 0 ] ) ;
if ( data . has_error | | data . nesting = = NULL ) {
asn1_free ( & data ) ;
/* Let caller catch. */
return NT_STATUS_OK ;
}
/* Integer wrap paranoia.... */
if ( data . nesting - > taglen + data . nesting - > start < data . nesting - > taglen | |
data . nesting - > taglen + data . nesting - > start < data . nesting - > start ) {
DEBUG ( 2 , ( " check_spnego_blob_complete: integer wrap "
" data.nesting->taglen = %u, "
" data.nesting->start = %u \n " ,
( unsigned int ) data . nesting - > taglen ,
( unsigned int ) data . nesting - > start ) ) ;
asn1_free ( & data ) ;
return NT_STATUS_INVALID_PARAMETER ;
}
/* Total length of the needed asn1 is the tag length
* plus the current offset . */
needed_len = data . nesting - > taglen + data . nesting - > start ;
asn1_free ( & data ) ;
DEBUG ( 10 , ( " check_spnego_blob_complete: needed_len = %u, "
" pblob->length = %u \n " ,
( unsigned int ) needed_len ,
( unsigned int ) pblob - > length ) ) ;
if ( needed_len < = pblob - > length ) {
/* Nothing to do - blob is complete. */
return NT_STATUS_OK ;
}
2007-02-21 02:56:46 +03:00
/* Refuse the blob if it's bigger than 64k. */
if ( needed_len > 65536 ) {
2007-08-21 06:04:24 +04:00
DEBUG ( 2 , ( " check_spnego_blob_complete: needed_len "
" too large (%u) \n " ,
2007-02-21 02:56:46 +03:00
( unsigned int ) needed_len ) ) ;
return NT_STATUS_INVALID_PARAMETER ;
}
2007-02-20 09:22:20 +03:00
/* We must store this blob until complete. */
2007-05-07 19:07:49 +04:00
if ( ! ( pad = SMB_MALLOC_P ( struct pending_auth_data ) ) ) {
2007-02-20 09:22:20 +03:00
return NT_STATUS_NO_MEMORY ;
}
pad - > needed_len = needed_len - pblob - > length ;
pad - > partial_data = data_blob ( pblob - > data , pblob - > length ) ;
2007-02-20 15:16:20 +03:00
if ( pad - > partial_data . data = = NULL ) {
SAFE_FREE ( pad ) ;
return NT_STATUS_NO_MEMORY ;
}
2007-02-20 09:22:20 +03:00
pad - > smbpid = smbpid ;
pad - > vuid = vuid ;
DLIST_ADD ( pd_list , pad ) ;
return NT_STATUS_MORE_PROCESSING_REQUIRED ;
}
2001-10-17 12:54:19 +04:00
/****************************************************************************
2003-07-16 03:05:57 +04:00
Reply to a session setup command .
2006-06-20 06:38:28 +04:00
conn POINTER CAN BE NULL HERE !
2001-10-17 12:54:19 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2003-07-16 03:05:57 +04:00
2008-01-05 02:37:24 +03:00
static void reply_sesssetup_and_X_spnego ( struct smb_request * req )
2001-10-17 12:54:19 +04:00
{
uint8 * p ;
DATA_BLOB blob1 ;
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 ;
2007-07-26 20:01:12 +04:00
const char * p2 ;
uint16 data_blob_len = SVAL ( req - > inbuf , smb_vwv7 ) ;
2003-03-15 02:06:06 +03:00
enum remote_arch_types ra_type = get_remote_arch ( ) ;
2007-07-26 20:01:12 +04:00
int vuid = SVAL ( req - > inbuf , smb_uid ) ;
2005-07-14 18:39:27 +04:00
user_struct * vuser = NULL ;
2007-02-20 09:22:20 +03:00
NTSTATUS status = NT_STATUS_OK ;
2007-07-26 20:01:12 +04:00
uint16 smbpid = req - > smbpid ;
uint16 smb_flag2 = req - > flags2 ;
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 ) {
2007-07-26 20:01:12 +04:00
global_client_caps = IVAL ( req - > 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
}
2007-08-21 06:04:24 +04:00
2007-07-26 20:01:12 +04:00
p = ( uint8 * ) smb_buf ( req - > 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 */
2007-07-26 20:01:12 +04:00
reply_nterror ( req , nt_status_squash ( NT_STATUS_LOGON_FAILURE ) ) ;
return ;
2001-10-20 15:47:44 +04:00
}
2007-07-26 20:01:12 +04:00
bufrem = smb_bufrem ( req - > 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
2007-07-26 20:01:12 +04:00
p2 = ( char * ) req - > inbuf + smb_vwv13 + data_blob_len ;
p2 + = srvstr_pull_buf ( req - > inbuf , smb_flag2 , native_os , p2 ,
2007-07-05 20:33:37 +04:00
sizeof ( native_os ) , STR_TERMINATE ) ;
2007-07-26 20:01:12 +04:00
p2 + = srvstr_pull_buf ( req - > inbuf , smb_flag2 , native_lanman , p2 ,
2007-07-05 20:33:37 +04:00
sizeof ( native_lanman ) , STR_TERMINATE ) ;
2007-07-26 20:01:12 +04:00
p2 + = srvstr_pull_buf ( req - > inbuf , smb_flag2 , primary_domain , p2 ,
2007-07-05 20:33:37 +04:00
sizeof ( primary_domain ) , STR_TERMINATE ) ;
2007-08-21 06:04:24 +04:00
DEBUG ( 3 , ( " NativeOS=[%s] NativeLanMan=[%s] PrimaryDomain=[%s] \n " ,
2003-12-06 00:51:51 +03:00
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 ) {
2007-04-05 23:56:08 +04:00
/* Vista sets neither the OS or lanman strings */
if ( ! strlen ( native_os ) & & ! strlen ( native_lanman ) )
set_remote_arch ( RA_VISTA ) ;
2007-08-21 06:04:24 +04:00
/* Windows 2003 doesn't set the native lanman string,
2003-12-06 00:51:51 +03:00
but does set primary domain which is a bug I think */
2007-08-21 06:04:24 +04:00
2007-02-20 09:22:20 +03:00
if ( ! strlen ( native_lanman ) ) {
2003-12-06 00:51:51 +03:00
ra_lanman_string ( primary_domain ) ;
2007-02-20 09:22:20 +03:00
} else {
2003-12-06 00:51:51 +03:00
ra_lanman_string ( native_lanman ) ;
2007-02-20 09:22:20 +03:00
}
2003-12-06 00:51:51 +03:00
}
2007-08-21 06:04:24 +04:00
2007-08-21 05:43:22 +04:00
/* Did we get a valid vuid ? */
if ( ! is_partial_auth_vuid ( vuid ) ) {
/* No, then try and see if this is an intermediate sessionsetup
* for a large SPNEGO packet . */
2007-02-20 09:22:20 +03:00
struct pending_auth_data * pad = get_pending_auth_data ( smbpid ) ;
if ( pad ) {
2007-08-21 06:04:24 +04:00
DEBUG ( 10 , ( " reply_sesssetup_and_X_spnego: found "
" pending vuid %u \n " ,
2007-02-20 09:22:20 +03:00
( unsigned int ) pad - > vuid ) ) ;
vuid = pad - > vuid ;
}
}
2007-08-21 05:43:22 +04:00
/* Do we have a valid vuid now ? */
if ( ! is_partial_auth_vuid ( vuid ) ) {
/* No, start a new authentication setup. */
vuid = register_initial_vuid ( ) ;
if ( vuid = = UID_FIELD_INVALID ) {
2007-02-20 09:22:20 +03:00
data_blob_free ( & blob1 ) ;
2007-07-26 20:01:12 +04:00
reply_nterror ( req , nt_status_squash (
NT_STATUS_INVALID_PARAMETER ) ) ;
return ;
2005-07-14 18:39:27 +04:00
}
}
2007-08-21 05:43:22 +04:00
vuser = get_partial_auth_user_struct ( vuid ) ;
/* This MUST be valid. */
2005-07-14 18:39:27 +04:00
if ( ! vuser ) {
2007-08-21 05:43:22 +04:00
smb_panic ( " reply_sesssetup_and_X_spnego: invalid vuid. " ) ;
2005-07-14 18:39:27 +04:00
}
2007-08-21 05:43:22 +04:00
2007-02-20 09:22:20 +03:00
/* Large (greater than 4k) SPNEGO blobs are split into multiple
* sessionsetup requests as the Windows limit on the security blob
* field is 4 k . Bug # 4400. JRA .
*/
status = check_spnego_blob_complete ( smbpid , vuid , & blob1 ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
2007-08-21 06:04:24 +04:00
if ( ! NT_STATUS_EQUAL ( status ,
NT_STATUS_MORE_PROCESSING_REQUIRED ) ) {
2007-02-20 09:22:20 +03:00
/* Real error - kill the intermediate vuid */
invalidate_vuid ( vuid ) ;
}
data_blob_free ( & blob1 ) ;
2007-07-26 20:01:12 +04:00
reply_nterror ( req , nt_status_squash ( status ) ) ;
return ;
2007-02-20 09:22:20 +03:00
}
2001-10-17 12:54:19 +04:00
if ( blob1 . data [ 0 ] = = ASN1_APPLICATION ( 0 ) ) {
2007-07-26 20:01:12 +04:00
2001-10-17 12:54:19 +04:00
/* its a negTokenTarg packet */
2007-07-26 20:01:12 +04:00
2008-01-05 02:37:24 +03:00
reply_spnego_negotiate ( req , vuid , blob1 ,
2007-07-26 20:01:12 +04:00
& vuser - > auth_ntlmssp_state ) ;
2001-10-17 12:54:19 +04:00
data_blob_free ( & blob1 ) ;
2007-07-26 20:01:12 +04:00
return ;
2001-10-17 12:54:19 +04:00
}
if ( blob1 . data [ 0 ] = = ASN1_CONTEXT ( 1 ) ) {
2007-07-26 20:01:12 +04:00
2001-10-17 12:54:19 +04:00
/* its a auth packet */
2007-07-26 20:01:12 +04:00
2008-01-05 02:37:24 +03:00
reply_spnego_auth ( req , vuid , blob1 ,
2007-07-26 20:01:12 +04:00
& vuser - > auth_ntlmssp_state ) ;
2001-10-17 12:54:19 +04:00
data_blob_free ( & blob1 ) ;
2007-07-26 20:01:12 +04:00
return ;
2001-10-17 12:54:19 +04:00
}
2005-09-30 21:13:37 +04:00
if ( strncmp ( ( char * ) ( blob1 . data ) , " NTLMSSP " , 7 ) = = 0 ) {
2005-08-02 10:36:42 +04:00
DATA_BLOB chal ;
2007-07-26 20:01:12 +04:00
2005-08-02 10:36:42 +04:00
if ( ! vuser - > auth_ntlmssp_state ) {
2007-02-20 09:22:20 +03:00
status = auth_ntlmssp_start ( & vuser - > auth_ntlmssp_state ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
2005-08-02 10:36:42 +04:00
/* Kill the intermediate vuid */
invalidate_vuid ( vuid ) ;
2007-02-20 09:22:20 +03:00
data_blob_free ( & blob1 ) ;
2007-07-26 20:01:12 +04:00
reply_nterror ( req , nt_status_squash ( status ) ) ;
return ;
2005-08-02 10:36:42 +04:00
}
}
2007-02-20 09:22:20 +03:00
status = auth_ntlmssp_update ( vuser - > auth_ntlmssp_state ,
2005-08-02 10:36:42 +04:00
blob1 , & chal ) ;
2007-08-21 06:04:24 +04:00
2005-08-02 10:36:42 +04:00
data_blob_free ( & blob1 ) ;
2007-08-21 06:04:24 +04:00
2008-01-05 02:37:24 +03:00
reply_spnego_ntlmssp ( req , vuid ,
2007-07-26 20:01:12 +04:00
& vuser - > auth_ntlmssp_state ,
2008-02-15 05:10:50 +03:00
& chal , status , OID_NTLMSSP , false ) ;
2005-08-02 11:07:43 +04:00
data_blob_free ( & chal ) ;
2007-07-26 20:01:12 +04:00
return ;
2005-08-02 10:36:42 +04:00
}
2001-10-17 12:54:19 +04:00
/* what sort of packet is this? */
DEBUG ( 1 , ( " Unknown packet in reply_sesssetup_and_X_spnego \n " ) ) ;
data_blob_free ( & blob1 ) ;
2007-07-26 20:01:12 +04:00
reply_nterror ( req , nt_status_squash ( NT_STATUS_LOGON_FAILURE ) ) ;
2001-10-17 12:54:19 +04:00
}
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
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-05-28 16:39:39 +04:00
static int shutdown_other_smbds ( struct db_record * rec ,
const struct connections_key * key ,
const struct connections_data * crec ,
void * private_data )
2005-11-25 15:31:40 +03:00
{
2007-05-28 16:39:39 +04:00
const char * ip = ( const char * ) private_data ;
2005-11-25 15:31:40 +03:00
2007-05-28 16:39:39 +04:00
if ( ! process_exists ( crec - > pid ) ) {
2005-11-25 15:31:40 +03:00
return 0 ;
}
2007-05-28 16:39:39 +04:00
if ( procid_is_me ( & crec - > pid ) ) {
2005-11-25 15:31:40 +03:00
return 0 ;
}
2007-05-28 16:39:39 +04:00
if ( strcmp ( ip , crec - > addr ) ! = 0 ) {
2005-11-25 15:31:40 +03:00
return 0 ;
}
2008-05-20 13:09:06 +04:00
DEBUG ( 0 , ( " shutdown_other_smbds: shutting down pid %d "
2008-05-21 01:08:42 +04:00
" (IP %s) \n " , procid_to_pid ( & crec - > pid ) , ip ) ) ;
2008-05-20 13:09:06 +04:00
2007-05-28 16:39:39 +04:00
messaging_send ( smbd_messaging_context ( ) , crec - > pid , MSG_SHUTDOWN ,
2007-05-15 00:31:28 +04:00
& data_blob_null ) ;
2005-11-25 15:31:40 +03:00
return 0 ;
}
2003-05-28 01:55:10 +04:00
static void setup_new_vc_session ( void )
{
2007-11-04 04:15:45 +03:00
char addr [ INET6_ADDRSTRLEN ] ;
2007-08-21 06:04:24 +04:00
DEBUG ( 2 , ( " setup_new_vc_session: New VC == 0, if NT4.x "
" compatible we would close all old resources. \n " ) ) ;
2003-05-28 05:00:58 +04:00
#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
2005-11-25 15:31:40 +03:00
if ( lp_reset_on_zero_vc ( ) ) {
2007-10-12 02:36:13 +04:00
connections_forall ( shutdown_other_smbds ,
2007-11-04 09:20:10 +03:00
CONST_DISCARD ( void * ,
client_addr ( get_client_fd ( ) , addr , sizeof ( addr ) ) ) ) ;
2005-11-25 15:31:40 +03:00
}
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
2008-01-05 02:37:24 +03:00
void reply_sesssetup_and_X ( struct smb_request * req )
2001-10-15 11:50:21 +04:00
{
int sess_vuid ;
2007-08-21 06:04:24 +04:00
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 ;
2007-10-19 04:40:25 +04:00
static bool done_sesssetup = False ;
2001-10-31 13:46:25 +03:00
auth_usersupplied_info * user_info = NULL ;
auth_serversupplied_info * server_info = NULL ;
2007-07-26 20:01:12 +04:00
uint16 smb_flag2 = req - > flags2 ;
2001-10-31 13:46:25 +03:00
2001-11-09 01:19:01 +03:00
NTSTATUS nt_status ;
2007-10-19 04:40:25 +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
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 ) ;
2007-07-26 20:01:12 +04:00
DEBUG ( 3 , ( " wct=%d flg2=0x%x \n " , req - > wct , req - > flags2 ) ) ;
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 . */
2007-07-26 20:01:12 +04:00
if ( req - > wct = = 12 & &
( req - > flags2 & FLAGS2_EXTENDED_SECURITY ) ) {
2001-12-08 05:12:17 +03:00
if ( ! global_spnego_negotiated ) {
2007-07-26 20:01:12 +04:00
DEBUG ( 0 , ( " reply_sesssetup_and_X: Rejecting attempt "
" at SPNEGO session setup when it was not "
" negotiated. \n " ) ) ;
reply_nterror ( req , nt_status_squash (
NT_STATUS_LOGON_FAILURE ) ) ;
2007-08-21 06:04:24 +04:00
END_PROFILE ( SMBsesssetupX ) ;
2007-07-26 20:01:12 +04:00
return ;
2001-12-08 05:12:17 +03:00
}
2007-07-26 20:01:12 +04:00
if ( SVAL ( req - > inbuf , smb_vwv4 ) = = 0 ) {
2003-05-28 01:55:10 +04:00
setup_new_vc_session ( ) ;
}
2007-07-26 20:01:12 +04:00
2008-01-05 02:37:24 +03:00
reply_sesssetup_and_X_spnego ( req ) ;
2007-08-21 06:04:24 +04:00
END_PROFILE ( SMBsesssetupX ) ;
2007-07-26 20:01:12 +04:00
return ;
2001-10-17 12:54:19 +04:00
}
2007-07-26 20:01:12 +04:00
smb_bufsize = SVAL ( req - > inbuf , smb_vwv2 ) ;
2001-10-31 13:46:25 +03:00
2001-10-15 11:50:21 +04:00
if ( Protocol < PROTOCOL_NT1 ) {
2007-07-26 20:01:12 +04:00
uint16 passlen1 = SVAL ( req - > inbuf , smb_vwv7 ) ;
2005-03-24 04:02:52 +03:00
2007-08-21 06:04:24 +04:00
/* Never do NT status codes with protocols before NT1 as we
* don ' t get client caps . */
2005-03-24 04:02:52 +03:00
remove_from_common_flags2 ( FLAGS2_32_BIT_ERROR_CODES ) ;
2007-07-26 20:01:12 +04:00
if ( ( passlen1 > MAX_PASS_LEN )
| | ( passlen1 > smb_bufrem ( req - > inbuf ,
smb_buf ( req - > inbuf ) ) ) ) {
reply_nterror ( req , nt_status_squash (
NT_STATUS_INVALID_PARAMETER ) ) ;
2007-08-21 06:04:24 +04:00
END_PROFILE ( SMBsesssetupX ) ;
2007-07-26 20:01:12 +04:00
return ;
2001-10-15 11:50:21 +04:00
}
2001-10-31 13:46:25 +03:00
if ( doencrypt ) {
2007-07-26 20:01:12 +04:00
lm_resp = data_blob ( smb_buf ( req - > inbuf ) , passlen1 ) ;
2001-10-31 13:46:25 +03:00
} else {
2007-07-26 20:01:12 +04:00
plaintext_password = data_blob ( smb_buf ( req - > 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
2007-07-26 20:01:12 +04:00
srvstr_pull_buf ( req - > inbuf , req - > flags2 , user ,
smb_buf ( req - > inbuf ) + passlen1 , sizeof ( user ) ,
2007-07-05 20:33:37 +04:00
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 {
2007-07-26 20:01:12 +04:00
uint16 passlen1 = SVAL ( req - > inbuf , smb_vwv7 ) ;
uint16 passlen2 = SVAL ( req - > inbuf , smb_vwv8 ) ;
2001-10-15 11:50:21 +04:00
enum remote_arch_types ra_type = get_remote_arch ( ) ;
2007-07-26 20:01:12 +04:00
char * p = smb_buf ( req - > inbuf ) ;
char * save_p = smb_buf ( req - > inbuf ) ;
2003-12-06 00:51:51 +03:00
uint16 byte_count ;
2007-08-21 06:04:24 +04:00
2001-10-31 13:46:25 +03:00
2003-12-01 05:25:56 +03:00
if ( global_client_caps = = 0 ) {
2007-07-26 20:01:12 +04:00
global_client_caps = IVAL ( req - > inbuf , smb_vwv11 ) ;
2007-08-21 06:04:24 +04:00
2003-12-01 09:19:17 +03:00
if ( ! ( global_client_caps & CAP_STATUS32 ) ) {
2007-08-21 06:04:24 +04:00
remove_from_common_flags2 (
FLAGS2_32_BIT_ERROR_CODES ) ;
2003-12-01 05:25:56 +03:00
}
2007-08-21 06:04:24 +04: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 .
2003-12-01 05:25:56 +03:00
*/
2007-08-21 06:04:24 +04:00
if ( ra_type = = RA_WINNT | | ra_type = = RA_WIN2K | |
ra_type = = RA_WIN95 ) {
if ( ! ( global_client_caps & ( CAP_NT_SMBS |
CAP_STATUS32 ) ) ) {
2003-12-01 05:25:56 +03:00
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 ) {
2007-08-21 06:04:24 +04:00
/* 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 ) {
2001-10-15 11:50:21 +04:00
passlen2 = 0 ;
2007-08-21 06:04:24 +04:00
}
2001-10-15 11:50:21 +04:00
}
2007-08-21 06:04:24 +04:00
2002-08-17 19:27:10 +04:00
/* check for nasty tricks */
2007-07-26 20:01:12 +04:00
if ( passlen1 > MAX_PASS_LEN
| | passlen1 > smb_bufrem ( req - > inbuf , p ) ) {
reply_nterror ( req , nt_status_squash (
NT_STATUS_INVALID_PARAMETER ) ) ;
2007-08-21 06:04:24 +04:00
END_PROFILE ( SMBsesssetupX ) ;
2007-07-26 20:01:12 +04:00
return ;
2002-08-17 19:27:10 +04:00
}
2007-07-26 20:01:12 +04:00
if ( passlen2 > MAX_PASS_LEN
| | passlen2 > smb_bufrem ( req - > inbuf , p + passlen1 ) ) {
reply_nterror ( req , nt_status_squash (
NT_STATUS_INVALID_PARAMETER ) ) ;
2007-08-21 06:04:24 +04:00
END_PROFILE ( SMBsesssetupX ) ;
2007-07-26 20:01:12 +04:00
return ;
2002-08-17 19:27:10 +04:00
}
2001-10-15 11:50:21 +04:00
/* Save the lanman2 password and the NT md4 password. */
2007-08-21 06:04:24 +04:00
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 ) ;
2008-03-20 18:50:52 +03:00
} else if ( lp_security ( ) ! = SEC_SHARE ) {
2008-03-28 02:08:39 +03:00
/*
* In share level we should ignore any passwords , so
* only read them if we ' re not .
*/
2007-11-11 02:36:47 +03:00
char * pass = NULL ;
2007-10-19 04:40:25 +04:00
bool unic = smb_flag2 & FLAGS2_UNICODE_STRINGS ;
2003-12-13 01:54:43 +03:00
2005-02-10 02:46:14 +03:00
if ( unic & & ( passlen2 = = 0 ) & & passlen1 ) {
/* Only a ascii plaintext password was sent. */
2007-11-11 02:36:47 +03:00
( void ) srvstr_pull_talloc ( talloc_tos ( ) ,
req - > inbuf ,
req - > flags2 ,
& pass ,
smb_buf ( req - > inbuf ) ,
passlen1 ,
STR_TERMINATE | STR_ASCII ) ;
2003-12-13 01:54:43 +03:00
} else {
2007-11-11 02:36:47 +03:00
( void ) srvstr_pull_talloc ( talloc_tos ( ) ,
req - > inbuf ,
req - > flags2 ,
& pass ,
smb_buf ( req - > inbuf ) ,
unic ? passlen2 : passlen1 ,
STR_TERMINATE ) ;
}
if ( ! pass ) {
reply_nterror ( req , nt_status_squash (
NT_STATUS_INVALID_PARAMETER ) ) ;
END_PROFILE ( SMBsesssetupX ) ;
return ;
2003-12-13 01:54:43 +03:00
}
2002-08-17 19:27:10 +04:00
plaintext_password = data_blob ( pass , strlen ( pass ) + 1 ) ;
2001-10-15 11:50:21 +04:00
}
2007-08-21 06:04:24 +04:00
2001-10-15 11:50:21 +04:00
p + = passlen1 + passlen2 ;
2007-07-26 20:01:12 +04:00
p + = srvstr_pull_buf ( req - > inbuf , req - > flags2 , user , p ,
2007-07-05 20:33:37 +04:00
sizeof ( user ) , STR_TERMINATE ) ;
2007-07-26 20:01:12 +04:00
p + = srvstr_pull_buf ( req - > inbuf , req - > flags2 , domain , p ,
2007-07-05 20:33:37 +04:00
sizeof ( domain ) , STR_TERMINATE ) ;
2007-07-26 20:01:12 +04:00
p + = srvstr_pull_buf ( req - > inbuf , req - > flags2 , native_os ,
2007-07-05 20:33:37 +04:00
p , sizeof ( native_os ) , STR_TERMINATE ) ;
2007-07-26 20:01:12 +04:00
p + = srvstr_pull_buf ( req - > inbuf , req - > flags2 ,
2007-07-05 20:33:37 +04:00
native_lanman , p , sizeof ( native_lanman ) ,
STR_TERMINATE ) ;
2003-02-28 00:22:36 +03:00
2007-08-21 06:04:24 +04: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 */
2007-07-26 20:01:12 +04:00
byte_count = SVAL ( req - > inbuf , smb_vwv13 ) ;
2007-08-21 06:04:24 +04:00
if ( PTR_DIFF ( p , save_p ) < byte_count ) {
2007-07-26 20:01:12 +04:00
p + = srvstr_pull_buf ( req - > inbuf , req - > flags2 ,
2007-07-05 20:33:37 +04:00
primary_domain , p ,
sizeof ( primary_domain ) ,
STR_TERMINATE ) ;
2007-08-21 06:04:24 +04:00
} else {
2003-12-06 00:51:51 +03:00
fstrcpy ( primary_domain , " null " ) ;
2007-08-21 06:04:24 +04:00
}
2003-12-06 00:51:51 +03:00
2007-08-21 06:04:24 +04:00
DEBUG ( 3 , ( " Domain=[%s] NativeOS=[%s] NativeLanMan=[%s] "
" PrimaryDomain=[%s] \n " ,
domain , native_os , native_lanman , primary_domain ) ) ;
2003-12-06 00:51:51 +03:00
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
2007-07-26 20:01:12 +04:00
if ( SVAL ( req - > inbuf , smb_vwv4 ) = = 0 ) {
2003-05-28 01:55:10 +04:00
setup_new_vc_session ( ) ;
}
2007-08-21 06:04:24 +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 ) {
2007-08-21 06:04:24 +04:00
/* This has to be here, because this is a perfectly
* valid behaviour for guest logons : - ( */
DEBUG ( 0 , ( " reply_sesssetup_and_X: Rejecting attempt "
" at 'normal' session setup after "
" negotiating spnego. \n " ) ) ;
2007-07-26 20:01:12 +04:00
reply_nterror ( req , nt_status_squash (
NT_STATUS_LOGON_FAILURE ) ) ;
2007-08-21 06:04:24 +04:00
END_PROFILE ( SMBsesssetupX ) ;
2007-07-26 20:01:12 +04:00
return ;
2002-01-06 04:37:14 +03:00
}
2003-01-02 23:43:17 +03:00
fstrcpy ( sub_user , 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 ) ;
2007-08-21 06:04:24 +04:00
2001-10-31 13:46:25 +03:00
if ( lp_security ( ) = = SEC_SHARE ) {
2008-03-28 02:08:39 +03:00
/* In share level we should ignore any passwords */
2001-10-31 13:46:25 +03:00
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 ) ;
2007-02-03 01:02:42 +03:00
add_session_workgroup ( domain ) ;
2001-11-09 01:19:01 +03:00
/* Then force it to null for the benfit of the code below */
* user = 0 ;
2001-10-31 13:46:25 +03:00
}
2007-08-21 06:04:24 +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 ) {
2007-08-21 06:04:24 +04:00
DEBUG ( 0 , ( " reply_sesssetup_and_X: Attempted encrypted "
" session setup without negprot denied! \n " ) ) ;
2007-07-26 20:01:12 +04:00
reply_nterror ( req , nt_status_squash (
NT_STATUS_LOGON_FAILURE ) ) ;
2007-08-21 06:04:24 +04:00
END_PROFILE ( SMBsesssetupX ) ;
2007-07-26 20:01:12 +04:00
return ;
2003-01-28 15:07:02 +03:00
}
2007-08-21 06:04:24 +04:00
nt_status = make_user_info_for_reply_enc ( & user_info , user ,
domain ,
lm_resp , nt_resp ) ;
2002-09-25 19:19:00 +04:00
if ( NT_STATUS_IS_OK ( nt_status ) ) {
2007-08-21 06:04:24 +04: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 ;
2006-03-10 20:52:41 +03:00
2007-08-21 06:04:24 +04:00
nt_status = make_auth_context_subsystem (
& plaintext_auth_context ) ;
2006-03-10 20:52:41 +03:00
if ( NT_STATUS_IS_OK ( nt_status ) ) {
2007-08-21 06:04:24 +04:00
chal = plaintext_auth_context - > get_ntlm_challenge (
plaintext_auth_context ) ;
if ( ! make_user_info_for_reply ( & user_info ,
2002-01-05 07:55:41 +03:00
user , domain , chal ,
plaintext_password ) ) {
nt_status = NT_STATUS_NO_MEMORY ;
}
2007-08-21 06:04:24 +04:00
2002-01-05 07:55:41 +03:00
if ( NT_STATUS_IS_OK ( nt_status ) ) {
2007-08-21 06:04:24 +04:00
nt_status = plaintext_auth_context - > check_ntlm_password (
plaintext_auth_context ,
user_info ,
& server_info ) ;
( 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 ) ;
2007-08-21 06:04:24 +04:00
2001-11-09 01:19:01 +03:00
if ( ! NT_STATUS_IS_OK ( nt_status ) ) {
2007-08-21 06:04:24 +04:00
nt_status = do_map_to_guest ( nt_status , & server_info ,
user , domain ) ;
2001-10-15 11:50:21 +04:00
}
2007-08-21 06:04:24 +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 ) ;
2007-07-26 20:01:12 +04:00
reply_nterror ( req , nt_status_squash ( nt_status ) ) ;
2007-08-21 06:04:24 +04:00
END_PROFILE ( SMBsesssetupX ) ;
2007-07-26 20:01:12 +04:00
return ;
2001-11-09 01:19:01 +03:00
}
2003-07-18 04:53:34 +04:00
2007-08-21 06:04:24 +04:00
/* Ensure we can't possible take a code path leading to a
* null defref . */
2006-03-10 21:32:18 +03:00
if ( ! server_info ) {
2007-07-26 20:01:12 +04:00
reply_nterror ( req , nt_status_squash ( NT_STATUS_LOGON_FAILURE ) ) ;
2007-08-21 06:04:24 +04:00
END_PROFILE ( SMBsesssetupX ) ;
2007-07-26 20:01:12 +04:00
return ;
2006-03-10 21:32:18 +03:00
}
2008-08-23 00:49:46 +04:00
if ( ! server_info - > ptok ) {
nt_status = create_local_token ( server_info ) ;
if ( ! NT_STATUS_IS_OK ( nt_status ) ) {
DEBUG ( 10 , ( " create_local_token failed: %s \n " ,
nt_errstr ( nt_status ) ) ) ;
data_blob_free ( & nt_resp ) ;
data_blob_free ( & lm_resp ) ;
data_blob_clear_free ( & plaintext_password ) ;
reply_nterror ( req , nt_status_squash ( nt_status ) ) ;
END_PROFILE ( SMBsesssetupX ) ;
return ;
}
2006-02-04 01:19:41 +03:00
}
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 ) ;
2007-08-21 06:04:24 +04:00
2001-10-15 11:50:21 +04:00
/* it's ok - setup a reply */
2007-07-26 20:01:12 +04:00
reply_outbuf ( req , 3 , 0 ) ;
2003-01-28 15:07:02 +03:00
if ( Protocol > = PROTOCOL_NT1 ) {
2007-07-26 20:01:12 +04:00
push_signature ( & req - > outbuf ) ;
2001-10-15 11:50:21 +04:00
/* perhaps grab OS version here?? */
}
2007-08-21 06:04:24 +04:00
2001-11-09 01:19:01 +03:00
if ( server_info - > guest ) {
2007-07-26 20:01:12 +04:00
SSVAL ( req - > 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
2006-05-14 03:05:53 +04:00
if ( lp_security ( ) = = SEC_SHARE ) {
sess_vuid = UID_FIELD_INVALID ;
TALLOC_FREE ( server_info ) ;
} else {
2007-08-21 05:43:22 +04:00
/* Ignore the initial vuid. */
sess_vuid = register_initial_vuid ( ) ;
2006-05-14 03:05:53 +04:00
if ( sess_vuid = = UID_FIELD_INVALID ) {
data_blob_free ( & nt_resp ) ;
data_blob_free ( & lm_resp ) ;
2007-08-21 05:43:22 +04:00
reply_nterror ( req , nt_status_squash (
NT_STATUS_LOGON_FAILURE ) ) ;
2007-08-26 14:50:39 +04:00
END_PROFILE ( SMBsesssetupX ) ;
return ;
2007-08-21 05:43:22 +04:00
}
/* register_existing_vuid keeps the server info */
sess_vuid = register_existing_vuid ( sess_vuid ,
server_info ,
nt_resp . data ? nt_resp : lm_resp ,
sub_user ) ;
if ( sess_vuid = = UID_FIELD_INVALID ) {
data_blob_free ( & nt_resp ) ;
data_blob_free ( & lm_resp ) ;
2007-07-26 20:01:12 +04:00
reply_nterror ( req , nt_status_squash (
NT_STATUS_LOGON_FAILURE ) ) ;
2007-08-21 06:04:24 +04:00
END_PROFILE ( SMBsesssetupX ) ;
2007-07-26 20:01:12 +04:00
return ;
2006-05-14 03:05:53 +04:00
}
2001-10-15 11:50:21 +04:00
2006-05-14 03:05:53 +04:00
/* current_user_info is changed on new vuid */
reload_services ( True ) ;
2004-03-20 01:06:54 +03:00
2007-07-26 20:01:12 +04:00
sessionsetup_start_signing_engine ( server_info , req - > inbuf ) ;
2006-05-14 03:05:53 +04:00
}
2003-07-18 04:53:34 +04:00
2006-05-14 03:05:53 +04:00
data_blob_free ( & nt_resp ) ;
data_blob_free ( & lm_resp ) ;
2007-08-21 06:04:24 +04:00
2007-07-26 20:01:12 +04:00
SSVAL ( req - > outbuf , smb_uid , sess_vuid ) ;
SSVAL ( req - > inbuf , smb_uid , sess_vuid ) ;
2007-08-21 06:04:24 +04:00
2001-10-15 11:50:21 +04:00
if ( ! done_sesssetup )
max_send = MIN ( max_send , smb_bufsize ) ;
2007-08-21 06:04:24 +04:00
2001-10-15 11:50:21 +04:00
done_sesssetup = True ;
2007-08-21 06:04:24 +04:00
2001-10-15 11:50:21 +04:00
END_PROFILE ( SMBsesssetupX ) ;
2007-08-27 16:04:09 +04:00
chain_reply ( req ) ;
2007-07-26 20:01:12 +04:00
return ;
2001-10-15 11:50:21 +04:00
}