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.

247 lines
6.5 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. ntautodl.c
  5. Abstract:
  6. NT specific routines for interfacing with the
  7. RAS AutoDial driver (acd.sys).
  8. Author:
  9. Anthony Discolo (adiscolo) Aug 30, 1995
  10. Revision History:
  11. Who When What
  12. -------- -------- ----------------------------------------------
  13. adiscolo 08-30-95 created
  14. Notes:
  15. --*/
  16. #include "precomp.h"
  17. #include <acd.h>
  18. #include <acdapi.h>
  19. #include "addr.h"
  20. #include "tcp.h"
  21. #include "tcb.h"
  22. #include "tcpconn.h"
  23. #include "udp.h"
  24. #include "tlcommon.h"
  25. //
  26. // Macro for calculating
  27. // an IP address component.
  28. //
  29. #define UC(pIpAddr, i) ((ULONG)(((PCHAR)(pIpAddr))[i]) & 0xff)
  30. VOID
  31. TCPAcdBind();
  32. #pragma alloc_text(INIT, TCPAcdBind)
  33. //
  34. // Global variables
  35. //
  36. BOOLEAN fAcdLoadedG;
  37. ACD_DRIVER AcdDriverG;
  38. ULONG ulDriverIdG = 'Tcp ';
  39. VOID
  40. TCPNoteNewConnection(
  41. IN TCB * pTCB,
  42. IN CTELockHandle Handle
  43. )
  44. {
  45. ACD_ADDR addr;
  46. ACD_ADAPTER adapter;
  47. //
  48. // If there is a NULL source
  49. // or destination IP address, then return.
  50. //
  51. if (!pTCB->tcb_saddr || !pTCB->tcb_daddr) {
  52. CTEFreeLock(&pTCB->tcb_lock, Handle);
  53. return;
  54. }
  55. //
  56. // We also know we aren't interested in
  57. // any connections on the 127 network.
  58. //
  59. if (UC(&pTCB->tcb_daddr, 0) == 127) {
  60. CTEFreeLock(&pTCB->tcb_lock, Handle);
  61. return;
  62. }
  63. //
  64. // Get the address of the connection.
  65. //
  66. addr.fType = ACD_ADDR_IP;
  67. addr.ulIpaddr = pTCB->tcb_daddr;
  68. adapter.fType = ACD_ADAPTER_IP;
  69. adapter.ulIpaddr = pTCB->tcb_saddr;
  70. //
  71. // Release the TCB lock handle before
  72. // calling out of this driver.
  73. //
  74. CTEFreeLock(&pTCB->tcb_lock, Handle);
  75. //
  76. // Inform the automatic connection driver
  77. // of the new connection.
  78. //
  79. (*AcdDriverG.lpfnNewConnection) (&addr, &adapter);
  80. } // TCPNoteNewConnection
  81. VOID
  82. TCPAcdBind()
  83. {
  84. NTSTATUS status;
  85. UNICODE_STRING nameString;
  86. IO_STATUS_BLOCK ioStatusBlock;
  87. PIRP pIrp;
  88. PFILE_OBJECT pAcdFileObject;
  89. PDEVICE_OBJECT pAcdDeviceObject;
  90. PACD_DRIVER pDriver = &AcdDriverG;
  91. //
  92. // Initialize the name of the automatic
  93. // connection device.
  94. //
  95. RtlInitUnicodeString(&nameString, ACD_DEVICE_NAME);
  96. //
  97. // Get the file and device objects for the
  98. // device.
  99. //
  100. status = IoGetDeviceObjectPointer(
  101. &nameString,
  102. SYNCHRONIZE | GENERIC_READ | GENERIC_WRITE,
  103. &pAcdFileObject,
  104. &pAcdDeviceObject);
  105. if (status != STATUS_SUCCESS)
  106. return;
  107. //
  108. // Reference the device object.
  109. //
  110. ObReferenceObject(pAcdDeviceObject);
  111. //
  112. // Remove the reference IoGetDeviceObjectPointer()
  113. // put on the file object.
  114. //
  115. ObDereferenceObject(pAcdFileObject);
  116. //
  117. // Initialize our part of the ACD_DRIVER
  118. // structure.
  119. //
  120. KeInitializeSpinLock(&AcdDriverG.SpinLock);
  121. AcdDriverG.ulDriverId = ulDriverIdG;
  122. AcdDriverG.fEnabled = FALSE;
  123. //
  124. // Build a request to get the automatic
  125. // connection driver entry points.
  126. //
  127. pIrp = IoBuildDeviceIoControlRequest(
  128. IOCTL_INTERNAL_ACD_BIND,
  129. pAcdDeviceObject,
  130. (PVOID) & pDriver,
  131. sizeof(pDriver),
  132. NULL,
  133. 0,
  134. TRUE,
  135. NULL,
  136. &ioStatusBlock);
  137. if (pIrp == NULL) {
  138. ObDereferenceObject(pAcdDeviceObject);
  139. return;
  140. }
  141. //
  142. // Submit the request to the
  143. // automatic connection driver.
  144. //
  145. status = IoCallDriver(pAcdDeviceObject, pIrp);
  146. fAcdLoadedG = (status == STATUS_SUCCESS)? TRUE:FALSE;
  147. //
  148. // Close the device.
  149. //
  150. ObDereferenceObject(pAcdDeviceObject);
  151. } // TCPAcdBind
  152. VOID
  153. TCPAcdUnbind()
  154. {
  155. NTSTATUS status;
  156. UNICODE_STRING nameString;
  157. IO_STATUS_BLOCK ioStatusBlock;
  158. PIRP pIrp;
  159. PFILE_OBJECT pAcdFileObject;
  160. PDEVICE_OBJECT pAcdDeviceObject;
  161. PACD_DRIVER pDriver = &AcdDriverG;
  162. //
  163. // Don't bother to unbind if we
  164. // didn't successfully bind in the
  165. // first place.
  166. //
  167. if (!fAcdLoadedG)
  168. return;
  169. //
  170. // Initialize the name of the automatic
  171. // connection device.
  172. //
  173. RtlInitUnicodeString(&nameString, ACD_DEVICE_NAME);
  174. //
  175. // Get the file and device objects for the
  176. // device.
  177. //
  178. status = IoGetDeviceObjectPointer(
  179. &nameString,
  180. SYNCHRONIZE | GENERIC_READ | GENERIC_WRITE,
  181. &pAcdFileObject,
  182. &pAcdDeviceObject);
  183. if (status != STATUS_SUCCESS)
  184. return;
  185. //
  186. // Reference the device object.
  187. //
  188. ObReferenceObject(pAcdDeviceObject);
  189. //
  190. // Remove the reference IoGetDeviceObjectPointer()
  191. // put on the file object.
  192. //
  193. ObDereferenceObject(pAcdFileObject);
  194. //
  195. // Build a request to unbind from
  196. // the automatic connection driver.
  197. //
  198. pIrp = IoBuildDeviceIoControlRequest(
  199. IOCTL_INTERNAL_ACD_UNBIND,
  200. pAcdDeviceObject,
  201. (PVOID) & pDriver,
  202. sizeof(pDriver),
  203. NULL,
  204. 0,
  205. TRUE,
  206. NULL,
  207. &ioStatusBlock);
  208. if (pIrp == NULL) {
  209. ObDereferenceObject(pAcdDeviceObject);
  210. return;
  211. }
  212. //
  213. // Submit the request to the
  214. // automatic connection driver.
  215. //
  216. status = IoCallDriver(pAcdDeviceObject, pIrp);
  217. //
  218. // Close the device.
  219. //
  220. ObDereferenceObject(pAcdDeviceObject);
  221. } // TCPAcdUnbind