Implement GetUserProfileDirectoryW().

Open user key in LoadUserProfileW() and close it in UnloadUserProfile().

svn path=/trunk/; revision=8723
This commit is contained in:
Eric Kohl 2004-03-14 18:15:59 +00:00
parent 2ce08a79bb
commit cc68c2e317
3 changed files with 140 additions and 22 deletions

View file

@ -1,4 +1,4 @@
/* $Id: profile.c,v 1.6 2004/03/13 20:49:07 ekohl Exp $ /* $Id: profile.c,v 1.7 2004/03/14 18:15:59 ekohl Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries * PROJECT: ReactOS system libraries
@ -506,8 +506,85 @@ GetUserProfileDirectoryW (HANDLE hToken,
LPWSTR lpProfileDir, LPWSTR lpProfileDir,
LPDWORD lpcchSize) LPDWORD lpcchSize)
{ {
/* FIXME */ UNICODE_STRING SidString;
WCHAR szKeyName[MAX_PATH];
WCHAR szRawImagePath[MAX_PATH];
WCHAR szImagePath[MAX_PATH];
DWORD dwLength;
HKEY hKey;
if (!GetUserSidFromToken (hToken,
&SidString))
{
DPRINT1 ("GetUserSidFromToken() failed\n");
return FALSE;
}
DPRINT ("SidString: '%wZ'\n", &SidString);
wcscpy (szKeyName,
L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList\\");
wcscat (szKeyName,
SidString.Buffer);
RtlFreeUnicodeString (&SidString);
DPRINT ("KeyName: '%S'\n", szKeyName);
if (RegOpenKeyExW (HKEY_LOCAL_MACHINE,
szKeyName,
0,
KEY_ALL_ACCESS,
&hKey))
{
DPRINT1 ("Error: %lu\n", GetLastError());
return FALSE;
}
dwLength = MAX_PATH * sizeof(WCHAR);
if (RegQueryValueExW (hKey,
L"ProfileImagePath",
NULL,
NULL,
(LPBYTE)szRawImagePath,
&dwLength))
{
DPRINT1 ("Error: %lu\n", GetLastError());
RegCloseKey (hKey);
return FALSE;
}
RegCloseKey (hKey);
DPRINT ("RawImagePath: '%S'\n", szRawImagePath);
/* Expand it */
if (!ExpandEnvironmentStringsW (szRawImagePath,
szImagePath,
MAX_PATH))
{
DPRINT1 ("Error: %lu\n", GetLastError());
return FALSE;
}
DPRINT ("ImagePath: '%S'\n", szImagePath);
dwLength = wcslen (szImagePath);
if (dwLength > *lpcchSize)
{
DPRINT1 ("Buffer too small\n");
SetLastError (ERROR_INSUFFICIENT_BUFFER);
return FALSE;
}
*lpcchSize = dwLength;
wcscpy (lpProfileDir,
szImagePath);
return TRUE;
#if 0
return GetDefaultUserProfileDirectoryW (lpProfileDir, lpcchSize); return GetDefaultUserProfileDirectoryW (lpProfileDir, lpcchSize);
#endif
} }
@ -601,6 +678,17 @@ LoadUserProfileW (HANDLE hToken,
return FALSE; return FALSE;
} }
if (RegOpenKeyExW (HKEY_USERS,
SidString.Buffer,
0,
KEY_ALL_ACCESS,
(PHKEY)&lpProfileInfo->hProfile))
{
DPRINT1 ("RegOpenKeyExW() failed (Error %ld)\n", GetLastError());
RtlFreeUnicodeString (&SidString);
return FALSE;
}
RtlFreeUnicodeString (&SidString); RtlFreeUnicodeString (&SidString);
DPRINT ("LoadUserProfileW() done\n"); DPRINT ("LoadUserProfileW() done\n");
@ -617,6 +705,15 @@ UnloadUserProfile (HANDLE hToken,
DPRINT ("UnloadUserProfile() called\n"); DPRINT ("UnloadUserProfile() called\n");
if (hProfile == NULL)
{
DPRINT1 ("Invalide profile handle\n");
SetLastError (ERROR_INVALID_PARAMETER);
return FALSE;
}
RegCloseKey (hProfile);
if (!GetUserSidFromToken (hToken, if (!GetUserSidFromToken (hToken,
&SidString)) &SidString))
{ {

View file

@ -1,4 +1,4 @@
/* $Id: registry.c,v 1.2 2004/02/28 11:30:59 ekohl Exp $ /* $Id: registry.c,v 1.3 2004/03/14 18:15:59 ekohl Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries * PROJECT: ReactOS system libraries
@ -52,7 +52,7 @@ CopyKey (HKEY hDstKey,
NULL, NULL,
NULL)) NULL))
{ {
DPRINT1("Error: %lu\n", GetLastError ()); DPRINT1 ("RegQueryInfoKey() failed (Error %lu)\n", GetLastError ());
return FALSE; return FALSE;
} }
@ -86,7 +86,7 @@ CopyKey (HKEY hDstKey,
NULL, NULL,
&LastWrite)) &LastWrite))
{ {
DPRINT1("Subkey enumeration failed (Error %lu)\n", GetLastError()); DPRINT ("Subkey enumeration failed (Error %lu)\n", GetLastError());
HeapFree (GetProcessHeap (), HeapFree (GetProcessHeap (),
0, 0,
lpNameBuffer); lpNameBuffer);
@ -103,7 +103,7 @@ CopyKey (HKEY hDstKey,
&hDstSubKey, &hDstSubKey,
&dwDisposition)) &dwDisposition))
{ {
DPRINT1("Subkey creation failed (Error %lu)\n", GetLastError()); DPRINT ("Subkey creation failed (Error %lu)\n", GetLastError());
HeapFree (GetProcessHeap (), HeapFree (GetProcessHeap (),
0, 0,
lpNameBuffer); lpNameBuffer);
@ -116,7 +116,7 @@ CopyKey (HKEY hDstKey,
KEY_READ, KEY_READ,
&hSrcSubKey)) &hSrcSubKey))
{ {
DPRINT1("Error: %lu\n", GetLastError()); DPRINT ("Error: %lu\n", GetLastError());
RegCloseKey (hDstSubKey); RegCloseKey (hDstSubKey);
HeapFree (GetProcessHeap (), HeapFree (GetProcessHeap (),
0, 0,
@ -127,7 +127,7 @@ CopyKey (HKEY hDstKey,
if (!CopyKey (hDstSubKey, if (!CopyKey (hDstSubKey,
hSrcSubKey)) hSrcSubKey))
{ {
DPRINT1("Error: %lu\n", GetLastError()); DPRINT ("Error: %lu\n", GetLastError());
RegCloseKey (hSrcSubKey); RegCloseKey (hSrcSubKey);
RegCloseKey (hDstSubKey); RegCloseKey (hDstSubKey);
HeapFree (GetProcessHeap (), HeapFree (GetProcessHeap (),
@ -153,7 +153,7 @@ CopyKey (HKEY hDstKey,
dwMaxValueNameLength * sizeof(WCHAR)); dwMaxValueNameLength * sizeof(WCHAR));
if (lpNameBuffer == NULL) if (lpNameBuffer == NULL)
{ {
DPRINT1("Buffer allocation failed\n"); DPRINT ("Buffer allocation failed\n");
return FALSE; return FALSE;
} }
@ -162,7 +162,7 @@ CopyKey (HKEY hDstKey,
dwMaxValueLength); dwMaxValueLength);
if (lpDataBuffer == NULL) if (lpDataBuffer == NULL)
{ {
DPRINT1("Buffer allocation failed\n"); DPRINT ("Buffer allocation failed\n");
HeapFree (GetProcessHeap (), HeapFree (GetProcessHeap (),
0, 0,
lpNameBuffer); lpNameBuffer);
@ -241,7 +241,7 @@ CreateUserHive (LPCWSTR lpKeyName)
KEY_READ, KEY_READ,
&hDefaultKey)) &hDefaultKey))
{ {
DPRINT1("Error: %lu\n", GetLastError()); DPRINT1 ("Error: %lu\n", GetLastError());
return FALSE; return FALSE;
} }
@ -251,7 +251,7 @@ CreateUserHive (LPCWSTR lpKeyName)
KEY_ALL_ACCESS, KEY_ALL_ACCESS,
&hUserKey)) &hUserKey))
{ {
DPRINT1("Error: %lu\n", GetLastError()); DPRINT1 ("Error: %lu\n", GetLastError());
RegCloseKey (hDefaultKey); RegCloseKey (hDefaultKey);
return FALSE; return FALSE;
} }

View file

@ -1,5 +1,6 @@
#ifndef _USERENV_H #ifndef _USERENV_H
#define _USERENV_H #define _USERENV_H
#if __GNUC__ >=3 #if __GNUC__ >=3
#pragma GCC system_header #pragma GCC system_header
#endif #endif
@ -7,9 +8,12 @@
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#define PI_NOUI (1) #define PI_NOUI (1)
#define PI_APPLYPOLICY (2) #define PI_APPLYPOLICY (2)
typedef struct _PROFILEINFOA {
typedef struct _PROFILEINFOA
{
DWORD dwSize; DWORD dwSize;
DWORD dwFlags; DWORD dwFlags;
LPSTR lpUserName; LPSTR lpUserName;
@ -19,7 +23,9 @@ typedef struct _PROFILEINFOA {
LPSTR lpPolicyPath; LPSTR lpPolicyPath;
HANDLE hProfile; HANDLE hProfile;
} PROFILEINFOA, *LPPROFILEINFOA; } PROFILEINFOA, *LPPROFILEINFOA;
typedef struct _PROFILEINFOW {
typedef struct _PROFILEINFOW
{
DWORD dwSize; DWORD dwSize;
DWORD dwFlags; DWORD dwFlags;
LPWSTR lpUserName; LPWSTR lpUserName;
@ -29,29 +35,44 @@ typedef struct _PROFILEINFOW {
LPWSTR lpPolicyPath; LPWSTR lpPolicyPath;
HANDLE hProfile; HANDLE hProfile;
} PROFILEINFOW, *LPPROFILEINFOW; } PROFILEINFOW, *LPPROFILEINFOW;
BOOL WINAPI LoadUserProfileA(HANDLE,LPPROFILEINFOA);
BOOL WINAPI LoadUserProfileW(HANDLE,LPPROFILEINFOW); BOOL WINAPI CreateUserProfileW (PSID, LPCWSTR);
BOOL WINAPI UnloadUserProfile(HANDLE,HANDLE); BOOL WINAPI LoadUserProfileA(HANDLE, LPPROFILEINFOA);
BOOL WINAPI GetProfilesDirectoryA(LPSTR,LPDWORD); BOOL WINAPI LoadUserProfileW(HANDLE, LPPROFILEINFOW);
BOOL WINAPI GetProfilesDirectoryW(LPWSTR,LPDWORD); BOOL WINAPI UnloadUserProfile(HANDLE, HANDLE);
BOOL WINAPI GetUserProfileDirectoryA(HANDLE,LPSTR,LPDWORD);
BOOL WINAPI GetUserProfileDirectoryW(HANDLE,LPWSTR,LPDWORD); BOOL WINAPI GetAllUsersProfileDirectoryA (LPSTR, LPDWORD);
BOOL WINAPI CreateEnvironmentBlock(LPVOID*,HANDLE,BOOL); BOOL WINAPI GetAllUsersProfileDirectoryW (LPWSTR, LPDWORD);
BOOL WINAPI GetDefaultUserProfileDirectoryA (LPSTR, LPDWORD);
BOOL WINAPI GetDefaultUserProfileDirectoryW (LPWSTR, LPDWORD);
BOOL WINAPI GetProfilesDirectoryA(LPSTR, LPDWORD);
BOOL WINAPI GetProfilesDirectoryW(LPWSTR, LPDWORD);
BOOL WINAPI GetUserProfileDirectoryA(HANDLE, LPSTR, LPDWORD);
BOOL WINAPI GetUserProfileDirectoryW(HANDLE, LPWSTR, LPDWORD);
BOOL WINAPI CreateEnvironmentBlock(LPVOID*, HANDLE, BOOL);
BOOL WINAPI DestroyEnvironmentBlock(LPVOID); BOOL WINAPI DestroyEnvironmentBlock(LPVOID);
#ifdef UNICODE #ifdef UNICODE
typedef PROFILEINFOW PROFILEINFO; typedef PROFILEINFOW PROFILEINFO;
typedef LPPROFILEINFOW LPPROFILEINFO; typedef LPPROFILEINFOW LPPROFILEINFO;
#define LoadUserProfile LoadUserProfileW #define LoadUserProfile LoadUserProfileW
#define GetAllUsersProfileDirectory GetAllUsersProfileDirectoryW
#define GetDefaultUserProfileDirectory GetDefaultUserProfileDirectoryW
#define GetProfilesDirectory GetProfilesDirectoryW #define GetProfilesDirectory GetProfilesDirectoryW
#define GetUserProfileDirectory GetUserProfileDirectoryW #define GetUserProfileDirectory GetUserProfileDirectoryW
#else #else
typedef PROFILEINFOA PROFILEINFO; typedef PROFILEINFOA PROFILEINFO;
typedef LPPROFILEINFOA LPPROFILEINFO; typedef LPPROFILEINFOA LPPROFILEINFO;
#define LoadUserProfile LoadUserProfileA #define LoadUserProfile LoadUserProfileA
#define GetAllUsersProfileDirectory GetAllUsersProfileDirectoryA
#define GetDefaultUserProfileDirectory GetDefaultUserProfileDirectoryA
#define GetProfilesDirectory GetProfilesDirectoryA #define GetProfilesDirectory GetProfilesDirectoryA
#define GetUserProfileDirectory GetUserProfileDirectoryA #define GetUserProfileDirectory GetUserProfileDirectoryA
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif /* _USERENV_H */ #endif /* _USERENV_H */