diff options
author | Andreas Schneider <asn@samba.org> | 2012-04-27 16:52:26 +0200 |
---|---|---|
committer | Simo Sorce <idra@samba.org> | 2012-05-04 16:51:29 +0200 |
commit | 4d77466dafdb4def6681534e47c06aa07ccf6e17 (patch) | |
tree | 5ac2020eac885cd11385da56e8c0f597cdec5210 /lib | |
parent | 6bec64b12a90ba81996ca6d049b56f168ef70bc0 (diff) | |
download | samba-4d77466dafdb4def6681534e47c06aa07ccf6e17.tar.gz samba-4d77466dafdb4def6681534e47c06aa07ccf6e17.tar.bz2 samba-4d77466dafdb4def6681534e47c06aa07ccf6e17.zip |
krb5samba: Add a smb_krb5_cc_get_lifetime() function.
Signed-off-by: Simo Sorce <idra@samba.org>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/krb5_wrap/krb5_samba.c | 47 | ||||
-rw-r--r-- | lib/krb5_wrap/krb5_samba.h | 12 |
2 files changed, 59 insertions, 0 deletions
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); |