Skip to content

Commit e03efb6

Browse files
committed
[WINLOGON]
- Move environment creation to a separate file. - Impersonate the new user and create the 'Volatile Environment' key for the new user. svn path=/trunk/; revision=47129
1 parent 0963ef8 commit e03efb6

File tree

4 files changed

+138
-49
lines changed

4 files changed

+138
-49
lines changed
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
/*
2+
* COPYRIGHT: See COPYING in the top level directory
3+
* PROJECT: ReactOS Winlogon
4+
* FILE: base/system/winlogon/environment.c
5+
* PURPOSE: User environment routines
6+
* PROGRAMMERS: Thomas Weidenmueller ([email protected])
7+
* Hervé Poussineau ([email protected])
8+
* Eric Kohl
9+
*/
10+
11+
/* INCLUDES *****************************************************************/
12+
13+
#include "winlogon.h"
14+
15+
#include <wine/debug.h>
16+
17+
WINE_DEFAULT_DEBUG_CHANNEL(winlogon);
18+
19+
/* GLOBALS ******************************************************************/
20+
21+
22+
/* FUNCTIONS ****************************************************************/
23+
24+
BOOL
25+
CreateUserEnvironment(IN PWLSESSION Session,
26+
IN LPVOID *lpEnvironment,
27+
IN LPWSTR *lpFullEnv)
28+
{
29+
LPCWSTR wstr;
30+
SIZE_T EnvBlockSize = 0, ProfileSize = 0;
31+
LPVOID lpEnviron = NULL;
32+
LPWSTR lpFullEnviron = NULL;
33+
HKEY hKey;
34+
DWORD dwDisp;
35+
LONG lError;
36+
HKEY hKeyCurrentUser;
37+
38+
TRACE("WL: CreateUserEnvironment called\n");
39+
40+
/* Create environment block for the user */
41+
if (!CreateEnvironmentBlock(&lpEnviron,
42+
Session->UserToken,
43+
TRUE))
44+
{
45+
WARN("WL: CreateEnvironmentBlock() failed\n");
46+
return FALSE;
47+
}
48+
49+
if (Session->Profile->dwType == WLX_PROFILE_TYPE_V2_0 && Session->Profile->pszEnvironment)
50+
{
51+
/* Count required size for full environment */
52+
wstr = (LPCWSTR)lpEnviron;
53+
while (*wstr != UNICODE_NULL)
54+
{
55+
SIZE_T size = wcslen(wstr) + 1;
56+
wstr += size;
57+
EnvBlockSize += size;
58+
}
59+
60+
wstr = Session->Profile->pszEnvironment;
61+
while (*wstr != UNICODE_NULL)
62+
{
63+
SIZE_T size = wcslen(wstr) + 1;
64+
wstr += size;
65+
ProfileSize += size;
66+
}
67+
68+
/* Allocate enough memory */
69+
lpFullEnviron = HeapAlloc(GetProcessHeap, 0, (EnvBlockSize + ProfileSize + 1) * sizeof(WCHAR));
70+
if (!lpFullEnviron)
71+
{
72+
TRACE("HeapAlloc() failed\n");
73+
return FALSE;
74+
}
75+
76+
/* Fill user environment block */
77+
CopyMemory(lpFullEnviron,
78+
lpEnviron,
79+
EnvBlockSize * sizeof(WCHAR));
80+
CopyMemory(&lpFullEnviron[EnvBlockSize],
81+
Session->Profile->pszEnvironment,
82+
ProfileSize * sizeof(WCHAR));
83+
lpFullEnviron[EnvBlockSize + ProfileSize] = UNICODE_NULL;
84+
}
85+
else
86+
{
87+
lpFullEnviron = (LPWSTR)lpEnviron;
88+
}
89+
90+
/* Impersonate the new user */
91+
ImpersonateLoggedOnUser(Session->UserToken);
92+
93+
/* Open the new users HKCU key */
94+
lError = RegOpenCurrentUser(KEY_CREATE_SUB_KEY,
95+
&hKeyCurrentUser);
96+
if (lError == ERROR_SUCCESS)
97+
{
98+
/* Create the 'Volatile Environment' key */
99+
lError = RegCreateKeyExW(hKeyCurrentUser,
100+
L"Volatile Environment",
101+
0,
102+
NULL,
103+
REG_OPTION_VOLATILE,
104+
KEY_WRITE,
105+
NULL,
106+
&hKey,
107+
&dwDisp);
108+
if (lError == ERROR_SUCCESS)
109+
{
110+
RegCloseKey(hKey);
111+
}
112+
else
113+
{
114+
WARN("WL: RegCreateKeyExW() failed (Error: %ld)\n", lError);
115+
}
116+
117+
RegCloseKey(hKeyCurrentUser);
118+
}
119+
120+
/* Revert the impersonation */
121+
RevertToSelf();
122+
123+
*lpEnvironment = lpEnviron;
124+
*lpFullEnv = lpFullEnviron;
125+
126+
TRACE("WL: CreateUserEnvironment done\n");
127+
128+
return TRUE;
129+
}

reactos/base/system/winlogon/sas.c

Lines changed: 2 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,6 @@ HandleLogon(
171171
PROFILEINFOW ProfileInfo;
172172
LPVOID lpEnvironment = NULL;
173173
LPWSTR lpFullEnv = NULL;
174-
LPCWSTR wstr;
175-
SIZE_T EnvBlockSize = 0, ProfileSize = 0;
176174
BOOLEAN Old;
177175
BOOL ret = FALSE;
178176

@@ -210,57 +208,12 @@ HandleLogon(
210208
}
211209

212210
/* Create environment block for the user */
213-
if (!CreateEnvironmentBlock(
214-
&lpEnvironment,
215-
Session->UserToken,
216-
TRUE))
211+
if (!CreateUserEnvironment(Session, &lpEnvironment, &lpFullEnv))
217212
{
218-
WARN("WL: CreateEnvironmentBlock() failed\n");
213+
WARN("WL: SetUserEnvironment() failed\n");
219214
goto cleanup;
220215
}
221216

222-
if (Session->Profile->dwType == WLX_PROFILE_TYPE_V2_0 && Session->Profile->pszEnvironment)
223-
{
224-
/* Count required size for full environment */
225-
wstr = (LPCWSTR)lpEnvironment;
226-
while (*wstr != UNICODE_NULL)
227-
{
228-
SIZE_T size = wcslen(wstr) + 1;
229-
wstr += size;
230-
EnvBlockSize += size;
231-
}
232-
wstr = Session->Profile->pszEnvironment;
233-
while (*wstr != UNICODE_NULL)
234-
{
235-
SIZE_T size = wcslen(wstr) + 1;
236-
wstr += size;
237-
ProfileSize += size;
238-
}
239-
240-
/* Allocate enough memory */
241-
lpFullEnv = HeapAlloc(GetProcessHeap, 0, (EnvBlockSize + ProfileSize + 1) * sizeof(WCHAR));
242-
if (!lpFullEnv)
243-
{
244-
TRACE("HeapAlloc() failed\n");
245-
goto cleanup;
246-
}
247-
248-
/* Fill user environment block */
249-
CopyMemory(
250-
lpFullEnv,
251-
lpEnvironment,
252-
EnvBlockSize * sizeof(WCHAR));
253-
CopyMemory(
254-
&lpFullEnv[EnvBlockSize],
255-
Session->Profile->pszEnvironment,
256-
ProfileSize * sizeof(WCHAR));
257-
lpFullEnv[EnvBlockSize + ProfileSize] = UNICODE_NULL;
258-
}
259-
else
260-
{
261-
lpFullEnv = (LPWSTR)lpEnvironment;
262-
}
263-
264217
DisplayStatusMessage(Session, Session->WinlogonDesktop, IDS_APPLYINGYOURPERSONALSETTINGS);
265218
UpdatePerUserSystemParameters(0, TRUE);
266219

reactos/base/system/winlogon/winlogon.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,12 @@ BOOL WINAPI
180180
UpdatePerUserSystemParameters(DWORD dwUnknown,
181181
DWORD dwReserved);
182182

183+
/* environment.c */
184+
BOOL
185+
CreateUserEnvironment(IN PWLSESSION Session,
186+
IN LPVOID *lpEnvironment,
187+
IN LPWSTR *lpFullEnv);
188+
183189
/* sas.c */
184190
BOOL
185191
SetDefaultLanguage(

reactos/base/system/winlogon/winlogon.rbuild

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<library>advapi32</library>
99
<library>userenv</library>
1010
<library>secur32</library>
11+
<file>environment.c</file>
1112
<file>sas.c</file>
1213
<file>screensaver.c</file>
1314
<file>setup.c</file>

0 commit comments

Comments
 (0)