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.

1201 lines
28 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 2000 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // WmiHelpers.cpp
  7. //
  8. // Description:
  9. // This file contains the implementation of WMI help functions.
  10. //
  11. // Documentation:
  12. //
  13. // Header File:
  14. // WmiHelpers.h
  15. //
  16. // Maintained By:
  17. // Galen Barbee (GalenB) 27-Apr-2000
  18. //
  19. //////////////////////////////////////////////////////////////////////////////
  20. //////////////////////////////////////////////////////////////////////////////
  21. // Include Files
  22. //////////////////////////////////////////////////////////////////////////////
  23. #include "pch.h"
  24. #include "PrivateInterfaces.h"
  25. #include "CEnumClusCfgNetworks.h"
  26. #include <WinIOCTL.h>
  27. //////////////////////////////////////////////////////////////////////////////
  28. // Constant Definitions
  29. //////////////////////////////////////////////////////////////////////////////
  30. const WCHAR g_szPhysicalDriveFormat [] = { L"\\\\.\\PHYSICALDRIVE%lu\0" };
  31. //////////////////////////////////////////////////////////////////////////////
  32. //++
  33. //
  34. // HrGetWMIProperty
  35. //
  36. // Description:
  37. // Get a named property from a WMI object.
  38. //
  39. // Arguments:
  40. //
  41. // Return Value:
  42. // S_OK
  43. // Success
  44. //
  45. // E_POINTER
  46. // The IWbemClassObject param is NULL.
  47. //
  48. // Remarks:
  49. // None.
  50. //
  51. //--
  52. //////////////////////////////////////////////////////////////////////////////
  53. HRESULT
  54. HrGetWMIProperty(
  55. IWbemClassObject * pWMIObjectIn,
  56. LPCWSTR pcszPropertyNameIn,
  57. ULONG ulPropertyTypeIn,
  58. VARIANT * pVariantOut
  59. )
  60. {
  61. TraceFunc1( "pcszPropertyNameIn = '%ws'", pcszPropertyNameIn );
  62. Assert( pWMIObjectIn != NULL );
  63. Assert( pcszPropertyNameIn != NULL );
  64. Assert( pVariantOut != NULL );
  65. HRESULT hr;
  66. BSTR bstrProp = NULL;
  67. VariantClear( pVariantOut );
  68. bstrProp = TraceSysAllocString( pcszPropertyNameIn );
  69. if ( bstrProp == NULL )
  70. {
  71. hr = THR( E_OUTOFMEMORY );
  72. goto Cleanup;
  73. } // if:
  74. hr = THR( pWMIObjectIn->Get( bstrProp, 0L, pVariantOut, NULL, NULL ) );
  75. if ( FAILED( hr ) )
  76. {
  77. LogMsg( L"[SRV] Could not get the value for WMI property '%ws'. (hr = %#08x)", bstrProp, hr );
  78. goto Cleanup;
  79. } // if:
  80. //
  81. // KB: 28-JUN-2000 GalenB
  82. //
  83. // For reasons only known to WMI boolean properties are of type VT_NULL instead of
  84. // VT_BOOL when they are not set or false...
  85. //
  86. // KB: 27-JUL-2000 GalenB
  87. //
  88. // Added the special case check for signature. We know that signature will be NULL
  89. // when the spindle is under ClusDisk control...
  90. //
  91. if ( ( ulPropertyTypeIn != VT_BOOL ) && ( _wcsicmp( bstrProp, L"Signature" ) != 0 ) )
  92. {
  93. if ( pVariantOut->vt != ulPropertyTypeIn )
  94. {
  95. LogMsg( L"[SRV] Variant type for WMI Property '%ws' was supposed to be '%d', but was '%d' instead.", pcszPropertyNameIn, ulPropertyTypeIn, pVariantOut->vt );
  96. hr = THR( E_PROPTYPEMISMATCH );
  97. } // if:
  98. } // if:
  99. Cleanup:
  100. TraceSysFreeString( bstrProp );
  101. HRETURN( hr );
  102. } //*** HrGetWMIProperty()
  103. //////////////////////////////////////////////////////////////////////////////
  104. //++
  105. //
  106. // HrSetWbemServices
  107. //
  108. // Description:
  109. // Set the WBemServices object into the passed in punk.
  110. //
  111. // Arguments:
  112. //
  113. // Return Value:
  114. // S_OK
  115. // Success
  116. //
  117. // E_POINTER
  118. // The IUnknown param is NULL.
  119. //
  120. // Remarks:
  121. // None.
  122. //
  123. //--
  124. //////////////////////////////////////////////////////////////////////////////
  125. HRESULT
  126. HrSetWbemServices( IUnknown * punkIn, IWbemServices * pIWbemServicesIn )
  127. {
  128. TraceFunc( "" );
  129. Assert( punkIn != NULL );
  130. HRESULT hr;
  131. IClusCfgWbemServices * pWbemProvider;
  132. if ( punkIn == NULL )
  133. {
  134. hr = THR( E_POINTER );
  135. goto Exit;
  136. } // if:
  137. hr = punkIn->TypeSafeQI( IClusCfgWbemServices, &pWbemProvider );
  138. if ( SUCCEEDED( hr ) )
  139. {
  140. hr = THR( pWbemProvider->SetWbemServices( pIWbemServicesIn ) );
  141. pWbemProvider->Release();
  142. } // if:
  143. else if ( hr == E_NOINTERFACE )
  144. {
  145. hr = S_OK;
  146. } // else if:
  147. else
  148. {
  149. THR( hr );
  150. }
  151. Exit:
  152. HRETURN( hr );
  153. } //*** HrSetWbemServices()
  154. //////////////////////////////////////////////////////////////////////////////
  155. //++
  156. //
  157. // HrSetInitialize
  158. //
  159. // Description:
  160. // Initialize the passed in punk.
  161. //
  162. // Arguments:
  163. //
  164. // Return Value:
  165. // S_OK
  166. // Success
  167. //
  168. // E_POINTER
  169. // The IUnknown param is NULL.
  170. //
  171. // Remarks:
  172. // None.
  173. //
  174. //--
  175. //////////////////////////////////////////////////////////////////////////////
  176. HRESULT
  177. HrSetInitialize(
  178. IUnknown * punkIn,
  179. IClusCfgCallback * picccIn,
  180. LCID lcidIn
  181. )
  182. {
  183. TraceFunc( "" );
  184. Assert( punkIn != NULL );
  185. HRESULT hr;
  186. IClusCfgInitialize * pcci;
  187. IUnknown * punkCallback = NULL;
  188. if ( punkIn == NULL )
  189. {
  190. hr = THR( E_POINTER );
  191. goto Cleanup;
  192. } // if:
  193. if ( picccIn != NULL )
  194. {
  195. hr = THR( picccIn->TypeSafeQI( IUnknown, &punkCallback ) );
  196. if ( FAILED( hr ) )
  197. {
  198. goto Cleanup;
  199. } // if:
  200. } // if:
  201. hr = THR( punkIn->TypeSafeQI( IClusCfgInitialize, &pcci ) );
  202. if ( SUCCEEDED( hr ) )
  203. {
  204. hr = STHR( pcci->Initialize( punkCallback, lcidIn ) );
  205. pcci->Release();
  206. } // if:
  207. else if ( hr == E_NOINTERFACE )
  208. {
  209. hr = S_OK;
  210. } // else if:
  211. Cleanup:
  212. if ( punkCallback != NULL )
  213. {
  214. punkCallback->Release();
  215. } // if:
  216. HRETURN( hr );
  217. } //*** HrSetInitialize()
  218. //////////////////////////////////////////////////////////////////////////////
  219. //++
  220. //
  221. // HrCreateNetworksEnum
  222. //
  223. // Description:
  224. // Create a network enumerator.
  225. //
  226. // Arguments:
  227. //
  228. // Return Value:
  229. // S_OK
  230. // Success
  231. //
  232. // E_POINTER
  233. // The IUnknown param is NULL.
  234. //
  235. // Remarks:
  236. // None.
  237. //
  238. //--
  239. //////////////////////////////////////////////////////////////////////////////
  240. HRESULT
  241. HrCreateNetworksEnum(
  242. IClusCfgCallback * picccIn,
  243. LCID lcidIn,
  244. IWbemServices * pIWbemServicesIn,
  245. IUnknown ** ppunkOut
  246. )
  247. {
  248. TraceFunc( "" );
  249. HRESULT hr;
  250. if ( ppunkOut == NULL )
  251. {
  252. hr = THR( E_POINTER );
  253. LogMsg( L"[SRV] HrCreateNetworksEnum() was given a NULL pointer argument." );
  254. goto Exit;
  255. } // if:
  256. hr = THR( CEnumClusCfgNetworks::S_HrCreateInstance( ppunkOut ) );
  257. if ( FAILED( hr ) )
  258. {
  259. goto Exit;
  260. } // if:
  261. *ppunkOut = TraceInterface( L"CEnumClusCfgNetworks", IUnknown, *ppunkOut, 1 );
  262. hr = THR( HrSetInitialize( *ppunkOut, picccIn, lcidIn ) );
  263. if ( FAILED( hr ) )
  264. {
  265. goto Exit;
  266. } // if:
  267. hr = THR( HrSetWbemServices( *ppunkOut, pIWbemServicesIn ) );
  268. if ( FAILED( hr ) )
  269. {
  270. goto Exit;
  271. } // if:
  272. Exit:
  273. HRETURN( hr );
  274. } //*** HrCreateNetworksEnum()
  275. /////////////////////////////////////////////////////////////////////////////
  276. //++
  277. //
  278. // HrLoadOperatingSystemInfo()
  279. //
  280. // Description:
  281. // Load the Win32_OperatingSystem object and determine which partition
  282. // were booted and have the OS installed on them.
  283. //
  284. // Arguments:
  285. // None.
  286. //
  287. // Return Value:
  288. // S_OK
  289. // Success.
  290. //
  291. // Win32 Error
  292. // something failed.
  293. //
  294. // Remarks:
  295. // None.
  296. //
  297. //--
  298. //////////////////////////////////////////////////////////////////////////////
  299. HRESULT
  300. HrLoadOperatingSystemInfo(
  301. IClusCfgCallback * picccIn,
  302. IWbemServices * pIWbemServicesIn,
  303. BSTR * pbstrBootDeviceOut,
  304. BSTR * pbstrSystemDeviceOut
  305. )
  306. {
  307. TraceFunc( "" );
  308. Assert( picccIn != NULL );
  309. Assert( pIWbemServicesIn != NULL );
  310. Assert( pbstrBootDeviceOut != NULL );
  311. Assert( pbstrSystemDeviceOut != NULL );
  312. HRESULT hr = S_OK;
  313. BSTR bstrClass;
  314. IEnumWbemClassObject * pOperatingSystems = NULL;
  315. ULONG ulReturned;
  316. IWbemClassObject * pOperatingSystem = NULL;
  317. int c;
  318. VARIANT var;
  319. HRESULT hrTemp;
  320. VariantInit( &var );
  321. bstrClass = TraceSysAllocString( L"Win32_OperatingSystem" );
  322. if ( bstrClass == NULL )
  323. {
  324. goto OutOfMemory;
  325. } // if:
  326. hr = THR( pIWbemServicesIn->CreateInstanceEnum( bstrClass, WBEM_FLAG_SHALLOW, NULL, &pOperatingSystems ) );
  327. if ( FAILED( hr ) )
  328. {
  329. hrTemp = THR( HrSendStatusReport(
  330. picccIn,
  331. TASKID_Major_Find_Devices,
  332. TASKID_Minor_WMI_OS_Qry_Failed,
  333. 0,
  334. 1,
  335. 1,
  336. hr,
  337. IDS_ERROR_WMI_OS_QRY_FAILED
  338. ) );
  339. if ( FAILED( hrTemp ) )
  340. {
  341. hr = hrTemp;
  342. } // if:
  343. goto Cleanup;
  344. } // if:
  345. for ( c = 1; ; c++ )
  346. {
  347. hr = pOperatingSystems->Next( WBEM_INFINITE, 1, &pOperatingSystem, &ulReturned );
  348. if ( ( hr == S_OK ) && ( ulReturned == 1 ) )
  349. {
  350. Assert( c < 2 ); // only expect one of these!
  351. hr = THR( HrGetWMIProperty( pOperatingSystem, L"BootDevice", VT_BSTR, &var ) );
  352. if ( FAILED( hr ) )
  353. {
  354. goto Cleanup;
  355. } // if:
  356. *pbstrBootDeviceOut = TraceSysAllocString( var.bstrVal );
  357. if ( *pbstrBootDeviceOut == NULL )
  358. {
  359. goto OutOfMemory;
  360. } // if:
  361. VariantClear( &var );
  362. hr = THR( HrGetWMIProperty( pOperatingSystem, L"SystemDevice", VT_BSTR, &var ) );
  363. if ( FAILED( hr ) )
  364. {
  365. goto Cleanup;
  366. } // if:
  367. *pbstrSystemDeviceOut = TraceSysAllocString( var.bstrVal );
  368. if ( *pbstrSystemDeviceOut == NULL )
  369. {
  370. goto OutOfMemory;
  371. } // if:
  372. pOperatingSystem->Release();
  373. pOperatingSystem = NULL;
  374. } // if:
  375. else if ( ( hr == S_FALSE ) && ( ulReturned == 0 ) )
  376. {
  377. hr = S_OK;
  378. break;
  379. } // else if:
  380. else
  381. {
  382. hrTemp = THR( HrSendStatusReport(
  383. picccIn,
  384. TASKID_Major_Find_Devices,
  385. TASKID_Minor_WMI_OS_Qry_Next_Failed,
  386. 0,
  387. 1,
  388. 1,
  389. hr,
  390. IDS_ERROR_WMI_OS_QRY_NEXT_FAILED
  391. ) );
  392. if ( FAILED( hrTemp ) )
  393. {
  394. hr = hrTemp;
  395. } // if:
  396. goto Cleanup;
  397. } // else:
  398. } // for:
  399. goto Cleanup;
  400. OutOfMemory:
  401. hr = THR( E_OUTOFMEMORY );
  402. Cleanup:
  403. VariantClear( &var );
  404. if ( pOperatingSystem != NULL )
  405. {
  406. pOperatingSystem->Release();
  407. } // if:
  408. if ( pOperatingSystems != NULL )
  409. {
  410. pOperatingSystems->Release();
  411. } // if:
  412. TraceSysFreeString( bstrClass );
  413. HRETURN( hr );
  414. } //*** HrLoadOperatingSystemInfo()
  415. /////////////////////////////////////////////////////////////////////////////
  416. //++
  417. //
  418. // HrConvertDeviceVolumeToLogicalDisk()
  419. //
  420. // Description:
  421. // Convert a device volume to a logical disk.
  422. //
  423. // Arguments:
  424. //
  425. //
  426. // Return Value:
  427. // S_OK
  428. // Success.
  429. //
  430. // Win32 Error
  431. // something failed.
  432. //
  433. // Remarks:
  434. // None.
  435. //
  436. //--
  437. //////////////////////////////////////////////////////////////////////////////
  438. HRESULT
  439. HrConvertDeviceVolumeToLogicalDisk(
  440. BSTR bstrDeviceVolumeIn,
  441. BSTR * pbstrLogicalDiskOut
  442. )
  443. {
  444. TraceFunc( "" );
  445. Assert( pbstrLogicalDiskOut != NULL );
  446. HRESULT hr = S_OK;
  447. BOOL fRet;
  448. size_t cchMountPoint;
  449. WCHAR * pszMountPoint = NULL;
  450. WCHAR szVolume[ MAX_PATH ];
  451. DWORD sc;
  452. DWORD cchPaths = 16;
  453. WCHAR * pszPaths = NULL;
  454. int c;
  455. DWORD cch;
  456. cchMountPoint = wcslen( g_szNameSpaceRoot ) + wcslen( bstrDeviceVolumeIn ) + 2;
  457. pszMountPoint = new WCHAR[ cchMountPoint ];
  458. if ( pszMountPoint == NULL )
  459. {
  460. goto OutOfMemory;
  461. } // if:
  462. wcscpy( pszMountPoint, g_szNameSpaceRoot );
  463. wcscat( pszMountPoint, bstrDeviceVolumeIn );
  464. wcscat( pszMountPoint, L"\\" );
  465. fRet = GetVolumeNameForVolumeMountPoint( pszMountPoint, szVolume, sizeof( szVolume ) );
  466. if ( !fRet )
  467. {
  468. sc = TW32( GetLastError() );
  469. hr = HRESULT_FROM_WIN32( sc );
  470. LogMsg( L"[SRV] GetVolumeNameForVolumeMountPoint() failed. Mount point is '%ws'. (hr = %#08x)", pszMountPoint, hr );
  471. //
  472. // GetVolumeNameForVolumeMountPoint() is no longer supported for IA64 EFI partitions. If the error is
  473. // ERROR_INVALID_FUNCTION then we should try to get the device number using an IOCTL.
  474. //
  475. if ( HRESULT_CODE( hr ) == ERROR_INVALID_FUNCTION )
  476. {
  477. LogMsg( L"[SRV] Device volume '%ws' must be an IA64 EFI volume.", bstrDeviceVolumeIn );
  478. } // if:
  479. goto Cleanup;
  480. } // if:
  481. pszPaths = new WCHAR[ cchPaths ];
  482. if ( pszPaths == NULL )
  483. {
  484. goto OutOfMemory;
  485. } // if:
  486. //
  487. // KB: 16 JAN 2001 GalenB
  488. //
  489. // Since the device name that is passed in is for a volume there will never be more than
  490. // one logical disk in the multisz pszPaths.
  491. //
  492. for ( c = 0; ; c++ )
  493. {
  494. Assert( c < 2 ); // expect to go through here no more than twice.
  495. fRet = GetVolumePathNamesForVolumeName( szVolume, pszPaths, cchPaths, &cch );
  496. if ( fRet )
  497. {
  498. break;
  499. } // if:
  500. else
  501. {
  502. sc = GetLastError();
  503. if ( sc == ERROR_MORE_DATA )
  504. {
  505. cchPaths = cch;
  506. delete [] pszPaths;
  507. pszPaths = new WCHAR[ cchPaths ];
  508. if ( pszPaths == NULL )
  509. {
  510. goto OutOfMemory;
  511. } // if:
  512. continue;
  513. } // if:
  514. hr = THR( HRESULT_FROM_WIN32( sc ) );
  515. LogMsg( L"[SRV] GetVolumePathNamesForVolumeName() failed. Volume is is '%ws'. (hr = %#08x)", szVolume, hr );
  516. goto Cleanup;
  517. } // else:
  518. } // for:
  519. *pbstrLogicalDiskOut = TraceSysAllocString( pszPaths );
  520. if ( *pbstrLogicalDiskOut == NULL )
  521. {
  522. goto OutOfMemory;
  523. } // if:
  524. goto Cleanup;
  525. OutOfMemory:
  526. hr = THR( E_OUTOFMEMORY );
  527. Cleanup:
  528. delete [] pszPaths;
  529. delete [] pszMountPoint;
  530. HRETURN( hr );
  531. } //*** HrConvertDeviceVolumeToLogicalDisk()
  532. /////////////////////////////////////////////////////////////////////////////
  533. //++
  534. //
  535. // HrConvertDeviceVolumeToWMIDeviceID()
  536. //
  537. // Description:
  538. // Since IA64 EFI partitions no longer support the call to
  539. // GetVolumeNameForVolumeMountPoint() to convert the device name
  540. // into a logical disk, since there will not longer be logical disks
  541. // for these partitions.
  542. //
  543. // Arguments:
  544. //
  545. //
  546. // Return Value:
  547. // S_OK
  548. // Success
  549. //
  550. // Remarks:
  551. // None.
  552. //
  553. //--
  554. //////////////////////////////////////////////////////////////////////////////
  555. HRESULT
  556. HrConvertDeviceVolumeToWMIDeviceID(
  557. BSTR bstrDeviceVolumeIn,
  558. BSTR * pbstrWMIDeviceIDOut
  559. )
  560. {
  561. TraceFunc( "" );
  562. HRESULT hr = S_OK;
  563. HANDLE hVolume = NULL;
  564. DWORD dwSize;
  565. DWORD sc;
  566. STORAGE_DEVICE_NUMBER sdnDevNumber;
  567. BOOL fRet;
  568. size_t cchDevice;
  569. WCHAR * pszDevice = NULL;
  570. WCHAR sz[ 64 ];
  571. cchDevice = wcslen( g_szNameSpaceRoot ) + wcslen( bstrDeviceVolumeIn ) + 2;
  572. pszDevice = new WCHAR[ cchDevice ];
  573. if ( pszDevice == NULL )
  574. {
  575. goto OutOfMemory;
  576. } // if:
  577. wcscpy( pszDevice, g_szNameSpaceRoot );
  578. wcscat( pszDevice, bstrDeviceVolumeIn );
  579. //
  580. // get handle to partition
  581. //
  582. hVolume = CreateFile(
  583. pszDevice
  584. , GENERIC_READ
  585. , FILE_SHARE_READ
  586. , NULL
  587. , OPEN_EXISTING
  588. , FILE_ATTRIBUTE_NORMAL
  589. , NULL
  590. );
  591. if ( hVolume == INVALID_HANDLE_VALUE )
  592. {
  593. sc = TW32( GetLastError() );
  594. hr = HRESULT_FROM_WIN32( sc );
  595. goto Cleanup;
  596. } // if:
  597. //
  598. // issue storage class ioctl to get drive and partition numbers
  599. // for this device
  600. //
  601. fRet = DeviceIoControl(
  602. hVolume
  603. , IOCTL_STORAGE_GET_DEVICE_NUMBER
  604. , NULL
  605. , 0
  606. , &sdnDevNumber
  607. , sizeof( sdnDevNumber )
  608. , &dwSize
  609. , NULL
  610. );
  611. if ( !fRet )
  612. {
  613. sc = TW32( GetLastError() );
  614. hr = HRESULT_FROM_WIN32( sc );
  615. goto Cleanup;
  616. } // if:
  617. _snwprintf( sz, ARRAYSIZE( sz ), g_szPhysicalDriveFormat, sdnDevNumber.DeviceNumber );
  618. *pbstrWMIDeviceIDOut = SysAllocString( sz );
  619. if ( *pbstrWMIDeviceIDOut == NULL )
  620. {
  621. goto OutOfMemory;
  622. } // if:
  623. goto Cleanup;
  624. OutOfMemory:
  625. hr = THR( E_OUTOFMEMORY );
  626. LogMsg( L"[SRV] HrConvertDeviceVolumeToWMIDeviceID() is out of memory. (hr = %#08x)", hr );
  627. Cleanup:
  628. if ( hVolume != NULL )
  629. {
  630. CloseHandle( hVolume );
  631. } // if:
  632. delete [] pszDevice;
  633. HRETURN( hr );
  634. } //*** HrConvertDeviceVolumeToWMIDeviceID()
  635. /////////////////////////////////////////////////////////////////////////////
  636. //++
  637. //
  638. // HrGetPageFileLogicalDisks()
  639. //
  640. // Description:
  641. // Mark the drives that have paging files on them.
  642. //
  643. // Arguments:
  644. //
  645. //
  646. // Return Value:
  647. // S_OK
  648. // Success.
  649. //
  650. // Remarks:
  651. // None.
  652. //
  653. //--
  654. //////////////////////////////////////////////////////////////////////////////
  655. HRESULT
  656. HrGetPageFileLogicalDisks(
  657. IClusCfgCallback * picccIn,
  658. IWbemServices * pIWbemServicesIn,
  659. WCHAR szLogicalDisksOut[ 26 ],
  660. int * pcLogicalDisksOut
  661. )
  662. {
  663. TraceFunc( "" );
  664. HRESULT hr = S_FALSE;
  665. IEnumWbemClassObject * pPagingFiles = NULL;
  666. BSTR bstrClass;
  667. ULONG ulReturned;
  668. IWbemClassObject * pPagingFile = NULL;
  669. VARIANT var;
  670. int idx;
  671. HRESULT hrTemp;
  672. bstrClass = TraceSysAllocString( L"Win32_PageFile" );
  673. if ( bstrClass == NULL )
  674. {
  675. hr = THR( E_OUTOFMEMORY );
  676. goto Cleanup;
  677. } // if:
  678. hr = THR( pIWbemServicesIn->CreateInstanceEnum( bstrClass, WBEM_FLAG_SHALLOW, NULL, &pPagingFiles ) );
  679. if ( FAILED( hr ) )
  680. {
  681. hrTemp = THR( HrSendStatusReport(
  682. picccIn,
  683. TASKID_Major_Find_Devices,
  684. TASKID_Minor_WMI_PageFile_Qry_Failed,
  685. 0,
  686. 1,
  687. 1,
  688. hr,
  689. IDS_ERROR_WMI_PAGEFILE_QRY_FAILED
  690. ) );
  691. if ( FAILED( hrTemp ) )
  692. {
  693. hr = hrTemp;
  694. } // if:
  695. goto Cleanup;
  696. } // if:
  697. VariantInit( &var );
  698. for ( idx = 0; idx < sizeof( szLogicalDisksOut ); idx++ )
  699. {
  700. hr = pPagingFiles->Next( WBEM_INFINITE, 1, &pPagingFile, &ulReturned );
  701. if ( ( hr == S_OK ) && ( ulReturned == 1 ) )
  702. {
  703. VariantClear( &var );
  704. hr = THR( HrGetWMIProperty( pPagingFile, L"Drive", VT_BSTR, &var ) );
  705. if ( FAILED( hr ) )
  706. {
  707. goto Cleanup;
  708. } // if:
  709. CharUpper( var.bstrVal );
  710. szLogicalDisksOut[ idx ] = var.bstrVal[ 0 ];
  711. pPagingFile->Release();
  712. pPagingFile = NULL;
  713. } // if:
  714. else if ( ( hr == S_FALSE ) && ( ulReturned == 0 ) )
  715. {
  716. hr = S_OK;
  717. break;
  718. } // else if:
  719. else
  720. {
  721. hrTemp = THR( HrSendStatusReport(
  722. picccIn,
  723. TASKID_Major_Find_Devices,
  724. TASKID_Minor_WMI_PageFile_Qry_Next_Failed,
  725. 0,
  726. 1,
  727. 1,
  728. hr,
  729. IDS_ERROR_WMI_PAGEFILE_QRY_NEXT_FAILED
  730. ) );
  731. if ( FAILED( hrTemp ) )
  732. {
  733. hr = hrTemp;
  734. } // if:
  735. goto Cleanup;
  736. } // else:
  737. } // for:
  738. if ( pcLogicalDisksOut != NULL )
  739. {
  740. *pcLogicalDisksOut = idx;
  741. } // if:
  742. Cleanup:
  743. VariantClear( &var );
  744. TraceSysFreeString( bstrClass );
  745. if ( pPagingFile != NULL )
  746. {
  747. pPagingFile->Release();
  748. } // if:
  749. if ( pPagingFiles != NULL )
  750. {
  751. pPagingFiles->Release();
  752. } // if:
  753. HRETURN( hr );
  754. } //*** HrGetPageFileLogicalDisks()
  755. /////////////////////////////////////////////////////////////////////////////
  756. //++
  757. //
  758. // HrGetSystemDevice()
  759. //
  760. // Description:
  761. // Returns the system (booted) device.
  762. //
  763. // Arguments:
  764. //
  765. //
  766. // Return Value:
  767. // None.
  768. //
  769. // Remarks:
  770. // None.
  771. //
  772. //--
  773. //////////////////////////////////////////////////////////////////////////////
  774. HRESULT
  775. HrGetSystemDevice( BSTR * pbstrSystemDeviceOut )
  776. {
  777. TraceFunc( "" );
  778. Assert( pbstrSystemDeviceOut != NULL );
  779. HRESULT hr = S_OK;
  780. DWORD sc;
  781. HKEY hKey = NULL;
  782. WCHAR * pszSystemDevice = NULL;
  783. DWORD cbSystemDevice = 0; // no need to but prefix complains #318170
  784. sc = TW32( RegOpenKeyEx( HKEY_LOCAL_MACHINE, L"System\\Setup", 0, KEY_READ, &hKey ) );
  785. if ( sc != ERROR_SUCCESS )
  786. {
  787. hr = HRESULT_FROM_WIN32( sc );
  788. LogMsg( L"[SRV] RegOpenKeyEx() failed. (hr = %#08x)", hr );
  789. goto Cleanup;
  790. } // if:
  791. sc = TW32( RegQueryValueEx( hKey, L"SystemPartition", NULL, NULL, NULL, &cbSystemDevice ) );
  792. if ( sc != ERROR_SUCCESS )
  793. {
  794. hr = HRESULT_FROM_WIN32( sc );
  795. LogMsg( L"[SRV] RegQueryValueEx() failed. (hr = %#08x)", hr );
  796. goto Cleanup;
  797. } // if:
  798. pszSystemDevice = new WCHAR[ cbSystemDevice / sizeof( WCHAR ) ];
  799. if ( pszSystemDevice == NULL )
  800. {
  801. goto OutOfMemory;
  802. } // if:
  803. sc = TW32( RegQueryValueEx( hKey, L"SystemPartition", NULL, NULL, (BYTE *) pszSystemDevice, &cbSystemDevice ) );
  804. if ( sc != ERROR_SUCCESS )
  805. {
  806. hr = HRESULT_FROM_WIN32( sc );
  807. LogMsg( L"[SRV] RegQueryValueEx() failed. (hr = %#08x)", hr );
  808. goto Cleanup;
  809. } // if:
  810. *pbstrSystemDeviceOut = TraceSysAllocString( pszSystemDevice );
  811. if ( *pbstrSystemDeviceOut == NULL )
  812. {
  813. goto OutOfMemory;
  814. } // if:
  815. goto Cleanup;
  816. OutOfMemory:
  817. hr = THR( E_OUTOFMEMORY );
  818. LogMsg( L"[SRV] HrGetSystemDevice() is out of memory. (hr = %#08x)", hr );
  819. Cleanup:
  820. delete [] pszSystemDevice;
  821. if ( hKey != NULL )
  822. {
  823. RegCloseKey( hKey );
  824. } // if:
  825. HRETURN( hr );
  826. } //*** HrGetSystemDevice()
  827. /////////////////////////////////////////////////////////////////////////////
  828. //++
  829. //
  830. // HrGetBootLogicalDisk()
  831. //
  832. // Description:
  833. // Returns the boot (system) logical disk.
  834. //
  835. // Arguments:
  836. //
  837. //
  838. // Return Value:
  839. // None.
  840. //
  841. // Remarks:
  842. // None.
  843. //
  844. //--
  845. //////////////////////////////////////////////////////////////////////////////
  846. HRESULT
  847. HrGetBootLogicalDisk( BSTR * pbstrBootLogicalDiskOut )
  848. {
  849. TraceFunc( "" );
  850. Assert( pbstrBootLogicalDiskOut != NULL );
  851. HRESULT hr = S_OK;
  852. DWORD sc;
  853. WCHAR szWindowsDir[ MAX_PATH ];
  854. WCHAR szVolume[ MAX_PATH ];
  855. BOOL fRet;
  856. sc = GetWindowsDirectory( szWindowsDir, ARRAYSIZE( szWindowsDir ) );
  857. if ( sc == 0 )
  858. {
  859. sc = TW32( GetLastError() );
  860. hr = HRESULT_FROM_WIN32( sc );
  861. LogMsg( L"[SRV] GetWindowsDirectory() failed. (hr = %#08x)", hr );
  862. goto Exit;
  863. } // if:
  864. fRet = GetVolumePathName( szWindowsDir, szVolume, ARRAYSIZE( szVolume ) );
  865. if ( !fRet )
  866. {
  867. sc = TW32( GetLastError() );
  868. hr = HRESULT_FROM_WIN32( sc );
  869. LogMsg( L"[SRV] GetVolumePathName() failed. (hr = %#08x)", hr );
  870. goto Exit;
  871. } // if:
  872. *pbstrBootLogicalDiskOut = TraceSysAllocString( szVolume );
  873. if ( *pbstrBootLogicalDiskOut == NULL )
  874. {
  875. hr = THR( E_OUTOFMEMORY );
  876. } // if:
  877. Exit:
  878. HRETURN( hr );
  879. } //*** HrGetBootLogicalDisk()
  880. /////////////////////////////////////////////////////////////////////////////
  881. //++
  882. //
  883. // HrCheckSecurity()
  884. //
  885. // Description:
  886. // Checks the server security level.
  887. //
  888. // Arguments:
  889. //
  890. //
  891. // Return Value:
  892. // S_OK
  893. // Secutity is high enough.
  894. //
  895. // E_ACCESSDENIED
  896. // Security is not high enough.
  897. //
  898. // Remarks:
  899. // None.
  900. //
  901. //--
  902. //////////////////////////////////////////////////////////////////////////////
  903. HRESULT
  904. HrCheckSecurity( void )
  905. {
  906. TraceFunc( "" );
  907. HRESULT hr = S_OK;
  908. IServerSecurity * piss = NULL;
  909. DWORD dwAuthnSvc;
  910. DWORD dwAuthzSvc;
  911. BSTR bstrServerPrincName = NULL;
  912. DWORD dwAuthnLevel;
  913. DWORD dwImpersonationLevel;
  914. void * pvPrivs = NULL;
  915. DWORD dwCapabilities;
  916. hr = THR( CoGetCallContext( IID_IServerSecurity, reinterpret_cast< void ** >( &piss ) ) );
  917. if ( FAILED( hr ) )
  918. {
  919. goto Cleanup;
  920. } // if:
  921. hr = THR( piss->QueryBlanket(
  922. &dwAuthnSvc,
  923. &dwAuthzSvc,
  924. &bstrServerPrincName,
  925. &dwAuthnLevel,
  926. &dwImpersonationLevel,
  927. &pvPrivs,
  928. &dwCapabilities ) );
  929. Cleanup:
  930. SysFreeString( bstrServerPrincName );
  931. if ( piss != NULL )
  932. {
  933. piss->Release();
  934. } // if:
  935. HRETURN( hr );
  936. } //*** HrCheckSecurity()
  937. /////////////////////////////////////////////////////////////////////////////
  938. //++
  939. //
  940. // TraceWMIProperties()
  941. //
  942. // Description:
  943. // Trace the properties to the debugger.
  944. //
  945. // Arguments:
  946. //
  947. //
  948. // Return Value:
  949. // None.
  950. //
  951. // Remarks:
  952. // None.
  953. //
  954. //--
  955. //////////////////////////////////////////////////////////////////////////////
  956. #ifdef DEBUG
  957. void
  958. TraceProperties( IWbemClassObject * pDiskIn )
  959. {
  960. TraceFunc( "" );
  961. HRESULT hr = S_FALSE;
  962. VARIANT var;
  963. BSTR bstrPropName;
  964. CIMTYPE cimType;
  965. LONG lFlags;
  966. VariantInit( &var );
  967. hr = THR( pDiskIn->BeginEnumeration( 0 ) );
  968. if ( FAILED( hr ) )
  969. {
  970. goto Exit;
  971. } // if:
  972. for ( ; ; )
  973. {
  974. VariantClear( &var );
  975. hr = pDiskIn->Next( 0, &bstrPropName, &var, &cimType, &lFlags );
  976. if ( FAILED( hr ) )
  977. {
  978. break;
  979. } // if:
  980. else if ( hr == S_OK )
  981. {
  982. if ( var.vt == VT_BSTR )
  983. {
  984. DebugMsg( L"Property %ws = %ws", bstrPropName, var.bstrVal );
  985. } // if:
  986. if ( var.vt == VT_I4 )
  987. {
  988. DebugMsg( L"Property %ws = %d", bstrPropName, var.iVal );
  989. } // if:
  990. if ( var.vt == VT_BOOL )
  991. {
  992. if ( var.boolVal == VARIANT_TRUE )
  993. {
  994. DebugMsg( L"Property %ws = True", bstrPropName );
  995. } // if:
  996. else
  997. {
  998. DebugMsg( L"Property %ws = False", bstrPropName );
  999. } // else:
  1000. } // if:
  1001. if ( var.vt == VT_NULL )
  1002. {
  1003. DebugMsg( L"Property %ws = NULL", bstrPropName );
  1004. } // if:
  1005. TraceSysFreeString( bstrPropName );
  1006. VariantClear( &var );
  1007. } // else if:
  1008. else
  1009. {
  1010. break;
  1011. } // else:
  1012. } // for:
  1013. Exit:
  1014. VariantClear( &var );
  1015. TraceFuncExit( );
  1016. } //*** TraceWMIProperties()
  1017. #endif