Skip to content

Commit 802d9a3

Browse files
committed
Fix #71; Env vars like APPDATA, LOCALAPPDATA etc in sshd are set correctly now.
APPDATA, LOCALAPPDATA, HOMEDRIVE, HOMEPATH set correctly in sshd server
1 parent 44d8ddd commit 802d9a3

File tree

2 files changed

+32
-9
lines changed

2 files changed

+32
-9
lines changed

contrib/win32/win32compat/pwd.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ int GetDomainFromToken ( HANDLE *hAccessToken, UCHAR *___domain, DWORD dwSize)
129129
char *GetHomeDirFromToken(char *userName, HANDLE token)
130130
{
131131
UCHAR ___domain[200];
132+
wchar_t pw_buf[MAX_PATH] = { L'\0' };
132133

133134
debug("-> GetHomeDirFromToken()...");
134135

@@ -172,7 +173,19 @@ char *GetHomeDirFromToken(char *userName, HANDLE token)
172173

173174
return NULL;
174175
}
175-
176+
177+
// update APPDATA user's env variable
178+
if (SUCCEEDED(SHGetFolderPathW(NULL, CSIDL_APPDATA, token, 0, pw_buf)))
179+
{
180+
SetEnvironmentVariableW(L"APPDATA", pw_buf);
181+
}
182+
183+
// update LOCALAPPDATA user's env variable
184+
if (SUCCEEDED(SHGetFolderPathW(NULL, CSIDL_LOCAL_APPDATA, token, 0, pw_buf)))
185+
{
186+
SetEnvironmentVariableW(L"LOCALAPPDATA", pw_buf);
187+
}
188+
176189
/*
177190
* Unload user profile.
178191
*/

session.c

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -804,25 +804,25 @@ do_exec_no_pty(Session *s, const char *command)
804804
* Get user homedir if needed.
805805
*/
806806

807-
if (s -> pw -> pw_dir == NULL || s -> pw -> pw_dir[0] == '\0')
807+
if (1) // (s -> pw -> pw_dir == NULL || s -> pw -> pw_dir[0] == '\0')
808808
{
809809
/*
810810
* If there is homedir from LSA use it.
811811
*/
812812

813-
if (HomeDirLsaW[0] != '\0')
814-
{
815-
s -> pw -> pw_dir = HomeDirLsaW;
816-
}
813+
//if (HomeDirLsaW[0] != '\0')
814+
//{
815+
//s -> pw -> pw_dir = HomeDirLsaW;
816+
//}
817817

818818
/*
819819
* If not get homedir from token.
820820
*/
821821

822-
else
823-
{
822+
//else
823+
//{
824824
s -> pw -> pw_dir = GetHomeDirFromToken(s -> pw -> pw_name, hToken);
825-
}
825+
//}
826826
}
827827

828828
/*
@@ -832,6 +832,16 @@ do_exec_no_pty(Session *s, const char *command)
832832
_wchdir(s -> pw -> pw_dir);
833833

834834
SetEnvironmentVariableW(L"HOME", s -> pw -> pw_dir);
835+
wchar_t *wstr, wchr;
836+
wstr = wcschr(s->pw->pw_dir, ':');
837+
if (wstr) {
838+
wchr = *(wstr + 1);
839+
*(wstr + 1) = '\0';
840+
SetEnvironmentVariableW(L"HOMEDRIVE", s->pw->pw_dir);
841+
*(wstr + 1) = wchr;
842+
SetEnvironmentVariableW(L"HOMEPATH", (wstr+1));
843+
}
844+
835845
SetEnvironmentVariableW(L"USERPROFILE", s -> pw -> pw_dir);
836846

837847
// find the server name of the ___domain controller which created this token

0 commit comments

Comments
 (0)