ReactOS 0.4.16-dev-117-g38f21f9
environment.c File Reference
#include "winlogon.h"
Include dependency graph for environment.c:

Go to the source code of this file.

Functions

static VOID BuildVolatileEnvironment (IN PWLSESSION Session, IN HKEY hKeyCurrentUser)
 
BOOL CreateUserEnvironment (IN PWLSESSION Session)
 

Function Documentation

◆ BuildVolatileEnvironment()

static VOID BuildVolatileEnvironment ( IN PWLSESSION  Session,
IN HKEY  hKeyCurrentUser 
)
static

Definition at line 19 of file environment.c.

22{
24 LPCWSTR wstr;
26 WCHAR szEnvKey[MAX_PATH];
27 WCHAR szEnvValue[1024];
29 LPWSTR eqptr, endptr;
30 DWORD dwDisp;
31 LONG lError;
32 HKEY hKeyVolatileEnv;
33 HKEY hKeyShellFolders;
34 DWORD dwType;
36
37 /* Create the 'Volatile Environment' key */
38 lError = RegCreateKeyExW(hKeyCurrentUser,
39 L"Volatile Environment",
40 0,
41 NULL,
44 NULL,
45 &hKeyVolatileEnv,
46 &dwDisp);
47 if (lError != ERROR_SUCCESS)
48 {
49 WARN("WL: RegCreateKeyExW() failed to create the volatile environment key (Error: %ld)\n", lError);
50 return;
51 }
52
53 /* Parse the environment variables and add them to the volatile environment key */
54 if (Session->Profile->dwType == WLX_PROFILE_TYPE_V2_0 &&
55 Session->Profile->pszEnvironment != NULL)
56 {
57 wstr = Session->Profile->pszEnvironment;
58 while (*wstr != UNICODE_NULL)
59 {
60 size = wcslen(wstr) + 1;
61
62 eqptr = wcschr(wstr, L'=');
63
64 if (eqptr != NULL)
65 {
66 endptr = eqptr;
67
68 endptr--;
69 while (iswspace(*endptr))
70 endptr--;
71
72 length = (SIZE_T)(endptr - wstr + 1);
73
74 wcsncpy(szEnvKey, wstr, length);
75 szEnvKey[length] = 0;
76
77 eqptr++;
78 while (iswspace(*eqptr))
79 eqptr++;
80 wcscpy(szEnvValue, eqptr);
81
82 RegSetValueExW(hKeyVolatileEnv,
83 szEnvKey,
84 0,
85 REG_SZ,
86 (LPBYTE)szEnvValue,
87 (wcslen(szEnvValue) + 1) * sizeof(WCHAR));
88 }
89
90 wstr += size;
91 }
92 }
93
94 /* Set the 'APPDATA' environment variable */
95 lError = RegOpenKeyExW(hKeyCurrentUser,
96 L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders",
97 0,
99 &hKeyShellFolders);
100 if (lError == ERROR_SUCCESS)
101 {
102 dwSize = (MAX_PATH + 1) * sizeof(WCHAR);
103 lError = RegQueryValueExW(hKeyShellFolders,
104 L"AppData",
105 NULL,
106 &dwType,
107 (LPBYTE)szPath,
108 &dwSize);
109 if (lError == ERROR_SUCCESS)
110 {
111 TRACE("APPDATA path: %S\n", szPath);
112 RegSetValueExW(hKeyVolatileEnv,
113 L"APPDATA",
114 0,
115 REG_SZ,
116 (LPBYTE)szPath,
117 (wcslen(szPath) + 1) * sizeof(WCHAR));
118 }
119
120 RegCloseKey(hKeyShellFolders);
121 }
122
123 RegCloseKey(hKeyVolatileEnv);
124}
#define WARN(fmt,...)
Definition: precomp.h:61
#define RegCloseKey(hKey)
Definition: registry.h:49
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
LONG WINAPI RegCreateKeyExW(_In_ HKEY hKey, _In_ LPCWSTR lpSubKey, _In_ DWORD Reserved, _In_opt_ LPWSTR lpClass, _In_ DWORD dwOptions, _In_ REGSAM samDesired, _In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes, _Out_ PHKEY phkResult, _Out_opt_ LPDWORD lpdwDisposition)
Definition: reg.c:1096
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3333
LONG WINAPI RegSetValueExW(_In_ HKEY hKey, _In_ LPCWSTR lpValueName, _In_ DWORD Reserved, _In_ DWORD dwType, _In_ CONST BYTE *lpData, _In_ DWORD cbData)
Definition: reg.c:4882
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4103
#define wcschr
Definition: compat.h:17
#define MAX_PATH
Definition: compat.h:34
unsigned long DWORD
Definition: ntddk_ex.h:95
GLsizeiptr size
Definition: glext.h:5919
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
#define iswspace(_c)
Definition: ctype.h:669
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define REG_SZ
Definition: layer.c:22
LPCWSTR szPath
Definition: env.c:37
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:56
#define KEY_READ
Definition: nt_native.h:1023
#define KEY_WRITE
Definition: nt_native.h:1031
#define REG_OPTION_VOLATILE
Definition: nt_native.h:1060
#define UNICODE_NULL
#define L(x)
Definition: ntvdm.h:50
long LONG
Definition: pedump.c:60
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
_CRTIMP wchar_t *__cdecl wcsncpy(wchar_t *_Dest, const wchar_t *_Source, size_t _Count)
#define TRACE(s)
Definition: solgame.cpp:4
unsigned char * LPBYTE
Definition: typedefs.h:53
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define WLX_PROFILE_TYPE_V2_0
Definition: winwlx.h:51
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185

Referenced by CreateUserEnvironment().

◆ CreateUserEnvironment()

BOOL CreateUserEnvironment ( IN PWLSESSION  Session)

Definition at line 128 of file environment.c.

130{
131 HKEY hKeyCurrentUser;
132 LONG lError;
133
134 TRACE("WL: CreateUserEnvironment called\n");
135
136 /* Impersonate the new user */
137 if (!ImpersonateLoggedOnUser(Session->UserToken))
138 {
139 ERR("ImpersonateLoggedOnUser() failed with error %lu\n", GetLastError());
140 return FALSE;
141 }
142
143 /* Open the new user HKCU key */
145 &hKeyCurrentUser);
146 if (lError == ERROR_SUCCESS)
147 {
149 hKeyCurrentUser);
150 RegCloseKey(hKeyCurrentUser);
151 }
152
153 /* Revert the impersonation */
154 RevertToSelf();
155
156 TRACE("WL: CreateUserEnvironment done\n");
157
158 return TRUE;
159}
#define ERR(fmt,...)
Definition: precomp.h:57
static VOID BuildVolatileEnvironment(IN PWLSESSION Session, IN HKEY hKeyCurrentUser)
Definition: environment.c:19
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
LONG WINAPI RegOpenCurrentUser(IN REGSAM samDesired, OUT PHKEY phkResult)
Definition: reg.c:3209
BOOL WINAPI ImpersonateLoggedOnUser(HANDLE hToken)
Definition: misc.c:152
#define KEY_CREATE_SUB_KEY
Definition: nt_native.h:1018
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
BOOL WINAPI RevertToSelf(void)
Definition: security.c:1608

Referenced by HandleLogon().