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.

161 lines
3.4 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. ntos\tdi\isn\flt\fwdbind.c
  5. Abstract:
  6. IPX Filter driver binding with forwarder routines
  7. Author:
  8. Vadim Eydelman
  9. Revision History:
  10. --*/
  11. #include "precomp.h"
  12. // Buffer to keep forwarder entry points
  13. IPX_FLT_BIND_OUTPUT FltBindOutput;
  14. // global handle of the FWD driver
  15. HANDLE HdlFwdFile = NULL;
  16. /*++
  17. B i n d T o F w d D r i v e r
  18. Routine Description:
  19. Opens forwarder driver and exchages entry points
  20. Arguments:
  21. None
  22. Return Value:
  23. STATUS_SUCCESS if successful,
  24. STATUS_UNSUCCESSFUL otherwise
  25. --*/
  26. NTSTATUS
  27. BindToFwdDriver (
  28. KPROCESSOR_MODE requestorMode
  29. ) {
  30. NTSTATUS status;
  31. IO_STATUS_BLOCK IoStatusBlock;
  32. OBJECT_ATTRIBUTES ObjectAttributes;
  33. UNICODE_STRING UstrFwdFileName;
  34. IPX_FLT_BIND_INPUT FltBindInput = {Filter, InterfaceDeleted};
  35. ASSERT (HdlFwdFile == NULL);
  36. RtlInitUnicodeString (&UstrFwdFileName, IPXFWD_NAME);
  37. InitializeObjectAttributes(
  38. &ObjectAttributes,
  39. &UstrFwdFileName,
  40. OBJ_CASE_INSENSITIVE,
  41. NULL,
  42. NULL
  43. );
  44. if (requestorMode==UserMode)
  45. status = ZwCreateFile(&HdlFwdFile,
  46. SYNCHRONIZE | GENERIC_READ,
  47. &ObjectAttributes,
  48. &IoStatusBlock,
  49. NULL,
  50. FILE_ATTRIBUTE_NORMAL,
  51. FILE_SHARE_READ | FILE_SHARE_WRITE,
  52. FILE_OPEN,
  53. FILE_SYNCHRONOUS_IO_NONALERT,
  54. NULL,
  55. 0L);
  56. else
  57. status = NtCreateFile(&HdlFwdFile,
  58. SYNCHRONIZE | GENERIC_READ,
  59. &ObjectAttributes,
  60. &IoStatusBlock,
  61. NULL,
  62. FILE_ATTRIBUTE_NORMAL,
  63. FILE_SHARE_READ | FILE_SHARE_WRITE,
  64. FILE_OPEN,
  65. FILE_SYNCHRONOUS_IO_NONALERT,
  66. NULL,
  67. 0L);
  68. if (NT_SUCCESS(status)) {
  69. if (requestorMode==UserMode)
  70. status = ZwDeviceIoControlFile(
  71. HdlFwdFile, // HANDLE to File
  72. NULL, // HANDLE to Event
  73. NULL, // ApcRoutine
  74. NULL, // ApcContext
  75. &IoStatusBlock, // IO_STATUS_BLOCK
  76. IOCTL_FWD_INTERNAL_BIND_FILTER, // IoControlCode
  77. &FltBindInput, // Input Buffer
  78. sizeof(FltBindInput), // Input Buffer Length
  79. &FltBindOutput, // Output Buffer
  80. sizeof(FltBindOutput));// Output Buffer Length
  81. else
  82. status = NtDeviceIoControlFile(
  83. HdlFwdFile, // HANDLE to File
  84. NULL, // HANDLE to Event
  85. NULL, // ApcRoutine
  86. NULL, // ApcContext
  87. &IoStatusBlock, // IO_STATUS_BLOCK
  88. IOCTL_FWD_INTERNAL_BIND_FILTER, // IoControlCode
  89. &FltBindInput, // Input Buffer
  90. sizeof(FltBindInput), // Input Buffer Length
  91. &FltBindOutput, // Output Buffer
  92. sizeof(FltBindOutput));// Output Buffer Length
  93. if (NT_SUCCESS (status))
  94. return STATUS_SUCCESS;
  95. else
  96. IpxFltDbgPrint (DBG_ERRORS,
  97. ("IpxFlt: Failed to bind to forwarder %08lx.\n", status));
  98. if (requestorMode==KernelMode)
  99. ZwClose (HdlFwdFile);
  100. else
  101. NtClose (HdlFwdFile);
  102. }
  103. else
  104. IpxFltDbgPrint (DBG_ERRORS,
  105. ("IpxFlt: Failed create forwarder file %08lx.\n", status));
  106. HdlFwdFile = NULL;
  107. return status;
  108. }
  109. /*++
  110. U n i n d T o F w d D r i v e r
  111. Routine Description:
  112. Closes forwarder driver
  113. Arguments:
  114. None
  115. Return Value:
  116. None
  117. --*/
  118. VOID
  119. UnbindFromFwdDriver (
  120. KPROCESSOR_MODE requestorMode
  121. ) {
  122. NTSTATUS status;
  123. ASSERT (HdlFwdFile != NULL);
  124. if (requestorMode==UserMode)
  125. status = ZwClose (HdlFwdFile);
  126. else
  127. status = NtClose (HdlFwdFile);
  128. ASSERT (NT_SUCCESS (status));
  129. HdlFwdFile = NULL;
  130. }