From 4d77466dafdb4def6681534e47c06aa07ccf6e17 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Fri, 27 Apr 2012 16:52:26 +0200 Subject: krb5samba: Add a smb_krb5_cc_get_lifetime() function. Signed-off-by: Simo Sorce --- lib/krb5_wrap/krb5_samba.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++ lib/krb5_wrap/krb5_samba.h | 12 ++++++++++++ 2 files changed, 59 insertions(+) (limited to 'lib') diff --git a/lib/krb5_wrap/krb5_samba.c b/lib/krb5_wrap/krb5_samba.c index 4bfc2531c6..ddebdd8ebd 100644 --- a/lib/krb5_wrap/krb5_samba.c +++ b/lib/krb5_wrap/krb5_samba.c @@ -2128,6 +2128,53 @@ krb5_error_code smb_krb5_make_principal(krb5_context context, } #endif +#if !defined(HAVE_KRB5_CC_GET_LIFETIME) && defined(HAVE_KRB5_CC_RETRIEVE_CRED) +/** + * @brief Get the lifetime of the initial ticket in the cache. + * + * @param[in] context The kerberos context. + * + * @param[in] id The credential cache to get the ticket lifetime. + * + * @param[out] t A pointer to a time value to store the lifetime. + * + * @return 0 on success, a krb5_error_code on error. + */ +krb5_error_code smb_krb5_cc_get_lifetime(krb5_context context, + krb5_ccache id, + time_t *t) +{ + krb5_error_code rc; + krb5_creds mcreds; + krb5_creds creds; + krb5_timestamp now; + + ZERO_STRUCT(mcreds); + + mcreds.ticket_flags = TKT_FLG_INITIAL; + + rc = krb5_cc_retrieve_cred(context, + id, + KRB5_TC_MATCH_FLAGS, + &mcreds, + &creds); + if (rc != 0) { + return rc; + } + + rc = krb5_timeofday(context, &now); + if (rc != 0) { + return rc; + } + + *t = (time_t) (creds.times.endtime - now); + + krb5_free_creds(context, &creds); + + return 0; +} +#endif /* HAVE_KRB5_CC_GET_LIFETIME */ + /* * smb_krb5_principal_get_realm * diff --git a/lib/krb5_wrap/krb5_samba.h b/lib/krb5_wrap/krb5_samba.h index 2c492642a6..f036e052b3 100644 --- a/lib/krb5_wrap/krb5_samba.h +++ b/lib/krb5_wrap/krb5_samba.h @@ -240,6 +240,18 @@ krb5_error_code smb_krb5_make_principal(krb5_context context, #else #error krb5_make_principal not available #endif + +#if defined(HAVE_KRB5_CC_GET_LIFETIME) +#define smb_krb5_cc_get_lifetime krb5_cc_get_lifetime +#elif defined(HAVE_KRB5_CC_RETRIEVE_CRED) +krb5_error_code smb_krb5_cc_get_lifetime(krb5_context context, + krb5_ccache id, + time_t *t); +#else +#error krb5_cc_get_lifetime not available +#endif + + char *smb_krb5_principal_get_realm(krb5_context context, krb5_principal principal); -- cgit