Patch suggested by Ian Ray <ian.ray@nokia.com>:

* syscalls.cc (seteuid): Unset environment variables HOMEDRIVE and
	HOMEPATH before calling internal_getlogin().
	* uinfo.cc (internal_getlogin): Use default HOMEPATH and HOMEDRIVE
	from environment if both are present, else query NetUserGetInfo().
This commit is contained in:
Corinna Vinschen 2001-10-22 18:31:00 +00:00
parent 333d609843
commit 65d1068cb8
3 changed files with 59 additions and 37 deletions

View File

@ -1,3 +1,11 @@
2001-10-22 Corinna Vinschen <corinna@vinschen.de>
Patch suggested by Ian Ray <ian.ray@nokia.com>:
* syscalls.cc (seteuid): Unset environment variables HOMEDRIVE and
HOMEPATH before calling internal_getlogin().
* uinfo.cc (internal_getlogin): Use default HOMEPATH and HOMEDRIVE
from environment if both are present, else query NetUserGetInfo().
2001-10-22 Corinna Vinschen <corinna@vinschen.de>
* net.cc (get_2k_ifconf): Change multiple IP address naming scheme

View File

@ -2031,6 +2031,11 @@ seteuid (uid_t uid)
retrieving user's SID. */
user.token = cygheap->user.impersonated ? cygheap->user.token
: INVALID_HANDLE_VALUE;
/* Unsetting these both env vars is necessary to get NetUserGetInfo()
called in internal_getlogin (). Otherwise the wrong path is used
after a user switch, probably. */
unsetenv ("HOMEDRIVE");
unsetenv ("HOMEPATH");
struct passwd *pw_cur = internal_getlogin (user);
if (pw_cur != pw_new)
{

View File

@ -78,46 +78,55 @@ internal_getlogin (cygheap_user &user)
user.set_logsrv (buf + 2);
setenv ("LOGONSERVER", buf, 1);
}
LPUSER_INFO_3 ui = NULL;
WCHAR wuser[UNLEN + 1];
/* HOMEDRIVE and HOMEPATH are wrong most of the time, too,
after changing user context! */
sys_mbstowcs (wuser, user.name (), UNLEN + 1);
if (NetUserGetInfo (NULL, wuser, 3, (LPBYTE *) &ui) && user.logsrv ())
{
WCHAR wlogsrv[INTERNET_MAX_HOST_NAME_LENGTH + 3];
strcat (strcpy (buf, "\\\\"), user.logsrv ());
sys_mbstowcs (wlogsrv, buf, INTERNET_MAX_HOST_NAME_LENGTH + 3);
ui = NULL;
if (NetUserGetInfo (wlogsrv, wuser, 3, (LPBYTE *) &ui))
ui = NULL;
}
if (ui)
{
sys_wcstombs (buf, ui->usri3_home_dir, MAX_PATH);
if (!buf[0])
{
sys_wcstombs (buf, ui->usri3_home_dir_drive, MAX_PATH);
if (buf[0])
strcat (buf, "\\");
else
{
env = getenv ("SYSTEMDRIVE");
if (env && *env)
strcat (strcpy (buf, env), "\\");
else
GetSystemDirectoryA (buf, MAX_PATH);
}
}
setenv ("HOMEPATH", buf + 2, 1);
buf[2] = '\0';
setenv ("HOMEDRIVE", buf, 1);
NetApiBufferFree (ui);
}
debug_printf ("Domain: %s, Logon Server: %s, Windows Username: %s",
user.domain (), user.logsrv (), user.name ());
/* NetUserGetInfo() can be slow in NT domain environment, thus we
* only obtain HOMEDRIVE and HOMEPATH if they are not already set
* in the environment. */
if (!getenv ("HOMEPATH") || !getenv ("HOMEDRIVE"))
{
LPUSER_INFO_3 ui = NULL;
WCHAR wuser[UNLEN + 1];
sys_mbstowcs (wuser, user.name (), sizeof (wuser) / sizeof (*wuser));
if ((ret = NetUserGetInfo (NULL, wuser, 3, (LPBYTE *)&ui)))
{
if (user.logsrv ())
{
WCHAR wlogsrv[INTERNET_MAX_HOST_NAME_LENGTH + 3];
strcat (strcpy (buf, "\\\\"), user.logsrv ());
sys_mbstowcs (wlogsrv, buf,
sizeof (wlogsrv) / sizeof(*wlogsrv));
ret = NetUserGetInfo (wlogsrv, wuser, 3,(LPBYTE *)&ui);
}
}
if (!ret)
{
sys_wcstombs (buf, ui->usri3_home_dir, MAX_PATH);
if (!buf[0])
{
sys_wcstombs (buf, ui->usri3_home_dir_drive, MAX_PATH);
if (buf[0])
strcat (buf, "\\");
else
{
env = getenv ("SYSTEMDRIVE");
if (env && *env)
strcat (strcpy (buf, env), "\\");
else
GetSystemDirectoryA (buf, MAX_PATH);
}
}
setenv ("HOMEPATH", buf + 2, 1);
buf[2] = '\0';
setenv ("HOMEDRIVE", buf, 1);
}
if (ui)
NetApiBufferFree (ui);
}
if (allow_ntsec)
{
HANDLE ptok = user.token; /* Which is INVALID_HANDLE_VALUE if no