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.

431 lines
13 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1996-1998 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // incompat.cpp
  7. //
  8. // Abstract:
  9. // This file implements compatibility checking for various components.
  10. // The functions get executed by winnt32. It's purpose is to alert the user to possible
  11. // incompatibilities that may be encountered after performing an upgrade.
  12. //
  13. //
  14. // Author:
  15. // matt thomlinson (mattt)
  16. //
  17. // Notes:
  18. //
  19. /////////////////////////////////////////////////////////////////////////////
  20. #include "precomp.h"
  21. #pragma hdrstop
  22. HRESULT CertSrv_TestForIllegalUpgrade(BOOL *pfComplain);
  23. extern HINSTANCE hInst;
  24. /////////////////////////////////////////////////////////////////////////////
  25. //++
  26. //
  27. // CertificateServerUpgradeCompatibilityCheck
  28. //
  29. // Routine Description:
  30. // This is the exported function, called to check for incompatibilities when
  31. // upgrading the machine.
  32. //
  33. // Behavior: If Certificate server is installed on NT4, we wish to warn the user.
  34. //
  35. // Arguments:
  36. // pfnCompatibilityCallback - points to the callback function used to supply
  37. // compatibility information to winnt32.exe.
  38. // pvContext - points to a context buffer supplied by winnt32.exe.
  39. //
  40. //
  41. // Return Value:
  42. // TRUE - either indicates that no incompatibility was detected or that
  43. // *pfnComaptibilityCallback() returned TRUE.
  44. // FALSE - *pfnCompatibilityCallback() returned FALSE
  45. //
  46. //--
  47. /////////////////////////////////////////////////////////////////////////////
  48. BOOL CertificateServerUpgradeCompatibilityCheck( PCOMPAIBILITYCALLBACK pfnCompatibilityCallback,
  49. LPVOID pvContext )
  50. {
  51. BOOL fReturnValue = (BOOL) TRUE;
  52. BOOL fComplain;
  53. // Is this an illegal upgrade?
  54. if ((S_OK == CertSrv_TestForIllegalUpgrade(&fComplain)) &&
  55. fComplain)
  56. {
  57. // It is necessary to display a compatibility warning.
  58. TCHAR tszDescription[MAX_PATH]; // size is arbitrary
  59. COMPATIBILITY_ENTRY CompatibilityEntry;
  60. ZeroMemory( &CompatibilityEntry, sizeof( CompatibilityEntry ) );
  61. // Set the Description string.
  62. *tszDescription = TEXT( '\0' );
  63. LoadString( hInst,
  64. IDS_CERTSRV_UPGRADE_WARNING,
  65. tszDescription,
  66. ARRAYSIZE(tszDescription));
  67. // Build the COMPATIBILITY_ENTRY structure to pass to *pfnCompatibilityCallback().
  68. CompatibilityEntry.Description = tszDescription;
  69. // Set the HTML file name.
  70. CompatibilityEntry.HtmlName = TEXT( "compdata\\certsrv.htm" );
  71. // Set the TEXT file name.
  72. CompatibilityEntry.TextName = TEXT( "compdata\\certsrv.txt" );
  73. // Execute the callback function.
  74. fReturnValue = pfnCompatibilityCallback( (PCOMPATIBILITY_ENTRY) &CompatibilityEntry,
  75. pvContext );
  76. }
  77. else
  78. {
  79. // It is not necessary to display a compatibility warning.
  80. fReturnValue = (BOOL) TRUE;
  81. } // Is it necessary to display a compatibility warning?
  82. return ( fReturnValue );
  83. }
  84. HRESULT CertSrv_TestForIllegalUpgrade(BOOL *pfComplain)
  85. {
  86. HRESULT hr = S_OK;
  87. SC_HANDLE hSC=NULL, hSvc=NULL;
  88. OSVERSIONINFO osVer;
  89. // only complain about NT4 certsvr upgrades
  90. *pfComplain = FALSE;
  91. osVer.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
  92. if(! GetVersionEx(&osVer) )
  93. {
  94. // error getting version, can't be NT4
  95. hr = GetLastError();
  96. goto error;
  97. }
  98. if ((osVer.dwPlatformId != VER_PLATFORM_WIN32_NT) ||
  99. (osVer.dwMajorVersion != 4))
  100. {
  101. goto NoComplaint;
  102. // not NT4, must be ok
  103. }
  104. // now the hard part -- open the service to see if it exists
  105. hSC = OpenSCManager(NULL, SERVICES_ACTIVE_DATABASE, SC_MANAGER_CONNECT);
  106. if (hSC == NULL)
  107. {
  108. hr = GetLastError();
  109. goto error;
  110. }
  111. hSvc = OpenService(hSC, TEXT("CertSvc"), SERVICE_QUERY_CONFIG);
  112. if (hSvc == NULL)
  113. {
  114. hr = GetLastError();
  115. if (ERROR_SERVICE_DOES_NOT_EXIST == hr)
  116. goto NoComplaint;
  117. goto error;
  118. }
  119. // failed version check and service is installed
  120. *pfComplain = TRUE;
  121. NoComplaint:
  122. hr = S_OK;
  123. error:
  124. if (NULL != hSC)
  125. CloseServiceHandle(hSC);
  126. if (NULL != hSvc)
  127. CloseServiceHandle(hSvc);
  128. return hr;
  129. }
  130. BOOL
  131. IsStandardServerSKU(
  132. PBOOL pIsServer
  133. )
  134. /////////////////////////////////////////////////////////////////////////////
  135. //++
  136. //
  137. // IsStandardServerSKU
  138. //
  139. // Routine Description:
  140. // This routine determines if the user is running the standard server
  141. // SKU
  142. //
  143. //
  144. // Arguments:
  145. // pIsServer - indicates if the server is the standard server SKU
  146. // or not.
  147. //
  148. // Return Value:
  149. // Indicates success of the check
  150. //
  151. //--
  152. /////////////////////////////////////////////////////////////////////////////
  153. {
  154. BOOL fReturnValue = (BOOL) FALSE;
  155. OSVERSIONINFOEX VersionInfo;
  156. BOOL IsServer = FALSE;
  157. //
  158. // get the current SKU.
  159. //
  160. VersionInfo.dwOSVersionInfoSize = sizeof(VersionInfo);
  161. if (GetVersionEx((OSVERSIONINFO *)&VersionInfo)) {
  162. fReturnValue = TRUE;
  163. //
  164. // is it some sort of server SKU?
  165. //
  166. if (VersionInfo.wProductType != VER_NT_WORKSTATION) {
  167. //
  168. // standard server or a server variant?
  169. //
  170. if ((VersionInfo.wSuiteMask & (VER_SUITE_ENTERPRISE | VER_SUITE_DATACENTER)) == 0) {
  171. //
  172. // it's standard server
  173. //
  174. IsServer = TRUE;
  175. }
  176. }
  177. *pIsServer = IsServer;
  178. }
  179. return(fReturnValue);
  180. }
  181. #if 0
  182. /////////////////////////////////////////////////////////////////////////////
  183. //++
  184. //
  185. // ProcessorUpgradeCompatibilityCheck
  186. //
  187. // Routine Description:
  188. // This is the exported function, called to check for incompatibilities when
  189. // upgrading the machine.
  190. //
  191. // Behavior: If the current processor count is > that allowed after upgrade,
  192. // a warning is generated.
  193. //
  194. // Arguments:
  195. // pfnCompatibilityCallback - points to the callback function used to supply
  196. // compatibility information to winnt32.exe.
  197. // pvContext - points to a context buffer supplied by winnt32.exe.
  198. //
  199. //
  200. // Return Value:
  201. // TRUE - either indicates that no incompatibility was detected or that
  202. // *pfnComaptibilityCallback() returned TRUE.
  203. // FALSE - *pfnCompatibilityCallback() returned FALSE
  204. //
  205. //--
  206. /////////////////////////////////////////////////////////////////////////////
  207. BOOL ProcessorUpgradeCompatibilityCheck( PCOMPAIBILITYCALLBACK pfnCompatibilityCallback,
  208. LPVOID pvContext )
  209. {
  210. BOOL fReturnValue = (BOOL) TRUE;
  211. BOOL fComplain = FALSE;
  212. BOOL IsServer = FALSE;
  213. SYSTEM_INFO SysInfo;
  214. ULONG SourceSkuId;
  215. ULONG DontCare;
  216. //
  217. // we only care about standard server SKU.
  218. //
  219. SourceSkuId = DetermineSourceProduct(&DontCare,NULL);
  220. if ( SourceSkuId == COMPLIANCE_SKU_NTSFULL || SourceSkuId == COMPLIANCE_SKU_NTSU) {
  221. //
  222. // we only allow 2 processors on standard server.
  223. //
  224. DWORD AllowedCount = 2;
  225. GetSystemInfo(&SysInfo);
  226. if (SysInfo.dwNumberOfProcessors > AllowedCount) {
  227. fComplain = TRUE;
  228. }
  229. }
  230. // Is this an illegal upgrade?
  231. if (fComplain)
  232. {
  233. // It is necessary to display a compatibility warning.
  234. TCHAR tszDescription[MAX_PATH]; // size is arbitrary
  235. COMPATIBILITY_ENTRY CompatibilityEntry;
  236. ZeroMemory( &CompatibilityEntry, sizeof( CompatibilityEntry ) );
  237. // Set the Description string.
  238. *tszDescription = TEXT( '\0' );
  239. LoadString( hInst,
  240. IDS_PROCESSOR_UPGRADE_WARNING,
  241. tszDescription,
  242. ARRAYSIZE(tszDescription) );
  243. // Build the COMPATIBILITY_ENTRY structure to pass to *pfnCompatibilityCallback().
  244. CompatibilityEntry.Description = tszDescription;
  245. // Set the HTML file name.
  246. CompatibilityEntry.HtmlName = TEXT( "compdata\\proccnt.htm" );
  247. // Set the TEXT file name.
  248. CompatibilityEntry.TextName = TEXT( "compdata\\proccnt.txt" );
  249. // Execute the callback function.
  250. fReturnValue = pfnCompatibilityCallback( (PCOMPATIBILITY_ENTRY) &CompatibilityEntry,
  251. pvContext );
  252. }
  253. else
  254. {
  255. // It is not necessary to display a compatibility warning.
  256. fReturnValue = (BOOL) TRUE;
  257. } // Is it necessary to display a compatibility warning?
  258. return ( fReturnValue );
  259. }
  260. #endif
  261. /////////////////////////////////////////////////////////////////////////////
  262. //++
  263. //
  264. // IntelProcessorPteCheck
  265. //
  266. // Routine Description:
  267. // This is the exported function, called to check for Intel PTE Errata when
  268. // upgrading the machine.
  269. //
  270. // Behavior: This PTE errata (EFLAGS may be incorrect after a MP TLB
  271. // shootdown) exists on Pentium-Pro steppings upto 619 (errata 69)
  272. // and Pentium II steppings upto 634 (errata A27). If a MP
  273. // system has these processors, a warning is generated to
  274. // let user know that the system will be brought up
  275. // uni-processor after the install
  276. //
  277. // Arguments:
  278. // pfnCompatibilityCallback - points to the callback function used to supply
  279. // compatibility information to winnt32.exe.
  280. // pvContext - points to a context buffer supplied by winnt32.exe.
  281. //
  282. //
  283. // Return Value:
  284. // TRUE - either indicates that no processor with incompatibility was
  285. // detected or a processor with incompatibility was detected but
  286. // *pfnComaptibilityCallback() returned TRUE.
  287. // FALSE - *pfnCompatibilityCallback() returned FALSE
  288. //
  289. //--
  290. /////////////////////////////////////////////////////////////////////////////
  291. BOOL IntelProcessorPteCheck( PCOMPAIBILITYCALLBACK pfnCompatibilityCallback,
  292. LPVOID pvContext )
  293. {
  294. BOOL fReturnValue = (BOOL) TRUE;
  295. BOOL fComplain = FALSE;
  296. SYSTEM_INFO SysInfo;
  297. WORD ProcessorFamily;
  298. WORD ProcessorModel;
  299. WORD ProcessorStepping;
  300. //
  301. // If there are more than one Intel processors and processor steppings
  302. // with PTE errata are found, let user know about it
  303. //
  304. GetSystemInfo(&SysInfo);
  305. if ((SysInfo.dwNumberOfProcessors > 1) &&
  306. (SysInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL)) {
  307. //
  308. // Get Processor Family, Model and Stepping info
  309. //
  310. ProcessorFamily = SysInfo.wProcessorLevel;
  311. ProcessorModel = ((SysInfo.wProcessorRevision & 0xff00) >> 8);
  312. ProcessorStepping = SysInfo.wProcessorRevision & 0xff;
  313. if (ProcessorFamily == 6) {
  314. if ( ((ProcessorModel == 1) && (ProcessorStepping <= 9)) ||
  315. ((ProcessorModel == 3) && (ProcessorStepping <= 4)) ) {
  316. //
  317. // There is at least one processor on the system with errata
  318. //
  319. fComplain = TRUE;
  320. }
  321. }
  322. }
  323. // Is this an illegal upgrade?
  324. if (fComplain)
  325. {
  326. // It is necessary to display a compatibility warning.
  327. TCHAR tszDescription[MAX_PATH]; // size is arbitrary
  328. COMPATIBILITY_ENTRY CompatibilityEntry;
  329. ZeroMemory( &CompatibilityEntry, sizeof( CompatibilityEntry ) );
  330. // Set the Description string.
  331. *tszDescription = TEXT( '\0' );
  332. LoadString( hInst,
  333. IDS_INTEL_PROCESSOR_PTE_WARNING,
  334. tszDescription,
  335. ARRAYSIZE(tszDescription));
  336. // Build the COMPATIBILITY_ENTRY structure to pass to
  337. // *pfnCompatibilityCallback().
  338. CompatibilityEntry.Description = tszDescription;
  339. CompatibilityEntry.HtmlName = TEXT("compdata\\intelup.htm");
  340. CompatibilityEntry.TextName = TEXT("compdata\\intelup.txt");
  341. // Execute the callback function.
  342. fReturnValue = pfnCompatibilityCallback(
  343. (PCOMPATIBILITY_ENTRY) &CompatibilityEntry,
  344. pvContext
  345. );
  346. }
  347. else
  348. {
  349. // It is not necessary to display a compatibility warning.
  350. fReturnValue = (BOOL) TRUE;
  351. } // Is it necessary to display a compatibility warning?
  352. return ( fReturnValue );
  353. }