From ae96106d7613e4868e0f514fb0615e6cbe14b3b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Love=20H=C3=B6rnquist=20=C3=85strand?= Date: Thu, 16 Apr 2009 07:53:13 +0000 Subject: [PATCH] add krb5_cc_get_lifetime git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@25106 ec53bebd-3082-4978-b11e-865c3cabbd6b --- lib/krb5/cache.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/lib/krb5/cache.c b/lib/krb5/cache.c index b6d494c7c..cf0042764 100644 --- a/lib/krb5/cache.c +++ b/lib/krb5/cache.c @@ -1570,3 +1570,49 @@ krb5_cc_set_friendly_name(krb5_context context, return krb5_cc_set_config(context, id, NULL, "FriendlyName", &data); } + +/** + * Get the lifetime of the initial ticket in the cache + * + * Get the lifetime of the initial ticket in the cache, if the initial + * ticket was not found, the error code KRB5_CC_END is returned. + * + * @param context A Kerberos 5 context. + * @param id a credential cache + * @param t the relative lifetime of the initial ticket + * + * @return Return an error code or 0, see krb5_get_error_message(). + * + * @ingroup krb5_ccache + */ + +krb5_error_code KRB5_LIB_FUNCTION +krb5_cc_get_lifetime(krb5_context context, krb5_ccache id, time_t *t) +{ + krb5_cc_cursor cursor; + krb5_error_code ret; + krb5_creds cred; + time_t now; + + *t = 0; + now = time(NULL); + + ret = krb5_cc_start_seq_get(context, id, &cursor); + if (ret) + return ret; + + while ((ret = krb5_cc_next_cred(context, id, &cursor, &cred)) == 0) { + if (cred.flags.b.initial) { + if (now < cred.times.endtime) + *t = cred.times.endtime - now; + krb5_free_cred_contents(context, &cred); + goto out; + } + krb5_free_cred_contents(context, &cred); + } + + out: + krb5_cc_end_seq_get(context, id, &cursor); + + return ret; +}