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.

254 lines
5.5 KiB

  1. //---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1995 - 1996
  5. //
  6. // File: cusers.cxx
  7. //
  8. // Contents: User Groups collection
  9. //
  10. // History: 08-08-96 t-danal Created from cgroups.cxx
  11. //
  12. //----------------------------------------------------------------------------
  13. #include "procs.hxx"
  14. #pragma hdrstop
  15. #include "winnt.hxx"
  16. // Class CWinNTUserGroupsCollection
  17. DEFINE_IDispatch_Implementation(CWinNTUserGroupsCollection)
  18. CWinNTUserGroupsCollection::CWinNTUserGroupsCollection():
  19. _ParentType(0),
  20. _ParentADsPath(NULL),
  21. _DomainName(NULL),
  22. _ServerName(NULL),
  23. _UserName(NULL),
  24. _pDispMgr(NULL)
  25. {
  26. VariantInit(&_vFilter);
  27. ENLIST_TRACKING(CWinNTUserGroupsCollection);
  28. }
  29. CWinNTUserGroupsCollection::~CWinNTUserGroupsCollection( )
  30. {
  31. if (_ParentADsPath)
  32. ADsFreeString(_ParentADsPath);
  33. if (_DomainName)
  34. ADsFreeString(_DomainName);
  35. if (_ServerName)
  36. ADsFreeString(_ServerName);
  37. if (_UserName)
  38. ADsFreeString(_UserName);
  39. VariantClear(&_vFilter);
  40. delete _pDispMgr;
  41. }
  42. HRESULT
  43. CWinNTUserGroupsCollection::CreateUserGroupsCollection(
  44. ULONG ParentType,
  45. BSTR ParentADsPath,
  46. BSTR DomainName,
  47. BSTR ServerName,
  48. BSTR UserName,
  49. REFIID riid,
  50. CWinNTCredentials& Credentials,
  51. void **ppvObj
  52. )
  53. {
  54. CWinNTUserGroupsCollection FAR * pUserGroups = NULL;
  55. HRESULT hr = S_OK;
  56. hr = AllocateUserGroupsCollectionObject(&pUserGroups);
  57. BAIL_ON_FAILURE(hr);
  58. ADsAssert(pUserGroups);
  59. pUserGroups->_ParentType = ParentType;
  60. hr = ADsAllocString( ParentADsPath, &pUserGroups->_ParentADsPath);
  61. BAIL_ON_FAILURE(hr);
  62. hr = ADsAllocString(DomainName, &pUserGroups->_DomainName);
  63. BAIL_ON_FAILURE(hr);
  64. hr = ADsAllocString( ServerName , &pUserGroups->_ServerName);
  65. BAIL_ON_FAILURE(hr);
  66. hr = ADsAllocString(UserName, &pUserGroups->_UserName);
  67. BAIL_ON_FAILURE(hr);
  68. pUserGroups->_Credentials = Credentials;
  69. hr = pUserGroups->_Credentials.Ref(ServerName, DomainName, ParentType);
  70. BAIL_ON_FAILURE(hr);
  71. hr = pUserGroups->QueryInterface(riid, ppvObj);
  72. BAIL_ON_FAILURE(hr);
  73. pUserGroups->Release();
  74. RRETURN(hr);
  75. error:
  76. delete pUserGroups;
  77. RRETURN_EXP_IF_ERR(hr);
  78. }
  79. STDMETHODIMP
  80. CWinNTUserGroupsCollection::QueryInterface(
  81. REFIID iid,
  82. LPVOID FAR* ppv
  83. )
  84. {
  85. if (ppv == NULL) {
  86. RRETURN(E_POINTER);
  87. }
  88. if (IsEqualIID(iid, IID_IUnknown))
  89. {
  90. *ppv = (IADsMembers FAR *) this;
  91. }
  92. else if (IsEqualIID(iid, IID_IADsMembers))
  93. {
  94. *ppv = (IADsMembers FAR *) this;
  95. }
  96. else if (IsEqualIID(iid, IID_IDispatch))
  97. {
  98. *ppv = (IADsMembers FAR *) this;
  99. }
  100. else if (IsEqualIID(iid, IID_ISupportErrorInfo))
  101. {
  102. *ppv = (ISupportErrorInfo FAR *) this;
  103. }
  104. else
  105. {
  106. *ppv = NULL;
  107. return E_NOINTERFACE;
  108. }
  109. AddRef();
  110. return NOERROR;
  111. }
  112. /* ISupportErrorInfo method */
  113. STDMETHODIMP
  114. CWinNTUserGroupsCollection::InterfaceSupportsErrorInfo(
  115. THIS_ REFIID riid
  116. )
  117. {
  118. if (IsEqualIID(riid, IID_IADsMembers)) {
  119. RRETURN(S_OK);
  120. } else {
  121. RRETURN(S_FALSE);
  122. }
  123. }
  124. STDMETHODIMP
  125. CWinNTUserGroupsCollection::get_Count(long FAR* retval)
  126. {
  127. RRETURN_EXP_IF_ERR(E_NOTIMPL);
  128. }
  129. STDMETHODIMP
  130. CWinNTUserGroupsCollection::get_Filter(THIS_ VARIANT FAR* pVar)
  131. {
  132. HRESULT hr;
  133. VariantInit(pVar);
  134. hr = VariantCopy(pVar, &_vFilter);
  135. RRETURN_EXP_IF_ERR(hr);
  136. }
  137. STDMETHODIMP
  138. CWinNTUserGroupsCollection::put_Filter(THIS_ VARIANT Var)
  139. {
  140. HRESULT hr = VariantClear(&_vFilter);
  141. if (FAILED(hr))
  142. RRETURN_EXP_IF_ERR(hr);
  143. hr = VariantCopy(&_vFilter, &Var);
  144. RRETURN_EXP_IF_ERR(hr);
  145. }
  146. STDMETHODIMP
  147. CWinNTUserGroupsCollection::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 = CWinNTUserGroupsCollectionEnum::Create(
  156. (CWinNTUserGroupsCollectionEnum **)&penum,
  157. _ParentType,
  158. _ParentADsPath,
  159. _DomainName,
  160. _ServerName,
  161. _UserName,
  162. _vFilter,
  163. _Credentials
  164. );
  165. BAIL_ON_FAILURE(hr);
  166. hr = penum->QueryInterface(
  167. IID_IUnknown,
  168. (VOID FAR* FAR*)retval
  169. );
  170. BAIL_ON_FAILURE(hr);
  171. if (penum) {
  172. penum->Release();
  173. }
  174. RRETURN(NOERROR);
  175. error:
  176. if (penum) {
  177. delete penum;
  178. }
  179. RRETURN_EXP_IF_ERR(hr);
  180. }
  181. HRESULT
  182. CWinNTUserGroupsCollection::AllocateUserGroupsCollectionObject(
  183. CWinNTUserGroupsCollection ** ppUserGroups
  184. )
  185. {
  186. CWinNTUserGroupsCollection FAR * pUserGroups = NULL;
  187. CAggregatorDispMgr FAR * pDispMgr = NULL;
  188. HRESULT hr = S_OK;
  189. pUserGroups = new CWinNTUserGroupsCollection();
  190. if (pUserGroups == NULL) {
  191. hr = E_OUTOFMEMORY;
  192. }
  193. BAIL_ON_FAILURE(hr);
  194. pDispMgr = new CAggregatorDispMgr;
  195. if (pDispMgr == NULL) {
  196. hr = E_OUTOFMEMORY;
  197. }
  198. BAIL_ON_FAILURE(hr);
  199. hr = LoadTypeInfoEntry(pDispMgr,
  200. LIBID_ADs,
  201. IID_IADsMembers,
  202. (IADsMembers *)pUserGroups,
  203. DISPID_NEWENUM
  204. );
  205. BAIL_ON_FAILURE(hr);
  206. pUserGroups->_pDispMgr = pDispMgr;
  207. *ppUserGroups = pUserGroups;
  208. RRETURN(hr);
  209. error:
  210. delete pDispMgr;
  211. RRETURN(hr);
  212. }