From f70ccfa967eaf3f7201073ef117b9d00ccc75339 Mon Sep 17 00:00:00 2001 From: Nicolas Williams Date: Wed, 11 Mar 2020 13:42:03 -0500 Subject: [PATCH] krb5: Restore FILE as the default ccache type --- lib/krb5/cache.c | 53 +++++++++++++++++----------------------------- lib/krb5/context.c | 2 +- lib/krb5/dcache.c | 7 +++--- 3 files changed, 25 insertions(+), 37 deletions(-) diff --git a/lib/krb5/cache.c b/lib/krb5/cache.c index c46ef3b8e..56e82884d 100644 --- a/lib/krb5/cache.c +++ b/lib/krb5/cache.c @@ -225,24 +225,6 @@ allocate_ccache(krb5_context context, return ret; } -static int -is_possible_path_name(const char * name) -{ - const char * colon; - - if ((colon = strchr(name, ':')) == NULL) - return TRUE; - -#ifdef _WIN32 - /* :\path\to\cache ? */ - - if (colon == name + 1 && - strchr(colon + 1, ':') == NULL) - return TRUE; -#endif - - return FALSE; -} /** * Find and allocate a ccache in `id' from the specification in `residual'. @@ -278,13 +260,7 @@ krb5_cc_resolve(krb5_context context, id); } } - if (is_possible_path_name(name)) - return allocate_ccache (context, &krb5_fcc_ops, name, NULL, id); - else { - krb5_set_error_message(context, KRB5_CC_UNKNOWN_TYPE, - N_("unknown ccache type %s", "name"), name); - return KRB5_CC_UNKNOWN_TYPE; - } + return allocate_ccache(context, &krb5_fcc_ops, name, NULL, id); } static const char * @@ -295,11 +271,12 @@ get_default_cc_type(krb5_context context, int simple) krb5_config_get_string_default(context, NULL, secure_getenv("KRB5CCTYPE"), "libdefaults", "default_cc_type", NULL); + const char *def_cccol = + krb5_config_get_string(context, NULL, "libdefaults", + "default_cc_collection", NULL); + size_t i; - if (!simple && - (def_ccname = krb5_cc_default_name(context))) { - size_t i; - + if (!simple && (def_ccname = krb5_cc_default_name(context))) { for (i = 0; i < context->num_cc_ops && context->cc_ops[i]->prefix; i++) { size_t prefix_len = strlen(context->cc_ops[i]->prefix); @@ -307,10 +284,17 @@ get_default_cc_type(krb5_context context, int simple) def_ccname[prefix_len] == ':') return context->cc_ops[i]->prefix; } - if (is_possible_path_name(def_ccname)) - return "FILE"; } - return def_cctype ? def_cctype : "DIR"; + if (!def_cctype && def_cccol) { + for (i = 0; i < context->num_cc_ops && context->cc_ops[i]->prefix; i++) { + size_t prefix_len = strlen(context->cc_ops[i]->prefix); + + if (!strncmp(context->cc_ops[i]->prefix, def_cccol, prefix_len) && + def_cccol[prefix_len] == ':') + return context->cc_ops[i]->prefix; + } + } + return def_cctype ? def_cctype : "FILE"; } /** @@ -358,7 +342,7 @@ krb5_cc_resolve_sub(krb5_context context, if (!cctype) { const char *def_cctype = get_default_cc_type(context, 0); - int might_be_path = collection && is_possible_path_name(collection); + int might_be_path = collection != NULL; if (def_cctype) cctype = def_cctype; @@ -453,6 +437,9 @@ krb5_cc_new_unique(krb5_context context, const char *type, const krb5_cc_ops *ops; krb5_error_code ret; + if (type == NULL) + type = get_default_cc_type(context, 1); + ops = krb5_cc_get_prefix_ops(context, type); if (ops == NULL) { krb5_set_error_message(context, KRB5_CC_UNKNOWN_TYPE, diff --git a/lib/krb5/context.c b/lib/krb5/context.c index 7c0966826..6cbcf9c92 100644 --- a/lib/krb5/context.c +++ b/lib/krb5/context.c @@ -789,7 +789,7 @@ krb5_set_config(krb5_context context, const char *config) #if 0 /* with this enabled and if there are no config files, Kerberos is considererd disabled */ - if(tmp == NULL) + if (tmp == NULL) return ENXIO; #endif diff --git a/lib/krb5/dcache.c b/lib/krb5/dcache.c index 4d4607061..8c4893a3a 100644 --- a/lib/krb5/dcache.c +++ b/lib/krb5/dcache.c @@ -779,9 +779,10 @@ dcc_get_default_name(krb5_context context, char **str) "libdefaults", "default_cc_collection", NULL); - /* What if def_cc_colname does not start with DIR:? We tolerate it. */ - return _krb5_expand_default_cc_name(context, def_cc_colname, - str); + /* [libdefaults] default_cc_collection is for testing */ + if (strncmp(def_cc_colname, "DIR:", sizeof("DIR:") - 1)) + def_cc_colname = KRB5_DEFAULT_CCNAME_DIR; + return _krb5_expand_default_cc_name(context, def_cc_colname, str); } static krb5_error_code KRB5_CALLCONV