[ros-diffs] [hpoussin] 28315: Cleanup WlxInitialize(), WlxStartApplication() and WlxActivateUserShell() Allocate and return a valid PWLX_PROFILE structure in DoLoginTasks Fix some warnings

hpoussin at svn.reactos.org hpoussin at svn.reactos.org
Mon Aug 13 16:20:36 CEST 2007


Author: hpoussin
Date: Mon Aug 13 18:20:36 2007
New Revision: 28315

URL: http://svn.reactos.org/svn/reactos?rev=28315&view=rev
Log:
Cleanup WlxInitialize(), WlxStartApplication() and WlxActivateUserShell()
Allocate and return a valid PWLX_PROFILE structure in DoLoginTasks
Fix some warnings

Modified:
    trunk/reactos/dll/win32/msgina/gui.c
    trunk/reactos/dll/win32/msgina/lang/fr-FR.rc
    trunk/reactos/dll/win32/msgina/msgina.c
    trunk/reactos/dll/win32/msgina/msgina.h
    trunk/reactos/dll/win32/msgina/msgina.rbuild

Modified: trunk/reactos/dll/win32/msgina/gui.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/msgina/gui.c?rev=28315&r1=28314&r2=28315&view=diff
==============================================================================
--- trunk/reactos/dll/win32/msgina/gui.c (original)
+++ trunk/reactos/dll/win32/msgina/gui.c Mon Aug 13 18:20:36 2007
@@ -77,7 +77,7 @@
 		return FALSE;
 	}
 	DialogBoxParam(
-		hDllInstance, 
+		hDllInstance,
 		MAKEINTRESOURCE(IDD_STATUSWINDOW_DLG),
 		GetDesktopWindow(),
 		StatusMessageWindowProc,

Modified: trunk/reactos/dll/win32/msgina/lang/fr-FR.rc
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/msgina/lang/fr-FR.rc?rev=28315&r1=28314&r2=28315&view=diff
==============================================================================
--- trunk/reactos/dll/win32/msgina/lang/fr-FR.rc (original)
+++ trunk/reactos/dll/win32/msgina/lang/fr-FR.rc Mon Aug 13 18:20:36 2007
@@ -18,7 +18,7 @@
 
 IDD_LOGGEDOUT_DLG DIALOGEX 0,0,275,147
 STYLE NOT WS_VISIBLE | DS_3DLOOK | DS_CENTER | DS_MODALFRAME | DS_SETFONT | DS_FIXEDSYS | WS_BORDER | WS_CAPTION | WS_DLGFRAME | WS_POPUP
-CAPTION "Connection"
+CAPTION "Connexion"
 FONT 8,"MS Shell Dlg 2",400,0,1
 BEGIN
     PUSHBUTTON      "OK",IDOK,51,122,50,14,BS_DEFPUSHBUTTON

Modified: trunk/reactos/dll/win32/msgina/msgina.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/msgina/msgina.c?rev=28315&r1=28314&r2=28315&view=diff
==============================================================================
--- trunk/reactos/dll/win32/msgina/msgina.c (original)
+++ trunk/reactos/dll/win32/msgina/msgina.c Mon Aug 13 18:20:36 2007
@@ -66,6 +66,10 @@
 	DWORD cbData = 0;
 	LPWSTR Value;
 
+	if (!pValue)
+		return ERROR_INVALID_PARAMETER;
+
+	*pValue = NULL;
 	rc = RegQueryValueExW(hKey, pszKey, NULL, &dwType, NULL, &cbData);
 	if (rc != ERROR_SUCCESS)
 		return rc;
@@ -145,39 +149,44 @@
 	PVOID  pWinlogonFunctions,
 	PVOID  *pWlxContext)
 {
-  PGINA_CONTEXT pgContext;
-  
-  pgContext = (PGINA_CONTEXT)LocalAlloc(LMEM_FIXED | LMEM_ZEROINIT, sizeof(GINA_CONTEXT));
-  if(!pgContext)
-    return FALSE;
-  
-  /* return the context to winlogon */
-  *pWlxContext = (PVOID)pgContext;
-  
-  pgContext->hDllInstance = hDllInstance;
-  
-  /* save pointer to dispatch table */
-  pgContext->pWlxFuncs = (PWLX_DISPATCH_VERSION_1_3)pWinlogonFunctions;
-  
-  /* save the winlogon handle used to call the dispatch functions */
-  pgContext->hWlx = hWlx;
-  
-  /* save window station */
-  pgContext->station = lpWinsta;
-  
-  /* clear status window handle */
-  pgContext->hStatusWindow = 0;
-  
-  /* notify winlogon that we will use the default SAS */
-  pgContext->pWlxFuncs->WlxUseCtrlAltDel(hWlx);
-  
-  /* Locates the authentification package */
-  //LsaRegisterLogonProcess(...);
-
-  pgContext->AutoLogonState = AUTOLOGON_CHECK_REGISTRY;
-
-  ChooseGinaUI();
-  return pGinaUI->Initialize(pgContext);
+	PGINA_CONTEXT pgContext;
+
+	UNREFERENCED_PARAMETER(pvReserved);
+
+	pgContext = (PGINA_CONTEXT)LocalAlloc(LMEM_FIXED | LMEM_ZEROINIT, sizeof(GINA_CONTEXT));
+	if(!pgContext)
+	{
+		WARN("LocalAlloc() failed\n");
+		return FALSE;
+	}
+
+	/* Return the context to winlogon */
+	*pWlxContext = (PVOID)pgContext;
+	pgContext->hDllInstance = hDllInstance;
+
+	/* Save pointer to dispatch table */
+	pgContext->pWlxFuncs = (PWLX_DISPATCH_VERSION_1_3)pWinlogonFunctions;
+
+	/* Save the winlogon handle used to call the dispatch functions */
+	pgContext->hWlx = hWlx;
+
+	/* Save window station */
+	pgContext->station = lpWinsta;
+
+	/* Clear status window handle */
+	pgContext->hStatusWindow = 0;
+
+	/* Notify winlogon that we will use the default SAS */
+	pgContext->pWlxFuncs->WlxUseCtrlAltDel(hWlx);
+
+	/* Locates the authentification package */
+	//LsaRegisterLogonProcess(...);
+
+	/* Check autologon settings the first time */
+	pgContext->AutoLogonState = AUTOLOGON_CHECK_REGISTRY;
+
+	ChooseGinaUI();
+	return pGinaUI->Initialize(pgContext);
 }
 
 /*
@@ -190,39 +199,43 @@
 	PVOID pEnvironment,
 	PWSTR pszCmdLine)
 {
-  PGINA_CONTEXT pgContext = (PGINA_CONTEXT)pWlxContext;
-  STARTUPINFOW StartupInfo;
-  PROCESS_INFORMATION ProcessInformation;
-  WCHAR CurrentDirectory[MAX_PATH];
-  BOOL Ret;
-  
-  StartupInfo.cb = sizeof(STARTUPINFOW);
-  StartupInfo.lpReserved = NULL;
-  StartupInfo.lpTitle = pszCmdLine;
-  StartupInfo.dwX = StartupInfo.dwY = StartupInfo.dwXSize = StartupInfo.dwYSize = 0L;
-  StartupInfo.dwFlags = 0;
-  StartupInfo.wShowWindow = SW_SHOW;  
-  StartupInfo.lpReserved2 = NULL;
-  StartupInfo.cbReserved2 = 0;
-  StartupInfo.lpDesktop = pszDesktopName;
-  
-  GetWindowsDirectoryW (CurrentDirectory, MAX_PATH);
-  Ret = CreateProcessAsUserW(pgContext->UserToken,
-                            pszCmdLine,
-                            NULL,
-                            NULL,
-                            NULL,
-                            FALSE,
-                            CREATE_UNICODE_ENVIRONMENT,
-                            pEnvironment,
-                            CurrentDirectory,
-                            &StartupInfo,
-                            &ProcessInformation);
-  
-  //VirtualFree(pEnvironment, 0, MEM_RELEASE);
-  return Ret;
-}
-
+	PGINA_CONTEXT pgContext = (PGINA_CONTEXT)pWlxContext;
+	STARTUPINFOW StartupInfo;
+	PROCESS_INFORMATION ProcessInformation;
+	WCHAR CurrentDirectory[MAX_PATH];
+	UINT len;
+	BOOL ret;
+
+	ZeroMemory(&StartupInfo, sizeof(STARTUPINFOW));
+	StartupInfo.cb = sizeof(STARTUPINFOW);
+	StartupInfo.lpTitle = pszCmdLine;
+	StartupInfo.dwX = StartupInfo.dwY = StartupInfo.dwXSize = StartupInfo.dwYSize = 0L;
+	StartupInfo.dwFlags = 0;
+	StartupInfo.wShowWindow = SW_SHOW;
+	StartupInfo.lpDesktop = pszDesktopName;
+
+	len = GetWindowsDirectoryW(CurrentDirectory, MAX_PATH);
+	if (len > MAX_PATH)
+	{
+		WARN("GetWindowsDirectoryW() failed\n");
+		return FALSE;
+	}
+	ret = CreateProcessAsUserW(
+		pgContext->UserToken,
+		pszCmdLine,
+		NULL,
+		NULL,
+		NULL,
+		FALSE,
+		CREATE_UNICODE_ENVIRONMENT,
+		pEnvironment,
+		CurrentDirectory,
+		&StartupInfo,
+		&ProcessInformation);
+	if (!ret)
+		WARN("CreateProcessAsUserW() failed with error %lu\n", GetLastError());
+	return ret;
+}
 
 /*
  * @implemented
@@ -234,37 +247,57 @@
 	PWSTR pszMprLogonScript,
 	PVOID pEnvironment)
 {
-  HKEY hKey;
-  DWORD BufSize, ValueType;
-  WCHAR pszUserInitApp[MAX_PATH];
-  WCHAR pszExpUserInitApp[MAX_PATH];
-  TRACE("WlxActivateUserShell()\n");
-  /* get the path of userinit */
-  if(RegOpenKeyExW(HKEY_LOCAL_MACHINE, 
-                  L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon", 
-                  0, KEY_QUERY_VALUE, &hKey) != ERROR_SUCCESS)
-  {ERR("GINA: Failed: 1\n");
-    VirtualFree(pEnvironment, 0, MEM_RELEASE);
-    return FALSE;
-  }
-  BufSize = MAX_PATH * sizeof(WCHAR);
-  if((RegQueryValueExW(hKey, L"Userinit", NULL, &ValueType, (LPBYTE)pszUserInitApp, 
-                     &BufSize) != ERROR_SUCCESS) || 
-                     !((ValueType == REG_SZ) || (ValueType == REG_EXPAND_SZ)))
-  {ERR("GINA: Failed: 2\n");
-    RegCloseKey(hKey);
-    VirtualFree(pEnvironment, 0, MEM_RELEASE);
-    return FALSE;
-  }
-  RegCloseKey(hKey);
-  ExpandEnvironmentStringsW(pszUserInitApp, pszExpUserInitApp, MAX_PATH);
-  
-  /* Start userinit */
-  /* FIXME - allow to start more applications that are comma-separated */
-  /* FIXME: Call VirtualFree(pEnvironment, 0, MEM_RELEASE); ? */
-  return WlxStartApplication(pWlxContext, pszDesktopName, pEnvironment, pszExpUserInitApp);
-}
-
+	HKEY hKey;
+	DWORD BufSize, ValueType;
+	WCHAR pszUserInitApp[MAX_PATH + 1];
+	WCHAR pszExpUserInitApp[MAX_PATH];
+	DWORD len;
+	LONG rc;
+
+	TRACE("WlxActivateUserShell()\n");
+
+	UNREFERENCED_PARAMETER(pszMprLogonScript);
+
+	/* Get the path of userinit */
+	rc = RegOpenKeyExW(
+		HKEY_LOCAL_MACHINE, 
+		L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon",
+		0,
+		KEY_QUERY_VALUE,
+		&hKey);
+	if (rc != ERROR_SUCCESS)
+	{
+		WARN("RegOpenKeyExW() failed with error %lu\n", rc);
+		return FALSE;
+	}
+
+	/* Query userinit application */
+	BufSize = sizeof(pszUserInitApp) - sizeof(UNICODE_NULL);
+	rc = RegQueryValueExW(
+		hKey,
+		L"Userinit",
+		NULL,
+		&ValueType,
+		(LPBYTE)pszUserInitApp,
+		&BufSize);
+	RegCloseKey(hKey);
+	if (rc != ERROR_SUCCESS || (ValueType != REG_SZ && ValueType != REG_EXPAND_SZ))
+	{
+		WARN("RegQueryValueExW() failed with error %lu\n", rc);
+		return FALSE;
+	}
+	pszUserInitApp[MAX_PATH] = UNICODE_NULL;
+
+	len = ExpandEnvironmentStringsW(pszUserInitApp, pszExpUserInitApp, MAX_PATH);
+	if (len > MAX_PATH)
+	{
+		WARN("ExpandEnvironmentStringsW() failed. Required size %lu\n", len);
+		return FALSE;
+	}
+
+	/* Start userinit app */
+	return WlxStartApplication(pWlxContext, pszDesktopName, pEnvironment, pszExpUserInitApp);
+}
 
 /*
  * @implemented
@@ -279,6 +312,8 @@
 	INT SasAction = WLX_SAS_ACTION_NONE;
 
 	TRACE("WlxLoggedOnSAS(0x%lx)\n", dwSasType);
+
+	UNREFERENCED_PARAMETER(pReserved);
 
 	switch (dwSasType)
 	{
@@ -361,8 +396,11 @@
 	IN PWSTR Domain,
 	IN PWSTR Password)
 {
+	LPWSTR ProfilePath = NULL;
 	TOKEN_STATISTICS Stats;
-	DWORD cbStats;
+	PWLX_PROFILE_V1_0 pProfile = NULL;
+	DWORD cbStats, cbSize;
+	BOOL bResult;
 
 	if (!LogonUserW(UserName, Domain, Password,
 		LOGON32_LOGON_INTERACTIVE, /* FIXME - use LOGON32_LOGON_UNLOCK instead! */
@@ -370,17 +408,37 @@
 		&pgContext->UserToken))
 	{
 		WARN("LogonUserW() failed\n");
-		return FALSE;
-	}
-
-	if (!pgContext->UserToken)
-	{
-		WARN("UserToken == NULL!\n");
-		return FALSE;
-	}
-
-	*pgContext->pdwOptions = 0;
-	*pgContext->pProfile = NULL;
+		goto cleanup;
+	}
+
+	/* Get profile path */
+	cbSize = 0;
+	bResult = GetProfilesDirectoryW(NULL, &cbSize);
+	if (!bResult && GetLastError() == ERROR_INSUFFICIENT_BUFFER)
+	{
+		ProfilePath = HeapAlloc(GetProcessHeap(), 0, cbSize * sizeof(WCHAR));
+		if (!ProfilePath)
+		{
+			WARN("HeapAlloc() failed\n");
+			goto cleanup;
+		}
+		bResult = GetProfilesDirectoryW(ProfilePath, &cbSize);
+	}
+	if (!bResult)
+	{
+		WARN("GetUserProfileDirectoryW() failed\n");
+		goto cleanup;
+	}
+
+	/* Allocate memory for profile */
+	pProfile = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WLX_PROFILE_V1_0));
+	if (!pProfile)
+	{
+		WARN("HeapAlloc() failed\n");
+		goto cleanup;
+	}
+	pProfile->dwType = WLX_PROFILE_TYPE_V1_0;
+	pProfile->pszProfile = ProfilePath;
 
 	if (!GetTokenInformation(pgContext->UserToken,
 		TokenStatistics,
@@ -389,14 +447,21 @@
 		&cbStats))
 	{
 		WARN("Couldn't get Authentication id from user token!\n");
-		return FALSE;
+		goto cleanup;
 	}
 	*pgContext->pAuthenticationId = Stats.AuthenticationId; 
 	pgContext->pNprNotifyInfo->pszUserName = DuplicationString(UserName);
 	pgContext->pNprNotifyInfo->pszDomain = DuplicationString(Domain);
 	pgContext->pNprNotifyInfo->pszPassword = DuplicationString(Password);
 	pgContext->pNprNotifyInfo->pszOldPassword = NULL;
+	*pgContext->pdwOptions = 0;
+	*pgContext->pProfile = pProfile;
 	return TRUE;
+
+cleanup:
+	HeapFree(GetProcessHeap(), 0, pProfile);
+	HeapFree(GetProcessHeap(), 0, ProfilePath);
+	return FALSE;
 }
 
 static BOOL
@@ -543,12 +608,15 @@
 
 	TRACE("WlxLoggedOutSAS()\n");
 
+	UNREFERENCED_PARAMETER(dwSasType);
+	UNREFERENCED_PARAMETER(pLogonSid);
+
 	pgContext->pAuthenticationId = pAuthenticationId;
 	pgContext->pdwOptions = pdwOptions;
 	pgContext->pNprNotifyInfo = pNprNotifyInfo;
 	pgContext->pProfile = pProfile;
 
-	if (!GetSystemMetrics(SM_REMOTESESSION) &&
+	if (0 == GetSystemMetrics(SM_REMOTESESSION) &&
 	    DoAutoLogon(pgContext))
 	{
 		/* User is local and registry contains information
@@ -573,6 +641,8 @@
 	PGINA_CONTEXT pgContext = (PGINA_CONTEXT)pWlxContext;
 
 	TRACE("WlxWkstaLockedSAS()\n");
+
+	UNREFERENCED_PARAMETER(dwSasType);
 
 	return pGinaUI->LockedSAS(pgContext);
 }
@@ -583,6 +653,8 @@
 	IN DWORD dwReason,
 	IN LPVOID lpvReserved)
 {
+	UNREFERENCED_PARAMETER(lpvReserved);
+
 	if (dwReason == DLL_PROCESS_ATTACH)
 		hDllInstance = hinstDLL;
 

Modified: trunk/reactos/dll/win32/msgina/msgina.h
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/msgina/msgina.h?rev=28315&r1=28314&r2=28315&view=diff
==============================================================================
--- trunk/reactos/dll/win32/msgina/msgina.h (original)
+++ trunk/reactos/dll/win32/msgina/msgina.h Mon Aug 13 18:20:36 2007
@@ -2,6 +2,7 @@
 #define __MSGINA_H
 
 #include <windows.h>
+#include <userenv.h>
 #include <winwlx.h>
 #include "resource.h"
 

Modified: trunk/reactos/dll/win32/msgina/msgina.rbuild
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/msgina/msgina.rbuild?rev=28315&r1=28314&r2=28315&view=diff
==============================================================================
--- trunk/reactos/dll/win32/msgina/msgina.rbuild (original)
+++ trunk/reactos/dll/win32/msgina/msgina.rbuild Mon Aug 13 18:20:36 2007
@@ -10,6 +10,7 @@
 	<library>advapi32</library>
 	<library>user32</library>
 	<library>gdi32</library>
+	<library>userenv</library>
 	<file>gui.c</file>
 	<file>msgina.c</file>
 	<file>stubs.c</file>




More information about the Ros-diffs mailing list