Author: ekohl
Date: Sat May 8 18:30:56 2010
New Revision: 47129
URL:
http://svn.reactos.org/svn/reactos?rev=47129&view=rev
Log:
[WINLOGON]
- Move environment creation to a separate file.
- Impersonate the new user and create the 'Volatile Environment' key for the new
user.
Added:
trunk/reactos/base/system/winlogon/environment.c (with props)
Modified:
trunk/reactos/base/system/winlogon/sas.c
trunk/reactos/base/system/winlogon/winlogon.h
trunk/reactos/base/system/winlogon/winlogon.rbuild
Added: trunk/reactos/base/system/winlogon/environment.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/system/winlogon/envir…
==============================================================================
--- trunk/reactos/base/system/winlogon/environment.c (added)
+++ trunk/reactos/base/system/winlogon/environment.c [iso-8859-1] Sat May 8 18:30:56
2010
@@ -1,0 +1,129 @@
+/*
+ * COPYRIGHT: See COPYING in the top level directory
+ * PROJECT: ReactOS Winlogon
+ * FILE: base/system/winlogon/environment.c
+ * PURPOSE: User environment routines
+ * PROGRAMMERS: Thomas Weidenmueller (w3seek(a)users.sourceforge.net)
+ * Hervé Poussineau (hpoussin(a)reactos.org)
+ * Eric Kohl
+ */
+
+/* INCLUDES *****************************************************************/
+
+#include "winlogon.h"
+
+#include <wine/debug.h>
+
+WINE_DEFAULT_DEBUG_CHANNEL(winlogon);
+
+/* GLOBALS ******************************************************************/
+
+
+/* FUNCTIONS ****************************************************************/
+
+BOOL
+CreateUserEnvironment(IN PWLSESSION Session,
+ IN LPVOID *lpEnvironment,
+ IN LPWSTR *lpFullEnv)
+{
+ LPCWSTR wstr;
+ SIZE_T EnvBlockSize = 0, ProfileSize = 0;
+ LPVOID lpEnviron = NULL;
+ LPWSTR lpFullEnviron = NULL;
+ HKEY hKey;
+ DWORD dwDisp;
+ LONG lError;
+ HKEY hKeyCurrentUser;
+
+ TRACE("WL: CreateUserEnvironment called\n");
+
+ /* Create environment block for the user */
+ if (!CreateEnvironmentBlock(&lpEnviron,
+ Session->UserToken,
+ TRUE))
+ {
+ WARN("WL: CreateEnvironmentBlock() failed\n");
+ return FALSE;
+ }
+
+ if (Session->Profile->dwType == WLX_PROFILE_TYPE_V2_0 &&
Session->Profile->pszEnvironment)
+ {
+ /* Count required size for full environment */
+ wstr = (LPCWSTR)lpEnviron;
+ while (*wstr != UNICODE_NULL)
+ {
+ SIZE_T size = wcslen(wstr) + 1;
+ wstr += size;
+ EnvBlockSize += size;
+ }
+
+ wstr = Session->Profile->pszEnvironment;
+ while (*wstr != UNICODE_NULL)
+ {
+ SIZE_T size = wcslen(wstr) + 1;
+ wstr += size;
+ ProfileSize += size;
+ }
+
+ /* Allocate enough memory */
+ lpFullEnviron = HeapAlloc(GetProcessHeap, 0, (EnvBlockSize + ProfileSize + 1) *
sizeof(WCHAR));
+ if (!lpFullEnviron)
+ {
+ TRACE("HeapAlloc() failed\n");
+ return FALSE;
+ }
+
+ /* Fill user environment block */
+ CopyMemory(lpFullEnviron,
+ lpEnviron,
+ EnvBlockSize * sizeof(WCHAR));
+ CopyMemory(&lpFullEnviron[EnvBlockSize],
+ Session->Profile->pszEnvironment,
+ ProfileSize * sizeof(WCHAR));
+ lpFullEnviron[EnvBlockSize + ProfileSize] = UNICODE_NULL;
+ }
+ else
+ {
+ lpFullEnviron = (LPWSTR)lpEnviron;
+ }
+
+ /* Impersonate the new user */
+ ImpersonateLoggedOnUser(Session->UserToken);
+
+ /* Open the new users HKCU key */
+ lError = RegOpenCurrentUser(KEY_CREATE_SUB_KEY,
+ &hKeyCurrentUser);
+ if (lError == ERROR_SUCCESS)
+ {
+ /* Create the 'Volatile Environment' key */
+ lError = RegCreateKeyExW(hKeyCurrentUser,
+ L"Volatile Environment",
+ 0,
+ NULL,
+ REG_OPTION_VOLATILE,
+ KEY_WRITE,
+ NULL,
+ &hKey,
+ &dwDisp);
+ if (lError == ERROR_SUCCESS)
+ {
+ RegCloseKey(hKey);
+ }
+ else
+ {
+ WARN("WL: RegCreateKeyExW() failed (Error: %ld)\n", lError);
+ }
+
+ RegCloseKey(hKeyCurrentUser);
+ }
+
+ /* Revert the impersonation */
+ RevertToSelf();
+
+ *lpEnvironment = lpEnviron;
+ *lpFullEnv = lpFullEnviron;
+
+ TRACE("WL: CreateUserEnvironment done\n");
+
+ return TRUE;
+}
Propchange: trunk/reactos/base/system/winlogon/environment.c
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: trunk/reactos/base/system/winlogon/environment.c
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Modified: trunk/reactos/base/system/winlogon/sas.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/system/winlogon/sas.c…
==============================================================================
--- trunk/reactos/base/system/winlogon/sas.c [iso-8859-1] (original)
+++ trunk/reactos/base/system/winlogon/sas.c [iso-8859-1] Sat May 8 18:30:56 2010
@@ -171,8 +171,6 @@
PROFILEINFOW ProfileInfo;
LPVOID lpEnvironment = NULL;
LPWSTR lpFullEnv = NULL;
- LPCWSTR wstr;
- SIZE_T EnvBlockSize = 0, ProfileSize = 0;
BOOLEAN Old;
BOOL ret = FALSE;
@@ -210,55 +208,10 @@
}
/* Create environment block for the user */
- if (!CreateEnvironmentBlock(
- &lpEnvironment,
- Session->UserToken,
- TRUE))
- {
- WARN("WL: CreateEnvironmentBlock() failed\n");
- goto cleanup;
- }
-
- if (Session->Profile->dwType == WLX_PROFILE_TYPE_V2_0 &&
Session->Profile->pszEnvironment)
- {
- /* Count required size for full environment */
- wstr = (LPCWSTR)lpEnvironment;
- while (*wstr != UNICODE_NULL)
- {
- SIZE_T size = wcslen(wstr) + 1;
- wstr += size;
- EnvBlockSize += size;
- }
- wstr = Session->Profile->pszEnvironment;
- while (*wstr != UNICODE_NULL)
- {
- SIZE_T size = wcslen(wstr) + 1;
- wstr += size;
- ProfileSize += size;
- }
-
- /* Allocate enough memory */
- lpFullEnv = HeapAlloc(GetProcessHeap, 0, (EnvBlockSize + ProfileSize + 1) *
sizeof(WCHAR));
- if (!lpFullEnv)
- {
- TRACE("HeapAlloc() failed\n");
- goto cleanup;
- }
-
- /* Fill user environment block */
- CopyMemory(
- lpFullEnv,
- lpEnvironment,
- EnvBlockSize * sizeof(WCHAR));
- CopyMemory(
- &lpFullEnv[EnvBlockSize],
- Session->Profile->pszEnvironment,
- ProfileSize * sizeof(WCHAR));
- lpFullEnv[EnvBlockSize + ProfileSize] = UNICODE_NULL;
- }
- else
- {
- lpFullEnv = (LPWSTR)lpEnvironment;
+ if (!CreateUserEnvironment(Session, &lpEnvironment, &lpFullEnv))
+ {
+ WARN("WL: SetUserEnvironment() failed\n");
+ goto cleanup;
}
DisplayStatusMessage(Session, Session->WinlogonDesktop,
IDS_APPLYINGYOURPERSONALSETTINGS);
Modified: trunk/reactos/base/system/winlogon/winlogon.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/system/winlogon/winlo…
==============================================================================
--- trunk/reactos/base/system/winlogon/winlogon.h [iso-8859-1] (original)
+++ trunk/reactos/base/system/winlogon/winlogon.h [iso-8859-1] Sat May 8 18:30:56 2010
@@ -179,6 +179,12 @@
BOOL WINAPI
UpdatePerUserSystemParameters(DWORD dwUnknown,
DWORD dwReserved);
+
+/* environment.c */
+BOOL
+CreateUserEnvironment(IN PWLSESSION Session,
+ IN LPVOID *lpEnvironment,
+ IN LPWSTR *lpFullEnv);
/* sas.c */
BOOL
Modified: trunk/reactos/base/system/winlogon/winlogon.rbuild
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/system/winlogon/winlo…
==============================================================================
--- trunk/reactos/base/system/winlogon/winlogon.rbuild [iso-8859-1] (original)
+++ trunk/reactos/base/system/winlogon/winlogon.rbuild [iso-8859-1] Sat May 8 18:30:56
2010
@@ -8,6 +8,7 @@
<library>advapi32</library>
<library>userenv</library>
<library>secur32</library>
+ <file>environment.c</file>
<file>sas.c</file>
<file>screensaver.c</file>
<file>setup.c</file>