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.

1160 lines
26 KiB

  1. //----------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 2000.
  5. //
  6. // File: refer-r.c
  7. //
  8. // Contents: Reference management for registry.
  9. //
  10. //
  11. // History: KrishnaG.
  12. // AbhisheV.
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "precomp.h"
  16. //
  17. // Policy Object References
  18. //
  19. DWORD
  20. RegAddNFAReferenceToPolicyObject(
  21. HKEY hRegistryKey,
  22. LPWSTR pszIpsecPolicyName,
  23. LPWSTR pszIpsecNFADistinguishedName
  24. )
  25. {
  26. DWORD dwError = ERROR_SUCCESS;
  27. HKEY hKey = NULL;
  28. LPBYTE pValueData = NULL;
  29. LPBYTE pNewValueData = NULL;
  30. DWORD dwSize = 0;
  31. DWORD dwNewSize = 0;
  32. dwError = RegOpenKeyExW(
  33. hRegistryKey,
  34. pszIpsecPolicyName,
  35. 0,
  36. KEY_ALL_ACCESS,
  37. &hKey
  38. );
  39. BAIL_ON_WIN32_ERROR(dwError);
  40. dwError = RegstoreQueryValue(
  41. hKey,
  42. L"ipsecNFAReference",
  43. REG_MULTI_SZ,
  44. &pValueData,
  45. &dwSize
  46. );
  47. // BAIL_ON_WIN32_ERROR(dwError);
  48. dwError = AddValueToMultiSz(
  49. pValueData,
  50. dwSize,
  51. pszIpsecNFADistinguishedName,
  52. &pNewValueData,
  53. &dwNewSize
  54. );
  55. BAIL_ON_WIN32_ERROR(dwError);
  56. dwError = RegSetValueExW(
  57. hKey,
  58. L"ipsecNFAReference",
  59. 0,
  60. REG_MULTI_SZ,
  61. (LPBYTE)pNewValueData,
  62. dwNewSize
  63. );
  64. BAIL_ON_WIN32_ERROR(dwError);
  65. error:
  66. if (hKey) {
  67. RegCloseKey(hKey);
  68. }
  69. if (pValueData) {
  70. FreePolMem(pValueData);
  71. }
  72. if (pNewValueData) {
  73. FreePolMem(pNewValueData);
  74. }
  75. return(dwError);
  76. }
  77. DWORD
  78. RegRemoveNFAReferenceFromPolicyObject(
  79. HKEY hRegistryKey,
  80. LPWSTR pszIpsecPolicyName,
  81. LPWSTR pszIpsecNFAName
  82. )
  83. {
  84. DWORD dwError = ERROR_SUCCESS;
  85. HKEY hKey = NULL;
  86. LPBYTE pValueData = NULL;
  87. LPBYTE pNewValueData = NULL;
  88. DWORD dwSize = 0;
  89. DWORD dwNewSize = 0;
  90. dwError = RegOpenKeyExW(
  91. hRegistryKey,
  92. pszIpsecPolicyName,
  93. 0,
  94. KEY_ALL_ACCESS,
  95. &hKey
  96. );
  97. BAIL_ON_WIN32_ERROR(dwError);
  98. dwError = RegstoreQueryValue(
  99. hKey,
  100. L"ipsecNFAReference",
  101. REG_MULTI_SZ,
  102. &pValueData,
  103. &dwSize
  104. );
  105. BAIL_ON_WIN32_ERROR(dwError);
  106. dwError = DeleteValueFromMultiSz(
  107. pValueData,
  108. dwSize,
  109. pszIpsecNFAName,
  110. &pNewValueData,
  111. &dwNewSize
  112. );
  113. BAIL_ON_WIN32_ERROR(dwError);
  114. if (pNewValueData && *pNewValueData) {
  115. dwError = RegSetValueExW(
  116. hKey,
  117. L"ipsecNFAReference",
  118. 0,
  119. REG_MULTI_SZ,
  120. (LPBYTE)pNewValueData,
  121. dwNewSize
  122. );
  123. BAIL_ON_WIN32_ERROR(dwError);
  124. }
  125. else {
  126. dwError = RegDeleteValueW(
  127. hKey,
  128. L"ipsecNFAReference"
  129. );
  130. BAIL_ON_WIN32_ERROR(dwError);
  131. }
  132. error:
  133. if (hKey) {
  134. RegCloseKey(hKey);
  135. }
  136. if (pValueData) {
  137. FreePolMem(pValueData);
  138. }
  139. if (pNewValueData) {
  140. FreePolMem(pNewValueData);
  141. }
  142. return(dwError);
  143. }
  144. //
  145. // NFA Object References
  146. //
  147. DWORD
  148. RegAddPolicyReferenceToNFAObject(
  149. HKEY hRegistryKey,
  150. LPWSTR pszIpsecNFAName,
  151. LPWSTR pszIpsecPolicyName
  152. )
  153. {
  154. DWORD dwError = ERROR_SUCCESS;
  155. HKEY hKey = NULL;
  156. LPBYTE pValueData = NULL;
  157. LPBYTE pNewValueData = NULL;
  158. DWORD dwSize = 0;
  159. DWORD dwNewSize = 0;
  160. dwError = RegOpenKeyExW(
  161. hRegistryKey,
  162. pszIpsecNFAName,
  163. 0,
  164. KEY_ALL_ACCESS,
  165. &hKey
  166. );
  167. BAIL_ON_WIN32_ERROR(dwError);
  168. dwError = RegstoreQueryValue(
  169. hKey,
  170. L"ipsecOwnersReference",
  171. REG_MULTI_SZ,
  172. &pValueData,
  173. &dwSize
  174. );
  175. // BAIL_ON_WIN32_ERROR(dwError);
  176. dwError = AddValueToMultiSz(
  177. pValueData,
  178. dwSize,
  179. pszIpsecPolicyName,
  180. &pNewValueData,
  181. &dwNewSize
  182. );
  183. BAIL_ON_WIN32_ERROR(dwError);
  184. dwError = RegSetValueExW(
  185. hKey,
  186. L"ipsecOwnersReference",
  187. 0,
  188. REG_MULTI_SZ,
  189. (LPBYTE)pNewValueData,
  190. dwNewSize
  191. );
  192. BAIL_ON_WIN32_ERROR(dwError);
  193. error:
  194. if (hKey) {
  195. RegCloseKey(hKey);
  196. }
  197. if (pValueData) {
  198. FreePolMem(pValueData);
  199. }
  200. if (pNewValueData) {
  201. FreePolMem(pNewValueData);
  202. }
  203. return(dwError);
  204. }
  205. DWORD
  206. RegAddNegPolReferenceToNFAObject(
  207. HKEY hRegistryKey,
  208. LPWSTR pszIpsecNFAName,
  209. LPWSTR pszIpsecNegPolName
  210. )
  211. {
  212. DWORD dwError = ERROR_SUCCESS;
  213. HKEY hKey = NULL;
  214. dwError = RegOpenKeyExW(
  215. hRegistryKey,
  216. pszIpsecNFAName,
  217. 0,
  218. KEY_ALL_ACCESS,
  219. &hKey
  220. );
  221. BAIL_ON_WIN32_ERROR(dwError);
  222. dwError = RegSetValueExW(
  223. hKey,
  224. L"ipsecNegotiationPolicyReference",
  225. 0,
  226. REG_SZ,
  227. (LPBYTE)pszIpsecNegPolName,
  228. (wcslen(pszIpsecNegPolName) + 1)*sizeof(WCHAR)
  229. );
  230. BAIL_ON_WIN32_ERROR(dwError);
  231. error:
  232. if (hKey) {
  233. RegCloseKey(hKey);
  234. }
  235. return(dwError);
  236. }
  237. DWORD
  238. RegUpdateNegPolReferenceInNFAObject(
  239. HKEY hRegistryKey,
  240. LPWSTR pszIpsecNFAName,
  241. LPWSTR pszOldIpsecNegPolName,
  242. LPWSTR pszNewIpsecNegPolName
  243. )
  244. {
  245. DWORD dwError = ERROR_SUCCESS;
  246. HKEY hKey = NULL;
  247. dwError = RegOpenKeyExW(
  248. hRegistryKey,
  249. pszIpsecNFAName,
  250. 0,
  251. KEY_ALL_ACCESS,
  252. &hKey
  253. );
  254. BAIL_ON_WIN32_ERROR(dwError);
  255. dwError = RegSetValueExW(
  256. hKey,
  257. L"ipsecNegotiationPolicyReference",
  258. 0,
  259. REG_SZ,
  260. (LPBYTE)pszNewIpsecNegPolName,
  261. (wcslen(pszNewIpsecNegPolName) + 1)*sizeof(WCHAR)
  262. );
  263. BAIL_ON_WIN32_ERROR(dwError);
  264. error:
  265. if (hKey) {
  266. RegCloseKey(hKey);
  267. }
  268. return(dwError);
  269. }
  270. DWORD
  271. RegAddFilterReferenceToNFAObject(
  272. HKEY hRegistryKey,
  273. LPWSTR pszIpsecNFAName,
  274. LPWSTR pszIpsecFilterName
  275. )
  276. {
  277. DWORD dwError = ERROR_SUCCESS;
  278. HKEY hKey = NULL;
  279. LPBYTE pMem = NULL;
  280. pMem = AllocPolMem(
  281. (wcslen(pszIpsecFilterName) + 1 + 1)*sizeof(WCHAR)
  282. );
  283. if (!pMem) {
  284. dwError = ERROR_OUTOFMEMORY;
  285. BAIL_ON_WIN32_ERROR(dwError);
  286. }
  287. memcpy(
  288. pMem,
  289. (LPBYTE) pszIpsecFilterName,
  290. (wcslen(pszIpsecFilterName) + 1)*sizeof(WCHAR)
  291. );
  292. dwError = RegOpenKeyExW(
  293. hRegistryKey,
  294. pszIpsecNFAName,
  295. 0,
  296. KEY_ALL_ACCESS,
  297. &hKey
  298. );
  299. BAIL_ON_WIN32_ERROR(dwError);
  300. dwError = RegSetValueExW(
  301. hKey,
  302. L"ipsecFilterReference",
  303. 0,
  304. REG_MULTI_SZ,
  305. pMem,
  306. (wcslen(pszIpsecFilterName) + 1 + 1)*sizeof(WCHAR)
  307. );
  308. BAIL_ON_WIN32_ERROR(dwError);
  309. error:
  310. if (pMem) {
  311. FreePolMem(pMem);
  312. }
  313. if (hKey) {
  314. RegCloseKey(hKey);
  315. }
  316. return(dwError);
  317. }
  318. DWORD
  319. RegUpdateFilterReferenceInNFAObject(
  320. HKEY hRegistryKey,
  321. LPWSTR pszIpsecNFAName,
  322. LPWSTR pszOldIpsecFilterName,
  323. LPWSTR pszNewIpsecFilterName
  324. )
  325. {
  326. DWORD dwError = ERROR_SUCCESS;
  327. HKEY hKey = NULL;
  328. LPBYTE pMem = NULL;
  329. pMem = AllocPolMem(
  330. (wcslen(pszNewIpsecFilterName) + 1 + 1)*sizeof(WCHAR)
  331. );
  332. if (!pMem) {
  333. dwError = ERROR_OUTOFMEMORY;
  334. BAIL_ON_WIN32_ERROR(dwError);
  335. }
  336. memcpy(
  337. pMem,
  338. (LPBYTE) pszNewIpsecFilterName,
  339. (wcslen(pszNewIpsecFilterName) + 1)*sizeof(WCHAR)
  340. );
  341. dwError = RegOpenKeyExW(
  342. hRegistryKey,
  343. pszIpsecNFAName,
  344. 0,
  345. KEY_ALL_ACCESS,
  346. &hKey
  347. );
  348. BAIL_ON_WIN32_ERROR(dwError);
  349. dwError = RegSetValueExW(
  350. hKey,
  351. L"ipsecFilterReference",
  352. 0,
  353. REG_MULTI_SZ,
  354. pMem,
  355. (wcslen(pszNewIpsecFilterName) + 1 + 1)*sizeof(WCHAR)
  356. );
  357. BAIL_ON_WIN32_ERROR(dwError);
  358. error:
  359. if (pMem) {
  360. FreePolMem(pMem);
  361. }
  362. if (hKey) {
  363. RegCloseKey(hKey);
  364. }
  365. return(dwError);
  366. }
  367. //
  368. // Filter Object References
  369. //
  370. DWORD
  371. RegAddNFAReferenceToFilterObject(
  372. HKEY hRegistryKey,
  373. LPWSTR pszIpsecFilterName,
  374. LPWSTR pszIpsecNFAName
  375. )
  376. {
  377. DWORD dwError = ERROR_SUCCESS;
  378. HKEY hKey = NULL;
  379. LPBYTE pValueData = NULL;
  380. LPBYTE pNewValueData = NULL;
  381. DWORD dwSize = 0;
  382. DWORD dwNewSize = 0;
  383. dwError = RegOpenKeyExW(
  384. hRegistryKey,
  385. pszIpsecFilterName,
  386. 0,
  387. KEY_ALL_ACCESS,
  388. &hKey
  389. );
  390. BAIL_ON_WIN32_ERROR(dwError);
  391. dwError = RegstoreQueryValue(
  392. hKey,
  393. L"ipsecOwnersReference",
  394. REG_MULTI_SZ,
  395. &pValueData,
  396. &dwSize
  397. );
  398. // BAIL_ON_WIN32_ERROR(dwError);
  399. dwError = AddValueToMultiSz(
  400. pValueData,
  401. dwSize,
  402. pszIpsecNFAName,
  403. &pNewValueData,
  404. &dwNewSize
  405. );
  406. BAIL_ON_WIN32_ERROR(dwError);
  407. dwError = RegSetValueExW(
  408. hKey,
  409. L"ipsecOwnersReference",
  410. 0,
  411. REG_MULTI_SZ,
  412. (LPBYTE)pNewValueData,
  413. dwNewSize
  414. );
  415. BAIL_ON_WIN32_ERROR(dwError);
  416. error:
  417. if (hKey) {
  418. RegCloseKey(hKey);
  419. }
  420. if (pValueData) {
  421. FreePolMem(pValueData);
  422. }
  423. if (pNewValueData) {
  424. FreePolMem(pNewValueData);
  425. }
  426. return(dwError);
  427. }
  428. DWORD
  429. RegDeleteNFAReferenceInFilterObject(
  430. HKEY hRegistryKey,
  431. LPWSTR pszIpsecFilterName,
  432. LPWSTR pszIpsecNFAName
  433. )
  434. {
  435. DWORD dwError = ERROR_SUCCESS;
  436. HKEY hKey = NULL;
  437. LPBYTE pValueData = NULL;
  438. LPBYTE pNewValueData = NULL;
  439. DWORD dwSize = 0;
  440. DWORD dwNewSize = 0;
  441. dwError = RegOpenKeyExW(
  442. hRegistryKey,
  443. pszIpsecFilterName,
  444. 0,
  445. KEY_ALL_ACCESS,
  446. &hKey
  447. );
  448. BAIL_ON_WIN32_ERROR(dwError);
  449. dwError = RegstoreQueryValue(
  450. hKey,
  451. L"ipsecOwnersReference",
  452. REG_MULTI_SZ,
  453. &pValueData,
  454. &dwSize
  455. );
  456. BAIL_ON_WIN32_ERROR(dwError);
  457. dwError = DeleteValueFromMultiSz(
  458. pValueData,
  459. dwSize,
  460. pszIpsecNFAName,
  461. &pNewValueData,
  462. &dwNewSize
  463. );
  464. BAIL_ON_WIN32_ERROR(dwError);
  465. if (pNewValueData && *pNewValueData) {
  466. dwError = RegSetValueExW(
  467. hKey,
  468. L"ipsecOwnersReference",
  469. 0,
  470. REG_MULTI_SZ,
  471. (LPBYTE)pNewValueData,
  472. dwNewSize
  473. );
  474. BAIL_ON_WIN32_ERROR(dwError);
  475. }
  476. else {
  477. dwError = RegDeleteValueW(
  478. hKey,
  479. L"ipsecOwnersReference"
  480. );
  481. BAIL_ON_WIN32_ERROR(dwError);
  482. }
  483. error:
  484. if (hKey) {
  485. RegCloseKey(hKey);
  486. }
  487. if (pValueData) {
  488. FreePolMem(pValueData);
  489. }
  490. if (pNewValueData) {
  491. FreePolMem(pNewValueData);
  492. }
  493. return(dwError);
  494. }
  495. //
  496. // NegPol Object References
  497. //
  498. DWORD
  499. RegAddNFAReferenceToNegPolObject(
  500. HKEY hRegistryKey,
  501. LPWSTR pszIpsecNegPolName,
  502. LPWSTR pszIpsecNFAName
  503. )
  504. {
  505. DWORD dwError = ERROR_SUCCESS;
  506. HKEY hKey = NULL;
  507. LPBYTE pValueData = NULL;
  508. LPBYTE pNewValueData = NULL;
  509. DWORD dwSize = 0;
  510. DWORD dwNewSize = 0;
  511. dwError = RegOpenKeyExW(
  512. hRegistryKey,
  513. pszIpsecNegPolName,
  514. 0,
  515. KEY_ALL_ACCESS,
  516. &hKey
  517. );
  518. BAIL_ON_WIN32_ERROR(dwError);
  519. dwError = RegstoreQueryValue(
  520. hKey,
  521. L"ipsecOwnersReference",
  522. REG_MULTI_SZ,
  523. &pValueData,
  524. &dwSize
  525. );
  526. // BAIL_ON_WIN32_ERROR(dwError);
  527. dwError = AddValueToMultiSz(
  528. pValueData,
  529. dwSize,
  530. pszIpsecNFAName,
  531. &pNewValueData,
  532. &dwNewSize
  533. );
  534. BAIL_ON_WIN32_ERROR(dwError);
  535. dwError = RegSetValueExW(
  536. hKey,
  537. L"ipsecOwnersReference",
  538. 0,
  539. REG_MULTI_SZ,
  540. (LPBYTE)pNewValueData,
  541. dwNewSize
  542. );
  543. BAIL_ON_WIN32_ERROR(dwError);
  544. error:
  545. if (hKey) {
  546. RegCloseKey(hKey);
  547. }
  548. if (pValueData) {
  549. FreePolMem(pValueData);
  550. }
  551. if (pNewValueData) {
  552. FreePolMem(pNewValueData);
  553. }
  554. return(dwError);
  555. }
  556. DWORD
  557. RegDeleteNFAReferenceInNegPolObject(
  558. HKEY hRegistryKey,
  559. LPWSTR pszIpsecNegPolName,
  560. LPWSTR pszIpsecNFAName
  561. )
  562. {
  563. DWORD dwError = ERROR_SUCCESS;
  564. HKEY hKey = NULL;
  565. LPBYTE pValueData = NULL;
  566. LPBYTE pNewValueData = NULL;
  567. DWORD dwSize = 0;
  568. DWORD dwNewSize = 0;
  569. dwError = RegOpenKeyExW(
  570. hRegistryKey,
  571. pszIpsecNegPolName,
  572. 0,
  573. KEY_ALL_ACCESS,
  574. &hKey
  575. );
  576. BAIL_ON_WIN32_ERROR(dwError);
  577. dwError = RegstoreQueryValue(
  578. hKey,
  579. L"ipsecOwnersReference",
  580. REG_MULTI_SZ,
  581. &pValueData,
  582. &dwSize
  583. );
  584. BAIL_ON_WIN32_ERROR(dwError);
  585. dwError = DeleteValueFromMultiSz(
  586. pValueData,
  587. dwSize,
  588. pszIpsecNFAName,
  589. &pNewValueData,
  590. &dwNewSize
  591. );
  592. BAIL_ON_WIN32_ERROR(dwError);
  593. if (pNewValueData && *pNewValueData) {
  594. dwError = RegSetValueExW(
  595. hKey,
  596. L"ipsecOwnersReference",
  597. 0,
  598. REG_MULTI_SZ,
  599. (LPBYTE)pNewValueData,
  600. dwNewSize
  601. );
  602. BAIL_ON_WIN32_ERROR(dwError);
  603. }
  604. else {
  605. dwError = RegDeleteValueW(
  606. hKey,
  607. L"ipsecOwnersReference"
  608. );
  609. BAIL_ON_WIN32_ERROR(dwError);
  610. }
  611. error:
  612. if (hKey) {
  613. RegCloseKey(hKey);
  614. }
  615. if (pValueData) {
  616. FreePolMem(pValueData);
  617. }
  618. if (pNewValueData) {
  619. FreePolMem(pNewValueData);
  620. }
  621. return(dwError);
  622. }
  623. DWORD
  624. AddValueToMultiSz(
  625. LPBYTE pValueData,
  626. DWORD dwSize,
  627. LPWSTR pszValuetoAdd,
  628. LPBYTE * ppNewValueData,
  629. DWORD * pdwNewSize
  630. )
  631. {
  632. DWORD dwError = ERROR_SUCCESS;
  633. LPBYTE pNewValueData = NULL;
  634. LPBYTE pNewPtr = NULL;
  635. DWORD dwLen = 0;
  636. DWORD dwAddSize = 0;
  637. DWORD dwNewSize = 0;
  638. BOOL bFound = FALSE;
  639. LPWSTR pszTemp = NULL;
  640. *ppNewValueData = NULL;
  641. *pdwNewSize = 0;
  642. dwLen = wcslen(pszValuetoAdd);
  643. dwLen ++;
  644. dwAddSize = dwLen*sizeof(WCHAR);
  645. if (pValueData) {
  646. pszTemp = (LPWSTR) pValueData;
  647. while (*pszTemp != L'\0') {
  648. if (!_wcsicmp(pszTemp, pszValuetoAdd)) {
  649. bFound = TRUE;
  650. break;
  651. }
  652. pszTemp += wcslen(pszTemp) + 1;
  653. }
  654. if (bFound) {
  655. dwNewSize = dwSize;
  656. }
  657. else {
  658. dwNewSize = dwSize + dwAddSize;
  659. }
  660. }
  661. else {
  662. dwNewSize = dwAddSize + sizeof(WCHAR);
  663. }
  664. pNewValueData = (LPBYTE)AllocPolMem(dwNewSize);
  665. if (!pNewValueData) {
  666. dwError = ERROR_OUTOFMEMORY;
  667. BAIL_ON_WIN32_ERROR(dwError);
  668. }
  669. if (!bFound) {
  670. wcscpy((LPWSTR)pNewValueData, pszValuetoAdd);
  671. pNewPtr = pNewValueData + dwAddSize;
  672. }
  673. else {
  674. pNewPtr = pNewValueData;
  675. }
  676. if (pValueData) {
  677. memcpy(pNewPtr, pValueData, dwSize);
  678. }
  679. *ppNewValueData = pNewValueData;
  680. *pdwNewSize = dwNewSize;
  681. error:
  682. return(dwError);
  683. }
  684. DWORD
  685. DeleteValueFromMultiSz(
  686. LPBYTE pValueData,
  687. DWORD dwSize,
  688. LPWSTR pszValuetoDel,
  689. LPBYTE * ppNewValueData,
  690. DWORD * pdwNewSize
  691. )
  692. {
  693. DWORD dwError = ERROR_SUCCESS;
  694. LPBYTE pNewValueData = NULL;
  695. LPBYTE pNew = NULL;
  696. DWORD dwLen = 0;
  697. DWORD dwDelSize = 0;
  698. DWORD dwNewSize = 0;
  699. BOOL bFound = FALSE;
  700. LPWSTR pszTemp = NULL;
  701. *ppNewValueData = NULL;
  702. *pdwNewSize = 0;
  703. if (!pValueData || !dwSize) {
  704. return (ERROR_INVALID_PARAMETER);
  705. }
  706. pszTemp = (LPWSTR) pValueData;
  707. while (*pszTemp != L'\0') {
  708. if (!_wcsicmp(pszTemp, pszValuetoDel)) {
  709. bFound = TRUE;
  710. break;
  711. }
  712. pszTemp += wcslen(pszTemp) + 1;
  713. }
  714. if (!bFound) {
  715. return (ERROR_INVALID_PARAMETER);
  716. }
  717. dwLen = wcslen(pszValuetoDel);
  718. dwLen ++;
  719. dwDelSize = dwLen*sizeof(WCHAR);
  720. if (dwSize == dwDelSize) {
  721. return (ERROR_SUCCESS);
  722. }
  723. dwNewSize = dwSize - dwDelSize;
  724. pNewValueData = (LPBYTE)AllocPolMem(dwNewSize);
  725. if (!pNewValueData) {
  726. dwError = ERROR_OUTOFMEMORY;
  727. BAIL_ON_WIN32_ERROR(dwError);
  728. }
  729. pszTemp = (LPWSTR) pValueData;
  730. pNew = pNewValueData;
  731. while (*pszTemp != L'\0') {
  732. if (!_wcsicmp(pszTemp, pszValuetoDel)) {
  733. pszTemp += wcslen(pszTemp) + 1;
  734. }
  735. else {
  736. memcpy(pNew, (LPBYTE) pszTemp, (wcslen(pszTemp)+1)*sizeof(WCHAR));
  737. pNew += (wcslen(pszTemp)+1)*sizeof(WCHAR);
  738. pszTemp += wcslen(pszTemp) + 1;
  739. }
  740. }
  741. *ppNewValueData = pNewValueData;
  742. *pdwNewSize = dwNewSize;
  743. error:
  744. return(dwError);
  745. }
  746. DWORD
  747. RegDelFilterRefValueOfNFAObject(
  748. HKEY hRegistryKey,
  749. LPWSTR pszIpsecNFAName
  750. )
  751. {
  752. DWORD dwError = ERROR_SUCCESS;
  753. HKEY hKey = NULL;
  754. dwError = RegOpenKeyExW(
  755. hRegistryKey,
  756. pszIpsecNFAName,
  757. 0,
  758. KEY_ALL_ACCESS,
  759. &hKey
  760. );
  761. BAIL_ON_WIN32_ERROR(dwError);
  762. dwError = RegDeleteValueW(
  763. hKey,
  764. L"ipsecFilterReference"
  765. );
  766. BAIL_ON_WIN32_ERROR(dwError);
  767. error:
  768. if (hKey) {
  769. RegCloseKey(hKey);
  770. }
  771. return(dwError);
  772. }
  773. //
  774. // ISAKMP Object References.
  775. //
  776. DWORD
  777. RegAddPolicyReferenceToISAKMPObject(
  778. HKEY hRegistryKey,
  779. LPWSTR pszIpsecISAKMPName,
  780. LPWSTR pszIpsecPolicyDistinguishedName
  781. )
  782. {
  783. DWORD dwError = ERROR_SUCCESS;
  784. HKEY hKey = NULL;
  785. LPBYTE pValueData = NULL;
  786. LPBYTE pNewValueData = NULL;
  787. DWORD dwSize = 0;
  788. DWORD dwNewSize = 0;
  789. dwError = RegOpenKeyExW(
  790. hRegistryKey,
  791. pszIpsecISAKMPName,
  792. 0,
  793. KEY_ALL_ACCESS,
  794. &hKey
  795. );
  796. BAIL_ON_WIN32_ERROR(dwError);
  797. dwError = RegstoreQueryValue(
  798. hKey,
  799. L"ipsecOwnersReference",
  800. REG_MULTI_SZ,
  801. &pValueData,
  802. &dwSize
  803. );
  804. // BAIL_ON_WIN32_ERROR(dwError);
  805. dwError = AddValueToMultiSz(
  806. pValueData,
  807. dwSize,
  808. pszIpsecPolicyDistinguishedName,
  809. &pNewValueData,
  810. &dwNewSize
  811. );
  812. BAIL_ON_WIN32_ERROR(dwError);
  813. dwError = RegSetValueExW(
  814. hKey,
  815. L"ipsecOwnersReference",
  816. 0,
  817. REG_MULTI_SZ,
  818. (LPBYTE)pNewValueData,
  819. dwNewSize
  820. );
  821. BAIL_ON_WIN32_ERROR(dwError);
  822. error:
  823. if (hKey) {
  824. RegCloseKey(hKey);
  825. }
  826. if (pValueData) {
  827. FreePolMem(pValueData);
  828. }
  829. if (pNewValueData) {
  830. FreePolMem(pNewValueData);
  831. }
  832. return(dwError);
  833. }
  834. DWORD
  835. RegRemovePolicyReferenceFromISAKMPObject(
  836. HKEY hRegistryKey,
  837. LPWSTR pszIpsecISAKMPName,
  838. LPWSTR pszIpsecPolicyName
  839. )
  840. {
  841. DWORD dwError = ERROR_SUCCESS;
  842. HKEY hKey = NULL;
  843. LPBYTE pValueData = NULL;
  844. LPBYTE pNewValueData = NULL;
  845. DWORD dwSize = 0;
  846. DWORD dwNewSize = 0;
  847. dwError = RegOpenKeyExW(
  848. hRegistryKey,
  849. pszIpsecISAKMPName,
  850. 0,
  851. KEY_ALL_ACCESS,
  852. &hKey
  853. );
  854. BAIL_ON_WIN32_ERROR(dwError);
  855. dwError = RegstoreQueryValue(
  856. hKey,
  857. L"ipsecOwnersReference",
  858. REG_MULTI_SZ,
  859. &pValueData,
  860. &dwSize
  861. );
  862. BAIL_ON_WIN32_ERROR(dwError);
  863. dwError = DeleteValueFromMultiSz(
  864. pValueData,
  865. dwSize,
  866. pszIpsecPolicyName,
  867. &pNewValueData,
  868. &dwNewSize
  869. );
  870. BAIL_ON_WIN32_ERROR(dwError);
  871. if (pNewValueData && *pNewValueData) {
  872. dwError = RegSetValueExW(
  873. hKey,
  874. L"ipsecOwnersReference",
  875. 0,
  876. REG_MULTI_SZ,
  877. (LPBYTE)pNewValueData,
  878. dwNewSize
  879. );
  880. BAIL_ON_WIN32_ERROR(dwError);
  881. }
  882. else {
  883. dwError = RegDeleteValueW(
  884. hKey,
  885. L"ipsecOwnersReference"
  886. );
  887. BAIL_ON_WIN32_ERROR(dwError);
  888. }
  889. error:
  890. if (hKey) {
  891. RegCloseKey(hKey);
  892. }
  893. if (pValueData) {
  894. FreePolMem(pValueData);
  895. }
  896. if (pNewValueData) {
  897. FreePolMem(pNewValueData);
  898. }
  899. return(dwError);
  900. }
  901. //
  902. // Policy Object Reference to the ISAKMP object.
  903. //
  904. DWORD
  905. RegAddISAKMPReferenceToPolicyObject(
  906. HKEY hRegistryKey,
  907. LPWSTR pszIpsecPolicyName,
  908. LPWSTR pszIpsecISAKMPName
  909. )
  910. {
  911. DWORD dwError = ERROR_SUCCESS;
  912. HKEY hKey = NULL;
  913. dwError = RegOpenKeyExW(
  914. hRegistryKey,
  915. pszIpsecPolicyName,
  916. 0,
  917. KEY_ALL_ACCESS,
  918. &hKey
  919. );
  920. BAIL_ON_WIN32_ERROR(dwError);
  921. dwError = RegSetValueExW(
  922. hKey,
  923. L"ipsecISAKMPReference",
  924. 0,
  925. REG_SZ,
  926. (LPBYTE)pszIpsecISAKMPName,
  927. (wcslen(pszIpsecISAKMPName) + 1)*sizeof(WCHAR)
  928. );
  929. BAIL_ON_WIN32_ERROR(dwError);
  930. error:
  931. if (hKey) {
  932. RegCloseKey(hKey);
  933. }
  934. return(dwError);
  935. }
  936. DWORD
  937. RegUpdateISAKMPReferenceInPolicyObject(
  938. HKEY hRegistryKey,
  939. LPWSTR pszIpsecPolicyName,
  940. LPWSTR pszOldIpsecISAKMPName,
  941. LPWSTR pszNewIpsecISAKMPName
  942. )
  943. {
  944. DWORD dwError = ERROR_SUCCESS;
  945. HKEY hKey = NULL;
  946. dwError = RegOpenKeyExW(
  947. hRegistryKey,
  948. pszIpsecPolicyName,
  949. 0,
  950. KEY_ALL_ACCESS,
  951. &hKey
  952. );
  953. BAIL_ON_WIN32_ERROR(dwError);
  954. dwError = RegSetValueExW(
  955. hKey,
  956. L"ipsecISAKMPReference",
  957. 0,
  958. REG_SZ,
  959. (LPBYTE)pszNewIpsecISAKMPName,
  960. (wcslen(pszNewIpsecISAKMPName) + 1)*sizeof(WCHAR)
  961. );
  962. BAIL_ON_WIN32_ERROR(dwError);
  963. error:
  964. if (hKey) {
  965. RegCloseKey(hKey);
  966. }
  967. return(dwError);
  968. }