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.

218 lines
5.2 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. #ifdef TRACE_ON
  16. #include "init.tmh"
  17. #endif
  18. #define SZAPPNAME L"ipsecsvc.dll"
  19. DWORD
  20. InitSPDThruRegistry(
  21. )
  22. {
  23. DWORD dwError = 0;
  24. HKEY hKey = NULL;
  25. DWORD dwtype = REG_DWORD;
  26. DWORD dwsize = sizeof(DWORD);
  27. DWORD dwBackwardSoftSA = 0;
  28. dwError = RegOpenKey(
  29. HKEY_LOCAL_MACHINE,
  30. gpszLocPolicyAgent,
  31. &hKey
  32. );
  33. if (dwError) {
  34. dwBackwardSoftSA = 0;
  35. dwError = ERROR_SUCCESS;
  36. BAIL_ON_WIN32_SUCCESS(dwError);
  37. }
  38. dwError = RegQueryValueEx(
  39. hKey,
  40. L"OldFallBackToClear",
  41. 0,
  42. &dwtype,
  43. (unsigned char *) &dwBackwardSoftSA,
  44. &dwsize
  45. );
  46. if (dwError) {
  47. dwBackwardSoftSA = 0;
  48. dwError = ERROR_SUCCESS;
  49. BAIL_ON_WIN32_SUCCESS(dwError);
  50. }
  51. success:
  52. gbBackwardSoftSA = dwBackwardSoftSA ? TRUE : FALSE;
  53. if (hKey) {
  54. RegCloseKey(hKey);
  55. }
  56. return (dwError);
  57. }
  58. DWORD InitAuditing(
  59. )
  60. {
  61. DWORD dwError = 0;
  62. InitializeCriticalSection(&gcSPDAuditSection);
  63. gbSPDAuditSection = TRUE;
  64. ghIpsecServerModule = GetModuleHandle(SZAPPNAME);
  65. if (!ghIpsecServerModule) {
  66. dwError = ERROR_INVALID_HANDLE;
  67. BAIL_ON_WIN32_ERROR(dwError);
  68. }
  69. gbAuditingInitialized = TRUE;
  70. return dwError;
  71. error:
  72. TRACE(TRC_ERROR, (L"Failed to initialize auditing %!winerr!", dwError));
  73. return dwError;
  74. }
  75. DWORD
  76. InitSPDGlobals(
  77. )
  78. {
  79. DWORD dwError = 0;
  80. SECURITY_ATTRIBUTES SecurityAttributes;
  81. dwError = InitializeSPDSecurity(&gpSPDSD);
  82. BAIL_ON_WIN32_ERROR(dwError);
  83. memset(&SecurityAttributes, 0, sizeof(SECURITY_ATTRIBUTES));
  84. SecurityAttributes.nLength = sizeof(SecurityAttributes);
  85. SecurityAttributes.lpSecurityDescriptor = NULL;
  86. SecurityAttributes.bInheritHandle = TRUE;
  87. ghNewDSPolicyEvent = CreateEvent(
  88. &SecurityAttributes,
  89. TRUE,
  90. FALSE,
  91. IPSEC_NEW_DS_POLICY_EVENT
  92. );
  93. if (!ghNewDSPolicyEvent) {
  94. dwError = GetLastError();
  95. BAIL_ON_WIN32_ERROR(dwError);
  96. }
  97. ghNewLocalPolicyEvent = CreateEvent(
  98. &SecurityAttributes,
  99. TRUE,
  100. FALSE,
  101. NULL
  102. );
  103. if (!ghNewLocalPolicyEvent) {
  104. dwError = GetLastError();
  105. BAIL_ON_WIN32_ERROR(dwError);
  106. }
  107. ghForcedPolicyReloadEvent = CreateEvent(
  108. &SecurityAttributes,
  109. TRUE,
  110. FALSE,
  111. NULL
  112. );
  113. if (!ghForcedPolicyReloadEvent) {
  114. dwError = GetLastError();
  115. BAIL_ON_WIN32_ERROR(dwError);
  116. }
  117. //
  118. // IPSEC_POLICY_CHANGE_NOTIFY is defined in ipsec.h.
  119. //
  120. ghPolicyChangeNotifyEvent = CreateEvent(
  121. NULL,
  122. TRUE,
  123. FALSE,
  124. IPSEC_POLICY_CHANGE_NOTIFY
  125. );
  126. if (!ghPolicyChangeNotifyEvent) {
  127. dwError = GetLastError();
  128. BAIL_ON_WIN32_ERROR(dwError);
  129. }
  130. ghServiceStopEvent = CreateEvent(
  131. &SecurityAttributes,
  132. TRUE,
  133. FALSE,
  134. NULL
  135. );
  136. if (!ghServiceStopEvent) {
  137. dwError = GetLastError();
  138. BAIL_ON_WIN32_ERROR(dwError);
  139. }
  140. ghGpupdateRefreshEvent = CreateEvent(
  141. &SecurityAttributes,
  142. TRUE,
  143. FALSE,
  144. IPSEC_GP_REFRESH_EVENT
  145. );
  146. if (!ghGpupdateRefreshEvent) {
  147. dwError = GetLastError();
  148. BAIL_ON_WIN32_ERROR(dwError);
  149. }
  150. InitializeCriticalSection(&gcServerListenSection);
  151. gbServerListenSection = TRUE;
  152. gdwServersListening = 0;
  153. InitializeCriticalSection(&gcSPDSection);
  154. gbSPDSection = TRUE;
  155. dwError = InitializeInterfaceChangeEvent();
  156. BAIL_ON_WIN32_ERROR(dwError);
  157. dwError = ResetInterfaceChangeEvent();
  158. BAIL_ON_WIN32_ERROR(dwError);
  159. InitializePolicyStateBlock(
  160. gpIpsecPolicyState
  161. );
  162. return (dwError);
  163. error:
  164. TRACE(TRC_ERROR, (L"Failed to initialize SPD globals %!winerr!", dwError));
  165. return (dwError);
  166. }