Leaked source code of windows server 2003
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.

288 lines
7.1 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. repair.c
  5. Abstract:
  6. This module contains the code necessary for the
  7. repair command.
  8. Author:
  9. Wesley Witt (wesw) 22-Sept-1998
  10. Revision History:
  11. Repair PathtoERFiles PathtoNTSourceFiles /NoConfirm /RepairStartup /Registry /RepairFiles
  12. Description: Replaces the NT4 Emergency Repair Process Screens
  13. Arguments:
  14. PathtoERFiles
  15. Path to the Emergency Repair Disk Files (Setup.log, autoexec.nt, config.nt).
  16. If this is not specified, the default is to prompt the user with 2 choices:
  17. Use a floppy, or use the repair info stored in %windir%\repair
  18. PathtoNTSourceFiles
  19. Path to the NT CD source files. By default, this is the CD-ROM if not
  20. specified. [Kartik Raghavan] This path does not need to be specified if
  21. you are repairing the registry and/or the Startup environment.
  22. NoConfirm
  23. Replace all files in setup.log whose checksums do not match without
  24. prompting the user. By default, the user is prompted for each file that
  25. is different and whether to replace or leave intact.
  26. Registry
  27. Replace all the registry files in %windir%\system32\config with the original
  28. copy of the registry saved after setup and located in %windir%\repair.
  29. RepairStartup
  30. Repair the startup environment / bootfiles/bootsector.
  31. (This may already be covered in another cmd--Wes?)
  32. Repair Files
  33. Compares the checksums of the files listed in setup.log to what's
  34. on system. If a file doesn't match, then the user is prompted to replace
  35. the file with the one from the NT Source Files. The user is not prompted
  36. if the /NoConfirm switch is specified.
  37. Usage:
  38. Repair a:\ d:\i386 /RepairStartup
  39. Repair
  40. --*/
  41. #include "cmdcons.h"
  42. #pragma hdrstop
  43. #define SETUP_REPAIR_DIRECTORY L"repair"
  44. #define SETUP_LOG_FILENAME L"\\setup.log"
  45. #define FLG_NO_CONFIRM 0x00000001
  46. #define FLG_STARTUP 0x00000002
  47. #define FLG_REGISTRY 0x00000004
  48. #define FLG_FILES 0x00000008
  49. LONG
  50. RcPromptForDisk(
  51. void
  52. )
  53. {
  54. PWSTR TagFile = NULL;
  55. ULONG i;
  56. WCHAR DevicePath[MAX_PATH];
  57. UNICODE_STRING UnicodeString;
  58. OBJECT_ATTRIBUTES ObjectAttributes;
  59. IO_STATUS_BLOCK IoStatusBlock;
  60. NTSTATUS Status;
  61. HANDLE Handle;
  62. /*
  63. SpGetSourceMediaInfo(
  64. _CmdConsBlock->SifHandle,
  65. L"",
  66. NULL,
  67. &TagFile,
  68. NULL
  69. );
  70. */
  71. for (i=0; i<IoGetConfigurationInformation()->CdRomCount; i++) {
  72. swprintf( DevicePath, L"\\Device\\Cdrom%u", i );
  73. SpConcatenatePaths( DevicePath, TagFile );
  74. INIT_OBJA( &ObjectAttributes, &UnicodeString, DevicePath) ;
  75. Status = ZwCreateFile(
  76. &Handle,
  77. FILE_GENERIC_READ,
  78. &ObjectAttributes,
  79. &IoStatusBlock,
  80. NULL,
  81. FILE_ATTRIBUTE_NORMAL,
  82. FILE_SHARE_READ,
  83. FILE_OPEN,
  84. 0,
  85. NULL,
  86. 0
  87. );
  88. if (NT_SUCCESS(Status)) {
  89. ZwClose(Handle);
  90. break;
  91. }
  92. }
  93. return -1;
  94. }
  95. ULONG
  96. RcCmdRepair(
  97. IN PTOKENIZED_LINE TokenizedLine
  98. )
  99. {
  100. ULONG i;
  101. PLINE_TOKEN Token;
  102. ULONG Flags = 0;
  103. BOOLEAN Rval;
  104. #ifdef _X86_
  105. ULONG RepairItems[RepairItemMax] = { 0, 0, 0};
  106. #else
  107. ULONG RepairItems[RepairItemMax] = { 0, 0};
  108. #endif
  109. PWSTR RepairPath;
  110. PDISK_REGION Region;
  111. PWSTR tmp;
  112. PWSTR PathtoERFiles = NULL;
  113. PWSTR ErDevicePath = NULL;
  114. PWSTR ErDirectory = NULL;
  115. PWSTR PathtoNTSourceFiles = NULL;
  116. PWSTR SrcDevicePath = NULL;
  117. PWSTR SrcDirectory = NULL;
  118. if (RcCmdParseHelp( TokenizedLine, MSG_REPAIR_HELP )) {
  119. return 1;
  120. }
  121. RcMessageOut(MSG_NYI);
  122. return 1;
  123. if (TokenizedLine->TokenCount == 1) {
  124. RcMessageOut(MSG_SYNTAX_ERROR);
  125. return 1;
  126. }
  127. //
  128. // process the command like tokens looking for the options
  129. //
  130. for (i=1,Token=TokenizedLine->Tokens->Next; i<TokenizedLine->TokenCount; i++) {
  131. if (Token->String[0] == L'/' || Token->String[0] == L'-') {
  132. if (_wcsicmp(&Token->String[1],L"NoConfirm") == 0) {
  133. Flags |= FLG_NO_CONFIRM;
  134. } else if (_wcsicmp(&Token->String[1],L"RepairStartup") == 0) {
  135. Flags |= FLG_STARTUP;
  136. } else if (_wcsicmp(&Token->String[1],L"Registry") == 0) {
  137. Flags |= FLG_REGISTRY;
  138. } else if (_wcsicmp(&Token->String[1],L"RepairFiles") == 0) {
  139. Flags |= FLG_FILES;
  140. }
  141. }
  142. }
  143. if (Flags == 0) {
  144. RcMessageOut(MSG_SYNTAX_ERROR);
  145. return 1;
  146. }
  147. if (TokenizedLine->Tokens->Next->String[0] != L'/') {
  148. PathtoERFiles = TokenizedLine->Tokens->Next->String;
  149. if (TokenizedLine->TokenCount > 2 && TokenizedLine->Tokens->Next->Next->String[0] != L'/') {
  150. PathtoNTSourceFiles = TokenizedLine->Tokens->Next->Next->String;
  151. }
  152. }
  153. if (Flags & FLG_NO_CONFIRM) {
  154. SpDrSetRepairFast( TRUE );
  155. } else {
  156. SpDrSetRepairFast( FALSE );
  157. }
  158. if (Flags & FLG_FILES) {
  159. RepairItems[RepairFiles] = 1;
  160. }
  161. if (Flags & FLG_STARTUP) {
  162. #ifdef _X86_
  163. RepairItems[RepairBootSect] = 1;
  164. #endif
  165. RepairItems[RepairNvram] = 1;
  166. }
  167. //
  168. // Get the path to the repair directory
  169. //
  170. if (PathtoERFiles == NULL) {
  171. if (InBatchMode) {
  172. RcMessageOut(MSG_SYNTAX_ERROR);
  173. return 1;
  174. }
  175. RcMessageOut( MSG_REPAIR_ERFILES_LOCATION );
  176. if (!RcLineIn(_CmdConsBlock->TemporaryBuffer,_CmdConsBlock->TemporaryBufferSize)) {
  177. return 1;
  178. }
  179. } else {
  180. wcscpy(_CmdConsBlock->TemporaryBuffer,PathtoERFiles);
  181. PathtoERFiles = NULL;
  182. }
  183. tmp = SpMemAlloc( MAX_PATH );
  184. if (tmp == NULL) {
  185. RcMessageOut(STATUS_NO_MEMORY);
  186. return 1;
  187. }
  188. if (!RcFormFullPath( _CmdConsBlock->TemporaryBuffer, tmp, FALSE )) {
  189. RcMessageOut(MSG_INVALID_PATH);
  190. SpMemFree(tmp);
  191. return 1;
  192. }
  193. Region = SpRegionFromDosName(tmp);
  194. if (Region == NULL) {
  195. SpMemFree(tmp);
  196. RcMessageOut(MSG_SYNTAX_ERROR);
  197. return 1;
  198. }
  199. ErDirectory = SpDupStringW( &tmp[2] );
  200. SpNtNameFromRegion( Region, tmp, MAX_PATH, PartitionOrdinalOnDisk );
  201. ErDevicePath = SpDupStringW( tmp );
  202. PathtoERFiles = SpMemAlloc( wcslen(ErDirectory) + wcslen(ErDevicePath) + 16 );
  203. wcscpy( PathtoERFiles, ErDevicePath );
  204. wcscat( PathtoERFiles, ErDirectory );
  205. SpMemFree(tmp);
  206. //
  207. // get the path to the nt source files, usually the cd
  208. //
  209. if (PathtoNTSourceFiles == NULL) {
  210. } else {
  211. }
  212. //
  213. // do the repair action(s)
  214. //
  215. /*
  216. Rval = SpDoRepair(
  217. _CmdConsBlock->SifHandle,
  218. _CmdConsBlock->BootDevicePath,
  219. _CmdConsBlock->DirectoryOnBootDevice,
  220. RepairPath,
  221. RepairItems
  222. );
  223. */
  224. return 1;
  225. }