krb5: Restore FILE as the default ccache type

This commit is contained in:
Nicolas Williams
2020-03-11 13:42:03 -05:00
parent 3a1f700cef
commit f70ccfa967
3 changed files with 25 additions and 37 deletions

View File

@@ -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
/* <drive letter>:\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,

View File

@@ -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

View File

@@ -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