Windows NT 4.0 source code leak
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.

309 lines
6.4 KiB

4 years ago
  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. autodial.c
  5. Abstract:
  6. NT specific routines for interfacing with the
  7. RAS AutoDial driver (rasacd.sys).
  8. Author:
  9. Anthony Discolo (adiscolo) 27-May-1996
  10. Revision History:
  11. Who When What
  12. -------- ----------- ---------------------------------------------
  13. adiscolo 27-May-1996 created
  14. Notes:
  15. --*/
  16. #include "precomp.h"
  17. #pragma hdrstop
  18. #ifdef RASAUTODIAL
  19. #include <acd.h>
  20. #include <acdapi.h>
  21. //
  22. // Global variables
  23. //
  24. BOOLEAN fAcdLoadedG;
  25. ACD_DRIVER AcdDriverG;
  26. ULONG ulDriverIdG = 'Rdr ';
  27. VOID
  28. RdrRetryCallServer(
  29. IN BOOLEAN fSuccess,
  30. IN PVOID *pArgs
  31. )
  32. /*++
  33. Routine Description:
  34. This routine is called indirectly by the automatic
  35. connection driver to continue the connection process
  36. after an automatic connection has been made.
  37. Arguments:
  38. fSuccess - TRUE if the connection attempt was successful.
  39. pArgs - a pointer to the argument vector
  40. Return Value:
  41. None.
  42. --*/
  43. {
  44. HANDLE hEvent = pArgs[0];
  45. #ifdef DBG
  46. DbgPrint(
  47. "RdrRetryCallServer: fSuccess=%d, hEvent=0x%x\n",
  48. fSuccess,
  49. hEvent);
  50. #endif
  51. KeSetEvent(hEvent, IO_NETWORK_INCREMENT, FALSE);
  52. } /* RdrRetryCallServer */
  53. VOID
  54. RdrAttemptAutoDial(
  55. IN PUNICODE_STRING pServer
  56. )
  57. /*++
  58. Routine Description:
  59. Call the automatic connection driver to attempt an
  60. automatic connection.
  61. Arguments:
  62. pServer - a pointer to UNICODE_STRING containing the server name
  63. Return Value:
  64. TRUE if the automatic connection was started successfully,
  65. FALSE otherwise.
  66. --*/
  67. {
  68. NTSTATUS status;
  69. ACD_ADDR addr;
  70. PVOID pArgs[1];
  71. OEM_STRING AnsiPath;
  72. KEVENT event;
  73. //
  74. // Get the address of the connection.
  75. //
  76. status = RtlUnicodeStringToOemString(&AnsiPath, pServer, TRUE);
  77. if (!NT_SUCCESS(status))
  78. return;
  79. addr.fType = ACD_ADDR_NB;
  80. RtlCopyMemory(addr.cNetbios, AnsiPath.Buffer, 16);
  81. RtlFreeOemString(&AnsiPath);
  82. #ifdef DBG
  83. DbgPrint("RdrAttemptAutoDial: Server=%-15.15s\n", addr.cNetbios);
  84. #endif
  85. //
  86. // Create an event that will be signalled
  87. // by RdrRetryCallServer when the connection
  88. // process has completed.
  89. //
  90. KeInitializeEvent(&event, SynchronizationEvent, FALSE);
  91. //
  92. // Attempt to start the connection. RdrRetryCallServer
  93. // will be called when the connection process has
  94. // completed.
  95. //
  96. pArgs[0] = &event;
  97. if (!(*AcdDriverG.lpfnStartConnection)(
  98. ulDriverIdG,
  99. &addr,
  100. 0,
  101. RdrRetryCallServer,
  102. 1,
  103. pArgs))
  104. {
  105. return;
  106. }
  107. //
  108. // Wait for the connection to complete.
  109. //
  110. status = KeWaitForSingleObject(
  111. &event,
  112. Executive,
  113. KernelMode,
  114. FALSE,
  115. NULL);
  116. } // RdrAttemptAutoDial
  117. VOID
  118. RdrAcdBind(VOID)
  119. {
  120. NTSTATUS status;
  121. UNICODE_STRING nameString;
  122. IO_STATUS_BLOCK ioStatusBlock;
  123. PIRP pIrp;
  124. PFILE_OBJECT pAcdFileObject;
  125. PDEVICE_OBJECT pAcdDeviceObject;
  126. PACD_DRIVER pDriver = &AcdDriverG;
  127. //
  128. // Initialize the name of the automatic
  129. // connection device.
  130. //
  131. RtlInitUnicodeString(&nameString, ACD_DEVICE_NAME);
  132. //
  133. // Get the file and device objects for the
  134. // device.
  135. //
  136. status = IoGetDeviceObjectPointer(
  137. &nameString,
  138. SYNCHRONIZE|GENERIC_READ|GENERIC_WRITE,
  139. &pAcdFileObject,
  140. &pAcdDeviceObject);
  141. if (status != STATUS_SUCCESS)
  142. return;
  143. //
  144. // Reference the device object.
  145. //
  146. ObReferenceObject(pAcdDeviceObject);
  147. //
  148. // Remove the reference IoGetDeviceObjectPointer()
  149. // put on the file object.
  150. //
  151. ObDereferenceObject(pAcdFileObject);
  152. //
  153. // Initialize our part of the ACD_DRIVER
  154. // structure.
  155. //
  156. KeInitializeSpinLock(&AcdDriverG.SpinLock);
  157. AcdDriverG.ulDriverId = ulDriverIdG;
  158. AcdDriverG.fEnabled = FALSE;
  159. //
  160. // Build a request to get the automatic
  161. // connection driver entry points.
  162. //
  163. pIrp = IoBuildDeviceIoControlRequest(
  164. IOCTL_INTERNAL_ACD_BIND,
  165. pAcdDeviceObject,
  166. (PVOID)&pDriver,
  167. sizeof (pDriver),
  168. NULL,
  169. 0,
  170. TRUE,
  171. NULL,
  172. &ioStatusBlock);
  173. if (pIrp == NULL) {
  174. ObDereferenceObject(pAcdDeviceObject);
  175. return;
  176. }
  177. //
  178. // Submit the request to the
  179. // automatic connection driver.
  180. //
  181. status = IoCallDriver(pAcdDeviceObject, pIrp);
  182. fAcdLoadedG = (status == STATUS_SUCCESS);
  183. //
  184. // Close the device.
  185. //
  186. ObDereferenceObject(pAcdDeviceObject);
  187. } // RdrAcdBind
  188. VOID
  189. RdrAcdUnbind(VOID)
  190. {
  191. NTSTATUS status;
  192. UNICODE_STRING nameString;
  193. IO_STATUS_BLOCK ioStatusBlock;
  194. PIRP pIrp;
  195. PFILE_OBJECT pAcdFileObject;
  196. PDEVICE_OBJECT pAcdDeviceObject;
  197. PACD_DRIVER pDriver = &AcdDriverG;
  198. //
  199. // Don't bother to uRdrnd if we
  200. // didn't successfully bind in the
  201. // first place.
  202. //
  203. if (!fAcdLoadedG)
  204. return;
  205. //
  206. // Initialize the name of the automatic
  207. // connection device.
  208. //
  209. RtlInitUnicodeString(&nameString, ACD_DEVICE_NAME);
  210. //
  211. // Get the file and device objects for the
  212. // device.
  213. //
  214. status = IoGetDeviceObjectPointer(
  215. &nameString,
  216. SYNCHRONIZE|GENERIC_READ|GENERIC_WRITE,
  217. &pAcdFileObject,
  218. &pAcdDeviceObject);
  219. if (status != STATUS_SUCCESS)
  220. return;
  221. //
  222. // Reference the device object.
  223. //
  224. ObReferenceObject(pAcdDeviceObject);
  225. //
  226. // Remove the reference IoGetDeviceObjectPointer()
  227. // put on the file object.
  228. //
  229. ObDereferenceObject(pAcdFileObject);
  230. //
  231. // Build a request to uRdrnd from
  232. // the automatic connection driver.
  233. //
  234. pIrp = IoBuildDeviceIoControlRequest(
  235. IOCTL_INTERNAL_ACD_UNBIND,
  236. pAcdDeviceObject,
  237. (PVOID)&pDriver,
  238. sizeof (pDriver),
  239. NULL,
  240. 0,
  241. TRUE,
  242. NULL,
  243. &ioStatusBlock);
  244. if (pIrp == NULL) {
  245. ObDereferenceObject(pAcdDeviceObject);
  246. return;
  247. }
  248. //
  249. // Submit the request to the
  250. // automatic connection driver.
  251. //
  252. status = IoCallDriver(pAcdDeviceObject, pIrp);
  253. //
  254. // Close the device.
  255. //
  256. ObDereferenceObject(pAcdDeviceObject);
  257. } // RdrAcdUnbind
  258. #endif // RASAUTODIAL