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.

294 lines
6.4 KiB

  1. /****************************************************************************/
  2. // ntdd.c
  3. //
  4. // Standard NT driver initialization, for inclusion in each of the TS
  5. // stack drivers.
  6. //
  7. // Copyright (C) 1997-1999 Microsoft Corp.
  8. /****************************************************************************/
  9. #include "precomp.h"
  10. #pragma hdrstop
  11. #define DEVICE_NAME_PREFIX L"\\Device\\"
  12. //
  13. // Global data
  14. //
  15. PDEVICE_OBJECT DrvDeviceObject;
  16. //
  17. // External references
  18. //
  19. // This is the name of the WD/TD/PD module we are initializing as.
  20. extern const PWCHAR ModuleName;
  21. // Global code page caching data to be initialized and freed in asmint.c.
  22. extern FAST_MUTEX fmCodePage;
  23. extern ULONG LastCodePageTranslated;
  24. extern PVOID LastNlsTableBuffer;
  25. extern UINT NlsTableUseCount;
  26. // This is the stack driver module entry point defined in ntos\citrix\inc\sdapi.h
  27. NTSTATUS
  28. _stdcall
  29. ModuleEntry(
  30. IN OUT PSDCONTEXT pSdContext,
  31. IN BOOLEAN bLoad
  32. );
  33. //
  34. // Forward refrences
  35. //
  36. VOID DrvUnload( PDRIVER_OBJECT );
  37. NTSTATUS
  38. DrvDispatch(
  39. IN PDEVICE_OBJECT DeviceObject,
  40. IN PIRP Irp
  41. );
  42. NTSTATUS
  43. DriverEntry(
  44. IN PDRIVER_OBJECT DriverObject,
  45. IN PUNICODE_STRING RegistryPath
  46. )
  47. /*++
  48. Routine Description:
  49. Standard NT driver entry routine.
  50. Arguments:
  51. DriverObject - NT passed driver object
  52. RegistryPath - Path to driver specific registry entry
  53. Return Value:
  54. NTSTATUS code.
  55. Environment:
  56. Kernel mode, DDK
  57. --*/
  58. {
  59. ULONG i;
  60. NTSTATUS Status;
  61. UNICODE_STRING DeviceName;
  62. PWCHAR NameBuffer;
  63. ULONG NameSize;
  64. PAGED_CODE( );
  65. NameSize = sizeof(DEVICE_NAME_PREFIX) + sizeof(WCHAR);
  66. NameSize += (wcslen(ModuleName) * sizeof(WCHAR));
  67. NameBuffer = ExAllocatePool( NonPagedPool, NameSize );
  68. if( NameBuffer == NULL ) {
  69. return( STATUS_INSUFFICIENT_RESOURCES );
  70. }
  71. wcscpy( NameBuffer, DEVICE_NAME_PREFIX );
  72. wcscat( NameBuffer, ModuleName );
  73. RtlInitUnicodeString( &DeviceName, NameBuffer );
  74. Status = IoCreateDevice(
  75. DriverObject,
  76. 0, // No DeviceExtension
  77. &DeviceName,
  78. FILE_DEVICE_TERMSRV,
  79. 0,
  80. FALSE,
  81. &DrvDeviceObject
  82. );
  83. if( !NT_SUCCESS(Status) ) {
  84. ExFreePool( NameBuffer );
  85. return( Status );
  86. }
  87. DriverObject->DriverUnload = DrvUnload;
  88. DriverObject->FastIoDispatch = NULL;
  89. for (i = 0; i <= IRP_MJ_MAXIMUM_FUNCTION; i++) {
  90. DriverObject->MajorFunction[i] = DrvDispatch;
  91. }
  92. // Init code page handling info from asmint.c.
  93. ExInitializeFastMutex(&fmCodePage);
  94. LastCodePageTranslated = 0;
  95. LastNlsTableBuffer = NULL;
  96. NlsTableUseCount = 0;
  97. DrvDeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
  98. ExFreePool( NameBuffer );
  99. return( Status );
  100. }
  101. VOID
  102. DrvUnload(
  103. IN PDRIVER_OBJECT DriverObject
  104. )
  105. /*++
  106. Routine Description:
  107. Driver unload routine.
  108. Arguments:
  109. DriverObject - Driver object being unloaded.
  110. Return Value:
  111. None.
  112. Environment:
  113. Kernel mode, DDK
  114. --*/
  115. {
  116. PAGED_CODE( );
  117. // Free remaining code page data on exit, if it exists.
  118. if (LastNlsTableBuffer != NULL) {
  119. ExFreePool(LastNlsTableBuffer);
  120. LastNlsTableBuffer = NULL;
  121. }
  122. IoDeleteDevice( DrvDeviceObject );
  123. return;
  124. }
  125. NTSTATUS
  126. DrvDispatch(
  127. IN PDEVICE_OBJECT DeviceObject,
  128. IN PIRP Irp
  129. )
  130. /*++
  131. Routine Description:
  132. This is the dispatch routine for the driver.
  133. Arguments:
  134. DeviceObject - Pointer to device object for target device
  135. Irp - Pointer to I/O request packet
  136. Return Value:
  137. NTSTATUS -- Indicates whether the request was successfully queued.
  138. Environment:
  139. Kernel mode, DDK
  140. --*/
  141. {
  142. PIO_STACK_LOCATION irpSp;
  143. KIRQL saveIrql;
  144. NTSTATUS Status;
  145. PSD_MODULE_INIT pmi;
  146. DeviceObject; // prevent compiler warnings
  147. irpSp = IoGetCurrentIrpStackLocation( Irp );
  148. switch ( irpSp->MajorFunction ) {
  149. case IRP_MJ_CREATE:
  150. if( Irp->RequestorMode != KernelMode ) {
  151. Status = STATUS_ACCESS_DENIED;
  152. Irp->IoStatus.Status = Status;
  153. IoCompleteRequest( Irp, 0 );
  154. return( Status );
  155. }
  156. Status = STATUS_SUCCESS;
  157. Irp->IoStatus.Status = Status;
  158. IoCompleteRequest( Irp, 0 );
  159. return Status;
  160. case IRP_MJ_INTERNAL_DEVICE_CONTROL:
  161. if( Irp->RequestorMode != KernelMode ) {
  162. Status = STATUS_NOT_IMPLEMENTED;
  163. Irp->IoStatus.Status = Status;
  164. IoCompleteRequest( Irp, 0 );
  165. return( Status );
  166. }
  167. if( irpSp->Parameters.DeviceIoControl.IoControlCode !=
  168. IOCTL_SD_MODULE_INIT ) {
  169. Status = STATUS_NOT_IMPLEMENTED;
  170. Irp->IoStatus.Status = Status;
  171. IoCompleteRequest( Irp, 0 );
  172. return( Status );
  173. }
  174. if( irpSp->Parameters.DeviceIoControl.OutputBufferLength <
  175. sizeof(SD_MODULE_INIT) ) {
  176. Status = STATUS_BUFFER_TOO_SMALL;
  177. Irp->IoStatus.Status = Status;
  178. IoCompleteRequest( Irp, 0 );
  179. return( Status );
  180. }
  181. // Return the SD module entry point.
  182. pmi = (PSD_MODULE_INIT)Irp->UserBuffer;
  183. pmi->SdLoadProc = ModuleEntry;
  184. Status = STATUS_SUCCESS;
  185. Irp->IoStatus.Information = sizeof(SD_MODULE_INIT);
  186. Irp->IoStatus.Status = Status;
  187. IoCompleteRequest( Irp, 0 );
  188. return Status;
  189. case IRP_MJ_CLEANUP:
  190. Status = STATUS_SUCCESS;
  191. Irp->IoStatus.Status = Status;
  192. IoCompleteRequest( Irp, 0 );
  193. return Status;
  194. case IRP_MJ_CLOSE:
  195. Status = STATUS_SUCCESS;
  196. Irp->IoStatus.Status = Status;
  197. IoCompleteRequest( Irp, 0 );
  198. return Status;
  199. default:
  200. Irp->IoStatus.Status = STATUS_NOT_IMPLEMENTED;
  201. IoCompleteRequest( Irp, 0 );
  202. return STATUS_NOT_IMPLEMENTED;
  203. }
  204. }