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.

246 lines
5.5 KiB

  1. #include "stdarg.h"
  2. #include "stdio.h"
  3. #include "stddef.h"
  4. #include <ntddk.h>
  5. #include <initguid.h>
  6. #include "common.h"
  7. //
  8. // Include the biggie...
  9. //
  10. #include "wdmsec.h"
  11. #define DEFAULT_EXTENSION_SIZE 0x100
  12. #define DEFAULT_DEVICE_NAME L"\\Device\\IoCreateDeviceSecure"
  13. #define DEFAULT_DEVICE_TYPE FILE_DEVICE_UNKNOWN
  14. #define DEFAULT_DEVICE_CHARACTERISTICS FILE_DEVICE_SECURE_OPEN
  15. //
  16. // Log levels
  17. //
  18. #define SAMPLE_LEVEL_ERROR 0
  19. #define SAMPLE_LEVEL_INFO 1
  20. #define SAMPLE_LEVEL_VERBOSE 2
  21. #define SAMPLE_DEFAULT_DEBUG_LEVEL 1
  22. //
  23. // Make it a global, so we can change it on the fly...
  24. //
  25. extern LONG g_DebugLevel;
  26. #if DBG
  27. #define SD_KdPrint(_l_, _x_) \
  28. if (_l_ <= g_DebugLevel ) { \
  29. DbgPrint ("WdmSecTest: "); \
  30. DbgPrint _x_; \
  31. }
  32. #define TRAP() DbgBreakPoint()
  33. #else
  34. #define SD_KdPrint(_l_, _x_)
  35. #define TRAP()
  36. #endif
  37. //
  38. // A device extension for the device object
  39. //
  40. typedef struct _SD_FDO_DATA {
  41. ULONG PdoSignature; // we use this do distinguish our FDO
  42. // from the test PDOs we create
  43. BOOLEAN IsStarted; // This flag is set when is started.
  44. BOOLEAN IsRemoved; // This flag is set when the device
  45. // is removed.
  46. BOOLEAN HoldNewRequests; // This flag is set whenever the
  47. // device needs to queue incoming
  48. // requests (when it receives a
  49. // QUERY_STOP or QUERY_REMOVE).
  50. BOOLEAN IsLegacy ; // TRUE if the device is created
  51. // using IoReportDetectedDevice
  52. LIST_ENTRY NewRequestsQueue; // The queue where the incoming
  53. // requests are queued when
  54. // HoldNewRequests is set.
  55. PDEVICE_OBJECT Self; // a back pointer to the DeviceObject.
  56. PDEVICE_OBJECT PDO; // The PDO to which the FDO is attached.
  57. PDEVICE_OBJECT NextLowerDriver; // The top of the device stack just
  58. // beneath this device object.
  59. KEVENT StartEvent; // an event to sync the start IRP.
  60. KEVENT RemoveEvent; // an event to synch outstandIO to zero.
  61. ULONG OutstandingIO; // 1 biased count of reasons why
  62. // this object should stick around.
  63. UNICODE_STRING DeviceInterfaceName; // The thing we need for the
  64. // the user-modeto get a handle on
  65. // us...
  66. SYSTEM_POWER_STATE SystemPowerState; // The general power state
  67. DEVICE_POWER_STATE DevicePowerState; // The power state of the device
  68. PDRIVER_OBJECT DriverObject;
  69. LIST_ENTRY PdoList;
  70. KSPIN_LOCK Lock;
  71. } SD_FDO_DATA, *PSD_FDO_DATA;
  72. //
  73. // The list of PDOs
  74. //
  75. typedef struct _PDO_ENTRY {
  76. LIST_ENTRY Link;
  77. PDEVICE_OBJECT Pdo;
  78. } PDO_ENTRY, *PPDO_ENTRY;
  79. //
  80. // Globals
  81. //
  82. extern PDRIVER_OBJECT g_DriverObject;
  83. NTSTATUS
  84. DriverEntry(
  85. IN PDRIVER_OBJECT DriverObject,
  86. IN PUNICODE_STRING RegistryPath
  87. ) ;
  88. NTSTATUS
  89. SD_AddDevice(
  90. IN PDRIVER_OBJECT DriverObject,
  91. IN PDEVICE_OBJECT PhysicalDeviceObject
  92. ) ;
  93. NTSTATUS
  94. SD_Pass (
  95. IN PDEVICE_OBJECT DeviceObject,
  96. IN PIRP Irp
  97. );
  98. NTSTATUS
  99. SD_DispatchPower (
  100. IN PDEVICE_OBJECT DeviceObject,
  101. IN PIRP Irp
  102. );
  103. NTSTATUS
  104. SD_DispatchPnp (
  105. IN PDEVICE_OBJECT DeviceObject,
  106. IN PIRP Irp
  107. );
  108. NTSTATUS
  109. SD_CreateClose (
  110. IN PDEVICE_OBJECT DeviceObject,
  111. IN PIRP Irp
  112. );
  113. NTSTATUS
  114. SD_Ioctl (
  115. IN PDEVICE_OBJECT DeviceObject,
  116. IN PIRP Irp
  117. );
  118. NTSTATUS
  119. SD_StartDevice (
  120. IN PSD_FDO_DATA FdoData,
  121. IN PIRP Irp
  122. );
  123. NTSTATUS
  124. SD_DispatchPnpComplete (
  125. IN PDEVICE_OBJECT DeviceObject,
  126. IN PIRP Irp,
  127. IN PVOID Context
  128. );
  129. VOID
  130. SD_Unload(
  131. IN PDRIVER_OBJECT DriverObject
  132. );
  133. LONG
  134. SD_IoIncrement (
  135. IN PSD_FDO_DATA FdoData
  136. ) ;
  137. LONG
  138. SD_IoDecrement (
  139. IN PSD_FDO_DATA FdoData
  140. ) ;
  141. //
  142. // Test (new) functions
  143. //
  144. NTSTATUS
  145. WdmSecTestName (
  146. IN PSD_FDO_DATA FdoData
  147. );
  148. NTSTATUS
  149. WdmSecTestCreateWithGuid (
  150. IN PSD_FDO_DATA FdoData,
  151. IN OUT PWST_CREATE_WITH_GUID Create
  152. );
  153. NTSTATUS
  154. WdmSecTestCreateNoGuid (
  155. IN PSD_FDO_DATA FdoData,
  156. IN OUT PWST_CREATE_NO_GUID Create
  157. );
  158. NTSTATUS
  159. WdmSecTestCreateObject (
  160. IN PSD_FDO_DATA FdoData,
  161. IN OUT PWST_CREATE_OBJECT Data
  162. );
  163. NTSTATUS
  164. WdmSecTestGetSecurity (
  165. IN PSD_FDO_DATA FdoData,
  166. IN OUT PWST_GET_SECURITY Data
  167. );
  168. NTSTATUS
  169. WdmSecTestDestroyObject (
  170. IN PSD_FDO_DATA FdoData,
  171. IN OUT PWST_DESTROY_OBJECT Data
  172. );