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.

273 lines
5.6 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1995 - 1995.
  5. //
  6. // File: enum.cxx
  7. //
  8. // Contents: Implementation of IEnumIDList
  9. //
  10. // History: 13-Dec-95 BruceFo Created
  11. //
  12. //----------------------------------------------------------------------------
  13. #include "headers.hxx"
  14. #pragma hdrstop
  15. #include "resource.h"
  16. #include "enum.hxx"
  17. #include "util.hxx"
  18. CSharesEnum::CSharesEnum(
  19. IN PWSTR pszMachine,
  20. IN DWORD level
  21. )
  22. :
  23. m_pszMachine(pszMachine),
  24. m_level(level),
  25. m_uFlags(0),
  26. m_pShares(NULL),
  27. m_cShares(0),
  28. m_dwEnumFlags(0),
  29. m_iCurrent(0),
  30. m_ulRefs(0)
  31. {
  32. AddRef();
  33. }
  34. HRESULT
  35. CSharesEnum::Init(
  36. ULONG uFlags
  37. )
  38. {
  39. HRESULT hr = S_OK;
  40. LPBYTE pBuf = NULL;
  41. DWORD entriesread, totalentries;
  42. NET_API_STATUS ret = NERR_Success;
  43. m_uFlags = uFlags;
  44. //
  45. // Enumerate shares.
  46. //
  47. appAssert(m_level == 1 || m_level == 2);
  48. ret = NetShareEnum(
  49. m_pszMachine,
  50. m_level,
  51. &pBuf,
  52. 0xffffffff, // get them all!
  53. &entriesread,
  54. &totalentries,
  55. NULL);
  56. if (NERR_Success != ret)
  57. {
  58. hr = HRESULT_FROM_WIN32(ret);
  59. }
  60. else
  61. {
  62. appAssert(entriesread == totalentries);
  63. m_pShares = (SHARE_INFO_2*)pBuf; // possibly level one info
  64. m_cShares = entriesread;
  65. #ifdef WIZARDS
  66. m_dwEnumFlags = EF_SHOW_NEW_WIZARD;
  67. // Now, see if the machine is running the NetWare or Mac server.
  68. PSERVER_INFO_101 pServerInfo;
  69. NET_API_STATUS ret = NetServerGetInfo(m_pszMachine, 101, (LPBYTE*)&pServerInfo);
  70. if (NERR_Success != ret)
  71. {
  72. hr = HRESULT_FROM_WIN32(ret);
  73. }
  74. else
  75. {
  76. if (pServerInfo->sv101_type & SV_TYPE_AFP)
  77. {
  78. m_dwEnumFlags |= EF_SHOW_MAC_WIZARD;
  79. }
  80. if (pServerInfo->sv101_type & SV_TYPE_NOVELL)
  81. {
  82. m_dwEnumFlags |= EF_SHOW_NW_WIZARD;
  83. }
  84. // If *either* of the non-SMB servers are running, then all the
  85. // special "all" wizard object.
  86. if (m_dwEnumFlags & (EF_SHOW_MAC_WIZARD | EF_SHOW_NW_WIZARD))
  87. {
  88. m_dwEnumFlags |= EF_SHOW_ALL_WIZARD;
  89. }
  90. }
  91. NetApiBufferFree(pServerInfo);
  92. #endif // WIZARDS
  93. }
  94. return hr;
  95. }
  96. CSharesEnum::~CSharesEnum()
  97. {
  98. if (NULL != m_pShares)
  99. {
  100. NetApiBufferFree(m_pShares);
  101. }
  102. }
  103. STDMETHODIMP
  104. CSharesEnum::Next(
  105. ULONG celt,
  106. LPITEMIDLIST* ppidlOut,
  107. ULONG* pceltFetched
  108. )
  109. {
  110. HRESULT hr = S_OK;
  111. IDSHARE ids;
  112. ULONG celtFetched = 0;
  113. if (NULL == pceltFetched)
  114. {
  115. if (celt != 1)
  116. {
  117. return E_INVALIDARG;
  118. }
  119. }
  120. else
  121. {
  122. *pceltFetched = 0;
  123. }
  124. if (celt == 0)
  125. {
  126. return S_OK;
  127. }
  128. if (!(m_uFlags & SHCONTF_NONFOLDERS))
  129. {
  130. return S_FALSE;
  131. }
  132. CopyAnother:
  133. if (celtFetched == celt)
  134. {
  135. if (NULL != pceltFetched)
  136. {
  137. *pceltFetched = celtFetched;
  138. }
  139. return S_OK; // got celt elements
  140. }
  141. #ifdef WIZARDS
  142. if (0 != m_dwEnumFlags)
  143. {
  144. // We still have some special stuff to enumerate
  145. if (m_dwEnumFlags & EF_SHOW_NEW_WIZARD)
  146. {
  147. FillSpecialID(&ids, SHID_SHARE_NEW, IDS_SHARE_NEW);
  148. m_dwEnumFlags &= ~EF_SHOW_NEW_WIZARD;
  149. goto CopyOne;
  150. }
  151. if (m_dwEnumFlags & EF_SHOW_NW_WIZARD)
  152. {
  153. FillSpecialID(&ids, SHID_SHARE_NW, IDS_SHARE_NW);
  154. m_dwEnumFlags &= ~EF_SHOW_NW_WIZARD;
  155. goto CopyOne;
  156. }
  157. if (m_dwEnumFlags & EF_SHOW_MAC_WIZARD)
  158. {
  159. FillSpecialID(&ids, SHID_SHARE_MAC, IDS_SHARE_MAC);
  160. m_dwEnumFlags &= ~EF_SHOW_MAC_WIZARD;
  161. goto CopyOne;
  162. }
  163. if (m_dwEnumFlags & EF_SHOW_ALL_WIZARD)
  164. {
  165. FillSpecialID(&ids, SHID_SHARE_ALL, IDS_SHARE_ALL);
  166. m_dwEnumFlags &= ~EF_SHOW_ALL_WIZARD;
  167. goto CopyOne;
  168. }
  169. }
  170. #endif // WIZARDS
  171. if (m_iCurrent >= m_cShares)
  172. {
  173. // already enumerated all of them
  174. if (NULL != pceltFetched)
  175. {
  176. *pceltFetched = celtFetched;
  177. }
  178. return S_FALSE; // didn't copy celt
  179. }
  180. switch (m_level)
  181. {
  182. case 1: FillID1(&ids, &(((LPSHARE_INFO_1)m_pShares)[m_iCurrent])); break;
  183. case 2: FillID2(&ids, &(((LPSHARE_INFO_2)m_pShares)[m_iCurrent])); break;
  184. default: appAssert(FALSE);
  185. }
  186. ++m_iCurrent;
  187. #ifdef WIZARDS
  188. CopyOne:
  189. #endif // WIZARDS
  190. ppidlOut[celtFetched] = ILClone((LPCITEMIDLIST)(&ids));
  191. if (NULL == ppidlOut[celtFetched])
  192. {
  193. // free up everything so far
  194. for (ULONG i = 0; i < celtFetched; i++)
  195. {
  196. ILFree(ppidlOut[i]);
  197. }
  198. return E_OUTOFMEMORY;
  199. }
  200. ++celtFetched;
  201. goto CopyAnother;
  202. }
  203. STDMETHODIMP
  204. CSharesEnum::Skip(
  205. ULONG celt
  206. )
  207. {
  208. if (m_iCurrent >= m_cShares)
  209. {
  210. return S_FALSE;
  211. }
  212. m_iCurrent += celt;
  213. return NOERROR;
  214. }
  215. STDMETHODIMP
  216. CSharesEnum::Reset(
  217. VOID
  218. )
  219. {
  220. m_iCurrent = 0;
  221. return NOERROR;
  222. }
  223. STDMETHODIMP
  224. CSharesEnum::Clone(
  225. IEnumIDList** ppenum
  226. )
  227. {
  228. return E_FAIL; // not supported
  229. }