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.
30 static void (*pLeash_AcquireInitialTicketsIfNeeded)(krb5_context,krb5_principal,char*,int) = NULL;
31 static HANDLE hLeashDLL = INVALID_HANDLE_VALUE;
33 #define LEASH_DLL "leashw64.dll"
35 #define LEASH_DLL "leashw32.dll"
40 krb5_error_code KRB5_CALLCONV
41 krb5_cc_default(krb5_context context, krb5_ccache *ccache)
43 const char *default_name;
45 if (!context || context->magic != KV5M_CONTEXT)
48 default_name = krb5_cc_default_name(context);
49 if (default_name == NULL) {
50 /* Could be a bogus context, or an allocation failure, or
51 other things. Unfortunately the API doesn't allow us
52 to find out any specifics. */
53 return KRB5_FCC_INTERNAL;
56 return krb5_cc_resolve(context, default_name, ccache);
59 /* This is the internal function which opens the default ccache. On
60 platforms supporting the login library's automatic popup dialog to
61 get tickets, this function also updated the library's internal view
62 of the current principal associated with this cache.
64 All krb5 and GSS functions which need to open a cache to get a tgt
65 to obtain service tickets should call this function, not
68 krb5_error_code KRB5_CALLCONV
69 krb5int_cc_default(krb5_context context, krb5_ccache *ccache)
71 if (!context || context->magic != KV5M_CONTEXT) {
76 if ( hLeashDLL == INVALID_HANDLE_VALUE ) {
77 hLeashDLL = LoadLibrary(LEASH_DLL);
78 if ( hLeashDLL != INVALID_HANDLE_VALUE ) {
79 (FARPROC) pLeash_AcquireInitialTicketsIfNeeded =
80 GetProcAddress(hLeashDLL, "not_an_API_Leash_AcquireInitialTicketsIfNeeded");
84 if ( pLeash_AcquireInitialTicketsIfNeeded ) {
86 pLeash_AcquireInitialTicketsIfNeeded(context, NULL, ccname, sizeof(ccname));
88 char * ccdefname = krb5_cc_default_name (context);
89 if (!ccdefname || strcmp (ccdefname, ccname) != 0) {
90 krb5_cc_set_default_name (context, ccname);
96 return krb5_cc_default (context, ccache);