1 /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /* lib/krb5/ccache/ccdefault.c - Find default credential cache */
4 * Copyright 1990, 2007, 2008 by the Massachusetts Institute of Technology.
7 * Export of this software from the United States of America may
8 * require a specific license from the United States Government.
9 * It is the responsibility of any person or organization contemplating
10 * export to obtain such a license before exporting.
12 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
13 * distribute this software and its documentation for any purpose and
14 * without fee is hereby granted, provided that the above copyright
15 * notice appear in all copies and that both that copyright notice and
16 * this permission notice appear in supporting documentation, and that
17 * the name of M.I.T. not be used in advertising or publicity pertaining
18 * to distribution of the software without specific, written prior
19 * permission. Furthermore if you modify this software you must label
20 * your software as modified software and not distribute it in such a
21 * fashion that it might be confused with the original M.I.T. software.
22 * M.I.T. makes no representations about the suitability of
23 * this software for any purpose. It is provided "as is" without express
24 * or implied warranty.
31 #include "kim_library_private.h"
32 #elif defined(USE_LEASH)
33 static void (*pLeash_AcquireInitialTicketsIfNeeded)(krb5_context,krb5_principal,char*,int) = NULL;
34 static HANDLE hLeashDLL = INVALID_HANDLE_VALUE;
36 #define LEASH_DLL "leashw64.dll"
38 #define LEASH_DLL "leashw32.dll"
43 krb5_error_code KRB5_CALLCONV
44 krb5_cc_default(krb5_context context, krb5_ccache *ccache)
46 const char *default_name;
48 if (!context || context->magic != KV5M_CONTEXT)
51 default_name = krb5_cc_default_name(context);
52 if (default_name == NULL) {
53 /* Could be a bogus context, or an allocation failure, or
54 other things. Unfortunately the API doesn't allow us
55 to find out any specifics. */
56 return KRB5_FCC_INTERNAL;
59 return krb5_cc_resolve(context, default_name, ccache);
62 /* This is the internal function which opens the default ccache. On
63 platforms supporting the login library's automatic popup dialog to
64 get tickets, this function also updated the library's internal view
65 of the current principal associated with this cache.
67 All krb5 and GSS functions which need to open a cache to get a tgt
68 to obtain service tickets should call this function, not
71 krb5_error_code KRB5_CALLCONV
72 krb5int_cc_default(krb5_context context, krb5_ccache *ccache)
74 if (!context || context->magic != KV5M_CONTEXT) {
79 if (kim_library_allow_automatic_prompting ()) {
80 kim_error err = KIM_NO_ERROR;
81 kim_ccache kimccache = NULL;
82 kim_identity identity = KIM_IDENTITY_ANY;
83 kim_credential_state state;
84 kim_string name = NULL;
86 err = kim_ccache_create_from_display_name (&kimccache,
87 krb5_cc_default_name (context));
90 err = kim_ccache_get_client_identity (kimccache, &identity);
94 err = kim_ccache_get_state (kimccache, &state);
97 if (err || state != kim_credentials_state_valid) {
98 /* Either the ccache is does not exist or is invalid. Get new
99 * tickets. Use the identity in the ccache if there was one. */
100 kim_ccache_free (&kimccache);
101 err = kim_ccache_create_new (&kimccache,
102 identity, KIM_OPTIONS_DEFAULT);
106 err = kim_ccache_get_display_name (kimccache, &name);
110 krb5_cc_set_default_name (context, name);
113 kim_identity_free (&identity);
114 kim_string_free (&name);
115 kim_ccache_free (&kimccache);
119 if ( hLeashDLL == INVALID_HANDLE_VALUE ) {
120 hLeashDLL = LoadLibrary(LEASH_DLL);
121 if ( hLeashDLL != INVALID_HANDLE_VALUE ) {
122 (FARPROC) pLeash_AcquireInitialTicketsIfNeeded =
123 GetProcAddress(hLeashDLL, "not_an_API_Leash_AcquireInitialTicketsIfNeeded");
127 if ( pLeash_AcquireInitialTicketsIfNeeded ) {
129 pLeash_AcquireInitialTicketsIfNeeded(context, NULL, ccname, sizeof(ccname));
131 char * ccdefname = krb5_cc_default_name (context);
132 if (!ccdefname || strcmp (ccdefname, ccname) != 0) {
133 krb5_cc_set_default_name (context, ccname);
140 return krb5_cc_default (context, ccache);