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.

278 lines
6.5 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. // CNWCOMPATGroupCollectionEnum::
  11. // CNWCOMPATGroupCollectionEnum::
  12. // CNWCOMPATGroupCollectionEnum::
  13. // CNWCOMPATGroupCollectionEnum::
  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. CNWCOMPATGroupCollectionEnum::Create(
  37. CNWCOMPATGroupCollectionEnum FAR* FAR* ppenumvariant,
  38. BSTR Parent,
  39. ULONG ParentType,
  40. BSTR ADsPath,
  41. BSTR ServerName,
  42. BSTR GroupName,
  43. VARIANT var
  44. )
  45. {
  46. HRESULT hr = NOERROR;
  47. CNWCOMPATGroupCollectionEnum FAR* penumvariant = NULL;
  48. *ppenumvariant = NULL;
  49. penumvariant = new CNWCOMPATGroupCollectionEnum();
  50. if (!penumvariant) {
  51. hr = E_OUTOFMEMORY;
  52. BAIL_ON_FAILURE(hr);
  53. }
  54. hr = ADsAllocString(Parent, &penumvariant->_Parent);
  55. BAIL_ON_FAILURE(hr);
  56. penumvariant->_ParentType = ParentType;
  57. hr = ADsAllocString( ServerName, &penumvariant->_ServerName);
  58. BAIL_ON_FAILURE(hr);
  59. hr = ADsAllocString( GroupName, &penumvariant->_GroupName);
  60. BAIL_ON_FAILURE(hr);
  61. hr = ADsAllocString( ADsPath, &penumvariant->_ADsPath);
  62. BAIL_ON_FAILURE(hr);
  63. hr = ObjectTypeList::CreateObjectTypeList(
  64. var,
  65. &penumvariant->_pObjList
  66. );
  67. BAIL_ON_FAILURE(hr);
  68. *ppenumvariant = penumvariant;
  69. RRETURN(hr);
  70. error:
  71. delete penumvariant;
  72. RRETURN_EXP_IF_ERR(hr);
  73. }
  74. //----------------------------------------------------------------------------
  75. //
  76. // Function:
  77. //
  78. // Synopsis:
  79. //
  80. //----------------------------------------------------------------------------
  81. CNWCOMPATGroupCollectionEnum::CNWCOMPATGroupCollectionEnum():
  82. _Parent(NULL),
  83. _ParentType(0),
  84. _ADsPath(NULL),
  85. _ServerName(NULL),
  86. _GroupName(NULL),
  87. _hGroup(NULL)
  88. {
  89. _pObjList = NULL;
  90. }
  91. //----------------------------------------------------------------------------
  92. //
  93. // Function:
  94. //
  95. // Synopsis:
  96. //
  97. //----------------------------------------------------------------------------
  98. CNWCOMPATGroupCollectionEnum::~CNWCOMPATGroupCollectionEnum()
  99. {
  100. if (_pObjList)
  101. delete _pObjList;
  102. if (_Parent)
  103. SysFreeString(_Parent);
  104. if (_ADsPath)
  105. SysFreeString(_ADsPath);
  106. if (_ServerName)
  107. SysFreeString(_ServerName);
  108. if (_GroupName)
  109. SysFreeString(_GroupName);
  110. if (_hGroup)
  111. NWCOMPATComputerGroupClose(_hGroup);
  112. }
  113. //----------------------------------------------------------------------------
  114. //
  115. // Function:
  116. //
  117. // Synopsis:
  118. //
  119. //----------------------------------------------------------------------------
  120. HRESULT
  121. CNWCOMPATGroupCollectionEnum::EnumGroupMembers(
  122. ULONG cElements,
  123. VARIANT FAR* pvar,
  124. ULONG FAR* pcElementFetched
  125. )
  126. {
  127. HRESULT hr = S_OK;
  128. IDispatch *pDispatch = NULL;
  129. DWORD i = 0;
  130. while (i < cElements) {
  131. hr = GetUserMemberObject(&pDispatch);
  132. if (hr == S_FALSE) {
  133. break;
  134. }
  135. VariantInit(&pvar[i]);
  136. pvar[i].vt = VT_DISPATCH;
  137. pvar[i].pdispVal = pDispatch;
  138. (*pcElementFetched)++;
  139. i++;
  140. }
  141. RRETURN(hr);
  142. }
  143. //----------------------------------------------------------------------------
  144. //
  145. // Function:
  146. //
  147. // Synopsis:
  148. //
  149. //----------------------------------------------------------------------------
  150. HRESULT
  151. CNWCOMPATGroupCollectionEnum::GetUserMemberObject(
  152. IDispatch ** ppDispatch
  153. )
  154. {
  155. HRESULT hr = S_OK;
  156. LPCOMPUTER_GROUP_MEMBER pComputerGrpMember = NULL;
  157. LPBYTE pBuffer = NULL;
  158. DWORD dwReturned = 0;
  159. BOOL dwRet = 0;
  160. if (!_hGroup) {
  161. dwRet = NWCOMPATComputerGroupOpen(
  162. _ServerName,
  163. _GroupName,
  164. &_hGroup
  165. );
  166. if (!dwRet) {
  167. goto error;
  168. }
  169. }
  170. dwRet = NWCOMPATComputerGroupEnum(
  171. _hGroup,
  172. 1,
  173. &pBuffer,
  174. &dwReturned
  175. );
  176. if (!dwRet) {
  177. goto error;
  178. }
  179. pComputerGrpMember = (LPCOMPUTER_GROUP_MEMBER)pBuffer;
  180. hr = CNWCOMPATUser::CreateUser(
  181. pComputerGrpMember->Parent,
  182. NWCOMPAT_COMPUTER_ID,
  183. pComputerGrpMember->Computer,
  184. pComputerGrpMember->Name,
  185. ADS_OBJECT_BOUND,
  186. IID_IDispatch,
  187. (void **)ppDispatch
  188. );
  189. BAIL_ON_FAILURE(hr);
  190. hr = S_OK;
  191. cleanup:
  192. if (pBuffer) {
  193. FreeADsMem(pBuffer);
  194. }
  195. RRETURN(hr);
  196. error:
  197. *ppDispatch = NULL;
  198. hr = S_FALSE;
  199. goto cleanup;
  200. }
  201. //+---------------------------------------------------------------------------
  202. //
  203. // Function: CNWCOMPATGroupCollectionEnum::Next
  204. //
  205. // Synopsis: Returns cElements number of requested NetOle objects in the
  206. // array supplied in pvar.
  207. //
  208. // Arguments: [cElements] -- The number of elements requested by client
  209. // [pvar] -- ptr to array of VARIANTs to for return objects
  210. // [pcElementFetched] -- if non-NULL, then number of elements
  211. // -- actually returned is placed here
  212. //
  213. // Returns: HRESULT -- S_OK if number of elements requested are returned
  214. // -- S_FALSE if number of elements is < requested
  215. //
  216. // Modifies:
  217. //
  218. // History: 11-3-95 krishnag Created.
  219. //
  220. //----------------------------------------------------------------------------
  221. STDMETHODIMP
  222. CNWCOMPATGroupCollectionEnum::Next(
  223. ULONG cElements,
  224. VARIANT FAR* pvar,
  225. ULONG FAR* pcElementFetched
  226. )
  227. {
  228. ULONG cElementFetched = 0;
  229. HRESULT hr = S_OK;
  230. hr = EnumGroupMembers(
  231. cElements,
  232. pvar,
  233. &cElementFetched
  234. );
  235. if (pcElementFetched) {
  236. *pcElementFetched = cElementFetched;
  237. }
  238. RRETURN_EXP_IF_ERR(hr);
  239. }