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.

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