2003-07-01 21:51:52 +04:00
/*
2002-01-30 09:08:46 +03:00
* Unix SMB / CIFS implementation .
2003-03-14 20:05:13 +03:00
* Routines to operate on various trust relationships
* Copyright ( C ) Andrew Bartlett 2001
* Copyright ( C ) Rafal Szczesniak 2003
2001-12-05 14:00:26 +03: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
2007-07-09 23:25:36 +04:00
* the Free Software Foundation ; either version 3 of the License , or
2001-12-05 14:00:26 +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 09:23:25 +04:00
* along with this program ; if not , see < http : //www.gnu.org/licenses/>.
2001-12-05 14:00:26 +03:00
*/
# include "includes.h"
2009-03-16 13:27:58 +03:00
# include "../libcli/auth/libcli_auth.h"
2013-09-15 15:19:52 +04:00
# include "../libcli/auth/netlogon_creds_cli.h"
2010-05-18 20:26:03 +04:00
# include "rpc_client/cli_netlogon.h"
2011-02-28 12:19:44 +03:00
# include "rpc_client/cli_pipe.h"
2010-06-30 14:10:55 +04:00
# include "../librpc/gen_ndr/ndr_netlogon.h"
s3:trusts_util: make use the workstation password change more robust
We use secrets_{prepare,failed,defer,finish}_password_change() to make
the process more robust.
Even if we just just verified the current password with the DC
it can still happen that the remote password change will fail.
If a server has the RefusePasswordChange=1 under
HKLM\SYSTEM\CurrentControlSet\Services\Netlogon\Parameters,
it will reject NetrServerPasswordSet2() with NT_STATUS_WRONG_PASSWORD.
This results in a successful local change, but a failing remote change,
which means the domain membership is broken (as we don't fallback to
the previous password for ntlmssp nor kerberos yet).
An (at least Samba) RODC will also reject a password change,
see https://bugzilla.samba.org/show_bug.cgi?id=12773.
Even with this change we still have open problems, e.g. if the password was
changed, but we didn't get the servers response. In order to fix that we need
to use only netlogon and lsa over unprotected transports, just using schannel
authentication (which supports the fallback to the old password).
BUG: https://bugzilla.samba.org/show_bug.cgi?id=12782
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
2017-05-22 21:47:17 +03:00
# include "librpc/gen_ndr/secrets.h"
2010-08-05 04:25:37 +04:00
# include "secrets.h"
2011-03-18 20:58:37 +03:00
# include "passdb.h"
2011-05-06 13:47:43 +04:00
# include "libsmb/libsmb.h"
2013-09-15 15:19:52 +04:00
# include "source3/include/messages.h"
# include "source3/include/g_lock.h"
2017-12-03 22:47:02 +03:00
# include "lib/util/util_tdb.h"
2001-12-05 14:00:26 +03:00
/*********************************************************
Change the domain password on the PDC .
2013-09-02 22:19:28 +04:00
Do most of the legwork ourselfs . Caller must have
already setup the connection to the NETLOGON pipe
2001-12-05 14:00:26 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2013-09-15 15:19:52 +04:00
struct trust_pw_change_state {
struct g_lock_ctx * g_ctx ;
char * g_lock_key ;
} ;
static int trust_pw_change_state_destructor ( struct trust_pw_change_state * state )
{
2017-12-03 22:47:02 +03:00
g_lock_unlock ( state - > g_ctx ,
string_term_tdb_data ( state - > g_lock_key ) ) ;
2013-09-15 15:19:52 +04:00
return 0 ;
}
2016-08-23 13:12:35 +03:00
char * trust_pw_new_value ( TALLOC_CTX * mem_ctx ,
enum netr_SchannelType sec_channel_type ,
int security )
{
/*
* use secure defaults .
*/
size_t min = 128 ;
size_t max = 255 ;
switch ( sec_channel_type ) {
case SEC_CHAN_WKSTA :
case SEC_CHAN_BDC :
if ( security = = SEC_DOMAIN ) {
/*
* The maximum length of a trust account password .
* Used when we randomly create it , 15 char passwords
* exceed NT4 ' s max password length .
*/
min = 14 ;
max = 14 ;
}
break ;
case SEC_CHAN_DNS_DOMAIN :
/*
* new_len * 2 = 498 bytes is the largest possible length
* NL_PASSWORD_VERSION consumes the rest of the possible 512 bytes
* and a confounder with at least 2 bytes is required .
*
* Windows uses new_len = 120 = > 240 bytes ( utf16 )
*/
min = 120 ;
max = 120 ;
break ;
case SEC_CHAN_DOMAIN :
/*
* The maximum length of a trust account password .
* Used when we randomly create it , 15 char passwords
* exceed NT4 ' s max password length .
*/
min = 14 ;
max = 14 ;
break ;
default :
break ;
}
/*
* Create a random machine account password
* We create a random buffer and convert that to utf8 .
* This is similar to what windows is doing .
*/
return generate_random_machine_password ( mem_ctx , min , max ) ;
}
2017-09-13 21:51:47 +03:00
/*
* Temporary function to wrap cli_auth in a lck
*/
static NTSTATUS netlogon_creds_cli_lck_auth (
struct netlogon_creds_cli_context * context ,
struct dcerpc_binding_handle * b ,
uint8_t num_nt_hashes ,
const struct samr_Password * const * nt_hashes ,
uint8_t * idx_nt_hashes )
{
struct netlogon_creds_cli_lck * lck ;
NTSTATUS status ;
status = netlogon_creds_cli_lck (
context , NETLOGON_CREDS_CLI_LCK_EXCLUSIVE ,
talloc_tos ( ) , & lck ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
DBG_WARNING ( " netlogon_creds_cli_lck failed: %s \n " ,
nt_errstr ( status ) ) ;
return status ;
}
status = netlogon_creds_cli_auth ( context , b , num_nt_hashes , nt_hashes ,
idx_nt_hashes ) ;
TALLOC_FREE ( lck ) ;
return status ;
}
2013-09-15 15:19:52 +04:00
NTSTATUS trust_pw_change ( struct netlogon_creds_cli_context * context ,
struct messaging_context * msg_ctx ,
struct dcerpc_binding_handle * b ,
const char * domain ,
2017-05-22 16:36:29 +03:00
const char * dcname ,
2013-09-15 15:19:52 +04:00
bool force )
{
TALLOC_CTX * frame = talloc_stackframe ( ) ;
2017-01-18 21:57:30 +03:00
const char * context_name = NULL ;
2013-09-15 15:19:52 +04:00
struct trust_pw_change_state * state ;
2015-01-30 12:21:59 +03:00
struct cli_credentials * creds = NULL ;
s3:trusts_util: make use the workstation password change more robust
We use secrets_{prepare,failed,defer,finish}_password_change() to make
the process more robust.
Even if we just just verified the current password with the DC
it can still happen that the remote password change will fail.
If a server has the RefusePasswordChange=1 under
HKLM\SYSTEM\CurrentControlSet\Services\Netlogon\Parameters,
it will reject NetrServerPasswordSet2() with NT_STATUS_WRONG_PASSWORD.
This results in a successful local change, but a failing remote change,
which means the domain membership is broken (as we don't fallback to
the previous password for ntlmssp nor kerberos yet).
An (at least Samba) RODC will also reject a password change,
see https://bugzilla.samba.org/show_bug.cgi?id=12773.
Even with this change we still have open problems, e.g. if the password was
changed, but we didn't get the servers response. In order to fix that we need
to use only netlogon and lsa over unprotected transports, just using schannel
authentication (which supports the fallback to the old password).
BUG: https://bugzilla.samba.org/show_bug.cgi?id=12782
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
2017-05-22 21:47:17 +03:00
struct secrets_domain_info1 * info = NULL ;
struct secrets_domain_info1_change * prev = NULL ;
2015-01-30 12:21:59 +03:00
const struct samr_Password * current_nt_hash = NULL ;
2017-06-21 22:30:39 +03:00
const struct samr_Password * previous_nt_hash = NULL ;
2017-05-22 21:44:40 +03:00
uint8_t num_nt_hashes = 0 ;
2017-06-21 22:30:39 +03:00
uint8_t idx = 0 ;
s3:trusts_util: make use the workstation password change more robust
We use secrets_{prepare,failed,defer,finish}_password_change() to make
the process more robust.
Even if we just just verified the current password with the DC
it can still happen that the remote password change will fail.
If a server has the RefusePasswordChange=1 under
HKLM\SYSTEM\CurrentControlSet\Services\Netlogon\Parameters,
it will reject NetrServerPasswordSet2() with NT_STATUS_WRONG_PASSWORD.
This results in a successful local change, but a failing remote change,
which means the domain membership is broken (as we don't fallback to
the previous password for ntlmssp nor kerberos yet).
An (at least Samba) RODC will also reject a password change,
see https://bugzilla.samba.org/show_bug.cgi?id=12773.
Even with this change we still have open problems, e.g. if the password was
changed, but we didn't get the servers response. In order to fix that we need
to use only netlogon and lsa over unprotected transports, just using schannel
authentication (which supports the fallback to the old password).
BUG: https://bugzilla.samba.org/show_bug.cgi?id=12782
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
2017-05-22 21:47:17 +03:00
const struct samr_Password * nt_hashes [ 1 + 3 ] = { NULL , } ;
2017-05-22 21:44:40 +03:00
uint8_t idx_nt_hashes = 0 ;
2017-06-21 22:30:39 +03:00
uint8_t idx_current = UINT8_MAX ;
2013-09-15 15:19:52 +04:00
enum netr_SchannelType sec_channel_type = SEC_CHAN_NULL ;
time_t pass_last_set_time ;
2015-01-30 12:21:59 +03:00
uint32_t old_version = 0 ;
2015-01-30 12:21:59 +03:00
struct pdb_trusted_domain * td = NULL ;
2013-09-15 15:19:52 +04:00
struct timeval g_timeout = { 0 , } ;
int timeout = 0 ;
struct timeval tv = { 0 , } ;
2017-06-13 12:18:37 +03:00
char * new_trust_pw_str = NULL ;
size_t len = 0 ;
DATA_BLOB new_trust_pw_blob = data_blob_null ;
2015-01-30 12:21:59 +03:00
uint32_t new_version = 0 ;
uint32_t * new_trust_version = NULL ;
2013-09-15 15:19:52 +04:00
NTSTATUS status ;
2015-01-30 12:21:59 +03:00
bool ok ;
2013-09-15 15:19:52 +04:00
state = talloc_zero ( frame , struct trust_pw_change_state ) ;
if ( state = = NULL ) {
TALLOC_FREE ( frame ) ;
return NT_STATUS_NO_MEMORY ;
}
state - > g_ctx = g_lock_ctx_init ( state , msg_ctx ) ;
if ( state - > g_ctx = = NULL ) {
TALLOC_FREE ( frame ) ;
return NT_STATUS_NO_MEMORY ;
}
state - > g_lock_key = talloc_asprintf ( state ,
" trust_password_change_%s " ,
domain ) ;
if ( state - > g_lock_key = = NULL ) {
TALLOC_FREE ( frame ) ;
return NT_STATUS_NO_MEMORY ;
}
g_timeout = timeval_current_ofs ( 10 , 0 ) ;
status = g_lock_lock ( state - > g_ctx ,
2017-12-03 22:47:02 +03:00
string_term_tdb_data ( state - > g_lock_key ) ,
2013-09-15 15:19:52 +04:00
G_LOCK_WRITE , g_timeout ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
DEBUG ( 1 , ( " could not get g_lock on [%s]! \n " ,
state - > g_lock_key ) ) ;
TALLOC_FREE ( frame ) ;
return status ;
}
talloc_set_destructor ( state , trust_pw_change_state_destructor ) ;
2015-01-30 12:21:59 +03:00
status = pdb_get_trust_credentials ( domain , NULL , frame , & creds ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
DEBUG ( 0 , ( " could not fetch domain creds for domain %s - %s! \n " ,
domain , nt_errstr ( status ) ) ) ;
TALLOC_FREE ( frame ) ;
return NT_STATUS_TRUSTED_RELATIONSHIP_FAILURE ;
}
current_nt_hash = cli_credentials_get_nt_hash ( creds , frame ) ;
if ( current_nt_hash = = NULL ) {
DEBUG ( 0 , ( " cli_credentials_get_nt_hash failed for domain %s! \n " ,
domain ) ) ;
2013-09-15 15:19:52 +04:00
TALLOC_FREE ( frame ) ;
return NT_STATUS_TRUSTED_RELATIONSHIP_FAILURE ;
}
2017-06-21 22:30:39 +03:00
previous_nt_hash = cli_credentials_get_old_nt_hash ( creds , frame ) ;
2013-09-15 15:19:52 +04:00
2015-01-30 12:21:59 +03:00
old_version = cli_credentials_get_kvno ( creds ) ;
2015-01-30 12:21:59 +03:00
pass_last_set_time = cli_credentials_get_password_last_changed_time ( creds ) ;
sec_channel_type = cli_credentials_get_secure_channel_type ( creds ) ;
2015-01-30 12:21:59 +03:00
new_version = old_version + 1 ;
2013-09-15 15:19:52 +04:00
switch ( sec_channel_type ) {
case SEC_CHAN_WKSTA :
2014-10-23 03:28:48 +04:00
case SEC_CHAN_BDC :
2013-09-15 15:19:52 +04:00
break ;
2015-01-30 12:21:59 +03:00
case SEC_CHAN_DNS_DOMAIN :
2013-09-15 15:19:52 +04:00
case SEC_CHAN_DOMAIN :
2015-01-30 12:21:59 +03:00
status = pdb_get_trusted_domain ( frame , domain , & td ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
DEBUG ( 0 , ( " pdb_get_trusted_domain() failed for domain %s - %s! \n " ,
domain , nt_errstr ( status ) ) ) ;
2013-09-15 15:19:52 +04:00
TALLOC_FREE ( frame ) ;
2015-01-30 12:21:59 +03:00
return status ;
2013-09-15 15:19:52 +04:00
}
2015-01-30 12:21:59 +03:00
new_trust_version = & new_version ;
2013-09-15 15:19:52 +04:00
break ;
default :
TALLOC_FREE ( frame ) ;
return NT_STATUS_NOT_SUPPORTED ;
}
timeout = lp_machine_password_timeout ( ) ;
if ( timeout = = 0 ) {
if ( ! force ) {
DEBUG ( 10 , ( " machine password never expires \n " ) ) ;
TALLOC_FREE ( frame ) ;
return NT_STATUS_OK ;
}
}
tv . tv_sec = pass_last_set_time ;
DEBUG ( 10 , ( " password last changed %s \n " ,
timeval_string ( talloc_tos ( ) , & tv , false ) ) ) ;
tv . tv_sec + = timeout ;
DEBUGADD ( 10 , ( " password valid until %s \n " ,
timeval_string ( talloc_tos ( ) , & tv , false ) ) ) ;
if ( ! force & & ! timeval_expired ( & tv ) ) {
TALLOC_FREE ( frame ) ;
return NT_STATUS_OK ;
}
2017-01-18 21:57:30 +03:00
context_name = netlogon_creds_cli_debug_string ( context , talloc_tos ( ) ) ;
if ( context_name = = NULL ) {
TALLOC_FREE ( frame ) ;
return NT_STATUS_NO_MEMORY ;
}
2015-01-30 12:21:59 +03:00
/*
* Create a random machine account password
* We create a random buffer and convert that to utf8 .
* This is similar to what windows is doing .
*/
2017-06-13 12:18:37 +03:00
new_trust_pw_str = trust_pw_new_value ( frame , sec_channel_type ,
2016-08-23 13:12:35 +03:00
lp_security ( ) ) ;
2017-06-13 12:18:37 +03:00
if ( new_trust_pw_str = = NULL ) {
2016-08-23 13:12:35 +03:00
DEBUG ( 0 , ( " trust_pw_new_value() failed \n " ) ) ;
2013-09-15 15:19:52 +04:00
TALLOC_FREE ( frame ) ;
return NT_STATUS_NO_MEMORY ;
}
2017-06-13 12:18:37 +03:00
len = strlen ( new_trust_pw_str ) ;
ok = convert_string_talloc ( frame , CH_UNIX , CH_UTF16 ,
new_trust_pw_str , len ,
( void * * ) & new_trust_pw_blob . data ,
& new_trust_pw_blob . length ) ;
if ( ! ok ) {
status = NT_STATUS_UNMAPPABLE_CHARACTER ;
if ( errno = = ENOMEM ) {
status = NT_STATUS_NO_MEMORY ;
}
DBG_ERR ( " convert_string_talloc(CH_UTF16MUNGED, CH_UNIX) "
" failed for of %s - %s \n " ,
domain , nt_errstr ( status ) ) ;
TALLOC_FREE ( frame ) ;
return status ;
}
s3:trusts_util: make use the workstation password change more robust
We use secrets_{prepare,failed,defer,finish}_password_change() to make
the process more robust.
Even if we just just verified the current password with the DC
it can still happen that the remote password change will fail.
If a server has the RefusePasswordChange=1 under
HKLM\SYSTEM\CurrentControlSet\Services\Netlogon\Parameters,
it will reject NetrServerPasswordSet2() with NT_STATUS_WRONG_PASSWORD.
This results in a successful local change, but a failing remote change,
which means the domain membership is broken (as we don't fallback to
the previous password for ntlmssp nor kerberos yet).
An (at least Samba) RODC will also reject a password change,
see https://bugzilla.samba.org/show_bug.cgi?id=12773.
Even with this change we still have open problems, e.g. if the password was
changed, but we didn't get the servers response. In order to fix that we need
to use only netlogon and lsa over unprotected transports, just using schannel
authentication (which supports the fallback to the old password).
BUG: https://bugzilla.samba.org/show_bug.cgi?id=12782
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
2017-05-22 21:47:17 +03:00
switch ( sec_channel_type ) {
case SEC_CHAN_WKSTA :
case SEC_CHAN_BDC :
status = secrets_prepare_password_change ( domain , dcname ,
new_trust_pw_str ,
frame , & info , & prev ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
DEBUG ( 0 , ( " secrets_prepare_password_change() failed for domain %s! \n " ,
domain ) ) ;
TALLOC_FREE ( frame ) ;
return NT_STATUS_INTERNAL_DB_CORRUPTION ;
}
TALLOC_FREE ( new_trust_pw_str ) ;
if ( prev ! = NULL ) {
/*
* We had a failure before we changed the password .
*/
nt_hashes [ idx + + ] = & prev - > password - > nt_hash ;
DEBUG ( 0 , ( " %s : %s(%s): A password change was already "
" started against '%s' at %s. Trying to "
" recover... \n " ,
current_timestring ( talloc_tos ( ) , false ) ,
__func__ , domain ,
prev - > password - > change_server ,
nt_time_string ( talloc_tos ( ) ,
prev - > password - > change_time ) ) ) ;
DEBUG ( 0 , ( " %s : %s(%s): Last failure local[%s] remote[%s] "
" against '%s' at %s. \n " ,
current_timestring ( talloc_tos ( ) , false ) ,
__func__ , domain ,
nt_errstr ( prev - > local_status ) ,
nt_errstr ( prev - > remote_status ) ,
prev - > change_server ,
nt_time_string ( talloc_tos ( ) ,
prev - > change_time ) ) ) ;
}
idx_current = idx ;
nt_hashes [ idx + + ] = & info - > password - > nt_hash ;
if ( info - > old_password ! = NULL ) {
nt_hashes [ idx + + ] = & info - > old_password - > nt_hash ;
}
if ( info - > older_password ! = NULL ) {
nt_hashes [ idx + + ] = & info - > older_password - > nt_hash ;
}
/*
2019-06-19 12:45:30 +03:00
* We use the password that ' s already persistent in
s3:trusts_util: make use the workstation password change more robust
We use secrets_{prepare,failed,defer,finish}_password_change() to make
the process more robust.
Even if we just just verified the current password with the DC
it can still happen that the remote password change will fail.
If a server has the RefusePasswordChange=1 under
HKLM\SYSTEM\CurrentControlSet\Services\Netlogon\Parameters,
it will reject NetrServerPasswordSet2() with NT_STATUS_WRONG_PASSWORD.
This results in a successful local change, but a failing remote change,
which means the domain membership is broken (as we don't fallback to
the previous password for ntlmssp nor kerberos yet).
An (at least Samba) RODC will also reject a password change,
see https://bugzilla.samba.org/show_bug.cgi?id=12773.
Even with this change we still have open problems, e.g. if the password was
changed, but we didn't get the servers response. In order to fix that we need
to use only netlogon and lsa over unprotected transports, just using schannel
authentication (which supports the fallback to the old password).
BUG: https://bugzilla.samba.org/show_bug.cgi?id=12782
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
2017-05-22 21:47:17 +03:00
* our database in order to handle failures .
*/
data_blob_clear_free ( & new_trust_pw_blob ) ;
new_trust_pw_blob = info - > next_change - > password - > cleartext_blob ;
break ;
case SEC_CHAN_DNS_DOMAIN :
case SEC_CHAN_DOMAIN :
idx_current = idx ;
nt_hashes [ idx + + ] = current_nt_hash ;
if ( previous_nt_hash ! = NULL ) {
nt_hashes [ idx + + ] = previous_nt_hash ;
}
break ;
default :
smb_panic ( " Unsupported secure channel type " ) ;
break ;
2017-06-21 22:30:39 +03:00
}
num_nt_hashes = idx ;
DEBUG ( 0 , ( " %s : %s(%s): Verifying passwords remotely %s. \n " ,
current_timestring ( talloc_tos ( ) , false ) ,
__func__ , domain , context_name ) ) ;
2017-05-22 21:44:40 +03:00
2015-01-31 13:42:09 +03:00
/*
2017-06-21 22:30:39 +03:00
* Check which password the dc knows about .
2015-01-31 13:42:09 +03:00
*
* TODO :
* If the previous password is the only password in common with the dc ,
* we better skip the password change , or use something like
* ServerTrustPasswordsGet ( ) or netr_ServerGetTrustInfo ( ) to fix our
* local secrets before doing the change .
*/
2017-09-13 21:51:47 +03:00
status = netlogon_creds_cli_lck_auth ( context , b ,
num_nt_hashes ,
nt_hashes ,
& idx_nt_hashes ) ;
2013-09-15 15:19:52 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2017-06-21 22:30:39 +03:00
DEBUG ( 0 , ( " netlogon_creds_cli_auth(%s) failed for old passwords (%u) - %s! \n " ,
context_name , num_nt_hashes , nt_errstr ( status ) ) ) ;
2013-09-15 15:19:52 +04:00
TALLOC_FREE ( frame ) ;
return status ;
}
s3:trusts_util: make use the workstation password change more robust
We use secrets_{prepare,failed,defer,finish}_password_change() to make
the process more robust.
Even if we just just verified the current password with the DC
it can still happen that the remote password change will fail.
If a server has the RefusePasswordChange=1 under
HKLM\SYSTEM\CurrentControlSet\Services\Netlogon\Parameters,
it will reject NetrServerPasswordSet2() with NT_STATUS_WRONG_PASSWORD.
This results in a successful local change, but a failing remote change,
which means the domain membership is broken (as we don't fallback to
the previous password for ntlmssp nor kerberos yet).
An (at least Samba) RODC will also reject a password change,
see https://bugzilla.samba.org/show_bug.cgi?id=12773.
Even with this change we still have open problems, e.g. if the password was
changed, but we didn't get the servers response. In order to fix that we need
to use only netlogon and lsa over unprotected transports, just using schannel
authentication (which supports the fallback to the old password).
BUG: https://bugzilla.samba.org/show_bug.cgi?id=12782
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
2017-05-22 21:47:17 +03:00
if ( prev ! = NULL & & idx_nt_hashes = = 0 ) {
DEBUG ( 0 , ( " %s : %s(%s): Verified new password remotely "
" without changing %s \n " ,
current_timestring ( talloc_tos ( ) , false ) ,
__func__ , domain , context_name ) ) ;
status = secrets_finish_password_change ( prev - > password - > change_server ,
prev - > password - > change_time ,
info ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
DEBUG ( 0 , ( " secrets_prepare_password_change() failed for domain %s! \n " ,
domain ) ) ;
TALLOC_FREE ( frame ) ;
return NT_STATUS_INTERNAL_DB_CORRUPTION ;
}
DEBUG ( 0 , ( " %s : %s(%s): Recovered previous password change. \n " ,
current_timestring ( talloc_tos ( ) , false ) ,
__func__ , domain ) ) ;
TALLOC_FREE ( frame ) ;
return NT_STATUS_OK ;
}
2017-06-21 22:30:39 +03:00
if ( idx_nt_hashes ! = idx_current ) {
DEBUG ( 0 , ( " %s : %s(%s): Verified older password remotely "
" skip changing %s \n " ,
current_timestring ( talloc_tos ( ) , false ) ,
__func__ , domain , context_name ) ) ;
s3:trusts_util: make use the workstation password change more robust
We use secrets_{prepare,failed,defer,finish}_password_change() to make
the process more robust.
Even if we just just verified the current password with the DC
it can still happen that the remote password change will fail.
If a server has the RefusePasswordChange=1 under
HKLM\SYSTEM\CurrentControlSet\Services\Netlogon\Parameters,
it will reject NetrServerPasswordSet2() with NT_STATUS_WRONG_PASSWORD.
This results in a successful local change, but a failing remote change,
which means the domain membership is broken (as we don't fallback to
the previous password for ntlmssp nor kerberos yet).
An (at least Samba) RODC will also reject a password change,
see https://bugzilla.samba.org/show_bug.cgi?id=12773.
Even with this change we still have open problems, e.g. if the password was
changed, but we didn't get the servers response. In order to fix that we need
to use only netlogon and lsa over unprotected transports, just using schannel
authentication (which supports the fallback to the old password).
BUG: https://bugzilla.samba.org/show_bug.cgi?id=12782
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
2017-05-22 21:47:17 +03:00
if ( info = = NULL ) {
TALLOC_FREE ( frame ) ;
return NT_STATUS_TRUSTED_RELATIONSHIP_FAILURE ;
}
status = secrets_defer_password_change ( dcname ,
NT_STATUS_TRUSTED_RELATIONSHIP_FAILURE ,
NT_STATUS_NOT_COMMITTED ,
info ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
DEBUG ( 0 , ( " secrets_defer_password_change() failed for domain %s! \n " ,
domain ) ) ;
TALLOC_FREE ( frame ) ;
return NT_STATUS_INTERNAL_DB_CORRUPTION ;
}
2017-06-21 22:30:39 +03:00
TALLOC_FREE ( frame ) ;
return NT_STATUS_TRUSTED_RELATIONSHIP_FAILURE ;
}
2017-01-18 21:57:30 +03:00
DEBUG ( 0 , ( " %s : %s(%s): Verified old password remotely using %s \n " ,
current_timestring ( talloc_tos ( ) , false ) ,
__func__ , domain , context_name ) ) ;
2013-09-15 15:19:52 +04:00
/*
* Return the result of trying to write the new password
* back into the trust account file .
*/
switch ( sec_channel_type ) {
case SEC_CHAN_WKSTA :
2014-10-23 03:28:48 +04:00
case SEC_CHAN_BDC :
s3:trusts_util: make use the workstation password change more robust
We use secrets_{prepare,failed,defer,finish}_password_change() to make
the process more robust.
Even if we just just verified the current password with the DC
it can still happen that the remote password change will fail.
If a server has the RefusePasswordChange=1 under
HKLM\SYSTEM\CurrentControlSet\Services\Netlogon\Parameters,
it will reject NetrServerPasswordSet2() with NT_STATUS_WRONG_PASSWORD.
This results in a successful local change, but a failing remote change,
which means the domain membership is broken (as we don't fallback to
the previous password for ntlmssp nor kerberos yet).
An (at least Samba) RODC will also reject a password change,
see https://bugzilla.samba.org/show_bug.cgi?id=12773.
Even with this change we still have open problems, e.g. if the password was
changed, but we didn't get the servers response. In order to fix that we need
to use only netlogon and lsa over unprotected transports, just using schannel
authentication (which supports the fallback to the old password).
BUG: https://bugzilla.samba.org/show_bug.cgi?id=12782
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
2017-05-22 21:47:17 +03:00
/*
* we called secrets_prepare_password_change ( ) above .
*/
2013-09-15 15:19:52 +04:00
break ;
2015-01-30 12:21:59 +03:00
case SEC_CHAN_DNS_DOMAIN :
2013-09-15 15:19:52 +04:00
case SEC_CHAN_DOMAIN :
/*
* we need to get the sid first for the
* pdb_set_trusteddom_pw call
*/
2017-06-13 12:18:37 +03:00
ok = pdb_set_trusteddom_pw ( domain , new_trust_pw_str ,
2015-01-30 12:21:59 +03:00
& td - > security_identifier ) ;
if ( ! ok ) {
DEBUG ( 0 , ( " pdb_set_trusteddom_pw() failed for domain %s! \n " ,
domain ) ) ;
2013-09-15 15:19:52 +04:00
TALLOC_FREE ( frame ) ;
return NT_STATUS_INTERNAL_DB_CORRUPTION ;
}
2017-06-13 12:18:37 +03:00
TALLOC_FREE ( new_trust_pw_str ) ;
2013-09-15 15:19:52 +04:00
break ;
default :
2014-10-23 03:28:48 +04:00
smb_panic ( " Unsupported secure channel type " ) ;
2013-09-15 15:19:52 +04:00
break ;
}
2017-01-18 21:57:30 +03:00
DEBUG ( 0 , ( " %s : %s(%s): Changed password locally \n " ,
2015-01-31 13:42:09 +03:00
current_timestring ( talloc_tos ( ) , false ) , __func__ , domain ) ) ;
status = netlogon_creds_cli_ServerPasswordSet ( context , b ,
2017-06-13 12:18:37 +03:00
& new_trust_pw_blob ,
2015-01-30 12:21:59 +03:00
new_trust_version ) ;
2015-01-31 13:42:09 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
s3:trusts_util: make use the workstation password change more robust
We use secrets_{prepare,failed,defer,finish}_password_change() to make
the process more robust.
Even if we just just verified the current password with the DC
it can still happen that the remote password change will fail.
If a server has the RefusePasswordChange=1 under
HKLM\SYSTEM\CurrentControlSet\Services\Netlogon\Parameters,
it will reject NetrServerPasswordSet2() with NT_STATUS_WRONG_PASSWORD.
This results in a successful local change, but a failing remote change,
which means the domain membership is broken (as we don't fallback to
the previous password for ntlmssp nor kerberos yet).
An (at least Samba) RODC will also reject a password change,
see https://bugzilla.samba.org/show_bug.cgi?id=12773.
Even with this change we still have open problems, e.g. if the password was
changed, but we didn't get the servers response. In order to fix that we need
to use only netlogon and lsa over unprotected transports, just using schannel
authentication (which supports the fallback to the old password).
BUG: https://bugzilla.samba.org/show_bug.cgi?id=12782
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
2017-05-22 21:47:17 +03:00
NTSTATUS status2 ;
const char * fn = NULL ;
ok = dcerpc_binding_handle_is_connected ( b ) ;
DEBUG ( 0 , ( " %s : %s(%s) remote password change with %s failed "
" - %s (%s) \n " ,
2017-01-18 21:57:30 +03:00
current_timestring ( talloc_tos ( ) , false ) ,
__func__ , domain , context_name ,
s3:trusts_util: make use the workstation password change more robust
We use secrets_{prepare,failed,defer,finish}_password_change() to make
the process more robust.
Even if we just just verified the current password with the DC
it can still happen that the remote password change will fail.
If a server has the RefusePasswordChange=1 under
HKLM\SYSTEM\CurrentControlSet\Services\Netlogon\Parameters,
it will reject NetrServerPasswordSet2() with NT_STATUS_WRONG_PASSWORD.
This results in a successful local change, but a failing remote change,
which means the domain membership is broken (as we don't fallback to
the previous password for ntlmssp nor kerberos yet).
An (at least Samba) RODC will also reject a password change,
see https://bugzilla.samba.org/show_bug.cgi?id=12773.
Even with this change we still have open problems, e.g. if the password was
changed, but we didn't get the servers response. In order to fix that we need
to use only netlogon and lsa over unprotected transports, just using schannel
authentication (which supports the fallback to the old password).
BUG: https://bugzilla.samba.org/show_bug.cgi?id=12782
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
2017-05-22 21:47:17 +03:00
nt_errstr ( status ) ,
ok ? " connected " : " disconnected " ) ) ;
if ( ! ok ) {
/*
* The connection is broken , we don ' t
* know if the password was changed ,
* we hope to have more luck next time .
*/
status2 = secrets_failed_password_change ( dcname ,
NT_STATUS_NOT_COMMITTED ,
status ,
info ) ;
fn = " secrets_failed_password_change " ;
} else {
/*
* The server rejected the change , we don ' t
* retry and defer the change to the next
* " machine password timeout " interval .
*/
status2 = secrets_defer_password_change ( dcname ,
NT_STATUS_NOT_COMMITTED ,
status ,
info ) ;
fn = " secrets_defer_password_change " ;
}
if ( ! NT_STATUS_IS_OK ( status2 ) ) {
DEBUG ( 0 , ( " %s() failed for domain %s! \n " ,
fn , domain ) ) ;
TALLOC_FREE ( frame ) ;
return NT_STATUS_INTERNAL_DB_CORRUPTION ;
}
2015-01-31 13:42:09 +03:00
TALLOC_FREE ( frame ) ;
return status ;
}
2017-01-18 21:57:30 +03:00
DEBUG ( 0 , ( " %s : %s(%s): Changed password remotely using %s \n " ,
current_timestring ( talloc_tos ( ) , false ) ,
__func__ , domain , context_name ) ) ;
2015-01-31 13:42:09 +03:00
s3:trusts_util: make use the workstation password change more robust
We use secrets_{prepare,failed,defer,finish}_password_change() to make
the process more robust.
Even if we just just verified the current password with the DC
it can still happen that the remote password change will fail.
If a server has the RefusePasswordChange=1 under
HKLM\SYSTEM\CurrentControlSet\Services\Netlogon\Parameters,
it will reject NetrServerPasswordSet2() with NT_STATUS_WRONG_PASSWORD.
This results in a successful local change, but a failing remote change,
which means the domain membership is broken (as we don't fallback to
the previous password for ntlmssp nor kerberos yet).
An (at least Samba) RODC will also reject a password change,
see https://bugzilla.samba.org/show_bug.cgi?id=12773.
Even with this change we still have open problems, e.g. if the password was
changed, but we didn't get the servers response. In order to fix that we need
to use only netlogon and lsa over unprotected transports, just using schannel
authentication (which supports the fallback to the old password).
BUG: https://bugzilla.samba.org/show_bug.cgi?id=12782
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
2017-05-22 21:47:17 +03:00
switch ( sec_channel_type ) {
case SEC_CHAN_WKSTA :
case SEC_CHAN_BDC :
status = secrets_finish_password_change (
info - > next_change - > change_server ,
info - > next_change - > change_time ,
info ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
DEBUG ( 0 , ( " secrets_finish_password_change() failed for domain %s! \n " ,
domain ) ) ;
TALLOC_FREE ( frame ) ;
return NT_STATUS_INTERNAL_DB_CORRUPTION ;
}
DEBUG ( 0 , ( " %s : %s(%s): Finished password change. \n " ,
current_timestring ( talloc_tos ( ) , false ) ,
__func__ , domain ) ) ;
break ;
case SEC_CHAN_DNS_DOMAIN :
case SEC_CHAN_DOMAIN :
/*
* we used pdb_set_trusteddom_pw ( ) .
*/
break ;
default :
smb_panic ( " Unsupported secure channel type " ) ;
break ;
}
2017-06-13 12:18:37 +03:00
ok = cli_credentials_set_utf16_password ( creds ,
& new_trust_pw_blob ,
CRED_SPECIFIED ) ;
2017-02-10 00:53:52 +03:00
if ( ! ok ) {
DEBUG ( 0 , ( " cli_credentials_set_password failed for domain %s! \n " ,
domain ) ) ;
TALLOC_FREE ( frame ) ;
return NT_STATUS_NO_MEMORY ;
}
current_nt_hash = cli_credentials_get_nt_hash ( creds , frame ) ;
if ( current_nt_hash = = NULL ) {
DEBUG ( 0 , ( " cli_credentials_get_nt_hash failed for domain %s! \n " ,
domain ) ) ;
TALLOC_FREE ( frame ) ;
return NT_STATUS_TRUSTED_RELATIONSHIP_FAILURE ;
}
/*
* Now we verify the new password .
*/
2017-06-21 22:30:39 +03:00
idx = 0 ;
nt_hashes [ idx + + ] = current_nt_hash ;
num_nt_hashes = idx ;
2017-09-13 21:51:47 +03:00
status = netlogon_creds_cli_lck_auth ( context , b ,
num_nt_hashes ,
nt_hashes ,
& idx_nt_hashes ) ;
2017-02-10 00:53:52 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
DEBUG ( 0 , ( " netlogon_creds_cli_auth(%s) failed for new password - %s! \n " ,
context_name , nt_errstr ( status ) ) ) ;
TALLOC_FREE ( frame ) ;
return status ;
}
DEBUG ( 0 , ( " %s : %s(%s): Verified new password remotely using %s \n " ,
current_timestring ( talloc_tos ( ) , false ) ,
__func__ , domain , context_name ) ) ;
2013-09-15 15:19:52 +04:00
TALLOC_FREE ( frame ) ;
return NT_STATUS_OK ;
}