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.

296 lines
5.9 KiB

  1. #include "precomp.h"
  2. LPWSTR gpszIpsecQMPoliciesKey =
  3. L"SOFTWARE\\Microsoft\\IPSec\\QM Policies";
  4. DWORD
  5. PersistQMPolicy(
  6. PIPSEC_QM_POLICY pQMPolicy
  7. )
  8. {
  9. DWORD dwError = 0;
  10. HKEY hRegistryKey = NULL;
  11. DWORD dwDisposition = 0;
  12. dwError = RegCreateKeyExW(
  13. HKEY_LOCAL_MACHINE,
  14. gpszIpsecQMPoliciesKey,
  15. 0,
  16. NULL,
  17. 0,
  18. KEY_ALL_ACCESS,
  19. NULL,
  20. &hRegistryKey,
  21. &dwDisposition
  22. );
  23. BAIL_ON_WIN32_ERROR(dwError);
  24. dwError = SPDWriteQMPolicy(
  25. hRegistryKey,
  26. pQMPolicy
  27. );
  28. BAIL_ON_WIN32_ERROR(dwError);
  29. cleanup:
  30. if (hRegistryKey) {
  31. RegCloseKey(hRegistryKey);
  32. }
  33. return (dwError);
  34. error:
  35. if (hRegistryKey) {
  36. (VOID) SPDPurgeQMPolicy(
  37. pQMPolicy->gPolicyID
  38. );
  39. }
  40. goto cleanup;
  41. }
  42. DWORD
  43. SPDWriteQMPolicy(
  44. HKEY hParentRegKey,
  45. PIPSEC_QM_POLICY pQMPolicy
  46. )
  47. {
  48. DWORD dwError = 0;
  49. WCHAR szPolicyID[MAX_PATH];
  50. LPWSTR pszStringUuid = NULL;
  51. HKEY hRegKey = NULL;
  52. DWORD dwDisposition = 0;
  53. LPBYTE pBuffer = NULL;
  54. DWORD dwBufferSize = 0;
  55. szPolicyID[0] = L'\0';
  56. dwError = UuidToString(
  57. &pQMPolicy->gPolicyID,
  58. &pszStringUuid
  59. );
  60. BAIL_ON_WIN32_ERROR(dwError);
  61. wcscpy(szPolicyID, L"{");
  62. wcscat(szPolicyID, pszStringUuid);
  63. wcscat(szPolicyID, L"}");
  64. dwError = RegCreateKeyExW(
  65. hParentRegKey,
  66. szPolicyID,
  67. 0,
  68. NULL,
  69. 0,
  70. KEY_ALL_ACCESS,
  71. NULL,
  72. &hRegKey,
  73. &dwDisposition
  74. );
  75. BAIL_ON_WIN32_ERROR(dwError);
  76. dwError = RegSetValueExW(
  77. hRegKey,
  78. L"PolicyID",
  79. 0,
  80. REG_SZ,
  81. (LPBYTE) szPolicyID,
  82. (wcslen(szPolicyID) + 1)*sizeof(WCHAR)
  83. );
  84. BAIL_ON_WIN32_ERROR(dwError);
  85. dwError = RegSetValueExW(
  86. hRegKey,
  87. L"PolicyName",
  88. 0,
  89. REG_SZ,
  90. (LPBYTE) pQMPolicy->pszPolicyName,
  91. (wcslen(pQMPolicy->pszPolicyName) + 1)*sizeof(WCHAR)
  92. );
  93. BAIL_ON_WIN32_ERROR(dwError);
  94. dwError = RegSetValueExW(
  95. hRegKey,
  96. L"Flags",
  97. 0,
  98. REG_DWORD,
  99. (LPBYTE)&pQMPolicy->dwFlags,
  100. sizeof(DWORD)
  101. );
  102. BAIL_ON_WIN32_ERROR(dwError);
  103. dwError = MarshallQMOffers(
  104. pQMPolicy->pOffers,
  105. pQMPolicy->dwOfferCount,
  106. &pBuffer,
  107. &dwBufferSize
  108. );
  109. BAIL_ON_WIN32_ERROR(dwError);
  110. dwError = RegSetValueExW(
  111. hRegKey,
  112. L"Offers",
  113. 0,
  114. REG_BINARY,
  115. (LPBYTE) pBuffer,
  116. dwBufferSize
  117. );
  118. BAIL_ON_WIN32_ERROR(dwError);
  119. cleanup:
  120. if (pszStringUuid) {
  121. RpcStringFree(&pszStringUuid);
  122. }
  123. if (hRegKey) {
  124. RegCloseKey(hRegKey);
  125. }
  126. if (pBuffer) {
  127. FreeSPDMem(pBuffer);
  128. }
  129. return (dwError);
  130. error:
  131. goto cleanup;
  132. }
  133. DWORD
  134. MarshallQMOffers(
  135. PIPSEC_QM_OFFER pOffers,
  136. DWORD dwOfferCount,
  137. LPBYTE * ppBuffer,
  138. PDWORD pdwBufferSize
  139. )
  140. {
  141. DWORD dwError = 0;
  142. LPBYTE pBuffer = NULL;
  143. DWORD dwBufferSize = 0;
  144. LPBYTE pMem = NULL;
  145. static const GUID GUID_IPSEC_QM_OFFER_VER1 =
  146. { 0xabcd0002, 0x0001, 0x0001, { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 } };
  147. dwBufferSize = sizeof(GUID) +
  148. sizeof(DWORD) +
  149. sizeof(DWORD) +
  150. sizeof(IPSEC_QM_OFFER)*dwOfferCount;
  151. pBuffer = (LPBYTE) AllocSPDMem(
  152. dwBufferSize
  153. );
  154. if (!pBuffer) {
  155. dwError = ERROR_OUTOFMEMORY;
  156. BAIL_ON_WIN32_ERROR(dwError);
  157. }
  158. pMem = pBuffer;
  159. memcpy(
  160. pMem,
  161. (LPBYTE) &GUID_IPSEC_QM_OFFER_VER1,
  162. sizeof(GUID)
  163. );
  164. pMem += sizeof(GUID);
  165. memcpy(
  166. pMem,
  167. (LPBYTE) &dwBufferSize,
  168. sizeof(DWORD)
  169. );
  170. pMem += sizeof(DWORD);
  171. memcpy(
  172. pMem,
  173. (LPBYTE) &dwOfferCount,
  174. sizeof(DWORD)
  175. );
  176. pMem += sizeof(DWORD);
  177. memcpy(
  178. pMem,
  179. (LPBYTE) pOffers,
  180. sizeof(IPSEC_QM_OFFER)*dwOfferCount
  181. );
  182. *ppBuffer = pBuffer;
  183. *pdwBufferSize = dwBufferSize;
  184. return (dwError);
  185. error:
  186. *ppBuffer = NULL;
  187. *pdwBufferSize = 0;
  188. return (dwError);
  189. }
  190. DWORD
  191. SPDPurgeQMPolicy(
  192. GUID gQMPolicyID
  193. )
  194. {
  195. DWORD dwError = 0;
  196. HKEY hParentRegKey = NULL;
  197. DWORD dwDisposition = 0;
  198. WCHAR szPolicyID[MAX_PATH];
  199. LPWSTR pszStringUuid = NULL;
  200. dwError = RegCreateKeyExW(
  201. HKEY_LOCAL_MACHINE,
  202. gpszIpsecQMPoliciesKey,
  203. 0,
  204. NULL,
  205. 0,
  206. KEY_ALL_ACCESS,
  207. NULL,
  208. &hParentRegKey,
  209. &dwDisposition
  210. );
  211. BAIL_ON_WIN32_ERROR(dwError);
  212. szPolicyID[0] = L'\0';
  213. dwError = UuidToString(
  214. &gQMPolicyID,
  215. &pszStringUuid
  216. );
  217. BAIL_ON_WIN32_ERROR(dwError);
  218. wcscpy(szPolicyID, L"{");
  219. wcscat(szPolicyID, pszStringUuid);
  220. wcscat(szPolicyID, L"}");
  221. dwError = RegDeleteKeyW(
  222. hParentRegKey,
  223. szPolicyID
  224. );
  225. BAIL_ON_WIN32_ERROR(dwError);
  226. error:
  227. if (hParentRegKey) {
  228. RegCloseKey(hParentRegKey);
  229. }
  230. if (pszStringUuid) {
  231. RpcStringFree(&pszStringUuid);
  232. }
  233. return(dwError);
  234. }