summaryrefslogtreecommitdiff
path: root/source4/heimdal/lib/krb5/cache.c
diff options
context:
space:
mode:
Diffstat (limited to 'source4/heimdal/lib/krb5/cache.c')
-rw-r--r--source4/heimdal/lib/krb5/cache.c129
1 files changed, 32 insertions, 97 deletions
diff --git a/source4/heimdal/lib/krb5/cache.c b/source4/heimdal/lib/krb5/cache.c
index ce8040d07c..32a131b07c 100644
--- a/source4/heimdal/lib/krb5/cache.c
+++ b/source4/heimdal/lib/krb5/cache.c
@@ -83,7 +83,7 @@ main (int argc, char **argv)
while((ret = krb5_cc_next_cred(context, id, &cursor, &creds)) == 0){
char *principal;
- krb5_unparse_name_short(context, creds.server, &principal);
+ krb5_unparse_name(context, creds.server, &principal);
printf("principal: %s\\n", principal);
free(principal);
krb5_free_cred_contents (context, &creds);
@@ -206,8 +206,10 @@ allocate_ccache (krb5_context context,
}
ret = (*id)->ops->resolve(context, id, residual);
- if(ret)
+ if(ret) {
free(*id);
+ *id = NULL;
+ }
#ifdef KRB5_USE_PATH_TOKENS
if (exp_residual)
@@ -217,6 +219,25 @@ 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'.
* If the ccache name doesn't contain any colon, interpret it as a file name.
@@ -251,7 +272,7 @@ krb5_cc_resolve(krb5_context context,
id);
}
}
- if (strchr (name, ':') == NULL)
+ if (is_possible_path_name(name))
return allocate_ccache (context, &krb5_fcc_ops, name, id);
else {
krb5_set_error_message(context, KRB5_CC_UNKNOWN_TYPE,
@@ -389,84 +410,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
}
/*
@@ -554,7 +498,7 @@ KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
krb5_cc_set_default_name(krb5_context context, const char *name)
{
krb5_error_code ret = 0;
- char *p;
+ char *p = NULL, *exp_p = NULL;
if (name == NULL) {
const char *e = NULL;
@@ -606,26 +550,17 @@ krb5_cc_set_default_name(krb5_context context, const char *name)
return ENOMEM;
}
-#ifdef KRB5_USE_PATH_TOKENS
- {
- char * exp_p = NULL;
-
- if (_krb5_expand_path_tokens(context, p, &exp_p) == 0) {
- free (p);
- p = exp_p;
- } else {
- free (p);
- return EINVAL;
- }
- }
-#endif
+ ret = _krb5_expand_path_tokens(context, p, &exp_p);
+ free(p);
+ if (ret)
+ return ret;
if (context->default_cc_name)
free(context->default_cc_name);
- context->default_cc_name = p;
+ context->default_cc_name = exp_p;
- return ret;
+ return 0;
}
/**
@@ -1499,7 +1434,7 @@ krb5_cccol_cursor_next(krb5_context context, krb5_cccol_cursor cursor,
cursor->cursor = NULL;
if (ret != KRB5_CC_END)
break;
-
+
cursor->idx++;
}
if (cursor->idx >= context->num_cc_ops) {