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.

270 lines
6.6 KiB

  1. //---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995
  5. //
  6. // File: cenumGroupCollection.cxx
  7. //
  8. // Contents: NetWare 3.12 GroupCollection Enumeration Code
  9. //
  10. // CNWCOMPATUserCollectionEnum::
  11. // CNWCOMPATUserCollectionEnum::
  12. // CNWCOMPATUserCollectionEnum::
  13. // CNWCOMPATUserCollectionEnum::
  14. //
  15. // History:
  16. //----------------------------------------------------------------------------
  17. #include "NWCOMPAT.hxx"
  18. #pragma hdrstop
  19. //+---------------------------------------------------------------------------
  20. //
  21. // Function: CNWCOMPATEnumVariant::Create
  22. //
  23. // Synopsis:
  24. //
  25. // Arguments: [pCollection]
  26. // [ppEnumVariant]
  27. //
  28. // Returns: HRESULT
  29. //
  30. // Modifies:
  31. //
  32. // History: 01-30-95 krishnag Created.
  33. //
  34. //----------------------------------------------------------------------------
  35. HRESULT
  36. CNWCOMPATUserCollectionEnum::Create(
  37. CNWCOMPATUserCollectionEnum FAR* FAR* ppenumvariant,
  38. BSTR Parent,
  39. ULONG ParentType,
  40. BSTR ADsPath,
  41. BSTR ServerName,
  42. BSTR UserName,
  43. CCredentials &Credentials,
  44. VARIANT var
  45. )
  46. {
  47. HRESULT hr = NOERROR;
  48. CNWCOMPATUserCollectionEnum FAR* penumvariant = NULL;
  49. *ppenumvariant = NULL;
  50. penumvariant = new CNWCOMPATUserCollectionEnum();
  51. if (!penumvariant) {
  52. hr = E_OUTOFMEMORY;
  53. BAIL_ON_FAILURE(hr);
  54. }
  55. hr = ADsAllocString( Parent , &penumvariant->_Parent);
  56. BAIL_ON_FAILURE(hr);
  57. penumvariant->_ParentType = ParentType;
  58. penumvariant->_Credentials = Credentials;
  59. hr = ADsAllocString(ServerName , &penumvariant->_ServerName);
  60. BAIL_ON_FAILURE(hr);
  61. hr = ADsAllocString( UserName , &penumvariant->_UserName);
  62. BAIL_ON_FAILURE(hr);
  63. hr = ADsAllocString( ADsPath , &penumvariant->_ADsPath);
  64. BAIL_ON_FAILURE(hr);
  65. hr = ObjectTypeList::CreateObjectTypeList(
  66. var,
  67. &penumvariant->_pObjList
  68. );
  69. BAIL_ON_FAILURE(hr);
  70. *ppenumvariant = penumvariant;
  71. RRETURN(hr);
  72. error:
  73. delete penumvariant;
  74. NW_RRETURN_EXP_IF_ERR(hr);
  75. }
  76. //----------------------------------------------------------------------------
  77. //
  78. // Function:
  79. //
  80. // Synopsis:
  81. //
  82. //----------------------------------------------------------------------------
  83. CNWCOMPATUserCollectionEnum::CNWCOMPATUserCollectionEnum():
  84. _Parent(NULL),
  85. _ParentType(0),
  86. _ADsPath(NULL),
  87. _ServerName(NULL),
  88. _UserName(NULL),
  89. _hUser(NULL)
  90. {
  91. _pObjList = NULL;
  92. }
  93. //----------------------------------------------------------------------------
  94. //
  95. // Function:
  96. //
  97. // Synopsis:
  98. //
  99. //----------------------------------------------------------------------------
  100. CNWCOMPATUserCollectionEnum::~CNWCOMPATUserCollectionEnum()
  101. {
  102. if (_pObjList)
  103. delete _pObjList;
  104. if (_Parent)
  105. SysFreeString(_Parent);
  106. if (_ADsPath)
  107. SysFreeString(_ADsPath);
  108. if (_ServerName)
  109. SysFreeString(_ServerName);
  110. if (_UserName)
  111. SysFreeString(_UserName);
  112. if (_hUser)
  113. NWCOMPATComputerUserClose(_hUser);
  114. }
  115. //----------------------------------------------------------------------------
  116. //
  117. // Function:
  118. //
  119. // Synopsis:
  120. //
  121. //----------------------------------------------------------------------------
  122. HRESULT
  123. CNWCOMPATUserCollectionEnum::EnumGroupMembers(
  124. ULONG cElements,
  125. VARIANT FAR* pvar,
  126. ULONG FAR* pcElementFetched
  127. )
  128. {
  129. HRESULT hr = S_OK;
  130. IDispatch *pDispatch = NULL;
  131. DWORD i = 0;
  132. while (i < cElements) {
  133. hr = GetUserMemberObject(&pDispatch);
  134. if (hr == S_FALSE) {
  135. break;
  136. }
  137. VariantInit(&pvar[i]);
  138. pvar[i].vt = VT_DISPATCH;
  139. pvar[i].pdispVal = pDispatch;
  140. (*pcElementFetched)++;
  141. i++;
  142. }
  143. RRETURN(hr);
  144. }
  145. //----------------------------------------------------------------------------
  146. //
  147. // Function:
  148. //
  149. // Synopsis:
  150. //
  151. //----------------------------------------------------------------------------
  152. HRESULT
  153. CNWCOMPATUserCollectionEnum::GetUserMemberObject(
  154. IDispatch ** ppDispatch
  155. )
  156. {
  157. HRESULT hr = S_OK;
  158. LPUSER_GROUP_ENTRY pComputerGrpMember = NULL;
  159. LPBYTE pBuffer = NULL;
  160. DWORD dwReturned = 0;
  161. BOOL dwRet = 0;
  162. if (!_hUser) {
  163. dwRet = NWCOMPATComputerUserOpen(
  164. _ServerName,
  165. _UserName,
  166. _Credentials,
  167. &_hUser
  168. );
  169. if (!dwRet) {
  170. goto error;
  171. }
  172. }
  173. dwRet = NWCOMPATComputerUserEnum(
  174. _hUser,
  175. 1,
  176. &pBuffer,
  177. &dwReturned
  178. );
  179. if (!dwRet) {
  180. goto error;
  181. }
  182. pComputerGrpMember = (LPUSER_GROUP_ENTRY)pBuffer;
  183. hr = CNWCOMPATGroup::CreateGroup(
  184. pComputerGrpMember->Parent,
  185. NWCOMPAT_COMPUTER_ID,
  186. pComputerGrpMember->Computer,
  187. pComputerGrpMember->Name,
  188. _Credentials,
  189. ADS_OBJECT_BOUND,
  190. IID_IDispatch,
  191. (void **)ppDispatch
  192. );
  193. BAIL_ON_FAILURE(hr);
  194. RRETURN(S_OK);
  195. error:
  196. *ppDispatch = NULL;
  197. RRETURN(S_FALSE);
  198. }
  199. //+---------------------------------------------------------------------------
  200. //
  201. // Function: CNWCOMPATUserCollectionEnum::Next
  202. //
  203. // Synopsis: Returns cElements number of requested NetOle objects in the
  204. // array supplied in pvar.
  205. //
  206. // Arguments: [cElements] -- The number of elements requested by client
  207. // [pvar] -- ptr to array of VARIANTs to for return objects
  208. // [pcElementFetched] -- if non-NULL, then number of elements
  209. // -- actually returned is placed here
  210. //
  211. // Returns: HRESULT -- S_OK if number of elements requested are returned
  212. // -- S_FALSE if number of elements is < requested
  213. //
  214. // Modifies:
  215. //
  216. // History: 11-3-95 krishnag Created.
  217. //
  218. //----------------------------------------------------------------------------
  219. STDMETHODIMP
  220. CNWCOMPATUserCollectionEnum::Next(
  221. ULONG cElements,
  222. VARIANT FAR* pvar,
  223. ULONG FAR* pcElementFetched
  224. )
  225. {
  226. ULONG cElementFetched = 0;
  227. HRESULT hr = S_OK;
  228. hr = EnumGroupMembers(
  229. cElements,
  230. pvar,
  231. &cElementFetched
  232. );
  233. if (pcElementFetched) {
  234. *pcElementFetched = cElementFetched;
  235. }
  236. NW_RRETURN_EXP_IF_ERR(hr);
  237. }