From bc4a1da9c6ba1e4bf749ee069a73ad2e3a77ddb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Love=20H=C3=B6rnquist=20=C3=85strand?= Date: Fri, 21 Oct 2005 12:44:08 +0000 Subject: [PATCH] (acquire_initiator_cred): use krb5_cc_cache_match to find a matching creditial cache, if that failes, fallback to the default cache. git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@16205 ec53bebd-3082-4978-b11e-865c3cabbd6b --- lib/gssapi/acquire_cred.c | 17 ++++++++++++++--- lib/gssapi/krb5/acquire_cred.c | 17 ++++++++++++++--- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/lib/gssapi/acquire_cred.c b/lib/gssapi/acquire_cred.c index 7f7e90f35..a786a43dc 100644 --- a/lib/gssapi/acquire_cred.c +++ b/lib/gssapi/acquire_cred.c @@ -82,9 +82,20 @@ static OM_uint32 acquire_initiator_cred ret = GSS_S_FAILURE; memset(&cred, 0, sizeof(cred)); - kret = krb5_cc_default(gssapi_krb5_context, &ccache); - if (kret) - goto end; + /* If we have a preferred principal, lets try to find it in all + * caches, otherwise, fall back to default cache. Ignore + * errors. */ + if (handle->principal) + kret = krb5_cc_cache_match (gssapi_krb5_context, + handle->principal, + NULL, + &ccache); + + if (ccache == NULL) { + kret = krb5_cc_default(gssapi_krb5_context, &ccache); + if (kret) + goto end; + } kret = krb5_cc_get_principal(gssapi_krb5_context, ccache, &def_princ); if (kret != 0) { diff --git a/lib/gssapi/krb5/acquire_cred.c b/lib/gssapi/krb5/acquire_cred.c index 7f7e90f35..a786a43dc 100644 --- a/lib/gssapi/krb5/acquire_cred.c +++ b/lib/gssapi/krb5/acquire_cred.c @@ -82,9 +82,20 @@ static OM_uint32 acquire_initiator_cred ret = GSS_S_FAILURE; memset(&cred, 0, sizeof(cred)); - kret = krb5_cc_default(gssapi_krb5_context, &ccache); - if (kret) - goto end; + /* If we have a preferred principal, lets try to find it in all + * caches, otherwise, fall back to default cache. Ignore + * errors. */ + if (handle->principal) + kret = krb5_cc_cache_match (gssapi_krb5_context, + handle->principal, + NULL, + &ccache); + + if (ccache == NULL) { + kret = krb5_cc_default(gssapi_krb5_context, &ccache); + if (kret) + goto end; + } kret = krb5_cc_get_principal(gssapi_krb5_context, ccache, &def_princ); if (kret != 0) {