2005-01-16 14:15:08 +03:00
/*
Unix SMB / CIFS implementation .
Copyright ( C ) Andrew Tridgell 2005
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-10 06:07:03 +04:00
the Free Software Foundation ; either version 3 of the License , or
2005-01-16 14:15:08 +03:00
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
2007-07-10 06:07:03 +04:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2005-01-16 14:15:08 +03:00
*/
/*
a composite API for making handling a generic async session setup
*/
# include "includes.h"
# include "libcli/raw/libcliraw.h"
2008-04-02 06:53:27 +04:00
# include "libcli/raw/raw_proto.h"
2005-01-16 14:15:08 +03:00
# include "libcli/composite/composite.h"
2005-09-26 15:47:55 +04:00
# include "libcli/smb_composite/smb_composite.h"
2008-04-02 06:53:27 +04:00
# include "libcli/smb_composite/proto.h"
2006-03-14 18:03:25 +03:00
# include "libcli/auth/libcli_auth.h"
2005-01-16 14:15:08 +03:00
# include "auth/auth.h"
2006-11-07 03:48:36 +03:00
# include "auth/gensec/gensec.h"
# include "auth/credentials/credentials.h"
2005-06-19 17:26:32 +04:00
# include "version.h"
2007-09-08 16:42:09 +04:00
# include "param/param.h"
2005-01-16 14:15:08 +03:00
struct sesssetup_state {
union smb_sesssetup setup ;
2005-08-23 09:29:37 +04:00
NTSTATUS gensec_status ;
2005-01-17 00:58:28 +03:00
struct smb_composite_sesssetup * io ;
2005-01-17 01:22:13 +03:00
struct smbcli_request * req ;
2005-01-16 14:15:08 +03:00
} ;
2007-05-01 13:06:25 +04:00
static int sesssetup_state_destructor ( struct sesssetup_state * state )
{
if ( state - > req ) {
talloc_free ( state - > req ) ;
state - > req = NULL ;
}
return 0 ;
}
2006-05-03 18:54:57 +04:00
static NTSTATUS session_setup_old ( struct composite_context * c ,
struct smbcli_session * session ,
struct smb_composite_sesssetup * io ,
struct smbcli_request * * req ) ;
static NTSTATUS session_setup_nt1 ( struct composite_context * c ,
struct smbcli_session * session ,
struct smb_composite_sesssetup * io ,
struct smbcli_request * * req ) ;
static NTSTATUS session_setup_spnego ( struct composite_context * c ,
struct smbcli_session * session ,
struct smb_composite_sesssetup * io ,
struct smbcli_request * * req ) ;
2005-01-16 14:15:08 +03:00
/*
store the user session key for a transport
*/
static void set_user_session_key ( struct smbcli_session * session ,
const DATA_BLOB * session_key )
{
session - > user_session_key = data_blob_talloc ( session ,
session_key - > data ,
session_key - > length ) ;
}
/*
handler for completion of a smbcli_request sub - request
*/
static void request_handler ( struct smbcli_request * req )
{
2007-09-07 17:31:15 +04:00
struct composite_context * c = ( struct composite_context * ) req - > async . private ;
2005-09-26 15:47:55 +04:00
struct sesssetup_state * state = talloc_get_type ( c - > private_data , struct sesssetup_state ) ;
2005-01-16 14:15:08 +03:00
struct smbcli_session * session = req - > session ;
DATA_BLOB session_key = data_blob ( NULL , 0 ) ;
DATA_BLOB null_data_blob = data_blob ( NULL , 0 ) ;
2006-05-03 18:54:57 +04:00
NTSTATUS session_key_err , nt_status ;
2005-01-16 14:15:08 +03:00
2005-08-09 08:11:09 +04:00
c - > status = smb_raw_sesssetup_recv ( req , state , & state - > setup ) ;
2007-05-01 13:06:25 +04:00
state - > req = NULL ;
2005-01-16 14:15:08 +03:00
switch ( state - > setup . old . level ) {
case RAW_SESSSETUP_OLD :
2005-01-17 00:58:28 +03:00
state - > io - > out . vuid = state - > setup . old . out . vuid ;
2006-05-03 18:59:55 +04:00
/* This doesn't work, as this only happens on old
* protocols , where this comparison won ' t match . */
2006-05-03 18:54:57 +04:00
if ( NT_STATUS_EQUAL ( c - > status , NT_STATUS_LOGON_FAILURE ) ) {
2006-10-24 20:16:31 +04:00
/* we neet to reset the vuid for a new try */
session - > vuid = 0 ;
2006-05-03 18:54:57 +04:00
if ( cli_credentials_wrong_password ( state - > io - > in . credentials ) ) {
nt_status = session_setup_old ( c , session ,
state - > io ,
& state - > req ) ;
if ( NT_STATUS_IS_OK ( nt_status ) ) {
c - > status = nt_status ;
2007-05-01 13:06:25 +04:00
composite_continue_smb ( c , state - > req , request_handler , c ) ;
2006-05-03 18:54:57 +04:00
return ;
}
}
}
2005-01-16 14:15:08 +03:00
break ;
case RAW_SESSSETUP_NT1 :
2005-01-17 00:58:28 +03:00
state - > io - > out . vuid = state - > setup . nt1 . out . vuid ;
2006-05-03 18:54:57 +04:00
if ( NT_STATUS_EQUAL ( c - > status , NT_STATUS_LOGON_FAILURE ) ) {
2006-10-24 20:16:31 +04:00
/* we neet to reset the vuid for a new try */
session - > vuid = 0 ;
2006-05-03 18:54:57 +04:00
if ( cli_credentials_wrong_password ( state - > io - > in . credentials ) ) {
nt_status = session_setup_nt1 ( c , session ,
state - > io ,
& state - > req ) ;
if ( NT_STATUS_IS_OK ( nt_status ) ) {
c - > status = nt_status ;
2007-05-01 13:06:25 +04:00
composite_continue_smb ( c , state - > req , request_handler , c ) ;
2006-05-03 18:54:57 +04:00
return ;
}
}
}
2005-01-16 14:15:08 +03:00
break ;
case RAW_SESSSETUP_SPNEGO :
2006-10-24 20:16:31 +04:00
state - > io - > out . vuid = state - > setup . spnego . out . vuid ;
2006-05-03 18:54:57 +04:00
if ( NT_STATUS_EQUAL ( c - > status , NT_STATUS_LOGON_FAILURE ) ) {
2008-01-07 07:01:31 +03:00
/* we need to reset the vuid for a new try */
2006-10-24 20:16:31 +04:00
session - > vuid = 0 ;
2006-05-03 18:54:57 +04:00
if ( cli_credentials_wrong_password ( state - > io - > in . credentials ) ) {
nt_status = session_setup_spnego ( c , session ,
state - > io ,
& state - > req ) ;
if ( NT_STATUS_IS_OK ( nt_status ) ) {
c - > status = nt_status ;
2007-05-01 13:06:25 +04:00
composite_continue_smb ( c , state - > req , request_handler , c ) ;
2006-05-03 18:54:57 +04:00
return ;
}
}
}
2005-01-16 14:15:08 +03:00
if ( ! NT_STATUS_EQUAL ( c - > status , NT_STATUS_MORE_PROCESSING_REQUIRED ) & &
! NT_STATUS_IS_OK ( c - > status ) ) {
break ;
}
2005-08-23 09:29:37 +04:00
if ( NT_STATUS_EQUAL ( state - > gensec_status , NT_STATUS_MORE_PROCESSING_REQUIRED ) ) {
/* The status value here, from the earlier pass at GENSEC is
* vital to the security of the system . Even if the other end
* accepts , if GENSEC claims ' MORE_PROCESSING_REQUIRED ' then
* you must keep feeding it blobs , or else the remote
* host / attacker might avoid mutal authentication
* requirements */
state - > gensec_status = gensec_update ( session - > gensec , state ,
state - > setup . spnego . out . secblob ,
& state - > setup . spnego . in . secblob ) ;
c - > status = state - > gensec_status ;
if ( ! NT_STATUS_EQUAL ( c - > status , NT_STATUS_MORE_PROCESSING_REQUIRED ) & &
! NT_STATUS_IS_OK ( c - > status ) ) {
break ;
}
} else {
state - > setup . spnego . in . secblob = data_blob ( NULL , 0 ) ;
2005-01-16 14:15:08 +03:00
}
2007-05-01 13:06:25 +04:00
2005-01-16 14:15:08 +03:00
/* we need to do another round of session setup. We keep going until both sides
are happy */
2005-08-23 09:29:37 +04:00
session_key_err = gensec_session_key ( session - > gensec , & session_key ) ;
if ( NT_STATUS_IS_OK ( session_key_err ) ) {
2005-01-16 14:45:49 +03:00
set_user_session_key ( session , & session_key ) ;
2005-01-16 14:15:08 +03:00
smbcli_transport_simple_set_signing ( session - > transport , session_key , null_data_blob ) ;
}
2005-08-23 09:29:37 +04:00
if ( state - > setup . spnego . in . secblob . length ) {
2006-10-24 20:16:31 +04:00
/*
* set the session - > vuid value only for calling
* smb_raw_sesssetup_send ( )
*/
uint16_t vuid = session - > vuid ;
session - > vuid = state - > io - > out . vuid ;
2005-08-23 09:29:37 +04:00
state - > req = smb_raw_sesssetup_send ( session , & state - > setup ) ;
2006-10-24 20:16:31 +04:00
session - > vuid = vuid ;
2007-05-01 13:06:25 +04:00
composite_continue_smb ( c , state - > req , request_handler , c ) ;
2005-08-23 09:29:37 +04:00
return ;
}
2006-05-20 14:46:38 +04:00
break ;
case RAW_SESSSETUP_SMB2 :
c - > status = NT_STATUS_INTERNAL_ERROR ;
break ;
2005-01-16 14:15:08 +03:00
}
/* enforce the local signing required flag */
r6028: A MAJOR update to intergrate the new credentails system fully with
GENSEC, and to pull SCHANNEL into GENSEC, by making it less 'special'.
GENSEC now no longer has it's own handling of 'set username' etc,
instead it uses cli_credentials calls.
In order to link the credentails code right though Samba, a lot of
interfaces have changed to remove 'username, domain, password'
arguments, and these have been replaced with a single 'struct
cli_credentials'.
In the session setup code, a new parameter 'workgroup' contains the
client/server current workgroup, which seems unrelated to the
authentication exchange (it was being filled in from the auth info).
This allows in particular kerberos to only call back for passwords
when it actually needs to perform the kinit.
The kerberos code has been modified not to use the SPNEGO provided
'principal name' (in the mechListMIC), but to instead use the name the
host was connected to as. This better matches Microsoft behaviour,
is more secure and allows better use of standard kerberos functions.
To achieve this, I made changes to our socket code so that the
hostname (before name resolution) is now recorded on the socket.
In schannel, most of the code from librpc/rpc/dcerpc_schannel.c is now
in libcli/auth/schannel.c, and it looks much more like a standard
GENSEC module. The actual sign/seal code moved to
libcli/auth/schannel_sign.c in a previous commit.
The schannel credentails structure is now merged with the rest of the
credentails, as many of the values (username, workstation, domain)
where already present there. This makes handling this in a generic
manner much easier, as there is no longer a custom entry-point.
The auth_domain module continues to be developed, but is now just as
functional as auth_winbind. The changes here are consequential to the
schannel changes.
The only removed function at this point is the RPC-LOGIN test
(simulating the load of a WinXP login), which needs much more work to
clean it up (it contains copies of too much code from all over the
torture suite, and I havn't been able to penetrate its 'structure').
Andrew Bartlett
(This used to be commit 2301a4b38a21aa60917973451687063d83d18d66)
2005-03-24 07:14:06 +03:00
if ( NT_STATUS_IS_OK ( c - > status ) & & ! cli_credentials_is_anonymous ( state - > io - > in . credentials ) ) {
2005-01-16 14:15:08 +03:00
if ( ! session - > transport - > negotiate . sign_info . doing_signing
& & session - > transport - > negotiate . sign_info . mandatory_signing ) {
DEBUG ( 0 , ( " SMB signing required, but server does not support it \n " ) ) ;
c - > status = NT_STATUS_ACCESS_DENIED ;
}
}
2007-05-01 13:06:25 +04:00
if ( ! NT_STATUS_IS_OK ( c - > status ) ) {
composite_error ( c , c - > status ) ;
return ;
2005-01-16 14:15:08 +03:00
}
2007-05-01 13:06:25 +04:00
composite_done ( c ) ;
2005-01-16 14:15:08 +03:00
}
/*
send a nt1 style session setup
*/
2005-08-23 09:29:37 +04:00
static NTSTATUS session_setup_nt1 ( struct composite_context * c ,
struct smbcli_session * session ,
struct smb_composite_sesssetup * io ,
struct smbcli_request * * req )
2005-01-16 14:15:08 +03:00
{
2005-10-14 07:57:35 +04:00
NTSTATUS nt_status ;
2005-09-26 15:47:55 +04:00
struct sesssetup_state * state = talloc_get_type ( c - > private_data , struct sesssetup_state ) ;
2008-02-21 17:45:32 +03:00
DATA_BLOB names_blob = NTLMv2_generate_names_blob ( state , lp_iconv_convenience ( global_loadparm ) , session - > transport - > socket - > hostname , lp_workgroup ( global_loadparm ) ) ;
2005-10-14 07:57:35 +04:00
DATA_BLOB session_key ;
int flags = CLI_CRED_NTLM_AUTH ;
2008-02-21 20:09:47 +03:00
if ( session - > options . lanman_auth ) {
2005-10-14 07:57:35 +04:00
flags | = CLI_CRED_LANMAN_AUTH ;
}
2008-02-21 20:09:47 +03:00
if ( session - > options . ntlmv2_auth ) {
2005-10-14 07:57:35 +04:00
flags | = CLI_CRED_NTLMv2_AUTH ;
}
2005-01-16 14:15:08 +03:00
state - > setup . nt1 . level = RAW_SESSSETUP_NT1 ;
state - > setup . nt1 . in . bufsize = session - > transport - > options . max_xmit ;
state - > setup . nt1 . in . mpx_max = session - > transport - > options . max_mux ;
state - > setup . nt1 . in . vc_num = 1 ;
state - > setup . nt1 . in . sesskey = io - > in . sesskey ;
state - > setup . nt1 . in . capabilities = io - > in . capabilities ;
state - > setup . nt1 . in . os = " Unix " ;
2005-06-19 17:26:32 +04:00
state - > setup . nt1 . in . lanman = talloc_asprintf ( state , " Samba %s " , SAMBA_VERSION_STRING ) ;
2005-10-14 07:57:35 +04:00
2005-09-22 05:50:58 +04:00
cli_credentials_get_ntlm_username_domain ( io - > in . credentials , state ,
& state - > setup . nt1 . in . user ,
& state - > setup . nt1 . in . domain ) ;
2005-10-14 07:57:35 +04:00
2005-01-16 14:15:08 +03:00
2005-10-14 07:57:35 +04:00
if ( session - > transport - > negotiate . sec_mode & NEGOTIATE_SECURITY_CHALLENGE_RESPONSE ) {
nt_status = cli_credentials_get_ntlm_response ( io - > in . credentials , state ,
& flags ,
session - > transport - > negotiate . secblob ,
names_blob ,
& state - > setup . nt1 . in . password1 ,
& state - > setup . nt1 . in . password2 ,
NULL , & session_key ) ;
2006-03-15 05:42:21 +03:00
NT_STATUS_NOT_OK_RETURN ( nt_status ) ;
2005-06-19 17:26:32 +04:00
2005-09-29 04:28:46 +04:00
smbcli_transport_simple_set_signing ( session - > transport , session_key ,
state - > setup . nt1 . in . password2 ) ;
set_user_session_key ( session , & session_key ) ;
data_blob_free ( & session_key ) ;
2008-02-21 20:09:47 +03:00
} else if ( session - > options . plaintext_auth ) {
2008-04-25 18:08:52 +04:00
const char * password = cli_credentials_get_password ( io - > in . credentials ) ;
r6028: A MAJOR update to intergrate the new credentails system fully with
GENSEC, and to pull SCHANNEL into GENSEC, by making it less 'special'.
GENSEC now no longer has it's own handling of 'set username' etc,
instead it uses cli_credentials calls.
In order to link the credentails code right though Samba, a lot of
interfaces have changed to remove 'username, domain, password'
arguments, and these have been replaced with a single 'struct
cli_credentials'.
In the session setup code, a new parameter 'workgroup' contains the
client/server current workgroup, which seems unrelated to the
authentication exchange (it was being filled in from the auth info).
This allows in particular kerberos to only call back for passwords
when it actually needs to perform the kinit.
The kerberos code has been modified not to use the SPNEGO provided
'principal name' (in the mechListMIC), but to instead use the name the
host was connected to as. This better matches Microsoft behaviour,
is more secure and allows better use of standard kerberos functions.
To achieve this, I made changes to our socket code so that the
hostname (before name resolution) is now recorded on the socket.
In schannel, most of the code from librpc/rpc/dcerpc_schannel.c is now
in libcli/auth/schannel.c, and it looks much more like a standard
GENSEC module. The actual sign/seal code moved to
libcli/auth/schannel_sign.c in a previous commit.
The schannel credentails structure is now merged with the rest of the
credentails, as many of the values (username, workstation, domain)
where already present there. This makes handling this in a generic
manner much easier, as there is no longer a custom entry-point.
The auth_domain module continues to be developed, but is now just as
functional as auth_winbind. The changes here are consequential to the
schannel changes.
The only removed function at this point is the RPC-LOGIN test
(simulating the load of a WinXP login), which needs much more work to
clean it up (it contains copies of too much code from all over the
torture suite, and I havn't been able to penetrate its 'structure').
Andrew Bartlett
(This used to be commit 2301a4b38a21aa60917973451687063d83d18d66)
2005-03-24 07:14:06 +03:00
state - > setup . nt1 . in . password1 = data_blob_talloc ( state , password , strlen ( password ) ) ;
2005-01-16 14:15:08 +03:00
state - > setup . nt1 . in . password2 = data_blob ( NULL , 0 ) ;
2005-06-19 17:26:32 +04:00
} else {
/* could match windows client and return 'cannot logon from this workstation', but it just confuses everybody */
2005-08-23 09:29:37 +04:00
return NT_STATUS_INVALID_PARAMETER ;
2005-01-16 14:15:08 +03:00
}
2005-08-23 09:29:37 +04:00
* req = smb_raw_sesssetup_send ( session , & state - > setup ) ;
if ( ! * req ) {
return NT_STATUS_NO_MEMORY ;
}
return ( * req ) - > status ;
2005-01-16 14:15:08 +03:00
}
/*
old style session setup ( pre NT1 protocol level )
*/
2005-08-23 09:29:37 +04:00
static NTSTATUS session_setup_old ( struct composite_context * c ,
struct smbcli_session * session ,
struct smb_composite_sesssetup * io ,
struct smbcli_request * * req )
2005-01-16 14:15:08 +03:00
{
2005-10-14 07:57:35 +04:00
NTSTATUS nt_status ;
2005-09-26 15:47:55 +04:00
struct sesssetup_state * state = talloc_get_type ( c - > private_data , struct sesssetup_state ) ;
r6028: A MAJOR update to intergrate the new credentails system fully with
GENSEC, and to pull SCHANNEL into GENSEC, by making it less 'special'.
GENSEC now no longer has it's own handling of 'set username' etc,
instead it uses cli_credentials calls.
In order to link the credentails code right though Samba, a lot of
interfaces have changed to remove 'username, domain, password'
arguments, and these have been replaced with a single 'struct
cli_credentials'.
In the session setup code, a new parameter 'workgroup' contains the
client/server current workgroup, which seems unrelated to the
authentication exchange (it was being filled in from the auth info).
This allows in particular kerberos to only call back for passwords
when it actually needs to perform the kinit.
The kerberos code has been modified not to use the SPNEGO provided
'principal name' (in the mechListMIC), but to instead use the name the
host was connected to as. This better matches Microsoft behaviour,
is more secure and allows better use of standard kerberos functions.
To achieve this, I made changes to our socket code so that the
hostname (before name resolution) is now recorded on the socket.
In schannel, most of the code from librpc/rpc/dcerpc_schannel.c is now
in libcli/auth/schannel.c, and it looks much more like a standard
GENSEC module. The actual sign/seal code moved to
libcli/auth/schannel_sign.c in a previous commit.
The schannel credentails structure is now merged with the rest of the
credentails, as many of the values (username, workstation, domain)
where already present there. This makes handling this in a generic
manner much easier, as there is no longer a custom entry-point.
The auth_domain module continues to be developed, but is now just as
functional as auth_winbind. The changes here are consequential to the
schannel changes.
The only removed function at this point is the RPC-LOGIN test
(simulating the load of a WinXP login), which needs much more work to
clean it up (it contains copies of too much code from all over the
torture suite, and I havn't been able to penetrate its 'structure').
Andrew Bartlett
(This used to be commit 2301a4b38a21aa60917973451687063d83d18d66)
2005-03-24 07:14:06 +03:00
const char * password = cli_credentials_get_password ( io - > in . credentials ) ;
2008-02-21 17:45:32 +03:00
DATA_BLOB names_blob = NTLMv2_generate_names_blob ( state , lp_iconv_convenience ( global_loadparm ) , session - > transport - > socket - > hostname , lp_workgroup ( global_loadparm ) ) ;
2005-10-14 07:57:35 +04:00
DATA_BLOB session_key ;
int flags = 0 ;
2008-02-21 20:09:47 +03:00
if ( session - > options . lanman_auth ) {
2005-10-14 07:57:35 +04:00
flags | = CLI_CRED_LANMAN_AUTH ;
}
2008-02-21 20:09:47 +03:00
if ( session - > options . ntlmv2_auth ) {
2005-10-14 07:57:35 +04:00
flags | = CLI_CRED_NTLMv2_AUTH ;
}
2005-01-16 14:15:08 +03:00
state - > setup . old . level = RAW_SESSSETUP_OLD ;
state - > setup . old . in . bufsize = session - > transport - > options . max_xmit ;
state - > setup . old . in . mpx_max = session - > transport - > options . max_mux ;
state - > setup . old . in . vc_num = 1 ;
state - > setup . old . in . sesskey = io - > in . sesskey ;
state - > setup . old . in . os = " Unix " ;
2005-06-19 17:26:32 +04:00
state - > setup . old . in . lanman = talloc_asprintf ( state , " Samba %s " , SAMBA_VERSION_STRING ) ;
2005-09-22 05:50:58 +04:00
cli_credentials_get_ntlm_username_domain ( io - > in . credentials , state ,
& state - > setup . old . in . user ,
& state - > setup . old . in . domain ) ;
2005-01-16 14:15:08 +03:00
2005-10-14 07:57:35 +04:00
if ( session - > transport - > negotiate . sec_mode & NEGOTIATE_SECURITY_CHALLENGE_RESPONSE ) {
nt_status = cli_credentials_get_ntlm_response ( io - > in . credentials , state ,
& flags ,
session - > transport - > negotiate . secblob ,
names_blob ,
& state - > setup . old . in . password ,
NULL ,
NULL , & session_key ) ;
2006-03-15 05:42:21 +03:00
NT_STATUS_NOT_OK_RETURN ( nt_status ) ;
2005-10-14 07:57:35 +04:00
set_user_session_key ( session , & session_key ) ;
data_blob_free ( & session_key ) ;
2008-02-21 20:09:47 +03:00
} else if ( session - > options . plaintext_auth ) {
2005-10-14 07:57:35 +04:00
state - > setup . old . in . password = data_blob_talloc ( state , password , strlen ( password ) ) ;
2005-01-16 14:15:08 +03:00
} else {
2005-10-14 07:57:35 +04:00
/* could match windows client and return 'cannot logon from this workstation', but it just confuses everybody */
return NT_STATUS_INVALID_PARAMETER ;
2005-01-16 14:15:08 +03:00
}
2005-08-23 09:29:37 +04:00
* req = smb_raw_sesssetup_send ( session , & state - > setup ) ;
if ( ! * req ) {
return NT_STATUS_NO_MEMORY ;
}
return ( * req ) - > status ;
2005-01-16 14:15:08 +03:00
}
/*
2005-08-23 09:29:37 +04:00
Modern , all singing , all dancing extended security ( and possibly SPNEGO ) request
2005-01-16 14:15:08 +03:00
*/
2005-08-23 09:29:37 +04:00
static NTSTATUS session_setup_spnego ( struct composite_context * c ,
struct smbcli_session * session ,
struct smb_composite_sesssetup * io ,
struct smbcli_request * * req )
2005-01-16 14:15:08 +03:00
{
2005-09-26 15:47:55 +04:00
struct sesssetup_state * state = talloc_get_type ( c - > private_data , struct sesssetup_state ) ;
2005-08-23 09:29:37 +04:00
NTSTATUS status , session_key_err ;
2005-01-16 14:15:08 +03:00
DATA_BLOB session_key = data_blob ( NULL , 0 ) ;
DATA_BLOB null_data_blob = data_blob ( NULL , 0 ) ;
const char * chosen_oid = NULL ;
state - > setup . spnego . level = RAW_SESSSETUP_SPNEGO ;
state - > setup . spnego . in . bufsize = session - > transport - > options . max_xmit ;
state - > setup . spnego . in . mpx_max = session - > transport - > options . max_mux ;
state - > setup . spnego . in . vc_num = 1 ;
state - > setup . spnego . in . sesskey = io - > in . sesskey ;
state - > setup . spnego . in . capabilities = io - > in . capabilities ;
state - > setup . spnego . in . os = " Unix " ;
2005-06-19 17:26:32 +04:00
state - > setup . spnego . in . lanman = talloc_asprintf ( state , " Samba %s " , SAMBA_VERSION_STRING ) ;
r6028: A MAJOR update to intergrate the new credentails system fully with
GENSEC, and to pull SCHANNEL into GENSEC, by making it less 'special'.
GENSEC now no longer has it's own handling of 'set username' etc,
instead it uses cli_credentials calls.
In order to link the credentails code right though Samba, a lot of
interfaces have changed to remove 'username, domain, password'
arguments, and these have been replaced with a single 'struct
cli_credentials'.
In the session setup code, a new parameter 'workgroup' contains the
client/server current workgroup, which seems unrelated to the
authentication exchange (it was being filled in from the auth info).
This allows in particular kerberos to only call back for passwords
when it actually needs to perform the kinit.
The kerberos code has been modified not to use the SPNEGO provided
'principal name' (in the mechListMIC), but to instead use the name the
host was connected to as. This better matches Microsoft behaviour,
is more secure and allows better use of standard kerberos functions.
To achieve this, I made changes to our socket code so that the
hostname (before name resolution) is now recorded on the socket.
In schannel, most of the code from librpc/rpc/dcerpc_schannel.c is now
in libcli/auth/schannel.c, and it looks much more like a standard
GENSEC module. The actual sign/seal code moved to
libcli/auth/schannel_sign.c in a previous commit.
The schannel credentails structure is now merged with the rest of the
credentails, as many of the values (username, workstation, domain)
where already present there. This makes handling this in a generic
manner much easier, as there is no longer a custom entry-point.
The auth_domain module continues to be developed, but is now just as
functional as auth_winbind. The changes here are consequential to the
schannel changes.
The only removed function at this point is the RPC-LOGIN test
(simulating the load of a WinXP login), which needs much more work to
clean it up (it contains copies of too much code from all over the
torture suite, and I havn't been able to penetrate its 'structure').
Andrew Bartlett
(This used to be commit 2301a4b38a21aa60917973451687063d83d18d66)
2005-03-24 07:14:06 +03:00
state - > setup . spnego . in . workgroup = io - > in . workgroup ;
2005-01-16 14:15:08 +03:00
smbcli_temp_set_signing ( session - > transport ) ;
2007-12-03 19:41:50 +03:00
status = gensec_client_start ( session , & session - > gensec , c - > event_ctx ,
global_loadparm ) ;
2005-01-16 14:15:08 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
DEBUG ( 1 , ( " Failed to start GENSEC client mode: %s \n " , nt_errstr ( status ) ) ) ;
2005-08-23 09:29:37 +04:00
return status ;
2005-01-16 14:15:08 +03:00
}
gensec_want_feature ( session - > gensec , GENSEC_FEATURE_SESSION_KEY ) ;
r6028: A MAJOR update to intergrate the new credentails system fully with
GENSEC, and to pull SCHANNEL into GENSEC, by making it less 'special'.
GENSEC now no longer has it's own handling of 'set username' etc,
instead it uses cli_credentials calls.
In order to link the credentails code right though Samba, a lot of
interfaces have changed to remove 'username, domain, password'
arguments, and these have been replaced with a single 'struct
cli_credentials'.
In the session setup code, a new parameter 'workgroup' contains the
client/server current workgroup, which seems unrelated to the
authentication exchange (it was being filled in from the auth info).
This allows in particular kerberos to only call back for passwords
when it actually needs to perform the kinit.
The kerberos code has been modified not to use the SPNEGO provided
'principal name' (in the mechListMIC), but to instead use the name the
host was connected to as. This better matches Microsoft behaviour,
is more secure and allows better use of standard kerberos functions.
To achieve this, I made changes to our socket code so that the
hostname (before name resolution) is now recorded on the socket.
In schannel, most of the code from librpc/rpc/dcerpc_schannel.c is now
in libcli/auth/schannel.c, and it looks much more like a standard
GENSEC module. The actual sign/seal code moved to
libcli/auth/schannel_sign.c in a previous commit.
The schannel credentails structure is now merged with the rest of the
credentails, as many of the values (username, workstation, domain)
where already present there. This makes handling this in a generic
manner much easier, as there is no longer a custom entry-point.
The auth_domain module continues to be developed, but is now just as
functional as auth_winbind. The changes here are consequential to the
schannel changes.
The only removed function at this point is the RPC-LOGIN test
(simulating the load of a WinXP login), which needs much more work to
clean it up (it contains copies of too much code from all over the
torture suite, and I havn't been able to penetrate its 'structure').
Andrew Bartlett
(This used to be commit 2301a4b38a21aa60917973451687063d83d18d66)
2005-03-24 07:14:06 +03:00
status = gensec_set_credentials ( session - > gensec , io - > in . credentials ) ;
2005-01-16 14:15:08 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2007-12-02 21:31:14 +03:00
DEBUG ( 1 , ( " Failed to start set GENSEC client credentials: %s \n " ,
r6028: A MAJOR update to intergrate the new credentails system fully with
GENSEC, and to pull SCHANNEL into GENSEC, by making it less 'special'.
GENSEC now no longer has it's own handling of 'set username' etc,
instead it uses cli_credentials calls.
In order to link the credentails code right though Samba, a lot of
interfaces have changed to remove 'username, domain, password'
arguments, and these have been replaced with a single 'struct
cli_credentials'.
In the session setup code, a new parameter 'workgroup' contains the
client/server current workgroup, which seems unrelated to the
authentication exchange (it was being filled in from the auth info).
This allows in particular kerberos to only call back for passwords
when it actually needs to perform the kinit.
The kerberos code has been modified not to use the SPNEGO provided
'principal name' (in the mechListMIC), but to instead use the name the
host was connected to as. This better matches Microsoft behaviour,
is more secure and allows better use of standard kerberos functions.
To achieve this, I made changes to our socket code so that the
hostname (before name resolution) is now recorded on the socket.
In schannel, most of the code from librpc/rpc/dcerpc_schannel.c is now
in libcli/auth/schannel.c, and it looks much more like a standard
GENSEC module. The actual sign/seal code moved to
libcli/auth/schannel_sign.c in a previous commit.
The schannel credentails structure is now merged with the rest of the
credentails, as many of the values (username, workstation, domain)
where already present there. This makes handling this in a generic
manner much easier, as there is no longer a custom entry-point.
The auth_domain module continues to be developed, but is now just as
functional as auth_winbind. The changes here are consequential to the
schannel changes.
The only removed function at this point is the RPC-LOGIN test
(simulating the load of a WinXP login), which needs much more work to
clean it up (it contains copies of too much code from all over the
torture suite, and I havn't been able to penetrate its 'structure').
Andrew Bartlett
(This used to be commit 2301a4b38a21aa60917973451687063d83d18d66)
2005-03-24 07:14:06 +03:00
nt_errstr ( status ) ) ) ;
2005-08-23 09:29:37 +04:00
return status ;
2005-01-16 14:15:08 +03:00
}
r6028: A MAJOR update to intergrate the new credentails system fully with
GENSEC, and to pull SCHANNEL into GENSEC, by making it less 'special'.
GENSEC now no longer has it's own handling of 'set username' etc,
instead it uses cli_credentials calls.
In order to link the credentails code right though Samba, a lot of
interfaces have changed to remove 'username, domain, password'
arguments, and these have been replaced with a single 'struct
cli_credentials'.
In the session setup code, a new parameter 'workgroup' contains the
client/server current workgroup, which seems unrelated to the
authentication exchange (it was being filled in from the auth info).
This allows in particular kerberos to only call back for passwords
when it actually needs to perform the kinit.
The kerberos code has been modified not to use the SPNEGO provided
'principal name' (in the mechListMIC), but to instead use the name the
host was connected to as. This better matches Microsoft behaviour,
is more secure and allows better use of standard kerberos functions.
To achieve this, I made changes to our socket code so that the
hostname (before name resolution) is now recorded on the socket.
In schannel, most of the code from librpc/rpc/dcerpc_schannel.c is now
in libcli/auth/schannel.c, and it looks much more like a standard
GENSEC module. The actual sign/seal code moved to
libcli/auth/schannel_sign.c in a previous commit.
The schannel credentails structure is now merged with the rest of the
credentails, as many of the values (username, workstation, domain)
where already present there. This makes handling this in a generic
manner much easier, as there is no longer a custom entry-point.
The auth_domain module continues to be developed, but is now just as
functional as auth_winbind. The changes here are consequential to the
schannel changes.
The only removed function at this point is the RPC-LOGIN test
(simulating the load of a WinXP login), which needs much more work to
clean it up (it contains copies of too much code from all over the
torture suite, and I havn't been able to penetrate its 'structure').
Andrew Bartlett
(This used to be commit 2301a4b38a21aa60917973451687063d83d18d66)
2005-03-24 07:14:06 +03:00
status = gensec_set_target_hostname ( session - > gensec , session - > transport - > socket - > hostname ) ;
2005-01-16 14:15:08 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
r6028: A MAJOR update to intergrate the new credentails system fully with
GENSEC, and to pull SCHANNEL into GENSEC, by making it less 'special'.
GENSEC now no longer has it's own handling of 'set username' etc,
instead it uses cli_credentials calls.
In order to link the credentails code right though Samba, a lot of
interfaces have changed to remove 'username, domain, password'
arguments, and these have been replaced with a single 'struct
cli_credentials'.
In the session setup code, a new parameter 'workgroup' contains the
client/server current workgroup, which seems unrelated to the
authentication exchange (it was being filled in from the auth info).
This allows in particular kerberos to only call back for passwords
when it actually needs to perform the kinit.
The kerberos code has been modified not to use the SPNEGO provided
'principal name' (in the mechListMIC), but to instead use the name the
host was connected to as. This better matches Microsoft behaviour,
is more secure and allows better use of standard kerberos functions.
To achieve this, I made changes to our socket code so that the
hostname (before name resolution) is now recorded on the socket.
In schannel, most of the code from librpc/rpc/dcerpc_schannel.c is now
in libcli/auth/schannel.c, and it looks much more like a standard
GENSEC module. The actual sign/seal code moved to
libcli/auth/schannel_sign.c in a previous commit.
The schannel credentails structure is now merged with the rest of the
credentails, as many of the values (username, workstation, domain)
where already present there. This makes handling this in a generic
manner much easier, as there is no longer a custom entry-point.
The auth_domain module continues to be developed, but is now just as
functional as auth_winbind. The changes here are consequential to the
schannel changes.
The only removed function at this point is the RPC-LOGIN test
(simulating the load of a WinXP login), which needs much more work to
clean it up (it contains copies of too much code from all over the
torture suite, and I havn't been able to penetrate its 'structure').
Andrew Bartlett
(This used to be commit 2301a4b38a21aa60917973451687063d83d18d66)
2005-03-24 07:14:06 +03:00
DEBUG ( 1 , ( " Failed to start set GENSEC target hostname: %s \n " ,
2005-01-16 14:15:08 +03:00
nt_errstr ( status ) ) ) ;
2005-08-23 09:29:37 +04:00
return status ;
2005-01-16 14:15:08 +03:00
}
2005-05-10 14:07:18 +04:00
status = gensec_set_target_service ( session - > gensec , " cifs " ) ;
2005-01-16 14:15:08 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
r6028: A MAJOR update to intergrate the new credentails system fully with
GENSEC, and to pull SCHANNEL into GENSEC, by making it less 'special'.
GENSEC now no longer has it's own handling of 'set username' etc,
instead it uses cli_credentials calls.
In order to link the credentails code right though Samba, a lot of
interfaces have changed to remove 'username, domain, password'
arguments, and these have been replaced with a single 'struct
cli_credentials'.
In the session setup code, a new parameter 'workgroup' contains the
client/server current workgroup, which seems unrelated to the
authentication exchange (it was being filled in from the auth info).
This allows in particular kerberos to only call back for passwords
when it actually needs to perform the kinit.
The kerberos code has been modified not to use the SPNEGO provided
'principal name' (in the mechListMIC), but to instead use the name the
host was connected to as. This better matches Microsoft behaviour,
is more secure and allows better use of standard kerberos functions.
To achieve this, I made changes to our socket code so that the
hostname (before name resolution) is now recorded on the socket.
In schannel, most of the code from librpc/rpc/dcerpc_schannel.c is now
in libcli/auth/schannel.c, and it looks much more like a standard
GENSEC module. The actual sign/seal code moved to
libcli/auth/schannel_sign.c in a previous commit.
The schannel credentails structure is now merged with the rest of the
credentails, as many of the values (username, workstation, domain)
where already present there. This makes handling this in a generic
manner much easier, as there is no longer a custom entry-point.
The auth_domain module continues to be developed, but is now just as
functional as auth_winbind. The changes here are consequential to the
schannel changes.
The only removed function at this point is the RPC-LOGIN test
(simulating the load of a WinXP login), which needs much more work to
clean it up (it contains copies of too much code from all over the
torture suite, and I havn't been able to penetrate its 'structure').
Andrew Bartlett
(This used to be commit 2301a4b38a21aa60917973451687063d83d18d66)
2005-03-24 07:14:06 +03:00
DEBUG ( 1 , ( " Failed to start set GENSEC target service: %s \n " ,
2005-01-16 14:15:08 +03:00
nt_errstr ( status ) ) ) ;
2005-08-23 09:29:37 +04:00
return status ;
2005-01-16 14:15:08 +03:00
}
if ( session - > transport - > negotiate . secblob . length ) {
chosen_oid = GENSEC_OID_SPNEGO ;
2006-03-06 02:06:37 +03:00
status = gensec_start_mech_by_oid ( session - > gensec , chosen_oid ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
DEBUG ( 1 , ( " Failed to start set GENSEC client mechanism %s: %s \n " ,
gensec_get_name_by_oid ( chosen_oid ) , nt_errstr ( status ) ) ) ;
chosen_oid = GENSEC_OID_NTLMSSP ;
status = gensec_start_mech_by_oid ( session - > gensec , chosen_oid ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
DEBUG ( 1 , ( " Failed to start set (fallback) GENSEC client mechanism %s: %s \n " ,
gensec_get_name_by_oid ( chosen_oid ) , nt_errstr ( status ) ) ) ;
return status ;
}
}
2005-01-16 14:15:08 +03:00
} else {
/* without a sec blob, means raw NTLMSSP */
chosen_oid = GENSEC_OID_NTLMSSP ;
2006-02-09 06:06:02 +03:00
status = gensec_start_mech_by_oid ( session - > gensec , chosen_oid ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
2006-03-06 02:06:37 +03:00
DEBUG ( 1 , ( " Failed to start set GENSEC client mechanism %s: %s \n " ,
2006-02-09 06:06:02 +03:00
gensec_get_name_by_oid ( chosen_oid ) , nt_errstr ( status ) ) ) ;
}
2005-01-16 14:15:08 +03:00
}
2006-03-06 02:06:37 +03:00
2007-10-01 22:52:55 +04:00
if ( ( const void * ) chosen_oid = = ( const void * ) GENSEC_OID_SPNEGO ) {
2006-03-06 02:06:37 +03:00
status = gensec_update ( session - > gensec , state ,
session - > transport - > negotiate . secblob ,
& state - > setup . spnego . in . secblob ) ;
} else {
status = gensec_update ( session - > gensec , state ,
data_blob ( NULL , 0 ) ,
& state - > setup . spnego . in . secblob ) ;
}
2005-08-23 09:29:37 +04:00
if ( ! NT_STATUS_EQUAL ( status , NT_STATUS_MORE_PROCESSING_REQUIRED ) & &
! NT_STATUS_IS_OK ( status ) ) {
2005-01-16 14:15:08 +03:00
DEBUG ( 1 , ( " Failed initial gensec_update with mechanism %s: %s \n " ,
gensec_get_name_by_oid ( chosen_oid ) , nt_errstr ( status ) ) ) ;
2005-08-23 09:29:37 +04:00
return status ;
2005-01-16 14:15:08 +03:00
}
2005-08-23 09:29:37 +04:00
state - > gensec_status = status ;
2005-01-16 14:15:08 +03:00
2005-08-23 09:29:37 +04:00
session_key_err = gensec_session_key ( session - > gensec , & session_key ) ;
if ( NT_STATUS_IS_OK ( session_key_err ) ) {
2005-01-16 14:15:08 +03:00
smbcli_transport_simple_set_signing ( session - > transport , session_key , null_data_blob ) ;
}
2005-08-23 09:29:37 +04:00
* req = smb_raw_sesssetup_send ( session , & state - > setup ) ;
if ( ! * req ) {
return NT_STATUS_NO_MEMORY ;
}
return ( * req ) - > status ;
2005-01-16 14:15:08 +03:00
}
/*
composite session setup function that hides the details of all the
different session setup varients , including the multi - pass nature of
the spnego varient
*/
2005-01-31 11:30:44 +03:00
struct composite_context * smb_composite_sesssetup_send ( struct smbcli_session * session ,
2005-03-26 13:22:02 +03:00
struct smb_composite_sesssetup * io )
2005-01-16 14:15:08 +03:00
{
2005-01-31 11:30:44 +03:00
struct composite_context * c ;
2005-01-16 14:15:08 +03:00
struct sesssetup_state * state ;
2005-08-23 09:29:37 +04:00
NTSTATUS status ;
2005-01-16 14:15:08 +03:00
2007-05-01 13:06:25 +04:00
c = composite_create ( session , session - > transport - > socket - > event . ctx ) ;
2005-08-23 09:29:37 +04:00
if ( c = = NULL ) return NULL ;
2005-01-16 14:15:08 +03:00
2007-05-01 13:06:25 +04:00
state = talloc_zero ( c , struct sesssetup_state ) ;
if ( composite_nomem ( state , c ) ) return c ;
c - > private_data = state ;
2005-01-16 14:15:08 +03:00
2005-01-17 00:58:28 +03:00
state - > io = io ;
2007-05-01 13:06:25 +04:00
talloc_set_destructor ( state , sesssetup_state_destructor ) ;
2005-01-16 14:15:08 +03:00
/* no session setup at all in earliest protocol varients */
if ( session - > transport - > negotiate . protocol < PROTOCOL_LANMAN1 ) {
ZERO_STRUCT ( io - > out ) ;
2006-07-27 20:20:59 +04:00
composite_done ( c ) ;
2005-01-16 14:15:08 +03:00
return c ;
}
/* see what session setup interface we will use */
if ( session - > transport - > negotiate . protocol < PROTOCOL_NT1 ) {
2005-08-23 09:29:37 +04:00
status = session_setup_old ( c , session , io , & state - > req ) ;
2005-01-16 14:15:08 +03:00
} else if ( ! session - > transport - > options . use_spnego | |
! ( io - > in . capabilities & CAP_EXTENDED_SECURITY ) ) {
2005-08-23 09:29:37 +04:00
status = session_setup_nt1 ( c , session , io , & state - > req ) ;
2005-01-16 14:15:08 +03:00
} else {
2005-08-23 09:29:37 +04:00
status = session_setup_spnego ( c , session , io , & state - > req ) ;
2005-01-16 14:15:08 +03:00
}
2005-08-23 09:29:37 +04:00
if ( NT_STATUS_EQUAL ( status , NT_STATUS_MORE_PROCESSING_REQUIRED ) | |
NT_STATUS_IS_OK ( status ) ) {
2007-05-01 13:06:25 +04:00
composite_continue_smb ( c , state - > req , request_handler , c ) ;
2005-08-23 09:29:37 +04:00
return c ;
}
2005-01-16 14:15:08 +03:00
2007-05-01 13:06:25 +04:00
composite_error ( c , status ) ;
2005-01-16 14:15:08 +03:00
return c ;
}
/*
receive a composite session setup reply
*/
2005-01-31 11:30:44 +03:00
NTSTATUS smb_composite_sesssetup_recv ( struct composite_context * c )
2005-01-16 14:15:08 +03:00
{
NTSTATUS status ;
2005-01-31 11:30:44 +03:00
status = composite_wait ( c ) ;
2005-01-16 14:15:08 +03:00
talloc_free ( c ) ;
return status ;
}
/*
sync version of smb_composite_sesssetup
*/
NTSTATUS smb_composite_sesssetup ( struct smbcli_session * session , struct smb_composite_sesssetup * io )
{
2005-01-31 11:30:44 +03:00
struct composite_context * c = smb_composite_sesssetup_send ( session , io ) ;
2005-01-16 14:15:08 +03:00
return smb_composite_sesssetup_recv ( c ) ;
}