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.

383 lines
8.7 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. netinfo.cxx
  5. Abstract:
  6. Contains entry points for Winnet API supported by the
  7. Multi-Provider Router.
  8. Contains:
  9. WNetGetNetworkInformationW
  10. WNetGetProviderNameW
  11. Author:
  12. Anirudh Sahni (anirudhs) 08-Jun-1995
  13. Environment:
  14. User Mode -Win32
  15. Notes:
  16. Revision History:
  17. 08-Jun-1995 anirudhs
  18. Created
  19. 05-May-1999 jschwart
  20. Make provider addition/removal dynamic
  21. --*/
  22. //
  23. // INCLUDES
  24. //
  25. #include "precomp.hxx"
  26. #include <tstr.h> // WCSSIZE
  27. //
  28. // EXTERNAL GLOBALS
  29. //
  30. //
  31. // Defines
  32. //
  33. //
  34. // Local Function Prototypes
  35. //
  36. DWORD
  37. WNetGetNetworkInformationW(
  38. IN LPCWSTR lpProvider,
  39. OUT LPNETINFOSTRUCT lpNetInfoStruct
  40. )
  41. /*++
  42. Routine Description:
  43. This function returns extended information about a named network provider.
  44. Arguments:
  45. lpProvider - Pointer to the name of the provider for which information is
  46. required.
  47. lpNetInfoStruct - Pointer to a structure that describes the behavior of
  48. the network.
  49. Return Value:
  50. WN_SUCCESS - Call is successful.
  51. WN_BAD_PROVIDER - lpProvider does not match any active network provider.
  52. WN_BAD_VALUE - lpProvider->cbStructure does not contain a valid structure
  53. size.
  54. Notes:
  55. Win 95's implementation of this API will accept a structure smaller than
  56. a NETINFOSTRUCT, and will fill in as many elements of the structure as
  57. will fit. This strange feature is not documented and is not used in
  58. the shell, so we don't do it here. It may be useful for future versions
  59. of this API that add fields to the NETINFOSTRUCT.
  60. --*/
  61. {
  62. DWORD status = WN_SUCCESS;
  63. LPPROVIDER Provider;
  64. if (!(ARGUMENT_PRESENT(lpProvider) &&
  65. ARGUMENT_PRESENT(lpNetInfoStruct)))
  66. {
  67. SetLastError(WN_BAD_POINTER);
  68. return WN_BAD_POINTER;
  69. }
  70. MprCheckProviders();
  71. CProviderSharedLock PLock;
  72. INIT_IF_NECESSARY(NETWORK_LEVEL,status);
  73. __try
  74. {
  75. //
  76. // Validate the parameters that we can.
  77. //
  78. if (lpNetInfoStruct->cbStructure < sizeof(NETINFOSTRUCT))
  79. {
  80. status = WN_BAD_VALUE;
  81. __leave;
  82. }
  83. if (IsBadWritePtr(lpNetInfoStruct, lpNetInfoStruct->cbStructure))
  84. {
  85. status = WN_BAD_POINTER;
  86. __leave;
  87. }
  88. //
  89. // Look up the provider by name
  90. //
  91. DWORD i;
  92. if (!MprGetProviderIndex(lpProvider, &i))
  93. {
  94. status = WN_BAD_PROVIDER;
  95. __leave;
  96. }
  97. Provider = & GlobalProviderInfo[i];
  98. }
  99. __except(EXCEPTION_EXECUTE_HANDLER)
  100. {
  101. status = GetExceptionCode();
  102. if (status != EXCEPTION_ACCESS_VIOLATION)
  103. {
  104. MPR_LOG(ERROR,
  105. "WNetGetNetworkInformationW: Unexpected Exception %#lx\n",
  106. status);
  107. }
  108. status = WN_BAD_POINTER;
  109. }
  110. if (status != WN_SUCCESS)
  111. {
  112. SetLastError(status);
  113. return status;
  114. }
  115. //
  116. // Fill in the fields of the structure
  117. //
  118. lpNetInfoStruct->cbStructure = sizeof(NETINFOSTRUCT);
  119. lpNetInfoStruct->dwProviderVersion = Provider->GetCaps(WNNC_DRIVER_VERSION);
  120. switch (Provider->GetCaps(WNNC_START))
  121. {
  122. case 0x0:
  123. lpNetInfoStruct->dwStatus = WN_NO_NETWORK;
  124. break;
  125. case 0x1:
  126. lpNetInfoStruct->dwStatus = WN_SUCCESS;
  127. break;
  128. default:
  129. lpNetInfoStruct->dwStatus = WN_FUNCTION_BUSY;
  130. break;
  131. }
  132. // We don't support this field. The shell doesn't use it.
  133. // Win 95 gets it by looking at registry entries created by the
  134. // provider. If the registry entries don't exist it leaves the
  135. // dwCharacteristics field as 0, which means that the provider
  136. // doesn't require redirection of a local drive to make a connection.
  137. lpNetInfoStruct->dwCharacteristics = 0;
  138. lpNetInfoStruct->dwHandle = (ULONG_PTR) Provider->Handle;
  139. // Note, this is a WORD field, not a DWORD.
  140. // Why does Win 95 omit the LOWORD anyway?
  141. lpNetInfoStruct->wNetType = HIWORD(Provider->Type);
  142. // We don't support these 2 fields. The shell doesn't use them.
  143. // Win 95 gets them by calling NPValidLocalDevices. If this entry
  144. // point doesn't exist it looks in the registry. If the registry
  145. // value doesn't exist it uses NPP_ALLVALID which is defined as
  146. // 0xffffffff.
  147. lpNetInfoStruct->dwPrinters = 0xffffffff;
  148. lpNetInfoStruct->dwDrives = 0xffffffff;
  149. return WN_SUCCESS;
  150. }
  151. DWORD
  152. WNetGetProviderNameW(
  153. IN DWORD dwNetType,
  154. OUT LPWSTR lpProviderName,
  155. IN OUT LPDWORD lpBufferSize
  156. )
  157. /*++
  158. Routine Description:
  159. This function returns the provider name for a specified type of network.
  160. Arguments:
  161. dwNetType - The network type unique to the network. Only the high word
  162. of the network type is used; the subtype in the low word is ignored.
  163. If two networks claim the same type, the first one loaded is returned.
  164. lpProviderName - Pointer to a buffer in which to return the provider name.
  165. lpBufferSize - On entry, size of the lpProviderName buffer in characters.
  166. On exit, iff the return code is WN_MORE_DATA, set to the required size
  167. to hold the provider name.
  168. Return Value:
  169. WN_SUCCESS - Call is successful.
  170. WN_MORE_DATA - The buffer is too small to hold the provider name.
  171. WN_NO_NETWORK - lpProvider does not match any active network provider.
  172. --*/
  173. {
  174. DWORD status = WN_SUCCESS;
  175. __try
  176. {
  177. //
  178. // Validate the parameters that we can.
  179. //
  180. if (IS_BAD_WCHAR_BUFFER(lpProviderName, lpBufferSize))
  181. {
  182. status = WN_BAD_POINTER;
  183. }
  184. }
  185. __except(EXCEPTION_EXECUTE_HANDLER)
  186. {
  187. status = GetExceptionCode();
  188. if (status != EXCEPTION_ACCESS_VIOLATION)
  189. {
  190. MPR_LOG(ERROR,
  191. "WNetGetProviderNameW: Unexpected Exception %#lx\n",
  192. status);
  193. }
  194. status = WN_BAD_POINTER;
  195. }
  196. if (status != WN_SUCCESS)
  197. {
  198. SetLastError(status);
  199. return status;
  200. }
  201. MprCheckProviders();
  202. CProviderSharedLock PLock;
  203. INIT_IF_NECESSARY(NETWORK_LEVEL,status);
  204. //
  205. // Loop through the list of providers to find one with the specified
  206. // net type.
  207. //
  208. LPPROVIDER provider = MprFindProviderByType(dwNetType);
  209. if (provider == NULL)
  210. {
  211. status = WN_NO_NETWORK;
  212. }
  213. else
  214. {
  215. //
  216. // Copy the provider name to the caller's buffer
  217. //
  218. DWORD dwReqSize = wcslen(provider->Resource.lpProvider) + 1;
  219. if (*lpBufferSize < dwReqSize)
  220. {
  221. status = WN_MORE_DATA;
  222. *lpBufferSize = dwReqSize;
  223. }
  224. else
  225. {
  226. status = WN_SUCCESS;
  227. wcscpy(lpProviderName, provider->Resource.lpProvider);
  228. }
  229. }
  230. if (status != WN_SUCCESS)
  231. {
  232. SetLastError(status);
  233. }
  234. return status;
  235. }
  236. DWORD
  237. WNetGetProviderTypeW(
  238. IN LPCWSTR lpProvider,
  239. OUT LPDWORD lpdwNetType
  240. )
  241. /*++
  242. Routine Description:
  243. This function returns the network type for a named network provider.
  244. Arguments:
  245. lpProvider - Pointer to the name of the provider for which information is
  246. required.
  247. lpdwNetType - Pointer to a network type value that is filled in.
  248. Return Value:
  249. WN_SUCCESS - Call is successful.
  250. WN_BAD_PROVIDER - lpProvider does not match any active network provider.
  251. WN_BAD_POINTER - an illegal argument was passed in.
  252. Notes:
  253. Since this is an internal, private API used only by the shell, we do
  254. minimal parameter validation, to make it as fast as possible.
  255. --*/
  256. {
  257. DWORD status = WN_SUCCESS;
  258. if (!(ARGUMENT_PRESENT(lpProvider) &&
  259. ARGUMENT_PRESENT(lpdwNetType)))
  260. {
  261. SetLastError(WN_BAD_POINTER);
  262. return WN_BAD_POINTER;
  263. }
  264. MprCheckProviders();
  265. CProviderSharedLock PLock;
  266. INIT_IF_NECESSARY(NETWORK_LEVEL,status);
  267. //
  268. // Look up the provider by name
  269. //
  270. LPPROVIDER provider = MprFindProviderByName(lpProvider);
  271. if (NULL == provider)
  272. {
  273. SetLastError(WN_BAD_PROVIDER);
  274. return WN_BAD_PROVIDER;
  275. }
  276. *lpdwNetType = provider->Type;
  277. return WN_SUCCESS;
  278. }