diff options
author | Corinna Vinschen <corinna@vinschen.de> | 2001-10-22 18:31:00 +0000 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2001-10-22 18:31:00 +0000 |
commit | 65d1068cb8f5cc2a2e291d3e45594b260762aa61 (patch) | |
tree | 5e6aa07130a141b4c6f33f1c68bee3b4e29270b4 /winsup/cygwin | |
parent | 333d60984389f9e0173c60d6016ac36099686b59 (diff) | |
download | cygnal-65d1068cb8f5cc2a2e291d3e45594b260762aa61.tar.gz cygnal-65d1068cb8f5cc2a2e291d3e45594b260762aa61.tar.bz2 cygnal-65d1068cb8f5cc2a2e291d3e45594b260762aa61.zip |
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().
Diffstat (limited to 'winsup/cygwin')
-rw-r--r-- | winsup/cygwin/ChangeLog | 8 | ||||
-rw-r--r-- | winsup/cygwin/syscalls.cc | 5 | ||||
-rw-r--r-- | winsup/cygwin/uinfo.cc | 73 |
3 files changed, 54 insertions, 32 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 0b231e1b8..9ced6a177 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,5 +1,13 @@ 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 to Linux style. diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc index 1fa7c37ee..9d9eaeb89 100644 --- a/winsup/cygwin/syscalls.cc +++ b/winsup/cygwin/syscalls.cc @@ -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) { diff --git a/winsup/cygwin/uinfo.cc b/winsup/cygwin/uinfo.cc index 79276e138..25994c702 100644 --- a/winsup/cygwin/uinfo.cc +++ b/winsup/cygwin/uinfo.cc @@ -78,45 +78,54 @@ internal_getlogin (cygheap_user &user) user.set_logsrv (buf + 2); setenv ("LOGONSERVER", buf, 1); } - LPUSER_INFO_3 ui = NULL; - WCHAR wuser[UNLEN + 1]; + debug_printf ("Domain: %s, Logon Server: %s, Windows Username: %s", + user.domain (), user.logsrv (), user.name ()); - /* 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]) + /* 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))) { - sys_wcstombs (buf, ui->usri3_home_dir_drive, MAX_PATH); - if (buf[0]) - strcat (buf, "\\"); - else + if (user.logsrv ()) { - env = getenv ("SYSTEMDRIVE"); - if (env && *env) - strcat (strcpy (buf, env), "\\"); + 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 - GetSystemDirectoryA (buf, MAX_PATH); + { + 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); } - setenv ("HOMEPATH", buf + 2, 1); - buf[2] = '\0'; - setenv ("HOMEDRIVE", buf, 1); - NetApiBufferFree (ui); + if (ui) + NetApiBufferFree (ui); } - debug_printf ("Domain: %s, Logon Server: %s, Windows Username: %s", - user.domain (), user.logsrv (), user.name ()); if (allow_ntsec) { |