/*
* Name of the default cache
*/
-char* gDefaultCacheName = NULL;
-char gDefaultName[ANAME_SZ];
-char gDefaultInstance[INST_SZ];
-char gDefaultRealm[REALM_SZ];
-Boolean gHaveDefaultPrincipal = false;
+char* gDefaultCacheName = NULL;
/*
* Initialize credentials cache
if (strncmp (service, KRB_TICKET_GRANTING_TICKET, ANAME_SZ) == 0) {
OSStatus err;
char *cacheName;
- KLPrincipal defaultPrincipal = nil;
KLPrincipal outPrincipal;
- if (gHaveDefaultPrincipal) {
- err = KLCreatePrincipalFromTriplet (gDefaultName, gDefaultInstance, gDefaultRealm, &defaultPrincipal);
- if (err != klNoErr)
- defaultPrincipal = nil;
- }
-
- err = __KLInternalAcquireInitialTicketsForCache (defaultPrincipal, NULL, TKT_FILE,
- kerberosVersion_V4, &outPrincipal, &cacheName);
- if (defaultPrincipal != nil)
- KLDisposePrincipal (defaultPrincipal);
-
- if (err == noErr) {
- char* newName = nil;
- char* newInstance = nil;
- char* newRealm = nil;
-
- gHaveDefaultPrincipal = false;
- err = KLGetTripletFromPrincipal (outPrincipal, &newName, &newInstance, &newRealm);
- if (err == noErr) {
- // If this isn't a valid krb4 principal, don't store it or track the cache name
- if ((strlen (newName) < ANAME_SZ) && (strlen (newInstance) < INST_SZ) &&
- (strlen (newRealm) < REALM_SZ)) {
- strcpy (gDefaultName, newName);
- strcpy (gDefaultInstance, newInstance);
- strcpy (gDefaultRealm, newRealm);
- krb_set_tkt_string (cacheName); // Tickets for the krb4 principal went here
-
- gHaveDefaultPrincipal = true;
- }
-
- KLDisposeString (newName);
- KLDisposeString (newInstance);
- KLDisposeString (newRealm);
- }
-
+ err = __KLInternalAcquireInitialTicketsForCache (TKT_FILE, kerberosVersion_V4, NULL,
+ &outPrincipal, &cacheName);
+
+ if (err == klNoErr) {
+ krb_set_tkt_string (cacheName); // Tickets for the krb4 principal went here
KLDisposeString (cacheName);
KLDisposePrincipal (outPrincipal);
} else {
gDefaultCacheName = malloc (strlen (val) + 1);
if (gDefaultCacheName != NULL)
strcpy (gDefaultCacheName, val);
- gHaveDefaultPrincipal = false;
}
}
krb5_error_code KRB5_CALLCONV
krb5_cc_default(krb5_context context, krb5_ccache *ccache)
{
- krb5_error_code retval;
+ krb5_error_code retval;
krb5_os_context os_ctx;
if (!context || context->magic != KV5M_CONTEXT)
os_ctx = context->os_context;
- retval = krb5_cc_resolve(context, krb5_cc_default_name(context), ccache);
- if (!retval && ccache && !os_ctx->default_ccprincipal) {
- /* We got a ccache... remember what principal is associated with it */
- if (krb5_cc_get_principal (context, *ccache, &os_ctx->default_ccprincipal) != 0)
- os_ctx->default_ccprincipal = 0;
- }
- return retval;
+ return krb5_cc_resolve(context, krb5_cc_default_name(context), ccache);
}
/* This is the internal function which opens the default ccache. On platforms supporting
krb5_error_code KRB5_CALLCONV
krb5int_cc_default(krb5_context context, krb5_ccache *ccache)
{
-#ifdef USE_LOGIN_LIBRARY
- {
- /* make sure the default cache has tix before you open it */
- char *outCacheName;
- KLPrincipal desiredPrincipal = nil;
- krb5_principal desiredKrb5Principal;
- krb5_error_code err;
- krb5_os_context os_ctx;
+ if (!context || context->magic != KV5M_CONTEXT) {
+ return KV5M_CONTEXT;
+ }
- if (!context || context->magic != KV5M_CONTEXT)
- return KV5M_CONTEXT;
-
- os_ctx = context->os_context;
-
- desiredKrb5Principal = os_ctx->default_ccprincipal;
-
- /* do we want a specific client principal? */
- if (desiredKrb5Principal != NULL) {
- char *desiredName;
-
- err = krb5_unparse_name (context, desiredKrb5Principal, &desiredName);
- if (!err) {
- err = KLCreatePrincipalFromString (desiredName,
- kerberosVersion_V5, &desiredPrincipal);
- krb5_free_unparsed_name (context, desiredName);
- if (err != klNoErr)
- desiredPrincipal = nil;
- }
- }
-
- /* Try to make sure a krb5 tgt is in the cache */
- err = __KLInternalAcquireInitialTicketsForCache (desiredPrincipal, NULL,
- krb5_cc_default_name (context),
- kerberosVersion_V5, nil, &outCacheName);
- if (err == klNoErr) {
- /* This function tries to get tickets and put them in the specified
- cache, however, if the cache does not exist, it may choose to put
- them elsewhere (ie: the system default) so we set that here */
- if (strcmp (krb5_cc_default_name (context), outCacheName) != 0) {
- krb5_cc_set_default_name (context, outCacheName);
- }
- KLDisposeString (outCacheName);
- }
-
- if (desiredPrincipal != nil)
- KLDisposePrincipal (desiredPrincipal);
- }
+#ifdef USE_LOGIN_LIBRARY
+ {
+ /* make sure the default cache has tix before you open it */
+ KLStatus err = klNoErr;
+ char *outCacheName = NULL;
+
+ /* Try to make sure a krb5 tgt is in the cache */
+ err = __KLInternalAcquireInitialTicketsForCache (krb5_cc_default_name (context), kerberosVersion_V5,
+ NULL, NULL, &outCacheName);
+ if (err == klNoErr) {
+ /* This function tries to get tickets and put them in the specified
+ cache, however, if the cache does not exist, it may choose to put
+ them elsewhere (ie: the system default) so we set that here */
+ if (strcmp (krb5_cc_default_name (context), outCacheName) != 0) {
+ krb5_cc_set_default_name (context, outCacheName);
+ }
+ KLDisposeString (outCacheName);
+ }
+ }
#else
#ifdef USE_LEASH
hLeashDLL = LoadLibrary("leashw32.dll");
if ( hLeashDLL != INVALID_HANDLE_VALUE ) {
(FARPROC) pLeash_AcquireInitialTicketsIfNeeded =
- GetProcAddress(hLeashDLL, "not_an_API_Leash_AcquireInitialTicketsIfNeeded");
+ GetProcAddress(hLeashDLL, "not_an_API_Leash_AcquireInitialTicketsIfNeeded");
}
}
-
- if ( pLeash_AcquireInitialTicketsIfNeeded )
- {
- krb5_os_context os_ctx;
-
- if (!context || context->magic != KV5M_CONTEXT)
- return KV5M_CONTEXT;
-
- os_ctx = context->os_context;
-
- pLeash_AcquireInitialTicketsIfNeeded(context,os_ctx->default_ccprincipal);
+
+ if ( pLeash_AcquireInitialTicketsIfNeeded ) {
+ pLeash_AcquireInitialTicketsIfNeeded(context, NULL);
}
#endif
#endif