#include "k5-int.h"
#if defined(USE_KIM)
#include <kim/kim.h>
#include "kim_library_private.h"
#elif defined(USE_LEASH)
static void (*pLeash_AcquireInitialTicketsIfNeeded)(krb5_context,krb5_principal,char*,int) = NULL;
static HANDLE hLeashDLL = INVALID_HANDLE_VALUE;
#ifdef _WIN64
#define LEASH_DLL "leashw64.dll"
#else
#define LEASH_DLL "leashw32.dll"
#endif
#endif
krb5_error_code KRB5_CALLCONV
krb5_cc_default(krb5_context context, krb5_ccache *ccache)
{
const char *default_name;
if (!context || context->magic != KV5M_CONTEXT)
return KV5M_CONTEXT;
default_name = krb5_cc_default_name(context);
if (default_name == NULL) {
return KRB5_FCC_INTERNAL;
}
return krb5_cc_resolve(context, default_name, ccache);
}
krb5_error_code KRB5_CALLCONV
krb5int_cc_default(krb5_context context, int no_ui, krb5_ccache *ccache)
{
if (!context || context->magic != KV5M_CONTEXT) {
return KV5M_CONTEXT;
}
#ifdef USE_KIM
if (no_ui == 0 && kim_library_allow_automatic_prompting ()) {
kim_error err = KIM_NO_ERROR;
kim_ccache kimccache = NULL;
kim_identity identity = KIM_IDENTITY_ANY;
kim_credential_state state;
kim_string name = NULL;
err = kim_ccache_create_from_display_name (&kimccache,
krb5_cc_default_name (context));
if (!err) {
err = kim_ccache_get_client_identity (kimccache, &identity);
}
if (!err) {
err = kim_ccache_get_state (kimccache, &state);
}
if (err || state != kim_credentials_state_valid) {
kim_ccache_free (&kimccache);
err = kim_ccache_create_new (&kimccache,
identity, KIM_OPTIONS_DEFAULT);
}
if (!err) {
err = kim_ccache_get_display_name (kimccache, &name);
}
if (!err) {
krb5_cc_set_default_name (context, name);
}
kim_identity_free (&identity);
kim_string_free (&name);
kim_ccache_free (&kimccache);
}
#else
#ifdef USE_LEASH
if ( hLeashDLL == INVALID_HANDLE_VALUE ) {
hLeashDLL = LoadLibrary(LEASH_DLL);
if ( hLeashDLL != INVALID_HANDLE_VALUE ) {
(FARPROC) pLeash_AcquireInitialTicketsIfNeeded =
GetProcAddress(hLeashDLL, "not_an_API_Leash_AcquireInitialTicketsIfNeeded");
}
}
if ( pLeash_AcquireInitialTicketsIfNeeded ) {
char ccname[256]="";
pLeash_AcquireInitialTicketsIfNeeded(context, NULL, ccname, sizeof(ccname));
if (ccname[0]) {
char * ccdefname = krb5_cc_default_name (context);
if (!ccdefname || strcmp (ccdefname, ccname) != 0) {
krb5_cc_set_default_name (context, ccname);
}
}
}
#endif
#endif
return krb5_cc_default (context, ccache);
}