Source code of Windows XP (NT5)
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.

345 lines
7.4 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. mupinit.c
  5. Abstract:
  6. This module implements the DRIVER_INITIALIZATION routine for the
  7. multiple UNC provider file system.
  8. Author:
  9. Manny Weiser (mannyw) 12-17-91
  10. Revision History:
  11. --*/
  12. #include "mup.h"
  13. NTSTATUS
  14. DriverEntry(
  15. IN PDRIVER_OBJECT DriverObject,
  16. IN PUNICODE_STRING RegistryPath
  17. );
  18. VOID
  19. MupUnload(
  20. IN PDRIVER_OBJECT DriverObject
  21. );
  22. BOOLEAN
  23. MuppIsDfsEnabled();
  24. BOOLEAN
  25. MupCheckNullSessionUsage();
  26. BOOLEAN MupUseNullSessionForDfs = TRUE;
  27. //
  28. // Globals
  29. //
  30. PMUP_DEVICE_OBJECT mupDeviceObject;
  31. #ifdef ALLOC_PRAGMA
  32. #pragma alloc_text( INIT, DriverEntry )
  33. #pragma alloc_text( PAGE, MuppIsDfsEnabled )
  34. #pragma alloc_text( PAGE, MupUnload )
  35. #endif
  36. NTSTATUS MupDrvWmiDispatch(PDEVICE_OBJECT p, PIRP i);
  37. NTSTATUS
  38. DriverEntry(
  39. IN PDRIVER_OBJECT DriverObject,
  40. IN PUNICODE_STRING RegistryPath
  41. )
  42. /*++
  43. Routine Description:
  44. This is the initialization routine for the mup file system
  45. device driver. This routine creates the device object for the mup
  46. device and performs all other driver initialization.
  47. Arguments:
  48. DriverObject - Pointer to driver object created by the system.
  49. Return Value:
  50. NTSTATUS - The function value is the final status from the initialization
  51. operation.
  52. --*/
  53. {
  54. NTSTATUS status = STATUS_SUCCESS;
  55. UNICODE_STRING nameString;
  56. PDEVICE_OBJECT deviceObject;
  57. PAGED_CODE();
  58. //
  59. // Initialize MUP global data.
  60. //
  61. MupInitializeData();
  62. //
  63. // Initialize the Dfs client
  64. //
  65. MupEnableDfs = MuppIsDfsEnabled();
  66. if (MupEnableDfs) {
  67. status = DfsDriverEntry( DriverObject, RegistryPath );
  68. if (!NT_SUCCESS( status )) {
  69. MupEnableDfs = FALSE;
  70. }
  71. }
  72. //
  73. // Create the MUP device object.
  74. //
  75. RtlInitUnicodeString( &nameString, DD_MUP_DEVICE_NAME );
  76. status = IoCreateDevice( DriverObject,
  77. sizeof(MUP_DEVICE_OBJECT)-sizeof(DEVICE_OBJECT),
  78. &nameString,
  79. FILE_DEVICE_MULTI_UNC_PROVIDER,
  80. 0,
  81. FALSE,
  82. &deviceObject );
  83. if (!NT_SUCCESS( status )) {
  84. if (MupEnableDfs) {
  85. DfsUnload (DriverObject);
  86. }
  87. MupUninitializeData();
  88. return status;
  89. }
  90. DriverObject->DriverUnload = MupUnload;
  91. //
  92. // Initialize the driver object with this driver's entry points.
  93. //
  94. // 2/27/96 MilanS - Be careful with these. If you add to this list
  95. // of dispatch routines, you'll need to make appropriate calls to the
  96. // corresponding Dfs fsd routine.
  97. //
  98. DriverObject->MajorFunction[IRP_MJ_CREATE] =
  99. (PDRIVER_DISPATCH)MupCreate;
  100. DriverObject->MajorFunction[IRP_MJ_CREATE_NAMED_PIPE] =
  101. (PDRIVER_DISPATCH)MupCreate;
  102. DriverObject->MajorFunction[IRP_MJ_CREATE_MAILSLOT] =
  103. (PDRIVER_DISPATCH)MupCreate;
  104. DriverObject->MajorFunction[IRP_MJ_WRITE] =
  105. (PDRIVER_DISPATCH)MupForwardIoRequest;
  106. DriverObject->MajorFunction[IRP_MJ_FILE_SYSTEM_CONTROL] =
  107. (PDRIVER_DISPATCH)MupFsControl;
  108. DriverObject->MajorFunction[IRP_MJ_CLEANUP] =
  109. (PDRIVER_DISPATCH)MupCleanup;
  110. DriverObject->MajorFunction[IRP_MJ_CLOSE] =
  111. (PDRIVER_DISPATCH)MupClose;
  112. //
  113. DriverObject->MajorFunction[IRP_MJ_SYSTEM_CONTROL] =
  114. (PDRIVER_DISPATCH) MupDrvWmiDispatch;
  115. status = IoWMIRegistrationControl (deviceObject, WMIREG_ACTION_REGISTER);
  116. // Initialize the VCB
  117. //
  118. mupDeviceObject = (PMUP_DEVICE_OBJECT)deviceObject;
  119. MupInitializeVcb( &mupDeviceObject->Vcb );
  120. //
  121. // Return to the caller.
  122. //
  123. return( STATUS_SUCCESS );
  124. }
  125. VOID
  126. MupUnload(
  127. IN PDRIVER_OBJECT DriverObject
  128. )
  129. /*++
  130. Routine Description:
  131. This is the unload routine for the mup driver
  132. Arguments:
  133. DriverObject - Mups driver object
  134. Return Value:
  135. None
  136. --*/
  137. {
  138. IoDeleteDevice (&mupDeviceObject->DeviceObject);
  139. if (MupEnableDfs) {
  140. DfsUnload (DriverObject);
  141. }
  142. MupUninitializeData();
  143. }
  144. BOOLEAN
  145. MuppIsDfsEnabled()
  146. /*++
  147. Routine Description:
  148. This routine checks a registry key to see if the Dfs client is enabled.
  149. The client is assumed to be enabled by default, and disabled only if there
  150. is a registry value indicating that it should be disabled.
  151. Arguments:
  152. None
  153. Return Value:
  154. TRUE if Dfs client is enabled, FALSE otherwise.
  155. --*/
  156. {
  157. NTSTATUS status;
  158. HANDLE mupRegHandle;
  159. OBJECT_ATTRIBUTES objectAttributes;
  160. ULONG valueSize;
  161. BOOLEAN dfsEnabled = TRUE;
  162. #define MUP_KEY L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\Mup"
  163. #define DISABLE_DFS_VALUE_NAME L"DisableDfs"
  164. UNICODE_STRING mupRegKey = {
  165. sizeof(MUP_KEY) - sizeof(WCHAR),
  166. sizeof(MUP_KEY),
  167. MUP_KEY};
  168. UNICODE_STRING disableDfs = {
  169. sizeof(DISABLE_DFS_VALUE_NAME) - sizeof(WCHAR),
  170. sizeof(DISABLE_DFS_VALUE_NAME),
  171. DISABLE_DFS_VALUE_NAME};
  172. struct {
  173. KEY_VALUE_PARTIAL_INFORMATION Info;
  174. ULONG Buffer;
  175. } disableDfsValue;
  176. InitializeObjectAttributes(
  177. &objectAttributes,
  178. &mupRegKey,
  179. OBJ_CASE_INSENSITIVE,
  180. 0,
  181. NULL
  182. );
  183. status = ZwOpenKey(&mupRegHandle, KEY_READ, &objectAttributes);
  184. if (NT_SUCCESS(status)) {
  185. status = ZwQueryValueKey(
  186. mupRegHandle,
  187. &disableDfs,
  188. KeyValuePartialInformation,
  189. (PVOID) &disableDfsValue,
  190. sizeof(disableDfsValue),
  191. &valueSize);
  192. if (NT_SUCCESS(status) && disableDfsValue.Info.Type == REG_DWORD) {
  193. if ( (*((PULONG) disableDfsValue.Info.Data)) == 1 )
  194. dfsEnabled = FALSE;
  195. }
  196. ZwClose( mupRegHandle );
  197. }
  198. return( dfsEnabled );
  199. }
  200. BOOLEAN
  201. MupCheckNullSessionUsage()
  202. {
  203. NTSTATUS status;
  204. HANDLE mupRegHandle;
  205. OBJECT_ATTRIBUTES objectAttributes;
  206. ULONG valueSize;
  207. BOOLEAN NullSessionEnabled = FALSE;
  208. #define MUP_KEY L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\Mup"
  209. #define DFS_NULL_SESSION_VALUE_NAME L"DfsUseNullSession"
  210. UNICODE_STRING mupRegKey = {
  211. sizeof(MUP_KEY) - sizeof(WCHAR),
  212. sizeof(MUP_KEY),
  213. MUP_KEY};
  214. UNICODE_STRING UseNullSession = {
  215. sizeof(DFS_NULL_SESSION_VALUE_NAME) - sizeof(WCHAR),
  216. sizeof(DFS_NULL_SESSION_VALUE_NAME),
  217. DFS_NULL_SESSION_VALUE_NAME};
  218. struct {
  219. KEY_VALUE_PARTIAL_INFORMATION Info;
  220. ULONG Buffer;
  221. } DfsUseNullSessionValue;
  222. InitializeObjectAttributes(
  223. &objectAttributes,
  224. &mupRegKey,
  225. OBJ_CASE_INSENSITIVE,
  226. 0,
  227. NULL
  228. );
  229. status = ZwOpenKey(&mupRegHandle, KEY_READ, &objectAttributes);
  230. if (NT_SUCCESS(status)) {
  231. status = ZwQueryValueKey(
  232. mupRegHandle,
  233. &UseNullSession,
  234. KeyValuePartialInformation,
  235. (PVOID) &DfsUseNullSessionValue,
  236. sizeof(DfsUseNullSessionValue),
  237. &valueSize);
  238. if (NT_SUCCESS(status) && DfsUseNullSessionValue.Info.Type == REG_DWORD) {
  239. if ( (*((PULONG) DfsUseNullSessionValue.Info.Data)) == 1 )
  240. NullSessionEnabled = TRUE;
  241. }
  242. ZwClose( mupRegHandle );
  243. }
  244. return( NullSessionEnabled );
  245. }