From 9595c8617b8aaf044ac934065df19a3f9caa3628 Mon Sep 17 00:00:00 2001 From: Eric Kohl Date: Thu, 15 Jan 2004 14:59:06 +0000 Subject: [PATCH] Implemented most of the user profile creation. svn path=/trunk/; revision=7646 --- reactos/lib/userenv/directory.c | 28 +++++ reactos/lib/userenv/internal.h | 9 +- reactos/lib/userenv/makefile | 2 +- reactos/lib/userenv/profile.c | 178 +++++++++++++++++++++++++++++++- 4 files changed, 213 insertions(+), 4 deletions(-) create mode 100644 reactos/lib/userenv/directory.c diff --git a/reactos/lib/userenv/directory.c b/reactos/lib/userenv/directory.c new file mode 100644 index 00000000000..c02285a7459 --- /dev/null +++ b/reactos/lib/userenv/directory.c @@ -0,0 +1,28 @@ +/* $Id: directory.c,v 1.1 2004/01/15 14:59:06 ekohl Exp $ + * + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: lib/userenv/directory.c + * PURPOSE: User profile code + * PROGRAMMER: Eric Kohl + */ + +#include +#include +#include + +//#include + +#include "internal.h" + + +/* FUNCTIONS ***************************************************************/ + +BOOL +CopyDirectory (LPCWSTR lpDestinationPath, + LPCWSTR lpSourcePath) +{ + return TRUE; +} + +/* EOF */ diff --git a/reactos/lib/userenv/internal.h b/reactos/lib/userenv/internal.h index 04a37b7500a..a0506f54444 100644 --- a/reactos/lib/userenv/internal.h +++ b/reactos/lib/userenv/internal.h @@ -1,4 +1,4 @@ -/* $Id: internal.h,v 1.2 2004/01/13 12:34:09 ekohl Exp $ +/* $Id: internal.h,v 1.3 2004/01/15 14:59:06 ekohl Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS system libraries @@ -11,11 +11,16 @@ #define _INTERNAL_H /* debug.h */ -void DebugPrint(char* fmt,...); +void +DebugPrint (char* fmt,...); #define DPRINT1 DebugPrint("(%s:%d) ",__FILE__,__LINE__), DebugPrint #define CHECKPOINT1 do { DebugPrint("%s:%d\n",__FILE__,__LINE__); } while(0); +/* directory.h */ +BOOL +CopyDirectory (LPCWSTR lpDestinationPath, + LPCWSTR lpSourcePath); #endif /* _INTERNAL_H */ diff --git a/reactos/lib/userenv/makefile b/reactos/lib/userenv/makefile index d27ae3361c0..a817441151b 100644 --- a/reactos/lib/userenv/makefile +++ b/reactos/lib/userenv/makefile @@ -15,7 +15,7 @@ TARGET_LFLAGS = -nostdlib -nostartfiles TARGET_SDKLIBS = ntdll.a kernel32.a advapi32.a -TARGET_OBJECTS = profile.o setup.o userenv.o +TARGET_OBJECTS = directory.o profile.o setup.o userenv.o DEP_OBJECTS = $(TARGET_OBJECTS) diff --git a/reactos/lib/userenv/profile.c b/reactos/lib/userenv/profile.c index 267c3171599..16827899586 100644 --- a/reactos/lib/userenv/profile.c +++ b/reactos/lib/userenv/profile.c @@ -1,4 +1,4 @@ -/* $Id: profile.c,v 1.1 2004/01/13 12:34:09 ekohl Exp $ +/* $Id: profile.c,v 1.2 2004/01/15 14:59:06 ekohl Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS system libraries @@ -7,6 +7,7 @@ * PROGRAMMER: Eric Kohl */ +#include #include #include @@ -21,6 +22,179 @@ BOOL WINAPI CreateUserProfileW (PSID Sid, LPCWSTR lpUserName) { + WCHAR szRawProfilesPath[MAX_PATH]; + WCHAR szProfilesPath[MAX_PATH]; + WCHAR szUserProfilePath[MAX_PATH]; + WCHAR szDefaultUserPath[MAX_PATH]; + WCHAR szBuffer[MAX_PATH]; + UNICODE_STRING SidString; + DWORD dwLength; + DWORD dwDisposition; + HKEY hKey; + NTSTATUS Status; + + + 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; + } + + /* Get default user path */ + dwLength = MAX_PATH * sizeof(WCHAR); + if (RegQueryValueExW (hKey, + L"DefaultUserProfile", + NULL, + NULL, + (LPBYTE)szBuffer, + &dwLength)) + { + DPRINT1("Error: %lu\n", GetLastError()); + RegCloseKey (hKey); + return FALSE; + } + + RegCloseKey (hKey); + + wcscpy (szUserProfilePath, szProfilesPath); + wcscat (szUserProfilePath, L"\\"); + wcscat (szUserProfilePath, lpUserName); + + wcscpy (szDefaultUserPath, szProfilesPath); + wcscat (szDefaultUserPath, L"\\"); + wcscat (szDefaultUserPath, szBuffer); + + /* Create user profile directory */ + if (!CreateDirectoryW (szUserProfilePath, NULL)) + { + if (GetLastError () != ERROR_ALREADY_EXISTS) + { + DPRINT1("Error: %lu\n", GetLastError()); + return FALSE; + } + } + + /* Copy default user directory */ + if (!CopyDirectory (szUserProfilePath, szDefaultUserPath)) + { + DPRINT1("Error: %lu\n", GetLastError()); + return FALSE; + } + + /* Add profile to profile list */ + Status = RtlConvertSidToUnicodeString (&SidString, Sid, TRUE); + if (!NT_SUCCESS(Status)) + { + DPRINT1("Status: %lx\n", Status); + return FALSE; + } + + wcscpy (szBuffer, + L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList\\"); + wcscat (szBuffer, SidString.Buffer); + +// DebugPrint ("User SID: %wZ\n", &SidString); +// RtlFreeUnicodeString (&SidString); + + /* Create user profile key */ + if (RegCreateKeyExW (HKEY_LOCAL_MACHINE, + szBuffer, + 0, + NULL, + REG_OPTION_NON_VOLATILE, + KEY_ALL_ACCESS, + NULL, + &hKey, + &dwDisposition)) + { + DPRINT1("Error: %lu\n", GetLastError()); + RtlFreeUnicodeString (&SidString); + return FALSE; + } + + /* Create non-expanded user profile path */ + wcscpy (szBuffer, szRawProfilesPath); + wcscat (szBuffer, L"\\"); + wcscat (szBuffer, lpUserName); + + /* 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); + RegCloseKey (hKey); + return FALSE; + } + + /* Set 'Sid' value */ + if (RegSetValueExW (hKey, + L"Sid", + 0, + REG_BINARY, + Sid, + RtlLengthSid (Sid))) + { + DPRINT1("Error: %lu\n", GetLastError()); + RtlFreeUnicodeString (&SidString); + RegCloseKey (hKey); + return FALSE; + } + + RegCloseKey (hKey); + + /* Create user hive name */ + wcscat (szUserProfilePath, L"\\ntuser.dat"); + + /* Create new user hive */ + if (RegLoadKeyW (HKEY_USERS, + SidString.Buffer, + szUserProfilePath)) + { + DPRINT1("Error: %lu\n", GetLastError()); + RtlFreeUnicodeString (&SidString); + return FALSE; + } + + /* FIXME: Copy default user hive */ + + RegUnLoadKeyW (HKEY_USERS, + SidString.Buffer); + + RtlFreeUnicodeString (&SidString); + return TRUE; } @@ -206,6 +380,7 @@ GetProfilesDirectoryW (LPWSTR lpProfilesDir, return FALSE; } + /* Get profiles path */ dwLength = MAX_PATH * sizeof(WCHAR); if (RegQueryValueExW (hKey, L"ProfilesDirectory", @@ -221,6 +396,7 @@ GetProfilesDirectoryW (LPWSTR lpProfilesDir, RegCloseKey (hKey); + /* Expand it */ if (!ExpandEnvironmentStringsW (szBuffer, szProfilesPath, MAX_PATH))