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.

233 lines
5.0 KiB

  1. #include "precomp.h"
  2. LPWSTR gpszIpsecLocalPolicyKey = L"SOFTWARE\\Policies\\Microsoft\\Windows\\IPSec\\Policy\\Local";
  3. LPWSTR gpszIpsecDSPolicyKey = L"SOFTWARE\\Policies\\Microsoft\\Windows\\IPSec\\GPTIPSECPolicy";
  4. DWORD
  5. IPSecIsDomainPolicyAssigned(
  6. PBOOL pbIsDomainPolicyAssigned
  7. )
  8. {
  9. DWORD dwError = 0;
  10. BOOL bIsDomainPolicyAssigned = FALSE;
  11. HKEY hRegistryKey = NULL;
  12. DWORD dwType = 0;
  13. DWORD dwDSPolicyPathLength = 0;
  14. dwError = RegOpenKeyExW(
  15. HKEY_LOCAL_MACHINE,
  16. (LPCWSTR) gpszIpsecDSPolicyKey,
  17. 0,
  18. KEY_ALL_ACCESS,
  19. &hRegistryKey
  20. );
  21. BAIL_ON_WIN32_ERROR(dwError);
  22. dwError = RegQueryValueExW(
  23. hRegistryKey,
  24. L"DSIPSECPolicyPath",
  25. NULL,
  26. &dwType,
  27. NULL,
  28. &dwDSPolicyPathLength
  29. );
  30. BAIL_ON_WIN32_ERROR(dwError);
  31. if (dwDSPolicyPathLength > 0) {
  32. bIsDomainPolicyAssigned = TRUE;
  33. }
  34. *pbIsDomainPolicyAssigned = bIsDomainPolicyAssigned;
  35. cleanup:
  36. if (hRegistryKey) {
  37. RegCloseKey(hRegistryKey);
  38. }
  39. return (dwError);
  40. error:
  41. *pbIsDomainPolicyAssigned = FALSE;
  42. goto cleanup;
  43. }
  44. DWORD
  45. IPSecIsLocalPolicyAssigned(
  46. PBOOL pbIsLocalPolicyAssigned
  47. )
  48. {
  49. DWORD dwError = 0;
  50. BOOL bIsLocalPolicyAssigned = FALSE;
  51. HKEY hRegistryKey = NULL;
  52. DWORD dwType = 0;
  53. DWORD dwLocalPolicyPathLength = 0;
  54. dwError = RegOpenKeyExW(
  55. HKEY_LOCAL_MACHINE,
  56. (LPCWSTR) gpszIpsecLocalPolicyKey,
  57. 0,
  58. KEY_ALL_ACCESS,
  59. &hRegistryKey
  60. );
  61. BAIL_ON_WIN32_ERROR(dwError);
  62. dwError = RegQueryValueExW(
  63. hRegistryKey,
  64. L"ActivePolicy",
  65. NULL,
  66. &dwType,
  67. NULL,
  68. &dwLocalPolicyPathLength
  69. );
  70. BAIL_ON_WIN32_ERROR(dwError);
  71. if (dwLocalPolicyPathLength > 0) {
  72. bIsLocalPolicyAssigned = TRUE;
  73. }
  74. *pbIsLocalPolicyAssigned = bIsLocalPolicyAssigned;
  75. cleanup:
  76. if (hRegistryKey) {
  77. RegCloseKey(hRegistryKey);
  78. }
  79. return (dwError);
  80. error:
  81. *pbIsLocalPolicyAssigned = FALSE;
  82. goto cleanup;
  83. }
  84. DWORD
  85. IPSecGetAssignedDomainPolicyName(
  86. LPWSTR * ppszAssignedDomainPolicyName
  87. )
  88. {
  89. DWORD dwError = 0;
  90. LPWSTR pszAssignedDomainPolicyName = NULL;
  91. HKEY hRegistryKey = NULL;
  92. DWORD dwType = 0;
  93. DWORD dwSize = 0;
  94. dwError = RegOpenKeyExW(
  95. HKEY_LOCAL_MACHINE,
  96. (LPCWSTR) gpszIpsecDSPolicyKey,
  97. 0,
  98. KEY_ALL_ACCESS,
  99. &hRegistryKey
  100. );
  101. BAIL_ON_WIN32_ERROR(dwError);
  102. dwError = RegstoreQueryValue(
  103. hRegistryKey,
  104. L"DSIPSECPolicyName",
  105. REG_SZ,
  106. (LPBYTE *)&pszAssignedDomainPolicyName,
  107. &dwSize
  108. );
  109. BAIL_ON_WIN32_ERROR(dwError);
  110. *ppszAssignedDomainPolicyName = pszAssignedDomainPolicyName;
  111. cleanup:
  112. if (hRegistryKey) {
  113. RegCloseKey(hRegistryKey);
  114. }
  115. return (dwError);
  116. error:
  117. *ppszAssignedDomainPolicyName = NULL;
  118. goto cleanup;
  119. }
  120. DWORD
  121. RegGetAssignedPolicyData(
  122. HKEY hRegistryKey,
  123. LPWSTR pszIpsecRootContainer,
  124. PIPSEC_POLICY_DATA * ppIpsecPolicyData
  125. )
  126. {
  127. DWORD dwError = 0;
  128. LPWSTR pszIpsecPolicyName = NULL;
  129. DWORD dwSize = 0;
  130. LPWSTR pszRelativeName = NULL;
  131. PIPSEC_POLICY_OBJECT pIpsecPolicyObject = NULL;
  132. PIPSEC_POLICY_DATA pIpsecPolicyData = NULL;
  133. dwError = RegstoreQueryValue(
  134. hRegistryKey,
  135. L"ActivePolicy",
  136. REG_SZ,
  137. (LPBYTE *)&pszIpsecPolicyName,
  138. &dwSize
  139. );
  140. if (pszIpsecPolicyName && *pszIpsecPolicyName) {
  141. if (wcslen(pszIpsecPolicyName) >
  142. (wcslen(pszIpsecRootContainer) + 1)) {
  143. pszRelativeName = pszIpsecPolicyName
  144. + wcslen(pszIpsecRootContainer) + 1;
  145. dwError = UnMarshallRegistryPolicyObject(
  146. hRegistryKey,
  147. pszIpsecRootContainer,
  148. pszRelativeName,
  149. REG_RELATIVE_NAME,
  150. &pIpsecPolicyObject
  151. );
  152. BAIL_ON_WIN32_ERROR(dwError);
  153. dwError = RegUnmarshallPolicyData(
  154. pIpsecPolicyObject,
  155. &pIpsecPolicyData
  156. );
  157. BAIL_ON_WIN32_ERROR(dwError);
  158. }
  159. }
  160. *ppIpsecPolicyData = pIpsecPolicyData;
  161. cleanup:
  162. if (pszIpsecPolicyName) {
  163. FreePolStr(pszIpsecPolicyName);
  164. }
  165. if (pIpsecPolicyObject) {
  166. FreeIpsecPolicyObject(
  167. pIpsecPolicyObject
  168. );
  169. }
  170. return (dwError);
  171. error:
  172. *ppIpsecPolicyData = NULL;
  173. goto cleanup;
  174. }