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.

322 lines
6.8 KiB

  1. //---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995
  5. //
  6. // File: cgroups.cxx
  7. //
  8. // Contents: Group object
  9. //
  10. // History: Mar-18-965 t-ptam (PatrickT) Migrated.
  11. //
  12. //----------------------------------------------------------------------------
  13. #include "NWCOMPAT.hxx"
  14. #pragma hdrstop
  15. //
  16. // Class CNWCOMPATUserCollection
  17. //
  18. DEFINE_IDispatch_Implementation(CNWCOMPATUserCollection)
  19. //----------------------------------------------------------------------------
  20. //
  21. // Function:
  22. //
  23. // Synopsis:
  24. //
  25. //----------------------------------------------------------------------------
  26. CNWCOMPATUserCollection::CNWCOMPATUserCollection():
  27. _ParentType(0),
  28. _ServerName(NULL),
  29. _pDispMgr(NULL)
  30. {
  31. VariantInit(&_vFilter);
  32. ENLIST_TRACKING(CNWCOMPATUserCollection);
  33. }
  34. //----------------------------------------------------------------------------
  35. //
  36. // Function:
  37. //
  38. // Synopsis:
  39. //
  40. //----------------------------------------------------------------------------
  41. CNWCOMPATUserCollection::~CNWCOMPATUserCollection( )
  42. {
  43. if (_ServerName)
  44. ADsFreeString(_ServerName);
  45. delete _pDispMgr;
  46. VariantClear(&_vFilter);
  47. }
  48. //----------------------------------------------------------------------------
  49. //
  50. // Function:
  51. //
  52. // Synopsis:
  53. //
  54. //----------------------------------------------------------------------------
  55. HRESULT
  56. CNWCOMPATUserCollection::CreateUserCollection(
  57. BSTR Parent,
  58. ULONG ParentType,
  59. BSTR ServerName,
  60. BSTR UserName,
  61. CCredentials &Credentials,
  62. REFIID riid,
  63. void **ppvObj
  64. )
  65. {
  66. CNWCOMPATUserCollection FAR * pUser = NULL;
  67. HRESULT hr = S_OK;
  68. hr = AllocateUserCollectionObject(&pUser);
  69. BAIL_ON_FAILURE(hr);
  70. hr = pUser->InitializeCoreObject(
  71. Parent,
  72. UserName,
  73. L"users",
  74. NO_SCHEMA,
  75. CLSID_NWCOMPATUser,
  76. ADS_OBJECT_UNBOUND
  77. );
  78. BAIL_ON_FAILURE(hr);
  79. hr = ADsAllocString(ServerName, &pUser->_ServerName);
  80. BAIL_ON_FAILURE(hr);
  81. pUser->_ParentType = ParentType;
  82. pUser->_Credentials = Credentials;
  83. hr = pUser->QueryInterface(riid, ppvObj);
  84. BAIL_ON_FAILURE(hr);
  85. pUser->Release();
  86. RRETURN(hr);
  87. error:
  88. delete pUser;
  89. NW_RRETURN_EXP_IF_ERR(hr);
  90. }
  91. //----------------------------------------------------------------------------
  92. //
  93. // Function:
  94. //
  95. // Synopsis:
  96. //
  97. //----------------------------------------------------------------------------
  98. STDMETHODIMP
  99. CNWCOMPATUserCollection::QueryInterface(
  100. REFIID iid,
  101. LPVOID FAR* ppv
  102. )
  103. {
  104. if (ppv == NULL) {
  105. RRETURN(E_POINTER);
  106. }
  107. if (IsEqualIID(iid, IID_IUnknown))
  108. {
  109. *ppv = (IADsMembers FAR *) this;
  110. }
  111. else if (IsEqualIID(iid, IID_IADsMembers))
  112. {
  113. *ppv = (IADsMembers FAR *) this;
  114. }
  115. else if (IsEqualIID(iid, IID_IDispatch))
  116. {
  117. *ppv = (IADsMembers FAR *) this;
  118. }
  119. else if (IsEqualIID(iid, IID_ISupportErrorInfo))
  120. {
  121. *ppv = (ISupportErrorInfo FAR *) this;
  122. }
  123. else
  124. {
  125. *ppv = NULL;
  126. return E_NOINTERFACE;
  127. }
  128. AddRef();
  129. return NOERROR;
  130. }
  131. //----------------------------------------------------------------------------
  132. //
  133. // Function:CNWCOMPATUserCollection::InterfaceSupportsErrorInfo
  134. //
  135. // Synopsis:
  136. //
  137. //----------------------------------------------------------------------------
  138. STDMETHODIMP
  139. CNWCOMPATUserCollection::InterfaceSupportsErrorInfo(
  140. THIS_ REFIID riid
  141. )
  142. {
  143. if (IsEqualIID(riid, IID_IADsMembers)) {
  144. RRETURN(S_OK);
  145. } else {
  146. RRETURN(S_FALSE);
  147. }
  148. }
  149. //----------------------------------------------------------------------------
  150. //
  151. // Function:
  152. //
  153. // Synopsis:
  154. //
  155. //----------------------------------------------------------------------------
  156. STDMETHODIMP
  157. CNWCOMPATUserCollection::get_Count(
  158. long FAR* retval
  159. )
  160. {
  161. NW_RRETURN_EXP_IF_ERR(E_NOTIMPL);
  162. }
  163. //----------------------------------------------------------------------------
  164. //
  165. // Function:
  166. //
  167. // Synopsis:
  168. //
  169. //----------------------------------------------------------------------------
  170. STDMETHODIMP
  171. CNWCOMPATUserCollection::get_Filter(
  172. THIS_ VARIANT FAR* pVar
  173. )
  174. {
  175. HRESULT hr;
  176. VariantInit(pVar);
  177. hr = VariantCopy(pVar, &_vFilter);
  178. NW_RRETURN_EXP_IF_ERR(hr);
  179. }
  180. //----------------------------------------------------------------------------
  181. //
  182. // Function:
  183. //
  184. // Synopsis:
  185. //
  186. //----------------------------------------------------------------------------
  187. STDMETHODIMP
  188. CNWCOMPATUserCollection::put_Filter(
  189. THIS_ VARIANT Var
  190. )
  191. {
  192. HRESULT hr;
  193. hr = VariantCopy(&_vFilter, &Var);
  194. NW_RRETURN_EXP_IF_ERR(hr);
  195. }
  196. //----------------------------------------------------------------------------
  197. //
  198. // Function:
  199. //
  200. // Synopsis:
  201. //
  202. //----------------------------------------------------------------------------
  203. STDMETHODIMP
  204. CNWCOMPATUserCollection::get__NewEnum(
  205. THIS_ IUnknown * FAR* retval
  206. )
  207. {
  208. HRESULT hr;
  209. IUnknown FAR* punkEnum=NULL;
  210. IEnumVARIANT * penum = NULL;
  211. *retval = NULL;
  212. hr = CNWCOMPATUserCollectionEnum::Create(
  213. (CNWCOMPATUserCollectionEnum **)&penum,
  214. _Parent,
  215. _ParentType,
  216. _ADsPath,
  217. _ServerName,
  218. _Name,
  219. _Credentials,
  220. _vFilter
  221. );
  222. BAIL_ON_FAILURE(hr);
  223. hr = penum->QueryInterface(
  224. IID_IUnknown,
  225. (VOID FAR* FAR*)retval
  226. );
  227. BAIL_ON_FAILURE(hr);
  228. if (penum) {
  229. penum->Release();
  230. }
  231. RRETURN(NOERROR);
  232. error:
  233. if (penum) {
  234. delete penum;
  235. }
  236. NW_RRETURN_EXP_IF_ERR(hr);
  237. }
  238. //----------------------------------------------------------------------------
  239. //
  240. // Function:
  241. //
  242. // Synopsis:
  243. //
  244. //----------------------------------------------------------------------------
  245. HRESULT
  246. CNWCOMPATUserCollection::AllocateUserCollectionObject(
  247. CNWCOMPATUserCollection ** ppUser
  248. )
  249. {
  250. CNWCOMPATUserCollection FAR * pUser = NULL;
  251. CDispatchMgr FAR * pDispMgr = NULL;
  252. HRESULT hr = S_OK;
  253. pUser = new CNWCOMPATUserCollection();
  254. if (pUser == NULL) {
  255. hr = E_OUTOFMEMORY;
  256. }
  257. BAIL_ON_FAILURE(hr);
  258. pDispMgr = new CDispatchMgr;
  259. if (pDispMgr == NULL) {
  260. hr = E_OUTOFMEMORY;
  261. }
  262. BAIL_ON_FAILURE(hr);
  263. hr = LoadTypeInfoEntry(
  264. pDispMgr,
  265. LIBID_ADs,
  266. IID_IADsMembers,
  267. (IADsMembers *)pUser,
  268. DISPID_NEWENUM
  269. );
  270. BAIL_ON_FAILURE(hr);
  271. pUser->_pDispMgr = pDispMgr;
  272. *ppUser = pUser;
  273. RRETURN(hr);
  274. error:
  275. if (pUser) {
  276. delete pUser;
  277. }
  278. if (pDispMgr) {
  279. delete pDispMgr;
  280. }
  281. RRETURN(hr);
  282. }