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.

186 lines
4.0 KiB

  1. #include "precomp.h"
  2. #define COUNTOF(x) (sizeof x/sizeof *x)
  3. DWORD
  4. DllRegisterServer(
  5. )
  6. {
  7. DWORD dwError = 0;
  8. HKEY hRegistryKey = NULL;
  9. HKEY hOakleyKey = NULL;
  10. DWORD dwDisposition = 0;
  11. DWORD dwTypesSupported = 7;
  12. HKEY hPolicyLocationKey = NULL;
  13. HANDLE hPolicyStore = NULL;
  14. dwError = RegOpenKeyExW(
  15. HKEY_LOCAL_MACHINE,
  16. (LPCWSTR) L"SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application",
  17. 0,
  18. KEY_ALL_ACCESS,
  19. &hRegistryKey
  20. );
  21. BAIL_ON_WIN32_ERROR(dwError);
  22. dwError = RegCreateKeyExW(
  23. hRegistryKey,
  24. L"Oakley",
  25. 0,
  26. NULL,
  27. 0,
  28. KEY_ALL_ACCESS,
  29. NULL,
  30. &hOakleyKey,
  31. &dwDisposition
  32. );
  33. BAIL_ON_WIN32_ERROR(dwError);
  34. dwError = RegSetValueExW(
  35. hOakleyKey,
  36. L"EventMessageFile",
  37. 0,
  38. REG_SZ,
  39. (LPBYTE) L"%SystemRoot%\\System32\\oakley.dll",
  40. (wcslen(L"%SystemRoot%\\System32\\oakley.dll") + 1)*sizeof(WCHAR)
  41. );
  42. BAIL_ON_WIN32_ERROR(dwError);
  43. dwError = RegSetValueExW(
  44. hOakleyKey,
  45. L"TypesSupported",
  46. 0,
  47. REG_DWORD,
  48. (LPBYTE) &dwTypesSupported,
  49. sizeof(DWORD)
  50. );
  51. BAIL_ON_WIN32_ERROR(dwError);
  52. if (IsCleanInstall()) {
  53. dwError = RegCreateKeyExW(
  54. HKEY_LOCAL_MACHINE,
  55. L"SOFTWARE\\Policies\\Microsoft\\Windows\\IPSec\\Policy\\Local",
  56. 0,
  57. NULL,
  58. 0,
  59. KEY_ALL_ACCESS,
  60. NULL,
  61. &hPolicyLocationKey,
  62. &dwDisposition
  63. );
  64. BAIL_ON_WIN32_ERROR(dwError);
  65. dwError = IPSecOpenPolicyStore(
  66. NULL,
  67. IPSEC_REGISTRY_PROVIDER,
  68. NULL,
  69. &hPolicyStore
  70. );
  71. BAIL_ON_WIN32_ERROR(dwError);
  72. dwError = GenerateDefaultInformation(
  73. hPolicyStore
  74. );
  75. BAIL_ON_WIN32_ERROR(dwError);
  76. }
  77. error:
  78. if (hPolicyStore) {
  79. (VOID) IPSecClosePolicyStore(
  80. hPolicyStore
  81. );
  82. }
  83. if (hPolicyLocationKey) {
  84. RegCloseKey(hPolicyLocationKey);
  85. }
  86. if (hOakleyKey) {
  87. RegCloseKey(hOakleyKey);
  88. }
  89. if (hRegistryKey) {
  90. RegCloseKey(hRegistryKey);
  91. }
  92. return (dwError);
  93. }
  94. DWORD
  95. DllUnregisterServer(
  96. )
  97. {
  98. return (ERROR_SUCCESS);
  99. }
  100. BOOL
  101. IsCleanInstall(
  102. )
  103. {
  104. BOOL bStatus = FALSE;
  105. bStatus = LocalIpsecInfoExists(
  106. HKEY_LOCAL_MACHINE,
  107. L"SOFTWARE\\Policies\\Microsoft\\Windows\\IPSec\\Policy\\Local"
  108. );
  109. return (!bStatus);
  110. }
  111. BOOL
  112. LocalIpsecInfoExists(
  113. HKEY hSourceParentKey,
  114. LPWSTR pszSourceKey
  115. )
  116. {
  117. DWORD dwError = 0;
  118. HKEY hSourceKey = NULL;
  119. BOOL bStatus = FALSE;
  120. WCHAR lpszName[MAX_PATH];
  121. DWORD dwSize = 0;
  122. DWORD dwCount = 0;
  123. dwError = RegOpenKeyExW(
  124. hSourceParentKey,
  125. pszSourceKey,
  126. 0,
  127. KEY_ALL_ACCESS,
  128. &hSourceKey
  129. );
  130. if (dwError != ERROR_SUCCESS) {
  131. return (bStatus);
  132. }
  133. memset(lpszName, 0, sizeof(WCHAR)*MAX_PATH);
  134. dwSize = COUNTOF(lpszName);
  135. if ((RegEnumKeyExW(
  136. hSourceKey,
  137. dwCount,
  138. lpszName,
  139. &dwSize,
  140. NULL,
  141. NULL,
  142. NULL,
  143. NULL)) == ERROR_SUCCESS) {
  144. bStatus = TRUE;
  145. }
  146. else {
  147. bStatus = FALSE;
  148. }
  149. RegCloseKey(hSourceKey);
  150. return (bStatus);
  151. }