* 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.
This commit is contained in:
Corinna Vinschen 2010-09-28 14:40:18 +00:00
parent 91e0b943a0
commit 2f1f8815c0
7 changed files with 122 additions and 15 deletions

View File

@ -1,3 +1,16 @@
2010-09-28 Corinna Vinschen <corinna@vinschen.de>
* 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.
2010-09-28 Corinna Vinschen <corinna@vinschen.de> 2010-09-28 Corinna Vinschen <corinna@vinschen.de>
* fhandler_tty.cc (fhandler_pty_master::setup): Always create master * fhandler_tty.cc (fhandler_pty_master::setup): Always create master

View File

@ -130,7 +130,7 @@ EXTRA_OFILES:=
MALLOC_OFILES:=@MALLOC_OFILES@ MALLOC_OFILES:=@MALLOC_OFILES@
DLL_IMPORTS:=$(w32api_lib)/libadvapi32.a $(w32api_lib)/libkernel32.a $(w32api_lib)/libntdll.a DLL_IMPORTS:=$(w32api_lib)/libkernel32.a $(w32api_lib)/libntdll.a
MT_SAFE_OBJECTS:= MT_SAFE_OBJECTS:=
# Please maintain this list in sorted order, with maximum files per 86 col line # Please maintain this list in sorted order, with maximum files per 86 col line

View File

@ -305,6 +305,77 @@ wsock_init ()
LoadDLLprime (ws2_32, _wsock_init) LoadDLLprime (ws2_32, _wsock_init)
LoadDLLfunc (AccessCheck, 32, advapi32)
LoadDLLfunc (AddAccessAllowedAce, 16, advapi32)
LoadDLLfunc (AddAccessDeniedAce, 16, advapi32)
LoadDLLfunc (AddAce, 20, advapi32)
LoadDLLfunc (AllocateLocallyUniqueId, 4, advapi32)
LoadDLLfunc (CopySid, 12, advapi32)
LoadDLLfunc (CreateProcessAsUserW, 44, advapi32)
LoadDLLfunc (CryptAcquireContextA, 20, advapi32)
LoadDLLfunc (CryptGenRandom, 12, advapi32)
LoadDLLfunc (CryptReleaseContext, 8, advapi32)
LoadDLLfunc (DeregisterEventSource, 4, advapi32)
LoadDLLfunc (DuplicateTokenEx, 24, advapi32)
LoadDLLfunc (EqualPrefixSid, 8, advapi32)
LoadDLLfunc (EqualSid, 8, advapi32)
LoadDLLfunc (FindFirstFreeAce, 8, advapi32)
LoadDLLfunc (GetAce, 12, advapi32)
LoadDLLfunc (GetKernelObjectSecurity, 20, advapi32)
LoadDLLfunc (GetLengthSid, 4, advapi32)
LoadDLLfunc (GetSecurityDescriptorDacl, 16, advapi32)
LoadDLLfunc (GetSecurityDescriptorGroup, 12, advapi32)
LoadDLLfunc (GetSecurityDescriptorOwner, 12, advapi32)
LoadDLLfunc (GetSecurityInfo, 32, advapi32)
LoadDLLfunc (GetSidIdentifierAuthority, 4, advapi32)
LoadDLLfunc (GetSidSubAuthority, 8, advapi32)
LoadDLLfunc (GetSidSubAuthorityCount, 4, advapi32)
LoadDLLfunc (GetTokenInformation, 20, advapi32)
LoadDLLfunc (GetUserNameW, 8, advapi32)
LoadDLLfunc (ImpersonateLoggedOnUser, 4, advapi32)
LoadDLLfunc (ImpersonateNamedPipeClient, 4, advapi32)
LoadDLLfunc (InitializeAcl, 12, advapi32)
LoadDLLfunc (InitializeSecurityDescriptor, 8, advapi32)
LoadDLLfunc (InitializeSid, 12, advapi32)
LoadDLLfunc (LogonUserW, 24, advapi32)
LoadDLLfunc (LookupAccountNameW, 28, advapi32)
LoadDLLfunc (LookupAccountSidA, 28, advapi32)
LoadDLLfunc (LookupAccountSidW, 28, advapi32)
LoadDLLfunc (LsaClose, 4, advapi32)
LoadDLLfunc (LsaEnumerateAccountRights, 16, advapi32)
LoadDLLfunc (LsaFreeMemory, 4, advapi32)
LoadDLLfunc (LsaNtStatusToWinError, 4, advapi32)
LoadDLLfunc (LsaOpenPolicy, 16, advapi32)
LoadDLLfunc (LsaRetrievePrivateData, 12, advapi32)
LoadDLLfunc (LsaStorePrivateData, 12, advapi32)
LoadDLLfunc (MakeSelfRelativeSD, 12, advapi32)
LoadDLLfunc (OpenProcessToken, 12, advapi32)
LoadDLLfunc (OpenThreadToken, 16, advapi32)
LoadDLLfunc (PrivilegeCheck, 12, advapi32)
LoadDLLfunc (RegCloseKey, 4, advapi32)
LoadDLLfunc (RegCreateKeyExA, 36, advapi32)
LoadDLLfunc (RegCreateKeyExW, 36, advapi32)
LoadDLLfunc (RegDeleteKeyA, 8, advapi32)
LoadDLLfunc (RegDeleteValueA, 8, advapi32)
LoadDLLfunc (RegEnumKeyExW, 32, advapi32)
LoadDLLfunc (RegEnumValueW, 32, advapi32)
LoadDLLfunc (RegGetKeySecurity, 16, advapi32)
LoadDLLfunc (RegLoadKeyW, 12, advapi32)
LoadDLLfunc (RegOpenKeyExA, 20, advapi32)
LoadDLLfunc (RegOpenKeyExW, 20, advapi32)
LoadDLLfunc (RegQueryInfoKeyA, 48, advapi32)
LoadDLLfunc (RegQueryValueExA, 24, advapi32)
LoadDLLfunc (RegQueryValueExW, 24, advapi32)
LoadDLLfunc (RegSetValueExA, 24, advapi32)
LoadDLLfunc (RegSetValueExW, 24, advapi32)
LoadDLLfunc (RegisterEventSourceA, 8, advapi32)
LoadDLLfunc (ReportEventA, 36, advapi32)
LoadDLLfunc (RevertToSelf, 0, advapi32)
LoadDLLfunc (SetSecurityDescriptorDacl, 16, advapi32)
LoadDLLfunc (SetSecurityDescriptorGroup, 12, advapi32)
LoadDLLfunc (SetSecurityDescriptorOwner, 12, advapi32)
LoadDLLfunc (SetTokenInformation, 16, advapi32)
LoadDLLfuncEx2 (DnsQuery_A, 24, dnsapi, 1, 127) // ERROR_PROC_NOT_FOUND LoadDLLfuncEx2 (DnsQuery_A, 24, dnsapi, 1, 127) // ERROR_PROC_NOT_FOUND
LoadDLLfuncEx (DnsRecordListFree, 8, dnsapi, 1) LoadDLLfuncEx (DnsRecordListFree, 8, dnsapi, 1)

View File

@ -467,6 +467,7 @@ mount_info::init ()
pathend = wcpcpy (pathend, L"\\etc\\fstab"); pathend = wcpcpy (pathend, L"\\etc\\fstab");
from_fstab (false, path, pathend); from_fstab (false, path, pathend);
if (cygheap->user.name () && *cygheap->user.name ())
from_fstab (true, path, pathend); from_fstab (true, path, pathend);
if (!got_usr_bin || !got_usr_lib) if (!got_usr_bin || !got_usr_lib)

View File

@ -66,7 +66,8 @@ pwdgrp::read_passwd ()
if (!user_shared->cb || myself->uid == ILLEGAL_UID) if (!user_shared->cb || myself->uid == ILLEGAL_UID)
searchentry = !internal_getpwsid (tu); searchentry = !internal_getpwsid (tu);
if (searchentry if (searchentry
&& (!(pw = internal_getpwnam (cygheap->user.name ())) && (!cygheap->user.name ()
|| !(pw = internal_getpwnam (cygheap->user.name ()))
|| !user_shared->cb || !user_shared->cb
|| (myself->uid != ILLEGAL_UID || (myself->uid != ILLEGAL_UID
&& myself->uid != (__uid32_t) pw->pw_uid && myself->uid != (__uid32_t) pw->pw_uid
@ -75,7 +76,7 @@ pwdgrp::read_passwd ()
static char linebuf[1024]; // must be static and static char linebuf[1024]; // must be static and
// should not be NO_COPY // should not be NO_COPY
snprintf (linebuf, sizeof (linebuf), "%s:*:%lu:%lu:,%s:%s:/bin/sh", snprintf (linebuf, sizeof (linebuf), "%s:*:%lu:%lu:,%s:%s:/bin/sh",
cygheap->user.name (), cygheap->user.name () ?: "",
(!user_shared->cb || myself->uid == ILLEGAL_UID) (!user_shared->cb || myself->uid == ILLEGAL_UID)
? UNKNOWN_UID : myself->uid, ? UNKNOWN_UID : myself->uid,
!user_shared->cb ? UNKNOWN_GID : myself->gid, !user_shared->cb ? UNKNOWN_GID : myself->gid,

View File

@ -312,7 +312,6 @@ user_info::initialize ()
spinlock sversion (version, CURR_USER_MAGIC); spinlock sversion (version, CURR_USER_MAGIC);
if (!sversion) if (!sversion)
{ {
cb = sizeof (*user_shared);
cygpsid sid (cygheap->user.sid ()); cygpsid sid (cygheap->user.sid ());
struct passwd *pw = internal_getpwsid (sid); struct passwd *pw = internal_getpwsid (sid);
/* Correct the user name with what's defined in /etc/passwd before /* Correct the user name with what's defined in /etc/passwd before
@ -320,6 +319,7 @@ user_info::initialize ()
if (pw) if (pw)
cygheap->user.set_name (pw->pw_name); cygheap->user.set_name (pw->pw_name);
mountinfo.init (); /* Initialize the mount table. */ mountinfo.init (); /* Initialize the mount table. */
cb = sizeof (*user_shared);
} }
else if (sversion != CURR_USER_MAGIC) else if (sversion != CURR_USER_MAGIC)
sversion.multiple_cygwin_problem ("user shared memory version", version, sversion.multiple_cygwin_problem ("user shared memory version", version,

View File

@ -38,14 +38,16 @@ void
cygheap_user::init () cygheap_user::init ()
{ {
WCHAR user_name[UNLEN + 1]; 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");
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)]; char mb_user_name[user_name_len = sys_wcstombs (NULL, 0, user_name)];
sys_wcstombs (mb_user_name, user_name_len, user_name); sys_wcstombs (mb_user_name, user_name_len, user_name);
set_name (mb_user_name); set_name (mb_user_name);
}
DWORD siz; DWORD siz;
PSECURITY_DESCRIPTOR psd; PSECURITY_DESCRIPTOR psd;
@ -96,10 +98,29 @@ internal_getlogin (cygheap_user &user)
{ {
struct passwd *pw = NULL; struct passwd *pw = NULL;
/* 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 (); cygpsid psid = user.sid ();
pw = internal_getpwsid (psid); pw = internal_getpwsid (psid);
}
if (!pw && !(pw = internal_getpwnam (user.name ())) if (!pw && !(pw = internal_getpwnam (user.name (), true))
&& !(pw = internal_getpwuid (DEFAULT_UID))) && !(pw = internal_getpwuid (DEFAULT_UID)))
debug_printf ("user not found in augmented /etc/passwd"); debug_printf ("user not found in augmented /etc/passwd");
else else