2005-09-29 04:02:38 +04:00
/*
Unix SMB / CIFS implementation .
User credentials handling ( as regards on - disk files )
Copyright ( C ) Jelmer Vernooij 2005
Copyright ( C ) Tim Potter 2001
Copyright ( C ) Andrew Bartlett < abartlet @ samba . org > 2005
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-10 06:07:03 +04:00
the Free Software Foundation ; either version 3 of the License , or
2005-09-29 04:02:38 +04: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 06:07:03 +04:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2005-09-29 04:02:38 +04:00
*/
# include "includes.h"
2008-06-14 19:24:17 +04:00
# include "lib/events/events.h"
2011-02-10 06:12:51 +03:00
# include <ldb.h>
2006-03-16 03:23:11 +03:00
# include "librpc/gen_ndr/samr.h" /* for struct samrPassword */
2006-11-06 19:11:52 +03:00
# include "param/secrets.h"
2005-09-29 04:02:38 +04:00
# include "system/filesys.h"
2006-03-14 04:29:56 +03:00
# include "auth/credentials/credentials.h"
2013-07-31 14:41:40 +04:00
# include "auth/credentials/credentials_internal.h"
2011-03-19 02:44:56 +03:00
# include "auth/credentials/credentials_proto.h"
2006-11-07 03:48:36 +03:00
# include "auth/credentials/credentials_krb5.h"
2010-10-11 06:05:37 +04:00
# include "auth/kerberos/kerberos_util.h"
2007-09-08 16:42:09 +04:00
# include "param/param.h"
2008-04-17 03:03:18 +04:00
# include "lib/events/events.h"
2009-10-28 08:49:30 +03:00
# include "dsdb/samdb/samdb.h"
2012-07-14 16:23:41 +04:00
# include "source3/include/secrets.h"
# include "dbwrap/dbwrap.h"
# include "dbwrap/dbwrap_open.h"
# include "lib/util/util_tdb.h"
2009-10-28 08:49:30 +03:00
2005-09-29 04:02:38 +04:00
/**
* Fill in credentials for the machine trust account , from the secrets database .
*
* @ param cred Credentials structure to fill in
* @ retval NTSTATUS error detailing any failure
*/
2012-08-29 03:44:12 +04:00
static NTSTATUS cli_credentials_set_secrets_lct ( struct cli_credentials * cred ,
struct loadparm_context * lp_ctx ,
struct ldb_context * ldb ,
const char * base ,
const char * filter ,
time_t secrets_tdb_last_change_time ,
const char * secrets_tdb_password ,
char * * error_string )
2005-09-29 04:02:38 +04:00
{
TALLOC_CTX * mem_ctx ;
int ldb_ret ;
2010-02-20 03:44:41 +03:00
struct ldb_message * msg ;
2005-09-29 04:02:38 +04:00
const char * machine_account ;
const char * password ;
const char * domain ;
const char * realm ;
enum netr_SchannelType sct ;
2005-10-20 14:28:16 +04:00
const char * salt_principal ;
2010-09-23 11:01:44 +04:00
char * keytab ;
2010-05-17 07:41:01 +04:00
const struct ldb_val * whenChanged ;
2012-08-29 03:44:12 +04:00
time_t lct ;
2010-05-17 07:41:01 +04:00
2005-09-29 04:02:38 +04:00
/* ok, we are going to get it now, don't recurse back here */
2007-10-07 02:16:19 +04:00
cred - > machine_account_pending = false ;
2005-09-29 04:02:38 +04:00
2005-10-31 03:23:38 +03:00
/* some other parts of the system will key off this */
2007-10-07 02:16:19 +04:00
cred - > machine_account = true ;
2005-10-31 03:23:38 +03:00
2012-08-29 03:21:52 +04:00
mem_ctx = talloc_named ( cred , 0 , " cli_credentials_set_secrets from ldb " ) ;
r11995: A big kerberos-related update.
This merges Samba4 up to current lorikeet-heimdal, which includes a
replacement for some Samba-specific hacks.
In particular, the credentials system now supplies GSS client and
server credentials. These are imported into GSS with
gss_krb5_import_creds(). Unfortunetly this can't take an MEMORY
keytab, so we now create a FILE based keytab as provision and join
time.
Because the keytab is now created in advance, we don't spend .4s at
negprot doing sha1 s2k calls. Also, because the keytab is read in
real time, any change in the server key will be correctly picked up by
the the krb5 code.
To mark entries in the secrets which should be exported to a keytab,
there is a new kerberosSecret objectClass. The new routine
cli_credentials_update_all_keytabs() searches for these, and updates
the keytabs.
This is called in the provision.js via the ejs wrapper
credentials_update_all_keytabs().
We can now (in theory) use a system-provided /etc/krb5.keytab, if
krb5Keytab: FILE:/etc/krb5.keytab
is added to the secrets.ldb record. By default the attribute
privateKeytab: secrets.keytab
is set, pointing to allow the whole private directory to be moved
without breaking the internal links.
(This used to be commit 6b75573df49c6210e1b9d71e108a9490976bd41d)
2005-12-01 08:20:39 +03:00
2005-09-29 04:02:38 +04:00
if ( ! ldb ) {
2007-02-04 10:17:03 +03:00
/* Local secrets are stored in secrets.ldb */
2010-10-11 09:43:07 +04:00
ldb = secrets_db_connect ( mem_ctx , lp_ctx ) ;
2007-02-04 10:17:03 +03:00
if ( ! ldb ) {
2010-02-20 03:44:41 +03:00
* error_string = talloc_strdup ( cred , " Could not open secrets.ldb " ) ;
2008-07-15 09:05:41 +04:00
talloc_free ( mem_ctx ) ;
2007-02-04 10:17:03 +03:00
return NT_STATUS_CANT_ACCESS_DOMAIN_INFO ;
}
2005-09-29 04:02:38 +04:00
}
2010-10-12 03:05:32 +04:00
ldb_ret = dsdb_search_one ( ldb , mem_ctx , & msg ,
2010-02-20 03:44:41 +03:00
ldb_dn_new ( mem_ctx , ldb , base ) ,
LDB_SCOPE_SUBTREE ,
2010-07-28 11:30:09 +04:00
NULL , 0 , " %s " , filter ) ;
2010-02-20 03:44:41 +03:00
if ( ldb_ret ! = LDB_SUCCESS ) {
2012-07-15 06:50:02 +04:00
* error_string = talloc_asprintf ( cred , " Could not find entry to match filter: '%s' base: '%s': %s: %s " ,
2010-02-20 03:44:41 +03:00
filter , base ? base : " " ,
ldb_strerror ( ldb_ret ) , ldb_errstring ( ldb ) ) ;
2005-09-29 04:02:38 +04:00
talloc_free ( mem_ctx ) ;
return NT_STATUS_CANT_ACCESS_DOMAIN_INFO ;
}
2010-02-20 03:44:41 +03:00
password = ldb_msg_find_attr_as_string ( msg , " secret " , NULL ) ;
2012-08-29 03:44:12 +04:00
whenChanged = ldb_msg_find_ldb_val ( msg , " whenChanged " ) ;
if ( ! whenChanged | | ldb_val_to_time ( whenChanged , & lct ) ! = LDB_SUCCESS ) {
/* This attribute is mandetory */
talloc_free ( mem_ctx ) ;
return NT_STATUS_NOT_FOUND ;
}
/* Don't set secrets.ldb info if the secrets.tdb entry was more recent */
if ( lct < secrets_tdb_last_change_time ) {
talloc_free ( mem_ctx ) ;
return NT_STATUS_NOT_FOUND ;
}
if ( lct = = secrets_tdb_last_change_time & & secrets_tdb_password & & strcmp ( password , secrets_tdb_password ) ! = 0 ) {
talloc_free ( mem_ctx ) ;
return NT_STATUS_NOT_FOUND ;
}
cli_credentials_set_password_last_changed_time ( cred , lct ) ;
2010-02-20 03:44:41 +03:00
machine_account = ldb_msg_find_attr_as_string ( msg , " samAccountName " , NULL ) ;
2005-09-29 04:02:38 +04:00
if ( ! machine_account ) {
2010-02-20 03:44:41 +03:00
machine_account = ldb_msg_find_attr_as_string ( msg , " servicePrincipalName " , NULL ) ;
2007-08-28 08:35:29 +04:00
if ( ! machine_account ) {
2010-02-20 03:44:41 +03:00
const char * ldap_bind_dn = ldb_msg_find_attr_as_string ( msg , " ldapBindDn " , NULL ) ;
2008-07-15 09:05:41 +04:00
if ( ! ldap_bind_dn ) {
2010-02-20 03:44:41 +03:00
* error_string = talloc_asprintf ( cred ,
" Could not find 'samAccountName', "
" 'servicePrincipalName' or "
" 'ldapBindDn' in secrets record: %s " ,
ldb_dn_get_linearized ( msg - > dn ) ) ;
2008-07-15 09:05:41 +04:00
talloc_free ( mem_ctx ) ;
return NT_STATUS_CANT_ACCESS_DOMAIN_INFO ;
2009-10-09 23:30:51 +04:00
} else {
/* store bind dn in credentials */
cli_credentials_set_bind_dn ( cred , ldap_bind_dn ) ;
2008-07-15 09:05:41 +04:00
}
2007-08-28 08:35:29 +04:00
}
2005-09-29 04:02:38 +04:00
}
2005-10-20 14:28:16 +04:00
2010-02-20 03:44:41 +03:00
salt_principal = ldb_msg_find_attr_as_string ( msg , " saltPrincipal " , NULL ) ;
2005-10-20 14:28:16 +04:00
cli_credentials_set_salt_principal ( cred , salt_principal ) ;
2005-09-29 04:02:38 +04:00
2010-02-20 03:44:41 +03:00
sct = ldb_msg_find_attr_as_int ( msg , " secureChannelType " , 0 ) ;
2005-10-20 08:53:42 +04:00
if ( sct ) {
cli_credentials_set_secure_channel_type ( cred , sct ) ;
2005-09-29 04:02:38 +04:00
}
if ( ! password ) {
2010-02-20 03:44:41 +03:00
const struct ldb_val * nt_password_hash = ldb_msg_find_ldb_val ( msg , " unicodePwd " ) ;
2005-09-29 04:02:38 +04:00
struct samr_Password hash ;
ZERO_STRUCT ( hash ) ;
if ( nt_password_hash ) {
memcpy ( hash . hash , nt_password_hash - > data ,
MIN ( nt_password_hash - > length , sizeof ( hash . hash ) ) ) ;
cli_credentials_set_nt_hash ( cred , & hash , CRED_SPECIFIED ) ;
} else {
2006-01-24 08:31:08 +03:00
cli_credentials_set_password ( cred , NULL , CRED_SPECIFIED ) ;
2005-09-29 04:02:38 +04:00
}
2006-01-24 08:31:08 +03:00
} else {
cli_credentials_set_password ( cred , password , CRED_SPECIFIED ) ;
2005-09-29 04:02:38 +04:00
}
2006-01-24 08:31:08 +03:00
2005-09-29 04:02:38 +04:00
2010-02-20 03:44:41 +03:00
domain = ldb_msg_find_attr_as_string ( msg , " flatname " , NULL ) ;
2005-09-29 04:02:38 +04:00
if ( domain ) {
cli_credentials_set_domain ( cred , domain , CRED_SPECIFIED ) ;
}
2010-02-20 03:44:41 +03:00
realm = ldb_msg_find_attr_as_string ( msg , " realm " , NULL ) ;
2005-09-29 04:02:38 +04:00
if ( realm ) {
cli_credentials_set_realm ( cred , realm , CRED_SPECIFIED ) ;
}
2008-07-15 09:05:41 +04:00
if ( machine_account ) {
cli_credentials_set_username ( cred , machine_account , CRED_SPECIFIED ) ;
}
2005-09-29 04:02:38 +04:00
2010-02-20 03:44:41 +03:00
cli_credentials_set_kvno ( cred , ldb_msg_find_attr_as_int ( msg , " msDS-KeyVersionNumber " , 0 ) ) ;
r11995: A big kerberos-related update.
This merges Samba4 up to current lorikeet-heimdal, which includes a
replacement for some Samba-specific hacks.
In particular, the credentials system now supplies GSS client and
server credentials. These are imported into GSS with
gss_krb5_import_creds(). Unfortunetly this can't take an MEMORY
keytab, so we now create a FILE based keytab as provision and join
time.
Because the keytab is now created in advance, we don't spend .4s at
negprot doing sha1 s2k calls. Also, because the keytab is read in
real time, any change in the server key will be correctly picked up by
the the krb5 code.
To mark entries in the secrets which should be exported to a keytab,
there is a new kerberosSecret objectClass. The new routine
cli_credentials_update_all_keytabs() searches for these, and updates
the keytabs.
This is called in the provision.js via the ejs wrapper
credentials_update_all_keytabs().
We can now (in theory) use a system-provided /etc/krb5.keytab, if
krb5Keytab: FILE:/etc/krb5.keytab
is added to the secrets.ldb record. By default the attribute
privateKeytab: secrets.keytab
is set, pointing to allow the whole private directory to be moved
without breaking the internal links.
(This used to be commit 6b75573df49c6210e1b9d71e108a9490976bd41d)
2005-12-01 08:20:39 +03:00
/* If there was an external keytab specified by reference in
* the LDB , then use this . Otherwise we will make one up
* ( chewing CPU time ) from the password */
2010-09-23 11:01:44 +04:00
keytab = keytab_name_from_msg ( cred , ldb , msg ) ;
r11995: A big kerberos-related update.
This merges Samba4 up to current lorikeet-heimdal, which includes a
replacement for some Samba-specific hacks.
In particular, the credentials system now supplies GSS client and
server credentials. These are imported into GSS with
gss_krb5_import_creds(). Unfortunetly this can't take an MEMORY
keytab, so we now create a FILE based keytab as provision and join
time.
Because the keytab is now created in advance, we don't spend .4s at
negprot doing sha1 s2k calls. Also, because the keytab is read in
real time, any change in the server key will be correctly picked up by
the the krb5 code.
To mark entries in the secrets which should be exported to a keytab,
there is a new kerberosSecret objectClass. The new routine
cli_credentials_update_all_keytabs() searches for these, and updates
the keytabs.
This is called in the provision.js via the ejs wrapper
credentials_update_all_keytabs().
We can now (in theory) use a system-provided /etc/krb5.keytab, if
krb5Keytab: FILE:/etc/krb5.keytab
is added to the secrets.ldb record. By default the attribute
privateKeytab: secrets.keytab
is set, pointing to allow the whole private directory to be moved
without breaking the internal links.
(This used to be commit 6b75573df49c6210e1b9d71e108a9490976bd41d)
2005-12-01 08:20:39 +03:00
if ( keytab ) {
2010-10-11 09:53:08 +04:00
cli_credentials_set_keytab_name ( cred , lp_ctx , keytab , CRED_SPECIFIED ) ;
2010-09-23 11:01:44 +04:00
talloc_free ( keytab ) ;
r11995: A big kerberos-related update.
This merges Samba4 up to current lorikeet-heimdal, which includes a
replacement for some Samba-specific hacks.
In particular, the credentials system now supplies GSS client and
server credentials. These are imported into GSS with
gss_krb5_import_creds(). Unfortunetly this can't take an MEMORY
keytab, so we now create a FILE based keytab as provision and join
time.
Because the keytab is now created in advance, we don't spend .4s at
negprot doing sha1 s2k calls. Also, because the keytab is read in
real time, any change in the server key will be correctly picked up by
the the krb5 code.
To mark entries in the secrets which should be exported to a keytab,
there is a new kerberosSecret objectClass. The new routine
cli_credentials_update_all_keytabs() searches for these, and updates
the keytabs.
This is called in the provision.js via the ejs wrapper
credentials_update_all_keytabs().
We can now (in theory) use a system-provided /etc/krb5.keytab, if
krb5Keytab: FILE:/etc/krb5.keytab
is added to the secrets.ldb record. By default the attribute
privateKeytab: secrets.keytab
is set, pointing to allow the whole private directory to be moved
without breaking the internal links.
(This used to be commit 6b75573df49c6210e1b9d71e108a9490976bd41d)
2005-12-01 08:20:39 +03:00
}
2005-09-29 04:02:38 +04:00
talloc_free ( mem_ctx ) ;
return NT_STATUS_OK ;
}
2012-08-29 03:44:12 +04:00
/**
* Fill in credentials for the machine trust account , from the secrets database .
*
* @ param cred Credentials structure to fill in
* @ retval NTSTATUS error detailing any failure
*/
_PUBLIC_ NTSTATUS cli_credentials_set_secrets ( struct cli_credentials * cred ,
struct loadparm_context * lp_ctx ,
struct ldb_context * ldb ,
const char * base ,
const char * filter ,
char * * error_string )
{
NTSTATUS status = cli_credentials_set_secrets_lct ( cred , lp_ctx , ldb , base , filter , 0 , NULL , error_string ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
/* set anonymous as the fallback, if the machine account won't work */
cli_credentials_set_anonymous ( cred ) ;
}
return status ;
}
2005-10-20 07:47:55 +04:00
/**
* Fill in credentials for the machine trust account , from the secrets database .
*
* @ param cred Credentials structure to fill in
* @ retval NTSTATUS error detailing any failure
*/
2008-04-02 06:53:27 +04:00
_PUBLIC_ NTSTATUS cli_credentials_set_machine_account ( struct cli_credentials * cred ,
2008-04-05 14:39:26 +04:00
struct loadparm_context * lp_ctx )
2014-10-02 21:32:39 +04:00
{
struct db_context * db_ctx ;
char * secrets_tdb_path ;
secrets_tdb_path = lpcfg_private_db_path ( cred , lp_ctx , " secrets " ) ;
if ( secrets_tdb_path = = NULL ) {
return NT_STATUS_NO_MEMORY ;
}
db_ctx = dbwrap_local_open ( cred , lp_ctx , secrets_tdb_path , 0 ,
TDB_DEFAULT , O_RDWR , 0600 ,
DBWRAP_LOCK_ORDER_1 ,
DBWRAP_FLAG_NONE ) ;
TALLOC_FREE ( secrets_tdb_path ) ;
/*
* We do not check for errors here , we might not have a
* secrets . tdb at all , and so we just need to check the
* secrets . ldb
*/
return cli_credentials_set_machine_account_db_ctx ( cred , lp_ctx , db_ctx ) ;
}
/**
* Fill in credentials for the machine trust account , from the
* secrets . ldb or passed in handle to secrets . tdb ( perhaps in CTDB ) .
*
* This version is used in parts of the code that can link in the
* CTDB dbwrap backend , by passing down the already open handle .
*
* @ param cred Credentials structure to fill in
* @ param db_ctx dbwrap context for secrets . tdb
* @ retval NTSTATUS error detailing any failure
*/
_PUBLIC_ NTSTATUS cli_credentials_set_machine_account_db_ctx ( struct cli_credentials * cred ,
struct loadparm_context * lp_ctx ,
struct db_context * db_ctx )
2005-10-20 07:47:55 +04:00
{
2008-07-15 09:05:41 +04:00
NTSTATUS status ;
2005-12-14 10:22:25 +03:00
char * filter ;
2010-02-20 03:44:41 +03:00
char * error_string ;
2012-07-14 16:23:41 +04:00
const char * domain ;
2012-08-27 15:37:19 +04:00
bool secrets_tdb_password_more_recent ;
time_t secrets_tdb_lct = 0 ;
char * secrets_tdb_password = NULL ;
2013-07-31 15:39:17 +04:00
char * secrets_tdb_old_password = NULL ;
2014-10-02 20:14:21 +04:00
uint32_t secrets_tdb_secure_channel_type = SEC_CHAN_NULL ;
2012-08-27 15:37:19 +04:00
char * keystr ;
char * keystr_upper = NULL ;
2012-08-29 03:21:52 +04:00
TALLOC_CTX * tmp_ctx = talloc_named ( cred , 0 , " cli_credentials_set_secrets from ldb " ) ;
if ( ! tmp_ctx ) {
return NT_STATUS_NO_MEMORY ;
}
2014-10-02 21:32:39 +04:00
2005-12-14 10:22:25 +03:00
/* Bleh, nasty recursion issues: We are setting a machine
* account here , so we don ' t want the ' pending ' flag around
* any more */
2007-10-07 02:16:19 +04:00
cred - > machine_account_pending = false ;
2012-07-14 16:23:41 +04:00
/* We have to do this, as the fallback in
* cli_credentials_set_secrets is to run as anonymous , so the domain is wiped */
domain = cli_credentials_get_domain ( cred ) ;
2012-08-27 15:37:19 +04:00
if ( db_ctx ) {
TDB_DATA dbuf ;
2012-08-29 03:21:52 +04:00
keystr = talloc_asprintf ( tmp_ctx , " %s/%s " ,
2012-08-27 15:37:19 +04:00
SECRETS_MACHINE_LAST_CHANGE_TIME ,
domain ) ;
2012-08-29 03:21:52 +04:00
keystr_upper = strupper_talloc ( tmp_ctx , keystr ) ;
status = dbwrap_fetch ( db_ctx , tmp_ctx , string_tdb_data ( keystr_upper ) ,
2012-08-27 15:37:19 +04:00
& dbuf ) ;
if ( NT_STATUS_IS_OK ( status ) & & dbuf . dsize = = 4 ) {
secrets_tdb_lct = IVAL ( dbuf . dptr , 0 ) ;
}
2012-08-29 03:21:52 +04:00
keystr = talloc_asprintf ( tmp_ctx , " %s/%s " ,
2012-08-27 15:37:19 +04:00
SECRETS_MACHINE_PASSWORD ,
domain ) ;
2012-08-29 03:21:52 +04:00
keystr_upper = strupper_talloc ( tmp_ctx , keystr ) ;
status = dbwrap_fetch ( db_ctx , tmp_ctx , string_tdb_data ( keystr_upper ) ,
2012-08-27 15:37:19 +04:00
& dbuf ) ;
if ( NT_STATUS_IS_OK ( status ) ) {
secrets_tdb_password = ( char * ) dbuf . dptr ;
}
2014-10-02 20:14:21 +04:00
2013-07-31 15:39:17 +04:00
keystr = talloc_asprintf ( tmp_ctx , " %s/%s " ,
SECRETS_MACHINE_PASSWORD_PREV ,
domain ) ;
keystr_upper = strupper_talloc ( tmp_ctx , keystr ) ;
status = dbwrap_fetch ( db_ctx , tmp_ctx , string_tdb_data ( keystr_upper ) ,
& dbuf ) ;
if ( NT_STATUS_IS_OK ( status ) ) {
secrets_tdb_old_password = ( char * ) dbuf . dptr ;
}
2014-10-02 20:14:21 +04:00
keystr = talloc_asprintf ( tmp_ctx , " %s/%s " ,
SECRETS_MACHINE_SEC_CHANNEL_TYPE ,
domain ) ;
keystr_upper = strupper_talloc ( tmp_ctx , keystr ) ;
status = dbwrap_fetch ( db_ctx , tmp_ctx , string_tdb_data ( keystr_upper ) ,
& dbuf ) ;
if ( NT_STATUS_IS_OK ( status ) & & dbuf . dsize = = 4 ) {
secrets_tdb_secure_channel_type = IVAL ( dbuf . dptr , 0 ) ;
}
2012-08-27 15:37:19 +04:00
}
2005-12-14 10:22:25 +03:00
filter = talloc_asprintf ( cred , SECRETS_PRIMARY_DOMAIN_FILTER ,
2012-07-14 16:23:41 +04:00
domain ) ;
2012-08-29 03:44:12 +04:00
status = cli_credentials_set_secrets_lct ( cred , lp_ctx , NULL ,
SECRETS_PRIMARY_DOMAIN_DN ,
filter , secrets_tdb_lct , secrets_tdb_password , & error_string ) ;
2012-08-27 15:37:19 +04:00
if ( secrets_tdb_password = = NULL ) {
secrets_tdb_password_more_recent = false ;
} else if ( NT_STATUS_EQUAL ( NT_STATUS_CANT_ACCESS_DOMAIN_INFO , status )
2012-07-14 16:23:41 +04:00
| | NT_STATUS_EQUAL ( NT_STATUS_NOT_FOUND , status ) ) {
2012-08-27 15:37:19 +04:00
secrets_tdb_password_more_recent = true ;
} else if ( secrets_tdb_lct > cli_credentials_get_password_last_changed_time ( cred ) ) {
secrets_tdb_password_more_recent = true ;
} else if ( secrets_tdb_lct = = cli_credentials_get_password_last_changed_time ( cred ) ) {
secrets_tdb_password_more_recent = strcmp ( secrets_tdb_password , cli_credentials_get_password ( cred ) ) ! = 0 ;
} else {
secrets_tdb_password_more_recent = false ;
}
if ( secrets_tdb_password_more_recent ) {
2012-08-29 03:21:52 +04:00
char * machine_account = talloc_asprintf ( tmp_ctx , " %s$ " , lpcfg_netbios_name ( lp_ctx ) ) ;
2012-08-27 15:37:19 +04:00
cli_credentials_set_password ( cred , secrets_tdb_password , CRED_SPECIFIED ) ;
2013-07-31 15:39:17 +04:00
cli_credentials_set_old_password ( cred , secrets_tdb_old_password , CRED_SPECIFIED ) ;
2012-08-27 15:37:19 +04:00
cli_credentials_set_domain ( cred , domain , CRED_SPECIFIED ) ;
cli_credentials_set_username ( cred , machine_account , CRED_SPECIFIED ) ;
2014-09-23 03:43:18 +04:00
cli_credentials_set_password_last_changed_time ( cred , secrets_tdb_lct ) ;
2014-10-02 20:14:21 +04:00
cli_credentials_set_secure_channel_type ( cred , secrets_tdb_secure_channel_type ) ;
2014-09-23 03:43:18 +04:00
status = NT_STATUS_OK ;
2012-08-29 03:21:52 +04:00
} else if ( ! NT_STATUS_IS_OK ( status ) ) {
2012-07-14 16:23:41 +04:00
if ( db_ctx ) {
2014-10-02 20:14:56 +04:00
error_string
= talloc_asprintf ( cred ,
" Failed to fetch machine account password for %s from both "
" secrets.ldb (%s) and from %s " ,
domain , error_string ,
dbwrap_name ( db_ctx ) ) ;
2012-08-27 15:37:19 +04:00
} else {
2014-10-02 21:32:39 +04:00
char * secrets_tdb_path ;
secrets_tdb_path = lpcfg_private_db_path ( tmp_ctx ,
lp_ctx ,
" secrets " ) ;
if ( secrets_tdb_path = = NULL ) {
return NT_STATUS_NO_MEMORY ;
}
2012-08-27 15:37:19 +04:00
error_string = talloc_asprintf ( cred ,
" Failed to fetch machine account password from "
" secrets.ldb: %s and failed to open %s " ,
2014-10-02 21:32:39 +04:00
error_string , secrets_tdb_path ) ;
2012-07-14 16:23:41 +04:00
}
DEBUG ( 1 , ( " Could not find machine account in secrets database: %s: %s \n " ,
error_string , nt_errstr ( status ) ) ) ;
2012-08-29 03:44:12 +04:00
/* set anonymous as the fallback, if the machine account won't work */
cli_credentials_set_anonymous ( cred ) ;
2008-07-15 09:05:41 +04:00
}
2012-08-29 03:21:52 +04:00
TALLOC_FREE ( tmp_ctx ) ;
2008-07-15 09:05:41 +04:00
return status ;
2005-10-20 07:47:55 +04:00
}
/**
2008-07-15 09:05:41 +04:00
* Fill in credentials for a particular prinicpal , from the secrets database .
2005-10-20 07:47:55 +04:00
*
* @ param cred Credentials structure to fill in
* @ retval NTSTATUS error detailing any failure
*/
2008-04-02 06:53:27 +04:00
_PUBLIC_ NTSTATUS cli_credentials_set_stored_principal ( struct cli_credentials * cred ,
2007-12-14 00:46:17 +03:00
struct loadparm_context * lp_ctx ,
2005-10-20 07:47:55 +04:00
const char * serviceprincipal )
{
2008-07-15 09:05:41 +04:00
NTSTATUS status ;
2005-12-14 10:22:25 +03:00
char * filter ;
2010-02-20 03:44:41 +03:00
char * error_string ;
2005-12-14 10:22:25 +03:00
/* Bleh, nasty recursion issues: We are setting a machine
* account here , so we don ' t want the ' pending ' flag around
* any more */
2007-10-07 02:16:19 +04:00
cred - > machine_account_pending = false ;
2005-12-14 10:22:25 +03:00
filter = talloc_asprintf ( cred , SECRETS_PRINCIPAL_SEARCH ,
cli_credentials_get_realm ( cred ) ,
cli_credentials_get_domain ( cred ) ,
serviceprincipal ) ;
2012-08-29 03:44:12 +04:00
status = cli_credentials_set_secrets_lct ( cred , lp_ctx , NULL ,
2010-02-20 03:44:41 +03:00
SECRETS_PRINCIPALS_DN , filter ,
2012-08-29 03:44:12 +04:00
0 , NULL , & error_string ) ;
2008-07-15 09:05:41 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2011-10-05 10:07:51 +04:00
DEBUG ( 1 , ( " Could not find %s principal in secrets database: %s: %s \n " , serviceprincipal , nt_errstr ( status ) , error_string ) ) ;
2008-07-15 09:05:41 +04:00
}
return status ;
2005-10-20 07:47:55 +04:00
}
2005-09-29 04:02:38 +04:00
/**
* Ask that when required , the credentials system will be filled with
* machine trust account , from the secrets database .
*
* @ param cred Credentials structure to fill in
* @ note This function is used to call the above function after , rather
* than during , popt processing .
*
*/
2008-04-02 06:53:27 +04:00
_PUBLIC_ void cli_credentials_set_machine_account_pending ( struct cli_credentials * cred ,
2007-12-14 00:46:17 +03:00
struct loadparm_context * lp_ctx )
2005-09-29 04:02:38 +04:00
{
2007-10-07 02:16:19 +04:00
cred - > machine_account_pending = true ;
2007-12-14 00:46:17 +03:00
cred - > machine_account_pending_lp_ctx = lp_ctx ;
2005-09-29 04:02:38 +04:00
}
r11995: A big kerberos-related update.
This merges Samba4 up to current lorikeet-heimdal, which includes a
replacement for some Samba-specific hacks.
In particular, the credentials system now supplies GSS client and
server credentials. These are imported into GSS with
gss_krb5_import_creds(). Unfortunetly this can't take an MEMORY
keytab, so we now create a FILE based keytab as provision and join
time.
Because the keytab is now created in advance, we don't spend .4s at
negprot doing sha1 s2k calls. Also, because the keytab is read in
real time, any change in the server key will be correctly picked up by
the the krb5 code.
To mark entries in the secrets which should be exported to a keytab,
there is a new kerberosSecret objectClass. The new routine
cli_credentials_update_all_keytabs() searches for these, and updates
the keytabs.
This is called in the provision.js via the ejs wrapper
credentials_update_all_keytabs().
We can now (in theory) use a system-provided /etc/krb5.keytab, if
krb5Keytab: FILE:/etc/krb5.keytab
is added to the secrets.ldb record. By default the attribute
privateKeytab: secrets.keytab
is set, pointing to allow the whole private directory to be moved
without breaking the internal links.
(This used to be commit 6b75573df49c6210e1b9d71e108a9490976bd41d)
2005-12-01 08:20:39 +03:00