Leaked source code of windows server 2003
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.

121 lines
2.9 KiB

  1. #include "precomp.h"
  2. DWORD
  3. ExportPolicyDataToFile(
  4. HANDLE hSrcPolicyStore,
  5. PIPSEC_POLICY_STORE pDesPolicyStore,
  6. PIPSEC_POLICY_DATA ** pppIpsecPolicyData,
  7. PDWORD pdwNumPolicyObjects
  8. )
  9. {
  10. DWORD dwError = 0;
  11. PIPSEC_POLICY_DATA * ppIpsecPolicyData = NULL;
  12. DWORD dwNumPolicyObjects = 0;
  13. DWORD i = 0;
  14. PIPSEC_POLICY_DATA pIpsecPolicyData = NULL;
  15. dwError = IPSecEnumPolicyData(
  16. hSrcPolicyStore,
  17. &ppIpsecPolicyData,
  18. &dwNumPolicyObjects
  19. );
  20. BAIL_ON_WIN32_ERROR(dwError);
  21. for (i = 0; i < dwNumPolicyObjects; i++) {
  22. pIpsecPolicyData = *(ppIpsecPolicyData + i);
  23. dwError = RegCreatePolicyData(
  24. pDesPolicyStore->hRegistryKey,
  25. pDesPolicyStore->pszIpsecRootContainer,
  26. pIpsecPolicyData
  27. );
  28. BAIL_ON_WIN32_ERROR(dwError);
  29. }
  30. *pppIpsecPolicyData = ppIpsecPolicyData;
  31. *pdwNumPolicyObjects = dwNumPolicyObjects;
  32. return (dwError);
  33. error:
  34. if (ppIpsecPolicyData) {
  35. FreeMulIpsecPolicyData(
  36. ppIpsecPolicyData,
  37. dwNumPolicyObjects
  38. );
  39. }
  40. *pppIpsecPolicyData = NULL;
  41. *pdwNumPolicyObjects = 0;
  42. return (dwError);
  43. }
  44. DWORD
  45. ImportPolicyDataFromFile(
  46. PIPSEC_POLICY_STORE pSrcPolicyStore,
  47. HANDLE hDesPolicyStore,
  48. PIPSEC_POLICY_DATA ** pppIpsecPolicyData,
  49. PDWORD pdwNumPolicyObjects
  50. )
  51. {
  52. DWORD dwError = 0;
  53. PIPSEC_POLICY_DATA * ppIpsecPolicyData = NULL;
  54. DWORD dwNumPolicyObjects = 0;
  55. DWORD i = 0;
  56. PIPSEC_POLICY_DATA pIpsecPolicyData = NULL;
  57. dwError = RegEnumPolicyData(
  58. pSrcPolicyStore->hRegistryKey,
  59. pSrcPolicyStore->pszIpsecRootContainer,
  60. &ppIpsecPolicyData,
  61. &dwNumPolicyObjects
  62. );
  63. BAIL_ON_WIN32_ERROR(dwError);
  64. for (i = 0; i < dwNumPolicyObjects; i++) {
  65. pIpsecPolicyData = *(ppIpsecPolicyData + i);
  66. dwError = IPSecCreatePolicyData(
  67. hDesPolicyStore,
  68. pIpsecPolicyData
  69. );
  70. if (dwError == ERROR_OBJECT_ALREADY_EXISTS) {
  71. dwError = IPSecSetPolicyData(
  72. hDesPolicyStore,
  73. pIpsecPolicyData
  74. );
  75. BAIL_ON_WIN32_ERROR(dwError);
  76. }
  77. BAIL_ON_WIN32_ERROR(dwError);
  78. }
  79. *pppIpsecPolicyData = ppIpsecPolicyData;
  80. *pdwNumPolicyObjects = dwNumPolicyObjects;
  81. return (dwError);
  82. error:
  83. if (ppIpsecPolicyData) {
  84. FreeMulIpsecPolicyData(
  85. ppIpsecPolicyData,
  86. dwNumPolicyObjects
  87. );
  88. }
  89. *pppIpsecPolicyData = NULL;
  90. *pdwNumPolicyObjects = 0;
  91. return (dwError);
  92. }