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.

867 lines
25 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. Init.c
  5. Abstract:
  6. This module implements the DRIVER_INITIALIZATION routine for the PROXY mini rdr.
  7. Author:
  8. Balan Sethu Raman [SethuR] 7-Mar-1995
  9. Revision History:
  10. --*/
  11. #include "precomp.h"
  12. #pragma hdrstop
  13. #include "ntverp.h"
  14. #include "netevent.h"
  15. #include "nvisible.h"
  16. #define RDBSS_DRIVER_LOAD_STRING L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\Rdbss"
  17. NTSYSAPI
  18. NTSTATUS
  19. NTAPI
  20. ZwLoadDriver(
  21. IN PUNICODE_STRING DriverServiceName
  22. );
  23. //
  24. // Global data declarations . CODE.IMPROVEMENT why are these placed here!!
  25. //
  26. PEPROCESS MRxProxySystemProcess;
  27. FAST_MUTEX MRxProxySerializationMutex;
  28. KIRQL MRxProxyGlobalSpinLockSavedIrql;
  29. KSPIN_LOCK MRxProxyGlobalSpinLock;
  30. BOOLEAN MRxProxyGlobalSpinLockAcquired;
  31. #ifdef EXPLODE_POOLTAGS
  32. ULONG MRxProxyExplodePoolTags = 1;
  33. #else
  34. ULONG MRxProxyExplodePoolTags = 0;
  35. #endif
  36. NTSTATUS
  37. MRxProxyInitializeTables(
  38. void
  39. );
  40. NTSTATUS
  41. ProxyCeGetConfigurationInformation (
  42. void
  43. );
  44. VOID
  45. MRxProxyUnload(
  46. IN PDRIVER_OBJECT DriverObject
  47. );
  48. NTSTATUS
  49. MRxProxyGetUlongRegistryParameter(
  50. HANDLE ParametersHandle,
  51. PWCHAR ParameterName,
  52. PULONG ParamUlong,
  53. BOOLEAN LogFailure
  54. );
  55. //
  56. // Mini Redirector global variables.
  57. //
  58. struct _MINIRDR_DISPATCH MRxProxyDispatch;
  59. PMRXPROXY_DEVICE_OBJECT MRxProxyDeviceObject;
  60. ULONG MRxProxyBuildNumber = VER_PRODUCTBUILD;
  61. #ifdef RX_PRIVATE_BUILD
  62. ULONG MRxProxyPrivateBuild = 1;
  63. #else
  64. ULONG MRxProxyPrivateBuild = 0;
  65. #endif
  66. //declare the shadow debugtrace controlpoints
  67. RXDT_DefineCategory(CREATE);
  68. RXDT_DefineCategory(CLEANUP);
  69. RXDT_DefineCategory(CLOSE);
  70. RXDT_DefineCategory(READ);
  71. RXDT_DefineCategory(WRITE);
  72. RXDT_DefineCategory(LOCKCTRL);
  73. RXDT_DefineCategory(FLUSH);
  74. RXDT_DefineCategory(PREFIX);
  75. RXDT_DefineCategory(FCBSTRUCTS);
  76. RXDT_DefineCategory(DISPATCH);
  77. RXDT_DefineCategory(EA);
  78. RXDT_DefineCategory(DEVFCB);
  79. typedef enum _MRXPROXY_INIT_STATES {
  80. MRXPROXYINIT_ALL_INITIALIZATION_COMPLETED,
  81. MRXPROXYINIT_MINIRDR_REGISTERED,
  82. MRXPROXYINIT_START
  83. } MRXPROXY_INIT_STATES;
  84. VOID
  85. MRxProxyInitUnwind(
  86. IN PDRIVER_OBJECT DriverObject,
  87. IN MRXPROXY_INIT_STATES MRxProxyInitState
  88. );
  89. NTSTATUS
  90. MRxProxyFsdDispatch (
  91. IN PDEVICE_OBJECT DeviceObject,
  92. IN PIRP Irp
  93. );
  94. NTSTATUS
  95. DriverEntry(
  96. IN PDRIVER_OBJECT DriverObject,
  97. IN PUNICODE_STRING RegistryPath
  98. )
  99. /*++
  100. Routine Description:
  101. This is the initialization routine for the PROXY mini redirector
  102. Arguments:
  103. DriverObject - Pointer to driver object created by the system.
  104. Return Value:
  105. RXSTATUS - The function value is the final status from the initialization
  106. operation.
  107. --*/
  108. {
  109. NTSTATUS Status;
  110. //UNICODE_STRING MRxProxyRdbssDriverLoadString;
  111. MRXPROXY_INIT_STATES MRxProxyInitState = 0;
  112. UNICODE_STRING ProxyMiniRedirectorName;
  113. #ifdef MONOLITHIC_MINIRDR
  114. DbgPrint("InitWrapper\n");
  115. Status = RxDriverEntry(DriverObject, RegistryPath);
  116. DbgPrint("BackFromInitWrapper %08lx\n",Status);
  117. if (Status != STATUS_SUCCESS) {
  118. DbgPrint("Wrapper failed to initialize. Status = %08lx\n",Status);
  119. return(Status);
  120. }
  121. #endif
  122. MRxProxySystemProcess = RxGetRDBSSProcess();
  123. MRxProxyInitializeLoudStrings();
  124. ExInitializeFastMutex(&MRxProxySerializationMutex);
  125. KeInitializeSpinLock(&MRxProxyGlobalSpinLock );
  126. MRxProxyGlobalSpinLockAcquired = FALSE;
  127. try {
  128. MRxProxyInitState = MRXPROXYINIT_START;
  129. RtlInitUnicodeString(&ProxyMiniRedirectorName,MRXPROXY_DEVICE_NAME_U);
  130. RxDbgTrace( 0, (DEBUG_TRACE_ALWAYS), ("MRxProxyDriverEntry: DriverObject =%08lx\n", DriverObject ));
  131. Status = RxRegisterMinirdr((PRDBSS_DEVICE_OBJECT *)(&MRxProxyDeviceObject),
  132. DriverObject,
  133. &MRxProxyDispatch,
  134. FALSE,FALSE, //don't register with unc and for mailslots
  135. &ProxyMiniRedirectorName,
  136. sizeof(MRXPROXY_DEVICE_OBJECT) - sizeof(RDBSS_DEVICE_OBJECT), //IN ULONG DeviceExtensionSize,
  137. 0 //IN ULONG DeviceCharacteristics
  138. );
  139. if (Status!=STATUS_SUCCESS) {
  140. RxDbgTrace( 0, (DEBUG_TRACE_ALWAYS), ("MRxProxyDriverEntry failed: %08lx\n", Status ));
  141. try_return(Status);
  142. }
  143. MRxProxyInitState = MRXPROXYINIT_MINIRDR_REGISTERED;
  144. MRxProxyDeviceObject->SectorSize = 512; //BUGBUG go find out
  145. RtlInitUnicodeString(&MRxProxyDeviceObject->InnerPrefixForOpens,
  146. MRXPROXY_INNERPREFIX_FOR_OPENS
  147. );
  148. RtlInitUnicodeString(&MRxProxyDeviceObject->PrefixForRename,
  149. MRXPROXY_INNERPREFIX_FOR_OPENS
  150. //MRXPROXY_PREFIX_FOR_RENAME
  151. );
  152. //for all this stuff, there's no undo.....so no extra state
  153. Status = MRxProxyInitializeTables();
  154. if (!NT_SUCCESS( Status )) {
  155. try_return(Status);
  156. }
  157. Status = ProxyCeGetConfigurationInformation();
  158. if (!NT_SUCCESS( Status )) {
  159. try_return(Status);
  160. }
  161. try_exit: NOTHING;
  162. } finally {
  163. if (Status != STATUS_SUCCESS) {
  164. MRxProxyInitUnwind(DriverObject,MRxProxyInitState);
  165. }
  166. }
  167. if (Status != STATUS_SUCCESS) {
  168. DbgPrint("MRxProxy failed to start with %08lx %08lx\n",Status,MRxProxyInitState);
  169. return(Status);
  170. }
  171. // Setup Unload Routine
  172. DriverObject->DriverUnload = MRxProxyUnload;
  173. //setup the driverdispatch for people who come in here directly....like the browser
  174. //CODE.IMPROVEMENT we should change this code so that the things that aren't examined
  175. // in MRxProxyFsdDispatch are routed directly, i.e. reads and writes
  176. {ULONG i;
  177. for (i = 0; i < IRP_MJ_MAXIMUM_FUNCTION; i++) {
  178. DriverObject->MajorFunction[i] = (PDRIVER_DISPATCH)MRxProxyFsdDispatch;
  179. }}
  180. //and get out
  181. return STATUS_SUCCESS;
  182. }
  183. VOID
  184. MRxProxyInitUnwind(
  185. IN PDRIVER_OBJECT DriverObject,
  186. IN MRXPROXY_INIT_STATES MRxProxyInitState
  187. )
  188. /*++
  189. Routine Description:
  190. This routine does the common uninit work for unwinding from a bad driver entry or for unloading.
  191. Arguments:
  192. RxInitState - tells how far we got into the intialization
  193. Return Value:
  194. None
  195. --*/
  196. {
  197. PAGED_CODE();
  198. switch (MRxProxyInitState) {
  199. case MRXPROXYINIT_ALL_INITIALIZATION_COMPLETED:
  200. //Nothing extra to do...this is just so that the constant in RxUnload doesn't change.......
  201. //lack of break intentional
  202. case MRXPROXYINIT_MINIRDR_REGISTERED:
  203. RxUnregisterMinirdr(&MRxProxyDeviceObject->RxDeviceObject);
  204. //lack of break intentional
  205. case MRXPROXYINIT_START:
  206. break;
  207. }
  208. }
  209. VOID
  210. MRxProxyUnload(
  211. IN PDRIVER_OBJECT DriverObject
  212. )
  213. /*++
  214. Routine Description:
  215. This is the unload routine for the PROXY mini redirector.
  216. Arguments:
  217. DriverObject - pointer to the driver object for the MRxProxy
  218. Return Value:
  219. None
  220. --*/
  221. {
  222. PAGED_CODE();
  223. RxDbgTrace( 0, (DEBUG_TRACE_ALWAYS), ("MRxProxyUnload: DriverObject =%08lx\n", DriverObject) );
  224. //ASSERT(!"Starting to unload!");
  225. //RxUnregisterMinirdr(MRxProxyDeviceObject);
  226. MRxProxyInitUnwind(DriverObject,MRXPROXYINIT_ALL_INITIALIZATION_COMPLETED);
  227. #ifdef MONOLITHIC_MINIRDR
  228. RxUnload(DriverObject);
  229. #endif
  230. RxDbgTrace( 0, (DEBUG_TRACE_ALWAYS), ("MRxProxyUnload exit: DriverObject =%08lx\n", DriverObject) );
  231. }
  232. NTSTATUS
  233. MRxProxyInitializeTables(
  234. void
  235. )
  236. /*++
  237. Routine Description:
  238. This routine sets up the mini redirector dispatch vector and also calls to initialize any other tables needed.
  239. Return Value:
  240. RXSTATUS - The return status for the operation
  241. --*/
  242. {
  243. // Ensure that the PROXY mini redirector context satisfies the size constraints
  244. ASSERT(sizeof(MRXPROXY_RX_CONTEXT) <= MRX_CONTEXT_SIZE);
  245. //local minirdr dispatch table init
  246. ZeroAndInitializeNodeType( &MRxProxyDispatch, RDBSS_NTC_MINIRDR_DISPATCH, sizeof(MINIRDR_DISPATCH));
  247. // PROXY mini redirector extension sizes and allocation policies.
  248. // CODE.IMPROVEMENT -- currently we do not allocate the NET_ROOT and SRV_CALL extensions
  249. // in the wrapper. Except for V_NET_ROOT wherein it is shared across multiple instances in
  250. // the wrapper all the other data structure management should be left to the wrappers
  251. MRxProxyDispatch.MRxFlags = (RDBSS_MANAGE_FCB_EXTENSION |
  252. RDBSS_MANAGE_SRV_OPEN_EXTENSION |
  253. RDBSS_MANAGE_FOBX_EXTENSION);
  254. MRxProxyDispatch.MRxSrvCallSize = 0;
  255. MRxProxyDispatch.MRxNetRootSize = 0;
  256. MRxProxyDispatch.MRxVNetRootSize = 0;
  257. MRxProxyDispatch.MRxFcbSize = sizeof(MRX_PROXY_FCB);
  258. MRxProxyDispatch.MRxSrvOpenSize = sizeof(MRX_PROXY_SRV_OPEN);
  259. MRxProxyDispatch.MRxFobxSize = sizeof(MRX_PROXY_FOBX);
  260. // // Transport update handler
  261. // MRxProxyDispatch.MRxTransportUpdateHandler = MRxProxyTransportUpdateHandler;
  262. // Mini redirector cancel routine ..
  263. MRxProxyDispatch.MRxCancel = NULL;
  264. // Mini redirector Start/Stop
  265. MRxProxyDispatch.MRxStart = MRxProxyStart;
  266. MRxProxyDispatch.MRxStop = MRxProxyStop;
  267. //MRxProxyDispatch.MRxMinirdrControl = MRxProxyMinirdrControl; //now we have no way to readch this BUGBUG
  268. MRxProxyDispatch.MRxDevFcbXXXControlFile = MRxProxyDevFcbXXXControlFile;
  269. // Mini redirector name resolution
  270. MRxProxyDispatch.MRxCreateSrvCall = MRxProxyCreateSrvCall;
  271. MRxProxyDispatch.MRxSrvCallWinnerNotify = MRxProxySrvCallWinnerNotify;
  272. MRxProxyDispatch.MRxCreateVNetRoot = MRxProxyCreateVNetRoot;
  273. MRxProxyDispatch.MRxUpdateNetRootState = MRxProxyUpdateNetRootState;
  274. MRxProxyDispatch.MRxExtractNetRootName = MRxProxyExtractNetRootName;
  275. MRxProxyDispatch.MRxFinalizeSrvCall = MRxProxyFinalizeSrvCall;
  276. MRxProxyDispatch.MRxFinalizeNetRoot = MRxProxyFinalizeNetRoot;
  277. MRxProxyDispatch.MRxFinalizeVNetRoot = MRxProxyFinalizeVNetRoot;
  278. // File System Object Creation/Deletion.
  279. MRxProxyDispatch.MRxCreate = MRxProxyCreate;
  280. MRxProxyDispatch.MRxCollapseOpen = MRxProxyCollapseOpen;
  281. MRxProxyDispatch.MRxShouldTryToCollapseThisOpen = MRxProxyShouldTryToCollapseThisOpen;
  282. MRxProxyDispatch.MRxExtendForCache = MRxProxyExtendForCache;
  283. MRxProxyDispatch.MRxExtendForNonCache = MRxProxyExtendForNonCache;
  284. MRxProxyDispatch.MRxTruncate = MRxProxyTruncate;
  285. MRxProxyDispatch.MRxCleanupFobx = MRxProxyCleanupFobx;
  286. MRxProxyDispatch.MRxCloseSrvOpen = MRxProxyCloseSrvOpen;
  287. MRxProxyDispatch.MRxFlush = MRxProxyFlush;
  288. MRxProxyDispatch.MRxForceClosed = MRxProxyForcedClose;
  289. MRxProxyDispatch.MRxDeallocateForFcb = MRxProxyDeallocateForFcb;
  290. MRxProxyDispatch.MRxDeallocateForFobx = MRxProxyDeallocateForFobx;
  291. MRxProxyDispatch.MRxIsLockRealizable = MRxProxyIsLockRealizable;
  292. // File System Objects query/Set
  293. MRxProxyDispatch.MRxQueryDirectory = MRxProxyQueryDirectory;
  294. MRxProxyDispatch.MRxQueryVolumeInfo = MRxProxyQueryVolumeInformation;
  295. MRxProxyDispatch.MRxQueryEaInfo = MRxProxyQueryEaInformation;
  296. MRxProxyDispatch.MRxSetEaInfo = MRxProxySetEaInformation;
  297. MRxProxyDispatch.MRxQuerySdInfo = MRxProxyQuerySecurityInformation;
  298. MRxProxyDispatch.MRxSetSdInfo = MRxProxySetSecurityInformation;
  299. MRxProxyDispatch.MRxQueryFileInfo = MRxProxyQueryFileInformation;
  300. MRxProxyDispatch.MRxSetFileInfo = MRxProxySetFileInformation;
  301. MRxProxyDispatch.MRxSetFileInfoAtCleanup
  302. = MRxProxySetFileInformationAtCleanup;
  303. // Buffering state change
  304. MRxProxyDispatch.MRxComputeNewBufferingState = MRxProxyComputeNewBufferingState;
  305. // File System Object I/O
  306. MRxProxyDispatch.MRxLowIOSubmit[LOWIO_OP_READ] = MRxProxyRead;
  307. MRxProxyDispatch.MRxLowIOSubmit[LOWIO_OP_WRITE] = MRxProxyWrite;
  308. MRxProxyDispatch.MRxLowIOSubmit[LOWIO_OP_SHAREDLOCK] = MRxProxyLocks;
  309. MRxProxyDispatch.MRxLowIOSubmit[LOWIO_OP_EXCLUSIVELOCK] = MRxProxyLocks;
  310. MRxProxyDispatch.MRxLowIOSubmit[LOWIO_OP_UNLOCK] = MRxProxyLocks;
  311. MRxProxyDispatch.MRxLowIOSubmit[LOWIO_OP_UNLOCK_MULTIPLE] = MRxProxyLocks;
  312. MRxProxyDispatch.MRxLowIOSubmit[LOWIO_OP_FSCTL] = MRxProxyFsCtl;
  313. MRxProxyDispatch.MRxLowIOSubmit[LOWIO_OP_IOCTL] = MRxProxyIoCtl;
  314. //CODE.IMPROVEMENT shouldn't flush come thru lowio???
  315. MRxProxyDispatch.MRxLowIOSubmit[LOWIO_OP_NOTIFY_CHANGE_DIRECTORY] = MRxProxyNotifyChangeDirectory;
  316. //no longer a field MRxProxyDispatch.MRxUnlockRoutine = MRxProxyUnlockRoutine;
  317. // Miscellanous
  318. MRxProxyDispatch.MRxCompleteBufferingStateChangeRequest = MRxProxyCompleteBufferingStateChangeRequest;
  319. return(STATUS_SUCCESS);
  320. }
  321. NTSTATUS
  322. MRxProxyStart(
  323. PRX_CONTEXT RxContext,
  324. IN OUT PRDBSS_DEVICE_OBJECT RxDeviceObject
  325. )
  326. /*++
  327. Routine Description:
  328. This routine completes the initialization of the mini redirector fromn the
  329. RDBSS perspective. Note that this is different from the initialization done
  330. in DriverEntry. Any initialization that depends on RDBSS should be done as
  331. part of this routine while the initialization that is independent of RDBSS
  332. should be done in the DriverEntry routine.
  333. Arguments:
  334. RxContext - Supplies the Irp that was used to startup the rdbss
  335. Return Value:
  336. RXSTATUS - The return status for the operation
  337. --*/
  338. {
  339. NTSTATUS Status;
  340. Status = STATUS_SUCCESS;
  341. return Status;
  342. }
  343. NTSTATUS
  344. MRxProxyStop(
  345. PRX_CONTEXT RxContext,
  346. IN OUT PRDBSS_DEVICE_OBJECT RxDeviceObject
  347. )
  348. /*++
  349. Routine Description:
  350. This routine is used to activate the mini redirector from the RDBSS perspective
  351. Arguments:
  352. RxContext - the context that was used to start the mini redirector
  353. pContext - the PROXY mini rdr context passed in at registration time.
  354. Return Value:
  355. RXSTATUS - The return status for the operation
  356. --*/
  357. {
  358. //NTSTATUS Status;
  359. // Deallocate the configuration strings ....
  360. #if 0
  361. if (ProxyCeContext.Transports.Buffer != NULL) {
  362. // the transports buffer is at the end of a larger buffer (by 12 bytes)
  363. // allocated to read the value from the registry. recover the original buffer
  364. // pointer in orer to free.
  365. PKEY_VALUE_PARTIAL_INFORMATION TransportsValueFromRegistry;
  366. TransportsValueFromRegistry = CONTAINING_RECORD(
  367. ProxyCeContext.Transports.Buffer,
  368. KEY_VALUE_PARTIAL_INFORMATION,
  369. Data[0]
  370. );
  371. //DbgPrint("b1 %08lx b2 %08lx\n", TransportsValueFromRegistry,ProxyCeContext.Transports.Buffer);
  372. RxFreePool(TransportsValueFromRegistry);
  373. }
  374. #endif //0
  375. return(STATUS_SUCCESS);
  376. }
  377. #if 0
  378. #define PROXYMRX_CONFIG_COMPUTER_NAME \
  379. L"\\Registry\\Machine\\System\\CurrentControlSet\\Control\\ComputerName\\ActiveComputerName"
  380. #define COMPUTERNAME L"ComputerName"
  381. #define PROXYMRX_CONFIG_TRANSPORTS \
  382. L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\LanmanWorkStation\\Linkage"
  383. #define TRANSPORT_BINDINGS L"Bind"
  384. #define PROXYMRX_MINIRDR_PARAMETERS \
  385. L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\MRxProxy\\Parameters"
  386. VOID
  387. MRxProxyReadMiscellaneousRegistryParameters()
  388. {
  389. NTSTATUS Status;
  390. //ULONG BytesRead;
  391. OBJECT_ATTRIBUTES ObjectAttributes;
  392. UNICODE_STRING ParametersRegistryKeyName;
  393. HANDLE ParametersHandle;
  394. ULONG Temp;
  395. RtlInitUnicodeString(&ParametersRegistryKeyName, PROXYMRX_MINIRDR_PARAMETERS);
  396. InitializeObjectAttributes(
  397. &ObjectAttributes,
  398. &ParametersRegistryKeyName,
  399. OBJ_CASE_INSENSITIVE,
  400. NULL,
  401. NULL
  402. );
  403. Status = ZwOpenKey (&ParametersHandle, KEY_READ, &ObjectAttributes);
  404. if (!NT_SUCCESS(Status)) {
  405. RxLogFailure(
  406. MRxProxyDeviceObject,
  407. NULL,
  408. EVENT_RDR_CANT_READ_REGISTRY,
  409. Status);
  410. return;
  411. }
  412. if (0) {
  413. MRxProxyGetUlongRegistryParameter(ParametersHandle,
  414. L"NoPreciousServerSetup",
  415. (PULONG)&Temp,
  416. FALSE
  417. );
  418. }
  419. Status = MRxProxyGetUlongRegistryParameter(ParametersHandle,
  420. L"DeferredOpensEnabled",
  421. (PULONG)&Temp,
  422. FALSE
  423. );
  424. if (NT_SUCCESS(Status)) MRxProxyDeferredOpensEnabled = (BOOLEAN)Temp;
  425. Status = MRxProxyGetUlongRegistryParameter(ParametersHandle,
  426. L"OplocksDisabled",
  427. (PULONG)&Temp,
  428. FALSE
  429. );
  430. if (NT_SUCCESS(Status)) MRxProxyOplocksDisabled = (BOOLEAN)Temp;
  431. ZwClose(ParametersHandle);
  432. }
  433. #endif
  434. NTSTATUS
  435. ProxyCeGetConfigurationInformation()
  436. {
  437. ULONG Storage[256];
  438. //UNICODE_STRING UnicodeString;
  439. //HANDLE hRegistryKey;
  440. //HANDLE hProxyMrxConfiguration;
  441. //HANDLE ParametersHandle;
  442. NTSTATUS Status;
  443. //ULONG BytesRead;
  444. //OBJECT_ATTRIBUTES ObjectAttributes;
  445. PKEY_VALUE_FULL_INFORMATION Value = (PKEY_VALUE_FULL_INFORMATION)Storage;
  446. //KEY_VALUE_PARTIAL_INFORMATION InitialPartialInformationValue;
  447. //ULONG AllocationLength;
  448. PAGED_CODE();
  449. //MRxProxyReadMiscellaneousRegistryParameters();
  450. #if 0
  451. // Obtain the list of transports associated with PROXY redirector. This is stored
  452. // as a multivalued string and is used subsequently to weed out the
  453. // appropriate transports. This is a two step process; first we try to find out
  454. // how much space we need; then we allocate; then we read in. unfortunately, the kind of
  455. // structure that we have to use to get the value has a header on it, so we have to offset the
  456. // returned pointer both here and in the free routine.
  457. //CODE.IMPROVEMENT we should perhaps get a subroutine going that does all this
  458. //also, there are no log entries.
  459. //also, we should be doing partial_infos instead of full
  460. RtlInitUnicodeString(&ProxyCeContext.Transports, NULL);
  461. RtlInitUnicodeString(&UnicodeString, PROXYMRX_CONFIG_TRANSPORTS);
  462. InitializeObjectAttributes(
  463. &ObjectAttributes,
  464. &UnicodeString, // name
  465. OBJ_CASE_INSENSITIVE, // attributes
  466. NULL, // root
  467. NULL); // security descriptor
  468. Status = ZwOpenKey (&hRegistryKey, KEY_READ, &ObjectAttributes);
  469. if (!NT_SUCCESS(Status)) {
  470. return Status;
  471. }
  472. RtlInitUnicodeString(&UnicodeString, TRANSPORT_BINDINGS);
  473. Status = ZwQueryValueKey(
  474. hRegistryKey,
  475. &UnicodeString,
  476. KeyValuePartialInformation,
  477. &InitialPartialInformationValue,
  478. sizeof(InitialPartialInformationValue),
  479. &BytesRead);
  480. if (Status== STATUS_BUFFER_OVERFLOW) {
  481. Status = STATUS_SUCCESS;
  482. }
  483. if (!NT_SUCCESS(Status)) {
  484. return Status;
  485. }
  486. AllocationLength = sizeof(KEY_VALUE_PARTIAL_INFORMATION)
  487. + InitialPartialInformationValue.DataLength;
  488. if (0) {
  489. DbgPrint("SizeofBindingInfo=%08lx %08lx\n",
  490. AllocationLength,
  491. InitialPartialInformationValue.DataLength);
  492. }
  493. //RtlInitUnicodeString(&UnicodeString, TRANSPORT_BINDINGS);
  494. {
  495. PKEY_VALUE_PARTIAL_INFORMATION TransportsValueFromRegistry;
  496. (PBYTE)TransportsValueFromRegistry = RxAllocatePoolWithTag(
  497. PagedPool,
  498. AllocationLength,
  499. MRXPROXY_MISC_POOLTAG);
  500. if (TransportsValueFromRegistry == NULL) {
  501. return(STATUS_INSUFFICIENT_RESOURCES);
  502. }
  503. Status = ZwQueryValueKey(
  504. hRegistryKey,
  505. &UnicodeString,
  506. KeyValuePartialInformation,
  507. TransportsValueFromRegistry,
  508. AllocationLength,
  509. &BytesRead);
  510. if (NT_SUCCESS(Status) &&
  511. (TransportsValueFromRegistry->DataLength > 0) &&
  512. (TransportsValueFromRegistry->Type == REG_MULTI_SZ)) {
  513. ProxyCeContext.Transports.MaximumLength =
  514. ProxyCeContext.Transports.Length = (USHORT)TransportsValueFromRegistry->DataLength;
  515. ProxyCeContext.Transports.Buffer = (PWCHAR)(&TransportsValueFromRegistry->Data[0]);
  516. //DbgPrint("b1 %08lx b2 %08lx\n", TransportsValueFromRegistry,ProxyCeContext.Transports.Buffer);
  517. } else {
  518. RxLog(("Invalid Transport Binding string... using all transports"));
  519. RxFreePool(TransportsValueFromRegistry);
  520. }
  521. }
  522. ZwClose(hRegistryKey);
  523. #endif //0
  524. Status = STATUS_SUCCESS;
  525. return Status;
  526. }
  527. NTSTATUS
  528. MRxProxyFsdDispatch (
  529. IN PDEVICE_OBJECT DeviceObject,
  530. IN PIRP Irp
  531. )
  532. /*++
  533. Routine Description:
  534. This routine implements the FSD dispatch for the proxymini DRIVER object.
  535. Arguments:
  536. DeviceObject - Supplies the device object for the packet being processed.
  537. Irp - Supplies the Irp being processed
  538. Return Value:
  539. RXSTATUS - The Fsd status for the Irp
  540. --*/
  541. {
  542. PIO_STACK_LOCATION IrpSp = IoGetCurrentIrpStackLocation( Irp ); //ok4ioget
  543. UCHAR MajorFunctionCode = IrpSp->MajorFunction;
  544. ASSERT(DeviceObject==(PDEVICE_OBJECT)MRxProxyDeviceObject);
  545. if (DeviceObject!=(PDEVICE_OBJECT)MRxProxyDeviceObject) {
  546. Irp->IoStatus.Status = STATUS_INVALID_DEVICE_REQUEST;
  547. Irp->IoStatus.Information = 0;
  548. IoCompleteRequest(Irp, IO_NO_INCREMENT );
  549. return (STATUS_INVALID_DEVICE_REQUEST);
  550. }
  551. return RxFsdDispatch((PRDBSS_DEVICE_OBJECT)MRxProxyDeviceObject,Irp);
  552. }
  553. NTSTATUS
  554. MRxProxyDeallocateForFcb (
  555. IN OUT PMRX_FCB pFcb
  556. )
  557. /*++
  558. Routine Description:
  559. This routine is called when the wrapper is about to deallocate a FCB.
  560. Arguments:
  561. pFcb - the Fcb being deallocated.
  562. Return Value:
  563. RXSTATUS - STATUS_SUCCESS
  564. --*/
  565. {
  566. //DbgPrint("Bob's opportunity to get rid of his fcb storage......\n");
  567. return(STATUS_SUCCESS);
  568. }
  569. NTSTATUS
  570. MRxProxyDeallocateForFobx (
  571. IN OUT PMRX_FOBX pFobx
  572. )
  573. /*++
  574. Routine Description:
  575. This routine is called when the wrapper is about to deallocate a FOBX.
  576. Arguments:
  577. pFobx - the Fobx being deallocated.
  578. Return Value:
  579. RXSTATUS - STATUS_SUCCESS
  580. --*/
  581. {
  582. PMRX_PROXY_FOBX proxyFobx = MRxProxyGetFileObjectExtension(pFobx);
  583. PMRX_SRV_OPEN SrvOpen = pFobx->pSrvOpen;
  584. PMRX_FCB Fcb = SrvOpen->pFcb;
  585. IF_DEBUG {
  586. if (proxyFobx && FlagOn(proxyFobx->Enumeration.Flags,PROXYFOBX_ENUMFLAG_LOUD_FINALIZE)) {
  587. DbgPrint("Finalizobx side buffer %08lx %08lx %08lx %08lx %08lxon %wZ\n",
  588. 0, 0, //sidebuffer,count
  589. proxyFobx,pFobx,&Fcb->AlreadyPrefixedName
  590. );
  591. }
  592. }
  593. return(STATUS_SUCCESS);
  594. }
  595. NTSTATUS
  596. MRxProxyGetUlongRegistryParameter(
  597. HANDLE ParametersHandle,
  598. PWCHAR ParameterName,
  599. PULONG ParamUlong,
  600. BOOLEAN LogFailure
  601. )
  602. /*++
  603. Routine Description:
  604. This routine is called to read a ULONG param from t he registry.
  605. Arguments:
  606. ParametersHandle - the handle of the containing registry "folder"
  607. ParameterName - name of the parameter to be read
  608. ParamUlong - where to store the value, if successful
  609. LogFailure - if TRUE and the registry stuff fails, log an error
  610. Return Value:
  611. RXSTATUS - STATUS_SUCCESS
  612. --*/
  613. {
  614. ULONG Storage[16];
  615. PKEY_VALUE_PARTIAL_INFORMATION Value;
  616. ULONG ValueSize;
  617. UNICODE_STRING UnicodeString;
  618. NTSTATUS Status;
  619. ULONG BytesRead;
  620. PAGED_CODE(); //INIT
  621. Value = (PKEY_VALUE_PARTIAL_INFORMATION)Storage;
  622. ValueSize = sizeof(Storage);
  623. RtlInitUnicodeString(&UnicodeString, ParameterName);
  624. Status = ZwQueryValueKey(ParametersHandle,
  625. &UnicodeString,
  626. KeyValuePartialInformation,
  627. Value,
  628. ValueSize,
  629. &BytesRead);
  630. if (NT_SUCCESS(Status)) {
  631. if (Value->Type == REG_DWORD) {
  632. PULONG ConfigValue = (PULONG)&Value->Data[0];
  633. *ParamUlong = *((PULONG)ConfigValue);
  634. DbgPrint("readRegistryvalue %wZ = %08lx\n",&UnicodeString,*ParamUlong);
  635. return(STATUS_SUCCESS);
  636. } else {
  637. Status = STATUS_INVALID_PARAMETER;
  638. }
  639. }
  640. if (!LogFailure) { return Status; }
  641. RxLogFailureWithBuffer(
  642. MRxProxyDeviceObject,
  643. NULL,
  644. EVENT_RDR_CANT_READ_REGISTRY,
  645. Status,
  646. ParameterName,
  647. (USHORT)(wcslen(ParameterName)*sizeof(WCHAR))
  648. );
  649. return Status;
  650. }
  651.