17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * lib/krb5/ccache/ccdefault.c
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * Copyright 1990 by the Massachusetts Institute of Technology.
57c478bd9Sstevel@tonic-gate * All Rights Reserved.
67c478bd9Sstevel@tonic-gate *
77c478bd9Sstevel@tonic-gate * Export of this software from the United States of America may
87c478bd9Sstevel@tonic-gate * require a specific license from the United States Government.
97c478bd9Sstevel@tonic-gate * It is the responsibility of any person or organization contemplating
107c478bd9Sstevel@tonic-gate * export to obtain such a license before exporting.
11*55fea89dSDan Cross *
127c478bd9Sstevel@tonic-gate * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
137c478bd9Sstevel@tonic-gate * distribute this software and its documentation for any purpose and
147c478bd9Sstevel@tonic-gate * without fee is hereby granted, provided that the above copyright
157c478bd9Sstevel@tonic-gate * notice appear in all copies and that both that copyright notice and
167c478bd9Sstevel@tonic-gate * this permission notice appear in supporting documentation, and that
177c478bd9Sstevel@tonic-gate * the name of M.I.T. not be used in advertising or publicity pertaining
187c478bd9Sstevel@tonic-gate * to distribution of the software without specific, written prior
197c478bd9Sstevel@tonic-gate * permission. Furthermore if you modify this software you must label
207c478bd9Sstevel@tonic-gate * your software as modified software and not distribute it in such a
217c478bd9Sstevel@tonic-gate * fashion that it might be confused with the original M.I.T. software.
227c478bd9Sstevel@tonic-gate * M.I.T. makes no representations about the suitability of
237c478bd9Sstevel@tonic-gate * this software for any purpose. It is provided "as is" without express
247c478bd9Sstevel@tonic-gate * or implied warranty.
25*55fea89dSDan Cross *
267c478bd9Sstevel@tonic-gate *
277c478bd9Sstevel@tonic-gate * Find default credential cache
287c478bd9Sstevel@tonic-gate */
297c478bd9Sstevel@tonic-gate
30159d09a2SMark Phalan #include "k5-int.h"
317c478bd9Sstevel@tonic-gate
32159d09a2SMark Phalan #if defined(USE_LOGIN_LIBRARY)
33159d09a2SMark Phalan #include "KerberosLoginPrivate.h"
34159d09a2SMark Phalan #elif defined(USE_LEASH)
35159d09a2SMark Phalan static void (*pLeash_AcquireInitialTicketsIfNeeded)(krb5_context,krb5_principal,char*,int) = NULL;
36159d09a2SMark Phalan static HANDLE hLeashDLL = INVALID_HANDLE_VALUE;
37159d09a2SMark Phalan #ifdef _WIN64
38159d09a2SMark Phalan #define LEASH_DLL "leashw64.dll"
39159d09a2SMark Phalan #else
40159d09a2SMark Phalan #define LEASH_DLL "leashw32.dll"
417c478bd9Sstevel@tonic-gate #endif
42159d09a2SMark Phalan #endif
43159d09a2SMark Phalan
447c478bd9Sstevel@tonic-gate
45505d05c7Sgtb krb5_error_code KRB5_CALLCONV
krb5_cc_default(krb5_context context,krb5_ccache * ccache)46505d05c7Sgtb krb5_cc_default(krb5_context context, krb5_ccache *ccache)
477c478bd9Sstevel@tonic-gate {
487c478bd9Sstevel@tonic-gate krb5_os_context os_ctx;
497c478bd9Sstevel@tonic-gate
507c478bd9Sstevel@tonic-gate if (!context || context->magic != KV5M_CONTEXT)
517c478bd9Sstevel@tonic-gate return KV5M_CONTEXT;
52*55fea89dSDan Cross
537c478bd9Sstevel@tonic-gate os_ctx = context->os_context;
54*55fea89dSDan Cross
55505d05c7Sgtb return krb5_cc_resolve(context, krb5_cc_default_name(context), ccache);
567c478bd9Sstevel@tonic-gate }
577c478bd9Sstevel@tonic-gate
587c478bd9Sstevel@tonic-gate /* This is the internal function which opens the default ccache. On platforms supporting
597c478bd9Sstevel@tonic-gate the login library's automatic popup dialog to get tickets, this function also updated the
60*55fea89dSDan Cross library's internal view of the current principal associated with this cache.
61*55fea89dSDan Cross
627c478bd9Sstevel@tonic-gate All krb5 and GSS functions which need to open a cache to get a tgt to obtain service tickets
637c478bd9Sstevel@tonic-gate should call this function, not krb5_cc_default() */
647c478bd9Sstevel@tonic-gate
65505d05c7Sgtb krb5_error_code KRB5_CALLCONV
krb5int_cc_default(krb5_context context,krb5_ccache * ccache)66505d05c7Sgtb krb5int_cc_default(krb5_context context, krb5_ccache *ccache)
677c478bd9Sstevel@tonic-gate {
68159d09a2SMark Phalan if (!context || context->magic != KV5M_CONTEXT) {
69159d09a2SMark Phalan return KV5M_CONTEXT;
70159d09a2SMark Phalan }
71505d05c7Sgtb
72505d05c7Sgtb #ifdef USE_LOGIN_LIBRARY
73159d09a2SMark Phalan {
74159d09a2SMark Phalan /* make sure the default cache has tix before you open it */
75159d09a2SMark Phalan KLStatus err = klNoErr;
76159d09a2SMark Phalan char *outCacheName = NULL;
77*55fea89dSDan Cross
78159d09a2SMark Phalan /* Try to make sure a krb5 tgt is in the cache */
79*55fea89dSDan Cross err = __KLInternalAcquireInitialTicketsForCache (krb5_cc_default_name (context), kerberosVersion_V5,
80159d09a2SMark Phalan NULL, NULL, &outCacheName);
81159d09a2SMark Phalan if (err == klNoErr) {
82*55fea89dSDan Cross /* This function tries to get tickets and put them in the specified
83*55fea89dSDan Cross cache, however, if the cache does not exist, it may choose to put
84159d09a2SMark Phalan them elsewhere (ie: the system default) so we set that here */
85159d09a2SMark Phalan if (strcmp (krb5_cc_default_name (context), outCacheName) != 0) {
86159d09a2SMark Phalan krb5_cc_set_default_name (context, outCacheName);
87159d09a2SMark Phalan }
88159d09a2SMark Phalan KLDisposeString (outCacheName);
89159d09a2SMark Phalan }
90159d09a2SMark Phalan }
91159d09a2SMark Phalan #else
92159d09a2SMark Phalan #ifdef USE_LEASH
93159d09a2SMark Phalan if ( hLeashDLL == INVALID_HANDLE_VALUE ) {
94159d09a2SMark Phalan hLeashDLL = LoadLibrary(LEASH_DLL);
95159d09a2SMark Phalan if ( hLeashDLL != INVALID_HANDLE_VALUE ) {
96159d09a2SMark Phalan (FARPROC) pLeash_AcquireInitialTicketsIfNeeded =
97159d09a2SMark Phalan GetProcAddress(hLeashDLL, "not_an_API_Leash_AcquireInitialTicketsIfNeeded");
98159d09a2SMark Phalan }
99159d09a2SMark Phalan }
100*55fea89dSDan Cross
101159d09a2SMark Phalan if ( pLeash_AcquireInitialTicketsIfNeeded ) {
102159d09a2SMark Phalan char ccname[256]="";
103159d09a2SMark Phalan pLeash_AcquireInitialTicketsIfNeeded(context, NULL, ccname, sizeof(ccname));
104159d09a2SMark Phalan if (ccname[0]) {
105159d09a2SMark Phalan if (strcmp (krb5_cc_default_name (context),ccname) != 0) {
106159d09a2SMark Phalan krb5_cc_set_default_name (context, ccname);
107159d09a2SMark Phalan }
108159d09a2SMark Phalan }
109159d09a2SMark Phalan }
110159d09a2SMark Phalan #endif
1117c478bd9Sstevel@tonic-gate #endif
112505d05c7Sgtb
1137c478bd9Sstevel@tonic-gate return krb5_cc_default (context, ccache);
1147c478bd9Sstevel@tonic-gate }
115