2003-08-13 01:53:07 +00:00
/*
Unix SMB / CIFS implementation .
simple kerberos5 routines for active directory
Copyright ( C ) Andrew Tridgell 2001
Copyright ( C ) Luke Howard 2002 - 2003
2005-06-04 11:17:05 +00:00
Copyright ( C ) Andrew Bartlett < abartlet @ samba . org > 2005
2005-10-20 10:15:31 +00:00
2003-08-13 01:53:07 +00: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-10 02:07:03 +00:00
the Free Software Foundation ; either version 3 of the License , or
2003-08-13 01:53:07 +00: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 02:07:03 +00:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2003-08-13 01:53:07 +00:00
*/
# include "includes.h"
2004-11-01 22:48:25 +00:00
# include "system/network.h"
# include "system/kerberos.h"
2005-02-11 10:15:56 +00:00
# include "system/time.h"
2005-03-29 08:24:03 +00:00
# include "auth/kerberos/kerberos.h"
2003-08-13 01:53:07 +00:00
# ifdef HAVE_KRB5
2004-12-24 09:54:23 +00:00
# if defined(HAVE_KRB5_PRINCIPAL2SALT) && defined(HAVE_KRB5_USE_ENCTYPE) && defined(HAVE_KRB5_STRING_TO_KEY) && defined(HAVE_KRB5_ENCRYPT_BLOCK)
2005-08-20 06:08:52 +00:00
int create_kerberos_key_from_string ( krb5_context context ,
2003-08-13 01:53:07 +00:00
krb5_principal host_princ ,
krb5_data * password ,
krb5_keyblock * key ,
krb5_enctype enctype )
{
int ret ;
krb5_data salt ;
krb5_encrypt_block eblock ;
ret = krb5_principal2salt ( context , host_princ , & salt ) ;
if ( ret ) {
DEBUG ( 1 , ( " krb5_principal2salt failed (%s) \n " , error_message ( ret ) ) ) ;
return ret ;
}
krb5_use_enctype ( context , & eblock , enctype ) ;
2004-02-01 11:26:25 +00:00
ret = krb5_string_to_key ( context , & eblock , key , password , & salt ) ;
SAFE_FREE ( salt . data ) ;
return ret ;
2003-08-13 01:53:07 +00:00
}
# elif defined(HAVE_KRB5_GET_PW_SALT) && defined(HAVE_KRB5_STRING_TO_KEY_SALT)
2005-08-20 06:08:52 +00:00
int create_kerberos_key_from_string ( krb5_context context ,
2003-08-13 01:53:07 +00:00
krb5_principal host_princ ,
krb5_data * password ,
krb5_keyblock * key ,
krb5_enctype enctype )
{
int ret ;
krb5_salt salt ;
ret = krb5_get_pw_salt ( context , host_princ , & salt ) ;
if ( ret ) {
DEBUG ( 1 , ( " krb5_get_pw_salt failed (%s) \n " , error_message ( ret ) ) ) ;
return ret ;
}
2005-10-12 22:24:43 +00:00
ret = krb5_string_to_key_salt ( context , enctype , password - > data ,
salt , key ) ;
krb5_free_salt ( context , salt ) ;
return ret ;
2003-08-13 01:53:07 +00:00
}
# else
2004-12-24 09:54:23 +00:00
# error UNKNOWN_CREATE_KEY_FUNCTIONS
2004-06-19 08:15:41 +00:00
# endif
2004-12-24 09:54:23 +00:00
void kerberos_free_data_contents ( krb5_context context , krb5_data * pdata )
{
if ( pdata - > data ) {
2009-03-25 12:21:36 +01:00
krb5_data_free ( pdata ) ;
2004-12-24 09:54:23 +00:00
}
}
2004-07-09 11:46:42 +00:00
krb5_error_code smb_krb5_kt_free_entry ( krb5_context context , krb5_keytab_entry * kt_entry )
{
# if defined(HAVE_KRB5_KT_FREE_ENTRY)
return krb5_kt_free_entry ( context , kt_entry ) ;
# elif defined(HAVE_KRB5_FREE_KEYTAB_ENTRY_CONTENTS)
return krb5_free_keytab_entry_contents ( context , kt_entry ) ;
# else
# error UNKNOWN_KT_FREE_FUNCTION
# endif
}
2005-03-28 06:40:18 +00:00
char * smb_get_krb5_error_message ( krb5_context context , krb5_error_code code , TALLOC_CTX * mem_ctx )
{
char * ret ;
2009-06-08 19:06:16 +10:00
# if defined(HAVE_KRB5_GET_ERROR_MESSAGE) && defined(HAVE_KRB5_FREE_ERROR_MESSAGE)
const char * context_error = krb5_get_error_message ( context , code ) ;
r10066: This is the second in my patches to work on Samba4's kerberos support,
with an aim to make the code simpiler and more correct.
Gone is the old (since the very early Samba 3.0 krb5 days) 'iterate over
all keytypes)' code in gensec_krb5, we now follow the approach used in
gensec_gssapi, and use a keytab.
I have also done a lot of work in the GSSAPI code, to try and reduce
the diff between us and upstream heimdal. It was becoming hard to
track patches in this code, and I also want this patch (the DCE_STYLE
support) to be in a 'manageable' state for when lha considers it for
merging. (metze assures me it still has memory leak problems, but
I've started to address some of that).
This patch also includes a simple update of other code to current
heimdal, as well as changes we need for better PAC verification.
On the PAC side of things we now match windows member servers by
checking the name and authtime on an incoming PAC. Not generating these
right was the cause of the PAC pain, and so now both the main code and
torture test validate this behaviour.
One thing doesn't work with this patch:
- the sealing of RPC pipes with kerberos, Samba -> Samba seems
broken. I'm pretty sure this is related to AES, and the need to break
apart the gss_wrap interface.
Andrew Bartlett
(This used to be commit a3aba57c00a9c5318f4706db55d03f64e8bea60c)
2005-09-07 21:52:50 +00:00
if ( context_error ) {
ret = talloc_asprintf ( mem_ctx , " %s: %s " , error_message ( code ) , context_error ) ;
2009-06-08 19:06:16 +10:00
krb5_free_error_message ( context , context_error ) ;
r10066: This is the second in my patches to work on Samba4's kerberos support,
with an aim to make the code simpiler and more correct.
Gone is the old (since the very early Samba 3.0 krb5 days) 'iterate over
all keytypes)' code in gensec_krb5, we now follow the approach used in
gensec_gssapi, and use a keytab.
I have also done a lot of work in the GSSAPI code, to try and reduce
the diff between us and upstream heimdal. It was becoming hard to
track patches in this code, and I also want this patch (the DCE_STYLE
support) to be in a 'manageable' state for when lha considers it for
merging. (metze assures me it still has memory leak problems, but
I've started to address some of that).
This patch also includes a simple update of other code to current
heimdal, as well as changes we need for better PAC verification.
On the PAC side of things we now match windows member servers by
checking the name and authtime on an incoming PAC. Not generating these
right was the cause of the PAC pain, and so now both the main code and
torture test validate this behaviour.
One thing doesn't work with this patch:
- the sealing of RPC pipes with kerberos, Samba -> Samba seems
broken. I'm pretty sure this is related to AES, and the need to break
apart the gss_wrap interface.
Andrew Bartlett
(This used to be commit a3aba57c00a9c5318f4706db55d03f64e8bea60c)
2005-09-07 21:52:50 +00:00
return ret ;
}
2005-03-28 06:40:18 +00:00
# endif
r10066: This is the second in my patches to work on Samba4's kerberos support,
with an aim to make the code simpiler and more correct.
Gone is the old (since the very early Samba 3.0 krb5 days) 'iterate over
all keytypes)' code in gensec_krb5, we now follow the approach used in
gensec_gssapi, and use a keytab.
I have also done a lot of work in the GSSAPI code, to try and reduce
the diff between us and upstream heimdal. It was becoming hard to
track patches in this code, and I also want this patch (the DCE_STYLE
support) to be in a 'manageable' state for when lha considers it for
merging. (metze assures me it still has memory leak problems, but
I've started to address some of that).
This patch also includes a simple update of other code to current
heimdal, as well as changes we need for better PAC verification.
On the PAC side of things we now match windows member servers by
checking the name and authtime on an incoming PAC. Not generating these
right was the cause of the PAC pain, and so now both the main code and
torture test validate this behaviour.
One thing doesn't work with this patch:
- the sealing of RPC pipes with kerberos, Samba -> Samba seems
broken. I'm pretty sure this is related to AES, and the need to break
apart the gss_wrap interface.
Andrew Bartlett
(This used to be commit a3aba57c00a9c5318f4706db55d03f64e8bea60c)
2005-09-07 21:52:50 +00:00
ret = talloc_strdup ( mem_ctx , error_message ( code ) ) ;
2005-03-28 06:40:18 +00:00
return ret ;
}
2003-08-13 01:53:07 +00:00
# endif