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.

227 lines
4.5 KiB

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