2010-07-19 13:36:33 -04:00
/*
NLTMSSP wrappers
Copyright ( C ) Andrew Tridgell 2001
2011-10-18 08:42:25 +11:00
Copyright ( C ) Andrew Bartlett 2001 - 2003 , 2011
2010-07-19 13:36:33 -04:00
This program is free software ; you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation ; either version 3 of the License , or
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
along with this program . If not , see < http : //www.gnu.org/licenses/>.
*/
# include "includes.h"
2011-07-25 16:04:38 +10:00
# include "auth/ntlmssp/ntlmssp.h"
2012-01-31 21:20:34 +11:00
# include "auth/ntlmssp/ntlmssp_private.h"
2011-12-27 10:25:55 +11:00
# include "auth_generic.h"
2011-07-27 13:34:34 +10:00
# include "auth/gensec/gensec.h"
2013-08-05 07:12:01 +02:00
# include "auth/gensec/gensec_internal.h"
2011-10-18 16:16:02 +11:00
# include "auth/credentials/credentials.h"
# include "librpc/rpc/dcerpc.h"
# include "lib/param/param.h"
2010-07-19 13:36:33 -04:00
2011-10-18 16:16:02 +11:00
static NTSTATUS gensec_ntlmssp3_client_update ( struct gensec_security * gensec_security ,
TALLOC_CTX * out_mem_ctx ,
struct tevent_context * ev ,
const DATA_BLOB request ,
DATA_BLOB * reply )
2010-07-19 13:36:33 -04:00
{
2011-07-26 17:20:35 +10:00
NTSTATUS status ;
2011-10-18 16:16:02 +11:00
struct gensec_ntlmssp_context * gensec_ntlmssp =
talloc_get_type_abort ( gensec_security - > private_data ,
struct gensec_ntlmssp_context ) ;
status = ntlmssp_update ( gensec_ntlmssp - > ntlmssp_state , request , reply ) ;
if ( NT_STATUS_IS_OK ( status ) | |
NT_STATUS_EQUAL ( status , NT_STATUS_MORE_PROCESSING_REQUIRED ) ) {
talloc_steal ( out_mem_ctx , reply - > data ) ;
2011-07-27 13:34:34 +10:00
}
2011-10-18 16:16:02 +11:00
2011-07-26 17:20:35 +10:00
return status ;
2010-07-19 13:36:33 -04:00
}
2011-10-18 16:16:02 +11:00
static NTSTATUS gensec_ntlmssp3_client_start ( struct gensec_security * gensec_security )
{
NTSTATUS nt_status ;
struct gensec_ntlmssp_context * gensec_ntlmssp ;
const char * user , * domain ;
const char * password ;
nt_status = gensec_ntlmssp_start ( gensec_security ) ;
NT_STATUS_NOT_OK_RETURN ( nt_status ) ;
gensec_ntlmssp =
talloc_get_type_abort ( gensec_security - > private_data ,
struct gensec_ntlmssp_context ) ;
nt_status = ntlmssp_client_start ( gensec_ntlmssp ,
lp_netbios_name ( ) , lp_workgroup ( ) ,
lp_client_ntlmv2_auth ( ) , & gensec_ntlmssp - > ntlmssp_state ) ;
if ( ! NT_STATUS_IS_OK ( nt_status ) ) {
return nt_status ;
}
cli_credentials_get_ntlm_username_domain ( gensec_security - > credentials , gensec_ntlmssp , & user , & domain ) ;
if ( ! user | | ! domain ) {
return NT_STATUS_NO_MEMORY ;
}
nt_status = ntlmssp_set_username ( gensec_ntlmssp - > ntlmssp_state , user ) ;
if ( ! NT_STATUS_IS_OK ( nt_status ) ) {
return nt_status ;
}
nt_status = ntlmssp_set_domain ( gensec_ntlmssp - > ntlmssp_state , domain ) ;
if ( ! NT_STATUS_IS_OK ( nt_status ) ) {
return nt_status ;
}
password = cli_credentials_get_password ( gensec_security - > credentials ) ;
if ( ! password ) {
return NT_STATUS_NO_MEMORY ;
}
nt_status = ntlmssp_set_password ( gensec_ntlmssp - > ntlmssp_state , password ) ;
if ( ! NT_STATUS_IS_OK ( nt_status ) ) {
return nt_status ;
}
2012-03-09 14:28:46 +11:00
if ( gensec_security - > want_features & GENSEC_FEATURE_SESSION_KEY ) {
2011-10-18 16:16:02 +11:00
gensec_ntlmssp - > ntlmssp_state - > neg_flags | = NTLMSSP_NEGOTIATE_SIGN ;
}
2012-03-09 14:28:46 +11:00
if ( gensec_security - > want_features & GENSEC_FEATURE_SIGN ) {
2011-10-18 16:16:02 +11:00
gensec_ntlmssp - > ntlmssp_state - > neg_flags | = NTLMSSP_NEGOTIATE_SIGN ;
}
2012-03-09 14:28:46 +11:00
if ( gensec_security - > want_features & GENSEC_FEATURE_SEAL ) {
2011-10-18 16:16:02 +11:00
gensec_ntlmssp - > ntlmssp_state - > neg_flags | = NTLMSSP_NEGOTIATE_SIGN ;
gensec_ntlmssp - > ntlmssp_state - > neg_flags | = NTLMSSP_NEGOTIATE_SEAL ;
}
return NT_STATUS_OK ;
}
static const char * gensec_ntlmssp3_client_oids [ ] = {
GENSEC_OID_NTLMSSP ,
NULL
} ;
2012-01-05 17:15:14 +01:00
const struct gensec_security_ops gensec_ntlmssp3_client_ops = {
2011-10-18 16:16:02 +11:00
. name = " ntlmssp3_client " ,
. sasl_name = GENSEC_SASL_NAME_NTLMSSP , /* "NTLM" */
. auth_type = DCERPC_AUTH_TYPE_NTLMSSP ,
. oid = gensec_ntlmssp3_client_oids ,
. client_start = gensec_ntlmssp3_client_start ,
. magic = gensec_ntlmssp_magic ,
. update = gensec_ntlmssp3_client_update ,
. sig_size = gensec_ntlmssp_sig_size ,
. sign_packet = gensec_ntlmssp_sign_packet ,
. check_packet = gensec_ntlmssp_check_packet ,
. seal_packet = gensec_ntlmssp_seal_packet ,
. unseal_packet = gensec_ntlmssp_unseal_packet ,
. wrap = gensec_ntlmssp_wrap ,
. unwrap = gensec_ntlmssp_unwrap ,
. session_key = gensec_ntlmssp_session_key ,
. have_feature = gensec_ntlmssp_have_feature ,
. enabled = true ,
. priority = GENSEC_NTLMSSP
} ;