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.

335 lines
6.7 KiB

  1. #include "precomp.h"
  2. LPWSTR gpszIpsecPersistenceKey =
  3. L"SOFTWARE\\Microsoft\\IPSec";
  4. DWORD
  5. LoadPersistedIPSecInformation(
  6. )
  7. {
  8. DWORD dwError = 0;
  9. HKEY hRegistryKey = NULL;
  10. gbLoadingPersistence = TRUE;
  11. dwError = RegOpenKeyExW(
  12. HKEY_LOCAL_MACHINE,
  13. gpszIpsecPersistenceKey,
  14. 0,
  15. KEY_ALL_ACCESS,
  16. &hRegistryKey
  17. );
  18. BAIL_ON_WIN32_ERROR(dwError);
  19. dwError = LoadPersistedMMPolicies(
  20. hRegistryKey
  21. );
  22. dwError = LoadPersistedMMAuthMethods(
  23. hRegistryKey
  24. );
  25. dwError = LoadPersistedMMFilters(
  26. hRegistryKey
  27. );
  28. dwError = LoadPersistedQMPolicies(
  29. hRegistryKey
  30. );
  31. dwError = LoadPersistedTxFilters(
  32. hRegistryKey
  33. );
  34. dwError = LoadPersistedTnFilters(
  35. hRegistryKey
  36. );
  37. dwError = ERROR_SUCCESS;
  38. error:
  39. if (hRegistryKey) {
  40. RegCloseKey(hRegistryKey);
  41. }
  42. gbLoadingPersistence = FALSE;
  43. return (dwError);
  44. }
  45. DWORD
  46. LoadPersistedMMPolicies(
  47. HKEY hParentRegKey
  48. )
  49. {
  50. DWORD dwError = 0;
  51. HKEY hRegKey = NULL;
  52. DWORD dwSize = 0;
  53. WCHAR szMMPolicyUniqueID[MAX_PATH];
  54. DWORD dwIndex = 0;
  55. PIPSEC_MM_POLICY pMMPolicy = NULL;
  56. LPWSTR pszServerName = NULL;
  57. DWORD dwPersist = 0;
  58. dwPersist |= PERSIST_SPD_OBJECT;
  59. dwError = RegOpenKeyExW(
  60. hParentRegKey,
  61. L"MM Policies",
  62. 0,
  63. KEY_ALL_ACCESS,
  64. &hRegKey
  65. );
  66. BAIL_ON_WIN32_ERROR(dwError);
  67. while (1) {
  68. dwSize = MAX_PATH;
  69. szMMPolicyUniqueID[0] = L'\0';
  70. dwError = RegEnumKeyExW(
  71. hRegKey,
  72. dwIndex,
  73. szMMPolicyUniqueID,
  74. &dwSize,
  75. NULL,
  76. NULL,
  77. 0,
  78. 0
  79. );
  80. if (dwError == ERROR_NO_MORE_ITEMS) {
  81. dwError = ERROR_SUCCESS;
  82. break;
  83. }
  84. BAIL_ON_WIN32_ERROR(dwError);
  85. dwError = SPDReadMMPolicy(
  86. hRegKey,
  87. szMMPolicyUniqueID,
  88. &pMMPolicy
  89. );
  90. if (dwError) {
  91. dwIndex++;
  92. continue;
  93. }
  94. dwError = AddMMPolicy(
  95. pszServerName,
  96. dwPersist,
  97. pMMPolicy
  98. );
  99. if (pMMPolicy) {
  100. FreeMMPolicies(
  101. 1,
  102. pMMPolicy
  103. );
  104. }
  105. dwIndex++;
  106. }
  107. error:
  108. if (hRegKey) {
  109. RegCloseKey(hRegKey);
  110. }
  111. return (dwError);
  112. }
  113. DWORD
  114. SPDReadMMPolicy(
  115. HKEY hParentRegKey,
  116. LPWSTR pszMMPolicyUniqueID,
  117. PIPSEC_MM_POLICY * ppMMPolicy
  118. )
  119. {
  120. DWORD dwError = 0;
  121. HKEY hRegKey = NULL;
  122. PIPSEC_MM_POLICY pMMPolicy = NULL;
  123. LPWSTR pszPolicyID = NULL;
  124. DWORD dwSize = 0;
  125. DWORD dwType = 0;
  126. LPBYTE pBuffer = NULL;
  127. DWORD dwBufferSize = 0;
  128. dwError = RegOpenKeyExW(
  129. hParentRegKey,
  130. pszMMPolicyUniqueID,
  131. 0,
  132. KEY_ALL_ACCESS,
  133. &hRegKey
  134. );
  135. BAIL_ON_WIN32_ERROR(dwError);
  136. pMMPolicy = (PIPSEC_MM_POLICY) AllocSPDMem(
  137. sizeof(IPSEC_MM_POLICY)
  138. );
  139. if (!pMMPolicy) {
  140. dwError = ERROR_OUTOFMEMORY;
  141. BAIL_ON_WIN32_ERROR(dwError);
  142. }
  143. dwError = RegstoreQueryValue(
  144. hRegKey,
  145. L"PolicyID",
  146. REG_SZ,
  147. (LPBYTE *)&pszPolicyID,
  148. &dwSize
  149. );
  150. BAIL_ON_WIN32_ERROR(dwError);
  151. wGUIDFromString(
  152. pszPolicyID,
  153. &pMMPolicy->gPolicyID
  154. );
  155. dwError = RegstoreQueryValue(
  156. hRegKey,
  157. L"PolicyName",
  158. REG_SZ,
  159. (LPBYTE *)&pMMPolicy->pszPolicyName,
  160. &dwSize
  161. );
  162. BAIL_ON_WIN32_ERROR(dwError);
  163. dwType = REG_DWORD;
  164. dwSize = sizeof(DWORD);
  165. dwError = RegQueryValueExW(
  166. hRegKey,
  167. L"Flags",
  168. NULL,
  169. &dwType,
  170. (LPBYTE)&pMMPolicy->dwFlags,
  171. &dwSize
  172. );
  173. BAIL_ON_WIN32_ERROR(dwError);
  174. dwType = REG_DWORD;
  175. dwSize = sizeof(DWORD);
  176. dwError = RegQueryValueExW(
  177. hRegKey,
  178. L"SoftSAExpirationTime",
  179. NULL,
  180. &dwType,
  181. (LPBYTE)&pMMPolicy->uSoftSAExpirationTime,
  182. &dwSize
  183. );
  184. BAIL_ON_WIN32_ERROR(dwError);
  185. dwError = RegstoreQueryValue(
  186. hRegKey,
  187. L"Offers",
  188. REG_BINARY,
  189. (LPBYTE *)&pBuffer,
  190. &dwBufferSize
  191. );
  192. BAIL_ON_WIN32_ERROR(dwError);
  193. dwError = UnMarshallMMOffers(
  194. pBuffer,
  195. dwBufferSize,
  196. &pMMPolicy->pOffers,
  197. &pMMPolicy->dwOfferCount
  198. );
  199. BAIL_ON_WIN32_ERROR(dwError);
  200. *ppMMPolicy = pMMPolicy;
  201. cleanup:
  202. if (hRegKey) {
  203. RegCloseKey(hRegKey);
  204. }
  205. if (pszPolicyID) {
  206. FreeSPDStr(pszPolicyID);
  207. }
  208. if (pBuffer) {
  209. FreeSPDMem(pBuffer);
  210. }
  211. return (dwError);
  212. error:
  213. *ppMMPolicy = NULL;
  214. if (pMMPolicy) {
  215. FreeMMPolicies(
  216. 1,
  217. pMMPolicy
  218. );
  219. }
  220. goto cleanup;
  221. }
  222. DWORD
  223. UnMarshallMMOffers(
  224. LPBYTE pBuffer,
  225. DWORD dwBufferSize,
  226. PIPSEC_MM_OFFER * ppOffers,
  227. PDWORD pdwOfferCount
  228. )
  229. {
  230. DWORD dwError = 0;
  231. LPBYTE pMem = NULL;
  232. PIPSEC_MM_OFFER pOffers = NULL;
  233. DWORD dwOfferCount = 0;
  234. pMem = pBuffer;
  235. pMem += sizeof(GUID);
  236. pMem += sizeof(DWORD);
  237. memcpy(
  238. (LPBYTE) &dwOfferCount,
  239. pMem,
  240. sizeof(DWORD)
  241. );
  242. pMem += sizeof(DWORD);
  243. pOffers = (PIPSEC_MM_OFFER) AllocSPDMem(
  244. sizeof(IPSEC_MM_OFFER)*dwOfferCount
  245. );
  246. if (!pOffers) {
  247. dwError = ERROR_OUTOFMEMORY;
  248. BAIL_ON_WIN32_ERROR(dwError);
  249. }
  250. memcpy(
  251. (LPBYTE) pOffers,
  252. pMem,
  253. sizeof(IPSEC_MM_OFFER)*dwOfferCount
  254. );
  255. *ppOffers = pOffers;
  256. *pdwOfferCount = dwOfferCount;
  257. return (dwError);
  258. error:
  259. *ppOffers = NULL;
  260. *pdwOfferCount = 0;
  261. return (dwError);
  262. }