diff --git a/lib/krb5/cache.c b/lib/krb5/cache.c index 6dc706f03..7fbe7ee40 100644 --- a/lib/krb5/cache.c +++ b/lib/krb5/cache.c @@ -222,6 +222,41 @@ krb5_cc_get_type(krb5_context context, return id->ops->prefix; } +/* + * Return the complete resolvable name the ccache `id' in `strī. + * `str` should be freed with free(3). + * Returns 0 or an error (and then *str is set to NULL). + */ + +krb5_error_code KRB5_LIB_FUNCTION +krb5_cc_get_full_name(krb5_context context, + krb5_ccache id, + char **str) +{ + const char *type, *name; + + *str = NULL; + + type = krb5_cc_get_type(context, id); + if (type == NULL) { + krb5_set_error_string(context, "cache have no name of type"); + return KRB5_CC_UNKNOWN_TYPE; + } + + name = krb5_cc_get_name(context, id); + if (name == NULL) { + krb5_set_error_string(context, "cache of type %s have no name", type); + return KRB5_CC_BADNAME; + } + + if (asprintf(str, "%s:%s", type, name) == -1) { + krb5_set_error_string(context, "malloc - out of memory"); + *str = NULL; + return ENOMEM; + } + return 0; +} + /* * Return krb5_cc_ops of a the ccache `id'. */