Patch from Secure Endpoints/Asanka Herath for windows support
This commit is contained in:
@@ -48,6 +48,8 @@ get_env_user(void)
|
||||
return user;
|
||||
}
|
||||
|
||||
#ifndef _WIN32
|
||||
|
||||
/*
|
||||
* Will only use operating-system dependant operation to get the
|
||||
* default principal, for use of functions that in ccache layer to
|
||||
@@ -93,7 +95,58 @@ _krb5_get_default_principal_local (krb5_context context,
|
||||
return ret;
|
||||
}
|
||||
|
||||
krb5_error_code KRB5_LIB_FUNCTION
|
||||
#else /* _WIN32 */
|
||||
|
||||
#define SECURITY_WIN32
|
||||
#include <security.h>
|
||||
|
||||
krb5_error_code
|
||||
_krb5_get_default_principal_local(krb5_context context,
|
||||
krb5_principal *princ)
|
||||
{
|
||||
krb5_error_code ret = 0;
|
||||
|
||||
/* See if we can get the principal first. We only expect this to
|
||||
work if logged into a domain. */
|
||||
{
|
||||
char username[1024];
|
||||
ULONG sz = sizeof(username);
|
||||
|
||||
if (GetUserNameEx(NameUserPrincipal, username, &sz)) {
|
||||
return krb5_parse_name_flags(context, username,
|
||||
KRB5_PRINCIPAL_PARSE_ENTERPRISE,
|
||||
princ);
|
||||
}
|
||||
}
|
||||
|
||||
/* Just get the Windows username. This should pretty much always
|
||||
work. */
|
||||
{
|
||||
char username[1024];
|
||||
DWORD dsz = sizeof(username);
|
||||
|
||||
if (GetUserName(username, &dsz)) {
|
||||
return krb5_make_principal(context, princ, NULL, username, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
/* Failing that, we look at the environment */
|
||||
{
|
||||
const char * username = get_env_user();
|
||||
|
||||
if (username == NULL) {
|
||||
krb5_set_error_string(context,
|
||||
"unable to figure out current principal");
|
||||
return ENOTTY; /* Really? */
|
||||
}
|
||||
|
||||
return krb5_make_principal(context, princ, NULL, username, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
|
||||
krb5_get_default_principal (krb5_context context,
|
||||
krb5_principal *princ)
|
||||
{
|
||||
|
Reference in New Issue
Block a user