diff options
author | Corinna Vinschen <corinna@vinschen.de> | 2011-03-31 19:33:53 +0400 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2011-03-31 19:33:53 +0400 |
commit | 3f74d8d568bd7772e2267d088ded2ab0f614d775 (patch) | |
tree | 485d81562df268f1df2db0fd9910f91d2bfca062 /winsup/cygwin/uinfo.cc | |
parent | 51c68491d859c96f099db41fbaa5c81e02795e5b (diff) |
* 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.
Diffstat (limited to 'winsup/cygwin/uinfo.cc')
-rw-r--r-- | winsup/cygwin/uinfo.cc | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/winsup/cygwin/uinfo.cc b/winsup/cygwin/uinfo.cc index 66cab121e..25c868ce4 100644 --- a/winsup/cygwin/uinfo.cc +++ b/winsup/cygwin/uinfo.cc @@ -40,12 +40,24 @@ cygheap_user::init () WCHAR user_name[UNLEN + 1]; DWORD user_name_len = UNLEN + 1; - if (!GetUserNameW (user_name, &user_name_len)) - wcpcpy (user_name, L"unknown"); - - 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); + /* This code is only run if a Cygwin process gets started by a native + Win32 process. We try to get the username from the environment, + first USERNAME (Win32), then USER (POSIX). If that fails (which is + very unlikely), it only has an impact if we don't have an entry in + /etc/passwd for this user either. In that case the username sticks + 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; PSECURITY_DESCRIPTOR psd; @@ -384,7 +396,7 @@ cygheap_user::env_domain (const char *name, size_t namelen) DWORD ulen = UNLEN + 1; WCHAR username[ulen]; - DWORD dlen = DNLEN + 1; + DWORD dlen = MAX_DOMAIN_NAME_LEN + 1; WCHAR userdomain[dlen]; SID_NAME_USE use; |