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.

283 lines
6.7 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. CCredentials &Credentials,
  44. VARIANT var
  45. )
  46. {
  47. HRESULT hr = NOERROR;
  48. CNWCOMPATGroupCollectionEnum FAR* penumvariant = NULL;
  49. *ppenumvariant = NULL;
  50. penumvariant = new CNWCOMPATGroupCollectionEnum();
  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( GroupName, &penumvariant->_GroupName);
  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. CNWCOMPATGroupCollectionEnum::CNWCOMPATGroupCollectionEnum():
  84. _Parent(NULL),
  85. _ParentType(0),
  86. _ADsPath(NULL),
  87. _ServerName(NULL),
  88. _GroupName(NULL),
  89. _hGroup(NULL)
  90. {
  91. _pObjList = NULL;
  92. }
  93. //----------------------------------------------------------------------------
  94. //
  95. // Function:
  96. //
  97. // Synopsis:
  98. //
  99. //----------------------------------------------------------------------------
  100. CNWCOMPATGroupCollectionEnum::~CNWCOMPATGroupCollectionEnum()
  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 (_GroupName)
  111. SysFreeString(_GroupName);
  112. if (_hGroup)
  113. NWCOMPATComputerGroupClose(_hGroup);
  114. }
  115. //----------------------------------------------------------------------------
  116. //
  117. // Function:
  118. //
  119. // Synopsis:
  120. //
  121. //----------------------------------------------------------------------------
  122. HRESULT
  123. CNWCOMPATGroupCollectionEnum::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. CNWCOMPATGroupCollectionEnum::GetUserMemberObject(
  154. IDispatch ** ppDispatch
  155. )
  156. {
  157. HRESULT hr = S_OK;
  158. LPCOMPUTER_GROUP_MEMBER pComputerGrpMember = NULL;
  159. LPBYTE pBuffer = NULL;
  160. DWORD dwReturned = 0;
  161. BOOL dwRet = 0;
  162. if (!_hGroup) {
  163. dwRet = NWCOMPATComputerGroupOpen(
  164. _ServerName,
  165. _GroupName,
  166. _Credentials,
  167. &_hGroup
  168. );
  169. if (!dwRet) {
  170. goto error;
  171. }
  172. }
  173. dwRet = NWCOMPATComputerGroupEnum(
  174. _hGroup,
  175. 1,
  176. &pBuffer,
  177. &dwReturned
  178. );
  179. if (!dwRet) {
  180. goto error;
  181. }
  182. pComputerGrpMember = (LPCOMPUTER_GROUP_MEMBER)pBuffer;
  183. hr = CNWCOMPATUser::CreateUser(
  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. hr = S_OK;
  195. cleanup:
  196. if (pBuffer) {
  197. FreeADsMem(pBuffer);
  198. }
  199. RRETURN(hr);
  200. error:
  201. *ppDispatch = NULL;
  202. hr = S_FALSE;
  203. goto cleanup;
  204. }
  205. //+---------------------------------------------------------------------------
  206. //
  207. // Function: CNWCOMPATGroupCollectionEnum::Next
  208. //
  209. // Synopsis: Returns cElements number of requested NetOle objects in the
  210. // array supplied in pvar.
  211. //
  212. // Arguments: [cElements] -- The number of elements requested by client
  213. // [pvar] -- ptr to array of VARIANTs to for return objects
  214. // [pcElementFetched] -- if non-NULL, then number of elements
  215. // -- actually returned is placed here
  216. //
  217. // Returns: HRESULT -- S_OK if number of elements requested are returned
  218. // -- S_FALSE if number of elements is < requested
  219. //
  220. // Modifies:
  221. //
  222. // History: 11-3-95 krishnag Created.
  223. //
  224. //----------------------------------------------------------------------------
  225. STDMETHODIMP
  226. CNWCOMPATGroupCollectionEnum::Next(
  227. ULONG cElements,
  228. VARIANT FAR* pvar,
  229. ULONG FAR* pcElementFetched
  230. )
  231. {
  232. ULONG cElementFetched = 0;
  233. HRESULT hr = S_OK;
  234. hr = EnumGroupMembers(
  235. cElements,
  236. pvar,
  237. &cElementFetched
  238. );
  239. if (pcElementFetched) {
  240. *pcElementFetched = cElementFetched;
  241. }
  242. NW_RRETURN_EXP_IF_ERR(hr);
  243. }