From cc68c2e317f5ae106efd00e5bec9c3a6f1c4d943 Mon Sep 17 00:00:00 2001 From: Eric Kohl Date: Sun, 14 Mar 2004 18:15:59 +0000 Subject: [PATCH] Implement GetUserProfileDirectoryW(). Open user key in LoadUserProfileW() and close it in UnloadUserProfile(). svn path=/trunk/; revision=8723 --- reactos/lib/userenv/profile.c | 101 ++++++++++++++++++++++++++++++- reactos/lib/userenv/registry.c | 20 +++--- reactos/w32api/include/userenv.h | 41 ++++++++++--- 3 files changed, 140 insertions(+), 22 deletions(-) diff --git a/reactos/lib/userenv/profile.c b/reactos/lib/userenv/profile.c index 564dc9fbdd3..f05d242b4e9 100644 --- a/reactos/lib/userenv/profile.c +++ b/reactos/lib/userenv/profile.c @@ -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 * PROJECT: ReactOS system libraries @@ -506,8 +506,85 @@ GetUserProfileDirectoryW (HANDLE hToken, LPWSTR lpProfileDir, 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); +#endif } @@ -601,6 +678,17 @@ LoadUserProfileW (HANDLE hToken, 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); DPRINT ("LoadUserProfileW() done\n"); @@ -617,6 +705,15 @@ UnloadUserProfile (HANDLE hToken, DPRINT ("UnloadUserProfile() called\n"); + if (hProfile == NULL) + { + DPRINT1 ("Invalide profile handle\n"); + SetLastError (ERROR_INVALID_PARAMETER); + return FALSE; + } + + RegCloseKey (hProfile); + if (!GetUserSidFromToken (hToken, &SidString)) { diff --git a/reactos/lib/userenv/registry.c b/reactos/lib/userenv/registry.c index 65f9ec99ebe..eaae1263cd2 100644 --- a/reactos/lib/userenv/registry.c +++ b/reactos/lib/userenv/registry.c @@ -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 * PROJECT: ReactOS system libraries @@ -52,7 +52,7 @@ CopyKey (HKEY hDstKey, NULL, NULL)) { - DPRINT1("Error: %lu\n", GetLastError ()); + DPRINT1 ("RegQueryInfoKey() failed (Error %lu)\n", GetLastError ()); return FALSE; } @@ -86,7 +86,7 @@ CopyKey (HKEY hDstKey, NULL, &LastWrite)) { - DPRINT1("Subkey enumeration failed (Error %lu)\n", GetLastError()); + DPRINT ("Subkey enumeration failed (Error %lu)\n", GetLastError()); HeapFree (GetProcessHeap (), 0, lpNameBuffer); @@ -103,7 +103,7 @@ CopyKey (HKEY hDstKey, &hDstSubKey, &dwDisposition)) { - DPRINT1("Subkey creation failed (Error %lu)\n", GetLastError()); + DPRINT ("Subkey creation failed (Error %lu)\n", GetLastError()); HeapFree (GetProcessHeap (), 0, lpNameBuffer); @@ -116,7 +116,7 @@ CopyKey (HKEY hDstKey, KEY_READ, &hSrcSubKey)) { - DPRINT1("Error: %lu\n", GetLastError()); + DPRINT ("Error: %lu\n", GetLastError()); RegCloseKey (hDstSubKey); HeapFree (GetProcessHeap (), 0, @@ -127,7 +127,7 @@ CopyKey (HKEY hDstKey, if (!CopyKey (hDstSubKey, hSrcSubKey)) { - DPRINT1("Error: %lu\n", GetLastError()); + DPRINT ("Error: %lu\n", GetLastError()); RegCloseKey (hSrcSubKey); RegCloseKey (hDstSubKey); HeapFree (GetProcessHeap (), @@ -153,7 +153,7 @@ CopyKey (HKEY hDstKey, dwMaxValueNameLength * sizeof(WCHAR)); if (lpNameBuffer == NULL) { - DPRINT1("Buffer allocation failed\n"); + DPRINT ("Buffer allocation failed\n"); return FALSE; } @@ -162,7 +162,7 @@ CopyKey (HKEY hDstKey, dwMaxValueLength); if (lpDataBuffer == NULL) { - DPRINT1("Buffer allocation failed\n"); + DPRINT ("Buffer allocation failed\n"); HeapFree (GetProcessHeap (), 0, lpNameBuffer); @@ -241,7 +241,7 @@ CreateUserHive (LPCWSTR lpKeyName) KEY_READ, &hDefaultKey)) { - DPRINT1("Error: %lu\n", GetLastError()); + DPRINT1 ("Error: %lu\n", GetLastError()); return FALSE; } @@ -251,7 +251,7 @@ CreateUserHive (LPCWSTR lpKeyName) KEY_ALL_ACCESS, &hUserKey)) { - DPRINT1("Error: %lu\n", GetLastError()); + DPRINT1 ("Error: %lu\n", GetLastError()); RegCloseKey (hDefaultKey); return FALSE; } diff --git a/reactos/w32api/include/userenv.h b/reactos/w32api/include/userenv.h index fad9f813b7c..1998e4c4d37 100644 --- a/reactos/w32api/include/userenv.h +++ b/reactos/w32api/include/userenv.h @@ -1,5 +1,6 @@ #ifndef _USERENV_H #define _USERENV_H + #if __GNUC__ >=3 #pragma GCC system_header #endif @@ -7,9 +8,12 @@ #ifdef __cplusplus extern "C" { #endif + #define PI_NOUI (1) #define PI_APPLYPOLICY (2) -typedef struct _PROFILEINFOA { + +typedef struct _PROFILEINFOA +{ DWORD dwSize; DWORD dwFlags; LPSTR lpUserName; @@ -19,7 +23,9 @@ typedef struct _PROFILEINFOA { LPSTR lpPolicyPath; HANDLE hProfile; } PROFILEINFOA, *LPPROFILEINFOA; -typedef struct _PROFILEINFOW { + +typedef struct _PROFILEINFOW +{ DWORD dwSize; DWORD dwFlags; LPWSTR lpUserName; @@ -29,29 +35,44 @@ typedef struct _PROFILEINFOW { LPWSTR lpPolicyPath; HANDLE hProfile; } PROFILEINFOW, *LPPROFILEINFOW; -BOOL WINAPI LoadUserProfileA(HANDLE,LPPROFILEINFOA); -BOOL WINAPI LoadUserProfileW(HANDLE,LPPROFILEINFOW); -BOOL WINAPI UnloadUserProfile(HANDLE,HANDLE); -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 CreateUserProfileW (PSID, LPCWSTR); +BOOL WINAPI LoadUserProfileA(HANDLE, LPPROFILEINFOA); +BOOL WINAPI LoadUserProfileW(HANDLE, LPPROFILEINFOW); +BOOL WINAPI UnloadUserProfile(HANDLE, HANDLE); + +BOOL WINAPI GetAllUsersProfileDirectoryA (LPSTR, LPDWORD); +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); + #ifdef UNICODE typedef PROFILEINFOW PROFILEINFO; typedef LPPROFILEINFOW LPPROFILEINFO; #define LoadUserProfile LoadUserProfileW +#define GetAllUsersProfileDirectory GetAllUsersProfileDirectoryW +#define GetDefaultUserProfileDirectory GetDefaultUserProfileDirectoryW #define GetProfilesDirectory GetProfilesDirectoryW #define GetUserProfileDirectory GetUserProfileDirectoryW #else typedef PROFILEINFOA PROFILEINFO; typedef LPPROFILEINFOA LPPROFILEINFO; #define LoadUserProfile LoadUserProfileA +#define GetAllUsersProfileDirectory GetAllUsersProfileDirectoryA +#define GetDefaultUserProfileDirectory GetDefaultUserProfileDirectoryA #define GetProfilesDirectory GetProfilesDirectoryA #define GetUserProfileDirectory GetUserProfileDirectoryA #endif + #ifdef __cplusplus } #endif + #endif /* _USERENV_H */