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.

846 lines
22 KiB

  1. /******************************************************************
  2. QuotaSettings.CPP -- WMI provider class implementation
  3. Description: Quota Settings class implementation. Quota settings
  4. are available only on those volumes that support
  5. Disk Quotas. It is supported only on Win2k.
  6. Copyright (c) 2000-2001 Microsoft Corporation, All Rights Reserved
  7. ******************************************************************/
  8. #include "precomp.h"
  9. #include "QuotaSettings.h"
  10. CQuotaSettings MyQuotaSettings (
  11. IDS_DiskVolumeClass ,
  12. NameSpace
  13. ) ;
  14. /*****************************************************************************
  15. *
  16. * FUNCTION : CQuotaSettings::CQuotaSettings
  17. *
  18. * DESCRIPTION : Constructor
  19. *
  20. * COMMENTS : Calls the Provider constructor.
  21. *
  22. *****************************************************************************/
  23. CQuotaSettings :: CQuotaSettings (
  24. LPCWSTR lpwszName,
  25. LPCWSTR lpwszNameSpace
  26. ) : Provider ( lpwszName , lpwszNameSpace )
  27. {
  28. }
  29. /*****************************************************************************
  30. *
  31. * FUNCTION : CQuotaSettings::~CQuotaSettings
  32. *
  33. * DESCRIPTION : Destructor
  34. *
  35. * COMMENTS :
  36. *
  37. *****************************************************************************/
  38. CQuotaSettings :: ~CQuotaSettings ()
  39. {
  40. }
  41. /*****************************************************************************
  42. *
  43. * FUNCTION : CQuotaSettings::EnumerateInstances
  44. *
  45. * DESCRIPTION : Returns all the instances of this class.
  46. *
  47. *****************************************************************************/
  48. HRESULT CQuotaSettings :: EnumerateInstances (
  49. MethodContext *pMethodContext,
  50. long lFlags
  51. )
  52. {
  53. HRESULT hRes = WBEM_S_NO_ERROR;
  54. DWORD dwPropertiesReq;
  55. dwPropertiesReq = QUOTASETTINGS_ALL_PROPS;
  56. // This method enumerates all volumes on the
  57. hRes = EnumerateAllVolumes ( pMethodContext, dwPropertiesReq );
  58. return hRes;
  59. }
  60. /*****************************************************************************
  61. *
  62. * FUNCTION : CQuotaSettings::GetObject
  63. *
  64. * DESCRIPTION : Find a single instance based on the key properties for the
  65. * class.
  66. *
  67. *****************************************************************************/
  68. HRESULT CQuotaSettings :: GetObject (
  69. CInstance *pInstance,
  70. long lFlags ,
  71. CFrameworkQuery &Query
  72. )
  73. {
  74. HRESULT hRes = WBEM_S_NO_ERROR;
  75. CHString t_Key ; // VolumePath;
  76. if ( pInstance->GetCHString ( IDS_VolumePath , t_Key ) == FALSE )
  77. {
  78. hRes = WBEM_E_FAILED ;
  79. }
  80. if ( SUCCEEDED ( hRes ) )
  81. {
  82. // verify this logical drives actually exists
  83. CHString t_DriveStrings1;
  84. CHString t_DriveStrings2;
  85. LPWSTR lpDriveStrings = t_DriveStrings1.GetBuffer ( MAX_PATH + 1 );
  86. DWORD dwDLength = GetLogicalDriveStrings ( MAX_PATH, lpDriveStrings );
  87. if ( dwDLength > MAX_PATH )
  88. {
  89. lpDriveStrings = t_DriveStrings2.GetBuffer ( dwDLength + 1 );
  90. dwDLength = GetLogicalDriveStrings ( dwDLength, lpDriveStrings );
  91. }
  92. hRes = m_CommonRoutine.SearchLogicalDisk ( t_Key.GetAt ( 0 ) , lpDriveStrings );
  93. if ( hRes == WBEM_E_NOT_FOUND)
  94. {
  95. //
  96. // I need to assume that VolumePath property already contains
  97. // volume path rather than logical disk drive
  98. //
  99. CHString t_VolumeName;
  100. hRes = m_CommonRoutine.VolumeSupportsDiskQuota ( t_Key, t_VolumeName );
  101. if ( SUCCEEDED ( hRes ) )
  102. {
  103. DWORD dwPropertiesReq;
  104. if ( Query.AllPropertiesAreRequired() )
  105. {
  106. dwPropertiesReq = QUOTASETTINGS_ALL_PROPS;
  107. }
  108. else
  109. {
  110. SetRequiredProperties ( &Query, dwPropertiesReq );
  111. }
  112. // put the instance with the requested properties only as in Query.
  113. // Get the Properties of the requested volume
  114. hRes = LoadDiskQuotaVolumeProperties ( t_Key, L"", dwPropertiesReq, pInstance );
  115. }
  116. }
  117. else
  118. {
  119. if ( SUCCEEDED ( hRes ) )
  120. {
  121. WCHAR t_VolumePathName[MAX_PATH + 1];
  122. if ( GetVolumeNameForVolumeMountPoint(
  123. t_Key,
  124. t_VolumePathName,
  125. MAX_PATH
  126. ) )
  127. {
  128. CHString t_VolumeName;
  129. hRes = m_CommonRoutine.VolumeSupportsDiskQuota ( t_VolumePathName, t_VolumeName );
  130. {
  131. DWORD dwPropertiesReq;
  132. if ( Query.AllPropertiesAreRequired() )
  133. {
  134. dwPropertiesReq = QUOTASETTINGS_ALL_PROPS;
  135. }
  136. else
  137. {
  138. SetRequiredProperties ( &Query, dwPropertiesReq );
  139. }
  140. // put the instance with the requested properties only as in Query.
  141. // Get the Properties of the requested volume
  142. hRes = LoadDiskQuotaVolumeProperties ( t_VolumePathName, t_Key, dwPropertiesReq, pInstance );
  143. }
  144. }
  145. }
  146. }
  147. }
  148. return hRes;
  149. }
  150. /*****************************************************************************
  151. *
  152. * FUNCTION : CQuotaSettings::ExecQuery
  153. *
  154. * DESCRIPTION : Optimization of Queries involving only the key attribute
  155. * is supported.
  156. *
  157. *****************************************************************************/
  158. HRESULT CQuotaSettings :: ExecQuery (
  159. MethodContext *pMethodContext,
  160. CFrameworkQuery &Query,
  161. long lFlags
  162. )
  163. {
  164. HRESULT hRes = WBEM_S_NO_ERROR;
  165. DWORD dwPropertiesReq;
  166. CHStringArray t_Values;
  167. hRes = Query.GetValuesForProp(
  168. IDS_VolumePath,
  169. t_Values
  170. );
  171. if ( t_Values.GetSize() == 0 )
  172. {
  173. hRes = Query.GetValuesForProp(
  174. IDS_Caption,
  175. t_Values
  176. );
  177. if (SUCCEEDED(hRes))
  178. {
  179. DWORD dwSize = t_Values.GetSize();
  180. for (DWORD x = 0; x < dwSize; x++)
  181. {
  182. t_Values[x] += L'\\';
  183. }
  184. }
  185. }
  186. if ( Query.AllPropertiesAreRequired() )
  187. {
  188. dwPropertiesReq = QUOTASETTINGS_ALL_PROPS;
  189. }
  190. else
  191. {
  192. SetRequiredProperties ( &Query, dwPropertiesReq );
  193. }
  194. if ( SUCCEEDED ( hRes ) )
  195. {
  196. if ( t_Values.GetSize() == 0 )
  197. {
  198. // This method is called when there is no where clause just to filter
  199. // the required properties
  200. hRes = EnumerateAllVolumes ( pMethodContext, dwPropertiesReq );
  201. }
  202. else
  203. {
  204. // Only Volume in VolumePath properties are needed to be enumerated
  205. WCHAR t_VolumePathName[MAX_PATH + 1];
  206. CHString t_VolumeName;
  207. int iSize = t_Values.GetSize ();
  208. for ( int i = 0; i < iSize; i++ )
  209. {
  210. if ( GetVolumeNameForVolumeMountPoint(
  211. t_Values[i],
  212. t_VolumePathName,
  213. MAX_PATH ) )
  214. {
  215. hRes = m_CommonRoutine.VolumeSupportsDiskQuota ( t_VolumePathName, t_VolumeName );
  216. if ( SUCCEEDED ( hRes ) )
  217. {
  218. // Get and Set the Properties of the requested volume
  219. hRes = PutVolumeDetails ( t_VolumePathName,
  220. pMethodContext,
  221. dwPropertiesReq );
  222. }
  223. }
  224. }
  225. }
  226. }
  227. return hRes;
  228. }
  229. /*****************************************************************************
  230. *
  231. * FUNCTION : CQuotaSettings::PutInstance
  232. *
  233. * DESCRIPTION : PutInstance should be used in provider classes that can
  234. * write instance information back to the hardware or
  235. * software. For example: Win32_Environment will allow a
  236. * PutInstance to create or update an environment variable.
  237. * However, a class like MotherboardDevice will not allow
  238. * editing of the number of slots, since it is difficult for
  239. * a provider to affect that number.
  240. *
  241. *****************************************************************************/
  242. HRESULT CQuotaSettings :: PutInstance (
  243. const CInstance &Instance,
  244. long lFlags
  245. )
  246. {
  247. HRESULT hRes = WBEM_S_NO_ERROR ;
  248. CHString t_Key;
  249. if ( Instance.GetCHString ( IDS_VolumePath , t_Key ) == FALSE )
  250. {
  251. hRes = WBEM_E_INVALID_PARAMETER;
  252. }
  253. if ( SUCCEEDED ( hRes ) )
  254. {
  255. WCHAR t_VolumePathName[MAX_PATH + 1];
  256. if ( GetVolumeNameForVolumeMountPoint(
  257. t_Key,
  258. t_VolumePathName,
  259. MAX_PATH ) )
  260. {
  261. // Only changing certain properties of volumes is allowed and not adding a new DIskQuota Volume.
  262. // Hence creating a new instance is not supported, but changing instance properties is supported.
  263. switch ( lFlags & 3)
  264. {
  265. case WBEM_FLAG_CREATE_OR_UPDATE:
  266. case WBEM_FLAG_UPDATE_ONLY:
  267. {
  268. hRes = CheckParameters ( Instance);
  269. if ( SUCCEEDED ( hRes ) )
  270. {
  271. CHString t_VolumePathName2;
  272. hRes = m_CommonRoutine.VolumeSupportsDiskQuota ( t_Key, t_VolumePathName2 );
  273. if ( SUCCEEDED ( hRes ) )
  274. {
  275. // Get the QuotaInterface Pointer
  276. IDiskQuotaControlPtr pIQuotaControl = NULL;
  277. if ( SUCCEEDED ( CoCreateInstance(
  278. CLSID_DiskQuotaControl,
  279. NULL,
  280. CLSCTX_INPROC_SERVER,
  281. IID_IDiskQuotaControl,
  282. (void **)&pIQuotaControl ) ) )
  283. {
  284. hRes = m_CommonRoutine.InitializeInterfacePointer ( pIQuotaControl, t_Key );
  285. if ( SUCCEEDED ( hRes ) )
  286. {
  287. hRes = SetDiskQuotaVolumeProperties ( Instance, pIQuotaControl );
  288. }
  289. }
  290. else
  291. {
  292. hRes = WBEM_E_FAILED;
  293. }
  294. }
  295. }
  296. break ;
  297. }
  298. default:
  299. {
  300. hRes = WBEM_E_PROVIDER_NOT_CAPABLE ;
  301. }
  302. break ;
  303. }
  304. }
  305. else
  306. {
  307. hRes = WBEM_E_NOT_FOUND;
  308. }
  309. }
  310. return hRes ;
  311. }
  312. /*****************************************************************************
  313. *
  314. * FUNCTION : CQuotaSettings:: EnumerateAllVolumes
  315. *
  316. * DESCRIPTION : This method Enumerates all the volumes by making use of Disk
  317. * Quotas Interfaces, gets all the required properties and deliveres
  318. * the instances to WMI, which will be postfiltered by WMI
  319. *
  320. *****************************************************************************/
  321. HRESULT CQuotaSettings :: EnumerateAllVolumes (
  322. MethodContext *pMethodContext,
  323. DWORD &a_PropertiesReq
  324. )
  325. {
  326. HRESULT hRes = WBEM_S_NO_ERROR;
  327. BOOL bNextVol = TRUE;
  328. WCHAR t_VolumeName[MAX_PATH + 1];
  329. // Initializing and getting the first volume on the computer
  330. SmartCloseVolumeHandle hVol;
  331. hVol = FindFirstVolume(
  332. t_VolumeName,
  333. MAX_PATH // size of output buffer
  334. );
  335. if ( hVol != INVALID_HANDLE_VALUE )
  336. {
  337. while ( bNextVol )
  338. {
  339. hRes = PutVolumeDetails ( t_VolumeName, pMethodContext, a_PropertiesReq );
  340. // Continue for next volume, even if the retval for this volume is false;
  341. bNextVol = FindNextVolume(
  342. hVol, // volume search handle
  343. t_VolumeName, // output buffer
  344. MAX_PATH // size of output buffer
  345. );
  346. if ( bNextVol == FALSE )
  347. break;
  348. }
  349. }
  350. else
  351. hRes = WBEM_E_FAILED;
  352. return hRes;
  353. }
  354. /*****************************************************************************
  355. *
  356. * FUNCTION : CQuotaSettings:: LoadDiskQuotaVolumeProperties
  357. *
  358. * DESCRIPTION : This method checks if the volume enumerated supports Disk Quotas
  359. * If the Volume Supposrts DIskQuotas, it fills up all the properties
  360. * of the volume and returns otherwise it just returns FALSE
  361. * indicating properties of this volume were not filled. and hence
  362. * intsnace should not be delivered to WMI
  363. *
  364. *****************************************************************************/
  365. HRESULT CQuotaSettings :: LoadDiskQuotaVolumeProperties (
  366. LPCWSTR a_VolumeName,
  367. LPCWSTR a_Caption,
  368. DWORD dwPropertiesReq,
  369. CInstancePtr pInstance
  370. )
  371. {
  372. HRESULT hRes = WBEM_S_NO_ERROR;
  373. DWORD dwLogFlags;
  374. DWORD dwQuotaState;
  375. CHString t_Temp;
  376. // checks to see if the volume supports Disk Quotas
  377. hRes = m_CommonRoutine.VolumeSupportsDiskQuota ( a_VolumeName, t_Temp );
  378. if ( SUCCEEDED ( hRes ) )
  379. {
  380. if ( ( dwPropertiesReq & QUOTASETTINGS_PROP_Caption ) )
  381. {
  382. t_Temp = a_Caption;
  383. pInstance->SetCHString(IDS_Caption, t_Temp.Left(2));
  384. }
  385. IDiskQuotaControlPtr pIQuotaControl;
  386. if ( SUCCEEDED ( CoCreateInstance(
  387. CLSID_DiskQuotaControl,
  388. NULL,
  389. CLSCTX_INPROC_SERVER,
  390. IID_IDiskQuotaControl,
  391. (void **)&pIQuotaControl ) ) )
  392. {
  393. // Initializing the QuotaCOntrol Interface pointer for this Volume
  394. hRes = m_CommonRoutine.InitializeInterfacePointer ( pIQuotaControl, a_VolumeName );
  395. if ( SUCCEEDED ( hRes ) )
  396. {
  397. // Get all the Volume Properties
  398. LONGLONG lQuotaLimit = 0;
  399. if ( ( dwPropertiesReq & QUOTASETTINGS_PROP_DefaultLimit ) )
  400. {
  401. if ( SUCCEEDED ( pIQuotaControl->GetDefaultQuotaLimit( &lQuotaLimit ) ) )
  402. {
  403. if ( pInstance->SetWBEMINT64 ( IDS_QuotasDefaultLimit, (ULONGLONG)lQuotaLimit ) == FALSE )
  404. {
  405. hRes = WBEM_E_FAILED;
  406. }
  407. }
  408. else
  409. {
  410. hRes = WBEM_E_FAILED;
  411. }
  412. }
  413. if ( ( dwPropertiesReq & QUOTASETTINGS_PROP_DefaultWarningLimit ) )
  414. {
  415. if ( SUCCEEDED ( pIQuotaControl->GetDefaultQuotaThreshold ( &lQuotaLimit ) ) )
  416. {
  417. if ( pInstance->SetWBEMINT64 ( IDS_QuotasDefaultWarningLimit, (ULONGLONG)lQuotaLimit ) == FALSE )
  418. {
  419. hRes = WBEM_E_FAILED;
  420. }
  421. }
  422. else
  423. {
  424. hRes = WBEM_E_FAILED;
  425. }
  426. }
  427. if ( ( ( dwPropertiesReq & QUOTASETTINGS_PROP_QuotaExceededNotification ) )
  428. || ( ( dwPropertiesReq & QUOTASETTINGS_PROP_WarningExceededNotification ) ) )
  429. {
  430. if ( SUCCEEDED ( pIQuotaControl->GetQuotaLogFlags( &dwLogFlags ) ) )
  431. {
  432. if ( ( dwPropertiesReq & QUOTASETTINGS_PROP_QuotaExceededNotification ) )
  433. {
  434. if ( pInstance->Setbool ( IDS_QuotaExceededNotification, DISKQUOTA_IS_LOGGED_USER_LIMIT ( dwLogFlags ) ) == FALSE )
  435. {
  436. hRes = WBEM_E_FAILED;
  437. }
  438. }
  439. if ( ( dwPropertiesReq & QUOTASETTINGS_PROP_WarningExceededNotification ) )
  440. {
  441. if ( pInstance->Setbool ( IDS_QuotasWarningExceededNotification, DISKQUOTA_IS_LOGGED_USER_THRESHOLD ( dwLogFlags) ) == FALSE )
  442. {
  443. hRes = WBEM_E_FAILED;
  444. }
  445. }
  446. }
  447. else
  448. {
  449. hRes = WBEM_E_FAILED;
  450. }
  451. }
  452. if ( ( dwPropertiesReq & QUOTASETTINGS_PROP_State ) )
  453. {
  454. if ( SUCCEEDED (pIQuotaControl->GetQuotaState( &dwQuotaState ) ) )
  455. {
  456. DWORD State = 0;
  457. if ( DISKQUOTA_IS_DISABLED ( dwQuotaState ) )
  458. State = 0;
  459. else
  460. if ( DISKQUOTA_IS_ENFORCED ( dwQuotaState) )
  461. State = 2;
  462. else
  463. if ( DISKQUOTA_IS_TRACKED ( dwQuotaState) )
  464. State = 1;
  465. pInstance->SetDWORD ( IDS_QuotaState, State );
  466. }
  467. else
  468. {
  469. hRes = WBEM_E_FAILED;
  470. }
  471. }
  472. }
  473. }
  474. }
  475. return hRes;
  476. }
  477. /*****************************************************************************
  478. *
  479. * FUNCTION : CQuotaSettings:: SetDiskQuotaVolumeProperties
  480. *
  481. * DESCRIPTION : This method Sets the DskQuota Volume Properties
  482. *
  483. *****************************************************************************/
  484. HRESULT CQuotaSettings :: SetDiskQuotaVolumeProperties (
  485. const CInstance &Instance,
  486. IDiskQuotaControlPtr pIQuotaControl
  487. )
  488. {
  489. HRESULT hRes = WBEM_S_NO_ERROR;
  490. DWORD dwLogFlags = 0;
  491. DWORD dwQuotaState = 0;
  492. bool bExceededNotn = false;
  493. bool bWarningNotn = false;
  494. DWORD dwState = 0;
  495. UINT64 ullDefaultLimit = 0;
  496. UINT64 ullWarningLimit = 0;
  497. bool bSetState = false;
  498. if (Instance.Getbool ( IDS_QuotaExceededNotification, bExceededNotn ))
  499. {
  500. if ( bExceededNotn )
  501. DISKQUOTA_SET_LOG_USER_LIMIT ( dwLogFlags, TRUE );
  502. else
  503. DISKQUOTA_SET_LOG_USER_LIMIT ( dwLogFlags, FALSE );
  504. bSetState = true;
  505. }
  506. if (Instance.Getbool ( IDS_QuotasWarningExceededNotification, bWarningNotn ))
  507. {
  508. if ( bWarningNotn )
  509. DISKQUOTA_SET_LOG_USER_THRESHOLD ( dwLogFlags, TRUE );
  510. else
  511. DISKQUOTA_SET_LOG_USER_THRESHOLD ( dwLogFlags, FALSE );
  512. bSetState = true;
  513. }
  514. if (bSetState)
  515. {
  516. if ( FAILED ( pIQuotaControl->SetQuotaLogFlags ( dwLogFlags ) ) )
  517. {
  518. hRes = WBEM_E_FAILED;
  519. }
  520. }
  521. if (Instance.GetWBEMINT64 ( IDS_QuotasDefaultLimit, ullDefaultLimit ))
  522. {
  523. if ( FAILED ( pIQuotaControl->SetDefaultQuotaLimit ( ullDefaultLimit ) ) )
  524. {
  525. hRes = WBEM_E_FAILED;
  526. }
  527. }
  528. if (Instance.GetWBEMINT64 ( IDS_QuotasDefaultWarningLimit, ullWarningLimit ))
  529. {
  530. if ( FAILED ( pIQuotaControl->SetDefaultQuotaThreshold ( ullWarningLimit ) ) )
  531. {
  532. hRes = WBEM_E_FAILED;
  533. }
  534. }
  535. if (Instance.GetDWORD ( IDS_QuotaState, dwState ))
  536. {
  537. if ( dwState == 0 )
  538. DISKQUOTA_SET_DISABLED ( dwQuotaState );
  539. if ( dwState == 1 )
  540. DISKQUOTA_SET_TRACKED ( dwQuotaState );
  541. if ( dwState == 2 )
  542. DISKQUOTA_SET_ENFORCED ( dwQuotaState );
  543. if ( FAILED ( pIQuotaControl->SetQuotaState( dwQuotaState ) ) )
  544. {
  545. hRes = WBEM_E_FAILED;
  546. }
  547. }
  548. return hRes;
  549. }
  550. /*****************************************************************************
  551. *
  552. * FUNCTION : CQuotaSettings:: CheckParameters
  553. *
  554. * DESCRIPTION : Checks for the validity of the input parameters while
  555. * Updating an instance
  556. *
  557. *****************************************************************************/
  558. HRESULT CQuotaSettings :: CheckParameters (
  559. const CInstance &a_Instance
  560. )
  561. {
  562. // Getall the Properties from the Instance to Verify
  563. HRESULT hRes = WBEM_S_NO_ERROR ;
  564. bool t_Exists ;
  565. VARTYPE t_Type ;
  566. if ( a_Instance.GetStatus ( IDS_QuotaState, t_Exists , t_Type ) )
  567. {
  568. DWORD t_State;
  569. if ( t_Exists && ( t_Type == VT_I4 ) )
  570. {
  571. if ( a_Instance.GetDWORD ( IDS_QuotaState , t_State ) )
  572. {
  573. if ( ( t_State != 1 ) && ( t_State != 0 ) && ( t_State != 2 ))
  574. {
  575. hRes = WBEM_E_INVALID_PARAMETER ;
  576. }
  577. }
  578. else
  579. {
  580. hRes = WBEM_E_INVALID_PARAMETER ;
  581. }
  582. }
  583. else
  584. {
  585. hRes = WBEM_E_INVALID_PARAMETER ;
  586. }
  587. }
  588. if ( a_Instance.GetStatus ( IDS_QuotaExceededNotification, t_Exists , t_Type ) )
  589. {
  590. if ( t_Exists && ( t_Type == VT_BOOL ) )
  591. {
  592. bool bQuotaState;
  593. if ( a_Instance.Getbool ( IDS_QuotaExceededNotification , bQuotaState ) == false )
  594. {
  595. hRes = WBEM_E_INVALID_PARAMETER ;
  596. }
  597. }
  598. else
  599. {
  600. hRes = WBEM_E_INVALID_PARAMETER ;
  601. }
  602. }
  603. if ( a_Instance.GetStatus ( IDS_QuotasWarningExceededNotification, t_Exists , t_Type ) )
  604. {
  605. if ( t_Exists && ( t_Type == VT_BOOL ) )
  606. {
  607. bool bQuotaState;
  608. if ( a_Instance.Getbool ( IDS_QuotasWarningExceededNotification , bQuotaState ) == false )
  609. {
  610. hRes = WBEM_E_INVALID_PARAMETER ;
  611. }
  612. }
  613. else
  614. {
  615. hRes = WBEM_E_INVALID_PARAMETER ;
  616. }
  617. }
  618. if ( a_Instance.GetStatus ( IDS_QuotasDefaultLimit, t_Exists , t_Type ) )
  619. {
  620. if ( t_Exists && ( t_Type == VT_BSTR ) )
  621. {
  622. LONGLONG lDefaultLimit;
  623. if ( a_Instance.GetWBEMINT64 ( IDS_QuotasDefaultLimit , lDefaultLimit ) == FALSE )
  624. {
  625. hRes = WBEM_E_INVALID_PARAMETER ;
  626. }
  627. }
  628. else
  629. {
  630. hRes = WBEM_E_INVALID_PARAMETER ;
  631. }
  632. }
  633. if ( a_Instance.GetStatus ( IDS_QuotasDefaultWarningLimit, t_Exists , t_Type ) )
  634. {
  635. if ( t_Exists && ( t_Type == VT_BSTR ) )
  636. {
  637. LONGLONG lDefaultWarningLimit;
  638. if ( a_Instance.GetWBEMINT64 ( IDS_QuotasDefaultWarningLimit , lDefaultWarningLimit ) == FALSE )
  639. {
  640. hRes = WBEM_E_INVALID_PARAMETER ;
  641. }
  642. }
  643. else
  644. {
  645. hRes = WBEM_E_INVALID_PARAMETER ;
  646. }
  647. }
  648. return hRes ;
  649. }
  650. /*****************************************************************************
  651. *
  652. * FUNCTION : CQuotaSettings:: SetRequiredProperties
  653. *
  654. * DESCRIPTION : This method sets the required properties for the instances
  655. * requested by the user
  656. *
  657. *****************************************************************************/
  658. void CQuotaSettings :: SetRequiredProperties (
  659. CFrameworkQuery *Query,
  660. DWORD &a_PropertiesReq
  661. )
  662. {
  663. a_PropertiesReq = 0;
  664. if ( Query->IsPropertyRequired ( IDS_VolumePath ) )
  665. a_PropertiesReq |= QUOTASETTINGS_PROP_VolumePath;
  666. if ( Query->IsPropertyRequired ( IDS_QuotasDefaultLimit ) )
  667. a_PropertiesReq |= QUOTASETTINGS_PROP_DefaultLimit;
  668. if ( Query->IsPropertyRequired ( IDS_Caption ) )
  669. a_PropertiesReq |= QUOTASETTINGS_PROP_Caption;
  670. if ( Query->IsPropertyRequired ( IDS_QuotasDefaultWarningLimit ) )
  671. a_PropertiesReq |= QUOTASETTINGS_PROP_DefaultWarningLimit;
  672. if ( Query->IsPropertyRequired ( IDS_QuotaExceededNotification ) )
  673. a_PropertiesReq |= QUOTASETTINGS_PROP_QuotaExceededNotification;
  674. if ( Query->IsPropertyRequired ( IDS_QuotasWarningExceededNotification ) )
  675. a_PropertiesReq |= QUOTASETTINGS_PROP_WarningExceededNotification;
  676. if ( Query->IsPropertyRequired ( IDS_QuotaState ) )
  677. a_PropertiesReq |= QUOTASETTINGS_PROP_State;
  678. }
  679. /*****************************************************************************
  680. *
  681. * FUNCTION : CQuotaSettings:: PutVolumeDetails
  682. *
  683. * DESCRIPTION : Putting the volume properties
  684. *
  685. *****************************************************************************/
  686. HRESULT CQuotaSettings :: PutVolumeDetails (
  687. LPCWSTR a_VolumeName,
  688. MethodContext *pMethodContext,
  689. DWORD a_PropertiesReq
  690. )
  691. {
  692. HRESULT hRes = WBEM_S_NO_ERROR;
  693. CHString t_DriveName ;
  694. // verify this logical drives actually exists
  695. CHString t_DriveStrings1;
  696. CHString t_DriveStrings2;
  697. LPWSTR lpDriveStrings = t_DriveStrings1.GetBuffer ( MAX_PATH + 1 );
  698. DWORD dwDLength = GetLogicalDriveStrings ( MAX_PATH, lpDriveStrings );
  699. if ( dwDLength > MAX_PATH )
  700. {
  701. lpDriveStrings = t_DriveStrings2.GetBuffer ( dwDLength + 1 );
  702. dwDLength = GetLogicalDriveStrings ( dwDLength, lpDriveStrings );
  703. }
  704. CInstancePtr pInstance(CreateNewInstance ( pMethodContext ), false) ;
  705. m_CommonRoutine.GetVolumeDrive ( a_VolumeName, lpDriveStrings, t_DriveName );
  706. hRes = LoadDiskQuotaVolumeProperties ( a_VolumeName, t_DriveName, a_PropertiesReq, pInstance );
  707. if ( SUCCEEDED ( hRes ) )
  708. {
  709. if ( ( a_PropertiesReq & QUOTASETTINGS_PROP_VolumePath ) )
  710. {
  711. if ( t_DriveName.IsEmpty() )
  712. {
  713. if ( pInstance->SetCHString ( IDS_VolumePath, a_VolumeName ) == FALSE )
  714. {
  715. hRes = WBEM_E_FAILED;
  716. }
  717. }
  718. else
  719. {
  720. if ( pInstance->SetCHString ( IDS_VolumePath, t_DriveName ) == FALSE )
  721. {
  722. hRes = WBEM_E_FAILED;
  723. }
  724. }
  725. }
  726. if ( FAILED ( pInstance->Commit() ) )
  727. {
  728. hRes = WBEM_E_FAILED;
  729. }
  730. }
  731. return hRes;
  732. }