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.

333 lines
7.2 KiB

  1. /*******************************************************************/
  2. /* Copyright(c) 1993 Microsoft Corporation */
  3. /*******************************************************************/
  4. //***
  5. //
  6. // Filename: browser.c
  7. //
  8. // Description: implements the functions to enable/restore browser
  9. // on IPX ras lines
  10. //
  11. // Author: Stefan Solomon (stefans) September 1, 1994.
  12. //
  13. // Revision History:
  14. //
  15. //***
  16. #include "precomp.h"
  17. #pragma hdrstop
  18. #include <ntddbrow.h>
  19. NTSTATUS
  20. OpenBrowser(
  21. OUT PHANDLE BrowserHandle
  22. );
  23. NTSTATUS
  24. BrDgReceiverIoControl(
  25. IN HANDLE FileHandle,
  26. IN ULONG DgReceiverControlCode,
  27. IN PLMDR_REQUEST_PACKET Drp,
  28. IN ULONG DrpSize,
  29. IN PVOID SecondBuffer OPTIONAL,
  30. IN ULONG SecondBufferLength,
  31. OUT PULONG Information OPTIONAL
  32. );
  33. VOID
  34. EnableDisableTransport(
  35. IN PCHAR Transport,
  36. BOOL Disable,
  37. BOOL *Previous
  38. );
  39. //***
  40. //
  41. // Function: DisableRestoreBrowserOverIpx
  42. //
  43. // Arguments:
  44. // contextp - context pointer
  45. // Disable - TRUE - disable, FALSE - restore previous state
  46. //
  47. //***
  48. VOID
  49. DisableRestoreBrowserOverIpx(PIPXCP_CONTEXT contextp,
  50. BOOL Disable)
  51. {
  52. PCHAR Transport = "\\Device\\NwLnkIpx";
  53. EnableDisableTransport(Transport,
  54. Disable,
  55. &contextp->NwLnkIpxPreviouslyEnabled);
  56. }
  57. //***
  58. //
  59. // Function: DisableRestoreBrowserOverNetbiosIpx
  60. //
  61. // Arguments:
  62. // contextp - context pointer
  63. // Disable - TRUE - disable, FALSE - restore previous state
  64. //
  65. //***
  66. VOID
  67. DisableRestoreBrowserOverNetbiosIpx(PIPXCP_CONTEXT contextp,
  68. BOOL Disable)
  69. {
  70. PCHAR Transport = "\\Device\\NwLnkNb";
  71. EnableDisableTransport(Transport,
  72. Disable,
  73. &contextp->NwLnkNbPreviouslyEnabled);
  74. }
  75. VOID
  76. EnableDisableTransport(
  77. IN PCHAR Transport,
  78. BOOL Disable,
  79. BOOL *Previous
  80. )
  81. {
  82. NTSTATUS Status;
  83. UNICODE_STRING TransportName;
  84. ANSI_STRING ATransportName;
  85. HANDLE BrowserHandle;
  86. PLMDR_REQUEST_PACKET RequestPacket = NULL;
  87. RtlInitString(&ATransportName, Transport);
  88. if ( RtlAnsiStringToUnicodeString(&TransportName, &ATransportName, TRUE)
  89. != STATUS_SUCCESS )
  90. {
  91. return;
  92. }
  93. RequestPacket = (PLMDR_REQUEST_PACKET)LocalAlloc(0, sizeof(LMDR_REQUEST_PACKET) + TransportName.MaximumLength);
  94. if (RequestPacket == NULL)
  95. {
  96. RtlFreeUnicodeString(&TransportName);
  97. return;
  98. }
  99. RequestPacket->TransportName.Buffer = (PWSTR)((PCHAR)RequestPacket + sizeof(LMDR_REQUEST_PACKET) );
  100. RequestPacket->TransportName.MaximumLength = TransportName.MaximumLength;
  101. RtlCopyUnicodeString(&RequestPacket->TransportName, &TransportName);
  102. Status = OpenBrowser(&BrowserHandle);
  103. if (!NT_SUCCESS(Status))
  104. {
  105. SS_PRINT(("EnableDisableTransport: Failed to open browser, status %x\n",
  106. Status));
  107. LocalFree(RequestPacket);
  108. RtlFreeUnicodeString(&TransportName);
  109. return;
  110. }
  111. SS_PRINT(("EnableDisableTransport: Browser opened succesfully!\n"));
  112. RequestPacket->Version = LMDR_REQUEST_PACKET_VERSION;
  113. if(Disable)
  114. {
  115. // request to disable
  116. RequestPacket->Parameters.EnableDisableTransport.EnableTransport = FALSE;
  117. }
  118. else
  119. {
  120. // request to restore
  121. RequestPacket->Parameters.EnableDisableTransport.EnableTransport = *Previous;
  122. }
  123. // IOCTl the Browser
  124. Status = BrDgReceiverIoControl(BrowserHandle,
  125. IOCTL_LMDR_ENABLE_DISABLE_TRANSPORT,
  126. RequestPacket,
  127. sizeof(LMDR_REQUEST_PACKET)+TransportName.MaximumLength,
  128. RequestPacket,
  129. sizeof(LMDR_REQUEST_PACKET)+TransportName.MaximumLength,
  130. NULL);
  131. if (!NT_SUCCESS(Status))
  132. {
  133. SS_PRINT(("EnableDisableTransport: Failed to IOCtl browser, status %x\n",
  134. Status));
  135. RtlFreeUnicodeString(&TransportName);
  136. CloseHandle(BrowserHandle);
  137. LocalFree(RequestPacket);
  138. return;
  139. }
  140. SS_PRINT(("Browser IOCTled Ok, EnableTransport %x PreviouslyEnabled %x\n",
  141. RequestPacket->Parameters.EnableDisableTransport.EnableTransport,
  142. RequestPacket->Parameters.EnableDisableTransport.PreviouslyEnabled));
  143. // save the previous if disable requested
  144. if(Disable)
  145. {
  146. *Previous = RequestPacket->Parameters.EnableDisableTransport.PreviouslyEnabled;
  147. }
  148. RtlFreeUnicodeString(&TransportName);
  149. CloseHandle(BrowserHandle);
  150. LocalFree(RequestPacket);
  151. }
  152. NTSTATUS
  153. OpenBrowser(
  154. OUT PHANDLE BrowserHandle
  155. )
  156. /*++
  157. Routine Description:
  158. This function opens a handle to the bowser device driver.
  159. Arguments:
  160. OUT PHANDLE BrowserHandle - Returns the handle to the browser.
  161. Return Value:
  162. Succes or reason for failure.
  163. --*/
  164. {
  165. NTSTATUS ntstatus;
  166. UNICODE_STRING DeviceName;
  167. IO_STATUS_BLOCK IoStatusBlock;
  168. OBJECT_ATTRIBUTES ObjectAttributes;
  169. //
  170. // Open the redirector device.
  171. //
  172. RtlInitUnicodeString(&DeviceName, DD_BROWSER_DEVICE_NAME_U);
  173. InitializeObjectAttributes(
  174. &ObjectAttributes,
  175. &DeviceName,
  176. OBJ_CASE_INSENSITIVE,
  177. NULL,
  178. NULL
  179. );
  180. ntstatus = NtOpenFile(
  181. BrowserHandle,
  182. SYNCHRONIZE | GENERIC_READ | GENERIC_WRITE,
  183. &ObjectAttributes,
  184. &IoStatusBlock,
  185. FILE_SHARE_READ | FILE_SHARE_WRITE,
  186. FILE_SYNCHRONOUS_IO_NONALERT
  187. );
  188. if (NT_SUCCESS(ntstatus)) {
  189. ntstatus = IoStatusBlock.Status;
  190. }
  191. return ntstatus;
  192. }
  193. NTSTATUS
  194. BrDgReceiverIoControl(
  195. IN HANDLE FileHandle,
  196. IN ULONG DgReceiverControlCode,
  197. IN PLMDR_REQUEST_PACKET Drp,
  198. IN ULONG DrpSize,
  199. IN PVOID SecondBuffer OPTIONAL,
  200. IN ULONG SecondBufferLength,
  201. OUT PULONG Information OPTIONAL
  202. )
  203. /*++
  204. Routine Description:
  205. Arguments:
  206. FileHandle - Supplies a handle to the file or device on which the service
  207. is being performed.
  208. DgReceiverControlCode - Supplies the NtDeviceIoControlFile function code
  209. given to the datagram receiver.
  210. Drp - Supplies the datagram receiver request packet.
  211. DrpSize - Supplies the length of the datagram receiver request packet.
  212. SecondBuffer - Supplies the second buffer in call to NtDeviceIoControlFile.
  213. SecondBufferLength - Supplies the length of the second buffer.
  214. Information - Returns the information field of the I/O status block.
  215. Return Value:
  216. Success or reason for failure.
  217. --*/
  218. {
  219. NTSTATUS ntstatus;
  220. IO_STATUS_BLOCK IoStatusBlock;
  221. HANDLE CompletionEvent;
  222. SS_PRINT(("TransportName.MaximumLength %d\n", Drp->TransportName.MaximumLength));
  223. CompletionEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
  224. if (CompletionEvent == NULL) {
  225. return(GetLastError());
  226. }
  227. //
  228. // Send the request to the Datagram Receiver DD.
  229. //
  230. ntstatus = NtDeviceIoControlFile(
  231. FileHandle,
  232. CompletionEvent,
  233. NULL,
  234. NULL,
  235. &IoStatusBlock,
  236. DgReceiverControlCode,
  237. Drp,
  238. DrpSize,
  239. Drp,
  240. DrpSize
  241. );
  242. if (NT_SUCCESS(ntstatus)) {
  243. //
  244. // If pending was returned, then wait until the request completes.
  245. //
  246. if (ntstatus == STATUS_PENDING) {
  247. do {
  248. ntstatus = WaitForSingleObjectEx(CompletionEvent, 0xffffffff, TRUE);
  249. } while ( ntstatus == WAIT_IO_COMPLETION );
  250. }
  251. if (NT_SUCCESS(ntstatus)) {
  252. ntstatus = IoStatusBlock.Status;
  253. }
  254. }
  255. CloseHandle(CompletionEvent);
  256. return (ntstatus);
  257. }