From c140f0255c065d58ec3bb42093882d3efb043d2b Mon Sep 17 00:00:00 2001 From: Love Hornquist Astrand Date: Mon, 27 Jul 2009 09:42:46 +0200 Subject: [PATCH] Implement core of _gsskrb5_store_cred() --- lib/gssapi/krb5/store_cred.c | 42 +++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/lib/gssapi/krb5/store_cred.c b/lib/gssapi/krb5/store_cred.c index 7e14e5342..675a1d8e9 100644 --- a/lib/gssapi/krb5/store_cred.c +++ b/lib/gssapi/krb5/store_cred.c @@ -44,7 +44,10 @@ _gsskrb5_store_cred(OM_uint32 *minor_status, gss_cred_usage_t *cred_usage_stored) { krb5_context context; + krb5_error_code ret; gsskrb5_cred cred; + krb5_ccache id; + int destroy = 0; *minor_status = 0; @@ -69,8 +72,45 @@ _gsskrb5_store_cred(OM_uint32 *minor_status, return(GSS_S_FAILURE); } + if (cred->principal == NULL) { + HEIMDAL_MUTEX_unlock(&cred->cred_id_mutex); + *minor_status = GSS_KRB5_S_KG_TGT_MISSING; + return(GSS_S_FAILURE); + } + /* write out cred to credential cache */ + ret = krb5_cc_cache_match(context, cred->principal, &id); + if (ret) { + ret = krb5_cc_new_unique(context, NULL, NULL, &id); + if (ret) { + HEIMDAL_MUTEX_unlock(&cred->cred_id_mutex); + *minor_status = ret; + return(GSS_S_FAILURE); + } + destroy = 1; + } + + ret = krb5_cc_initialize(context, id, cred->principal); + if (ret == 0) + ret = krb5_cc_copy_match_f(context, cred->ccache, id, NULL, NULL, NULL); + if (ret) { + if (destroy) + krb5_cc_destroy(context, id); + else + krb5_cc_close(context, id); + HEIMDAL_MUTEX_unlock(&cred->cred_id_mutex); + *minor_status = ret; + return(GSS_S_FAILURE); + } + + if (default_cred) + krb5_cc_switch(context, id); + + krb5_cc_close(context, id); + + HEIMDAL_MUTEX_unlock(&cred->cred_id_mutex); + *minor_status = 0; - return GSS_S_FAILURE; + return GSS_S_COMPLETE; }