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.

103 lines
2.3 KiB

  1. #include "precomp.h"
  2. DWORD
  3. ExportNegPolDataToFile(
  4. HANDLE hSrcPolicyStore,
  5. PIPSEC_POLICY_STORE pDesPolicyStore
  6. )
  7. {
  8. DWORD dwError = 0;
  9. PIPSEC_NEGPOL_DATA * ppIpsecNegPolData = NULL;
  10. DWORD dwNumNegPolObjects = 0;
  11. DWORD i = 0;
  12. PIPSEC_NEGPOL_DATA pIpsecNegPolData = NULL;
  13. dwError = IPSecEnumNegPolData(
  14. hSrcPolicyStore,
  15. &ppIpsecNegPolData,
  16. &dwNumNegPolObjects
  17. );
  18. BAIL_ON_WIN32_ERROR(dwError);
  19. for (i = 0; i < dwNumNegPolObjects; i++) {
  20. pIpsecNegPolData = *(ppIpsecNegPolData + i);
  21. dwError = RegCreateNegPolData(
  22. pDesPolicyStore->hRegistryKey,
  23. pDesPolicyStore->pszIpsecRootContainer,
  24. pIpsecNegPolData
  25. );
  26. BAIL_ON_WIN32_ERROR(dwError);
  27. }
  28. error:
  29. if (ppIpsecNegPolData) {
  30. FreeMulIpsecNegPolData(
  31. ppIpsecNegPolData,
  32. dwNumNegPolObjects
  33. );
  34. }
  35. return (dwError);
  36. }
  37. DWORD
  38. ImportNegPolDataFromFile(
  39. PIPSEC_POLICY_STORE pSrcPolicyStore,
  40. HANDLE hDesPolicyStore
  41. )
  42. {
  43. DWORD dwError = 0;
  44. PIPSEC_NEGPOL_DATA * ppIpsecNegPolData = NULL;
  45. DWORD dwNumNegPolObjects = 0;
  46. DWORD i = 0;
  47. PIPSEC_NEGPOL_DATA pIpsecNegPolData = NULL;
  48. dwError = RegEnumNegPolData(
  49. pSrcPolicyStore->hRegistryKey,
  50. pSrcPolicyStore->pszIpsecRootContainer,
  51. &ppIpsecNegPolData,
  52. &dwNumNegPolObjects
  53. );
  54. BAIL_ON_WIN32_ERROR(dwError);
  55. for (i = 0; i < dwNumNegPolObjects; i++) {
  56. pIpsecNegPolData = *(ppIpsecNegPolData + i);
  57. dwError = IPSecCreateNegPolData(
  58. hDesPolicyStore,
  59. pIpsecNegPolData
  60. );
  61. if (dwError == ERROR_OBJECT_ALREADY_EXISTS) {
  62. dwError = IPSecSetNegPolData(
  63. hDesPolicyStore,
  64. pIpsecNegPolData
  65. );
  66. BAIL_ON_WIN32_ERROR(dwError);
  67. }
  68. BAIL_ON_WIN32_ERROR(dwError);
  69. }
  70. error:
  71. if (ppIpsecNegPolData) {
  72. FreeMulIpsecNegPolData(
  73. ppIpsecNegPolData,
  74. dwNumNegPolObjects
  75. );
  76. }
  77. return (dwError);
  78. }