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 (w3seek@users.sourceforge.net)
7 * Hervé Poussineau (hpoussin@reactos.org)
11 /* INCLUDES *****************************************************************/
15 #include <wine/debug.h>
17 WINE_DEFAULT_DEBUG_CHANNEL(winlogon
);
19 /* GLOBALS ******************************************************************/
22 /* FUNCTIONS ****************************************************************/
25 CreateUserEnvironment(IN PWLSESSION Session
,
26 IN LPVOID
*lpEnvironment
,
30 SIZE_T EnvBlockSize
= 0, ProfileSize
= 0;
31 LPVOID lpEnviron
= NULL
;
32 LPWSTR lpFullEnviron
= NULL
;
38 TRACE("WL: CreateUserEnvironment called\n");
40 /* Create environment block for the user */
41 if (!CreateEnvironmentBlock(&lpEnviron
,
45 WARN("WL: CreateEnvironmentBlock() failed\n");
49 if (Session
->Profile
->dwType
== WLX_PROFILE_TYPE_V2_0
&& Session
->Profile
->pszEnvironment
)
51 /* Count required size for full environment */
52 wstr
= (LPCWSTR
)lpEnviron
;
53 while (*wstr
!= UNICODE_NULL
)
55 SIZE_T size
= wcslen(wstr
) + 1;
60 wstr
= Session
->Profile
->pszEnvironment
;
61 while (*wstr
!= UNICODE_NULL
)
63 SIZE_T size
= wcslen(wstr
) + 1;
68 /* Allocate enough memory */
69 lpFullEnviron
= HeapAlloc(GetProcessHeap
, 0, (EnvBlockSize
+ ProfileSize
+ 1) * sizeof(WCHAR
));
72 TRACE("HeapAlloc() failed\n");
76 /* Fill user environment block */
77 CopyMemory(lpFullEnviron
,
79 EnvBlockSize
* sizeof(WCHAR
));
80 CopyMemory(&lpFullEnviron
[EnvBlockSize
],
81 Session
->Profile
->pszEnvironment
,
82 ProfileSize
* sizeof(WCHAR
));
83 lpFullEnviron
[EnvBlockSize
+ ProfileSize
] = UNICODE_NULL
;
87 lpFullEnviron
= (LPWSTR
)lpEnviron
;
90 /* Impersonate the new user */
91 ImpersonateLoggedOnUser(Session
->UserToken
);
93 /* Open the new users HKCU key */
94 lError
= RegOpenCurrentUser(KEY_CREATE_SUB_KEY
,
96 if (lError
== ERROR_SUCCESS
)
98 /* Create the 'Volatile Environment' key */
99 lError
= RegCreateKeyExW(hKeyCurrentUser
,
100 L
"Volatile Environment",
108 if (lError
== ERROR_SUCCESS
)
114 WARN("WL: RegCreateKeyExW() failed (Error: %ld)\n", lError
);
117 RegCloseKey(hKeyCurrentUser
);
120 /* Revert the impersonation */
123 *lpEnvironment
= lpEnviron
;
124 *lpFullEnv
= lpFullEnviron
;
126 TRACE("WL: CreateUserEnvironment done\n");