Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2010-09-28 18:40:18 +0400
committerCorinna Vinschen <corinna@vinschen.de>2010-09-28 18:40:18 +0400
commit2f1f8815c037ee0387c30fba98689e544ab75c9a (patch)
tree58a54bb45cbd833ed7169a8669005e7468dbb1ec /winsup/cygwin/uinfo.cc
parent91e0b943a07e768bbdcd7d8da2b991eee41fc0c4 (diff)
* Makefile.in (DLL_IMPORTS): Remove libadvapi32.a.
* autoload.cc: Add all advapi32 entry points. * mount.cc (mount_info::init): Read user fstab only if we have a username. * passwd.cc (pwdgrp::read_passwd): Only use username if we have one. * shared.cc (user_info::initialize): Set cb last so as not to override planned behaviour in pwdgrp::read_passwd. * uinfo.cc (cygheap_user::init): Fetch Windows username from environment variable $USERNAME. Don't set name in cygheap if variable is empty. (internal_getlogin): If we still have no username, try GetUserNameW.
Diffstat (limited to 'winsup/cygwin/uinfo.cc')
-rw-r--r--winsup/cygwin/uinfo.cc41
1 files changed, 31 insertions, 10 deletions
diff --git a/winsup/cygwin/uinfo.cc b/winsup/cygwin/uinfo.cc
index 60db38e76..8ea3e1ab0 100644
--- a/winsup/cygwin/uinfo.cc
+++ b/winsup/cygwin/uinfo.cc
@@ -38,14 +38,16 @@ void
cygheap_user::init ()
{
WCHAR user_name[UNLEN + 1];
- DWORD user_name_len = UNLEN + 1;
+ DWORD user_name_len;
- 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);
+ user_name_len = GetEnvironmentVariableW (L"USERNAME", user_name, UNLEN + 1);
+ if (user_name_len)
+ {
+ user_name[UNLEN] = L'\0';
+ 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);
+ }
DWORD siz;
PSECURITY_DESCRIPTOR psd;
@@ -96,10 +98,29 @@ internal_getlogin (cygheap_user &user)
{
struct passwd *pw = NULL;
- cygpsid psid = user.sid ();
- pw = internal_getpwsid (psid);
+ /* Handle a border case. If neither $USERNAME, nor /etc/passwd exists,
+ we tryto fetch the username from the system now. */
+ if (!user.name () || !*user.name ())
+ {
+ WCHAR user_name[UNLEN + 1];
+ DWORD user_name_len = UNLEN + 1;
+
+ if (GetUserNameW (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);
+ user.set_name (mb_user_name);
+ }
+ else
+ user.set_name ("unknown");
+ }
+ else
+ {
+ cygpsid psid = user.sid ();
+ pw = internal_getpwsid (psid);
+ }
- if (!pw && !(pw = internal_getpwnam (user.name ()))
+ if (!pw && !(pw = internal_getpwnam (user.name (), true))
&& !(pw = internal_getpwuid (DEFAULT_UID)))
debug_printf ("user not found in augmented /etc/passwd");
else