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.

209 lines
4.1 KiB

  1. /*++
  2. Copyright (c) 1997-2001 Microsoft Corporation
  3. Module Name:
  4. NsInit.c
  5. Abstract:
  6. IpSec NAT shim initialization and shutdown routines
  7. Author:
  8. Jonathan Burstein (jonburs) 11-July-2001
  9. Environment:
  10. Kernel mode
  11. Revision History:
  12. --*/
  13. #include "precomp.h"
  14. #pragma hdrstop
  15. //
  16. // Global Variables
  17. //
  18. PDEVICE_OBJECT NsIpSecDeviceObject;
  19. #if DBG
  20. ULONG NsTraceClassesEnabled;
  21. WCHAR NsTraceClassesRegistryPath[] =
  22. L"MACHINE\\System\\CurrentControlSet\\Services\\IpNat\\Parameters";
  23. WCHAR NsTraceClassesEnabledName[] =
  24. L"NatShimTraceClassesEnabled";
  25. #endif
  26. NTSTATUS
  27. NsCleanupShim(
  28. VOID
  29. )
  30. /*++
  31. Routine Description:
  32. This routine is invoked to shutdown the shim.
  33. Arguments:
  34. none.
  35. Return Value:
  36. NTSTATUS.
  37. Environment:
  38. Must be called at PASSIVE_LEVEL.
  39. --*/
  40. {
  41. CALLTRACE(("NsCleanupShim\n"));
  42. NsShutdownTimerManagement();
  43. NsShutdownIcmpManagement();
  44. NsShutdownPacketManagement();
  45. NsShutdownConnectionManagement();
  46. NsIpSecDeviceObject = NULL;
  47. return STATUS_SUCCESS;
  48. } // NsCleanupShim
  49. NTSTATUS
  50. NsInitializeShim(
  51. PDEVICE_OBJECT pIpSecDeviceObject,
  52. PIPSEC_NATSHIM_FUNCTIONS pShimFunctions
  53. )
  54. /*++
  55. Routine Description:
  56. This routine is invoked to initialize the shim.
  57. Arguments:
  58. pIpSecDeviceObject - a pointer to the IpSec device object
  59. pShimFunctions - a pointer to an allocated strcture. This routine will
  60. fill out the function pointers w/in the structure
  61. Return Value:
  62. NTSTATUS.
  63. Environment:
  64. Must be called at PASSIVE_LEVEL.
  65. --*/
  66. {
  67. NTSTATUS status;
  68. #if DBG
  69. HANDLE hKey;
  70. OBJECT_ATTRIBUTES ObjectAttributes;
  71. UNICODE_STRING String;
  72. #endif
  73. CALLTRACE(("NsInitializeShim\n"));
  74. if (NULL == pIpSecDeviceObject
  75. || NULL == pShimFunctions)
  76. {
  77. return STATUS_INVALID_PARAMETER;
  78. }
  79. #if DBG
  80. //
  81. // Open the registry key containing debug tracing informatin.
  82. //
  83. RtlInitUnicodeString(&String, NsTraceClassesRegistryPath);
  84. InitializeObjectAttributes(
  85. &ObjectAttributes,
  86. &String,
  87. OBJ_CASE_INSENSITIVE,
  88. NULL,
  89. NULL
  90. );
  91. status = ZwOpenKey(&hKey, KEY_READ, &ObjectAttributes);
  92. if (NT_SUCCESS(status))
  93. {
  94. UCHAR Buffer[32];
  95. ULONG BytesRead;
  96. PKEY_VALUE_PARTIAL_INFORMATION Value;
  97. RtlInitUnicodeString(&String, NsTraceClassesEnabledName);
  98. status =
  99. ZwQueryValueKey(
  100. hKey,
  101. &String,
  102. KeyValuePartialInformation,
  103. (PKEY_VALUE_PARTIAL_INFORMATION)Buffer,
  104. sizeof(Buffer),
  105. &BytesRead
  106. );
  107. ZwClose(hKey);
  108. if (NT_SUCCESS(status)
  109. && ((PKEY_VALUE_PARTIAL_INFORMATION)Buffer)->Type == REG_DWORD)
  110. {
  111. NsTraceClassesEnabled =
  112. *(PULONG)((PKEY_VALUE_PARTIAL_INFORMATION)Buffer)->Data;
  113. }
  114. }
  115. #endif
  116. status = NsInitializeConnectionManagement();
  117. if (!NT_SUCCESS(status))
  118. {
  119. return status;
  120. }
  121. status = NsInitializePacketManagement();
  122. if (!NT_SUCCESS(status))
  123. {
  124. NsShutdownConnectionManagement();
  125. return status;
  126. }
  127. status = NsInitializeIcmpManagement();
  128. if (!NT_SUCCESS(status))
  129. {
  130. NsShutdownPacketManagement();
  131. NsShutdownConnectionManagement();
  132. return status;
  133. }
  134. status = NsInitializeTimerManagement();
  135. if (!NT_SUCCESS(status))
  136. {
  137. NsShutdownIcmpManagement();
  138. NsShutdownPacketManagement();
  139. NsShutdownConnectionManagement();
  140. return status;
  141. }
  142. NsIpSecDeviceObject = pIpSecDeviceObject;
  143. pShimFunctions->pCleanupRoutine = NsCleanupShim;
  144. pShimFunctions->pIncomingPacketRoutine = NsProcessIncomingPacket;
  145. pShimFunctions->pOutgoingPacketRoutine = NsProcessOutgoingPacket;
  146. return STATUS_SUCCESS;
  147. } // NsInitializeShim