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.

212 lines
5.0 KiB

  1. /*++
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. init.h
  5. Abstract:
  6. This module contains all of the code to
  7. initialize the variables for the IPSecSPD Service.
  8. Author:
  9. abhisheV 30-September-1999
  10. Environment
  11. User Level: Win32
  12. Revision History:
  13. --*/
  14. #include "precomp.h"
  15. #define SZAPPNAME L"ipsecsvc.dll"
  16. DWORD
  17. InitSPDThruRegistry(
  18. )
  19. {
  20. DWORD dwError = 0;
  21. HKEY hKey = NULL;
  22. DWORD dwtype = REG_DWORD;
  23. DWORD dwsize = sizeof(DWORD);
  24. DWORD dwBackwardSoftSA = 0;
  25. dwError = RegOpenKey(
  26. HKEY_LOCAL_MACHINE,
  27. gpszLocPolicyAgent,
  28. &hKey
  29. );
  30. if (dwError) {
  31. gdwDSConnectivityCheck = DEFAULT_DS_CONNECTIVITY_CHECK;
  32. dwError = ERROR_SUCCESS;
  33. BAIL_ON_WIN32_SUCCESS(dwError);
  34. }
  35. //
  36. // Get DS connectivity check polling interval in minutes.
  37. //
  38. dwError = RegQueryValueEx(
  39. hKey,
  40. L"DSConnectivityCheck",
  41. 0,
  42. &dwtype,
  43. (unsigned char *) &gdwDSConnectivityCheck,
  44. &dwsize
  45. );
  46. if (dwError || !gdwDSConnectivityCheck) {
  47. gdwDSConnectivityCheck = DEFAULT_DS_CONNECTIVITY_CHECK;
  48. dwError = ERROR_SUCCESS;
  49. }
  50. //
  51. // Fix for bug 628668: SECURITY: ITG: BUG: IPsec accepts unsecured packet when
  52. // "accept unsecured" not checked. If OldFallBackToClear == 1, then will revert
  53. // to old behavior and plumb inbound pass thru if fall back to clear selected.
  54. // If OldFallBackToClear 0, then will plumb "negotiate security" instead.
  55. //
  56. dwsize = sizeof(DWORD);
  57. dwError = RegQueryValueEx(
  58. hKey,
  59. L"OldFallBackToClear",
  60. 0,
  61. &dwtype,
  62. (unsigned char *) &dwBackwardSoftSA,
  63. &dwsize
  64. );
  65. if (dwError) {
  66. dwBackwardSoftSA = 0;
  67. dwError = ERROR_SUCCESS;
  68. BAIL_ON_WIN32_SUCCESS(dwError);
  69. }
  70. success:
  71. gbBackwardSoftSA = dwBackwardSoftSA ? TRUE : FALSE;
  72. if (hKey) {
  73. RegCloseKey(hKey);
  74. }
  75. return (dwError);
  76. }
  77. DWORD
  78. InitSPDGlobals(
  79. )
  80. {
  81. DWORD dwError = 0;
  82. SECURITY_ATTRIBUTES SecurityAttributes;
  83. dwError = InitializeSPDSecurity(&gpSPDSD);
  84. BAIL_ON_WIN32_ERROR(dwError);
  85. InitializeCriticalSection(&gcSPDAuditSection);
  86. gbSPDAuditSection = TRUE;
  87. ghIpsecServerModule = GetModuleHandle(SZAPPNAME);
  88. if (!ghIpsecServerModule) {
  89. dwError = ERROR_INVALID_HANDLE;
  90. BAIL_ON_WIN32_ERROR(dwError);
  91. }
  92. memset(&SecurityAttributes, 0, sizeof(SECURITY_ATTRIBUTES));
  93. SecurityAttributes.nLength = sizeof(SecurityAttributes);
  94. SecurityAttributes.lpSecurityDescriptor = NULL;
  95. SecurityAttributes.bInheritHandle = TRUE;
  96. ghNewDSPolicyEvent = CreateEvent(
  97. &SecurityAttributes,
  98. TRUE,
  99. FALSE,
  100. IPSEC_NEW_DS_POLICY_EVENT
  101. );
  102. if (!ghNewDSPolicyEvent) {
  103. dwError = GetLastError();
  104. BAIL_ON_WIN32_ERROR(dwError);
  105. }
  106. ghNewLocalPolicyEvent = CreateEvent(
  107. &SecurityAttributes,
  108. TRUE,
  109. FALSE,
  110. NULL
  111. );
  112. if (!ghNewLocalPolicyEvent) {
  113. dwError = GetLastError();
  114. BAIL_ON_WIN32_ERROR(dwError);
  115. }
  116. ghForcedPolicyReloadEvent = CreateEvent(
  117. &SecurityAttributes,
  118. TRUE,
  119. FALSE,
  120. NULL
  121. );
  122. if (!ghForcedPolicyReloadEvent) {
  123. dwError = GetLastError();
  124. BAIL_ON_WIN32_ERROR(dwError);
  125. }
  126. //
  127. // IPSEC_POLICY_CHANGE_NOTIFY is defined in ipsec.h.
  128. //
  129. ghPolicyChangeNotifyEvent = CreateEvent(
  130. NULL,
  131. TRUE,
  132. FALSE,
  133. IPSEC_POLICY_CHANGE_NOTIFY
  134. );
  135. if (!ghPolicyChangeNotifyEvent) {
  136. dwError = GetLastError();
  137. BAIL_ON_WIN32_ERROR(dwError);
  138. }
  139. ghServiceStopEvent = CreateEvent(
  140. &SecurityAttributes,
  141. TRUE,
  142. FALSE,
  143. NULL
  144. );
  145. if (!ghServiceStopEvent) {
  146. dwError = GetLastError();
  147. BAIL_ON_WIN32_ERROR(dwError);
  148. }
  149. InitializeCriticalSection(&gcServerListenSection);
  150. gbServerListenSection = TRUE;
  151. gdwServersListening = 0;
  152. InitializeCriticalSection(&gcSPDSection);
  153. gbSPDSection = TRUE;
  154. dwError = InitializeInterfaceChangeEvent();
  155. BAIL_ON_WIN32_ERROR(dwError);
  156. dwError = ResetInterfaceChangeEvent();
  157. BAIL_ON_WIN32_ERROR(dwError);
  158. error:
  159. return (dwError);
  160. }