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 .
*/
# 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 ;
2002-01-15 01:08:47 +03: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 ] ;
2003-07-07 09:11:10 +04:00
const char * contact_domain ;
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 ) ;
if ( ! name_domain ) {
2002-04-08 03:41:55 +04:00
DEBUG ( 5 , ( " no domain separator (%s) in username (%s) - failing auth \n " , lp_winbind_separator ( ) , state - > request . data . auth . user ) ) ;
2002-02-05 12:40:36 +03:00
result = NT_STATUS_INVALID_PARAMETER ;
goto done ;
2002-01-10 13:23:54 +03:00
}
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-06-30 21:24:59 +04:00
if ( ! get_trust_pw ( name_domain , trust_passwd , & last_change_time , & sec_channel_type ) ) {
2002-02-05 12:40:36 +03:00
result = NT_STATUS_CANT_ACCESS_DOMAIN_INFO ;
goto done ;
2001-08-12 15:19:57 +04:00
}
2003-07-07 09:11:10 +04:00
/* what domain should we contact? */
if ( IS_DC )
contact_domain = name_domain ;
else
contact_domain = lp_workgroup ( ) ;
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-06 23:49:59 +04:00
if ( cli )
SAFE_FREE ( cli ) ;
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
/* if we get access denied, a possible cuase was that we had and open
connection to the DC , but someone changed our machine accoutn password
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 ( ) ;
cli - > fd = - 1 ;
}
2003-05-08 12:02:52 +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 . */
} while ( ( attempts < 2 ) & & ( cli - > fd = = - 1 ) ) ;
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 ) ;
}
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 ) ) ;
2003-01-15 20:39:47 +03:00
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 ;
2002-01-15 01:08:47 +03:00
struct cli_state * cli = NULL ;
2002-02-05 12:40:36 +03:00
TALLOC_CTX * mem_ctx = NULL ;
2002-08-17 21:00:51 +04:00
char * user = NULL ;
2002-11-13 02:20:50 +03:00
const char * domain = NULL ;
const char * workstation ;
2003-07-07 09:11:10 +04:00
const char * contact_domain ;
2003-05-08 12:02:52 +04:00
DOM_CRED ret_creds ;
int attempts = 0 ;
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 ) {
DEBUG ( 2 , ( " winbindd_pam_auth_crap: non-privileged access denied! \n " ) ) ;
/* send a better message than ACCESS_DENIED */
push_utf8_fstring ( state - > response . data . auth . error_string , " winbind client not authorized to use winbindd_pam_auth_crap " ) ;
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
2003-01-02 22:25:28 +03:00
if ( pull_utf8_talloc ( mem_ctx , & 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
}
2002-11-13 02:20:50 +03:00
domain = dom ;
2002-01-18 05:37:55 +03:00
} else if ( lp_winbind_use_default_domain ( ) ) {
2002-08-17 21:00:51 +04:00
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 " ,
user ) ) ;
2002-02-05 12:40:36 +03:00
result = NT_STATUS_INVALID_PARAMETER ;
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 ,
2002-08-17 21:00:51 +04:00
domain , user ) ) ;
2003-06-30 21:24:59 +04:00
if ( ! get_trust_pw ( domain , trust_passwd , & last_change_time , & sec_channel_type ) ) {
result = NT_STATUS_CANT_ACCESS_DOMAIN_INFO ;
goto done ;
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
2003-07-07 09:11:10 +04:00
/* what domain should we contact? */
if ( IS_DC )
contact_domain = domain ;
else
contact_domain = lp_workgroup ( ) ;
2003-05-08 12:02:52 +04:00
do {
ZERO_STRUCT ( info3 ) ;
ZERO_STRUCT ( ret_creds ) ;
2003-09-06 23:49:59 +04:00
if ( cli )
SAFE_FREE ( cli ) ;
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 ,
user , domain ,
workstation ,
state - > request . data . auth_crap . chal ,
lm_resp , nt_resp ,
& info3 ) ;
attempts + = 1 ;
2001-11-05 03:21:17 +03:00
2003-07-03 20:23:11 +04:00
/* if we get access denied, a possible cuase was that we had and open
connection to the DC , but someone changed our machine accoutn password
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 " ,
domain ) ) ;
winbindd_cm_flush ( ) ;
cli - > fd = - 1 ;
}
2003-05-08 12:02:52 +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 . */
2001-11-23 03:14:04 +03:00
2003-05-08 12:02:52 +04:00
} while ( ( attempts < 2 ) & & ( cli - > fd = = - 1 ) ) ;
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 ) ;
wcache_invalidate_samlogon ( find_domain_from_name ( domain ) , & info3 ) ;
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-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 :
2000-05-09 15:43:00 +04:00
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-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 " ,
2002-08-17 21:00:51 +04:00
domain ,
user ,
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 ;
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
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 ) ;
if ( ! * domain ) {
2002-02-05 12:40:36 +03:00
result = NT_STATUS_INVALID_PARAMETER ;
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
2003-06-21 08:05:01 +04:00
if ( NT_STATUS_IS_ERR ( result = cm_get_sam_handle ( 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
2002-01-30 06:23:40 +03:00
if ( ! cli_oem_change_password ( hnd - > cli , user , newpass , oldpass ) ) {
2002-02-05 12:40:36 +03:00
DEBUG ( 1 , ( " password change failed for user %s/%s \n " , domain ,
2002-01-30 06:23:40 +03:00
user ) ) ;
2002-02-05 12:40:36 +03:00
result = NT_STATUS_WRONG_PASSWORD ;
} else {
result = NT_STATUS_OK ;
2001-12-05 07:17:39 +03:00
}
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 ) ) ;
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
}