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.

265 lines
5.3 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 "winnt.hxx"
  16. // Class CWinNTLocalGroupCollection
  17. DEFINE_IDispatch_Implementation(CWinNTLocalGroupCollection)
  18. CWinNTLocalGroupCollection::CWinNTLocalGroupCollection():
  19. _ParentType(0),
  20. _DomainName(NULL),
  21. _ServerName(NULL),
  22. _lpServerName(NULL),
  23. _pDispMgr(NULL)
  24. {
  25. VariantInit(&_vFilter);
  26. ENLIST_TRACKING(CWinNTLocalGroupCollection);
  27. }
  28. HRESULT
  29. CWinNTLocalGroupCollection::CreateGroupCollection(
  30. BSTR Parent,
  31. ULONG ParentType,
  32. BSTR DomainName,
  33. BSTR ServerName,
  34. BSTR GroupName,
  35. ULONG GroupType,
  36. REFIID riid,
  37. CWinNTCredentials& Credentials,
  38. void **ppvObj
  39. )
  40. {
  41. CWinNTLocalGroupCollection FAR * pGroup = NULL;
  42. HRESULT hr = S_OK;
  43. hr = AllocateGroupCollectionObject(&pGroup);
  44. BAIL_ON_FAILURE(hr);
  45. hr = pGroup->InitializeCoreObject(
  46. Parent,
  47. GroupName,
  48. LOCALGROUP_CLASS_NAME,
  49. NULL,
  50. CLSID_WinNTGroup,
  51. ADS_OBJECT_UNBOUND
  52. );
  53. BAIL_ON_FAILURE(hr);
  54. hr = ADsAllocString( DomainName, &pGroup->_DomainName);
  55. BAIL_ON_FAILURE(hr);
  56. hr = ADsAllocString( ServerName, &pGroup->_ServerName);
  57. BAIL_ON_FAILURE(hr);
  58. pGroup->_ParentType = ParentType;
  59. pGroup->_GroupType = GroupType;
  60. pGroup->_Credentials = Credentials;
  61. hr = pGroup->_Credentials.Ref(ServerName, DomainName, ParentType);
  62. BAIL_ON_FAILURE(hr);
  63. hr = pGroup->QueryInterface(riid, ppvObj);
  64. BAIL_ON_FAILURE(hr);
  65. pGroup->Release();
  66. RRETURN(hr);
  67. error:
  68. delete pGroup;
  69. RRETURN_EXP_IF_ERR(hr);
  70. }
  71. CWinNTLocalGroupCollection::~CWinNTLocalGroupCollection( )
  72. {
  73. VariantClear( &_vFilter);
  74. if(_DomainName) {
  75. ADsFreeString(_DomainName);
  76. }
  77. if(_ServerName) {
  78. ADsFreeString(_ServerName);
  79. }
  80. delete _pDispMgr;
  81. }
  82. STDMETHODIMP
  83. CWinNTLocalGroupCollection::QueryInterface(
  84. REFIID iid,
  85. LPVOID FAR* ppv
  86. )
  87. {
  88. if (ppv == NULL) {
  89. RRETURN(E_POINTER);
  90. }
  91. if (IsEqualIID(iid, IID_IUnknown))
  92. {
  93. *ppv = (IADsMembers FAR *) this;
  94. }
  95. else if (IsEqualIID(iid, IID_IADsMembers))
  96. {
  97. *ppv = (IADsMembers FAR *) this;
  98. }
  99. else if (IsEqualIID(iid, IID_IDispatch))
  100. {
  101. *ppv = (IADsMembers FAR *) this;
  102. }
  103. else if (IsEqualIID(iid, IID_ISupportErrorInfo))
  104. {
  105. *ppv = (ISupportErrorInfo FAR *) this;
  106. }
  107. else
  108. {
  109. *ppv = NULL;
  110. return E_NOINTERFACE;
  111. }
  112. AddRef();
  113. return NOERROR;
  114. }
  115. STDMETHODIMP
  116. CWinNTLocalGroupCollection::InterfaceSupportsErrorInfo(
  117. THIS_ REFIID riid
  118. )
  119. {
  120. if (IsEqualIID(riid, IID_IADsMembers)) {
  121. RRETURN(S_OK);
  122. } else {
  123. RRETURN(S_FALSE);
  124. }
  125. }
  126. STDMETHODIMP
  127. CWinNTLocalGroupCollection::get_Count(long FAR* retval)
  128. {
  129. RRETURN_EXP_IF_ERR(E_NOTIMPL);
  130. }
  131. STDMETHODIMP
  132. CWinNTLocalGroupCollection::get_Filter(THIS_ VARIANT FAR* pVar)
  133. {
  134. HRESULT hr;
  135. VariantInit(pVar);
  136. hr = VariantCopy(pVar, &_vFilter);
  137. RRETURN_EXP_IF_ERR(hr);
  138. }
  139. STDMETHODIMP
  140. CWinNTLocalGroupCollection::put_Filter(THIS_ VARIANT Var)
  141. {
  142. HRESULT hr;
  143. hr = VariantCopy(&_vFilter, &Var);
  144. RRETURN_EXP_IF_ERR(hr);
  145. }
  146. STDMETHODIMP
  147. CWinNTLocalGroupCollection::get__NewEnum(
  148. THIS_ IUnknown * FAR* retval
  149. )
  150. {
  151. HRESULT hr;
  152. IUnknown FAR* punkEnum=NULL;
  153. IEnumVARIANT * penum = NULL;
  154. *retval = NULL;
  155. hr = CWinNTLocalGroupCollectionEnum::Create(
  156. (CWinNTLocalGroupCollectionEnum **)&penum,
  157. _Parent,
  158. _ParentType,
  159. _ADsPath,
  160. _DomainName,
  161. _ServerName,
  162. _Name,
  163. _GroupType,
  164. _vFilter,
  165. _Credentials
  166. );
  167. BAIL_ON_FAILURE(hr);
  168. hr = penum->QueryInterface(
  169. IID_IUnknown,
  170. (VOID FAR* FAR*)retval
  171. );
  172. BAIL_ON_FAILURE(hr);
  173. if (penum) {
  174. penum->Release();
  175. }
  176. RRETURN(NOERROR);
  177. error:
  178. if (penum) {
  179. delete penum;
  180. }
  181. RRETURN_EXP_IF_ERR(hr);
  182. }
  183. HRESULT
  184. CWinNTLocalGroupCollection::AllocateGroupCollectionObject(
  185. CWinNTLocalGroupCollection ** ppGroup
  186. )
  187. {
  188. CWinNTLocalGroupCollection FAR * pGroup = NULL;
  189. CAggregatorDispMgr FAR * pDispMgr = NULL;
  190. HRESULT hr = S_OK;
  191. pGroup = new CWinNTLocalGroupCollection();
  192. if (pGroup == NULL) {
  193. hr = E_OUTOFMEMORY;
  194. }
  195. BAIL_ON_FAILURE(hr);
  196. pDispMgr = new CAggregatorDispMgr;
  197. if (pDispMgr == NULL) {
  198. hr = E_OUTOFMEMORY;
  199. }
  200. BAIL_ON_FAILURE(hr);
  201. hr = LoadTypeInfoEntry(pDispMgr,
  202. LIBID_ADs,
  203. IID_IADsMembers,
  204. (IADsMembers *)pGroup,
  205. DISPID_NEWENUM
  206. );
  207. BAIL_ON_FAILURE(hr);
  208. pGroup->_pDispMgr = pDispMgr;
  209. *ppGroup = pGroup;
  210. RRETURN(hr);
  211. error:
  212. delete pDispMgr;
  213. RRETURN(hr);
  214. }