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.

2591 lines
68 KiB

  1. #include "precomp.h"
  2. LPWSTR gpszIpsecCacheKey = L"SOFTWARE\\Policies\\Microsoft\\Windows\\IPSec\\Policy\\Cache";
  3. DWORD
  4. CacheDirectorytoRegistry(
  5. PIPSEC_POLICY_OBJECT pIpsecPolicyObject
  6. )
  7. {
  8. DWORD dwError = 0;
  9. PIPSEC_POLICY_OBJECT pIpsecRegPolicyObject = NULL;
  10. //
  11. // Delete the existing cache.
  12. //
  13. DeleteRegistryCache();
  14. //
  15. // Create a copy of the directory policy in registry terms
  16. //
  17. dwError = CloneDirectoryPolicyObject(
  18. pIpsecPolicyObject,
  19. &pIpsecRegPolicyObject
  20. );
  21. BAIL_ON_WIN32_ERROR(dwError);
  22. //
  23. // Write the registry policy
  24. //
  25. dwError = PersistRegistryObject(
  26. pIpsecRegPolicyObject
  27. );
  28. BAIL_ON_WIN32_ERROR(dwError);
  29. cleanup:
  30. if (pIpsecRegPolicyObject) {
  31. FreeIpsecPolicyObject(
  32. pIpsecRegPolicyObject
  33. );
  34. }
  35. return(dwError);
  36. error:
  37. DeleteRegistryCache();
  38. goto cleanup;
  39. }
  40. DWORD
  41. PersistRegistryObject(
  42. PIPSEC_POLICY_OBJECT pIpsecRegPolicyObject
  43. )
  44. {
  45. DWORD dwError = 0;
  46. HKEY hRegistryKey = NULL;
  47. DWORD dwDisposition = 0;
  48. dwError = RegCreateKeyExW(
  49. HKEY_LOCAL_MACHINE,
  50. gpszIpsecCacheKey,
  51. 0,
  52. NULL,
  53. 0,
  54. KEY_ALL_ACCESS,
  55. NULL,
  56. &hRegistryKey,
  57. &dwDisposition
  58. );
  59. BAIL_ON_WIN32_ERROR(dwError);
  60. if (pIpsecRegPolicyObject->ppIpsecFilterObjects) {
  61. dwError = PersistFilterObjects(
  62. hRegistryKey,
  63. pIpsecRegPolicyObject->ppIpsecFilterObjects,
  64. pIpsecRegPolicyObject->NumberofFilters
  65. );
  66. BAIL_ON_WIN32_ERROR(dwError);
  67. }
  68. if (pIpsecRegPolicyObject->ppIpsecNegPolObjects) {
  69. dwError = PersistNegPolObjects(
  70. hRegistryKey,
  71. pIpsecRegPolicyObject->ppIpsecNegPolObjects,
  72. pIpsecRegPolicyObject->NumberofNegPols
  73. );
  74. BAIL_ON_WIN32_ERROR(dwError);
  75. }
  76. if (pIpsecRegPolicyObject->ppIpsecNFAObjects) {
  77. dwError = PersistNFAObjects(
  78. hRegistryKey,
  79. pIpsecRegPolicyObject->ppIpsecNFAObjects,
  80. pIpsecRegPolicyObject->NumberofRulesReturned
  81. );
  82. BAIL_ON_WIN32_ERROR(dwError);
  83. }
  84. if (pIpsecRegPolicyObject->ppIpsecISAKMPObjects) {
  85. dwError = PersistISAKMPObjects(
  86. hRegistryKey,
  87. pIpsecRegPolicyObject->ppIpsecISAKMPObjects,
  88. pIpsecRegPolicyObject->NumberofISAKMPs
  89. );
  90. BAIL_ON_WIN32_ERROR(dwError);
  91. }
  92. dwError = PersistPolicyObject(
  93. hRegistryKey,
  94. pIpsecRegPolicyObject
  95. );
  96. error:
  97. if (hRegistryKey) {
  98. RegCloseKey(hRegistryKey);
  99. }
  100. return(dwError);
  101. }
  102. DWORD
  103. PersistNegPolObjects(
  104. HKEY hRegistryKey,
  105. PIPSEC_NEGPOL_OBJECT *ppIpsecNegPolObjects,
  106. DWORD dwNumNegPolObjects
  107. )
  108. {
  109. DWORD i = 0;
  110. DWORD dwError = 0;
  111. for (i = 0; i < dwNumNegPolObjects; i++) {
  112. dwError = PersistNegPolObject(
  113. hRegistryKey,
  114. *(ppIpsecNegPolObjects + i)
  115. );
  116. BAIL_ON_WIN32_ERROR(dwError);
  117. }
  118. error:
  119. return(dwError);
  120. }
  121. DWORD
  122. PersistFilterObjects(
  123. HKEY hRegistryKey,
  124. PIPSEC_FILTER_OBJECT * ppIpsecFilterObjects,
  125. DWORD dwNumFilterObjects
  126. )
  127. {
  128. DWORD i = 0;
  129. DWORD dwError = 0;
  130. for (i = 0; i < dwNumFilterObjects; i++) {
  131. dwError = PersistFilterObject(
  132. hRegistryKey,
  133. *(ppIpsecFilterObjects + i)
  134. );
  135. BAIL_ON_WIN32_ERROR(dwError);
  136. }
  137. error:
  138. return(dwError);
  139. }
  140. DWORD
  141. PersistNFAObjects(
  142. HKEY hRegistryKey,
  143. PIPSEC_NFA_OBJECT * ppIpsecNFAObjects,
  144. DWORD dwNumNFAObjects
  145. )
  146. {
  147. DWORD i = 0;
  148. DWORD dwError = 0;
  149. for (i = 0; i < dwNumNFAObjects; i++) {
  150. dwError = PersistNFAObject(
  151. hRegistryKey,
  152. *(ppIpsecNFAObjects + i)
  153. );
  154. BAIL_ON_WIN32_ERROR(dwError);
  155. }
  156. error:
  157. return(dwError);
  158. }
  159. DWORD
  160. PersistISAKMPObjects(
  161. HKEY hRegistryKey,
  162. PIPSEC_ISAKMP_OBJECT * ppIpsecISAKMPObjects,
  163. DWORD dwNumISAKMPObjects
  164. )
  165. {
  166. DWORD i = 0;
  167. DWORD dwError = 0;
  168. for (i = 0; i < dwNumISAKMPObjects; i++) {
  169. dwError = PersistISAKMPObject(
  170. hRegistryKey,
  171. *(ppIpsecISAKMPObjects + i)
  172. );
  173. BAIL_ON_WIN32_ERROR(dwError);
  174. }
  175. error:
  176. return(dwError);
  177. }
  178. DWORD
  179. PersistPolicyObject(
  180. HKEY hRegistryKey,
  181. PIPSEC_POLICY_OBJECT pIpsecPolicyObject
  182. )
  183. {
  184. DWORD dwError = 0;
  185. HKEY hRegKey = NULL;
  186. DWORD dwDisposition = 0;
  187. dwError = RegCreateKeyExW(
  188. hRegistryKey,
  189. pIpsecPolicyObject->pszIpsecOwnersReference,
  190. 0,
  191. NULL,
  192. 0,
  193. KEY_ALL_ACCESS,
  194. NULL,
  195. &hRegKey,
  196. &dwDisposition
  197. );
  198. BAIL_ON_WIN32_ERROR(dwError);
  199. dwError = RegSetValueExW(
  200. hRegKey,
  201. L"ClassName",
  202. 0,
  203. REG_SZ,
  204. (LPBYTE) L"ipsecPolicy",
  205. (wcslen(L"ipsecPolicy") + 1)*sizeof(WCHAR)
  206. );
  207. BAIL_ON_WIN32_ERROR(dwError);
  208. if (pIpsecPolicyObject->pszDescription) {
  209. dwError = RegSetValueExW(
  210. hRegKey,
  211. L"description",
  212. 0,
  213. REG_SZ,
  214. (LPBYTE)pIpsecPolicyObject->pszDescription,
  215. (wcslen(pIpsecPolicyObject->pszDescription) + 1)*sizeof(WCHAR)
  216. );
  217. BAIL_ON_WIN32_ERROR(dwError);
  218. }
  219. else {
  220. (VOID) RegDeleteValueW(
  221. hRegKey,
  222. L"description"
  223. );
  224. }
  225. if (pIpsecPolicyObject->pszIpsecOwnersReference) {
  226. dwError = RegSetValueExW(
  227. hRegKey,
  228. L"name",
  229. 0,
  230. REG_SZ,
  231. (LPBYTE)pIpsecPolicyObject->pszIpsecOwnersReference,
  232. (wcslen(pIpsecPolicyObject->pszIpsecOwnersReference) + 1)*sizeof(WCHAR)
  233. );
  234. BAIL_ON_WIN32_ERROR(dwError);
  235. }
  236. if (pIpsecPolicyObject->pszIpsecName) {
  237. dwError = RegSetValueExW(
  238. hRegKey,
  239. L"ipsecName",
  240. 0,
  241. REG_SZ,
  242. (LPBYTE)pIpsecPolicyObject->pszIpsecName,
  243. (wcslen(pIpsecPolicyObject->pszIpsecName) + 1)*sizeof(WCHAR)
  244. );
  245. BAIL_ON_WIN32_ERROR(dwError);
  246. }
  247. if (pIpsecPolicyObject->pszIpsecID) {
  248. dwError = RegSetValueExW(
  249. hRegKey,
  250. L"ipsecID",
  251. 0,
  252. REG_SZ,
  253. (LPBYTE)pIpsecPolicyObject->pszIpsecID,
  254. (wcslen(pIpsecPolicyObject->pszIpsecID) + 1)*sizeof(WCHAR)
  255. );
  256. BAIL_ON_WIN32_ERROR(dwError);
  257. }
  258. dwError = RegSetValueExW(
  259. hRegKey,
  260. L"ipsecDataType",
  261. 0,
  262. REG_DWORD,
  263. (LPBYTE)&pIpsecPolicyObject->dwIpsecDataType,
  264. sizeof(DWORD)
  265. );
  266. BAIL_ON_WIN32_ERROR(dwError);
  267. if (pIpsecPolicyObject->pIpsecData) {
  268. dwError = RegSetValueExW(
  269. hRegKey,
  270. L"ipsecData",
  271. 0,
  272. REG_BINARY,
  273. pIpsecPolicyObject->pIpsecData,
  274. pIpsecPolicyObject->dwIpsecDataLen
  275. );
  276. BAIL_ON_WIN32_ERROR(dwError);
  277. }
  278. if (pIpsecPolicyObject->pszIpsecISAKMPReference) {
  279. dwError = RegSetValueExW(
  280. hRegKey,
  281. L"ipsecISAKMPReference",
  282. 0,
  283. REG_SZ,
  284. (LPBYTE)pIpsecPolicyObject->pszIpsecISAKMPReference,
  285. (wcslen(pIpsecPolicyObject->pszIpsecISAKMPReference) + 1)*sizeof(WCHAR)
  286. );
  287. BAIL_ON_WIN32_ERROR(dwError);
  288. }
  289. if (pIpsecPolicyObject->ppszIpsecNFAReferences) {
  290. dwError = RegWriteMultiValuedString(
  291. hRegKey,
  292. L"ipsecNFAReference",
  293. pIpsecPolicyObject->ppszIpsecNFAReferences,
  294. pIpsecPolicyObject->NumberofRules
  295. );
  296. BAIL_ON_WIN32_ERROR(dwError);
  297. }
  298. dwError = RegSetValueExW(
  299. hRegKey,
  300. L"whenChanged",
  301. 0,
  302. REG_DWORD,
  303. (LPBYTE)&pIpsecPolicyObject->dwWhenChanged,
  304. sizeof(DWORD)
  305. );
  306. BAIL_ON_WIN32_ERROR(dwError);
  307. error:
  308. if (hRegKey) {
  309. RegCloseKey(hRegKey);
  310. }
  311. return(dwError);
  312. }
  313. DWORD
  314. PersistNFAObject(
  315. HKEY hRegistryKey,
  316. PIPSEC_NFA_OBJECT pIpsecNFAObject
  317. )
  318. {
  319. HKEY hRegKey = NULL;
  320. DWORD dwError = 0;
  321. DWORD dwDisposition = 0;
  322. LPBYTE pMem = NULL;
  323. dwError = RegCreateKeyExW(
  324. hRegistryKey,
  325. pIpsecNFAObject->pszDistinguishedName,
  326. 0,
  327. NULL,
  328. 0,
  329. KEY_ALL_ACCESS,
  330. NULL,
  331. &hRegKey,
  332. &dwDisposition
  333. );
  334. BAIL_ON_WIN32_ERROR(dwError);
  335. dwError = RegSetValueExW(
  336. hRegKey,
  337. L"ClassName",
  338. 0,
  339. REG_SZ,
  340. (LPBYTE) L"ipsecNFA",
  341. (wcslen(L"ipsecNFA") + 1)*sizeof(WCHAR)
  342. );
  343. BAIL_ON_WIN32_ERROR(dwError);
  344. if (pIpsecNFAObject->pszDistinguishedName) {
  345. dwError = RegSetValueExW(
  346. hRegKey,
  347. L"name",
  348. 0,
  349. REG_SZ,
  350. (LPBYTE)pIpsecNFAObject->pszDistinguishedName,
  351. (wcslen(pIpsecNFAObject->pszDistinguishedName) + 1)*sizeof(WCHAR)
  352. );
  353. BAIL_ON_WIN32_ERROR(dwError);
  354. }
  355. if (pIpsecNFAObject->pszIpsecName) {
  356. dwError = RegSetValueExW(
  357. hRegKey,
  358. L"ipsecName",
  359. 0,
  360. REG_SZ,
  361. (LPBYTE)pIpsecNFAObject->pszIpsecName,
  362. (wcslen(pIpsecNFAObject->pszIpsecName) + 1)*sizeof(WCHAR)
  363. );
  364. BAIL_ON_WIN32_ERROR(dwError);
  365. }
  366. if (pIpsecNFAObject->pszDescription) {
  367. dwError = RegSetValueExW(
  368. hRegKey,
  369. L"description",
  370. 0,
  371. REG_SZ,
  372. (LPBYTE)pIpsecNFAObject->pszDescription,
  373. (wcslen(pIpsecNFAObject->pszDescription) + 1)*sizeof(WCHAR)
  374. );
  375. BAIL_ON_WIN32_ERROR(dwError);
  376. }
  377. else {
  378. (VOID) RegDeleteValueW(
  379. hRegKey,
  380. L"description"
  381. );
  382. }
  383. if (pIpsecNFAObject->pszIpsecID) {
  384. dwError = RegSetValueExW(
  385. hRegKey,
  386. L"ipsecID",
  387. 0,
  388. REG_SZ,
  389. (LPBYTE)pIpsecNFAObject->pszIpsecID,
  390. (wcslen(pIpsecNFAObject->pszIpsecID) + 1)*sizeof(WCHAR)
  391. );
  392. BAIL_ON_WIN32_ERROR(dwError);
  393. }
  394. dwError = RegSetValueExW(
  395. hRegKey,
  396. L"ipsecDataType",
  397. 0,
  398. REG_DWORD,
  399. (LPBYTE)&pIpsecNFAObject->dwIpsecDataType,
  400. sizeof(DWORD)
  401. );
  402. BAIL_ON_WIN32_ERROR(dwError);
  403. if (pIpsecNFAObject->pIpsecData) {
  404. dwError = RegSetValueExW(
  405. hRegKey,
  406. L"ipsecData",
  407. 0,
  408. REG_BINARY,
  409. pIpsecNFAObject->pIpsecData,
  410. pIpsecNFAObject->dwIpsecDataLen
  411. );
  412. BAIL_ON_WIN32_ERROR(dwError);
  413. }
  414. if (pIpsecNFAObject->pszIpsecOwnersReference) {
  415. dwError = RegSetValueExW(
  416. hRegKey,
  417. L"ipsecOwnersReference",
  418. 0,
  419. REG_SZ,
  420. (LPBYTE)pIpsecNFAObject->pszIpsecOwnersReference,
  421. (wcslen(pIpsecNFAObject->pszIpsecOwnersReference) + 1)*sizeof(WCHAR)
  422. );
  423. BAIL_ON_WIN32_ERROR(dwError);
  424. }
  425. if (pIpsecNFAObject->pszIpsecNegPolReference) {
  426. dwError = RegSetValueExW(
  427. hRegKey,
  428. L"ipsecNegotiationPolicyReference",
  429. 0,
  430. REG_SZ,
  431. (LPBYTE)pIpsecNFAObject->pszIpsecNegPolReference,
  432. (wcslen(pIpsecNFAObject->pszIpsecNegPolReference) + 1)*sizeof(WCHAR)
  433. );
  434. BAIL_ON_WIN32_ERROR(dwError);
  435. }
  436. if (pIpsecNFAObject->pszIpsecFilterReference) {
  437. pMem = AllocPolMem(
  438. (wcslen(pIpsecNFAObject->pszIpsecFilterReference) + 1 + 1)*sizeof(WCHAR)
  439. );
  440. if (!pMem) {
  441. dwError = ERROR_OUTOFMEMORY;
  442. BAIL_ON_WIN32_ERROR(dwError);
  443. }
  444. memcpy(
  445. pMem,
  446. (LPBYTE) pIpsecNFAObject->pszIpsecFilterReference,
  447. (wcslen(pIpsecNFAObject->pszIpsecFilterReference) + 1)*sizeof(WCHAR)
  448. );
  449. dwError = RegSetValueExW(
  450. hRegKey,
  451. L"ipsecFilterReference",
  452. 0,
  453. REG_MULTI_SZ,
  454. pMem,
  455. (wcslen(pIpsecNFAObject->pszIpsecFilterReference) + 1 + 1)*sizeof(WCHAR)
  456. );
  457. BAIL_ON_WIN32_ERROR(dwError);
  458. if (pMem) {
  459. FreePolMem(pMem);
  460. }
  461. }
  462. dwError = RegSetValueExW(
  463. hRegKey,
  464. L"whenChanged",
  465. 0,
  466. REG_DWORD,
  467. (LPBYTE)&pIpsecNFAObject->dwWhenChanged,
  468. sizeof(DWORD)
  469. );
  470. BAIL_ON_WIN32_ERROR(dwError);
  471. error:
  472. if (hRegKey) {
  473. RegCloseKey(hRegKey);
  474. }
  475. return(dwError);
  476. }
  477. DWORD
  478. PersistFilterObject(
  479. HKEY hRegistryKey,
  480. PIPSEC_FILTER_OBJECT pIpsecFilterObject
  481. )
  482. {
  483. HKEY hRegKey = NULL;
  484. DWORD dwError = 0;
  485. DWORD dwDisposition = 0;
  486. dwError = RegCreateKeyExW(
  487. hRegistryKey,
  488. pIpsecFilterObject->pszDistinguishedName,
  489. 0,
  490. NULL,
  491. 0,
  492. KEY_ALL_ACCESS,
  493. NULL,
  494. &hRegKey,
  495. &dwDisposition
  496. );
  497. BAIL_ON_WIN32_ERROR(dwError);
  498. dwError = RegSetValueExW(
  499. hRegKey,
  500. L"ClassName",
  501. 0,
  502. REG_SZ,
  503. (LPBYTE) L"ipsecFilter",
  504. (wcslen(L"ipsecFilter") + 1)*sizeof(WCHAR)
  505. );
  506. BAIL_ON_WIN32_ERROR(dwError);
  507. if (pIpsecFilterObject->pszDescription) {
  508. dwError = RegSetValueExW(
  509. hRegKey,
  510. L"description",
  511. 0,
  512. REG_SZ,
  513. (LPBYTE)pIpsecFilterObject->pszDescription,
  514. (wcslen(pIpsecFilterObject->pszDescription) + 1)*sizeof(WCHAR)
  515. );
  516. BAIL_ON_WIN32_ERROR(dwError);
  517. }
  518. else {
  519. (VOID) RegDeleteValueW(
  520. hRegKey,
  521. L"description"
  522. );
  523. }
  524. if (pIpsecFilterObject->pszDistinguishedName) {
  525. dwError = RegSetValueExW(
  526. hRegKey,
  527. L"name",
  528. 0,
  529. REG_SZ,
  530. (LPBYTE)pIpsecFilterObject->pszDistinguishedName,
  531. (wcslen(pIpsecFilterObject->pszDistinguishedName) + 1)*sizeof(WCHAR)
  532. );
  533. BAIL_ON_WIN32_ERROR(dwError);
  534. }
  535. if (pIpsecFilterObject->pszIpsecName) {
  536. dwError = RegSetValueExW(
  537. hRegKey,
  538. L"ipsecName",
  539. 0,
  540. REG_SZ,
  541. (LPBYTE)pIpsecFilterObject->pszIpsecName,
  542. (wcslen(pIpsecFilterObject->pszIpsecName) + 1)* sizeof(WCHAR)
  543. );
  544. BAIL_ON_WIN32_ERROR(dwError);
  545. }
  546. if (pIpsecFilterObject->pszIpsecID) {
  547. dwError = RegSetValueExW(
  548. hRegKey,
  549. L"ipsecID",
  550. 0,
  551. REG_SZ,
  552. (LPBYTE)pIpsecFilterObject->pszIpsecID,
  553. (wcslen(pIpsecFilterObject->pszIpsecID) + 1)* sizeof(WCHAR)
  554. );
  555. BAIL_ON_WIN32_ERROR(dwError);
  556. }
  557. dwError = RegSetValueExW(
  558. hRegKey,
  559. L"ipsecDataType",
  560. 0,
  561. REG_DWORD,
  562. (LPBYTE)&pIpsecFilterObject->dwIpsecDataType,
  563. sizeof(DWORD)
  564. );
  565. BAIL_ON_WIN32_ERROR(dwError);
  566. if (pIpsecFilterObject->pIpsecData) {
  567. dwError = RegSetValueExW(
  568. hRegKey,
  569. L"ipsecData",
  570. 0,
  571. REG_BINARY,
  572. pIpsecFilterObject->pIpsecData,
  573. pIpsecFilterObject->dwIpsecDataLen
  574. );
  575. BAIL_ON_WIN32_ERROR(dwError);
  576. }
  577. dwError = RegSetValueExW(
  578. hRegKey,
  579. L"whenChanged",
  580. 0,
  581. REG_DWORD,
  582. (LPBYTE)&pIpsecFilterObject->dwWhenChanged,
  583. sizeof(DWORD)
  584. );
  585. BAIL_ON_WIN32_ERROR(dwError);
  586. if (pIpsecFilterObject->ppszIpsecNFAReferences) {
  587. dwError = RegWriteMultiValuedString(
  588. hRegKey,
  589. L"ipsecOwnersReference",
  590. pIpsecFilterObject->ppszIpsecNFAReferences,
  591. pIpsecFilterObject->dwNFACount
  592. );
  593. BAIL_ON_WIN32_ERROR(dwError);
  594. }
  595. error:
  596. if (hRegKey) {
  597. RegCloseKey(hRegKey);
  598. }
  599. return(dwError);
  600. }
  601. DWORD
  602. PersistNegPolObject(
  603. HKEY hRegistryKey,
  604. PIPSEC_NEGPOL_OBJECT pIpsecNegPolObject
  605. )
  606. {
  607. DWORD dwError = 0;
  608. DWORD dwDisposition = 0;
  609. HKEY hRegKey = NULL;
  610. dwError = RegCreateKeyExW(
  611. hRegistryKey,
  612. pIpsecNegPolObject->pszDistinguishedName,
  613. 0,
  614. NULL,
  615. 0,
  616. KEY_ALL_ACCESS,
  617. NULL,
  618. &hRegKey,
  619. &dwDisposition
  620. );
  621. BAIL_ON_WIN32_ERROR(dwError);
  622. dwError = RegSetValueExW(
  623. hRegKey,
  624. L"ClassName",
  625. 0,
  626. REG_SZ,
  627. (LPBYTE) L"ipsecNegotiationPolicy",
  628. (wcslen(L"ipsecNegotiationPolicy") + 1)*sizeof(WCHAR)
  629. );
  630. BAIL_ON_WIN32_ERROR(dwError);
  631. if (pIpsecNegPolObject->pszDescription) {
  632. dwError = RegSetValueExW(
  633. hRegKey,
  634. L"description",
  635. 0,
  636. REG_SZ,
  637. (LPBYTE)pIpsecNegPolObject->pszDescription,
  638. (wcslen(pIpsecNegPolObject->pszDescription) + 1)*sizeof(WCHAR)
  639. );
  640. BAIL_ON_WIN32_ERROR(dwError);
  641. }
  642. else {
  643. (VOID) RegDeleteValueW(
  644. hRegKey,
  645. L"description"
  646. );
  647. }
  648. if (pIpsecNegPolObject->pszDistinguishedName) {
  649. dwError = RegSetValueExW(
  650. hRegKey,
  651. L"name",
  652. 0,
  653. REG_SZ,
  654. (LPBYTE)pIpsecNegPolObject->pszDistinguishedName,
  655. (wcslen(pIpsecNegPolObject->pszDistinguishedName) + 1)*sizeof(WCHAR)
  656. );
  657. BAIL_ON_WIN32_ERROR(dwError);
  658. }
  659. if (pIpsecNegPolObject->pszIpsecName) {
  660. dwError = RegSetValueExW(
  661. hRegKey,
  662. L"ipsecName",
  663. 0,
  664. REG_SZ,
  665. (LPBYTE)pIpsecNegPolObject->pszIpsecName,
  666. (wcslen(pIpsecNegPolObject->pszIpsecName) + 1)*sizeof(WCHAR)
  667. );
  668. BAIL_ON_WIN32_ERROR(dwError);
  669. }
  670. if (pIpsecNegPolObject->pszIpsecID) {
  671. dwError = RegSetValueExW(
  672. hRegKey,
  673. L"ipsecID",
  674. 0,
  675. REG_SZ,
  676. (LPBYTE)pIpsecNegPolObject->pszIpsecID,
  677. (wcslen(pIpsecNegPolObject->pszIpsecID) + 1)*sizeof(WCHAR)
  678. );
  679. BAIL_ON_WIN32_ERROR(dwError);
  680. }
  681. if (pIpsecNegPolObject->pszIpsecNegPolAction) {
  682. dwError = RegSetValueExW(
  683. hRegKey,
  684. L"ipsecNegotiationPolicyAction",
  685. 0,
  686. REG_SZ,
  687. (LPBYTE)pIpsecNegPolObject->pszIpsecNegPolAction,
  688. (wcslen(pIpsecNegPolObject->pszIpsecNegPolAction) + 1)*sizeof(WCHAR)
  689. );
  690. BAIL_ON_WIN32_ERROR(dwError);
  691. }
  692. if (pIpsecNegPolObject->pszIpsecNegPolType) {
  693. dwError = RegSetValueExW(
  694. hRegKey,
  695. L"ipsecNegotiationPolicyType",
  696. 0,
  697. REG_SZ,
  698. (LPBYTE)pIpsecNegPolObject->pszIpsecNegPolType,
  699. (wcslen(pIpsecNegPolObject->pszIpsecNegPolType) + 1)*sizeof(WCHAR)
  700. );
  701. BAIL_ON_WIN32_ERROR(dwError);
  702. }
  703. dwError = RegSetValueExW(
  704. hRegKey,
  705. L"ipsecDataType",
  706. 0,
  707. REG_DWORD,
  708. (LPBYTE)&pIpsecNegPolObject->dwIpsecDataType,
  709. sizeof(DWORD)
  710. );
  711. BAIL_ON_WIN32_ERROR(dwError);
  712. if (pIpsecNegPolObject->pIpsecData) {
  713. dwError = RegSetValueExW(
  714. hRegKey,
  715. L"ipsecData",
  716. 0,
  717. REG_BINARY,
  718. pIpsecNegPolObject->pIpsecData,
  719. pIpsecNegPolObject->dwIpsecDataLen
  720. );
  721. BAIL_ON_WIN32_ERROR(dwError);
  722. }
  723. if (pIpsecNegPolObject->ppszIpsecNFAReferences) {
  724. dwError = RegWriteMultiValuedString(
  725. hRegKey,
  726. L"ipsecOwnersReference",
  727. pIpsecNegPolObject->ppszIpsecNFAReferences,
  728. pIpsecNegPolObject->dwNFACount
  729. );
  730. BAIL_ON_WIN32_ERROR(dwError);
  731. }
  732. dwError = RegSetValueExW(
  733. hRegKey,
  734. L"whenChanged",
  735. 0,
  736. REG_DWORD,
  737. (LPBYTE)&pIpsecNegPolObject->dwWhenChanged,
  738. sizeof(DWORD)
  739. );
  740. BAIL_ON_WIN32_ERROR(dwError);
  741. error:
  742. if (hRegKey) {
  743. RegCloseKey(hRegKey);
  744. }
  745. return(dwError);
  746. }
  747. DWORD
  748. PersistISAKMPObject(
  749. HKEY hRegistryKey,
  750. PIPSEC_ISAKMP_OBJECT pIpsecISAKMPObject
  751. )
  752. {
  753. HKEY hRegKey = NULL;
  754. DWORD dwError = 0;
  755. DWORD dwDisposition = 0;
  756. dwError = RegCreateKeyExW(
  757. hRegistryKey,
  758. pIpsecISAKMPObject->pszDistinguishedName,
  759. 0,
  760. NULL,
  761. 0,
  762. KEY_ALL_ACCESS,
  763. NULL,
  764. &hRegKey,
  765. &dwDisposition
  766. );
  767. BAIL_ON_WIN32_ERROR(dwError);
  768. dwError = RegSetValueExW(
  769. hRegKey,
  770. L"ClassName",
  771. 0,
  772. REG_SZ,
  773. (LPBYTE) L"ipsecISAKMPPolicy",
  774. (wcslen(L"ipsecISAKMPPolicy") + 1)*sizeof(WCHAR)
  775. );
  776. BAIL_ON_WIN32_ERROR(dwError);
  777. if (pIpsecISAKMPObject->pszDistinguishedName) {
  778. dwError = RegSetValueExW(
  779. hRegKey,
  780. L"name",
  781. 0,
  782. REG_SZ,
  783. (LPBYTE)pIpsecISAKMPObject->pszDistinguishedName,
  784. (wcslen(pIpsecISAKMPObject->pszDistinguishedName) + 1)*sizeof(WCHAR)
  785. );
  786. BAIL_ON_WIN32_ERROR(dwError);
  787. }
  788. if (pIpsecISAKMPObject->pszIpsecName) {
  789. dwError = RegSetValueExW(
  790. hRegKey,
  791. L"ipsecName",
  792. 0,
  793. REG_SZ,
  794. (LPBYTE)pIpsecISAKMPObject->pszIpsecName,
  795. (wcslen(pIpsecISAKMPObject->pszIpsecName) + 1)* sizeof(WCHAR)
  796. );
  797. BAIL_ON_WIN32_ERROR(dwError);
  798. }
  799. if (pIpsecISAKMPObject->pszIpsecID) {
  800. dwError = RegSetValueExW(
  801. hRegKey,
  802. L"ipsecID",
  803. 0,
  804. REG_SZ,
  805. (LPBYTE)pIpsecISAKMPObject->pszIpsecID,
  806. (wcslen(pIpsecISAKMPObject->pszIpsecID) + 1)* sizeof(WCHAR)
  807. );
  808. BAIL_ON_WIN32_ERROR(dwError);
  809. }
  810. dwError = RegSetValueExW(
  811. hRegKey,
  812. L"ipsecDataType",
  813. 0,
  814. REG_DWORD,
  815. (LPBYTE)&pIpsecISAKMPObject->dwIpsecDataType,
  816. sizeof(DWORD)
  817. );
  818. BAIL_ON_WIN32_ERROR(dwError);
  819. if (pIpsecISAKMPObject->pIpsecData) {
  820. dwError = RegSetValueExW(
  821. hRegKey,
  822. L"ipsecData",
  823. 0,
  824. REG_BINARY,
  825. pIpsecISAKMPObject->pIpsecData,
  826. pIpsecISAKMPObject->dwIpsecDataLen
  827. );
  828. BAIL_ON_WIN32_ERROR(dwError);
  829. }
  830. dwError = RegSetValueExW(
  831. hRegKey,
  832. L"whenChanged",
  833. 0,
  834. REG_DWORD,
  835. (LPBYTE)&pIpsecISAKMPObject->dwWhenChanged,
  836. sizeof(DWORD)
  837. );
  838. BAIL_ON_WIN32_ERROR(dwError);
  839. if (pIpsecISAKMPObject->ppszIpsecNFAReferences) {
  840. dwError = RegWriteMultiValuedString(
  841. hRegKey,
  842. L"ipsecOwnersReference",
  843. pIpsecISAKMPObject->ppszIpsecNFAReferences,
  844. pIpsecISAKMPObject->dwNFACount
  845. );
  846. BAIL_ON_WIN32_ERROR(dwError);
  847. }
  848. error:
  849. if (hRegKey) {
  850. RegCloseKey(hRegKey);
  851. }
  852. return(dwError);
  853. }
  854. DWORD
  855. CloneDirectoryPolicyObject(
  856. PIPSEC_POLICY_OBJECT pIpsecPolicyObject,
  857. PIPSEC_POLICY_OBJECT * ppIpsecRegPolicyObject
  858. )
  859. {
  860. DWORD dwError = 0;
  861. PIPSEC_POLICY_OBJECT pIpsecRegPolicyObject = NULL;
  862. //
  863. // Clone Filter Objects
  864. //
  865. pIpsecRegPolicyObject = (PIPSEC_POLICY_OBJECT)AllocPolMem(
  866. sizeof(IPSEC_POLICY_OBJECT)
  867. );
  868. if (!pIpsecRegPolicyObject) {
  869. dwError = ERROR_OUTOFMEMORY;
  870. BAIL_ON_WIN32_ERROR(dwError);
  871. }
  872. if (pIpsecPolicyObject->ppIpsecFilterObjects) {
  873. dwError = CloneDirectoryFilterObjects(
  874. pIpsecPolicyObject->ppIpsecFilterObjects,
  875. pIpsecPolicyObject->NumberofFilters,
  876. &pIpsecRegPolicyObject->ppIpsecFilterObjects
  877. );
  878. BAIL_ON_WIN32_ERROR(dwError);
  879. pIpsecRegPolicyObject->NumberofFilters = pIpsecPolicyObject->NumberofFilters;
  880. }
  881. //
  882. // Clone NegPol Objects
  883. //
  884. if (pIpsecPolicyObject->ppIpsecNegPolObjects) {
  885. dwError = CloneDirectoryNegPolObjects(
  886. pIpsecPolicyObject->ppIpsecNegPolObjects,
  887. pIpsecPolicyObject->NumberofNegPols,
  888. &pIpsecRegPolicyObject->ppIpsecNegPolObjects
  889. );
  890. BAIL_ON_WIN32_ERROR(dwError);
  891. pIpsecRegPolicyObject->NumberofNegPols = pIpsecPolicyObject->NumberofNegPols;
  892. }
  893. //
  894. // Clone NFA Objects
  895. //
  896. if (pIpsecPolicyObject->ppIpsecNFAObjects) {
  897. dwError = CloneDirectoryNFAObjects(
  898. pIpsecPolicyObject->ppIpsecNFAObjects,
  899. pIpsecPolicyObject->NumberofRulesReturned,
  900. &pIpsecRegPolicyObject->ppIpsecNFAObjects
  901. );
  902. BAIL_ON_WIN32_ERROR(dwError);
  903. pIpsecRegPolicyObject->NumberofRules = pIpsecPolicyObject->NumberofRules;
  904. pIpsecRegPolicyObject->NumberofRulesReturned = pIpsecPolicyObject->NumberofRulesReturned;
  905. }
  906. //
  907. // Clone ISAKMP Objects
  908. //
  909. if (pIpsecPolicyObject->ppIpsecISAKMPObjects) {
  910. dwError = CloneDirectoryISAKMPObjects(
  911. pIpsecPolicyObject->ppIpsecISAKMPObjects,
  912. pIpsecPolicyObject->NumberofISAKMPs,
  913. &pIpsecRegPolicyObject->ppIpsecISAKMPObjects
  914. );
  915. BAIL_ON_WIN32_ERROR(dwError);
  916. pIpsecRegPolicyObject->NumberofISAKMPs = pIpsecPolicyObject->NumberofISAKMPs;
  917. }
  918. //
  919. // Now copy the rest of the data in the object
  920. //
  921. if (pIpsecPolicyObject->pszIpsecOwnersReference) {
  922. dwError = CopyPolicyDSToRegString(
  923. pIpsecPolicyObject->pszIpsecOwnersReference,
  924. &pIpsecRegPolicyObject->pszIpsecOwnersReference
  925. );
  926. BAIL_ON_WIN32_ERROR(dwError);
  927. }
  928. if (pIpsecPolicyObject->pszIpsecName) {
  929. pIpsecRegPolicyObject->pszIpsecName = AllocPolStr(
  930. pIpsecPolicyObject->pszIpsecName
  931. );
  932. if (!pIpsecRegPolicyObject->pszIpsecName) {
  933. dwError = ERROR_OUTOFMEMORY;
  934. BAIL_ON_WIN32_ERROR(dwError);
  935. }
  936. }
  937. if (pIpsecPolicyObject->pszIpsecID) {
  938. pIpsecRegPolicyObject->pszIpsecID = AllocPolStr(
  939. pIpsecPolicyObject->pszIpsecID
  940. );
  941. if (!pIpsecRegPolicyObject->pszIpsecID) {
  942. dwError = ERROR_OUTOFMEMORY;
  943. BAIL_ON_WIN32_ERROR(dwError);
  944. }
  945. }
  946. if (pIpsecPolicyObject->pszIpsecISAKMPReference) {
  947. dwError = CopyISAKMPDSToFQRegString(
  948. pIpsecPolicyObject->pszIpsecISAKMPReference,
  949. &pIpsecRegPolicyObject->pszIpsecISAKMPReference
  950. );
  951. BAIL_ON_WIN32_ERROR(dwError);
  952. }
  953. pIpsecRegPolicyObject->dwIpsecDataType = pIpsecPolicyObject->dwIpsecDataType;
  954. if (pIpsecPolicyObject->pIpsecData) {
  955. dwError = CopyBinaryValue(
  956. pIpsecPolicyObject->pIpsecData,
  957. pIpsecPolicyObject->dwIpsecDataLen,
  958. &pIpsecRegPolicyObject->pIpsecData
  959. );
  960. BAIL_ON_WIN32_ERROR(dwError);
  961. pIpsecRegPolicyObject->dwIpsecDataLen = pIpsecPolicyObject->dwIpsecDataLen;
  962. }
  963. if (pIpsecPolicyObject->ppszIpsecNFAReferences) {
  964. dwError = CloneNFAReferencesDSToRegistry(
  965. pIpsecPolicyObject->ppszIpsecNFAReferences,
  966. pIpsecPolicyObject->NumberofRules,
  967. &(pIpsecRegPolicyObject->ppszIpsecNFAReferences),
  968. &(pIpsecRegPolicyObject->NumberofRules)
  969. );
  970. BAIL_ON_WIN32_ERROR(dwError);
  971. }
  972. if (pIpsecPolicyObject->pszDescription) {
  973. pIpsecRegPolicyObject->pszDescription = AllocPolStr(
  974. pIpsecPolicyObject->pszDescription
  975. );
  976. if (!pIpsecRegPolicyObject->pszDescription) {
  977. dwError = ERROR_OUTOFMEMORY;
  978. BAIL_ON_WIN32_ERROR(dwError);
  979. }
  980. }
  981. pIpsecRegPolicyObject->dwWhenChanged = pIpsecPolicyObject->dwWhenChanged;
  982. *ppIpsecRegPolicyObject = pIpsecRegPolicyObject;
  983. return(dwError);
  984. error:
  985. if (pIpsecRegPolicyObject) {
  986. FreeIpsecPolicyObject(
  987. pIpsecRegPolicyObject
  988. );
  989. }
  990. *ppIpsecRegPolicyObject = NULL;
  991. return(dwError);
  992. }
  993. DWORD
  994. CloneDirectoryNFAObjects(
  995. PIPSEC_NFA_OBJECT * ppIpsecNFAObjects,
  996. DWORD dwNumNFAObjects,
  997. PIPSEC_NFA_OBJECT ** pppIpsecRegNFAObjects
  998. )
  999. {
  1000. DWORD dwError = 0;
  1001. DWORD i = 0;
  1002. PIPSEC_NFA_OBJECT * ppIpsecRegNFAObjects = NULL;
  1003. PIPSEC_NFA_OBJECT pIpsecRegNFAObject = NULL;
  1004. if (dwNumNFAObjects) {
  1005. ppIpsecRegNFAObjects = (PIPSEC_NFA_OBJECT *)AllocPolMem(
  1006. dwNumNFAObjects*sizeof(PIPSEC_NFA_OBJECT)
  1007. );
  1008. if (!ppIpsecRegNFAObjects) {
  1009. dwError = ERROR_OUTOFMEMORY;
  1010. BAIL_ON_WIN32_ERROR(dwError);
  1011. }
  1012. }
  1013. for (i = 0; i < dwNumNFAObjects; i++) {
  1014. dwError = CloneDirectoryNFAObject(
  1015. *(ppIpsecNFAObjects + i),
  1016. &pIpsecRegNFAObject
  1017. );
  1018. BAIL_ON_WIN32_ERROR(dwError);
  1019. *(ppIpsecRegNFAObjects + i) = pIpsecRegNFAObject;
  1020. }
  1021. *pppIpsecRegNFAObjects = ppIpsecRegNFAObjects;
  1022. return(dwError);
  1023. error:
  1024. if (ppIpsecRegNFAObjects) {
  1025. FreeIpsecNFAObjects(
  1026. ppIpsecRegNFAObjects,
  1027. i
  1028. );
  1029. }
  1030. *pppIpsecRegNFAObjects = NULL;
  1031. return(dwError);
  1032. }
  1033. DWORD
  1034. CloneDirectoryFilterObjects(
  1035. PIPSEC_FILTER_OBJECT * ppIpsecFilterObjects,
  1036. DWORD dwNumFilterObjects,
  1037. PIPSEC_FILTER_OBJECT ** pppIpsecRegFilterObjects
  1038. )
  1039. {
  1040. DWORD dwError = 0;
  1041. DWORD i = 0;
  1042. PIPSEC_FILTER_OBJECT * ppIpsecRegFilterObjects = NULL;
  1043. PIPSEC_FILTER_OBJECT pIpsecRegFilterObject = NULL;
  1044. if (dwNumFilterObjects) {
  1045. ppIpsecRegFilterObjects = (PIPSEC_FILTER_OBJECT *)AllocPolMem(
  1046. dwNumFilterObjects*sizeof(PIPSEC_FILTER_OBJECT)
  1047. );
  1048. if (!ppIpsecRegFilterObjects) {
  1049. dwError = ERROR_OUTOFMEMORY;
  1050. BAIL_ON_WIN32_ERROR(dwError);
  1051. }
  1052. }
  1053. for (i = 0; i < dwNumFilterObjects; i++) {
  1054. dwError = CloneDirectoryFilterObject(
  1055. *(ppIpsecFilterObjects + i),
  1056. &pIpsecRegFilterObject
  1057. );
  1058. BAIL_ON_WIN32_ERROR(dwError);
  1059. *(ppIpsecRegFilterObjects + i) = pIpsecRegFilterObject;
  1060. }
  1061. *pppIpsecRegFilterObjects = ppIpsecRegFilterObjects;
  1062. return(dwError);
  1063. error:
  1064. if (ppIpsecRegFilterObjects) {
  1065. FreeIpsecFilterObjects(
  1066. ppIpsecRegFilterObjects,
  1067. i
  1068. );
  1069. }
  1070. *pppIpsecRegFilterObjects = NULL;
  1071. return(dwError);
  1072. }
  1073. DWORD
  1074. CloneDirectoryISAKMPObjects(
  1075. PIPSEC_ISAKMP_OBJECT * ppIpsecISAKMPObjects,
  1076. DWORD dwNumISAKMPObjects,
  1077. PIPSEC_ISAKMP_OBJECT ** pppIpsecRegISAKMPObjects
  1078. )
  1079. {
  1080. DWORD dwError = 0;
  1081. DWORD i = 0;
  1082. PIPSEC_ISAKMP_OBJECT * ppIpsecRegISAKMPObjects = NULL;
  1083. PIPSEC_ISAKMP_OBJECT pIpsecRegISAKMPObject = NULL;
  1084. if (dwNumISAKMPObjects) {
  1085. ppIpsecRegISAKMPObjects = (PIPSEC_ISAKMP_OBJECT *)AllocPolMem(
  1086. dwNumISAKMPObjects*sizeof(PIPSEC_ISAKMP_OBJECT)
  1087. );
  1088. if (!ppIpsecRegISAKMPObjects) {
  1089. dwError = ERROR_OUTOFMEMORY;
  1090. BAIL_ON_WIN32_ERROR(dwError);
  1091. }
  1092. }
  1093. for (i = 0; i < dwNumISAKMPObjects; i++) {
  1094. dwError = CloneDirectoryISAKMPObject(
  1095. *(ppIpsecISAKMPObjects + i),
  1096. &pIpsecRegISAKMPObject
  1097. );
  1098. BAIL_ON_WIN32_ERROR(dwError);
  1099. *(ppIpsecRegISAKMPObjects + i) = pIpsecRegISAKMPObject;
  1100. }
  1101. *pppIpsecRegISAKMPObjects = ppIpsecRegISAKMPObjects;
  1102. return(dwError);
  1103. error:
  1104. if (ppIpsecRegISAKMPObjects) {
  1105. FreeIpsecISAKMPObjects(
  1106. ppIpsecRegISAKMPObjects,
  1107. i
  1108. );
  1109. }
  1110. *pppIpsecRegISAKMPObjects = NULL;
  1111. return(dwError);
  1112. }
  1113. DWORD
  1114. CloneDirectoryNegPolObjects(
  1115. PIPSEC_NEGPOL_OBJECT * ppIpsecNegPolObjects,
  1116. DWORD dwNumNegPolObjects,
  1117. PIPSEC_NEGPOL_OBJECT ** pppIpsecRegNegPolObjects
  1118. )
  1119. {
  1120. DWORD dwError = 0;
  1121. DWORD i = 0;
  1122. PIPSEC_NEGPOL_OBJECT * ppIpsecRegNegPolObjects = NULL;
  1123. PIPSEC_NEGPOL_OBJECT pIpsecRegNegPolObject = NULL;
  1124. if (dwNumNegPolObjects) {
  1125. ppIpsecRegNegPolObjects = (PIPSEC_NEGPOL_OBJECT *)AllocPolMem(
  1126. dwNumNegPolObjects*sizeof(PIPSEC_NEGPOL_OBJECT)
  1127. );
  1128. if (!ppIpsecRegNegPolObjects) {
  1129. dwError = ERROR_OUTOFMEMORY;
  1130. BAIL_ON_WIN32_ERROR(dwError);
  1131. }
  1132. }
  1133. for (i = 0; i < dwNumNegPolObjects; i++) {
  1134. dwError = CloneDirectoryNegPolObject(
  1135. *(ppIpsecNegPolObjects + i),
  1136. &pIpsecRegNegPolObject
  1137. );
  1138. BAIL_ON_WIN32_ERROR(dwError);
  1139. *(ppIpsecRegNegPolObjects + i) = pIpsecRegNegPolObject;
  1140. }
  1141. *pppIpsecRegNegPolObjects = ppIpsecRegNegPolObjects;
  1142. return(dwError);
  1143. error:
  1144. if (ppIpsecRegNegPolObjects) {
  1145. FreeIpsecNegPolObjects(
  1146. ppIpsecRegNegPolObjects,
  1147. i
  1148. );
  1149. }
  1150. *pppIpsecRegNegPolObjects = NULL;
  1151. return(dwError);
  1152. }
  1153. DWORD
  1154. CloneDirectoryFilterObject(
  1155. PIPSEC_FILTER_OBJECT pIpsecFilterObject,
  1156. PIPSEC_FILTER_OBJECT * ppIpsecRegFilterObject
  1157. )
  1158. {
  1159. DWORD dwError = 0;
  1160. PIPSEC_FILTER_OBJECT pIpsecRegFilterObject = NULL;
  1161. pIpsecRegFilterObject = (PIPSEC_FILTER_OBJECT)AllocPolMem(
  1162. sizeof(IPSEC_FILTER_OBJECT)
  1163. );
  1164. if (!pIpsecRegFilterObject) {
  1165. dwError = ERROR_OUTOFMEMORY;
  1166. BAIL_ON_WIN32_ERROR(dwError);
  1167. }
  1168. if (pIpsecFilterObject->pszDistinguishedName) {
  1169. dwError = CopyFilterDSToRegString(
  1170. pIpsecFilterObject->pszDistinguishedName,
  1171. &pIpsecRegFilterObject->pszDistinguishedName
  1172. );
  1173. BAIL_ON_WIN32_ERROR(dwError);
  1174. }
  1175. if (pIpsecFilterObject->pszDescription) {
  1176. pIpsecRegFilterObject->pszDescription = AllocPolStr(
  1177. pIpsecFilterObject->pszDescription
  1178. );
  1179. if (!pIpsecRegFilterObject->pszDescription) {
  1180. dwError = ERROR_OUTOFMEMORY;
  1181. BAIL_ON_WIN32_ERROR(dwError);
  1182. }
  1183. }
  1184. if (pIpsecFilterObject->pszIpsecName) {
  1185. pIpsecRegFilterObject->pszIpsecName = AllocPolStr(
  1186. pIpsecFilterObject->pszIpsecName
  1187. );
  1188. if (!pIpsecRegFilterObject->pszIpsecName) {
  1189. dwError = ERROR_OUTOFMEMORY;
  1190. BAIL_ON_WIN32_ERROR(dwError);
  1191. }
  1192. }
  1193. if (pIpsecFilterObject->pszIpsecID) {
  1194. pIpsecRegFilterObject->pszIpsecID = AllocPolStr(
  1195. pIpsecFilterObject->pszIpsecID
  1196. );
  1197. if (!pIpsecRegFilterObject->pszIpsecID) {
  1198. dwError = ERROR_OUTOFMEMORY;
  1199. BAIL_ON_WIN32_ERROR(dwError);
  1200. }
  1201. }
  1202. pIpsecRegFilterObject->dwIpsecDataType = pIpsecFilterObject->dwIpsecDataType;
  1203. if (pIpsecFilterObject->pIpsecData) {
  1204. dwError = CopyBinaryValue(
  1205. pIpsecFilterObject->pIpsecData,
  1206. pIpsecFilterObject->dwIpsecDataLen,
  1207. &pIpsecRegFilterObject->pIpsecData
  1208. );
  1209. BAIL_ON_WIN32_ERROR(dwError);
  1210. pIpsecRegFilterObject->dwIpsecDataLen = pIpsecFilterObject->dwIpsecDataLen;
  1211. }
  1212. if (pIpsecFilterObject->ppszIpsecNFAReferences) {
  1213. dwError = CloneNFAReferencesDSToRegistry(
  1214. pIpsecFilterObject->ppszIpsecNFAReferences,
  1215. pIpsecFilterObject->dwNFACount,
  1216. &pIpsecRegFilterObject->ppszIpsecNFAReferences,
  1217. &pIpsecRegFilterObject->dwNFACount
  1218. );
  1219. BAIL_ON_WIN32_ERROR(dwError);
  1220. }
  1221. pIpsecRegFilterObject->dwWhenChanged = pIpsecFilterObject->dwWhenChanged;
  1222. *ppIpsecRegFilterObject = pIpsecRegFilterObject;
  1223. return(dwError);
  1224. error:
  1225. if (pIpsecRegFilterObject) {
  1226. FreeIpsecFilterObject(pIpsecRegFilterObject);
  1227. }
  1228. *ppIpsecRegFilterObject = NULL;
  1229. return(dwError);
  1230. }
  1231. DWORD
  1232. CloneDirectoryNegPolObject(
  1233. PIPSEC_NEGPOL_OBJECT pIpsecNegPolObject,
  1234. PIPSEC_NEGPOL_OBJECT * ppIpsecRegNegPolObject
  1235. )
  1236. {
  1237. DWORD dwError = 0;
  1238. PIPSEC_NEGPOL_OBJECT pIpsecRegNegPolObject = NULL;
  1239. pIpsecRegNegPolObject = (PIPSEC_NEGPOL_OBJECT)AllocPolMem(
  1240. sizeof(IPSEC_NEGPOL_OBJECT)
  1241. );
  1242. if (!pIpsecRegNegPolObject) {
  1243. dwError = ERROR_OUTOFMEMORY;
  1244. BAIL_ON_WIN32_ERROR(dwError);
  1245. }
  1246. if (pIpsecNegPolObject->pszDistinguishedName) {
  1247. dwError = CopyNegPolDSToRegString(
  1248. pIpsecNegPolObject->pszDistinguishedName,
  1249. &pIpsecRegNegPolObject->pszDistinguishedName
  1250. );
  1251. BAIL_ON_WIN32_ERROR(dwError);
  1252. }
  1253. if (pIpsecNegPolObject->pszIpsecName) {
  1254. pIpsecRegNegPolObject->pszIpsecName = AllocPolStr(
  1255. pIpsecNegPolObject->pszIpsecName
  1256. );
  1257. if (!pIpsecRegNegPolObject->pszIpsecName) {
  1258. dwError = ERROR_OUTOFMEMORY;
  1259. BAIL_ON_WIN32_ERROR(dwError);
  1260. }
  1261. }
  1262. if (pIpsecNegPolObject->pszDescription) {
  1263. pIpsecRegNegPolObject->pszDescription = AllocPolStr(
  1264. pIpsecNegPolObject->pszDescription
  1265. );
  1266. if (!pIpsecRegNegPolObject->pszDescription) {
  1267. dwError = ERROR_OUTOFMEMORY;
  1268. BAIL_ON_WIN32_ERROR(dwError);
  1269. }
  1270. }
  1271. if (pIpsecNegPolObject->pszIpsecID) {
  1272. pIpsecRegNegPolObject->pszIpsecID = AllocPolStr(
  1273. pIpsecNegPolObject->pszIpsecID
  1274. );
  1275. if (!pIpsecRegNegPolObject->pszIpsecID) {
  1276. dwError = ERROR_OUTOFMEMORY;
  1277. BAIL_ON_WIN32_ERROR(dwError);
  1278. }
  1279. }
  1280. pIpsecRegNegPolObject->dwIpsecDataType = pIpsecNegPolObject->dwIpsecDataType;
  1281. if (pIpsecNegPolObject->pIpsecData) {
  1282. dwError = CopyBinaryValue(
  1283. pIpsecNegPolObject->pIpsecData,
  1284. pIpsecNegPolObject->dwIpsecDataLen,
  1285. &pIpsecRegNegPolObject->pIpsecData
  1286. );
  1287. BAIL_ON_WIN32_ERROR(dwError);
  1288. pIpsecRegNegPolObject->dwIpsecDataLen = pIpsecNegPolObject->dwIpsecDataLen;
  1289. }
  1290. if (pIpsecNegPolObject->pszIpsecNegPolAction) {
  1291. pIpsecRegNegPolObject->pszIpsecNegPolAction = AllocPolStr(
  1292. pIpsecNegPolObject->pszIpsecNegPolAction
  1293. );
  1294. if (!pIpsecRegNegPolObject->pszIpsecNegPolAction) {
  1295. dwError = ERROR_OUTOFMEMORY;
  1296. BAIL_ON_WIN32_ERROR(dwError);
  1297. }
  1298. }
  1299. if (pIpsecNegPolObject->pszIpsecNegPolType) {
  1300. pIpsecRegNegPolObject->pszIpsecNegPolType = AllocPolStr(
  1301. pIpsecNegPolObject->pszIpsecNegPolType
  1302. );
  1303. if (!pIpsecRegNegPolObject->pszIpsecNegPolType) {
  1304. dwError = ERROR_OUTOFMEMORY;
  1305. BAIL_ON_WIN32_ERROR(dwError);
  1306. }
  1307. }
  1308. if (pIpsecNegPolObject->ppszIpsecNFAReferences) {
  1309. dwError = CloneNFAReferencesDSToRegistry(
  1310. pIpsecNegPolObject->ppszIpsecNFAReferences,
  1311. pIpsecNegPolObject->dwNFACount,
  1312. &pIpsecRegNegPolObject->ppszIpsecNFAReferences,
  1313. &pIpsecRegNegPolObject->dwNFACount
  1314. );
  1315. BAIL_ON_WIN32_ERROR(dwError);
  1316. }
  1317. pIpsecRegNegPolObject->dwWhenChanged = pIpsecNegPolObject->dwWhenChanged;
  1318. *ppIpsecRegNegPolObject = pIpsecRegNegPolObject;
  1319. return(dwError);
  1320. error:
  1321. if (pIpsecRegNegPolObject) {
  1322. FreeIpsecNegPolObject(pIpsecRegNegPolObject);
  1323. }
  1324. *ppIpsecRegNegPolObject = NULL;
  1325. return(dwError);
  1326. }
  1327. DWORD
  1328. CloneDirectoryNFAObject(
  1329. PIPSEC_NFA_OBJECT pIpsecNFAObject,
  1330. PIPSEC_NFA_OBJECT * ppIpsecRegNFAObject
  1331. )
  1332. {
  1333. DWORD dwError = 0;
  1334. PIPSEC_NFA_OBJECT pIpsecRegNFAObject = NULL;
  1335. pIpsecRegNFAObject = (PIPSEC_NFA_OBJECT)AllocPolMem(
  1336. sizeof(IPSEC_NFA_OBJECT)
  1337. );
  1338. if (!pIpsecRegNFAObject) {
  1339. dwError = ERROR_OUTOFMEMORY;
  1340. BAIL_ON_WIN32_ERROR(dwError);
  1341. }
  1342. if (pIpsecNFAObject->pszDistinguishedName) {
  1343. dwError = CopyNFADSToRegString(
  1344. pIpsecNFAObject->pszDistinguishedName,
  1345. &pIpsecRegNFAObject->pszDistinguishedName
  1346. );
  1347. BAIL_ON_WIN32_ERROR(dwError);
  1348. }
  1349. if (pIpsecNFAObject->pszIpsecName) {
  1350. pIpsecRegNFAObject->pszIpsecName = AllocPolStr(
  1351. pIpsecNFAObject->pszIpsecName
  1352. );
  1353. if (!pIpsecRegNFAObject->pszIpsecName) {
  1354. dwError = ERROR_OUTOFMEMORY;
  1355. BAIL_ON_WIN32_ERROR(dwError);
  1356. }
  1357. }
  1358. if (pIpsecNFAObject->pszDescription) {
  1359. pIpsecRegNFAObject->pszDescription = AllocPolStr(
  1360. pIpsecNFAObject->pszDescription
  1361. );
  1362. if (!pIpsecRegNFAObject->pszDescription) {
  1363. dwError = ERROR_OUTOFMEMORY;
  1364. BAIL_ON_WIN32_ERROR(dwError);
  1365. }
  1366. }
  1367. if (pIpsecNFAObject->pszIpsecID) {
  1368. pIpsecRegNFAObject->pszIpsecID = AllocPolStr(
  1369. pIpsecNFAObject->pszIpsecID
  1370. );
  1371. if (!pIpsecRegNFAObject->pszIpsecID) {
  1372. dwError = ERROR_OUTOFMEMORY;
  1373. BAIL_ON_WIN32_ERROR(dwError);
  1374. }
  1375. }
  1376. pIpsecRegNFAObject->dwIpsecDataType = pIpsecNFAObject->dwIpsecDataType;
  1377. if (pIpsecNFAObject->pIpsecData) {
  1378. dwError = CopyBinaryValue(
  1379. pIpsecNFAObject->pIpsecData,
  1380. pIpsecNFAObject->dwIpsecDataLen,
  1381. &pIpsecRegNFAObject->pIpsecData
  1382. );
  1383. BAIL_ON_WIN32_ERROR(dwError);
  1384. pIpsecRegNFAObject->dwIpsecDataLen = pIpsecNFAObject->dwIpsecDataLen;
  1385. }
  1386. if (pIpsecNFAObject->pszIpsecOwnersReference) {
  1387. dwError = CopyPolicyDSToFQRegString(
  1388. pIpsecNFAObject->pszIpsecOwnersReference,
  1389. &pIpsecRegNFAObject->pszIpsecOwnersReference
  1390. );
  1391. BAIL_ON_WIN32_ERROR(dwError);
  1392. }
  1393. if (pIpsecNFAObject->pszIpsecFilterReference) {
  1394. dwError = CopyFilterDSToFQRegString(
  1395. pIpsecNFAObject->pszIpsecFilterReference,
  1396. &pIpsecRegNFAObject->pszIpsecFilterReference
  1397. );
  1398. BAIL_ON_WIN32_ERROR(dwError);
  1399. }
  1400. if (pIpsecNFAObject->pszIpsecNegPolReference) {
  1401. dwError = CopyNegPolDSToFQRegString(
  1402. pIpsecNFAObject->pszIpsecNegPolReference,
  1403. &pIpsecRegNFAObject->pszIpsecNegPolReference
  1404. );
  1405. BAIL_ON_WIN32_ERROR(dwError);
  1406. }
  1407. pIpsecRegNFAObject->dwWhenChanged = pIpsecNFAObject->dwWhenChanged;
  1408. *ppIpsecRegNFAObject = pIpsecRegNFAObject;
  1409. return(dwError);
  1410. error:
  1411. if (pIpsecRegNFAObject) {
  1412. FreeIpsecNFAObject(pIpsecRegNFAObject);
  1413. }
  1414. *ppIpsecRegNFAObject = NULL;
  1415. return(dwError);
  1416. }
  1417. DWORD
  1418. CloneDirectoryISAKMPObject(
  1419. PIPSEC_ISAKMP_OBJECT pIpsecISAKMPObject,
  1420. PIPSEC_ISAKMP_OBJECT * ppIpsecRegISAKMPObject
  1421. )
  1422. {
  1423. DWORD dwError = 0;
  1424. PIPSEC_ISAKMP_OBJECT pIpsecRegISAKMPObject = NULL;
  1425. pIpsecRegISAKMPObject = (PIPSEC_ISAKMP_OBJECT)AllocPolMem(
  1426. sizeof(IPSEC_ISAKMP_OBJECT)
  1427. );
  1428. if (!pIpsecRegISAKMPObject) {
  1429. dwError = ERROR_OUTOFMEMORY;
  1430. BAIL_ON_WIN32_ERROR(dwError);
  1431. }
  1432. if (pIpsecISAKMPObject->pszDistinguishedName) {
  1433. dwError = CopyISAKMPDSToRegString(
  1434. pIpsecISAKMPObject->pszDistinguishedName,
  1435. &pIpsecRegISAKMPObject->pszDistinguishedName
  1436. );
  1437. BAIL_ON_WIN32_ERROR(dwError);
  1438. }
  1439. if (pIpsecISAKMPObject->pszIpsecName) {
  1440. pIpsecRegISAKMPObject->pszIpsecName = AllocPolStr(
  1441. pIpsecISAKMPObject->pszIpsecName
  1442. );
  1443. if (!pIpsecRegISAKMPObject->pszIpsecName) {
  1444. dwError = ERROR_OUTOFMEMORY;
  1445. BAIL_ON_WIN32_ERROR(dwError);
  1446. }
  1447. }
  1448. if (pIpsecISAKMPObject->pszIpsecID) {
  1449. pIpsecRegISAKMPObject->pszIpsecID = AllocPolStr(
  1450. pIpsecISAKMPObject->pszIpsecID
  1451. );
  1452. if (!pIpsecRegISAKMPObject->pszIpsecID) {
  1453. dwError = ERROR_OUTOFMEMORY;
  1454. BAIL_ON_WIN32_ERROR(dwError);
  1455. }
  1456. }
  1457. pIpsecRegISAKMPObject->dwIpsecDataType = pIpsecISAKMPObject->dwIpsecDataType;
  1458. if (pIpsecISAKMPObject->pIpsecData) {
  1459. dwError = CopyBinaryValue(
  1460. pIpsecISAKMPObject->pIpsecData,
  1461. pIpsecISAKMPObject->dwIpsecDataLen,
  1462. &pIpsecRegISAKMPObject->pIpsecData
  1463. );
  1464. BAIL_ON_WIN32_ERROR(dwError);
  1465. }
  1466. pIpsecRegISAKMPObject->dwIpsecDataLen = pIpsecISAKMPObject->dwIpsecDataLen;
  1467. if (pIpsecISAKMPObject->ppszIpsecNFAReferences) {
  1468. dwError = CloneNFAReferencesDSToRegistry(
  1469. pIpsecISAKMPObject->ppszIpsecNFAReferences,
  1470. pIpsecISAKMPObject->dwNFACount,
  1471. &pIpsecRegISAKMPObject->ppszIpsecNFAReferences,
  1472. &pIpsecRegISAKMPObject->dwNFACount
  1473. );
  1474. BAIL_ON_WIN32_ERROR(dwError);
  1475. }
  1476. pIpsecRegISAKMPObject->dwWhenChanged = pIpsecISAKMPObject->dwWhenChanged;
  1477. *ppIpsecRegISAKMPObject = pIpsecRegISAKMPObject;
  1478. return(dwError);
  1479. error:
  1480. if (pIpsecRegISAKMPObject) {
  1481. FreeIpsecISAKMPObject(pIpsecRegISAKMPObject);
  1482. }
  1483. *ppIpsecRegISAKMPObject = NULL;
  1484. return(dwError);
  1485. }
  1486. DWORD
  1487. CopyBinaryValue(
  1488. LPBYTE pMem,
  1489. DWORD dwMemSize,
  1490. LPBYTE * ppNewMem
  1491. )
  1492. {
  1493. LPBYTE pNewMem = NULL;
  1494. DWORD dwError = 0;
  1495. pNewMem = (LPBYTE)AllocPolMem(dwMemSize);
  1496. if (!pNewMem) {
  1497. dwError = ERROR_OUTOFMEMORY;
  1498. BAIL_ON_WIN32_ERROR(dwError);
  1499. }
  1500. memcpy(pNewMem, pMem, dwMemSize);
  1501. *ppNewMem = pNewMem;
  1502. return(dwError);
  1503. error:
  1504. if (pNewMem) {
  1505. FreePolMem(pNewMem);
  1506. }
  1507. *ppNewMem = NULL;
  1508. return(dwError);
  1509. }
  1510. DWORD
  1511. CopyFilterDSToFQRegString(
  1512. LPWSTR pszFilterDN,
  1513. LPWSTR * ppszFilterName
  1514. )
  1515. {
  1516. DWORD dwError = 0;
  1517. WCHAR szCommonName[MAX_PATH];
  1518. LPWSTR pszGuidName = NULL;
  1519. LPWSTR pszFilterName = NULL;
  1520. DWORD dwStringSize = 0;
  1521. dwError = ComputePrelimCN(
  1522. pszFilterDN,
  1523. szCommonName
  1524. );
  1525. BAIL_ON_WIN32_ERROR(dwError);
  1526. dwError = ComputeGUIDName(
  1527. szCommonName,
  1528. &pszGuidName
  1529. );
  1530. BAIL_ON_WIN32_ERROR(dwError);
  1531. dwStringSize = wcslen(gpszIpsecCacheKey);
  1532. dwStringSize += 1;
  1533. dwStringSize += wcslen(pszGuidName);
  1534. dwStringSize += 1;
  1535. pszFilterName = (LPWSTR)AllocPolMem(dwStringSize*sizeof(WCHAR));
  1536. if (!pszFilterName) {
  1537. dwError = ERROR_OUTOFMEMORY;
  1538. BAIL_ON_WIN32_ERROR(dwError);
  1539. }
  1540. wcscpy(pszFilterName, gpszIpsecCacheKey);
  1541. wcscat(pszFilterName, L"\\");
  1542. wcscat(pszFilterName, pszGuidName);
  1543. *ppszFilterName = pszFilterName;
  1544. return(dwError);
  1545. error:
  1546. *ppszFilterName = NULL;
  1547. return(dwError);
  1548. }
  1549. DWORD
  1550. CopyNFADSToFQRegString(
  1551. LPWSTR pszNFADN,
  1552. LPWSTR * ppszNFAName
  1553. )
  1554. {
  1555. DWORD dwError = 0;
  1556. WCHAR szCommonName[MAX_PATH];
  1557. LPWSTR pszGuidName = NULL;
  1558. LPWSTR pszNFAName = NULL;
  1559. DWORD dwStringSize = 0;
  1560. dwError = ComputePrelimCN(
  1561. pszNFADN,
  1562. szCommonName
  1563. );
  1564. BAIL_ON_WIN32_ERROR(dwError);
  1565. dwError = ComputeGUIDName(
  1566. szCommonName,
  1567. &pszGuidName
  1568. );
  1569. BAIL_ON_WIN32_ERROR(dwError);
  1570. dwStringSize = wcslen(gpszIpsecCacheKey);
  1571. dwStringSize += 1;
  1572. dwStringSize += wcslen(pszGuidName);
  1573. dwStringSize += 1;
  1574. pszNFAName = (LPWSTR)AllocPolMem(dwStringSize*sizeof(WCHAR));
  1575. if (!pszNFAName) {
  1576. dwError = ERROR_OUTOFMEMORY;
  1577. BAIL_ON_WIN32_ERROR(dwError);
  1578. }
  1579. wcscpy(pszNFAName, gpszIpsecCacheKey);
  1580. wcscat(pszNFAName, L"\\");
  1581. wcscat(pszNFAName, pszGuidName);
  1582. *ppszNFAName = pszNFAName;
  1583. return(dwError);
  1584. error:
  1585. *ppszNFAName = NULL;
  1586. return(dwError);
  1587. }
  1588. DWORD
  1589. CopyNegPolDSToFQRegString(
  1590. LPWSTR pszNegPolDN,
  1591. LPWSTR * ppszNegPolName
  1592. )
  1593. {
  1594. DWORD dwError = 0;
  1595. WCHAR szCommonName[MAX_PATH];
  1596. LPWSTR pszGuidName = NULL;
  1597. LPWSTR pszNegPolName = NULL;
  1598. DWORD dwStringSize = 0;
  1599. dwError = ComputePrelimCN(
  1600. pszNegPolDN,
  1601. szCommonName
  1602. );
  1603. BAIL_ON_WIN32_ERROR(dwError);
  1604. dwError = ComputeGUIDName(
  1605. szCommonName,
  1606. &pszGuidName
  1607. );
  1608. BAIL_ON_WIN32_ERROR(dwError);
  1609. dwStringSize = wcslen(gpszIpsecCacheKey);
  1610. dwStringSize += 1;
  1611. dwStringSize += wcslen(pszGuidName);
  1612. dwStringSize += 1;
  1613. pszNegPolName = (LPWSTR)AllocPolMem(dwStringSize*sizeof(WCHAR));
  1614. if (!pszNegPolName) {
  1615. dwError = ERROR_OUTOFMEMORY;
  1616. BAIL_ON_WIN32_ERROR(dwError);
  1617. }
  1618. wcscpy(pszNegPolName, gpszIpsecCacheKey);
  1619. wcscat(pszNegPolName, L"\\");
  1620. wcscat(pszNegPolName, pszGuidName);
  1621. *ppszNegPolName = pszNegPolName;
  1622. return(dwError);
  1623. error:
  1624. *ppszNegPolName = NULL;
  1625. return(dwError);
  1626. }
  1627. DWORD
  1628. CopyPolicyDSToFQRegString(
  1629. LPWSTR pszPolicyDN,
  1630. LPWSTR * ppszPolicyName
  1631. )
  1632. {
  1633. DWORD dwError = 0;
  1634. WCHAR szCommonName[MAX_PATH];
  1635. LPWSTR pszGuidName = NULL;
  1636. LPWSTR pszPolicyName = NULL;
  1637. DWORD dwStringSize = 0;
  1638. dwError = ComputePrelimCN(
  1639. pszPolicyDN,
  1640. szCommonName
  1641. );
  1642. BAIL_ON_WIN32_ERROR(dwError);
  1643. dwError = ComputeGUIDName(
  1644. szCommonName,
  1645. &pszGuidName
  1646. );
  1647. BAIL_ON_WIN32_ERROR(dwError);
  1648. dwStringSize = wcslen(gpszIpsecCacheKey);
  1649. dwStringSize += 1;
  1650. dwStringSize += wcslen(pszGuidName);
  1651. dwStringSize += 1;
  1652. pszPolicyName = (LPWSTR)AllocPolMem(dwStringSize*sizeof(WCHAR));
  1653. if (!pszPolicyName) {
  1654. dwError = ERROR_OUTOFMEMORY;
  1655. BAIL_ON_WIN32_ERROR(dwError);
  1656. }
  1657. wcscpy(pszPolicyName, gpszIpsecCacheKey);
  1658. wcscat(pszPolicyName, L"\\");
  1659. wcscat(pszPolicyName, pszGuidName);
  1660. *ppszPolicyName = pszPolicyName;
  1661. return(dwError);
  1662. error:
  1663. *ppszPolicyName = NULL;
  1664. return(dwError);
  1665. }
  1666. DWORD
  1667. CopyISAKMPDSToFQRegString(
  1668. LPWSTR pszISAKMPDN,
  1669. LPWSTR * ppszISAKMPName
  1670. )
  1671. {
  1672. DWORD dwError = 0;
  1673. WCHAR szCommonName[MAX_PATH];
  1674. LPWSTR pszGuidName = NULL;
  1675. LPWSTR pszISAKMPName = NULL;
  1676. DWORD dwStringSize = 0;
  1677. dwError = ComputePrelimCN(
  1678. pszISAKMPDN,
  1679. szCommonName
  1680. );
  1681. BAIL_ON_WIN32_ERROR(dwError);
  1682. dwError = ComputeGUIDName(
  1683. szCommonName,
  1684. &pszGuidName
  1685. );
  1686. BAIL_ON_WIN32_ERROR(dwError);
  1687. dwStringSize = wcslen(gpszIpsecCacheKey);
  1688. dwStringSize += 1;
  1689. dwStringSize += wcslen(pszGuidName);
  1690. dwStringSize += 1;
  1691. pszISAKMPName = (LPWSTR)AllocPolMem(dwStringSize*sizeof(WCHAR));
  1692. if (!pszISAKMPName) {
  1693. dwError = ERROR_OUTOFMEMORY;
  1694. BAIL_ON_WIN32_ERROR(dwError);
  1695. }
  1696. wcscpy(pszISAKMPName, gpszIpsecCacheKey);
  1697. wcscat(pszISAKMPName, L"\\");
  1698. wcscat(pszISAKMPName, pszGuidName);
  1699. *ppszISAKMPName = pszISAKMPName;
  1700. return(dwError);
  1701. error:
  1702. *ppszISAKMPName = NULL;
  1703. return(dwError);
  1704. }
  1705. DWORD
  1706. ComputeGUIDName(
  1707. LPWSTR szCommonName,
  1708. LPWSTR * ppszGuidName
  1709. )
  1710. {
  1711. LPWSTR pszGuidName = NULL;
  1712. DWORD dwError = 0;
  1713. pszGuidName = wcschr(szCommonName, L'=');
  1714. if (!pszGuidName) {
  1715. dwError = ERROR_INVALID_PARAMETER;
  1716. BAIL_ON_WIN32_ERROR(dwError);
  1717. }
  1718. *ppszGuidName = (pszGuidName + 1);
  1719. return(dwError);
  1720. error:
  1721. *ppszGuidName = NULL;
  1722. return(dwError);
  1723. }
  1724. DWORD
  1725. CloneNFAReferencesDSToRegistry(
  1726. LPWSTR * ppszIpsecNFAReferences,
  1727. DWORD dwNFACount,
  1728. LPWSTR * * pppszIpsecRegNFAReferences,
  1729. PDWORD pdwRegNFACount
  1730. )
  1731. {
  1732. DWORD dwError = 0;
  1733. DWORD i = 0;
  1734. LPWSTR * ppszIpsecRegNFAReferences = NULL;
  1735. ppszIpsecRegNFAReferences = (LPWSTR *)AllocPolMem(
  1736. sizeof(LPWSTR)*dwNFACount
  1737. );
  1738. if (!ppszIpsecRegNFAReferences) {
  1739. dwError = ERROR_OUTOFMEMORY;
  1740. BAIL_ON_WIN32_ERROR(dwError);
  1741. }
  1742. for (i = 0; i < dwNFACount; i++) {
  1743. dwError = CopyNFADSToFQRegString(
  1744. *(ppszIpsecNFAReferences + i),
  1745. (ppszIpsecRegNFAReferences + i)
  1746. );
  1747. BAIL_ON_WIN32_ERROR(dwError);
  1748. }
  1749. *pppszIpsecRegNFAReferences = ppszIpsecRegNFAReferences;
  1750. *pdwRegNFACount = dwNFACount;
  1751. return(dwError);
  1752. error:
  1753. if (ppszIpsecRegNFAReferences) {
  1754. FreeNFAReferences(
  1755. ppszIpsecRegNFAReferences,
  1756. i
  1757. );
  1758. }
  1759. *pppszIpsecRegNFAReferences = NULL;
  1760. *pdwRegNFACount = 0;
  1761. return(dwError);
  1762. }
  1763. DWORD
  1764. DeleteRegistryCache(
  1765. )
  1766. {
  1767. DWORD dwError = 0;
  1768. HKEY hParentKey = NULL;
  1769. WCHAR lpszName[MAX_PATH];
  1770. DWORD dwSize = 0;
  1771. dwError = RegOpenKeyExW(
  1772. HKEY_LOCAL_MACHINE,
  1773. gpszIpsecCacheKey,
  1774. 0,
  1775. KEY_ALL_ACCESS,
  1776. &hParentKey
  1777. );
  1778. BAIL_ON_WIN32_ERROR(dwError);
  1779. memset(lpszName, 0, sizeof(WCHAR)*MAX_PATH);
  1780. dwSize = MAX_PATH;
  1781. while((RegEnumKeyExW(hParentKey, 0, lpszName,
  1782. &dwSize, NULL,
  1783. NULL, NULL,NULL)) == ERROR_SUCCESS) {
  1784. dwError = RegDeleteKeyW(
  1785. hParentKey,
  1786. lpszName
  1787. );
  1788. if (dwError != ERROR_SUCCESS) {
  1789. break;
  1790. }
  1791. memset(lpszName, 0, sizeof(WCHAR)*MAX_PATH);
  1792. dwSize = MAX_PATH;
  1793. }
  1794. error:
  1795. if (hParentKey) {
  1796. RegCloseKey(hParentKey);
  1797. }
  1798. return(dwError);
  1799. }
  1800. DWORD
  1801. RegWriteMultiValuedString(
  1802. HKEY hRegKey,
  1803. LPWSTR pszValueName,
  1804. LPWSTR * ppszStringReferences,
  1805. DWORD dwNumStringReferences
  1806. )
  1807. {
  1808. DWORD dwError = 0;
  1809. DWORD i = 0;
  1810. LPWSTR pMem = NULL;
  1811. LPWSTR pszTemp = NULL;
  1812. DWORD dwSize = 0;
  1813. if (!ppszStringReferences) {
  1814. dwError = ERROR_INVALID_PARAMETER;
  1815. BAIL_ON_WIN32_ERROR(dwError);
  1816. }
  1817. for (i = 0; i < dwNumStringReferences; i++) {
  1818. dwSize += wcslen (*(ppszStringReferences + i));
  1819. dwSize ++;
  1820. }
  1821. dwSize ++;
  1822. pMem = (LPWSTR) AllocPolMem(dwSize*sizeof(WCHAR));
  1823. if (!pMem) {
  1824. dwError = ERROR_OUTOFMEMORY;
  1825. BAIL_ON_WIN32_ERROR(dwError);
  1826. }
  1827. pszTemp = pMem;
  1828. for (i = 0; i < dwNumStringReferences; i++) {
  1829. memcpy(pszTemp, *(ppszStringReferences + i), wcslen(*(ppszStringReferences + i))*sizeof(WCHAR));
  1830. pszTemp += wcslen(pszTemp) + 1;
  1831. }
  1832. //*pszTemp = L'\0';
  1833. dwError = RegSetValueExW(
  1834. hRegKey,
  1835. pszValueName,
  1836. 0,
  1837. REG_MULTI_SZ,
  1838. (LPBYTE)pMem,
  1839. dwSize * sizeof(WCHAR)
  1840. );
  1841. BAIL_ON_WIN32_ERROR(dwError);
  1842. error:
  1843. if (pMem) {
  1844. FreePolMem(pMem);
  1845. }
  1846. return(dwError);
  1847. }
  1848. DWORD
  1849. CopyFilterDSToRegString(
  1850. LPWSTR pszFilterDN,
  1851. LPWSTR * ppszFilterName
  1852. )
  1853. {
  1854. DWORD dwError = 0;
  1855. WCHAR szCommonName[MAX_PATH];
  1856. LPWSTR pszGuidName = NULL;
  1857. LPWSTR pszFilterName = NULL;
  1858. dwError = ComputePrelimCN(
  1859. pszFilterDN,
  1860. szCommonName
  1861. );
  1862. BAIL_ON_WIN32_ERROR(dwError);
  1863. dwError = ComputeGUIDName(
  1864. szCommonName,
  1865. &pszGuidName
  1866. );
  1867. BAIL_ON_WIN32_ERROR(dwError);
  1868. pszFilterName = AllocPolStr(pszGuidName);
  1869. if (!pszFilterName) {
  1870. dwError = ERROR_OUTOFMEMORY;
  1871. BAIL_ON_WIN32_ERROR(dwError);
  1872. }
  1873. *ppszFilterName = pszFilterName;
  1874. return(dwError);
  1875. error:
  1876. *ppszFilterName = NULL;
  1877. return(dwError);
  1878. }
  1879. DWORD
  1880. CopyNFADSToRegString(
  1881. LPWSTR pszNFADN,
  1882. LPWSTR * ppszNFAName
  1883. )
  1884. {
  1885. DWORD dwError = 0;
  1886. WCHAR szCommonName[MAX_PATH];
  1887. LPWSTR pszGuidName = NULL;
  1888. LPWSTR pszNFAName = NULL;
  1889. dwError = ComputePrelimCN(
  1890. pszNFADN,
  1891. szCommonName
  1892. );
  1893. BAIL_ON_WIN32_ERROR(dwError);
  1894. dwError = ComputeGUIDName(
  1895. szCommonName,
  1896. &pszGuidName
  1897. );
  1898. BAIL_ON_WIN32_ERROR(dwError);
  1899. pszNFAName = AllocPolStr(pszGuidName);
  1900. if (!pszNFAName) {
  1901. dwError = ERROR_OUTOFMEMORY;
  1902. BAIL_ON_WIN32_ERROR(dwError);
  1903. }
  1904. *ppszNFAName = pszNFAName;
  1905. return(dwError);
  1906. error:
  1907. *ppszNFAName = NULL;
  1908. return(dwError);
  1909. }
  1910. DWORD
  1911. CopyNegPolDSToRegString(
  1912. LPWSTR pszNegPolDN,
  1913. LPWSTR * ppszNegPolName
  1914. )
  1915. {
  1916. DWORD dwError = 0;
  1917. WCHAR szCommonName[MAX_PATH];
  1918. LPWSTR pszGuidName = NULL;
  1919. LPWSTR pszNegPolName = NULL;
  1920. dwError = ComputePrelimCN(
  1921. pszNegPolDN,
  1922. szCommonName
  1923. );
  1924. BAIL_ON_WIN32_ERROR(dwError);
  1925. dwError = ComputeGUIDName(
  1926. szCommonName,
  1927. &pszGuidName
  1928. );
  1929. BAIL_ON_WIN32_ERROR(dwError);
  1930. pszNegPolName = AllocPolStr(pszGuidName);
  1931. if (!pszNegPolName) {
  1932. dwError = ERROR_OUTOFMEMORY;
  1933. BAIL_ON_WIN32_ERROR(dwError);
  1934. }
  1935. *ppszNegPolName = pszNegPolName;
  1936. return(dwError);
  1937. error:
  1938. *ppszNegPolName = NULL;
  1939. return(dwError);
  1940. }
  1941. DWORD
  1942. CopyPolicyDSToRegString(
  1943. LPWSTR pszPolicyDN,
  1944. LPWSTR * ppszPolicyName
  1945. )
  1946. {
  1947. DWORD dwError = 0;
  1948. WCHAR szCommonName[MAX_PATH];
  1949. LPWSTR pszGuidName = NULL;
  1950. LPWSTR pszPolicyName = NULL;
  1951. dwError = ComputePrelimCN(
  1952. pszPolicyDN,
  1953. szCommonName
  1954. );
  1955. BAIL_ON_WIN32_ERROR(dwError);
  1956. dwError = ComputeGUIDName(
  1957. szCommonName,
  1958. &pszGuidName
  1959. );
  1960. BAIL_ON_WIN32_ERROR(dwError);
  1961. pszPolicyName = AllocPolStr(pszGuidName);
  1962. if (!pszPolicyName) {
  1963. dwError = ERROR_OUTOFMEMORY;
  1964. BAIL_ON_WIN32_ERROR(dwError);
  1965. }
  1966. *ppszPolicyName = pszPolicyName;
  1967. return(dwError);
  1968. error:
  1969. *ppszPolicyName = NULL;
  1970. return(dwError);
  1971. }
  1972. DWORD
  1973. CopyISAKMPDSToRegString(
  1974. LPWSTR pszISAKMPDN,
  1975. LPWSTR * ppszISAKMPName
  1976. )
  1977. {
  1978. DWORD dwError = 0;
  1979. WCHAR szCommonName[MAX_PATH];
  1980. LPWSTR pszGuidName = NULL;
  1981. LPWSTR pszISAKMPName = NULL;
  1982. dwError = ComputePrelimCN(
  1983. pszISAKMPDN,
  1984. szCommonName
  1985. );
  1986. BAIL_ON_WIN32_ERROR(dwError);
  1987. dwError = ComputeGUIDName(
  1988. szCommonName,
  1989. &pszGuidName
  1990. );
  1991. BAIL_ON_WIN32_ERROR(dwError);
  1992. pszISAKMPName = AllocPolStr(pszGuidName);
  1993. if (!pszISAKMPName) {
  1994. dwError = ERROR_OUTOFMEMORY;
  1995. BAIL_ON_WIN32_ERROR(dwError);
  1996. }
  1997. *ppszISAKMPName = pszISAKMPName;
  1998. return(dwError);
  1999. error:
  2000. *ppszISAKMPName = NULL;
  2001. return(dwError);
  2002. }