* uinfo.cc (cygheap_user::init): Don't call GetUserName. Fetch username

from Windows environment instead.  Explain why.
	(cygheap_user::env_domain): Use MAX_DOMAIN_NAME_LEN rather than DNLEN
	to specify the size of the domain name buffer.
This commit is contained in:
Corinna Vinschen 2011-03-31 15:33:53 +00:00
parent 51c68491d8
commit 3f74d8d568
2 changed files with 26 additions and 7 deletions

View File

@ -1,3 +1,10 @@
2011-03-31 Corinna Vinschen <corinna@vinschen.de>
* uinfo.cc (cygheap_user::init): Don't call GetUserName. Fetch username
from Windows environment instead. Explain why.
(cygheap_user::env_domain): Use MAX_DOMAIN_NAME_LEN rather than DNLEN
to specify the size of the domain name buffer.
2011-03-30 Corinna Vinschen <corinna@vinschen.de> 2011-03-30 Corinna Vinschen <corinna@vinschen.de>
* hires.h: Fix copyright. * hires.h: Fix copyright.

View File

@ -40,12 +40,24 @@ cygheap_user::init ()
WCHAR user_name[UNLEN + 1]; WCHAR user_name[UNLEN + 1];
DWORD user_name_len = UNLEN + 1; DWORD user_name_len = UNLEN + 1;
if (!GetUserNameW (user_name, &user_name_len)) /* This code is only run if a Cygwin process gets started by a native
wcpcpy (user_name, L"unknown"); Win32 process. We try to get the username from the environment,
first USERNAME (Win32), then USER (POSIX). If that fails (which is
char mb_user_name[user_name_len = sys_wcstombs (NULL, 0, user_name)]; very unlikely), it only has an impact if we don't have an entry in
sys_wcstombs (mb_user_name, user_name_len, user_name); /etc/passwd for this user either. In that case the username sticks
set_name (mb_user_name); to "unknown". Since this is called early in initialization, and
since we don't want pull in a dependency to any other DLL except
ntdll and kernel32 at this early stage, don't call GetUserName,
GetUserNameEx, NetWkstaUserGetInfo, etc. */
if (GetEnvironmentVariableW (L"USERNAME", user_name, user_name_len)
|| GetEnvironmentVariableW (L"USER", user_name, user_name_len))
{
char mb_user_name[user_name_len = sys_wcstombs (NULL, 0, user_name)];
sys_wcstombs (mb_user_name, user_name_len, user_name);
set_name (mb_user_name);
}
else
set_name ("unknown");
DWORD siz; DWORD siz;
PSECURITY_DESCRIPTOR psd; PSECURITY_DESCRIPTOR psd;
@ -384,7 +396,7 @@ cygheap_user::env_domain (const char *name, size_t namelen)
DWORD ulen = UNLEN + 1; DWORD ulen = UNLEN + 1;
WCHAR username[ulen]; WCHAR username[ulen];
DWORD dlen = DNLEN + 1; DWORD dlen = MAX_DOMAIN_NAME_LEN + 1;
WCHAR userdomain[dlen]; WCHAR userdomain[dlen];
SID_NAME_USE use; SID_NAME_USE use;