Implement LoadUserProfileW() and UnloadUserProfile().

svn path=/trunk/; revision=8693
This commit is contained in:
Eric Kohl 2004-03-13 20:49:07 +00:00
parent 17d9fc0744
commit 3211fcf2d0
7 changed files with 188 additions and 10 deletions

View file

@ -1,4 +1,4 @@
/* $Id: internal.h,v 1.4 2004/01/16 15:31:53 ekohl Exp $
/* $Id: internal.h,v 1.5 2004/03/13 20:49:07 ekohl Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
@ -24,21 +24,25 @@ DebugPrint (char* fmt,...);
#endif /* __GNUC__ */
#define CHECKPOINT
/* directory.h */
/* directory.c */
BOOL
CopyDirectory (LPCWSTR lpDestinationPath,
LPCWSTR lpSourcePath);
/* misc.h */
/* misc.c */
LPWSTR
AppendBackslash (LPWSTR String);
BOOL
GetUserSidFromToken (HANDLE hToken,
PUNICODE_STRING SidString);
/* profile.c */
BOOL
AppendSystemPostfix (LPWSTR lpName,
DWORD dwMaxLength);
/* registry.h */
/* registry.c */
BOOL
CreateUserHive (LPCWSTR lpKeyName);

View file

@ -1,4 +1,4 @@
/* $Id: misc.c,v 1.1 2004/01/16 15:31:53 ekohl Exp $
/* $Id: misc.c,v 1.2 2004/03/13 20:49:07 ekohl Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
@ -32,4 +32,63 @@ AppendBackslash (LPWSTR String)
return &String[Length];
}
BOOL
GetUserSidFromToken (HANDLE hToken,
PUNICODE_STRING SidString)
{
PSID_AND_ATTRIBUTES SidBuffer;
ULONG Length;
NTSTATUS Status;
Length = 256;
SidBuffer = LocalAlloc (0,
Length);
if (SidBuffer == NULL)
return FALSE;
Status = NtQueryInformationToken (hToken,
TokenUser,
(PVOID)SidBuffer,
Length,
&Length);
if (Status == STATUS_BUFFER_TOO_SMALL)
{
SidBuffer = LocalReAlloc (SidBuffer,
Length,
0);
if (SidBuffer == NULL)
return FALSE;
Status = NtQueryInformationToken (hToken,
TokenUser,
(PVOID)SidBuffer,
Length,
&Length);
}
if (!NT_SUCCESS (Status))
{
LocalFree (SidBuffer);
return FALSE;
}
DPRINT ("SidLength: %lu\n", RtlLengthSid (SidBuffer[0].Sid));
Status = RtlConvertSidToUnicodeString (SidString,
SidBuffer[0].Sid,
TRUE);
LocalFree (SidBuffer);
if (!NT_SUCCESS (Status))
return FALSE;
DPRINT ("SidString.Length: %lu\n", SidString->Length);
DPRINT ("SidString.MaximumLength: %lu\n", SidString->MaximumLength);
DPRINT ("SidString: '%wZ'\n", SidString);
return TRUE;
}
/* EOF */

View file

@ -1,4 +1,4 @@
/* $Id: profile.c,v 1.5 2004/02/28 11:30:59 ekohl Exp $
/* $Id: profile.c,v 1.6 2004/03/13 20:49:07 ekohl Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
@ -515,6 +515,14 @@ BOOL WINAPI
LoadUserProfileW (HANDLE hToken,
LPPROFILEINFOW lpProfileInfo)
{
WCHAR szRawProfilesPath[MAX_PATH];
WCHAR szProfilesPath[MAX_PATH];
WCHAR szUserHivePath[MAX_PATH];
UNICODE_STRING SidString;
DWORD dwLength;
HKEY hKey;
DPRINT ("LoadUserProfileW() called\n");
/* Check profile info */
if (lpProfileInfo->dwSize != sizeof(PROFILEINFOW) ||
@ -525,7 +533,110 @@ LoadUserProfileW (HANDLE hToken,
return FALSE;
}
/* FIXME: load the profile */
if (RegOpenKeyExW (HKEY_LOCAL_MACHINE,
L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList",
0,
KEY_ALL_ACCESS,
&hKey))
{
DPRINT1("Error: %lu\n", GetLastError());
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());
RegCloseKey (hKey);
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))
{
DPRINT1("AppendSystemPostfix() failed\n", GetLastError());
return FALSE;
}
/* Create user hive name */
wcscat (szUserHivePath, L"\\ntuser.dat");
DPRINT ("szUserHivePath: %S\n", szUserHivePath);
if (!GetUserSidFromToken (hToken,
&SidString))
{
DPRINT1 ("GetUserSidFromToken() failed\n");
return FALSE;
}
DPRINT ("SidString: '%wZ'\n", &SidString);
if (RegLoadKeyW (HKEY_USERS,
SidString.Buffer,
szUserHivePath))
{
DPRINT1 ("RegLoadKeyW() failed (Error %ld)\n", GetLastError());
RtlFreeUnicodeString (&SidString);
return FALSE;
}
RtlFreeUnicodeString (&SidString);
DPRINT ("LoadUserProfileW() done\n");
return TRUE;
}
BOOL WINAPI
UnloadUserProfile (HANDLE hToken,
HANDLE hProfile)
{
UNICODE_STRING SidString;
DPRINT ("UnloadUserProfile() called\n");
if (!GetUserSidFromToken (hToken,
&SidString))
{
DPRINT1 ("GetUserSidFromToken() failed\n");
return FALSE;
}
DPRINT ("SidString: '%wZ'\n", &SidString);
if (RegUnLoadKeyW (HKEY_USERS,
SidString.Buffer))
{
DPRINT1 ("RegUnLoadKeyW() failed (Error %ld)\n", GetLastError());
RtlFreeUnicodeString (&SidString);
return FALSE;
}
RtlFreeUnicodeString (&SidString);
DPRINT ("UnloadUserProfile() done\n");
return TRUE;
}

View file

@ -1,4 +1,4 @@
/* $Id: setup.c,v 1.3 2004/01/16 15:31:53 ekohl Exp $
/* $Id: setup.c,v 1.4 2004/03/13 20:49:07 ekohl Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
@ -7,6 +7,7 @@
* PROGRAMMER: Eric Kohl
*/
#include <ntos.h>
#include <windows.h>
#include <string.h>
#include <stdarg.h>

View file

@ -1,4 +1,4 @@
/* $Id: userenv.c,v 1.1 2004/01/09 19:52:01 ekohl Exp $
/* $Id: userenv.c,v 1.2 2004/03/13 20:49:07 ekohl Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
@ -7,6 +7,7 @@
* PROGRAMMER: Eric Kohl
*/
#include <ntos.h>
#include <windows.h>
#include <userenv.h>

View file

@ -7,4 +7,5 @@ GetProfilesDirectoryW@8
GetUserProfileDirectoryW@12
CreateUserProfileW@8
LoadUserProfileW@8
UnloadUserProfile@8
;EOF

View file

@ -7,4 +7,5 @@ GetProfilesDirectoryW=GetProfilesDirectoryW@8
GetUserProfileDirectoryW=GetUserProfileDirectoryW@12
CreateUserProfileW=CreateUserProfileW@8
LoadUserProfileW=LoadUserProfileW@8
UnloadUserProfile=UnloadUserProfile@8
;EOF