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"
2011-04-28 19:26:40 +04:00
# include "../lib/tsocket/tsocket.h"
2017-01-01 23:00:55 +03:00
# include "lib/util/server_id.h"
2011-03-22 18:57:01 +03:00
# include "smbd/smbd.h"
2009-01-08 14:03:45 +03:00
# include "smbd/globals.h"
2011-03-24 15:46:20 +03:00
# include "auth.h"
2011-03-24 17:31:06 +03:00
# include "messages.h"
2011-04-14 02:36:23 +04:00
# include "smbprofile.h"
2011-07-19 05:57:05 +04:00
# include "../libcli/security/security.h"
2011-07-26 09:11:47 +04:00
# include "auth/gensec/gensec.h"
2012-06-04 17:32:28 +04:00
# include "lib/conn_tdb.h"
2016-03-22 18:30:42 +03:00
# include "../libcli/smb/smb_signing.h"
2001-10-15 11:50:21 +04:00
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
2015-05-03 07:01:14 +03:00
static int push_signature ( uint8_t * * outbuf )
2001-11-12 03:08:30 +03:00
{
2007-07-26 20:01:12 +04:00
char * lanman ;
int result , tmp ;
2014-01-07 18:57:50 +04:00
fstring native_os ;
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
2014-01-07 18:57:50 +04:00
fstr_sprintf ( native_os , " Windows %d.%d " , SAMBA_MAJOR_NBT_ANNOUNCE_VERSION ,
SAMBA_MINOR_NBT_ANNOUNCE_VERSION ) ;
tmp = message_push_string ( outbuf , native_os , 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 ;
2009-01-16 00:27:52 +03:00
if ( asprintf ( & lanman , " Samba %s " , samba_version_string ( ) ) ! = - 1 ) {
2007-07-26 20:01:12 +04:00
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
}
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
2011-06-08 20:55:37 +04:00
static NTSTATUS check_guest_password ( const struct tsocket_address * remote_address ,
2012-02-03 10:09:37 +04:00
TALLOC_CTX * mem_ctx ,
struct auth_session_info * * session_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
{
2012-02-03 10:09:37 +04:00
struct auth4_context * auth_context ;
2010-01-10 16:16:04 +03:00
struct auth_usersupplied_info * user_info = NULL ;
2012-02-03 10:09:37 +04:00
uint8_t 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
NTSTATUS nt_status ;
DEBUG ( 3 , ( " Got anonymous request \n " ) ) ;
2012-02-03 10:09:37 +04:00
nt_status = make_auth4_context ( talloc_tos ( ) , & auth_context ) ;
2010-09-26 02:35:44 +04:00
if ( ! NT_STATUS_IS_OK ( nt_status ) ) {
2002-01-05 07:55:41 +03:00
return nt_status ;
}
2012-02-03 10:09:37 +04:00
auth_context - > get_ntlm_challenge ( auth_context ,
chal ) ;
2014-03-27 00:17:15 +04:00
if ( ! make_user_info_guest ( talloc_tos ( ) , remote_address , & user_info ) ) {
2010-07-17 02:23:55 +04:00
TALLOC_FREE ( auth_context ) ;
2002-01-05 07:55:41 +03:00
return NT_STATUS_NO_MEMORY ;
}
2007-08-21 06:04:24 +04:00
2012-02-03 10:09:37 +04:00
nt_status = auth_check_password_session_info ( auth_context ,
mem_ctx , user_info , session_info ) ;
2014-03-27 00:17:15 +04:00
TALLOC_FREE ( user_info ) ;
2012-02-03 10:09:37 +04:00
TALLOC_FREE ( 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
return nt_status ;
}
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
{
2015-05-03 07:01:14 +03:00
const uint8_t * p ;
2012-01-14 15:38:36 +04:00
DATA_BLOB in_blob ;
2012-01-14 16:24:51 +04:00
DATA_BLOB out_blob = data_blob_null ;
2003-01-28 15:07:02 +03:00
size_t bufrem ;
2008-11-01 22:02:07 +03:00
char * tmp ;
const char * native_os ;
const char * native_lanman ;
const char * primary_domain ;
2015-05-03 07:01:14 +03:00
uint16_t data_blob_len = SVAL ( req - > vwv + 7 , 0 ) ;
2003-03-15 02:06:06 +03:00
enum remote_arch_types ra_type = get_remote_arch ( ) ;
2012-06-05 20:17:15 +04:00
uint64_t vuid = req - > vuid ;
2007-02-20 09:22:20 +03:00
NTSTATUS status = NT_STATUS_OK ;
2014-06-11 17:11:05 +04:00
struct smbXsrv_connection * xconn = req - > xconn ;
2014-06-11 17:11:05 +04:00
struct smbd_server_connection * sconn = req - > sconn ;
2012-01-14 16:24:51 +04:00
uint16_t action = 0 ;
2016-05-18 10:56:02 +03:00
bool is_authenticated = false ;
2012-04-01 23:19:53 +04:00
NTTIME now = timeval_to_nttime ( & req - > request_time ) ;
struct smbXsrv_session * session = NULL ;
2013-03-18 13:10:25 +04:00
uint16_t smb_bufsize = SVAL ( req - > vwv + 2 , 0 ) ;
2012-04-25 21:36:20 +04:00
uint32_t client_caps = IVAL ( req - > vwv + 10 , 0 ) ;
2015-07-30 14:23:45 +03:00
struct smbXsrv_session_auth0 * auth ;
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
2014-05-21 12:56:26 +04:00
if ( ! xconn - > smb1 . sessions . done_sesssetup ) {
2012-04-25 21:36:20 +04:00
global_client_caps = client_caps ;
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
2008-11-01 19:35:48 +03:00
p = req - > buf ;
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
}
2008-11-02 03:21:53 +03:00
bufrem = smbreq_bufrem ( req , p ) ;
2001-10-17 12:54:19 +04:00
/* pull the spnego blob */
2012-01-14 15:38:36 +04:00
in_blob = data_blob_const ( p , MIN ( bufrem , data_blob_len ) ) ;
2001-10-20 15:47:44 +04:00
2001-10-18 14:26:06 +04:00
#if 0
2012-01-14 15:38:36 +04:00
file_save ( " negotiate.dat " , in_blob . data , in_blob . length ) ;
2001-10-18 14:26:06 +04:00
# endif
2014-02-26 23:16:26 +04:00
p = req - > buf + in_blob . length ;
2008-11-01 22:02:07 +03:00
2014-02-26 23:16:26 +04:00
p + = srvstr_pull_req_talloc ( talloc_tos ( ) , req , & tmp , p ,
2008-11-02 03:07:46 +03:00
STR_TERMINATE ) ;
2008-11-01 22:02:07 +03:00
native_os = tmp ? tmp : " " ;
2014-02-26 23:16:26 +04:00
p + = srvstr_pull_req_talloc ( talloc_tos ( ) , req , & tmp , p ,
2008-11-02 03:07:46 +03:00
STR_TERMINATE ) ;
2008-11-01 22:02:07 +03:00
native_lanman = tmp ? tmp : " " ;
2014-02-26 23:16:26 +04:00
p + = srvstr_pull_req_talloc ( talloc_tos ( ) , req , & tmp , p ,
2008-11-02 03:07:46 +03:00
STR_TERMINATE ) ;
2008-11-01 22:02:07 +03:00
primary_domain = tmp ? tmp : " " ;
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
}
2011-02-25 03:25:30 +03:00
} else if ( ra_type = = RA_VISTA ) {
if ( strncmp ( native_os , " Mac OS X " , 8 ) = = 0 ) {
set_remote_arch ( RA_OSX ) ;
}
2003-12-06 00:51:51 +03:00
}
2007-08-21 06:04:24 +04:00
2012-04-01 23:19:53 +04:00
if ( vuid ! = 0 ) {
2014-06-11 17:11:05 +04:00
status = smb1srv_session_lookup ( xconn ,
2012-04-01 23:19:53 +04:00
vuid , now ,
& session ) ;
if ( NT_STATUS_EQUAL ( status , NT_STATUS_USER_SESSION_DELETED ) ) {
2012-05-03 18:13:08 +04:00
reply_force_doserror ( req , ERRSRV , ERRbaduid ) ;
return ;
}
2012-04-25 21:36:20 +04:00
if ( NT_STATUS_EQUAL ( status , NT_STATUS_NETWORK_SESSION_EXPIRED ) ) {
status = NT_STATUS_OK ;
}
2012-04-01 23:19:53 +04:00
if ( NT_STATUS_IS_OK ( status ) ) {
2012-04-25 21:36:20 +04:00
session - > status = NT_STATUS_MORE_PROCESSING_REQUIRED ;
status = NT_STATUS_MORE_PROCESSING_REQUIRED ;
2015-07-30 14:23:45 +03:00
TALLOC_FREE ( session - > pending_auth ) ;
2012-04-01 23:19:53 +04:00
}
if ( ! NT_STATUS_EQUAL ( status , NT_STATUS_MORE_PROCESSING_REQUIRED ) ) {
reply_nterror ( req , nt_status_squash ( status ) ) ;
2007-07-26 20:01:12 +04:00
return ;
2005-07-14 18:39:27 +04:00
}
}
2012-04-01 23:19:53 +04:00
if ( session = = NULL ) {
/* create a new session */
2014-06-11 17:11:05 +04:00
status = smbXsrv_session_create ( xconn ,
2012-04-01 23:19:53 +04:00
now , & session ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
reply_nterror ( req , nt_status_squash ( status ) ) ;
return ;
}
2005-07-14 18:39:27 +04:00
}
2007-08-21 05:43:22 +04:00
2015-07-30 14:23:45 +03:00
status = smbXsrv_session_find_auth ( session , xconn , now , & auth ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
status = smbXsrv_session_create_auth ( session , xconn , now ,
0 , /* flags */
0 , /* security */
& auth ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
reply_nterror ( req , nt_status_squash ( status ) ) ;
return ;
}
}
if ( auth - > gensec = = NULL ) {
2014-06-11 17:11:05 +04:00
status = auth_generic_prepare ( session , xconn - > remote_address ,
2015-07-30 14:23:45 +03:00
& auth - > gensec ) ;
2012-01-13 15:24:47 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2012-04-01 23:19:53 +04:00
TALLOC_FREE ( session ) ;
2012-01-13 15:24:47 +04:00
reply_nterror ( req , nt_status_squash ( status ) ) ;
return ;
2005-08-02 10:36:42 +04:00
}
2015-07-30 14:23:45 +03:00
gensec_want_feature ( auth - > gensec , GENSEC_FEATURE_SESSION_KEY ) ;
gensec_want_feature ( auth - > gensec , GENSEC_FEATURE_UNIX_TOKEN ) ;
2011-07-26 09:11:47 +04:00
2015-07-30 14:23:45 +03:00
status = gensec_start_mech_by_oid ( auth - > gensec ,
2012-04-01 23:19:53 +04:00
GENSEC_OID_SPNEGO ) ;
2012-01-13 15:24:47 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2012-02-03 04:54:32 +04:00
DEBUG ( 0 , ( " Failed to start SPNEGO handler! \n " ) ) ;
2012-04-01 23:19:53 +04:00
TALLOC_FREE ( session ) ; ;
2012-01-13 15:24:47 +04:00
reply_nterror ( req , nt_status_squash ( status ) ) ;
return ;
}
2011-07-26 09:11:47 +04:00
}
2012-04-01 23:19:53 +04:00
become_root ( ) ;
2015-07-30 14:23:45 +03:00
status = gensec_update ( auth - > gensec ,
2013-12-13 22:56:13 +04:00
talloc_tos ( ) ,
2012-01-14 16:24:51 +04:00
in_blob , & out_blob ) ;
2012-04-01 23:19:53 +04:00
unbecome_root ( ) ;
2012-01-14 16:24:51 +04:00
if ( ! NT_STATUS_IS_OK ( status ) & &
! NT_STATUS_EQUAL ( status , NT_STATUS_MORE_PROCESSING_REQUIRED ) ) {
2012-04-01 23:19:53 +04:00
TALLOC_FREE ( session ) ;
2012-01-14 16:24:51 +04:00
reply_nterror ( req , nt_status_squash ( status ) ) ;
return ;
}
2012-04-25 21:36:20 +04:00
if ( NT_STATUS_IS_OK ( status ) & & session - > global - > auth_session_info = = NULL ) {
2012-01-14 16:24:51 +04:00
struct auth_session_info * session_info = NULL ;
2015-07-30 14:23:45 +03:00
status = gensec_session_info ( auth - > gensec ,
2012-04-01 23:19:53 +04:00
session ,
2012-01-14 16:24:51 +04:00
& session_info ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
2012-01-31 05:53:30 +04:00
DEBUG ( 1 , ( " Failed to generate session_info "
" (user and group token) for session setup: %s \n " ,
nt_errstr ( status ) ) ) ;
2012-01-14 16:24:51 +04:00
data_blob_free ( & out_blob ) ;
2012-04-01 23:19:53 +04:00
TALLOC_FREE ( session ) ;
2012-01-14 16:24:51 +04:00
reply_nterror ( req , nt_status_squash ( status ) ) ;
return ;
}
2016-04-20 17:34:28 +03:00
if ( security_session_user_level ( session_info , NULL ) = = SECURITY_GUEST ) {
2016-04-18 18:36:56 +03:00
action | = SMB_SETUP_GUEST ;
2012-01-14 16:24:51 +04:00
}
2012-08-02 20:47:48 +04:00
if ( session_info - > session_key . length > 0 ) {
struct smbXsrv_session * x = session ;
/*
* Note : the SMB1 signing key is not truncated to 16 byte !
*/
x - > global - > signing_key =
data_blob_dup_talloc ( x - > global ,
session_info - > session_key ) ;
if ( x - > global - > signing_key . data = = NULL ) {
data_blob_free ( & out_blob ) ;
TALLOC_FREE ( session ) ;
reply_nterror ( req , NT_STATUS_NO_MEMORY ) ;
return ;
}
/*
2012-08-03 10:42:43 +04:00
* clear the session key
* the first tcon will add setup the application key
2012-08-02 20:47:48 +04:00
*/
data_blob_clear_free ( & session_info - > session_key ) ;
}
2012-04-01 23:19:53 +04:00
session - > compat = talloc_zero ( session , struct user_struct ) ;
if ( session - > compat = = NULL ) {
data_blob_free ( & out_blob ) ;
TALLOC_FREE ( session ) ;
reply_nterror ( req , NT_STATUS_NO_MEMORY ) ;
return ;
}
session - > compat - > session = session ;
session - > compat - > homes_snum = - 1 ;
session - > compat - > session_info = session_info ;
session - > compat - > session_keystr = NULL ;
session - > compat - > vuid = session - > global - > session_wire_id ;
DLIST_ADD ( sconn - > users , session - > compat ) ;
sconn - > num_users + + ;
if ( security_session_user_level ( session_info , NULL ) > = SECURITY_USER ) {
2016-05-18 10:56:02 +03:00
is_authenticated = true ;
2012-04-01 23:19:53 +04:00
session - > compat - > homes_snum =
register_homes_share ( session_info - > unix_info - > unix_name ) ;
}
2014-05-21 16:44:01 +04:00
if ( srv_is_signing_negotiated ( xconn ) & &
2016-05-18 10:56:02 +03:00
is_authenticated & &
2012-08-02 20:47:48 +04:00
session - > global - > signing_key . length > 0 )
{
2012-04-01 23:19:53 +04:00
/*
* Try and turn on server signing on the first non - guest
* sessionsetup .
*/
2014-05-21 16:44:01 +04:00
srv_set_signing ( xconn ,
2012-08-02 20:47:48 +04:00
session - > global - > signing_key ,
2012-04-01 23:19:53 +04:00
data_blob_null ) ;
}
set_current_user_info ( session_info - > unix_info - > sanitized_username ,
session_info - > unix_info - > unix_name ,
session_info - > info - > domain_name ) ;
session - > status = NT_STATUS_OK ;
session - > global - > auth_session_info = talloc_move ( session - > global ,
& session_info ) ;
session - > global - > auth_session_info_seqnum + = 1 ;
session - > global - > channels [ 0 ] . auth_session_info_seqnum =
session - > global - > auth_session_info_seqnum ;
2014-06-12 11:49:28 +04:00
session - > global - > auth_time = now ;
2012-04-25 21:36:20 +04:00
if ( client_caps & CAP_DYNAMIC_REAUTH ) {
session - > global - > expiration_time =
2015-07-30 14:23:45 +03:00
gensec_expire_time ( auth - > gensec ) ;
2012-04-25 21:36:20 +04:00
} else {
session - > global - > expiration_time =
GENSEC_EXPIRE_TIME_INFINITY ;
}
2012-08-27 13:03:25 +04:00
if ( ! session_claim ( session ) ) {
DEBUG ( 1 , ( " smb1: Failed to claim session for vuid=%llu \n " ,
( unsigned long long ) session - > compat - > vuid ) ) ;
data_blob_free ( & out_blob ) ;
TALLOC_FREE ( session ) ;
reply_nterror ( req , NT_STATUS_LOGON_FAILURE ) ;
return ;
}
2012-04-25 21:36:20 +04:00
status = smbXsrv_session_update ( session ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
DEBUG ( 0 , ( " smb1: Failed to update session for vuid=%llu - %s \n " ,
( unsigned long long ) session - > compat - > vuid ,
nt_errstr ( status ) ) ) ;
data_blob_free ( & out_blob ) ;
TALLOC_FREE ( session ) ;
reply_nterror ( req , NT_STATUS_LOGON_FAILURE ) ;
return ;
}
2014-05-21 12:56:26 +04:00
if ( ! xconn - > smb1 . sessions . done_sesssetup ) {
2013-12-06 16:52:09 +04:00
if ( smb_bufsize < SMB_BUFFER_SIZE_MIN ) {
reply_force_doserror ( req , ERRSRV , ERRerror ) ;
return ;
}
2014-05-21 12:56:26 +04:00
xconn - > smb1 . sessions . max_send = smb_bufsize ;
xconn - > smb1 . sessions . done_sesssetup = true ;
2013-03-18 13:10:25 +04:00
}
2012-04-25 21:36:20 +04:00
/* current_user_info is changed on new vuid */
reload_services ( sconn , conn_snum_used , true ) ;
} else if ( NT_STATUS_IS_OK ( status ) ) {
struct auth_session_info * session_info = NULL ;
2015-07-30 14:23:45 +03:00
status = gensec_session_info ( auth - > gensec ,
2012-04-25 21:36:20 +04:00
session ,
& session_info ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
DEBUG ( 1 , ( " Failed to generate session_info "
" (user and group token) for session setup: %s \n " ,
nt_errstr ( status ) ) ) ;
data_blob_free ( & out_blob ) ;
TALLOC_FREE ( session ) ;
reply_nterror ( req , nt_status_squash ( status ) ) ;
return ;
}
2016-04-20 17:34:28 +03:00
if ( security_session_user_level ( session_info , NULL ) = = SECURITY_GUEST ) {
2016-04-18 18:36:56 +03:00
action | = SMB_SETUP_GUEST ;
2012-04-25 21:36:20 +04:00
}
2012-08-02 20:46:09 +04:00
/*
* Keep the application key
*/
data_blob_clear_free ( & session_info - > session_key ) ;
session_info - > session_key =
session - > global - > auth_session_info - > session_key ;
talloc_steal ( session_info , session_info - > session_key . data ) ;
TALLOC_FREE ( session - > global - > auth_session_info ) ;
2012-04-25 21:36:20 +04:00
session - > compat - > session_info = session_info ;
2012-08-02 20:46:09 +04:00
2012-04-25 21:36:20 +04:00
session - > compat - > vuid = session - > global - > session_wire_id ;
if ( security_session_user_level ( session_info , NULL ) > = SECURITY_USER ) {
session - > compat - > homes_snum =
register_homes_share ( session_info - > unix_info - > unix_name ) ;
}
set_current_user_info ( session_info - > unix_info - > sanitized_username ,
session_info - > unix_info - > unix_name ,
session_info - > info - > domain_name ) ;
session - > status = NT_STATUS_OK ;
2012-08-02 20:46:09 +04:00
session - > global - > auth_session_info = talloc_move ( session - > global ,
& session_info ) ;
2012-04-25 21:36:20 +04:00
session - > global - > auth_session_info_seqnum + = 1 ;
session - > global - > channels [ 0 ] . auth_session_info_seqnum =
session - > global - > auth_session_info_seqnum ;
2014-06-12 11:49:28 +04:00
session - > global - > auth_time = now ;
2012-04-25 21:36:20 +04:00
if ( client_caps & CAP_DYNAMIC_REAUTH ) {
session - > global - > expiration_time =
2015-07-30 14:23:45 +03:00
gensec_expire_time ( auth - > gensec ) ;
2012-04-25 21:36:20 +04:00
} else {
session - > global - > expiration_time =
GENSEC_EXPIRE_TIME_INFINITY ;
}
2012-04-01 23:19:53 +04:00
status = smbXsrv_session_update ( session ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
DEBUG ( 0 , ( " smb1: Failed to update session for vuid=%llu - %s \n " ,
( unsigned long long ) session - > compat - > vuid ,
nt_errstr ( status ) ) ) ;
2012-01-14 16:24:51 +04:00
data_blob_free ( & out_blob ) ;
2012-04-01 23:19:53 +04:00
TALLOC_FREE ( session ) ;
2012-01-14 16:24:51 +04:00
reply_nterror ( req , NT_STATUS_LOGON_FAILURE ) ;
return ;
}
2012-04-25 21:36:20 +04:00
conn_clear_vuid_caches ( sconn , session - > compat - > vuid ) ;
2012-01-14 16:24:51 +04:00
/* current_user_info is changed on new vuid */
reload_services ( sconn , conn_snum_used , true ) ;
}
2012-04-01 23:19:53 +04:00
vuid = session - > global - > session_wire_id ;
2012-01-14 16:24:51 +04:00
reply_outbuf ( req , 4 , 0 ) ;
2001-10-17 12:54:19 +04:00
2012-01-14 16:24:51 +04:00
SSVAL ( req - > outbuf , smb_uid , vuid ) ;
SIVAL ( req - > outbuf , smb_rcls , NT_STATUS_V ( status ) ) ;
SSVAL ( req - > outbuf , smb_vwv0 , 0xFF ) ; /* no chaining possible */
SSVAL ( req - > outbuf , smb_vwv2 , action ) ;
SSVAL ( req - > outbuf , smb_vwv3 , out_blob . length ) ;
if ( message_push_blob ( & req - > outbuf , out_blob ) = = - 1 ) {
data_blob_free ( & out_blob ) ;
2012-04-01 23:19:53 +04:00
TALLOC_FREE ( session ) ;
2012-01-14 16:24:51 +04:00
reply_nterror ( req , NT_STATUS_NO_MEMORY ) ;
return ;
}
data_blob_free ( & out_blob ) ;
if ( push_signature ( & req - > outbuf ) = = - 1 ) {
2012-04-01 23:19:53 +04:00
TALLOC_FREE ( session ) ;
2012-01-14 16:24:51 +04:00
reply_nterror ( req , NT_STATUS_NO_MEMORY ) ;
return ;
}
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
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2010-07-04 21:56:51 +04:00
struct shutdown_state {
const char * ip ;
struct messaging_context * msg_ctx ;
} ;
2012-08-28 16:29:51 +04:00
static int shutdown_other_smbds ( struct smbXsrv_session_global0 * session ,
2007-05-28 16:39:39 +04:00
void * private_data )
2005-11-25 15:31:40 +03:00
{
2010-07-04 21:56:51 +04:00
struct shutdown_state * state = ( struct shutdown_state * ) private_data ;
2012-06-15 16:29:08 +04:00
struct server_id self_pid = messaging_server_id ( state - > msg_ctx ) ;
2012-08-28 16:29:51 +04:00
struct server_id pid = session - > channels [ 0 ] . server_id ;
const char * addr = session - > channels [ 0 ] . remote_address ;
2015-04-28 14:30:58 +03:00
struct server_id_buf tmp ;
2005-11-25 15:31:40 +03:00
2010-08-15 11:48:19 +04:00
DEBUG ( 10 , ( " shutdown_other_smbds: %s, %s \n " ,
2015-04-28 14:30:58 +03:00
server_id_str_buf ( pid , & tmp ) , addr ) ) ;
2010-08-15 11:48:19 +04:00
2012-08-28 16:29:51 +04:00
if ( ! process_exists ( pid ) ) {
2010-08-15 11:48:19 +04:00
DEBUG ( 10 , ( " process does not exist \n " ) ) ;
2005-11-25 15:31:40 +03:00
return 0 ;
}
2012-08-28 16:29:51 +04:00
if ( serverid_equal ( & pid , & self_pid ) ) {
2010-08-15 11:48:19 +04:00
DEBUG ( 10 , ( " It's me \n " ) ) ;
2005-11-25 15:31:40 +03:00
return 0 ;
}
2012-08-28 16:29:51 +04:00
/*
* here we use strstr ( ) because ' addr '
* ( session - > channels [ 0 ] . remote_address )
* contains a string like :
* ' ipv4 : 127.0 .0 .1 : 48163 '
*/
if ( strstr ( addr , state - > ip ) = = NULL ) {
DEBUG ( 10 , ( " %s does not match %s \n " , state - > ip , addr ) ) ;
2005-11-25 15:31:40 +03:00
return 0 ;
}
2010-08-15 11:48:53 +04:00
DEBUG ( 1 , ( " shutdown_other_smbds: shutting down pid %u "
2012-08-28 16:29:51 +04:00
" (IP %s) \n " , ( unsigned int ) procid_to_pid ( & pid ) ,
2010-08-15 11:48:53 +04:00
state - > ip ) ) ;
2008-05-20 13:09:06 +04:00
2012-08-28 16:29:51 +04:00
messaging_send ( state - > msg_ctx , pid , MSG_SHUTDOWN ,
2007-05-15 00:31:28 +04:00
& data_blob_null ) ;
2005-11-25 15:31:40 +03:00
return 0 ;
}
2010-08-15 11:24:30 +04:00
static void setup_new_vc_session ( struct smbd_server_connection * sconn )
2003-05-28 01:55:10 +04:00
{
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 ( ) ) {
2010-08-15 11:24:30 +04:00
char * addr ;
2010-07-04 21:56:51 +04:00
struct shutdown_state state ;
2010-08-15 11:24:30 +04:00
addr = tsocket_address_inet_addr_string (
sconn - > remote_address , talloc_tos ( ) ) ;
if ( addr = = NULL ) {
return ;
}
state . ip = addr ;
state . msg_ctx = sconn - > msg_ctx ;
2012-08-28 16:29:51 +04:00
smbXsrv_session_global_traverse ( shutdown_other_smbds , & state ) ;
2010-08-15 11:24:30 +04:00
TALLOC_FREE ( 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
{
2012-06-05 20:17:15 +04:00
uint64_t sess_vuid ;
2013-03-18 13:10:25 +04:00
uint16_t smb_bufsize ;
2001-10-31 13:46:25 +03:00
DATA_BLOB lm_resp ;
DATA_BLOB nt_resp ;
DATA_BLOB plaintext_password ;
2008-11-01 22:02:07 +03:00
char * tmp ;
const char * user ;
2010-06-12 14:39:21 +04:00
fstring sub_user ; /* Sanitised username for substituion */
2008-11-01 22:02:07 +03:00
const char * domain ;
const char * native_os ;
const char * native_lanman ;
const char * primary_domain ;
2010-01-10 16:16:04 +03:00
struct auth_usersupplied_info * user_info = NULL ;
2011-07-18 07:06:47 +04:00
struct auth_session_info * session_info = NULL ;
2015-05-03 07:01:14 +03:00
uint16_t smb_flag2 = req - > flags2 ;
2012-04-01 23:19:53 +04:00
uint16_t action = 0 ;
2016-05-18 10:56:02 +03:00
bool is_authenticated = false ;
2012-04-01 23:19:53 +04:00
NTTIME now = timeval_to_nttime ( & req - > request_time ) ;
struct smbXsrv_session * session = NULL ;
2001-11-09 01:19:01 +03:00
NTSTATUS nt_status ;
2014-06-11 17:11:05 +04:00
struct smbXsrv_connection * xconn = req - > xconn ;
2014-06-11 17:11:05 +04:00
struct smbd_server_connection * sconn = req - > sconn ;
2014-05-21 12:27:50 +04:00
bool doencrypt = xconn - > smb1 . negprot . encrypted_passwords ;
2011-09-12 11:19:06 +04:00
bool signing_allowed = false ;
2016-03-22 18:30:42 +03:00
bool signing_mandatory = smb_signing_is_mandatory (
xconn - > smb1 . signing_state ) ;
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
2011-09-12 11:19:06 +04:00
if ( req - > flags2 & FLAGS2_SMB_SECURITY_SIGNATURES ) {
signing_allowed = true ;
}
if ( req - > flags2 & FLAGS2_SMB_SECURITY_SIGNATURES_REQUIRED ) {
signing_mandatory = true ;
}
/*
* We can call srv_set_signing_negotiated ( ) each time .
* It finds out when it needs to turn into a noop
* itself .
*/
2014-05-21 16:44:01 +04:00
srv_set_signing_negotiated ( xconn ,
2011-09-12 11:19:06 +04:00
signing_allowed ,
signing_mandatory ) ;
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 ) ) {
2014-05-21 12:27:50 +04:00
if ( ! xconn - > smb1 . negprot . spnego ) {
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
}
2008-11-02 14:20:47 +03:00
if ( SVAL ( req - > vwv + 4 , 0 ) = = 0 ) {
2010-08-15 11:24:30 +04:00
setup_new_vc_session ( req - > sconn ) ;
2003-05-28 01:55:10 +04:00
}
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
}
2008-11-02 14:20:47 +03:00
smb_bufsize = SVAL ( req - > vwv + 2 , 0 ) ;
2001-10-31 13:46:25 +03:00
2009-11-23 18:33:26 +03:00
if ( get_Protocol ( ) < PROTOCOL_NT1 ) {
2015-05-03 07:01:14 +03:00
uint16_t passlen1 = SVAL ( req - > vwv + 7 , 0 ) ;
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 ) ;
2008-11-01 18:24:42 +03:00
if ( ( passlen1 > MAX_PASS_LEN ) | | ( passlen1 > req - > buflen ) ) {
2007-07-26 20:01:12 +04:00
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 ) {
2008-11-01 19:35:48 +03:00
lm_resp = data_blob ( req - > buf , passlen1 ) ;
2001-10-31 13:46:25 +03:00
} else {
2008-11-01 19:35:48 +03:00
plaintext_password = data_blob ( req - > buf , 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
2008-11-02 03:07:46 +03:00
srvstr_pull_req_talloc ( talloc_tos ( ) , req , & tmp ,
req - > buf + passlen1 , STR_TERMINATE ) ;
2008-11-01 22:02:07 +03:00
user = tmp ? tmp : " " ;
domain = " " ;
2003-05-28 01:55:10 +04:00
2001-10-15 11:50:21 +04:00
} else {
2015-05-03 07:01:14 +03:00
uint16_t passlen1 = SVAL ( req - > vwv + 7 , 0 ) ;
uint16_t passlen2 = SVAL ( req - > vwv + 8 , 0 ) ;
2001-10-15 11:50:21 +04:00
enum remote_arch_types ra_type = get_remote_arch ( ) ;
2008-11-01 19:35:48 +03:00
const uint8_t * p = req - > buf ;
const uint8_t * save_p = req - > buf ;
2015-05-03 07:01:14 +03:00
uint16_t byte_count ;
2007-08-21 06:04:24 +04:00
2014-05-21 12:56:26 +04:00
if ( ! xconn - > smb1 . sessions . done_sesssetup ) {
2008-11-02 14:20:47 +03:00
global_client_caps = IVAL ( req - > vwv + 11 , 0 ) ;
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
2008-11-02 03:21:53 +03:00
| | passlen1 > smbreq_bufrem ( req , p ) ) {
2007-07-26 20:01:12 +04:00
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
2008-11-02 03:21:53 +03:00
| | passlen2 > smbreq_bufrem ( req , p + passlen1 ) ) {
2007-07-26 20:01:12 +04:00
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 ) ;
2012-02-03 11:03:10 +04:00
} else {
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 ,
2008-11-01 19:35:48 +03:00
req - > buf ,
2007-11-11 02:36:47 +03:00
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 ,
2008-11-01 19:35:48 +03:00
req - > buf ,
2007-11-11 02:36:47 +03:00
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 ;
2008-11-01 22:02:07 +03:00
2008-11-02 03:07:46 +03:00
p + = srvstr_pull_req_talloc ( talloc_tos ( ) , req , & tmp , p ,
2008-11-01 22:02:07 +03:00
STR_TERMINATE ) ;
user = tmp ? tmp : " " ;
2008-11-02 03:07:46 +03:00
p + = srvstr_pull_req_talloc ( talloc_tos ( ) , req , & tmp , p ,
2008-11-01 22:02:07 +03:00
STR_TERMINATE ) ;
domain = tmp ? tmp : " " ;
2008-11-02 03:07:46 +03:00
p + = srvstr_pull_req_talloc ( talloc_tos ( ) , req , & tmp , p ,
2008-11-01 22:02:07 +03:00
STR_TERMINATE ) ;
native_os = tmp ? tmp : " " ;
2008-11-02 03:07:46 +03:00
p + = srvstr_pull_req_talloc ( talloc_tos ( ) , req , & tmp , p ,
2008-11-01 22:02:07 +03:00
STR_TERMINATE ) ;
native_lanman = tmp ? tmp : " " ;
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 */
2008-11-02 14:20:47 +03:00
byte_count = SVAL ( req - > vwv + 13 , 0 ) ;
2007-08-21 06:04:24 +04:00
if ( PTR_DIFF ( p , save_p ) < byte_count ) {
2008-11-02 03:07:46 +03:00
p + = srvstr_pull_req_talloc ( talloc_tos ( ) , req , & tmp , p ,
2008-11-01 22:02:07 +03:00
STR_TERMINATE ) ;
primary_domain = tmp ? tmp : " " ;
2007-08-21 06:04:24 +04:00
} else {
2008-11-01 22:02:07 +03:00
primary_domain = talloc_strdup ( talloc_tos ( ) , " 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
2008-11-02 14:20:47 +03:00
if ( SVAL ( req - > vwv + 4 , 0 ) = = 0 ) {
2010-08-15 11:24:30 +04:00
setup_new_vc_session ( req - > sconn ) ;
2003-05-28 01:55:10 +04:00
}
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 ) {
2014-05-21 12:27:50 +04:00
if ( xconn - > smb1 . negprot . spnego ) {
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 {
2011-07-27 10:06:31 +04:00
fstrcpy ( sub_user , " " ) ;
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
2011-12-14 16:25:20 +04:00
reload_services ( sconn , conn_snum_used , true ) ;
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 ) {
2012-02-03 10:09:37 +04:00
nt_status = check_guest_password ( sconn - > remote_address , req , & session_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 if ( doencrypt ) {
2012-02-03 10:09:37 +04:00
struct auth4_context * negprot_auth_context = NULL ;
2014-05-21 12:27:50 +04:00
negprot_auth_context = xconn - > smb1 . negprot . auth_context ;
2009-05-26 14:48:58 +04:00
if ( ! negprot_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
}
2014-03-27 00:17:15 +04:00
nt_status = make_user_info_for_reply_enc ( talloc_tos ( ) ,
& user_info , user ,
domain ,
sconn - > remote_address ,
lm_resp , nt_resp ) ;
2002-09-25 19:19:00 +04:00
if ( NT_STATUS_IS_OK ( nt_status ) ) {
2012-02-03 10:09:37 +04:00
nt_status = auth_check_password_session_info ( negprot_auth_context ,
req , user_info , & session_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 {
2012-02-03 10:09:37 +04:00
struct auth4_context * plaintext_auth_context = NULL ;
2006-03-10 20:52:41 +03:00
2012-02-03 10:09:37 +04:00
nt_status = make_auth4_context (
2010-09-26 02:31:29 +04:00
talloc_tos ( ) , & plaintext_auth_context ) ;
2006-03-10 20:52:41 +03:00
if ( NT_STATUS_IS_OK ( nt_status ) ) {
2009-02-20 01:41:48 +03:00
uint8_t chal [ 8 ] ;
plaintext_auth_context - > get_ntlm_challenge (
plaintext_auth_context , chal ) ;
2007-08-21 06:04:24 +04:00
2014-03-27 00:17:15 +04:00
if ( ! make_user_info_for_reply ( talloc_tos ( ) ,
& user_info ,
2011-06-08 20:55:37 +04:00
user , domain ,
sconn - > remote_address ,
chal ,
2002-01-05 07:55:41 +03:00
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 ) ) {
2012-02-03 10:09:37 +04:00
nt_status = auth_check_password_session_info ( plaintext_auth_context ,
req , user_info , & session_info ) ;
2002-01-05 07:55:41 +03:00
}
2012-02-03 10:09:37 +04:00
TALLOC_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
2014-03-27 00:17:15 +04:00
TALLOC_FREE ( 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 ) ) {
2011-02-11 03:50:37 +03:00
data_blob_free ( & nt_resp ) ;
data_blob_free ( & lm_resp ) ;
data_blob_clear_free ( & plaintext_password ) ;
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 ;
2006-03-10 21:32:18 +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 ) ;
2012-02-26 19:49:09 +04:00
SSVAL ( req - > outbuf , smb_vwv0 , 0xff ) ; /* andx chain ends */
SSVAL ( req - > outbuf , smb_vwv1 , 0 ) ; /* no andx offset */
2009-11-23 18:33:26 +03:00
if ( get_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
2016-04-20 17:34:28 +03:00
if ( security_session_user_level ( session_info , NULL ) = = SECURITY_GUEST ) {
2016-04-18 18:36:56 +03:00
action | = SMB_SETUP_GUEST ;
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
2014-06-11 17:11:05 +04:00
nt_status = smbXsrv_session_create ( xconn ,
2012-04-01 23:19:53 +04:00
now , & session ) ;
if ( ! NT_STATUS_IS_OK ( nt_status ) ) {
data_blob_free ( & nt_resp ) ;
data_blob_free ( & lm_resp ) ;
reply_nterror ( req , nt_status_squash ( nt_status ) ) ;
END_PROFILE ( SMBsesssetupX ) ;
return ;
}
2012-08-02 20:47:48 +04:00
if ( session_info - > session_key . length > 0 ) {
uint8_t session_key [ 16 ] ;
/*
* Note : the SMB1 signing key is not truncated to 16 byte !
*/
session - > global - > signing_key =
data_blob_dup_talloc ( session - > global ,
session_info - > session_key ) ;
if ( session - > global - > signing_key . data = = NULL ) {
data_blob_free ( & nt_resp ) ;
data_blob_free ( & lm_resp ) ;
TALLOC_FREE ( session ) ;
reply_nterror ( req , NT_STATUS_NO_MEMORY ) ;
END_PROFILE ( SMBsesssetupX ) ;
return ;
}
/*
* The application key is truncated / padded to 16 bytes
*/
ZERO_STRUCT ( session_key ) ;
memcpy ( session_key , session - > global - > signing_key . data ,
MIN ( session - > global - > signing_key . length ,
sizeof ( session_key ) ) ) ;
session - > global - > application_key =
data_blob_talloc ( session - > global ,
session_key ,
sizeof ( session_key ) ) ;
ZERO_STRUCT ( session_key ) ;
if ( session - > global - > application_key . data = = NULL ) {
data_blob_free ( & nt_resp ) ;
data_blob_free ( & lm_resp ) ;
TALLOC_FREE ( session ) ;
reply_nterror ( req , NT_STATUS_NO_MEMORY ) ;
END_PROFILE ( SMBsesssetupX ) ;
return ;
}
/*
* Place the application key into the session_info
*/
data_blob_clear_free ( & session_info - > session_key ) ;
session_info - > session_key = data_blob_dup_talloc ( session_info ,
session - > global - > application_key ) ;
if ( session_info - > session_key . data = = NULL ) {
data_blob_free ( & nt_resp ) ;
data_blob_free ( & lm_resp ) ;
TALLOC_FREE ( session ) ;
reply_nterror ( req , NT_STATUS_NO_MEMORY ) ;
END_PROFILE ( SMBsesssetupX ) ;
return ;
}
}
2012-04-01 23:19:53 +04:00
session - > compat = talloc_zero ( session , struct user_struct ) ;
if ( session - > compat = = NULL ) {
2012-02-03 11:03:10 +04:00
data_blob_free ( & nt_resp ) ;
data_blob_free ( & lm_resp ) ;
2012-04-01 23:19:53 +04:00
TALLOC_FREE ( session ) ;
reply_nterror ( req , NT_STATUS_NO_MEMORY ) ;
2012-02-03 11:03:10 +04:00
END_PROFILE ( SMBsesssetupX ) ;
return ;
2006-05-14 03:05:53 +04:00
}
2012-04-01 23:19:53 +04:00
session - > compat - > session = session ;
session - > compat - > homes_snum = - 1 ;
session - > compat - > session_info = session_info ;
session - > compat - > session_keystr = NULL ;
session - > compat - > vuid = session - > global - > session_wire_id ;
DLIST_ADD ( sconn - > users , session - > compat ) ;
sconn - > num_users + + ;
if ( security_session_user_level ( session_info , NULL ) > = SECURITY_USER ) {
2016-05-18 10:56:02 +03:00
is_authenticated = true ;
2012-04-01 23:19:53 +04:00
session - > compat - > homes_snum =
register_homes_share ( session_info - > unix_info - > unix_name ) ;
}
2014-05-21 16:44:01 +04:00
if ( srv_is_signing_negotiated ( xconn ) & &
2016-05-18 10:56:02 +03:00
is_authenticated & &
2012-08-02 20:47:48 +04:00
session - > global - > signing_key . length > 0 )
{
2012-04-01 23:19:53 +04:00
/*
* Try and turn on server signing on the first non - guest
* sessionsetup .
*/
2014-05-21 16:44:01 +04:00
srv_set_signing ( xconn ,
2012-08-02 20:47:48 +04:00
session - > global - > signing_key ,
2012-04-01 23:19:53 +04:00
nt_resp . data ? nt_resp : lm_resp ) ;
}
set_current_user_info ( session_info - > unix_info - > sanitized_username ,
session_info - > unix_info - > unix_name ,
session_info - > info - > domain_name ) ;
session - > status = NT_STATUS_OK ;
session - > global - > auth_session_info = talloc_move ( session - > global ,
& session_info ) ;
session - > global - > auth_session_info_seqnum + = 1 ;
session - > global - > channels [ 0 ] . auth_session_info_seqnum =
session - > global - > auth_session_info_seqnum ;
2014-06-12 11:49:28 +04:00
session - > global - > auth_time = now ;
2012-04-25 21:36:20 +04:00
session - > global - > expiration_time = GENSEC_EXPIRE_TIME_INFINITY ;
2012-04-01 23:19:53 +04:00
nt_status = smbXsrv_session_update ( session ) ;
if ( ! NT_STATUS_IS_OK ( nt_status ) ) {
DEBUG ( 0 , ( " smb1: Failed to update session for vuid=%llu - %s \n " ,
( unsigned long long ) session - > compat - > vuid ,
nt_errstr ( nt_status ) ) ) ;
data_blob_free ( & nt_resp ) ;
data_blob_free ( & lm_resp ) ;
TALLOC_FREE ( session ) ;
reply_nterror ( req , nt_status_squash ( nt_status ) ) ;
2012-02-03 11:03:10 +04:00
END_PROFILE ( SMBsesssetupX ) ;
return ;
}
2012-08-27 13:03:25 +04:00
if ( ! session_claim ( session ) ) {
DEBUG ( 1 , ( " smb1: Failed to claim session for vuid=%llu \n " ,
( unsigned long long ) session - > compat - > vuid ) ) ;
data_blob_free ( & nt_resp ) ;
data_blob_free ( & lm_resp ) ;
TALLOC_FREE ( session ) ;
reply_nterror ( req , NT_STATUS_LOGON_FAILURE ) ;
END_PROFILE ( SMBsesssetupX ) ;
return ;
}
2012-02-03 11:03:10 +04:00
/* current_user_info is changed on new vuid */
reload_services ( sconn , conn_snum_used , true ) ;
2003-07-18 04:53:34 +04:00
2012-04-01 23:19:53 +04:00
sess_vuid = session - > global - > session_wire_id ;
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
2012-04-01 23:19:53 +04:00
SSVAL ( req - > outbuf , smb_vwv2 , action ) ;
2007-07-26 20:01:12 +04:00
SSVAL ( req - > outbuf , smb_uid , sess_vuid ) ;
2011-05-06 01:22:11 +04:00
SSVAL ( discard_const_p ( char , req - > inbuf ) , smb_uid , sess_vuid ) ;
2009-07-16 00:59:11 +04:00
req - > vuid = sess_vuid ;
2007-08-21 06:04:24 +04:00
2014-05-21 12:56:26 +04:00
if ( ! xconn - > smb1 . sessions . done_sesssetup ) {
2013-12-06 16:52:09 +04:00
if ( smb_bufsize < SMB_BUFFER_SIZE_MIN ) {
reply_force_doserror ( req , ERRSRV , ERRerror ) ;
END_PROFILE ( SMBsesssetupX ) ;
return ;
}
2014-05-21 12:56:26 +04:00
xconn - > smb1 . sessions . max_send = smb_bufsize ;
xconn - > smb1 . sessions . done_sesssetup = true ;
2009-05-26 17:21:16 +04:00
}
2007-08-21 06:04:24 +04:00
2001-10-15 11:50:21 +04:00
END_PROFILE ( SMBsesssetupX ) ;
}