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.

277 lines
5.9 KiB

  1. //---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995
  5. //
  6. // File: cenumfs.cxx
  7. //
  8. // Contents: NetWare 3.X Enumerator Code
  9. //
  10. // CNWCOMPATFileServiceEnum::Create
  11. // CNWCOMPATFileServiceEnum::CNWCOMPATFileServiceEnum
  12. // CNWCOMPATFileServiceEnum::~CNWCOMPATFileServiceEnum
  13. // CNWCOMPATFileServiceEnum::Next
  14. //
  15. // History:
  16. //----------------------------------------------------------------------------
  17. #include "NWCOMPAT.hxx"
  18. #pragma hdrstop
  19. //----------------------------------------------------------------------------
  20. //
  21. // Function: CNWCOMPATFileServiceEnum::Create
  22. //
  23. // Synopsis:
  24. //
  25. //----------------------------------------------------------------------------
  26. HRESULT
  27. CNWCOMPATFileServiceEnum::Create(
  28. CNWCOMPATFileServiceEnum FAR* FAR* ppEnumVariant,
  29. BSTR ADsPath,
  30. BSTR bstrServerName,
  31. CCredentials &Credentials
  32. )
  33. {
  34. HRESULT hr = S_OK;
  35. CNWCOMPATFileServiceEnum FAR* pEnumVariant = NULL;
  36. pEnumVariant = new CNWCOMPATFileServiceEnum();
  37. if (pEnumVariant == NULL){
  38. hr = E_OUTOFMEMORY;
  39. BAIL_ON_FAILURE(hr);
  40. }
  41. //
  42. // Get a handle to the bindery (FileServer) that is going to be enumerated
  43. // on.
  44. //
  45. hr = NWApiGetBinderyHandle(
  46. &pEnumVariant->_hConn,
  47. bstrServerName,
  48. Credentials
  49. );
  50. BAIL_ON_FAILURE(hr);
  51. //
  52. // Get FileServer VersionInfo. The Version Info structure has the maximum
  53. // number of volumes.
  54. //
  55. hr = NWApiGetFileServerVersionInfo(
  56. pEnumVariant->_hConn,
  57. &pEnumVariant->_FileServerInfo
  58. );
  59. BAIL_ON_FAILURE(hr);
  60. //
  61. // Save ADsPath.
  62. //
  63. hr = ADsAllocString(ADsPath, &pEnumVariant->_ADsPath);
  64. BAIL_ON_FAILURE(hr);
  65. //
  66. // Save Credentials
  67. //
  68. pEnumVariant->_Credentials = Credentials;
  69. //
  70. // Return.
  71. //
  72. *ppEnumVariant = pEnumVariant;
  73. RRETURN(hr);
  74. error:
  75. delete pEnumVariant;
  76. NW_RRETURN_EXP_IF_ERR(hr);
  77. }
  78. //----------------------------------------------------------------------------
  79. //
  80. // Function: CNWCOMPATFileServiceEnum::CNWCOMPATFileServiceEnum
  81. //
  82. // Synopsis:
  83. //
  84. //----------------------------------------------------------------------------
  85. CNWCOMPATFileServiceEnum::CNWCOMPATFileServiceEnum():
  86. _ADsPath(NULL),
  87. _bResumeVolumeID(0),
  88. _hConn(NULL)
  89. {
  90. }
  91. //----------------------------------------------------------------------------
  92. //
  93. // Function:
  94. //
  95. // Synopsis:
  96. //
  97. //----------------------------------------------------------------------------
  98. CNWCOMPATFileServiceEnum::~CNWCOMPATFileServiceEnum()
  99. {
  100. if (_ADsPath)
  101. SysFreeString(_ADsPath);
  102. if (_hConn)
  103. NWApiReleaseBinderyHandle(_hConn);
  104. }
  105. //----------------------------------------------------------------------------
  106. //
  107. // Function:
  108. //
  109. // Synopsis:
  110. //
  111. //----------------------------------------------------------------------------
  112. STDMETHODIMP
  113. CNWCOMPATFileServiceEnum::Next(
  114. ULONG cElements,
  115. VARIANT FAR* pvar,
  116. ULONG FAR* pcElementFetched
  117. )
  118. {
  119. ULONG cElementFetched = 0;
  120. HRESULT hr = S_OK;
  121. hr = EnumFileShares(
  122. cElements,
  123. pvar,
  124. &cElementFetched
  125. );
  126. if (pcElementFetched) {
  127. *pcElementFetched = cElementFetched;
  128. }
  129. NW_RRETURN_EXP_IF_ERR(hr);
  130. }
  131. //----------------------------------------------------------------------------
  132. //
  133. // Function: CNWCOMPATFileServiceEnum::EnumFileShares
  134. //
  135. // Synopsis:
  136. //
  137. //----------------------------------------------------------------------------
  138. HRESULT
  139. CNWCOMPATFileServiceEnum::EnumFileShares(
  140. ULONG cElements,
  141. VARIANT FAR* pvar,
  142. ULONG FAR* pcElementFetched
  143. )
  144. {
  145. HRESULT hr = S_OK;
  146. IDispatch *pDispatch = NULL;
  147. DWORD i = 0;
  148. while (i < cElements) {
  149. hr = GetFileShareObject(&pDispatch);
  150. if (hr == S_FALSE) {
  151. break;
  152. }
  153. VariantInit(&pvar[i]);
  154. pvar[i].vt = VT_DISPATCH;
  155. pvar[i].pdispVal = pDispatch;
  156. (*pcElementFetched)++;
  157. i++;
  158. }
  159. return(hr);
  160. }
  161. //----------------------------------------------------------------------------
  162. //
  163. // Function: CNWCOMPATFileServiceEnum::GetFileShareObject
  164. //
  165. // Synopsis:
  166. //
  167. //----------------------------------------------------------------------------
  168. HRESULT
  169. CNWCOMPATFileServiceEnum::GetFileShareObject(
  170. IDispatch ** ppDispatch
  171. )
  172. {
  173. LPTSTR pszObjectName = NULL;
  174. HRESULT hr = S_OK;
  175. *ppDispatch = NULL;
  176. //
  177. // Since Volume Number of defined Volume doesn't necessarily exist in
  178. // consecutive chunk, a loop is needed to skip all the "holes".
  179. //
  180. while (_bResumeVolumeID < _FileServerInfo.maxVolumes) {
  181. //
  182. // Get the name of the next Volume.
  183. //
  184. hr = NWApiGetVolumeName(
  185. _hConn,
  186. _bResumeVolumeID,
  187. &pszObjectName
  188. );
  189. BAIL_ON_FAILURE(hr);
  190. if (wcscmp(pszObjectName, L"")) {
  191. break;
  192. }
  193. else {
  194. _bResumeVolumeID++;
  195. }
  196. if (pszObjectName){
  197. FreeADsStr(pszObjectName);
  198. pszObjectName = NULL;
  199. }
  200. }
  201. //
  202. // Check if the last volume was reached already.
  203. //
  204. if (_bResumeVolumeID >= _FileServerInfo.maxVolumes) {
  205. RRETURN(S_FALSE);
  206. }
  207. //
  208. // Create a FileShare object.
  209. //
  210. hr = CNWCOMPATFileShare::CreateFileShare(
  211. _ADsPath,
  212. pszObjectName,
  213. _Credentials,
  214. ADS_OBJECT_BOUND,
  215. IID_IDispatch,
  216. (void **)ppDispatch
  217. );
  218. BAIL_ON_FAILURE(hr);
  219. //
  220. // Increase the current volume number.
  221. //
  222. _bResumeVolumeID++;
  223. //
  224. // Return.
  225. //
  226. error:
  227. if (pszObjectName) {
  228. FreeADsStr(pszObjectName);
  229. }
  230. RRETURN_ENUM_STATUS(hr);
  231. }