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.

941 lines
20 KiB

  1. //***************************************************************************
  2. //
  3. // Copyright (c) 1998-1999 Microsoft Corporation
  4. //
  5. // ENUMOBJ.CPP
  6. //
  7. // alanbos 15-Aug-96 Created.
  8. //
  9. // Defines the implementation of ISWbemObjectSet
  10. //
  11. //***************************************************************************
  12. #include "precomp.h"
  13. //***************************************************************************
  14. //
  15. // CSWbemPrivilegeSet::CSWbemPrivilegeSet
  16. //
  17. // DESCRIPTION:
  18. //
  19. // Constructor.
  20. //
  21. //***************************************************************************
  22. CSWbemPrivilegeSet::CSWbemPrivilegeSet()
  23. {
  24. m_Dispatch.SetObj (this, IID_ISWbemPrivilegeSet,
  25. CLSID_SWbemPrivilegeSet, L"SWbemPrivilegeSet");
  26. m_cRef=1;
  27. m_bMutable = true;
  28. InterlockedIncrement(&g_cObj);
  29. }
  30. CSWbemPrivilegeSet::CSWbemPrivilegeSet(
  31. const CSWbemPrivilegeSet &privSet,
  32. bool bMutable
  33. )
  34. {
  35. m_Dispatch.SetObj (this, IID_ISWbemPrivilegeSet,
  36. CLSID_SWbemPrivilegeSet, L"SWbemPrivilegeSet");
  37. m_cRef=1;
  38. m_bMutable = bMutable;
  39. // Copy the contents of the supplied Privilege set to this set
  40. PrivilegeMap::const_iterator next = privSet.m_PrivilegeMap.begin ();
  41. while (next != privSet.m_PrivilegeMap.end ())
  42. {
  43. WbemPrivilegeEnum iPrivilege = (*next).first;
  44. CSWbemPrivilege *pPrivilege = (*next).second;
  45. pPrivilege->AddRef ();
  46. m_PrivilegeMap.insert
  47. (PrivilegeMap::value_type(iPrivilege, pPrivilege));
  48. next++;
  49. }
  50. InterlockedIncrement(&g_cObj);
  51. }
  52. CSWbemPrivilegeSet::CSWbemPrivilegeSet(
  53. ISWbemPrivilegeSet *pPrivilegeSet
  54. )
  55. {
  56. m_Dispatch.SetObj (this, IID_ISWbemPrivilegeSet,
  57. CLSID_SWbemPrivilegeSet, L"SWbemPrivilegeSet");
  58. m_cRef=1;
  59. m_bMutable = true;
  60. // Copy the contents of the supplied Privilege set to this set
  61. if (pPrivilegeSet)
  62. {
  63. IUnknown *pUnk = NULL;
  64. if (SUCCEEDED(pPrivilegeSet->get__NewEnum (&pUnk)))
  65. {
  66. IEnumVARIANT *pNewEnum = NULL;
  67. if (SUCCEEDED(pUnk->QueryInterface(IID_IEnumVARIANT, (void**) &pNewEnum)))
  68. {
  69. VARIANT var;
  70. VariantInit (&var);
  71. ULONG lFetched = 0;
  72. while (S_OK == pNewEnum->Next(1, &var, &lFetched))
  73. {
  74. if (VT_DISPATCH == V_VT(&var))
  75. {
  76. ISWbemPrivilege *pISWbemPrivilege = NULL;
  77. if (SUCCEEDED((var.pdispVal)->QueryInterface (IID_ISWbemPrivilege,
  78. (void**) &pISWbemPrivilege)))
  79. {
  80. WbemPrivilegeEnum iPrivilege;
  81. VARIANT_BOOL bIsEnabled;
  82. ISWbemPrivilege *pDummy = NULL;
  83. pISWbemPrivilege->get_Identifier (&iPrivilege);
  84. pISWbemPrivilege->get_IsEnabled (&bIsEnabled);
  85. if (SUCCEEDED (Add (iPrivilege, bIsEnabled, &pDummy)))
  86. pDummy->Release ();
  87. pISWbemPrivilege->Release ();
  88. }
  89. }
  90. VariantClear (&var);
  91. }
  92. VariantClear (&var);
  93. pNewEnum->Release ();
  94. }
  95. pUnk->Release ();
  96. }
  97. }
  98. InterlockedIncrement(&g_cObj);
  99. }
  100. //***************************************************************************
  101. //
  102. // CSWbemPrivilegeSet::~CSWbemPrivilegeSet
  103. //
  104. // DESCRIPTION:
  105. //
  106. // Destructor.
  107. //
  108. //***************************************************************************
  109. CSWbemPrivilegeSet::~CSWbemPrivilegeSet(void)
  110. {
  111. PrivilegeMap::iterator next;
  112. while ((next = m_PrivilegeMap.begin ()) != m_PrivilegeMap.end ())
  113. {
  114. CSWbemPrivilege *pPrivilege = (*next).second;
  115. next = m_PrivilegeMap.erase (next);
  116. pPrivilege->Release ();
  117. }
  118. InterlockedDecrement(&g_cObj);
  119. }
  120. //***************************************************************************
  121. // HRESULT CSWbemPrivilegeSet::QueryInterface
  122. // long CSWbemPrivilegeSet::AddRef
  123. // long CSWbemPrivilegeSet::Release
  124. //
  125. // DESCRIPTION:
  126. //
  127. // Standard Com IUNKNOWN functions.
  128. //
  129. //***************************************************************************
  130. STDMETHODIMP CSWbemPrivilegeSet::QueryInterface (
  131. IN REFIID riid,
  132. OUT LPVOID *ppv
  133. )
  134. {
  135. *ppv=NULL;
  136. if (IID_IUnknown==riid)
  137. *ppv = reinterpret_cast<IUnknown*>(this);
  138. else if (IID_ISWbemPrivilegeSet==riid)
  139. *ppv = (ISWbemPrivilegeSet *)this;
  140. else if (IID_IDispatch==riid)
  141. *ppv = (IDispatch *)this;
  142. else if (IID_ISupportErrorInfo==riid)
  143. *ppv = (ISupportErrorInfo *)this;
  144. else if (IID_IProvideClassInfo==riid)
  145. *ppv = (IProvideClassInfo *)this;
  146. if (NULL!=*ppv)
  147. {
  148. ((LPUNKNOWN)*ppv)->AddRef();
  149. return NOERROR;
  150. }
  151. return ResultFromScode(E_NOINTERFACE);
  152. }
  153. STDMETHODIMP_(ULONG) CSWbemPrivilegeSet::AddRef(void)
  154. {
  155. long l = InterlockedIncrement(&m_cRef);
  156. return l;
  157. }
  158. STDMETHODIMP_(ULONG) CSWbemPrivilegeSet::Release(void)
  159. {
  160. long l = InterlockedDecrement(&m_cRef);
  161. if (0L!=l)
  162. return l;
  163. delete this;
  164. return 0;
  165. }
  166. //***************************************************************************
  167. // HRESULT CSWbemPrivilegeSet::InterfaceSupportsErrorInfo
  168. //
  169. // DESCRIPTION:
  170. //
  171. // Standard Com ISupportErrorInfo functions.
  172. //
  173. //***************************************************************************
  174. STDMETHODIMP CSWbemPrivilegeSet::InterfaceSupportsErrorInfo (IN REFIID riid)
  175. {
  176. return (IID_ISWbemPrivilegeSet == riid) ? S_OK : S_FALSE;
  177. }
  178. //***************************************************************************
  179. //
  180. // SCODE CSWbemPrivilegeSet::get__NewEnum
  181. //
  182. // DESCRIPTION:
  183. //
  184. // Return an IEnumVARIANT-supporting interface for collections
  185. //
  186. // PARAMETERS:
  187. //
  188. // ppUnk on successful return addresses the IUnknown interface
  189. //
  190. // RETURN VALUES:
  191. //
  192. // S_OK success
  193. // E_FAIL otherwise
  194. //
  195. //***************************************************************************
  196. HRESULT CSWbemPrivilegeSet::get__NewEnum (
  197. IUnknown **ppUnk
  198. )
  199. {
  200. HRESULT hr = E_FAIL;
  201. ResetLastErrors ();
  202. if (NULL != ppUnk)
  203. {
  204. *ppUnk = NULL;
  205. CEnumPrivilegeSet *pEnum = new CEnumPrivilegeSet (this);
  206. if (!pEnum)
  207. hr = WBEM_E_OUT_OF_MEMORY;
  208. else if (FAILED(hr = pEnum->QueryInterface (IID_IUnknown, (PPVOID) ppUnk)))
  209. delete pEnum;
  210. }
  211. if (FAILED(hr))
  212. m_Dispatch.RaiseException (hr);
  213. return hr;
  214. }
  215. //***************************************************************************
  216. //
  217. // SCODE CSWbemPrivilegeSet::get_Count
  218. //
  219. // DESCRIPTION:
  220. //
  221. // Return the number of items in the collection
  222. //
  223. // PARAMETERS:
  224. //
  225. // plCount on successful return addresses the count
  226. //
  227. // RETURN VALUES:
  228. //
  229. // S_OK success
  230. // E_FAIL otherwise
  231. //
  232. //***************************************************************************
  233. HRESULT CSWbemPrivilegeSet::get_Count (
  234. long *plCount
  235. )
  236. {
  237. HRESULT hr = E_FAIL;
  238. ResetLastErrors ();
  239. if (NULL != plCount)
  240. {
  241. *plCount = m_PrivilegeMap.size ();
  242. hr = S_OK;
  243. }
  244. if (FAILED(hr))
  245. m_Dispatch.RaiseException (hr);
  246. return hr;
  247. }
  248. //***************************************************************************
  249. //
  250. // SCODE CSWbemPrivilegeSet::Item
  251. //
  252. // DESCRIPTION:
  253. //
  254. // Get object from the enumeration by path.
  255. //
  256. // PARAMETERS:
  257. //
  258. // bsObjectPath The path of the object to retrieve
  259. // lFlags Flags
  260. // ppNamedObject On successful return addresses the object
  261. //
  262. // RETURN VALUES:
  263. //
  264. // WBEM_S_NO_ERROR success
  265. // WBEM_E_INVALID_PARAMETER bad input parameters
  266. // WBEM_E_FAILED otherwise
  267. //
  268. //***************************************************************************
  269. HRESULT CSWbemPrivilegeSet::Item (
  270. WbemPrivilegeEnum iPrivilege,
  271. ISWbemPrivilege **ppPrivilege
  272. )
  273. {
  274. HRESULT hr = WBEM_E_NOT_FOUND;
  275. ResetLastErrors ();
  276. if (NULL == ppPrivilege)
  277. hr = WBEM_E_INVALID_PARAMETER;
  278. else
  279. {
  280. *ppPrivilege = NULL;
  281. PrivilegeMap::iterator theIterator;
  282. theIterator = m_PrivilegeMap.find (iPrivilege);
  283. if (theIterator != m_PrivilegeMap.end ())
  284. {
  285. CSWbemPrivilege *pPrivilege = (*theIterator).second;
  286. if (SUCCEEDED(pPrivilege->QueryInterface
  287. (IID_ISWbemPrivilege, (PPVOID) ppPrivilege)))
  288. {
  289. hr = WBEM_S_NO_ERROR;
  290. }
  291. }
  292. }
  293. if (FAILED(hr))
  294. m_Dispatch.RaiseException (hr);
  295. return hr;
  296. }
  297. //***************************************************************************
  298. //
  299. // SCODE CSWbemPrivilegeSet::DeleteAll
  300. //
  301. // DESCRIPTION:
  302. //
  303. // Remove all items in the collection
  304. //
  305. // RETURN VALUES:
  306. //
  307. // S_OK success
  308. // E_FAIL otherwise
  309. //
  310. //***************************************************************************
  311. HRESULT CSWbemPrivilegeSet::DeleteAll ()
  312. {
  313. HRESULT hr = S_OK;
  314. ResetLastErrors ();
  315. if (m_bMutable)
  316. {
  317. PrivilegeMap::iterator next;
  318. while ((next = m_PrivilegeMap.begin ()) != m_PrivilegeMap.end ())
  319. {
  320. CSWbemPrivilege *pPrivilege = (*next).second;
  321. next = m_PrivilegeMap.erase (next);
  322. pPrivilege->Release ();
  323. }
  324. }
  325. else
  326. hr = WBEM_E_READ_ONLY;
  327. if (FAILED(hr))
  328. m_Dispatch.RaiseException (hr);
  329. return hr;
  330. }
  331. //***************************************************************************
  332. //
  333. // SCODE CSWbemPrivilegeSet::Remove
  334. //
  335. // DESCRIPTION:
  336. //
  337. // Remove the named item in the collection
  338. //
  339. // PARAMETERS
  340. // bsName Name of item to remove
  341. //
  342. // RETURN VALUES:
  343. //
  344. // S_OK success
  345. // E_FAIL otherwise
  346. //
  347. //***************************************************************************
  348. HRESULT CSWbemPrivilegeSet::Remove (
  349. WbemPrivilegeEnum iPrivilege
  350. )
  351. {
  352. HRESULT hr = WBEM_E_NOT_FOUND;
  353. ResetLastErrors ();
  354. if (m_bMutable)
  355. {
  356. PrivilegeMap::iterator theIterator = m_PrivilegeMap.find (iPrivilege);
  357. if (theIterator != m_PrivilegeMap.end ())
  358. {
  359. // Found it - release and remove
  360. CSWbemPrivilege *pPrivilege = (*theIterator).second;
  361. m_PrivilegeMap.erase (theIterator);
  362. pPrivilege->Release ();
  363. hr = S_OK;
  364. }
  365. }
  366. else
  367. hr = WBEM_E_READ_ONLY;
  368. if (FAILED(hr))
  369. m_Dispatch.RaiseException (hr);
  370. return hr;
  371. }
  372. //***************************************************************************
  373. //
  374. // SCODE CSWbemPrivilegeSet::Add
  375. //
  376. // DESCRIPTION:
  377. //
  378. // Add a new item to the collection
  379. //
  380. // RETURN VALUES:
  381. //
  382. // S_OK success
  383. // wbemErrInvalidParameter privilege name not recognized by OS
  384. // E_FAIL otherwise
  385. //
  386. //***************************************************************************
  387. HRESULT CSWbemPrivilegeSet::Add (
  388. WbemPrivilegeEnum iPrivilege,
  389. VARIANT_BOOL bIsEnabled,
  390. ISWbemPrivilege **ppPrivilege
  391. )
  392. {
  393. HRESULT hr = E_FAIL;
  394. ResetLastErrors ();
  395. if (NULL == ppPrivilege)
  396. hr = WBEM_E_INVALID_PARAMETER;
  397. else if (m_bMutable)
  398. {
  399. CSWbemPrivilege *pPrivilege = NULL;
  400. PrivilegeMap::iterator theIterator = m_PrivilegeMap.find (iPrivilege);
  401. if (theIterator != m_PrivilegeMap.end ())
  402. {
  403. // Already there, so modify setting
  404. pPrivilege = (*theIterator).second;
  405. if (SUCCEEDED(hr = pPrivilege->QueryInterface (IID_ISWbemPrivilege,
  406. (PPVOID) ppPrivilege)))
  407. {
  408. pPrivilege->put_IsEnabled (bIsEnabled);
  409. }
  410. }
  411. else
  412. {
  413. /*
  414. * Potential new element - first check it's
  415. * a valid Privilege name by getting it's LUID.
  416. */
  417. LUID luid;
  418. TCHAR *tName = CSWbemPrivilege::GetNameFromId (iPrivilege);
  419. if (tName && CSWbemSecurity::LookupPrivilegeValue(tName, &luid))
  420. {
  421. // Super. Now add it to the map (note that constructor AddRef's)
  422. pPrivilege = new CSWbemPrivilege (iPrivilege, luid,
  423. (bIsEnabled) ? true : false);
  424. if (!pPrivilege)
  425. hr = WBEM_E_OUT_OF_MEMORY;
  426. else if (SUCCEEDED(hr = pPrivilege->QueryInterface (IID_ISWbemPrivilege,
  427. (PPVOID)ppPrivilege)))
  428. {
  429. m_PrivilegeMap.insert
  430. (PrivilegeMap::value_type(iPrivilege, pPrivilege));
  431. }
  432. else
  433. {
  434. delete pPrivilege;
  435. }
  436. }
  437. else
  438. {
  439. DWORD dwLastError = GetLastError ();
  440. hr = wbemErrInvalidParameter;
  441. }
  442. }
  443. }
  444. else
  445. hr = WBEM_E_READ_ONLY;
  446. if (FAILED(hr))
  447. m_Dispatch.RaiseException (hr);
  448. return hr;
  449. }
  450. //***************************************************************************
  451. //
  452. // SCODE CSWbemPrivilegeSet::AddAsString
  453. //
  454. // DESCRIPTION:
  455. //
  456. // Add a new item to the collection; the privilege is specified by
  457. // an NT privilege string rather than a WbemPrivilegeEnum id.
  458. //
  459. // RETURN VALUES:
  460. //
  461. // S_OK success
  462. // wbemErrInvalidParameter privilege name not recognized by OS
  463. // E_FAIL otherwise
  464. //
  465. //***************************************************************************
  466. HRESULT CSWbemPrivilegeSet::AddAsString (
  467. BSTR bsPrivilege,
  468. VARIANT_BOOL bIsEnabled,
  469. ISWbemPrivilege **ppPrivilege
  470. )
  471. {
  472. HRESULT hr = wbemErrInvalidParameter;
  473. ResetLastErrors ();
  474. // Map the string into a Privilege id
  475. WbemPrivilegeEnum iPrivilege;
  476. if (CSWbemPrivilege::GetIdFromName (bsPrivilege, iPrivilege))
  477. hr = Add (iPrivilege, bIsEnabled, ppPrivilege);
  478. else
  479. {
  480. if (FAILED(hr))
  481. m_Dispatch.RaiseException (hr);
  482. }
  483. return hr;
  484. }
  485. //***************************************************************************
  486. //
  487. // SCODE CSWbemPrivilegeSet::GetNumberOfDisabledElements
  488. //
  489. // DESCRIPTION:
  490. //
  491. // Add a new item to the collection
  492. //
  493. // RETURN VALUES:
  494. //
  495. // S_OK success
  496. // wbemErrInvalidParameter privilege name not recognized by OS
  497. // E_FAIL otherwise
  498. //
  499. //***************************************************************************
  500. ULONG CSWbemPrivilegeSet::GetNumberOfDisabledElements ()
  501. {
  502. ULONG lNum = 0;
  503. PrivilegeMap::iterator next = m_PrivilegeMap.begin ();
  504. while (next != m_PrivilegeMap.end ())
  505. {
  506. CSWbemPrivilege *pPrivilege = (*next).second;
  507. VARIANT_BOOL bValue;
  508. if (SUCCEEDED(pPrivilege->get_IsEnabled (&bValue)) && (VARIANT_FALSE == bValue))
  509. lNum++;
  510. next++;
  511. }
  512. return lNum;
  513. }
  514. //***************************************************************************
  515. //
  516. // SCODE CSWbemPrivilegeSet::Reset
  517. //
  518. // DESCRIPTION:
  519. //
  520. // Remove all items from the set and reinstantiate with
  521. // a copy of the items in the input privilege set
  522. //
  523. //***************************************************************************
  524. void CSWbemPrivilegeSet::Reset (CSWbemPrivilegeSet &privSet)
  525. {
  526. DeleteAll ();
  527. PrivilegeMap::iterator next = privSet.m_PrivilegeMap.begin ();
  528. while (next != privSet.m_PrivilegeMap.end ())
  529. {
  530. VARIANT_BOOL bIsEnabled;
  531. CSWbemPrivilege *pPrivilege = (*next).second;
  532. pPrivilege->get_IsEnabled (&bIsEnabled);
  533. ISWbemPrivilege *pDummy = NULL;
  534. if (SUCCEEDED (Add ((*next).first, bIsEnabled, &pDummy)))
  535. pDummy->Release ();
  536. next++;
  537. }
  538. }
  539. // CEnumPrivilegeSet Methods
  540. //***************************************************************************
  541. //
  542. // CEnumPrivilegeSet::CEnumPrivilegeSet
  543. //
  544. // DESCRIPTION:
  545. //
  546. // Constructor.
  547. //
  548. //***************************************************************************
  549. CEnumPrivilegeSet::CEnumPrivilegeSet(CSWbemPrivilegeSet *pPrivilegeSet)
  550. {
  551. m_cRef=0;
  552. m_pPrivilegeSet = pPrivilegeSet;
  553. if (m_pPrivilegeSet)
  554. {
  555. m_pPrivilegeSet->AddRef ();
  556. m_Iterator = m_pPrivilegeSet->m_PrivilegeMap.begin ();
  557. }
  558. InterlockedIncrement(&g_cObj);
  559. }
  560. CEnumPrivilegeSet::CEnumPrivilegeSet(CSWbemPrivilegeSet *pPrivilegeSet,
  561. PrivilegeMap::iterator iterator) :
  562. m_Iterator (iterator)
  563. {
  564. m_cRef=0;
  565. m_pPrivilegeSet = pPrivilegeSet;
  566. if (m_pPrivilegeSet)
  567. {
  568. m_pPrivilegeSet->AddRef ();
  569. }
  570. InterlockedIncrement(&g_cObj);
  571. }
  572. //***************************************************************************
  573. //
  574. // CEnumPrivilegeSet::~CEnumPrivilegeSet
  575. //
  576. // DESCRIPTION:
  577. //
  578. // Destructor.
  579. //
  580. //***************************************************************************
  581. CEnumPrivilegeSet::~CEnumPrivilegeSet(void)
  582. {
  583. InterlockedDecrement(&g_cObj);
  584. if (m_pPrivilegeSet)
  585. m_pPrivilegeSet->Release ();
  586. }
  587. //***************************************************************************
  588. // HRESULT CEnumPrivilegeSet::QueryInterface
  589. // long CEnumPrivilegeSet::AddRef
  590. // long CEnumPrivilegeSet::Release
  591. //
  592. // DESCRIPTION:
  593. //
  594. // Standard Com IUNKNOWN functions.
  595. //
  596. //***************************************************************************
  597. STDMETHODIMP CEnumPrivilegeSet::QueryInterface (
  598. IN REFIID riid,
  599. OUT LPVOID *ppv
  600. )
  601. {
  602. *ppv=NULL;
  603. if (IID_IUnknown==riid || IID_IEnumVARIANT==riid)
  604. *ppv=this;
  605. if (NULL!=*ppv)
  606. {
  607. ((LPUNKNOWN)*ppv)->AddRef();
  608. return NOERROR;
  609. }
  610. return ResultFromScode(E_NOINTERFACE);
  611. }
  612. STDMETHODIMP_(ULONG) CEnumPrivilegeSet::AddRef(void)
  613. {
  614. long l = InterlockedIncrement(&m_cRef);
  615. return l;
  616. }
  617. STDMETHODIMP_(ULONG) CEnumPrivilegeSet::Release(void)
  618. {
  619. long l = InterlockedDecrement(&m_cRef);
  620. if (0L!=l)
  621. return l;
  622. delete this;
  623. return 0;
  624. }
  625. //***************************************************************************
  626. //
  627. // SCODE CEnumPrivilegeSet::Reset
  628. //
  629. // DESCRIPTION:
  630. //
  631. // Reset the enumeration
  632. //
  633. // PARAMETERS:
  634. //
  635. // RETURN VALUES:
  636. //
  637. // S_OK success
  638. // S_FALSE otherwise
  639. //
  640. //***************************************************************************
  641. HRESULT CEnumPrivilegeSet::Reset ()
  642. {
  643. HRESULT hr = S_FALSE;
  644. if (m_pPrivilegeSet)
  645. {
  646. m_Iterator = m_pPrivilegeSet->m_PrivilegeMap.begin ();
  647. }
  648. else
  649. {
  650. hr = E_FAIL;
  651. }
  652. return hr;
  653. }
  654. //***************************************************************************
  655. //
  656. // SCODE CEnumPrivilegeSet::Next
  657. //
  658. // DESCRIPTION:
  659. //
  660. // Get the next object in the enumeration
  661. //
  662. // PARAMETERS:
  663. //
  664. // lTimeout Number of ms to wait for object (or WBEM_INFINITE for
  665. // indefinite)
  666. // ppObject On return may contain the next element (if any)
  667. //
  668. // RETURN VALUES:
  669. //
  670. // S_OK success
  671. // S_FALSE not all elements could be returned
  672. //
  673. //***************************************************************************
  674. HRESULT CEnumPrivilegeSet::Next (
  675. ULONG cElements,
  676. VARIANT FAR* pVar,
  677. ULONG FAR* pcElementFetched
  678. )
  679. {
  680. HRESULT hr = S_OK;
  681. ULONG l2 = 0;
  682. if (NULL != pcElementFetched)
  683. *pcElementFetched = 0;
  684. if ((NULL != pVar) && (m_pPrivilegeSet))
  685. {
  686. for (ULONG l = 0; l < cElements; l++)
  687. VariantInit (&pVar [l]);
  688. // Retrieve the next cElements elements.
  689. for (l2 = 0; l2 < cElements; l2++)
  690. {
  691. if (m_Iterator != m_pPrivilegeSet->m_PrivilegeMap.end ())
  692. {
  693. CSWbemPrivilege *pSWbemPrivilege = (*m_Iterator).second;
  694. m_Iterator++;
  695. ISWbemPrivilege *pISWbemPrivilege = NULL;
  696. if (SUCCEEDED(pSWbemPrivilege->QueryInterface
  697. (IID_ISWbemPrivilege, (PPVOID) &pISWbemPrivilege)))
  698. {
  699. // Set the object into the variant array; note that pObject
  700. // has been addref'd as a result of the QI() call above
  701. pVar[l2].vt = VT_DISPATCH;
  702. pVar[l2].pdispVal = pISWbemPrivilege;
  703. }
  704. }
  705. else
  706. break;
  707. }
  708. if (NULL != pcElementFetched)
  709. *pcElementFetched = l2;
  710. }
  711. if (FAILED(hr))
  712. return hr;
  713. return (l2 < cElements) ? S_FALSE : S_OK;
  714. }
  715. //***************************************************************************
  716. //
  717. // SCODE CEnumPrivilegeSet::Clone
  718. //
  719. // DESCRIPTION:
  720. //
  721. // Create a copy of this enumeration
  722. //
  723. // PARAMETERS:
  724. //
  725. // ppEnum on successful return addresses the clone
  726. //
  727. // RETURN VALUES:
  728. //
  729. // WBEM_S_NO_ERROR success
  730. // WBEM_E_FAILED otherwise
  731. //
  732. //***************************************************************************
  733. HRESULT CEnumPrivilegeSet::Clone (
  734. IEnumVARIANT **ppEnum
  735. )
  736. {
  737. HRESULT hr = E_FAIL;
  738. if (NULL != ppEnum)
  739. {
  740. *ppEnum = NULL;
  741. if (m_pPrivilegeSet)
  742. {
  743. CEnumPrivilegeSet *pEnum = new CEnumPrivilegeSet (m_pPrivilegeSet, m_Iterator);
  744. if (!pEnum)
  745. hr = WBEM_E_OUT_OF_MEMORY;
  746. else if (FAILED(hr = pEnum->QueryInterface (IID_IEnumVARIANT, (PPVOID) ppEnum)))
  747. delete pEnum;;
  748. }
  749. }
  750. return hr;
  751. }
  752. //***************************************************************************
  753. //
  754. // SCODE CEnumPrivilegeSet::Skip
  755. //
  756. // DESCRIPTION:
  757. //
  758. // Skip specified number of elements
  759. //
  760. // PARAMETERS:
  761. //
  762. // ppEnum on successful return addresses the clone
  763. //
  764. // RETURN VALUES:
  765. //
  766. // S_OK success
  767. // S_FALSE end of sequence reached prematurely
  768. //
  769. //***************************************************************************
  770. HRESULT CEnumPrivilegeSet::Skip(
  771. ULONG cElements
  772. )
  773. {
  774. HRESULT hr = S_FALSE;
  775. if (m_pPrivilegeSet)
  776. {
  777. ULONG l2;
  778. // Retrieve the next cElements elements.
  779. for (l2 = 0; l2 < cElements; l2++)
  780. {
  781. if (m_Iterator != m_pPrivilegeSet->m_PrivilegeMap.end ())
  782. m_Iterator++;
  783. else
  784. break;
  785. }
  786. if (l2 == cElements)
  787. hr = S_OK;
  788. }
  789. return hr;
  790. }