Skip to content

Commit 5c3dc05

Browse files
committed
Fixed Wrong user profile folder created on first logon through ssh problem
Fixed this #3 problem ticket. We determine domain hostname which created the authenticated token from the token and then pass it to LoadUserProfile() Windows API which now correctly creates the user's home directory name and profile folder.
1 parent 47df661 commit 5c3dc05

File tree

1 file changed

+37
-14
lines changed
  • contrib/win32/win32compat

1 file changed

+37
-14
lines changed

contrib/win32/win32compat/pwd.c

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,23 @@ static char pw_homedir_ascii[MAX_PATH] = {'\0'};
9797
static char pw_password[MAX_PATH] = {'\0'};
9898
static char pw_shellpath[MAX_PATH] = {'\0'};
9999

100+
/* given a access token, find the domain name of user account of the access token */
101+
int GetDomainFromToken ( HANDLE *hAccessToken, UCHAR *domain, DWORD dwSize)
102+
{
103+
UCHAR InfoBuffer[1000],username[200];
104+
PTOKEN_USER pTokenUser = (PTOKEN_USER)InfoBuffer;
105+
DWORD dwInfoBufferSize,dwAccountSize = 200, dwDomainSize = dwSize;
106+
SID_NAME_USE snu;
107+
108+
domain[0] = '\0' ;
109+
GetTokenInformation(*hAccessToken,TokenUser,InfoBuffer,
110+
1000, &dwInfoBufferSize);
111+
112+
LookupAccountSid(NULL, pTokenUser->User.Sid, (LPSTR)username,
113+
&dwAccountSize,(LPSTR)domain, &dwDomainSize, &snu);
114+
return 0;
115+
}
116+
100117
/*
101118
* Retrieve user homedir from token, save it in static string
102119
* and return pointer to this string.
@@ -109,24 +126,30 @@ static char pw_shellpath[MAX_PATH] = {'\0'};
109126

110127
char *GetHomeDirFromToken(char *userName, HANDLE token)
111128
{
112-
113-
wchar_t userNameW[UNLEN + 1];
129+
UCHAR domain[200];
114130

115131
debug("-> GetHomeDirFromToken()...");
116132

117-
PROFILEINFOW profileInfo;
118-
119-
if (MultiByteToWideChar(CP_UTF8, 0, userName, -1, userNameW, UNLEN) == 0)
120-
{
121-
debug("userName encoding conversion failure");
122-
return NULL;
123-
}
124-
125-
memset(&profileInfo, 0, sizeof(profileInfo));
133+
PROFILEINFO profileInfo;
134+
135+
// find the server name of the domain controller which created this token
136+
GetDomainFromToken ( &token, domain, sizeof(domain));
137+
//if (MultiByteToWideChar(CP_UTF8, 0, domain, -1, domainW, sizeof(domainW)) == 0)
138+
//{
139+
//debug("DomainServerName encoding conversion failure");
140+
//return NULL;
141+
//}
142+
143+
profileInfo.dwFlags = PI_NOUI;
144+
profileInfo.lpProfilePath = NULL;
145+
profileInfo.lpUserName = userName;
146+
profileInfo.lpDefaultPath = NULL;
147+
profileInfo.lpServerName = domain;
148+
profileInfo.lpPolicyPath = NULL;
149+
profileInfo.hProfile = NULL;
150+
profileInfo.dwSize = sizeof(profileInfo);
151+
126152

127-
profileInfo.dwSize = sizeof(profileInfo);
128-
profileInfo.lpUserName = userNameW;
129-
profileInfo.lpServerName = NULL;
130153

131154
if (LoadUserProfile(token, &profileInfo) == FALSE)
132155
{

0 commit comments

Comments
 (0)