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:
Diffstat (limited to 'winsup/cygwin/uinfo.cc')
-rw-r--r--winsup/cygwin/uinfo.cc73
1 files changed, 41 insertions, 32 deletions
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)
{