-/* $Id: profile.c,v 1.7 2004/03/14 18:15:59 ekohl Exp $
+/*
+ * ReactOS kernel
+ * Copyright (C) 2004 ReactOS Team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+/* $Id$
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
* PROGRAMMER: Eric Kohl
*/
-#include <ntos.h>
-#include <windows.h>
-#include <string.h>
-
-#include <userenv.h>
+#include <precomp.h>
-#include "internal.h"
+#define NDEBUG
+#include <debug.h>
/* FUNCTIONS ***************************************************************/
DWORD dwMaxLength)
{
WCHAR szSystemRoot[MAX_PATH];
- WCHAR szDrivePostfix[3];
LPWSTR lpszPostfix;
LPWSTR lpszPtr;
- DWORD dwPostfixLength;
/* Build profile name postfix */
if (!ExpandEnvironmentStringsW (L"%SystemRoot%",
lpszPtr++;
}
- dwPostfixLength = wcslen (lpszPostfix);
- if (szSystemRoot[0] != L'C')
- {
- dwPostfixLength += 2;
- szDrivePostfix[0] = L'_';
- szDrivePostfix[1] = szSystemRoot[0];
- szDrivePostfix[2] = (WCHAR)0;
- }
-
- if (wcslen (lpName) + dwPostfixLength >= dwMaxLength)
+ if (wcslen(lpName) + wcslen(lpszPostfix) >= dwMaxLength)
{
DPRINT1("Error: buffer overflow\n");
+ SetLastError(ERROR_BUFFER_OVERFLOW);
return FALSE;
}
- wcscat (lpName, lpszPostfix);
- if (szSystemRoot[0] != L'C')
+ wcscat(lpName, lpszPostfix);
+
+ return TRUE;
+}
+
+
+BOOL WINAPI
+CreateUserProfileA (PSID Sid,
+ LPCSTR lpUserName)
+{
+ UNICODE_STRING UserName;
+ BOOL bResult;
+ NTSTATUS Status;
+
+ Status = RtlCreateUnicodeStringFromAsciiz (&UserName,
+ (LPSTR)lpUserName);
+ if (!NT_SUCCESS(Status))
{
- wcscat (lpName, szDrivePostfix);
+ SetLastError (RtlNtStatusToDosError (Status));
+ return FALSE;
}
- return TRUE;
+ bResult = CreateUserProfileW (Sid,
+ UserName.Buffer);
+
+ RtlFreeUnicodeString (&UserName);
+
+ return bResult;
}
WCHAR szUserProfilePath[MAX_PATH];
WCHAR szDefaultUserPath[MAX_PATH];
WCHAR szBuffer[MAX_PATH];
- UNICODE_STRING SidString;
+ LPWSTR SidString;
DWORD dwLength;
DWORD dwDisposition;
HKEY hKey;
- NTSTATUS Status;
+ LONG Error;
- DPRINT ("CreateUserProfileW() called\n");
+ DPRINT("CreateUserProfileW() called\n");
- if (RegOpenKeyExW (HKEY_LOCAL_MACHINE,
- L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList",
- 0,
- KEY_ALL_ACCESS,
- &hKey))
+ Error = RegOpenKeyExW (HKEY_LOCAL_MACHINE,
+ L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList",
+ 0,
+ KEY_ALL_ACCESS,
+ &hKey);
+ if (Error != ERROR_SUCCESS)
{
- DPRINT1("Error: %lu\n", GetLastError());
+ DPRINT1("Error: %lu\n", Error);
+ SetLastError((DWORD)Error);
return FALSE;
}
/* Get profiles path */
dwLength = MAX_PATH * sizeof(WCHAR);
- if (RegQueryValueExW (hKey,
- L"ProfilesDirectory",
- NULL,
- NULL,
- (LPBYTE)szRawProfilesPath,
- &dwLength))
- {
- DPRINT1("Error: %lu\n", GetLastError());
+ Error = RegQueryValueExW (hKey,
+ L"ProfilesDirectory",
+ NULL,
+ NULL,
+ (LPBYTE)szRawProfilesPath,
+ &dwLength);
+ if (Error != ERROR_SUCCESS)
+ {
+ DPRINT1("Error: %lu\n", Error);
RegCloseKey (hKey);
+ SetLastError((DWORD)Error);
return FALSE;
}
/* Get default user path */
dwLength = MAX_PATH * sizeof(WCHAR);
- if (RegQueryValueExW (hKey,
- L"DefaultUserProfile",
- NULL,
- NULL,
- (LPBYTE)szBuffer,
- &dwLength))
- {
- DPRINT1("Error: %lu\n", GetLastError());
+ Error = RegQueryValueExW (hKey,
+ L"DefaultUserProfile",
+ NULL,
+ NULL,
+ (LPBYTE)szBuffer,
+ &dwLength);
+ if (Error != ERROR_SUCCESS)
+ {
+ DPRINT1("Error: %lu\n", Error);
RegCloseKey (hKey);
+ SetLastError((DWORD)Error);
return FALSE;
}
if (!AppendSystemPostfix (szUserProfilePath, MAX_PATH))
{
DPRINT1("AppendSystemPostfix() failed\n", GetLastError());
- RtlFreeUnicodeString (&SidString);
+ LocalFree ((HLOCAL)SidString);
RegCloseKey (hKey);
return FALSE;
}
}
/* Add profile to profile list */
- Status = RtlConvertSidToUnicodeString (&SidString, Sid, TRUE);
- if (!NT_SUCCESS(Status))
+ if (!ConvertSidToStringSidW (Sid,
+ &SidString))
{
- DPRINT1("Status: %lx\n", Status);
+ DPRINT1("Error: %lu\n", GetLastError());
return FALSE;
}
wcscpy (szBuffer,
L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList\\");
- wcscat (szBuffer, SidString.Buffer);
+ wcscat (szBuffer, SidString);
/* Create user profile key */
- if (RegCreateKeyExW (HKEY_LOCAL_MACHINE,
- szBuffer,
- 0,
- NULL,
- REG_OPTION_NON_VOLATILE,
- KEY_ALL_ACCESS,
- NULL,
- &hKey,
- &dwDisposition))
+ Error = RegCreateKeyExW (HKEY_LOCAL_MACHINE,
+ szBuffer,
+ 0,
+ NULL,
+ REG_OPTION_NON_VOLATILE,
+ KEY_ALL_ACCESS,
+ NULL,
+ &hKey,
+ &dwDisposition);
+ if (Error != ERROR_SUCCESS)
{
- DPRINT1("Error: %lu\n", GetLastError());
- RtlFreeUnicodeString (&SidString);
+ DPRINT1("Error: %lu\n", Error);
+ LocalFree ((HLOCAL)SidString);
+ SetLastError((DWORD)Error);
return FALSE;
}
if (!AppendSystemPostfix (szBuffer, MAX_PATH))
{
DPRINT1("AppendSystemPostfix() failed\n", GetLastError());
- RtlFreeUnicodeString (&SidString);
+ LocalFree ((HLOCAL)SidString);
RegCloseKey (hKey);
return FALSE;
}
/* Set 'ProfileImagePath' value (non-expanded) */
- if (RegSetValueExW (hKey,
- L"ProfileImagePath",
- 0,
- REG_EXPAND_SZ,
- (LPBYTE)szBuffer,
- (wcslen (szBuffer) + 1) * sizeof(WCHAR)))
- {
- DPRINT1("Error: %lu\n", GetLastError());
- RtlFreeUnicodeString (&SidString);
+ Error = RegSetValueExW (hKey,
+ L"ProfileImagePath",
+ 0,
+ REG_EXPAND_SZ,
+ (LPBYTE)szBuffer,
+ (wcslen (szBuffer) + 1) * sizeof(WCHAR));
+ if (Error != ERROR_SUCCESS)
+ {
+ DPRINT1("Error: %lu\n", Error);
+ LocalFree ((HLOCAL)SidString);
RegCloseKey (hKey);
+ SetLastError((DWORD)Error);
return FALSE;
}
/* Set 'Sid' value */
- if (RegSetValueExW (hKey,
- L"Sid",
- 0,
- REG_BINARY,
- Sid,
- RtlLengthSid (Sid)))
- {
- DPRINT1("Error: %lu\n", GetLastError());
- RtlFreeUnicodeString (&SidString);
+ Error = RegSetValueExW (hKey,
+ L"Sid",
+ 0,
+ REG_BINARY,
+ Sid,
+ GetLengthSid (Sid));
+ if (Error != ERROR_SUCCESS)
+ {
+ DPRINT1("Error: %lu\n", Error);
+ LocalFree ((HLOCAL)SidString);
RegCloseKey (hKey);
+ SetLastError((DWORD)Error);
return FALSE;
}
RegCloseKey (hKey);
/* Create user hive name */
- wcscat (szUserProfilePath, L"\\ntuser.dat");
+ wcscpy (szBuffer, szUserProfilePath);
+ wcscat (szBuffer, L"\\ntuser.dat");
/* Create new user hive */
- if (RegLoadKeyW (HKEY_USERS,
- SidString.Buffer,
- szUserProfilePath))
+ Error = RegLoadKeyW (HKEY_USERS,
+ SidString,
+ szBuffer);
+ if (Error != ERROR_SUCCESS)
{
- DPRINT1("Error: %lu\n", GetLastError());
- RtlFreeUnicodeString (&SidString);
+ DPRINT1("Error: %lu\n", Error);
+ LocalFree ((HLOCAL)SidString);
+ SetLastError((DWORD)Error);
return FALSE;
}
/* Initialize user hive */
- if (!CreateUserHive (SidString.Buffer))
+ if (!CreateUserHive (SidString, szUserProfilePath))
{
DPRINT1("Error: %lu\n", GetLastError());
- RtlFreeUnicodeString (&SidString);
+ LocalFree ((HLOCAL)SidString);
return FALSE;
}
RegUnLoadKeyW (HKEY_USERS,
- SidString.Buffer);
+ SidString);
- RtlFreeUnicodeString (&SidString);
+ LocalFree ((HLOCAL)SidString);
- DPRINT ("CreateUserProfileW() done\n");
+ DPRINT("CreateUserProfileW() done\n");
return TRUE;
}
+BOOL WINAPI
+GetAllUsersProfileDirectoryA (LPSTR lpProfileDir,
+ LPDWORD lpcchSize)
+{
+ LPWSTR lpBuffer;
+ BOOL bResult;
+
+ lpBuffer = GlobalAlloc (GMEM_FIXED,
+ *lpcchSize * sizeof(WCHAR));
+ if (lpBuffer == NULL)
+ return FALSE;
+
+ bResult = GetAllUsersProfileDirectoryW (lpBuffer,
+ lpcchSize);
+ if (bResult)
+ {
+ WideCharToMultiByte (CP_ACP,
+ 0,
+ lpBuffer,
+ -1,
+ lpProfileDir,
+ *lpcchSize,
+ NULL,
+ NULL);
+ }
+
+ GlobalFree (lpBuffer);
+
+ return bResult;
+}
+
+
BOOL WINAPI
GetAllUsersProfileDirectoryW (LPWSTR lpProfileDir,
LPDWORD lpcchSize)
WCHAR szBuffer[MAX_PATH];
DWORD dwLength;
HKEY hKey;
+ LONG Error;
- if (RegOpenKeyExW (HKEY_LOCAL_MACHINE,
- L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList",
- 0,
- KEY_READ,
- &hKey))
+ Error = RegOpenKeyExW (HKEY_LOCAL_MACHINE,
+ L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList",
+ 0,
+ KEY_READ,
+ &hKey);
+ if (Error != ERROR_SUCCESS)
{
- DPRINT1("Error: %lu\n", GetLastError());
+ DPRINT1("Error: %lu\n", Error);
+ SetLastError((DWORD)Error);
return FALSE;
}
/* Get profiles path */
- dwLength = MAX_PATH * sizeof(WCHAR);
- if (RegQueryValueExW (hKey,
- L"ProfilesDirectory",
- NULL,
- NULL,
- (LPBYTE)szBuffer,
- &dwLength))
- {
- DPRINT1("Error: %lu\n", GetLastError());
+ dwLength = sizeof(szBuffer);
+ Error = RegQueryValueExW (hKey,
+ L"ProfilesDirectory",
+ NULL,
+ NULL,
+ (LPBYTE)szBuffer,
+ &dwLength);
+ if (Error != ERROR_SUCCESS)
+ {
+ DPRINT1("Error: %lu\n", Error);
RegCloseKey (hKey);
+ SetLastError((DWORD)Error);
return FALSE;
}
}
/* Get 'AllUsersProfile' name */
- dwLength = MAX_PATH * sizeof(WCHAR);
- if (RegQueryValueExW (hKey,
- L"AllUsersProfile",
- NULL,
- NULL,
- (LPBYTE)szBuffer,
- &dwLength))
- {
- DPRINT1("Error: %lu\n", GetLastError());
+ dwLength = sizeof(szBuffer);
+ Error = RegQueryValueExW (hKey,
+ L"AllUsersProfile",
+ NULL,
+ NULL,
+ (LPBYTE)szBuffer,
+ &dwLength);
+ if (Error != ERROR_SUCCESS)
+ {
+ DPRINT1("Error: %lu\n", Error);
RegCloseKey (hKey);
+ SetLastError((DWORD)Error);
return FALSE;
}
wcscat (szProfilePath, L"\\");
wcscat (szProfilePath, szBuffer);
- dwLength = wcslen (szProfilePath);
+ dwLength = wcslen (szProfilePath) + 1;
if (lpProfileDir != NULL)
{
if (*lpcchSize < dwLength)
}
+BOOL WINAPI
+GetDefaultUserProfileDirectoryA (LPSTR lpProfileDir,
+ LPDWORD lpcchSize)
+{
+ LPWSTR lpBuffer;
+ BOOL bResult;
+
+ lpBuffer = GlobalAlloc (GMEM_FIXED,
+ *lpcchSize * sizeof(WCHAR));
+ if (lpBuffer == NULL)
+ return FALSE;
+
+ bResult = GetDefaultUserProfileDirectoryW (lpBuffer,
+ lpcchSize);
+ if (bResult)
+ {
+ WideCharToMultiByte (CP_ACP,
+ 0,
+ lpBuffer,
+ -1,
+ lpProfileDir,
+ *lpcchSize,
+ NULL,
+ NULL);
+ }
+
+ GlobalFree (lpBuffer);
+
+ return bResult;
+}
+
+
BOOL WINAPI
GetDefaultUserProfileDirectoryW (LPWSTR lpProfileDir,
LPDWORD lpcchSize)
WCHAR szBuffer[MAX_PATH];
DWORD dwLength;
HKEY hKey;
+ LONG Error;
- if (RegOpenKeyExW (HKEY_LOCAL_MACHINE,
- L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList",
- 0,
- KEY_READ,
- &hKey))
+ Error = RegOpenKeyExW (HKEY_LOCAL_MACHINE,
+ L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList",
+ 0,
+ KEY_READ,
+ &hKey);
+ if (Error != ERROR_SUCCESS)
{
- DPRINT1("Error: %lu\n", GetLastError());
+ DPRINT1("Error: %lu\n", Error);
+ SetLastError((DWORD)Error);
return FALSE;
}
/* Get profiles path */
- dwLength = MAX_PATH * sizeof(WCHAR);
- if (RegQueryValueExW (hKey,
- L"ProfilesDirectory",
- NULL,
- NULL,
- (LPBYTE)szBuffer,
- &dwLength))
- {
- DPRINT1("Error: %lu\n", GetLastError());
+ dwLength = sizeof(szBuffer);
+ Error = RegQueryValueExW (hKey,
+ L"ProfilesDirectory",
+ NULL,
+ NULL,
+ (LPBYTE)szBuffer,
+ &dwLength);
+ if (Error != ERROR_SUCCESS)
+ {
+ DPRINT1("Error: %lu\n", Error);
RegCloseKey (hKey);
+ SetLastError((DWORD)Error);
return FALSE;
}
}
/* Get 'DefaultUserProfile' name */
- dwLength = MAX_PATH * sizeof(WCHAR);
- if (RegQueryValueExW (hKey,
- L"DefaultUserProfile",
- NULL,
- NULL,
- (LPBYTE)szBuffer,
- &dwLength))
- {
- DPRINT1("Error: %lu\n", GetLastError());
+ dwLength = sizeof(szBuffer);
+ Error = RegQueryValueExW (hKey,
+ L"DefaultUserProfile",
+ NULL,
+ NULL,
+ (LPBYTE)szBuffer,
+ &dwLength);
+ if (Error != ERROR_SUCCESS)
+ {
+ DPRINT1("Error: %lu\n", Error);
RegCloseKey (hKey);
+ SetLastError((DWORD)Error);
return FALSE;
}
wcscat (szProfilePath, L"\\");
wcscat (szProfilePath, szBuffer);
- dwLength = wcslen (szProfilePath);
+ dwLength = wcslen (szProfilePath) + 1;
if (lpProfileDir != NULL)
{
if (*lpcchSize < dwLength)
}
+BOOL WINAPI
+GetProfilesDirectoryA (LPSTR lpProfileDir,
+ LPDWORD lpcchSize)
+{
+ LPWSTR lpBuffer;
+ BOOL bResult;
+
+ lpBuffer = GlobalAlloc (GMEM_FIXED,
+ *lpcchSize * sizeof(WCHAR));
+ if (lpBuffer == NULL)
+ return FALSE;
+
+ bResult = GetProfilesDirectoryW (lpBuffer,
+ lpcchSize);
+ if (bResult)
+ {
+ WideCharToMultiByte (CP_ACP,
+ 0,
+ lpBuffer,
+ -1,
+ lpProfileDir,
+ *lpcchSize,
+ NULL,
+ NULL);
+ }
+
+ GlobalFree (lpBuffer);
+
+ return bResult;
+}
+
+
BOOL WINAPI
GetProfilesDirectoryW (LPWSTR lpProfilesDir,
LPDWORD lpcchSize)
WCHAR szBuffer[MAX_PATH];
DWORD dwLength;
HKEY hKey;
+ LONG Error;
- if (RegOpenKeyExW (HKEY_LOCAL_MACHINE,
- L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList",
- 0,
- KEY_READ,
- &hKey))
+ Error = RegOpenKeyExW (HKEY_LOCAL_MACHINE,
+ L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList",
+ 0,
+ KEY_READ,
+ &hKey);
+ if (Error != ERROR_SUCCESS)
{
- DPRINT1("Error: %lu\n", GetLastError());
+ DPRINT1("Error: %lu\n", Error);
+ SetLastError((DWORD)Error);
return FALSE;
}
/* Get profiles path */
- dwLength = MAX_PATH * sizeof(WCHAR);
- if (RegQueryValueExW (hKey,
- L"ProfilesDirectory",
- NULL,
- NULL,
- (LPBYTE)szBuffer,
- &dwLength))
- {
- DPRINT1("Error: %lu\n", GetLastError());
+ dwLength = sizeof(szBuffer);
+ Error = RegQueryValueExW (hKey,
+ L"ProfilesDirectory",
+ NULL,
+ NULL,
+ (LPBYTE)szBuffer,
+ &dwLength);
+ if (Error != ERROR_SUCCESS)
+ {
+ DPRINT1("Error: %lu\n", Error);
RegCloseKey (hKey);
+ SetLastError((DWORD)Error);
return FALSE;
}
return FALSE;
}
- dwLength = wcslen (szProfilesPath);
+ dwLength = wcslen (szProfilesPath) + 1;
if (lpProfilesDir != NULL)
{
if (*lpcchSize < dwLength)
}
+BOOL WINAPI
+GetUserProfileDirectoryA (HANDLE hToken,
+ LPSTR lpProfileDir,
+ LPDWORD lpcchSize)
+{
+ LPWSTR lpBuffer;
+ BOOL bResult;
+
+ lpBuffer = GlobalAlloc (GMEM_FIXED,
+ *lpcchSize * sizeof(WCHAR));
+ if (lpBuffer == NULL)
+ return FALSE;
+
+ bResult = GetUserProfileDirectoryW (hToken,
+ lpBuffer,
+ lpcchSize);
+ if (bResult)
+ {
+ WideCharToMultiByte (CP_ACP,
+ 0,
+ lpBuffer,
+ -1,
+ lpProfileDir,
+ *lpcchSize,
+ NULL,
+ NULL);
+ }
+
+ GlobalFree (lpBuffer);
+
+ return bResult;
+}
+
+
BOOL WINAPI
GetUserProfileDirectoryW (HANDLE hToken,
LPWSTR lpProfileDir,
WCHAR szImagePath[MAX_PATH];
DWORD dwLength;
HKEY hKey;
+ LONG Error;
if (!GetUserSidFromToken (hToken,
&SidString))
DPRINT ("KeyName: '%S'\n", szKeyName);
- if (RegOpenKeyExW (HKEY_LOCAL_MACHINE,
- szKeyName,
- 0,
- KEY_ALL_ACCESS,
- &hKey))
+ Error = RegOpenKeyExW (HKEY_LOCAL_MACHINE,
+ szKeyName,
+ 0,
+ KEY_ALL_ACCESS,
+ &hKey);
+ if (Error != ERROR_SUCCESS)
{
- DPRINT1 ("Error: %lu\n", GetLastError());
+ DPRINT1 ("Error: %lu\n", Error);
+ SetLastError((DWORD)Error);
return FALSE;
}
- dwLength = MAX_PATH * sizeof(WCHAR);
- if (RegQueryValueExW (hKey,
- L"ProfileImagePath",
- NULL,
- NULL,
- (LPBYTE)szRawImagePath,
- &dwLength))
+ dwLength = sizeof(szRawImagePath);
+ Error = RegQueryValueExW (hKey,
+ L"ProfileImagePath",
+ NULL,
+ NULL,
+ (LPBYTE)szRawImagePath,
+ &dwLength);
+ if (Error != ERROR_SUCCESS)
{
- DPRINT1 ("Error: %lu\n", GetLastError());
+ DPRINT1 ("Error: %lu\n", Error);
RegCloseKey (hKey);
+ SetLastError((DWORD)Error);
return FALSE;
}
DPRINT ("ImagePath: '%S'\n", szImagePath);
- dwLength = wcslen (szImagePath);
- if (dwLength > *lpcchSize)
+ dwLength = wcslen (szImagePath) + 1;
+ if (*lpcchSize < dwLength)
{
DPRINT1 ("Buffer too small\n");
SetLastError (ERROR_INSUFFICIENT_BUFFER);
szImagePath);
return TRUE;
-#if 0
- return GetDefaultUserProfileDirectoryW (lpProfileDir, lpcchSize);
-#endif
+}
+
+
+static BOOL
+CheckForLoadedProfile (HANDLE hToken)
+{
+ UNICODE_STRING SidString;
+ HKEY hKey;
+
+ DPRINT ("CheckForLoadedProfile() called \n");
+
+ if (!GetUserSidFromToken (hToken,
+ &SidString))
+ {
+ DPRINT1 ("GetUserSidFromToken() failed\n");
+ return FALSE;
+ }
+
+ if (RegOpenKeyExW (HKEY_USERS,
+ SidString.Buffer,
+ 0,
+ KEY_ALL_ACCESS,
+ &hKey))
+ {
+ DPRINT ("Profile not loaded\n");
+ RtlFreeUnicodeString (&SidString);
+ return FALSE;
+ }
+
+ RegCloseKey (hKey);
+
+ RtlFreeUnicodeString (&SidString);
+
+ DPRINT ("Profile already loaded\n");
+
+ return TRUE;
+}
+
+
+BOOL WINAPI
+LoadUserProfileA (HANDLE hToken,
+ LPPROFILEINFOA lpProfileInfo)
+{
+ DPRINT ("LoadUserProfileA() not implemented\n");
+ return FALSE;
}
LoadUserProfileW (HANDLE hToken,
LPPROFILEINFOW lpProfileInfo)
{
- WCHAR szRawProfilesPath[MAX_PATH];
- WCHAR szProfilesPath[MAX_PATH];
WCHAR szUserHivePath[MAX_PATH];
UNICODE_STRING SidString;
- DWORD dwLength;
- HKEY hKey;
+ LONG Error;
+ DWORD dwLength = sizeof(szUserHivePath) / sizeof(szUserHivePath[0]);
DPRINT ("LoadUserProfileW() called\n");
return FALSE;
}
- if (RegOpenKeyExW (HKEY_LOCAL_MACHINE,
- L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList",
- 0,
- KEY_ALL_ACCESS,
- &hKey))
+ /* Don't load a profile twice */
+ if (CheckForLoadedProfile (hToken))
{
- DPRINT1("Error: %lu\n", GetLastError());
- return FALSE;
+ DPRINT ("Profile already loaded\n");
+ lpProfileInfo->hProfile = NULL;
+ return TRUE;
}
- /* Get profiles path */
- dwLength = MAX_PATH * sizeof(WCHAR);
- if (RegQueryValueExW (hKey,
- L"ProfilesDirectory",
- NULL,
- NULL,
- (LPBYTE)szRawProfilesPath,
- &dwLength))
+ if (!GetProfilesDirectoryW (szUserHivePath,
+ &dwLength))
{
- DPRINT1("Error: %lu\n", GetLastError());
- RegCloseKey (hKey);
+ DPRINT1("GetProfilesDirectoryW() failed\n", GetLastError());
return FALSE;
}
- /* Expand it */
- if (!ExpandEnvironmentStringsW (szRawProfilesPath,
- szProfilesPath,
- MAX_PATH))
- {
- DPRINT1("Error: %lu\n", GetLastError());
- RegCloseKey (hKey);
- return FALSE;
- }
-
- RegCloseKey (hKey);
-
- wcscpy (szUserHivePath, szProfilesPath);
wcscat (szUserHivePath, L"\\");
wcscat (szUserHivePath, lpProfileInfo->lpUserName);
if (!AppendSystemPostfix (szUserHivePath, MAX_PATH))
DPRINT ("SidString: '%wZ'\n", &SidString);
- if (RegLoadKeyW (HKEY_USERS,
- SidString.Buffer,
- szUserHivePath))
+ Error = RegLoadKeyW (HKEY_USERS,
+ SidString.Buffer,
+ szUserHivePath);
+ if (Error != ERROR_SUCCESS)
{
- DPRINT1 ("RegLoadKeyW() failed (Error %ld)\n", GetLastError());
+ DPRINT1 ("RegLoadKeyW() failed (Error %ld)\n", Error);
RtlFreeUnicodeString (&SidString);
+ SetLastError((DWORD)Error);
return FALSE;
}
- if (RegOpenKeyExW (HKEY_USERS,
- SidString.Buffer,
- 0,
- KEY_ALL_ACCESS,
- (PHKEY)&lpProfileInfo->hProfile))
+ Error = RegOpenKeyExW (HKEY_USERS,
+ SidString.Buffer,
+ 0,
+ KEY_ALL_ACCESS,
+ (PHKEY)&lpProfileInfo->hProfile);
+ if (Error != ERROR_SUCCESS)
{
- DPRINT1 ("RegOpenKeyExW() failed (Error %ld)\n", GetLastError());
+ DPRINT1 ("RegOpenKeyExW() failed (Error %ld)\n", Error);
RtlFreeUnicodeString (&SidString);
+ SetLastError((DWORD)Error);
return FALSE;
}
HANDLE hProfile)
{
UNICODE_STRING SidString;
+ LONG Error;
DPRINT ("UnloadUserProfile() called\n");
DPRINT ("SidString: '%wZ'\n", &SidString);
- if (RegUnLoadKeyW (HKEY_USERS,
- SidString.Buffer))
+ Error = RegUnLoadKeyW (HKEY_USERS,
+ SidString.Buffer);
+ if (Error != ERROR_SUCCESS)
{
- DPRINT1 ("RegUnLoadKeyW() failed (Error %ld)\n", GetLastError());
+ DPRINT1 ("RegUnLoadKeyW() failed (Error %ld)\n", Error);
RtlFreeUnicodeString (&SidString);
+ SetLastError((DWORD)Error);
return FALSE;
}