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.

172 lines
3.3 KiB

  1. #ifndef _WIN32_WINNT
  2. #define _WIN32_WINNT 0x0510
  3. #endif
  4. #ifndef WIN32_LEAN_AND_MEAN
  5. #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
  6. #endif
  7. #define SECURITY_WIN32
  8. #include <windows.h>
  9. #include <objbase.h>
  10. #include <atlbase.h>
  11. #include <Security.h>
  12. #include <wbemidl.h>
  13. #include <string.h>
  14. #include "globals.h"
  15. static HRESULT GetOSProductSuiteMask( LPCTSTR pszRemoteServer, UINT *pdwMask );
  16. HRESULT
  17. GetOSProductSuiteMask( LPCTSTR szRemoteServer, UINT *pdwMask )
  18. {
  19. HRESULT hr = S_OK;
  20. if( IsBadWritePtr( pdwMask, sizeof( UINT ) ) )
  21. {
  22. return E_INVALIDARG;
  23. }
  24. try
  25. {
  26. DWORD retCount = 0;
  27. TCHAR buf[ 512 ] = {0};
  28. LPCTSTR locatorPath = L"//%s/root/cimv2";
  29. CComBSTR objQry = L"SELECT * FROM Win32_OperatingSystem";
  30. CComPtr<IWbemClassObject> pWMIOS;
  31. CComPtr<IWbemServices> pWMISvc;
  32. CComPtr<IWbemLocator> pWMILocator;
  33. CComPtr<IEnumWbemClassObject> pWMIEnum;
  34. //
  35. // First, compose the locator string
  36. //
  37. if( szRemoteServer )
  38. {
  39. _stprintf( buf, locatorPath, szRemoteServer );
  40. }
  41. else
  42. {
  43. _stprintf( buf, locatorPath, _T(".") );
  44. }
  45. hr = pWMILocator.CoCreateInstance( CLSID_WbemLocator );
  46. if( FAILED(hr) )
  47. {
  48. throw hr;
  49. }
  50. BSTR bstrBuf = ::SysAllocString( buf );
  51. if( NULL == bstrBuf )
  52. {
  53. throw E_OUTOFMEMORY;
  54. }
  55. hr = pWMILocator->ConnectServer( bstrBuf, NULL, NULL, NULL,
  56. WBEM_FLAG_CONNECT_USE_MAX_WAIT,
  57. NULL, NULL, &pWMISvc );
  58. ::SysFreeString( bstrBuf );
  59. if( FAILED(hr) )
  60. {
  61. throw hr;
  62. }
  63. hr = CoSetProxyBlanket( pWMISvc,
  64. RPC_C_AUTHN_WINNT,
  65. RPC_C_AUTHZ_NONE,
  66. NULL,
  67. RPC_C_AUTHN_LEVEL_CALL,
  68. RPC_C_IMP_LEVEL_IMPERSONATE,
  69. NULL,
  70. EOAC_NONE );
  71. if( FAILED(hr) )
  72. {
  73. throw hr;
  74. }
  75. //
  76. // Now get the Win32_OperatingSystem instances and check the first one found
  77. //
  78. hr = pWMISvc->ExecQuery( CComBSTR( L"WQL" ), objQry,
  79. WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_ENSURE_LOCATABLE,
  80. NULL, &pWMIEnum );
  81. if( FAILED(hr) )
  82. {
  83. throw hr;
  84. }
  85. hr = pWMIEnum->Next( 60000, 1, &pWMIOS, &retCount );
  86. if( WBEM_S_NO_ERROR == hr )
  87. {
  88. VARIANT vt;
  89. CIMTYPE cimType;
  90. long flavor = 0;
  91. ZeroMemory( &vt, sizeof( vt ) );
  92. VariantInit( &vt );
  93. hr = pWMIOS->Get( L"SuiteMask", 0, &vt, &cimType, &flavor );
  94. if( FAILED( hr ) )
  95. {
  96. VariantClear( &vt );
  97. throw hr;
  98. }
  99. if( VT_NULL == vt.vt || VT_EMPTY == vt.vt )
  100. {
  101. VariantClear( &vt );
  102. throw E_FAIL;
  103. }
  104. hr = VariantChangeType( &vt, &vt, 0, VT_UINT );
  105. if( FAILED( hr ) )
  106. {
  107. VariantClear( &vt );
  108. throw hr;
  109. }
  110. *pdwMask = vt.uintVal;
  111. }
  112. }
  113. catch( HRESULT hrErr )
  114. {
  115. hr = hrErr;
  116. }
  117. catch(...)
  118. {
  119. hr = E_UNEXPECTED;
  120. }
  121. return hr;
  122. }
  123. HRESULT
  124. IsStandardServer( LPCTSTR szRemoteServer, BOOL *pbResult )
  125. {
  126. if( IsBadWritePtr( pbResult, sizeof( BOOL ) ) )
  127. {
  128. return E_INVALIDARG;
  129. }
  130. HRESULT hr = E_FAIL;
  131. UINT uSuiteMask = 0;
  132. hr = GetOSProductSuiteMask( szRemoteServer, &uSuiteMask );
  133. if( FAILED(hr) )
  134. {
  135. return hr;
  136. }
  137. if( ( uSuiteMask & VER_SUITE_DATACENTER ) || ( uSuiteMask & VER_SUITE_ENTERPRISE ) )
  138. {
  139. *pbResult = FALSE;
  140. }
  141. else
  142. {
  143. *pbResult = TRUE;
  144. }
  145. return S_OK;
  146. }