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.

349 lines
8.9 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. dispatch.c
  5. Abstract:
  6. This module contains the dispatch routines for AFD.
  7. Author:
  8. David Treadwell (davidtr) 21-Feb-1992
  9. Revision History:
  10. --*/
  11. #include "afdp.h"
  12. #ifdef ALLOC_PRAGMA
  13. #pragma alloc_text( PAGEAFD, AfdDispatch )
  14. #pragma alloc_text( PAGEAFD, AfdDispatchDeviceControl )
  15. #endif
  16. NTSTATUS
  17. AfdDispatch (
  18. IN PDEVICE_OBJECT DeviceObject,
  19. IN PIRP Irp
  20. )
  21. /*++
  22. Routine Description:
  23. This is the dispatch routine for AFD.
  24. Arguments:
  25. DeviceObject - Pointer to device object for target device
  26. Irp - Pointer to I/O request packet
  27. Return Value:
  28. NTSTATUS -- Indicates whether the request was successfully queued.
  29. --*/
  30. {
  31. PIO_STACK_LOCATION irpSp;
  32. NTSTATUS status;
  33. #if DBG
  34. KIRQL currentIrql;
  35. currentIrql = KeGetCurrentIrql( );
  36. #endif
  37. irpSp = IoGetCurrentIrpStackLocation( Irp );
  38. switch ( irpSp->MajorFunction ) {
  39. case IRP_MJ_WRITE:
  40. //
  41. // Make the IRP look like a send IRP.
  42. //
  43. ASSERT( FIELD_OFFSET( IO_STACK_LOCATION, Parameters.Write.Length ) ==
  44. FIELD_OFFSET( IO_STACK_LOCATION, Parameters.DeviceIoControl.OutputBufferLength ) );
  45. ASSERT( FIELD_OFFSET( IO_STACK_LOCATION, Parameters.Write.Key ) ==
  46. FIELD_OFFSET( IO_STACK_LOCATION, Parameters.DeviceIoControl.InputBufferLength ) );
  47. irpSp->Parameters.Write.Key = 0;
  48. if (IS_SAN_ENDPOINT ((PAFD_ENDPOINT)irpSp->FileObject->FsContext)) {
  49. status = AfdSanRedirectRequest (Irp, irpSp);
  50. }
  51. else {
  52. status = AfdSend( Irp, irpSp );
  53. }
  54. ASSERT( KeGetCurrentIrql( ) == currentIrql );
  55. return status;
  56. case IRP_MJ_READ:
  57. //
  58. // Make the IRP look like a receive IRP.
  59. //
  60. ASSERT( FIELD_OFFSET( IO_STACK_LOCATION, Parameters.Read.Length ) ==
  61. FIELD_OFFSET( IO_STACK_LOCATION, Parameters.DeviceIoControl.OutputBufferLength ) );
  62. ASSERT( FIELD_OFFSET( IO_STACK_LOCATION, Parameters.Read.Key ) ==
  63. FIELD_OFFSET( IO_STACK_LOCATION, Parameters.DeviceIoControl.InputBufferLength ) );
  64. irpSp->Parameters.Read.Key = 0;
  65. if (IS_SAN_ENDPOINT ((PAFD_ENDPOINT)irpSp->FileObject->FsContext)) {
  66. status = AfdSanRedirectRequest (Irp, irpSp);
  67. }
  68. else {
  69. status = AfdReceive( Irp, irpSp );
  70. }
  71. ASSERT( KeGetCurrentIrql( ) == currentIrql );
  72. return status;
  73. case IRP_MJ_CREATE:
  74. status = AfdCreate( Irp, irpSp );
  75. ASSERT( KeGetCurrentIrql( ) == currentIrql );
  76. Irp->IoStatus.Status = status;
  77. IoCompleteRequest( Irp, AfdPriorityBoost );
  78. return status;
  79. case IRP_MJ_CLEANUP:
  80. status = AfdCleanup( Irp, irpSp );
  81. Irp->IoStatus.Status = status;
  82. IoCompleteRequest( Irp, AfdPriorityBoost );
  83. ASSERT( KeGetCurrentIrql( ) == currentIrql );
  84. return status;
  85. case IRP_MJ_CLOSE:
  86. status = AfdClose( Irp, irpSp );
  87. Irp->IoStatus.Status = status;
  88. IoCompleteRequest( Irp, AfdPriorityBoost );
  89. ASSERT( KeGetCurrentIrql( ) == currentIrql );
  90. return status;
  91. case IRP_MJ_PNP:
  92. status = AfdPnpPower (Irp, irpSp );
  93. ASSERT( KeGetCurrentIrql( ) == currentIrql );
  94. return status;
  95. case IRP_MJ_DEVICE_CONTROL:
  96. return AfdDispatchDeviceControl( DeviceObject, Irp );
  97. case IRP_MJ_QUERY_SECURITY:
  98. status = AfdGetSecurity (
  99. irpSp->FileObject->FsContext,
  100. irpSp->Parameters.QuerySecurity.SecurityInformation,
  101. irpSp->Parameters.QuerySecurity.Length,
  102. Irp->UserBuffer,
  103. &Irp->IoStatus.Information
  104. );
  105. ASSERT( KeGetCurrentIrql( ) == currentIrql );
  106. Irp->IoStatus.Status = status;
  107. IoCompleteRequest( Irp, AfdPriorityBoost );
  108. return status;
  109. case IRP_MJ_SET_SECURITY:
  110. status = AfdSetSecurity (
  111. irpSp->FileObject->FsContext,
  112. irpSp->Parameters.SetSecurity.SecurityInformation,
  113. irpSp->Parameters.SetSecurity.SecurityDescriptor
  114. );
  115. ASSERT( KeGetCurrentIrql( ) == currentIrql );
  116. Irp->IoStatus.Status = status;
  117. IoCompleteRequest( Irp, AfdPriorityBoost );
  118. return status;
  119. default:
  120. KdPrintEx(( DPFLTR_WSOCKTRANSPORT_ID, DPFLTR_INFO_LEVEL,
  121. "AfdDispatch: Invalid major function %lx\n",
  122. irpSp->MajorFunction ));
  123. Irp->IoStatus.Status = STATUS_NOT_IMPLEMENTED;
  124. IoCompleteRequest( Irp, AfdPriorityBoost );
  125. return STATUS_NOT_IMPLEMENTED;
  126. }
  127. } // AfdDispatch
  128. NTSTATUS
  129. AfdDispatchDeviceControl (
  130. IN PDEVICE_OBJECT DeviceObject,
  131. IN PIRP Irp
  132. )
  133. /*++
  134. Routine Description:
  135. This is the dispatch routine for AFD IOCTLs.
  136. Arguments:
  137. DeviceObject - Pointer to device object for target device
  138. Irp - Pointer to I/O request packet
  139. Return Value:
  140. NTSTATUS -- Indicates whether the request was successfully queued.
  141. --*/
  142. {
  143. ULONG code;
  144. ULONG request;
  145. NTSTATUS status;
  146. PAFD_IRP_CALL irpProc;
  147. PIO_STACK_LOCATION IrpSp = IoGetCurrentIrpStackLocation (Irp);
  148. #if DBG
  149. KIRQL currentIrql;
  150. currentIrql = KeGetCurrentIrql( );
  151. #endif
  152. UNREFERENCED_PARAMETER (DeviceObject);
  153. //
  154. // Extract the IOCTL control code and process the request.
  155. //
  156. code = IrpSp->Parameters.DeviceIoControl.IoControlCode;
  157. request = _AFD_REQUEST(code);
  158. if( request < AFD_NUM_IOCTLS && AfdIoctlTable[request] == code ) {
  159. //
  160. // Helps in debugging.
  161. //
  162. IrpSp->MinorFunction = (UCHAR)request;
  163. //
  164. // Try IRP dispatch first
  165. //
  166. irpProc = AfdIrpCallDispatch[request];
  167. if (irpProc!=NULL) {
  168. status = (*irpProc)(Irp, IrpSp);
  169. ASSERT( KeGetCurrentIrql( ) == currentIrql );
  170. return status;
  171. }
  172. }
  173. //
  174. // This is currently not used by helper dlls.
  175. // Commented out because of security concerns
  176. //
  177. #if 0
  178. else if (request==AFD_TRANSPORT_IOCTL) {
  179. //
  180. // This is a "special" used to pass request
  181. // to transport driver using socket handle in
  182. // order to facilitate proper completion
  183. // on sockets associated with completion port.
  184. // It accepts and properly handles all methods.
  185. //
  186. status = AfdDoTransportIoctl (Irp, IrpSp);
  187. ASSERT( KeGetCurrentIrql() == currentIrql );
  188. return status;
  189. }
  190. #endif
  191. //
  192. // If we made it this far, then the ioctl is invalid.
  193. //
  194. KdPrintEx(( DPFLTR_WSOCKTRANSPORT_ID, DPFLTR_WARNING_LEVEL,
  195. "AfdDispatchDeviceControl: invalid IOCTL %08lX\n",
  196. code
  197. ));
  198. Irp->IoStatus.Status = STATUS_INVALID_DEVICE_REQUEST;
  199. IoCompleteRequest( Irp, AfdPriorityBoost );
  200. return STATUS_INVALID_DEVICE_REQUEST;
  201. } // AfdDispatchDeviceControl
  202. NTSTATUS
  203. FASTCALL
  204. AfdDispatchImmediateIrp(
  205. IN PIRP Irp,
  206. IN PIO_STACK_LOCATION IrpSp
  207. )
  208. {
  209. PAFD_IMMEDIATE_CALL immProc;
  210. ULONG code;
  211. ULONG request;
  212. NTSTATUS status;
  213. #if DBG
  214. KIRQL currentIrql;
  215. currentIrql = KeGetCurrentIrql( );
  216. #endif
  217. code = IrpSp->Parameters.DeviceIoControl.IoControlCode;
  218. request = _AFD_REQUEST(code);
  219. immProc = AfdImmediateCallDispatch[request];
  220. if (immProc!=NULL) {
  221. //
  222. // Must be METHOD_NEITHER for the below code to be
  223. // valid.
  224. //
  225. ASSERT ( (code & 3) == METHOD_NEITHER );
  226. #if DBG
  227. if (Irp->RequestorMode!=KernelMode) {
  228. KdPrintEx(( DPFLTR_WSOCKTRANSPORT_ID, DPFLTR_WARNING_LEVEL,
  229. "AfdDispatchDeviceControl: "
  230. "User mode application somehow bypassed fast io dispatch\n"));
  231. }
  232. #endif
  233. status = (*immProc) (
  234. IrpSp->FileObject,
  235. code,
  236. Irp->RequestorMode,
  237. IrpSp->Parameters.DeviceIoControl.Type3InputBuffer,
  238. IrpSp->Parameters.DeviceIoControl.InputBufferLength,
  239. Irp->UserBuffer,
  240. IrpSp->Parameters.DeviceIoControl.OutputBufferLength,
  241. &Irp->IoStatus.Information
  242. );
  243. ASSERT( KeGetCurrentIrql( ) == currentIrql );
  244. }
  245. else {
  246. ASSERT (!"Missing IOCTL in dispatch table!!!");
  247. status = STATUS_INVALID_DEVICE_REQUEST;
  248. }
  249. Irp->IoStatus.Status = status;
  250. IoCompleteRequest( Irp, AfdPriorityBoost );
  251. return status;
  252. }