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.

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