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.

240 lines
4.8 KiB

  1. //---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995
  5. //
  6. // File: cgroup.cxx
  7. //
  8. // Contents: Group object
  9. //
  10. // History: 11-1-95 krishnag Created.
  11. //
  12. //----------------------------------------------------------------------------
  13. #include "procs.hxx"
  14. #pragma hdrstop
  15. #include "nds.hxx"
  16. // Class CNDSGroupCollection
  17. DEFINE_IDispatch_Implementation(CNDSGroupCollection)
  18. CNDSGroupCollection::CNDSGroupCollection():
  19. _ADsPath(NULL),
  20. _pDispMgr(NULL)
  21. {
  22. VariantInit(&_vMembers);
  23. VariantInit(&_vFilter);
  24. ENLIST_TRACKING(CNDSGroupCollection);
  25. }
  26. HRESULT
  27. CNDSGroupCollection::CreateGroupCollection(
  28. BSTR bstrADsPath,
  29. VARIANT varMembers,
  30. CCredentials& Credentials,
  31. REFIID riid,
  32. void **ppvObj
  33. )
  34. {
  35. CNDSGroupCollection FAR * pGroup = NULL;
  36. HRESULT hr = S_OK;
  37. hr = AllocateGroupCollectionObject(Credentials, &pGroup);
  38. BAIL_ON_FAILURE(hr);
  39. hr = ADsAllocString(bstrADsPath, &(pGroup->_ADsPath));
  40. BAIL_ON_FAILURE(hr);
  41. hr = VariantCopy(&(pGroup->_vMembers), &varMembers);
  42. BAIL_ON_FAILURE(hr);
  43. hr = pGroup->QueryInterface(riid, ppvObj);
  44. BAIL_ON_FAILURE(hr);
  45. pGroup->Release();
  46. RRETURN(hr);
  47. error:
  48. delete pGroup;
  49. RRETURN_EXP_IF_ERR(hr);
  50. }
  51. CNDSGroupCollection::~CNDSGroupCollection( )
  52. {
  53. VariantClear(&_vMembers);
  54. VariantClear(&_vFilter);
  55. if (_ADsPath) {
  56. ADsFreeString(_ADsPath);
  57. }
  58. delete _pDispMgr;
  59. }
  60. STDMETHODIMP
  61. CNDSGroupCollection::QueryInterface(
  62. REFIID iid,
  63. LPVOID FAR* ppv
  64. )
  65. {
  66. if (ppv == NULL) {
  67. RRETURN(E_POINTER);
  68. }
  69. if (IsEqualIID(iid, IID_IUnknown))
  70. {
  71. *ppv = (IADsMembers FAR *) this;
  72. }
  73. else if (IsEqualIID(iid, IID_IADsMembers))
  74. {
  75. *ppv = (IADsMembers FAR *) this;
  76. }
  77. else if (IsEqualIID(iid, IID_IDispatch))
  78. {
  79. *ppv = (IADsMembers FAR *) this;
  80. }
  81. else if (IsEqualIID(iid, IID_ISupportErrorInfo))
  82. {
  83. *ppv = (ISupportErrorInfo FAR *) this;
  84. }
  85. else
  86. {
  87. *ppv = NULL;
  88. return E_NOINTERFACE;
  89. }
  90. AddRef();
  91. return NOERROR;
  92. }
  93. /* ISupportErrorInfo method */
  94. STDMETHODIMP
  95. CNDSGroupCollection::InterfaceSupportsErrorInfo(THIS_ REFIID riid)
  96. {
  97. if (IsEqualIID(riid, IID_IADsMembers)) {
  98. RRETURN(S_OK);
  99. } else {
  100. RRETURN(S_FALSE);
  101. }
  102. }
  103. STDMETHODIMP
  104. CNDSGroupCollection::get_Count(long FAR* retval)
  105. {
  106. RRETURN_EXP_IF_ERR(E_NOTIMPL);
  107. }
  108. STDMETHODIMP
  109. CNDSGroupCollection::get_Filter(THIS_ VARIANT FAR* pVar)
  110. {
  111. HRESULT hr;
  112. if (!pVar) {
  113. RRETURN_EXP_IF_ERR(E_ADS_BAD_PARAMETER);
  114. }
  115. VariantInit(pVar);
  116. hr = VariantCopy(pVar, &_vFilter);
  117. RRETURN_EXP_IF_ERR(hr);
  118. }
  119. STDMETHODIMP
  120. CNDSGroupCollection::put_Filter(THIS_ VARIANT Var)
  121. {
  122. HRESULT hr;
  123. hr = VariantCopy(&_vFilter, &Var);
  124. RRETURN_EXP_IF_ERR(hr);
  125. }
  126. STDMETHODIMP
  127. CNDSGroupCollection::get__NewEnum(
  128. THIS_ IUnknown * FAR* retval
  129. )
  130. {
  131. HRESULT hr;
  132. IUnknown FAR* punkEnum=NULL;
  133. IEnumVARIANT * penum = NULL;
  134. if (!retval) {
  135. RRETURN_EXP_IF_ERR(E_ADS_BAD_PARAMETER);
  136. }
  137. *retval = NULL;
  138. hr = CNDSGroupCollectionEnum::Create(
  139. _ADsPath,
  140. _Credentials,
  141. (CNDSGroupCollectionEnum **)&penum,
  142. _vMembers,
  143. _vFilter
  144. );
  145. BAIL_ON_FAILURE(hr);
  146. hr = penum->QueryInterface(
  147. IID_IUnknown,
  148. (VOID FAR* FAR*)retval
  149. );
  150. BAIL_ON_FAILURE(hr);
  151. if (penum) {
  152. penum->Release();
  153. }
  154. RRETURN(NOERROR);
  155. error:
  156. if (penum) {
  157. delete penum;
  158. }
  159. RRETURN_EXP_IF_ERR(hr);
  160. }
  161. HRESULT
  162. CNDSGroupCollection::AllocateGroupCollectionObject(
  163. CCredentials& Credentials,
  164. CNDSGroupCollection ** ppGroup
  165. )
  166. {
  167. CNDSGroupCollection FAR * pGroup = NULL;
  168. CDispatchMgr FAR * pDispMgr = NULL;
  169. HRESULT hr = S_OK;
  170. pGroup = new CNDSGroupCollection();
  171. if (pGroup == NULL) {
  172. hr = E_OUTOFMEMORY;
  173. }
  174. BAIL_ON_FAILURE(hr);
  175. pDispMgr = new CDispatchMgr;
  176. if (pDispMgr == NULL) {
  177. hr = E_OUTOFMEMORY;
  178. }
  179. BAIL_ON_FAILURE(hr);
  180. hr = LoadTypeInfoEntry(pDispMgr,
  181. LIBID_ADs,
  182. IID_IADsMembers,
  183. (IADsMembers *)pGroup,
  184. DISPID_NEWENUM
  185. );
  186. BAIL_ON_FAILURE(hr);
  187. pGroup->_Credentials = Credentials;
  188. pGroup->_pDispMgr = pDispMgr;
  189. *ppGroup = pGroup;
  190. RRETURN(hr);
  191. error:
  192. delete pGroup;
  193. delete pDispMgr;
  194. RRETURN(hr);
  195. }