2 * lib/krb5/ccache/ccdefault.c
4 * Copyright 1990 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.
27 * Find default credential cache
32 #if defined(USE_LOGIN_LIBRARY)
33 #include "KerberosLoginPrivate.h"
34 #elif defined(USE_LEASH)
35 static void (*pLeash_AcquireInitialTicketsIfNeeded
)(krb5_context
,krb5_principal
,char*,int) = NULL
;
36 static HANDLE hLeashDLL
= INVALID_HANDLE_VALUE
;
38 #define LEASH_DLL "leashw64.dll"
40 #define LEASH_DLL "leashw32.dll"
45 krb5_error_code KRB5_CALLCONV
46 krb5_cc_default(krb5_context context
, krb5_ccache
*ccache
)
48 krb5_os_context os_ctx
;
50 if (!context
|| context
->magic
!= KV5M_CONTEXT
)
53 os_ctx
= context
->os_context
;
55 return krb5_cc_resolve(context
, krb5_cc_default_name(context
), ccache
);
58 /* This is the internal function which opens the default ccache. On platforms supporting
59 the login library's automatic popup dialog to get tickets, this function also updated the
60 library's internal view of the current principal associated with this cache.
62 All krb5 and GSS functions which need to open a cache to get a tgt to obtain service tickets
63 should call this function, not krb5_cc_default() */
65 krb5_error_code KRB5_CALLCONV
66 krb5int_cc_default(krb5_context context
, krb5_ccache
*ccache
)
68 if (!context
|| context
->magic
!= KV5M_CONTEXT
) {
72 #ifdef USE_LOGIN_LIBRARY
74 /* make sure the default cache has tix before you open it */
75 KLStatus err
= klNoErr
;
76 char *outCacheName
= NULL
;
78 /* Try to make sure a krb5 tgt is in the cache */
79 err
= __KLInternalAcquireInitialTicketsForCache (krb5_cc_default_name (context
), kerberosVersion_V5
,
80 NULL
, NULL
, &outCacheName
);
82 /* This function tries to get tickets and put them in the specified
83 cache, however, if the cache does not exist, it may choose to put
84 them elsewhere (ie: the system default) so we set that here */
85 if (strcmp (krb5_cc_default_name (context
), outCacheName
) != 0) {
86 krb5_cc_set_default_name (context
, outCacheName
);
88 KLDisposeString (outCacheName
);
93 if ( hLeashDLL
== INVALID_HANDLE_VALUE
) {
94 hLeashDLL
= LoadLibrary(LEASH_DLL
);
95 if ( hLeashDLL
!= INVALID_HANDLE_VALUE
) {
96 (FARPROC
) pLeash_AcquireInitialTicketsIfNeeded
=
97 GetProcAddress(hLeashDLL
, "not_an_API_Leash_AcquireInitialTicketsIfNeeded");
101 if ( pLeash_AcquireInitialTicketsIfNeeded
) {
103 pLeash_AcquireInitialTicketsIfNeeded(context
, NULL
, ccname
, sizeof(ccname
));
105 if (strcmp (krb5_cc_default_name (context
),ccname
) != 0) {
106 krb5_cc_set_default_name (context
, ccname
);
113 return krb5_cc_default (context
, ccache
);