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.

372 lines
9.4 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. cenmfpsh.cxx
  5. Abstract:
  6. Contains methods for implementing the Enumeration of session on a
  7. server. Has methods for the CFPNWFileSharesEnumVar object.
  8. Author:
  9. Ram Viswanathan (ramv) 11-28-95
  10. Revision History:
  11. --*/
  12. #include "winnt.hxx"
  13. #pragma hdrstop
  14. #if DBG
  15. DECLARE_INFOLEVEL(FPNWEnumFileShare);
  16. DECLARE_DEBUG(FPNWEnumFileShare);
  17. #define FPNWEnumFileShareDebugOut(x) FPNWEnumFileShareInlineDebugOut x
  18. #endif
  19. //+---------------------------------------------------------------------------
  20. //
  21. // Function: CFPNWFileSharesEnumVar::CFPNWFileSharesEnumVar
  22. //
  23. // Synopsis:
  24. //
  25. //
  26. // Arguments:
  27. //
  28. //
  29. // Returns:
  30. //
  31. // Modifies:
  32. //
  33. // History: 11-22-95 RamV Created.
  34. //
  35. //----------------------------------------------------------------------------
  36. CFPNWFileSharesEnumVar::CFPNWFileSharesEnumVar()
  37. {
  38. _pszADsPath = NULL;
  39. _pszServerName = NULL;
  40. _pbFileShares = NULL;
  41. _cElements = 0;
  42. _lLBound = 0;
  43. _lCurrentPosition = _lLBound;
  44. _dwTotalEntries = 0;
  45. _dwResumeHandle = 0;
  46. VariantInit(&_vFilter);
  47. }
  48. //+---------------------------------------------------------------------------
  49. //
  50. // Function: CFPNWFileSharesEnumVar::~CFPNWFileSharesEnumVar
  51. //
  52. // Synopsis:
  53. //
  54. //
  55. // Arguments:
  56. //
  57. // Returns:
  58. //
  59. // Modifies:
  60. //
  61. // History: 11-22-95 RamV Created.
  62. //
  63. //----------------------------------------------------------------------------
  64. CFPNWFileSharesEnumVar::~CFPNWFileSharesEnumVar()
  65. {
  66. if(_pszADsPath){
  67. FreeADsStr(_pszADsPath);
  68. }
  69. if(_pszServerName){
  70. FreeADsStr(_pszServerName);
  71. }
  72. if(_pbFileShares){
  73. ADsNwApiBufferFree(_pbFileShares);
  74. }
  75. VariantClear(&_vFilter);
  76. }
  77. HRESULT CFPNWFileSharesEnumVar::Create(LPTSTR pszServerName,
  78. LPTSTR pszADsPath,
  79. CFPNWFileSharesEnumVar **ppCFileSharesEnumVar,
  80. VARIANT vFilter,
  81. CWinNTCredentials& Credentials
  82. )
  83. {
  84. HRESULT hr = S_OK;
  85. BOOL fStatus = FALSE;
  86. CFPNWFileSharesEnumVar FAR* pCFileSharesEnumVar = NULL;
  87. *ppCFileSharesEnumVar = NULL;
  88. pCFileSharesEnumVar = new CFPNWFileSharesEnumVar();
  89. if (pCFileSharesEnumVar == NULL){
  90. hr = E_OUTOFMEMORY;
  91. goto error;
  92. }
  93. pCFileSharesEnumVar->_pszServerName =
  94. AllocADsStr(pszServerName);
  95. if(!(pCFileSharesEnumVar->_pszServerName)){
  96. hr = E_OUTOFMEMORY;
  97. goto error;
  98. }
  99. pCFileSharesEnumVar->_pszADsPath =
  100. AllocADsStr(pszADsPath);
  101. if(!(pCFileSharesEnumVar->_pszADsPath)){
  102. hr = E_OUTOFMEMORY;
  103. goto error;
  104. }
  105. hr = VariantCopy(&(pCFileSharesEnumVar->_vFilter), &vFilter);
  106. BAIL_ON_FAILURE(hr);
  107. pCFileSharesEnumVar->_Credentials = Credentials;
  108. hr = pCFileSharesEnumVar->_Credentials.RefServer(pszServerName);
  109. BAIL_ON_FAILURE(hr);
  110. *ppCFileSharesEnumVar = pCFileSharesEnumVar;
  111. RRETURN(hr);
  112. error:
  113. delete pCFileSharesEnumVar;
  114. RRETURN_EXP_IF_ERR(hr);
  115. }
  116. //+---------------------------------------------------------------------------
  117. //
  118. // Function: CFPNWFileSharesEnumVar::Next
  119. //
  120. // Synopsis: Returns cElements number of requested Share objects in the
  121. // array supplied in pvar.
  122. //
  123. // Arguments: [cElements] -- The number of elements requested by client
  124. // [pvar] -- ptr to array of VARIANTs to for return objects
  125. // [ulNumFetched] -- if non-NULL, then number of elements
  126. // -- actually returned is placed here
  127. //
  128. // Returns: HRESULT -- S_OK if number of elements requested are returned
  129. // -- S_FALSE if number of elements is < requested
  130. //
  131. // Modifies:
  132. //
  133. // History: 11-27-95 RamV Created.
  134. //
  135. //----------------------------------------------------------------------------
  136. STDMETHODIMP
  137. CFPNWFileSharesEnumVar::Next(ULONG ulNumElementsRequested,
  138. VARIANT FAR* pvar,
  139. ULONG FAR* pulNumFetched)
  140. {
  141. HRESULT hresult;
  142. ULONG l;
  143. ULONG lNewCurrent;
  144. ULONG lNumFetched;
  145. PNWVOLUMEINFO pVolumeInfo = NULL;
  146. VARIANT v;
  147. IDispatch * pDispatch = NULL;
  148. if (pulNumFetched != NULL){
  149. *pulNumFetched = 0;
  150. }
  151. //
  152. // Check the out parameter to ensure it is valid
  153. //
  154. if (!pvar)
  155. return S_FALSE;
  156. //
  157. // Initialize the elements to be returned
  158. //
  159. for (l=0; l<ulNumElementsRequested; l++){
  160. VariantInit(&pvar[l]);
  161. }
  162. if(!_pbFileShares ||(_lCurrentPosition == _lLBound +(LONG)_cElements)){
  163. if (_pbFileShares){
  164. ADsNwApiBufferFree(_pbFileShares);
  165. _pbFileShares = NULL;
  166. }
  167. if(!(ValidateFilterValue(_vFilter))){
  168. RRETURN(S_FALSE);
  169. }
  170. hresult = FPNWEnumFileShares(_pszServerName,
  171. &_cElements,
  172. &_dwResumeHandle,
  173. &_pbFileShares);
  174. if(hresult == S_FALSE){
  175. goto cleanup;
  176. }
  177. _lLBound = 0;
  178. _lCurrentPosition = _lLBound;
  179. }
  180. //
  181. // Get each element and place it into the return array
  182. // Don't request more than we have
  183. //
  184. lNumFetched = 0;
  185. lNewCurrent = _lCurrentPosition;
  186. while((lNumFetched < ulNumElementsRequested) ||
  187. (lNewCurrent< _lLBound +_cElements ))
  188. {
  189. pVolumeInfo = (PNWVOLUMEINFO)(_pbFileShares +
  190. lNewCurrent*sizeof(NWVOLUMEINFO));
  191. if(pVolumeInfo->dwType == FPNWVOL_TYPE_DISKTREE){
  192. //
  193. // file share object
  194. //
  195. hresult = CFPNWFileShare::Create((LPTSTR)_pszADsPath,
  196. _pszServerName,
  197. FILESHARE_CLASS_NAME,
  198. pVolumeInfo->lpVolumeName,
  199. ADS_OBJECT_BOUND,
  200. IID_IDispatch,
  201. _Credentials,
  202. (void **)&pDispatch);
  203. BAIL_IF_ERROR(hresult);
  204. VariantInit(&v);
  205. V_VT(&v) = VT_DISPATCH;
  206. V_DISPATCH(&v) = pDispatch;
  207. pvar[lNumFetched] = v;
  208. lNumFetched++;
  209. }
  210. lNewCurrent++;
  211. if(lNumFetched == ulNumElementsRequested){
  212. //
  213. // we got all elements
  214. //
  215. break;
  216. }
  217. if(lNewCurrent==(_lLBound+_cElements)){
  218. //
  219. // first free our current buffer
  220. //
  221. if(_pbFileShares){
  222. ADsNwApiBufferFree(_pbFileShares);
  223. _pbFileShares = NULL;
  224. }
  225. hresult = FPNWEnumFileShares(_pszServerName,
  226. &_cElements,
  227. &_dwResumeHandle,
  228. &_pbFileShares);
  229. if(hresult == S_FALSE){
  230. break;
  231. }
  232. _lLBound = 0;
  233. _lCurrentPosition = _lLBound;
  234. lNewCurrent = _lCurrentPosition;
  235. }
  236. }
  237. //
  238. // Tell the caller how many we got (which may be less than the number
  239. // requested), and save the current position
  240. //
  241. if (pulNumFetched != NULL)
  242. *pulNumFetched = lNumFetched;
  243. _lCurrentPosition = lNewCurrent;
  244. //
  245. // If we're returning less than they asked for return S_FALSE, but
  246. // they still have the data (S_FALSE is a success code)
  247. //
  248. return (lNumFetched < ulNumElementsRequested) ?
  249. S_FALSE
  250. : S_OK;
  251. cleanup:
  252. if(_pbFileShares){
  253. ADsNwApiBufferFree(_pbFileShares);
  254. _pbFileShares = NULL;
  255. }
  256. if(FAILED(hresult)){
  257. #if DBG
  258. FPNWEnumFileShareDebugOut((DEB_TRACE,
  259. "hresult Failed with value: %ld \n", hresult ));
  260. #endif
  261. }
  262. RRETURN(S_FALSE);
  263. }
  264. HRESULT
  265. FPNWEnumFileShares(LPTSTR pszServerName,
  266. PDWORD pdwElements,
  267. PDWORD pdwResumeHandle,
  268. LPBYTE * ppMem
  269. )
  270. {
  271. NET_API_STATUS nasStatus;
  272. DWORD dwErrorCode;
  273. //
  274. // assumption: *ppMem = NULL when passed here
  275. //
  276. dwErrorCode = ADsNwVolumeEnum(pszServerName,
  277. 1,
  278. (PNWVOLUMEINFO *)ppMem,
  279. pdwElements,
  280. pdwResumeHandle);
  281. if(dwErrorCode != NERR_Success || (*ppMem == NULL )){
  282. //
  283. // NwVolumeEnum returns NERR_Success even when there
  284. // aren't any more items to enumerate
  285. //
  286. RRETURN(S_FALSE);
  287. }
  288. RRETURN(S_OK);
  289. }