2012-04-10 13:09:20 +04:00
/*
Unix SMB / CIFS implementation .
Copyright ( C ) Andrew Bartlett < abartlet @ samba . org > 2009
This program is free software ; you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation ; either version 3 of the License , or
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
along with this program . If not , see < http : //www.gnu.org/licenses/>.
*/
2009-07-27 16:04:26 +04:00
# include "includes.h"
# include "system/kerberos.h"
# include "auth/kerberos/kerberos.h"
# include <hdb.h>
2010-01-28 09:27:11 +03:00
# include "kdc/samba_kdc.h"
2012-04-10 13:09:20 +04:00
# include "libnet/libnet_export_keytab.h"
2009-07-27 16:04:26 +04:00
NTSTATUS libnet_export_keytab ( struct libnet_context * ctx , TALLOC_CTX * mem_ctx , struct libnet_export_keytab * r )
{
krb5_error_code ret ;
struct smb_krb5_context * smb_krb5_context ;
const char * from_keytab ;
/* Register hdb-samba4 hooks for use as a keytab */
2010-01-28 08:08:36 +03:00
struct samba_kdc_base_context * base_ctx = talloc_zero ( mem_ctx , struct samba_kdc_base_context ) ;
if ( ! base_ctx ) {
2009-07-27 16:04:26 +04:00
return NT_STATUS_NO_MEMORY ;
}
2010-01-28 08:08:36 +03:00
base_ctx - > ev_ctx = ctx - > event_ctx ;
base_ctx - > lp_ctx = ctx - > lp_ctx ;
2009-07-27 16:04:26 +04:00
2010-01-28 08:08:36 +03:00
from_keytab = talloc_asprintf ( base_ctx , " HDB:samba4&%p " , base_ctx ) ;
2009-07-27 16:04:26 +04:00
if ( ! from_keytab ) {
return NT_STATUS_NO_MEMORY ;
}
2014-04-17 14:35:33 +04:00
ret = smb_krb5_init_context ( ctx , ctx - > lp_ctx , & smb_krb5_context ) ;
2009-07-27 16:04:26 +04:00
if ( ret ) {
return NT_STATUS_NO_MEMORY ;
}
ret = krb5_plugin_register ( smb_krb5_context - > krb5_context ,
PLUGIN_TYPE_DATA , " hdb " ,
2011-11-30 00:45:25 +04:00
& hdb_samba4_interface ) ;
2009-07-27 16:04:26 +04:00
if ( ret ) {
return NT_STATUS_NO_MEMORY ;
}
ret = krb5_kt_register ( smb_krb5_context - > krb5_context , & hdb_kt_ops ) ;
if ( ret ) {
return NT_STATUS_NO_MEMORY ;
}
2011-11-29 05:47:40 +04:00
if ( r - > in . principal ) {
2012-08-29 10:22:24 +04:00
ret = kt_copy_one_principal ( smb_krb5_context - > krb5_context , from_keytab , r - > in . keytab_name , r - > in . principal , 0 , samba_all_enctypes ( ) ) ;
2011-11-29 05:47:40 +04:00
} else {
unlink ( r - > in . keytab_name ) ;
ret = kt_copy ( smb_krb5_context - > krb5_context , from_keytab , r - > in . keytab_name ) ;
}
2010-09-30 23:43:14 +04:00
2009-07-27 16:04:26 +04:00
if ( ret ) {
r - > out . error_string = smb_get_krb5_error_message ( smb_krb5_context - > krb5_context ,
ret , mem_ctx ) ;
2011-11-29 05:47:40 +04:00
if ( ret = = KRB5_KT_NOTFOUND ) {
return NT_STATUS_NO_SUCH_USER ;
} else {
return NT_STATUS_UNSUCCESSFUL ;
}
2009-07-27 16:04:26 +04:00
}
return NT_STATUS_OK ;
}