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.

240 lines
6.8 KiB

  1. #include "dfuser.h"
  2. #include <stdio.h>
  3. #include "dferr.h"
  4. #include "dfhlprs.h"
  5. #include "drvfull.h"
  6. #include <winnetwk.h>
  7. #define ARRAYSIZE(a) (sizeof((a))/sizeof((a)[0]))
  8. _sFLAG_DESCR _scopeFD[] =
  9. {
  10. FLAG_DESCR(RESOURCE_CONNECTED ),
  11. FLAG_DESCR(RESOURCE_GLOBALNET ),
  12. FLAG_DESCR(RESOURCE_REMEMBERED),
  13. FLAG_DESCR(RESOURCE_RECENT ),
  14. FLAG_DESCR(RESOURCE_CONTEXT ),
  15. };
  16. _sFLAG_DESCR _typeFD[] =
  17. {
  18. FLAG_DESCR(RESOURCETYPE_ANY ),
  19. FLAG_DESCR(RESOURCETYPE_DISK ),
  20. FLAG_DESCR(RESOURCETYPE_PRINT ),
  21. FLAG_DESCR(RESOURCETYPE_RESERVED ),
  22. FLAG_DESCR(RESOURCETYPE_UNKNOWN ),
  23. };
  24. _sFLAG_DESCR _usageFD[] =
  25. {
  26. FLAG_DESCR(RESOURCEUSAGE_CONNECTABLE ),
  27. FLAG_DESCR(RESOURCEUSAGE_CONTAINER ),
  28. FLAG_DESCR(RESOURCEUSAGE_NOLOCALDEVICE ),
  29. FLAG_DESCR(RESOURCEUSAGE_SIBLING ),
  30. FLAG_DESCR(RESOURCEUSAGE_ATTACHED ),
  31. FLAG_DESCR(RESOURCEUSAGE_RESERVED ),
  32. };
  33. _sFLAG_DESCR _displaytypeFD[] =
  34. {
  35. FLAG_DESCR(RESOURCEDISPLAYTYPE_GENERIC ),
  36. FLAG_DESCR(RESOURCEDISPLAYTYPE_DOMAIN ),
  37. FLAG_DESCR(RESOURCEDISPLAYTYPE_SERVER ),
  38. FLAG_DESCR(RESOURCEDISPLAYTYPE_SHARE ),
  39. FLAG_DESCR(RESOURCEDISPLAYTYPE_FILE ),
  40. FLAG_DESCR(RESOURCEDISPLAYTYPE_GROUP ),
  41. FLAG_DESCR(RESOURCEDISPLAYTYPE_NETWORK ),
  42. FLAG_DESCR(RESOURCEDISPLAYTYPE_ROOT ),
  43. FLAG_DESCR(RESOURCEDISPLAYTYPE_SHAREADMIN ),
  44. FLAG_DESCR(RESOURCEDISPLAYTYPE_DIRECTORY ),
  45. FLAG_DESCR(RESOURCEDISPLAYTYPE_TREE ),
  46. FLAG_DESCR(RESOURCEDISPLAYTYPE_NDSCONTAINER ),
  47. };
  48. HRESULT _EnumConnections(DWORD dwFlags[], LPTSTR pszArg, DWORD cchIndent)
  49. {
  50. HRESULT hres = S_OK;
  51. HANDLE hEnum;
  52. DWORD dw;
  53. DWORD dwScope;
  54. _StartClock();
  55. if (_IsFlagSet(USER_WNETENUMRESOURCECONNECTED, dwFlags))
  56. {
  57. dwScope = RESOURCE_CONNECTED;
  58. }
  59. else
  60. {
  61. dwScope = RESOURCE_REMEMBERED;
  62. }
  63. dw = WNetOpenEnum(dwScope, RESOURCETYPE_DISK, 0, NULL, &hEnum);
  64. if (WN_SUCCESS == dw)
  65. {
  66. BOOL fExit = FALSE;
  67. DWORD cbBuf = 4096 * 4;
  68. PBYTE pbBuf = (PBYTE)LocalAlloc(LPTR, cbBuf);
  69. do
  70. {
  71. //return as much as possible
  72. DWORD c = 0xFFFFFFFF;
  73. ZeroMemory(pbBuf, cbBuf);
  74. dw = WNetEnumResource(hEnum, &c, pbBuf, &cbBuf);
  75. // we assume we'll call it only once
  76. _StopClock();
  77. _PrintElapsedTime(cchIndent, TRUE);
  78. switch (dw)
  79. {
  80. case WN_SUCCESS:
  81. {
  82. NETRESOURCE* pnr = (NETRESOURCE*)pbBuf;
  83. for (DWORD i = 0; i < c; ++i)
  84. {
  85. _PrintIndent(cchIndent);
  86. wprintf(TEXT("NETRESOURCE\n"));
  87. _PrintIndent(cchIndent);
  88. wprintf(TEXT("{\n"));
  89. // Scope
  90. _PrintFlag(pnr->dwScope, _scopeFD, ARRAYSIZE(_scopeFD),
  91. cchIndent + 2, TRUE, TRUE, FALSE, FALSE);
  92. wprintf(TEXT(" (DWORD dwScope)\n"));
  93. // Type
  94. _PrintFlag(pnr->dwType, _typeFD, ARRAYSIZE(_typeFD),
  95. cchIndent + 2, TRUE, TRUE, FALSE, FALSE);
  96. wprintf(TEXT(" (DWORD dwType)\n"));
  97. // DisplayType
  98. _PrintFlag(pnr->dwDisplayType, _displaytypeFD,
  99. ARRAYSIZE(_displaytypeFD), cchIndent + 2, TRUE, TRUE,
  100. FALSE, FALSE);
  101. wprintf(TEXT(" (DWORD dwDisplayType)\n"));
  102. // Usage
  103. _PrintFlag(pnr->dwUsage, _usageFD, ARRAYSIZE(_usageFD),
  104. cchIndent + 2, TRUE, TRUE, FALSE, TRUE);
  105. wprintf(TEXT(" (DWORD dwUsage)\n"));
  106. // lpLocalName
  107. _PrintIndent(cchIndent + 2);
  108. if (pnr->lpLocalName)
  109. {
  110. wprintf(TEXT("'%s'"), pnr->lpLocalName);
  111. }
  112. else
  113. {
  114. wprintf(TEXT("<NULL>"));
  115. }
  116. wprintf(TEXT(" (LPTSTR lpLocalName)\n"));
  117. // lpRemoteName
  118. _PrintIndent(cchIndent + 2);
  119. if (pnr->lpRemoteName)
  120. {
  121. wprintf(TEXT("'%s'"), pnr->lpRemoteName);
  122. }
  123. else
  124. {
  125. wprintf(TEXT("<NULL>"));
  126. }
  127. wprintf(TEXT(" (LPTSTR lpRemoteName)\n"));
  128. // lpComment
  129. _PrintIndent(cchIndent + 2);
  130. if (pnr->lpComment)
  131. {
  132. wprintf(TEXT("'%s'"), pnr->lpComment);
  133. }
  134. else
  135. {
  136. wprintf(TEXT("<NULL>"));
  137. }
  138. wprintf(TEXT(" (LPTSTR lpComment)\n"));
  139. // lpProvider
  140. _PrintIndent(cchIndent + 2);
  141. if (pnr->lpProvider)
  142. {
  143. wprintf(TEXT("'%s'"), pnr->lpProvider);
  144. }
  145. else
  146. {
  147. wprintf(TEXT("<NULL>"));
  148. }
  149. wprintf(TEXT(" (LPTSTR lpProvider)\n"));
  150. _PrintIndent(cchIndent);
  151. wprintf(TEXT("}\n\n"));
  152. ++pnr;
  153. }
  154. break;
  155. }
  156. case ERROR_NO_MORE_ITEMS:
  157. {
  158. fExit = TRUE;
  159. break;
  160. }
  161. case ERROR_MORE_DATA:
  162. {
  163. if (pbBuf)
  164. {
  165. LocalFree(pbBuf);
  166. }
  167. // cbBuf contains required size
  168. pbBuf = (PBYTE)LocalAlloc(LPTR, cbBuf);
  169. if (!pbBuf)
  170. {
  171. fExit = TRUE;
  172. }
  173. break;
  174. }
  175. }
  176. }
  177. while (!fExit);
  178. if (pbBuf)
  179. {
  180. LocalFree(pbBuf);
  181. }
  182. WNetCloseEnum(hEnum);
  183. }
  184. else
  185. {
  186. if (ERROR_NO_NETWORK == dw)
  187. {
  188. wprintf(TEXT("Error: No Network!\n"));
  189. }
  190. else
  191. {
  192. if (ERROR_NO_MORE_ITEMS == dw)
  193. {
  194. wprintf(TEXT("None\n"));
  195. }
  196. }
  197. }
  198. return hres;
  199. }