2005-03-23 03:15:41 +03:00
/*
Unix SMB / CIFS implementation .
Authenticate a user to a domain controller
Copyright ( C ) Andrew Bartlett < abartlet @ samba . org > 2004 - 2005
Copyright ( C ) Andrew Tridgell 2004
This program is free software ; you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation ; either version 2 of the License , or
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
along with this program ; if not , write to the Free Software
Foundation , Inc . , 675 Mass Ave , Cambridge , MA 0213 9 , USA .
*/
# include "includes.h"
# include "librpc/gen_ndr/ndr_netlogon.h"
# include "include/secrets.h"
# include "lib/ldb/include/ldb.h"
# include "auth/auth.h"
/* Authenticate a user with a challenge/response */
static NTSTATUS domain_check_password ( struct auth_method_context * ctx ,
TALLOC_CTX * mem_ctx ,
const struct auth_usersupplied_info * user_info ,
struct auth_serversupplied_info * * server_info )
{
NTSTATUS status ;
struct dcerpc_pipe * p ;
struct dcerpc_binding * b ;
struct netr_LogonSamLogon r ;
struct netr_Authenticator auth , auth2 ;
struct netr_NetworkInfo ninfo ;
struct creds_CredentialState * creds ;
struct cli_credentials * credentials ;
const char * * bindings = lp_passwordserver ( ) ;
const char * binding ;
if ( bindings & & bindings [ 0 ] ) {
binding = bindings [ 0 ] ;
2005-06-03 15:18:48 +04:00
} else {
return NT_STATUS_INVALID_PARAMETER ;
2005-03-23 03:15:41 +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
if ( ! user_info - > account_name ) {
return NT_STATUS_INVALID_PARAMETER ;
}
if ( ! user_info - > workstation_name ) {
return NT_STATUS_INVALID_PARAMETER ;
}
2005-03-23 03:15:41 +03:00
credentials = cli_credentials_init ( mem_ctx ) ;
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
cli_credentials_set_conf ( credentials ) ;
2005-03-23 04:30:43 +03:00
status = cli_credentials_set_machine_account ( credentials ) ;
2005-03-23 03:15:41 +03:00
2005-03-23 04:30:43 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
return status ;
2005-03-23 03:15:41 +03:00
}
/* Connect to DC (take a binding string for now) */
status = dcerpc_parse_binding ( mem_ctx , binding , & b ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " Bad binding string %s \n " , binding ) ;
return NT_STATUS_INVALID_PARAMETER ;
}
/* We like schannel */
b - > flags & = ~ DCERPC_AUTH_OPTIONS ;
2005-05-01 23:29:00 +04:00
b - > flags | = DCERPC_SCHANNEL | DCERPC_SEAL | DCERPC_SCHANNEL_128 ;
2005-03-23 03:15:41 +03:00
/* Setup schannel */
status = dcerpc_pipe_connect_b ( mem_ctx , & p , b ,
DCERPC_NETLOGON_UUID ,
DCERPC_NETLOGON_VERSION ,
credentials ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return status ;
}
/* call domain logon */
status = dcerpc_schannel_creds ( p - > conn - > security_state . generic_state , mem_ctx , & creds ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return status ;
}
ninfo . identity_info . domain_name . string = user_info - > domain_name ;
ninfo . identity_info . parameter_control = 0 ;
ninfo . identity_info . logon_id_low = 0 ;
ninfo . identity_info . logon_id_high = 0 ;
ninfo . identity_info . account_name . string = user_info - > account_name ;
ninfo . identity_info . workstation . string = user_info - > workstation_name ;
memcpy ( ninfo . challenge , ctx - > auth_ctx - > challenge . data . data , sizeof ( ninfo . challenge ) ) ;
ninfo . nt . length = user_info - > nt_resp . length ;
ninfo . nt . data = user_info - > nt_resp . data ;
ninfo . lm . length = user_info - > lm_resp . length ;
ninfo . lm . data = user_info - > lm_resp . data ;
r . in . server_name = talloc_asprintf ( mem_ctx , " \\ \\ %s " , dcerpc_server_name ( p ) ) ;
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
r . in . workstation = cli_credentials_get_workstation ( credentials ) ;
2005-03-23 03:15:41 +03:00
r . in . credential = & auth ;
r . in . return_authenticator = & auth2 ;
r . in . logon_level = 2 ;
r . in . logon . network = & ninfo ;
r . in . validation_level = 3 ;
ZERO_STRUCT ( auth2 ) ;
creds_client_authenticator ( creds , & auth ) ;
status = dcerpc_netr_LogonSamLogon ( p , mem_ctx , & r ) ;
if ( ! creds_client_check ( creds , & r . out . return_authenticator - > cred ) ) {
DEBUG ( 1 , ( " Credential chaining failed \n " ) ) ;
return NT_STATUS_ACCESS_DENIED ;
}
/* make server info */
if ( ! NT_STATUS_IS_OK ( status ) ) {
return status ;
}
status = make_server_info_netlogon_validation ( mem_ctx ,
user_info - > account_name ,
r . in . validation_level , & r . out . validation ,
server_info ) ;
return status ;
}
static const struct auth_operations domain_ops = {
. name = " domain " ,
. get_challenge = auth_get_challenge_not_implemented ,
. check_password = domain_check_password
} ;
NTSTATUS auth_domain_init ( void )
{
NTSTATUS ret ;
ret = auth_register ( & domain_ops ) ;
if ( ! NT_STATUS_IS_OK ( ret ) ) {
DEBUG ( 0 , ( " Failed to register 'domain' auth backend! \n " ) ) ;
return ret ;
}
return ret ;
}