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.

522 lines
12 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. init.c
  5. Abstract:
  6. This module contains the initialization code of the NT browser
  7. File System Driver (FSD) and File System Process (FSP).
  8. Author:
  9. Larry Osterman (larryo) 24-May-1990
  10. Environment:
  11. Kernel mode, FSD, and FSP
  12. Revision History:
  13. 30-May-1990 LarryO
  14. Created
  15. --*/
  16. //
  17. // Include modules
  18. //
  19. #include "precomp.h"
  20. #pragma hdrstop
  21. HANDLE
  22. BowserServerAnnouncementEventHandle = {0};
  23. PKEVENT
  24. BowserServerAnnouncementEvent = {0};
  25. PDOMAIN_INFO BowserPrimaryDomainInfo = NULL;
  26. // External functions
  27. //(fsctl.c)
  28. NTSTATUS
  29. StopBowser (
  30. IN BOOLEAN Wait,
  31. IN BOOLEAN InFsd,
  32. IN PBOWSER_FS_DEVICE_OBJECT DeviceObject,
  33. IN PLMDR_REQUEST_PACKET InputBuffer,
  34. IN ULONG InputBufferLength
  35. );
  36. // Local functions
  37. VOID
  38. BowserReadBowserConfiguration(
  39. PUNICODE_STRING RegistryPath
  40. );
  41. #ifdef ALLOC_PRAGMA
  42. #pragma alloc_text(INIT, BowserDriverEntry)
  43. #pragma alloc_text(PAGE, BowserUnload)
  44. #pragma alloc_text(INIT, BowserReadBowserConfiguration)
  45. #endif
  46. NTSTATUS
  47. BowserDriverEntry(
  48. IN PDRIVER_OBJECT DriverObject,
  49. IN PUNICODE_STRING RegistryPath
  50. )
  51. /*++
  52. Routine Description:
  53. This is the initialization routine for the file system. It is invoked once
  54. when the driver is loaded into the system. Its job is to initialize all
  55. the structures which will be used by the FSD and the FSP. It also creates
  56. the process from which all of the file system threads will be executed. It
  57. then registers the file system with the I/O system as a valid file system
  58. resident in the system.
  59. Arguments:
  60. DriverObject - Pointer to driver object created by the system.
  61. Return Value:
  62. None.
  63. --*/
  64. {
  65. NTSTATUS Status;
  66. UNICODE_STRING unicodeEventName;
  67. UNICODE_STRING DummyDomain;
  68. PDEVICE_OBJECT DeviceObject;
  69. OBJECT_ATTRIBUTES obja;
  70. PAGED_CODE();
  71. #if DBG
  72. BowserInitializeTraceLog();
  73. #endif
  74. //
  75. // Create the device object for this file system.
  76. //
  77. RtlInitUnicodeString( &BowserNameString, DD_BROWSER_DEVICE_NAME_U );
  78. dlog(DPRT_INIT, ("Creating device %wZ\n", &BowserNameString));
  79. #if DBG
  80. #define BOWSER_LOAD_BP 0
  81. #if BOWSER_LOAD_BP
  82. dlog(DPRT_INIT, ("DebugBreakPoint...\n"));
  83. DbgBreakPoint();
  84. #endif
  85. #endif
  86. dlog(DPRT_INIT, ("DriverObject at %08lx\n", DriverObject));
  87. Status = IoCreateDevice( DriverObject,
  88. sizeof(BOWSER_FS_DEVICE_OBJECT) - sizeof(DEVICE_OBJECT),
  89. &BowserNameString,
  90. FILE_DEVICE_NETWORK_BROWSER,
  91. 0,
  92. FALSE,
  93. &DeviceObject );
  94. if (!NT_SUCCESS(Status)) {
  95. InternalError(("Unable to create redirector device"));
  96. }
  97. dlog(DPRT_INIT, ("Device created at %08lx\n", DeviceObject));
  98. Status = BowserInitializeSecurity(DeviceObject);
  99. if (!NT_SUCCESS(Status)) {
  100. InternalError(("Unable to initialize security."));
  101. }
  102. dlog(DPRT_INIT, ("Initialized Browser security at %p\n", g_pBowSecurityDescriptor));
  103. ExInitializeResourceLite( &BowserDataResource );
  104. //
  105. // Save the device object address for this file system driver.
  106. //
  107. BowserDeviceObject = (PBOWSER_FS_DEVICE_OBJECT )DeviceObject;
  108. BowserReadBowserConfiguration(RegistryPath);
  109. DeviceObject->StackSize = (CCHAR)BowserIrpStackSize;
  110. dlog(DPRT_INIT, ("Stacksize is %d\n",DeviceObject->StackSize));
  111. //
  112. // Initialize the TDI package
  113. //
  114. BowserpInitializeTdi();
  115. //
  116. // Initialize the datagram buffer structures
  117. //
  118. BowserpInitializeMailslot();
  119. BowserInitializeFsd();
  120. BowserpInitializeIrpQueue();
  121. //
  122. // Initialize the code to receive a browser server list.
  123. //
  124. BowserpInitializeGetBrowserServerList();
  125. //
  126. // Initialize the bowser FSP.
  127. //
  128. if (!NT_SUCCESS(Status = BowserpInitializeFsp(DriverObject))) {
  129. return Status;
  130. }
  131. if (!NT_SUCCESS(Status = BowserpInitializeNames())) {
  132. return Status;
  133. }
  134. #if DBG
  135. //
  136. // If we have a preconfigured trace level, open the browser trace log
  137. // right away.
  138. //
  139. if (BowserDebugLogLevel != 0) {
  140. BowserOpenTraceLogFile(L"\\SystemRoot\\Bowser.Log");
  141. }
  142. #endif
  143. // //
  144. // // Set up the browsers unload routine.
  145. // //
  146. //
  147. // DriverObject->DriverUnload = BowserUnload;
  148. BowserInitializeDiscardableCode();
  149. //
  150. // Set the timer up for the idle timer.
  151. //
  152. IoInitializeTimer((PDEVICE_OBJECT )BowserDeviceObject, BowserIdleTimer,
  153. NULL);
  154. RtlInitUnicodeString( &unicodeEventName, SERVER_ANNOUNCE_EVENT_W );
  155. InitializeObjectAttributes( &obja, &unicodeEventName, OBJ_OPENIF, NULL, NULL );
  156. Status = ZwCreateEvent(
  157. &BowserServerAnnouncementEventHandle,
  158. SYNCHRONIZE | EVENT_QUERY_STATE | EVENT_MODIFY_STATE,
  159. &obja,
  160. SynchronizationEvent,
  161. FALSE
  162. );
  163. if (NT_SUCCESS(Status)) {
  164. Status = ObReferenceObjectByHandle(BowserServerAnnouncementEventHandle,
  165. EVENT_MODIFY_STATE,
  166. NULL,
  167. KernelMode,
  168. &BowserServerAnnouncementEvent,
  169. NULL);
  170. }
  171. //
  172. // Always create a domain structure for the primary domain.
  173. //
  174. RtlInitUnicodeString( &DummyDomain, NULL );
  175. BowserPrimaryDomainInfo = BowserCreateDomain( &DummyDomain, &DummyDomain );
  176. return Status;
  177. }
  178. VOID
  179. BowserUnload(
  180. IN PDRIVER_OBJECT DriverObject
  181. )
  182. /*++
  183. Routine Description:
  184. This is the unload routine for the bowser device.
  185. Arguments:
  186. DriverObject - pointer to the driver object for the browser driver
  187. Return Value:
  188. None
  189. --*/
  190. {
  191. PAGED_CODE();
  192. if ( BowserData.Initialized ){
  193. //
  194. // StopBowser was never called (mem cleanup skipped etc).
  195. // Call it before exiting (see bug 359407).
  196. //
  197. // Fake (unused) paramters
  198. BOWSER_FS_DEVICE_OBJECT fsDevice;
  199. LMDR_REQUEST_PACKET InputBuffer;
  200. fsDevice.DeviceObject = *DriverObject->DeviceObject;
  201. // set fake input buffer. It is unused (except param check) in
  202. // StopBowser
  203. InputBuffer.Version = LMDR_REQUEST_PACKET_VERSION_DOM;
  204. ASSERT ((IoGetCurrentProcess() == BowserFspProcess));
  205. (VOID) StopBowser(
  206. TRUE,
  207. TRUE,
  208. &fsDevice,
  209. &InputBuffer,
  210. sizeof(LMDR_REQUEST_PACKET) );
  211. }
  212. //
  213. // Ditch the global reference to the primary domain.
  214. //
  215. if ( BowserPrimaryDomainInfo != NULL ) {
  216. // break if we're leaking memory. StopBowser should
  217. // have cleaned all references.
  218. ASSERT ( BowserPrimaryDomainInfo->ReferenceCount == 1 );
  219. BowserDereferenceDomain( BowserPrimaryDomainInfo );
  220. }
  221. //
  222. // Uninitialize the bowser name structures.
  223. //
  224. BowserpUninitializeNames();
  225. //
  226. // Uninitialize the bowser FSP.
  227. //
  228. BowserpUninitializeFsp();
  229. //
  230. // Uninitialize the routines involved in retrieving browser server lists.
  231. //
  232. BowserpUninitializeGetBrowserServerList();
  233. //
  234. // Uninitialize the mailslot related functions.
  235. //
  236. BowserpUninitializeMailslot();
  237. //
  238. // Uninitialize the TDI related functions.
  239. //
  240. BowserpUninitializeTdi();
  241. //
  242. // Delete the resource protecting the bowser global data.
  243. //
  244. ExDeleteResourceLite(&BowserDataResource);
  245. ObDereferenceObject(BowserServerAnnouncementEvent);
  246. ZwClose(BowserServerAnnouncementEventHandle);
  247. #if DBG
  248. BowserUninitializeTraceLog();
  249. #endif
  250. //
  251. // Delete the browser device object.
  252. //
  253. IoDeleteDevice((PDEVICE_OBJECT)BowserDeviceObject);
  254. BowserUninitializeDiscardableCode();
  255. return;
  256. }
  257. VOID
  258. BowserReadBowserConfiguration(
  259. PUNICODE_STRING RegistryPath
  260. )
  261. {
  262. ULONG Storage[256];
  263. UNICODE_STRING UnicodeString;
  264. HANDLE RedirConfigHandle;
  265. HANDLE ParametersHandle;
  266. NTSTATUS Status;
  267. ULONG BytesRead;
  268. OBJECT_ATTRIBUTES ObjectAttributes;
  269. PBOWSER_CONFIG_INFO ConfigEntry;
  270. PKEY_VALUE_FULL_INFORMATION Value = (PKEY_VALUE_FULL_INFORMATION)Storage;
  271. PAGED_CODE();
  272. InitializeObjectAttributes(
  273. &ObjectAttributes,
  274. RegistryPath, // name
  275. OBJ_CASE_INSENSITIVE, // attributes
  276. NULL, // root
  277. NULL // security descriptor
  278. );
  279. Status = ZwOpenKey (&RedirConfigHandle, KEY_READ, &ObjectAttributes);
  280. if (!NT_SUCCESS(Status)) {
  281. BowserWriteErrorLogEntry (
  282. EVENT_BOWSER_CANT_READ_REGISTRY,
  283. Status,
  284. NULL,
  285. 0,
  286. 0
  287. );
  288. return;
  289. }
  290. RtlInitUnicodeString(&UnicodeString, BOWSER_CONFIG_PARAMETERS);
  291. InitializeObjectAttributes(
  292. &ObjectAttributes,
  293. &UnicodeString,
  294. OBJ_CASE_INSENSITIVE,
  295. RedirConfigHandle,
  296. NULL
  297. );
  298. Status = ZwOpenKey (&ParametersHandle, KEY_READ, &ObjectAttributes);
  299. if (!NT_SUCCESS(Status)) {
  300. BowserWriteErrorLogEntry (
  301. EVENT_BOWSER_CANT_READ_REGISTRY,
  302. Status,
  303. NULL,
  304. 0,
  305. 0
  306. );
  307. ZwClose(RedirConfigHandle);
  308. return;
  309. }
  310. for (ConfigEntry = BowserConfigEntries;
  311. ConfigEntry->ConfigParameterName != NULL;
  312. ConfigEntry += 1) {
  313. RtlInitUnicodeString(&UnicodeString, ConfigEntry->ConfigParameterName);
  314. Status = ZwQueryValueKey(ParametersHandle,
  315. &UnicodeString,
  316. KeyValueFullInformation,
  317. Value,
  318. sizeof(Storage),
  319. &BytesRead);
  320. if (NT_SUCCESS(Status)) {
  321. if (Value->DataLength != 0) {
  322. if (ConfigEntry->ConfigValueType == REG_BOOLEAN) {
  323. if (Value->Type != REG_DWORD ||
  324. Value->DataLength != REG_BOOLEAN_SIZE) {
  325. BowserWriteErrorLogEntry (
  326. EVENT_BOWSER_CANT_READ_REGISTRY,
  327. STATUS_INVALID_PARAMETER,
  328. ConfigEntry->ConfigParameterName,
  329. (USHORT)(wcslen(ConfigEntry->ConfigParameterName)*sizeof(WCHAR)),
  330. 0
  331. );
  332. } else {
  333. ULONG_PTR ConfigValue = (ULONG_PTR)((PCHAR)Value)+Value->DataOffset;
  334. *(PBOOLEAN)(ConfigEntry->ConfigValue) = (BOOLEAN)(*((PULONG)ConfigValue) != 0);
  335. }
  336. } else if (Value->Type != ConfigEntry->ConfigValueType ||
  337. Value->DataLength != ConfigEntry->ConfigValueSize) {
  338. BowserWriteErrorLogEntry (
  339. EVENT_BOWSER_CANT_READ_REGISTRY,
  340. STATUS_INVALID_PARAMETER,
  341. ConfigEntry->ConfigParameterName,
  342. (USHORT)(wcslen(ConfigEntry->ConfigParameterName)*sizeof(WCHAR)),
  343. 0
  344. );
  345. } else {
  346. RtlCopyMemory(ConfigEntry->ConfigValue, ((PCHAR)Value)+Value->DataOffset, Value->DataLength);
  347. }
  348. } else {
  349. BowserWriteErrorLogEntry (
  350. EVENT_BOWSER_CANT_READ_REGISTRY,
  351. STATUS_INVALID_PARAMETER,
  352. ConfigEntry->ConfigParameterName,
  353. (USHORT)(wcslen(ConfigEntry->ConfigParameterName)*sizeof(WCHAR)),
  354. 0
  355. );
  356. }
  357. }
  358. }
  359. ZwClose(ParametersHandle);
  360. ZwClose(RedirConfigHandle);
  361. }