2003-06-30 21:24:59 +04:00
/*
2002-01-30 09:08:46 +03:00
Unix SMB / CIFS implementation .
2000-05-09 15:43:00 +04:00
2001-11-23 03:14:04 +03:00
Winbind daemon - pam auth funcions
2000-05-09 15:43:00 +04:00
Copyright ( C ) Andrew Tridgell 2000
2001-08-23 06:55:42 +04:00
Copyright ( C ) Tim Potter 2001
2002-02-05 12:40:36 +03:00
Copyright ( C ) Andrew Bartlett 2001 - 2002
2000-05-09 15:43:00 +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 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 .
*/
2003-11-12 04:51:10 +03:00
# include "includes.h"
2000-05-09 15:43:00 +04:00
# include "winbindd.h"
2002-07-15 14:35:28 +04:00
# undef DBGC_CLASS
# define DBGC_CLASS DBGC_WINBIND
2002-08-17 21:00:51 +04:00
static NTSTATUS append_info3_as_ndr ( TALLOC_CTX * mem_ctx ,
struct winbindd_cli_state * state ,
NET_USER_INFO_3 * info3 )
{
prs_struct ps ;
uint32 size ;
if ( ! prs_init ( & ps , 256 /* Random, non-zero number */ , mem_ctx , MARSHALL ) ) {
return NT_STATUS_NO_MEMORY ;
}
if ( ! net_io_user_info3 ( " " , info3 , & ps , 1 , 3 ) ) {
prs_mem_free ( & ps ) ;
return NT_STATUS_UNSUCCESSFUL ;
}
size = prs_data_size ( & ps ) ;
2003-02-15 01:55:46 +03:00
state - > response . extra_data = malloc ( size ) ;
2002-08-17 21:00:51 +04:00
if ( ! state - > response . extra_data ) {
prs_mem_free ( & ps ) ;
return NT_STATUS_NO_MEMORY ;
}
2003-02-15 01:55:46 +03:00
prs_copy_all_data_out ( state - > response . extra_data , & ps ) ;
2002-08-17 21:00:51 +04:00
state - > response . length + = size ;
prs_mem_free ( & ps ) ;
return NT_STATUS_OK ;
}
2003-06-30 21:24:59 +04:00
/**********************************************************************
Authenticate a user with a clear test password
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2000-05-09 15:43:00 +04:00
enum winbindd_result winbindd_pam_auth ( struct winbindd_cli_state * state )
{
2001-09-04 11:13:01 +04:00
NTSTATUS result ;
2001-11-05 03:21:17 +03:00
fstring name_domain , name_user ;
2001-08-12 15:19:57 +04:00
unsigned char trust_passwd [ 16 ] ;
time_t last_change_time ;
2003-04-21 18:09:03 +04:00
uint32 sec_channel_type ;
2001-11-05 03:21:17 +03:00
NET_USER_INFO_3 info3 ;
2003-09-24 05:22:59 +04:00
struct cli_state * cli = NULL ;
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
uchar chal [ 8 ] ;
2002-02-05 12:40:36 +03:00
TALLOC_CTX * mem_ctx = NULL ;
2002-01-01 07:50:45 +03:00
DATA_BLOB lm_resp ;
DATA_BLOB nt_resp ;
2003-05-08 12:02:52 +04:00
DOM_CRED ret_creds ;
int attempts = 0 ;
2003-06-30 21:24:59 +04:00
unsigned char local_lm_response [ 24 ] ;
unsigned char local_nt_response [ 24 ] ;
2004-01-05 07:10:28 +03:00
struct winbindd_domain * contact_domain ;
2003-09-08 17:53:19 +04:00
BOOL retry ;
2002-01-01 07:50:45 +03:00
2002-08-17 21:00:51 +04:00
/* Ensure null termination */
state - > request . data . auth . user [ sizeof ( state - > request . data . auth . user ) - 1 ] = ' \0 ' ;
/* Ensure null termination */
state - > request . data . auth . pass [ sizeof ( state - > request . data . auth . pass ) - 1 ] = ' \0 ' ;
2003-07-22 08:31:20 +04:00
DEBUG ( 3 , ( " [%5lu]: pam auth %s \n " , ( unsigned long ) state - > pid ,
2001-05-07 08:32:40 +04:00
state - > request . data . auth . user ) ) ;
2000-05-09 15:43:00 +04:00
2002-12-20 23:21:31 +03:00
if ( ! ( mem_ctx = talloc_init ( " winbind pam auth for %s " , state - > request . data . auth . user ) ) ) {
2002-01-01 07:50:45 +03:00
DEBUG ( 0 , ( " winbindd_pam_auth: could not talloc_init()! \n " ) ) ;
2002-02-05 12:40:36 +03:00
result = NT_STATUS_NO_MEMORY ;
goto done ;
2002-01-01 07:50:45 +03:00
}
2000-05-09 15:43:00 +04:00
/* Parse domain and username */
2002-01-10 13:23:54 +03:00
2003-07-09 20:44:47 +04:00
parse_domain_user ( state - > request . data . auth . user , name_domain , name_user ) ;
2000-05-09 15:43:00 +04:00
2003-06-30 21:24:59 +04:00
/* do password magic */
generate_random_buffer ( chal , 8 , False ) ;
SMBencrypt ( state - > request . data . auth . pass , chal , local_lm_response ) ;
2002-01-01 07:50:45 +03:00
2003-06-30 21:24:59 +04:00
SMBNTencrypt ( state - > request . data . auth . pass , chal , local_nt_response ) ;
2002-01-01 07:50:45 +03:00
2003-06-30 21:24:59 +04:00
lm_resp = data_blob_talloc ( mem_ctx , local_lm_response , sizeof ( local_lm_response ) ) ;
nt_resp = data_blob_talloc ( mem_ctx , local_nt_response , sizeof ( local_nt_response ) ) ;
This is my 'Authentication Rewrite' version 1.01, mostly as submitted to
samba-technical a few weeks ago.
The idea here is to standardize the checking of user names and passwords,
thereby ensuring that all authtentications pass the same standards. The
interface currently implemented in as
nt_status = check_password(user_info, server_info)
where user_info contains (mostly) the authentication data, and server_info
contains things like the user-id they got, and their resolved user name.
The current ugliness with the way the structures are created will be killed
the next revision, when they will be created and malloced by creator functions.
This patch also includes the first implementation of NTLMv2 in HEAD, but which
needs some more testing. We also add a hack to allow plaintext passwords to be
compared with smbpasswd, not the system password database.
Finally, this patch probably reintroduces the PAM accounts bug we had in
2.2.0, I'll fix that once this hits the tree. (I've just finished testing
it on a wide variety of platforms, so I want to get this patch in).
(This used to be commit b30b6202f31d339b48d51c0d38174cafd1cfcd42)
2001-08-03 17:09:23 +04:00
2003-07-07 09:11:10 +04:00
/* what domain should we contact? */
2003-12-31 11:45:03 +03:00
if ( IS_DC ) {
2004-01-05 07:10:28 +03:00
if ( ! ( contact_domain = find_domain_from_name ( name_domain ) ) ) {
DEBUG ( 3 , ( " Authentication for domain for [%s] -> [%s] \\ [%s] failed as %s is not a trusted domain \n " ,
2003-12-31 11:45:03 +03:00
state - > request . data . auth . user , name_domain , name_user , name_domain ) ) ;
result = NT_STATUS_NO_SUCH_USER ;
goto done ;
}
2003-07-07 09:11:10 +04:00
2003-12-31 11:45:03 +03:00
} else {
if ( is_myname ( name_domain ) ) {
DEBUG ( 3 , ( " Authentication for domain %s (local domain to this server) not supported at this stage \n " , name_domain ) ) ;
result = NT_STATUS_NO_SUCH_USER ;
goto done ;
}
2004-01-05 07:10:28 +03:00
if ( ! ( contact_domain = find_our_domain ( ) ) ) {
DEBUG ( 1 , ( " Authenticatoin for [%s] -> [%s] \\ [%s] in our domain failed - we can't find our domain! \n " ,
state - > request . data . auth . user , name_domain , name_user ) ) ;
result = NT_STATUS_NO_SUCH_USER ;
goto done ;
}
}
if ( ! get_trust_pw ( contact_domain - > name , trust_passwd , & last_change_time , & sec_channel_type ) ) {
result = NT_STATUS_CANT_ACCESS_DOMAIN_INFO ;
goto done ;
2003-12-31 11:45:03 +03:00
}
2004-01-05 07:10:28 +03:00
2003-06-30 21:24:59 +04:00
/* check authentication loop */
2003-05-08 12:02:52 +04:00
do {
ZERO_STRUCT ( info3 ) ;
ZERO_STRUCT ( ret_creds ) ;
2003-09-08 17:53:19 +04:00
retry = False ;
2002-02-11 04:29:07 +03:00
2003-05-08 12:02:52 +04:00
/* Don't shut this down - it belongs to the connection cache code */
2003-07-07 09:11:10 +04:00
result = cm_get_netlogon_cli ( contact_domain , trust_passwd ,
2003-05-08 12:02:52 +04:00
sec_channel_type , False , & cli ) ;
if ( ! NT_STATUS_IS_OK ( result ) ) {
DEBUG ( 3 , ( " could not open handle to NETLOGON pipe \n " ) ) ;
goto done ;
}
result = cli_netlogon_sam_network_logon ( cli , mem_ctx ,
& ret_creds ,
name_user , name_domain ,
global_myname ( ) , chal ,
lm_resp , nt_resp ,
& info3 ) ;
attempts + = 1 ;
2003-07-03 20:23:11 +04:00
2003-09-24 05:22:59 +04:00
/* We have to try a second time as cm_get_netlogon_cli
might not yet have noticed that the DC has killed
our connection . */
if ( cli - > fd = = - 1 ) {
retry = True ;
continue ;
}
2003-07-03 20:23:11 +04:00
/* if we get access denied, a possible cuase was that we had and open
2003-09-24 05:22:59 +04:00
connection to the DC , but someone changed our machine account password
2003-07-03 20:23:11 +04:00
out from underneath us using ' net rpc changetrustpw ' */
if ( NT_STATUS_V ( result ) = = NT_STATUS_V ( NT_STATUS_ACCESS_DENIED ) ) {
DEBUG ( 3 , ( " winbindd_pam_auth: sam_logon returned ACCESS_DENIED. Maybe the trust account "
" password was changed and we didn't know it. Killing connections to domain %s \n " ,
name_domain ) ) ;
winbindd_cm_flush ( ) ;
2003-09-08 17:53:19 +04:00
retry = True ;
2003-09-24 05:22:59 +04:00
cli = NULL ;
2003-07-03 20:23:11 +04:00
}
2003-09-08 17:53:19 +04:00
} while ( ( attempts < 2 ) & & retry ) ;
2003-05-08 12:02:52 +04:00
clnt_deal_with_creds ( cli - > sess_key , & ( cli - > clnt_cred ) , & ret_creds ) ;
2003-07-03 20:23:11 +04:00
if ( NT_STATUS_IS_OK ( result ) ) {
netsamlogon_cache_store ( cli - > mem_ctx , & info3 ) ;
wcache_invalidate_samlogon ( find_domain_from_name ( name_domain ) , & info3 ) ;
}
2003-09-08 17:53:19 +04:00
2002-01-01 07:50:45 +03:00
done :
2003-04-07 11:32:51 +04:00
/* give us a more useful (more correct?) error code */
if ( ( NT_STATUS_EQUAL ( result , NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND ) | | ( NT_STATUS_EQUAL ( result , NT_STATUS_UNSUCCESSFUL ) ) ) ) {
result = NT_STATUS_NO_LOGON_SERVERS ;
}
2002-02-05 12:40:36 +03:00
state - > response . data . auth . nt_status = NT_STATUS_V ( result ) ;
2002-03-17 07:36:35 +03:00
fstrcpy ( state - > response . data . auth . nt_status_string , nt_errstr ( result ) ) ;
2004-01-05 07:10:28 +03:00
/* we might have given a more useful error above */
if ( ! * state - > response . data . auth . error_string )
fstrcpy ( state - > response . data . auth . error_string , get_friendly_nt_error_msg ( result ) ) ;
2002-02-05 12:40:36 +03:00
state - > response . data . auth . pam_error = nt_status_to_pam ( result ) ;
2002-09-25 19:19:00 +04:00
DEBUG ( NT_STATUS_IS_OK ( result ) ? 5 : 2 , ( " Plain-text authentication for user %s returned %s (PAM: %d) \n " ,
2002-02-05 12:40:36 +03:00
state - > request . data . auth . user ,
state - > response . data . auth . nt_status_string ,
state - > response . data . auth . pam_error ) ) ;
2002-02-08 09:43:55 +03:00
if ( mem_ctx )
talloc_destroy ( mem_ctx ) ;
2001-09-04 11:13:01 +04:00
return NT_STATUS_IS_OK ( result ) ? WINBINDD_OK : WINBINDD_ERROR ;
2001-08-22 06:48:16 +04:00
}
2003-06-30 21:24:59 +04:00
/**********************************************************************
Challenge Response Authentication Protocol
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2001-08-22 06:48:16 +04:00
enum winbindd_result winbindd_pam_auth_crap ( struct winbindd_cli_state * state )
{
2001-09-04 11:13:01 +04:00
NTSTATUS result ;
2001-08-22 06:48:16 +04:00
unsigned char trust_passwd [ 16 ] ;
time_t last_change_time ;
2003-04-21 18:09:03 +04:00
uint32 sec_channel_type ;
2001-11-05 03:21:17 +03:00
NET_USER_INFO_3 info3 ;
2003-09-24 05:22:59 +04:00
struct cli_state * cli = NULL ;
2002-02-05 12:40:36 +03:00
TALLOC_CTX * mem_ctx = NULL ;
2004-01-05 07:10:28 +03:00
char * name_user = NULL ;
const char * name_domain = NULL ;
2002-11-13 02:20:50 +03:00
const char * workstation ;
2004-01-05 07:10:28 +03:00
struct winbindd_domain * contact_domain ;
2003-05-08 12:02:52 +04:00
DOM_CRED ret_creds ;
int attempts = 0 ;
2003-09-08 17:53:19 +04:00
BOOL retry ;
2002-01-01 07:50:45 +03:00
DATA_BLOB lm_resp , nt_resp ;
2003-04-07 11:32:51 +04:00
if ( ! state - > privileged ) {
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
char * error_string = NULL ;
DEBUG ( 2 , ( " winbindd_pam_auth_crap: non-privileged access denied. ! \n " ) ) ;
DEBUGADD ( 2 , ( " winbindd_pam_auth_crap: Ensure permissions on %s are set correctly. \n " ,
get_winbind_priv_pipe_dir ( ) ) ) ;
2003-04-07 11:32:51 +04:00
/* send a better message than ACCESS_DENIED */
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
asprintf ( & error_string , " winbind client not authorized to use winbindd_pam_auth_crap. Ensure permissions on %s are set correctly. " ,
get_winbind_priv_pipe_dir ( ) ) ;
push_utf8_fstring ( state - > response . data . auth . error_string , error_string ) ;
SAFE_FREE ( error_string ) ;
2003-03-24 12:54:13 +03:00
result = NT_STATUS_ACCESS_DENIED ;
goto done ;
}
2002-08-17 21:00:51 +04:00
/* Ensure null termination */
2003-08-12 04:46:15 +04:00
state - > request . data . auth_crap . user [ sizeof ( state - > request . data . auth_crap . user ) - 1 ] = 0 ;
state - > request . data . auth_crap . domain [ sizeof ( state - > request . data . auth_crap . domain ) - 1 ] = 0 ;
2001-08-22 06:48:16 +04:00
2002-12-20 23:21:31 +03:00
if ( ! ( mem_ctx = talloc_init ( " winbind pam auth crap for (utf8) %s " , state - > request . data . auth_crap . user ) ) ) {
2002-01-01 07:50:45 +03:00
DEBUG ( 0 , ( " winbindd_pam_auth_crap: could not talloc_init()! \n " ) ) ;
2002-02-05 12:40:36 +03:00
result = NT_STATUS_NO_MEMORY ;
goto done ;
2002-01-01 07:50:45 +03:00
}
2001-08-22 06:48:16 +04:00
2004-01-05 07:10:28 +03:00
if ( pull_utf8_talloc ( mem_ctx , & name_user , state - > request . data . auth_crap . user ) = = ( size_t ) - 1 ) {
2002-08-17 21:00:51 +04:00
DEBUG ( 0 , ( " winbindd_pam_auth_crap: pull_utf8_talloc failed! \n " ) ) ;
2003-08-12 04:46:15 +04:00
result = NT_STATUS_UNSUCCESSFUL ;
goto done ;
2002-08-17 21:00:51 +04:00
}
2002-01-18 05:37:55 +03:00
if ( * state - > request . data . auth_crap . domain ) {
2002-11-13 02:20:50 +03:00
char * dom = NULL ;
2003-01-02 23:25:59 +03:00
if ( pull_utf8_talloc ( mem_ctx , & dom , state - > request . data . auth_crap . domain ) = = ( size_t ) - 1 ) {
2002-08-17 21:00:51 +04:00
DEBUG ( 0 , ( " winbindd_pam_auth_crap: pull_utf8_talloc failed! \n " ) ) ;
2003-08-12 04:46:15 +04:00
result = NT_STATUS_UNSUCCESSFUL ;
goto done ;
2002-08-17 21:00:51 +04:00
}
2004-01-05 07:10:28 +03:00
name_domain = dom ;
2002-01-18 05:37:55 +03:00
} else if ( lp_winbind_use_default_domain ( ) ) {
2004-01-05 07:10:28 +03:00
name_domain = lp_workgroup ( ) ;
2002-01-18 05:37:55 +03:00
} else {
2002-08-17 21:00:51 +04:00
DEBUG ( 5 , ( " no domain specified with username (%s) - failing auth \n " ,
2004-01-05 07:10:28 +03:00
name_user ) ) ;
result = NT_STATUS_NO_SUCH_USER ;
2002-02-05 12:40:36 +03:00
goto done ;
2002-01-18 05:37:55 +03:00
}
2003-07-22 08:31:20 +04:00
DEBUG ( 3 , ( " [%5lu]: pam auth crap domain: %s user: %s \n " , ( unsigned long ) state - > pid ,
2004-01-05 07:10:28 +03:00
name_domain , name_user ) ) ;
2003-06-30 21:24:59 +04:00
2002-08-17 21:00:51 +04:00
if ( * state - > request . data . auth_crap . workstation ) {
2002-11-13 02:20:50 +03:00
char * wrk = NULL ;
2003-01-02 22:25:28 +03:00
if ( pull_utf8_talloc ( mem_ctx , & wrk , state - > request . data . auth_crap . workstation ) = = ( size_t ) - 1 ) {
2002-08-17 21:00:51 +04:00
DEBUG ( 0 , ( " winbindd_pam_auth_crap: pull_utf8_talloc failed! \n " ) ) ;
2003-08-12 04:46:15 +04:00
result = NT_STATUS_UNSUCCESSFUL ;
goto done ;
2002-08-17 21:00:51 +04:00
}
2002-11-13 02:20:50 +03:00
workstation = wrk ;
2002-08-17 21:00:51 +04:00
} else {
2002-11-13 02:20:50 +03:00
workstation = global_myname ( ) ;
2002-08-17 21:00:51 +04:00
}
if ( state - > request . data . auth_crap . lm_resp_len > sizeof ( state - > request . data . auth_crap . lm_resp )
| | state - > request . data . auth_crap . nt_resp_len > sizeof ( state - > request . data . auth_crap . nt_resp ) ) {
DEBUG ( 0 , ( " winbindd_pam_auth_crap: invalid password length %u/%u \n " ,
state - > request . data . auth_crap . lm_resp_len ,
state - > request . data . auth_crap . nt_resp_len ) ) ;
result = NT_STATUS_INVALID_PARAMETER ;
2002-02-05 12:40:36 +03:00
goto done ;
2002-01-18 05:37:55 +03:00
}
2002-01-10 13:23:54 +03:00
lm_resp = data_blob_talloc ( mem_ctx , state - > request . data . auth_crap . lm_resp , state - > request . data . auth_crap . lm_resp_len ) ;
nt_resp = data_blob_talloc ( mem_ctx , state - > request . data . auth_crap . nt_resp , state - > request . data . auth_crap . nt_resp_len ) ;
2001-08-22 06:48:16 +04:00
2004-01-05 07:10:28 +03:00
2003-07-07 09:11:10 +04:00
/* what domain should we contact? */
2003-12-31 11:45:03 +03:00
if ( IS_DC ) {
2004-01-05 07:10:28 +03:00
if ( ! ( contact_domain = find_domain_from_name ( name_domain ) ) ) {
DEBUG ( 3 , ( " Authentication for domain for [%s] -> [%s] \\ [%s] failed as %s is not a trusted domain \n " ,
state - > request . data . auth . user , name_domain , name_user , name_domain ) ) ;
2003-12-31 11:45:03 +03:00
result = NT_STATUS_NO_SUCH_USER ;
goto done ;
}
2004-01-05 07:10:28 +03:00
2003-12-31 11:45:03 +03:00
} else {
2004-01-05 07:10:28 +03:00
if ( is_myname ( name_domain ) ) {
DEBUG ( 3 , ( " Authentication for domain %s (local domain to this server) not supported at this stage \n " , name_domain ) ) ;
2003-12-31 11:45:03 +03:00
result = NT_STATUS_NO_SUCH_USER ;
goto done ;
}
2004-01-05 07:10:28 +03:00
if ( ! ( contact_domain = find_our_domain ( ) ) ) {
DEBUG ( 1 , ( " Authenticatoin for [%s] -> [%s] \\ [%s] in our domain failed - we can't find our domain! \n " ,
state - > request . data . auth . user , name_domain , name_user ) ) ;
result = NT_STATUS_NO_SUCH_USER ;
goto done ;
}
2003-12-31 11:45:03 +03:00
}
2004-01-05 07:10:28 +03:00
if ( ! get_trust_pw ( contact_domain - > name , trust_passwd , & last_change_time , & sec_channel_type ) ) {
result = NT_STATUS_CANT_ACCESS_DOMAIN_INFO ;
goto done ;
}
2003-05-08 12:02:52 +04:00
do {
ZERO_STRUCT ( info3 ) ;
ZERO_STRUCT ( ret_creds ) ;
2003-09-08 17:53:19 +04:00
retry = False ;
2003-09-06 23:49:59 +04:00
2003-05-08 12:02:52 +04:00
/* Don't shut this down - it belongs to the connection cache code */
2003-07-07 09:11:10 +04:00
result = cm_get_netlogon_cli ( contact_domain , trust_passwd , sec_channel_type , False , & cli ) ;
2003-05-08 12:02:52 +04:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
DEBUG ( 3 , ( " could not open handle to NETLOGON pipe (error: %s) \n " ,
nt_errstr ( result ) ) ) ;
goto done ;
}
result = cli_netlogon_sam_network_logon ( cli , mem_ctx ,
& ret_creds ,
2004-01-05 07:10:28 +03:00
name_user , name_domain ,
2003-05-08 12:02:52 +04:00
workstation ,
state - > request . data . auth_crap . chal ,
lm_resp , nt_resp ,
& info3 ) ;
attempts + = 1 ;
2001-11-05 03:21:17 +03:00
2003-09-24 05:22:59 +04:00
/* We have to try a second time as cm_get_netlogon_cli
might not yet have noticed that the DC has killed
our connection . */
if ( cli - > fd = = - 1 ) {
retry = True ;
continue ;
}
/* if we get access denied, a possible cause was that we had and open
connection to the DC , but someone changed our machine account password
2003-07-03 20:23:11 +04:00
out from underneath us using ' net rpc changetrustpw ' */
if ( NT_STATUS_V ( result ) = = NT_STATUS_V ( NT_STATUS_ACCESS_DENIED ) ) {
DEBUG ( 3 , ( " winbindd_pam_auth_crap: sam_logon returned ACCESS_DENIED. Maybe the trust account "
" password was changed and we didn't know it. Killing connections to domain %s \n " ,
2004-01-05 07:10:28 +03:00
contact_domain - > name ) ) ;
2003-07-03 20:23:11 +04:00
winbindd_cm_flush ( ) ;
2003-09-08 17:53:19 +04:00
retry = True ;
2003-09-24 05:22:59 +04:00
cli = NULL ;
2003-07-03 20:23:11 +04:00
}
2003-09-08 17:53:19 +04:00
} while ( ( attempts < 2 ) & & retry ) ;
2001-10-05 04:20:06 +04:00
2003-05-08 12:02:52 +04:00
clnt_deal_with_creds ( cli - > sess_key , & ( cli - > clnt_cred ) , & ret_creds ) ;
2002-01-01 07:50:45 +03:00
2002-02-05 12:40:36 +03:00
if ( NT_STATUS_IS_OK ( result ) ) {
2003-06-21 08:05:01 +04:00
netsamlogon_cache_store ( cli - > mem_ctx , & info3 ) ;
2004-01-05 07:10:28 +03:00
wcache_invalidate_samlogon ( find_domain_from_name ( name_domain ) , & info3 ) ;
2003-06-21 08:05:01 +04:00
2003-07-07 09:11:10 +04:00
if ( state - > request . flags & WBFLAG_PAM_INFO3_NDR ) {
2002-08-17 21:00:51 +04:00
result = append_info3_as_ndr ( mem_ctx , state , & info3 ) ;
2003-12-30 16:20:39 +03:00
} else if ( state - > request . flags & WBFLAG_PAM_UNIX_NAME ) {
/* ntlm_auth should return the unix username, per
' winbind use default domain ' settings and the like */
fstring username_out ;
const char * nt_username , * nt_domain ;
if ( ! ( nt_username = unistr2_tdup ( mem_ctx , & ( info3 . uni_user_name ) ) ) ) {
/* If the server didn't give us one, just use the one we sent them */
2004-01-05 07:10:28 +03:00
nt_username = name_user ;
2003-12-30 16:20:39 +03:00
}
if ( ! ( nt_domain = unistr2_tdup ( mem_ctx , & ( info3 . uni_logon_dom ) ) ) ) {
/* If the server didn't give us one, just use the one we sent them */
2004-01-05 07:10:28 +03:00
nt_domain = name_domain ;
2003-12-30 16:20:39 +03:00
}
2003-12-31 01:27:33 +03:00
fill_domain_username ( username_out , nt_domain , nt_username ) ;
2003-12-30 16:20:39 +03:00
DEBUG ( 5 , ( " Setting unix username to [%s] \n " , username_out ) ) ;
2003-12-31 01:27:33 +03:00
/* this interface is in UTF8 */
if ( push_utf8_allocate ( ( char * * ) & state - > response . extra_data , username_out ) = = - 1 ) {
2003-12-30 16:20:39 +03:00
result = NT_STATUS_NO_MEMORY ;
goto done ;
}
state - > response . length + = strlen ( state - > response . extra_data ) + 1 ;
2002-08-17 21:00:51 +04:00
}
2003-06-21 08:05:01 +04:00
2003-07-07 09:11:10 +04:00
if ( state - > request . flags & WBFLAG_PAM_NTKEY ) {
2002-08-17 21:00:51 +04:00
memcpy ( state - > response . data . auth . nt_session_key , info3 . user_sess_key , sizeof ( state - > response . data . auth . nt_session_key ) /* 16 */ ) ;
}
2003-07-07 09:11:10 +04:00
if ( state - > request . flags & WBFLAG_PAM_LMKEY ) {
2003-04-07 11:32:51 +04:00
memcpy ( state - > response . data . auth . first_8_lm_hash , info3 . padding , sizeof ( state - > response . data . auth . first_8_lm_hash ) /* 8 */ ) ;
2002-08-17 21:00:51 +04:00
}
2002-02-05 12:40:36 +03:00
}
2002-01-01 07:50:45 +03:00
done :
2003-04-07 11:32:51 +04:00
/* give us a more useful (more correct?) error code */
if ( ( NT_STATUS_EQUAL ( result , NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND ) | | ( NT_STATUS_EQUAL ( result , NT_STATUS_UNSUCCESSFUL ) ) ) ) {
result = NT_STATUS_NO_LOGON_SERVERS ;
}
2002-02-05 12:40:36 +03:00
state - > response . data . auth . nt_status = NT_STATUS_V ( result ) ;
2002-08-17 21:00:51 +04:00
push_utf8_fstring ( state - > response . data . auth . nt_status_string , nt_errstr ( result ) ) ;
2003-11-26 02:24:14 +03:00
/* we might have given a more useful error above */
2003-04-07 11:32:51 +04:00
if ( ! * state - > response . data . auth . error_string )
push_utf8_fstring ( state - > response . data . auth . error_string , get_friendly_nt_error_msg ( result ) ) ;
2002-02-05 12:40:36 +03:00
state - > response . data . auth . pam_error = nt_status_to_pam ( result ) ;
2002-08-17 21:00:51 +04:00
DEBUG ( NT_STATUS_IS_OK ( result ) ? 5 : 2 ,
2002-09-25 19:19:00 +04:00
( " NTLM CRAP authentication for user [%s] \\ [%s] returned %s (PAM: %d) \n " ,
2004-01-05 07:10:28 +03:00
name_domain ,
name_user ,
2002-08-17 21:00:51 +04:00
state - > response . data . auth . nt_status_string ,
state - > response . data . auth . pam_error ) ) ;
2002-02-05 12:40:36 +03:00
2002-02-08 09:43:55 +03:00
if ( mem_ctx )
talloc_destroy ( mem_ctx ) ;
2001-09-04 11:13:01 +04:00
return NT_STATUS_IS_OK ( result ) ? WINBINDD_OK : WINBINDD_ERROR ;
2000-05-09 15:43:00 +04:00
}
2001-05-07 08:32:40 +04:00
/* Change a user password */
enum winbindd_result winbindd_pam_chauthtok ( struct winbindd_cli_state * state )
{
2002-02-05 12:40:36 +03:00
NTSTATUS result ;
2001-12-05 07:17:39 +03:00
char * oldpass , * newpass ;
fstring domain , user ;
2002-01-30 06:23:40 +03:00
CLI_POLICY_HND * hnd ;
2004-01-05 07:10:28 +03:00
TALLOC_CTX * mem_ctx ;
struct winbindd_domain * contact_domain ;
2001-05-07 08:32:40 +04:00
2003-07-22 08:31:20 +04:00
DEBUG ( 3 , ( " [%5lu]: pam chauthtok %s \n " , ( unsigned long ) state - > pid ,
2001-12-05 07:17:39 +03:00
state - > request . data . chauthtok . user ) ) ;
2001-05-07 08:32:40 +04:00
2004-01-05 07:10:28 +03:00
if ( ! ( mem_ctx = talloc_init ( " winbind password change for (utf8) %s " ,
state - > request . data . chauthtok . user ) ) ) {
DEBUG ( 0 , ( " winbindd_pam_auth_crap: could not talloc_init()! \n " ) ) ;
result = NT_STATUS_NO_MEMORY ;
goto done ;
}
2001-12-05 07:17:39 +03:00
/* Setup crap */
2001-05-07 08:32:40 +04:00
2001-12-05 07:17:39 +03:00
if ( state = = NULL )
return WINBINDD_ERROR ;
2001-05-07 08:32:40 +04:00
2003-07-09 20:44:47 +04:00
parse_domain_user ( state - > request . data . chauthtok . user , domain , user ) ;
2003-12-31 11:45:03 +03:00
2004-01-05 07:10:28 +03:00
if ( ! ( contact_domain = find_domain_from_name ( domain ) ) ) {
2003-12-31 11:45:03 +03:00
DEBUG ( 3 , ( " Cannot change password for [%s] -> [%s] \\ [%s] as %s is not a trusted domain \n " ,
state - > request . data . chauthtok . user , domain , user , domain ) ) ;
result = NT_STATUS_NO_SUCH_USER ;
2002-02-05 12:40:36 +03:00
goto done ;
}
2001-05-07 08:32:40 +04:00
2002-01-30 06:23:40 +03:00
/* Change password */
2001-12-05 07:17:39 +03:00
oldpass = state - > request . data . chauthtok . oldpass ;
newpass = state - > request . data . chauthtok . newpass ;
2001-05-07 08:32:40 +04:00
2002-01-30 06:23:40 +03:00
/* Get sam handle */
2001-05-07 08:32:40 +04:00
2004-01-05 07:10:28 +03:00
if ( NT_STATUS_IS_ERR ( result = cm_get_sam_handle ( contact_domain , & hnd ) ) ) {
2002-02-05 12:40:36 +03:00
DEBUG ( 1 , ( " could not get SAM handle on DC for %s \n " , domain ) ) ;
goto done ;
}
2001-05-07 08:32:40 +04:00
2004-01-05 08:07:59 +03:00
if ( ! cli_oem_change_password ( hnd - > cli , user , newpass , oldpass ) ) {
DEBUG ( 1 , ( " password change failed for user %s/%s \n " , domain ,
user ) ) ;
result = NT_STATUS_WRONG_PASSWORD ;
} else {
result = NT_STATUS_OK ;
}
2002-02-05 12:40:36 +03:00
done :
state - > response . data . auth . nt_status = NT_STATUS_V ( result ) ;
2002-03-17 07:36:35 +03:00
fstrcpy ( state - > response . data . auth . nt_status_string , nt_errstr ( result ) ) ;
fstrcpy ( state - > response . data . auth . error_string , nt_errstr ( result ) ) ;
2002-02-05 12:40:36 +03:00
state - > response . data . auth . pam_error = nt_status_to_pam ( result ) ;
2002-10-26 06:20:59 +04:00
DEBUG ( NT_STATUS_IS_OK ( result ) ? 5 : 2 ,
( " Password change for user [%s] \\ [%s] returned %s (PAM: %d) \n " ,
domain ,
user ,
state - > response . data . auth . nt_status_string ,
state - > response . data . auth . pam_error ) ) ;
2004-01-05 07:10:28 +03:00
if ( mem_ctx )
talloc_destroy ( mem_ctx ) ;
2002-02-05 12:40:36 +03:00
return NT_STATUS_IS_OK ( result ) ? WINBINDD_OK : WINBINDD_ERROR ;
2001-05-07 08:32:40 +04:00
}