Windows: Use backwards compatible registry key for default cache

On Windows, existing applications determine and change the default
credentials cache using the Kerberos for Windows registry key
(\Software\MIT\Kerberos5, ccname).  Use it for backwards
compatibility.
This commit is contained in:
Asanka C. Herath
2010-10-20 12:42:13 -04:00
parent 45002e092c
commit 00ba841893
2 changed files with 70 additions and 0 deletions

@@ -512,6 +512,12 @@ krb5_cc_set_default_name(krb5_context context, const char *name)
context->default_cc_name_env = strdup(e);
}
}
#ifdef _WIN32
if (e == NULL) {
p = e = _krb5_get_default_mit_cc_name();
}
#endif
if (e == NULL) {
e = krb5_config_get_string(context, NULL, "libdefaults",
"default_cc_name", NULL);

@@ -431,4 +431,68 @@ krb5_free_default_realm(krb5_context context, krb5_realm realm)
return krb5_xfree(realm);
}
#ifdef _WIN32
char *
_krb5_get_default_mit_cc_name(void)
{
HKEY hk_k5 = 0;
LONG code;
DWORD type;
DWORD cb = 0, alloc_cb = 0;
LPBYTE buffer = NULL;
code = RegOpenKeyEx(HKEY_CURRENT_USER,
"Software\\MIT\\Kerberos5",
0, KEY_READ, &hk_k5);
if (code != ERROR_SUCCESS)
return NULL;
do {
code = RegQueryValueEx(hk_k5, "ccname", NULL,
&type, buffer, &cb);
if (code != ERROR_SUCCESS && code != ERROR_MORE_DATA)
break;
if (type != REG_SZ || cb == 0) {
code = ERROR_INVALID_PARAMETER;
break;
}
if (buffer == NULL || code == ERROR_MORE_DATA ||
cb >= alloc_cb) {
LPBYTE new_buf;
alloc_cb = cb + sizeof(char);
new_buf = realloc(buffer, alloc_cb);
if (new_buf == NULL) {
code = ERROR_MORE_DATA;
break;
}
buffer = new_buf;
continue;
}
break;
} while (TRUE);
if (code == ERROR_SUCCESS) {
if (buffer[cb / sizeof(char) - 1] != 0) {
buffer[cb / sizeof(char)] = 0;
}
return (char *) buffer;
}
if (buffer)
free(buffer);
return NULL;
}
#endif
#endif /* HEIMDAL_SMALLER */