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.

142 lines
3.4 KiB

  1. #include "precomp.h"
  2. DWORD
  3. ExportNFADataToFile(
  4. HANDLE hSrcPolicyStore,
  5. PIPSEC_POLICY_STORE pDesPolicyStore,
  6. PIPSEC_POLICY_DATA * ppIpsecPolicyData,
  7. DWORD dwNumPolicyObjects
  8. )
  9. {
  10. DWORD dwError = 0;
  11. DWORD i = 0;
  12. PIPSEC_POLICY_DATA pIpsecPolicyData = NULL;
  13. DWORD j = 0;
  14. PIPSEC_NFA_DATA * ppIpsecNFAData = NULL;
  15. DWORD dwNumNFAObjects = 0;
  16. PIPSEC_NFA_DATA pIpsecNFAData = NULL;
  17. for (i = 0; i < dwNumPolicyObjects; i++) {
  18. pIpsecPolicyData = *(ppIpsecPolicyData + i);
  19. ppIpsecNFAData = NULL;
  20. dwNumNFAObjects = 0;
  21. dwError = IPSecEnumNFAData(
  22. hSrcPolicyStore,
  23. pIpsecPolicyData->PolicyIdentifier,
  24. &ppIpsecNFAData,
  25. &dwNumNFAObjects
  26. );
  27. if (dwError) {
  28. continue;
  29. }
  30. for (j = 0; j < dwNumNFAObjects; j++) {
  31. pIpsecNFAData = *(ppIpsecNFAData + j);
  32. dwError = RegCreateNFAData(
  33. pDesPolicyStore->hRegistryKey,
  34. pDesPolicyStore->pszIpsecRootContainer,
  35. pIpsecPolicyData->PolicyIdentifier,
  36. pDesPolicyStore->pszLocationName,
  37. pIpsecNFAData
  38. );
  39. if (dwError) {
  40. continue;
  41. }
  42. }
  43. if (ppIpsecNFAData) {
  44. FreeMulIpsecNFAData(
  45. ppIpsecNFAData,
  46. dwNumNFAObjects
  47. );
  48. }
  49. }
  50. dwError = ERROR_SUCCESS;
  51. return (dwError);
  52. }
  53. DWORD
  54. ImportNFADataFromFile(
  55. PIPSEC_POLICY_STORE pSrcPolicyStore,
  56. HANDLE hDesPolicyStore,
  57. PIPSEC_POLICY_DATA * ppIpsecPolicyData,
  58. DWORD dwNumPolicyObjects
  59. )
  60. {
  61. DWORD dwError = 0;
  62. DWORD i = 0;
  63. PIPSEC_POLICY_DATA pIpsecPolicyData = NULL;
  64. DWORD j = 0;
  65. PIPSEC_NFA_DATA * ppIpsecNFAData = NULL;
  66. DWORD dwNumNFAObjects = 0;
  67. PIPSEC_NFA_DATA pIpsecNFAData = NULL;
  68. for (i = 0; i < dwNumPolicyObjects; i++) {
  69. pIpsecPolicyData = *(ppIpsecPolicyData + i);
  70. ppIpsecNFAData = NULL;
  71. dwNumNFAObjects = 0;
  72. dwError = RegEnumNFAData(
  73. pSrcPolicyStore->hRegistryKey,
  74. pSrcPolicyStore->pszIpsecRootContainer,
  75. pIpsecPolicyData->PolicyIdentifier,
  76. &ppIpsecNFAData,
  77. &dwNumNFAObjects
  78. );
  79. if (dwError) {
  80. continue;
  81. }
  82. for (j = 0; j < dwNumNFAObjects; j++) {
  83. pIpsecNFAData = *(ppIpsecNFAData + j);
  84. dwError = IPSecCreateNFAData(
  85. hDesPolicyStore,
  86. pIpsecPolicyData->PolicyIdentifier,
  87. pIpsecNFAData
  88. );
  89. if (dwError == ERROR_OBJECT_ALREADY_EXISTS) {
  90. dwError = IPSecSetNFAData(
  91. hDesPolicyStore,
  92. pIpsecPolicyData->PolicyIdentifier,
  93. pIpsecNFAData
  94. );
  95. }
  96. if (dwError) {
  97. continue;
  98. }
  99. }
  100. if (ppIpsecNFAData) {
  101. FreeMulIpsecNFAData(
  102. ppIpsecNFAData,
  103. dwNumNFAObjects
  104. );
  105. }
  106. }
  107. dwError = ERROR_SUCCESS;
  108. return (dwError);
  109. }