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 *****************************************************************/
16 #include <wine/debug.h>
18 WINE_DEFAULT_DEBUG_CHANNEL(winlogon
);
20 /* GLOBALS ******************************************************************/
22 typedef HRESULT (WINAPI
*PFSHGETFOLDERPATHW
)(HWND
, int, HANDLE
, DWORD
, LPWSTR
);
25 /* FUNCTIONS ****************************************************************/
28 BuildVolatileEnvironment(IN PWLSESSION Session
,
31 HINSTANCE hShell32
= NULL
;
32 PFSHGETFOLDERPATHW pfSHGetFolderPathW
= NULL
;
33 WCHAR szPath
[MAX_PATH
+ 1];
34 WCHAR szExpandedPath
[MAX_PATH
+ 1];
37 WCHAR szEnvKey
[MAX_PATH
];
38 WCHAR szEnvValue
[1024];
42 /* Parse the environment variables and add them to the volatile environment key */
43 if (Session
->Profile
->dwType
== WLX_PROFILE_TYPE_V2_0
&&
44 Session
->Profile
->pszEnvironment
!= NULL
)
46 wstr
= Session
->Profile
->pszEnvironment
;
47 while (*wstr
!= UNICODE_NULL
)
49 size
= wcslen(wstr
) + 1;
51 eqptr
= wcschr(wstr
, L
'=');
58 while (iswspace(*endptr
))
61 length
= (SIZE_T
)(endptr
- wstr
+ 1);
63 wcsncpy(szEnvKey
, wstr
, length
);
67 while (iswspace(*eqptr
))
69 wcscpy(szEnvValue
, eqptr
);
76 (wcslen(szEnvValue
) + 1) * sizeof(WCHAR
));
83 /* Load shell32.dll and call SHGetFolderPathW to get the users appdata folder path */
84 hShell32
= LoadLibraryW(L
"shell32.dll");
87 pfSHGetFolderPathW
= (PFSHGETFOLDERPATHW
)GetProcAddress(hShell32
,
89 if (pfSHGetFolderPathW
!= NULL
)
91 if (pfSHGetFolderPathW(NULL
,
92 CSIDL_APPDATA
| CSIDL_FLAG_DONT_VERIFY
,
97 /* FIXME: Expand %USERPROFILE% here. SHGetFolderPathW should do it for us. See Bug #5372.*/
98 TRACE("APPDATA path: %S\n", szPath
);
99 ExpandEnvironmentStringsForUserW(Session
->UserToken
,
104 /* Add the appdata folder path to the users volatile environment key */
105 TRACE("APPDATA expanded path: %S\n", szExpandedPath
);
110 (LPBYTE
)szExpandedPath
,
111 (wcslen(szExpandedPath
) + 1) * sizeof(WCHAR
));
115 FreeLibrary(hShell32
);
121 CreateUserEnvironment(IN PWLSESSION Session
)
126 HKEY hKeyCurrentUser
;
128 TRACE("WL: CreateUserEnvironment called\n");
130 /* Impersonate the new user */
131 ImpersonateLoggedOnUser(Session
->UserToken
);
133 /* Open the new users HKCU key */
134 lError
= RegOpenCurrentUser(KEY_CREATE_SUB_KEY
,
136 if (lError
== ERROR_SUCCESS
)
138 /* Create the 'Volatile Environment' key */
139 lError
= RegCreateKeyExW(hKeyCurrentUser
,
140 L
"Volatile Environment",
148 if (lError
== ERROR_SUCCESS
)
150 BuildVolatileEnvironment(Session
,
157 WARN("WL: RegCreateKeyExW() failed (Error: %ld)\n", lError
);
160 RegCloseKey(hKeyCurrentUser
);
163 /* Revert the impersonation */
166 TRACE("WL: CreateUserEnvironment done\n");