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.

331 lines
9.2 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. TCHAR tszHtmlName[MAX_PATH];
  60. TCHAR tszTextName[MAX_PATH];
  61. COMPATIBILITY_ENTRY CompatibilityEntry;
  62. ZeroMemory( &CompatibilityEntry, sizeof( CompatibilityEntry ) );
  63. // Set the Description string.
  64. *tszDescription = TEXT( '\0' );
  65. LoadString( hInst,
  66. IDS_CERTSRV_UPGRADE_WARNING,
  67. tszDescription,
  68. sizeof(tszDescription)/sizeof(tszDescription[0]) );
  69. // Set the HTML file name.
  70. _tcscpy( tszHtmlName, TEXT( "CompData\\certsrv.htm" ) );
  71. // Set the TEXT file name.
  72. _tcscpy( tszTextName, TEXT( "CompData\\certsrv.txt" ) );
  73. // Build the COMPATIBILITY_ENTRY structure to pass to *pfnCompatibilityCallback().
  74. CompatibilityEntry.Description = tszDescription;
  75. CompatibilityEntry.HtmlName = tszHtmlName;
  76. CompatibilityEntry.TextName = tszTextName;
  77. // Execute the callback function.
  78. fReturnValue = pfnCompatibilityCallback( (PCOMPATIBILITY_ENTRY) &CompatibilityEntry,
  79. pvContext );
  80. }
  81. else
  82. {
  83. // It is not necessary to display a compatibility warning.
  84. fReturnValue = (BOOL) TRUE;
  85. } // Is it necessary to display a compatibility warning?
  86. return ( fReturnValue );
  87. }
  88. HRESULT CertSrv_TestForIllegalUpgrade(BOOL *pfComplain)
  89. {
  90. HRESULT hr = S_OK;
  91. SC_HANDLE hSC=NULL, hSvc=NULL;
  92. OSVERSIONINFO osVer;
  93. // only complain about NT4 certsvr upgrades
  94. *pfComplain = FALSE;
  95. osVer.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
  96. if(! GetVersionEx(&osVer) )
  97. {
  98. // error getting version, can't be NT4
  99. hr = GetLastError();
  100. goto error;
  101. }
  102. if ((osVer.dwPlatformId != VER_PLATFORM_WIN32_NT) ||
  103. (osVer.dwMajorVersion != 4))
  104. {
  105. goto NoComplaint;
  106. // not NT4, must be ok
  107. }
  108. // now the hard part -- open the service to see if it exists
  109. hSC = OpenSCManager(NULL, SERVICES_ACTIVE_DATABASE, SC_MANAGER_CONNECT);
  110. if (hSC == NULL)
  111. {
  112. hr = GetLastError();
  113. goto error;
  114. }
  115. hSvc = OpenService(hSC, TEXT("CertSvc"), SERVICE_QUERY_CONFIG);
  116. if (hSvc == NULL)
  117. {
  118. hr = GetLastError();
  119. if (ERROR_SERVICE_DOES_NOT_EXIST == hr)
  120. goto NoComplaint;
  121. goto error;
  122. }
  123. // failed version check and service is installed
  124. *pfComplain = TRUE;
  125. NoComplaint:
  126. hr = S_OK;
  127. error:
  128. if (NULL != hSC)
  129. CloseServiceHandle(hSC);
  130. if (NULL != hSvc)
  131. CloseServiceHandle(hSvc);
  132. return hr;
  133. }
  134. BOOL
  135. IsStandardServerSKU(
  136. PBOOL pIsServer
  137. )
  138. /////////////////////////////////////////////////////////////////////////////
  139. //++
  140. //
  141. // IsStandardServerSKU
  142. //
  143. // Routine Description:
  144. // This routine determines if the user is running the standard server
  145. // SKU
  146. //
  147. //
  148. // Arguments:
  149. // pIsServer - indicates if the server is the standard server SKU
  150. // or not.
  151. //
  152. // Return Value:
  153. // Indicates success of the check
  154. //
  155. //--
  156. /////////////////////////////////////////////////////////////////////////////
  157. {
  158. BOOL fReturnValue = (BOOL) FALSE;
  159. OSVERSIONINFOEX VersionInfo;
  160. BOOL IsServer = FALSE;
  161. //
  162. // get the current SKU.
  163. //
  164. VersionInfo.dwOSVersionInfoSize = sizeof(VersionInfo);
  165. if (GetVersionEx((OSVERSIONINFO *)&VersionInfo)) {
  166. fReturnValue = TRUE;
  167. //
  168. // is it some sort of server SKU?
  169. //
  170. if (VersionInfo.wProductType != VER_NT_WORKSTATION) {
  171. //
  172. // standard server or a server variant?
  173. //
  174. if ((VersionInfo.wSuiteMask & (VER_SUITE_ENTERPRISE | VER_SUITE_DATACENTER)) == 0) {
  175. //
  176. // it's standard server
  177. //
  178. IsServer = TRUE;
  179. }
  180. }
  181. *pIsServer = IsServer;
  182. }
  183. return(fReturnValue);
  184. }
  185. /////////////////////////////////////////////////////////////////////////////
  186. //++
  187. //
  188. // ProcessorUpgradeCompatibilityCheck
  189. //
  190. // Routine Description:
  191. // This is the exported function, called to check for incompatibilities when
  192. // upgrading the machine.
  193. //
  194. // Behavior: If the current processor count is > that allowed after upgrade,
  195. // a warning is generated.
  196. //
  197. // Arguments:
  198. // pfnCompatibilityCallback - points to the callback function used to supply
  199. // compatibility information to winnt32.exe.
  200. // pvContext - points to a context buffer supplied by winnt32.exe.
  201. //
  202. //
  203. // Return Value:
  204. // TRUE - either indicates that no incompatibility was detected or that
  205. // *pfnComaptibilityCallback() returned TRUE.
  206. // FALSE - *pfnCompatibilityCallback() returned FALSE
  207. //
  208. //--
  209. /////////////////////////////////////////////////////////////////////////////
  210. BOOL ProcessorUpgradeCompatibilityCheck( PCOMPAIBILITYCALLBACK pfnCompatibilityCallback,
  211. LPVOID pvContext )
  212. {
  213. BOOL fReturnValue = (BOOL) TRUE;
  214. BOOL fComplain = FALSE;
  215. BOOL IsServer = FALSE;
  216. SYSTEM_INFO SysInfo;
  217. ULONG SourceSkuId;
  218. ULONG DontCare;
  219. //
  220. // we only care about standard server SKU.
  221. //
  222. SourceSkuId = DetermineSourceProduct(&DontCare,NULL);
  223. if ( SourceSkuId == COMPLIANCE_SKU_NTSFULL || SourceSkuId == COMPLIANCE_SKU_NTSU) {
  224. //
  225. // we only allow 2 processors on standard server.
  226. //
  227. DWORD AllowedCount = 2;
  228. GetSystemInfo(&SysInfo);
  229. if (SysInfo.dwNumberOfProcessors > AllowedCount) {
  230. fComplain = TRUE;
  231. }
  232. }
  233. // Is this an illegal upgrade?
  234. if (fComplain)
  235. {
  236. // It is necessary to display a compatibility warning.
  237. TCHAR tszDescription[MAX_PATH]; // size is arbitrary
  238. TCHAR tszHtmlName[MAX_PATH];
  239. TCHAR tszTextName[MAX_PATH];
  240. COMPATIBILITY_ENTRY CompatibilityEntry;
  241. ZeroMemory( &CompatibilityEntry, sizeof( CompatibilityEntry ) );
  242. // Set the Description string.
  243. *tszDescription = TEXT( '\0' );
  244. LoadString( hInst,
  245. IDS_PROCESSOR_UPGRADE_WARNING,
  246. tszDescription,
  247. sizeof(tszDescription)/sizeof(tszDescription[0]) );
  248. // Set the HTML file name.
  249. _tcscpy( tszHtmlName, TEXT( "CompData\\proccnt.htm" ) );
  250. // Set the TEXT file name.
  251. _tcscpy( tszTextName, TEXT( "CompData\\proccnt.txt" ) );
  252. // Build the COMPATIBILITY_ENTRY structure to pass to *pfnCompatibilityCallback().
  253. CompatibilityEntry.Description = tszDescription;
  254. CompatibilityEntry.HtmlName = tszHtmlName;
  255. CompatibilityEntry.TextName = tszTextName;
  256. // Execute the callback function.
  257. fReturnValue = pfnCompatibilityCallback( (PCOMPATIBILITY_ENTRY) &CompatibilityEntry,
  258. pvContext );
  259. }
  260. else
  261. {
  262. // It is not necessary to display a compatibility warning.
  263. fReturnValue = (BOOL) TRUE;
  264. } // Is it necessary to display a compatibility warning?
  265. return ( fReturnValue );
  266. }