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.

266 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. // 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. VARIANT var
  44. )
  45. {
  46. HRESULT hr = NOERROR;
  47. CNWCOMPATUserCollectionEnum FAR* penumvariant = NULL;
  48. *ppenumvariant = NULL;
  49. penumvariant = new CNWCOMPATUserCollectionEnum();
  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( UserName , &penumvariant->_UserName);
  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. CNWCOMPATUserCollectionEnum::CNWCOMPATUserCollectionEnum():
  82. _Parent(NULL),
  83. _ParentType(0),
  84. _ADsPath(NULL),
  85. _ServerName(NULL),
  86. _UserName(NULL),
  87. _hUser(NULL)
  88. {
  89. _pObjList = NULL;
  90. }
  91. //----------------------------------------------------------------------------
  92. //
  93. // Function:
  94. //
  95. // Synopsis:
  96. //
  97. //----------------------------------------------------------------------------
  98. CNWCOMPATUserCollectionEnum::~CNWCOMPATUserCollectionEnum()
  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 (_UserName)
  109. SysFreeString(_UserName);
  110. if (_hUser)
  111. NWCOMPATComputerUserClose(_hUser);
  112. }
  113. //----------------------------------------------------------------------------
  114. //
  115. // Function:
  116. //
  117. // Synopsis:
  118. //
  119. //----------------------------------------------------------------------------
  120. HRESULT
  121. CNWCOMPATUserCollectionEnum::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. CNWCOMPATUserCollectionEnum::GetUserMemberObject(
  152. IDispatch ** ppDispatch
  153. )
  154. {
  155. HRESULT hr = S_OK;
  156. LPUSER_GROUP_ENTRY pComputerGrpMember = NULL;
  157. LPBYTE pBuffer = NULL;
  158. DWORD dwReturned = 0;
  159. BOOL dwRet = 0;
  160. if (!_hUser) {
  161. dwRet = NWCOMPATComputerUserOpen(
  162. _ServerName,
  163. _UserName,
  164. &_hUser
  165. );
  166. if (!dwRet) {
  167. goto error;
  168. }
  169. }
  170. dwRet = NWCOMPATComputerUserEnum(
  171. _hUser,
  172. 1,
  173. &pBuffer,
  174. &dwReturned
  175. );
  176. if (!dwRet) {
  177. goto error;
  178. }
  179. pComputerGrpMember = (LPUSER_GROUP_ENTRY)pBuffer;
  180. hr = CNWCOMPATGroup::CreateGroup(
  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. RRETURN(S_OK);
  191. error:
  192. *ppDispatch = NULL;
  193. RRETURN(S_FALSE);
  194. }
  195. //+---------------------------------------------------------------------------
  196. //
  197. // Function: CNWCOMPATUserCollectionEnum::Next
  198. //
  199. // Synopsis: Returns cElements number of requested NetOle objects in the
  200. // array supplied in pvar.
  201. //
  202. // Arguments: [cElements] -- The number of elements requested by client
  203. // [pvar] -- ptr to array of VARIANTs to for return objects
  204. // [pcElementFetched] -- if non-NULL, then number of elements
  205. // -- actually returned is placed here
  206. //
  207. // Returns: HRESULT -- S_OK if number of elements requested are returned
  208. // -- S_FALSE if number of elements is < requested
  209. //
  210. // Modifies:
  211. //
  212. // History: 11-3-95 krishnag Created.
  213. //
  214. //----------------------------------------------------------------------------
  215. STDMETHODIMP
  216. CNWCOMPATUserCollectionEnum::Next(
  217. ULONG cElements,
  218. VARIANT FAR* pvar,
  219. ULONG FAR* pcElementFetched
  220. )
  221. {
  222. ULONG cElementFetched = 0;
  223. HRESULT hr = S_OK;
  224. hr = EnumGroupMembers(
  225. cElements,
  226. pvar,
  227. &cElementFetched
  228. );
  229. if (pcElementFetched) {
  230. *pcElementFetched = cElementFetched;
  231. }
  232. RRETURN_EXP_IF_ERR(hr);
  233. }