ReactOS.org
Sign In
Sign Up
Sign In
Sign Up
Manage this list
×
Keyboard Shortcuts
Thread View
j
: Next unread message
k
: Previous unread message
j a
: Jump to all threads
j l
: Jump to MailingList overview
2024
December
November
October
September
August
July
June
May
April
March
February
January
2023
December
November
October
September
August
July
June
May
April
March
February
January
2022
December
November
October
September
August
July
June
May
April
March
February
January
2021
December
November
October
September
August
July
June
May
April
March
February
January
2020
December
November
October
September
August
July
June
May
April
March
February
January
2019
December
November
October
September
August
July
June
May
April
March
February
January
2018
December
November
October
September
August
July
June
May
April
March
February
January
2017
December
November
October
September
August
July
June
May
April
March
February
January
2016
December
November
October
September
August
July
June
May
April
March
February
January
2015
December
November
October
September
August
July
June
May
April
March
February
January
2014
December
November
October
September
August
July
June
May
April
March
February
January
2013
December
November
October
September
August
July
June
May
April
March
February
January
2012
December
November
October
September
August
July
June
May
April
March
February
January
2011
December
November
October
September
August
July
June
May
April
March
February
January
2010
December
November
October
September
August
July
June
May
April
March
February
January
2009
December
November
October
September
August
July
June
May
April
March
February
January
2008
December
November
October
September
August
July
June
May
April
March
February
January
2007
December
November
October
September
August
July
June
May
April
March
February
January
2006
December
November
October
September
August
July
June
May
April
March
February
January
2005
December
November
October
September
August
July
June
May
April
March
February
January
2004
December
November
October
September
August
July
June
May
April
March
February
List overview
Download
Ros-diffs
October 2018
----- 2024 -----
December 2024
November 2024
October 2024
September 2024
August 2024
July 2024
June 2024
May 2024
April 2024
March 2024
February 2024
January 2024
----- 2023 -----
December 2023
November 2023
October 2023
September 2023
August 2023
July 2023
June 2023
May 2023
April 2023
March 2023
February 2023
January 2023
----- 2022 -----
December 2022
November 2022
October 2022
September 2022
August 2022
July 2022
June 2022
May 2022
April 2022
March 2022
February 2022
January 2022
----- 2021 -----
December 2021
November 2021
October 2021
September 2021
August 2021
July 2021
June 2021
May 2021
April 2021
March 2021
February 2021
January 2021
----- 2020 -----
December 2020
November 2020
October 2020
September 2020
August 2020
July 2020
June 2020
May 2020
April 2020
March 2020
February 2020
January 2020
----- 2019 -----
December 2019
November 2019
October 2019
September 2019
August 2019
July 2019
June 2019
May 2019
April 2019
March 2019
February 2019
January 2019
----- 2018 -----
December 2018
November 2018
October 2018
September 2018
August 2018
July 2018
June 2018
May 2018
April 2018
March 2018
February 2018
January 2018
----- 2017 -----
December 2017
November 2017
October 2017
September 2017
August 2017
July 2017
June 2017
May 2017
April 2017
March 2017
February 2017
January 2017
----- 2016 -----
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
----- 2015 -----
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
----- 2014 -----
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
----- 2013 -----
December 2013
November 2013
October 2013
September 2013
August 2013
July 2013
June 2013
May 2013
April 2013
March 2013
February 2013
January 2013
----- 2012 -----
December 2012
November 2012
October 2012
September 2012
August 2012
July 2012
June 2012
May 2012
April 2012
March 2012
February 2012
January 2012
----- 2011 -----
December 2011
November 2011
October 2011
September 2011
August 2011
July 2011
June 2011
May 2011
April 2011
March 2011
February 2011
January 2011
----- 2010 -----
December 2010
November 2010
October 2010
September 2010
August 2010
July 2010
June 2010
May 2010
April 2010
March 2010
February 2010
January 2010
----- 2009 -----
December 2009
November 2009
October 2009
September 2009
August 2009
July 2009
June 2009
May 2009
April 2009
March 2009
February 2009
January 2009
----- 2008 -----
December 2008
November 2008
October 2008
September 2008
August 2008
July 2008
June 2008
May 2008
April 2008
March 2008
February 2008
January 2008
----- 2007 -----
December 2007
November 2007
October 2007
September 2007
August 2007
July 2007
June 2007
May 2007
April 2007
March 2007
February 2007
January 2007
----- 2006 -----
December 2006
November 2006
October 2006
September 2006
August 2006
July 2006
June 2006
May 2006
April 2006
March 2006
February 2006
January 2006
----- 2005 -----
December 2005
November 2005
October 2005
September 2005
August 2005
July 2005
June 2005
May 2005
April 2005
March 2005
February 2005
January 2005
----- 2004 -----
December 2004
November 2004
October 2004
September 2004
August 2004
July 2004
June 2004
May 2004
April 2004
March 2004
February 2004
ros-diffs@reactos.org
21 participants
354 discussions
Start a n
N
ew thread
06/08: [USETUP] Mark some variables as 'static'.
by Hermès Bélusca-Maïto
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=b20908acc80f65496ad3d…
commit b20908acc80f65496ad3d153b87069c6b652ec8b Author: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org> AuthorDate: Thu Jun 22 00:36:29 2017 +0000 Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org> CommitDate: Thu Oct 25 00:58:24 2018 +0200 [USETUP] Mark some variables as 'static'. svn path=/branches/setup_improvements/; revision=75161 --- base/setup/usetup/usetup.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/base/setup/usetup/usetup.c b/base/setup/usetup/usetup.c index 9318f7e250..80d6345aa2 100644 --- a/base/setup/usetup/usetup.c +++ b/base/setup/usetup/usetup.c @@ -45,9 +45,11 @@ /* GLOBALS ******************************************************************/ HANDLE ProcessHeap; + static UNICODE_STRING SourceRootPath; static UNICODE_STRING SourceRootDir; /* static */ UNICODE_STRING SourcePath; + BOOLEAN IsUnattendedSetup = FALSE; LONG UnattendDestinationDiskNumber; LONG UnattendDestinationPartitionNumber; @@ -59,12 +61,12 @@ PWCHAR SelectedLanguageId; WCHAR LocaleID[9]; WCHAR DefaultLanguage[20]; WCHAR DefaultKBLayout[20]; -BOOLEAN RepairUpdateFlag = FALSE; -HANDLE hPnpThread = INVALID_HANDLE_VALUE; +static BOOLEAN RepairUpdateFlag = FALSE; +static HANDLE hPnpThread = INVALID_HANDLE_VALUE; -PPARTLIST PartitionList = NULL; -PPARTENTRY TempPartition = NULL; -FORMATMACHINESTATE FormatState = Start; +static PPARTLIST PartitionList = NULL; +static PPARTENTRY TempPartition = NULL; +static FORMATMACHINESTATE FormatState = Start; /* LOCALS *******************************************************************/
6 years, 2 months
1
0
0
0
05/08: [USETUP] Implement work-in-progress code that allows verifying whether registry hives validity.
by Hermès Bélusca-Maïto
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=455e69a0113defa7e28a6…
commit 455e69a0113defa7e28a61ba0c16fecef5f77e77 Author: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org> AuthorDate: Mon Jun 12 00:09:16 2017 +0000 Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org> CommitDate: Thu Oct 25 00:58:23 2018 +0200 [USETUP] Implement work-in-progress code that allows verifying whether registry hives validity. Implement work-in-progress code that, when upgrading an existing ReactOS installation, verifies whether the (existing) system registry hives are valid (by loading & unloading them, this allows using the built-in repair functionality if needed), or not. If a given hive cannot be repaired successfully, it is backed up (with a '.brk' extension, "brk" as "broken"), then is marked up for recreation. When all hives have been checked, if there are any hive that needs to be recreated, we recreate its hive file, mount it, but we do *NOT* mount the other valid existing hives for update. We create instead dummy registry hives so that we can actually use, as the update code, the same one as the one used when fully creating the registry hives for a clean installation (of course, this choice can be improved later on). The update code (i.e. the same as the registry clean-install one) then adds the registry keys & values, either putting them in the dummy registry hives (the ones that we don't want to recreate) or in the registry hive that is recreated. At the end, the (re)created registry hives are flushed back to disk, and a copy of them (under a '.sav' extension) are created, so that they can be used for restoration purposes if 2nd-stage (and up) goes berserk. Extra fixes: - Use the correct structure member field when initializing the 'InstallDir' variable, when performing an upgrade. - CreateNestedKey() should be better analysed to see whether it correctly creates the full registry path compatible with volatile/non-volatile keys (under inspection). svn path=/branches/setup_improvements/; revision=75010 --- base/setup/usetup/registry.c | 556 ++++++++++++++++++++++++++++++------------- base/setup/usetup/registry.h | 8 +- base/setup/usetup/usetup.c | 95 +++++--- 3 files changed, 454 insertions(+), 205 deletions(-) diff --git a/base/setup/usetup/registry.c b/base/setup/usetup/registry.c index 7fda1c928c..bb79689789 100644 --- a/base/setup/usetup/registry.c +++ b/base/setup/usetup/registry.c @@ -28,6 +28,9 @@ #include "usetup.h" +// HACK! +#include <strsafe.h> + #define NDEBUG #include <debug.h> @@ -59,6 +62,9 @@ /* FUNCTIONS ****************************************************************/ +#define REGISTRY_SETUP_MACHINE L"\\Registry\\Machine\\SYSTEM\\USetup_Machine\\" +#define REGISTRY_SETUP_USER L"\\Registry\\Machine\\SYSTEM\\USetup_User\\" + typedef struct _ROOT_KEY { PCWSTR Name; @@ -68,11 +74,10 @@ typedef struct _ROOT_KEY ROOT_KEY RootKeys[] = { - // L"\\Registry\\Machine\\SYSTEM\\USetup_Machine\\SOFTWARE\\Classes\\" - { L"HKCR", L"\\Registry\\Machine\\USetup_SOFTWARE\\Classes\\", NULL }, /* "\\Registry\\Machine\\SOFTWARE\\Classes\\" */ // HKEY_CLASSES_ROOT - { L"HKCU", L"\\Registry\\User\\USetup_DEFAULT\\" , NULL }, /* "\\Registry\\User\\.DEFAULT\\" */ // HKEY_CURRENT_USER - { L"HKLM", L"\\Registry\\Machine\\SYSTEM\\USetup_Machine\\" , NULL }, /* "\\Registry\\Machine\\" */ // HKEY_LOCAL_MACHINE - { L"HKU" , L"\\Registry\\Machine\\SYSTEM\\USetup_User\\" , NULL }, /* "\\Registry\\User\\" */ // HKEY_USERS + { L"HKCR", REGISTRY_SETUP_MACHINE L"SOFTWARE\\Classes\\", NULL }, /* "\\Registry\\Machine\\SOFTWARE\\Classes\\" */ // HKEY_CLASSES_ROOT + { L"HKCU", REGISTRY_SETUP_USER L".DEFAULT\\" , NULL }, /* "\\Registry\\User\\.DEFAULT\\" */ // HKEY_CURRENT_USER + { L"HKLM", REGISTRY_SETUP_MACHINE , NULL }, /* "\\Registry\\Machine\\" */ // HKEY_LOCAL_MACHINE + { L"HKU" , REGISTRY_SETUP_USER , NULL }, /* "\\Registry\\User\\" */ // HKEY_USERS #if 0 { L"HKR", NULL, NULL }, #endif @@ -401,10 +406,17 @@ do_reg_operation(HANDLE KeyHandle, return TRUE; } +/* + * This function is similar to the one in dlls/win32/advapi32/reg/reg.c + * TODO: I should review both of them very carefully, because they may need + * some adjustments in their NtCreateKey calls, especially for CreateOptions + * stuff etc... + */ NTSTATUS CreateNestedKey(PHANDLE KeyHandle, ACCESS_MASK DesiredAccess, - POBJECT_ATTRIBUTES ObjectAttributes) + POBJECT_ATTRIBUTES ObjectAttributes, + ULONG CreateOptions) { OBJECT_ATTRIBUTES LocalObjectAttributes; UNICODE_STRING LocalKeyName; @@ -419,11 +431,16 @@ CreateNestedKey(PHANDLE KeyHandle, ObjectAttributes, 0, NULL, - 0, + CreateOptions, &Disposition); DPRINT("NtCreateKey(%wZ) called (Status %lx)\n", ObjectAttributes->ObjectName, Status); if (Status != STATUS_OBJECT_NAME_NOT_FOUND) + { + if (!NT_SUCCESS(Status)) + DPRINT1("CreateNestedKey: NtCreateKey(%wZ) failed (Status %lx)\n", ObjectAttributes->ObjectName, Status); + return Status; + } /* Copy object attributes */ RtlCopyMemory(&LocalObjectAttributes, @@ -437,28 +454,30 @@ CreateNestedKey(PHANDLE KeyHandle, /* Remove the last part of the key name and try to create the key again. */ while (Status == STATUS_OBJECT_NAME_NOT_FOUND) { - Ptr = wcsrchr (LocalKeyName.Buffer, '\\'); + Ptr = wcsrchr(LocalKeyName.Buffer, '\\'); if (Ptr == NULL || Ptr == LocalKeyName.Buffer) { Status = STATUS_UNSUCCESSFUL; break; } *Ptr = (WCHAR)0; - LocalKeyName.Length = wcslen (LocalKeyName.Buffer) * sizeof(WCHAR); + LocalKeyName.Length = wcslen(LocalKeyName.Buffer) * sizeof(WCHAR); Status = NtCreateKey(&LocalKeyHandle, - KEY_ALL_ACCESS, + KEY_CREATE_SUB_KEY, &LocalObjectAttributes, 0, NULL, - 0, + REG_OPTION_NON_VOLATILE, &Disposition); DPRINT("NtCreateKey(%wZ) called (Status %lx)\n", &LocalKeyName, Status); + if (!NT_SUCCESS(Status) && Status != STATUS_OBJECT_NAME_NOT_FOUND) + DPRINT1("CreateNestedKey: NtCreateKey(%wZ) failed (Status %lx)\n", LocalObjectAttributes.ObjectName, Status); } if (!NT_SUCCESS(Status)) { - RtlFreeUnicodeString (&LocalKeyName); + RtlFreeUnicodeString(&LocalKeyName); return Status; } @@ -474,18 +493,21 @@ CreateNestedKey(PHANDLE KeyHandle, NtClose(LocalKeyHandle); LocalKeyName.Buffer[LocalKeyName.Length / sizeof(WCHAR)] = L'\\'; - LocalKeyName.Length = wcslen (LocalKeyName.Buffer) * sizeof(WCHAR); + LocalKeyName.Length = wcslen(LocalKeyName.Buffer) * sizeof(WCHAR); Status = NtCreateKey(&LocalKeyHandle, KEY_ALL_ACCESS, &LocalObjectAttributes, 0, NULL, - 0, + CreateOptions, &Disposition); DPRINT("NtCreateKey(%wZ) called (Status %lx)\n", &LocalKeyName, Status); if (!NT_SUCCESS(Status)) + { + DPRINT1("CreateNestedKey: NtCreateKey(%wZ) failed (Status %lx)\n", LocalObjectAttributes.ObjectName, Status); break; + } } RtlFreeUnicodeString(&LocalKeyName); @@ -560,7 +582,8 @@ registry_callback(HINF hInf, PCWSTR Section, BOOLEAN Delete) { Status = CreateNestedKey(&KeyHandle, KEY_ALL_ACCESS, - &ObjectAttributes); + &ObjectAttributes, + REG_OPTION_NON_VOLATILE); if (!NT_SUCCESS(Status)) { DPRINT1("CreateNestedKey(%wZ) failed (Status %lx)\n", &Name, Status); @@ -649,29 +672,86 @@ ImportRegistryFile( /* * Should be called under privileges */ -// static -NTSTATUS +static NTSTATUS CreateRegistryFile( IN PUNICODE_STRING InstallPath, IN PCWSTR RegistryKey, - IN HANDLE ProtoKeyHandle) + IN BOOLEAN IsHiveNew, + IN HANDLE ProtoKeyHandle +/* + IN PUCHAR Descriptor, + IN ULONG DescriptorLength +*/ + ) { + /* '.old' is for old valid hives, while '.brk' is for old broken hives */ + static PCWSTR Extensions[] = {L"old", L"brk"}; + NTSTATUS Status; HANDLE FileHandle; UNICODE_STRING FileName; OBJECT_ATTRIBUTES ObjectAttributes; IO_STATUS_BLOCK IoStatusBlock; + PCWSTR Extension; WCHAR PathBuffer[MAX_PATH]; + WCHAR PathBuffer2[MAX_PATH]; - /* Create the file */ CombinePaths(PathBuffer, ARRAYSIZE(PathBuffer), 3, InstallPath->Buffer, L"System32\\config", RegistryKey); + + Extension = Extensions[IsHiveNew ? 0 : 1]; + + // + // FIXME: The best, actually, would be to rename (move) the existing + // System32\config\RegistryKey file to System32\config\RegistryKey.old, + // and if it already existed some System32\config\RegistryKey.old, we should + // first rename this one into System32\config\RegistryKey_N.old before + // performing the original rename. + // + + /* Check whether the registry hive file already existed, and if so, rename it */ + if (DoesFileExist(NULL, PathBuffer)) + { + // UINT i; + + DPRINT1("Registry hive '%S' already exists, rename it\n", PathBuffer); + + // i = 1; + /* Try first by just appending the '.old' extension */ + StringCchPrintfW(PathBuffer2, ARRAYSIZE(PathBuffer2), L"%s.%s", PathBuffer, Extension); +#if 0 + while (DoesFileExist(NULL, PathBuffer2)) + { + /* An old file already exists, increments its index, but not too much */ + if (i <= 0xFFFF) + { + /* Append '_N.old' extension */ + StringCchPrintfW(PathBuffer2, ARRAYSIZE(PathBuffer2), L"%s_%lu.%s", PathBuffer, i, Extension); + ++i; + } + else + { + /* + * Too many old files exist, we will rename the file + * using the name of the oldest one. + */ + StringCchPrintfW(PathBuffer2, ARRAYSIZE(PathBuffer2), L"%s.%s", PathBuffer, Extension); + break; + } + } +#endif + + /* Now rename the file (force the move) */ + Status = SetupMoveFile(PathBuffer, PathBuffer2, MOVEFILE_REPLACE_EXISTING); + } + + /* Create the file */ RtlInitUnicodeString(&FileName, PathBuffer); InitializeObjectAttributes(&ObjectAttributes, &FileName, OBJ_CASE_INSENSITIVE, - NULL, // Could have been installpath, etc... - NULL); + NULL, // Could have been installpath, etc... + NULL); // Descriptor Status = NtCreateFile(&FileHandle, FILE_GENERIC_WRITE, @@ -773,18 +853,19 @@ CmpLinkKeyToHive( /* * Should be called under privileges */ -// static -NTSTATUS +static NTSTATUS ConnectRegistry( IN HKEY RootKey OPTIONAL, + IN PCWSTR RegMountPoint, // IN HANDLE RootDirectory OPTIONAL, IN PUNICODE_STRING InstallPath, - IN PCWSTR RegistryKey, - // IN PUCHAR Descriptor, - // IN ULONG DescriptorLength, - IN PCWSTR RegMountPoint) + IN PCWSTR RegistryKey +/* + IN PUCHAR Descriptor, + IN ULONG DescriptorLength +*/ + ) { - NTSTATUS Status; UNICODE_STRING KeyName, FileName; OBJECT_ATTRIBUTES KeyObjectAttributes; OBJECT_ATTRIBUTES FileObjectAttributes; @@ -795,7 +876,7 @@ ConnectRegistry( &KeyName, OBJ_CASE_INSENSITIVE, RootKey, - NULL); + NULL); // Descriptor CombinePaths(PathBuffer, ARRAYSIZE(PathBuffer), 3, InstallPath->Buffer, L"System32\\config", RegistryKey); @@ -806,56 +887,202 @@ ConnectRegistry( NULL, // RootDirectory, NULL); -#if 0 - IN PCMHIVE HiveToConnect; - /* - * Add security to the root key. - * NOTE: One can implement this using the lpSecurityAttributes - * parameter of RegCreateKeyExW. - */ - Status = CmiCreateSecurityKey(&HiveToConnect->Hive, - HiveToConnect->Hive.BaseBlock->RootCell, - Descriptor, DescriptorLength); + /* Mount the registry hive in the registry namespace */ + return NtLoadKey(&KeyObjectAttributes, &FileObjectAttributes); +} + + +static NTSTATUS +VerifyRegistryHive( + // IN HKEY RootKey OPTIONAL, + // // IN HANDLE RootDirectory OPTIONAL, + IN PUNICODE_STRING InstallPath, + IN PCWSTR RegistryKey /* , + IN PCWSTR RegMountPoint */) +{ + NTSTATUS Status; + UNICODE_STRING KeyName; + OBJECT_ATTRIBUTES KeyObjectAttributes; + + /* Try to mount the specified registry hive */ + Status = ConnectRegistry(NULL, + L"\\Registry\\Machine\\USetup_VerifyHive", + InstallPath, + RegistryKey + /* NULL, 0 */); if (!NT_SUCCESS(Status)) - DPRINT1("Failed to add security for root key '%S'\n", Path); -#endif + { + DPRINT1("ConnectRegistry(%S) failed, Status 0x%08lx\n", RegistryKey, Status); + } - /* Mount the registry hive in the registry namespace */ - Status = NtLoadKey(&KeyObjectAttributes, &FileObjectAttributes); + DPRINT1("VerifyRegistryHive: ConnectRegistry(%S) returns Status 0x%08lx\n", RegistryKey, Status); + + // + // TODO: Check the Status error codes: STATUS_SUCCESS, STATUS_REGISTRY_RECOVERED, + // STATUS_REGISTRY_HIVE_RECOVERED, STATUS_REGISTRY_CORRUPT, STATUS_REGISTRY_IO_FAILED, + // STATUS_NOT_REGISTRY_FILE, STATUS_CANNOT_LOAD_REGISTRY_FILE ; + //(STATUS_HIVE_UNLOADED) ; STATUS_SYSTEM_HIVE_TOO_LARGE + // + + if (Status == STATUS_REGISTRY_HIVE_RECOVERED) // NT_SUCCESS is still FALSE in this case! + DPRINT1("VerifyRegistryHive: Registry hive %S was recovered but some data may be lost (Status 0x%08lx)\n", RegistryKey, Status); + + if (!NT_SUCCESS(Status)) + { + DPRINT1("VerifyRegistryHive: Registry hive %S is corrupted (Status 0x%08lx)\n", RegistryKey, Status); + return Status; + } + + if (Status == STATUS_REGISTRY_RECOVERED) + DPRINT1("VerifyRegistryHive: Registry hive %S succeeded recovered (Status 0x%08lx)\n", RegistryKey, Status); + + /* Unmount the hive */ + InitializeObjectAttributes(&KeyObjectAttributes, + &KeyName, + OBJ_CASE_INSENSITIVE, + NULL, + NULL); + + RtlInitUnicodeString(&KeyName, L"\\Registry\\Machine\\USetup_VerifyHive"); + Status = NtUnloadKey(&KeyObjectAttributes); + if (!NT_SUCCESS(Status)) + { + DPRINT1("NtUnloadKey(%S, %wZ) failed, Status 0x%08lx\n", RegistryKey, &KeyName, Status); + } return Status; } + +typedef enum _HIVE_UPDATE_STATE +{ + Create, // Create a new hive file and save possibly existing old one with a .old extension. + Repair, // Re-create a new hive file and save possibly existing old one with a .brk extension. + Update // Hive update, do not need to be recreated. +} HIVE_UPDATE_STATE; + +typedef struct _HIVE_LIST_ENTRY +{ + PCWSTR HiveName; // HiveFileName; + PCWSTR HiveRegistryPath; // HiveRegMountPoint; + HANDLE PredefKeyHandle; + PCWSTR RegSymLink; + HIVE_UPDATE_STATE State; + // PUCHAR SecurityDescriptor; + // ULONG SecurityDescriptorLength; +} HIVE_LIST_ENTRY, *PHIVE_LIST_ENTRY; + +#define NUMBER_OF_STANDARD_REGISTRY_HIVES 3 + +HIVE_LIST_ENTRY RegistryHives[/*NUMBER_OF_STANDARD_REGISTRY_HIVES*/] = +{ + { L"SYSTEM" , L"\\Registry\\Machine\\USetup_SYSTEM" , HKEY_LOCAL_MACHINE, L"SYSTEM" , Create /* , SystemSecurity , sizeof(SystemSecurity) */ }, + { L"SOFTWARE", L"\\Registry\\Machine\\USetup_SOFTWARE", HKEY_LOCAL_MACHINE, L"SOFTWARE", Create /* , SoftwareSecurity, sizeof(SoftwareSecurity) */ }, + { L"DEFAULT" , L"\\Registry\\User\\USetup_DEFAULT" , HKEY_USERS , L".DEFAULT", Create /* , SystemSecurity , sizeof(SystemSecurity) */ }, + +// { L"BCD" , L"\\Registry\\Machine\\USetup_BCD", HKEY_LOCAL_MACHINE, L"BCD00000000", Create /* , BcdSecurity , sizeof(BcdSecurity) */ }, +}; +C_ASSERT(_countof(RegistryHives) == NUMBER_OF_STANDARD_REGISTRY_HIVES); + +#define NUMBER_OF_SECURITY_REGISTRY_HIVES 2 + +/** These hives are created by LSASS during 2nd stage setup */ +HIVE_LIST_ENTRY SecurityRegistryHives[/*NUMBER_OF_SECURITY_REGISTRY_HIVES*/] = +{ + { L"SAM" , L"\\Registry\\Machine\\USetup_SAM" , HKEY_LOCAL_MACHINE, L"SAM" , Create /* , SystemSecurity , sizeof(SystemSecurity) */ }, + { L"SECURITY", L"\\Registry\\Machine\\USetup_SECURITY", HKEY_LOCAL_MACHINE, L"SECURITY", Create /* , NULL , 0 */ }, +}; +C_ASSERT(_countof(SecurityRegistryHives) == NUMBER_OF_SECURITY_REGISTRY_HIVES); + + NTSTATUS -RegInitializeRegistry( - IN PUNICODE_STRING InstallPath) +VerifyRegistryHives( + IN PUNICODE_STRING InstallPath, + OUT PBOOLEAN ShouldUpdateRegistry) { NTSTATUS Status; - HANDLE KeyHandle; - UNICODE_STRING KeyName; - OBJECT_ATTRIBUTES ObjectAttributes; BOOLEAN PrivilegeSet[2] = {FALSE, FALSE}; - ULONG Disposition; UINT i; - PCWSTR RegistryKeys[] = + + /* Suppose first the registry hives do not have to be updated/recreated */ + *ShouldUpdateRegistry = FALSE; + + /* Acquire restore privilege */ + Status = RtlAdjustPrivilege(SE_RESTORE_PRIVILEGE, TRUE, FALSE, &PrivilegeSet[0]); + if (!NT_SUCCESS(Status)) { - L"SYSTEM", - L"SOFTWARE", - L"DEFAULT", // L".DEFAULT", - // L"SAM", - // L"SECURITY", - // L"BCD00000000", - }; + DPRINT1("RtlAdjustPrivilege(SE_RESTORE_PRIVILEGE) failed (Status 0x%08lx)\n", Status); + /* Exit prematurely here.... */ + return Status; + } -#if 0 - /* Initialize the current session registry */ - Status = NtInitializeRegistry(CM_BOOT_FLAG_SETUP); + /* Acquire backup privilege */ + Status = RtlAdjustPrivilege(SE_BACKUP_PRIVILEGE, TRUE, FALSE, &PrivilegeSet[1]); if (!NT_SUCCESS(Status)) { - DPRINT1("NtInitializeRegistry() failed (Status %lx)\n", Status); + DPRINT1("RtlAdjustPrivilege(SE_BACKUP_PRIVILEGE) failed (Status 0x%08lx)\n", Status); + RtlAdjustPrivilege(SE_RESTORE_PRIVILEGE, PrivilegeSet[0], FALSE, &PrivilegeSet[0]); + /* Exit prematurely here.... */ return Status; } -#endif + + for (i = 0; i < ARRAYSIZE(RegistryHives); ++i) + { + Status = VerifyRegistryHive(InstallPath, RegistryHives[i].HiveName); + if (!NT_SUCCESS(Status)) + { + DPRINT1("Registry hive '%S' needs repair!\n", RegistryHives[i].HiveName); + RegistryHives[i].State = Repair; + *ShouldUpdateRegistry = TRUE; + } + else + { + RegistryHives[i].State = Update; + } + } + + /** These hives are created by LSASS during 2nd stage setup */ + for (i = 0; i < ARRAYSIZE(SecurityRegistryHives); ++i) + { + Status = VerifyRegistryHive(InstallPath, SecurityRegistryHives[i].HiveName); + if (!NT_SUCCESS(Status)) + { + DPRINT1("Registry hive '%S' needs repair!\n", SecurityRegistryHives[i].HiveName); + SecurityRegistryHives[i].State = Repair; + /* + * Note that it's not the role of the 1st-stage installer to fix + * the security hives. This should be done at 2nd-stage installation + * by LSASS. + */ + } + else + { + SecurityRegistryHives[i].State = Update; + } + } + + /* Reset the status (we succeeded in checking all the hives) */ + Status = STATUS_SUCCESS; + + /* Remove restore and backup privileges */ + RtlAdjustPrivilege(SE_BACKUP_PRIVILEGE, PrivilegeSet[1], FALSE, &PrivilegeSet[1]); + RtlAdjustPrivilege(SE_RESTORE_PRIVILEGE, PrivilegeSet[0], FALSE, &PrivilegeSet[0]); + + return Status; +} + + +NTSTATUS +RegInitializeRegistry( + IN PUNICODE_STRING InstallPath) +{ + NTSTATUS Status; + HANDLE KeyHandle; + UNICODE_STRING KeyName; + OBJECT_ATTRIBUTES ObjectAttributes; + BOOLEAN PrivilegeSet[2] = {FALSE, FALSE}; + ULONG Disposition; + UINT i; /* Acquire restore privilege */ Status = RtlAdjustPrivilege(SE_RESTORE_PRIVILEGE, TRUE, FALSE, &PrivilegeSet[0]); @@ -885,8 +1112,7 @@ RegInitializeRegistry( * See
https://github.com/libyal/winreg-kb/blob/master/documentation/Registry%20fi…
* for more information. */ - RtlInitUnicodeString(&KeyName, - L"\\Registry\\Machine\\SYSTEM\\$$$PROTO.HIV"); + RtlInitUnicodeString(&KeyName, L"\\Registry\\Machine\\SYSTEM\\$$$PROTO.HIV"); InitializeObjectAttributes(&ObjectAttributes, &KeyName, OBJ_CASE_INSENSITIVE, @@ -906,14 +1132,18 @@ RegInitializeRegistry( } NtFlushKey(KeyHandle); - for (i = 0; i < ARRAYSIZE(RegistryKeys); ++i) + for (i = 0; i < ARRAYSIZE(RegistryHives); ++i) { + if (RegistryHives[i].State != Create && RegistryHives[i].State != Repair) + continue; + Status = CreateRegistryFile(InstallPath, - RegistryKeys[i], + RegistryHives[i].HiveName, + RegistryHives[i].State != Repair, // RegistryHives[i].State == Create, KeyHandle); if (!NT_SUCCESS(Status)) { - DPRINT1("CreateRegistryFile(%S) failed, Status 0x%08lx\n", RegistryKeys[i], Status); + DPRINT1("CreateRegistryFile(%S) failed, Status 0x%08lx\n", RegistryHives[i].HiveName, Status); /* Exit prematurely here.... */ /* That is now done, clean everything up! */ NtDeleteKey(KeyHandle); @@ -928,7 +1158,7 @@ RegInitializeRegistry( /* - * Prepare the installation roots. Since we cannot create real registry keys + * Prepare the registry root keys. Since we cannot create real registry keys * inside the master keys (\Registry, \Registry\Machine or \Registry\User), * we need to perform some SymLink tricks instead. */ @@ -946,7 +1176,7 @@ RegInitializeRegistry( &ObjectAttributes, 0, NULL, - REG_OPTION_VOLATILE, + REG_OPTION_NON_VOLATILE, // REG_OPTION_VOLATILE, // FIXME! &Disposition); if (!NT_SUCCESS(Status)) { @@ -968,7 +1198,7 @@ RegInitializeRegistry( &ObjectAttributes, 0, NULL, - REG_OPTION_VOLATILE, + REG_OPTION_NON_VOLATILE, // REG_OPTION_VOLATILE, // FIXME! &Disposition); if (!NT_SUCCESS(Status)) { @@ -978,72 +1208,61 @@ RegInitializeRegistry( RootKeys[GetPredefKeyIndex(HKEY_USERS)].Handle = KeyHandle; - /* * Now properly mount the offline hive files */ - - /* Create SYSTEM key */ - Status = - ConnectRegistry(NULL, - InstallPath, - RegistryKeys[0], - // SystemSecurity, sizeof(SystemSecurity), - L"\\Registry\\Machine\\USetup_SYSTEM"); - if (!NT_SUCCESS(Status)) - { - DPRINT1("ConnectRegistry(SYSTEM) failed, Status 0x%08lx\n", Status); - } - - /* Create the 'HKLM\SYSTEM' symlink to this key */ - if (!CmpLinkKeyToHive(RootKeys[GetPredefKeyIndex(HKEY_LOCAL_MACHINE)].Handle, - L"SYSTEM", - L"\\Registry\\Machine\\USetup_SYSTEM")) - { - DPRINT1("CmpLinkKeyToHive(SYSTEM) failed!\n"); - } - - - /* Create SOFTWARE key */ - Status = - ConnectRegistry(NULL, - InstallPath, - RegistryKeys[1], - // SoftwareSecurity, sizeof(SoftwareSecurity), - L"\\Registry\\Machine\\USetup_SOFTWARE"); - if (!NT_SUCCESS(Status)) - { - DPRINT1("ConnectRegistry(SOFTWARE) failed, Status 0x%08lx\n", Status); - } - - /* Create the 'HKLM\Software' symlink to this key */ - if (!CmpLinkKeyToHive(RootKeys[GetPredefKeyIndex(HKEY_LOCAL_MACHINE)].Handle, - L"Software", - L"\\Registry\\Machine\\USetup_SOFTWARE")) + for (i = 0; i < ARRAYSIZE(RegistryHives); ++i) { - DPRINT1("CmpLinkKeyToHive(SOFTWARE) failed!\n"); - } + // if (RegistryHives[i].State != Create && RegistryHives[i].State != Repair) + // continue; + if (RegistryHives[i].State == Create || RegistryHives[i].State == Repair) + { + Status = ConnectRegistry(NULL, + RegistryHives[i].HiveRegistryPath, + InstallPath, + RegistryHives[i].HiveName + /* SystemSecurity, sizeof(SystemSecurity) */); + if (!NT_SUCCESS(Status)) + { + DPRINT1("ConnectRegistry(%S) failed, Status 0x%08lx\n", RegistryHives[i].HiveName, Status); + } - /* Create DEFAULT key */ - Status = - ConnectRegistry(NULL, - InstallPath, - RegistryKeys[2], - // SystemSecurity, sizeof(SystemSecurity), - L"\\Registry\\User\\USetup_DEFAULT"); - if (!NT_SUCCESS(Status)) - { - DPRINT1("ConnectRegistry(DEFAULT) failed, Status 0x%08lx\n", Status); + /* Create the registry symlink to this key */ + if (!CmpLinkKeyToHive(RootKeys[GetPredefKeyIndex(RegistryHives[i].PredefKeyHandle)].Handle, + RegistryHives[i].RegSymLink, + RegistryHives[i].HiveRegistryPath)) + { + DPRINT1("CmpLinkKeyToHive(%S) failed!\n", RegistryHives[i].HiveName); + } + } + else + { + /* Create *DUMMY* volatile hives just to make the update procedure work */ + + RtlInitUnicodeString(&KeyName, RegistryHives[i].RegSymLink); + InitializeObjectAttributes(&ObjectAttributes, + &KeyName, + OBJ_CASE_INSENSITIVE, + RootKeys[GetPredefKeyIndex(RegistryHives[i].PredefKeyHandle)].Handle, + NULL); + KeyHandle = NULL; + Status = NtCreateKey(&KeyHandle, + KEY_ALL_ACCESS, + &ObjectAttributes, + 0, + NULL, + REG_OPTION_NON_VOLATILE, // REG_OPTION_VOLATILE, // FIXME! + &Disposition); + if (!NT_SUCCESS(Status)) + { + DPRINT1("NtCreateKey(%wZ) failed (Status 0x%08lx)\n", &KeyName, Status); + // return Status; + } + NtClose(KeyHandle); + } } - /* Create the 'HKU\.DEFAULT' symlink to this key */ - if (!CmpLinkKeyToHive(RootKeys[GetPredefKeyIndex(HKEY_USERS)].Handle, - L".DEFAULT", - L"\\Registry\\User\\USetup_DEFAULT")) - { - DPRINT1("CmpLinkKeyToHive(DEFAULT) failed!\n"); - } /* HKCU is a handle to 'HKU\.DEFAULT' */ #if 0 @@ -1089,12 +1308,13 @@ RegInitializeRegistry( NULL); #endif KeyHandle = NULL; + /* We use NtCreateKey instead of NtOpenKey because Software\Classes doesn't exist originally */ Status = NtCreateKey(&KeyHandle, KEY_ALL_ACCESS, &ObjectAttributes, 0, NULL, - 0, + REG_OPTION_NON_VOLATILE, &Disposition); if (!NT_SUCCESS(Status)) { @@ -1109,31 +1329,11 @@ RegInitializeRegistry( RootKeys[GetPredefKeyIndex(HKEY_CLASSES_ROOT)].Handle = KeyHandle; -#if 0 - /* Create SAM key */ - ConnectRegistry(NULL, - &SamHive, - // SystemSecurity, sizeof(SystemSecurity), - L"\\Registry\\Machine\\USetup_SAM"); - - /* Create SECURITY key */ - ConnectRegistry(NULL, - &SecurityHive, - // NULL, 0, - L"\\Registry\\Machine\\USetup_SECURITY"); - - /* Create BCD key */ - ConnectRegistry(NULL, - &BcdHive, - // BcdSecurity, sizeof(BcdSecurity), - L"\\Registry\\Machine\\USetup_BCD00000000"); -#endif - Status = STATUS_SUCCESS; /* Create the 'HKLM\SYSTEM\ControlSet001' key */ - // L"\\Registry\\Machine\\SYSTEM\\USetup_Machine\\SYSTEM\\ControlSet001" + // REGISTRY_SETUP_MACHINE L"SYSTEM\\ControlSet001" RtlInitUnicodeString(&KeyName, L"SYSTEM\\ControlSet001"); InitializeObjectAttributes(&ObjectAttributes, &KeyName, @@ -1163,12 +1363,15 @@ RegInitializeRegistry( /* Create the 'HKLM\SYSTEM\CurrentControlSet' symlink */ if (!CmpLinkKeyToHive(RootKeys[GetPredefKeyIndex(HKEY_LOCAL_MACHINE)].Handle, L"SYSTEM\\CurrentControlSet", - L"\\Registry\\Machine\\SYSTEM\\USetup_Machine\\SYSTEM\\ControlSet001")) + REGISTRY_SETUP_MACHINE L"SYSTEM\\ControlSet001")) { DPRINT1("CmpLinkKeyToHive(CurrentControlSet) failed!\n"); } + Status = STATUS_SUCCESS; + + Quit: /* Remove restore and backup privileges */ RtlAdjustPrivilege(SE_BACKUP_PRIVILEGE, PrivilegeSet[1], FALSE, &PrivilegeSet[1]); @@ -1178,18 +1381,22 @@ Quit: } VOID -RegCleanupRegistry(VOID) +RegCleanupRegistry( + IN PUNICODE_STRING InstallPath) { NTSTATUS Status; UNICODE_STRING KeyName; OBJECT_ATTRIBUTES KeyObjectAttributes; BOOLEAN PrivilegeSet[2] = {FALSE, FALSE}; - UCHAR i; + UINT i; + WCHAR SrcPath[MAX_PATH]; + WCHAR DstPath[MAX_PATH]; for (i = 0; i < ARRAYSIZE(RootKeys); ++i) { if (RootKeys[i].Handle) { + NtFlushKey(RootKeys[i].Handle); NtClose(RootKeys[i].Handle); RootKeys[i].Handle = NULL; } @@ -1220,25 +1427,38 @@ RegCleanupRegistry(VOID) NULL, NULL); - RtlInitUnicodeString(&KeyName, L"\\Registry\\Machine\\USetup_SYSTEM"); - Status = NtUnloadKey(&KeyObjectAttributes); - - RtlInitUnicodeString(&KeyName, L"\\Registry\\Machine\\USetup_SOFTWARE"); - Status = NtUnloadKey(&KeyObjectAttributes); + for (i = 0; i < ARRAYSIZE(RegistryHives); ++i) + { + if (RegistryHives[i].State != Create && RegistryHives[i].State != Repair) + continue; - RtlInitUnicodeString(&KeyName, L"\\Registry\\User\\USetup_DEFAULT"); - Status = NtUnloadKey(&KeyObjectAttributes); + RtlInitUnicodeString(&KeyName, RegistryHives[i].HiveRegistryPath); + Status = NtUnloadKey(&KeyObjectAttributes); + DPRINT1("Unmounting '%S' %s\n", RegistryHives[i].HiveRegistryPath, NT_SUCCESS(Status) ? "succeeded" : "failed"); + } -#if 0 - RtlInitUnicodeString(&KeyName, L"\\Registry\\Machine\\USetup_SAM"); - Status = NtUnloadKey(&KeyObjectAttributes); + // + // RegBackupRegistry() + // + /* Now backup the hives into .sav files */ + for (i = 0; i < ARRAYSIZE(RegistryHives); ++i) + { + if (RegistryHives[i].State != Create && RegistryHives[i].State != Repair) + continue; - RtlInitUnicodeString(&KeyName, L"\\Registry\\Machine\\USetup_SECURITY"); - Status = NtUnloadKey(&KeyObjectAttributes); + CombinePaths(SrcPath, ARRAYSIZE(SrcPath), 3, + InstallPath->Buffer, L"System32\\config", RegistryHives[i].HiveName); + StringCchCopyW(DstPath, ARRAYSIZE(DstPath), SrcPath); + StringCchCatW(DstPath, ARRAYSIZE(DstPath), L".sav"); - RtlInitUnicodeString(&KeyName, L"\\Registry\\Machine\\USetup_BCD00000000"); - Status = NtUnloadKey(&KeyObjectAttributes); -#endif + DPRINT1("Copy hive: %S ==> %S\n", SrcPath, DstPath); + Status = SetupCopyFile(SrcPath, DstPath, FALSE); + if (!NT_SUCCESS(Status)) + { + DPRINT1("SetupCopyFile() failed (Status %lx)\n", Status); + // return Status; + } + } /* Remove restore and backup privileges */ RtlAdjustPrivilege(SE_BACKUP_PRIVILEGE, PrivilegeSet[1], FALSE, &PrivilegeSet[1]); diff --git a/base/setup/usetup/registry.h b/base/setup/usetup/registry.h index c97d897a78..cae50e8271 100644 --- a/base/setup/usetup/registry.h +++ b/base/setup/usetup/registry.h @@ -43,12 +43,18 @@ ImportRegistryFile( LCID LocaleId, BOOLEAN Delete); +NTSTATUS +VerifyRegistryHives( + IN PUNICODE_STRING InstallPath, + OUT PBOOLEAN ShouldUpdateRegistry); + NTSTATUS RegInitializeRegistry( IN PUNICODE_STRING InstallPath); VOID -RegCleanupRegistry(VOID); +RegCleanupRegistry( + IN PUNICODE_STRING InstallPath); VOID SetDefaultPagefile( diff --git a/base/setup/usetup/usetup.c b/base/setup/usetup/usetup.c index 4eb2558fdf..9318f7e250 100644 --- a/base/setup/usetup/usetup.c +++ b/base/setup/usetup/usetup.c @@ -551,6 +551,7 @@ CheckUnattendedSetup(VOID) wcscpy(UnattendInstallationDirectory, Value); IsUnattendedSetup = TRUE; + DPRINT("Running unattended setup\n"); /* Search for 'MBRInstallType' in the 'Unattend' section */ if (SetupFindFirstLineW(UnattendInf, L"Unattend", L"MBRInstallType", &Context)) @@ -589,8 +590,6 @@ CheckUnattendedSetup(VOID) } SetupCloseInfFile(UnattendInf); - - DPRINT("Running unattended setup\n"); } @@ -1503,7 +1502,7 @@ IsDiskSizeValid(PPARTENTRY PartEntry) if (size < RequiredPartitionDiskSpace) { - /* partition is too small so ask for another partition */ + /* Partition is too small so ask for another one */ DPRINT1("Partition is too small (size: %I64u MB), required disk space is %lu MB\n", size, RequiredPartitionDiskSpace); return FALSE; } @@ -3291,6 +3290,22 @@ InstallDirectoryPage(PINPUT_RECORD Ir) DiskEntry = PartitionList->CurrentDisk; PartEntry = PartitionList->CurrentPartition; +#if 0 + if (RepairUpdateFlag) + { + if (!IsValidPath(CurrentInstallation->PathComponent)) // SystemNtPath + { + /* FIXME: Log the error? */ + return QUIT_PAGE; + } + + BuildInstallPaths(CurrentInstallation->PathComponent, // SystemNtPath + DiskEntry, + PartEntry); + + return PREPARE_COPY_PAGE; + } +#endif if (IsUnattendedSetup) { if (!IsValidPath(UnattendInstallationDirectory)) @@ -4057,20 +4072,34 @@ FileCopyPage(PINPUT_RECORD Ir) static PAGE_NUMBER RegistryPage(PINPUT_RECORD Ir) { + NTSTATUS Status; INFCONTEXT InfContext; PWSTR Action; PWSTR File; PWSTR Section; BOOLEAN Delete; - NTSTATUS Status; MUIDisplayPage(REGISTRY_PAGE); if (RepairUpdateFlag) { - // FIXME! - DPRINT1("FIXME: Updating / repairing the registry is NOT implemented yet!\n"); - return SUCCESS_PAGE; + BOOLEAN ShouldUpdateRegistry = FALSE; + + DPRINT1("TODO: Updating / repairing the registry is not completely implemented yet!\n"); + + /* Verify the registry hives and check whether we need to update or repair any of them */ + Status = VerifyRegistryHives(&DestinationPath, &ShouldUpdateRegistry); + if (!NT_SUCCESS(Status)) + { + DPRINT1("VerifyRegistryHives failed, Status 0x%08lx\n", Status); + ShouldUpdateRegistry = FALSE; + } + if (!ShouldUpdateRegistry) + { + DPRINT1("No need to update the registry\n"); + // return SUCCESS_PAGE; + goto Quit; + } } /* Initialize the registry and setup the default installation hives */ @@ -4087,7 +4116,7 @@ RegistryPage(PINPUT_RECORD Ir) else /*************************************/ { - /* Something else (correct) failed */ + /* Something else failed */ MUIDisplayError(ERROR_CREATE_HIVE, Ir, POPUP_WAIT_ENTER); } return QUIT_PAGE; @@ -4099,9 +4128,8 @@ RegistryPage(PINPUT_RECORD Ir) if (!SetupFindFirstLineW(SetupInf, L"HiveInfs.Install", NULL, &InfContext)) { DPRINT1("SetupFindFirstLine() failed\n"); - RegCleanupRegistry(); MUIDisplayError(ERROR_FIND_REGISTRY, Ir, POPUP_WAIT_ENTER); - return QUIT_PAGE; + goto Cleanup; } do @@ -4116,27 +4144,19 @@ RegistryPage(PINPUT_RECORD Ir) break; // Hackfix if (!_wcsicmp(Action, L"AddReg")) - { Delete = FALSE; - } else if (!_wcsicmp(Action, L"DelReg")) - { Delete = TRUE; - } else - { continue; - } CONSOLE_SetStatusText(MUIGetString(STRING_IMPORTFILE), File); if (!ImportRegistryFile(File, Section, LanguageId, Delete)) { DPRINT1("Importing %S failed\n", File); - - RegCleanupRegistry(); MUIDisplayError(ERROR_IMPORT_HIVE, Ir, POPUP_WAIT_ENTER); - return QUIT_PAGE; + goto Cleanup; } } while (SetupFindNextLine(&InfContext, &InfContext)); @@ -4144,35 +4164,31 @@ RegistryPage(PINPUT_RECORD Ir) CONSOLE_SetStatusText(MUIGetString(STRING_DISPLAYETTINGSUPDATE)); if (!ProcessDisplayRegistry(SetupInf, DisplayList)) { - RegCleanupRegistry(); MUIDisplayError(ERROR_UPDATE_DISPLAY_SETTINGS, Ir, POPUP_WAIT_ENTER); - return QUIT_PAGE; + goto Cleanup; } /* Set the locale */ CONSOLE_SetStatusText(MUIGetString(STRING_LOCALESETTINGSUPDATE)); if (!ProcessLocaleRegistry(LanguageList)) { - RegCleanupRegistry(); MUIDisplayError(ERROR_UPDATE_LOCALESETTINGS, Ir, POPUP_WAIT_ENTER); - return QUIT_PAGE; + goto Cleanup; } /* Add keyboard layouts */ CONSOLE_SetStatusText(MUIGetString(STRING_ADDKBLAYOUTS)); if (!AddKeyboardLayouts()) { - RegCleanupRegistry(); MUIDisplayError(ERROR_ADDING_KBLAYOUTS, Ir, POPUP_WAIT_ENTER); - return QUIT_PAGE; + goto Cleanup; } /* Set GeoID */ if (!SetGeoID(MUIGetGeoID())) { - RegCleanupRegistry(); MUIDisplayError(ERROR_UPDATE_GEOID, Ir, POPUP_WAIT_ENTER); - return QUIT_PAGE; + goto Cleanup; } if (!IsUnattendedSetup) @@ -4181,9 +4197,8 @@ RegistryPage(PINPUT_RECORD Ir) CONSOLE_SetStatusText(MUIGetString(STRING_KEYBOARDSETTINGSUPDATE)); if (!ProcessKeyboardLayoutRegistry(LayoutList)) { - RegCleanupRegistry(); MUIDisplayError(ERROR_UPDATE_KBSETTINGS, Ir, POPUP_WAIT_ENTER); - return QUIT_PAGE; + goto Cleanup; } } @@ -4191,26 +4206,34 @@ RegistryPage(PINPUT_RECORD Ir) CONSOLE_SetStatusText(MUIGetString(STRING_CODEPAGEINFOUPDATE)); if (!AddCodePage()) { - RegCleanupRegistry(); MUIDisplayError(ERROR_ADDING_CODEPAGE, Ir, POPUP_WAIT_ENTER); - return QUIT_PAGE; + goto Cleanup; } /* Set the default pagefile entry */ SetDefaultPagefile(DestinationDriveLetter); /* Update the mounted devices list */ + // FIXME: This should technically be done by mountmgr (if AutoMount is enabled)! SetMountedDeviceValues(PartitionList); +Cleanup: // // TODO: Unload all the registry stuff, perform cleanup, - // and copy the created hive files into .sav ones. + // and copy the created hive files into .sav files. // - RegCleanupRegistry(); + RegCleanupRegistry(&DestinationPath); - CONSOLE_SetStatusText(MUIGetString(STRING_DONE)); - - return BOOT_LOADER_PAGE; +Quit: + if (NT_SUCCESS(Status)) + { + CONSOLE_SetStatusText(MUIGetString(STRING_DONE)); + return BOOT_LOADER_PAGE; + } + else + { + return QUIT_PAGE; + } }
6 years, 2 months
1
0
0
0
04/08: [USETUP] Introduce SetupDeleteFile() and SetupMoveFile() (in addition to the already-existing SetupCopyFile()) in order to implement moving / renaming existing files.
by Hermès Bélusca-Maïto
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=55d8a8490c5cb795fa130…
commit 55d8a8490c5cb795fa1308c291485d31f8b53608 Author: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org> AuthorDate: Sun Jun 11 23:58:43 2017 +0000 Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org> CommitDate: Thu Oct 25 00:58:22 2018 +0200 [USETUP] Introduce SetupDeleteFile() and SetupMoveFile() (in addition to the already-existing SetupCopyFile()) in order to implement moving / renaming existing files. Will be used soon to make backups of system files, like the registry hive files just freshly created. - Make the SetupCopyFile() function closer to its win32 counterpart. - Adjust the code that calls SetupCopyFile(). svn path=/branches/setup_improvements/; revision=75008 svn path=/branches/setup_improvements/; revision=75009 --- base/setup/usetup/bootsup.c | 6 +- base/setup/usetup/filequeue.c | 2 +- base/setup/usetup/filesup.c | 240 +++++++++++++++++++++++++++++++++++++++--- base/setup/usetup/filesup.h | 31 +++++- 4 files changed, 257 insertions(+), 22 deletions(-) diff --git a/base/setup/usetup/bootsup.c b/base/setup/usetup/bootsup.c index 7fd723c33a..b6d4220dc0 100644 --- a/base/setup/usetup/bootsup.c +++ b/base/setup/usetup/bootsup.c @@ -1788,7 +1788,7 @@ InstallFatBootcodeToPartition( CombinePaths(DstPath, ARRAYSIZE(DstPath), 2, SystemRootPath->Buffer, L"freeldr.sys"); DPRINT("Copy: %S ==> %S\n", SrcPath, DstPath); - Status = SetupCopyFile(SrcPath, DstPath); + Status = SetupCopyFile(SrcPath, DstPath, FALSE); if (!NT_SUCCESS(Status)) { DPRINT1("SetupCopyFile() failed (Status %lx)\n", Status); @@ -2101,7 +2101,7 @@ InstallBtrfsBootcodeToPartition( CombinePaths(DstPath, ARRAYSIZE(DstPath), 2, SystemRootPath->Buffer, L"freeldr.sys"); DPRINT("Copy: %S ==> %S\n", SrcPath, DstPath); - Status = SetupCopyFile(SrcPath, DstPath); + Status = SetupCopyFile(SrcPath, DstPath, FALSE); if (!NT_SUCCESS(Status)) { DPRINT1("SetupCopyFile() failed (Status %lx)\n", Status); @@ -2266,7 +2266,7 @@ InstallFatBootcodeToFloppy( CombinePaths(DstPath, ARRAYSIZE(DstPath), 2, FloppyDevice.Buffer, L"freeldr.sys"); DPRINT("Copy: %S ==> %S\n", SrcPath, DstPath); - Status = SetupCopyFile(SrcPath, DstPath); + Status = SetupCopyFile(SrcPath, DstPath, FALSE); if (!NT_SUCCESS(Status)) { DPRINT1("SetupCopyFile() failed (Status %lx)\n", Status); diff --git a/base/setup/usetup/filequeue.c b/base/setup/usetup/filequeue.c index f672e2b23e..6067fca07e 100644 --- a/base/setup/usetup/filequeue.c +++ b/base/setup/usetup/filequeue.c @@ -427,7 +427,7 @@ SetupCommitFileQueueW( else { /* Copy the file */ - Status = SetupCopyFile(FileSrcPath, FileDstPath); + Status = SetupCopyFile(FileSrcPath, FileDstPath, FALSE); } if (!NT_SUCCESS(Status)) diff --git a/base/setup/usetup/filesup.c b/base/setup/usetup/filesup.c index e0bd0b110e..06d9d86344 100644 --- a/base/setup/usetup/filesup.c +++ b/base/setup/usetup/filesup.c @@ -142,27 +142,116 @@ done: return Status; } +NTSTATUS +SetupDeleteFile( + IN PCWSTR FileName, + IN BOOLEAN ForceDelete) // ForceDelete can be used to delete read-only files +{ + NTSTATUS Status; + UNICODE_STRING NtPathU; + OBJECT_ATTRIBUTES ObjectAttributes; + IO_STATUS_BLOCK IoStatusBlock; + HANDLE FileHandle; + FILE_DISPOSITION_INFORMATION FileDispInfo; + BOOLEAN RetryOnce = FALSE; + + /* Open the directory name that was passed in */ + RtlInitUnicodeString(&NtPathU, FileName); + InitializeObjectAttributes(&ObjectAttributes, + &NtPathU, + OBJ_CASE_INSENSITIVE, + NULL, + NULL); + +Retry: // We go back there once if RetryOnce == TRUE + Status = NtOpenFile(&FileHandle, + DELETE | FILE_READ_ATTRIBUTES | + (RetryOnce ? FILE_WRITE_ATTRIBUTES : 0), + &ObjectAttributes, + &IoStatusBlock, + FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, + FILE_NON_DIRECTORY_FILE | FILE_OPEN_FOR_BACKUP_INTENT); + if (!NT_SUCCESS(Status)) + { + DPRINT1("NtOpenFile failed with Status 0x%08lx\n", Status); + return Status; + } + + if (RetryOnce) + { + FILE_BASIC_INFORMATION FileInformation; + + Status = NtQueryInformationFile(FileHandle, + &IoStatusBlock, + &FileInformation, + sizeof(FILE_BASIC_INFORMATION), + FileBasicInformation); + if (!NT_SUCCESS(Status)) + { + DPRINT1("NtQueryInformationFile failed with Status 0x%08lx\n", Status); + NtClose(FileHandle); + return Status; + } + + FileInformation.FileAttributes = FILE_ATTRIBUTE_NORMAL; + Status = NtSetInformationFile(FileHandle, + &IoStatusBlock, + &FileInformation, + sizeof(FILE_BASIC_INFORMATION), + FileBasicInformation); + NtClose(FileHandle); + if (!NT_SUCCESS(Status)) + { + DPRINT1("NtSetInformationFile failed with Status 0x%08lx\n", Status); + return Status; + } + } + + /* Ask for the file to be deleted */ + FileDispInfo.DeleteFile = TRUE; + Status = NtSetInformationFile(FileHandle, + &IoStatusBlock, + &FileDispInfo, + sizeof(FILE_DISPOSITION_INFORMATION), + FileDispositionInformation); + NtClose(FileHandle); + + if (!NT_SUCCESS(Status)) + DPRINT1("Deletion of file '%S' failed, Status 0x%08lx\n", FileName, Status); + + // FIXME: Check the precise value of Status! + if (!NT_SUCCESS(Status) && ForceDelete && !RetryOnce) + { + /* Retry once */ + RetryOnce = TRUE; + goto Retry; + } + + /* Return result to the caller */ + return Status; +} + NTSTATUS SetupCopyFile( - PWCHAR SourceFileName, - PWCHAR DestinationFileName) + IN PCWSTR SourceFileName, + IN PCWSTR DestinationFileName, + IN BOOLEAN FailIfExists) { + NTSTATUS Status; + UNICODE_STRING FileName; OBJECT_ATTRIBUTES ObjectAttributes; HANDLE FileHandleSource; HANDLE FileHandleDest; - static IO_STATUS_BLOCK IoStatusBlock; + IO_STATUS_BLOCK IoStatusBlock; FILE_STANDARD_INFORMATION FileStandard; FILE_BASIC_INFORMATION FileBasic; ULONG RegionSize; - UNICODE_STRING FileName; - NTSTATUS Status; - PVOID SourceFileMap = 0; HANDLE SourceFileSection; + PVOID SourceFileMap = NULL; SIZE_T SourceSectionSize = 0; LARGE_INTEGER ByteOffset; - RtlInitUnicodeString(&FileName, - SourceFileName); + RtlInitUnicodeString(&FileName, SourceFileName); InitializeObjectAttributes(&ObjectAttributes, &FileName, @@ -194,7 +283,8 @@ SetupCopyFile( } Status = NtQueryInformationFile(FileHandleSource, - &IoStatusBlock,&FileBasic, + &IoStatusBlock, + &FileBasic, sizeof(FILE_BASIC_INFORMATION), FileBasicInformation); if (!NT_SUCCESS(Status)) @@ -225,15 +315,14 @@ SetupCopyFile( &SourceSectionSize, ViewUnmap, 0, - PAGE_READONLY ); + PAGE_READONLY); if (!NT_SUCCESS(Status)) { DPRINT1("NtMapViewOfSection failed: %x, %S\n", Status, SourceFileName); goto closesrcsec; } - RtlInitUnicodeString(&FileName, - DestinationFileName); + RtlInitUnicodeString(&FileName, DestinationFileName); InitializeObjectAttributes(&ObjectAttributes, &FileName, @@ -246,9 +335,9 @@ SetupCopyFile( &ObjectAttributes, &IoStatusBlock, NULL, - FILE_ATTRIBUTE_NORMAL, + FileBasic.FileAttributes, // FILE_ATTRIBUTE_NORMAL, 0, - FILE_OVERWRITE_IF, + FailIfExists ? FILE_CREATE : FILE_OVERWRITE_IF, FILE_NO_INTERMEDIATE_BUFFERING | FILE_SEQUENTIAL_ONLY | FILE_SYNCHRONOUS_IO_NONALERT, @@ -335,7 +424,8 @@ SetupCopyFile( NULL); if (!NT_SUCCESS(Status)) { - DPRINT1("NtWriteFile failed: %x:%x, iosb: %p src: %p, size: %x\n", Status, IoStatusBlock.Status, &IoStatusBlock, SourceFileMap, RegionSize); + DPRINT1("NtWriteFile failed: %x:%x, iosb: %p src: %p, size: %x\n", + Status, IoStatusBlock.Status, &IoStatusBlock, SourceFileMap, RegionSize); goto closedest; } @@ -351,7 +441,7 @@ SetupCopyFile( goto closedest; } - /* shorten the file back to it's real size after completing the write */ + /* Shorten the file back to its real size after completing the write */ Status = NtSetInformationFile(FileHandleDest, &IoStatusBlock, &FileStandard.EndOfFile, @@ -378,6 +468,124 @@ done: return Status; } +/* + * Synchronized with its kernel32 counterpart, but we don't manage reparse points here. + */ +NTSTATUS +SetupMoveFile( + IN PCWSTR ExistingFileName, + IN PCWSTR NewFileName, + IN ULONG Flags) +{ + NTSTATUS Status; + IO_STATUS_BLOCK IoStatusBlock; + OBJECT_ATTRIBUTES ObjectAttributes; + PFILE_RENAME_INFORMATION RenameInfo; + UNICODE_STRING NewPathU, ExistingPathU; + HANDLE SourceHandle = NULL; + BOOLEAN ReplaceIfExists; + + RtlInitUnicodeString(&ExistingPathU, ExistingFileName); + RtlInitUnicodeString(&NewPathU, NewFileName); + + _SEH2_TRY + { + ReplaceIfExists = !!(Flags & MOVEFILE_REPLACE_EXISTING); + + /* Unless we manage a proper opening, we'll attempt to reopen without reparse support */ + InitializeObjectAttributes(&ObjectAttributes, + &ExistingPathU, + OBJ_CASE_INSENSITIVE, + NULL, + NULL); + /* Attempt to open source file */ + Status = NtOpenFile(&SourceHandle, + FILE_READ_ATTRIBUTES | DELETE | SYNCHRONIZE, + &ObjectAttributes, + &IoStatusBlock, + FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, + FILE_OPEN_FOR_BACKUP_INTENT | ((Flags & MOVEFILE_WRITE_THROUGH) ? FILE_WRITE_THROUGH : 0)); + if (!NT_SUCCESS(Status)) + { + if (Status != STATUS_INVALID_PARAMETER) + { + _SEH2_LEAVE; + } + } + + /* At that point, we MUST have a source handle */ + ASSERT(SourceHandle); + + /* Allocate renaming buffer and fill it */ + RenameInfo = RtlAllocateHeap(RtlGetProcessHeap(), 0, NewPathU.Length + sizeof(FILE_RENAME_INFORMATION)); + if (RenameInfo == NULL) + { + Status = STATUS_NO_MEMORY; + _SEH2_LEAVE; + } + + RtlCopyMemory(&RenameInfo->FileName, NewPathU.Buffer, NewPathU.Length); + RenameInfo->ReplaceIfExists = ReplaceIfExists; + RenameInfo->RootDirectory = NULL; + RenameInfo->FileNameLength = NewPathU.Length; + + /* Attempt to rename the file */ + Status = NtSetInformationFile(SourceHandle, + &IoStatusBlock, + RenameInfo, + NewPathU.Length + sizeof(FILE_RENAME_INFORMATION), + FileRenameInformation); + RtlFreeHeap(RtlGetProcessHeap(), 0, RenameInfo); + if (NT_SUCCESS(Status)) + { + /* If it succeeded, all fine, quit */ + _SEH2_LEAVE; + } + /* + * If we failed for any other reason than not the same device, fail. + * If we failed because of different devices, only allow renaming + * if user allowed copy. + */ + if (Status != STATUS_NOT_SAME_DEVICE || !(Flags & MOVEFILE_COPY_ALLOWED)) + { + /* ReactOS hack! To be removed once all FSD have proper renaming support + * Just leave status to error and leave + */ + if (Status == STATUS_NOT_IMPLEMENTED) + { + DPRINT1("Forcing copy, renaming not supported by FSD\n"); + } + else + { + _SEH2_LEAVE; + } + } + + /* Close the source file */ + NtClose(SourceHandle); + SourceHandle = NULL; + + /* Perform the file copy */ + Status = SetupCopyFile(ExistingFileName, + NewFileName, + !ReplaceIfExists); + + /* If it succeeded, delete the source file */ + if (NT_SUCCESS(Status)) + { + /* Force-delete files even if read-only */ + SetupDeleteFile(ExistingFileName, TRUE); + } + } + _SEH2_FINALLY + { + if (SourceHandle) + NtClose(SourceHandle); + } + _SEH2_END; + + return Status; +} NTSTATUS SetupExtractFile( diff --git a/base/setup/usetup/filesup.h b/base/setup/usetup/filesup.h index 5c2c296ecf..a8cc7940a7 100644 --- a/base/setup/usetup/filesup.h +++ b/base/setup/usetup/filesup.h @@ -12,10 +12,37 @@ NTSTATUS SetupCreateDirectory( PWCHAR DirectoryName); +NTSTATUS +SetupDeleteFile( + IN PCWSTR FileName, + IN BOOLEAN ForceDelete); // ForceDelete can be used to delete read-only files + NTSTATUS SetupCopyFile( - PWCHAR SourceFileName, - PWCHAR DestinationFileName); + IN PCWSTR SourceFileName, + IN PCWSTR DestinationFileName, + IN BOOLEAN FailIfExists); + +#ifndef _WINBASE_ + +#define MOVEFILE_REPLACE_EXISTING 1 +#define MOVEFILE_COPY_ALLOWED 2 +#define MOVEFILE_WRITE_THROUGH 8 + +#endif + +// ACHTUNG! HAXX FIXME!! +#define _SEH2_TRY +#define _SEH2_LEAVE goto __SEH2_FINALLY__label; +#define _SEH2_FINALLY __SEH2_FINALLY__label: +#define _SEH2_END + + +NTSTATUS +SetupMoveFile( + IN PCWSTR ExistingFileName, + IN PCWSTR NewFileName, + IN ULONG Flags); NTSTATUS SetupExtractFile(
6 years, 2 months
1
0
0
0
03/08: [USETUP] Explicitly use the REG_OPTION_(NON_)VOLATILE flags in NtCreateKey calls.
by Hermès Bélusca-Maïto
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=5a1af6ccd8ec136a181c9…
commit 5a1af6ccd8ec136a181c957b176139f8c42f73e3 Author: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org> AuthorDate: Sun Jun 11 23:47:11 2017 +0000 Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org> CommitDate: Thu Oct 25 00:58:21 2018 +0200 [USETUP] Explicitly use the REG_OPTION_(NON_)VOLATILE flags in NtCreateKey calls. svn path=/branches/setup_improvements/; revision=75007 --- base/setup/usetup/devinst.c | 4 ++-- base/setup/usetup/mui.c | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/base/setup/usetup/devinst.c b/base/setup/usetup/devinst.c index b1e4baf64f..bd9af3a357 100644 --- a/base/setup/usetup/devinst.c +++ b/base/setup/usetup/devinst.c @@ -98,7 +98,7 @@ InstallDriver( /* Create service key */ RtlInitUnicodeString(&StringU, Driver); InitializeObjectAttributes(&ObjectAttributes, &StringU, 0, hServices, NULL); - Status = NtCreateKey(&hService, KEY_SET_VALUE, &ObjectAttributes, 0, NULL, 0, &Disposition); + Status = NtCreateKey(&hService, KEY_SET_VALUE, &ObjectAttributes, 0, NULL, REG_OPTION_NON_VOLATILE, &Disposition); if (!NT_SUCCESS(Status)) { DPRINT1("NtCreateKey('%wZ') failed with status 0x%08x\n", &StringU, Status); @@ -342,7 +342,7 @@ EventThread(IN LPVOID lpParameter) } InitializeObjectAttributes(&ObjectAttributes, &ServicesU, OBJ_CASE_INSENSITIVE, NULL, NULL); - Status = NtCreateKey(&hServices, KEY_ALL_ACCESS, &ObjectAttributes, 0, NULL, 0, NULL); + Status = NtCreateKey(&hServices, KEY_ALL_ACCESS, &ObjectAttributes, 0, NULL, REG_OPTION_NON_VOLATILE, NULL); if (!NT_SUCCESS(Status)) { DPRINT1("NtCreateKey('%wZ') failed with status 0x%08lx\n", &ServicesU, Status); diff --git a/base/setup/usetup/mui.c b/base/setup/usetup/mui.c index a983f0f47a..93b2feaff6 100644 --- a/base/setup/usetup/mui.c +++ b/base/setup/usetup/mui.c @@ -309,7 +309,7 @@ AddHotkeySettings( &ObjectAttributes, 0, NULL, - 0, + REG_OPTION_NON_VOLATILE, &Disposition); if(!NT_SUCCESS(Status)) @@ -401,7 +401,7 @@ AddKbLayoutsToRegistry( &ObjectAttributes, 0, NULL, - 0, + REG_OPTION_NON_VOLATILE, &Disposition); if(NT_SUCCESS(Status)) @@ -433,7 +433,7 @@ AddKbLayoutsToRegistry( &ObjectAttributes, 0, NULL, - 0, + REG_OPTION_NON_VOLATILE, &Disposition); if (!NT_SUCCESS(Status)) @@ -454,7 +454,7 @@ AddKbLayoutsToRegistry( &ObjectAttributes, 0, NULL, - 0, + REG_OPTION_NON_VOLATILE, &Disposition); if(!NT_SUCCESS(Status))
6 years, 2 months
1
0
0
0
02/08: [USETUP] Implement offline ReactOS registry initialization in USetup (equivalent of mkhive, but using OS functionality).
by Hermès Bélusca-Maïto
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=bbb04c470adc222c672df…
commit bbb04c470adc222c672df7a3d06d0926fb0003e9 Author: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org> AuthorDate: Sat Jun 3 16:22:42 2017 +0000 Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org> CommitDate: Thu Oct 25 00:57:02 2018 +0200 [USETUP] Implement offline ReactOS registry initialization in USetup (equivalent of mkhive, but using OS functionality). The rationale is as follows. We now have the 1st-stage ReactOS setup running with its own registry SYSTEM hive, similarly to regular ROS running instances (livecd, regular installation...). The ReactOS-specific SetInstallPathValue() hack, introduced in a76689e9 (r3794) and 5f973ce0 (r3795), is removed. This hack told the kernel that, during the setup, it had to "switch" the used registry hives and instead use the ones of the ROS installation being prepared. This was really hackish because this means, mixing between registry settings used only for the setup running instance, that could use different registry settings than the ones that should be set for the ROS installation being actually performed. Also, note that in the case of a 1st-stage GUI setup, consisting in running the LiveCD + the GUI setup program, this situation would be untenable. Note also that for people willing to use the Setup*** functions exported by setupapi.dll to parse the registry INF files to initialize the registry of the ROS installation being prepared, this would be impossible either. Hence the need to have offline registry modification functionality. svn path=/branches/setup_improvements/; revision=74766 --- base/setup/usetup/mui.c | 39 ++- base/setup/usetup/registry.c | 697 ++++++++++++++++++++++++++++++++++++++++--- base/setup/usetup/registry.h | 19 +- base/setup/usetup/settings.c | 140 +++++---- base/setup/usetup/usetup.c | 56 ++-- 5 files changed, 816 insertions(+), 135 deletions(-) diff --git a/base/setup/usetup/mui.c b/base/setup/usetup/mui.c index 0ddbdfebbb..a983f0f47a 100644 --- a/base/setup/usetup/mui.c +++ b/base/setup/usetup/mui.c @@ -297,11 +297,11 @@ AddHotkeySettings( NTSTATUS Status; RtlInitUnicodeString(&KeyName, - L"\\Registry\\User\\.DEFAULT\\Keyboard Layout\\Toggle"); + L".DEFAULT\\Keyboard Layout\\Toggle"); InitializeObjectAttributes(&ObjectAttributes, &KeyName, OBJ_CASE_INSENSITIVE, - NULL, + GetRootKeyByPredefKey(HKEY_USERS, NULL), NULL); Status = NtCreateKey(&KeyHandle, @@ -384,17 +384,16 @@ AddKbLayoutsToRegistry( ULONG Disposition; ULONG uIndex = 0; ULONG uCount = 0; - WCHAR szKeyName[48] = L"\\Registry\\User\\.DEFAULT\\Keyboard Layout"; + WCHAR szKeyName[48] = L".DEFAULT\\Keyboard Layout"; WCHAR szValueName[3 + 1]; WCHAR szLangID[8 + 1]; // Open the keyboard layout key - RtlInitUnicodeString(&KeyName, - szKeyName); + RtlInitUnicodeString(&KeyName, szKeyName); InitializeObjectAttributes(&ObjectAttributes, &KeyName, OBJ_CASE_INSENSITIVE, - NULL, + GetRootKeyByPredefKey(HKEY_USERS, NULL), NULL); Status = NtCreateKey(&KeyHandle, @@ -416,7 +415,7 @@ AddKbLayoutsToRegistry( KeyName.MaximumLength = sizeof(szKeyName); Status = RtlAppendUnicodeToString(&KeyName, L"\\Preload"); - if(!NT_SUCCESS(Status)) + if (!NT_SUCCESS(Status)) { DPRINT1("RtlAppend failed! (%lx)\n", Status); DPRINT1("String is %wZ\n", &KeyName); @@ -426,7 +425,7 @@ AddKbLayoutsToRegistry( InitializeObjectAttributes(&ObjectAttributes, &KeyName, OBJ_CASE_INSENSITIVE, - NULL, + GetRootKeyByPredefKey(HKEY_USERS, NULL), NULL); Status = NtCreateKey(&KeyHandle, @@ -443,11 +442,11 @@ AddKbLayoutsToRegistry( return FALSE; } - RtlInitUnicodeString(&KeyName, L"\\Registry\\User\\.DEFAULT\\Keyboard Layout\\Substitutes"); + RtlInitUnicodeString(&KeyName, L".DEFAULT\\Keyboard Layout\\Substitutes"); InitializeObjectAttributes(&ObjectAttributes, &KeyName, OBJ_CASE_INSENSITIVE, - NULL, + GetRootKeyByPredefKey(HKEY_USERS, NULL), NULL); Status = NtCreateKey(&SubKeyHandle, @@ -577,15 +576,15 @@ AddCodepageToRegistry( // Open the nls codepage key RtlInitUnicodeString(&KeyName, - L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\NLS\\CodePage"); + L"SYSTEM\\CurrentControlSet\\Control\\NLS\\CodePage"); InitializeObjectAttributes(&ObjectAttributes, &KeyName, OBJ_CASE_INSENSITIVE, - NULL, + GetRootKeyByPredefKey(HKEY_LOCAL_MACHINE, NULL), NULL); - Status = NtOpenKey(&KeyHandle, - KEY_WRITE, - &ObjectAttributes); + Status = NtOpenKey(&KeyHandle, + KEY_WRITE, + &ObjectAttributes); if (!NT_SUCCESS(Status)) { DPRINT1("NtOpenKey() failed (Status %lx)\n", Status); @@ -656,15 +655,15 @@ AddFontsSettingsToRegistry( ULONG uIndex = 0; RtlInitUnicodeString(&KeyName, - L"\\Registry\\Machine\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\FontSubstitutes"); + L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\FontSubstitutes"); InitializeObjectAttributes(&ObjectAttributes, &KeyName, OBJ_CASE_INSENSITIVE, - NULL, + GetRootKeyByPredefKey(HKEY_LOCAL_MACHINE, NULL), NULL); - Status = NtOpenKey(&KeyHandle, - KEY_WRITE, - &ObjectAttributes); + Status = NtOpenKey(&KeyHandle, + KEY_WRITE, + &ObjectAttributes); if (!NT_SUCCESS(Status)) { DPRINT1("NtOpenKey() failed (Status %lx)\n", Status); diff --git a/base/setup/usetup/registry.c b/base/setup/usetup/registry.c index fc9b127358..7fda1c928c 100644 --- a/base/setup/usetup/registry.c +++ b/base/setup/usetup/registry.c @@ -59,41 +59,66 @@ /* FUNCTIONS ****************************************************************/ -static -BOOLEAN -GetRootKey( - PWCHAR Name) +typedef struct _ROOT_KEY { - if (!_wcsicmp (Name, L"HKCR")) - { - wcscpy (Name, L"\\Registry\\Machine\\SOFTWARE\\Classes\\"); - return TRUE; - } + PCWSTR Name; + PCWSTR MountPoint; + HANDLE Handle; +} ROOT_KEY, *PROOT_KEY; - if (!_wcsicmp (Name, L"HKCU")) - { - wcscpy (Name, L"\\Registry\\User\\.DEFAULT\\"); - return TRUE; - } +ROOT_KEY RootKeys[] = +{ + // L"\\Registry\\Machine\\SYSTEM\\USetup_Machine\\SOFTWARE\\Classes\\" + { L"HKCR", L"\\Registry\\Machine\\USetup_SOFTWARE\\Classes\\", NULL }, /* "\\Registry\\Machine\\SOFTWARE\\Classes\\" */ // HKEY_CLASSES_ROOT + { L"HKCU", L"\\Registry\\User\\USetup_DEFAULT\\" , NULL }, /* "\\Registry\\User\\.DEFAULT\\" */ // HKEY_CURRENT_USER + { L"HKLM", L"\\Registry\\Machine\\SYSTEM\\USetup_Machine\\" , NULL }, /* "\\Registry\\Machine\\" */ // HKEY_LOCAL_MACHINE + { L"HKU" , L"\\Registry\\Machine\\SYSTEM\\USetup_User\\" , NULL }, /* "\\Registry\\User\\" */ // HKEY_USERS +#if 0 + { L"HKR", NULL, NULL }, +#endif +}; - if (!_wcsicmp (Name, L"HKLM")) - { - wcscpy (Name, L"\\Registry\\Machine\\"); - return TRUE; - } +#define IsPredefKey(HKey) \ + (((ULONG_PTR)(HKey) & 0xF0000000) == 0x80000000) + +#define GetPredefKeyIndex(HKey) \ + ((ULONG_PTR)(HKey) & 0x0FFFFFFF) + +HANDLE +GetRootKeyByPredefKey( + IN HANDLE KeyHandle, + OUT PCWSTR* RootKeyMountPoint OPTIONAL) +{ + ULONG_PTR Index = GetPredefKeyIndex(KeyHandle); + + if (!IsPredefKey(KeyHandle)) + return NULL; + if (GetPredefKeyIndex(KeyHandle) >= ARRAYSIZE(RootKeys)) + return NULL; - if (!_wcsicmp (Name, L"HKU")) + if (RootKeyMountPoint) + *RootKeyMountPoint = RootKeys[Index].MountPoint; + return RootKeys[Index].Handle; +} + +HANDLE +GetRootKeyByName( + IN PCWSTR RootKeyName, + OUT PCWSTR* RootKeyMountPoint OPTIONAL) +{ + UCHAR i; + + for (i = 0; i < ARRAYSIZE(RootKeys); ++i) { - wcscpy (Name, L"\\Registry\\User\\"); - return TRUE; + if (!_wcsicmp(RootKeyName, RootKeys[i].Name)) + { + if (RootKeyMountPoint) + *RootKeyMountPoint = RootKeys[i].MountPoint; + return RootKeys[i].Handle; + } } -#if 0 - if (!_wcsicmp (Name, L"HKR")) - return FALSE; -#endif - - return FALSE; + return NULL; } @@ -481,11 +506,11 @@ registry_callback(HINF hInf, PCWSTR Section, BOOLEAN Delete) UNICODE_STRING Name, Value; PUNICODE_STRING ValuePtr; UINT Flags; - ULONG Length; WCHAR Buffer[MAX_INF_STRING_LENGTH]; INFCONTEXT Context; - HANDLE KeyHandle; + PCWSTR RootKeyName; + HANDLE RootKeyHandle, KeyHandle; BOOLEAN Ok; Ok = SetupFindFirstLineW(hInf, Section, NULL, &Context); @@ -497,15 +522,15 @@ registry_callback(HINF hInf, PCWSTR Section, BOOLEAN Delete) /* get root */ if (!SetupGetStringFieldW(&Context, 1, Buffer, sizeof(Buffer)/sizeof(WCHAR), NULL)) continue; - if (!GetRootKey (Buffer)) + RootKeyHandle = GetRootKeyByName(Buffer, &RootKeyName); + if (!RootKeyHandle) continue; /* get key */ - Length = wcslen(Buffer); - if (!SetupGetStringFieldW(&Context, 2, Buffer + Length, sizeof(Buffer)/sizeof(WCHAR) - Length, NULL)) + if (!SetupGetStringFieldW(&Context, 2, Buffer, sizeof(Buffer)/sizeof(WCHAR), NULL)) *Buffer = 0; - DPRINT("KeyName: <%S>\n", Buffer); + DPRINT("KeyName: <%S\\%S>\n", RootKeyName, Buffer); /* get flags */ if (!SetupGetIntField(&Context, 4, (PINT)&Flags)) @@ -517,7 +542,7 @@ registry_callback(HINF hInf, PCWSTR Section, BOOLEAN Delete) InitializeObjectAttributes(&ObjectAttributes, &Name, OBJ_CASE_INSENSITIVE, - NULL, + RootKeyHandle, NULL); if (Delete || (Flags & FLG_ADDREG_OVERWRITEONLY)) @@ -621,13 +646,611 @@ ImportRegistryFile( return TRUE; } +/* + * Should be called under privileges + */ +// static +NTSTATUS +CreateRegistryFile( + IN PUNICODE_STRING InstallPath, + IN PCWSTR RegistryKey, + IN HANDLE ProtoKeyHandle) +{ + NTSTATUS Status; + HANDLE FileHandle; + UNICODE_STRING FileName; + OBJECT_ATTRIBUTES ObjectAttributes; + IO_STATUS_BLOCK IoStatusBlock; + WCHAR PathBuffer[MAX_PATH]; + + /* Create the file */ + CombinePaths(PathBuffer, ARRAYSIZE(PathBuffer), 3, + InstallPath->Buffer, L"System32\\config", RegistryKey); + RtlInitUnicodeString(&FileName, PathBuffer); + InitializeObjectAttributes(&ObjectAttributes, + &FileName, + OBJ_CASE_INSENSITIVE, + NULL, // Could have been installpath, etc... + NULL); + + Status = NtCreateFile(&FileHandle, + FILE_GENERIC_WRITE, + &ObjectAttributes, + &IoStatusBlock, + NULL, + FILE_ATTRIBUTE_NORMAL, + 0, + FILE_OVERWRITE_IF, + FILE_SYNCHRONOUS_IO_NONALERT | FILE_NON_DIRECTORY_FILE, + NULL, + 0); + if (!NT_SUCCESS(Status)) + { + DPRINT1("NtCreateFile(%wZ) failed, Status 0x%08lx\n", &FileName, Status); + return Status; + } + + /* Save the selected hive into the file */ + Status = NtSaveKeyEx(ProtoKeyHandle, FileHandle, REG_LATEST_FORMAT); + if (!NT_SUCCESS(Status)) + { + DPRINT1("NtSaveKeyEx(%wZ) failed, Status 0x%08lx\n", &FileName, Status); + } + + /* Close the file and return */ + NtClose(FileHandle); + return Status; +} + +static BOOLEAN +CmpLinkKeyToHive( + IN HANDLE RootLinkKeyHandle OPTIONAL, + IN PCWSTR LinkKeyName, + IN PCWSTR TargetKeyName) +{ + static UNICODE_STRING CmSymbolicLinkValueName = + RTL_CONSTANT_STRING(L"SymbolicLinkValue"); + + NTSTATUS Status; + OBJECT_ATTRIBUTES ObjectAttributes; + UNICODE_STRING KeyName; + HANDLE TargetKeyHandle; + ULONG Disposition; + + /* Initialize the object attributes */ + RtlInitUnicodeString(&KeyName, LinkKeyName); + InitializeObjectAttributes(&ObjectAttributes, + &KeyName, + OBJ_CASE_INSENSITIVE, + RootLinkKeyHandle, + NULL); + + /* Create the link key */ + Status = NtCreateKey(&TargetKeyHandle, + KEY_SET_VALUE | KEY_CREATE_LINK, + &ObjectAttributes, + 0, + NULL, + REG_OPTION_VOLATILE | REG_OPTION_CREATE_LINK, + &Disposition); + if (!NT_SUCCESS(Status)) + { + DPRINT1("CmpLinkKeyToHive: couldn't create %S, Status = 0x%08lx\n", + LinkKeyName, Status); + return FALSE; + } + + /* Check if the new key was actually created */ + if (Disposition != REG_CREATED_NEW_KEY) + { + DPRINT1("CmpLinkKeyToHive: %S already exists!\n", LinkKeyName); + NtClose(TargetKeyHandle); + return FALSE; + } + + /* Set the target key name as link target */ + RtlInitUnicodeString(&KeyName, TargetKeyName); + Status = NtSetValueKey(TargetKeyHandle, + &CmSymbolicLinkValueName, + 0, + REG_LINK, + KeyName.Buffer, + KeyName.Length); + + /* Close the link key handle */ + NtClose(TargetKeyHandle); + + if (!NT_SUCCESS(Status)) + { + DPRINT1("CmpLinkKeyToHive: couldn't create symbolic link for %S, Status = 0x%08lx\n", + TargetKeyName, Status); + return FALSE; + } + + return TRUE; +} + +/* + * Should be called under privileges + */ +// static +NTSTATUS +ConnectRegistry( + IN HKEY RootKey OPTIONAL, + // IN HANDLE RootDirectory OPTIONAL, + IN PUNICODE_STRING InstallPath, + IN PCWSTR RegistryKey, + // IN PUCHAR Descriptor, + // IN ULONG DescriptorLength, + IN PCWSTR RegMountPoint) +{ + NTSTATUS Status; + UNICODE_STRING KeyName, FileName; + OBJECT_ATTRIBUTES KeyObjectAttributes; + OBJECT_ATTRIBUTES FileObjectAttributes; + WCHAR PathBuffer[MAX_PATH]; + + RtlInitUnicodeString(&KeyName, RegMountPoint); + InitializeObjectAttributes(&KeyObjectAttributes, + &KeyName, + OBJ_CASE_INSENSITIVE, + RootKey, + NULL); + + CombinePaths(PathBuffer, ARRAYSIZE(PathBuffer), 3, + InstallPath->Buffer, L"System32\\config", RegistryKey); + RtlInitUnicodeString(&FileName, PathBuffer); + InitializeObjectAttributes(&FileObjectAttributes, + &FileName, + OBJ_CASE_INSENSITIVE, + NULL, // RootDirectory, + NULL); + +#if 0 + IN PCMHIVE HiveToConnect; + /* + * Add security to the root key. + * NOTE: One can implement this using the lpSecurityAttributes + * parameter of RegCreateKeyExW. + */ + Status = CmiCreateSecurityKey(&HiveToConnect->Hive, + HiveToConnect->Hive.BaseBlock->RootCell, + Descriptor, DescriptorLength); + if (!NT_SUCCESS(Status)) + DPRINT1("Failed to add security for root key '%S'\n", Path); +#endif + + /* Mount the registry hive in the registry namespace */ + Status = NtLoadKey(&KeyObjectAttributes, &FileObjectAttributes); + + return Status; +} + +NTSTATUS +RegInitializeRegistry( + IN PUNICODE_STRING InstallPath) +{ + NTSTATUS Status; + HANDLE KeyHandle; + UNICODE_STRING KeyName; + OBJECT_ATTRIBUTES ObjectAttributes; + BOOLEAN PrivilegeSet[2] = {FALSE, FALSE}; + ULONG Disposition; + UINT i; + PCWSTR RegistryKeys[] = + { + L"SYSTEM", + L"SOFTWARE", + L"DEFAULT", // L".DEFAULT", + // L"SAM", + // L"SECURITY", + // L"BCD00000000", + }; + +#if 0 + /* Initialize the current session registry */ + Status = NtInitializeRegistry(CM_BOOT_FLAG_SETUP); + if (!NT_SUCCESS(Status)) + { + DPRINT1("NtInitializeRegistry() failed (Status %lx)\n", Status); + return Status; + } +#endif + + /* Acquire restore privilege */ + Status = RtlAdjustPrivilege(SE_RESTORE_PRIVILEGE, TRUE, FALSE, &PrivilegeSet[0]); + if (!NT_SUCCESS(Status)) + { + DPRINT1("RtlAdjustPrivilege(SE_RESTORE_PRIVILEGE) failed (Status 0x%08lx)\n", Status); + /* Exit prematurely here.... */ + return Status; + } + + /* Acquire backup privilege */ + Status = RtlAdjustPrivilege(SE_BACKUP_PRIVILEGE, TRUE, FALSE, &PrivilegeSet[1]); + if (!NT_SUCCESS(Status)) + { + DPRINT1("RtlAdjustPrivilege(SE_BACKUP_PRIVILEGE) failed (Status 0x%08lx)\n", Status); + RtlAdjustPrivilege(SE_RESTORE_PRIVILEGE, PrivilegeSet[0], FALSE, &PrivilegeSet[0]); + /* Exit prematurely here.... */ + return Status; + } + + /* + * Create the template proto-hive. + * + * Use a dummy root key name: + * - On 2k/XP/2k3, this is "$$$PROTO.HIV" + * - On Vista+, this is "CMI-CreateHive{guid}" + * See
https://github.com/libyal/winreg-kb/blob/master/documentation/Registry%20fi…
+ * for more information. + */ + RtlInitUnicodeString(&KeyName, + L"\\Registry\\Machine\\SYSTEM\\$$$PROTO.HIV"); + InitializeObjectAttributes(&ObjectAttributes, + &KeyName, + OBJ_CASE_INSENSITIVE, + NULL, + NULL); + Status = NtCreateKey(&KeyHandle, + KEY_ALL_ACCESS, + &ObjectAttributes, + 0, + NULL, + REG_OPTION_NON_VOLATILE, + NULL); + if (!NT_SUCCESS(Status)) + { + DPRINT1("NtCreateKey() failed to create the proto-hive (Status %lx)\n", Status); + goto Quit; + } + NtFlushKey(KeyHandle); + + for (i = 0; i < ARRAYSIZE(RegistryKeys); ++i) + { + Status = CreateRegistryFile(InstallPath, + RegistryKeys[i], + KeyHandle); + if (!NT_SUCCESS(Status)) + { + DPRINT1("CreateRegistryFile(%S) failed, Status 0x%08lx\n", RegistryKeys[i], Status); + /* Exit prematurely here.... */ + /* That is now done, clean everything up! */ + NtDeleteKey(KeyHandle); + NtClose(KeyHandle); + goto Quit; + } + } + + /* That is now done, clean everything up! */ + NtDeleteKey(KeyHandle); + NtClose(KeyHandle); + + + /* + * Prepare the installation roots. Since we cannot create real registry keys + * inside the master keys (\Registry, \Registry\Machine or \Registry\User), + * we need to perform some SymLink tricks instead. + */ + + /* Our offline HKLM '\Registry\Machine' is inside '\Registry\Machine\SYSTEM\USetup_Machine' */ + RtlInitUnicodeString(&KeyName, RootKeys[GetPredefKeyIndex(HKEY_LOCAL_MACHINE)].MountPoint); + InitializeObjectAttributes(&ObjectAttributes, + &KeyName, + OBJ_CASE_INSENSITIVE, + NULL, + NULL); + KeyHandle = NULL; + Status = NtCreateKey(&KeyHandle, + KEY_ALL_ACCESS, + &ObjectAttributes, + 0, + NULL, + REG_OPTION_VOLATILE, + &Disposition); + if (!NT_SUCCESS(Status)) + { + DPRINT1("NtCreateKey(%wZ) failed (Status 0x%08lx)\n", &KeyName, Status); + // return Status; + } + RootKeys[GetPredefKeyIndex(HKEY_LOCAL_MACHINE)].Handle = KeyHandle; + + /* Our offline HKU '\Registry\User' is inside '\Registry\Machine\SYSTEM\USetup_User' */ + RtlInitUnicodeString(&KeyName, RootKeys[GetPredefKeyIndex(HKEY_USERS)].MountPoint); + InitializeObjectAttributes(&ObjectAttributes, + &KeyName, + OBJ_CASE_INSENSITIVE, + NULL, + NULL); + KeyHandle = NULL; + Status = NtCreateKey(&KeyHandle, + KEY_ALL_ACCESS, + &ObjectAttributes, + 0, + NULL, + REG_OPTION_VOLATILE, + &Disposition); + if (!NT_SUCCESS(Status)) + { + DPRINT1("NtCreateKey(%wZ) failed (Status 0x%08lx)\n", &KeyName, Status); + // return Status; + } + RootKeys[GetPredefKeyIndex(HKEY_USERS)].Handle = KeyHandle; + + + + /* + * Now properly mount the offline hive files + */ + + /* Create SYSTEM key */ + Status = + ConnectRegistry(NULL, + InstallPath, + RegistryKeys[0], + // SystemSecurity, sizeof(SystemSecurity), + L"\\Registry\\Machine\\USetup_SYSTEM"); + if (!NT_SUCCESS(Status)) + { + DPRINT1("ConnectRegistry(SYSTEM) failed, Status 0x%08lx\n", Status); + } + + /* Create the 'HKLM\SYSTEM' symlink to this key */ + if (!CmpLinkKeyToHive(RootKeys[GetPredefKeyIndex(HKEY_LOCAL_MACHINE)].Handle, + L"SYSTEM", + L"\\Registry\\Machine\\USetup_SYSTEM")) + { + DPRINT1("CmpLinkKeyToHive(SYSTEM) failed!\n"); + } + + + /* Create SOFTWARE key */ + Status = + ConnectRegistry(NULL, + InstallPath, + RegistryKeys[1], + // SoftwareSecurity, sizeof(SoftwareSecurity), + L"\\Registry\\Machine\\USetup_SOFTWARE"); + if (!NT_SUCCESS(Status)) + { + DPRINT1("ConnectRegistry(SOFTWARE) failed, Status 0x%08lx\n", Status); + } + + /* Create the 'HKLM\Software' symlink to this key */ + if (!CmpLinkKeyToHive(RootKeys[GetPredefKeyIndex(HKEY_LOCAL_MACHINE)].Handle, + L"Software", + L"\\Registry\\Machine\\USetup_SOFTWARE")) + { + DPRINT1("CmpLinkKeyToHive(SOFTWARE) failed!\n"); + } + + + /* Create DEFAULT key */ + Status = + ConnectRegistry(NULL, + InstallPath, + RegistryKeys[2], + // SystemSecurity, sizeof(SystemSecurity), + L"\\Registry\\User\\USetup_DEFAULT"); + if (!NT_SUCCESS(Status)) + { + DPRINT1("ConnectRegistry(DEFAULT) failed, Status 0x%08lx\n", Status); + } + + /* Create the 'HKU\.DEFAULT' symlink to this key */ + if (!CmpLinkKeyToHive(RootKeys[GetPredefKeyIndex(HKEY_USERS)].Handle, + L".DEFAULT", + L"\\Registry\\User\\USetup_DEFAULT")) + { + DPRINT1("CmpLinkKeyToHive(DEFAULT) failed!\n"); + } + + /* HKCU is a handle to 'HKU\.DEFAULT' */ +#if 0 + RtlInitUnicodeString(&KeyName, L".DEFAULT"); + InitializeObjectAttributes(&ObjectAttributes, + &KeyName, + OBJ_CASE_INSENSITIVE, + RootKeys[GetPredefKeyIndex(HKEY_USERS)].Handle, + NULL); +#else + RtlInitUnicodeString(&KeyName, RootKeys[GetPredefKeyIndex(HKEY_CURRENT_USER)].MountPoint); + InitializeObjectAttributes(&ObjectAttributes, + &KeyName, + OBJ_CASE_INSENSITIVE, + NULL, + NULL); +#endif + KeyHandle = NULL; + Status = NtOpenKey(&KeyHandle, + KEY_ALL_ACCESS, + &ObjectAttributes); + if (!NT_SUCCESS(Status)) + { + DPRINT1("NtOpenKey(%wZ) failed (Status %lx)\n", &KeyName, Status); + } + RootKeys[GetPredefKeyIndex(HKEY_CURRENT_USER)].Handle = KeyHandle; + + + /* HKCR is a handle to 'HKLM\Software\Classes' */ +#if 0 + RtlInitUnicodeString(&KeyName, L"Software\\Classes"); + InitializeObjectAttributes(&ObjectAttributes, + &KeyName, + OBJ_CASE_INSENSITIVE, + RootKeys[GetPredefKeyIndex(HKEY_LOCAL_MACHINE)].Handle, + NULL); +#else + RtlInitUnicodeString(&KeyName, RootKeys[GetPredefKeyIndex(HKEY_CLASSES_ROOT)].MountPoint); + InitializeObjectAttributes(&ObjectAttributes, + &KeyName, + OBJ_CASE_INSENSITIVE, + NULL, + NULL); +#endif + KeyHandle = NULL; + Status = NtCreateKey(&KeyHandle, + KEY_ALL_ACCESS, + &ObjectAttributes, + 0, + NULL, + 0, + &Disposition); + if (!NT_SUCCESS(Status)) + { + DPRINT1("NtCreateKey(%wZ) failed (Status %lx)\n", &KeyName, Status); + } + else + { + DPRINT1("NtCreateKey() succeeded to %s the %wZ key (Status %lx)\n", + Disposition == REG_CREATED_NEW_KEY ? "create" : /* REG_OPENED_EXISTING_KEY */ "open", + &KeyName, Status); + } + RootKeys[GetPredefKeyIndex(HKEY_CLASSES_ROOT)].Handle = KeyHandle; + + +#if 0 + /* Create SAM key */ + ConnectRegistry(NULL, + &SamHive, + // SystemSecurity, sizeof(SystemSecurity), + L"\\Registry\\Machine\\USetup_SAM"); + + /* Create SECURITY key */ + ConnectRegistry(NULL, + &SecurityHive, + // NULL, 0, + L"\\Registry\\Machine\\USetup_SECURITY"); + + /* Create BCD key */ + ConnectRegistry(NULL, + &BcdHive, + // BcdSecurity, sizeof(BcdSecurity), + L"\\Registry\\Machine\\USetup_BCD00000000"); +#endif + + Status = STATUS_SUCCESS; + + + /* Create the 'HKLM\SYSTEM\ControlSet001' key */ + // L"\\Registry\\Machine\\SYSTEM\\USetup_Machine\\SYSTEM\\ControlSet001" + RtlInitUnicodeString(&KeyName, L"SYSTEM\\ControlSet001"); + InitializeObjectAttributes(&ObjectAttributes, + &KeyName, + OBJ_CASE_INSENSITIVE, + RootKeys[GetPredefKeyIndex(HKEY_LOCAL_MACHINE)].Handle, + NULL); + Status = NtCreateKey(&KeyHandle, + KEY_ALL_ACCESS, + &ObjectAttributes, + 0, + NULL, + REG_OPTION_NON_VOLATILE, + &Disposition); + if (!NT_SUCCESS(Status)) + { + DPRINT1("NtCreateKey() failed to create the ControlSet001 key (Status %lx)\n", Status); + // return Status; + } + else + { + DPRINT1("NtCreateKey() succeeded to %s the ControlSet001 key (Status %lx)\n", + Disposition == REG_CREATED_NEW_KEY ? "create" : /* REG_OPENED_EXISTING_KEY */ "open", + Status); + } + NtClose(KeyHandle); + + /* Create the 'HKLM\SYSTEM\CurrentControlSet' symlink */ + if (!CmpLinkKeyToHive(RootKeys[GetPredefKeyIndex(HKEY_LOCAL_MACHINE)].Handle, + L"SYSTEM\\CurrentControlSet", + L"\\Registry\\Machine\\SYSTEM\\USetup_Machine\\SYSTEM\\ControlSet001")) + { + DPRINT1("CmpLinkKeyToHive(CurrentControlSet) failed!\n"); + } + + +Quit: + /* Remove restore and backup privileges */ + RtlAdjustPrivilege(SE_BACKUP_PRIVILEGE, PrivilegeSet[1], FALSE, &PrivilegeSet[1]); + RtlAdjustPrivilege(SE_RESTORE_PRIVILEGE, PrivilegeSet[0], FALSE, &PrivilegeSet[0]); + + return Status; +} + +VOID +RegCleanupRegistry(VOID) +{ + NTSTATUS Status; + UNICODE_STRING KeyName; + OBJECT_ATTRIBUTES KeyObjectAttributes; + BOOLEAN PrivilegeSet[2] = {FALSE, FALSE}; + UCHAR i; + + for (i = 0; i < ARRAYSIZE(RootKeys); ++i) + { + if (RootKeys[i].Handle) + { + NtClose(RootKeys[i].Handle); + RootKeys[i].Handle = NULL; + } + } + + /* Acquire restore privilege */ + Status = RtlAdjustPrivilege(SE_RESTORE_PRIVILEGE, TRUE, FALSE, &PrivilegeSet[0]); + if (!NT_SUCCESS(Status)) + { + DPRINT1("RtlAdjustPrivilege(SE_RESTORE_PRIVILEGE) failed (Status 0x%08lx)\n", Status); + /* Exit prematurely here.... */ + return; + } + + /* Acquire backup privilege */ + Status = RtlAdjustPrivilege(SE_BACKUP_PRIVILEGE, TRUE, FALSE, &PrivilegeSet[1]); + if (!NT_SUCCESS(Status)) + { + DPRINT1("RtlAdjustPrivilege(SE_BACKUP_PRIVILEGE) failed (Status 0x%08lx)\n", Status); + RtlAdjustPrivilege(SE_RESTORE_PRIVILEGE, PrivilegeSet[0], FALSE, &PrivilegeSet[0]); + /* Exit prematurely here.... */ + return; + } + + InitializeObjectAttributes(&KeyObjectAttributes, + &KeyName, + OBJ_CASE_INSENSITIVE, + NULL, + NULL); + + RtlInitUnicodeString(&KeyName, L"\\Registry\\Machine\\USetup_SYSTEM"); + Status = NtUnloadKey(&KeyObjectAttributes); + + RtlInitUnicodeString(&KeyName, L"\\Registry\\Machine\\USetup_SOFTWARE"); + Status = NtUnloadKey(&KeyObjectAttributes); + + RtlInitUnicodeString(&KeyName, L"\\Registry\\User\\USetup_DEFAULT"); + Status = NtUnloadKey(&KeyObjectAttributes); + +#if 0 + RtlInitUnicodeString(&KeyName, L"\\Registry\\Machine\\USetup_SAM"); + Status = NtUnloadKey(&KeyObjectAttributes); + + RtlInitUnicodeString(&KeyName, L"\\Registry\\Machine\\USetup_SECURITY"); + Status = NtUnloadKey(&KeyObjectAttributes); + + RtlInitUnicodeString(&KeyName, L"\\Registry\\Machine\\USetup_BCD00000000"); + Status = NtUnloadKey(&KeyObjectAttributes); +#endif + + /* Remove restore and backup privileges */ + RtlAdjustPrivilege(SE_BACKUP_PRIVILEGE, PrivilegeSet[1], FALSE, &PrivilegeSet[1]); + RtlAdjustPrivilege(SE_RESTORE_PRIVILEGE, PrivilegeSet[0], FALSE, &PrivilegeSet[0]); +} VOID SetDefaultPagefile( WCHAR Drive) { OBJECT_ATTRIBUTES ObjectAttributes; - UNICODE_STRING KeyName = RTL_CONSTANT_STRING(L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Memory Management"); + UNICODE_STRING KeyName = RTL_CONSTANT_STRING(L"SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Memory Management"); UNICODE_STRING ValueName = RTL_CONSTANT_STRING(L"PagingFiles"); WCHAR ValueBuffer[] = L"?:\\pagefile.sys 0 0\0"; HANDLE KeyHandle; @@ -636,7 +1259,7 @@ SetDefaultPagefile( InitializeObjectAttributes(&ObjectAttributes, &KeyName, OBJ_CASE_INSENSITIVE, - NULL, + RootKeys[GetPredefKeyIndex(HKEY_LOCAL_MACHINE)].Handle, NULL); Status = NtOpenKey(&KeyHandle, KEY_ALL_ACCESS, diff --git a/base/setup/usetup/registry.h b/base/setup/usetup/registry.h index 5064bb97f3..c97d897a78 100644 --- a/base/setup/usetup/registry.h +++ b/base/setup/usetup/registry.h @@ -26,6 +26,16 @@ #pragma once +HANDLE +GetRootKeyByPredefKey( + IN HANDLE KeyHandle, + OUT PCWSTR* RootKeyMountPoint OPTIONAL); + +HANDLE +GetRootKeyByName( + IN PCWSTR RootKeyName, + OUT PCWSTR* RootKeyMountPoint OPTIONAL); + BOOLEAN ImportRegistryFile( PWSTR Filename, @@ -33,9 +43,12 @@ ImportRegistryFile( LCID LocaleId, BOOLEAN Delete); -BOOLEAN -SetInstallPathValue( - PUNICODE_STRING InstallPath); +NTSTATUS +RegInitializeRegistry( + IN PUNICODE_STRING InstallPath); + +VOID +RegCleanupRegistry(VOID); VOID SetDefaultPagefile( diff --git a/base/setup/usetup/settings.c b/base/setup/usetup/settings.c index a6dc2ed0fb..d358f85e39 100644 --- a/base/setup/usetup/settings.c +++ b/base/setup/usetup/settings.c @@ -214,7 +214,7 @@ GetComputerIdentifier( NULL); Status = NtOpenKey(&ProcessorsKey, - KEY_QUERY_VALUE , + KEY_QUERY_VALUE, &ObjectAttributes); if (!NT_SUCCESS(Status)) { @@ -676,14 +676,17 @@ ProcessDisplayRegistry( HINF InfFile, PGENERIC_LIST List) { + NTSTATUS Status; PGENERIC_LIST_ENTRY Entry; INFCONTEXT Context; + PWCHAR Buffer; PWCHAR ServiceName; ULONG StartValue; - NTSTATUS Status; - WCHAR RegPath [255]; - PWCHAR Buffer; ULONG Width, Height, Bpp; + OBJECT_ATTRIBUTES ObjectAttributes; + UNICODE_STRING KeyName; + HANDLE KeyHandle; + WCHAR RegPath[255]; DPRINT("ProcessDisplayRegistry() called\n"); @@ -700,7 +703,7 @@ ProcessDisplayRegistry( return FALSE; } - /* Enable the right driver */ + /* Enable the correct driver */ if (!INF_GetDataField(&Context, 3, &ServiceName)) { DPRINT1("INF_GetDataField() failed\n"); @@ -708,15 +711,31 @@ ProcessDisplayRegistry( } ASSERT(wcslen(ServiceName) < 10); - DPRINT("Service name: %S\n", ServiceName); + DPRINT1("Service name: '%S'\n", ServiceName); + + swprintf(RegPath, L"System\\CurrentControlSet\\Services\\%s", ServiceName); + RtlInitUnicodeString(&KeyName, RegPath); + InitializeObjectAttributes(&ObjectAttributes, + &KeyName, + OBJ_CASE_INSENSITIVE, + GetRootKeyByPredefKey(HKEY_LOCAL_MACHINE, NULL), + NULL); + Status = NtOpenKey(&KeyHandle, + KEY_SET_VALUE, + &ObjectAttributes); + if (!NT_SUCCESS(Status)) + { + DPRINT1("NtOpenKey() failed (Status %lx)\n", Status); + return FALSE; + } StartValue = 1; - Status = RtlWriteRegistryValue(RTL_REGISTRY_SERVICES, - ServiceName, + Status = RtlWriteRegistryValue(RTL_REGISTRY_HANDLE, KeyHandle, L"Start", REG_DWORD, &StartValue, - sizeof(ULONG)); + sizeof(StartValue)); + NtClose(KeyHandle); if (!NT_SUCCESS(Status)) { DPRINT1("RtlWriteRegistryValue() failed (Status %lx)\n", Status); @@ -724,7 +743,6 @@ ProcessDisplayRegistry( } /* Set the resolution */ - swprintf(RegPath, L"\\Registry\\Machine\\System\\CurrentControlSet\\Hardware Profiles\\Current\\System\\CurrentControlSet\\Services\\%s\\Device0", ServiceName); if (!INF_GetDataField(&Context, 4, &Buffer)) { @@ -732,57 +750,80 @@ ProcessDisplayRegistry( return FALSE; } + swprintf(RegPath, + L"System\\CurrentControlSet\\Hardware Profiles\\Current\\System\\CurrentControlSet\\Services\\%s\\Device0", + ServiceName); + DPRINT1("RegPath: '%S'\n", RegPath); + RtlInitUnicodeString(&KeyName, RegPath); + InitializeObjectAttributes(&ObjectAttributes, + &KeyName, + OBJ_CASE_INSENSITIVE, + GetRootKeyByPredefKey(HKEY_LOCAL_MACHINE, NULL), + NULL); + Status = NtOpenKey(&KeyHandle, + KEY_SET_VALUE, + &ObjectAttributes); + if (!NT_SUCCESS(Status)) + { + DPRINT1("NtOpenKey() failed (Status %lx)\n", Status); + return FALSE; + } + Width = wcstoul(Buffer, NULL, 10); - Status = RtlWriteRegistryValue(RTL_REGISTRY_ABSOLUTE, - RegPath, + Status = RtlWriteRegistryValue(RTL_REGISTRY_HANDLE, KeyHandle, L"DefaultSettings.XResolution", REG_DWORD, &Width, - sizeof(ULONG)); + sizeof(Width)); if (!NT_SUCCESS(Status)) { DPRINT1("RtlWriteRegistryValue() failed (Status %lx)\n", Status); + NtClose(KeyHandle); return FALSE; } if (!INF_GetDataField(&Context, 5, &Buffer)) { DPRINT1("INF_GetDataField() failed\n"); + NtClose(KeyHandle); return FALSE; } Height = wcstoul(Buffer, 0, 0); - Status = RtlWriteRegistryValue(RTL_REGISTRY_ABSOLUTE, - RegPath, + Status = RtlWriteRegistryValue(RTL_REGISTRY_HANDLE, KeyHandle, L"DefaultSettings.YResolution", REG_DWORD, &Height, - sizeof(ULONG)); + sizeof(Height)); if (!NT_SUCCESS(Status)) { DPRINT1("RtlWriteRegistryValue() failed (Status %lx)\n", Status); + NtClose(KeyHandle); return FALSE; } if (!INF_GetDataField(&Context, 6, &Buffer)) { DPRINT1("INF_GetDataField() failed\n"); + NtClose(KeyHandle); return FALSE; } Bpp = wcstoul(Buffer, 0, 0); - Status = RtlWriteRegistryValue(RTL_REGISTRY_ABSOLUTE, - RegPath, + Status = RtlWriteRegistryValue(RTL_REGISTRY_HANDLE, KeyHandle, L"DefaultSettings.BitsPerPel", REG_DWORD, &Bpp, - sizeof(ULONG)); + sizeof(Bpp)); if (!NT_SUCCESS(Status)) { DPRINT1("RtlWriteRegistryValue() failed (Status %lx)\n", Status); + NtClose(KeyHandle); return FALSE; } + NtClose(KeyHandle); + DPRINT("ProcessDisplayRegistry() done\n"); return TRUE; @@ -814,17 +855,17 @@ ProcessLocaleRegistry( /* Open the default users locale key */ RtlInitUnicodeString(&KeyName, - L"\\Registry\\User\\.DEFAULT\\Control Panel\\International"); + L".DEFAULT\\Control Panel\\International"); InitializeObjectAttributes(&ObjectAttributes, &KeyName, OBJ_CASE_INSENSITIVE, - NULL, + GetRootKeyByPredefKey(HKEY_USERS, NULL), NULL); - Status = NtOpenKey(&KeyHandle, - KEY_SET_VALUE, - &ObjectAttributes); + Status = NtOpenKey(&KeyHandle, + KEY_SET_VALUE, + &ObjectAttributes); if (!NT_SUCCESS(Status)) { DPRINT1("NtOpenKey() failed (Status %lx)\n", Status); @@ -832,8 +873,7 @@ ProcessLocaleRegistry( } /* Set default user locale */ - RtlInitUnicodeString(&ValueName, - L"Locale"); + RtlInitUnicodeString(&ValueName, L"Locale"); Status = NtSetValueKey(KeyHandle, &ValueName, 0, @@ -853,17 +893,17 @@ ProcessLocaleRegistry( /* Open the NLS language key */ RtlInitUnicodeString(&KeyName, - L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\NLS\\Language"); + L"SYSTEM\\CurrentControlSet\\Control\\NLS\\Language"); InitializeObjectAttributes(&ObjectAttributes, &KeyName, OBJ_CASE_INSENSITIVE, - NULL, + GetRootKeyByPredefKey(HKEY_LOCAL_MACHINE, NULL), NULL); - Status = NtOpenKey(&KeyHandle, - KEY_SET_VALUE, - &ObjectAttributes); + Status = NtOpenKey(&KeyHandle, + KEY_SET_VALUE, + &ObjectAttributes); if (!NT_SUCCESS(Status)) { DPRINT1("NtOpenKey() failed (Status %lx)\n", Status); @@ -871,8 +911,7 @@ ProcessLocaleRegistry( } /* Set default language */ - RtlInitUnicodeString(&ValueName, - L"Default"); + RtlInitUnicodeString(&ValueName, L"Default"); Status = NtSetValueKey(KeyHandle, &ValueName, 0, @@ -887,14 +926,13 @@ ProcessLocaleRegistry( } /* Set install language */ - RtlInitUnicodeString(&ValueName, - L"InstallLanguage"); - Status = NtSetValueKey (KeyHandle, - &ValueName, - 0, - REG_SZ, - (PVOID)LanguageId, - (wcslen(LanguageId) + 1) * sizeof(WCHAR)); + RtlInitUnicodeString(&ValueName, L"InstallLanguage"); + Status = NtSetValueKey(KeyHandle, + &ValueName, + 0, + REG_SZ, + (PVOID)LanguageId, + (wcslen(LanguageId) + 1) * sizeof(WCHAR)); NtClose(KeyHandle); if (!NT_SUCCESS(Status)) { @@ -1191,22 +1229,18 @@ BOOLEAN SetGeoID( PWCHAR Id) { + NTSTATUS Status; OBJECT_ATTRIBUTES ObjectAttributes; - UNICODE_STRING KeyName; - UNICODE_STRING ValueName; + UNICODE_STRING Name; HANDLE KeyHandle; - WCHAR szKeyName[] = L"\\Registry\\User\\.DEFAULT\\Control Panel\\International\\Geo"; - WCHAR szValueName[] = L"Nation"; - NTSTATUS Status; - RtlInitUnicodeString(&KeyName, - szKeyName); + RtlInitUnicodeString(&Name, + L".DEFAULT\\Control Panel\\International\\Geo"); InitializeObjectAttributes(&ObjectAttributes, - &KeyName, + &Name, OBJ_CASE_INSENSITIVE, - NULL, + GetRootKeyByPredefKey(HKEY_USERS, NULL), NULL); - Status = NtOpenKey(&KeyHandle, KEY_SET_VALUE, &ObjectAttributes); @@ -1216,9 +1250,9 @@ SetGeoID( return FALSE; } - RtlInitUnicodeString(&ValueName, szValueName); + RtlInitUnicodeString(&Name, L"Nation"); Status = NtSetValueKey(KeyHandle, - &ValueName, + &Name, 0, REG_SZ, (PVOID)Id, diff --git a/base/setup/usetup/usetup.c b/base/setup/usetup/usetup.c index 9170b23225..4eb2558fdf 100644 --- a/base/setup/usetup/usetup.c +++ b/base/setup/usetup/usetup.c @@ -816,9 +816,9 @@ SetupStartPage(PINPUT_RECORD Ir) MUIDisplayError(ERROR_NO_SOURCE_DRIVE, Ir, POPUP_WAIT_ENTER); return QUIT_PAGE; } - DPRINT1("SourcePath: '%wZ'", &SourcePath); - DPRINT1("SourceRootPath: '%wZ'", &SourceRootPath); - DPRINT1("SourceRootDir: '%wZ'", &SourceRootDir); + DPRINT1("SourcePath: '%wZ'\n", &SourcePath); + DPRINT1("SourceRootPath: '%wZ'\n", &SourceRootPath); + DPRINT1("SourceRootDir: '%wZ'\n", &SourceRootDir); /* Load txtsetup.sif from install media. */ CombinePaths(FileNameBuffer, ARRAYSIZE(FileNameBuffer), 2, SourcePath.Buffer, L"txtsetup.sif"); @@ -4046,8 +4046,7 @@ FileCopyPage(PINPUT_RECORD Ir) * QuitPage * * SIDEEFFECTS - * Calls SetInstallPathValue - * Calls NtInitializeRegistry + * Calls RegInitializeRegistry * Calls ImportRegistryFile * Calls SetDefaultPagefile * Calls SetMountedDeviceValues @@ -4074,21 +4073,23 @@ RegistryPage(PINPUT_RECORD Ir) return SUCCESS_PAGE; } - /************************ HACK!!!!!!!!!!! *********************************/ - if (!SetInstallPathValue(&DestinationPath)) - { - DPRINT1("SetInstallPathValue() failed\n"); - MUIDisplayError(ERROR_INITIALIZE_REGISTRY, Ir, POPUP_WAIT_ENTER); - return QUIT_PAGE; - } - /************************ HACK!!!!!!!!!!! *********************************/ - - /* Create the default hives */ - Status = NtInitializeRegistry(CM_BOOT_FLAG_SETUP); + /* Initialize the registry and setup the default installation hives */ + Status = RegInitializeRegistry(&DestinationPath); if (!NT_SUCCESS(Status)) { - DPRINT1("NtInitializeRegistry() failed (Status %lx)\n", Status); - MUIDisplayError(ERROR_CREATE_HIVE, Ir, POPUP_WAIT_ENTER); + DPRINT1("RegInitializeRegistry() failed\n"); + /********** HACK!!!!!!!!!!! **********/ + if (Status == STATUS_NOT_IMPLEMENTED) + { + /* The hack was called, display its corresponding error */ + MUIDisplayError(ERROR_INITIALIZE_REGISTRY, Ir, POPUP_WAIT_ENTER); + } + else + /*************************************/ + { + /* Something else (correct) failed */ + MUIDisplayError(ERROR_CREATE_HIVE, Ir, POPUP_WAIT_ENTER); + } return QUIT_PAGE; } @@ -4098,6 +4099,7 @@ RegistryPage(PINPUT_RECORD Ir) if (!SetupFindFirstLineW(SetupInf, L"HiveInfs.Install", NULL, &InfContext)) { DPRINT1("SetupFindFirstLine() failed\n"); + RegCleanupRegistry(); MUIDisplayError(ERROR_FIND_REGISTRY, Ir, POPUP_WAIT_ENTER); return QUIT_PAGE; } @@ -4132,6 +4134,7 @@ RegistryPage(PINPUT_RECORD Ir) { DPRINT1("Importing %S failed\n", File); + RegCleanupRegistry(); MUIDisplayError(ERROR_IMPORT_HIVE, Ir, POPUP_WAIT_ENTER); return QUIT_PAGE; } @@ -4141,6 +4144,7 @@ RegistryPage(PINPUT_RECORD Ir) CONSOLE_SetStatusText(MUIGetString(STRING_DISPLAYETTINGSUPDATE)); if (!ProcessDisplayRegistry(SetupInf, DisplayList)) { + RegCleanupRegistry(); MUIDisplayError(ERROR_UPDATE_DISPLAY_SETTINGS, Ir, POPUP_WAIT_ENTER); return QUIT_PAGE; } @@ -4149,6 +4153,7 @@ RegistryPage(PINPUT_RECORD Ir) CONSOLE_SetStatusText(MUIGetString(STRING_LOCALESETTINGSUPDATE)); if (!ProcessLocaleRegistry(LanguageList)) { + RegCleanupRegistry(); MUIDisplayError(ERROR_UPDATE_LOCALESETTINGS, Ir, POPUP_WAIT_ENTER); return QUIT_PAGE; } @@ -4157,6 +4162,7 @@ RegistryPage(PINPUT_RECORD Ir) CONSOLE_SetStatusText(MUIGetString(STRING_ADDKBLAYOUTS)); if (!AddKeyboardLayouts()) { + RegCleanupRegistry(); MUIDisplayError(ERROR_ADDING_KBLAYOUTS, Ir, POPUP_WAIT_ENTER); return QUIT_PAGE; } @@ -4164,6 +4170,7 @@ RegistryPage(PINPUT_RECORD Ir) /* Set GeoID */ if (!SetGeoID(MUIGetGeoID())) { + RegCleanupRegistry(); MUIDisplayError(ERROR_UPDATE_GEOID, Ir, POPUP_WAIT_ENTER); return QUIT_PAGE; } @@ -4174,6 +4181,7 @@ RegistryPage(PINPUT_RECORD Ir) CONSOLE_SetStatusText(MUIGetString(STRING_KEYBOARDSETTINGSUPDATE)); if (!ProcessKeyboardLayoutRegistry(LayoutList)) { + RegCleanupRegistry(); MUIDisplayError(ERROR_UPDATE_KBSETTINGS, Ir, POPUP_WAIT_ENTER); return QUIT_PAGE; } @@ -4183,6 +4191,7 @@ RegistryPage(PINPUT_RECORD Ir) CONSOLE_SetStatusText(MUIGetString(STRING_CODEPAGEINFOUPDATE)); if (!AddCodePage()) { + RegCleanupRegistry(); MUIDisplayError(ERROR_ADDING_CODEPAGE, Ir, POPUP_WAIT_ENTER); return QUIT_PAGE; } @@ -4193,6 +4202,12 @@ RegistryPage(PINPUT_RECORD Ir) /* Update the mounted devices list */ SetMountedDeviceValues(PartitionList); + // + // TODO: Unload all the registry stuff, perform cleanup, + // and copy the created hive files into .sav ones. + // + RegCleanupRegistry(); + CONSOLE_SetStatusText(MUIGetString(STRING_DONE)); return BOOT_LOADER_PAGE; @@ -4211,8 +4226,7 @@ RegistryPage(PINPUT_RECORD Ir) * QuitPage * * SIDEEFFECTS - * Calls SetInstallPathValue - * Calls NtInitializeRegistry + * Calls RegInitializeRegistry * Calls ImportRegistryFile * Calls SetDefaultPagefile * Calls SetMountedDeviceValues @@ -4865,12 +4879,10 @@ RunUSetup(VOID) InfSetHeap(ProcessHeap); -#if 0 /* Tell the Cm this is a setup boot, and it has to behave accordingly */ Status = NtInitializeRegistry(CM_BOOT_FLAG_SETUP); if (!NT_SUCCESS(Status)) DPRINT1("NtInitializeRegistry() failed (Status 0x%08lx)\n", Status); -#endif /* Create the PnP thread in suspended state */ Status = RtlCreateUserThread(NtCurrentProcess(),
6 years, 2 months
1
0
0
0
01/08: [USETUP] Code formatting, making also the code closer to mkhive's one. Also, definitely remove the SetInstallPathValue() hack.
by Hermès Bélusca-Maïto
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=cd89e5b797c9368272d32…
commit cd89e5b797c9368272d32f397eacacc0d474bbca Author: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org> AuthorDate: Sat Jun 3 15:20:09 2017 +0000 Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org> CommitDate: Thu Oct 25 00:51:43 2018 +0200 [USETUP] Code formatting, making also the code closer to mkhive's one. Also, definitely remove the SetInstallPathValue() hack. svn path=/branches/setup_improvements/; revision=74763 --- base/setup/usetup/registry.c | 356 +++++++++++++++++++------------------------ 1 file changed, 161 insertions(+), 195 deletions(-) diff --git a/base/setup/usetup/registry.c b/base/setup/usetup/registry.c index 2587741892..fc9b127358 100644 --- a/base/setup/usetup/registry.c +++ b/base/setup/usetup/registry.c @@ -102,6 +102,7 @@ GetRootKey( * * Append a multisz string to a multisz registry value. */ +// NOTE: Synced with setupapi/install.c ; see also mkhive/reginf.c #if 0 static void append_multi_sz_value (HANDLE hkey, @@ -115,7 +116,7 @@ append_multi_sz_value (HANDLE hkey, if (RegQueryValueExW( hkey, value, NULL, &type, NULL, &size )) return; if (type != REG_MULTI_SZ) return; - if (!(buffer = HeapAlloc( GetProcessHeap(), 0, (size + str_size) * sizeof(WCHAR) ))) return; + if (!(buffer = HeapAlloc( GetProcessHeap(), 0, size + str_size * sizeof(WCHAR) ))) return; if (RegQueryValueExW( hkey, value, NULL, NULL, (BYTE *)buffer, &size )) goto done; /* compare each string against all the existing ones */ @@ -196,7 +197,7 @@ do_reg_operation(HANDLE KeyHandle, PINFCONTEXT Context, ULONG Flags) { - WCHAR EmptyStr = (WCHAR)0; + WCHAR EmptyStr = 0; ULONG Type; ULONG Size; @@ -221,7 +222,7 @@ do_reg_operation(HANDLE KeyHandle, #if 0 if (Flags & (FLG_ADDREG_NOCLOBBER | FLG_ADDREG_OVERWRITEONLY)) { - BOOL exists = !RegQueryValueExW( hkey, value, NULL, NULL, NULL, NULL ); + BOOL exists = !RegQueryValueExW( hkey, ValueName, NULL, NULL, NULL, NULL ); if (exists && (flags & FLG_ADDREG_NOCLOBBER)) return TRUE; if (!exists & (flags & FLG_ADDREG_OVERWRITEONLY)) @@ -272,7 +273,7 @@ do_reg_operation(HANDLE KeyHandle, if (Size) { - Str = (WCHAR*) RtlAllocateHeap (ProcessHeap, 0, Size * sizeof(WCHAR)); + Str = (WCHAR*) RtlAllocateHeap(ProcessHeap, 0, Size * sizeof(WCHAR)); if (Str == NULL) return FALSE; @@ -284,6 +285,7 @@ do_reg_operation(HANDLE KeyHandle, if (Str == NULL) return TRUE; + DPRINT1("append_multi_sz_value '%S' commented out, WHY??\n", ValueName); // append_multi_sz_value( hkey, value, str, size ); RtlFreeHeap (ProcessHeap, 0, Str); @@ -293,16 +295,16 @@ do_reg_operation(HANDLE KeyHandle, } else { - if (!SetupGetStringFieldW (Context, 5, NULL, 0, &Size)) + if (!SetupGetStringFieldW(Context, 5, NULL, 0, &Size)) Size = 0; if (Size) { - Str = (WCHAR*) RtlAllocateHeap (ProcessHeap, 0, Size * sizeof(WCHAR)); + Str = (WCHAR*)RtlAllocateHeap(ProcessHeap, 0, Size * sizeof(WCHAR)); if (Str == NULL) return FALSE; - SetupGetStringFieldW (Context, 5, Str, Size, NULL); + SetupGetStringFieldW(Context, 5, Str, Size, NULL); } } @@ -353,7 +355,7 @@ do_reg_operation(HANDLE KeyHandle, if (Size) { - Data = (unsigned char*) RtlAllocateHeap (ProcessHeap, 0, Size); + Data = (unsigned char*) RtlAllocateHeap(ProcessHeap, 0, Size); if (Data == NULL) return FALSE; @@ -375,95 +377,95 @@ do_reg_operation(HANDLE KeyHandle, } NTSTATUS -CreateNestedKey (PHANDLE KeyHandle, - ACCESS_MASK DesiredAccess, - POBJECT_ATTRIBUTES ObjectAttributes) +CreateNestedKey(PHANDLE KeyHandle, + ACCESS_MASK DesiredAccess, + POBJECT_ATTRIBUTES ObjectAttributes) { - OBJECT_ATTRIBUTES LocalObjectAttributes; - UNICODE_STRING LocalKeyName; - ULONG Disposition; - NTSTATUS Status; - USHORT FullNameLength; - PWCHAR Ptr; - HANDLE LocalKeyHandle; - - Status = NtCreateKey (KeyHandle, - KEY_ALL_ACCESS, - ObjectAttributes, - 0, - NULL, - 0, - &Disposition); - DPRINT("NtCreateKey(%wZ) called (Status %lx)\n", ObjectAttributes->ObjectName, Status); - if (Status != STATUS_OBJECT_NAME_NOT_FOUND) - return Status; + OBJECT_ATTRIBUTES LocalObjectAttributes; + UNICODE_STRING LocalKeyName; + ULONG Disposition; + NTSTATUS Status; + USHORT FullNameLength; + PWCHAR Ptr; + HANDLE LocalKeyHandle; - /* Copy object attributes */ - RtlCopyMemory (&LocalObjectAttributes, - ObjectAttributes, - sizeof(OBJECT_ATTRIBUTES)); - RtlCreateUnicodeString (&LocalKeyName, - ObjectAttributes->ObjectName->Buffer); - LocalObjectAttributes.ObjectName = &LocalKeyName; - FullNameLength = LocalKeyName.Length; - - /* Remove the last part of the key name and try to create the key again. */ - while (Status == STATUS_OBJECT_NAME_NOT_FOUND) + Status = NtCreateKey(KeyHandle, + KEY_ALL_ACCESS, + ObjectAttributes, + 0, + NULL, + 0, + &Disposition); + DPRINT("NtCreateKey(%wZ) called (Status %lx)\n", ObjectAttributes->ObjectName, Status); + if (Status != STATUS_OBJECT_NAME_NOT_FOUND) + return Status; + + /* Copy object attributes */ + RtlCopyMemory(&LocalObjectAttributes, + ObjectAttributes, + sizeof(OBJECT_ATTRIBUTES)); + RtlCreateUnicodeString(&LocalKeyName, + ObjectAttributes->ObjectName->Buffer); + LocalObjectAttributes.ObjectName = &LocalKeyName; + FullNameLength = LocalKeyName.Length; + + /* Remove the last part of the key name and try to create the key again. */ + while (Status == STATUS_OBJECT_NAME_NOT_FOUND) { - Ptr = wcsrchr (LocalKeyName.Buffer, '\\'); - if (Ptr == NULL || Ptr == LocalKeyName.Buffer) + Ptr = wcsrchr (LocalKeyName.Buffer, '\\'); + if (Ptr == NULL || Ptr == LocalKeyName.Buffer) { - Status = STATUS_UNSUCCESSFUL; - break; + Status = STATUS_UNSUCCESSFUL; + break; } - *Ptr = (WCHAR)0; - LocalKeyName.Length = wcslen (LocalKeyName.Buffer) * sizeof(WCHAR); - - Status = NtCreateKey (&LocalKeyHandle, - KEY_ALL_ACCESS, - &LocalObjectAttributes, - 0, - NULL, - 0, - &Disposition); - DPRINT("NtCreateKey(%wZ) called (Status %lx)\n", &LocalKeyName, Status); + *Ptr = (WCHAR)0; + LocalKeyName.Length = wcslen (LocalKeyName.Buffer) * sizeof(WCHAR); + + Status = NtCreateKey(&LocalKeyHandle, + KEY_ALL_ACCESS, + &LocalObjectAttributes, + 0, + NULL, + 0, + &Disposition); + DPRINT("NtCreateKey(%wZ) called (Status %lx)\n", &LocalKeyName, Status); } - if (!NT_SUCCESS(Status)) + if (!NT_SUCCESS(Status)) { - RtlFreeUnicodeString (&LocalKeyName); - return Status; + RtlFreeUnicodeString (&LocalKeyName); + return Status; } - /* Add removed parts of the key name and create them too. */ - while (TRUE) + /* Add removed parts of the key name and create them too. */ + while (TRUE) { - if (LocalKeyName.Length == FullNameLength) + if (LocalKeyName.Length == FullNameLength) { - Status = STATUS_SUCCESS; - *KeyHandle = LocalKeyHandle; - break; + Status = STATUS_SUCCESS; + *KeyHandle = LocalKeyHandle; + break; } - NtClose (LocalKeyHandle); - - LocalKeyName.Buffer[LocalKeyName.Length / sizeof(WCHAR)] = L'\\'; - LocalKeyName.Length = wcslen (LocalKeyName.Buffer) * sizeof(WCHAR); - - Status = NtCreateKey (&LocalKeyHandle, - KEY_ALL_ACCESS, - &LocalObjectAttributes, - 0, - NULL, - 0, - &Disposition); - DPRINT("NtCreateKey(%wZ) called (Status %lx)\n", &LocalKeyName, Status); - if (!NT_SUCCESS(Status)) - break; + NtClose(LocalKeyHandle); + + LocalKeyName.Buffer[LocalKeyName.Length / sizeof(WCHAR)] = L'\\'; + LocalKeyName.Length = wcslen (LocalKeyName.Buffer) * sizeof(WCHAR); + + Status = NtCreateKey(&LocalKeyHandle, + KEY_ALL_ACCESS, + &LocalObjectAttributes, + 0, + NULL, + 0, + &Disposition); + DPRINT("NtCreateKey(%wZ) called (Status %lx)\n", &LocalKeyName, Status); + if (!NT_SUCCESS(Status)) + break; } - RtlFreeUnicodeString (&LocalKeyName); + RtlFreeUnicodeString(&LocalKeyName); - return Status; + return Status; } /*********************************************************************** @@ -474,101 +476,95 @@ CreateNestedKey (PHANDLE KeyHandle, static BOOLEAN registry_callback(HINF hInf, PCWSTR Section, BOOLEAN Delete) { - OBJECT_ATTRIBUTES ObjectAttributes; - WCHAR Buffer[MAX_INF_STRING_LENGTH]; - UNICODE_STRING Name; - UNICODE_STRING Value; - PUNICODE_STRING ValuePtr; - NTSTATUS Status; - UINT Flags; - ULONG Length; - - INFCONTEXT Context; - HANDLE KeyHandle; - BOOLEAN Ok; + NTSTATUS Status; + OBJECT_ATTRIBUTES ObjectAttributes; + UNICODE_STRING Name, Value; + PUNICODE_STRING ValuePtr; + UINT Flags; + ULONG Length; + WCHAR Buffer[MAX_INF_STRING_LENGTH]; + INFCONTEXT Context; + HANDLE KeyHandle; + BOOLEAN Ok; - Ok = SetupFindFirstLineW (hInf, Section, NULL, &Context); + Ok = SetupFindFirstLineW(hInf, Section, NULL, &Context); + if (!Ok) + return TRUE; /* Don't fail if the section isn't present */ - if (Ok) + for (;Ok; Ok = SetupFindNextLine (&Context, &Context)) { - for (;Ok; Ok = SetupFindNextLine (&Context, &Context)) - { - /* get root */ - if (!SetupGetStringFieldW (&Context, 1, Buffer, MAX_INF_STRING_LENGTH, NULL)) - continue; - if (!GetRootKey (Buffer)) + /* get root */ + if (!SetupGetStringFieldW(&Context, 1, Buffer, sizeof(Buffer)/sizeof(WCHAR), NULL)) + continue; + if (!GetRootKey (Buffer)) continue; - /* get key */ - Length = wcslen (Buffer); - if (!SetupGetStringFieldW (&Context, 2, Buffer + Length, MAX_INF_STRING_LENGTH - Length, NULL)) + /* get key */ + Length = wcslen(Buffer); + if (!SetupGetStringFieldW(&Context, 2, Buffer + Length, sizeof(Buffer)/sizeof(WCHAR) - Length, NULL)) *Buffer = 0; - DPRINT("KeyName: <%S>\n", Buffer); + DPRINT("KeyName: <%S>\n", Buffer); - /* get flags */ - if (!SetupGetIntField (&Context, 4, (PINT)&Flags)) + /* get flags */ + if (!SetupGetIntField(&Context, 4, (PINT)&Flags)) Flags = 0; - DPRINT("Flags: %lx\n", Flags); - - RtlInitUnicodeString (&Name, - Buffer); + DPRINT("Flags: %lx\n", Flags); - InitializeObjectAttributes (&ObjectAttributes, - &Name, - OBJ_CASE_INSENSITIVE, - NULL, - NULL); - - if (Delete || (Flags & FLG_ADDREG_OVERWRITEONLY)) - { - Status = NtOpenKey (&KeyHandle, - KEY_ALL_ACCESS, - &ObjectAttributes); - if (!NT_SUCCESS(Status)) - { - DPRINT1("NtOpenKey(%wZ) failed (Status %lx)\n", &Name, Status); - continue; /* ignore if it doesn't exist */ - } - } - else - { - Status = CreateNestedKey (&KeyHandle, - KEY_ALL_ACCESS, - &ObjectAttributes); - if (!NT_SUCCESS(Status)) - { - DPRINT1("CreateNestedKey(%wZ) failed (Status %lx)\n", &Name, Status); - continue; - } - } + RtlInitUnicodeString(&Name, Buffer); + InitializeObjectAttributes(&ObjectAttributes, + &Name, + OBJ_CASE_INSENSITIVE, + NULL, + NULL); - /* get value name */ - if (SetupGetStringFieldW (&Context, 3, Buffer, MAX_INF_STRING_LENGTH, NULL)) + if (Delete || (Flags & FLG_ADDREG_OVERWRITEONLY)) + { + Status = NtOpenKey(&KeyHandle, + KEY_ALL_ACCESS, + &ObjectAttributes); + if (!NT_SUCCESS(Status)) { - RtlInitUnicodeString (&Value, - Buffer); - ValuePtr = &Value; + DPRINT1("NtOpenKey(%wZ) failed (Status %lx)\n", &Name, Status); + continue; /* ignore if it doesn't exist */ } - else + } + else + { + Status = CreateNestedKey(&KeyHandle, + KEY_ALL_ACCESS, + &ObjectAttributes); + if (!NT_SUCCESS(Status)) { - ValuePtr = NULL; + DPRINT1("CreateNestedKey(%wZ) failed (Status %lx)\n", &Name, Status); + continue; } + } - /* and now do it */ - if (!do_reg_operation (KeyHandle, ValuePtr, &Context, Flags)) - { - NtClose (KeyHandle); - return FALSE; - } + /* get value name */ + if (SetupGetStringFieldW(&Context, 3, Buffer, sizeof(Buffer)/sizeof(WCHAR), NULL)) + { + RtlInitUnicodeString(&Value, Buffer); + ValuePtr = &Value; + } + else + { + ValuePtr = NULL; + } - NtClose (KeyHandle); + /* and now do it */ + if (!do_reg_operation(KeyHandle, ValuePtr, &Context, Flags)) + { + NtClose(KeyHandle); + return FALSE; } + + NtClose(KeyHandle); } - return TRUE; + return TRUE; } @@ -598,60 +594,30 @@ ImportRegistryFile( return FALSE; } - if (!registry_callback(hInf, L"AddReg", FALSE)) +#if 0 + if (!registry_callback(hInf, L"DelReg", FALSE)) { DPRINT1("registry_callback() failed\n"); + InfCloseFile(hInf); + return FALSE; } +#endif - if (!registry_callback(hInf, L"AddReg.NT" Architecture, FALSE)) + if (!registry_callback(hInf, L"AddReg", FALSE)) { DPRINT1("registry_callback() failed\n"); - } - - InfCloseFile(hInf); - - return TRUE; -} - - -BOOLEAN -SetInstallPathValue( - PUNICODE_STRING InstallPath) -{ - OBJECT_ATTRIBUTES ObjectAttributes; - UNICODE_STRING KeyName = RTL_CONSTANT_STRING(L"\\Registry\\Machine\\HARDWARE"); - UNICODE_STRING ValueName = RTL_CONSTANT_STRING(L"InstallPath"); - HANDLE KeyHandle; - NTSTATUS Status; - - /* Create the 'secret' InstallPath key */ - InitializeObjectAttributes(&ObjectAttributes, - &KeyName, - OBJ_CASE_INSENSITIVE, - NULL, - NULL); - Status = NtOpenKey(&KeyHandle, - KEY_ALL_ACCESS, - &ObjectAttributes); - if (!NT_SUCCESS(Status)) - { - DPRINT1("NtOpenKey() failed (Status %lx)\n", Status); + InfCloseFile(hInf); return FALSE; } - Status = NtSetValueKey(KeyHandle, - &ValueName, - 0, - REG_SZ, - (PVOID)InstallPath->Buffer, - InstallPath->Length + sizeof(WCHAR)); - NtClose(KeyHandle); - if (!NT_SUCCESS(Status)) + if (!registry_callback(hInf, L"AddReg.NT" Architecture, FALSE)) { - DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status); + DPRINT1("registry_callback() failed\n"); + InfCloseFile(hInf); return FALSE; } + InfCloseFile(hInf); return TRUE; }
6 years, 2 months
1
0
0
0
07/07: [CMAKE] Apply patch INF file for the SETUP SYSTEM registry hive that removes the entries in the Critical Device Database that cause problems with PnP setup during 1st-stage setup.
by Hermès Bélusca-Maïto
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=8269478385fa520c5be57…
commit 8269478385fa520c5be5756714980b6ab1613cc2 Author: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org> AuthorDate: Thu Oct 25 00:18:29 2018 +0200 Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org> CommitDate: Thu Oct 25 00:45:10 2018 +0200 [CMAKE] Apply patch INF file for the SETUP SYSTEM registry hive that removes the entries in the Critical Device Database that cause problems with PnP setup during 1st-stage setup. --- boot/bootdata/setupreg.inf | 44 ++++++++++++++++++++++++++++++++++++++++++++ sdk/cmake/CMakeMacros.cmake | 2 +- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/boot/bootdata/setupreg.inf b/boot/bootdata/setupreg.inf new file mode 100644 index 0000000000..7dbf932b56 --- /dev/null +++ b/boot/bootdata/setupreg.inf @@ -0,0 +1,44 @@ +[Version] +Signature = "$ReactOS$" + +[DelReg] + +; Critical Device Database +;; +;; WARNING! Keep it in sync with hivesys.inf +;; + +HKLM,"SYSTEM\CurrentControlSet\Control\CriticalDeviceDatabase\*PNP0A03" +HKLM,"SYSTEM\CurrentControlSet\Control\CriticalDeviceDatabase\*PNP0A08" +HKLM,"SYSTEM\CurrentControlSet\Control\CriticalDeviceDatabase\PCI#CC_0604" +HKLM,"SYSTEM\CurrentControlSet\Control\CriticalDeviceDatabase\*PNP0C08" +HKLM,"SYSTEM\CurrentControlSet\Control\CriticalDeviceDatabase\PCI#CC_0C0300" +HKLM,"SYSTEM\CurrentControlSet\Control\CriticalDeviceDatabase\PCI#CC_0C0310" +HKLM,"SYSTEM\CurrentControlSet\Control\CriticalDeviceDatabase\PCI#CC_0C0320" +HKLM,"SYSTEM\CurrentControlSet\Control\CriticalDeviceDatabase\USB#Class_08&SubClass_06&Prot_50" +HKLM,"SYSTEM\CurrentControlSet\Control\CriticalDeviceDatabase\USB#COMPOSITE" +;HKLM,"SYSTEM\CurrentControlSet\Control\CriticalDeviceDatabase\USB#CLASS_09" +HKLM,"SYSTEM\CurrentControlSet\Control\CriticalDeviceDatabase\USB#ROOT_HUB" +HKLM,"SYSTEM\CurrentControlSet\Control\CriticalDeviceDatabase\USB#ROOT_HUB20" +HKLM,"SYSTEM\CurrentControlSet\Control\CriticalDeviceDatabase\GenDisk" +HKLM,"SYSTEM\CurrentControlSet\Control\CriticalDeviceDatabase\USB#Class_03" +HKLM,"SYSTEM\CurrentControlSet\Control\CriticalDeviceDatabase\GENERIC_HID_DEVICE" +HKLM,"SYSTEM\CurrentControlSet\Control\CriticalDeviceDatabase\HID_DEVICE_SYSTEM_KEYBOARD" +HKLM,"SYSTEM\CurrentControlSet\Control\CriticalDeviceDatabase\HID_DEVICE_SYSTEM_MOUSE" +HKLM,"SYSTEM\CurrentControlSet\Control\CriticalDeviceDatabase\PCI#CC_0000" +HKLM,"SYSTEM\CurrentControlSet\Control\CriticalDeviceDatabase\PCI#CC_0001" +HKLM,"SYSTEM\CurrentControlSet\Control\CriticalDeviceDatabase\PCI#CC_0300" +HKLM,"SYSTEM\CurrentControlSet\Control\CriticalDeviceDatabase\PCI#CC_0301" +HKLM,"SYSTEM\CurrentControlSet\Control\CriticalDeviceDatabase\*PNP0303" +HKLM,"SYSTEM\CurrentControlSet\Control\CriticalDeviceDatabase\*PNP0F0E" +HKLM,"SYSTEM\CurrentControlSet\Control\CriticalDeviceDatabase\*PNP0F19" +HKLM,"SYSTEM\CurrentControlSet\Control\CriticalDeviceDatabase\PS2_MOUSE" +HKLM,"SYSTEM\CurrentControlSet\Control\CriticalDeviceDatabase\*PNP0F13" +HKLM,"SYSTEM\CurrentControlSet\Control\CriticalDeviceDatabase\*IBM3780" +HKLM,"SYSTEM\CurrentControlSet\Control\CriticalDeviceDatabase\*PNP0F12" +HKLM,"SYSTEM\CurrentControlSet\Control\CriticalDeviceDatabase\*PNP0F03" +HKLM,"SYSTEM\CurrentControlSet\Control\CriticalDeviceDatabase\ROOT#SWENUM" + +HKLM,"SYSTEM\CurrentControlSet\Control\CriticalDeviceDatabase" + +; EOF diff --git a/sdk/cmake/CMakeMacros.cmake b/sdk/cmake/CMakeMacros.cmake index 257fece149..f7eba51794 100644 --- a/sdk/cmake/CMakeMacros.cmake +++ b/sdk/cmake/CMakeMacros.cmake @@ -811,7 +811,7 @@ function(create_registry_hives) # BootCD setup system hive add_custom_command( OUTPUT ${CMAKE_BINARY_DIR}/boot/bootdata/SETUPREG.HIV - COMMAND native-mkhive -h:SETUPREG -u -d:${CMAKE_BINARY_DIR}/boot/bootdata ${CMAKE_BINARY_DIR}/boot/bootdata/hivesys_utf16.inf + COMMAND native-mkhive -h:SETUPREG -u -d:${CMAKE_BINARY_DIR}/boot/bootdata ${CMAKE_BINARY_DIR}/boot/bootdata/hivesys_utf16.inf ${CMAKE_SOURCE_DIR}/boot/bootdata/setupreg.inf DEPENDS native-mkhive ${CMAKE_BINARY_DIR}/boot/bootdata/hivesys_utf16.inf) add_custom_target(bootcd_hives
6 years, 2 months
1
0
0
0
06/07: [FREELDR] Adjust WinLdrInitSystemHive() and its callers to load at startup either the regular SYSTEM hive, or the SETUPREG.HIV setup system hive.
by Hermès Bélusca-Maïto
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=0b2b53b9c3e002276c6c0…
commit 0b2b53b9c3e002276c6c034c8d43b9e7d8453d92 Author: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org> AuthorDate: Sat Jun 3 14:55:18 2017 +0000 Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org> CommitDate: Thu Oct 25 00:40:05 2018 +0200 [FREELDR] Adjust WinLdrInitSystemHive() and its callers to load at startup either the regular SYSTEM hive, or the SETUPREG.HIV setup system hive. We now run the 1st-stage setup with a regular system hive, similarly to what's done for the LiveCD, or for a regular ROS installation. The ExpInTextModeSetup hacks I previously removed are now completely unneeded. svn path=/branches/setup_improvements/; revision=74762 --- boot/freeldr/freeldr/ntldr/setupldr.c | 28 ++++++++++++-- boot/freeldr/freeldr/ntldr/winldr.c | 2 +- boot/freeldr/freeldr/ntldr/wlregistry.c | 68 +++++++++++++++++++++------------ 3 files changed, 69 insertions(+), 29 deletions(-) diff --git a/boot/freeldr/freeldr/ntldr/setupldr.c b/boot/freeldr/freeldr/ntldr/setupldr.c index 72e69f889c..111194acd0 100644 --- a/boot/freeldr/freeldr/ntldr/setupldr.c +++ b/boot/freeldr/freeldr/ntldr/setupldr.c @@ -74,8 +74,13 @@ SetupLdrLoadNlsData(PLOADER_PARAMETER_BLOCK LoaderBlock, HINF InfHandle, LPCSTR return; } + TRACE("NLS data %s %s %s\n", AnsiName, OemName, LangName); + Success = WinLdrLoadNLSData(LoaderBlock, SearchPath, AnsiName, OemName, LangName); TRACE("NLS data loading %s\n", Success ? "successful" : "failed"); + + /* TODO: Load OEM HAL font */ + // Value "OemHalFont" } static VOID @@ -128,6 +133,9 @@ SetupLdrScanBootDrivers(PLIST_ENTRY BootDriverListHead, HINF InfHandle, LPCSTR S } while (InfFindNextLine(&InfContext, &InfContext)); } + +/* SETUP STARTER **************************************************************/ + VOID LoadReactOSSetup(IN OperatingSystemItem* OperatingSystem, IN USHORT OperatingSystemVersion) @@ -143,6 +151,7 @@ LoadReactOSSetup(IN OperatingSystemItem* OperatingSystem, LPCSTR LoadOptions; LPSTR BootOptions; BOOLEAN BootFromFloppy; + BOOLEAN Success; ULONG i, ErrorLine; HINF InfHandle; INFCONTEXT InfContext; @@ -163,6 +172,8 @@ LoadReactOSSetup(IN OperatingSystemItem* OperatingSystem, NULL }; + UiDrawStatusText("Setup is loading..."); + /* Get OS setting value */ SettingsValue[0] = ANSI_NULL; IniOpenSection("Operating Systems", &SectionId); @@ -303,8 +314,6 @@ LoadReactOSSetup(IN OperatingSystemItem* OperatingSystem, TRACE("BootOptions: '%s'\n", BootOptions); - UiDrawStatusText("Setup is loading..."); - /* Allocate and minimalist-initialize LPB */ AllocateAndInitLPB(&LoaderBlock); @@ -315,17 +324,30 @@ LoadReactOSSetup(IN OperatingSystemItem* OperatingSystem, /* Set textmode setup flag */ SetupBlock->Flags = SETUPLDR_TEXT_MODE; - /* Load NLS data, they are in system32 */ + /* Load the system hive "setupreg.hiv" for setup */ + UiDrawBackdrop(); + UiDrawProgressBarCenter(15, 100, "Loading setup system hive..."); + Success = WinLdrInitSystemHive(LoaderBlock, BootPath, TRUE); + TRACE("Setup SYSTEM hive %s\n", (Success ? "loaded" : "not loaded")); + /* Bail out if failure */ + if (!Success) + return; + + /* Load NLS data, they are in the System32 directory of the installation medium */ strcpy(FileName, BootPath); strcat(FileName, "system32\\"); SetupLdrLoadNlsData(LoaderBlock, InfHandle, FileName); + // UiDrawStatusText("Press F6 if you need to install a 3rd-party SCSI or RAID driver..."); + /* Get a list of boot drivers */ SetupLdrScanBootDrivers(&LoaderBlock->BootDriverListHead, InfHandle, BootPath); /* Close the inf file */ InfCloseFile(InfHandle); + UiDrawStatusText("The Setup program is starting..."); + /* Load ReactOS Setup */ LoadAndBootWindowsCommon(_WIN32_WINNT_WS03, LoaderBlock, diff --git a/boot/freeldr/freeldr/ntldr/winldr.c b/boot/freeldr/freeldr/ntldr/winldr.c index 6c8da87683..e776a84024 100644 --- a/boot/freeldr/freeldr/ntldr/winldr.c +++ b/boot/freeldr/freeldr/ntldr/winldr.c @@ -750,7 +750,7 @@ LoadAndBootWindows(IN OperatingSystemItem* OperatingSystem, /* Load the system hive */ UiDrawBackdrop(); UiDrawProgressBarCenter(15, 100, "Loading system hive..."); - Success = WinLdrInitSystemHive(LoaderBlock, BootPath); + Success = WinLdrInitSystemHive(LoaderBlock, BootPath, FALSE); TRACE("SYSTEM hive %s\n", (Success ? "loaded" : "not loaded")); /* Bail out if failure */ if (!Success) diff --git a/boot/freeldr/freeldr/ntldr/wlregistry.c b/boot/freeldr/freeldr/ntldr/wlregistry.c index 5fd438fd14..641b13f69e 100644 --- a/boot/freeldr/freeldr/ntldr/wlregistry.c +++ b/boot/freeldr/freeldr/ntldr/wlregistry.c @@ -30,20 +30,21 @@ WinLdrScanRegistry(IN OUT PLIST_ENTRY BootDriverListHead, /* FUNCTIONS **************************************************************/ -BOOLEAN -WinLdrLoadSystemHive(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock, - IN LPCSTR DirectoryPath, - IN LPCSTR HiveName) +static BOOLEAN +WinLdrLoadSystemHive( + IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock, + IN PCSTR DirectoryPath, + IN PCSTR HiveName) { ULONG FileId; - CHAR FullHiveName[256]; + CHAR FullHiveName[MAX_PATH]; ARC_STATUS Status; FILEINFORMATION FileInfo; ULONG HiveFileSize; ULONG_PTR HiveDataPhysical; PVOID HiveDataVirtual; ULONG BytesRead; - LPCWSTR FsService; + PCWSTR FsService; /* Concatenate path and filename to get the full name */ strcpy(FullHiveName, DirectoryPath); @@ -94,7 +95,7 @@ WinLdrLoadSystemHive(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock, return FALSE; } - // Add boot filesystem driver to the list + /* Add boot filesystem driver to the list */ FsService = FsGetServiceName(FileId); if (FsService) { @@ -116,25 +117,40 @@ WinLdrLoadSystemHive(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock, return TRUE; } -BOOLEAN WinLdrInitSystemHive(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock, - IN LPCSTR DirectoryPath) +BOOLEAN +WinLdrInitSystemHive( + IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock, + IN PCSTR SystemRoot, + IN BOOLEAN Setup) { CHAR SearchPath[1024]; + PCSTR HiveName; BOOLEAN Success; - // There is a simple logic here: try to load usual hive (system), if it - // fails, then give system.alt a try, and finally try a system.sav + if (Setup) + { + strcpy(SearchPath, SystemRoot); + HiveName = "SETUPREG.HIV"; + } + else + { + // There is a simple logic here: try to load usual hive (system), if it + // fails, then give system.alt a try, and finally try a system.sav - // FIXME: For now we only try system - strcpy(SearchPath, DirectoryPath); - strcat(SearchPath, "system32\\config\\"); - Success = WinLdrLoadSystemHive(LoaderBlock, SearchPath, "SYSTEM"); + // FIXME: For now we only try system + strcpy(SearchPath, SystemRoot); + strcat(SearchPath, "system32\\config\\"); + HiveName = "SYSTEM"; + } + + ERR("WinLdrInitSystemHive: try to load hive %s%s\n", SearchPath, HiveName); + Success = WinLdrLoadSystemHive(LoaderBlock, SearchPath, HiveName); - // Fail if failed... + /* Fail if failed... */ if (!Success) return FALSE; - // Import what was loaded + /* Import what was loaded */ Success = RegImportBinaryHive(VaToPa(LoaderBlock->RegistryBase), LoaderBlock->RegistryLength); if (!Success) { @@ -142,7 +158,7 @@ BOOLEAN WinLdrInitSystemHive(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock, return FALSE; } - // Initialize the 'CurrentControlSet' link + /* Initialize the 'CurrentControlSet' link */ if (RegInitCurrentControlSet(FALSE) != ERROR_SUCCESS) { UiMessageBox("Initializing CurrentControlSet link failed!"); @@ -159,10 +175,10 @@ BOOLEAN WinLdrScanSystemHive(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock, CHAR AnsiName[256], OemName[256], LangName[256]; BOOLEAN Success; - // Scan registry and prepare boot drivers list + /* Scan registry and prepare boot drivers list */ WinLdrScanRegistry(&LoaderBlock->BootDriverListHead, DirectoryPath); - // Get names of NLS files + /* Get names of NLS files */ Success = WinLdrGetNLSNames(AnsiName, OemName, LangName); if (!Success) { @@ -172,13 +188,15 @@ BOOLEAN WinLdrScanSystemHive(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock, TRACE("NLS data %s %s %s\n", AnsiName, OemName, LangName); - // Load NLS data + /* Load NLS data */ strcpy(SearchPath, DirectoryPath); strcat(SearchPath, "system32\\"); Success = WinLdrLoadNLSData(LoaderBlock, SearchPath, AnsiName, OemName, LangName); TRACE("NLS data loading %s\n", Success ? "successful" : "failed"); /* TODO: Load OEM HAL font */ + // In HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Nls\CodePage, + // REG_SZ value "OEMHAL" return TRUE; } @@ -208,7 +226,7 @@ WinLdrGetNLSNames(LPSTR AnsiName, return FALSE; } - /* get ANSI codepage */ + /* Get ANSI codepage */ BufferSize = sizeof(szIdBuffer); rc = RegQueryValue(hKey, L"ACP", NULL, (PUCHAR)szIdBuffer, &BufferSize); if (rc != ERROR_SUCCESS) @@ -227,7 +245,7 @@ WinLdrGetNLSNames(LPSTR AnsiName, } sprintf(AnsiName, "%S", NameBuffer); - /* get OEM codepage */ + /* Get OEM codepage */ BufferSize = sizeof(szIdBuffer); rc = RegQueryValue(hKey, L"OEMCP", NULL, (PUCHAR)szIdBuffer, &BufferSize); if (rc != ERROR_SUCCESS) @@ -246,7 +264,7 @@ WinLdrGetNLSNames(LPSTR AnsiName, } sprintf(OemName, "%S", NameBuffer); - /* open the language key */ + /* Open the language key */ rc = RegOpenKey(NULL, L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\NLS\\Language", &hKey); @@ -256,7 +274,7 @@ WinLdrGetNLSNames(LPSTR AnsiName, return FALSE; } - /* get the Unicode case table */ + /* Get the Unicode case table */ BufferSize = sizeof(szIdBuffer); rc = RegQueryValue(hKey, L"Default", NULL, (PUCHAR)szIdBuffer, &BufferSize); if (rc != ERROR_SUCCESS)
6 years, 2 months
1
0
0
0
05/07: [FREELDR] Small code re-organization for the "ntldr" sub-module.
by Hermès Bélusca-Maïto
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=5e705d06834c947514e18…
commit 5e705d06834c947514e18ec64ef0338b60a35113 Author: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org> AuthorDate: Fri Jun 2 00:52:36 2017 +0000 Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org> CommitDate: Thu Oct 25 00:40:04 2018 +0200 [FREELDR] Small code re-organization for the "ntldr" sub-module. Split the "main" winldr.h header into the one containing global code that actually doesn't really depend on the "windows" NT loader part, and one that actually concerns code just for the NT Loader. The latter goes into "ntldr". svn path=/branches/setup_improvements/; revision=74743 --- boot/freeldr/freeldr/include/winldr.h | 98 ++++-------------------- boot/freeldr/freeldr/ntldr/setupldr.c | 7 +- boot/freeldr/freeldr/ntldr/winldr.c | 1 + boot/freeldr/freeldr/{include => ntldr}/winldr.h | 75 +++++------------- boot/freeldr/freeldr/ntldr/wlmemory.c | 1 + boot/freeldr/freeldr/ntldr/wlregistry.c | 1 + 6 files changed, 36 insertions(+), 147 deletions(-) diff --git a/boot/freeldr/freeldr/include/winldr.h b/boot/freeldr/freeldr/include/winldr.h index f5b3a8821c..56af2eda3f 100644 --- a/boot/freeldr/freeldr/include/winldr.h +++ b/boot/freeldr/freeldr/include/winldr.h @@ -22,20 +22,20 @@ #include <arc/setupblk.h> +// See freeldr/ntldr/winldr.h #define TAG_WLDR_DTE 'eDlW' #define TAG_WLDR_BDE 'dBlW' #define TAG_WLDR_NAME 'mNlW' -/* Entry-point to kernel */ -typedef VOID (NTAPI *KERNEL_ENTRY_POINT) (PLOADER_PARAMETER_BLOCK LoaderBlock); - // Some definitions + +// FIXME: This one has nothing to do here!! #define SECTOR_SIZE 512 // Descriptors -#define NUM_GDT 128 // Must be 128 -#define NUM_IDT 0x100 // only 16 are used though. Must be 0x100 +#define NUM_GDT 128 // Must be 128 +#define NUM_IDT 0x100 // Only 16 are used though. Must be 0x100 #include <pshpack1.h> typedef struct /* Root System Descriptor Pointer */ @@ -58,27 +58,6 @@ typedef struct _ARC_DISK_SIGNATURE_EX CHAR ArcName[MAX_PATH]; } ARC_DISK_SIGNATURE_EX, *PARC_DISK_SIGNATURE_EX; -#define MAX_OPTIONS_LENGTH 255 - -typedef struct _LOADER_SYSTEM_BLOCK -{ - LOADER_PARAMETER_BLOCK LoaderBlock; - LOADER_PARAMETER_EXTENSION Extension; - SETUP_LOADER_BLOCK SetupBlock; -#ifdef _M_IX86 - HEADLESS_LOADER_BLOCK HeadlessLoaderBlock; -#endif - NLS_DATA_BLOCK NlsDataBlock; - CHAR LoadOptions[MAX_OPTIONS_LENGTH+1]; - CHAR ArcBootDeviceName[MAX_PATH+1]; - // CHAR ArcHalDeviceName[MAX_PATH]; - CHAR NtBootPathName[MAX_PATH+1]; - CHAR NtHalPathName[MAX_PATH+1]; - ARC_DISK_INFORMATION ArcDiskInformation; -} LOADER_SYSTEM_BLOCK, *PLOADER_SYSTEM_BLOCK; - -extern PLOADER_SYSTEM_BLOCK WinLdrSystemBlock; - /////////////////////////////////////////////////////////////////////////////////////// // // ReactOS Loading Functions @@ -87,11 +66,16 @@ extern PLOADER_SYSTEM_BLOCK WinLdrSystemBlock; VOID LoadAndBootWindows(IN OperatingSystemItem* OperatingSystem, IN USHORT OperatingSystemVersion); -// conversion.c +VOID +LoadReactOSSetup(IN OperatingSystemItem* OperatingSystem, + IN USHORT OperatingSystemVersion); + + +// conversion.c and conversion.h PVOID VaToPa(PVOID Va); PVOID PaToVa(PVOID Pa); VOID List_PaToVa(_In_ LIST_ENTRY *ListEntry); -VOID ConvertConfigToVA(PCONFIGURATION_COMPONENT_DATA Start); + // peloader.c BOOLEAN @@ -99,7 +83,6 @@ WinLdrLoadImage(IN PCHAR FileName, TYPE_OF_MEMORY MemoryType, OUT PVOID *ImageBasePA); - BOOLEAN WinLdrAllocateDataTableEntry(IN OUT PLIST_ENTRY ModuleListHead, IN PCCH BaseDllName, @@ -112,54 +95,13 @@ WinLdrScanImportDescriptorTable(IN OUT PLIST_ENTRY ModuleListHead, IN PCCH DirectoryPath, IN PLDR_DATA_TABLE_ENTRY ScanDTE); -// winldr.c -PVOID WinLdrLoadModule(PCSTR ModuleName, ULONG *Size, - TYPE_OF_MEMORY MemoryType); - -// wlmemory.c -BOOLEAN -WinLdrSetupMemoryLayout(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock); - -// wlregistry.c -BOOLEAN WinLdrInitSystemHive(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock, - IN LPCSTR DirectoryPath); - -BOOLEAN WinLdrScanSystemHive(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock, - IN LPCSTR DirectoryPath); - - BOOLEAN WinLdrCheckForLoadedDll(IN OUT PLIST_ENTRY ModuleListHead, IN PCH DllName, OUT PLDR_DATA_TABLE_ENTRY *LoadedEntry); -VOID -WinLdrInitializePhase1(PLOADER_PARAMETER_BLOCK LoaderBlock, - LPCSTR Options, - LPCSTR SystemPath, - LPCSTR BootPath, - USHORT VersionToBoot); -BOOLEAN -WinLdrLoadNLSData(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock, - IN LPCSTR DirectoryPath, - IN LPCSTR AnsiFileName, - IN LPCSTR OemFileName, - IN LPCSTR LanguageFileName); -BOOLEAN -WinLdrAddDriverToList(LIST_ENTRY *BootDriverListHead, - LPWSTR RegistryPath, - LPWSTR ImagePath, - LPWSTR ServiceName); - -VOID -WinLdrpDumpMemoryDescriptors(PLOADER_PARAMETER_BLOCK LoaderBlock); - -VOID -WinLdrpDumpBootDriver(PLOADER_PARAMETER_BLOCK LoaderBlock); - -VOID -WinLdrpDumpArcDisks(PLOADER_PARAMETER_BLOCK LoaderBlock); +// arch/xxx/winldr.c BOOLEAN MempSetupPaging(IN PFN_NUMBER StartPage, IN PFN_NUMBER NumberOfPages, @@ -169,19 +111,7 @@ VOID MempUnmapPage(PFN_NUMBER Page); VOID -MempDump(); - -VOID -LoadAndBootWindowsCommon( - USHORT OperatingSystemVersion, - PLOADER_PARAMETER_BLOCK LoaderBlock, - LPCSTR BootOptions, - LPCSTR BootPath, - BOOLEAN Setup); - -VOID -LoadReactOSSetup(IN OperatingSystemItem* OperatingSystem, - IN USHORT OperatingSystemVersion); +MempDump(VOID); VOID WinLdrSetupMachineDependent(PLOADER_PARAMETER_BLOCK LoaderBlock); diff --git a/boot/freeldr/freeldr/ntldr/setupldr.c b/boot/freeldr/freeldr/ntldr/setupldr.c index 20fc1b63a3..72e69f889c 100644 --- a/boot/freeldr/freeldr/ntldr/setupldr.c +++ b/boot/freeldr/freeldr/ntldr/setupldr.c @@ -19,6 +19,7 @@ */ #include <freeldr.h> +#include "winldr.h" #include <ndk/ldrtypes.h> #include <arc/setupblk.h> @@ -28,12 +29,6 @@ DBG_DEFAULT_CHANNEL(WINDOWS); #define TAG_BOOT_OPTIONS 'pOtB' -void -WinLdrSetupMachineDependent(PLOADER_PARAMETER_BLOCK LoaderBlock); - -VOID -WinLdrSetProcessorContext(void); - // TODO: Move to .h VOID AllocateAndInitLPB(PLOADER_PARAMETER_BLOCK *OutLoaderBlock); diff --git a/boot/freeldr/freeldr/ntldr/winldr.c b/boot/freeldr/freeldr/ntldr/winldr.c index b11015600a..6c8da87683 100644 --- a/boot/freeldr/freeldr/ntldr/winldr.c +++ b/boot/freeldr/freeldr/ntldr/winldr.c @@ -20,6 +20,7 @@ */ #include <freeldr.h> +#include "winldr.h" #include "registry.h" #include <ndk/ldrtypes.h> diff --git a/boot/freeldr/freeldr/include/winldr.h b/boot/freeldr/freeldr/ntldr/winldr.h similarity index 70% copy from boot/freeldr/freeldr/include/winldr.h copy to boot/freeldr/freeldr/ntldr/winldr.h index f5b3a8821c..31ca33dd44 100644 --- a/boot/freeldr/freeldr/include/winldr.h +++ b/boot/freeldr/freeldr/ntldr/winldr.h @@ -22,20 +22,25 @@ #include <arc/setupblk.h> +#if 0 +// See freeldr/include/winldr.h #define TAG_WLDR_DTE 'eDlW' #define TAG_WLDR_BDE 'dBlW' #define TAG_WLDR_NAME 'mNlW' +#endif + /* Entry-point to kernel */ typedef VOID (NTAPI *KERNEL_ENTRY_POINT) (PLOADER_PARAMETER_BLOCK LoaderBlock); // Some definitions -#define SECTOR_SIZE 512 + +#if 0 // Descriptors -#define NUM_GDT 128 // Must be 128 -#define NUM_IDT 0x100 // only 16 are used though. Must be 0x100 +#define NUM_GDT 128 // Must be 128 +#define NUM_IDT 0x100 // Only 16 are used though. Must be 0x100 #include <pshpack1.h> typedef struct /* Root System Descriptor Pointer */ @@ -58,6 +63,8 @@ typedef struct _ARC_DISK_SIGNATURE_EX CHAR ArcName[MAX_PATH]; } ARC_DISK_SIGNATURE_EX, *PARC_DISK_SIGNATURE_EX; +#endif + #define MAX_OPTIONS_LENGTH 255 typedef struct _LOADER_SYSTEM_BLOCK @@ -79,38 +86,15 @@ typedef struct _LOADER_SYSTEM_BLOCK extern PLOADER_SYSTEM_BLOCK WinLdrSystemBlock; -/////////////////////////////////////////////////////////////////////////////////////// -// -// ReactOS Loading Functions -// -/////////////////////////////////////////////////////////////////////////////////////// -VOID LoadAndBootWindows(IN OperatingSystemItem* OperatingSystem, - IN USHORT OperatingSystemVersion); // conversion.c +#if 0 PVOID VaToPa(PVOID Va); PVOID PaToVa(PVOID Pa); VOID List_PaToVa(_In_ LIST_ENTRY *ListEntry); +#endif VOID ConvertConfigToVA(PCONFIGURATION_COMPONENT_DATA Start); -// peloader.c -BOOLEAN -WinLdrLoadImage(IN PCHAR FileName, - TYPE_OF_MEMORY MemoryType, - OUT PVOID *ImageBasePA); - - -BOOLEAN -WinLdrAllocateDataTableEntry(IN OUT PLIST_ENTRY ModuleListHead, - IN PCCH BaseDllName, - IN PCCH FullDllName, - IN PVOID BasePA, - OUT PLDR_DATA_TABLE_ENTRY *NewEntry); - -BOOLEAN -WinLdrScanImportDescriptorTable(IN OUT PLIST_ENTRY ModuleListHead, - IN PCCH DirectoryPath, - IN PLDR_DATA_TABLE_ENTRY ScanDTE); // winldr.c PVOID WinLdrLoadModule(PCSTR ModuleName, ULONG *Size, @@ -121,18 +105,16 @@ BOOLEAN WinLdrSetupMemoryLayout(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock); // wlregistry.c -BOOLEAN WinLdrInitSystemHive(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock, - IN LPCSTR DirectoryPath); +BOOLEAN +WinLdrInitSystemHive( + IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock, + IN PCSTR SystemRoot, + IN BOOLEAN Setup); BOOLEAN WinLdrScanSystemHive(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock, IN LPCSTR DirectoryPath); - -BOOLEAN -WinLdrCheckForLoadedDll(IN OUT PLIST_ENTRY ModuleListHead, - IN PCH DllName, - OUT PLDR_DATA_TABLE_ENTRY *LoadedEntry); - +// winldr.c VOID WinLdrInitializePhase1(PLOADER_PARAMETER_BLOCK LoaderBlock, LPCSTR Options, @@ -160,17 +142,6 @@ WinLdrpDumpBootDriver(PLOADER_PARAMETER_BLOCK LoaderBlock); VOID WinLdrpDumpArcDisks(PLOADER_PARAMETER_BLOCK LoaderBlock); -BOOLEAN -MempSetupPaging(IN PFN_NUMBER StartPage, - IN PFN_NUMBER NumberOfPages, - IN BOOLEAN KernelMapping); - -VOID -MempUnmapPage(PFN_NUMBER Page); - -VOID -MempDump(); - VOID LoadAndBootWindowsCommon( USHORT OperatingSystemVersion, @@ -178,13 +149,3 @@ LoadAndBootWindowsCommon( LPCSTR BootOptions, LPCSTR BootPath, BOOLEAN Setup); - -VOID -LoadReactOSSetup(IN OperatingSystemItem* OperatingSystem, - IN USHORT OperatingSystemVersion); - -VOID -WinLdrSetupMachineDependent(PLOADER_PARAMETER_BLOCK LoaderBlock); - -VOID -WinLdrSetProcessorContext(VOID); diff --git a/boot/freeldr/freeldr/ntldr/wlmemory.c b/boot/freeldr/freeldr/ntldr/wlmemory.c index 09638d82e5..99a1c9d9db 100644 --- a/boot/freeldr/freeldr/ntldr/wlmemory.c +++ b/boot/freeldr/freeldr/ntldr/wlmemory.c @@ -9,6 +9,7 @@ /* INCLUDES ***************************************************************/ #include <freeldr.h> +#include "winldr.h" #include <debug.h> diff --git a/boot/freeldr/freeldr/ntldr/wlregistry.c b/boot/freeldr/freeldr/ntldr/wlregistry.c index 40e297e9cb..5fd438fd14 100644 --- a/boot/freeldr/freeldr/ntldr/wlregistry.c +++ b/boot/freeldr/freeldr/ntldr/wlregistry.c @@ -9,6 +9,7 @@ /* INCLUDES ***************************************************************/ #include <freeldr.h> +#include "winldr.h" #include "registry.h" #include <debug.h>
6 years, 2 months
1
0
0
0
04/07: [NTOS] Drastically reduce the hackish function CmpGetRegistryPath() for the text-mode setup case (it should ultimately completely disappear).
by Hermès Bélusca-Maïto
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=83d5c711b366434d4fd33…
commit 83d5c711b366434d4fd33fe183db7f3eb2c0eca8 Author: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org> AuthorDate: Thu Jun 22 00:46:30 2017 +0000 Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org> CommitDate: Thu Oct 25 00:40:03 2018 +0200 [NTOS] Drastically reduce the hackish function CmpGetRegistryPath() for the text-mode setup case (it should ultimately completely disappear). svn path=/branches/setup_improvements/; revision=75163 --- ntoskrnl/config/cmsysini.c | 72 ++++++++-------------------------------------- 1 file changed, 12 insertions(+), 60 deletions(-) diff --git a/ntoskrnl/config/cmsysini.c b/ntoskrnl/config/cmsysini.c index f49c07acd1..295e4b4376 100644 --- a/ntoskrnl/config/cmsysini.c +++ b/ntoskrnl/config/cmsysini.c @@ -1166,76 +1166,28 @@ CmpCreateRegistryRoot(VOID) return TRUE; } -NTSTATUS -NTAPI +static NTSTATUS CmpGetRegistryPath(OUT PWCHAR ConfigPath) { - OBJECT_ATTRIBUTES ObjectAttributes; - NTSTATUS Status; - HANDLE KeyHandle; - PKEY_VALUE_PARTIAL_INFORMATION ValueInfo; - UNICODE_STRING KeyName = RTL_CONSTANT_STRING(L"\\Registry\\Machine\\HARDWARE"); - UNICODE_STRING ValueName = RTL_CONSTANT_STRING(L"InstallPath"); - ULONG BufferSize, ResultSize; + /* Just use default path */ + wcscpy(ConfigPath, L"\\SystemRoot"); /* Check if we are booted in setup */ - if (ExpInTextModeSetup) + if (!ExpInTextModeSetup) { - DPRINT1("CmpGetRegistryPath TextMode setup HACK!!\n"); - - /* Setup the object attributes */ - InitializeObjectAttributes(&ObjectAttributes, - &KeyName, - OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE, - NULL, - NULL); - /* Open the key */ - Status = ZwOpenKey(&KeyHandle, - KEY_ALL_ACCESS, - &ObjectAttributes); - if (!NT_SUCCESS(Status)) return Status; - - /* Allocate the buffer */ - BufferSize = sizeof(KEY_VALUE_PARTIAL_INFORMATION) + 4096; - ValueInfo = ExAllocatePoolWithTag(PagedPool, BufferSize, TAG_CM); - if (!ValueInfo) - { - /* Fail */ - ZwClose(KeyHandle); - return STATUS_INSUFFICIENT_RESOURCES; - } - - /* Query the value */ - Status = ZwQueryValueKey(KeyHandle, - &ValueName, - KeyValuePartialInformation, - ValueInfo, - BufferSize, - &ResultSize); - ZwClose(KeyHandle); - if (!NT_SUCCESS(Status)) - { - /* Fail */ - ExFreePoolWithTag(ValueInfo, TAG_CM); - return Status; - } - - /* Copy the config path and null-terminate it */ - RtlCopyMemory(ConfigPath, - ValueInfo->Data, - ValueInfo->DataLength); - ConfigPath[ValueInfo->DataLength / sizeof(WCHAR)] = UNICODE_NULL; - ExFreePoolWithTag(ValueInfo, TAG_CM); + /* Add registry path */ +#if 0 + ResultSize = wcslen(ConfigPath); + if (ResultSize && ConfigPath[ResultSize - 1] == L'\\') + ConfigPath[ResultSize - 1] = UNICODE_NULL; +#endif + wcscat(ConfigPath, L"\\System32\\Config\\"); } else { - /* Just use default path */ - wcscpy(ConfigPath, L"\\SystemRoot"); + wcscat(ConfigPath, L"\\"); } - /* Add registry path */ - wcscat(ConfigPath, L"\\System32\\Config\\"); - DPRINT1("CmpGetRegistryPath: ConfigPath = '%S'\n", ConfigPath); /* Done */
6 years, 2 months
1
0
0
0
← Newer
1
...
11
12
13
14
15
16
17
...
36
Older →
Jump to page:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
Results per page:
10
25
50
100
200