--- uinfo.cc-orig Tue Oct 2 16:18:09 2001 +++ uinfo.cc Tue Oct 2 16:53:34 2001 @@ -76,28 +76,48 @@ internal_getlogin (cygheap_user &user) user.set_logsrv (buf + 2); setenv ("LOGONSERVER", buf, 1); } + LPUSER_INFO_3 ui = NULL; - WCHAR wuser[UNLEN + 1]; - WCHAR wlogsrv[INTERNET_MAX_HOST_NAME_LENGTH + 3]; - /* HOMEDRIVE and HOMEPATH are wrong most of the time, too, - after changing user context! */ - sys_mbstowcs (wuser, user.name (), UNLEN + 1); - wlogsrv[0] = '\0'; - if (user.logsrv ()) - { - strcat (strcpy (buf, "\\\\"), user.logsrv ()); - sys_mbstowcs (wlogsrv, buf, INTERNET_MAX_HOST_NAME_LENGTH + 3); + /* + * 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")) + { + WCHAR wuser[UNLEN + 1]; + + sys_mbstowcs (wuser, user.name (), sizeof(wuser)/sizeof(*wuser)); + ret = NetUserGetInfo (NULL, wuser, 3, (LPBYTE *)&ui); + + if (ret) + { + 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); + } + } + } + else + { + ret = 1; } - if (!NetUserGetInfo (NULL, wuser, 3, (LPBYTE *)&ui) - || (wlogsrv[0] && !NetUserGetInfo (wlogsrv, wuser, 3,(LPBYTE *)&ui))) + + if (ret == 0) { 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, "\\"); + { + strcat (buf, "\\"); + } else { env = getenv ("SYSTEMDRIVE"); @@ -110,8 +130,14 @@ internal_getlogin (cygheap_user &user) setenv ("HOMEPATH", buf + 2, 1); buf[2] = '\0'; setenv ("HOMEDRIVE", buf, 1); + } + + if (ui) + { NetApiBufferFree (ui); + ui = NULL; } + debug_printf ("Domain: %s, Logon Server: %s, Windows Username: %s", user.domain (), user.logsrv (), user.name ());