use _krb5_expand_path_tokens
This commit is contained in:
@@ -389,84 +389,7 @@ krb5_cc_get_ops(krb5_context context, krb5_ccache id)
|
||||
krb5_error_code
|
||||
_krb5_expand_default_cc_name(krb5_context context, const char *str, char **res)
|
||||
{
|
||||
#ifndef KRB5_USE_PATH_TOKENS
|
||||
size_t tlen, len = 0;
|
||||
char *tmp, *tmp2, *append;
|
||||
|
||||
*res = NULL;
|
||||
|
||||
while (str && *str) {
|
||||
tmp = strstr(str, "%{");
|
||||
if (tmp && tmp != str) {
|
||||
append = malloc((tmp - str) + 1);
|
||||
if (append) {
|
||||
memcpy(append, str, tmp - str);
|
||||
append[tmp - str] = '\0';
|
||||
}
|
||||
str = tmp;
|
||||
} else if (tmp) {
|
||||
tmp2 = strchr(tmp, '}');
|
||||
if (tmp2 == NULL) {
|
||||
if (*res)
|
||||
free(*res);
|
||||
*res = NULL;
|
||||
krb5_set_error_message(context, KRB5_CONFIG_BADFORMAT,
|
||||
"variable missing }");
|
||||
return KRB5_CONFIG_BADFORMAT;
|
||||
}
|
||||
if (strncasecmp(tmp, "%{uid}", 6) == 0)
|
||||
asprintf(&append, "%u", (unsigned)getuid());
|
||||
else if (strncasecmp(tmp, "%{null}", 7) == 0)
|
||||
append = strdup("");
|
||||
else {
|
||||
if (*res)
|
||||
free(*res);
|
||||
*res = NULL;
|
||||
krb5_set_error_message(context,
|
||||
KRB5_CONFIG_BADFORMAT,
|
||||
"expand default cache unknown "
|
||||
"variable \"%.*s\"",
|
||||
(int)(tmp2 - tmp) - 2, tmp + 2);
|
||||
return KRB5_CONFIG_BADFORMAT;
|
||||
}
|
||||
str = tmp2 + 1;
|
||||
} else {
|
||||
append = strdup(str);
|
||||
str = NULL;
|
||||
}
|
||||
if (append == NULL) {
|
||||
if (*res)
|
||||
free(*res);
|
||||
*res = NULL;
|
||||
krb5_set_error_message(context, ENOMEM,
|
||||
N_("malloc: out of memory", ""));
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
tlen = strlen(append);
|
||||
tmp = realloc(*res, len + tlen + 1);
|
||||
if (tmp == NULL) {
|
||||
free(append);
|
||||
if (*res)
|
||||
free(*res);
|
||||
*res = NULL;
|
||||
krb5_set_error_message(context, ENOMEM,
|
||||
N_("malloc: out of memory", ""));
|
||||
return ENOMEM;
|
||||
}
|
||||
*res = tmp;
|
||||
memcpy(*res + len, append, tlen + 1);
|
||||
len = len + tlen;
|
||||
free(append);
|
||||
}
|
||||
return 0;
|
||||
#else /* _WIN32 */
|
||||
/* On Windows, we use the more generic _krb5_expand_path_tokens()
|
||||
function which also handles path tokens in addition to %{uid}
|
||||
and %{null} */
|
||||
|
||||
return _krb5_expand_path_tokens(context, str, res);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
|
Reference in New Issue
Block a user