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.

262 lines
5.2 KiB

  1. #include "precomp.h"
  2. DWORD
  3. LoadPersistedQMPolicies(
  4. HKEY hParentRegKey
  5. )
  6. {
  7. DWORD dwError = 0;
  8. HKEY hRegKey = NULL;
  9. DWORD dwSize = 0;
  10. WCHAR szQMPolicyUniqueID[MAX_PATH];
  11. DWORD dwIndex = 0;
  12. PIPSEC_QM_POLICY pQMPolicy = NULL;
  13. LPWSTR pszServerName = NULL;
  14. DWORD dwPersist = 0;
  15. dwPersist |= PERSIST_SPD_OBJECT;
  16. dwError = RegOpenKeyExW(
  17. hParentRegKey,
  18. L"QM Policies",
  19. 0,
  20. KEY_ALL_ACCESS,
  21. &hRegKey
  22. );
  23. BAIL_ON_WIN32_ERROR(dwError);
  24. while (1) {
  25. dwSize = MAX_PATH;
  26. szQMPolicyUniqueID[0] = L'\0';
  27. dwError = RegEnumKeyExW(
  28. hRegKey,
  29. dwIndex,
  30. szQMPolicyUniqueID,
  31. &dwSize,
  32. NULL,
  33. NULL,
  34. 0,
  35. 0
  36. );
  37. if (dwError == ERROR_NO_MORE_ITEMS) {
  38. dwError = ERROR_SUCCESS;
  39. break;
  40. }
  41. BAIL_ON_WIN32_ERROR(dwError);
  42. dwError = SPDReadQMPolicy(
  43. hRegKey,
  44. szQMPolicyUniqueID,
  45. &pQMPolicy
  46. );
  47. if (dwError) {
  48. dwIndex++;
  49. continue;
  50. }
  51. dwError = AddQMPolicy(
  52. pszServerName,
  53. dwPersist,
  54. pQMPolicy
  55. );
  56. if (pQMPolicy) {
  57. FreeQMPolicies(
  58. 1,
  59. pQMPolicy
  60. );
  61. }
  62. dwIndex++;
  63. }
  64. error:
  65. if (hRegKey) {
  66. RegCloseKey(hRegKey);
  67. }
  68. return (dwError);
  69. }
  70. DWORD
  71. SPDReadQMPolicy(
  72. HKEY hParentRegKey,
  73. LPWSTR pszQMPolicyUniqueID,
  74. PIPSEC_QM_POLICY * ppQMPolicy
  75. )
  76. {
  77. DWORD dwError = 0;
  78. HKEY hRegKey = NULL;
  79. PIPSEC_QM_POLICY pQMPolicy = NULL;
  80. LPWSTR pszPolicyID = NULL;
  81. DWORD dwSize = 0;
  82. DWORD dwType = 0;
  83. LPBYTE pBuffer = NULL;
  84. DWORD dwBufferSize = 0;
  85. dwError = RegOpenKeyExW(
  86. hParentRegKey,
  87. pszQMPolicyUniqueID,
  88. 0,
  89. KEY_ALL_ACCESS,
  90. &hRegKey
  91. );
  92. BAIL_ON_WIN32_ERROR(dwError);
  93. pQMPolicy = (PIPSEC_QM_POLICY) AllocSPDMem(
  94. sizeof(IPSEC_QM_POLICY)
  95. );
  96. if (!pQMPolicy) {
  97. dwError = ERROR_OUTOFMEMORY;
  98. BAIL_ON_WIN32_ERROR(dwError);
  99. }
  100. dwError = RegstoreQueryValue(
  101. hRegKey,
  102. L"PolicyID",
  103. REG_SZ,
  104. (LPBYTE *)&pszPolicyID,
  105. &dwSize
  106. );
  107. BAIL_ON_WIN32_ERROR(dwError);
  108. wGUIDFromString(
  109. pszPolicyID,
  110. &pQMPolicy->gPolicyID
  111. );
  112. dwError = RegstoreQueryValue(
  113. hRegKey,
  114. L"PolicyName",
  115. REG_SZ,
  116. (LPBYTE *)&pQMPolicy->pszPolicyName,
  117. &dwSize
  118. );
  119. BAIL_ON_WIN32_ERROR(dwError);
  120. dwType = REG_DWORD;
  121. dwSize = sizeof(DWORD);
  122. dwError = RegQueryValueExW(
  123. hRegKey,
  124. L"Flags",
  125. NULL,
  126. &dwType,
  127. (LPBYTE)&pQMPolicy->dwFlags,
  128. &dwSize
  129. );
  130. BAIL_ON_WIN32_ERROR(dwError);
  131. dwError = RegstoreQueryValue(
  132. hRegKey,
  133. L"Offers",
  134. REG_BINARY,
  135. (LPBYTE *)&pBuffer,
  136. &dwBufferSize
  137. );
  138. BAIL_ON_WIN32_ERROR(dwError);
  139. dwError = UnMarshallQMOffers(
  140. pBuffer,
  141. dwBufferSize,
  142. &pQMPolicy->pOffers,
  143. &pQMPolicy->dwOfferCount
  144. );
  145. BAIL_ON_WIN32_ERROR(dwError);
  146. *ppQMPolicy = pQMPolicy;
  147. cleanup:
  148. if (hRegKey) {
  149. RegCloseKey(hRegKey);
  150. }
  151. if (pszPolicyID) {
  152. FreeSPDStr(pszPolicyID);
  153. }
  154. if (pBuffer) {
  155. FreeSPDMem(pBuffer);
  156. }
  157. return (dwError);
  158. error:
  159. *ppQMPolicy = NULL;
  160. if (pQMPolicy) {
  161. FreeQMPolicies(
  162. 1,
  163. pQMPolicy
  164. );
  165. }
  166. goto cleanup;
  167. }
  168. DWORD
  169. UnMarshallQMOffers(
  170. LPBYTE pBuffer,
  171. DWORD dwBufferSize,
  172. PIPSEC_QM_OFFER * ppOffers,
  173. PDWORD pdwOfferCount
  174. )
  175. {
  176. DWORD dwError = 0;
  177. LPBYTE pMem = NULL;
  178. PIPSEC_QM_OFFER pOffers = NULL;
  179. DWORD dwOfferCount = 0;
  180. pMem = pBuffer;
  181. pMem += sizeof(GUID);
  182. pMem += sizeof(DWORD);
  183. memcpy(
  184. (LPBYTE) &dwOfferCount,
  185. pMem,
  186. sizeof(DWORD)
  187. );
  188. pMem += sizeof(DWORD);
  189. pOffers = (PIPSEC_QM_OFFER) AllocSPDMem(
  190. sizeof(IPSEC_QM_OFFER)*dwOfferCount
  191. );
  192. if (!pOffers) {
  193. dwError = ERROR_OUTOFMEMORY;
  194. BAIL_ON_WIN32_ERROR(dwError);
  195. }
  196. memcpy(
  197. (LPBYTE) pOffers,
  198. pMem,
  199. sizeof(IPSEC_QM_OFFER)*dwOfferCount
  200. );
  201. *ppOffers = pOffers;
  202. *pdwOfferCount = dwOfferCount;
  203. return (dwError);
  204. error:
  205. *ppOffers = NULL;
  206. *pdwOfferCount = 0;
  207. return (dwError);
  208. }