2003-08-13 05:53:07 +04:00
/*
Unix SMB / CIFS implementation .
kerberos utility library
Copyright ( C ) Andrew Tridgell 2001
Copyright ( C ) Remus Koos 2001
2004-12-24 12:54:23 +03:00
Copyright ( C ) Nalin Dahyabhai 2004.
Copyright ( C ) Jeremy Allison 2004.
2005-03-24 06:35:51 +03:00
Copyright ( C ) Andrew Bartlett < abartlet @ samba . org > 2004 - 2005
2004-12-24 12:54:23 +03:00
2003-08-13 05:53:07 +04: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
the Free Software Foundation ; either version 2 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 , write to the Free Software
Foundation , Inc . , 675 Mass Ave , Cambridge , MA 0213 9 , USA .
*/
# include "includes.h"
2005-04-17 04:06:46 +04:00
# include "system/network.h"
2004-11-02 01:48:25 +03:00
# include "system/kerberos.h"
2005-02-11 13:15:56 +03:00
# include "system/time.h"
2005-03-29 12:24:03 +04:00
# include "auth/kerberos/kerberos.h"
2004-12-24 12:54:23 +03:00
# include "secrets.h"
2005-02-10 10:43:39 +03:00
# include "ads.h"
2003-08-13 05:53:07 +04:00
# ifdef HAVE_KRB5
2004-12-24 12:54:23 +03:00
# define LIBADS_CCACHE_NAME "MEMORY:libads"
2005-06-29 07:01:35 +04:00
/*
simulate a kinit , putting the tgt in the given credentials cache .
Orignally by remus @ snapserver . com
This version is built to use a keyblock , rather than needing the
original password .
*/
int kerberos_kinit_keyblock_cc ( krb5_context ctx , krb5_ccache cc ,
2005-09-05 14:53:14 +04:00
krb5_principal principal , krb5_keyblock * keyblock ,
2005-06-29 07:01:35 +04:00
time_t * expire_time , time_t * kdc_time )
{
krb5_error_code code = 0 ;
krb5_creds my_creds ;
krb5_get_init_creds_opt options ;
krb5_get_init_creds_opt_init ( & options ) ;
2005-09-05 14:53:14 +04:00
if ( ( code = krb5_get_init_creds_keyblock ( ctx , & my_creds , principal , keyblock ,
2005-06-29 07:01:35 +04:00
0 , NULL , & options ) ) ) {
return code ;
}
2005-09-05 14:53:14 +04:00
if ( ( code = krb5_cc_initialize ( ctx , cc , principal ) ) ) {
2005-06-29 07:01:35 +04:00
krb5_free_cred_contents ( ctx , & my_creds ) ;
return code ;
}
if ( ( code = krb5_cc_store_cred ( ctx , cc , & my_creds ) ) ) {
krb5_free_cred_contents ( ctx , & my_creds ) ;
return code ;
}
if ( expire_time ) {
* expire_time = ( time_t ) my_creds . times . endtime ;
}
if ( kdc_time ) {
* kdc_time = ( time_t ) my_creds . times . starttime ;
}
krb5_free_cred_contents ( ctx , & my_creds ) ;
return 0 ;
}
2003-08-13 05:53:07 +04:00
/*
2004-12-24 12:54:23 +03:00
simulate a kinit , putting the tgt in the given credentials cache .
Orignally by remus @ snapserver . com
2003-08-13 05:53:07 +04:00
*/
2004-12-24 12:54:23 +03:00
int kerberos_kinit_password_cc ( krb5_context ctx , krb5_ccache cc ,
2005-09-05 14:53:14 +04:00
krb5_principal principal , const char * password ,
time_t * expire_time , time_t * kdc_time )
2003-08-13 05:53:07 +04:00
{
krb5_error_code code = 0 ;
krb5_creds my_creds ;
2004-11-08 05:01:05 +03:00
krb5_get_init_creds_opt options ;
2003-08-13 05:53:07 +04:00
2004-11-08 05:28:12 +03:00
krb5_get_init_creds_opt_init ( & options ) ;
2004-11-08 05:01:05 +03:00
2005-09-05 14:53:14 +04:00
if ( ( code = krb5_get_init_creds_password ( ctx , & my_creds , principal , password ,
2005-10-20 14:10:40 +04:00
NULL ,
2004-11-08 05:01:05 +03:00
NULL , 0 , NULL , & options ) ) ) {
2003-08-13 05:53:07 +04:00
return code ;
}
2005-09-05 14:53:14 +04:00
if ( ( code = krb5_cc_initialize ( ctx , cc , principal ) ) ) {
2003-08-13 05:53:07 +04:00
krb5_free_cred_contents ( ctx , & my_creds ) ;
return code ;
}
if ( ( code = krb5_cc_store_cred ( ctx , cc , & my_creds ) ) ) {
krb5_free_cred_contents ( ctx , & my_creds ) ;
return code ;
}
2004-07-13 09:14:59 +04:00
if ( expire_time ) {
2004-06-19 12:15:41 +04:00
* expire_time = ( time_t ) my_creds . times . endtime ;
2004-07-13 09:14:59 +04:00
}
if ( kdc_time ) {
* kdc_time = ( time_t ) my_creds . times . starttime ;
}
2004-06-19 12:15:41 +04:00
2003-08-13 05:53:07 +04:00
krb5_free_cred_contents ( ctx , & my_creds ) ;
2004-07-13 09:14:59 +04:00
return 0 ;
}
2004-12-24 12:54:23 +03:00
2003-08-13 05:53:07 +04:00
# endif