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.

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