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.

162 lines
3.6 KiB

  1. #include "stdinc.h"
  2. #include "FusionBuffer.h"
  3. #include "Util.h"
  4. #include "FusionHandle.h"
  5. // NTRAID#NTBUG9 - 574025 - jonwis - 2002/04/25 - Initialize to NULL for safety
  6. HKEY s_hkeySystemSetup;
  7. #if DBG
  8. #if defined(__cplusplus)
  9. extern "C"
  10. {
  11. #endif
  12. BOOL g_fForceInOsSetupMode;
  13. BOOL g_fForceInMiniSetupMode;
  14. #if defined(__cplusplus)
  15. }
  16. #endif
  17. #endif
  18. BOOL
  19. WINAPI
  20. FusionpAreWeInOSSetupModeMain(
  21. HINSTANCE Module,
  22. DWORD Reason,
  23. PVOID Reserved
  24. )
  25. {
  26. FN_PROLOG_WIN32
  27. LONG lRegOp = 0;
  28. switch (Reason)
  29. {
  30. case DLL_PROCESS_ATTACH:
  31. {
  32. BOOL fOpenKeyFail = FALSE;
  33. IFREGFAILED_ORIGINATE_AND_EXIT_UNLESS2(
  34. ::RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"System\\Setup", 0, KEY_READ | FUSIONP_KEY_WOW64_64KEY, &s_hkeySystemSetup),
  35. LIST_3(ERROR_FILE_NOT_FOUND, ERROR_PATH_NOT_FOUND, ERROR_ACCESS_DENIED),
  36. fOpenKeyFail);
  37. }
  38. break;
  39. case DLL_PROCESS_DETACH:
  40. if (s_hkeySystemSetup != NULL)
  41. {
  42. if (Reserved == NULL)
  43. {
  44. if ((lRegOp = RegCloseKey(s_hkeySystemSetup)) != ERROR_SUCCESS)
  45. {
  46. ::FusionpSetLastWin32Error(lRegOp);
  47. TRACE_WIN32_FAILURE(RegCloseKey);
  48. // but eat the error
  49. }
  50. }
  51. s_hkeySystemSetup = NULL;
  52. }
  53. break;
  54. case DLL_THREAD_ATTACH:
  55. case DLL_THREAD_DETACH:
  56. break;
  57. }
  58. FN_EPILOG
  59. }
  60. BOOL
  61. FusionpAreWeInSpecifiedSetupMode(
  62. BOOL* pfIsInSetup,
  63. #if DBG
  64. BOOL* pfGlobalOverride,
  65. #endif
  66. PCWSTR pszValueName
  67. )
  68. {
  69. //
  70. // Queries to see if we're currently in OS-setup mode. This is required to avoid
  71. // some trickiness in the SFC protection system, where we don't want to validate
  72. // hashes and catalogs during setup. We just assume that whoever is installing us
  73. // is really a nice guy and won't muck up the assemblies.
  74. //
  75. FN_PROLOG_WIN32;
  76. DWORD dwType = 0;
  77. DWORD dwData = 0;
  78. DWORD cbData = sizeof(dwData);
  79. bool fRegFileNotFound;
  80. PARAMETER_CHECK(pfIsInSetup != NULL);
  81. if (s_hkeySystemSetup == NULL)
  82. {
  83. *pfIsInSetup = FALSE;
  84. FN_SUCCESSFUL_EXIT();
  85. }
  86. #if DBG
  87. if (*pfGlobalOverride)
  88. {
  89. *pfIsInSetup = TRUE;
  90. FN_SUCCESSFUL_EXIT();
  91. }
  92. #endif
  93. *pfIsInSetup = FALSE;
  94. cbData = sizeof(dwData);
  95. IFREGFAILED_ORIGINATE_AND_EXIT_UNLESS2(
  96. ::RegQueryValueExW(
  97. s_hkeySystemSetup,
  98. pszValueName,
  99. NULL,
  100. &dwType,
  101. reinterpret_cast<PBYTE>(&dwData),
  102. &cbData
  103. ),
  104. { ERROR_FILE_NOT_FOUND },
  105. fRegFileNotFound
  106. );
  107. if (fRegFileNotFound)
  108. {
  109. FN_SUCCESSFUL_EXIT();
  110. }
  111. if (dwType != REG_DWORD)
  112. {
  113. ORIGINATE_WIN32_FAILURE_AND_EXIT(RegQueryValueExW, ERROR_DATATYPE_MISMATCH);
  114. }
  115. if (dwData != 0)
  116. *pfIsInSetup = TRUE;
  117. FN_EPILOG;
  118. }
  119. BOOL
  120. FusionpAreWeInOSSetupMode(
  121. BOOL* pfIsInSetup
  122. )
  123. {
  124. return
  125. FusionpAreWeInSpecifiedSetupMode(
  126. pfIsInSetup,
  127. #if DBG
  128. &g_fForceInOsSetupMode,
  129. #endif
  130. L"SystemSetupInProgress"
  131. );
  132. }
  133. BOOL
  134. FusionpAreWeInMiniSetupMode(
  135. BOOL* pfIsInSetup
  136. )
  137. {
  138. return
  139. FusionpAreWeInSpecifiedSetupMode(
  140. pfIsInSetup,
  141. #if DBG
  142. &g_fForceInMiniSetupMode,
  143. #endif
  144. L"MiniSetupInProgress"
  145. );
  146. }