Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

8369 lines
244 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name:
  4. spconfig.c
  5. Abstract:
  6. Registry manipulation routines
  7. Author:
  8. Vijay Jayaseelan (vijayj@microsoft.com) 16 May 2001
  9. Revision History:
  10. None.
  11. --*/
  12. #include "spprecmp.h"
  13. #pragma hdrstop
  14. #include <initguid.h>
  15. #include <devguid.h>
  16. //
  17. // The following two are defined in winlogon\setup.h, but we
  18. // cannot include setup.h so we are putting these two values here
  19. //
  20. #define SETUPTYPE_FULL 1
  21. #define SETUPTYPE_UPGRADE 4
  22. PWSTR LOCAL_MACHINE_KEY_NAME = L"\\registry\\machine";
  23. PWSTR SETUP_KEY_NAME = L"setup";
  24. PWSTR ATDISK_NAME = L"atdisk";
  25. PWSTR ABIOSDISK_NAME = L"abiosdsk";
  26. PWSTR PRIMARY_DISK_GROUP = L"Primary disk";
  27. PWSTR VIDEO_GROUP = L"Video";
  28. PWSTR KEYBOARD_PORT_GROUP = L"Keyboard Port";
  29. PWSTR POINTER_PORT_GROUP = L"Pointer Port";
  30. PWSTR DEFAULT_EVENT_LOG = L"%SystemRoot%\\System32\\IoLogMsg.dll";
  31. PWSTR CODEPAGE_NAME = L"CodePage";
  32. PWSTR UPGRADE_IN_PROGRESS = L"UpgradeInProgress";
  33. PWSTR VIDEO_DEVICE0 = L"Device0";
  34. PWSTR SESSION_MANAGER_KEY = L"Control\\Session Manager";
  35. PWSTR BOOT_EXECUTE = L"BootExecute";
  36. PWSTR RESTART_SETUP = L"RestartSetup";
  37. PWSTR PRODUCT_OPTIONS_KEY_NAME = L"ProductOptions";
  38. PWSTR PRODUCT_SUITE_VALUE_NAME = L"ProductSuite";
  39. PWSTR SP_SERVICES_TO_DISABLE = L"ServicesToDisable";
  40. PWSTR SP_UPPER_FILTERS = L"UpperFilters";
  41. PWSTR SP_LOWER_FILTERS = L"LowerFilters";
  42. PWSTR SP_MATCHING_DEVICE_ID = L"MatchingDeviceId";
  43. PWSTR SP_CONTROL_CLASS_KEY = L"Control\\Class";
  44. PWSTR SP_CLASS_GUID_VALUE_NAME = L"ClassGUID";
  45. PWSTR ProductSuiteNames[] =
  46. {
  47. L"Small Business",
  48. L"Enterprise",
  49. L"BackOffice",
  50. L"CommunicationServer",
  51. L"Terminal Server",
  52. L"Small Business(Restricted)",
  53. L"EmbeddedNT",
  54. L"DataCenter",
  55. NULL, // This is a placeholder for Single User TS - not actually a suite but the bit position is defined in ntdef.h
  56. L"Personal",
  57. L"Blade"
  58. };
  59. #define CountProductSuiteNames (sizeof(ProductSuiteNames)/sizeof(PWSTR))
  60. #define MAX_PRODUCT_SUITE_BYTES 1024
  61. extern BOOLEAN DriveAssignFromA; //NEC98
  62. NTSTATUS
  63. SpSavePreinstallList(
  64. IN PVOID SifHandle,
  65. IN PWSTR SystemRoot,
  66. IN HANDLE hKeySystemHive
  67. );
  68. NTSTATUS
  69. SpDoRegistryInitialization(
  70. IN PVOID SifHandle,
  71. IN PDISK_REGION TargetRegion,
  72. IN PWSTR PartitionPath,
  73. IN PWSTR SystemRoot,
  74. IN HANDLE *HiveRootKeys,
  75. IN PWSTR SetupSourceDevicePath,
  76. IN PWSTR DirectoryOnSourceDevice,
  77. IN PWSTR SpecialDevicePath, OPTIONAL
  78. IN HANDLE ControlSet
  79. );
  80. NTSTATUS
  81. SpFormSetupCommandLine(
  82. IN PVOID SifHandle,
  83. IN HANDLE hKeySystemHive,
  84. IN PWSTR SetupSourceDevicePath,
  85. IN PWSTR DirectoryOnSourceDevice,
  86. IN PWSTR FullTargetPath,
  87. IN PWSTR SpecialDevicePath OPTIONAL
  88. );
  89. NTSTATUS
  90. SpDriverLoadList(
  91. IN PVOID SifHandle,
  92. IN PWSTR SystemRoot,
  93. IN HANDLE hKeySystemHive,
  94. IN HANDLE hKeyControlSet
  95. );
  96. NTSTATUS
  97. SpSaveSKUStuff(
  98. IN HANDLE hKeySystemHive
  99. );
  100. NTSTATUS
  101. SpWriteVideoParameters(
  102. IN PVOID SifHandle,
  103. IN HANDLE hKeyControlSetServices
  104. );
  105. NTSTATUS
  106. SpConfigureNlsParameters(
  107. IN PVOID SifHandle,
  108. IN HANDLE hKeyDefaultHive,
  109. IN HANDLE hKeyControlSetControl
  110. );
  111. NTSTATUS
  112. SpCreateCodepageEntry(
  113. IN PVOID SifHandle,
  114. IN HANDLE hKeyNls,
  115. IN PWSTR SubkeyName,
  116. IN PWSTR SifNlsSectionKeyName,
  117. IN PWSTR EntryName
  118. );
  119. NTSTATUS
  120. SpConfigureFonts(
  121. IN PVOID SifHandle,
  122. IN HANDLE hKeySoftwareHive
  123. );
  124. NTSTATUS
  125. SpStoreHwInfoForSetup(
  126. IN HANDLE hKeyControlSetControl
  127. );
  128. NTSTATUS
  129. SpConfigureMouseKeyboardDrivers(
  130. IN PVOID SifHandle,
  131. IN ULONG HwComponent,
  132. IN PWSTR ClassServiceName,
  133. IN HANDLE hKeyControlSetServices,
  134. IN PWSTR ServiceGroup
  135. );
  136. NTSTATUS
  137. SpCreateServiceEntryIndirect(
  138. IN HANDLE hKeyControlSetServices,
  139. IN PVOID SifHandle, OPTIONAL
  140. IN PWSTR SifSectionName, OPTIONAL
  141. IN PWSTR KeyName,
  142. IN ULONG ServiceType,
  143. IN ULONG ServiceStart,
  144. IN PWSTR ServiceGroup, OPTIONAL
  145. IN ULONG ServiceError,
  146. IN PWSTR FileName, OPTIONAL
  147. OUT PHANDLE SubkeyHandle OPTIONAL
  148. );
  149. NTSTATUS
  150. SpThirdPartyRegistry(
  151. IN PVOID hKeyControlSetServices
  152. );
  153. NTSTATUS
  154. SpGetCurrentControlSetNumber(
  155. IN HANDLE SystemHiveRoot,
  156. OUT PULONG Number
  157. );
  158. NTSTATUS
  159. SpCreateControlSetSymbolicLink(
  160. IN HANDLE SystemHiveRoot,
  161. OUT HANDLE *CurrentControlSetRoot
  162. );
  163. NTSTATUS
  164. SpAppendStringToMultiSz(
  165. IN HANDLE hKey,
  166. IN PWSTR Subkey,
  167. IN PWSTR ValueName,
  168. IN PWSTR StringToAdd
  169. );
  170. NTSTATUS
  171. SpGetValueKey(
  172. IN HANDLE hKeyRoot,
  173. IN PWSTR KeyName,
  174. IN PWSTR ValueName,
  175. IN ULONG BufferLength,
  176. OUT PUCHAR Buffer,
  177. OUT PULONG ResultLength
  178. );
  179. NTSTATUS
  180. SpPostprocessHives(
  181. IN PWSTR PartitionPath,
  182. IN PWSTR Sysroot,
  183. IN PCWSTR *HiveNames,
  184. IN HANDLE *HiveRootKeys,
  185. IN unsigned HiveCount,
  186. IN HANDLE hkeyCCS
  187. );
  188. NTSTATUS
  189. SpSaveSetupPidList(
  190. IN HANDLE hKeySystemHive
  191. );
  192. NTSTATUS
  193. SpSavePageFileInfo(
  194. IN HANDLE hKeyCCSetControl,
  195. IN HANDLE hKeySystemHive
  196. );
  197. NTSTATUS
  198. SpSetPageFileInfo(
  199. IN PVOID SifHandle,
  200. IN HANDLE hKeyCCSetControl,
  201. IN HANDLE hKeySystemHive
  202. );
  203. NTSTATUS
  204. SpGetProductSuiteMask(
  205. IN HANDLE hKeyControlSetControl,
  206. OUT PULONG SuiteMask
  207. );
  208. NTSTATUS
  209. SpSetProductSuite(
  210. IN HANDLE hKeyControlSetControl,
  211. IN ULONG SuiteMask
  212. );
  213. NTSTATUS
  214. SppMigrateFtKeys(
  215. IN HANDLE hDestSystemHive
  216. );
  217. NTSTATUS
  218. SpMigrateSetupKeys(
  219. IN PWSTR PartitionPath,
  220. IN PWSTR SystemRoot,
  221. IN HANDLE hDestLocalMachine,
  222. IN PVOID SifHandle
  223. );
  224. NTSTATUS
  225. SppDisableDynamicVolumes(
  226. IN HANDLE hCCSet
  227. );
  228. NTSTATUS
  229. SppCleanupKeysFromRemoteInstall(
  230. VOID
  231. );
  232. NTSTATUS
  233. SpDisableUnsupportedScsiDrivers(
  234. IN HANDLE hKeyControlSet
  235. );
  236. NTSTATUS
  237. SpAppendPathToDevicePath(
  238. IN HANDLE hKeySoftwareHive,
  239. IN PWSTR OemPnpDriversDirPath
  240. );
  241. NTSTATUS
  242. SpAppendFullPathListToDevicePath (
  243. IN HANDLE hKeySoftwareHive,
  244. IN PWSTR PnpDriverFullPathList
  245. );
  246. NTSTATUS
  247. SpUpdateDeviceInstanceData(
  248. IN HANDLE ControlSet
  249. );
  250. NTSTATUS
  251. SpCleanUpHive(
  252. VOID
  253. );
  254. NTSTATUS
  255. SpProcessServicesToDisable(
  256. IN PVOID WinntSifHandle,
  257. IN PWSTR SectionName,
  258. IN HANDLE SystemKey
  259. );
  260. NTSTATUS
  261. SpDeleteRequiredDeviceInstanceFilters(
  262. IN HANDLE CCSHandle
  263. );
  264. #if defined(REMOTE_BOOT)
  265. NTSTATUS
  266. SpCopyRemoteBootKeyword(
  267. IN PVOID SifHandle,
  268. IN PWSTR KeywordName,
  269. IN HANDLE hKeyCCSetControl
  270. );
  271. #endif // defined(REMOTE_BOOT)
  272. #define STRING_VALUE(s) REG_SZ,(s),(wcslen((s))+1)*sizeof(WCHAR)
  273. #define ULONG_VALUE(u) REG_DWORD,&(u),sizeof(ULONG)
  274. //
  275. // List of oem inf files installed as part of the installation of third party drivers
  276. //
  277. extern POEM_INF_FILE OemInfFileList;
  278. //
  279. // Name of the directory where OEM files need to be copied, if a catalog file (.cat) is part of
  280. // the third party driver package that the user provide using the F6 or F5 key.
  281. //
  282. extern PWSTR OemDirName;
  283. VOID
  284. SpInitializeRegistry(
  285. IN PVOID SifHandle,
  286. IN PDISK_REGION TargetRegion,
  287. IN PWSTR SystemRoot,
  288. IN PWSTR SetupSourceDevicePath,
  289. IN PWSTR DirectoryOnSourceDevice,
  290. IN PWSTR SpecialDevicePath OPTIONAL,
  291. IN PDISK_REGION SystemPartitionRegion
  292. )
  293. {
  294. OBJECT_ATTRIBUTES ObjectAttributes;
  295. UNICODE_STRING UnicodeString;
  296. NTSTATUS Status;
  297. PWSTR pwstrTemp1,pwstrTemp2;
  298. int h;
  299. ULONG Disposition;
  300. LPCWSTR HiveNames[SetupHiveMax] = { L"system",L"software",L"default",L"userdiff" };
  301. HANDLE HiveRootKeys[SetupHiveMax] = { NULL ,NULL ,NULL ,NULL };
  302. PWSTR PartitionPath;
  303. HANDLE FileHandle;
  304. HANDLE KeyHandle;
  305. IO_STATUS_BLOCK IoStatusBlock;
  306. //
  307. // Put up a screen telling the user what we are doing.
  308. //
  309. SpStartScreen(
  310. SP_SCRN_DOING_REG_CONFIG,
  311. 0,
  312. 8,
  313. TRUE,
  314. FALSE,
  315. DEFAULT_ATTRIBUTE
  316. );
  317. SpDisplayStatusText(SP_STAT_REG_LOADING_HIVES,DEFAULT_STATUS_ATTRIBUTE);
  318. //
  319. // Get the name of the target patition.
  320. //
  321. SpNtNameFromRegion(
  322. TargetRegion,
  323. TemporaryBuffer,
  324. sizeof(TemporaryBuffer),
  325. PartitionOrdinalCurrent
  326. );
  327. PartitionPath = SpDupStringW(TemporaryBuffer);
  328. // pwstrTemp2 points half way through the buffer.
  329. pwstrTemp1 = TemporaryBuffer;
  330. pwstrTemp2 = TemporaryBuffer + (sizeof(TemporaryBuffer) / sizeof(WCHAR) / 2);
  331. //
  332. // In the fresh install case, there are no hive files in the target tree.
  333. // We create a key in a known place (\Registry\Machine\System\$$$PROTO.HIV,
  334. // which is 4 levels deep because \Registry\Machine\$$$PROTO.HIV would
  335. // imply a hive called $$$PROTO.HIV and we don't want to get tripped up
  336. // by those semantics). Then we save off that empty key 3 times into
  337. // system32\config to form 3 empty hives.
  338. //
  339. // In the upgrade case this there are actual hives in the target tree
  340. // which we do NOT want to overwrite!
  341. //
  342. // If this is the ASR quick test, we don't want to recreate any of the hives
  343. //
  344. // We also want to create an empty userdiff hive in both the fresh and
  345. // upgrade cases.
  346. //
  347. //
  348. INIT_OBJA(
  349. &ObjectAttributes,
  350. &UnicodeString,
  351. L"\\Registry\\Machine\\System\\$$$PROTO.HIV"
  352. );
  353. Status = ZwCreateKey(
  354. &KeyHandle,
  355. KEY_ALL_ACCESS,
  356. &ObjectAttributes,
  357. 0,
  358. NULL,
  359. REG_OPTION_NON_VOLATILE,
  360. &Disposition
  361. );
  362. if(!NT_SUCCESS(Status)) {
  363. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: unable to create root key for protohive (%lx)\n",Status));
  364. } else {
  365. ASSERT(SetupHiveUserdiff == SetupHiveMax-1);
  366. if (ASRMODE_QUICKTEST_FULL != SpAsrGetAsrMode()) {
  367. for(h = ((NTUpgrade == UpgradeFull) ? SetupHiveUserdiff : 0);
  368. NT_SUCCESS(Status) && (h < SetupHiveMax);
  369. h++) {
  370. //
  371. // Form full pathname to the hive we want to create.
  372. // Then create the file.
  373. //
  374. wcscpy(pwstrTemp1,PartitionPath);
  375. SpConcatenatePaths(pwstrTemp1,SystemRoot);
  376. SpConcatenatePaths(pwstrTemp1,L"SYSTEM32\\CONFIG");
  377. SpConcatenatePaths(pwstrTemp1,HiveNames[h]);
  378. SpDeleteFile(pwstrTemp1,NULL,NULL); // Make sure that we get rid of the file if it has attributes.
  379. INIT_OBJA(&ObjectAttributes,&UnicodeString,pwstrTemp1);
  380. Status = ZwCreateFile(
  381. &FileHandle,
  382. FILE_GENERIC_WRITE,
  383. &ObjectAttributes,
  384. &IoStatusBlock,
  385. NULL,
  386. FILE_ATTRIBUTE_NORMAL,
  387. 0, // no sharing
  388. FILE_OVERWRITE_IF,
  389. FILE_NON_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT,
  390. NULL,
  391. 0
  392. );
  393. if(!NT_SUCCESS(Status)) {
  394. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: unable to create file %ws for protohive (%lx)\n",pwstrTemp1,Status));
  395. } else {
  396. //
  397. // Save the empty key we created above into the file
  398. // we just created. This creates an empty hive.
  399. // Call the Ex version to make sure the hive is in the latest format
  400. //
  401. Status = ZwSaveKeyEx(KeyHandle,FileHandle,REG_LATEST_FORMAT);
  402. if(!NT_SUCCESS(Status)) {
  403. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: unable to save empty key to protohive %ws (%lx)\n",pwstrTemp1,Status));
  404. }
  405. ZwClose(FileHandle);
  406. }
  407. }
  408. }
  409. ZwDeleteKey(KeyHandle);
  410. ZwClose(KeyHandle);
  411. }
  412. //
  413. // Now we have hives in both the upgrade and fresh install cases.
  414. // Load them up. We use the convention that a hive is loaded into
  415. // \Registry\Machine\x<hivename>.
  416. //
  417. for(h=0; NT_SUCCESS(Status) && (h<SetupHiveMax); h++) {
  418. swprintf(pwstrTemp1,L"%ws\\x%ws",LOCAL_MACHINE_KEY_NAME,HiveNames[h]);
  419. wcscpy(pwstrTemp2,PartitionPath);
  420. SpConcatenatePaths(pwstrTemp2,SystemRoot);
  421. SpConcatenatePaths(pwstrTemp2,L"SYSTEM32\\CONFIG");
  422. SpConcatenatePaths(pwstrTemp2,HiveNames[h]);
  423. Status = SpLoadUnloadKey(NULL,NULL,pwstrTemp1,pwstrTemp2);
  424. if(!NT_SUCCESS(Status)) {
  425. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: load hive %ws into %ws failed (%lx)\n",pwstrTemp2,pwstrTemp1,Status));
  426. } else {
  427. INIT_OBJA(&ObjectAttributes,&UnicodeString,pwstrTemp1);
  428. Status = ZwOpenKey(&HiveRootKeys[h],KEY_ALL_ACCESS,&ObjectAttributes);
  429. if(!NT_SUCCESS(Status)) {
  430. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: open root key %ws failed (%lx)\n",pwstrTemp1,Status));
  431. }
  432. }
  433. }
  434. //
  435. // Make a symbolic link such that CurrentControlSet is valid.
  436. // This allows references in infs to work in either the fresh install case,
  437. // where we're always dealing with ControlSet001, or in the upgrade case,
  438. // where the control set we're dealing with is dictated by the state of
  439. // the existing registry.
  440. //
  441. if(NT_SUCCESS(Status)) {
  442. Status = SpCreateControlSetSymbolicLink(HiveRootKeys[SetupHiveSystem],&KeyHandle);
  443. if(!NT_SUCCESS(Status)) {
  444. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Unable to create ccs symbolic link (%lx)\n",Status));
  445. }
  446. }
  447. //
  448. // Go do registry initialization.
  449. //
  450. if(NT_SUCCESS(Status)) {
  451. SpDisplayStatusText(SP_STAT_REG_DOING_HIVES,DEFAULT_STATUS_ATTRIBUTE);
  452. Status = SpDoRegistryInitialization(
  453. SifHandle,
  454. TargetRegion,
  455. PartitionPath,
  456. SystemRoot,
  457. HiveRootKeys,
  458. SetupSourceDevicePath,
  459. DirectoryOnSourceDevice,
  460. SpecialDevicePath,
  461. KeyHandle
  462. );
  463. SpDisplayStatusText(SP_STAT_REG_SAVING_HIVES,DEFAULT_STATUS_ATTRIBUTE);
  464. if(NT_SUCCESS(Status)) {
  465. #ifdef _X86_
  466. if (WinUpgradeType == UpgradeWin95) {
  467. //
  468. // NOTE: -- Clean this up.
  469. //
  470. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_INFO_LEVEL, "SETUP: Migrating disk registry of win9x information.\n"));
  471. Status = SpMigrateDiskRegistry( HiveRootKeys[SetupHiveSystem]);
  472. if (!NT_SUCCESS(Status)) {
  473. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Unable to migrate disk registry.\n"));
  474. }
  475. }
  476. //
  477. // We've set the \\Registry\\Machine\\System\\Setup\\SystemPartition
  478. // value when we did the partitioning code. Now we need to migrate
  479. // that value into the proto hives so they'll be there for
  480. // the reboot.
  481. //
  482. {
  483. #if 0
  484. HANDLE Key;
  485. DWORD ResultLength;
  486. PWSTR SystemPartitionString = 0;
  487. INIT_OBJA(&ObjectAttributes,&UnicodeString,LOCAL_MACHINE_KEY_NAME);
  488. Status = ZwOpenKey(&Key,KEY_READ,&ObjectAttributes);
  489. if(NT_SUCCESS(Status)) {
  490. Status = SpGetValueKey(
  491. Key,
  492. L"System\\Setup",
  493. L"SystemPartition",
  494. sizeof(TemporaryBuffer),
  495. (PCHAR)TemporaryBuffer,
  496. &ResultLength
  497. );
  498. ZwClose(Key);
  499. if(NT_SUCCESS(Status)) {
  500. SystemPartitionString = SpDupStringW( TemporaryBuffer );
  501. if( SystemPartitionString ) {
  502. Status = SpOpenSetValueAndClose( HiveRootKeys[SetupHiveSystem],
  503. SETUP_KEY_NAME,
  504. L"SystemPartition",
  505. STRING_VALUE(SystemPartitionString) );
  506. if(!NT_SUCCESS(Status)) {
  507. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Failed to set SystemPartitionString. (%lx)\n", Status));
  508. }
  509. SpMemFree(SystemPartitionString);
  510. } else {
  511. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Failed to duplicate SystemPartitionString.\n"));
  512. }
  513. } else {
  514. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Failed to query SystemPartition Value.\n"));
  515. }
  516. } else {
  517. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Failed to Open HKLM while trying to query the SytemPartition Value.\n"));
  518. }
  519. #else
  520. PWSTR SystemPartitionString = 0;
  521. SpNtNameFromRegion( SystemPartitionRegion,
  522. TemporaryBuffer,
  523. sizeof(TemporaryBuffer),
  524. PartitionOrdinalCurrent );
  525. SystemPartitionString = SpDupStringW( TemporaryBuffer );
  526. if( SystemPartitionString ) {
  527. Status = SpOpenSetValueAndClose( HiveRootKeys[SetupHiveSystem],
  528. SETUP_KEY_NAME,
  529. L"SystemPartition",
  530. STRING_VALUE(SystemPartitionString) );
  531. if(!NT_SUCCESS(Status)) {
  532. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Failed to set SystemPartitionString. (%lx)\n", Status));
  533. }
  534. SpMemFree(SystemPartitionString);
  535. } else {
  536. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Failed to duplicate SystemPartitionString.\n"));
  537. }
  538. #endif
  539. }
  540. #endif
  541. //
  542. // Note that SpPostprocessHives() will always close KeyHandle
  543. //
  544. Status = SpPostprocessHives(
  545. PartitionPath,
  546. SystemRoot,
  547. HiveNames,
  548. HiveRootKeys,
  549. 3,
  550. KeyHandle
  551. );
  552. } else {
  553. //
  554. // If SpDoRegistryInitialization() fails, then we need to close KeyHandle here,
  555. // before we start unloading the hives.
  556. //
  557. NtClose(KeyHandle);
  558. }
  559. }
  560. SpDisplayStatusText(SP_STAT_REG_SAVING_HIVES,DEFAULT_STATUS_ATTRIBUTE);
  561. //
  562. // From now on, do not disturb the value of Status.
  563. //
  564. // NOTE: DO NOT WRITE ANYTHING INTO HIVES BEYOND THIS POINT!!!
  565. //
  566. // In the upgrade case we have performed a little swictheroo in
  567. // SpPostprocessHives() such that anything written to the system hive
  568. // ends up in system.sav instead of system!
  569. //
  570. for(h=0; h<SetupHiveMax; h++) {
  571. if(HiveRootKeys[h]) {
  572. ZwClose(HiveRootKeys[h]);
  573. }
  574. swprintf(pwstrTemp1,L"%ws\\x%ws",LOCAL_MACHINE_KEY_NAME,HiveNames[h]);
  575. SpLoadUnloadKey(NULL,NULL,pwstrTemp1,NULL);
  576. }
  577. SpMemFree(PartitionPath);
  578. if(!NT_SUCCESS(Status)) {
  579. SpDisplayScreen(SP_SCRN_REGISTRY_CONFIG_FAILED,3,HEADER_HEIGHT+1);
  580. SpDisplayStatusOptions(DEFAULT_STATUS_ATTRIBUTE,SP_STAT_F3_EQUALS_EXIT,0);
  581. SpInputDrain();
  582. while(SpInputGetKeypress() != KEY_F3) ;
  583. SpDone(0,FALSE,TRUE);
  584. }
  585. }
  586. NTSTATUS
  587. SpDoRegistryInitialization(
  588. IN PVOID SifHandle,
  589. IN PDISK_REGION TargetRegion,
  590. IN PWSTR PartitionPath,
  591. IN PWSTR SystemRoot,
  592. IN HANDLE *HiveRootKeys,
  593. IN PWSTR SetupSourceDevicePath,
  594. IN PWSTR DirectoryOnSourceDevice,
  595. IN PWSTR SpecialDevicePath, OPTIONAL
  596. IN HANDLE ControlSet
  597. )
  598. /*++
  599. Routine Description:
  600. Initialize a registry based on user selection for hardware types,
  601. software options, and user preferences.
  602. - Create a command line for GUI setup, to be used by winlogon.
  603. - Create/munge service list entries for device drivers being installed.
  604. - Initialize the keyboard layout.
  605. - Initialize a core set of fonts for use with Windows.
  606. - Store information about selected ahrdware components for use by GUI setup.
  607. Arguments:
  608. SifHandle - supplies handle to loaded setup information file.
  609. TargetRegion - supplies region descriptor for region to which the system
  610. is to be installed.
  611. PartitionPath - supplies the NT name for the drive of windows nt.
  612. SystemRoot - supplies nt path of the windows nt directory.
  613. HiveRootKeys - supplies the handles to the root key of the system, software
  614. and default hives
  615. HiveRootPaths - supplies the paths to the root keys of the system, software
  616. and default hives.
  617. SetupSourceDevicePath - supplies nt path to the device setup is using for
  618. source media (\device\floppy0, \device\cdrom0, etc).
  619. DirectoryOnSourceDevice - supplies the directory on the source device
  620. where setup files are kept.
  621. Return Value:
  622. Status value indicating outcome of operation.
  623. --*/
  624. {
  625. NTSTATUS Status;
  626. OBJECT_ATTRIBUTES Obja;
  627. UNICODE_STRING UnicodeString;
  628. HANDLE hKeyControlSetControl;
  629. PWSTR FullTargetPath;
  630. LPWSTR p;
  631. BOOLEAN b;
  632. ULONG SuiteMask = 0;
  633. PWSTR AdditionalGuiPnpDrivers;
  634. if(NTUpgrade != UpgradeFull) {
  635. b = SpHivesFromInfs(
  636. SifHandle,
  637. L"HiveInfs.Fresh",
  638. SetupSourceDevicePath,
  639. DirectoryOnSourceDevice,
  640. HiveRootKeys[SetupHiveSystem],
  641. HiveRootKeys[SetupHiveSoftware],
  642. HiveRootKeys[SetupHiveDefault],
  643. HiveRootKeys[SetupHiveUserdiff]
  644. );
  645. #if defined(REMOTE_BOOT)
  646. //
  647. // If this is a remote boot setup, process the AddReg.RemoteBoot
  648. // section in hivesys.inf and the AddReg section in winnt.sif.
  649. //
  650. if (b && RemoteBootSetup) {
  651. (VOID)SpHivesFromInfs(
  652. SifHandle,
  653. L"HiveInfs.Fresh.RemoteBoot",
  654. SetupSourceDevicePath,
  655. DirectoryOnSourceDevice,
  656. HiveRootKeys[SetupHiveSystem],
  657. HiveRootKeys[SetupHiveSoftware],
  658. HiveRootKeys[SetupHiveDefault],
  659. NULL
  660. );
  661. ASSERT(WinntSifHandle != NULL);
  662. (VOID)SpProcessAddRegSection(
  663. WinntSifHandle,
  664. L"AddReg",
  665. HiveRootKeys[SetupHiveSystem],
  666. HiveRootKeys[SetupHiveSoftware],
  667. HiveRootKeys[SetupHiveDefault],
  668. NULL
  669. );
  670. }
  671. #endif // defined(REMOTE_BOOT)
  672. if(!b) {
  673. Status = STATUS_UNSUCCESSFUL;
  674. goto sdoinitreg1;
  675. }
  676. }
  677. //
  678. // Open ControlSet\Control.
  679. //
  680. INIT_OBJA(&Obja,&UnicodeString,L"Control");
  681. Obja.RootDirectory = ControlSet;
  682. Status = ZwOpenKey(&hKeyControlSetControl,KEY_ALL_ACCESS,&Obja);
  683. if(!NT_SUCCESS(Status)) {
  684. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Unable to open CurrentControlSet\\Control (%lx)\n",Status));
  685. goto sdoinitreg1;
  686. }
  687. //
  688. // Save the Pid list
  689. //
  690. SpSaveSetupPidList( HiveRootKeys[SetupHiveSystem] );
  691. //
  692. // Form the setup command line.
  693. //
  694. wcscpy(TemporaryBuffer, PartitionPath);
  695. SpConcatenatePaths(TemporaryBuffer, SystemRoot);
  696. FullTargetPath = SpDupStringW(TemporaryBuffer);
  697. Status = SpFormSetupCommandLine(
  698. SifHandle,
  699. HiveRootKeys[SetupHiveSystem],
  700. SetupSourceDevicePath,
  701. DirectoryOnSourceDevice,
  702. FullTargetPath,
  703. SpecialDevicePath
  704. );
  705. SpMemFree(FullTargetPath);
  706. if(!NT_SUCCESS(Status)) {
  707. goto sdoinitreg3;
  708. }
  709. //
  710. // Save evalution time
  711. //
  712. Status = SpSaveSKUStuff(HiveRootKeys[SetupHiveSystem]);
  713. if(!NT_SUCCESS(Status)) {
  714. goto sdoinitreg3;
  715. }
  716. //
  717. // Set the product suite
  718. //
  719. SpGetProductSuiteMask(hKeyControlSetControl,&SuiteMask);
  720. //
  721. // Account for multiple suite bits being set in SuiteType.
  722. //
  723. // SuiteMask |= (1 << (SuiteType-1));
  724. //
  725. // there's one more problem: PERSONAL sku is identified by VER_SUITE_PERSONAL flag set
  726. // we want to be able to upgrade from PER to PRO, but PRO doesn't have any flag set
  727. // we also want to be able to upgrade from PER to PER, but in this case this bit will be set
  728. // in SuiteType; therefore it's safe to always clear this bit before applying the new mask
  729. //
  730. SuiteMask &= ~VER_SUITE_PERSONAL;
  731. SuiteMask |= SuiteType;
  732. SpSetProductSuite(hKeyControlSetControl,SuiteMask);
  733. //
  734. // Language/locale-specific registry initialization.
  735. //
  736. Status = SplangSetRegistryData(
  737. SifHandle,
  738. ControlSet,
  739. (NTUpgrade == UpgradeFull) ? NULL : HardwareComponents,
  740. (BOOLEAN)(NTUpgrade == UpgradeFull)
  741. );
  742. if(!NT_SUCCESS(Status)) {
  743. goto sdoinitreg3;
  744. }
  745. //
  746. // If we need to convert to ntfs, set that up here.
  747. // We can't use the PartitionPath since that is based on
  748. // *current* disk ordinal -- we need a name based on the *on-disk*
  749. // ordinal, since the convert occurs after a reboot. Moved it here
  750. // so that this is done for upgrades too.
  751. //
  752. if(ConvertNtVolumeToNtfs) {
  753. WCHAR GuidVolumeName[MAX_PATH] = {0};
  754. PWSTR VolumeName;
  755. wcscpy(TemporaryBuffer,L"autoconv ");
  756. VolumeName = TemporaryBuffer + wcslen(TemporaryBuffer);
  757. SpNtNameFromRegion(
  758. TargetRegion,
  759. VolumeName, // append to the "autoconv " we put there
  760. 512, // just need any reasonable size
  761. PartitionOrdinalCurrent
  762. );
  763. //
  764. // NOTE: Don't use volume GUIDs for file system conversion
  765. // for 9x upgrades.
  766. //
  767. if (WinUpgradeType == NoWinUpgrade) {
  768. //
  769. // Try to get hold of the \\??\Volume{a-b-c-d} format
  770. // volume name for the partition
  771. //
  772. Status = SpPtnGetGuidNameForPartition(VolumeName,
  773. GuidVolumeName);
  774. //
  775. // If GuidVolumeName is available then use that rather
  776. // than \device\harddiskX\partitionY since disk ids can
  777. // change across reboots
  778. //
  779. if (NT_SUCCESS(Status) && GuidVolumeName[0]) {
  780. wcscpy(VolumeName, GuidVolumeName);
  781. }
  782. }
  783. wcscat(TemporaryBuffer, L" /fs:NTFS");
  784. FullTargetPath = SpDupStringW(TemporaryBuffer);
  785. Status = SpAppendStringToMultiSz(
  786. ControlSet,
  787. SESSION_MANAGER_KEY,
  788. BOOT_EXECUTE,
  789. FullTargetPath
  790. );
  791. SpMemFree(FullTargetPath);
  792. }
  793. if(NTUpgrade == UpgradeFull) {
  794. SpSavePageFileInfo( hKeyControlSetControl,
  795. HiveRootKeys[SetupHiveSystem] );
  796. Status = SpUpgradeNTRegistry(
  797. SifHandle,
  798. HiveRootKeys,
  799. SetupSourceDevicePath,
  800. DirectoryOnSourceDevice,
  801. ControlSet
  802. );
  803. if(!NT_SUCCESS(Status)) {
  804. goto sdoinitreg3;
  805. }
  806. Status = SpProcessAddRegSection(
  807. WinntSifHandle,
  808. L"compatibility",
  809. HiveRootKeys[SetupHiveSystem],
  810. NULL,
  811. NULL,
  812. NULL
  813. );
  814. if (!NT_SUCCESS(Status)) {
  815. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Unable to process compatibility settings.\n"));
  816. }
  817. //
  818. // Disable all upper and lower level class filters for the services which were
  819. // disabled
  820. //
  821. Status = SpProcessServicesToDisable(WinntSifHandle,
  822. SP_SERVICES_TO_DISABLE,
  823. hKeyControlSetControl);
  824. if (!NT_SUCCESS(Status)) {
  825. KdPrintEx((DPFLTR_SETUP_ID,
  826. DPFLTR_ERROR_LEVEL,
  827. "SETUP: Unable to process ServicesToDisable section (%lx).\n",
  828. Status));
  829. }
  830. //
  831. // Remove all the upper and lower device instance filter drivers for keyboard and
  832. // mouse class drivers
  833. //
  834. Status = SpDeleteRequiredDeviceInstanceFilters(ControlSet);
  835. if (!NT_SUCCESS(Status)) {
  836. KdPrintEx((DPFLTR_SETUP_ID,
  837. DPFLTR_ERROR_LEVEL,
  838. "SETUP: Unable to unable to delete keyboard & mouse device filter drivers (%lx).\n",
  839. Status));
  840. }
  841. //
  842. // Set up font entries.
  843. //
  844. Status = SpConfigureFonts(SifHandle,HiveRootKeys[SetupHiveSoftware]);
  845. if(!NT_SUCCESS(Status)) {
  846. goto sdoinitreg3;
  847. }
  848. //
  849. // Enable detected scsi miniports, atdisk and abios disk, if necessary
  850. //
  851. Status = SpDriverLoadList(SifHandle,SystemRoot,HiveRootKeys[SetupHiveSystem],ControlSet);
  852. if(!NT_SUCCESS(Status)) {
  853. goto sdoinitreg3;
  854. }
  855. //
  856. // Disable the unsupported scsi drivers that need to be disabled
  857. //
  858. if( UnsupportedScsiHardwareToDisable != NULL ) {
  859. SpDisableUnsupportedScsiDrivers( ControlSet );
  860. }
  861. } else {
  862. if (IsNEC_98) { //NEC98
  863. //
  864. // NEC98 default drive assign for hard drive is start from A:,
  865. // so if it need to start from C: we should set "DriveLetter" KEY into hive.
  866. //
  867. if( !DriveAssignFromA ) {
  868. Status = SpOpenSetValueAndClose(HiveRootKeys[SetupHiveSystem],
  869. SETUP_KEY_NAME,
  870. L"DriveLetter",
  871. STRING_VALUE(L"C"));
  872. }
  873. if(!NT_SUCCESS(Status)) {
  874. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Unable to set system\\setup\\drive letter (%lx)\n",Status));
  875. return(Status);
  876. }
  877. } //NEC98
  878. //
  879. // Create service entries for drivers being installed
  880. // (ie, munge the driver load list).
  881. //
  882. Status = SpDriverLoadList(SifHandle,SystemRoot,HiveRootKeys[SetupHiveSystem],ControlSet);
  883. if(!NT_SUCCESS(Status)) {
  884. goto sdoinitreg3;
  885. }
  886. if (SpDrEnabled()) {
  887. Status = SpDrSetEnvironmentVariables(HiveRootKeys);
  888. if(!NT_SUCCESS(Status)) {
  889. goto sdoinitreg3;
  890. }
  891. }
  892. //
  893. // Set up the keyboard layout and nls-related stuff.
  894. //
  895. Status = SpConfigureNlsParameters(SifHandle,HiveRootKeys[SetupHiveDefault],hKeyControlSetControl);
  896. if(!NT_SUCCESS(Status)) {
  897. goto sdoinitreg3;
  898. }
  899. //
  900. // Set up font entries.
  901. //
  902. Status = SpConfigureFonts(SifHandle,HiveRootKeys[SetupHiveSoftware]);
  903. if(!NT_SUCCESS(Status)) {
  904. goto sdoinitreg3;
  905. }
  906. //
  907. // Store information used by gui setup, describing the hardware
  908. // selections made by the user.
  909. //
  910. Status = SpStoreHwInfoForSetup(hKeyControlSetControl);
  911. if(!NT_SUCCESS(Status)) {
  912. goto sdoinitreg3;
  913. }
  914. if( PreInstall ) {
  915. ULONG u;
  916. PWSTR OemPnpDriversDirPath;
  917. u = 1;
  918. SpSavePreinstallList( SifHandle,
  919. SystemRoot,
  920. HiveRootKeys[SetupHiveSystem] );
  921. Status = SpOpenSetValueAndClose( hKeyControlSetControl,
  922. L"Windows",
  923. L"NoPopupsOnBoot",
  924. ULONG_VALUE(u) );
  925. if(!NT_SUCCESS(Status)) {
  926. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Unable to set NoPopupOnBoot. Status = %lx \n",Status));
  927. }
  928. //
  929. // Add autolfn.exe to bootexecute list.
  930. //
  931. Status = SpAppendStringToMultiSz(
  932. ControlSet,
  933. SESSION_MANAGER_KEY,
  934. BOOT_EXECUTE,
  935. L"autolfn"
  936. );
  937. if(!NT_SUCCESS(Status)) {
  938. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Unable to add autolfn to BootExecute. Status = %lx \n",Status));
  939. goto sdoinitreg3;
  940. }
  941. //
  942. // If unattended file specifies path to OEM drivers directory, then append path
  943. // to HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion, DevicePath
  944. //
  945. OemPnpDriversDirPath = SpGetSectionKeyIndex(UnattendedSifHandle,
  946. SIF_UNATTENDED,
  947. WINNT_OEM_PNP_DRIVERS_PATH_W,
  948. 0);
  949. if( OemPnpDriversDirPath != NULL ) {
  950. Status = SpAppendPathToDevicePath( HiveRootKeys[SetupHiveSoftware], OemPnpDriversDirPath );
  951. if(!NT_SUCCESS(Status)) {
  952. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Unable to append %ls to DevicePath. Status = %lx \n",OemPnpDriversDirPath,Status));
  953. goto sdoinitreg3;
  954. }
  955. }
  956. }
  957. }
  958. SpSetPageFileInfo( SifHandle, hKeyControlSetControl, HiveRootKeys[SetupHiveSystem] );
  959. //
  960. // Skip migration of FTKeys in the win95 upgrade case. This is important in order to ensure that
  961. // drive letters are preserved. At the beginning of GUI mode, the mounted devices key will
  962. // be rebuilt using the data stored by win9xupg in the HKLM\System\DISK.
  963. //
  964. #ifdef _X86_
  965. if (WinUpgradeType != UpgradeWin95) {
  966. #endif
  967. //
  968. // Do the migration of HKEY_LOCAL_MACHINE\SYSTEM\DISK and HKEY_LOCAL_MACHINE\SYSTEM\MountedDevices
  969. // from the setup hive to the target hive (if these keys exist).
  970. //
  971. Status = SppMigrateFtKeys(HiveRootKeys[SetupHiveSystem]);
  972. if(!NT_SUCCESS(Status)) {
  973. goto sdoinitreg3;
  974. }
  975. #ifdef _X86_
  976. }
  977. #endif
  978. //
  979. // On a remote install, we do some registry cleanup before migrating
  980. // keys.
  981. //
  982. if (RemoteInstallSetup) {
  983. SppCleanupKeysFromRemoteInstall();
  984. }
  985. //
  986. // Do any cleanup on the system hive before we migrate it to the target
  987. // system hive.
  988. //
  989. SpCleanUpHive();
  990. //
  991. // Migrate some keys from the setup hive to the target system hive.
  992. //
  993. Status = SpMigrateSetupKeys( PartitionPath, SystemRoot, ControlSet, SifHandle );
  994. if( !NT_SUCCESS(Status) ) {
  995. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Unable to migrate registry keys from the setup hive to the target system hive. Status = %lx\n", Status));
  996. goto sdoinitreg3;
  997. }
  998. //
  999. // Disable Dynamic Volumes on portables and
  1000. // Whistler Personal
  1001. //
  1002. if( DockableMachine || SpIsProductSuite(VER_SUITE_PERSONAL)) {
  1003. NTSTATUS Status1;
  1004. Status1 = SppDisableDynamicVolumes(ControlSet);
  1005. if( !NT_SUCCESS( Status1 ) ) {
  1006. KdPrintEx((DPFLTR_SETUP_ID,
  1007. DPFLTR_ERROR_LEVEL,
  1008. "SETUP: Unable to disable dynamic volumes on laptop/personal builds. Status = %lx \n",
  1009. Status1));
  1010. }
  1011. }
  1012. //
  1013. // A side-effect of loading setupdd.sys is that Plug&Play generates a device instance
  1014. // key for it called "Root\LEGACY_SETUPDD\0000". Clean that up now. (No need to check
  1015. // the return status--if this fails it's no big deal.)
  1016. //
  1017. SppDeleteKeyRecursive(ControlSet,
  1018. L"Enum\\Root\\LEGACY_SETUPDD",
  1019. TRUE
  1020. );
  1021. //
  1022. // Delete the virtual RAM devices and driver keys
  1023. //
  1024. if (VirtualOemSourceDevices) {
  1025. //
  1026. // delete the root devnodes
  1027. //
  1028. SpDeleteRootDevnodeKeys(SifHandle,
  1029. ControlSet,
  1030. L"RootDevicesToDelete.clean",
  1031. NULL);
  1032. //
  1033. // Remove the service
  1034. //
  1035. SppDeleteKeyRecursive(ControlSet,
  1036. L"Services\\" RAMDISK_DRIVER_NAME,
  1037. TRUE);
  1038. }
  1039. #if defined(REMOTE_BOOT)
  1040. //
  1041. // Copy information that remote boot needs from the .sif to the
  1042. // registry.
  1043. //
  1044. if (RemoteBootSetup) {
  1045. (VOID)SpCopyRemoteBootKeyword(WinntSifHandle,
  1046. SIF_ENABLEIPSECURITY,
  1047. hKeyControlSetControl);
  1048. (VOID)SpCopyRemoteBootKeyword(WinntSifHandle,
  1049. SIF_REPARTITION,
  1050. hKeyControlSetControl);
  1051. }
  1052. #endif // defined(REMOTE_BOOT)
  1053. //
  1054. // Finally, if the answer file specifies a path list to additional GUI drivers,
  1055. // then append this path to the DevicePath value
  1056. //
  1057. AdditionalGuiPnpDrivers = SpGetSectionKeyIndex (
  1058. WinntSifHandle,
  1059. SIF_SETUPPARAMS,
  1060. WINNT_SP_DYNUPDTADDITIONALGUIDRIVERS_W,
  1061. 0
  1062. );
  1063. if (AdditionalGuiPnpDrivers) {
  1064. Status = SpAppendFullPathListToDevicePath (HiveRootKeys[SetupHiveSoftware], AdditionalGuiPnpDrivers);
  1065. if (!NT_SUCCESS(Status)) {
  1066. KdPrintEx ((
  1067. DPFLTR_SETUP_ID,
  1068. DPFLTR_ERROR_LEVEL,
  1069. "SETUP: Unable to append %ls to DevicePath. Status = %lx \n",
  1070. AdditionalGuiPnpDrivers,
  1071. Status
  1072. ));
  1073. goto sdoinitreg3;
  1074. }
  1075. }
  1076. sdoinitreg3:
  1077. ZwClose(hKeyControlSetControl);
  1078. sdoinitreg1:
  1079. return(Status);
  1080. }
  1081. NTSTATUS
  1082. SpFormSetupCommandLine(
  1083. IN PVOID SifHandle,
  1084. IN HANDLE hKeySystemHive,
  1085. IN PWSTR SetupSourceDevicePath,
  1086. IN PWSTR DirectoryOnSourceDevice,
  1087. IN PWSTR FullTargetPath,
  1088. IN PWSTR SpecialDevicePath OPTIONAL
  1089. )
  1090. /*++
  1091. Routine Description:
  1092. Create the command line to invoke GUI setup and store it in
  1093. HKEY_LOCAL_MACHINE\system\<ControlSet>\Setup:CmdLine.
  1094. The command line for the command to be launched depends
  1095. on whether NT Setup is executing within a disaster recovery
  1096. context, or a normal context. For the normal case, the
  1097. command line is is as follows:
  1098. setup -newsetup
  1099. For Automated System Recovery (ASR), the command line is
  1100. setup -newsetup -asr
  1101. For the automated ASR quick test, the command line is
  1102. setup - newsetup -asrquicktest
  1103. Arguments:
  1104. SifHandle - handle to the master sif (txtsetup.sif)
  1105. hKeySystemHive - supplies handle to root of the system hive
  1106. (ie, HKEY_LOCAL_MACHINE\System).
  1107. SetupSourceDevicePath - supplies the nt device path of the source media
  1108. to be used during setup (\device\floppy0, \device\cdrom0, etc).
  1109. DirectoryOnSourceDevice - supplies the directory on the source device
  1110. where setup files are kept.
  1111. FullTargetPath - supplies the NtPartitionName+SystemRoot path on the target device.
  1112. SpecialDevicePath - if specified, will be passed to setup as the value for
  1113. STF_SPECIAL_PATH. If not specified, STF_SPECIAL_PATH will be "NO"
  1114. Return Value:
  1115. Status value indicating outcome of operation.
  1116. --*/
  1117. {
  1118. PWSTR OptionalDirSpec = NULL;
  1119. PWSTR UserExecuteCmd = NULL;
  1120. PWSTR szLanManNt = WINNT_A_LANMANNT_W;
  1121. PWSTR szWinNt = WINNT_A_WINNT_W;
  1122. PWSTR szYes = WINNT_A_YES_W;
  1123. PWSTR szNo = WINNT_A_NO_W;
  1124. PWSTR SourcePathBuffer;
  1125. PWSTR CmdLine;
  1126. DWORD SetupType,SetupInProgress;
  1127. NTSTATUS Status;
  1128. PWSTR TargetFile;
  1129. PWSTR p;
  1130. WCHAR *Data[1];
  1131. //
  1132. // Can't use TemporaryBuffer because we make subroutine calls
  1133. // below that trash its contents.
  1134. //
  1135. CmdLine = SpMemAlloc(256);
  1136. CmdLine[0] = 0;
  1137. //
  1138. // Construct the setup command line. Start with the basic part.
  1139. // We first look in winnt.sif for this data, and if it isn't there, then
  1140. // we look in the sif handle which was input to us.
  1141. //
  1142. if(p = SpGetSectionKeyIndex(WinntSifHandle,SIF_SETUPDATA,SIF_SETUPCMDPREPEND,0)) {
  1143. wcscpy(CmdLine,p);
  1144. } else if(p = SpGetSectionKeyIndex(SifHandle,SIF_SETUPDATA,SIF_SETUPCMDPREPEND,0)) {
  1145. wcscpy(CmdLine,p);
  1146. }
  1147. // If we did get some parameter read in from unattend file, add separator.
  1148. //
  1149. if (*CmdLine)
  1150. wcscat(CmdLine,L" ");
  1151. //
  1152. // If this is ASR, append the appropriate cmd line options to GUI-mode Setup
  1153. //
  1154. if (SpDrEnabled()) {
  1155. if (ASRMODE_NORMAL == SpAsrGetAsrMode()) {
  1156. //
  1157. // This is normal ASR mode
  1158. //
  1159. wcscat(CmdLine, L"setup -newsetup -asr");
  1160. }
  1161. else {
  1162. //
  1163. // This is the Full Asr QuickTest
  1164. //
  1165. wcscat(CmdLine, L"setup -newsetup -asrquicktest");
  1166. }
  1167. } else {
  1168. wcscat( CmdLine,L"setup -newsetup" );
  1169. }
  1170. //
  1171. // Put the setup source in the command line.
  1172. // Note that the source is an NT-style name. GUI Setup handles this properly.
  1173. //
  1174. SourcePathBuffer = SpMemAlloc( (wcslen(SetupSourceDevicePath) +
  1175. wcslen(DirectoryOnSourceDevice) + 2) * sizeof(WCHAR) );
  1176. wcscpy(SourcePathBuffer,SetupSourceDevicePath);
  1177. if (!NoLs) {
  1178. SpConcatenatePaths(SourcePathBuffer,DirectoryOnSourceDevice);
  1179. }
  1180. //
  1181. // if we were given an administrator password via a remote install,
  1182. // we need to put this in the unattend file if appropriate.
  1183. //
  1184. if (NetBootAdministratorPassword) {
  1185. SpAddLineToSection(
  1186. WinntSifHandle,
  1187. SIF_GUI_UNATTENDED,
  1188. WINNT_US_ADMINPASS_W,
  1189. &NetBootAdministratorPassword,
  1190. 1);
  1191. }
  1192. SpAddLineToSection(WinntSifHandle,SIF_DATA,WINNT_D_SOURCEPATH_W,
  1193. &SourcePathBuffer,1);
  1194. //
  1195. // Put a flag indicating whether this is a win3.1 upgrade.
  1196. //
  1197. SpAddLineToSection(WinntSifHandle,SIF_DATA,WINNT_D_WIN31UPGRADE_W,
  1198. ( (WinUpgradeType == UpgradeWin31) ? &szYes : &szNo),1);
  1199. //
  1200. // Put a flag indicating whether this is a win95 upgrade.
  1201. //
  1202. SpAddLineToSection(WinntSifHandle,SIF_DATA,WINNT_D_WIN95UPGRADE_W,
  1203. ( (WinUpgradeType == UpgradeWin95) ? &szYes : &szNo),1);
  1204. //
  1205. // Put a flag indicating whether this is an NT upgrade.
  1206. //
  1207. SpAddLineToSection(WinntSifHandle,SIF_DATA,WINNT_D_NTUPGRADE_W,
  1208. ((NTUpgrade == UpgradeFull) ? &szYes : &szNo), 1);
  1209. //
  1210. // Put a flag indicating whether to upgrade a standard server
  1211. // (an existing standard server, or an existing workstation to
  1212. // a standard server)
  1213. //
  1214. SpAddLineToSection(WinntSifHandle,SIF_DATA,WINNT_D_SERVERUPGRADE_W,
  1215. (StandardServerUpgrade ? &szYes : &szNo),1);
  1216. //
  1217. // Tell gui mode whether this is server or workstation.
  1218. //
  1219. SpAddLineToSection(WinntSifHandle,SIF_DATA,WINNT_D_PRODUCT_W,
  1220. (AdvancedServer ? &szLanManNt : &szWinNt),1);
  1221. //
  1222. // Special path spec.
  1223. //
  1224. SpAddLineToSection(WinntSifHandle,SIF_DATA,WINNT_D_BOOTPATH_W,
  1225. (SpecialDevicePath ? &SpecialDevicePath : &szNo), 1);
  1226. //
  1227. // Go Fetch the Optional Dir Specs...
  1228. //
  1229. OptionalDirSpec = SpGetSectionKeyIndex(WinntSifHandle,SIF_SETUPPARAMS,
  1230. L"OptionalDirs",0);
  1231. //
  1232. // Check for commad line to execute at end of gui setup
  1233. //
  1234. UserExecuteCmd = SpGetSectionKeyIndex(WinntSifHandle,SIF_SETUPPARAMS,
  1235. L"UserExecute",0);
  1236. //
  1237. // Unattended mode flag | script filename
  1238. //
  1239. SpAddLineToSection(WinntSifHandle,SIF_DATA,WINNT_D_INSTALL_W,
  1240. ((UnattendedOperation || UnattendedGuiOperation || SpDrEnabled()) ? &szYes : &szNo), 1);
  1241. //
  1242. // If this is ASR, write out the Networking sections to allow
  1243. // GUI-mode to be unattended
  1244. //
  1245. if (SpDrEnabled()) {
  1246. SpAddLineToSection(WinntSifHandle,L"Networking",L"InstallDefaultComponents",&szYes,1);
  1247. Data[0]=L"WORKGROUP";
  1248. SpAddLineToSection(WinntSifHandle,L"Identification",L"JoinWorkgroup",Data,1);
  1249. }
  1250. //
  1251. // Write the name of OEM inf files, if any.
  1252. //
  1253. if( OemInfFileList != NULL ) {
  1254. PWSTR OemDriversKeyName = WINNT_OEMDRIVERS_W; // L"OemDrivers";
  1255. PWSTR OemDriverPathName = WINNT_OEMDRIVERS_PATHNAME_W; // L"OemDriverPathName";
  1256. PWSTR OemInfName = WINNT_OEMDRIVERS_INFNAME_W; // L"OemInfName";
  1257. PWSTR OemDriverFlags = WINNT_OEMDRIVERS_FLAGS_W;
  1258. PWSTR OemInfSectionName = L"OemInfFiles";
  1259. PWSTR szOne = L"1";
  1260. PWSTR p;
  1261. PWSTR *r;
  1262. ULONG NumberOfInfFiles;
  1263. POEM_INF_FILE q;
  1264. ULONG i;
  1265. SpAddLineToSection(WinntSifHandle, SIF_DATA, OemDriversKeyName, &OemInfSectionName, 1);
  1266. wcscpy( TemporaryBuffer, L"%SystemRoot%" );
  1267. SpConcatenatePaths( TemporaryBuffer, OemDirName );
  1268. p = SpDupStringW( TemporaryBuffer );
  1269. SpAddLineToSection(WinntSifHandle, OemInfSectionName, OemDriverPathName, &p, 1);
  1270. SpMemFree( p );
  1271. SpAddLineToSection(WinntSifHandle, OemInfSectionName, OemDriverFlags, &szOne, 1);
  1272. for( q = OemInfFileList, NumberOfInfFiles = 0;
  1273. q != NULL;
  1274. q = q->Next, NumberOfInfFiles++ );
  1275. r = SpMemAlloc( NumberOfInfFiles * sizeof( PWSTR ) );
  1276. for( q = OemInfFileList, i = 0;
  1277. q != NULL;
  1278. r[i] = q->InfName, q = q->Next, i++ );
  1279. SpAddLineToSection(WinntSifHandle,OemInfSectionName, OemInfName, r, NumberOfInfFiles);
  1280. SpMemFree( r );
  1281. }
  1282. //
  1283. // Before we write the answer to this, we need to know if we successfully
  1284. // have written Winnt.sif into system32\$winnt$.inf
  1285. //
  1286. wcscpy(TemporaryBuffer, FullTargetPath);
  1287. SpConcatenatePaths(TemporaryBuffer, L"system32");
  1288. SpConcatenatePaths(TemporaryBuffer, SIF_UNATTENDED_INF_FILE);
  1289. TargetFile = SpDupStringW(TemporaryBuffer);
  1290. Status = SpWriteSetupTextFile(WinntSifHandle,TargetFile,NULL,NULL);
  1291. if(NT_SUCCESS(Status)) {
  1292. Status = SpOpenSetValueAndClose(
  1293. hKeySystemHive,
  1294. SETUP_KEY_NAME,
  1295. L"CmdLine",
  1296. STRING_VALUE(CmdLine)
  1297. );
  1298. }
  1299. //
  1300. // Free up whatever memory we have allocated
  1301. //
  1302. SpMemFree(TargetFile);
  1303. SpMemFree(CmdLine);
  1304. SpMemFree(SourcePathBuffer);
  1305. if(!NT_SUCCESS(Status)) {
  1306. return(Status);
  1307. }
  1308. //
  1309. // Set the SetupType value to the right value SETUPTYPE_FULL in the
  1310. // case of initial install and SETUPTYPE_UPGRADE in the case of upgrade.
  1311. //
  1312. SetupType = (NTUpgrade == UpgradeFull) ? SETUPTYPE_UPGRADE : SETUPTYPE_FULL;
  1313. Status = SpOpenSetValueAndClose(
  1314. hKeySystemHive,
  1315. SETUP_KEY_NAME,
  1316. L"SetupType",
  1317. ULONG_VALUE(SetupType)
  1318. );
  1319. if(!NT_SUCCESS(Status)) {
  1320. return(Status);
  1321. }
  1322. //
  1323. // Set the SystemSetupInProgress value. Don't rely on the default hives
  1324. // having this set
  1325. //
  1326. SetupInProgress = 1;
  1327. Status = SpOpenSetValueAndClose(
  1328. hKeySystemHive,
  1329. SETUP_KEY_NAME,
  1330. L"SystemSetupInProgress",
  1331. ULONG_VALUE(SetupInProgress)
  1332. );
  1333. return(Status);
  1334. }
  1335. NTSTATUS
  1336. SpDriverLoadList(
  1337. IN PVOID SifHandle,
  1338. IN PWSTR SystemRoot,
  1339. IN HANDLE hKeySystemHive,
  1340. IN HANDLE hKeyControlSet
  1341. )
  1342. {
  1343. NTSTATUS Status;
  1344. OBJECT_ATTRIBUTES Obja;
  1345. UNICODE_STRING UnicodeString;
  1346. HANDLE hKeyControlSetServices;
  1347. PHARDWARE_COMPONENT ScsiHwComponent;
  1348. // PHARDWARE_COMPONENT TempExtender;
  1349. ULONG u;
  1350. ULONG i;
  1351. PHARDWARE_COMPONENT TempHw;
  1352. PHARDWARE_COMPONENT DeviceLists[] = {
  1353. BootBusExtenders,
  1354. BusExtenders,
  1355. InputDevicesSupport
  1356. };
  1357. PWSTR SectionNames[] = {
  1358. SIF_BOOTBUSEXTENDERS,
  1359. SIF_BUSEXTENDERS,
  1360. SIF_INPUTDEVICESSUPPORT
  1361. };
  1362. PWSTR ServiceGroupNames[] = {
  1363. L"Boot Bus Extender",
  1364. L"System Bus Extender",
  1365. NULL
  1366. };
  1367. ULONG StartValues[] = {
  1368. SERVICE_BOOT_START,
  1369. SERVICE_BOOT_START,
  1370. SERVICE_DEMAND_START
  1371. };
  1372. //
  1373. // Open controlset\services.
  1374. //
  1375. INIT_OBJA(&Obja,&UnicodeString,L"services");
  1376. Obja.RootDirectory = hKeyControlSet;
  1377. Status = ZwCreateKey(
  1378. &hKeyControlSetServices,
  1379. KEY_ALL_ACCESS,
  1380. &Obja,
  1381. 0,
  1382. NULL,
  1383. REG_OPTION_NON_VOLATILE,
  1384. NULL
  1385. );
  1386. if(!NT_SUCCESS(Status)) {
  1387. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: unable to open services key (%lx)\n",Status));
  1388. return(Status);
  1389. }
  1390. //
  1391. // For each non-third-party miniport driver that loaded,
  1392. // go create a services entry for it.
  1393. //
  1394. if( !PreInstall ||
  1395. ( PreinstallScsiHardware == NULL ) ) {
  1396. ScsiHwComponent = ScsiHardware;
  1397. } else {
  1398. ScsiHwComponent = PreinstallScsiHardware;
  1399. }
  1400. for( ; ScsiHwComponent; ScsiHwComponent=ScsiHwComponent->Next) {
  1401. if(!ScsiHwComponent->ThirdPartyOptionSelected) {
  1402. //
  1403. // For scsi, the shortname (idstring) is used as
  1404. // the name of the service node key in the registry --
  1405. // we don't look up the service entry in the [SCSI] section
  1406. // of the setup info file.
  1407. //
  1408. Status = SpCreateServiceEntryIndirect(
  1409. hKeyControlSetServices,
  1410. NULL,
  1411. NULL,
  1412. ScsiHwComponent->IdString,
  1413. SERVICE_KERNEL_DRIVER,
  1414. SERVICE_BOOT_START,
  1415. L"SCSI miniport",
  1416. SERVICE_ERROR_NORMAL,
  1417. NULL,
  1418. NULL
  1419. );
  1420. if(!NT_SUCCESS(Status)) {
  1421. goto spdrvlist1;
  1422. }
  1423. }
  1424. }
  1425. //
  1426. // If there are any atdisks out there, enable atdisk.
  1427. // We have to enable AtDisk if Pcmcia was loaded, even
  1428. // if atdisk doesn't exist. This will allow the user to
  1429. // insert a pcmcia atdisk device, and have it work when
  1430. // they boot. In this case, however, we turn off error
  1431. // logging, so that they won't get an annoying popup
  1432. // when there is no atdisk device in the card slot.
  1433. //
  1434. // Note that atdisk.sys is always copied to the system.
  1435. //
  1436. Status = SpCreateServiceEntryIndirect(
  1437. hKeyControlSetServices,
  1438. NULL,
  1439. NULL,
  1440. ATDISK_NAME,
  1441. SERVICE_KERNEL_DRIVER,
  1442. ( AtDisksExist )? SERVICE_BOOT_START : SERVICE_DISABLED,
  1443. PRIMARY_DISK_GROUP,
  1444. ( AtDisksExist && !AtapiLoaded )? SERVICE_ERROR_NORMAL : SERVICE_ERROR_IGNORE,
  1445. NULL,
  1446. NULL
  1447. );
  1448. if(!NT_SUCCESS(Status)) {
  1449. goto spdrvlist1;
  1450. }
  1451. //
  1452. // If there are any abios disks out there, enable abiosdsk.
  1453. //
  1454. if(AbiosDisksExist) {
  1455. Status = SpCreateServiceEntryIndirect(
  1456. hKeyControlSetServices,
  1457. NULL,
  1458. NULL,
  1459. ABIOSDISK_NAME,
  1460. SERVICE_KERNEL_DRIVER,
  1461. SERVICE_BOOT_START,
  1462. PRIMARY_DISK_GROUP,
  1463. SERVICE_ERROR_NORMAL,
  1464. NULL,
  1465. NULL
  1466. );
  1467. if(!NT_SUCCESS(Status)) {
  1468. goto spdrvlist1;
  1469. }
  1470. }
  1471. //
  1472. // For each bus enumerator driver that loaded,
  1473. // go create a services entry for it.
  1474. //
  1475. for( i = 0; i < sizeof(DeviceLists) / sizeof(PDETECTED_DEVICE); i++ ) {
  1476. for( TempHw = DeviceLists[i]; TempHw; TempHw=TempHw->Next) {
  1477. //
  1478. // For bus extenders and input devices, the shortname (idstring) is used as
  1479. // the name of the service node key in the registry --
  1480. // we don't look up the service entry in the [BusExtenders] or [InputDevicesSupport] section
  1481. // of the setup info file.
  1482. //
  1483. Status = SpCreateServiceEntryIndirect(
  1484. hKeyControlSetServices,
  1485. SifHandle,
  1486. SectionNames[i],
  1487. TempHw->IdString,
  1488. SERVICE_KERNEL_DRIVER,
  1489. StartValues[i],
  1490. ServiceGroupNames[i],
  1491. SERVICE_ERROR_NORMAL,
  1492. NULL,
  1493. NULL
  1494. );
  1495. if(!NT_SUCCESS(Status)) {
  1496. goto spdrvlist1;
  1497. }
  1498. }
  1499. }
  1500. if( NTUpgrade != UpgradeFull ) {
  1501. //
  1502. // Set up video parameters.
  1503. //
  1504. Status = SpWriteVideoParameters(SifHandle,hKeyControlSetServices);
  1505. if(!NT_SUCCESS(Status)) {
  1506. goto spdrvlist1;
  1507. }
  1508. //
  1509. // Enable the relevent keyboard and mouse drivers. If the class drivers
  1510. // are being replaced by third-party ones, then disable the built-in ones.
  1511. //
  1512. Status = SpConfigureMouseKeyboardDrivers(
  1513. SifHandle,
  1514. HwComponentKeyboard,
  1515. L"kbdclass",
  1516. hKeyControlSetServices,
  1517. KEYBOARD_PORT_GROUP
  1518. );
  1519. if(!NT_SUCCESS(Status)) {
  1520. goto spdrvlist1;
  1521. }
  1522. Status = SpConfigureMouseKeyboardDrivers(
  1523. SifHandle,
  1524. HwComponentMouse,
  1525. L"mouclass",
  1526. hKeyControlSetServices,
  1527. POINTER_PORT_GROUP
  1528. );
  1529. if(!NT_SUCCESS(Status)) {
  1530. goto spdrvlist1;
  1531. }
  1532. }
  1533. Status = SpThirdPartyRegistry(hKeyControlSetServices);
  1534. spdrvlist1:
  1535. ZwClose(hKeyControlSetServices);
  1536. return(Status);
  1537. }
  1538. NTSTATUS
  1539. SpSaveSKUStuff(
  1540. IN HANDLE hKeySystemHive
  1541. )
  1542. {
  1543. LARGE_INTEGER l;
  1544. NTSTATUS Status;
  1545. ULONG NumberOfProcessors;
  1546. BOOLEAN OldStyleRegisteredProcessorMode;
  1547. //
  1548. // Do not change any of this algorithm without changing
  1549. // SetUpEvaluationSKUStuff() in syssetup.dll (registry.c).
  1550. //
  1551. // Embed the evaluation time and a bool indicating whether
  1552. // this is a server or workstation inside a random large integer.
  1553. //
  1554. // Evaluation time: bits 13-44
  1555. // Product type : bit 58
  1556. //
  1557. // Bit 10 == 1 : Setup works as it does before the 4.0 restriction logic
  1558. // == 0 : GUI Setup writes registered processors based on the
  1559. // contents of bits 5-9
  1560. //
  1561. // Bits 5 - 9 : The maximum number of processors that the system is licensed
  1562. // to use. The value stored is actually ~(MaxProcessors-1)
  1563. //
  1564. //
  1565. // RestrictCpu is used to build protucts this place a very hard
  1566. // limit on the number of processors
  1567. //
  1568. // - a value of 0 means for NTW, the hard limit is 2, and for NTS,
  1569. // the hard limit is 4
  1570. //
  1571. // - a value of 1-32 means that the hard limit is the number
  1572. // specified
  1573. //
  1574. // - a value > 32 means that the hard limit is 32 processors and GUI
  1575. // setup operates on registered processors as it does today
  1576. //
  1577. l.LowPart = SpComputeSerialNumber();
  1578. l.HighPart = SpComputeSerialNumber();
  1579. l.QuadPart &= 0xfbffe0000000181f;
  1580. l.QuadPart |= ((ULONGLONG)EvaluationTime) << 13;
  1581. if ( RestrictCpu == 0 ) {
  1582. //
  1583. // NTW and NTS will take this path using setupreg.hiv/setupret.hiv
  1584. //
  1585. OldStyleRegisteredProcessorMode = FALSE;
  1586. //
  1587. // new licensing model says that whistler is a 2 cpu system, not 4
  1588. //
  1589. NumberOfProcessors = 2;
  1590. //NumberOfProcessors = (AdvancedServer ? 4 : 2);
  1591. } else if ( RestrictCpu <= 32 ) {
  1592. //
  1593. // NTS/EE/DTC will take this path using a hive targetted at 8/16 CPU.
  1594. //
  1595. OldStyleRegisteredProcessorMode = FALSE;
  1596. NumberOfProcessors = RestrictCpu;
  1597. } else {
  1598. OldStyleRegisteredProcessorMode = TRUE;
  1599. NumberOfProcessors = 32;
  1600. }
  1601. //
  1602. // Now NumberOfProcessors is correct. Convert it to the in registry format
  1603. //
  1604. NumberOfProcessors--;
  1605. NumberOfProcessors = ~NumberOfProcessors;
  1606. NumberOfProcessors = NumberOfProcessors << 5;
  1607. NumberOfProcessors &= 0x000003e0;
  1608. //
  1609. // Store NumberOfProcessors into the registry
  1610. //
  1611. l.LowPart |= NumberOfProcessors;
  1612. //
  1613. // Tell Gui Mode to do old style registered processors
  1614. //
  1615. if ( OldStyleRegisteredProcessorMode ) {
  1616. l.LowPart |= 0x00000400;
  1617. }
  1618. if(AdvancedServer) {
  1619. l.HighPart |= 0x04000000;
  1620. }
  1621. //
  1622. // Save in registry.
  1623. //
  1624. Status = SpOpenSetValueAndClose(
  1625. hKeySystemHive,
  1626. SETUP_KEY_NAME,
  1627. L"SystemPrefix",
  1628. REG_BINARY,
  1629. &l.QuadPart,
  1630. sizeof(ULONGLONG)
  1631. );
  1632. if(!NT_SUCCESS(Status)) {
  1633. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Unable to set SystemPrefix (%lx)\n",Status));
  1634. }
  1635. return(Status);
  1636. }
  1637. NTSTATUS
  1638. SpSetUlongValueFromSif(
  1639. IN PVOID SifHandle,
  1640. IN PWSTR SifSection,
  1641. IN PWSTR SifKey,
  1642. IN ULONG SifIndex,
  1643. IN HANDLE hKey,
  1644. IN PWSTR ValueName
  1645. )
  1646. {
  1647. UNICODE_STRING UnicodeString;
  1648. PWSTR ValueString;
  1649. LONG Value;
  1650. NTSTATUS Status;
  1651. //
  1652. // Look up the value.
  1653. //
  1654. ValueString = SpGetSectionKeyIndex(SifHandle,SifSection,SifKey,SifIndex);
  1655. if(!ValueString) {
  1656. SpFatalSifError(SifHandle,SifSection,SifKey,0,SifIndex);
  1657. }
  1658. Value = SpStringToLong(ValueString,NULL,10);
  1659. if(Value == -1) {
  1660. Status = STATUS_SUCCESS;
  1661. } else {
  1662. RtlInitUnicodeString(&UnicodeString,ValueName);
  1663. Status = ZwSetValueKey(hKey,&UnicodeString,0,ULONG_VALUE((ULONG)Value));
  1664. if(!NT_SUCCESS(Status)) {
  1665. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Unable to set value %ws (%lx)\n",ValueName,Status));
  1666. }
  1667. }
  1668. return(Status);
  1669. }
  1670. NTSTATUS
  1671. SpConfigureMouseKeyboardDrivers(
  1672. IN PVOID SifHandle,
  1673. IN ULONG HwComponent,
  1674. IN PWSTR ClassServiceName,
  1675. IN HANDLE hKeyControlSetServices,
  1676. IN PWSTR ServiceGroup
  1677. )
  1678. {
  1679. PHARDWARE_COMPONENT hw;
  1680. NTSTATUS Status;
  1681. ULONG val = SERVICE_DISABLED;
  1682. Status = STATUS_SUCCESS;
  1683. if( !PreInstall ||
  1684. ( PreinstallHardwareComponents[HwComponent] == NULL ) ) {
  1685. hw = HardwareComponents[HwComponent];
  1686. } else {
  1687. hw = PreinstallHardwareComponents[HwComponent];
  1688. }
  1689. for(;hw && NT_SUCCESS( Status ); hw=hw->Next) {
  1690. if(hw->ThirdPartyOptionSelected) {
  1691. if(IS_FILETYPE_PRESENT(hw->FileTypeBits,HwFileClass)) {
  1692. if( !PreInstall ) {
  1693. //
  1694. // Disable the built-in class driver.
  1695. //
  1696. Status = SpOpenSetValueAndClose(
  1697. hKeyControlSetServices,
  1698. ClassServiceName,
  1699. L"Start",
  1700. ULONG_VALUE(val)
  1701. );
  1702. }
  1703. }
  1704. } else {
  1705. Status = SpCreateServiceEntryIndirect(
  1706. hKeyControlSetServices,
  1707. SifHandle,
  1708. NonlocalizedComponentNames[HwComponent],
  1709. hw->IdString,
  1710. SERVICE_KERNEL_DRIVER,
  1711. SERVICE_SYSTEM_START,
  1712. ServiceGroup,
  1713. SERVICE_ERROR_IGNORE,
  1714. NULL,
  1715. NULL
  1716. );
  1717. }
  1718. }
  1719. return(Status);
  1720. }
  1721. NTSTATUS
  1722. SpWriteVideoParameters(
  1723. IN PVOID SifHandle,
  1724. IN HANDLE hKeyControlSetServices
  1725. )
  1726. {
  1727. NTSTATUS Status;
  1728. PWSTR KeyName;
  1729. HANDLE hKeyDisplayService;
  1730. OBJECT_ATTRIBUTES Obja;
  1731. UNICODE_STRING UnicodeString;
  1732. ULONG x,y,b,v,i;
  1733. PHARDWARE_COMPONENT pHw;
  1734. if( !PreInstall ||
  1735. ( PreinstallHardwareComponents[HwComponentDisplay] == NULL ) ) {
  1736. pHw = HardwareComponents[HwComponentDisplay];
  1737. } else {
  1738. pHw = PreinstallHardwareComponents[HwComponentDisplay];
  1739. }
  1740. Status = STATUS_SUCCESS;
  1741. for(;pHw && NT_SUCCESS(Status);pHw=pHw->Next) {
  1742. //
  1743. // Third party drivers will have values written into the miniport
  1744. // Device0 key at the discretion of the txtsetup.oem author.
  1745. //
  1746. if(pHw->ThirdPartyOptionSelected) {
  1747. continue;
  1748. // return(STATUS_SUCCESS);
  1749. }
  1750. KeyName = SpGetSectionKeyIndex(
  1751. SifHandle,
  1752. NonlocalizedComponentNames[HwComponentDisplay],
  1753. pHw->IdString,
  1754. INDEX_INFKEYNAME
  1755. );
  1756. //
  1757. // If no key name is specified for this display then there's nothing to do.
  1758. // The setup display subsystem can tell us that the mode parameters are
  1759. // not relevent. If so there's nothing to do.
  1760. //
  1761. if(!KeyName || !SpvidGetModeParams(&x,&y,&b,&v,&i)) {
  1762. continue;
  1763. // return(STATUS_SUCCESS);
  1764. }
  1765. //
  1766. // We want to write the parameters for the display mode setup
  1767. // is using into the relevent key in the service list. This will force
  1768. // the right mode for, say, a fixed-frequency monitor attached to
  1769. // a vxl (which might default to a mode not supported by the monitor).
  1770. //
  1771. INIT_OBJA(&Obja,&UnicodeString,KeyName);
  1772. Obja.RootDirectory = hKeyControlSetServices;
  1773. Status = ZwCreateKey(
  1774. &hKeyDisplayService,
  1775. KEY_ALL_ACCESS,
  1776. &Obja,
  1777. 0,
  1778. NULL,
  1779. REG_OPTION_NON_VOLATILE,
  1780. NULL
  1781. );
  1782. if(!NT_SUCCESS(Status)) {
  1783. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: unable to open/create key %ws (%lx)\n",KeyName,Status));
  1784. return(Status);
  1785. }
  1786. //
  1787. // Set the x resolution.
  1788. //
  1789. Status = SpOpenSetValueAndClose(
  1790. hKeyDisplayService,
  1791. VIDEO_DEVICE0,
  1792. L"DefaultSettings.XResolution",
  1793. ULONG_VALUE(x)
  1794. );
  1795. if(NT_SUCCESS(Status)) {
  1796. //
  1797. // Set the y resolution.
  1798. //
  1799. Status = SpOpenSetValueAndClose(
  1800. hKeyDisplayService,
  1801. VIDEO_DEVICE0,
  1802. L"DefaultSettings.YResolution",
  1803. ULONG_VALUE(y)
  1804. );
  1805. if(NT_SUCCESS(Status)) {
  1806. //
  1807. // Set the bits per pixel.
  1808. //
  1809. Status = SpOpenSetValueAndClose(
  1810. hKeyDisplayService,
  1811. VIDEO_DEVICE0,
  1812. L"DefaultSettings.BitsPerPel",
  1813. ULONG_VALUE(b)
  1814. );
  1815. if(NT_SUCCESS(Status)) {
  1816. //
  1817. // Set the vertical refresh.
  1818. //
  1819. Status = SpOpenSetValueAndClose(
  1820. hKeyDisplayService,
  1821. VIDEO_DEVICE0,
  1822. L"DefaultSettings.VRefresh",
  1823. ULONG_VALUE(v)
  1824. );
  1825. if(NT_SUCCESS(Status)) {
  1826. //
  1827. // Set the interlaced flag.
  1828. //
  1829. Status = SpOpenSetValueAndClose(
  1830. hKeyDisplayService,
  1831. VIDEO_DEVICE0,
  1832. L"DefaultSettings.Interlaced",
  1833. ULONG_VALUE(i)
  1834. );
  1835. }
  1836. }
  1837. }
  1838. }
  1839. ZwClose(hKeyDisplayService);
  1840. }
  1841. return(Status);
  1842. }
  1843. NTSTATUS
  1844. SpConfigureNlsParameters(
  1845. IN PVOID SifHandle,
  1846. IN HANDLE hKeyDefaultHive,
  1847. IN HANDLE hKeyControlSetControl
  1848. )
  1849. /*++
  1850. Routine Description:
  1851. This routine configures NLS-related stuff in the registry:
  1852. - a keyboard layout
  1853. - the primary ansi, oem, and mac codepages
  1854. - the language casetable
  1855. - the oem hal font
  1856. Arguments:
  1857. SifHandle - supplies handle to open setup information file.
  1858. hKeyDefaultHive - supplies handle to root of default user hive.
  1859. hKeyControlSetControl - supplies handle to the Control subkey of
  1860. the control set being operated on.
  1861. Return Value:
  1862. Status value indicating outcome of operation.
  1863. --*/
  1864. {
  1865. PHARDWARE_COMPONENT_FILE HwFile;
  1866. PWSTR LayoutId;
  1867. NTSTATUS Status;
  1868. HANDLE hKeyNls;
  1869. PWSTR OemHalFont;
  1870. OBJECT_ATTRIBUTES Obja;
  1871. UNICODE_STRING UnicodeString;
  1872. PWSTR IntlLayoutId, LayoutText, LayoutFile, SubKey;
  1873. //
  1874. // We don't allow third-party keyboard layouts.
  1875. //
  1876. ASSERT(!HardwareComponents[HwComponentLayout]->ThirdPartyOptionSelected);
  1877. //
  1878. // Make an entry in the keyboard layout section in the default user hive.
  1879. // This will match an entry in HKLM\CCS\Control\Nls\Keyboard Layouts,
  1880. // which is 'preloaded' with all the possible layouts.
  1881. //
  1882. if( !PreInstall ||
  1883. (PreinstallHardwareComponents[HwComponentLayout] == NULL) ) {
  1884. LayoutId = HardwareComponents[HwComponentLayout]->IdString;
  1885. } else {
  1886. LayoutId = PreinstallHardwareComponents[HwComponentLayout]->IdString;
  1887. }
  1888. Status = SpOpenSetValueAndClose(
  1889. hKeyDefaultHive,
  1890. L"Keyboard Layout\\Preload",
  1891. L"1",
  1892. STRING_VALUE(LayoutId)
  1893. );
  1894. if(!NT_SUCCESS(Status)) {
  1895. return(Status);
  1896. }
  1897. //
  1898. // Add 3 entries into the registry here. our entries will be:
  1899. // 1. HKLM\System\CurrentControlSet\Control\Keyboard Layouts\LayoutId\Layout File
  1900. // 2. HKLM\System\CurrentControlSet\Control\Keyboard Layouts\LayoutId\Layout Id
  1901. // 3. HKLM\System\CurrentControlSet\Control\Keyboard Layouts\LayoutId\Layout Text
  1902. //
  1903. wcscpy( TemporaryBuffer, L"Keyboard Layouts" );
  1904. SpConcatenatePaths( TemporaryBuffer, LayoutId );
  1905. SubKey = SpDupStringW(TemporaryBuffer);
  1906. //
  1907. // First, do the "Layout File" key.
  1908. //
  1909. LayoutFile = SpGetSectionKeyIndex(
  1910. SifHandle, // txtsetup.sif
  1911. SIF_KEYBOARDLAYOUTFILES,// Files.KeyboardLayout
  1912. LayoutId, // IdString
  1913. 0 // 0
  1914. );
  1915. if(!LayoutFile) {
  1916. SpFatalSifError(
  1917. SifHandle,
  1918. SIF_KEYBOARDLAYOUTFILES,
  1919. LayoutId,
  1920. 0,
  1921. INDEX_DESCRIPTION
  1922. );
  1923. //
  1924. // Should not come here, but lets make prefix happy
  1925. //
  1926. return STATUS_NO_SUCH_FILE;
  1927. }
  1928. Status = SpOpenSetValueAndClose(
  1929. hKeyControlSetControl, // Handle to ControlSet\Control
  1930. SubKey, // \Keyboard Layouts\LayoutId
  1931. L"Layout File", // ValueName
  1932. REG_SZ, // ValueType
  1933. LayoutFile, // Value
  1934. (wcslen(LayoutFile)+1)*sizeof(WCHAR) // ValueSize
  1935. );
  1936. if(!NT_SUCCESS(Status)) {
  1937. return(Status);
  1938. }
  1939. //
  1940. // Next, do the "\Keyboard layouts\Layout Text" key.
  1941. //
  1942. LayoutText = SpGetSectionKeyIndex(
  1943. SifHandle, // txtsetup.sif
  1944. SIF_KEYBOARDLAYOUT, // Keyboard Layout
  1945. LayoutId, // IdString
  1946. 0 // 0
  1947. );
  1948. if(!LayoutText) {
  1949. SpFatalSifError(
  1950. SifHandle,
  1951. SIF_KEYBOARDLAYOUT,
  1952. LayoutId,
  1953. 0,
  1954. INDEX_DESCRIPTION
  1955. );
  1956. }
  1957. Status = SpOpenSetValueAndClose(
  1958. hKeyControlSetControl, // Handle to ControlSet\Control
  1959. SubKey, // \Keyboard Layouts\LayoutId
  1960. L"Layout Text", // ValueName
  1961. REG_SZ, // ValueType
  1962. LayoutText, // Value
  1963. (wcslen(LayoutText)+1)*sizeof(WCHAR) // ValueSize
  1964. );
  1965. if(!NT_SUCCESS(Status)) {
  1966. return(Status);
  1967. }
  1968. //
  1969. // Lastly, do the "\Keyboard layouts\Layout Id" key.
  1970. //
  1971. IntlLayoutId = SpGetSectionKeyIndex(
  1972. SifHandle, // txtsetup.sif
  1973. L"KeyboardLayoutId", // KeyboardLayoutId
  1974. LayoutId, // IdString
  1975. 0 // 0
  1976. );
  1977. //
  1978. // There may legitimatley not be one...
  1979. //
  1980. if(IntlLayoutId) {
  1981. Status = SpOpenSetValueAndClose(
  1982. hKeyControlSetControl, // Handle to ControlSet\Control
  1983. SubKey, // \Keyboard Layouts\LayoutId
  1984. L"Layout Id", // ValueName
  1985. REG_SZ, // ValueType
  1986. IntlLayoutId, // Value
  1987. (wcslen(IntlLayoutId)+1)*sizeof(WCHAR) // ValueSize
  1988. );
  1989. if(!NT_SUCCESS(Status)) {
  1990. return(Status);
  1991. }
  1992. }
  1993. SpMemFree(SubKey);
  1994. //
  1995. // Open controlset\Control\Nls.
  1996. //
  1997. INIT_OBJA(&Obja,&UnicodeString,L"Nls");
  1998. Obja.RootDirectory = hKeyControlSetControl;
  1999. Status = ZwCreateKey(
  2000. &hKeyNls,
  2001. KEY_ALL_ACCESS,
  2002. &Obja,
  2003. 0,
  2004. NULL,
  2005. REG_OPTION_NON_VOLATILE,
  2006. NULL
  2007. );
  2008. if(!NT_SUCCESS(Status)) {
  2009. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Unable to open controlset\\Control\\Nls key (%lx)\n",Status));
  2010. return(Status);
  2011. }
  2012. //
  2013. // Create an entry for the ansi codepage.
  2014. //
  2015. Status = SpCreateCodepageEntry(
  2016. SifHandle,
  2017. hKeyNls,
  2018. CODEPAGE_NAME,
  2019. SIF_ANSICODEPAGE,
  2020. L"ACP"
  2021. );
  2022. if(NT_SUCCESS(Status)) {
  2023. //
  2024. // Create entries for the oem codepage(s).
  2025. //
  2026. Status = SpCreateCodepageEntry(
  2027. SifHandle,
  2028. hKeyNls,
  2029. CODEPAGE_NAME,
  2030. SIF_OEMCODEPAGE,
  2031. L"OEMCP"
  2032. );
  2033. if(NT_SUCCESS(Status)) {
  2034. //
  2035. // Create an entry for the mac codepage.
  2036. //
  2037. Status = SpCreateCodepageEntry(
  2038. SifHandle,
  2039. hKeyNls,
  2040. CODEPAGE_NAME,
  2041. SIF_MACCODEPAGE,
  2042. L"MACCP"
  2043. );
  2044. }
  2045. }
  2046. if(NT_SUCCESS(Status)) {
  2047. //
  2048. // Create an entry for the oem hal font.
  2049. //
  2050. OemHalFont = SpGetSectionKeyIndex(SifHandle,SIF_NLS,SIF_OEMHALFONT,0);
  2051. if(!OemHalFont) {
  2052. SpFatalSifError(SifHandle,SIF_NLS,SIF_OEMHALFONT,0,0);
  2053. }
  2054. Status = SpOpenSetValueAndClose(
  2055. hKeyNls,
  2056. CODEPAGE_NAME,
  2057. L"OEMHAL",
  2058. STRING_VALUE(OemHalFont)
  2059. );
  2060. }
  2061. //
  2062. // Create an entry for the language case table.
  2063. //
  2064. if(NT_SUCCESS(Status)) {
  2065. Status = SpCreateCodepageEntry(
  2066. SifHandle,
  2067. hKeyNls,
  2068. L"Language",
  2069. SIF_UNICODECASETABLE,
  2070. L"Default"
  2071. );
  2072. }
  2073. #ifdef _X86_
  2074. //
  2075. // If necessary, let the win9x upgrade override the code page for GUI mode.
  2076. //
  2077. if (WinUpgradeType == UpgradeWin95) {
  2078. SpWin9xOverrideGuiModeCodePage (hKeyNls);
  2079. }
  2080. #endif
  2081. ZwClose(hKeyNls);
  2082. return(Status);
  2083. }
  2084. NTSTATUS
  2085. SpCreateCodepageEntry(
  2086. IN PVOID SifHandle,
  2087. IN HANDLE hKeyNls,
  2088. IN PWSTR SubkeyName,
  2089. IN PWSTR SifNlsSectionKeyName,
  2090. IN PWSTR EntryName
  2091. )
  2092. {
  2093. PWSTR Filename,Identifier;
  2094. NTSTATUS Status;
  2095. ULONG value = 0;
  2096. PWSTR DefaultIdentifier = NULL;
  2097. while(Filename = SpGetSectionKeyIndex(SifHandle,SIF_NLS,SifNlsSectionKeyName,value)) {
  2098. value++;
  2099. Identifier = SpGetSectionKeyIndex(SifHandle,SIF_NLS,SifNlsSectionKeyName,value);
  2100. if(!Identifier) {
  2101. SpFatalSifError(SifHandle,SIF_NLS,SifNlsSectionKeyName,0,value);
  2102. }
  2103. //
  2104. // Remember first identifier.
  2105. //
  2106. if(DefaultIdentifier == NULL) {
  2107. DefaultIdentifier = Identifier;
  2108. }
  2109. value++;
  2110. Status = SpOpenSetValueAndClose(
  2111. hKeyNls,
  2112. SubkeyName,
  2113. Identifier,
  2114. STRING_VALUE(Filename)
  2115. );
  2116. if(!NT_SUCCESS(Status)) {
  2117. return(Status);
  2118. }
  2119. }
  2120. if(!value) {
  2121. SpFatalSifError(SifHandle,SIF_NLS,SifNlsSectionKeyName,0,0);
  2122. }
  2123. Status = SpOpenSetValueAndClose(
  2124. hKeyNls,
  2125. SubkeyName,
  2126. EntryName,
  2127. STRING_VALUE(DefaultIdentifier)
  2128. );
  2129. return(Status);
  2130. }
  2131. NTSTATUS
  2132. SpConfigureFonts(
  2133. IN PVOID SifHandle,
  2134. IN HANDLE hKeySoftwareHive
  2135. )
  2136. /*++
  2137. Routine Description:
  2138. Prepare a list of fonts for use with Windows.
  2139. This routine runs down a list of fonts stored in the setup information
  2140. file and adds each one to the registry, in the area that shadows the
  2141. [Fonts] section of win.ini (HKEY_LOCAL_MACHINE\Software\Microsoft\
  2142. Windows NT\CurrentVersion\Fonts). If a particular font value entry
  2143. already exists (e.g., if we're doing an upgrade), then it is left alone.
  2144. Eventually it will add the correct resolution (96 or 120 dpi)
  2145. fonts but for now it only deals with the 96 dpi fonts.
  2146. Arguments:
  2147. SifHandle - supplies a handle to the open text setup information file.
  2148. hKeySoftwareHive - supplies handle to root of software registry hive.
  2149. Return Value:
  2150. Status value indicating outcome of operation.
  2151. --*/
  2152. {
  2153. OBJECT_ATTRIBUTES Obja;
  2154. UNICODE_STRING UnicodeString;
  2155. NTSTATUS Status;
  2156. HANDLE hKey;
  2157. PWSTR FontList;
  2158. PWSTR FontName;
  2159. PWSTR FontDescription;
  2160. ULONG FontCount,font;
  2161. ULONG KeyValueLength;
  2162. //
  2163. // Open HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Fonts.
  2164. //
  2165. INIT_OBJA(
  2166. &Obja,
  2167. &UnicodeString,
  2168. L"Microsoft\\Windows NT\\CurrentVersion\\Fonts"
  2169. );
  2170. Obja.RootDirectory = hKeySoftwareHive;
  2171. Status = ZwCreateKey(
  2172. &hKey,
  2173. KEY_ALL_ACCESS,
  2174. &Obja,
  2175. 0,
  2176. NULL,
  2177. REG_OPTION_NON_VOLATILE,
  2178. NULL
  2179. );
  2180. if(!NT_SUCCESS(Status)) {
  2181. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Unable to open Fonts key (%lx)\n",Status));
  2182. return(Status);
  2183. }
  2184. //
  2185. // For now always use the 96 dpi fonts.
  2186. //
  2187. FontList = L"FontListE";
  2188. //
  2189. // Process each line in the text setup information file section
  2190. // for the selected font list.
  2191. //
  2192. FontCount = SpCountLinesInSection(SifHandle,FontList);
  2193. if(!FontCount) {
  2194. SpFatalSifError(SifHandle,FontList,NULL,0,0);
  2195. }
  2196. for(font=0; font<FontCount; font++) {
  2197. //
  2198. // Fetch the font description.
  2199. //
  2200. FontDescription = SpGetKeyName(SifHandle,FontList,font);
  2201. if(!FontDescription) {
  2202. SpFatalSifError(SifHandle,FontList,NULL,font,(ULONG)(-1));
  2203. }
  2204. //
  2205. // Check to see if a value entry for this font already exists. If so,
  2206. // we want to leave it alone.
  2207. //
  2208. RtlInitUnicodeString(&UnicodeString,FontDescription);
  2209. Status = ZwQueryValueKey(hKey,
  2210. &UnicodeString,
  2211. KeyValueFullInformation,
  2212. (PVOID)NULL,
  2213. 0,
  2214. &KeyValueLength
  2215. );
  2216. if((Status == STATUS_BUFFER_OVERFLOW) || (Status == STATUS_BUFFER_TOO_SMALL)) {
  2217. Status = STATUS_SUCCESS;
  2218. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_WARNING_LEVEL, "SETUP: Font %ws already exists--entry will not be modified\n", FontDescription));
  2219. continue;
  2220. }
  2221. //
  2222. // Fetch the font filename.
  2223. //
  2224. FontName = SpGetSectionLineIndex(SifHandle,FontList,font,0);
  2225. if(!FontName) {
  2226. SpFatalSifError(SifHandle,FontList,NULL,font,0);
  2227. }
  2228. //
  2229. // Set the entry.
  2230. //
  2231. Status = ZwSetValueKey(hKey,&UnicodeString,0,STRING_VALUE(FontName));
  2232. if(!NT_SUCCESS(Status)) {
  2233. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Unable to set %ws to %ws (%lx)\n",FontDescription,FontName,Status));
  2234. break;
  2235. }
  2236. }
  2237. ZwClose(hKey);
  2238. return(Status);
  2239. }
  2240. NTSTATUS
  2241. SpStoreHwInfoForSetup(
  2242. IN HANDLE hKeyControlSetControl
  2243. )
  2244. /*++
  2245. Routine Description:
  2246. This routine stored information in the registry which will be used by
  2247. GUI setup to determine which options for mouse, display, and keyboard
  2248. are currently selected.
  2249. The data is stored in HKEY_LOCAL_MACHINE\System\<control set>\Control\Setup
  2250. in values pointer, video, and keyboard.
  2251. Arguments:
  2252. hKeyControlSetControl - supplies handle to open key
  2253. HKEY_LOCAL_MACHINE\System\<Control Set>\Control.
  2254. Return Value:
  2255. Status value indicating outcome of operation.
  2256. --*/
  2257. {
  2258. NTSTATUS Status;
  2259. ASSERT(HardwareComponents[HwComponentMouse]->IdString);
  2260. ASSERT(HardwareComponents[HwComponentDisplay]->IdString);
  2261. ASSERT(HardwareComponents[HwComponentKeyboard]->IdString);
  2262. Status = SpOpenSetValueAndClose(
  2263. hKeyControlSetControl,
  2264. SETUP_KEY_NAME,
  2265. L"pointer",
  2266. STRING_VALUE(HardwareComponents[HwComponentMouse]->IdString)
  2267. );
  2268. if(!NT_SUCCESS(Status)) {
  2269. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Unable to set control\\setup\\pointer value (%lx)\n",Status));
  2270. return(Status);
  2271. }
  2272. Status = SpOpenSetValueAndClose(
  2273. hKeyControlSetControl,
  2274. SETUP_KEY_NAME,
  2275. L"video",
  2276. STRING_VALUE(HardwareComponents[HwComponentDisplay]->IdString)
  2277. );
  2278. if(!NT_SUCCESS(Status)) {
  2279. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Unable to set control\\setup\\video value (%lx)\n",Status));
  2280. return(Status);
  2281. }
  2282. Status = SpOpenSetValueAndClose(
  2283. hKeyControlSetControl,
  2284. SETUP_KEY_NAME,
  2285. L"keyboard",
  2286. STRING_VALUE(HardwareComponents[HwComponentKeyboard]->IdString)
  2287. );
  2288. if(!NT_SUCCESS(Status)) {
  2289. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Unable to set control\\setup\\keyboard value (%lx)\n",Status));
  2290. return(Status);
  2291. }
  2292. return(STATUS_SUCCESS);
  2293. }
  2294. NTSTATUS
  2295. SpOpenSetValueAndClose(
  2296. IN HANDLE hKeyRoot,
  2297. IN PWSTR SubKeyName, OPTIONAL
  2298. IN PWSTR ValueName,
  2299. IN ULONG ValueType,
  2300. IN PVOID Value,
  2301. IN ULONG ValueSize
  2302. )
  2303. /*++
  2304. Routine Description:
  2305. Open a subkey, set a value in it, and close the subkey.
  2306. The subkey will be created if it does not exist.
  2307. Arguments:
  2308. hKeyRoot - supplies handle to an open registry key.
  2309. SubKeyName - supplies path relative to hKeyRoot for key in which
  2310. the value is to be set. If this is not specified, then the value
  2311. is set in hKeyRoot.
  2312. ValueName - supplies the name of the value to be set.
  2313. ValueType - supplies the data type for the value to be set.
  2314. Value - supplies a buffer containing the value data.
  2315. ValueSize - supplies the size of the buffer pointed to by Value.
  2316. Return Value:
  2317. Status value indicating outcome of operation.
  2318. --*/
  2319. {
  2320. OBJECT_ATTRIBUTES Obja;
  2321. HANDLE hSubKey;
  2322. UNICODE_STRING UnicodeString;
  2323. NTSTATUS Status;
  2324. //
  2325. // Open or create the subkey in which we want to set the value.
  2326. //
  2327. hSubKey = hKeyRoot;
  2328. if(SubKeyName) {
  2329. //
  2330. // If SubKeyName is a path to the key, then we need to create
  2331. // the subkeys in the path, because they may not exist yet.
  2332. //
  2333. PWSTR p;
  2334. PWSTR q;
  2335. PWSTR r;
  2336. //
  2337. // Since this function may temporarily write to the key path (which may be a constant string,
  2338. // and the system will bug check if we write to it), we need to duplicate the string so that
  2339. // we can write to memory that we own.
  2340. //
  2341. p = SpDupStringW( SubKeyName );
  2342. r = p;
  2343. do {
  2344. //
  2345. // p points to the next subkey to be created.
  2346. // q points to NUL character at the end of the
  2347. // name.
  2348. // r points to the beginning of the duplicated string. It will be used at the end of this
  2349. // routine, when we no longer need the string, so that we can free the alocated memory.
  2350. //
  2351. q = wcschr(p, (WCHAR)'\\');
  2352. if( q != NULL ) {
  2353. //
  2354. // Temporarily replace the '\' with the
  2355. // NUL character
  2356. //
  2357. *q = (WCHAR)'\0';
  2358. }
  2359. INIT_OBJA(&Obja,&UnicodeString,p);
  2360. Obja.RootDirectory = hSubKey;
  2361. Status = ZwCreateKey(
  2362. &hSubKey,
  2363. KEY_ALL_ACCESS,
  2364. &Obja,
  2365. 0,
  2366. NULL,
  2367. REG_OPTION_NON_VOLATILE,
  2368. NULL
  2369. );
  2370. if( q != NULL ) {
  2371. //
  2372. // Restore the '\' in the subkey name, and make
  2373. // p and q point to the remainder of the path
  2374. // that was not processed yet.
  2375. //
  2376. *q = (WCHAR)'\\';
  2377. q++;
  2378. p = q;
  2379. }
  2380. //
  2381. // The parent of the key that we just attempted to open/create
  2382. // is no longer needed.
  2383. //
  2384. if( Obja.RootDirectory != hKeyRoot ) {
  2385. ZwClose( Obja.RootDirectory );
  2386. }
  2387. if(!NT_SUCCESS(Status)) {
  2388. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Unable to open subkey %ws (%lx)\n",SubKeyName,Status));
  2389. return(Status);
  2390. }
  2391. } while( q != NULL );
  2392. SpMemFree( r );
  2393. }
  2394. //
  2395. // Set the value.
  2396. //
  2397. RtlInitUnicodeString(&UnicodeString,ValueName);
  2398. Status = ZwSetValueKey(
  2399. hSubKey,
  2400. &UnicodeString,
  2401. 0,
  2402. ValueType,
  2403. Value,
  2404. ValueSize
  2405. );
  2406. if(!NT_SUCCESS(Status)) {
  2407. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Unable to set value %ws:%ws (%lx)\n",SubKeyName,ValueName,Status));
  2408. }
  2409. if(SubKeyName) {
  2410. ZwClose(hSubKey);
  2411. }
  2412. return(Status);
  2413. }
  2414. NTSTATUS
  2415. SpGetProductSuiteMask(
  2416. IN HANDLE hKeyControlSetControl,
  2417. OUT PULONG SuiteMask
  2418. )
  2419. {
  2420. OBJECT_ATTRIBUTES Obja;
  2421. HANDLE hSubKey;
  2422. UNICODE_STRING UnicodeString;
  2423. NTSTATUS Status;
  2424. UCHAR Buffer[MAX_PRODUCT_SUITE_BYTES];
  2425. ULONG BufferLength;
  2426. ULONG ResultLength = 0;
  2427. PWSTR p;
  2428. PUCHAR Data;
  2429. ULONG DataLength;
  2430. BOOLEAN SuiteFound = FALSE;
  2431. ULONG i,j;
  2432. *SuiteMask = 0;
  2433. //
  2434. // Open or create the subkey in which we want to set the value.
  2435. //
  2436. INIT_OBJA(&Obja,&UnicodeString,PRODUCT_OPTIONS_KEY_NAME);
  2437. Obja.RootDirectory = hKeyControlSetControl;
  2438. Status = ZwCreateKey(
  2439. &hSubKey,
  2440. KEY_ALL_ACCESS,
  2441. &Obja,
  2442. 0,
  2443. NULL,
  2444. REG_OPTION_NON_VOLATILE,
  2445. NULL
  2446. );
  2447. if(!NT_SUCCESS(Status)) {
  2448. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Unable to open subkey (%lx)\n",Status));
  2449. return(Status);
  2450. }
  2451. //
  2452. // query the current value
  2453. //
  2454. INIT_OBJA(&Obja,&UnicodeString,PRODUCT_SUITE_VALUE_NAME);
  2455. BufferLength = sizeof(Buffer);
  2456. RtlZeroMemory( Buffer, BufferLength );
  2457. Status = ZwQueryValueKey(
  2458. hSubKey,
  2459. &UnicodeString,
  2460. KeyValuePartialInformation,
  2461. Buffer,
  2462. BufferLength,
  2463. &ResultLength
  2464. );
  2465. if((!NT_SUCCESS(Status)) && (Status != STATUS_OBJECT_NAME_NOT_FOUND)) {
  2466. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Unable to query subkey (%lx)\n",Status));
  2467. return(Status);
  2468. }
  2469. if (ResultLength == BufferLength) {
  2470. //
  2471. // the buffer is too small, this should not happen
  2472. // unless we have too many suites
  2473. //
  2474. ZwClose(hSubKey);
  2475. return STATUS_BUFFER_OVERFLOW;
  2476. }
  2477. if (ResultLength) {
  2478. Data = (PUCHAR)(((PKEY_VALUE_PARTIAL_INFORMATION)Buffer)->Data);
  2479. if (((PWSTR)Data)[0] == 0) {
  2480. ((PKEY_VALUE_PARTIAL_INFORMATION)Buffer)->DataLength -= sizeof(WCHAR);
  2481. }
  2482. DataLength = ((PKEY_VALUE_PARTIAL_INFORMATION)Buffer)->DataLength;
  2483. p = (PWSTR)Data;
  2484. i = 0;
  2485. while (i<DataLength) {
  2486. for (j=0; j<CountProductSuiteNames; j++) {
  2487. if (ProductSuiteNames[j] != NULL && wcscmp(p,ProductSuiteNames[j]) == 0) {
  2488. *SuiteMask |= (1 << j);
  2489. }
  2490. }
  2491. if (*p < L'A' || *p > L'z') {
  2492. i += 1;
  2493. p += 1;
  2494. } else {
  2495. i += (wcslen( p ) + 1);
  2496. p += (wcslen( p ) + 1);
  2497. }
  2498. }
  2499. }
  2500. ZwClose(hSubKey);
  2501. return(Status);
  2502. }
  2503. NTSTATUS
  2504. SpSetProductSuite(
  2505. IN HANDLE hKeyControlSetControl,
  2506. IN ULONG SuiteMask
  2507. )
  2508. {
  2509. OBJECT_ATTRIBUTES Obja;
  2510. HANDLE hSubKey;
  2511. UNICODE_STRING UnicodeString;
  2512. NTSTATUS Status;
  2513. UCHAR Buffer[MAX_PRODUCT_SUITE_BYTES];
  2514. ULONG BufferLength;
  2515. ULONG ResultLength = 0;
  2516. PWSTR p;
  2517. PUCHAR Data;
  2518. ULONG DataLength;
  2519. BOOLEAN SuiteFound = FALSE;
  2520. ULONG i;
  2521. ULONG tmp;
  2522. //
  2523. // Open or create the subkey in which we want to set the value.
  2524. //
  2525. INIT_OBJA(&Obja,&UnicodeString,PRODUCT_OPTIONS_KEY_NAME);
  2526. Obja.RootDirectory = hKeyControlSetControl;
  2527. Status = ZwCreateKey(
  2528. &hSubKey,
  2529. KEY_ALL_ACCESS,
  2530. &Obja,
  2531. 0,
  2532. NULL,
  2533. REG_OPTION_NON_VOLATILE,
  2534. NULL
  2535. );
  2536. if(!NT_SUCCESS(Status)) {
  2537. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Unable to open subkey (%lx)\n",Status));
  2538. return(Status);
  2539. }
  2540. RtlZeroMemory( Buffer, sizeof(Buffer) );
  2541. tmp = SuiteMask;
  2542. p = (PWSTR)Buffer;
  2543. i = 0;
  2544. while (tmp && i<CountProductSuiteNames) {
  2545. if ((tmp&1) && ProductSuiteNames[i] != NULL) {
  2546. wcscpy(p,ProductSuiteNames[i]);
  2547. p += (wcslen(p) + 1);
  2548. }
  2549. i += 1;
  2550. tmp >>= 1;
  2551. }
  2552. BufferLength = (ULONG)((ULONG_PTR)p - (ULONG_PTR)Buffer) + sizeof(WCHAR);
  2553. //
  2554. // Set the value.
  2555. //
  2556. INIT_OBJA(&Obja,&UnicodeString,PRODUCT_SUITE_VALUE_NAME);
  2557. Status = ZwSetValueKey(
  2558. hSubKey,
  2559. &UnicodeString,
  2560. 0,
  2561. REG_MULTI_SZ,
  2562. Buffer,
  2563. BufferLength
  2564. );
  2565. if(!NT_SUCCESS(Status)) {
  2566. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Unable to set value (%lx)\n",Status));
  2567. }
  2568. ZwClose(hSubKey);
  2569. return Status;
  2570. }
  2571. NTSTATUS
  2572. SpCreateServiceEntryIndirect(
  2573. IN HANDLE hKeyControlSetServices,
  2574. IN PVOID SifHandle, OPTIONAL
  2575. IN PWSTR SifSectionName, OPTIONAL
  2576. IN PWSTR KeyName,
  2577. IN ULONG ServiceType,
  2578. IN ULONG ServiceStart,
  2579. IN PWSTR ServiceGroup, OPTIONAL
  2580. IN ULONG ServiceError,
  2581. IN PWSTR FileName, OPTIONAL
  2582. OUT PHANDLE SubkeyHandle OPTIONAL
  2583. )
  2584. {
  2585. HANDLE hKeyService;
  2586. OBJECT_ATTRIBUTES Obja;
  2587. NTSTATUS Status;
  2588. UNICODE_STRING UnicodeString;
  2589. PWSTR pwstr;
  2590. //
  2591. // Look in the sif file to get the subkey name within the
  2592. // services list, unless the key name specified by the caller
  2593. // is the actual key name.
  2594. //
  2595. if(SifHandle) {
  2596. pwstr = SpGetSectionKeyIndex(SifHandle,SifSectionName,KeyName,INDEX_INFKEYNAME);
  2597. if(!pwstr) {
  2598. SpFatalSifError(SifHandle,SifSectionName,KeyName,0,INDEX_INFKEYNAME);
  2599. }
  2600. KeyName = pwstr;
  2601. }
  2602. //
  2603. // Create the subkey in the services key.
  2604. //
  2605. INIT_OBJA(&Obja,&UnicodeString,KeyName);
  2606. Obja.RootDirectory = hKeyControlSetServices;
  2607. Status = ZwCreateKey(
  2608. &hKeyService,
  2609. KEY_ALL_ACCESS,
  2610. &Obja,
  2611. 0,
  2612. NULL,
  2613. REG_OPTION_NON_VOLATILE,
  2614. NULL
  2615. );
  2616. if(!NT_SUCCESS(Status)) {
  2617. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Unable to open/create key for %ws service (%lx)\n",KeyName,Status));
  2618. return (Status) ;
  2619. }
  2620. //
  2621. // Set the service type.
  2622. //
  2623. RtlInitUnicodeString(&UnicodeString, REGSTR_VALUE_TYPE);
  2624. Status = ZwSetValueKey(
  2625. hKeyService,
  2626. &UnicodeString,
  2627. 0,
  2628. ULONG_VALUE(ServiceType)
  2629. );
  2630. if(!NT_SUCCESS(Status)) {
  2631. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Unable to set service %ws Type (%lx)\n",KeyName,Status));
  2632. goto spcsie1;
  2633. }
  2634. //
  2635. // Set the service start type.
  2636. //
  2637. RtlInitUnicodeString(&UnicodeString,L"Start");
  2638. Status = ZwSetValueKey(
  2639. hKeyService,
  2640. &UnicodeString,
  2641. 0,
  2642. ULONG_VALUE(ServiceStart)
  2643. );
  2644. if(!NT_SUCCESS(Status)) {
  2645. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Unable to set service %ws Start (%lx)\n",KeyName,Status));
  2646. goto spcsie1;
  2647. }
  2648. if( ServiceGroup != NULL ) {
  2649. //
  2650. // Set the service group name.
  2651. //
  2652. RtlInitUnicodeString(&UnicodeString,L"Group");
  2653. Status = ZwSetValueKey(
  2654. hKeyService,
  2655. &UnicodeString,
  2656. 0,
  2657. STRING_VALUE(ServiceGroup)
  2658. );
  2659. if(!NT_SUCCESS(Status)) {
  2660. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Unable to set service %ws Group (%lx)\n",KeyName,Status));
  2661. goto spcsie1;
  2662. }
  2663. }
  2664. //
  2665. // Set the service error type.
  2666. //
  2667. RtlInitUnicodeString(&UnicodeString,L"ErrorControl");
  2668. Status = ZwSetValueKey(
  2669. hKeyService,
  2670. &UnicodeString,
  2671. 0,
  2672. ULONG_VALUE(ServiceError)
  2673. );
  2674. if(!NT_SUCCESS(Status)) {
  2675. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Unable to set service %ws ErrorControl (%lx)\n",KeyName,Status));
  2676. goto spcsie1;
  2677. }
  2678. //
  2679. // If asked to do so, set the service image path.
  2680. //
  2681. if(FileName) {
  2682. pwstr = TemporaryBuffer;
  2683. wcscpy(pwstr,L"system32\\drivers");
  2684. SpConcatenatePaths(pwstr,FileName);
  2685. RtlInitUnicodeString(&UnicodeString,L"ImagePath");
  2686. Status = ZwSetValueKey(hKeyService,&UnicodeString,0,STRING_VALUE(pwstr));
  2687. if(!NT_SUCCESS(Status)) {
  2688. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Unable to set service %w image path (%lx)\n",KeyName,Status));
  2689. goto spcsie1;
  2690. }
  2691. } else {
  2692. if(NTUpgrade == UpgradeFull) {
  2693. //
  2694. // Delete imagepath on upgrade. This makes sure we are getting
  2695. // our driver, and from the right place. Fixes Compaq's SSD stuff,
  2696. // for example. Do something similar for PlugPlayServiceType, in case
  2697. // we are renabling a device that the user disabled (in which case
  2698. // the PlugPlayServiceType could cause us to fail to make up a
  2699. // device instance for a legacy device, and cause the driver to fail
  2700. // to load/initialize.
  2701. //
  2702. RtlInitUnicodeString(&UnicodeString,L"ImagePath");
  2703. Status = ZwDeleteValueKey(hKeyService,&UnicodeString);
  2704. if(!NT_SUCCESS(Status)) {
  2705. if (Status != STATUS_OBJECT_NAME_NOT_FOUND) {
  2706. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Unable to remove imagepath from service %ws (%lx)\n",KeyName,Status));
  2707. }
  2708. Status = STATUS_SUCCESS;
  2709. }
  2710. RtlInitUnicodeString(&UnicodeString,L"PlugPlayServiceType");
  2711. Status = ZwDeleteValueKey(hKeyService,&UnicodeString);
  2712. if(!NT_SUCCESS(Status)) {
  2713. if (Status != STATUS_OBJECT_NAME_NOT_FOUND) {
  2714. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Unable to remove plugplayservicetype from service %ws (%lx)\n",KeyName,Status));
  2715. }
  2716. Status = STATUS_SUCCESS;
  2717. }
  2718. }
  2719. }
  2720. //
  2721. // If the caller doesn't want the handle to the service subkey
  2722. // we just created, close the handle. If we are returning an
  2723. // error, always close it.
  2724. //
  2725. spcsie1:
  2726. if(NT_SUCCESS(Status) && SubkeyHandle) {
  2727. *SubkeyHandle = hKeyService;
  2728. } else {
  2729. ZwClose(hKeyService);
  2730. }
  2731. //
  2732. // Done.
  2733. //
  2734. return(Status);
  2735. }
  2736. NTSTATUS
  2737. SpThirdPartyRegistry(
  2738. IN PVOID hKeyControlSetServices
  2739. )
  2740. {
  2741. OBJECT_ATTRIBUTES Obja;
  2742. UNICODE_STRING UnicodeString;
  2743. NTSTATUS Status;
  2744. HANDLE hKeyEventLogSystem;
  2745. HwComponentType Component;
  2746. PHARDWARE_COMPONENT Dev;
  2747. PHARDWARE_COMPONENT_REGISTRY Reg;
  2748. PHARDWARE_COMPONENT_FILE File;
  2749. WCHAR NodeName[9];
  2750. ULONG DriverType;
  2751. ULONG DriverStart;
  2752. ULONG DriverErrorControl;
  2753. PWSTR DriverGroup;
  2754. HANDLE hKeyService;
  2755. //
  2756. // Open HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\EventLog\System
  2757. //
  2758. INIT_OBJA(&Obja,&UnicodeString,L"EventLog\\System");
  2759. Obja.RootDirectory = hKeyControlSetServices;
  2760. Status = ZwCreateKey(
  2761. &hKeyEventLogSystem,
  2762. KEY_ALL_ACCESS,
  2763. &Obja,
  2764. 0,
  2765. NULL,
  2766. REG_OPTION_NON_VOLATILE,
  2767. NULL
  2768. );
  2769. if(!NT_SUCCESS(Status)) {
  2770. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: SpThirdPartyRegistry: couldn't open eventlog\\system (%lx)",Status));
  2771. return(Status);
  2772. }
  2773. for(Component=0; Component<=HwComponentMax; Component++) {
  2774. // no registry stuff applicable to keyboard layout
  2775. if(Component == HwComponentLayout) {
  2776. continue;
  2777. }
  2778. Dev = (Component == HwComponentMax)
  2779. ? ((!PreInstall ||
  2780. (PreinstallScsiHardware==NULL))? ScsiHardware :
  2781. PreinstallScsiHardware)
  2782. : ((!PreInstall ||
  2783. (PreinstallHardwareComponents[Component]==NULL))? HardwareComponents[Component] :
  2784. PreinstallHardwareComponents[Component]);
  2785. for( ; Dev; Dev = Dev->Next) {
  2786. //
  2787. // If there is no third-party option selected here, then skip
  2788. // the component.
  2789. //
  2790. if(!Dev->ThirdPartyOptionSelected) {
  2791. continue;
  2792. }
  2793. //
  2794. // Iterate through the files for this device. If a file has
  2795. // a ServiceKeyName, create the key and add values in it
  2796. // as appropriate.
  2797. //
  2798. for(File=Dev->Files; File; File=File->Next) {
  2799. HwFileType filetype = File->FileType;
  2800. PWSTR p;
  2801. ULONG dw;
  2802. //
  2803. // If there is to be no node for this file, skip it.
  2804. //
  2805. if(!File->ConfigName) {
  2806. continue;
  2807. }
  2808. //
  2809. // Calculate the node name. This is the name of the driver
  2810. // without the extension.
  2811. //
  2812. wcsncpy(NodeName,File->Filename,8);
  2813. NodeName[8] = 0;
  2814. if(p = wcschr(NodeName,L'.')) {
  2815. *p = 0;
  2816. }
  2817. //
  2818. // The driver type and error control are always the same.
  2819. //
  2820. DriverType = SERVICE_KERNEL_DRIVER;
  2821. DriverErrorControl = SERVICE_ERROR_NORMAL;
  2822. //
  2823. // The start type depends on the component.
  2824. // For scsi, it's boot loader start. For others, it's
  2825. // system start.
  2826. //
  2827. DriverStart = (Component == HwComponentMax)
  2828. ? SERVICE_BOOT_START
  2829. : SERVICE_SYSTEM_START;
  2830. //
  2831. // The group depends on the component.
  2832. //
  2833. switch(Component) {
  2834. case HwComponentDisplay:
  2835. DriverGroup = L"Video";
  2836. break;
  2837. case HwComponentMouse:
  2838. if(filetype == HwFileClass) {
  2839. DriverGroup = L"Pointer Class";
  2840. } else {
  2841. DriverGroup = L"Pointer Port";
  2842. }
  2843. break;
  2844. case HwComponentKeyboard:
  2845. if(filetype == HwFileClass) {
  2846. DriverGroup = L"Keyboard Class";
  2847. } else {
  2848. DriverGroup = L"Keyboard Port";
  2849. }
  2850. break;
  2851. case HwComponentMax:
  2852. DriverGroup = L"SCSI miniport";
  2853. break;
  2854. default:
  2855. DriverGroup = L"Base";
  2856. break;
  2857. }
  2858. //
  2859. // Attempt to create the service entry.
  2860. //
  2861. Status = SpCreateServiceEntryIndirect(
  2862. hKeyControlSetServices,
  2863. NULL,
  2864. NULL,
  2865. NodeName,
  2866. DriverType,
  2867. DriverStart,
  2868. DriverGroup,
  2869. DriverErrorControl,
  2870. File->Filename,
  2871. &hKeyService
  2872. );
  2873. if(!NT_SUCCESS(Status)) {
  2874. goto sp3reg1;
  2875. }
  2876. //
  2877. // Create a default eventlog configuration.
  2878. //
  2879. Status = SpOpenSetValueAndClose(
  2880. hKeyEventLogSystem,
  2881. NodeName,
  2882. L"EventMessageFile",
  2883. REG_EXPAND_SZ,
  2884. DEFAULT_EVENT_LOG,
  2885. (wcslen(DEFAULT_EVENT_LOG)+1)*sizeof(WCHAR)
  2886. );
  2887. if(!NT_SUCCESS(Status)) {
  2888. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: SpThirdPartyRegistry: unable to set eventlog %ws EventMessageFile",NodeName));
  2889. ZwClose(hKeyService);
  2890. goto sp3reg1;
  2891. }
  2892. dw = 7;
  2893. Status = SpOpenSetValueAndClose(
  2894. hKeyEventLogSystem,
  2895. NodeName,
  2896. L"TypesSupported",
  2897. ULONG_VALUE(dw)
  2898. );
  2899. if(!NT_SUCCESS(Status)) {
  2900. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: SpThirdPartyRegistry: unable to set eventlog %ws TypesSupported",NodeName));
  2901. ZwClose(hKeyService);
  2902. goto sp3reg1;
  2903. }
  2904. for(Reg=File->RegistryValueList; Reg; Reg=Reg->Next) {
  2905. //
  2906. // If the key name is null or empty, there is no key to create;
  2907. // use the load list node itself in this case. Otherwise create
  2908. // the subkey in the load list node.
  2909. //
  2910. Status = SpOpenSetValueAndClose(
  2911. hKeyService,
  2912. (Reg->KeyName && *Reg->KeyName) ? Reg->KeyName : NULL,
  2913. Reg->ValueName,
  2914. Reg->ValueType,
  2915. Reg->Buffer,
  2916. Reg->BufferSize
  2917. );
  2918. if(!NT_SUCCESS(Status)) {
  2919. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL,
  2920. "SETUP: SpThirdPartyRegistry: unable to set value %ws (%lx)\n",
  2921. Reg->ValueName,
  2922. Status
  2923. ));
  2924. ZwClose(hKeyService);
  2925. goto sp3reg1;
  2926. }
  2927. }
  2928. ZwClose(hKeyService);
  2929. }
  2930. }
  2931. }
  2932. sp3reg1:
  2933. ZwClose(hKeyEventLogSystem);
  2934. return(Status);
  2935. }
  2936. NTSTATUS
  2937. SpDetermineProduct(
  2938. IN PDISK_REGION TargetRegion,
  2939. IN PWSTR SystemRoot,
  2940. OUT PNT_PRODUCT_TYPE ProductType,
  2941. OUT ULONG *MajorVersion,
  2942. OUT ULONG *MinorVersion,
  2943. OUT ULONG *BuildNumber, OPTIONAL
  2944. OUT ULONG *ProductSuiteMask,
  2945. OUT UPG_PROGRESS_TYPE *UpgradeProgressValue,
  2946. OUT PWSTR *UniqueIdFromReg, OPTIONAL
  2947. OUT PWSTR *Pid, OPTIONAL
  2948. OUT PBOOLEAN pIsEvalVariation OPTIONAL,
  2949. OUT PLCID LangId,
  2950. OUT ULONG *ServicePack OPTIONAL
  2951. )
  2952. {
  2953. OBJECT_ATTRIBUTES Obja;
  2954. UNICODE_STRING UnicodeString;
  2955. NTSTATUS Status, TempStatus;
  2956. PWSTR Hive,HiveKey;
  2957. PUCHAR buffer;
  2958. #define BUFFERSIZE (sizeof(KEY_VALUE_PARTIAL_INFORMATION)+256)
  2959. BOOLEAN HiveLoaded = FALSE;
  2960. PWSTR PartitionPath = NULL;
  2961. PWSTR p;
  2962. HANDLE hKeyRoot = NULL, hKeyCCSet = NULL;
  2963. ULONG ResultLength;
  2964. ULONG Number;
  2965. ULONG i;
  2966. //
  2967. // Allocate buffers.
  2968. //
  2969. Hive = SpMemAlloc(MAX_PATH * sizeof(WCHAR));
  2970. HiveKey = SpMemAlloc(MAX_PATH * sizeof(WCHAR));
  2971. buffer = SpMemAlloc(BUFFERSIZE);
  2972. //
  2973. // Get the name of the target partition.
  2974. //
  2975. SpNtNameFromRegion(
  2976. TargetRegion,
  2977. TemporaryBuffer,
  2978. sizeof(TemporaryBuffer),
  2979. PartitionOrdinalCurrent
  2980. );
  2981. PartitionPath = SpDupStringW(TemporaryBuffer);
  2982. //
  2983. // Load the system hive
  2984. //
  2985. wcscpy(Hive,PartitionPath);
  2986. SpConcatenatePaths(Hive,SystemRoot);
  2987. SpConcatenatePaths(Hive,L"system32\\config");
  2988. SpConcatenatePaths(Hive,L"system");
  2989. //
  2990. // Form the path of the key into which we will
  2991. // load the hive. We'll use the convention that
  2992. // a hive will be loaded into \registry\machine\x<hivename>.
  2993. //
  2994. wcscpy(HiveKey,LOCAL_MACHINE_KEY_NAME);
  2995. SpConcatenatePaths(HiveKey,L"xSystem");
  2996. //
  2997. // Attempt to load the key.
  2998. //
  2999. Status = SpLoadUnloadKey(NULL,NULL,HiveKey,Hive);
  3000. if(!NT_SUCCESS(Status)) {
  3001. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Unable to load hive %ws to key %ws (%lx)\n",Hive,HiveKey,Status));
  3002. goto spdp_1;
  3003. }
  3004. HiveLoaded = TRUE;
  3005. //
  3006. // Now get a key to the root of the hive we just loaded.
  3007. //
  3008. INIT_OBJA(&Obja,&UnicodeString,HiveKey);
  3009. Status = ZwOpenKey(&hKeyRoot,KEY_ALL_ACCESS,&Obja);
  3010. if(!NT_SUCCESS(Status)) {
  3011. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Unable to open %ws (%lx)\n",HiveKey,Status));
  3012. goto spdp_2;
  3013. }
  3014. //
  3015. // Get the unique identifier if needed.
  3016. // This value is not always present.
  3017. //
  3018. if(UniqueIdFromReg) {
  3019. *UniqueIdFromReg = NULL;
  3020. Status = SpGetValueKey(
  3021. hKeyRoot,
  3022. SETUP_KEY_NAME,
  3023. SIF_UNIQUEID,
  3024. BUFFERSIZE,
  3025. buffer,
  3026. &ResultLength
  3027. );
  3028. if(NT_SUCCESS(Status)) {
  3029. *UniqueIdFromReg = SpDupStringW((PWSTR)(((PKEY_VALUE_PARTIAL_INFORMATION)buffer)->Data));
  3030. }
  3031. // no error if not found.
  3032. }
  3033. //
  3034. // See if this is a failed upgrade
  3035. //
  3036. *UpgradeProgressValue = UpgradeNotInProgress;
  3037. Status = SpGetValueKey(
  3038. hKeyRoot,
  3039. SETUP_KEY_NAME,
  3040. UPGRADE_IN_PROGRESS,
  3041. BUFFERSIZE,
  3042. buffer,
  3043. &ResultLength
  3044. );
  3045. if(NT_SUCCESS(Status)) {
  3046. DWORD dw;
  3047. if( (dw = *(DWORD *)(((PKEY_VALUE_PARTIAL_INFORMATION)buffer)->Data)) < UpgradeMaxValue ) {
  3048. *UpgradeProgressValue = (UPG_PROGRESS_TYPE)dw;
  3049. }
  3050. }
  3051. //
  3052. // Get the key to the current control set
  3053. //
  3054. Status = SpGetCurrentControlSetNumber(hKeyRoot,&Number);
  3055. if(!NT_SUCCESS(Status)) {
  3056. goto spdp_3;
  3057. }
  3058. swprintf((PVOID)buffer,L"ControlSet%03d",Number);
  3059. INIT_OBJA(&Obja,&UnicodeString,(PVOID)buffer);
  3060. Obja.RootDirectory = hKeyRoot;
  3061. Status = ZwOpenKey(&hKeyCCSet,KEY_READ,&Obja);
  3062. if(!NT_SUCCESS(Status)) {
  3063. goto spdp_3;
  3064. }
  3065. //
  3066. // Get the Product type field
  3067. //
  3068. Status = SpGetValueKey(
  3069. hKeyCCSet,
  3070. L"Control\\ProductOptions",
  3071. L"ProductType",
  3072. BUFFERSIZE,
  3073. buffer,
  3074. &ResultLength
  3075. );
  3076. if(!NT_SUCCESS(Status)) {
  3077. goto spdp_3;
  3078. }
  3079. if( _wcsicmp( (PWSTR)(((PKEY_VALUE_PARTIAL_INFORMATION)buffer)->Data), L"WinNT" ) == 0 ) {
  3080. *ProductType = NtProductWinNt;
  3081. } else if( _wcsicmp( (PWSTR)(((PKEY_VALUE_PARTIAL_INFORMATION)buffer)->Data), L"LanmanNt" ) == 0 ) {
  3082. *ProductType = NtProductLanManNt;
  3083. } else if( _wcsicmp( (PWSTR)(((PKEY_VALUE_PARTIAL_INFORMATION)buffer)->Data), L"ServerNt" ) == 0 ) {
  3084. *ProductType = NtProductServer;
  3085. } else {
  3086. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Error, unknown ProductType = %ls. Assuming WinNt \n",
  3087. (PWSTR)(((PKEY_VALUE_PARTIAL_INFORMATION)buffer)->Data) ));
  3088. *ProductType = NtProductWinNt;
  3089. }
  3090. *ProductSuiteMask = 0;
  3091. Status = SpGetValueKey(
  3092. hKeyCCSet,
  3093. L"Control\\ProductOptions",
  3094. L"ProductSuite",
  3095. BUFFERSIZE,
  3096. buffer,
  3097. &ResultLength
  3098. );
  3099. if(NT_SUCCESS(Status)) {
  3100. p = (PWSTR)(((PKEY_VALUE_PARTIAL_INFORMATION)buffer)->Data);
  3101. while (p && *p) {
  3102. for (i = 0; i < CountProductSuiteNames; i++) {
  3103. if (ProductSuiteNames[i] != NULL && _wcsicmp( p, ProductSuiteNames[i]) == 0) {
  3104. *ProductSuiteMask |= (1 << i);
  3105. break;
  3106. }
  3107. }
  3108. p = p + wcslen(p) + 1;
  3109. }
  3110. } else {
  3111. Status = SpGetValueKey(
  3112. hKeyCCSet,
  3113. L"Control\\Citrix",
  3114. L"OemId",
  3115. BUFFERSIZE,
  3116. buffer,
  3117. &ResultLength
  3118. );
  3119. if (NT_SUCCESS(Status)) {
  3120. PWSTR wbuff = (PWSTR)(((PKEY_VALUE_PARTIAL_INFORMATION)buffer)->Data);
  3121. if (*wbuff != L'\0') {
  3122. *ProductSuiteMask |= VER_SUITE_TERMINAL;
  3123. }
  3124. }
  3125. }
  3126. if (LangId) {
  3127. PWSTR EndChar;
  3128. PWSTR Value = 0;
  3129. //
  3130. // Get the install language ID
  3131. //
  3132. Status = SpGetValueKey(
  3133. hKeyCCSet,
  3134. L"Control\\Nls\\Language",
  3135. L"InstallLanguage",
  3136. BUFFERSIZE,
  3137. buffer,
  3138. &ResultLength
  3139. );
  3140. if (!NT_SUCCESS(Status) || !buffer || !ResultLength) {
  3141. //
  3142. // Try to get default Language ID if we can't get install
  3143. // language ID
  3144. //
  3145. Status = SpGetValueKey(
  3146. hKeyCCSet,
  3147. L"Control\\Nls\\Language",
  3148. L"Default",
  3149. BUFFERSIZE,
  3150. buffer,
  3151. &ResultLength
  3152. );
  3153. if (!NT_SUCCESS(Status) || !buffer || !ResultLength)
  3154. goto spdp_3;
  3155. }
  3156. Value = (PWSTR)(((PKEY_VALUE_PARTIAL_INFORMATION)buffer)->Data);
  3157. *LangId = (LANGID)SpStringToLong(Value, &EndChar, 16); // hex base
  3158. }
  3159. //
  3160. // Get the Eval variation flag
  3161. //
  3162. if (pIsEvalVariation) {
  3163. *pIsEvalVariation = FALSE;
  3164. Status = SpGetValueKey(
  3165. hKeyCCSet,
  3166. L"Control\\Session Manager\\Executive",
  3167. L"PriorityQuantumMatrix",
  3168. BUFFERSIZE,
  3169. buffer,
  3170. &ResultLength);
  3171. if (NT_SUCCESS(Status)) {
  3172. PKEY_VALUE_PARTIAL_INFORMATION pValInfo =
  3173. (PKEY_VALUE_PARTIAL_INFORMATION)buffer;
  3174. PBYTE pData = (PBYTE)(((PKEY_VALUE_PARTIAL_INFORMATION)buffer)->Data);
  3175. //
  3176. // Note : PriorityQantumMatix Value is made up of 3 ULONGS
  3177. // Low Install Date&Time ULONG, Eval Duration (ULONG),
  3178. // High Install Date&Time ULONG
  3179. //
  3180. if (pData && pValInfo && (pValInfo->Type == REG_BINARY) &&
  3181. (ResultLength >= 8) && *(((ULONG *)pData) + 1)) {
  3182. *pIsEvalVariation = TRUE;
  3183. }
  3184. } else {
  3185. // discard the error (NT 3.51 and below version does not have this key)
  3186. Status = STATUS_SUCCESS;
  3187. }
  3188. }
  3189. //
  3190. // Get the ServicePack Number
  3191. //
  3192. if(ServicePack) {
  3193. *ServicePack = 0;
  3194. Status = SpGetValueKey(
  3195. hKeyCCSet,
  3196. L"Control\\Windows",
  3197. L"CSDVersion",
  3198. BUFFERSIZE,
  3199. buffer,
  3200. &ResultLength
  3201. );
  3202. if (NT_SUCCESS(Status)) {
  3203. PKEY_VALUE_PARTIAL_INFORMATION pValInfo =
  3204. (PKEY_VALUE_PARTIAL_INFORMATION)buffer;
  3205. if (pValInfo && pValInfo->Data && (pValInfo->Type == REG_DWORD)) {
  3206. *ServicePack = ((*(PULONG)(pValInfo->Data)) >> 8 & (0xff)) * 100
  3207. + ((*(PULONG)(pValInfo->Data)) & 0xff);
  3208. }
  3209. } else {
  3210. // discard the error
  3211. Status = STATUS_SUCCESS;
  3212. }
  3213. }
  3214. //
  3215. // Close the hive key
  3216. //
  3217. ZwClose( hKeyCCSet );
  3218. ZwClose( hKeyRoot );
  3219. hKeyRoot = NULL;
  3220. hKeyCCSet = NULL;
  3221. //
  3222. // Unload the system hive
  3223. //
  3224. TempStatus = SpLoadUnloadKey(NULL,NULL,HiveKey,NULL);
  3225. if(!NT_SUCCESS(TempStatus)) {
  3226. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: warning: unable to unload key %ws (%lx)\n",HiveKey,TempStatus));
  3227. }
  3228. HiveLoaded = FALSE;
  3229. //
  3230. // Load the software hive
  3231. //
  3232. wcscpy(Hive,PartitionPath);
  3233. SpConcatenatePaths(Hive,SystemRoot);
  3234. SpConcatenatePaths(Hive,L"system32\\config");
  3235. SpConcatenatePaths(Hive,L"software");
  3236. //
  3237. // Form the path of the key into which we will
  3238. // load the hive. We'll use the convention that
  3239. // a hive will be loaded into \registry\machine\x<hivename>.
  3240. //
  3241. wcscpy(HiveKey,LOCAL_MACHINE_KEY_NAME);
  3242. SpConcatenatePaths(HiveKey,L"x");
  3243. wcscat(HiveKey,L"software");
  3244. //
  3245. // Attempt to load the key.
  3246. //
  3247. Status = SpLoadUnloadKey(NULL,NULL,HiveKey,Hive);
  3248. if(!NT_SUCCESS(Status)) {
  3249. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Unable to load hive %ws to key %ws (%lx)\n",Hive,HiveKey,Status));
  3250. goto spdp_1;
  3251. }
  3252. HiveLoaded = TRUE;
  3253. //
  3254. // Now get a key to the root of the hive we just loaded.
  3255. //
  3256. INIT_OBJA(&Obja,&UnicodeString,HiveKey);
  3257. Status = ZwOpenKey(&hKeyRoot,KEY_ALL_ACCESS,&Obja);
  3258. if(!NT_SUCCESS(Status)) {
  3259. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Unable to open %ws (%lx)\n",HiveKey,Status));
  3260. goto spdp_2;
  3261. }
  3262. //
  3263. // Query the version of the NT
  3264. //
  3265. Status = SpGetValueKey(
  3266. hKeyRoot,
  3267. L"Microsoft\\Windows NT\\CurrentVersion",
  3268. L"CurrentVersion",
  3269. BUFFERSIZE,
  3270. buffer,
  3271. &ResultLength
  3272. );
  3273. //
  3274. // Convert the version into a dword
  3275. //
  3276. {
  3277. WCHAR wcsMajorVersion[] = L"0";
  3278. WCHAR wcsMinorVersion[] = L"00";
  3279. PWSTR Version = (PWSTR)(((PKEY_VALUE_PARTIAL_INFORMATION)buffer)->Data);
  3280. if( Version[0] && Version[1] && Version[2] ) {
  3281. wcsMajorVersion[0] = Version[0];
  3282. wcsMinorVersion[0] = Version[2];
  3283. if( Version[3] ) {
  3284. wcsMinorVersion[1] = Version[3];
  3285. }
  3286. }
  3287. *MajorVersion = (ULONG)SpStringToLong( wcsMajorVersion, NULL, 10 );
  3288. *MinorVersion = (ULONG)SpStringToLong( wcsMinorVersion, NULL, 10 );
  3289. }
  3290. //
  3291. // EVAL variations on NT 5.0 are detected using MPC code
  3292. // (This is to allow pre 5.0 RTM builds with timebomb to
  3293. // upgrade properly
  3294. //
  3295. if (pIsEvalVariation && (*MajorVersion >= 5))
  3296. *pIsEvalVariation = FALSE;
  3297. //
  3298. // Get build number
  3299. //
  3300. if(BuildNumber) {
  3301. Status = SpGetValueKey(
  3302. hKeyRoot,
  3303. L"Microsoft\\Windows NT\\CurrentVersion",
  3304. L"CurrentBuildNumber",
  3305. BUFFERSIZE,
  3306. buffer,
  3307. &ResultLength
  3308. );
  3309. *BuildNumber = NT_SUCCESS(Status)
  3310. ? (ULONG)SpStringToLong((PWSTR)(((PKEY_VALUE_PARTIAL_INFORMATION)buffer)->Data),NULL,10)
  3311. : 0;
  3312. }
  3313. //
  3314. // Query the PID, if requested
  3315. //
  3316. if( Pid != NULL ) {
  3317. TempStatus = SpGetValueKey(
  3318. hKeyRoot,
  3319. L"Microsoft\\Windows NT\\CurrentVersion",
  3320. L"ProductId",
  3321. BUFFERSIZE,
  3322. buffer,
  3323. &ResultLength
  3324. );
  3325. if(!NT_SUCCESS(TempStatus)) {
  3326. //
  3327. // If unable to read PID, assume empty string
  3328. //
  3329. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Unable to query PID from hive %ws. Status = (%lx)\n",Hive,TempStatus));
  3330. *Pid = SpDupStringW( L"" );
  3331. } else {
  3332. *Pid = SpDupStringW( (PWSTR)(((PKEY_VALUE_PARTIAL_INFORMATION)buffer)->Data) );
  3333. }
  3334. }
  3335. //
  3336. // Let the following do the cleaning up
  3337. spdp_3:
  3338. if( hKeyCCSet ) {
  3339. ZwClose( hKeyCCSet );
  3340. }
  3341. if( hKeyRoot ) {
  3342. ZwClose(hKeyRoot);
  3343. }
  3344. spdp_2:
  3345. //
  3346. // Unload the currently loaded hive.
  3347. //
  3348. if( HiveLoaded ) {
  3349. TempStatus = SpLoadUnloadKey(NULL,NULL,HiveKey,NULL);
  3350. if(!NT_SUCCESS(TempStatus)) {
  3351. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: warning: unable to unload key %ws (%lx)\n",HiveKey,TempStatus));
  3352. }
  3353. }
  3354. spdp_1:
  3355. SpMemFree(PartitionPath);
  3356. SpMemFree(Hive);
  3357. SpMemFree(HiveKey);
  3358. SpMemFree(buffer);
  3359. return( Status );
  3360. #undef BUFFERSIZE
  3361. }
  3362. NTSTATUS
  3363. SpSetUpgradeStatus(
  3364. IN PDISK_REGION TargetRegion,
  3365. IN PWSTR SystemRoot,
  3366. IN UPG_PROGRESS_TYPE UpgradeProgressValue
  3367. )
  3368. {
  3369. OBJECT_ATTRIBUTES Obja;
  3370. UNICODE_STRING UnicodeString;
  3371. NTSTATUS Status, TempStatus;
  3372. WCHAR Hive[MAX_PATH], HiveKey[MAX_PATH];
  3373. BOOLEAN HiveLoaded = FALSE;
  3374. PWSTR PartitionPath = NULL;
  3375. HANDLE hKeySystemHive;
  3376. DWORD dw;
  3377. //
  3378. // Get the name of the target patition.
  3379. //
  3380. SpNtNameFromRegion(
  3381. TargetRegion,
  3382. TemporaryBuffer,
  3383. sizeof(TemporaryBuffer),
  3384. PartitionOrdinalCurrent
  3385. );
  3386. PartitionPath = SpDupStringW(TemporaryBuffer);
  3387. //
  3388. // Load the system hive
  3389. //
  3390. wcscpy(Hive,PartitionPath);
  3391. SpConcatenatePaths(Hive,SystemRoot);
  3392. SpConcatenatePaths(Hive,L"system32\\config");
  3393. SpConcatenatePaths(Hive,L"system");
  3394. //
  3395. // Form the path of the key into which we will
  3396. // load the hive. We'll use the convention that
  3397. // a hive will be loaded into \registry\machine\x<hivename>.
  3398. //
  3399. wcscpy(HiveKey,LOCAL_MACHINE_KEY_NAME);
  3400. SpConcatenatePaths(HiveKey,L"x");
  3401. wcscat(HiveKey,L"system");
  3402. //
  3403. // Attempt to load the key.
  3404. //
  3405. Status = SpLoadUnloadKey(NULL,NULL,HiveKey,Hive);
  3406. if(!NT_SUCCESS(Status)) {
  3407. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Unable to load hive %ws to key %ws (%lx)\n",Hive,HiveKey,Status));
  3408. goto spus_1;
  3409. }
  3410. HiveLoaded = TRUE;
  3411. //
  3412. // Now get a key to the root of the hive we just loaded.
  3413. //
  3414. INIT_OBJA(&Obja,&UnicodeString,HiveKey);
  3415. Status = ZwOpenKey(&hKeySystemHive,KEY_ALL_ACCESS,&Obja);
  3416. if(!NT_SUCCESS(Status)) {
  3417. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Unable to open %ws (%lx)\n",HiveKey,Status));
  3418. goto spus_2;
  3419. }
  3420. //
  3421. // Set the upgrade status under the setup key.
  3422. //
  3423. dw = UpgradeProgressValue;
  3424. Status = SpOpenSetValueAndClose(
  3425. hKeySystemHive,
  3426. SETUP_KEY_NAME,
  3427. UPGRADE_IN_PROGRESS,
  3428. ULONG_VALUE(dw)
  3429. );
  3430. //
  3431. // Flush the key. Ignore the error
  3432. //
  3433. TempStatus = ZwFlushKey(hKeySystemHive);
  3434. if(!NT_SUCCESS(TempStatus)) {
  3435. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: ZwFlushKey %ws failed (%lx)\n",HiveKey,Status));
  3436. }
  3437. //
  3438. // Close the hive key
  3439. //
  3440. ZwClose( hKeySystemHive );
  3441. hKeySystemHive = NULL;
  3442. //
  3443. // Unload the system hive
  3444. //
  3445. TempStatus = SpLoadUnloadKey(NULL,NULL,HiveKey,NULL);
  3446. if(!NT_SUCCESS(TempStatus)) {
  3447. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: warning: unable to unload key %ws (%lx)\n",HiveKey,TempStatus));
  3448. }
  3449. HiveLoaded = FALSE;
  3450. spus_2:
  3451. //
  3452. // Unload the currently loaded hive.
  3453. //
  3454. if( HiveLoaded ) {
  3455. TempStatus = SpLoadUnloadKey(NULL,NULL,HiveKey,NULL);
  3456. if(!NT_SUCCESS(TempStatus)) {
  3457. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: warning: unable to unload key %ws (%lx)\n",HiveKey,TempStatus));
  3458. }
  3459. }
  3460. spus_1:
  3461. SpMemFree(PartitionPath);
  3462. return( Status );
  3463. }
  3464. NTSTATUS
  3465. SpGetCurrentControlSetNumber(
  3466. IN HANDLE SystemHiveRoot,
  3467. OUT PULONG Number
  3468. )
  3469. /*++
  3470. Routine Description:
  3471. This routine determines the ordinal number of the "current" control set
  3472. as indicated by the values in a SELECT key at the root of a system hive.
  3473. Arguments:
  3474. SystemHiveRoot - supplies an open key to the a key which is to be
  3475. considered the root of a system hive.
  3476. Number - If the routine is successful, recieves the ordinal number of
  3477. the "current" control set in that system hive.
  3478. Return Value:
  3479. NT Status value indicating outcome.
  3480. --*/
  3481. {
  3482. NTSTATUS Status;
  3483. UCHAR buffer[sizeof(KEY_VALUE_PARTIAL_INFORMATION)+256];
  3484. ULONG ResultLength;
  3485. Status = SpGetValueKey(
  3486. SystemHiveRoot,
  3487. L"Select",
  3488. L"Current",
  3489. sizeof(buffer),
  3490. buffer,
  3491. &ResultLength
  3492. );
  3493. if(NT_SUCCESS(Status)) {
  3494. *Number = *(DWORD *)(((PKEY_VALUE_PARTIAL_INFORMATION)buffer)->Data);
  3495. }
  3496. return(Status);
  3497. }
  3498. NTSTATUS
  3499. SpCreateControlSetSymbolicLink(
  3500. IN HANDLE SystemHiveRoot,
  3501. OUT HANDLE *CurrentControlSetRoot
  3502. )
  3503. /*++
  3504. Routine Description:
  3505. This routine creates a CurrentControlSet symbolic link, whose target
  3506. is the appropriate ControlSetxxx key within a given system hive.
  3507. The symbolic link is created volatile.
  3508. Arguments:
  3509. SystemHiveRoot - supplies a handle to a key that is to be considered
  3510. the root key of a system hive.
  3511. CurrentControlSetRoot - if this routine is successful then this receives
  3512. a handle to the open root key of the current control set, with
  3513. KEY_ALL_ACCESS.
  3514. Return Value:
  3515. NT status code indicating outcome.
  3516. --*/
  3517. {
  3518. NTSTATUS Status;
  3519. ULONG Number;
  3520. HANDLE KeyHandle;
  3521. OBJECT_ATTRIBUTES Obja;
  3522. UNICODE_STRING UnicodeString;
  3523. WCHAR name[50];
  3524. //
  3525. // First we need to figure out which control set is the "current" one.
  3526. // In the upgrade case we need to get it from looking at the existing
  3527. // hive; in the fresh install case it's always 1.
  3528. //
  3529. if(NTUpgrade == UpgradeFull) {
  3530. Status = SpGetCurrentControlSetNumber(SystemHiveRoot,&Number);
  3531. if(!NT_SUCCESS(Status)) {
  3532. return(Status);
  3533. }
  3534. } else {
  3535. Number = 1;
  3536. //
  3537. // HACK: In the fresh install case we need to make sure that there is
  3538. // a ControlSet001 value to link to! There won't be one when we get here
  3539. // because we didn't run any infs yet.
  3540. //
  3541. RtlInitUnicodeString(&UnicodeString,L"ControlSet001");
  3542. InitializeObjectAttributes(
  3543. &Obja,
  3544. &UnicodeString,
  3545. OBJ_CASE_INSENSITIVE,
  3546. SystemHiveRoot,
  3547. NULL
  3548. );
  3549. Status = ZwCreateKey(
  3550. &KeyHandle,
  3551. KEY_QUERY_VALUE,
  3552. &Obja,
  3553. 0,
  3554. NULL,
  3555. REG_OPTION_NON_VOLATILE,
  3556. NULL
  3557. );
  3558. if(!NT_SUCCESS(Status)) {
  3559. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: can't create ControlSet001 key (%lx)\n",Status));
  3560. return(Status);
  3561. }
  3562. ZwClose(KeyHandle);
  3563. }
  3564. //
  3565. // Create CurrentControlSet for create-link access.
  3566. //
  3567. RtlInitUnicodeString(&UnicodeString,L"CurrentControlSet");
  3568. InitializeObjectAttributes(
  3569. &Obja,
  3570. &UnicodeString,
  3571. OBJ_CASE_INSENSITIVE,
  3572. SystemHiveRoot,
  3573. NULL
  3574. );
  3575. Status = ZwCreateKey(
  3576. &KeyHandle,
  3577. KEY_CREATE_LINK,
  3578. &Obja,
  3579. 0,
  3580. NULL,
  3581. REG_OPTION_VOLATILE | REG_OPTION_CREATE_LINK,
  3582. NULL
  3583. );
  3584. if(!NT_SUCCESS(Status)) {
  3585. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: can't create CurrentControlSet symbolic key (%lx)\n",Status));
  3586. return(Status);
  3587. }
  3588. //
  3589. // Now set the value value in there. If the swprintf changes, make sure
  3590. // the name buffer is large enough!
  3591. //
  3592. swprintf(name,L"\\Registry\\Machine\\xSystem\\ControlSet%03d",Number);
  3593. RtlInitUnicodeString(&UnicodeString,L"SymbolicLinkValue");
  3594. Status = ZwSetValueKey(KeyHandle,&UnicodeString,0,REG_LINK,name,wcslen(name)*sizeof(WCHAR));
  3595. ZwClose(KeyHandle);
  3596. if(!NT_SUCCESS(Status)) {
  3597. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Unable to set SymbolicLinkValue for CurrentControlSet to %ws (%lx)\n",name,Status));
  3598. } else {
  3599. //
  3600. // Finally, open a handle to the key.
  3601. //
  3602. INIT_OBJA(&Obja,&UnicodeString,name);
  3603. Status = ZwOpenKey(CurrentControlSetRoot,KEY_ALL_ACCESS,&Obja);
  3604. if(!NT_SUCCESS(Status)) {
  3605. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Unable to open control set root %ws (%lx)\n",name,Status));
  3606. }
  3607. }
  3608. return(Status);
  3609. }
  3610. NTSTATUS
  3611. SpAppendStringToMultiSz(
  3612. IN HANDLE hKey,
  3613. IN PWSTR Subkey,
  3614. IN PWSTR ValueName,
  3615. IN PWSTR StringToAdd
  3616. )
  3617. {
  3618. NTSTATUS Status;
  3619. ULONG Length;
  3620. PUCHAR Data;
  3621. Status = SpGetValueKey(
  3622. hKey,
  3623. Subkey,
  3624. ValueName,
  3625. sizeof(TemporaryBuffer),
  3626. (PCHAR)TemporaryBuffer,
  3627. &Length
  3628. );
  3629. if(!NT_SUCCESS(Status)) {
  3630. return(Status);
  3631. }
  3632. Data = ((PKEY_VALUE_PARTIAL_INFORMATION)TemporaryBuffer)->Data;
  3633. Length = ((PKEY_VALUE_PARTIAL_INFORMATION)TemporaryBuffer)->DataLength;
  3634. //
  3635. // Stick on end. For a multi_sz there has to be at least
  3636. // the terminating nul, but just to be safe we'll be robust.
  3637. //
  3638. ASSERT(Length);
  3639. if(!Length) {
  3640. *(PWCHAR)Data = 0;
  3641. Length = sizeof(WCHAR);
  3642. }
  3643. //
  3644. // Append new string to end and add new terminating 0.
  3645. //
  3646. wcscpy((PWSTR)(Data+Length-sizeof(WCHAR)),StringToAdd);
  3647. Length += (wcslen(StringToAdd)+1)*sizeof(WCHAR);
  3648. *(PWCHAR)(Data+Length-sizeof(WCHAR)) = 0;
  3649. //
  3650. // Write back out to registry.
  3651. //
  3652. Status = SpOpenSetValueAndClose(
  3653. hKey,
  3654. Subkey,
  3655. ValueName,
  3656. REG_MULTI_SZ,
  3657. Data,
  3658. Length
  3659. );
  3660. return(Status);
  3661. }
  3662. NTSTATUS
  3663. SpRemoveStringFromMultiSz(
  3664. IN HANDLE KeyHandle,
  3665. IN PWSTR SubKey OPTIONAL,
  3666. IN PWSTR ValueName,
  3667. IN PWSTR StringToRemove
  3668. )
  3669. /*++
  3670. Routine Description:
  3671. Removes the specified string from the given multi_sz value.
  3672. Arguments:
  3673. KeyHandle - The handle to the key which contains the value or
  3674. the SubKey.
  3675. SubKey - The subkey name which contains the value.
  3676. ValueName - The value name which is under the SubKey or the
  3677. Key reachable by KeyHandle.
  3678. StringToRemove - The string that needs to be removed from
  3679. from the multi_sz strings.
  3680. Return Value:
  3681. Appropriate NT status error code.
  3682. --*/
  3683. {
  3684. NTSTATUS Status = STATUS_INVALID_PARAMETER;
  3685. //
  3686. // Validate parameters
  3687. //
  3688. if (KeyHandle && ValueName && StringToRemove) {
  3689. HANDLE NewKeyHandle = KeyHandle;
  3690. HANDLE SubKeyHandle = NULL;
  3691. Status = STATUS_SUCCESS;
  3692. //
  3693. // Open the subkey if needed
  3694. //
  3695. if (SubKey) {
  3696. UNICODE_STRING SubKeyName;
  3697. OBJECT_ATTRIBUTES ObjAttrs;
  3698. INIT_OBJA(&ObjAttrs, &SubKeyName, SubKey);
  3699. ObjAttrs.RootDirectory = KeyHandle;
  3700. Status = ZwOpenKey(&SubKeyHandle,
  3701. KEY_ALL_ACCESS,
  3702. &ObjAttrs);
  3703. if (NT_SUCCESS(Status)) {
  3704. NewKeyHandle = SubKeyHandle;
  3705. }
  3706. }
  3707. if (NT_SUCCESS(Status)) {
  3708. ULONG ResultLength = 0;
  3709. PWSTR Buffer = NULL;
  3710. ULONG BufferLength = 0;
  3711. UNICODE_STRING ValueNameStr;
  3712. RtlInitUnicodeString(&ValueNameStr, ValueName);
  3713. Status = ZwQueryValueKey(NewKeyHandle,
  3714. &ValueNameStr,
  3715. KeyValueFullInformation,
  3716. NULL,
  3717. 0,
  3718. &ResultLength);
  3719. //
  3720. // Is there something to process ?
  3721. //
  3722. if (ResultLength &&
  3723. (Status == STATUS_BUFFER_OVERFLOW) || (Status == STATUS_BUFFER_TOO_SMALL)) {
  3724. //
  3725. // Allocate adequate buffer
  3726. //
  3727. BufferLength = ResultLength + (2 * sizeof(WCHAR));
  3728. Buffer = (PWSTR)SpMemAlloc(BufferLength);
  3729. if (Buffer) {
  3730. PKEY_VALUE_FULL_INFORMATION ValueInfo;
  3731. //
  3732. // Get the current value
  3733. //
  3734. ValueInfo = (PKEY_VALUE_FULL_INFORMATION)Buffer;
  3735. Status = ZwQueryValueKey(NewKeyHandle,
  3736. &ValueNameStr,
  3737. KeyValueFullInformation,
  3738. ValueInfo,
  3739. BufferLength,
  3740. &ResultLength);
  3741. if (NT_SUCCESS(Status)) {
  3742. //
  3743. // Verify that its REG_MULTI_SZ or REG_SZ type
  3744. // NOTE : We allow REG_SZ also since in some W2K installations
  3745. // the string type is REG_SZ for class upperfilters & lowerfilters
  3746. //
  3747. if ((ValueInfo->Type == REG_MULTI_SZ) ||
  3748. (ValueInfo->Type == REG_SZ)){
  3749. PWSTR CurrString = (PWSTR)(((PUCHAR)ValueInfo + ValueInfo->DataOffset));
  3750. BOOLEAN Found = FALSE;
  3751. ULONG BytesToProcess = ValueInfo->DataLength;
  3752. ULONG BytesProcessed;
  3753. ULONG Length;
  3754. //
  3755. // null terminate the string (we allocated enough buffer space above)
  3756. //
  3757. CurrString[ValueInfo->DataLength/sizeof(WCHAR)] = UNICODE_NULL;
  3758. CurrString[(ValueInfo->DataLength/sizeof(WCHAR))+1] = UNICODE_NULL;
  3759. //
  3760. // Search for an occurrence of the string to replace
  3761. //
  3762. for (BytesProcessed = 0;
  3763. (!Found && (BytesProcessed < BytesToProcess));
  3764. CurrString += (Length + 1), BytesProcessed += ((Length + 1) * sizeof(WCHAR)))
  3765. {
  3766. Length = wcslen(CurrString);
  3767. if (Length && !_wcsicmp(CurrString, StringToRemove)) {
  3768. Found = TRUE;
  3769. }
  3770. }
  3771. if (Found) {
  3772. //
  3773. // We found an occurrence -- allocate new buffer to selectively
  3774. // copy the required information from the old string
  3775. //
  3776. PWSTR NewString = (PWSTR)(SpMemAlloc(ValueInfo->DataLength));
  3777. if (NewString) {
  3778. PWSTR CurrDestString = NewString;
  3779. RtlZeroMemory(NewString, ValueInfo->DataLength);
  3780. CurrString = (PWSTR)(((PUCHAR)ValueInfo + ValueInfo->DataOffset));
  3781. CurrString[ValueInfo->DataLength/sizeof(WCHAR)] = UNICODE_NULL;
  3782. CurrString[(ValueInfo->DataLength/sizeof(WCHAR))+1] = UNICODE_NULL;
  3783. //
  3784. // Copy all the strings except the one's to skip
  3785. //
  3786. for (BytesProcessed = 0;
  3787. (BytesProcessed < BytesToProcess);
  3788. CurrString += (Length + 1), BytesProcessed += ((Length + 1) * sizeof(WCHAR)))
  3789. {
  3790. Length = wcslen(CurrString);
  3791. //
  3792. // copy the unmatched non-empty source string to destination
  3793. //
  3794. if (Length && (_wcsicmp(CurrString, StringToRemove))) {
  3795. wcscpy(CurrDestString, CurrString);
  3796. CurrDestString += (Length + 1);
  3797. }
  3798. }
  3799. //
  3800. // Set the string back if its not empty
  3801. //
  3802. if (CurrDestString != NewString) {
  3803. *CurrDestString++ = UNICODE_NULL;
  3804. //
  3805. // Set the new value back
  3806. //
  3807. Status = ZwSetValueKey(NewKeyHandle,
  3808. &ValueNameStr,
  3809. 0,
  3810. REG_MULTI_SZ,
  3811. NewString,
  3812. ((CurrDestString - NewString) * sizeof(WCHAR)));
  3813. } else {
  3814. //
  3815. // Remove the empty value
  3816. //
  3817. Status = ZwDeleteValueKey(NewKeyHandle,
  3818. &ValueNameStr);
  3819. }
  3820. //
  3821. // done with the buffer
  3822. //
  3823. SpMemFree(NewString);
  3824. } else {
  3825. Status = STATUS_NO_MEMORY;
  3826. }
  3827. } else {
  3828. Status = STATUS_OBJECT_NAME_NOT_FOUND;
  3829. }
  3830. } else {
  3831. Status = STATUS_INVALID_PARAMETER;
  3832. }
  3833. }
  3834. SpMemFree(Buffer);
  3835. } else {
  3836. Status = STATUS_NO_MEMORY;
  3837. }
  3838. }
  3839. }
  3840. if (SubKeyHandle) {
  3841. ZwClose(SubKeyHandle);
  3842. }
  3843. }
  3844. return Status;
  3845. }
  3846. NTSTATUS
  3847. SpGetValueKey(
  3848. IN HANDLE hKeyRoot,
  3849. IN PWSTR KeyName,
  3850. IN PWSTR ValueName,
  3851. IN ULONG BufferLength,
  3852. OUT PUCHAR Buffer,
  3853. OUT PULONG ResultLength
  3854. )
  3855. {
  3856. UNICODE_STRING UnicodeString;
  3857. OBJECT_ATTRIBUTES Obja;
  3858. NTSTATUS Status;
  3859. HANDLE hKey = NULL;
  3860. //
  3861. // Open the key for read access
  3862. //
  3863. INIT_OBJA(&Obja,&UnicodeString,KeyName);
  3864. Obja.RootDirectory = hKeyRoot;
  3865. #if 0
  3866. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_INFO_LEVEL, "+ [spconfig.c:%lu] KeyName %ws\n", __LINE__, KeyName ));
  3867. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_INFO_LEVEL, "+ [spconfig.c:%lu] ValueName %ws\n", __LINE__, UnicodeString ));
  3868. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_INFO_LEVEL, "+ [spconfig.c:%lu] UnicodeString %ws\n", __LINE__, UnicodeString ));
  3869. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_INFO_LEVEL, "+ [spconfig.c:%lu] UnicodeString %S\n", __LINE__, UnicodeString ));
  3870. #endif
  3871. Status = ZwOpenKey(&hKey,KEY_READ,&Obja);
  3872. if(!NT_SUCCESS(Status)) {
  3873. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_WARNING_LEVEL, "SETUP: SpGetValueKey: couldn't open key %ws for read access (%lx)\n",KeyName, Status));
  3874. }
  3875. else {
  3876. //
  3877. // Find out the value of the Current value
  3878. //
  3879. RtlInitUnicodeString(&UnicodeString,ValueName);
  3880. Status = ZwQueryValueKey(
  3881. hKey,
  3882. &UnicodeString,
  3883. KeyValuePartialInformation,
  3884. Buffer,
  3885. BufferLength,
  3886. ResultLength
  3887. );
  3888. if(!NT_SUCCESS(Status)) {
  3889. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_WARNING_LEVEL, "SETUP: SpGetValueKey: couldn't query value %ws in key %ws (%lx)\n",ValueName,KeyName,Status));
  3890. }
  3891. }
  3892. if( hKey ) {
  3893. ZwClose( hKey );
  3894. }
  3895. return( Status );
  3896. }
  3897. NTSTATUS
  3898. SpDeleteValueKey(
  3899. IN HANDLE hKeyRoot,
  3900. IN PWSTR KeyName,
  3901. IN PWSTR ValueName
  3902. )
  3903. {
  3904. UNICODE_STRING UnicodeString;
  3905. OBJECT_ATTRIBUTES Obja;
  3906. NTSTATUS Status;
  3907. HANDLE hKey = NULL;
  3908. //
  3909. // Open the key for read access
  3910. //
  3911. INIT_OBJA(&Obja,&UnicodeString,KeyName);
  3912. Obja.RootDirectory = hKeyRoot;
  3913. Status = ZwOpenKey(&hKey,KEY_SET_VALUE,&Obja);
  3914. if(!NT_SUCCESS(Status)) {
  3915. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: SpDeleteValueKey: couldn't open key %ws for write access (%lx)\n",KeyName, Status));
  3916. }
  3917. else {
  3918. //
  3919. // Find out the value of the Current value
  3920. //
  3921. RtlInitUnicodeString(&UnicodeString,ValueName);
  3922. Status = ZwDeleteValueKey(
  3923. hKey,
  3924. &UnicodeString
  3925. );
  3926. if(!NT_SUCCESS(Status)) {
  3927. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: SpDeleteValueKey: couldn't delete value %ws in key %ws (%lx)\n",ValueName,KeyName,Status));
  3928. }
  3929. }
  3930. if( hKey ) {
  3931. ZwClose( hKey );
  3932. }
  3933. return( Status );
  3934. }
  3935. BOOLEAN
  3936. SpReadSKUStuff(
  3937. VOID
  3938. )
  3939. /*++
  3940. Routine Description:
  3941. Read SKU differentiation data from the setup hive we are currently
  3942. running on.
  3943. In the unnamed key of our driver node, there is a REG_BINARY that
  3944. tells us whether this is stepup mode, and/or whether this is an
  3945. evaluation unit (gives us the time in minutes).
  3946. Arguments:
  3947. None.
  3948. Return Value:
  3949. Boolean value indicating outcome.
  3950. If TRUE, StepUpMode and EvaluationTime globals are filled in.
  3951. If FALSE, product may have been tampered with.
  3952. --*/
  3953. {
  3954. NTSTATUS Status;
  3955. PKEY_VALUE_PARTIAL_INFORMATION ValueInfo;
  3956. PULONG Values;
  3957. ULONG ResultLength;
  3958. OBJECT_ATTRIBUTES Obja;
  3959. UNICODE_STRING UnicodeString;
  3960. HKEY Key;
  3961. INIT_OBJA(&Obja,&UnicodeString,LOCAL_MACHINE_KEY_NAME);
  3962. Status = ZwOpenKey(&Key,KEY_READ,&Obja);
  3963. if(!NT_SUCCESS(Status)) {
  3964. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Failed to open %ws (Status = %lx)\n",LOCAL_MACHINE_KEY_NAME,Status));
  3965. return(FALSE);
  3966. }
  3967. Status = SpGetValueKey(
  3968. Key,
  3969. L"System\\ControlSet001\\Services\\setupdd",
  3970. L"",
  3971. sizeof(TemporaryBuffer),
  3972. (PCHAR)TemporaryBuffer,
  3973. &ResultLength
  3974. );
  3975. ZwClose(Key);
  3976. ValueInfo = (PKEY_VALUE_PARTIAL_INFORMATION)TemporaryBuffer;
  3977. //
  3978. // This line of code depends on the setup hive setupreg.hiv
  3979. // (see oak\bin\setupreg.ini).
  3980. //
  3981. if(NT_SUCCESS(Status) && (ValueInfo->Type == REG_BINARY) && (ValueInfo->DataLength == 16)) {
  3982. Values = (PULONG)ValueInfo->Data;
  3983. //
  3984. // First DWORD is eval time, second is stepup boolean, third is restric cpu val, fourth is suite
  3985. //
  3986. EvaluationTime = Values[0];
  3987. StepUpMode = (BOOLEAN)Values[1];
  3988. RestrictCpu = Values[2];
  3989. SuiteType = Values[3];
  3990. return(TRUE);
  3991. }
  3992. return(FALSE);
  3993. }
  3994. VOID
  3995. SpSetDirtyShutdownFlag(
  3996. IN PDISK_REGION TargetRegion,
  3997. IN PWSTR SystemRoot
  3998. )
  3999. {
  4000. NTSTATUS Status;
  4001. PWSTR HiveRootPath;
  4002. PWSTR HiveFilePath;
  4003. BOOLEAN HiveLoaded;
  4004. OBJECT_ATTRIBUTES Obja;
  4005. UNICODE_STRING UnicodeString;
  4006. HANDLE HiveRootKey;
  4007. UCHAR buffer[sizeof(KEY_VALUE_PARTIAL_INFORMATION)+sizeof(DISK_CONFIG_HEADER)];
  4008. ULONG ResultLength;
  4009. PDISK_CONFIG_HEADER DiskHeader;
  4010. //
  4011. // Get the name of the target patition.
  4012. //
  4013. SpNtNameFromRegion(
  4014. TargetRegion,
  4015. TemporaryBuffer,
  4016. sizeof(TemporaryBuffer),
  4017. PartitionOrdinalCurrent
  4018. );
  4019. //
  4020. // Form the name of the hive file.
  4021. // This is partitionpath + sysroot + system32\config + the hive name.
  4022. //
  4023. SpConcatenatePaths(TemporaryBuffer, SystemRoot);
  4024. SpConcatenatePaths(TemporaryBuffer,L"system32\\config\\system");
  4025. HiveFilePath = SpDupStringW(TemporaryBuffer);
  4026. //
  4027. // Form the path of the key into which we will
  4028. // load the hive. We'll use the convention that
  4029. // a hive will be loaded into \registry\machine\x<hivename>.
  4030. //
  4031. wcscpy(TemporaryBuffer,LOCAL_MACHINE_KEY_NAME);
  4032. SpConcatenatePaths(TemporaryBuffer,L"x");
  4033. wcscat(TemporaryBuffer,L"system");
  4034. HiveRootPath = SpDupStringW(TemporaryBuffer);
  4035. ASSERT(HiveRootPath);
  4036. //
  4037. // Attempt to load the key.
  4038. //
  4039. HiveLoaded = FALSE;
  4040. Status = SpLoadUnloadKey(NULL,NULL,HiveRootPath,HiveFilePath);
  4041. if(!NT_SUCCESS(Status)) {
  4042. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Unable to load hive %ws to key %ws (%lx)\n",HiveFilePath,HiveRootPath,Status));
  4043. goto setdirty1;
  4044. }
  4045. HiveLoaded = TRUE;
  4046. //
  4047. // Now get a key to the root of the hive we just loaded.
  4048. //
  4049. INIT_OBJA(&Obja,&UnicodeString,HiveRootPath);
  4050. Status = ZwOpenKey(&HiveRootKey,KEY_ALL_ACCESS,&Obja);
  4051. if(!NT_SUCCESS(Status)) {
  4052. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Unable to open %ws (%lx)\n",HiveRootPath,Status));
  4053. goto setdirty1;
  4054. }
  4055. //
  4056. // Make the appropriate change
  4057. //
  4058. Status = SpGetValueKey(
  4059. HiveRootKey,
  4060. L"DISK",
  4061. L"Information",
  4062. sizeof(TemporaryBuffer),
  4063. (PCHAR)TemporaryBuffer,
  4064. &ResultLength
  4065. );
  4066. //
  4067. // TemporaryBuffer is 32kb long, and it should be big enough
  4068. // for the data.
  4069. //
  4070. ASSERT( Status != STATUS_BUFFER_OVERFLOW );
  4071. if(!NT_SUCCESS(Status)) {
  4072. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Unable to read value from registry. KeyName = Disk, ValueName = Information, Status = (%lx)\n",Status));
  4073. goto setdirty1;
  4074. }
  4075. DiskHeader = ( PDISK_CONFIG_HEADER )(((PKEY_VALUE_PARTIAL_INFORMATION)TemporaryBuffer)->Data);
  4076. DiskHeader->DirtyShutdown = TRUE;
  4077. Status = SpOpenSetValueAndClose( HiveRootKey,
  4078. L"DISK",
  4079. L"Information",
  4080. REG_BINARY,
  4081. DiskHeader,
  4082. ((PKEY_VALUE_PARTIAL_INFORMATION)TemporaryBuffer)->DataLength
  4083. );
  4084. if(!NT_SUCCESS(Status)) {
  4085. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Unable to write value to registry. KeyName = Disk, ValueName = Information, Status = (%lx)\n",Status));
  4086. goto setdirty1;
  4087. }
  4088. setdirty1:
  4089. //
  4090. // Flush the hive.
  4091. //
  4092. if(HiveLoaded && HiveRootKey) {
  4093. NTSTATUS stat;
  4094. stat = ZwFlushKey(HiveRootKey);
  4095. if(!NT_SUCCESS(stat)) {
  4096. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: ZwFlushKey x%ws failed (%lx)\n", HiveRootPath, Status));
  4097. }
  4098. }
  4099. if(HiveLoaded) {
  4100. //
  4101. // We don't want to disturb the value of Status
  4102. // so use a we'll different variable below.
  4103. //
  4104. NTSTATUS stat;
  4105. if(HiveRootKey!=NULL) {
  4106. ZwClose(HiveRootKey);
  4107. HiveRootKey = NULL;
  4108. }
  4109. //
  4110. // Unload the hive.
  4111. //
  4112. stat = SpLoadUnloadKey(NULL,NULL,HiveRootPath,NULL);
  4113. if(!NT_SUCCESS(stat)) {
  4114. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: warning: unable to unload key %ws (%lx)\n",HiveRootPath,stat));
  4115. }
  4116. HiveLoaded = FALSE;
  4117. }
  4118. SpMemFree(HiveRootPath);
  4119. SpMemFree(HiveFilePath);
  4120. //
  4121. // If we fail to set the DirtyShutdown flag, then we silently fail
  4122. // because there is nothing that the user can do about, and the system
  4123. // is unlikely to boot anyway.
  4124. // This will occur if setup fails to:
  4125. //
  4126. // - Load the system hive
  4127. // - Open System\Disk key
  4128. // - Read the value entry
  4129. // - Write the value entry
  4130. // - Unload the system hive
  4131. //
  4132. if(!NT_SUCCESS(Status)) {
  4133. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: setup was unable to set DirtyShutdown flag. Status = (%lx)\n", Status));
  4134. }
  4135. }
  4136. NTSTATUS
  4137. SpPostprocessHives(
  4138. IN PWSTR PartitionPath,
  4139. IN PWSTR Sysroot,
  4140. IN PCWSTR *HiveNames,
  4141. IN HANDLE *HiveRootKeys,
  4142. IN unsigned HiveCount,
  4143. IN HANDLE hKeyCCS
  4144. )
  4145. {
  4146. NTSTATUS Status;
  4147. ULONG u;
  4148. unsigned h;
  4149. PWSTR SaveHiveName;
  4150. PWSTR HiveName;
  4151. HANDLE SaveHiveHandle;
  4152. IO_STATUS_BLOCK IoStatusBlock;
  4153. OBJECT_ATTRIBUTES ObjectAttributes;
  4154. OBJECT_ATTRIBUTES ObjectAttributes2;
  4155. UNICODE_STRING UnicodeString;
  4156. UNICODE_STRING UnicodeString2;
  4157. DWORD MangledVersion;
  4158. PWSTR Value;
  4159. PWSTR SecurityHives[] = {
  4160. L"sam",
  4161. L"security"
  4162. };
  4163. //
  4164. // Flush all hives.
  4165. //
  4166. for(h=0; h<HiveCount; h++) {
  4167. Status = ZwFlushKey(HiveRootKeys[h]);
  4168. if(!NT_SUCCESS(Status)) {
  4169. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Warning: ZwFlushKey %ws failed (%lx)\n",HiveNames[h],Status));
  4170. }
  4171. SendSetupProgressEvent(SavingSettingsEvent, SaveHiveEvent, NULL);
  4172. }
  4173. //
  4174. // If GUI setup is supposed to be restartable, we need to add an entry
  4175. // to the BootExecute list, to cause sprestrt.exe to run.
  4176. // Also, we want system.sav to have a RestartSetup=TRUE value in it,
  4177. // but we want the actual system hive to have RestartSetup=FALSE.
  4178. //
  4179. if(RestartableGuiSetup) {
  4180. Status = SpAppendStringToMultiSz(
  4181. hKeyCCS,
  4182. SESSION_MANAGER_KEY,
  4183. BOOT_EXECUTE,
  4184. L"sprestrt"
  4185. );
  4186. if(NT_SUCCESS(Status)) {
  4187. //
  4188. // Add a RestartSetup value, set to TRUE.
  4189. // To understand why we use a different value here in upgrade
  4190. // and non-upgrade case, see discussion below.
  4191. //
  4192. u = (NTUpgrade == UpgradeFull) ? 0 : 1;
  4193. Status = SpOpenSetValueAndClose(
  4194. HiveRootKeys[SetupHiveSystem],
  4195. SETUP_KEY_NAME,
  4196. RESTART_SETUP,
  4197. ULONG_VALUE(u)
  4198. );
  4199. }
  4200. } else {
  4201. Status = STATUS_SUCCESS;
  4202. }
  4203. //
  4204. // Do the final update of device instance data.
  4205. //
  4206. if((NTUpgrade == UpgradeFull)) {
  4207. //
  4208. // SANTOSHJ: This whole code needs to go away for BLACKCOMB.
  4209. //
  4210. Value = SpGetSectionKeyIndex(WinntSifHandle,
  4211. SIF_DATA, WINNT_D_WIN32_VER_W, 0);
  4212. if(Value) {
  4213. //
  4214. // version is bbbbllhh - build/low/high
  4215. //
  4216. MangledVersion = (DWORD)SpStringToLong( Value, NULL, 16 );
  4217. if (LOWORD(MangledVersion) == 0x0105) {
  4218. Status = SpUpdateDeviceInstanceData(hKeyCCS);
  4219. if (!NT_SUCCESS(Status)) {
  4220. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Could not update device instance data. Status = (%lx)\n",Status));
  4221. return(Status);
  4222. }
  4223. }
  4224. }
  4225. }
  4226. //
  4227. // At this point, we no longer need hKeyCCS, so we close the key.
  4228. // Note that key needs to be closed before we call ZwReplaceKey, otherwise
  4229. // this API will fail.
  4230. //
  4231. // Note also, that the caller of this function expects this function to close this handle
  4232. // before it returns.
  4233. //
  4234. NtClose(hKeyCCS);
  4235. if(NT_SUCCESS(Status)) {
  4236. //
  4237. // Save out the hives to *.sav in the initial install case,
  4238. // or *.tmp in the upgrade case.
  4239. //
  4240. for(h=0; NT_SUCCESS(Status) && (h<HiveCount); h++) {
  4241. //
  4242. // Form full pathname of hive file.
  4243. //
  4244. wcscpy(TemporaryBuffer,PartitionPath);
  4245. SpConcatenatePaths(TemporaryBuffer,Sysroot);
  4246. SpConcatenatePaths(TemporaryBuffer,L"system32\\config");
  4247. SpConcatenatePaths(TemporaryBuffer,HiveNames[h]);
  4248. wcscat(TemporaryBuffer,(NTUpgrade == UpgradeFull) ? L".tmp" : L".sav");
  4249. SaveHiveName = SpDupStringW(TemporaryBuffer);
  4250. SpDeleteFile( SaveHiveName, NULL, NULL ); // Make sure that we get rid of the file if it has attributes.
  4251. INIT_OBJA(&ObjectAttributes,&UnicodeString,SaveHiveName);
  4252. Status = ZwCreateFile(
  4253. &SaveHiveHandle,
  4254. FILE_GENERIC_WRITE,
  4255. &ObjectAttributes,
  4256. &IoStatusBlock,
  4257. NULL,
  4258. FILE_ATTRIBUTE_NORMAL,
  4259. 0, // no sharing
  4260. FILE_OVERWRITE_IF,
  4261. FILE_NON_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT,
  4262. NULL,
  4263. 0
  4264. );
  4265. if(NT_SUCCESS(Status)) {
  4266. //
  4267. // call the Ex version to make sure the hive is saved in the lates format
  4268. //
  4269. Status = ZwSaveKeyEx(HiveRootKeys[h],SaveHiveHandle,REG_LATEST_FORMAT);
  4270. if(!NT_SUCCESS(Status)) {
  4271. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: save key into %ws failed (%lx)\n",SaveHiveName,Status));
  4272. }
  4273. ZwClose(SaveHiveHandle);
  4274. } else {
  4275. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: unable to create file %ws to save hive (%lx)\n",SaveHiveName,Status));
  4276. }
  4277. //
  4278. // In the upgrade case, there is significant benefit to ensuring that
  4279. // the hives are in the latest format. A hive that has been created
  4280. // via NtSaveKeyEx(...,...,REG_LATEST_FORMAT) is guaranteed to be in the latest format.
  4281. // Since we just did a SaveKey, xxx.tmp is in the latest format,
  4282. // and we should use that as the xxx hive from now on. The existing
  4283. // (old-format) hive can be retained as xxx.sav.
  4284. //
  4285. // NtReplaceKey does exactly what we want, but we have to make sure
  4286. // that there is no .sav file already there, because that causes
  4287. // NtReplaceKey to fail with STATUS_OBJECT_NAME_COLLISION.
  4288. //
  4289. // After NtReplaceKey is done, the hive root keys refer to the .sav
  4290. // on-disk file but the extensionless on-disk file will be used at next
  4291. // boot. Thus we need to be careful about how we write the restart values
  4292. // into the hives.
  4293. //
  4294. if(NT_SUCCESS(Status) && (NTUpgrade == UpgradeFull)) {
  4295. HiveName = SpDupStringW(SaveHiveName);
  4296. wcscpy(HiveName+wcslen(HiveName)-3,L"sav");
  4297. SpDeleteFile(HiveName,NULL,NULL);
  4298. INIT_OBJA(&ObjectAttributes,&UnicodeString,SaveHiveName);
  4299. INIT_OBJA(&ObjectAttributes2,&UnicodeString2,HiveName);
  4300. Status = ZwReplaceKey(&ObjectAttributes,HiveRootKeys[h],&ObjectAttributes2);
  4301. }
  4302. SpMemFree(SaveHiveName);
  4303. }
  4304. }
  4305. if(NT_SUCCESS(Status) && (NTUpgrade == UpgradeFull)) {
  4306. //
  4307. // In the upgarde case, make a backup of the security
  4308. // hives. They need to be restored if the system is restartable.
  4309. //
  4310. //
  4311. // Initialize the diamond decompression engine.
  4312. // This needs to be done, because SpCopyFileUsingNames() uses
  4313. // the decompression engine.
  4314. //
  4315. SpdInitialize();
  4316. for( h = 0; h < sizeof(SecurityHives)/sizeof(PWSTR); h++ ) {
  4317. PWSTR p, q;
  4318. wcscpy(TemporaryBuffer,PartitionPath);
  4319. SpConcatenatePaths(TemporaryBuffer,Sysroot);
  4320. SpConcatenatePaths(TemporaryBuffer,L"system32\\config");
  4321. SpConcatenatePaths(TemporaryBuffer,SecurityHives[h]);
  4322. p = SpDupStringW(TemporaryBuffer);
  4323. wcscat(TemporaryBuffer, L".sav");
  4324. q = SpDupStringW(TemporaryBuffer);
  4325. Status = SpCopyFileUsingNames( p, q, 0, 0 );
  4326. if( !NT_SUCCESS(Status) ) {
  4327. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: unable to create backup file %ws. Status = %lx\n", q, Status));
  4328. }
  4329. SpMemFree(p);
  4330. SpMemFree(q);
  4331. if( !NT_SUCCESS(Status) ) {
  4332. break;
  4333. }
  4334. }
  4335. //
  4336. // Terminate diamond.
  4337. //
  4338. SpdTerminate();
  4339. }
  4340. if(NT_SUCCESS(Status) && RestartableGuiSetup) {
  4341. //
  4342. // Set RestartSetup to FALSE in mainline hive.
  4343. // To understand why we use a different value here in upgrade
  4344. // and non-upgrade case, see discussion above.
  4345. //
  4346. u = (NTUpgrade == UpgradeFull) ? 1 : 0;
  4347. Status = SpOpenSetValueAndClose(
  4348. HiveRootKeys[SetupHiveSystem],
  4349. SETUP_KEY_NAME,
  4350. RESTART_SETUP,
  4351. ULONG_VALUE(u)
  4352. );
  4353. }
  4354. return(Status);
  4355. }
  4356. NTSTATUS
  4357. SpSaveSetupPidList(
  4358. IN HANDLE hKeySystemHive
  4359. )
  4360. /*++
  4361. Routine Description:
  4362. Save the Product Id read from setup.ini on HKEY_LOCAL_MACHINE\SYSTEM\Setup\\Pid.
  4363. Also create the key HKEY_LOCAL_MACHINE\SYSTEM\Setup\PidList, and create
  4364. value entries under this key that contain various Pid20 found in the other
  4365. systems installed on this machine (the contents Pid20Array).
  4366. Arguments:
  4367. hKeySystemHive - supplies handle to root of the system hive
  4368. (ie, HKEY_LOCAL_MACHINE\System).
  4369. Return Value:
  4370. Status value indicating outcome of operation.
  4371. --*/
  4372. {
  4373. PWSTR ValueName;
  4374. NTSTATUS Status;
  4375. ULONG i;
  4376. //
  4377. // First save the Pid read from setup.ini
  4378. //
  4379. if( PidString != NULL ) {
  4380. Status = SpOpenSetValueAndClose( hKeySystemHive,
  4381. L"Setup\\Pid",
  4382. L"Pid",
  4383. STRING_VALUE(PidString)
  4384. );
  4385. if(!NT_SUCCESS(Status)) {
  4386. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Unable to save Pid on SYSTEM\\Setup\\Pid. Status = %lx\n", Status ));
  4387. }
  4388. }
  4389. //
  4390. // If Pid20Array is empty, then don't bother to create the Pid key
  4391. //
  4392. if( Pid20Array == NULL || Pid20Array[0] == NULL ) {
  4393. return( STATUS_SUCCESS );
  4394. }
  4395. //
  4396. // Can't use TemporaryBuffer because we make subroutine calls
  4397. // below that trash its contents.
  4398. // Note that a buffer of size MAX_PATH for a value name is more than enough.
  4399. //
  4400. ValueName = SpMemAlloc((MAX_PATH+1)*sizeof(WCHAR));
  4401. for( i = 0; Pid20Array[i] != NULL; i++ ) {
  4402. swprintf( ValueName, L"Pid_%d", i );
  4403. Status = SpOpenSetValueAndClose( hKeySystemHive,
  4404. L"Setup\\PidList",
  4405. ValueName,
  4406. STRING_VALUE(Pid20Array[i])
  4407. );
  4408. if(!NT_SUCCESS(Status)) {
  4409. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Unable to open or create SYSTEM\\Setup\\PidList. ValueName = %ws, ValueData = %ws, Status = %lx\n",
  4410. ValueName, Pid20Array[i] ));
  4411. }
  4412. }
  4413. SpMemFree(ValueName);
  4414. return( STATUS_SUCCESS );
  4415. }
  4416. NTSTATUS
  4417. SpSavePreinstallHwInfo(
  4418. IN PVOID SifHandle,
  4419. IN PWSTR SystemRoot,
  4420. IN HANDLE hKeyPreinstall,
  4421. IN ULONG ComponentIndex,
  4422. IN PHARDWARE_COMPONENT pHwList
  4423. )
  4424. {
  4425. NTSTATUS Status;
  4426. NTSTATUS SaveStatus;
  4427. PHARDWARE_COMPONENT TmpHw;
  4428. PHARDWARE_COMPONENT_FILE File;
  4429. PWSTR OemTag = L"OemComponent";
  4430. PWSTR RetailClass = L"RetailClassToDisable";
  4431. PWSTR ClassName;
  4432. ULONG u;
  4433. WCHAR NodeName[9];
  4434. PWSTR ServiceName;
  4435. SaveStatus = STATUS_SUCCESS;
  4436. for( TmpHw = pHwList; TmpHw != NULL; TmpHw = TmpHw->Next ) {
  4437. if( !TmpHw->ThirdPartyOptionSelected ) {
  4438. u = 0;
  4439. if( ( ComponentIndex == HwComponentKeyboard ) ||
  4440. ( ComponentIndex == HwComponentMouse ) ) {
  4441. ServiceName = SpGetSectionKeyIndex(SifHandle,
  4442. NonlocalizedComponentNames[ComponentIndex],
  4443. TmpHw->IdString,
  4444. INDEX_INFKEYNAME);
  4445. } else {
  4446. ServiceName = TmpHw->IdString;
  4447. }
  4448. Status = SpOpenSetValueAndClose( hKeyPreinstall,
  4449. ServiceName,
  4450. OemTag,
  4451. ULONG_VALUE(u)
  4452. );
  4453. if( !NT_SUCCESS( Status ) ) {
  4454. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Failed to save information for preinstalled retail driver %ls. Status = %lx \n", TmpHw->IdString, Status ));
  4455. if( SaveStatus == STATUS_SUCCESS ) {
  4456. SaveStatus = Status;
  4457. }
  4458. }
  4459. } else {
  4460. //
  4461. // Find the name of the service, save it, and indicate if there is
  4462. // a retail class driver that needs to be disabled if the service
  4463. // initializes successfully.
  4464. //
  4465. if( IS_FILETYPE_PRESENT(TmpHw->FileTypeBits, HwFileClass) ) {
  4466. if( ComponentIndex == HwComponentKeyboard ) {
  4467. ClassName = L"kbdclass";
  4468. } else if( ComponentIndex == HwComponentMouse ) {
  4469. ClassName = L"mouclass";
  4470. } else {
  4471. ClassName = NULL;
  4472. }
  4473. } else {
  4474. ClassName = NULL;
  4475. }
  4476. for(File=TmpHw->Files; File; File=File->Next) {
  4477. PWSTR p;
  4478. //
  4479. // If there is to be no node for this file, skip it.
  4480. //
  4481. if(!File->ConfigName) {
  4482. continue;
  4483. }
  4484. //
  4485. // Calculate the node name. This is the name of the driver
  4486. // without the extension.
  4487. //
  4488. wcsncpy(NodeName,File->Filename,8);
  4489. NodeName[8] = L'\0';
  4490. if(p = wcschr(NodeName,L'.')) {
  4491. *p = L'\0';
  4492. }
  4493. u = 1;
  4494. Status = SpOpenSetValueAndClose( hKeyPreinstall,
  4495. NodeName,
  4496. OemTag,
  4497. ULONG_VALUE(u)
  4498. );
  4499. if( !NT_SUCCESS( Status ) ) {
  4500. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Failed to save information for preinstalled OEM driver %ls. Status = %lx \n", NodeName, Status ));
  4501. if( SaveStatus == STATUS_SUCCESS ) {
  4502. SaveStatus = Status;
  4503. }
  4504. }
  4505. if( ClassName != NULL ) {
  4506. Status = SpOpenSetValueAndClose( hKeyPreinstall,
  4507. NodeName,
  4508. RetailClass,
  4509. STRING_VALUE(ClassName)
  4510. );
  4511. if( !NT_SUCCESS( Status ) ) {
  4512. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Failed to save information for preinstalled OEM driver %ls. Status = %lx \n", NodeName, Status ));
  4513. if( SaveStatus == STATUS_SUCCESS ) {
  4514. SaveStatus = Status;
  4515. }
  4516. }
  4517. }
  4518. }
  4519. }
  4520. }
  4521. return( SaveStatus );
  4522. }
  4523. NTSTATUS
  4524. SpSavePreinstallList(
  4525. IN PVOID SifHandle,
  4526. IN PWSTR SystemRoot,
  4527. IN HANDLE hKeySystemHive
  4528. )
  4529. {
  4530. NTSTATUS Status;
  4531. NTSTATUS SaveStatus;
  4532. OBJECT_ATTRIBUTES Obja;
  4533. UNICODE_STRING UnicodeString;
  4534. HANDLE hKeyPreinstall;
  4535. ULONG i;
  4536. //
  4537. // Create setup\preinstall
  4538. //
  4539. INIT_OBJA(&Obja,&UnicodeString,L"Setup\\Preinstall");
  4540. Obja.RootDirectory = hKeySystemHive;
  4541. Status = ZwCreateKey(
  4542. &hKeyPreinstall,
  4543. KEY_ALL_ACCESS,
  4544. &Obja,
  4545. 0,
  4546. NULL,
  4547. REG_OPTION_NON_VOLATILE,
  4548. NULL
  4549. );
  4550. if(!NT_SUCCESS(Status)) {
  4551. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: unable to create Preinstall key. Status = %lx\n",Status));
  4552. return( Status );
  4553. }
  4554. SaveStatus = STATUS_SUCCESS;
  4555. for( i = 0; i < HwComponentMax; i++ ) {
  4556. if( ( i == HwComponentComputer ) ||
  4557. ( i == HwComponentDisplay ) ||
  4558. ( i == HwComponentLayout ) ||
  4559. ( PreinstallHardwareComponents[i] == NULL ) ) {
  4560. continue;
  4561. }
  4562. Status = SpSavePreinstallHwInfo( SifHandle,
  4563. SystemRoot,
  4564. hKeyPreinstall,
  4565. i,
  4566. PreinstallHardwareComponents[i] );
  4567. if( !NT_SUCCESS( Status ) ) {
  4568. if( SaveStatus == STATUS_SUCCESS ) {
  4569. SaveStatus = Status;
  4570. }
  4571. }
  4572. }
  4573. if( PreinstallScsiHardware != NULL ) {
  4574. Status = SpSavePreinstallHwInfo( SifHandle,
  4575. SystemRoot,
  4576. hKeyPreinstall,
  4577. HwComponentMax,
  4578. PreinstallScsiHardware );
  4579. if( !NT_SUCCESS( Status ) ) {
  4580. if( SaveStatus == STATUS_SUCCESS ) {
  4581. SaveStatus = Status;
  4582. }
  4583. }
  4584. }
  4585. ZwClose(hKeyPreinstall);
  4586. return( SaveStatus );
  4587. }
  4588. NTSTATUS
  4589. SpSetPageFileInfo(
  4590. IN PVOID SifHandle,
  4591. IN HANDLE hKeyCCSetControl,
  4592. IN HANDLE hKeySystemHive
  4593. )
  4594. /*++
  4595. Routine Description:
  4596. This function replaces the original data of 'PagingFile'
  4597. CurrentControlSet\Session Manager\Memory Management with values from txtsetup.sif if the values don't measure up.
  4598. The original value will have already been saved on HKEY_LOCAL_MACHINE\SYSTEM\Setup\\PageFile,
  4599. and it will be restored at the end of GUI setup.
  4600. Arguments:
  4601. SifHandle - handle to txtsetup.sif
  4602. hKeyCCSetControl - supplies handle to SYSTEM\CurrentControlSet\Control
  4603. hKeySystemHive - supplies handle to root of the system hive
  4604. (ie, HKEY_LOCAL_MACHINE\System).
  4605. Return Value:
  4606. Status value indicating outcome of operation.
  4607. --*/
  4608. {
  4609. NTSTATUS Status;
  4610. PUCHAR Data;
  4611. ULONG Length;
  4612. PWSTR SrcKeyPath = L"Session Manager\\Memory Management";
  4613. PWSTR ValueName = L"PagingFiles";
  4614. PWSTR Buffer;
  4615. PWSTR NextDstSubstring;
  4616. ULONG AuxLength;
  4617. ULONG StartPagefile,MaxPagefile;
  4618. ULONG OldStartPagefile,OldMaxPagefile;
  4619. PWSTR p;
  4620. //
  4621. // Read recommended pagefile size for gui-mode.
  4622. //
  4623. if(p = SpGetSectionKeyIndex(SifHandle,SIF_SETUPDATA,SIF_PAGEFILE,0)) {
  4624. StartPagefile = SpStringToLong( p, NULL, 10 );
  4625. }
  4626. else {
  4627. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Unable to retrieve initial pagefile size from txtsetup.sif\n"));
  4628. return( STATUS_UNSUCCESSFUL );
  4629. }
  4630. if(p = SpGetSectionKeyIndex(SifHandle,SIF_SETUPDATA,SIF_PAGEFILE,1)) {
  4631. MaxPagefile = SpStringToLong( p, NULL, 10 );
  4632. }
  4633. else {
  4634. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Unable to retrieve max pagefile size from txtsetup.sif\n"));
  4635. return( STATUS_UNSUCCESSFUL );
  4636. }
  4637. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Read pagefile from txtsetup %lx %lx\n", StartPagefile, MaxPagefile ));
  4638. //
  4639. // Retrieve the original value of 'PagingFiles'
  4640. //
  4641. Status = SpGetValueKey( hKeyCCSetControl,
  4642. SrcKeyPath,
  4643. ValueName,
  4644. sizeof(TemporaryBuffer),
  4645. (PCHAR)TemporaryBuffer,
  4646. &Length );
  4647. OldStartPagefile = 0;
  4648. OldMaxPagefile = 0;
  4649. NextDstSubstring = TemporaryBuffer;
  4650. if(NT_SUCCESS(Status) && ((PKEY_VALUE_PARTIAL_INFORMATION)TemporaryBuffer)->Type == REG_MULTI_SZ) {
  4651. PWSTR r;
  4652. WCHAR SaveChar;
  4653. PWSTR s=NULL;
  4654. Data = ((PKEY_VALUE_PARTIAL_INFORMATION)TemporaryBuffer)->Data;
  4655. Length = ((PKEY_VALUE_PARTIAL_INFORMATION)TemporaryBuffer)->DataLength;
  4656. Buffer = SpMemAlloc( Length );
  4657. RtlMoveMemory( Buffer, Data, Length );
  4658. AuxLength = wcslen( Buffer);
  4659. // If it's not one string, then we won't change the pagefile
  4660. if( AuxLength == 0 || *(Buffer+AuxLength+1) != (WCHAR)'\0') {
  4661. SpMemFree( Buffer );
  4662. return( STATUS_SUCCESS );
  4663. }
  4664. //
  4665. // Form a new value entry that contains the information regarding the
  4666. // paging files to be created. The paths to the paging files will be the
  4667. // same ones used in the system before the upgrade.
  4668. //
  4669. // Make a copy of the original value entry, and form the data for the new
  4670. // value entry in the TemporaryBuffer.
  4671. //
  4672. SpStringToLower( Buffer );
  4673. r = wcsstr( Buffer, L"\\pagefile.sys" );
  4674. if( r != NULL ) {
  4675. r += wcslen( L"\\pagefile.sys" );
  4676. SaveChar = *r;
  4677. *r = (WCHAR)'\0';
  4678. wcscpy( NextDstSubstring, Buffer );
  4679. *r = SaveChar;
  4680. OldStartPagefile = SpStringToLong( r, &s, 10 );
  4681. if( (s != NULL) && (*s != (WCHAR)'\0') ) {
  4682. OldMaxPagefile = max( OldStartPagefile, (ULONG)SpStringToLong( s, NULL, 10 ));
  4683. } else {
  4684. OldMaxPagefile = OldStartPagefile;
  4685. }
  4686. } else {
  4687. wcscpy( NextDstSubstring, L"?:\\pagefile.sys" );
  4688. }
  4689. SpMemFree( Buffer );
  4690. // NextDstSubstring should now point just after pagefile.sys at the null
  4691. } else {
  4692. wcscpy( NextDstSubstring, L"?:\\pagefile.sys" );
  4693. }
  4694. NextDstSubstring += wcslen( NextDstSubstring );
  4695. //
  4696. // Overwrite the original value of PagingFiles
  4697. //
  4698. swprintf( NextDstSubstring, L" %d %d", max( OldStartPagefile, StartPagefile), max( OldMaxPagefile, MaxPagefile));
  4699. Length = wcslen( TemporaryBuffer );
  4700. Length++;
  4701. (TemporaryBuffer)[ Length++ ] = UNICODE_NULL;
  4702. Status = SpOpenSetValueAndClose( hKeyCCSetControl,
  4703. SrcKeyPath,
  4704. ValueName,
  4705. REG_MULTI_SZ,
  4706. TemporaryBuffer,
  4707. Length*sizeof(WCHAR) );
  4708. if(!NT_SUCCESS(Status)) {
  4709. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Unable to save pagefile. Status = %lx\n", Status ));
  4710. }
  4711. return( Status );
  4712. }
  4713. NTSTATUS
  4714. SpSavePageFileInfo(
  4715. IN HANDLE hKeyCCSetControl,
  4716. IN HANDLE hKeySystemHive
  4717. )
  4718. /*++
  4719. Routine Description:
  4720. This function is only called on the upgrade case.
  4721. The original value will be saved on HKEY_LOCAL_MACHINE\SYSTEM\Setup\\PageFile,
  4722. and it will be restored at the end of GUI setup.
  4723. Arguments:
  4724. hKeyCCSetControl - supplies handle to SYSTEM\CurrentControlSet\Control
  4725. hKeySystemHive - supplies handle to root of the system hive
  4726. (ie, HKEY_LOCAL_MACHINE\System).
  4727. Return Value:
  4728. Status value indicating outcome of operation.
  4729. --*/
  4730. {
  4731. NTSTATUS Status;
  4732. PUCHAR Data;
  4733. ULONG Length;
  4734. PWSTR SrcKeyPath = L"Session Manager\\Memory Management";
  4735. PWSTR ValueName = L"PagingFiles";
  4736. //
  4737. // Retrieve the original value of 'PagingFiles'
  4738. //
  4739. Status = SpGetValueKey( hKeyCCSetControl,
  4740. SrcKeyPath,
  4741. ValueName,
  4742. sizeof(TemporaryBuffer),
  4743. (PCHAR)TemporaryBuffer,
  4744. &Length );
  4745. if(!NT_SUCCESS(Status)) {
  4746. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Unable to retrieve %ls on %ls. Status = %lx \n", ValueName, SrcKeyPath, Status ));
  4747. return( Status );
  4748. }
  4749. Data = ((PKEY_VALUE_PARTIAL_INFORMATION)TemporaryBuffer)->Data;
  4750. Length = ((PKEY_VALUE_PARTIAL_INFORMATION)TemporaryBuffer)->DataLength;
  4751. //
  4752. // Save the data in SYSTEM\Setup\PageFile
  4753. //
  4754. Status = SpOpenSetValueAndClose(
  4755. hKeySystemHive,
  4756. L"Setup\\PageFile",
  4757. ValueName,
  4758. REG_MULTI_SZ,
  4759. Data,
  4760. Length
  4761. );
  4762. if(!NT_SUCCESS(Status)) {
  4763. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Unable to save %ls on SYSTEM\\Setup\\PageFile. ValueName, Status = %lx\n", Status ));
  4764. }
  4765. return( Status );
  4766. }
  4767. NTSTATUS
  4768. SppMigrateSetupRegNonVolatileKeys(
  4769. IN PWSTR PartitionPath,
  4770. IN PWSTR SystemRoot,
  4771. IN HANDLE hDestControlSet,
  4772. IN PWSTR KeyPath,
  4773. IN BOOLEAN OverwriteValues,
  4774. IN BOOLEAN OverwriteACLs
  4775. )
  4776. /*++
  4777. Routine Description:
  4778. This routine migrates keys of the setup hive to the target hive.
  4779. These keys are subkeys of \Registry\Machine\System\CurrentControlSet,
  4780. and are listed on the section [SetupKeysToMigrate] on txtsetup.sif.
  4781. Arguments:
  4782. PartitionPath - supplies the NT name for the drive of windows nt.
  4783. SystemRoot - supplies nt path of the windows nt directory.
  4784. hDestLocalMachine - Handle to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet on the target hive.
  4785. KeyPath - Path to the key to be migrated, relative to \Registry\Machine\System\CurrentControlSet.
  4786. SifHandle - Handle to txtsetup.sif
  4787. Return Value:
  4788. Status value indicating outcome of operation.
  4789. --*/
  4790. {
  4791. NTSTATUS Status;
  4792. OBJECT_ATTRIBUTES Obja;
  4793. UNICODE_STRING UnicodeString;
  4794. HANDLE hSrcKey;
  4795. HANDLE hTempSrcKey;
  4796. HANDLE SaveHiveHandle;
  4797. HANDLE hDestKey;
  4798. PWSTR TempKeyPath = L"\\registry\\machine\\TempKey";
  4799. PWSTR SaveHiveName;
  4800. IO_STATUS_BLOCK IoStatusBlock;
  4801. PSECURITY_DESCRIPTOR Security = NULL;
  4802. ULONG ResultLength;
  4803. //
  4804. // Open the key the key that needs to be saved
  4805. //
  4806. wcscpy(TemporaryBuffer,L"\\registry\\machine\\system\\currentcontrolset");
  4807. SpConcatenatePaths(TemporaryBuffer,KeyPath);
  4808. INIT_OBJA(&Obja,&UnicodeString,TemporaryBuffer);
  4809. Obja.RootDirectory = NULL;
  4810. Status = ZwOpenKey(&hSrcKey,KEY_ALL_ACCESS,&Obja);
  4811. if( !NT_SUCCESS( Status ) ) {
  4812. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Unable to open %ls on the setup hive (%lx)\n", TemporaryBuffer, Status));
  4813. return( Status ) ;
  4814. }
  4815. //
  4816. // Create the hive file
  4817. //
  4818. wcscpy(TemporaryBuffer,PartitionPath);
  4819. SpConcatenatePaths(TemporaryBuffer,SystemRoot);
  4820. SpConcatenatePaths(TemporaryBuffer,L"system32\\config");
  4821. SpConcatenatePaths(TemporaryBuffer,L"TempKey");
  4822. SaveHiveName = SpDupStringW(TemporaryBuffer);
  4823. SpDeleteFile( SaveHiveName, NULL, NULL );
  4824. INIT_OBJA(&Obja,&UnicodeString,SaveHiveName);
  4825. Status = ZwCreateFile(
  4826. &SaveHiveHandle,
  4827. FILE_GENERIC_WRITE,
  4828. &Obja,
  4829. &IoStatusBlock,
  4830. NULL,
  4831. FILE_ATTRIBUTE_NORMAL,
  4832. 0, // no sharing
  4833. FILE_OVERWRITE_IF,
  4834. FILE_NON_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT,
  4835. NULL,
  4836. 0
  4837. );
  4838. if( !NT_SUCCESS( Status ) ) {
  4839. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Unable to create the hive file %ls. Status = %lx\n", SaveHiveName, Status));
  4840. goto TempMigr_2;
  4841. }
  4842. Status = ZwSaveKey( hSrcKey, SaveHiveHandle );
  4843. ZwClose( SaveHiveHandle );
  4844. if( !NT_SUCCESS( Status ) ) {
  4845. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Unable to save %ls key to the hive file %ls. Status = %lx\n", KeyPath, SaveHiveName, Status));
  4846. goto TempMigr_3;
  4847. }
  4848. Status = SpLoadUnloadKey( NULL,
  4849. NULL,
  4850. TempKeyPath,
  4851. SaveHiveName );
  4852. if( !NT_SUCCESS( Status ) ) {
  4853. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Unable to load %ls key to the setup hive. Status = %lx\n", SaveHiveName, Status));
  4854. goto TempMigr_3;
  4855. }
  4856. //
  4857. // Open TempKey
  4858. //
  4859. INIT_OBJA(&Obja,&UnicodeString,TempKeyPath);
  4860. Obja.RootDirectory = NULL;
  4861. Status = ZwOpenKey(&hTempSrcKey,KEY_ALL_ACCESS,&Obja);
  4862. if( !NT_SUCCESS( Status ) ) {
  4863. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Unable to open TempSrc key on the setup hive. Status = %lx\n", Status));
  4864. goto TempMigr_4;
  4865. }
  4866. //
  4867. // First, get the security descriptor from the source key so we can create
  4868. // the destination key with the correct ACL.
  4869. //
  4870. Status = ZwQuerySecurityObject(hTempSrcKey,
  4871. DACL_SECURITY_INFORMATION,
  4872. NULL,
  4873. 0,
  4874. &ResultLength
  4875. );
  4876. if(Status==STATUS_BUFFER_TOO_SMALL) {
  4877. Security=SpMemAlloc(ResultLength);
  4878. Status = ZwQuerySecurityObject(hTempSrcKey,
  4879. DACL_SECURITY_INFORMATION,
  4880. Security,
  4881. ResultLength,
  4882. &ResultLength);
  4883. if(!NT_SUCCESS(Status)) {
  4884. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: unable to query security for key %ws in the source hive (%lx)\n",
  4885. TempKeyPath,
  4886. Status)
  4887. );
  4888. SpMemFree(Security);
  4889. Security=NULL;
  4890. }
  4891. } else {
  4892. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: unable to query security size for key %ws in the source hive (%lx)\n",
  4893. TempKeyPath,
  4894. Status)
  4895. );
  4896. Security=NULL;
  4897. }
  4898. //
  4899. // Open the key on the target hive
  4900. //
  4901. INIT_OBJA(&Obja,&UnicodeString,KeyPath);
  4902. Obja.RootDirectory = hDestControlSet;
  4903. Status = ZwOpenKey(&hDestKey,KEY_ALL_ACCESS,&Obja);
  4904. if(!NT_SUCCESS(Status)) {
  4905. //
  4906. // Assume that failure was because the key didn't exist. Now try creating
  4907. // the key.
  4908. Obja.SecurityDescriptor = Security;
  4909. Status = ZwCreateKey(
  4910. &hDestKey,
  4911. KEY_ALL_ACCESS,
  4912. &Obja,
  4913. 0,
  4914. NULL,
  4915. REG_OPTION_NON_VOLATILE,
  4916. NULL
  4917. );
  4918. if(!NT_SUCCESS(Status)) {
  4919. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: unable to open or create key %ws(%lx)\n",KeyPath, Status));
  4920. if(Security) {
  4921. SpMemFree(Security);
  4922. }
  4923. goto TempMigr_5;
  4924. }
  4925. } else if (OverwriteACLs) {
  4926. Status = ZwSetSecurityObject(
  4927. hDestKey,
  4928. DACL_SECURITY_INFORMATION,
  4929. Security );
  4930. if(!NT_SUCCESS(Status)) {
  4931. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: unable to copy ACL to existing key %ws(%lx)\n",KeyPath, Status));
  4932. }
  4933. }
  4934. if(Security) {
  4935. SpMemFree(Security);
  4936. }
  4937. Status = SppCopyKeyRecursive(
  4938. hTempSrcKey,
  4939. hDestKey,
  4940. NULL,
  4941. NULL,
  4942. OverwriteValues,
  4943. OverwriteACLs
  4944. );
  4945. if( !NT_SUCCESS( Status ) ) {
  4946. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Unable to migrate %ls to the target hive. KeyPath, Status = %lx\n", Status));
  4947. }
  4948. ZwClose( hDestKey );
  4949. TempMigr_5:
  4950. ZwClose( hTempSrcKey );
  4951. TempMigr_4:
  4952. //
  4953. // Unload hive
  4954. //
  4955. SpLoadUnloadKey( NULL,
  4956. NULL,
  4957. TempKeyPath,
  4958. NULL );
  4959. TempMigr_3:
  4960. SpDeleteFile( SaveHiveName, NULL, NULL );
  4961. TempMigr_2:
  4962. SpMemFree( SaveHiveName );
  4963. return( Status );
  4964. }
  4965. BOOLEAN
  4966. SpHivesFromInfs(
  4967. IN PVOID SifHandle,
  4968. IN LPCWSTR SectionName,
  4969. IN LPCWSTR SourcePath1,
  4970. IN LPCWSTR SourcePath2, OPTIONAL
  4971. IN HANDLE SystemHiveRoot,
  4972. IN HANDLE SoftwareHiveRoot,
  4973. IN HANDLE DefaultUserHiveRoot,
  4974. IN HANDLE HKR
  4975. )
  4976. /*++
  4977. Routine Description:
  4978. This routine runs addreg and delreg sections as listed in txtsetup.sif,
  4979. in order to create or perform the basic upgrade on the registry hives.
  4980. Each line in the given section is expected to be in the following form:
  4981. addreg = <filename>,<section>
  4982. or
  4983. delreg = <filename>,<section>
  4984. Multiple addreg and delreg lines can be supplied, and the sections are
  4985. processed in order listed.
  4986. The filename specs are filename only; the files are expected to be
  4987. in the source directory.
  4988. Arguments:
  4989. SifHandle - supplies the handle to txtsetup.sif.
  4990. SectionName - supplies the name of the section in txtsetuyp.sif that
  4991. lists infs/sections to be processed.
  4992. SourcePath - supplies NT-style path to the source files for installation.
  4993. SystemHiveRoot - supplies handle to root key of system hive under
  4994. construction.
  4995. SoftwareHiveRoot - supplies handle to root key of software hive under
  4996. construction.
  4997. DefaultUserHiveRoot - supplies handle to root key of default hive under
  4998. construction.
  4999. HKR - supplies key to be used for HKR.
  5000. Return Value:
  5001. Boolean value indicating outcome.
  5002. --*/
  5003. {
  5004. LPCWSTR PreviousInf;
  5005. LPCWSTR CurrentInf;
  5006. ULONG LineNumber;
  5007. LPCWSTR TypeSpec;
  5008. LPCWSTR SectionSpec;
  5009. PVOID InfHandle;
  5010. ULONG ErrorLine;
  5011. NTSTATUS Status;
  5012. LPWSTR name;
  5013. LPWSTR MediaShortname;
  5014. LPWSTR MediaDirectory;
  5015. //
  5016. // Allocate a buffer for names.
  5017. //
  5018. name = SpMemAlloc(1000);
  5019. LineNumber = 0;
  5020. PreviousInf = L"";
  5021. InfHandle = NULL;
  5022. while((TypeSpec = SpGetKeyName(SifHandle,SectionName,LineNumber))
  5023. && (CurrentInf = SpGetSectionLineIndex(SifHandle,SectionName,LineNumber,0))
  5024. && (SectionSpec = SpGetSectionLineIndex(SifHandle,SectionName,LineNumber,1))) {
  5025. //
  5026. // Only load the inf if it's different than the previous one,
  5027. // as a time optimization.
  5028. //
  5029. if(_wcsicmp(CurrentInf,PreviousInf)) {
  5030. if(InfHandle) {
  5031. SpFreeTextFile(InfHandle);
  5032. InfHandle = NULL;
  5033. }
  5034. MediaShortname = SpLookUpValueForFile(SifHandle,(LPWSTR)CurrentInf,INDEX_WHICHMEDIA,TRUE);
  5035. SpGetSourceMediaInfo(SifHandle,MediaShortname,NULL,NULL,&MediaDirectory);
  5036. wcscpy(name,SourcePath1);
  5037. if(SourcePath2) {
  5038. SpConcatenatePaths(name,SourcePath2);
  5039. }
  5040. SpConcatenatePaths(name,MediaDirectory);
  5041. SpConcatenatePaths(name,CurrentInf);
  5042. Status = SpLoadSetupTextFile(name,NULL,0,&InfHandle,&ErrorLine,FALSE,FALSE);
  5043. if(!NT_SUCCESS(Status)) {
  5044. SpStartScreen(
  5045. SP_SCRN_INF_LINE_CORRUPT,
  5046. 3,
  5047. HEADER_HEIGHT+1,
  5048. FALSE,
  5049. FALSE,
  5050. DEFAULT_ATTRIBUTE,
  5051. ErrorLine,
  5052. CurrentInf
  5053. );
  5054. SpDisplayStatusOptions(DEFAULT_STATUS_ATTRIBUTE,SP_STAT_F3_EQUALS_EXIT,0);
  5055. SpInputDrain();
  5056. while(SpInputGetKeypress() != KEY_F3) ;
  5057. SpDone(0,FALSE,TRUE);
  5058. }
  5059. PreviousInf = CurrentInf;
  5060. }
  5061. if(!_wcsicmp(TypeSpec,L"addreg")) {
  5062. Status = SpProcessAddRegSection(
  5063. InfHandle,
  5064. SectionSpec,
  5065. SystemHiveRoot,
  5066. SoftwareHiveRoot,
  5067. DefaultUserHiveRoot,
  5068. HKR
  5069. );
  5070. SendSetupProgressEvent(SavingSettingsEvent, InitializeHiveEvent, NULL);
  5071. } else {
  5072. if(!_wcsicmp(TypeSpec,L"delreg")) {
  5073. Status = SpProcessDelRegSection(
  5074. InfHandle,
  5075. SectionSpec,
  5076. SystemHiveRoot,
  5077. SoftwareHiveRoot,
  5078. DefaultUserHiveRoot,
  5079. HKR
  5080. );
  5081. SendSetupProgressEvent(SavingSettingsEvent, InitializeHiveEvent, NULL);
  5082. } else {
  5083. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: unknown hive section type spec %ws\n",TypeSpec));
  5084. SpFreeTextFile(InfHandle);
  5085. SpMemFree(name);
  5086. return(FALSE);
  5087. }
  5088. }
  5089. if(!NT_SUCCESS(Status)) {
  5090. SpFreeTextFile(InfHandle);
  5091. SpMemFree(name);
  5092. return(FALSE);
  5093. }
  5094. LineNumber++;
  5095. }
  5096. if(InfHandle) {
  5097. SpFreeTextFile(InfHandle);
  5098. }
  5099. SpMemFree(name);
  5100. return(TRUE);
  5101. }
  5102. NTSTATUS
  5103. SpMigrateSetupKeys(
  5104. IN PWSTR PartitionPath,
  5105. IN PWSTR SystemRoot,
  5106. IN HANDLE hDestControlSet,
  5107. IN PVOID SifHandle
  5108. )
  5109. /*++
  5110. Routine Description:
  5111. This routine migrates keys of the setup hive to the target hive.
  5112. These keys are subkeys of \Registry\Machine\System\CurrentControlSet,
  5113. and are listed on the section [SetupKeysToMigrate] on txtsetup.sif.
  5114. Arguments:
  5115. PartitionPath - supplies the NT name for the drive of windows nt.
  5116. SystemRoot - supplies nt path of the windows nt directory.
  5117. hDestLocalMachine - Handle to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet
  5118. on the target hive.
  5119. SifHandle - Handle to txtsetup.sif
  5120. Return Value:
  5121. Status value indicating outcome of operation.
  5122. --*/
  5123. {
  5124. NTSTATUS Status;
  5125. NTSTATUS SavedStatus;
  5126. OBJECT_ATTRIBUTES Obja;
  5127. UNICODE_STRING UnicodeString;
  5128. HANDLE hSrcKey;
  5129. ULONG LineIndex;
  5130. PWSTR KeyName;
  5131. PWSTR SectionName = L"SetupKeysToMigrate";
  5132. BOOLEAN MigrateVolatileKeys;
  5133. BOOLEAN OverwriteValues;
  5134. BOOLEAN OverwriteACLs;
  5135. BOOLEAN MigrateOnCleanInstall;
  5136. BOOLEAN MigrateOnUpgrade;
  5137. ULONG InstType;
  5138. PWSTR p;
  5139. SavedStatus = STATUS_SUCCESS;
  5140. for( LineIndex = 0;
  5141. ( KeyName = SpGetKeyName( SifHandle,
  5142. SectionName,
  5143. LineIndex ) ) != NULL;
  5144. LineIndex++ ) {
  5145. p = SpGetSectionKeyIndex ( SifHandle,
  5146. SectionName,
  5147. KeyName,
  5148. 0 );
  5149. MigrateVolatileKeys = ( ( p != NULL ) && ( SpStringToLong( p, NULL, 10 ) == 0 ) )? FALSE : TRUE;
  5150. p = SpGetSectionKeyIndex ( SifHandle,
  5151. SectionName,
  5152. KeyName,
  5153. 1 );
  5154. if( p != NULL ) {
  5155. InstType = SpStringToLong( p, NULL, 10 );
  5156. if( InstType > 2 ) {
  5157. InstType = 2;
  5158. }
  5159. } else {
  5160. InstType = 2;
  5161. }
  5162. MigrateOnCleanInstall = ( InstType != 1 );
  5163. MigrateOnUpgrade = ( InstType != 0 );
  5164. p = SpGetSectionKeyIndex ( SifHandle,
  5165. SectionName,
  5166. KeyName,
  5167. 2 );
  5168. OverwriteValues = ( ( p != NULL ) && ( SpStringToLong( p, NULL, 10 ) == 0 ) )? FALSE : TRUE;
  5169. p = SpGetSectionKeyIndex ( SifHandle,
  5170. SectionName,
  5171. KeyName,
  5172. 3 );
  5173. OverwriteACLs = ( ( p != NULL ) && ( SpStringToLong( p, NULL, 10 ) != 0 ) );
  5174. if( ( ( NTUpgrade == DontUpgrade ) && MigrateOnCleanInstall ) ||
  5175. ( ( NTUpgrade != DontUpgrade ) && MigrateOnUpgrade ) ) {
  5176. if( MigrateVolatileKeys ) {
  5177. wcscpy( TemporaryBuffer, L"\\registry\\machine\\system\\currentcontrolset\\" );
  5178. SpConcatenatePaths(TemporaryBuffer, KeyName);
  5179. //
  5180. // Open the source key
  5181. //
  5182. INIT_OBJA(&Obja,&UnicodeString,TemporaryBuffer);
  5183. Obja.RootDirectory = NULL;
  5184. Status = ZwOpenKey(&hSrcKey,KEY_ALL_ACCESS,&Obja);
  5185. if( !NT_SUCCESS( Status ) ) {
  5186. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Unable to open %ls on the setup hive (%lx)\n", TemporaryBuffer, Status));
  5187. if( SavedStatus != STATUS_SUCCESS ) {
  5188. SavedStatus = Status;
  5189. }
  5190. continue;
  5191. }
  5192. Status = SppCopyKeyRecursive(
  5193. hSrcKey,
  5194. hDestControlSet,
  5195. NULL,
  5196. KeyName,
  5197. OverwriteValues,
  5198. OverwriteACLs
  5199. );
  5200. if( !NT_SUCCESS( Status ) ) {
  5201. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Unable to migrate %ls. Status = %lx\n", KeyName, Status));
  5202. if( SavedStatus != STATUS_SUCCESS ) {
  5203. SavedStatus = Status;
  5204. }
  5205. }
  5206. } else {
  5207. Status = SppMigrateSetupRegNonVolatileKeys( PartitionPath,
  5208. SystemRoot,
  5209. hDestControlSet,
  5210. KeyName,
  5211. OverwriteValues,
  5212. OverwriteACLs );
  5213. if( !NT_SUCCESS( Status ) ) {
  5214. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Unable to migrate %ls. Status = %lx\n", KeyName, Status));
  5215. if( SavedStatus != STATUS_SUCCESS ) {
  5216. SavedStatus = Status;
  5217. }
  5218. }
  5219. }
  5220. }
  5221. }
  5222. return( SavedStatus );
  5223. }
  5224. NTSTATUS
  5225. SppMigrateFtKeys(
  5226. IN HANDLE hDestSystemHive
  5227. )
  5228. /*++
  5229. Routine Description:
  5230. This routine migrates the ftdisk related keys on the setup hive to the
  5231. target hive.
  5232. Arguments:
  5233. hDestSystemHive - Handle to the root of the system hive on the system
  5234. being upgraded.
  5235. Return Value:
  5236. Status value indicating outcome of operation.
  5237. --*/
  5238. {
  5239. NTSTATUS Status;
  5240. NTSTATUS SavedStatus;
  5241. OBJECT_ATTRIBUTES Obja;
  5242. UNICODE_STRING UnicodeString;
  5243. PWSTR FtDiskKeys[] = {
  5244. L"Disk",
  5245. L"MountedDevices"
  5246. };
  5247. WCHAR KeyPath[MAX_PATH];
  5248. HANDLE SrcKey;
  5249. ULONG i;
  5250. SavedStatus = STATUS_SUCCESS;
  5251. for( i = 0; i < sizeof(FtDiskKeys)/sizeof(PWSTR); i++ ) {
  5252. //
  5253. // Open the source key
  5254. //
  5255. swprintf( KeyPath, L"\\registry\\machine\\system\\%ls", FtDiskKeys[i] );
  5256. INIT_OBJA(&Obja,&UnicodeString,KeyPath);
  5257. Obja.RootDirectory = NULL;
  5258. Status = ZwOpenKey(&SrcKey,KEY_ALL_ACCESS,&Obja);
  5259. if( !NT_SUCCESS( Status ) ) {
  5260. //
  5261. // If the key doesn't exist, just assume success
  5262. //
  5263. if( Status != STATUS_OBJECT_NAME_NOT_FOUND ) {
  5264. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Unable to open %ls on the setup hive. Status = %lx \n", KeyPath, Status));
  5265. if( SavedStatus == STATUS_SUCCESS ) {
  5266. SavedStatus = Status;
  5267. }
  5268. }
  5269. continue;
  5270. }
  5271. Status = SppCopyKeyRecursive( SrcKey,
  5272. hDestSystemHive,
  5273. NULL,
  5274. FtDiskKeys[i],
  5275. (((NTUpgrade == UpgradeFull) && !_wcsicmp( FtDiskKeys[i], L"MountedDevices"))? FALSE : TRUE),
  5276. FALSE
  5277. );
  5278. if( !NT_SUCCESS( Status ) ) {
  5279. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Unable to migrate %ls to SYSTEM\\%ls. Status = %lx\n", KeyPath, FtDiskKeys[i], Status));
  5280. if( SavedStatus == STATUS_SUCCESS ) {
  5281. SavedStatus = Status;
  5282. }
  5283. }
  5284. ZwClose( SrcKey );
  5285. }
  5286. return( SavedStatus );
  5287. }
  5288. NTSTATUS
  5289. SppCleanupKeysFromRemoteInstall(
  5290. VOID
  5291. )
  5292. /*++
  5293. Routine Description:
  5294. This routine cleans up some keys that remote install modified to get
  5295. the network card working. This is so that PnP setup during GUI-mode is
  5296. not confused by the card already being setup.
  5297. Arguments:
  5298. None.
  5299. Return Value:
  5300. Status value indicating outcome of operation.
  5301. --*/
  5302. {
  5303. OBJECT_ATTRIBUTES Obja;
  5304. UNICODE_STRING UnicodeString;
  5305. NTSTATUS Status;
  5306. ULONG ResultLength;
  5307. HANDLE hKey;
  5308. PWSTR DeviceInstance;
  5309. //
  5310. // Open the remote boot key.
  5311. //
  5312. wcscpy( TemporaryBuffer, L"\\registry\\machine\\system\\currentcontrolset\\control\\remoteboot" );
  5313. INIT_OBJA(&Obja,&UnicodeString,TemporaryBuffer);
  5314. Obja.RootDirectory = NULL;
  5315. Status = ZwOpenKey(&hKey,KEY_READ,&Obja);
  5316. if( !NT_SUCCESS( Status ) ) {
  5317. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: SppCleanupKeysFromRemoteInstall unable to open %ls on the setup hive (%lx)\n", TemporaryBuffer, Status));
  5318. return Status;
  5319. }
  5320. //
  5321. // Read the netboot card's device instance out.
  5322. //
  5323. RtlInitUnicodeString(&UnicodeString, REGSTR_VAL_DEVICE_INSTANCE);
  5324. Status = ZwQueryValueKey(
  5325. hKey,
  5326. &UnicodeString,
  5327. KeyValuePartialInformation,
  5328. TemporaryBuffer,
  5329. sizeof(TemporaryBuffer),
  5330. &ResultLength
  5331. );
  5332. ZwClose(hKey);
  5333. if( !NT_SUCCESS( Status ) ) {
  5334. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: SppCleanupKeysFromRemoteInstall unable to read RemoteBoot\\DeviceInstance value (%lx)\n", Status));
  5335. return Status;
  5336. }
  5337. DeviceInstance = SpDupStringW((PWSTR)(((PKEY_VALUE_PARTIAL_INFORMATION)TemporaryBuffer)->Data));
  5338. //
  5339. // Now open the device instance key under control\enum.
  5340. //
  5341. wcscpy( TemporaryBuffer, L"\\registry\\machine\\system\\currentcontrolset\\enum\\" );
  5342. SpConcatenatePaths(TemporaryBuffer, DeviceInstance);
  5343. SpMemFree(DeviceInstance);
  5344. INIT_OBJA(&Obja,&UnicodeString,TemporaryBuffer);
  5345. Obja.RootDirectory = NULL;
  5346. Status = ZwOpenKey(&hKey,KEY_ALL_ACCESS,&Obja);
  5347. if( !NT_SUCCESS( Status ) ) {
  5348. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: SppCleanupKeysFromRemoteInstall unable to open %ls on the setup hive (%lx)\n", TemporaryBuffer, Status));
  5349. return Status;
  5350. }
  5351. //
  5352. // Now delete the keys we added to get the card up -- Service,
  5353. // ClassGUID, and Driver.
  5354. //
  5355. RtlInitUnicodeString(&UnicodeString, REGSTR_VAL_SERVICE);
  5356. Status = ZwDeleteValueKey(hKey,&UnicodeString);
  5357. if( !NT_SUCCESS( Status ) ) {
  5358. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: SppCleanupKeysFromRemoteInstall unable to delete Service (%lx)\n", Status));
  5359. ZwClose(hKey);
  5360. return Status;
  5361. }
  5362. RtlInitUnicodeString(&UnicodeString, REGSTR_VAL_CLASSGUID);
  5363. Status = ZwDeleteValueKey(hKey,&UnicodeString);
  5364. if( !NT_SUCCESS( Status ) ) {
  5365. RtlInitUnicodeString(&UnicodeString, REGSTR_VALUE_GUID);
  5366. Status = ZwDeleteValueKey(hKey,&UnicodeString);
  5367. if( !NT_SUCCESS( Status ) ) {
  5368. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: SppCleanupKeysFromRemoteInstall unable to delete ClassGUID (%lx)\n", Status));
  5369. ZwClose(hKey);
  5370. return Status;
  5371. }
  5372. }
  5373. RtlInitUnicodeString(&UnicodeString, REGSTR_VAL_DRIVER);
  5374. Status = ZwDeleteValueKey(hKey,&UnicodeString);
  5375. if( !NT_SUCCESS( Status ) ) {
  5376. RtlInitUnicodeString(&UnicodeString, REGSTR_VALUE_DRVINST);
  5377. Status = ZwDeleteValueKey(hKey,&UnicodeString);
  5378. ZwClose(hKey);
  5379. if( !NT_SUCCESS( Status ) ) {
  5380. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: SppCleanupKeysFromRemoteInstall unable to delete Driver (%lx)\n", Status));
  5381. return Status;
  5382. }
  5383. }
  5384. return STATUS_SUCCESS;
  5385. }
  5386. NTSTATUS
  5387. SpDisableUnsupportedScsiDrivers(
  5388. IN HANDLE hKeyControlSet
  5389. )
  5390. {
  5391. NTSTATUS Status;
  5392. NTSTATUS SavedStatus;
  5393. PHARDWARE_COMPONENT TmpHw;
  5394. ULONG u;
  5395. OBJECT_ATTRIBUTES Obja;
  5396. UNICODE_STRING UnicodeString;
  5397. HANDLE hKeyControlSetServices;
  5398. ULONG val = SERVICE_DISABLED;
  5399. //
  5400. // Open controlset\services.
  5401. //
  5402. INIT_OBJA(&Obja,&UnicodeString,L"services");
  5403. Obja.RootDirectory = hKeyControlSet;
  5404. Status = ZwCreateKey(
  5405. &hKeyControlSetServices,
  5406. KEY_ALL_ACCESS,
  5407. &Obja,
  5408. 0,
  5409. NULL,
  5410. REG_OPTION_NON_VOLATILE,
  5411. NULL
  5412. );
  5413. if(!NT_SUCCESS(Status)) {
  5414. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: unable to open services key (%lx)\n",Status));
  5415. return(Status);
  5416. }
  5417. SavedStatus = STATUS_SUCCESS;
  5418. for( TmpHw = UnsupportedScsiHardwareToDisable;
  5419. TmpHw != NULL;
  5420. TmpHw = TmpHw->Next ) {
  5421. Status = SpOpenSetValueAndClose(
  5422. hKeyControlSetServices,
  5423. TmpHw->IdString,
  5424. L"Start",
  5425. ULONG_VALUE(val)
  5426. );
  5427. if(!NT_SUCCESS(Status)) {
  5428. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: unable to disable unsupported driver %ls. Status = %lx \n", TmpHw->IdString, Status));
  5429. if( SavedStatus == STATUS_SUCCESS ) {
  5430. SavedStatus = Status;
  5431. }
  5432. } else {
  5433. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: unsupported driver %ls successfully disabled. \n", TmpHw->IdString));
  5434. }
  5435. }
  5436. ZwClose( hKeyControlSetServices );
  5437. return( SavedStatus );
  5438. }
  5439. NTSTATUS
  5440. SpAppendPathToDevicePath(
  5441. IN HANDLE hKeySoftwareHive,
  5442. IN PWSTR OemPnpDriversDirPath
  5443. )
  5444. /*++
  5445. Routine Description:
  5446. This routine should be called only on OEM preinstall.
  5447. It appends the path to the directory that cntains the OEM drivers to be installed during GUI
  5448. setup to HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion!DevicePath.
  5449. Arguments:
  5450. hKeySoftwareKey - Handle to the root of the software hive.
  5451. OemPnpDriversDirPath - Path to the directory that contains the OEM pnp drivers (eg. \Dell).
  5452. Return Value:
  5453. Status value indicating outcome of operation.
  5454. --*/
  5455. {
  5456. NTSTATUS Status;
  5457. ULONG Length;
  5458. PWSTR szCurrentVersionKey = L"Microsoft\\Windows\\CurrentVersion";
  5459. PWSTR szDevicePath = L"DevicePath";
  5460. Status = SpGetValueKey( hKeySoftwareHive,
  5461. szCurrentVersionKey,
  5462. szDevicePath,
  5463. sizeof(TemporaryBuffer),
  5464. (PCHAR)TemporaryBuffer,
  5465. &Length );
  5466. if( NT_SUCCESS(Status) ) {
  5467. if( wcslen( (PWSTR)(((PKEY_VALUE_PARTIAL_INFORMATION)TemporaryBuffer)->Data) ) != 0 ) {
  5468. PWSTR BeginStrPtr;
  5469. PWSTR EndStrPtr;
  5470. BOOL Done = FALSE;
  5471. //
  5472. // OemPnpDriversDirPath can have several entries, separated by
  5473. // a semicolon. For each entry, we need to:
  5474. // 1. append a semicolon.
  5475. // 2. append %SystemDrive%
  5476. // 3. concatenate the entry.
  5477. //
  5478. BeginStrPtr = OemPnpDriversDirPath;
  5479. do {
  5480. //
  5481. // Mark the end of this entry.
  5482. //
  5483. EndStrPtr = BeginStrPtr;
  5484. while( (*EndStrPtr) && (*EndStrPtr != L';') ) {
  5485. EndStrPtr++;
  5486. }
  5487. //
  5488. // Is this the last entry?
  5489. //
  5490. if( *EndStrPtr == 0 ) {
  5491. Done = TRUE;
  5492. }
  5493. *EndStrPtr = 0;
  5494. wcscat( (PWSTR)(((PKEY_VALUE_PARTIAL_INFORMATION)TemporaryBuffer)->Data), L";" );
  5495. wcscat( (PWSTR)(((PKEY_VALUE_PARTIAL_INFORMATION)TemporaryBuffer)->Data), L"%SystemDrive%" );
  5496. SpConcatenatePaths((PWSTR)(((PKEY_VALUE_PARTIAL_INFORMATION)TemporaryBuffer)->Data), BeginStrPtr);
  5497. BeginStrPtr = EndStrPtr + 1;
  5498. //
  5499. // Take care of the case where the user ended the
  5500. // OemPnpDriversPath entry with a semicolon.
  5501. //
  5502. if( *BeginStrPtr == 0 ) {
  5503. Done = TRUE;
  5504. }
  5505. } while( !Done );
  5506. //
  5507. // Now put the entry back into the registry.
  5508. //
  5509. Status = SpOpenSetValueAndClose( hKeySoftwareHive,
  5510. szCurrentVersionKey,
  5511. szDevicePath,
  5512. ((PKEY_VALUE_PARTIAL_INFORMATION)TemporaryBuffer)->Type,
  5513. ((PKEY_VALUE_PARTIAL_INFORMATION)TemporaryBuffer)->Data,
  5514. (wcslen( (PWSTR)(((PKEY_VALUE_PARTIAL_INFORMATION)TemporaryBuffer)->Data) ) +1 ) * sizeof(WCHAR) );
  5515. }
  5516. }
  5517. return( Status );
  5518. }
  5519. NTSTATUS
  5520. SpAppendFullPathListToDevicePath (
  5521. IN HANDLE hKeySoftwareHive,
  5522. IN PWSTR PnpDriverFullPathList
  5523. )
  5524. /*++
  5525. Routine Description:
  5526. This routine appends the given full path list to the directory that cntains the OEM drivers to be installed during GUI
  5527. setup to HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion!DevicePath.
  5528. Arguments:
  5529. hKeySoftwareKey - Handle to the root of the software hive.
  5530. PnpDriverFullPathList - List of full paths to the directories that contain additional pnp drivers
  5531. Return Value:
  5532. Status value indicating outcome of operation.
  5533. --*/
  5534. {
  5535. NTSTATUS Status;
  5536. ULONG Length;
  5537. PWSTR szCurrentVersionKey = L"Microsoft\\Windows\\CurrentVersion";
  5538. PWSTR szDevicePath = L"DevicePath";
  5539. Status = SpGetValueKey (
  5540. hKeySoftwareHive,
  5541. szCurrentVersionKey,
  5542. szDevicePath,
  5543. sizeof(TemporaryBuffer),
  5544. (PCHAR)TemporaryBuffer,
  5545. &Length
  5546. );
  5547. if (NT_SUCCESS (Status)) {
  5548. if (*(WCHAR*)((PKEY_VALUE_PARTIAL_INFORMATION)TemporaryBuffer)->Data) {
  5549. wcscat ((PWSTR)(((PKEY_VALUE_PARTIAL_INFORMATION)TemporaryBuffer)->Data), L";");
  5550. }
  5551. wcscat ((PWSTR)(((PKEY_VALUE_PARTIAL_INFORMATION)TemporaryBuffer)->Data), PnpDriverFullPathList);
  5552. //
  5553. // Now put the entry back into the registry.
  5554. //
  5555. Status = SpOpenSetValueAndClose (
  5556. hKeySoftwareHive,
  5557. szCurrentVersionKey,
  5558. szDevicePath,
  5559. ((PKEY_VALUE_PARTIAL_INFORMATION)TemporaryBuffer)->Type,
  5560. ((PKEY_VALUE_PARTIAL_INFORMATION)TemporaryBuffer)->Data,
  5561. (wcslen ((PWSTR)((PKEY_VALUE_PARTIAL_INFORMATION)TemporaryBuffer)->Data) + 1) * sizeof(WCHAR)
  5562. );
  5563. }
  5564. return( Status );
  5565. }
  5566. #if defined(REMOTE_BOOT)
  5567. NTSTATUS
  5568. SpCopyRemoteBootKeyword(
  5569. IN PVOID SifHandle,
  5570. IN PWSTR KeywordName,
  5571. IN HANDLE hKeyCCSetControl
  5572. )
  5573. /*++
  5574. Routine Description:
  5575. This routine looks in a .sif file for the specified keyword
  5576. in the [RemoteBoot] section. If it finds it, it creates a registry
  5577. DWORD value with same name under System\CurrentControlSet\Control\
  5578. RemoteBoot. The value will be set to 1 if the sif keyword was
  5579. "Yes" and 0 if it was "No" (or anything else).
  5580. Arguments:
  5581. SifHandle - The handle to the open SIF file.
  5582. KeywordName - The name of the keyword.
  5583. hKeyCCSetControl - The handle to CurrentControlSet\Control.
  5584. Return Value:
  5585. Status value indicating outcome of operation.
  5586. --*/
  5587. {
  5588. PWSTR KeywordSifValue;
  5589. DWORD KeywordRegistryValue;
  5590. NTSTATUS Status;
  5591. //
  5592. // First see if the value exists in the SIF.
  5593. //
  5594. KeywordSifValue = SpGetSectionKeyIndex(SifHandle,
  5595. SIF_REMOTEBOOT,
  5596. KeywordName,
  5597. 0);
  5598. if (KeywordSifValue == NULL) {
  5599. return STATUS_SUCCESS;
  5600. }
  5601. //
  5602. // This is the value we write to the registry.
  5603. //
  5604. if ((KeywordSifValue[0] == 'Y') || (KeywordSifValue[0] == 'y')) {
  5605. KeywordRegistryValue = 1;
  5606. } else {
  5607. KeywordRegistryValue = 0;
  5608. }
  5609. //
  5610. // Set the value.
  5611. //
  5612. Status = SpOpenSetValueAndClose(
  5613. hKeyCCSetControl,
  5614. SIF_REMOTEBOOT,
  5615. KeywordName,
  5616. ULONG_VALUE(KeywordRegistryValue)
  5617. );
  5618. return Status;
  5619. }
  5620. #endif // defined(REMOTE_BOOT)
  5621. NTSTATUS
  5622. SppDisableDynamicVolumes(
  5623. IN HANDLE hCCSet
  5624. )
  5625. /*++
  5626. Routine Description:
  5627. This routine disable dynamic volumes by disabling the appropriate services in the
  5628. target hive.
  5629. In addition, DmServer is reset to MANUAL start, so that it will only run when
  5630. the LDM UI is open.
  5631. Arguments:
  5632. hCCSet - Handle to CurrentControlSet of the target system hive.
  5633. Return Value:
  5634. Status value indicating outcome of operation.
  5635. --*/
  5636. {
  5637. OBJECT_ATTRIBUTES Obja;
  5638. UNICODE_STRING UnicodeString;
  5639. NTSTATUS Status;
  5640. NTSTATUS SavedStatus;
  5641. DWORD u;
  5642. ULONG i;
  5643. HANDLE hServices;
  5644. WCHAR KeyPath[MAX_PATH];
  5645. PWSTR LDMServices[] = {
  5646. L"dmboot",
  5647. L"dmio",
  5648. L"dmload"
  5649. };
  5650. PWSTR LDMDmServer = L"dmserver";
  5651. //
  5652. // Open ControlSet\Services.
  5653. //
  5654. INIT_OBJA(&Obja,&UnicodeString,L"Services");
  5655. Obja.RootDirectory = hCCSet;
  5656. Status = ZwOpenKey(&hServices,KEY_ALL_ACCESS,&Obja);
  5657. if(!NT_SUCCESS(Status)) {
  5658. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Unable to open CurrentControlSet\\Services. Status = %lx \n",Status));
  5659. return(Status);
  5660. }
  5661. SavedStatus = STATUS_SUCCESS;
  5662. u = 0x4;
  5663. for( i = 0; i < sizeof(LDMServices)/sizeof(PWSTR); i++ ) {
  5664. Status = SpOpenSetValueAndClose( hServices,
  5665. LDMServices[i],
  5666. L"Start",
  5667. ULONG_VALUE(u)
  5668. );
  5669. if( !NT_SUCCESS( Status ) ) {
  5670. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Unable to disable HKLM\\SYSTEM\\CurrentControlSet\\Services\\%ls. Status = %lx\n", LDMServices[i], Status));
  5671. if( SavedStatus == STATUS_SUCCESS ) {
  5672. SavedStatus = Status;
  5673. }
  5674. }
  5675. }
  5676. u = 0x3;
  5677. Status = SpOpenSetValueAndClose( hServices,
  5678. LDMDmServer,
  5679. L"Start",
  5680. ULONG_VALUE(u)
  5681. );
  5682. if( !NT_SUCCESS( Status ) ) {
  5683. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Unable to set HKLM\\SYSTEM\\CurrentControlSet\\Services\\%ls to MANUAL start. Status = %lx\n", LDMDmServer, Status));
  5684. if( SavedStatus == STATUS_SUCCESS ) {
  5685. SavedStatus = Status;
  5686. }
  5687. }
  5688. ZwClose( hServices );
  5689. return( SavedStatus );
  5690. }
  5691. NTSTATUS
  5692. SpGetRegistryValue(
  5693. IN HANDLE KeyHandle,
  5694. IN PWSTR ValueName,
  5695. OUT PKEY_VALUE_FULL_INFORMATION *Information
  5696. )
  5697. /*++
  5698. Routine Description:
  5699. This routine is invoked to retrieve the data for a registry key's value.
  5700. This is done by querying the value of the key with a zero-length buffer
  5701. to determine the size of the value, and then allocating a buffer and
  5702. actually querying the value into the buffer.
  5703. It is the responsibility of the caller to free the buffer.
  5704. Arguments:
  5705. KeyHandle - Supplies the key handle whose value is to be queried
  5706. ValueName - Supplies the null-terminated Unicode name of the value.
  5707. Information - Returns a pointer to the allocated data buffer.
  5708. Return Value:
  5709. The function value is the final status of the query operation.
  5710. --*/
  5711. {
  5712. UNICODE_STRING unicodeString;
  5713. NTSTATUS status;
  5714. PKEY_VALUE_FULL_INFORMATION infoBuffer;
  5715. ULONG keyValueLength;
  5716. PAGED_CODE();
  5717. RtlInitUnicodeString( &unicodeString, ValueName );
  5718. //
  5719. // Figure out how big the data value is so that a buffer of the
  5720. // appropriate size can be allocated.
  5721. //
  5722. status = ZwQueryValueKey( KeyHandle,
  5723. &unicodeString,
  5724. KeyValueFullInformation,
  5725. (PVOID) NULL,
  5726. 0,
  5727. &keyValueLength );
  5728. if (status != STATUS_BUFFER_OVERFLOW &&
  5729. status != STATUS_BUFFER_TOO_SMALL) {
  5730. ASSERT(!NT_SUCCESS(status));
  5731. return status;
  5732. }
  5733. //
  5734. // Allocate a buffer large enough to contain the entire key data value.
  5735. //
  5736. infoBuffer = SpMemAlloc(keyValueLength);
  5737. if (!infoBuffer) {
  5738. return STATUS_INSUFFICIENT_RESOURCES;
  5739. }
  5740. //
  5741. // Query the data for the key value.
  5742. //
  5743. status = ZwQueryValueKey( KeyHandle,
  5744. &unicodeString,
  5745. KeyValueFullInformation,
  5746. infoBuffer,
  5747. keyValueLength,
  5748. &keyValueLength );
  5749. if (!NT_SUCCESS( status )) {
  5750. SpMemFree(infoBuffer);
  5751. return status;
  5752. }
  5753. //
  5754. // Everything worked, so simply return the address of the allocated
  5755. // buffer to the caller, who is now responsible for freeing it.
  5756. //
  5757. *Information = infoBuffer;
  5758. return STATUS_SUCCESS;
  5759. }
  5760. VOID
  5761. SpUpdateDeviceInstanceKeyData(
  5762. IN HANDLE InstanceKey,
  5763. IN HANDLE ClassBranchKey,
  5764. IN PUNICODE_STRING EnumName,
  5765. IN PUNICODE_STRING DeviceName,
  5766. IN PUNICODE_STRING InstanceName
  5767. )
  5768. /*++
  5769. Routine Description:
  5770. This routine updates (removes\changes type\names) the various values under
  5771. the device instance key on an upgrade.
  5772. Arguments:
  5773. InstanceKey - Handle to the device instance key.
  5774. ClassBranchKey - Handle to the classes branch.
  5775. EnumName - Enumerator name.
  5776. DeviceName - Device name.
  5777. InstanceName - Instance name.
  5778. Return Value:
  5779. None.
  5780. --*/
  5781. {
  5782. NTSTATUS status;
  5783. UNICODE_STRING valueName, guidString, drvInstString;
  5784. DWORD length;
  5785. GUID guid;
  5786. PKEY_VALUE_FULL_INFORMATION info, guidInfo;
  5787. PWCHAR ids, className;
  5788. ULONG drvInst;
  5789. WCHAR driver[GUID_STRING_LEN + 5];
  5790. OBJECT_ATTRIBUTES obja;
  5791. HANDLE hClassKey;
  5792. BOOLEAN guidAllocatedViaRtl;
  5793. //
  5794. // Preinit
  5795. //
  5796. RtlInitUnicodeString(&guidString, NULL);
  5797. info = NULL;
  5798. guidInfo = NULL;
  5799. //
  5800. // Look at the instance key to see if we are dealing with a WinXP Beta2
  5801. // machine. If so, we need to convert it's compressed PnP data format back
  5802. // to the original Win2K format (app compat):
  5803. //
  5804. // <Normal, Win2K/WinXP> <Compressed, XP Beta2>
  5805. // "ClassGUID" (REG_SZ) "GUID" (REG_BINARY)
  5806. // "Driver" (REG_SZ, ClassGUID\DrvInst) "DrvInst" (REG_DWORD, DrvInst)
  5807. // "HardwareID" (UNICODE, MultiSz) "HwIDs" (ANSI-REG_BINARY, MultiSz)
  5808. // "CompatibleIDs" (UNICODE, MultiSz) "CIDs" (ANSI-REG_BINARY, MultiSz)
  5809. // "Class" (UNICODE) none, retrieved using ClassGUID
  5810. //
  5811. //
  5812. // Do we have the XP-Beta2 style "GUID" key?
  5813. //
  5814. status = SpGetRegistryValue(InstanceKey, REGSTR_VALUE_GUID, &info);
  5815. if (NT_SUCCESS(status) && !info) {
  5816. status = STATUS_UNSUCCESSFUL;
  5817. }
  5818. if (NT_SUCCESS(status)) {
  5819. //
  5820. // Change "GUID" (REG_BINARY) to "ClassGUID" (REG_SZ).
  5821. //
  5822. status = RtlStringFromGUID((GUID *)((PUCHAR)info + info->DataOffset), &guidString);
  5823. SpMemFree(info);
  5824. if (NT_SUCCESS(status)) {
  5825. guidAllocatedViaRtl = TRUE;
  5826. RtlInitUnicodeString(&valueName, REGSTR_VAL_CLASSGUID);
  5827. ZwSetValueKey(
  5828. InstanceKey,
  5829. &valueName,
  5830. 0,
  5831. REG_SZ,
  5832. guidString.Buffer,
  5833. guidString.Length + sizeof(UNICODE_NULL));
  5834. //
  5835. // Delete old "GUID" value
  5836. //
  5837. RtlInitUnicodeString(&valueName, REGSTR_VALUE_GUID);
  5838. ZwDeleteValueKey(InstanceKey, &valueName);
  5839. }
  5840. } else {
  5841. //
  5842. // This might be a rare Lab1 build where we've already done the
  5843. // conversion but we forgot to restore the class name.
  5844. //
  5845. status = SpGetRegistryValue(InstanceKey, REGSTR_VAL_CLASS, &info);
  5846. if (NT_SUCCESS(status) && info) {
  5847. //
  5848. // We successfully retrieved the class name from the device
  5849. // instance key--no need to attempt further migration.
  5850. //
  5851. SpMemFree(info);
  5852. status = STATUS_UNSUCCESSFUL;
  5853. } else {
  5854. status = SpGetRegistryValue(InstanceKey, REGSTR_VAL_CLASSGUID, &guidInfo);
  5855. if (NT_SUCCESS(status) && !guidInfo) {
  5856. status = STATUS_UNSUCCESSFUL;
  5857. }
  5858. if (NT_SUCCESS(status)) {
  5859. //
  5860. // The ClassGUID value exists. Initialize our string with this
  5861. // GUID so we can go to the corresponding key under the Class
  5862. // Branch to lookup the Class name.
  5863. //
  5864. guidAllocatedViaRtl = FALSE;
  5865. RtlInitUnicodeString(&guidString,
  5866. (PWCHAR)((PUCHAR)guidInfo + guidInfo->DataOffset)
  5867. );
  5868. }
  5869. }
  5870. }
  5871. if (NT_SUCCESS(status)) {
  5872. //
  5873. // While we are here we need to restore the class name as well.
  5874. // Start by getting the class name from the class's branch itself.
  5875. //
  5876. InitializeObjectAttributes(
  5877. &obja,
  5878. &guidString,
  5879. OBJ_CASE_INSENSITIVE,
  5880. ClassBranchKey,
  5881. NULL
  5882. );
  5883. status = ZwOpenKey(&hClassKey, KEY_ALL_ACCESS, &obja);
  5884. ASSERT(NT_SUCCESS(status));
  5885. if (NT_SUCCESS(status)) {
  5886. status = SpGetRegistryValue(hClassKey, REGSTR_VAL_CLASS, &info);
  5887. if (NT_SUCCESS(status) && !info) {
  5888. status = STATUS_UNSUCCESSFUL;
  5889. }
  5890. if (NT_SUCCESS(status)) {
  5891. //
  5892. // Copy the class name stored in the class branch to the
  5893. // instance key.
  5894. //
  5895. className = (PWCHAR)((PUCHAR)info + info->DataOffset);
  5896. RtlInitUnicodeString(&valueName, REGSTR_VAL_CLASS);
  5897. ZwSetValueKey(
  5898. InstanceKey,
  5899. &valueName,
  5900. 0,
  5901. REG_SZ,
  5902. className,
  5903. (wcslen(className)+1)*sizeof(WCHAR)
  5904. );
  5905. SpMemFree(info);
  5906. }
  5907. ZwClose(hClassKey);
  5908. }
  5909. }
  5910. //
  5911. // At this point, if status is successful, that means we migrated Class/
  5912. // ClassGUID values, so there may be more to do...
  5913. //
  5914. if (NT_SUCCESS(status)) {
  5915. //
  5916. // Do we have the XP-Beta2 style "DrvInst" key?
  5917. //
  5918. status = SpGetRegistryValue(InstanceKey, REGSTR_VALUE_DRVINST, &info);
  5919. if (NT_SUCCESS(status) && !info) {
  5920. status = STATUS_UNSUCCESSFUL;
  5921. }
  5922. if (NT_SUCCESS(status)) {
  5923. //
  5924. // Change DrvInst (REG_DWORD) to Driver (REG_SZ) from "ClassGuid\DrvInst"
  5925. //
  5926. ASSERT(guidString.Length != 0);
  5927. drvInst = *(PULONG)((PUCHAR)info + info->DataOffset);
  5928. swprintf(driver,
  5929. TEXT("%wZ\\%04u"),
  5930. &guidString,
  5931. drvInst);
  5932. SpMemFree(info);
  5933. RtlInitUnicodeString(&valueName, REGSTR_VAL_DRIVER);
  5934. ZwSetValueKey(
  5935. InstanceKey,
  5936. &valueName,
  5937. 0,
  5938. REG_SZ,
  5939. driver,
  5940. sizeof(driver)
  5941. );
  5942. //
  5943. // Delete DrvInst value
  5944. //
  5945. RtlInitUnicodeString(&valueName, REGSTR_VALUE_DRVINST);
  5946. ZwDeleteValueKey(InstanceKey, &valueName);
  5947. }
  5948. }
  5949. //
  5950. // We don't need the class guid anymore.
  5951. //
  5952. if (guidString.Buffer) {
  5953. if (guidAllocatedViaRtl) {
  5954. RtlFreeUnicodeString(&guidString);
  5955. } else {
  5956. SpMemFree(guidInfo);
  5957. }
  5958. }
  5959. //
  5960. // Do we have the XP-Beta2 "HwIDs" key?
  5961. //
  5962. status = SpGetRegistryValue(InstanceKey, REGSTR_VALUE_HWIDS, &info);
  5963. if (NT_SUCCESS(status) && !info) {
  5964. status = STATUS_UNSUCCESSFUL;
  5965. }
  5966. if (NT_SUCCESS(status)) {
  5967. //
  5968. // Change HW IDs from ANSI to UNICODE.
  5969. //
  5970. ids = SpConvertMultiSzStrToWstr(((PUCHAR)info + info->DataOffset), info->DataLength);
  5971. if (ids) {
  5972. RtlInitUnicodeString(&valueName, REGSTR_VAL_HARDWAREID);
  5973. ZwSetValueKey(
  5974. InstanceKey,
  5975. &valueName,
  5976. 0,
  5977. REG_MULTI_SZ,
  5978. ids,
  5979. info->DataLength * sizeof(WCHAR)
  5980. );
  5981. //
  5982. // Delete HwIDs value
  5983. //
  5984. RtlInitUnicodeString(&valueName, REGSTR_VALUE_HWIDS);
  5985. ZwDeleteValueKey(InstanceKey, &valueName);
  5986. SpMemFree(ids);
  5987. }
  5988. SpMemFree(info);
  5989. }
  5990. //
  5991. // Do we have the XP-Beta2 "CIDs" key?
  5992. //
  5993. status = SpGetRegistryValue(InstanceKey, REGSTR_VALUE_CIDS, &info);
  5994. if (NT_SUCCESS(status) && !info) {
  5995. status = STATUS_UNSUCCESSFUL;
  5996. }
  5997. if (NT_SUCCESS(status)) {
  5998. //
  5999. // Change Compatible IDs from ANSI to UNICODE.
  6000. //
  6001. ids = SpConvertMultiSzStrToWstr(((PUCHAR)info + info->DataOffset), info->DataLength);
  6002. if (ids) {
  6003. RtlInitUnicodeString(&valueName, REGSTR_VAL_COMPATIBLEIDS);
  6004. ZwSetValueKey(
  6005. InstanceKey,
  6006. &valueName,
  6007. 0,
  6008. REG_MULTI_SZ,
  6009. ids,
  6010. info->DataLength * sizeof(WCHAR)
  6011. );
  6012. //
  6013. // Delete CIDs value
  6014. //
  6015. RtlInitUnicodeString(&valueName, REGSTR_VALUE_CIDS);
  6016. ZwDeleteValueKey(InstanceKey, &valueName);
  6017. SpMemFree(ids);
  6018. }
  6019. SpMemFree(info);
  6020. }
  6021. }
  6022. NTSTATUS
  6023. SpUpdateDeviceInstanceData(
  6024. IN HANDLE ControlSet
  6025. )
  6026. /*++
  6027. Routine Description:
  6028. This routine enumerates all the keys under HKLM\System\CCS\Enum and call
  6029. SpUpdateDeviceInstanceKeyData for each device instance key.
  6030. Arguments:
  6031. ControlSet - Handle to the control set to update.
  6032. Return Value:
  6033. Status value indicating outcome of operation.
  6034. --*/
  6035. {
  6036. NTSTATUS status;
  6037. OBJECT_ATTRIBUTES obja;
  6038. HANDLE hEnumBranchKey, hClassBranchKey;
  6039. UNICODE_STRING enumBranch, classBranch;
  6040. HANDLE hEnumeratorKey, hDeviceKey, hInstanceKey;
  6041. UNICODE_STRING enumeratorName, deviceName, instanceName;
  6042. PKEY_BASIC_INFORMATION enumBasicInfo, deviceBasicInfo, instBasicInfo;
  6043. ULONG ulEnumerator, ulDevice, ulInstance, ulLength, ulBasicInfoSize;
  6044. //
  6045. // Preinit for error
  6046. //
  6047. hEnumBranchKey = NULL;
  6048. hClassBranchKey = NULL;
  6049. enumBasicInfo = NULL;
  6050. //
  6051. // First open the enum branch for this control set
  6052. //
  6053. RtlInitUnicodeString(&enumBranch, REGSTR_KEY_ENUM);
  6054. InitializeObjectAttributes(
  6055. &obja,
  6056. &enumBranch,
  6057. OBJ_CASE_INSENSITIVE,
  6058. ControlSet,
  6059. NULL
  6060. );
  6061. status = ZwOpenKey(&hEnumBranchKey, KEY_ALL_ACCESS, &obja);
  6062. if (!NT_SUCCESS(status)) {
  6063. ASSERT(NT_SUCCESS(status));
  6064. goto Exit;
  6065. }
  6066. //
  6067. // Now open the class key for this control set.
  6068. //
  6069. RtlInitUnicodeString(&classBranch, REGSTR_KEY_CONTROL L"\\" REGSTR_KEY_CLASS);
  6070. InitializeObjectAttributes(
  6071. &obja,
  6072. &classBranch,
  6073. OBJ_CASE_INSENSITIVE,
  6074. ControlSet,
  6075. NULL
  6076. );
  6077. status = ZwOpenKey(&hClassBranchKey, KEY_ALL_ACCESS, &obja);
  6078. if (!NT_SUCCESS(status)) {
  6079. ASSERT(NT_SUCCESS(status));
  6080. goto Exit;
  6081. }
  6082. //
  6083. // Allocate memory for enumeration
  6084. //
  6085. ulBasicInfoSize = sizeof(KEY_BASIC_INFORMATION) + REG_MAX_KEY_NAME_LENGTH;
  6086. enumBasicInfo = SpMemAlloc(ulBasicInfoSize * 3);
  6087. if (enumBasicInfo == NULL) {
  6088. status = STATUS_INSUFFICIENT_RESOURCES;
  6089. goto Exit;
  6090. }
  6091. //
  6092. // Cast two pointers for future buffer usage.
  6093. //
  6094. deviceBasicInfo = (PKEY_BASIC_INFORMATION)((PUCHAR)enumBasicInfo + ulBasicInfoSize);
  6095. instBasicInfo = (PKEY_BASIC_INFORMATION)((PUCHAR)deviceBasicInfo + ulBasicInfoSize);
  6096. //
  6097. // Walk each enumerator and then each device instance
  6098. //
  6099. status = STATUS_SUCCESS;
  6100. for (ulEnumerator = 0; ; ulEnumerator++) {
  6101. status = ZwEnumerateKey(
  6102. hEnumBranchKey,
  6103. ulEnumerator,
  6104. KeyBasicInformation,
  6105. enumBasicInfo,
  6106. ulBasicInfoSize,
  6107. &ulLength
  6108. );
  6109. if (!NT_SUCCESS(status)) {
  6110. break;
  6111. }
  6112. //
  6113. // Open the enumerator
  6114. //
  6115. enumeratorName.Length = enumeratorName.MaximumLength = (USHORT)enumBasicInfo->NameLength;
  6116. enumeratorName.Buffer = &enumBasicInfo->Name[0];
  6117. InitializeObjectAttributes(
  6118. &obja,
  6119. &enumeratorName,
  6120. OBJ_CASE_INSENSITIVE,
  6121. hEnumBranchKey,
  6122. NULL
  6123. );
  6124. status = ZwOpenKey(&hEnumeratorKey, KEY_ALL_ACCESS, &obja);
  6125. if (!NT_SUCCESS(status)) {
  6126. break;
  6127. }
  6128. //
  6129. // Walk each device
  6130. //
  6131. for (ulDevice = 0; ; ulDevice++) {
  6132. status = ZwEnumerateKey(
  6133. hEnumeratorKey,
  6134. ulDevice,
  6135. KeyBasicInformation,
  6136. deviceBasicInfo,
  6137. ulBasicInfoSize,
  6138. &ulLength
  6139. );
  6140. if (!NT_SUCCESS(status)) {
  6141. break;
  6142. }
  6143. deviceName.Length = deviceName.MaximumLength = (USHORT)deviceBasicInfo->NameLength;
  6144. deviceName.Buffer = &deviceBasicInfo->Name[0];
  6145. InitializeObjectAttributes(
  6146. &obja,
  6147. &deviceName,
  6148. OBJ_CASE_INSENSITIVE,
  6149. hEnumeratorKey,
  6150. NULL
  6151. );
  6152. status = ZwOpenKey(&hDeviceKey, KEY_ALL_ACCESS, &obja);
  6153. if (!NT_SUCCESS(status)) {
  6154. break;
  6155. }
  6156. //
  6157. // Now walk each instance
  6158. //
  6159. for (ulInstance = 0; ; ulInstance++) {
  6160. status = ZwEnumerateKey(
  6161. hDeviceKey,
  6162. ulInstance,
  6163. KeyBasicInformation,
  6164. instBasicInfo,
  6165. ulBasicInfoSize,
  6166. &ulLength
  6167. );
  6168. if (!NT_SUCCESS(status)) {
  6169. break;
  6170. }
  6171. instanceName.Length = instanceName.MaximumLength = (USHORT)instBasicInfo->NameLength;
  6172. instanceName.Buffer = &instBasicInfo->Name[0];
  6173. InitializeObjectAttributes(
  6174. &obja,
  6175. &instanceName,
  6176. OBJ_CASE_INSENSITIVE,
  6177. hDeviceKey,
  6178. NULL
  6179. );
  6180. status = ZwOpenKey(&hInstanceKey, KEY_ALL_ACCESS, &obja);
  6181. if (!NT_SUCCESS(status)) {
  6182. break;
  6183. }
  6184. SpUpdateDeviceInstanceKeyData(
  6185. hInstanceKey,
  6186. hClassBranchKey,
  6187. &enumeratorName,
  6188. &deviceName,
  6189. &instanceName
  6190. );
  6191. ZwClose(hInstanceKey);
  6192. }
  6193. ZwClose(hDeviceKey);
  6194. if (status != STATUS_NO_MORE_ENTRIES) {
  6195. break;
  6196. }
  6197. }
  6198. ZwClose(hEnumeratorKey);
  6199. if (status != STATUS_NO_MORE_ENTRIES) {
  6200. break;
  6201. }
  6202. }
  6203. //
  6204. // STATUS_NO_MORE_ENTRIES isn't a failure, it just means we've exhausted
  6205. // the number of enumerators.
  6206. //
  6207. if (status == STATUS_NO_MORE_ENTRIES) {
  6208. status = STATUS_SUCCESS;
  6209. }
  6210. Exit:
  6211. if (enumBasicInfo) {
  6212. SpMemFree(enumBasicInfo);
  6213. }
  6214. if (hEnumBranchKey) {
  6215. ZwClose(hEnumBranchKey);
  6216. }
  6217. if (hClassBranchKey) {
  6218. ZwClose(hClassBranchKey);
  6219. }
  6220. ASSERT(NT_SUCCESS(status));
  6221. return status;
  6222. }
  6223. NTSTATUS
  6224. SppDeleteRegistryValueRecursive(
  6225. HANDLE hKeyRoot,
  6226. PWSTR KeyPath, OPTIONAL
  6227. PWSTR ValueToDelete
  6228. )
  6229. /*++
  6230. Routine Description:
  6231. This routine will recursively enumerate the specified hKeyRoot and KeyPath
  6232. and delete any ValueToDelete registry values in those keys.
  6233. Arguments:
  6234. hKeyRoot: Handle to root key
  6235. KeyPath: root key relative path to the subkey which needs to be
  6236. recursively copied. if this is null hKeyRoot is the key
  6237. from which the recursive copy is to be done.
  6238. ValueToDelete name of the value that needs to be deleted.
  6239. Return Value:
  6240. Status is returned.
  6241. --*/
  6242. {
  6243. NTSTATUS Status = STATUS_SUCCESS;
  6244. OBJECT_ATTRIBUTES ObjaSrc;
  6245. UNICODE_STRING UnicodeStringSrc, UnicodeStringValue;
  6246. HANDLE hKey=NULL;
  6247. ULONG ResultLength, Index;
  6248. PWSTR SubkeyName;
  6249. PKEY_BASIC_INFORMATION KeyInfo;
  6250. //
  6251. // Get a handle to the source key
  6252. //
  6253. if(KeyPath == NULL) {
  6254. hKey = hKeyRoot;
  6255. }
  6256. else {
  6257. //
  6258. // Open the Src key
  6259. //
  6260. INIT_OBJA(&ObjaSrc,&UnicodeStringSrc,KeyPath);
  6261. ObjaSrc.RootDirectory = hKeyRoot;
  6262. Status = ZwOpenKey(&hKey,KEY_READ,&ObjaSrc);
  6263. if(!NT_SUCCESS(Status)) {
  6264. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: unable to open key %ws in the source hive (%lx)\n",KeyPath,Status));
  6265. return(Status);
  6266. }
  6267. }
  6268. //
  6269. // Enumerate all keys in the source key and recursively create
  6270. // all the subkeys
  6271. //
  6272. KeyInfo = (PKEY_BASIC_INFORMATION)TemporaryBuffer;
  6273. for( Index=0;;Index++ ) {
  6274. Status = ZwEnumerateKey(
  6275. hKey,
  6276. Index,
  6277. KeyBasicInformation,
  6278. TemporaryBuffer,
  6279. sizeof(TemporaryBuffer),
  6280. &ResultLength
  6281. );
  6282. if(!NT_SUCCESS(Status)) {
  6283. if(Status == STATUS_NO_MORE_ENTRIES) {
  6284. Status = STATUS_SUCCESS;
  6285. }
  6286. else {
  6287. if(KeyPath!=NULL) {
  6288. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: unable to enumerate subkeys in key %ws(%lx)\n",KeyPath, Status));
  6289. }
  6290. else {
  6291. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: unable to enumerate subkeys in root key(%lx)\n", Status));
  6292. }
  6293. }
  6294. break;
  6295. }
  6296. //
  6297. // Zero-terminate the subkey name just in case.
  6298. //
  6299. KeyInfo->Name[KeyInfo->NameLength/sizeof(WCHAR)] = 0;
  6300. //
  6301. // Make a duplicate of the subkey name because the name is
  6302. // in TemporaryBuffer, which might get clobbered by recursive
  6303. // calls to this routine.
  6304. //
  6305. SubkeyName = SpDupStringW(KeyInfo->Name);
  6306. if (SubkeyName) {
  6307. Status = SppDeleteRegistryValueRecursive(
  6308. hKey,
  6309. SubkeyName,
  6310. ValueToDelete
  6311. );
  6312. SpMemFree(SubkeyName);
  6313. }
  6314. }
  6315. //
  6316. // Process any errors if found
  6317. //
  6318. if(!NT_SUCCESS(Status)) {
  6319. if(KeyPath != NULL) {
  6320. ZwClose(hKey);
  6321. }
  6322. return(Status);
  6323. }
  6324. //
  6325. // Delete the ValueToDelete value in this key. We won't check the status
  6326. // since it doesn't matter if this succeeds or not.
  6327. //
  6328. RtlInitUnicodeString(&UnicodeStringValue, ValueToDelete);
  6329. ZwDeleteValueKey(hKey,&UnicodeStringValue);
  6330. //
  6331. // cleanup
  6332. //
  6333. if(KeyPath != NULL) {
  6334. ZwClose(hKey);
  6335. }
  6336. return(Status);
  6337. }
  6338. NTSTATUS
  6339. SpCleanUpHive(
  6340. VOID
  6341. )
  6342. /*++
  6343. Routine Description:
  6344. This routine will cleanup the system hive before it is migrated to the
  6345. target system hive.
  6346. Arguments:
  6347. none
  6348. Return Value:
  6349. Status value indicating outcome of operation.
  6350. --*/
  6351. {
  6352. NTSTATUS Status;
  6353. OBJECT_ATTRIBUTES Obja;
  6354. UNICODE_STRING UnicodeString;
  6355. HANDLE hKey;
  6356. INIT_OBJA(&Obja,&UnicodeString,L"\\registry\\machine\\system\\currentcontrolset");
  6357. Obja.RootDirectory = NULL;
  6358. Status = ZwOpenKey(&hKey,KEY_ALL_ACCESS,&Obja);
  6359. if( !NT_SUCCESS( Status ) ) {
  6360. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Unable to open %ls on the setup hive (%lx)\n", L"\\registry\\machine\\system\\currentcontrolset", Status));
  6361. return( Status ) ;
  6362. }
  6363. //
  6364. // Delete the DeviceDesc values from under the enum key.
  6365. // The reason for this is that if we replace the DeviceDesc values on an
  6366. // upgrade then GUI mode setup won't be able to backup any 3rd party drivers
  6367. // that we are replaceing with our in-box drivers. This is because the
  6368. // DeviceDesc is one of three values that setupapi uses to create a
  6369. // unique driver node.
  6370. //
  6371. if (NTUpgrade == UpgradeFull) {
  6372. Status = SppDeleteRegistryValueRecursive(
  6373. hKey,
  6374. REGSTR_KEY_ENUM,
  6375. REGSTR_VAL_DEVDESC
  6376. );
  6377. if( !NT_SUCCESS( Status ) ) {
  6378. KdPrintEx((DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL, "SETUP: Unable to migrate %ls to the target hive. KeyPath, Status = %lx\n", Status));
  6379. }
  6380. }
  6381. ZwClose( hKey );
  6382. return( Status );
  6383. }
  6384. NTSTATUS
  6385. SpIterateRegistryKeyForKeys(
  6386. IN HANDLE RootKeyHandle,
  6387. IN PWSTR KeyToIterate,
  6388. IN SP_REGISTRYKEY_ITERATION_CALLBACK Callback,
  6389. IN PVOID Context
  6390. )
  6391. /*++
  6392. Routine Description:
  6393. Iterates the registry key looking for registry keys which are
  6394. immediately below the current key.
  6395. NOTE : To stop the iteration the callback function should return
  6396. FALSE.
  6397. Arguments:
  6398. RootKeyHandle - The root key which contains the key to iterate
  6399. KeyToIterate - The relative path for the key to iterate w.r.t to
  6400. root key.
  6401. Callback - The call function which will be called for each subkey
  6402. found under the requested key.
  6403. Context - Opaque context data that the caller needs and will be
  6404. passed on by the iteration routine for each invocation of
  6405. the callback function.
  6406. Return Value:
  6407. Appropriate NT status error code.
  6408. --*/
  6409. {
  6410. NTSTATUS Status = STATUS_INVALID_PARAMETER;
  6411. //
  6412. // Validate the arguments
  6413. //
  6414. if (RootKeyHandle && KeyToIterate && Callback) {
  6415. HANDLE KeyHandle = NULL;
  6416. UNICODE_STRING KeyName;
  6417. OBJECT_ATTRIBUTES ObjAttrs;
  6418. //
  6419. // Open the key which needs to be iterated
  6420. //
  6421. INIT_OBJA(&ObjAttrs, &KeyName, KeyToIterate);
  6422. ObjAttrs.RootDirectory = RootKeyHandle;
  6423. Status = ZwOpenKey(&KeyHandle,
  6424. KEY_ALL_ACCESS,
  6425. &ObjAttrs);
  6426. if (NT_SUCCESS(Status)) {
  6427. ULONG BufferLength = 4096;
  6428. PKEY_FULL_INFORMATION FullInfo = (PKEY_FULL_INFORMATION)SpMemAlloc(BufferLength);
  6429. ULONG ResultLength = 0;
  6430. if (FullInfo) {
  6431. //
  6432. // Find out how many subkeys the current key has
  6433. //
  6434. Status = ZwQueryKey(KeyHandle,
  6435. KeyFullInformation,
  6436. FullInfo,
  6437. BufferLength,
  6438. &ResultLength);
  6439. if (NT_SUCCESS(Status)) {
  6440. ULONG NumSubKeys = FullInfo->SubKeys;
  6441. ULONG Index;
  6442. BOOLEAN Done;
  6443. NTSTATUS LastError = STATUS_SUCCESS;
  6444. //
  6445. // Iterate each subkey of the current key and callback
  6446. // the subscriber function
  6447. //
  6448. for (Index = 0, Done = FALSE;
  6449. NT_SUCCESS(Status) && !Done && (Index < NumSubKeys);
  6450. Index++) {
  6451. PKEY_BASIC_INFORMATION BasicInfo = (PKEY_BASIC_INFORMATION)FullInfo;
  6452. Status = ZwEnumerateKey(KeyHandle,
  6453. Index,
  6454. KeyBasicInformation,
  6455. BasicInfo,
  6456. BufferLength,
  6457. &ResultLength);
  6458. if (NT_SUCCESS(Status)) {
  6459. NTSTATUS CallbackStatus = STATUS_SUCCESS;
  6460. SP_REGISTRYKEY_ITERATION_CALLBACK_DATA CallbackData;
  6461. CallbackData.InformationType = KeyBasicInformation;
  6462. CallbackData.Information = (PVOID)BasicInfo;
  6463. CallbackData.ParentKeyHandle = KeyHandle;
  6464. //
  6465. // Callback
  6466. //
  6467. Done = (Callback(Context, &CallbackData, &CallbackStatus) == FALSE);
  6468. //
  6469. // register any error and continue on
  6470. //
  6471. if (!NT_SUCCESS(CallbackStatus)) {
  6472. LastError = CallbackStatus;
  6473. }
  6474. } else if (Status == STATUS_NO_MORE_ENTRIES) {
  6475. //
  6476. // Done with iteration
  6477. //
  6478. Done = TRUE;
  6479. Status = STATUS_SUCCESS;
  6480. }
  6481. }
  6482. if (!NT_SUCCESS(LastError)) {
  6483. Status = LastError;
  6484. }
  6485. }
  6486. SpMemFree(FullInfo);
  6487. } else {
  6488. Status = STATUS_NO_MEMORY;
  6489. }
  6490. }
  6491. }
  6492. return Status;
  6493. }
  6494. //
  6495. // Context data structure for class filter deletion
  6496. //
  6497. typedef struct _SP_CLASS_FILTER_DELETE_CONTEXT {
  6498. PVOID Buffer;
  6499. ULONG BufferLength;
  6500. PWSTR DriverName;
  6501. } SP_CLASS_FILTER_DELETE_CONTEXT, *PSP_CLASS_FILTER_DELETE_CONTEXT;
  6502. static
  6503. BOOLEAN
  6504. SppFixUpperAndLowerFilterEntries(
  6505. IN PVOID Context,
  6506. IN PSP_REGISTRYKEY_ITERATION_CALLBACK_DATA Data,
  6507. OUT NTSTATUS *Status
  6508. )
  6509. /*++
  6510. Routine Description:
  6511. Arguments:
  6512. Context - The SP_CLASS_FILTER_DELETE_CONTEXT disguised as
  6513. a void pointer.
  6514. Data - The data the iterator passed to us, containing information
  6515. about the current subkey.
  6516. Status - Place holder for receiving the error status code which
  6517. this function returns.
  6518. Return Value:
  6519. TRUE if the iteration needs to be continued otherwise FALSE.
  6520. --*/
  6521. {
  6522. BOOLEAN Result = FALSE;
  6523. *Status = STATUS_INVALID_PARAMETER;
  6524. if (Context && Data && (Data->InformationType == KeyBasicInformation)) {
  6525. NTSTATUS UpperStatus, LowerStatus;
  6526. PKEY_BASIC_INFORMATION BasicInfo = (PKEY_BASIC_INFORMATION)(Data->Information);
  6527. PSP_CLASS_FILTER_DELETE_CONTEXT DelContext = (PSP_CLASS_FILTER_DELETE_CONTEXT)Context;
  6528. PWSTR KeyName = (PWSTR)(DelContext->Buffer);
  6529. if (KeyName && (BasicInfo->NameLength < DelContext->BufferLength)) {
  6530. wcsncpy(KeyName, BasicInfo->Name, BasicInfo->NameLength/sizeof(WCHAR));
  6531. KeyName[BasicInfo->NameLength/sizeof(WCHAR)] = UNICODE_NULL;
  6532. //
  6533. // Delete the string from upperfilters
  6534. //
  6535. UpperStatus = SpRemoveStringFromMultiSz(Data->ParentKeyHandle,
  6536. KeyName,
  6537. SP_UPPER_FILTERS,
  6538. DelContext->DriverName);
  6539. //
  6540. // Delete the string from lowerfilters
  6541. //
  6542. LowerStatus = SpRemoveStringFromMultiSz(Data->ParentKeyHandle,
  6543. KeyName,
  6544. SP_LOWER_FILTERS,
  6545. DelContext->DriverName);
  6546. if (NT_SUCCESS(UpperStatus) || NT_SUCCESS(LowerStatus)) {
  6547. *Status = STATUS_SUCCESS;
  6548. } else if (((UpperStatus == STATUS_OBJECT_NAME_NOT_FOUND) ||
  6549. (UpperStatus == STATUS_OBJECT_NAME_INVALID)) &&
  6550. ((LowerStatus == STATUS_OBJECT_NAME_NOT_FOUND) ||
  6551. (LowerStatus == STATUS_OBJECT_NAME_INVALID))) {
  6552. //
  6553. // If the value was not found then continue on
  6554. //
  6555. *Status = STATUS_SUCCESS;
  6556. }
  6557. //
  6558. // we want to continue iterating irrespective of the results
  6559. //
  6560. Result = TRUE;
  6561. }
  6562. }
  6563. return Result;
  6564. }
  6565. NTSTATUS
  6566. SpProcessServicesToDisable(
  6567. IN PVOID WinntSifHandle,
  6568. IN PWSTR SectionName,
  6569. IN HANDLE CurrentControlSetKey
  6570. )
  6571. /*++
  6572. Routine Description:
  6573. Processess the winnt.sif's [ServiceToDisable] section to
  6574. remove the service entries from upper and lower filters.
  6575. Arguments:
  6576. WinntSifHandle - Handle to winnt.sif file.
  6577. SectionName - The name of section in winnt.sif which contains
  6578. a list of service name which need to be removed from
  6579. the filter list.
  6580. CurrentControlKey - The handle to CurrentControlSet root key.
  6581. Return Value:
  6582. Appropriate NTSTATUS error code.
  6583. --*/
  6584. {
  6585. NTSTATUS Status = STATUS_INVALID_PARAMETER;
  6586. //
  6587. // Validate arguments
  6588. //
  6589. if (WinntSifHandle && SectionName && CurrentControlSetKey) {
  6590. ULONG EntriesToProcess = SpCountLinesInSection(WinntSifHandle,
  6591. SP_SERVICES_TO_DISABLE);
  6592. //
  6593. // If there are any entries to process -- then process them
  6594. //
  6595. if (EntriesToProcess) {
  6596. ULONG BufferLength = 16 * 1024;
  6597. PVOID Buffer = SpMemAlloc(BufferLength);
  6598. if (Buffer) {
  6599. ULONG Index;
  6600. PWSTR CurrentEntry;
  6601. SP_CLASS_FILTER_DELETE_CONTEXT DeleteContext = {0};
  6602. NTSTATUS LastErrorStatus = STATUS_SUCCESS;
  6603. //
  6604. // Process each entry
  6605. //
  6606. DeleteContext.Buffer = Buffer;
  6607. DeleteContext.BufferLength = BufferLength;
  6608. for(Index = 0; Index < EntriesToProcess; Index++) {
  6609. CurrentEntry = SpGetSectionLineIndex(WinntSifHandle,
  6610. SP_SERVICES_TO_DISABLE,
  6611. Index,
  6612. 0);
  6613. if (CurrentEntry) {
  6614. DeleteContext.DriverName = CurrentEntry;
  6615. Status = SpIterateRegistryKeyForKeys(CurrentControlSetKey,
  6616. L"Class",
  6617. SppFixUpperAndLowerFilterEntries,
  6618. &DeleteContext);
  6619. //
  6620. // save away the error code and continue on
  6621. //
  6622. if (!NT_SUCCESS(Status)) {
  6623. LastErrorStatus = Status;
  6624. }
  6625. }
  6626. }
  6627. //
  6628. // Even one of the entries failed to delete correctly
  6629. // then flag it as a failure
  6630. //
  6631. if (!NT_SUCCESS(LastErrorStatus)) {
  6632. Status = LastErrorStatus;
  6633. }
  6634. SpMemFree(Buffer);
  6635. }
  6636. } else {
  6637. Status = STATUS_SUCCESS; // nothing to process
  6638. }
  6639. }
  6640. return Status;
  6641. }
  6642. //
  6643. // Context data structure for device instance filter deletion
  6644. //
  6645. typedef struct _SP_DEVINSTANCE_FILTER_DELETE_CONTEXT {
  6646. PVOID Buffer;
  6647. ULONG BufferLength;
  6648. PUNICODE_STRING *ClassGuids;
  6649. } SP_DEVINSTANCE_FILTER_DELETE_CONTEXT, *PSP_DEVINSTANCE_FILTER_DELETE_CONTEXT;
  6650. static
  6651. VOID
  6652. SppRemoveFilterDriversForClassDeviceInstances(
  6653. IN HANDLE SetupInstanceKeyHandle,
  6654. IN HANDLE UpgradeInstanceKeyHandle,
  6655. IN BOOLEAN RootEnumerated,
  6656. IN PVOID Context
  6657. )
  6658. /*++
  6659. Routine Description:
  6660. Callback which removes the filter drivers for the
  6661. specified device instance
  6662. Arguments:
  6663. SetupInstanceKeyHandle - Handle to device instance key in setupreg.hiv.
  6664. UpgradeInstanceKeyHandle - Handle to device instance key in the
  6665. system hive of the installation being upgraded.
  6666. RootEnumerated - Whether this is root enumerated key or not.
  6667. Context - SP_DEVINSTANCE_FILTER_DELETE_CONTEXT instance disguised
  6668. as PVOID context.
  6669. Return Value:
  6670. None.
  6671. --*/
  6672. {
  6673. //
  6674. // Validate arguments
  6675. //
  6676. if (Context && SetupInstanceKeyHandle) {
  6677. PSP_DEVINSTANCE_FILTER_DELETE_CONTEXT DelContext;
  6678. //
  6679. // get device instance filter deletion context
  6680. //
  6681. DelContext = (PSP_DEVINSTANCE_FILTER_DELETE_CONTEXT)Context;
  6682. //
  6683. // Validate the context
  6684. //
  6685. if (DelContext->Buffer && DelContext->BufferLength &&
  6686. DelContext->ClassGuids && DelContext->ClassGuids[0]) {
  6687. PKEY_VALUE_FULL_INFORMATION ValueInfo;
  6688. UNICODE_STRING GuidValueName;
  6689. ULONG BufferLength;
  6690. NTSTATUS Status;
  6691. BOOLEAN DeleteFilterValueKeys = FALSE;
  6692. //
  6693. // reuse the buffer allocated by the iterator caller
  6694. //
  6695. ValueInfo = (PKEY_VALUE_FULL_INFORMATION)(DelContext->Buffer);
  6696. RtlInitUnicodeString(&GuidValueName, SP_CLASS_GUID_VALUE_NAME);
  6697. //
  6698. // Get the class GUID for the current device instance
  6699. //
  6700. Status = ZwQueryValueKey(SetupInstanceKeyHandle,
  6701. &GuidValueName,
  6702. KeyValueFullInformation,
  6703. ValueInfo,
  6704. DelContext->BufferLength - sizeof(WCHAR),
  6705. &BufferLength);
  6706. if (NT_SUCCESS(Status)) {
  6707. PWSTR CurrentGuid = (PWSTR)(((PUCHAR)ValueInfo + ValueInfo->DataOffset));
  6708. ULONG Index;
  6709. //
  6710. // null terminate the string (NOTE:we assume buffer has space)
  6711. //
  6712. CurrentGuid[ValueInfo->DataLength/sizeof(WCHAR)] = UNICODE_NULL;
  6713. //
  6714. // Is this the one of the class device instance we are looking for?
  6715. //
  6716. for (Index = 0; DelContext->ClassGuids[Index]; Index++) {
  6717. if (!_wcsicmp(CurrentGuid, DelContext->ClassGuids[Index]->Buffer)) {
  6718. DeleteFilterValueKeys = TRUE;
  6719. break;
  6720. }
  6721. }
  6722. }
  6723. //
  6724. // Delete the upper and lower filter value keys
  6725. //
  6726. if (DeleteFilterValueKeys) {
  6727. UNICODE_STRING UpperValueName, LowerValueName;
  6728. RtlInitUnicodeString(&UpperValueName, SP_UPPER_FILTERS);
  6729. RtlInitUnicodeString(&LowerValueName, SP_LOWER_FILTERS);
  6730. if (SetupInstanceKeyHandle) {
  6731. ZwDeleteValueKey(SetupInstanceKeyHandle, &UpperValueName);
  6732. ZwDeleteValueKey(SetupInstanceKeyHandle, &LowerValueName);
  6733. }
  6734. if (UpgradeInstanceKeyHandle) {
  6735. ZwDeleteValueKey(UpgradeInstanceKeyHandle, &UpperValueName);
  6736. ZwDeleteValueKey(UpgradeInstanceKeyHandle, &LowerValueName);
  6737. }
  6738. }
  6739. }
  6740. }
  6741. }
  6742. NTSTATUS
  6743. SpDeleteRequiredDeviceInstanceFilters(
  6744. IN HANDLE CCSKeyHandle
  6745. )
  6746. /*++
  6747. Routine Description:
  6748. Deletes filter entries from keyboard and mouse class device
  6749. instances in registry.
  6750. Arguments:
  6751. CCSHandle - Handle to CCS key.
  6752. Return Value:
  6753. Appropriate NT status code.
  6754. --*/
  6755. {
  6756. NTSTATUS Status = STATUS_INVALID_PARAMETER;
  6757. if (CCSKeyHandle) {
  6758. UNICODE_STRING MouseGuidStr = {0};
  6759. UNICODE_STRING KeyboardGuidStr = {0};
  6760. PUNICODE_STRING ClassGuids[16] = {0};
  6761. ULONG CurrentIndex = 0;
  6762. NTSTATUS LastErrorCode = STATUS_SUCCESS;
  6763. //
  6764. // Get hold of keyboard class GUID string
  6765. //
  6766. Status = RtlStringFromGUID(&GUID_DEVCLASS_KEYBOARD, &KeyboardGuidStr);
  6767. if (NT_SUCCESS(Status)) {
  6768. ClassGuids[CurrentIndex++] = &KeyboardGuidStr;
  6769. } else {
  6770. LastErrorCode = Status;
  6771. }
  6772. //
  6773. // Get hold of mouse class GUID string
  6774. //
  6775. Status = RtlStringFromGUID(&GUID_DEVCLASS_MOUSE, &MouseGuidStr);
  6776. if (NT_SUCCESS(Status)) {
  6777. ClassGuids[CurrentIndex++] = &MouseGuidStr;
  6778. } else {
  6779. LastErrorCode = Status;
  6780. }
  6781. //
  6782. // If we could form atleast one class guid string
  6783. //
  6784. if (CurrentIndex) {
  6785. SP_DEVINSTANCE_FILTER_DELETE_CONTEXT DelContext = {0};
  6786. ULONG BufferLength = 4096;
  6787. PVOID Buffer = SpMemAlloc(BufferLength);
  6788. if (Buffer) {
  6789. //
  6790. // null terminate the class GUID unicode string array
  6791. //
  6792. ClassGuids[CurrentIndex] = NULL;
  6793. DelContext.Buffer = Buffer;
  6794. DelContext.BufferLength = BufferLength;
  6795. DelContext.ClassGuids = ClassGuids;
  6796. //
  6797. // Iterate through all the device instances
  6798. //
  6799. SpApplyFunctionToDeviceInstanceKeys(CCSKeyHandle,
  6800. SppRemoveFilterDriversForClassDeviceInstances,
  6801. &DelContext);
  6802. SpMemFree(Buffer);
  6803. } else {
  6804. LastErrorCode = STATUS_NO_MEMORY;
  6805. }
  6806. //
  6807. // free the allocated strings
  6808. //
  6809. if (MouseGuidStr.Buffer) {
  6810. RtlFreeUnicodeString(&MouseGuidStr);
  6811. }
  6812. if (KeyboardGuidStr.Buffer) {
  6813. RtlFreeUnicodeString(&KeyboardGuidStr);
  6814. }
  6815. }
  6816. Status = LastErrorCode;
  6817. }
  6818. return Status;
  6819. }