10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * lib/krb5/ccache/ccdefault.c
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * Copyright 1990 by the Massachusetts Institute of Technology.
50Sstevel@tonic-gate * All Rights Reserved.
60Sstevel@tonic-gate *
70Sstevel@tonic-gate * Export of this software from the United States of America may
80Sstevel@tonic-gate * require a specific license from the United States Government.
90Sstevel@tonic-gate * It is the responsibility of any person or organization contemplating
100Sstevel@tonic-gate * export to obtain such a license before exporting.
11*7934SMark.Phalan@Sun.COM *
120Sstevel@tonic-gate * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
130Sstevel@tonic-gate * distribute this software and its documentation for any purpose and
140Sstevel@tonic-gate * without fee is hereby granted, provided that the above copyright
150Sstevel@tonic-gate * notice appear in all copies and that both that copyright notice and
160Sstevel@tonic-gate * this permission notice appear in supporting documentation, and that
170Sstevel@tonic-gate * the name of M.I.T. not be used in advertising or publicity pertaining
180Sstevel@tonic-gate * to distribution of the software without specific, written prior
190Sstevel@tonic-gate * permission. Furthermore if you modify this software you must label
200Sstevel@tonic-gate * your software as modified software and not distribute it in such a
210Sstevel@tonic-gate * fashion that it might be confused with the original M.I.T. software.
220Sstevel@tonic-gate * M.I.T. makes no representations about the suitability of
230Sstevel@tonic-gate * this software for any purpose. It is provided "as is" without express
240Sstevel@tonic-gate * or implied warranty.
25*7934SMark.Phalan@Sun.COM *
260Sstevel@tonic-gate *
270Sstevel@tonic-gate * Find default credential cache
280Sstevel@tonic-gate */
290Sstevel@tonic-gate
30*7934SMark.Phalan@Sun.COM #include "k5-int.h"
310Sstevel@tonic-gate
32*7934SMark.Phalan@Sun.COM #if defined(USE_LOGIN_LIBRARY)
33*7934SMark.Phalan@Sun.COM #include "KerberosLoginPrivate.h"
34*7934SMark.Phalan@Sun.COM #elif defined(USE_LEASH)
35*7934SMark.Phalan@Sun.COM static void (*pLeash_AcquireInitialTicketsIfNeeded)(krb5_context,krb5_principal,char*,int) = NULL;
36*7934SMark.Phalan@Sun.COM static HANDLE hLeashDLL = INVALID_HANDLE_VALUE;
37*7934SMark.Phalan@Sun.COM #ifdef _WIN64
38*7934SMark.Phalan@Sun.COM #define LEASH_DLL "leashw64.dll"
39*7934SMark.Phalan@Sun.COM #else
40*7934SMark.Phalan@Sun.COM #define LEASH_DLL "leashw32.dll"
410Sstevel@tonic-gate #endif
42*7934SMark.Phalan@Sun.COM #endif
43*7934SMark.Phalan@Sun.COM
440Sstevel@tonic-gate
45781Sgtb krb5_error_code KRB5_CALLCONV
krb5_cc_default(krb5_context context,krb5_ccache * ccache)46781Sgtb krb5_cc_default(krb5_context context, krb5_ccache *ccache)
470Sstevel@tonic-gate {
480Sstevel@tonic-gate krb5_os_context os_ctx;
490Sstevel@tonic-gate
500Sstevel@tonic-gate if (!context || context->magic != KV5M_CONTEXT)
510Sstevel@tonic-gate return KV5M_CONTEXT;
520Sstevel@tonic-gate
530Sstevel@tonic-gate os_ctx = context->os_context;
540Sstevel@tonic-gate
55781Sgtb return krb5_cc_resolve(context, krb5_cc_default_name(context), ccache);
560Sstevel@tonic-gate }
570Sstevel@tonic-gate
580Sstevel@tonic-gate /* This is the internal function which opens the default ccache. On platforms supporting
590Sstevel@tonic-gate the login library's automatic popup dialog to get tickets, this function also updated the
60*7934SMark.Phalan@Sun.COM library's internal view of the current principal associated with this cache.
61*7934SMark.Phalan@Sun.COM
620Sstevel@tonic-gate All krb5 and GSS functions which need to open a cache to get a tgt to obtain service tickets
630Sstevel@tonic-gate should call this function, not krb5_cc_default() */
640Sstevel@tonic-gate
65781Sgtb krb5_error_code KRB5_CALLCONV
krb5int_cc_default(krb5_context context,krb5_ccache * ccache)66781Sgtb krb5int_cc_default(krb5_context context, krb5_ccache *ccache)
670Sstevel@tonic-gate {
68*7934SMark.Phalan@Sun.COM if (!context || context->magic != KV5M_CONTEXT) {
69*7934SMark.Phalan@Sun.COM return KV5M_CONTEXT;
70*7934SMark.Phalan@Sun.COM }
71781Sgtb
72781Sgtb #ifdef USE_LOGIN_LIBRARY
73*7934SMark.Phalan@Sun.COM {
74*7934SMark.Phalan@Sun.COM /* make sure the default cache has tix before you open it */
75*7934SMark.Phalan@Sun.COM KLStatus err = klNoErr;
76*7934SMark.Phalan@Sun.COM char *outCacheName = NULL;
77*7934SMark.Phalan@Sun.COM
78*7934SMark.Phalan@Sun.COM /* Try to make sure a krb5 tgt is in the cache */
79*7934SMark.Phalan@Sun.COM err = __KLInternalAcquireInitialTicketsForCache (krb5_cc_default_name (context), kerberosVersion_V5,
80*7934SMark.Phalan@Sun.COM NULL, NULL, &outCacheName);
81*7934SMark.Phalan@Sun.COM if (err == klNoErr) {
82*7934SMark.Phalan@Sun.COM /* This function tries to get tickets and put them in the specified
83*7934SMark.Phalan@Sun.COM cache, however, if the cache does not exist, it may choose to put
84*7934SMark.Phalan@Sun.COM them elsewhere (ie: the system default) so we set that here */
85*7934SMark.Phalan@Sun.COM if (strcmp (krb5_cc_default_name (context), outCacheName) != 0) {
86*7934SMark.Phalan@Sun.COM krb5_cc_set_default_name (context, outCacheName);
87*7934SMark.Phalan@Sun.COM }
88*7934SMark.Phalan@Sun.COM KLDisposeString (outCacheName);
89*7934SMark.Phalan@Sun.COM }
90*7934SMark.Phalan@Sun.COM }
91*7934SMark.Phalan@Sun.COM #else
92*7934SMark.Phalan@Sun.COM #ifdef USE_LEASH
93*7934SMark.Phalan@Sun.COM if ( hLeashDLL == INVALID_HANDLE_VALUE ) {
94*7934SMark.Phalan@Sun.COM hLeashDLL = LoadLibrary(LEASH_DLL);
95*7934SMark.Phalan@Sun.COM if ( hLeashDLL != INVALID_HANDLE_VALUE ) {
96*7934SMark.Phalan@Sun.COM (FARPROC) pLeash_AcquireInitialTicketsIfNeeded =
97*7934SMark.Phalan@Sun.COM GetProcAddress(hLeashDLL, "not_an_API_Leash_AcquireInitialTicketsIfNeeded");
98*7934SMark.Phalan@Sun.COM }
99*7934SMark.Phalan@Sun.COM }
100*7934SMark.Phalan@Sun.COM
101*7934SMark.Phalan@Sun.COM if ( pLeash_AcquireInitialTicketsIfNeeded ) {
102*7934SMark.Phalan@Sun.COM char ccname[256]="";
103*7934SMark.Phalan@Sun.COM pLeash_AcquireInitialTicketsIfNeeded(context, NULL, ccname, sizeof(ccname));
104*7934SMark.Phalan@Sun.COM if (ccname[0]) {
105*7934SMark.Phalan@Sun.COM if (strcmp (krb5_cc_default_name (context),ccname) != 0) {
106*7934SMark.Phalan@Sun.COM krb5_cc_set_default_name (context, ccname);
107*7934SMark.Phalan@Sun.COM }
108*7934SMark.Phalan@Sun.COM }
109*7934SMark.Phalan@Sun.COM }
1100Sstevel@tonic-gate #endif
111*7934SMark.Phalan@Sun.COM #endif
112781Sgtb
1130Sstevel@tonic-gate return krb5_cc_default (context, ccache);
1140Sstevel@tonic-gate }
115