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.

1801 lines
41 KiB

  1. #include "precomp.h"
  2. LPWSTR gpszIpsecRegRootContainer = L"SOFTWARE\\Policies\\Microsoft\\Windows\\IPSec\\Policy\\Local";
  3. LPWSTR gpszIpsecFileRootContainer = L"SOFTWARE\\Policies\\Microsoft\\Windows\\IPSec\\Policy\\Save";
  4. DWORD
  5. IPSecEnumPolicyData(
  6. HANDLE hPolicyStore,
  7. PIPSEC_POLICY_DATA ** pppIpsecPolicyData,
  8. PDWORD pdwNumPolicyObjects
  9. )
  10. {
  11. DWORD dwError = 0;
  12. DWORD dwProvider = 0;
  13. PIPSEC_POLICY_STORE pPolicyStore = NULL;
  14. pPolicyStore = (PIPSEC_POLICY_STORE)hPolicyStore;
  15. switch (pPolicyStore->dwProvider) {
  16. case IPSEC_REGISTRY_PROVIDER:
  17. dwError = RegEnumPolicyData(
  18. (pPolicyStore->hRegistryKey),
  19. pPolicyStore->pszIpsecRootContainer,
  20. pppIpsecPolicyData,
  21. pdwNumPolicyObjects
  22. );
  23. break;
  24. case IPSEC_DIRECTORY_PROVIDER:
  25. dwError = DirEnumPolicyData(
  26. (pPolicyStore->hLdapBindHandle),
  27. pPolicyStore->pszIpsecRootContainer,
  28. pppIpsecPolicyData,
  29. pdwNumPolicyObjects
  30. );
  31. break;
  32. default:
  33. dwError = ERROR_INVALID_PARAMETER;
  34. break;
  35. }
  36. return(dwError);
  37. }
  38. DWORD
  39. IPSecSetPolicyData(
  40. HANDLE hPolicyStore,
  41. PIPSEC_POLICY_DATA pIpsecPolicyData
  42. )
  43. {
  44. DWORD dwError = 0;
  45. DWORD dwProvider = 0;
  46. PIPSEC_POLICY_STORE pPolicyStore = NULL;
  47. dwError = ValidatePolicyData(
  48. hPolicyStore,
  49. pIpsecPolicyData
  50. );
  51. BAIL_ON_WIN32_ERROR(dwError);
  52. pPolicyStore = (PIPSEC_POLICY_STORE)hPolicyStore;
  53. switch (pPolicyStore->dwProvider) {
  54. case IPSEC_REGISTRY_PROVIDER:
  55. dwError = RegSetPolicyData(
  56. (pPolicyStore->hRegistryKey),
  57. pPolicyStore->pszIpsecRootContainer,
  58. pPolicyStore->pszLocationName,
  59. pIpsecPolicyData
  60. );
  61. break;
  62. case IPSEC_DIRECTORY_PROVIDER:
  63. dwError = DirSetPolicyData(
  64. (pPolicyStore->hLdapBindHandle),
  65. pPolicyStore->pszIpsecRootContainer,
  66. pIpsecPolicyData
  67. );
  68. break;
  69. default:
  70. dwError = ERROR_INVALID_PARAMETER;
  71. break;
  72. }
  73. error:
  74. return(dwError);
  75. }
  76. DWORD
  77. IPSecCreatePolicyData(
  78. HANDLE hPolicyStore,
  79. PIPSEC_POLICY_DATA pIpsecPolicyData
  80. )
  81. {
  82. DWORD dwError = 0;
  83. DWORD dwProvider = 0;
  84. PIPSEC_POLICY_STORE pPolicyStore = NULL;
  85. dwError = ValidatePolicyData(
  86. hPolicyStore,
  87. pIpsecPolicyData
  88. );
  89. BAIL_ON_WIN32_ERROR(dwError);
  90. pPolicyStore = (PIPSEC_POLICY_STORE)hPolicyStore;
  91. switch (pPolicyStore->dwProvider) {
  92. case IPSEC_REGISTRY_PROVIDER:
  93. dwError = RegCreatePolicyData(
  94. (pPolicyStore->hRegistryKey),
  95. pPolicyStore->pszIpsecRootContainer,
  96. pIpsecPolicyData
  97. );
  98. break;
  99. case IPSEC_DIRECTORY_PROVIDER:
  100. dwError = DirCreatePolicyData(
  101. (pPolicyStore->hLdapBindHandle),
  102. pPolicyStore->pszIpsecRootContainer,
  103. pIpsecPolicyData
  104. );
  105. break;
  106. default:
  107. dwError = ERROR_INVALID_PARAMETER;
  108. break;
  109. }
  110. error:
  111. return(dwError);
  112. }
  113. DWORD
  114. IPSecDeletePolicyData(
  115. HANDLE hPolicyStore,
  116. PIPSEC_POLICY_DATA pIpsecPolicyData
  117. )
  118. {
  119. DWORD dwError = 0;
  120. DWORD dwProvider = 0;
  121. PIPSEC_POLICY_STORE pPolicyStore = NULL;
  122. dwError = ValidatePolicyDataDeletion(
  123. hPolicyStore,
  124. pIpsecPolicyData
  125. );
  126. BAIL_ON_WIN32_ERROR(dwError);
  127. pPolicyStore = (PIPSEC_POLICY_STORE)hPolicyStore;
  128. switch (pPolicyStore->dwProvider) {
  129. case IPSEC_REGISTRY_PROVIDER:
  130. dwError = RegDeletePolicyData(
  131. (pPolicyStore->hRegistryKey),
  132. pPolicyStore->pszIpsecRootContainer,
  133. pIpsecPolicyData
  134. );
  135. break;
  136. case IPSEC_DIRECTORY_PROVIDER:
  137. dwError = DirDeletePolicyData(
  138. (pPolicyStore->hLdapBindHandle),
  139. pPolicyStore->pszIpsecRootContainer,
  140. pIpsecPolicyData
  141. );
  142. break;
  143. default:
  144. dwError = ERROR_INVALID_PARAMETER;
  145. break;
  146. }
  147. error:
  148. return(dwError);
  149. }
  150. DWORD
  151. IPSecEnumFilterData(
  152. HANDLE hPolicyStore,
  153. PIPSEC_FILTER_DATA ** pppIpsecFilterData,
  154. PDWORD pdwNumFilterObjects
  155. )
  156. {
  157. DWORD dwError = 0;
  158. DWORD dwProvider = 0;
  159. PIPSEC_POLICY_STORE pPolicyStore = NULL;
  160. pPolicyStore = (PIPSEC_POLICY_STORE)hPolicyStore;
  161. switch (pPolicyStore->dwProvider) {
  162. case IPSEC_REGISTRY_PROVIDER:
  163. dwError = RegEnumFilterData(
  164. (pPolicyStore->hRegistryKey),
  165. pPolicyStore->pszIpsecRootContainer,
  166. pppIpsecFilterData,
  167. pdwNumFilterObjects
  168. );
  169. break;
  170. case IPSEC_DIRECTORY_PROVIDER:
  171. dwError = DirEnumFilterData(
  172. (pPolicyStore->hLdapBindHandle),
  173. (pPolicyStore->pszIpsecRootContainer),
  174. pppIpsecFilterData,
  175. pdwNumFilterObjects
  176. );
  177. break;
  178. default:
  179. dwError = ERROR_INVALID_PARAMETER;
  180. break;
  181. }
  182. return(dwError);
  183. }
  184. DWORD
  185. IPSecSetFilterData(
  186. HANDLE hPolicyStore,
  187. PIPSEC_FILTER_DATA pIpsecFilterData
  188. )
  189. {
  190. DWORD dwError = 0;
  191. DWORD dwProvider = 0;
  192. PIPSEC_POLICY_STORE pPolicyStore = NULL;
  193. pPolicyStore = (PIPSEC_POLICY_STORE)hPolicyStore;
  194. switch (pPolicyStore->dwProvider) {
  195. case IPSEC_REGISTRY_PROVIDER:
  196. dwError = RegSetFilterData(
  197. (pPolicyStore->hRegistryKey),
  198. pPolicyStore->pszIpsecRootContainer,
  199. pPolicyStore->pszLocationName,
  200. pIpsecFilterData
  201. );
  202. break;
  203. case IPSEC_DIRECTORY_PROVIDER:
  204. dwError = DirSetFilterData(
  205. (pPolicyStore->hLdapBindHandle),
  206. (pPolicyStore->pszIpsecRootContainer),
  207. pIpsecFilterData
  208. );
  209. break;
  210. default:
  211. dwError = ERROR_INVALID_PARAMETER;
  212. break;
  213. }
  214. return(dwError);
  215. }
  216. DWORD
  217. IPSecCreateFilterData(
  218. HANDLE hPolicyStore,
  219. PIPSEC_FILTER_DATA pIpsecFilterData
  220. )
  221. {
  222. DWORD dwError = 0;
  223. DWORD dwProvider = 0;
  224. PIPSEC_POLICY_STORE pPolicyStore = NULL;
  225. pPolicyStore = (PIPSEC_POLICY_STORE)hPolicyStore;
  226. switch (pPolicyStore->dwProvider) {
  227. case IPSEC_REGISTRY_PROVIDER:
  228. dwError = RegCreateFilterData(
  229. (pPolicyStore->hRegistryKey),
  230. pPolicyStore->pszIpsecRootContainer,
  231. pIpsecFilterData
  232. );
  233. break;
  234. case IPSEC_DIRECTORY_PROVIDER:
  235. dwError = DirCreateFilterData(
  236. (pPolicyStore->hLdapBindHandle),
  237. (pPolicyStore->pszIpsecRootContainer),
  238. pIpsecFilterData
  239. );
  240. break;
  241. default:
  242. dwError = ERROR_INVALID_PARAMETER;
  243. break;
  244. }
  245. return(dwError);
  246. }
  247. DWORD
  248. IPSecDeleteFilterData(
  249. HANDLE hPolicyStore,
  250. GUID FilterIdentifier
  251. )
  252. {
  253. DWORD dwError = 0;
  254. DWORD dwProvider = 0;
  255. PIPSEC_POLICY_STORE pPolicyStore = NULL;
  256. dwError = ValidateFilterDataDeletion(
  257. hPolicyStore,
  258. FilterIdentifier
  259. );
  260. BAIL_ON_WIN32_ERROR(dwError);
  261. pPolicyStore = (PIPSEC_POLICY_STORE)hPolicyStore;
  262. switch (pPolicyStore->dwProvider) {
  263. case IPSEC_REGISTRY_PROVIDER:
  264. dwError = RegDeleteFilterData(
  265. (pPolicyStore->hRegistryKey),
  266. pPolicyStore->pszIpsecRootContainer,
  267. FilterIdentifier
  268. );
  269. break;
  270. case IPSEC_DIRECTORY_PROVIDER:
  271. dwError = DirDeleteFilterData(
  272. (pPolicyStore->hLdapBindHandle),
  273. (pPolicyStore->pszIpsecRootContainer),
  274. FilterIdentifier
  275. );
  276. break;
  277. default:
  278. dwError = ERROR_INVALID_PARAMETER;
  279. break;
  280. }
  281. error:
  282. return(dwError);
  283. }
  284. DWORD
  285. IPSecEnumNegPolData(
  286. HANDLE hPolicyStore,
  287. PIPSEC_NEGPOL_DATA ** pppIpsecNegPolData,
  288. PDWORD pdwNumNegPolObjects
  289. )
  290. {
  291. DWORD dwError = 0;
  292. DWORD dwProvider = 0;
  293. PIPSEC_POLICY_STORE pPolicyStore = NULL;
  294. pPolicyStore = (PIPSEC_POLICY_STORE)hPolicyStore;
  295. switch (pPolicyStore->dwProvider) {
  296. case IPSEC_REGISTRY_PROVIDER:
  297. dwError = RegEnumNegPolData(
  298. (pPolicyStore->hRegistryKey),
  299. pPolicyStore->pszIpsecRootContainer,
  300. pppIpsecNegPolData,
  301. pdwNumNegPolObjects
  302. );
  303. break;
  304. case IPSEC_DIRECTORY_PROVIDER:
  305. dwError = DirEnumNegPolData(
  306. (pPolicyStore->hLdapBindHandle),
  307. pPolicyStore->pszIpsecRootContainer,
  308. pppIpsecNegPolData,
  309. pdwNumNegPolObjects
  310. );
  311. break;
  312. default:
  313. dwError = ERROR_INVALID_PARAMETER;
  314. break;
  315. }
  316. return(dwError);
  317. }
  318. DWORD
  319. IPSecSetNegPolData(
  320. HANDLE hPolicyStore,
  321. PIPSEC_NEGPOL_DATA pIpsecNegPolData
  322. )
  323. {
  324. DWORD dwError = 0;
  325. DWORD dwProvider = 0;
  326. PIPSEC_POLICY_STORE pPolicyStore = NULL;
  327. dwError = ValidateNegPolData(
  328. pIpsecNegPolData
  329. );
  330. BAIL_ON_WIN32_ERROR(dwError);
  331. pPolicyStore = (PIPSEC_POLICY_STORE)hPolicyStore;
  332. switch (pPolicyStore->dwProvider) {
  333. case IPSEC_REGISTRY_PROVIDER:
  334. dwError = RegSetNegPolData(
  335. (pPolicyStore->hRegistryKey),
  336. pPolicyStore->pszIpsecRootContainer,
  337. pPolicyStore->pszLocationName,
  338. pIpsecNegPolData
  339. );
  340. break;
  341. case IPSEC_DIRECTORY_PROVIDER:
  342. dwError = DirSetNegPolData(
  343. (pPolicyStore->hLdapBindHandle),
  344. pPolicyStore->pszIpsecRootContainer,
  345. pIpsecNegPolData
  346. );
  347. break;
  348. default:
  349. dwError = ERROR_INVALID_PARAMETER;
  350. break;
  351. }
  352. error:
  353. return(dwError);
  354. }
  355. DWORD
  356. IPSecCreateNegPolData(
  357. HANDLE hPolicyStore,
  358. PIPSEC_NEGPOL_DATA pIpsecNegPolData
  359. )
  360. {
  361. DWORD dwError = 0;
  362. DWORD dwProvider = 0;
  363. PIPSEC_POLICY_STORE pPolicyStore = NULL;
  364. dwError = ValidateNegPolData(
  365. pIpsecNegPolData
  366. );
  367. BAIL_ON_WIN32_ERROR(dwError);
  368. pPolicyStore = (PIPSEC_POLICY_STORE)hPolicyStore;
  369. switch (pPolicyStore->dwProvider) {
  370. case IPSEC_REGISTRY_PROVIDER:
  371. dwError = RegCreateNegPolData(
  372. (pPolicyStore->hRegistryKey),
  373. pPolicyStore->pszIpsecRootContainer,
  374. pIpsecNegPolData
  375. );
  376. break;
  377. case IPSEC_DIRECTORY_PROVIDER:
  378. dwError = DirCreateNegPolData(
  379. (pPolicyStore->hLdapBindHandle),
  380. pPolicyStore->pszIpsecRootContainer,
  381. pIpsecNegPolData
  382. );
  383. break;
  384. default:
  385. dwError = ERROR_INVALID_PARAMETER;
  386. break;
  387. }
  388. error:
  389. return(dwError);
  390. }
  391. DWORD
  392. IPSecDeleteNegPolData(
  393. HANDLE hPolicyStore,
  394. GUID NegPolIdentifier
  395. )
  396. {
  397. DWORD dwError = 0;
  398. DWORD dwProvider = 0;
  399. PIPSEC_POLICY_STORE pPolicyStore = NULL;
  400. dwError = ValidateNegPolDataDeletion(
  401. hPolicyStore,
  402. NegPolIdentifier
  403. );
  404. BAIL_ON_WIN32_ERROR(dwError);
  405. pPolicyStore = (PIPSEC_POLICY_STORE)hPolicyStore;
  406. switch (pPolicyStore->dwProvider) {
  407. case IPSEC_REGISTRY_PROVIDER:
  408. dwError = RegDeleteNegPolData(
  409. (pPolicyStore->hRegistryKey),
  410. pPolicyStore->pszIpsecRootContainer,
  411. NegPolIdentifier
  412. );
  413. break;
  414. case IPSEC_DIRECTORY_PROVIDER:
  415. dwError = DirDeleteNegPolData(
  416. (pPolicyStore->hLdapBindHandle),
  417. pPolicyStore->pszIpsecRootContainer,
  418. NegPolIdentifier
  419. );
  420. break;
  421. default:
  422. dwError = ERROR_INVALID_PARAMETER;
  423. break;
  424. }
  425. error:
  426. return(dwError);
  427. }
  428. DWORD
  429. IPSecCreateNFAData(
  430. HANDLE hPolicyStore,
  431. GUID PolicyIdentifier,
  432. PIPSEC_NFA_DATA pIpsecNFAData
  433. )
  434. {
  435. DWORD dwError = 0;
  436. DWORD dwProvider = 0;
  437. PIPSEC_POLICY_STORE pPolicyStore = NULL;
  438. dwError = ValidateNFAData(
  439. hPolicyStore,
  440. PolicyIdentifier,
  441. pIpsecNFAData
  442. );
  443. BAIL_ON_WIN32_ERROR(dwError);
  444. pPolicyStore = (PIPSEC_POLICY_STORE)hPolicyStore;
  445. switch(pPolicyStore->dwProvider) {
  446. case IPSEC_REGISTRY_PROVIDER:
  447. dwError = RegCreateNFAData(
  448. (pPolicyStore->hRegistryKey),
  449. pPolicyStore->pszIpsecRootContainer,
  450. PolicyIdentifier,
  451. pPolicyStore->pszLocationName,
  452. pIpsecNFAData
  453. );
  454. break;
  455. case IPSEC_DIRECTORY_PROVIDER:
  456. dwError = DirCreateNFAData(
  457. (pPolicyStore->hLdapBindHandle),
  458. pPolicyStore->pszIpsecRootContainer,
  459. PolicyIdentifier,
  460. pIpsecNFAData
  461. );
  462. break;
  463. default:
  464. dwError = ERROR_INVALID_PARAMETER;
  465. break;
  466. }
  467. error:
  468. return(dwError);
  469. }
  470. DWORD
  471. IPSecSetNFAData(
  472. HANDLE hPolicyStore,
  473. GUID PolicyIdentifier,
  474. PIPSEC_NFA_DATA pIpsecNFAData
  475. )
  476. {
  477. DWORD dwError = 0;
  478. DWORD dwProvider = 0;
  479. PIPSEC_POLICY_STORE pPolicyStore = NULL;
  480. dwError = ValidateNFAData(
  481. hPolicyStore,
  482. PolicyIdentifier,
  483. pIpsecNFAData
  484. );
  485. BAIL_ON_WIN32_ERROR(dwError);
  486. pPolicyStore = (PIPSEC_POLICY_STORE)hPolicyStore;
  487. switch (pPolicyStore->dwProvider) {
  488. case IPSEC_REGISTRY_PROVIDER:
  489. dwError = RegSetNFAData(
  490. (pPolicyStore->hRegistryKey),
  491. pPolicyStore->pszIpsecRootContainer,
  492. PolicyIdentifier,
  493. pPolicyStore->pszLocationName,
  494. pIpsecNFAData
  495. );
  496. break;
  497. case IPSEC_DIRECTORY_PROVIDER:
  498. dwError = DirSetNFAData(
  499. (pPolicyStore->hLdapBindHandle),
  500. pPolicyStore->pszIpsecRootContainer,
  501. PolicyIdentifier,
  502. pIpsecNFAData
  503. );
  504. break;
  505. default:
  506. dwError = ERROR_INVALID_PARAMETER;
  507. break;
  508. }
  509. error:
  510. return(dwError);
  511. }
  512. DWORD
  513. IPSecDeleteNFAData(
  514. HANDLE hPolicyStore,
  515. GUID PolicyIdentifier,
  516. PIPSEC_NFA_DATA pIpsecNFAData
  517. )
  518. {
  519. DWORD dwError = 0;
  520. DWORD dwProvider = 0;
  521. PIPSEC_POLICY_STORE pPolicyStore = NULL;
  522. pPolicyStore = (PIPSEC_POLICY_STORE)hPolicyStore;
  523. switch (pPolicyStore->dwProvider) {
  524. case IPSEC_REGISTRY_PROVIDER:
  525. dwError = RegDeleteNFAData(
  526. (pPolicyStore->hRegistryKey),
  527. (pPolicyStore->pszIpsecRootContainer),
  528. PolicyIdentifier,
  529. pPolicyStore->pszLocationName,
  530. pIpsecNFAData
  531. );
  532. break;
  533. case IPSEC_DIRECTORY_PROVIDER:
  534. dwError = DirDeleteNFAData(
  535. (pPolicyStore->hLdapBindHandle),
  536. pPolicyStore->pszIpsecRootContainer,
  537. PolicyIdentifier,
  538. pIpsecNFAData
  539. );
  540. break;
  541. default:
  542. dwError = ERROR_INVALID_PARAMETER;
  543. break;
  544. }
  545. return(dwError);
  546. }
  547. DWORD
  548. IPSecEnumNFAData(
  549. HANDLE hPolicyStore,
  550. GUID PolicyIdentifier,
  551. PIPSEC_NFA_DATA ** pppIpsecNFAData,
  552. PDWORD pdwNumNFAObjects
  553. )
  554. {
  555. DWORD dwError = 0;
  556. DWORD dwProvider = 0;
  557. PIPSEC_POLICY_STORE pPolicyStore = NULL;
  558. pPolicyStore = (PIPSEC_POLICY_STORE)hPolicyStore;
  559. switch (pPolicyStore->dwProvider) {
  560. case IPSEC_REGISTRY_PROVIDER:
  561. dwError = RegEnumNFAData(
  562. (pPolicyStore->hRegistryKey),
  563. pPolicyStore->pszIpsecRootContainer,
  564. PolicyIdentifier,
  565. pppIpsecNFAData,
  566. pdwNumNFAObjects
  567. );
  568. break;
  569. case IPSEC_DIRECTORY_PROVIDER:
  570. dwError = DirEnumNFAData(
  571. (pPolicyStore->hLdapBindHandle),
  572. pPolicyStore->pszIpsecRootContainer,
  573. PolicyIdentifier,
  574. pppIpsecNFAData,
  575. pdwNumNFAObjects
  576. );
  577. break;
  578. default:
  579. dwError = ERROR_INVALID_PARAMETER;
  580. break;
  581. }
  582. return(dwError);
  583. }
  584. DWORD
  585. IPSecGetFilterData(
  586. HANDLE hPolicyStore,
  587. GUID FilterGUID,
  588. PIPSEC_FILTER_DATA * ppIpsecFilterData
  589. )
  590. {
  591. DWORD dwError = 0;
  592. DWORD dwProvider = 0;
  593. PIPSEC_POLICY_STORE pPolicyStore = NULL;
  594. pPolicyStore = (PIPSEC_POLICY_STORE)hPolicyStore;
  595. switch (pPolicyStore->dwProvider) {
  596. case IPSEC_REGISTRY_PROVIDER:
  597. dwError = RegGetFilterData(
  598. (pPolicyStore->hRegistryKey),
  599. pPolicyStore->pszIpsecRootContainer,
  600. FilterGUID,
  601. ppIpsecFilterData
  602. );
  603. break;
  604. case IPSEC_DIRECTORY_PROVIDER:
  605. dwError = DirGetFilterData(
  606. (pPolicyStore->hLdapBindHandle),
  607. (pPolicyStore->pszIpsecRootContainer),
  608. FilterGUID,
  609. ppIpsecFilterData
  610. );
  611. break;
  612. default:
  613. dwError = ERROR_INVALID_PARAMETER;
  614. break;
  615. }
  616. return(dwError);
  617. }
  618. DWORD
  619. IPSecGetNegPolData(
  620. HANDLE hPolicyStore,
  621. GUID NegPolGUID,
  622. PIPSEC_NEGPOL_DATA * ppIpsecNegPolData
  623. )
  624. {
  625. DWORD dwError = 0;
  626. DWORD dwProvider = 0;
  627. PIPSEC_POLICY_STORE pPolicyStore = NULL;
  628. pPolicyStore = (PIPSEC_POLICY_STORE)hPolicyStore;
  629. switch (pPolicyStore->dwProvider) {
  630. case IPSEC_REGISTRY_PROVIDER:
  631. dwError = RegGetNegPolData(
  632. (pPolicyStore->hRegistryKey),
  633. pPolicyStore->pszIpsecRootContainer,
  634. NegPolGUID,
  635. ppIpsecNegPolData
  636. );
  637. break;
  638. case IPSEC_DIRECTORY_PROVIDER:
  639. dwError = DirGetNegPolData(
  640. (pPolicyStore->hLdapBindHandle),
  641. pPolicyStore->pszIpsecRootContainer,
  642. NegPolGUID,
  643. ppIpsecNegPolData
  644. );
  645. break;
  646. default:
  647. dwError = ERROR_INVALID_PARAMETER;
  648. break;
  649. }
  650. return(dwError);
  651. }
  652. DWORD
  653. IPSecEnumISAKMPData(
  654. HANDLE hPolicyStore,
  655. PIPSEC_ISAKMP_DATA ** pppIpsecISAKMPData,
  656. PDWORD pdwNumISAKMPObjects
  657. )
  658. {
  659. DWORD dwError = 0;
  660. DWORD dwProvider = 0;
  661. PIPSEC_POLICY_STORE pPolicyStore = NULL;
  662. pPolicyStore = (PIPSEC_POLICY_STORE)hPolicyStore;
  663. switch (pPolicyStore->dwProvider) {
  664. case IPSEC_REGISTRY_PROVIDER:
  665. dwError = RegEnumISAKMPData(
  666. (pPolicyStore->hRegistryKey),
  667. pPolicyStore->pszIpsecRootContainer,
  668. pppIpsecISAKMPData,
  669. pdwNumISAKMPObjects
  670. );
  671. break;
  672. case IPSEC_DIRECTORY_PROVIDER:
  673. dwError = DirEnumISAKMPData(
  674. (pPolicyStore->hLdapBindHandle),
  675. pPolicyStore->pszIpsecRootContainer,
  676. pppIpsecISAKMPData,
  677. pdwNumISAKMPObjects
  678. );
  679. break;
  680. default:
  681. dwError = ERROR_INVALID_PARAMETER;
  682. break;
  683. }
  684. return(dwError);
  685. }
  686. DWORD
  687. IPSecSetISAKMPData(
  688. HANDLE hPolicyStore,
  689. PIPSEC_ISAKMP_DATA pIpsecISAKMPData
  690. )
  691. {
  692. DWORD dwError = 0;
  693. DWORD dwProvider = 0;
  694. PIPSEC_POLICY_STORE pPolicyStore = NULL;
  695. dwError = ValidateISAKMPData(
  696. pIpsecISAKMPData
  697. );
  698. BAIL_ON_WIN32_ERROR(dwError);
  699. pPolicyStore = (PIPSEC_POLICY_STORE)hPolicyStore;
  700. switch (pPolicyStore->dwProvider) {
  701. case IPSEC_REGISTRY_PROVIDER:
  702. dwError = RegSetISAKMPData(
  703. (pPolicyStore->hRegistryKey),
  704. pPolicyStore->pszIpsecRootContainer,
  705. pPolicyStore->pszLocationName,
  706. pIpsecISAKMPData
  707. );
  708. break;
  709. case IPSEC_DIRECTORY_PROVIDER:
  710. dwError = DirSetISAKMPData(
  711. (pPolicyStore->hLdapBindHandle),
  712. pPolicyStore->pszIpsecRootContainer,
  713. pIpsecISAKMPData
  714. );
  715. break;
  716. default:
  717. dwError = ERROR_INVALID_PARAMETER;
  718. break;
  719. }
  720. error:
  721. return(dwError);
  722. }
  723. DWORD
  724. IPSecCreateISAKMPData(
  725. HANDLE hPolicyStore,
  726. PIPSEC_ISAKMP_DATA pIpsecISAKMPData
  727. )
  728. {
  729. DWORD dwError = 0;
  730. DWORD dwProvider = 0;
  731. PIPSEC_POLICY_STORE pPolicyStore = NULL;
  732. dwError = ValidateISAKMPData(
  733. pIpsecISAKMPData
  734. );
  735. BAIL_ON_WIN32_ERROR(dwError);
  736. pPolicyStore = (PIPSEC_POLICY_STORE)hPolicyStore;
  737. switch (pPolicyStore->dwProvider) {
  738. case IPSEC_REGISTRY_PROVIDER:
  739. dwError = RegCreateISAKMPData(
  740. (pPolicyStore->hRegistryKey),
  741. pPolicyStore->pszIpsecRootContainer,
  742. pIpsecISAKMPData
  743. );
  744. break;
  745. case IPSEC_DIRECTORY_PROVIDER:
  746. dwError = DirCreateISAKMPData(
  747. (pPolicyStore->hLdapBindHandle),
  748. pPolicyStore->pszIpsecRootContainer,
  749. pIpsecISAKMPData
  750. );
  751. break;
  752. default:
  753. dwError = ERROR_INVALID_PARAMETER;
  754. break;
  755. }
  756. error:
  757. return(dwError);
  758. }
  759. DWORD
  760. IPSecDeleteISAKMPData(
  761. HANDLE hPolicyStore,
  762. GUID ISAKMPIdentifier
  763. )
  764. {
  765. DWORD dwError = 0;
  766. DWORD dwProvider = 0;
  767. PIPSEC_POLICY_STORE pPolicyStore = NULL;
  768. dwError = ValidateISAKMPDataDeletion(
  769. hPolicyStore,
  770. ISAKMPIdentifier
  771. );
  772. BAIL_ON_WIN32_ERROR(dwError);
  773. pPolicyStore = (PIPSEC_POLICY_STORE)hPolicyStore;
  774. switch (pPolicyStore->dwProvider) {
  775. case IPSEC_REGISTRY_PROVIDER:
  776. dwError = RegDeleteISAKMPData(
  777. (pPolicyStore->hRegistryKey),
  778. pPolicyStore->pszIpsecRootContainer,
  779. ISAKMPIdentifier
  780. );
  781. break;
  782. case IPSEC_DIRECTORY_PROVIDER:
  783. dwError = DirDeleteISAKMPData(
  784. (pPolicyStore->hLdapBindHandle),
  785. pPolicyStore->pszIpsecRootContainer,
  786. ISAKMPIdentifier
  787. );
  788. break;
  789. default:
  790. dwError = ERROR_INVALID_PARAMETER;
  791. break;
  792. }
  793. error:
  794. return(dwError);
  795. }
  796. DWORD
  797. IPSecGetISAKMPData(
  798. HANDLE hPolicyStore,
  799. GUID ISAKMPGUID,
  800. PIPSEC_ISAKMP_DATA * ppIpsecISAKMPData
  801. )
  802. {
  803. DWORD dwError = 0;
  804. DWORD dwProvider = 0;
  805. PIPSEC_POLICY_STORE pPolicyStore = NULL;
  806. pPolicyStore = (PIPSEC_POLICY_STORE)hPolicyStore;
  807. switch (pPolicyStore->dwProvider) {
  808. case IPSEC_REGISTRY_PROVIDER:
  809. dwError = RegGetISAKMPData(
  810. (pPolicyStore->hRegistryKey),
  811. pPolicyStore->pszIpsecRootContainer,
  812. ISAKMPGUID,
  813. ppIpsecISAKMPData
  814. );
  815. break;
  816. case IPSEC_DIRECTORY_PROVIDER:
  817. dwError = DirGetISAKMPData(
  818. (pPolicyStore->hLdapBindHandle),
  819. pPolicyStore->pszIpsecRootContainer,
  820. ISAKMPGUID,
  821. ppIpsecISAKMPData
  822. );
  823. break;
  824. default:
  825. dwError = ERROR_INVALID_PARAMETER;
  826. break;
  827. }
  828. return(dwError);
  829. }
  830. DWORD
  831. IPSecOpenPolicyStore(
  832. LPWSTR pszMachineName,
  833. DWORD dwTypeOfStore,
  834. LPWSTR pszFileName,
  835. HANDLE * phPolicyStore
  836. )
  837. {
  838. DWORD dwError = 0;
  839. switch (dwTypeOfStore) {
  840. case IPSEC_REGISTRY_PROVIDER:
  841. dwError = RegOpenPolicyStore(
  842. pszMachineName,
  843. phPolicyStore
  844. );
  845. break;
  846. case IPSEC_DIRECTORY_PROVIDER:
  847. dwError = DirOpenPolicyStore(
  848. pszMachineName,
  849. phPolicyStore
  850. );
  851. break;
  852. case IPSEC_FILE_PROVIDER:
  853. dwError = FileOpenPolicyStore(
  854. pszMachineName,
  855. pszFileName,
  856. phPolicyStore
  857. );
  858. break;
  859. default:
  860. dwError = ERROR_INVALID_PARAMETER;
  861. break;
  862. }
  863. return (dwError);
  864. }
  865. DWORD
  866. RegOpenPolicyStore(
  867. LPWSTR pszMachineName,
  868. HANDLE * phPolicyStore
  869. )
  870. {
  871. PIPSEC_POLICY_STORE pPolicyStore = NULL;
  872. DWORD dwError = 0;
  873. HKEY hParentRegistryKey = NULL;
  874. HKEY hRegistryKey = NULL;
  875. WCHAR szName[MAX_PATH];
  876. LPWSTR pszLocationName = NULL;
  877. LPWSTR pszIpsecRootContainer = NULL;
  878. pszIpsecRootContainer = AllocPolStr(gpszIpsecRegRootContainer);
  879. if (!pszIpsecRootContainer) {
  880. dwError = ERROR_OUTOFMEMORY;
  881. BAIL_ON_WIN32_ERROR(dwError);
  882. }
  883. szName[0] = L'\0';
  884. if (!pszMachineName || !*pszMachineName) {
  885. dwError = RegOpenKeyExW(
  886. HKEY_LOCAL_MACHINE,
  887. (LPCWSTR) gpszIpsecRegRootContainer,
  888. 0,
  889. KEY_ALL_ACCESS,
  890. &hRegistryKey
  891. );
  892. BAIL_ON_WIN32_ERROR(dwError);
  893. pszLocationName = NULL;
  894. }
  895. else {
  896. wcscpy(szName, L"\\\\");
  897. wcscat(szName, pszMachineName);
  898. dwError = RegConnectRegistryW(
  899. szName,
  900. HKEY_LOCAL_MACHINE,
  901. &hParentRegistryKey
  902. );
  903. BAIL_ON_WIN32_ERROR(dwError);
  904. dwError = RegOpenKeyExW(
  905. hParentRegistryKey,
  906. (LPCWSTR) gpszIpsecRegRootContainer,
  907. 0,
  908. KEY_ALL_ACCESS,
  909. &hRegistryKey
  910. );
  911. BAIL_ON_WIN32_ERROR(dwError);
  912. pszLocationName = AllocPolStr(szName);
  913. if (!pszLocationName) {
  914. dwError = ERROR_OUTOFMEMORY;
  915. BAIL_ON_WIN32_ERROR(dwError);
  916. }
  917. }
  918. pPolicyStore = (PIPSEC_POLICY_STORE)AllocPolMem(
  919. sizeof(IPSEC_POLICY_STORE)
  920. );
  921. if (!pPolicyStore) {
  922. dwError = ERROR_OUTOFMEMORY;
  923. BAIL_ON_WIN32_ERROR(dwError);
  924. }
  925. pPolicyStore->dwProvider = IPSEC_REGISTRY_PROVIDER;
  926. pPolicyStore->hParentRegistryKey = hParentRegistryKey;
  927. pPolicyStore->hRegistryKey = hRegistryKey;
  928. pPolicyStore->pszLocationName = pszLocationName;
  929. pPolicyStore->hLdapBindHandle = NULL;
  930. pPolicyStore->pszIpsecRootContainer = pszIpsecRootContainer;
  931. pPolicyStore->pszFileName = NULL;
  932. *phPolicyStore = pPolicyStore;
  933. return(dwError);
  934. error:
  935. if (pszIpsecRootContainer) {
  936. FreePolStr(pszIpsecRootContainer);
  937. }
  938. if (hRegistryKey) {
  939. RegCloseKey(hRegistryKey);
  940. }
  941. if (hParentRegistryKey) {
  942. RegCloseKey(hParentRegistryKey);
  943. }
  944. if (pszLocationName) {
  945. FreePolStr(pszLocationName);
  946. }
  947. if (pPolicyStore) {
  948. FreePolMem(pPolicyStore);
  949. }
  950. *phPolicyStore = NULL;
  951. return(dwError);
  952. }
  953. DWORD
  954. DirOpenPolicyStore(
  955. LPWSTR pszMachineName,
  956. HANDLE * phPolicyStore
  957. )
  958. {
  959. PIPSEC_POLICY_STORE pPolicyStore = NULL;
  960. DWORD dwError = 0;
  961. LPWSTR pszIpsecRootContainer = NULL;
  962. HLDAP hLdapBindHandle = NULL;
  963. LPWSTR pszDefaultDirectory = NULL;
  964. if (!pszMachineName || !*pszMachineName) {
  965. dwError = ComputeDefaultDirectory(
  966. &pszDefaultDirectory
  967. );
  968. BAIL_ON_WIN32_ERROR(dwError);
  969. dwError = OpenDirectoryServerHandle(
  970. pszDefaultDirectory,
  971. 389,
  972. &hLdapBindHandle
  973. );
  974. BAIL_ON_WIN32_ERROR(dwError);
  975. dwError = ComputeDirLocationName(
  976. pszDefaultDirectory,
  977. &pszIpsecRootContainer
  978. );
  979. BAIL_ON_WIN32_ERROR(dwError);
  980. }
  981. else {
  982. dwError = OpenDirectoryServerHandle(
  983. pszMachineName,
  984. 389,
  985. &hLdapBindHandle
  986. );
  987. BAIL_ON_WIN32_ERROR(dwError);
  988. dwError = ComputeDirLocationName(
  989. pszMachineName,
  990. &pszIpsecRootContainer
  991. );
  992. BAIL_ON_WIN32_ERROR(dwError);
  993. }
  994. pPolicyStore = (PIPSEC_POLICY_STORE)AllocPolMem(
  995. sizeof(IPSEC_POLICY_STORE)
  996. );
  997. if (!pPolicyStore) {
  998. dwError = ERROR_OUTOFMEMORY;
  999. BAIL_ON_WIN32_ERROR(dwError);
  1000. }
  1001. pPolicyStore->dwProvider = IPSEC_DIRECTORY_PROVIDER;
  1002. pPolicyStore->hParentRegistryKey = NULL;
  1003. pPolicyStore->hRegistryKey = NULL;
  1004. pPolicyStore->pszLocationName = NULL;
  1005. pPolicyStore->hLdapBindHandle = hLdapBindHandle;
  1006. pPolicyStore->pszIpsecRootContainer = pszIpsecRootContainer;
  1007. pPolicyStore->pszFileName = NULL;
  1008. *phPolicyStore = pPolicyStore;
  1009. cleanup:
  1010. if (pszDefaultDirectory) {
  1011. FreePolStr(pszDefaultDirectory);
  1012. }
  1013. return(dwError);
  1014. error:
  1015. if (hLdapBindHandle) {
  1016. CloseDirectoryServerHandle(hLdapBindHandle);
  1017. }
  1018. if (pszIpsecRootContainer) {
  1019. FreePolStr(pszIpsecRootContainer);
  1020. }
  1021. if (pPolicyStore) {
  1022. FreePolMem(pPolicyStore);
  1023. }
  1024. *phPolicyStore = NULL;
  1025. goto cleanup;
  1026. }
  1027. DWORD
  1028. FileOpenPolicyStore(
  1029. LPWSTR pszMachineName,
  1030. LPWSTR pszFileName,
  1031. HANDLE * phPolicyStore
  1032. )
  1033. {
  1034. DWORD dwError = 0;
  1035. LPWSTR pszIpsecRootContainer = NULL;
  1036. HKEY hRegistryKey = NULL;
  1037. LPWSTR pszTempFileName = NULL;
  1038. PIPSEC_POLICY_STORE pPolicyStore = NULL;
  1039. DWORD dwDisposition = 0;
  1040. pszIpsecRootContainer = AllocPolStr(gpszIpsecFileRootContainer);
  1041. if (!pszIpsecRootContainer) {
  1042. dwError = ERROR_OUTOFMEMORY;
  1043. BAIL_ON_WIN32_ERROR(dwError);
  1044. }
  1045. if (!pszMachineName || !*pszMachineName) {
  1046. dwError = RegCreateKeyExW(
  1047. HKEY_LOCAL_MACHINE,
  1048. (LPCWSTR) gpszIpsecFileRootContainer,
  1049. 0,
  1050. NULL,
  1051. 0,
  1052. KEY_ALL_ACCESS,
  1053. NULL,
  1054. &hRegistryKey,
  1055. &dwDisposition
  1056. );
  1057. BAIL_ON_WIN32_ERROR(dwError);
  1058. }
  1059. else {
  1060. dwError = ERROR_INVALID_DATA;
  1061. BAIL_ON_WIN32_ERROR(dwError);
  1062. }
  1063. if (!pszFileName || !*pszFileName) {
  1064. dwError = ERROR_INVALID_DATA;
  1065. BAIL_ON_WIN32_ERROR(dwError);
  1066. }
  1067. pszTempFileName = AllocPolStr(pszFileName);
  1068. if (!pszTempFileName) {
  1069. dwError = ERROR_OUTOFMEMORY;
  1070. BAIL_ON_WIN32_ERROR(dwError);
  1071. }
  1072. pPolicyStore = (PIPSEC_POLICY_STORE)AllocPolMem(
  1073. sizeof(IPSEC_POLICY_STORE)
  1074. );
  1075. if (!pPolicyStore) {
  1076. dwError = ERROR_OUTOFMEMORY;
  1077. BAIL_ON_WIN32_ERROR(dwError);
  1078. }
  1079. pPolicyStore->dwProvider = IPSEC_FILE_PROVIDER;
  1080. pPolicyStore->hParentRegistryKey = NULL;
  1081. pPolicyStore->hRegistryKey = hRegistryKey;
  1082. pPolicyStore->pszLocationName = NULL;
  1083. pPolicyStore->hLdapBindHandle = NULL;
  1084. pPolicyStore->pszIpsecRootContainer = pszIpsecRootContainer;
  1085. pPolicyStore->pszFileName = pszTempFileName;
  1086. *phPolicyStore = pPolicyStore;
  1087. return(dwError);
  1088. error:
  1089. if (pszIpsecRootContainer) {
  1090. FreePolStr(pszIpsecRootContainer);
  1091. }
  1092. if (hRegistryKey) {
  1093. RegCloseKey(hRegistryKey);
  1094. }
  1095. if (pszTempFileName) {
  1096. FreePolStr(pszTempFileName);
  1097. }
  1098. *phPolicyStore = NULL;
  1099. return(dwError);
  1100. }
  1101. DWORD
  1102. IPSecClosePolicyStore(
  1103. HANDLE hPolicyStore
  1104. )
  1105. {
  1106. DWORD dwError = 0;
  1107. PIPSEC_POLICY_STORE pPolicyStore = NULL;
  1108. pPolicyStore = (PIPSEC_POLICY_STORE)hPolicyStore;
  1109. switch (pPolicyStore->dwProvider) {
  1110. case IPSEC_REGISTRY_PROVIDER:
  1111. if (pPolicyStore->hRegistryKey) {
  1112. dwError = RegCloseKey(
  1113. pPolicyStore->hRegistryKey
  1114. );
  1115. BAIL_ON_WIN32_ERROR(dwError);
  1116. }
  1117. if (pPolicyStore->hParentRegistryKey) {
  1118. dwError = RegCloseKey(
  1119. pPolicyStore->hParentRegistryKey
  1120. );
  1121. BAIL_ON_WIN32_ERROR(dwError);
  1122. }
  1123. if (pPolicyStore->pszLocationName) {
  1124. FreePolStr(pPolicyStore->pszLocationName);
  1125. }
  1126. if (pPolicyStore->pszIpsecRootContainer) {
  1127. FreePolStr(pPolicyStore->pszIpsecRootContainer);
  1128. }
  1129. break;
  1130. case IPSEC_DIRECTORY_PROVIDER:
  1131. if (pPolicyStore->hLdapBindHandle) {
  1132. CloseDirectoryServerHandle(
  1133. pPolicyStore->hLdapBindHandle
  1134. );
  1135. }
  1136. if (pPolicyStore->pszIpsecRootContainer) {
  1137. FreePolStr(pPolicyStore->pszIpsecRootContainer);
  1138. }
  1139. break;
  1140. case IPSEC_FILE_PROVIDER:
  1141. if (pPolicyStore->hRegistryKey) {
  1142. dwError = RegCloseKey(
  1143. pPolicyStore->hRegistryKey
  1144. );
  1145. BAIL_ON_WIN32_ERROR(dwError);
  1146. }
  1147. if (pPolicyStore->pszIpsecRootContainer) {
  1148. FreePolStr(pPolicyStore->pszIpsecRootContainer);
  1149. }
  1150. if (pPolicyStore->pszFileName) {
  1151. FreePolStr(pPolicyStore->pszFileName);
  1152. }
  1153. break;
  1154. default:
  1155. dwError = ERROR_INVALID_PARAMETER;
  1156. BAIL_ON_WIN32_ERROR(dwError);
  1157. break;
  1158. }
  1159. if (pPolicyStore) {
  1160. FreePolMem(pPolicyStore);
  1161. }
  1162. error:
  1163. return(dwError);
  1164. }
  1165. DWORD
  1166. IPSecAssignPolicy(
  1167. HANDLE hPolicyStore,
  1168. GUID PolicyGUID
  1169. )
  1170. {
  1171. DWORD dwError = 0;
  1172. DWORD dwProvider = 0;
  1173. PIPSEC_POLICY_STORE pPolicyStore = NULL;
  1174. pPolicyStore = (PIPSEC_POLICY_STORE)hPolicyStore;
  1175. switch (pPolicyStore->dwProvider) {
  1176. case IPSEC_REGISTRY_PROVIDER:
  1177. dwError = RegAssignPolicy(
  1178. (pPolicyStore->hRegistryKey),
  1179. pPolicyStore->pszIpsecRootContainer,
  1180. PolicyGUID,
  1181. pPolicyStore->pszLocationName
  1182. );
  1183. break;
  1184. default:
  1185. dwError = ERROR_INVALID_PARAMETER;
  1186. break;
  1187. }
  1188. return(dwError);
  1189. }
  1190. DWORD
  1191. IPSecUnassignPolicy(
  1192. HANDLE hPolicyStore,
  1193. GUID PolicyGUID
  1194. )
  1195. {
  1196. DWORD dwError = 0;
  1197. DWORD dwProvider = 0;
  1198. PIPSEC_POLICY_STORE pPolicyStore = NULL;
  1199. pPolicyStore = (PIPSEC_POLICY_STORE)hPolicyStore;
  1200. switch (pPolicyStore->dwProvider) {
  1201. case IPSEC_REGISTRY_PROVIDER:
  1202. dwError = RegUnassignPolicy(
  1203. (pPolicyStore->hRegistryKey),
  1204. pPolicyStore->pszIpsecRootContainer,
  1205. PolicyGUID,
  1206. pPolicyStore->pszLocationName
  1207. );
  1208. break;
  1209. default:
  1210. dwError = ERROR_INVALID_PARAMETER;
  1211. break;
  1212. }
  1213. return(dwError);
  1214. }
  1215. DWORD
  1216. ComputeDirLocationName(
  1217. LPWSTR pszDirDomainName,
  1218. LPWSTR * ppszDirFQPathName
  1219. )
  1220. {
  1221. DWORD dwError = 0;
  1222. WCHAR szName[MAX_PATH];
  1223. LPWSTR pszDotBegin = NULL;
  1224. LPWSTR pszDotEnd = NULL;
  1225. LPWSTR pszDirFQPathName = NULL;
  1226. LPWSTR pszDirName = NULL;
  1227. szName[0] = L'\0';
  1228. wcscpy(szName, L"CN=IP Security,CN=System");
  1229. pszDirName = AllocPolStr(pszDirDomainName);
  1230. if (!pszDirName) {
  1231. dwError = ERROR_OUTOFMEMORY;
  1232. BAIL_ON_WIN32_ERROR(dwError);
  1233. }
  1234. pszDotBegin = pszDirName;
  1235. pszDotEnd = wcschr(pszDirName, L'.');
  1236. if (!pszDotEnd) {
  1237. dwError = ERROR_INVALID_PARAMETER;
  1238. BAIL_ON_WIN32_ERROR(dwError);
  1239. }
  1240. while (pszDotEnd) {
  1241. *pszDotEnd = L'\0';
  1242. wcscat(szName, L",DC=");
  1243. wcscat(szName, pszDotBegin);
  1244. *pszDotEnd = L'.';
  1245. pszDotEnd += 1;
  1246. pszDotBegin = pszDotEnd;
  1247. pszDotEnd = wcschr(pszDotEnd, L'.');
  1248. }
  1249. wcscat(szName, L",DC=");
  1250. wcscat(szName, pszDotBegin);
  1251. pszDirFQPathName = AllocPolStr(szName);
  1252. if (!pszDirFQPathName) {
  1253. dwError = ERROR_OUTOFMEMORY;
  1254. BAIL_ON_WIN32_ERROR(dwError);
  1255. }
  1256. *ppszDirFQPathName = pszDirFQPathName;
  1257. cleanup:
  1258. if (pszDirName) {
  1259. FreePolStr(pszDirName);
  1260. }
  1261. return (dwError);
  1262. error:
  1263. *ppszDirFQPathName = NULL;
  1264. goto cleanup;
  1265. }
  1266. DWORD
  1267. IPSecGetAssignedPolicyData(
  1268. HANDLE hPolicyStore,
  1269. PIPSEC_POLICY_DATA * ppIpsecPolicyData
  1270. )
  1271. {
  1272. DWORD dwError = 0;
  1273. PIPSEC_POLICY_STORE pPolicyStore = NULL;
  1274. pPolicyStore = (PIPSEC_POLICY_STORE)hPolicyStore;
  1275. switch (pPolicyStore->dwProvider) {
  1276. case IPSEC_REGISTRY_PROVIDER:
  1277. dwError = RegGetAssignedPolicyData(
  1278. (pPolicyStore->hRegistryKey),
  1279. pPolicyStore->pszIpsecRootContainer,
  1280. ppIpsecPolicyData
  1281. );
  1282. break;
  1283. default:
  1284. dwError = ERROR_INVALID_PARAMETER;
  1285. break;
  1286. }
  1287. return(dwError);
  1288. }
  1289. DWORD
  1290. IPSecExportPolicies(
  1291. HANDLE hSrcPolicyStore,
  1292. HANDLE hDesPolicyStore
  1293. )
  1294. {
  1295. DWORD dwError = 0;
  1296. PIPSEC_POLICY_STORE pSrcPolicyStore = NULL;
  1297. PIPSEC_POLICY_STORE pDesPolicyStore = NULL;
  1298. pSrcPolicyStore = (PIPSEC_POLICY_STORE) hSrcPolicyStore;
  1299. switch (pSrcPolicyStore->dwProvider) {
  1300. case IPSEC_REGISTRY_PROVIDER:
  1301. case IPSEC_DIRECTORY_PROVIDER:
  1302. break;
  1303. default:
  1304. dwError = ERROR_INVALID_PARAMETER;
  1305. BAIL_ON_WIN32_ERROR(dwError);
  1306. break;
  1307. }
  1308. pDesPolicyStore = (PIPSEC_POLICY_STORE) hDesPolicyStore;
  1309. switch (pDesPolicyStore->dwProvider) {
  1310. case IPSEC_FILE_PROVIDER:
  1311. dwError = ExportPoliciesToFile(
  1312. hSrcPolicyStore,
  1313. hDesPolicyStore
  1314. );
  1315. BAIL_ON_WIN32_ERROR(dwError);
  1316. break;
  1317. default:
  1318. dwError = ERROR_INVALID_PARAMETER;
  1319. BAIL_ON_WIN32_ERROR(dwError);
  1320. break;
  1321. }
  1322. error:
  1323. return(dwError);
  1324. }
  1325. DWORD
  1326. IPSecImportPolicies(
  1327. HANDLE hSrcPolicyStore,
  1328. HANDLE hDesPolicyStore
  1329. )
  1330. {
  1331. DWORD dwError = 0;
  1332. PIPSEC_POLICY_STORE pSrcPolicyStore = NULL;
  1333. PIPSEC_POLICY_STORE pDesPolicyStore = NULL;
  1334. pSrcPolicyStore = (PIPSEC_POLICY_STORE) hSrcPolicyStore;
  1335. switch (pSrcPolicyStore->dwProvider) {
  1336. case IPSEC_FILE_PROVIDER:
  1337. break;
  1338. default:
  1339. dwError = ERROR_INVALID_PARAMETER;
  1340. BAIL_ON_WIN32_ERROR(dwError);
  1341. break;
  1342. }
  1343. pDesPolicyStore = (PIPSEC_POLICY_STORE) hDesPolicyStore;
  1344. switch (pDesPolicyStore->dwProvider) {
  1345. case IPSEC_REGISTRY_PROVIDER:
  1346. case IPSEC_DIRECTORY_PROVIDER:
  1347. dwError = ImportPoliciesFromFile(
  1348. hSrcPolicyStore,
  1349. hDesPolicyStore
  1350. );
  1351. BAIL_ON_WIN32_ERROR(dwError);
  1352. break;
  1353. default:
  1354. dwError = ERROR_INVALID_PARAMETER;
  1355. BAIL_ON_WIN32_ERROR(dwError);
  1356. break;
  1357. }
  1358. error:
  1359. return(dwError);
  1360. }
  1361. DWORD
  1362. IPSecRestoreDefaultPolicies(
  1363. HANDLE hPolicyStore
  1364. )
  1365. {
  1366. DWORD dwError = 0;
  1367. PIPSEC_POLICY_STORE pPolicyStore = NULL;
  1368. pPolicyStore = (PIPSEC_POLICY_STORE) hPolicyStore;
  1369. switch (pPolicyStore->dwProvider) {
  1370. case IPSEC_REGISTRY_PROVIDER:
  1371. dwError = RegRestoreDefaults(
  1372. hPolicyStore,
  1373. pPolicyStore->hRegistryKey,
  1374. pPolicyStore->pszIpsecRootContainer,
  1375. pPolicyStore->pszLocationName
  1376. );
  1377. BAIL_ON_WIN32_ERROR(dwError);
  1378. break;
  1379. case IPSEC_DIRECTORY_PROVIDER:
  1380. dwError = ERROR_INVALID_PARAMETER;
  1381. break;
  1382. default:
  1383. dwError = ERROR_INVALID_PARAMETER;
  1384. break;
  1385. }
  1386. error:
  1387. return(dwError);
  1388. }