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"
2005-09-29 04:02:38 +04:00
# include "lib/ldb/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"
2008-10-11 23:31:42 +04:00
# include "../lib/util/util_ldb.h"
2006-03-14 04:29:56 +03:00
# include "auth/credentials/credentials.h"
2006-11-07 03:48:36 +03:00
# include "auth/credentials/credentials_krb5.h"
2008-10-20 20:59:51 +04:00
# include "auth/credentials/credentials_proto.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"
2005-09-29 04:02:38 +04:00
/**
* Read a file descriptor , and parse it for a password ( eg from a file or stdin )
*
* @ param credentials Credentials structure on which to set the password
* @ param fd open file descriptor to read the password from
* @ param obtained This enum describes how ' specified ' this password is
*/
2008-04-02 06:53:27 +04:00
_PUBLIC_ bool cli_credentials_parse_password_fd ( struct cli_credentials * credentials ,
2005-09-29 04:02:38 +04:00
int fd , enum credentials_obtained obtained )
{
char * p ;
char pass [ 128 ] ;
for ( p = pass , * p = ' \0 ' ; /* ensure that pass is null-terminated */
p & & p - pass < sizeof ( pass ) ; ) {
switch ( read ( fd , p , 1 ) ) {
case 1 :
if ( * p ! = ' \n ' & & * p ! = ' \0 ' ) {
* + + p = ' \0 ' ; /* advance p, and null-terminate pass */
break ;
}
2006-04-08 06:44:37 +04:00
/* fall through */
2005-09-29 04:02:38 +04:00
case 0 :
if ( p - pass ) {
* p = ' \0 ' ; /* null-terminate it, just in case... */
p = NULL ; /* then force the loop condition to become false */
break ;
} else {
fprintf ( stderr , " Error reading password from file descriptor %d: %s \n " , fd , " empty password \n " ) ;
2007-10-07 02:16:19 +04:00
return false ;
2005-09-29 04:02:38 +04:00
}
default :
fprintf ( stderr , " Error reading password from file descriptor %d: %s \n " ,
fd , strerror ( errno ) ) ;
2007-10-07 02:16:19 +04:00
return false ;
2005-09-29 04:02:38 +04:00
}
}
cli_credentials_set_password ( credentials , pass , obtained ) ;
2007-10-07 02:16:19 +04:00
return true ;
2005-09-29 04:02:38 +04:00
}
/**
* Read a named file , and parse it for a password
*
* @ param credentials Credentials structure on which to set the password
* @ param file a named file to read the password from
* @ param obtained This enum describes how ' specified ' this password is
*/
2008-04-02 06:53:27 +04:00
_PUBLIC_ bool cli_credentials_parse_password_file ( struct cli_credentials * credentials , const char * file , enum credentials_obtained obtained )
2005-09-29 04:02:38 +04:00
{
int fd = open ( file , O_RDONLY , 0 ) ;
2007-10-07 02:16:19 +04:00
bool ret ;
2005-09-29 04:02:38 +04:00
if ( fd < 0 ) {
2007-03-07 07:20:10 +03:00
fprintf ( stderr , " Error opening password file %s: %s \n " ,
2005-09-29 04:02:38 +04:00
file , strerror ( errno ) ) ;
2007-10-07 02:16:19 +04:00
return false ;
2005-09-29 04:02:38 +04:00
}
ret = cli_credentials_parse_password_fd ( credentials , fd , obtained ) ;
close ( fd ) ;
return ret ;
}
/**
* Read a named file , and parse it for username , domain , realm and password
*
* @ param credentials Credentials structure on which to set the password
* @ param file a named file to read the details from
* @ param obtained This enum describes how ' specified ' this password is
*/
2008-04-02 06:53:27 +04:00
_PUBLIC_ bool cli_credentials_parse_file ( struct cli_credentials * cred , const char * file , enum credentials_obtained obtained )
2005-09-29 04:02:38 +04:00
{
uint16_t len = 0 ;
char * ptr , * val , * param ;
char * * lines ;
int i , numlines ;
2008-10-12 19:34:43 +04:00
lines = file_lines_load ( file , & numlines , 0 , NULL ) ;
2005-09-29 04:02:38 +04:00
if ( lines = = NULL )
{
/* fail if we can't open the credentials file */
d_printf ( " ERROR: Unable to open credentials file! \n " ) ;
2007-10-07 02:16:19 +04:00
return false ;
2005-09-29 04:02:38 +04:00
}
for ( i = 0 ; i < numlines ; i + + ) {
len = strlen ( lines [ i ] ) ;
if ( len = = 0 )
continue ;
/* break up the line into parameter & value.
* will need to eat a little whitespace possibly */
param = lines [ i ] ;
if ( ! ( ptr = strchr_m ( lines [ i ] , ' = ' ) ) )
continue ;
val = ptr + 1 ;
* ptr = ' \0 ' ;
/* eat leading white space */
while ( ( * val ! = ' \0 ' ) & & ( ( * val = = ' ' ) | | ( * val = = ' \t ' ) ) )
val + + ;
if ( strwicmp ( " password " , param ) = = 0 ) {
cli_credentials_set_password ( cred , val , obtained ) ;
} else if ( strwicmp ( " username " , param ) = = 0 ) {
cli_credentials_set_username ( cred , val , obtained ) ;
} else if ( strwicmp ( " domain " , param ) = = 0 ) {
cli_credentials_set_domain ( cred , val , obtained ) ;
} else if ( strwicmp ( " realm " , param ) = = 0 ) {
cli_credentials_set_realm ( cred , val , obtained ) ;
}
memset ( lines [ i ] , 0 , len ) ;
}
talloc_free ( lines ) ;
2007-10-07 02:16:19 +04:00
return true ;
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
*/
2008-04-02 06:53:27 +04:00
_PUBLIC_ NTSTATUS cli_credentials_set_secrets ( struct cli_credentials * cred ,
2008-12-29 22:24:57 +03:00
struct tevent_context * event_ctx ,
2010-02-20 03:44:41 +03:00
struct loadparm_context * lp_ctx ,
struct ldb_context * ldb ,
const char * base ,
const char * filter ,
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 * attrs [ ] = {
" secret " ,
2005-10-20 09:09:58 +04:00
" priorSecret " ,
2005-09-29 04:02:38 +04:00
" samAccountName " ,
" flatname " ,
" realm " ,
" secureChannelType " ,
2007-02-15 15:54:58 +03:00
" unicodePwd " ,
2005-09-29 04:02:38 +04:00
" msDS-KeyVersionNumber " ,
2005-10-20 14:28:16 +04:00
" saltPrincipal " ,
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
" privateKeytab " ,
" krb5Keytab " ,
2007-08-28 08:35:29 +04:00
" servicePrincipalName " ,
2008-07-15 09:05:41 +04:00
" ldapBindDn " ,
2005-09-29 04:02:38 +04:00
NULL
} ;
const char * machine_account ;
const char * password ;
2005-10-20 07:47:55 +04:00
const char * old_password ;
2005-09-29 04:02:38 +04:00
const char * domain ;
const char * realm ;
enum netr_SchannelType sct ;
2005-10-20 14:28:16 +04:00
const char * salt_principal ;
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
const char * keytab ;
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
2005-09-29 04:02:38 +04:00
mem_ctx = talloc_named ( cred , 0 , " cli_credentials fetch machine password " ) ;
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 */
2008-06-14 19:24:17 +04:00
ldb = secrets_db_connect ( mem_ctx , event_ctx , lp_ctx ) ;
2007-02-04 10:17:03 +03:00
if ( ! ldb ) {
/* set anonymous as the fallback, if the machine account won't work */
cli_credentials_set_anonymous ( cred ) ;
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-02-20 03:44:41 +03:00
ldb_ret = dsdb_search_one ( ldb , ldb , & msg ,
ldb_dn_new ( mem_ctx , ldb , base ) ,
LDB_SCOPE_SUBTREE ,
attrs , 0 , " %s " , filter ) ;
if ( ldb_ret ! = LDB_SUCCESS ) {
* error_string = talloc_asprintf ( cred , " Could not find entry to match filter: '%s' base: '%s': %s: %s \n " ,
filter , base ? base : " " ,
ldb_strerror ( ldb_ret ) , ldb_errstring ( ldb ) ) ;
2005-12-14 10:22:25 +03:00
/* set anonymous as the fallback, if the machine account won't work */
cli_credentials_set_anonymous ( cred ) ;
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 ) ;
old_password = ldb_msg_find_attr_as_string ( msg , " priorSecret " , NULL ) ;
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
/* set anonymous as the fallback, if the machine account won't work */
cli_credentials_set_anonymous ( cred ) ;
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-02-20 03:44:41 +03:00
keytab = ldb_msg_find_attr_as_string ( msg , " krb5Keytab " , NULL ) ;
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 ) {
2008-04-17 03:03:18 +04:00
cli_credentials_set_keytab_name ( cred , event_ctx , lp_ctx , keytab , CRED_SPECIFIED ) ;
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
} else {
2010-02-20 03:44:41 +03:00
keytab = ldb_msg_find_attr_as_string ( msg , " privateKeytab " , NULL ) ;
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 ) {
2009-10-28 08:49:30 +03:00
keytab = talloc_asprintf ( mem_ctx , " FILE:%s " , samdb_relative_path ( ldb , mem_ctx , 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
if ( keytab ) {
2008-04-17 03:03:18 +04:00
cli_credentials_set_keytab_name ( cred , event_ctx , lp_ctx , keytab , CRED_SPECIFIED ) ;
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 ;
}
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 )
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 ;
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_PRIMARY_DOMAIN_FILTER ,
2005-10-20 07:47:55 +04:00
cli_credentials_get_domain ( cred ) ) ;
2008-07-15 09:05:41 +04:00
status = cli_credentials_set_secrets ( cred , event_context_find ( cred ) , lp_ctx , NULL ,
2007-12-04 01:33:16 +03:00
SECRETS_PRIMARY_DOMAIN_DN ,
2010-02-20 03:44:41 +03:00
filter , & error_string ) ;
2008-07-15 09:05:41 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2010-02-20 03:44:41 +03:00
DEBUG ( 1 , ( " Could not find machine account in secrets database: %s: %s " , nt_errstr ( status ) , error_string ) ) ;
talloc_free ( error_string ) ;
2008-07-15 09:05:41 +04:00
}
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
*/
2007-12-04 01:33:22 +03:00
NTSTATUS cli_credentials_set_krbtgt ( struct cli_credentials * cred ,
2008-12-29 22:24:57 +03:00
struct tevent_context * event_ctx ,
2007-12-04 01:33:22 +03:00
struct loadparm_context * lp_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 ;
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_KRBTGT_SEARCH ,
2005-10-20 07:47:55 +04:00
cli_credentials_get_realm ( cred ) ,
cli_credentials_get_domain ( cred ) ) ;
2008-07-15 09:05:41 +04:00
status = cli_credentials_set_secrets ( cred , event_ctx , lp_ctx , NULL ,
2010-02-20 03:44:41 +03:00
SECRETS_PRINCIPALS_DN ,
filter , & error_string ) ;
2008-07-15 09:05:41 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2010-02-20 03:44:41 +03:00
DEBUG ( 1 , ( " Could not find krbtgt (master Kerberos) account in secrets database: %s: %s " , nt_errstr ( status ) , error_string ) ) ;
talloc_free ( error_string ) ;
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 ,
2008-12-29 22:24:57 +03:00
struct tevent_context * event_ctx ,
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 ) ;
2008-07-15 09:05:41 +04:00
status = cli_credentials_set_secrets ( cred , event_ctx , lp_ctx , NULL ,
2010-02-20 03:44:41 +03:00
SECRETS_PRINCIPALS_DN , filter ,
& error_string ) ;
2008-07-15 09:05:41 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2010-02-20 03:44:41 +03:00
DEBUG ( 1 , ( " Could not find %s principal in secrets database: %s: %s " , 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