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.

882 lines
20 KiB

  1. //----------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 2000.
  5. //
  6. // File: filters-r.c
  7. //
  8. // Contents: Filter management for registry.
  9. //
  10. //
  11. // History: KrishnaG.
  12. // AbhisheV.
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "precomp.h"
  16. extern LPWSTR FilterDNAttributes[];
  17. DWORD
  18. RegEnumFilterData(
  19. HKEY hRegistryKey,
  20. LPWSTR pszIpsecRootContainer,
  21. PIPSEC_FILTER_DATA ** pppIpsecFilterData,
  22. PDWORD pdwNumFilterObjects
  23. )
  24. {
  25. DWORD dwError = 0;
  26. PIPSEC_FILTER_OBJECT * ppIpsecFilterObjects = NULL;
  27. PIPSEC_FILTER_DATA pIpsecFilterData = NULL;
  28. PIPSEC_FILTER_DATA * ppIpsecFilterData = NULL;
  29. DWORD dwNumFilterObjects = 0;
  30. DWORD i = 0;
  31. DWORD j = 0;
  32. dwError = RegEnumFilterObjects(
  33. hRegistryKey,
  34. pszIpsecRootContainer,
  35. &ppIpsecFilterObjects,
  36. &dwNumFilterObjects
  37. );
  38. BAIL_ON_WIN32_ERROR(dwError);
  39. if (dwNumFilterObjects) {
  40. ppIpsecFilterData = (PIPSEC_FILTER_DATA *) AllocPolMem(
  41. dwNumFilterObjects*sizeof(PIPSEC_FILTER_DATA)
  42. );
  43. if (!ppIpsecFilterData) {
  44. dwError = ERROR_OUTOFMEMORY;
  45. BAIL_ON_WIN32_ERROR(dwError);
  46. }
  47. }
  48. for (i = 0; i < dwNumFilterObjects; i++) {
  49. dwError = RegUnmarshallFilterData(
  50. *(ppIpsecFilterObjects + i),
  51. &pIpsecFilterData
  52. );
  53. if (!dwError) {
  54. *(ppIpsecFilterData + j) = pIpsecFilterData;
  55. j++;
  56. }
  57. }
  58. if (j == 0) {
  59. if (ppIpsecFilterData) {
  60. FreePolMem(ppIpsecFilterData);
  61. ppIpsecFilterData = NULL;
  62. }
  63. }
  64. *pppIpsecFilterData = ppIpsecFilterData;
  65. *pdwNumFilterObjects = j;
  66. dwError = ERROR_SUCCESS;
  67. cleanup:
  68. if (ppIpsecFilterObjects) {
  69. FreeIpsecFilterObjects(
  70. ppIpsecFilterObjects,
  71. dwNumFilterObjects
  72. );
  73. }
  74. return(dwError);
  75. error:
  76. if (ppIpsecFilterData) {
  77. FreeMulIpsecFilterData(
  78. ppIpsecFilterData,
  79. i
  80. );
  81. }
  82. *pppIpsecFilterData = NULL;
  83. *pdwNumFilterObjects = 0;
  84. goto cleanup;
  85. }
  86. DWORD
  87. RegEnumFilterObjects(
  88. HKEY hRegistryKey,
  89. LPWSTR pszIpsecRootContainer,
  90. PIPSEC_FILTER_OBJECT ** pppIpsecFilterObjects,
  91. PDWORD pdwNumFilterObjects
  92. )
  93. {
  94. DWORD dwError = 0;
  95. DWORD i = 0;
  96. DWORD dwCount = 0;
  97. PIPSEC_FILTER_OBJECT pIpsecFilterObject = NULL;
  98. PIPSEC_FILTER_OBJECT * ppIpsecFilterObjects = NULL;
  99. DWORD dwNumFilterObjectsReturned = 0;
  100. DWORD dwIndex = 0;
  101. WCHAR szFilterName[MAX_PATH];
  102. DWORD dwSize = 0;
  103. *pppIpsecFilterObjects = NULL;
  104. *pdwNumFilterObjects = 0;
  105. while (1) {
  106. dwSize = MAX_PATH;
  107. szFilterName[0] = L'\0';
  108. dwError = RegEnumKeyExW(
  109. hRegistryKey,
  110. dwIndex,
  111. szFilterName,
  112. &dwSize,
  113. NULL,
  114. NULL,
  115. 0,
  116. 0
  117. );
  118. if (dwError == ERROR_NO_MORE_ITEMS) {
  119. break;
  120. }
  121. BAIL_ON_WIN32_ERROR(dwError);
  122. if (!wcsstr(szFilterName, L"ipsecFilter")) {
  123. dwIndex++;
  124. continue;
  125. }
  126. pIpsecFilterObject = NULL;
  127. dwError =UnMarshallRegistryFilterObject(
  128. hRegistryKey,
  129. pszIpsecRootContainer,
  130. szFilterName,
  131. REG_RELATIVE_NAME,
  132. &pIpsecFilterObject
  133. );
  134. if (dwError == ERROR_SUCCESS) {
  135. dwError = ReallocatePolMem(
  136. (LPVOID *) &ppIpsecFilterObjects,
  137. sizeof(PIPSEC_FILTER_OBJECT)*(dwNumFilterObjectsReturned),
  138. sizeof(PIPSEC_FILTER_OBJECT)*(dwNumFilterObjectsReturned + 1)
  139. );
  140. BAIL_ON_WIN32_ERROR(dwError);
  141. *(ppIpsecFilterObjects + dwNumFilterObjectsReturned) = pIpsecFilterObject;
  142. dwNumFilterObjectsReturned++;
  143. }
  144. dwIndex++;
  145. }
  146. *pppIpsecFilterObjects = ppIpsecFilterObjects;
  147. *pdwNumFilterObjects = dwNumFilterObjectsReturned;
  148. dwError = ERROR_SUCCESS;
  149. return(dwError);
  150. error:
  151. if (ppIpsecFilterObjects) {
  152. FreeIpsecFilterObjects(
  153. ppIpsecFilterObjects,
  154. dwNumFilterObjectsReturned
  155. );
  156. }
  157. if (pIpsecFilterObject) {
  158. FreeIpsecFilterObject(
  159. pIpsecFilterObject
  160. );
  161. }
  162. *pppIpsecFilterObjects = NULL;
  163. *pdwNumFilterObjects = 0;
  164. return(dwError);
  165. }
  166. DWORD
  167. RegSetFilterData(
  168. HKEY hRegistryKey,
  169. LPWSTR pszIpsecRootContainer,
  170. LPWSTR pszLocationName,
  171. PIPSEC_FILTER_DATA pIpsecFilterData
  172. )
  173. {
  174. DWORD dwError = 0;
  175. PIPSEC_FILTER_OBJECT pIpsecFilterObject = NULL;
  176. dwError = RegMarshallFilterObject(
  177. pIpsecFilterData,
  178. &pIpsecFilterObject
  179. );
  180. BAIL_ON_WIN32_ERROR(dwError);
  181. dwError = RegSetFilterObject(
  182. hRegistryKey,
  183. pszIpsecRootContainer,
  184. pIpsecFilterObject
  185. );
  186. BAIL_ON_WIN32_ERROR(dwError);
  187. dwError = RegBackPropIncChangesForFilterToNFA(
  188. hRegistryKey,
  189. pszIpsecRootContainer,
  190. pszLocationName,
  191. pIpsecFilterObject
  192. );
  193. BAIL_ON_WIN32_ERROR(dwError);
  194. error:
  195. if (pIpsecFilterObject) {
  196. FreeIpsecFilterObject(pIpsecFilterObject);
  197. }
  198. return(dwError);
  199. }
  200. DWORD
  201. RegSetFilterObject(
  202. HKEY hRegistryKey,
  203. LPWSTR pszIpsecRootContainer,
  204. PIPSEC_FILTER_OBJECT pIpsecFilterObject
  205. )
  206. {
  207. DWORD dwError = 0;
  208. dwError = PersistFilterObject(
  209. hRegistryKey,
  210. pIpsecFilterObject
  211. );
  212. BAIL_ON_WIN32_ERROR(dwError);
  213. error:
  214. return(dwError);
  215. }
  216. DWORD
  217. RegCreateFilterData(
  218. HKEY hRegistryKey,
  219. LPWSTR pszIpsecRootContainer,
  220. PIPSEC_FILTER_DATA pIpsecFilterData
  221. )
  222. {
  223. DWORD dwError = 0;
  224. PIPSEC_FILTER_OBJECT pIpsecFilterObject = NULL;
  225. dwError = RegMarshallFilterObject(
  226. pIpsecFilterData,
  227. &pIpsecFilterObject
  228. );
  229. BAIL_ON_WIN32_ERROR(dwError);
  230. dwError = RegCreateFilterObject(
  231. hRegistryKey,
  232. pszIpsecRootContainer,
  233. pIpsecFilterObject
  234. );
  235. BAIL_ON_WIN32_ERROR(dwError);
  236. error:
  237. if (pIpsecFilterObject) {
  238. FreeIpsecFilterObject(
  239. pIpsecFilterObject
  240. );
  241. }
  242. return(dwError);
  243. }
  244. DWORD
  245. RegCreateFilterObject(
  246. HKEY hRegistryKey,
  247. LPWSTR pszIpsecRootContainer,
  248. PIPSEC_FILTER_OBJECT pIpsecFilterObject
  249. )
  250. {
  251. DWORD dwError = 0;
  252. dwError = PersistFilterObject(
  253. hRegistryKey,
  254. pIpsecFilterObject
  255. );
  256. BAIL_ON_WIN32_ERROR(dwError);
  257. error:
  258. return(dwError);
  259. }
  260. DWORD
  261. RegDeleteFilterData(
  262. HKEY hRegistryKey,
  263. LPWSTR pszIpsecRootContainer,
  264. GUID FilterIdentifier
  265. )
  266. {
  267. DWORD dwError = ERROR_SUCCESS;
  268. WCHAR szGuid[MAX_PATH];
  269. WCHAR szDistinguishedName[MAX_PATH];
  270. LPWSTR pszStringUuid = NULL;
  271. szGuid[0] = L'\0';
  272. szDistinguishedName[0] = L'\0';
  273. dwError = UuidToString(
  274. &FilterIdentifier,
  275. &pszStringUuid
  276. );
  277. BAIL_ON_WIN32_ERROR(dwError);
  278. wcscpy(szGuid, L"{");
  279. wcscat(szGuid, pszStringUuid);
  280. wcscat(szGuid, L"}");
  281. wcscpy(szDistinguishedName,L"ipsecFilter");
  282. wcscat(szDistinguishedName, szGuid);
  283. dwError = RegDeleteKeyW(
  284. hRegistryKey,
  285. szDistinguishedName
  286. );
  287. BAIL_ON_WIN32_ERROR(dwError);
  288. error:
  289. if (pszStringUuid) {
  290. RpcStringFree(&pszStringUuid);
  291. }
  292. return(dwError);
  293. }
  294. DWORD
  295. RegUnmarshallFilterData(
  296. PIPSEC_FILTER_OBJECT pIpsecFilterObject,
  297. PIPSEC_FILTER_DATA * ppIpsecFilterData
  298. )
  299. {
  300. DWORD dwError = 0;
  301. dwError = UnmarshallFilterObject(
  302. pIpsecFilterObject,
  303. ppIpsecFilterData
  304. );
  305. return(dwError);
  306. }
  307. DWORD
  308. RegMarshallFilterObject(
  309. PIPSEC_FILTER_DATA pIpsecFilterData,
  310. PIPSEC_FILTER_OBJECT * ppIpsecFilterObject
  311. )
  312. {
  313. DWORD dwError = 0;
  314. PIPSEC_FILTER_OBJECT pIpsecFilterObject = NULL;
  315. WCHAR szGuid[MAX_PATH];
  316. WCHAR szDistinguishedName[MAX_PATH];
  317. LPBYTE pBuffer = NULL;
  318. DWORD dwBufferLen = 0;
  319. LPWSTR pszStringUuid = NULL;
  320. time_t PresentTime;
  321. szGuid[0] = L'\0';
  322. szDistinguishedName[0] = L'\0';
  323. pIpsecFilterObject = (PIPSEC_FILTER_OBJECT)AllocPolMem(
  324. sizeof(IPSEC_FILTER_OBJECT)
  325. );
  326. if (!pIpsecFilterObject) {
  327. dwError = ERROR_OUTOFMEMORY;
  328. BAIL_ON_WIN32_ERROR(dwError);
  329. }
  330. dwError = UuidToString(
  331. &pIpsecFilterData->FilterIdentifier,
  332. &pszStringUuid
  333. );
  334. BAIL_ON_WIN32_ERROR(dwError);
  335. wcscpy(szGuid, L"{");
  336. wcscat(szGuid, pszStringUuid);
  337. wcscat(szGuid, L"}");
  338. //
  339. // Fill in the distinguishedName
  340. //
  341. wcscpy(szDistinguishedName,L"ipsecFilter");
  342. wcscat(szDistinguishedName, szGuid);
  343. pIpsecFilterObject->pszDistinguishedName = AllocPolStr(
  344. szDistinguishedName
  345. );
  346. if (!pIpsecFilterObject->pszDistinguishedName) {
  347. dwError = ERROR_OUTOFMEMORY;
  348. BAIL_ON_WIN32_ERROR(dwError);
  349. }
  350. //
  351. // Fill in the ipsecName
  352. //
  353. if (pIpsecFilterData->pszIpsecName &&
  354. *pIpsecFilterData->pszIpsecName) {
  355. pIpsecFilterObject->pszIpsecName = AllocPolStr(
  356. pIpsecFilterData->pszIpsecName
  357. );
  358. if (!pIpsecFilterObject->pszIpsecName) {
  359. dwError = ERROR_OUTOFMEMORY;
  360. BAIL_ON_WIN32_ERROR(dwError);
  361. }
  362. }
  363. if (pIpsecFilterData->pszDescription &&
  364. *pIpsecFilterData->pszDescription) {
  365. pIpsecFilterObject->pszDescription = AllocPolStr(
  366. pIpsecFilterData->pszDescription
  367. );
  368. if (!pIpsecFilterObject->pszDescription) {
  369. dwError = ERROR_OUTOFMEMORY;
  370. BAIL_ON_WIN32_ERROR(dwError);
  371. }
  372. }
  373. //
  374. // Fill in the ipsecID
  375. //
  376. pIpsecFilterObject->pszIpsecID = AllocPolStr(
  377. szGuid
  378. );
  379. if (!pIpsecFilterObject->pszIpsecID) {
  380. dwError = ERROR_OUTOFMEMORY;
  381. BAIL_ON_WIN32_ERROR(dwError);
  382. }
  383. //
  384. // Fill in the ipsecDataType
  385. //
  386. pIpsecFilterObject->dwIpsecDataType = 0x100;
  387. //
  388. // Marshall the pIpsecDataBuffer and the Length
  389. //
  390. dwError = MarshallFilterBuffer(
  391. pIpsecFilterData,
  392. &pBuffer,
  393. &dwBufferLen
  394. );
  395. BAIL_ON_WIN32_ERROR(dwError);
  396. pIpsecFilterObject->pIpsecData = pBuffer;
  397. pIpsecFilterObject->dwIpsecDataLen = dwBufferLen;
  398. time(&PresentTime);
  399. pIpsecFilterObject->dwWhenChanged = (DWORD) PresentTime;
  400. *ppIpsecFilterObject = pIpsecFilterObject;
  401. cleanup:
  402. if (pszStringUuid) {
  403. RpcStringFree(
  404. &pszStringUuid
  405. );
  406. }
  407. return(dwError);
  408. error:
  409. if (pIpsecFilterObject) {
  410. FreeIpsecFilterObject(
  411. pIpsecFilterObject
  412. );
  413. }
  414. *ppIpsecFilterObject = NULL;
  415. goto cleanup;
  416. }
  417. DWORD
  418. MarshallFilterBuffer(
  419. PIPSEC_FILTER_DATA pIpsecFilterData,
  420. LPBYTE * ppBuffer,
  421. DWORD * pdwBufferLen
  422. )
  423. {
  424. LPBYTE pMem = NULL;
  425. DWORD dwNumFilterSpecs = 0;
  426. PIPSEC_FILTER_SPEC * ppIpsecFilterSpecs = NULL;
  427. PIPSEC_FILTER_SPEC pIpsecFilterSpec = NULL;
  428. DWORD i = 0;
  429. DWORD dwNumBytesAdvanced = 0;
  430. DWORD dwError = 0;
  431. LPBYTE pBuffer = NULL;
  432. LPBYTE pCurrentPos = NULL;
  433. PSPEC_BUFFER pSpecBuffer = NULL;
  434. DWORD dwSpecSize = 0;
  435. DWORD dwTotalSize = 0;
  436. DWORD dwEffectiveSize = 0;
  437. // {80DC20B5-2EC8-11d1-A89E-00A0248D3021}
  438. static const GUID GUID_IPSEC_FILTER_BLOB =
  439. { 0x80dc20b5, 0x2ec8, 0x11d1, { 0xa8, 0x9e, 0x0, 0xa0, 0x24, 0x8d, 0x30, 0x21 } };
  440. //
  441. // Advance by the GUID
  442. //
  443. dwTotalSize += sizeof(GUID);
  444. //
  445. // Advance by a DWORD - Total size of the buffer.
  446. //
  447. dwTotalSize += sizeof(DWORD);
  448. //
  449. // Advance by a DWORD - this is dwNumFilterSpecs;
  450. //
  451. dwTotalSize += sizeof(DWORD);
  452. dwNumFilterSpecs = pIpsecFilterData->dwNumFilterSpecs;
  453. pSpecBuffer = (PSPEC_BUFFER)AllocPolMem(
  454. sizeof(SPEC_BUFFER)*dwNumFilterSpecs
  455. );
  456. if (!pSpecBuffer) {
  457. dwError = ERROR_OUTOFMEMORY;
  458. BAIL_ON_WIN32_ERROR(dwError);
  459. }
  460. for (i = 0; i < dwNumFilterSpecs;i++){
  461. dwError = MarshallFilterSpecBuffer(
  462. *(pIpsecFilterData->ppFilterSpecs + i),
  463. &pMem,
  464. &dwSpecSize
  465. );
  466. BAIL_ON_WIN32_ERROR(dwError);
  467. dwTotalSize += dwSpecSize;
  468. //
  469. // Fill in the spec size information
  470. //
  471. (pSpecBuffer + i)->dwSize = dwSpecSize;
  472. (pSpecBuffer + i)->pMem = pMem;
  473. }
  474. dwTotalSize++;
  475. pBuffer = AllocPolMem(dwTotalSize);
  476. if (!pBuffer) {
  477. dwError = ERROR_OUTOFMEMORY;
  478. BAIL_ON_WIN32_ERROR(dwError);
  479. }
  480. pCurrentPos = pBuffer;
  481. //
  482. // Copy the GUID
  483. //
  484. memcpy(pCurrentPos, &GUID_IPSEC_FILTER_BLOB, sizeof(GUID));
  485. pCurrentPos += sizeof(GUID);
  486. dwEffectiveSize = dwTotalSize - sizeof(GUID) - sizeof(DWORD) - 1;
  487. memcpy(pCurrentPos, &dwEffectiveSize, sizeof(DWORD));
  488. pCurrentPos += sizeof(DWORD);
  489. memcpy(pCurrentPos, &dwNumFilterSpecs, sizeof(DWORD));
  490. pCurrentPos += sizeof(DWORD);
  491. for (i = 0; i < dwNumFilterSpecs; i++) {
  492. pMem = (pSpecBuffer + i)->pMem;
  493. dwSpecSize = (pSpecBuffer + i)->dwSize;
  494. memcpy(pCurrentPos, pMem, dwSpecSize);
  495. pCurrentPos += dwSpecSize;
  496. }
  497. *ppBuffer = pBuffer;
  498. *pdwBufferLen = dwTotalSize;
  499. cleanup:
  500. if (pSpecBuffer) {
  501. FreeSpecBuffer(
  502. pSpecBuffer,
  503. dwNumFilterSpecs
  504. );
  505. }
  506. return(dwError);
  507. error:
  508. if (pBuffer) {
  509. FreePolMem(pBuffer);
  510. }
  511. *ppBuffer = NULL;
  512. *pdwBufferLen = 0;
  513. goto cleanup;
  514. }
  515. DWORD
  516. MarshallFilterSpecBuffer(
  517. PIPSEC_FILTER_SPEC pIpsecFilterSpec,
  518. LPBYTE * ppMem,
  519. DWORD * pdwSize
  520. )
  521. {
  522. DWORD dwSrcDNSNameLen = 0;
  523. DWORD dwDestDNSNameLen = 0;
  524. DWORD dwDescriptionLen = 0;
  525. LPBYTE pMem = NULL;
  526. LPBYTE pCurrentPos = NULL;
  527. DWORD dwSize = 0;
  528. DWORD dwError = 0;
  529. dwSize += sizeof(DWORD);
  530. if (pIpsecFilterSpec->pszSrcDNSName &&
  531. *pIpsecFilterSpec->pszSrcDNSName) {
  532. dwSrcDNSNameLen = (wcslen(pIpsecFilterSpec->pszSrcDNSName) + 1)
  533. *sizeof(WCHAR);
  534. }
  535. else {
  536. dwSrcDNSNameLen = sizeof(WCHAR);
  537. }
  538. if (dwSrcDNSNameLen) {
  539. dwSize += dwSrcDNSNameLen;
  540. }
  541. dwSize += sizeof(DWORD);
  542. if (pIpsecFilterSpec->pszDestDNSName &&
  543. *pIpsecFilterSpec->pszDestDNSName) {
  544. dwDestDNSNameLen = (wcslen(pIpsecFilterSpec->pszDestDNSName) + 1)
  545. *sizeof(WCHAR);
  546. }
  547. else {
  548. dwDestDNSNameLen = sizeof(WCHAR);
  549. }
  550. if (dwDestDNSNameLen) {
  551. dwSize += dwDestDNSNameLen;
  552. }
  553. dwSize += sizeof(DWORD);
  554. if (pIpsecFilterSpec->pszDescription &&
  555. *pIpsecFilterSpec->pszDescription) {
  556. dwDescriptionLen = (wcslen(pIpsecFilterSpec->pszDescription) + 1)
  557. *sizeof(WCHAR);
  558. }
  559. else {
  560. dwDescriptionLen = sizeof(WCHAR);
  561. }
  562. if (dwDescriptionLen) {
  563. dwSize += dwDescriptionLen;
  564. }
  565. //
  566. // Filter Spec GUID
  567. //
  568. dwSize += sizeof(GUID);
  569. //
  570. // dwMirrorFlag
  571. //
  572. dwSize += sizeof(DWORD);
  573. dwSize += sizeof(IPSEC_FILTER);
  574. pMem = (LPBYTE)AllocPolMem(dwSize);
  575. if (!pMem) {
  576. dwError = ERROR_OUTOFMEMORY;
  577. BAIL_ON_WIN32_ERROR(dwError);
  578. }
  579. pCurrentPos = pMem;
  580. memcpy(pCurrentPos, &(dwSrcDNSNameLen), sizeof(DWORD));
  581. pCurrentPos += sizeof(DWORD);
  582. if (pIpsecFilterSpec->pszSrcDNSName &&
  583. *pIpsecFilterSpec->pszSrcDNSName) {
  584. memcpy(pCurrentPos, pIpsecFilterSpec->pszSrcDNSName, dwSrcDNSNameLen);
  585. }
  586. pCurrentPos += dwSrcDNSNameLen;
  587. memcpy(pCurrentPos, &(dwDestDNSNameLen), sizeof(DWORD));
  588. pCurrentPos += sizeof(DWORD);
  589. if (pIpsecFilterSpec->pszDestDNSName &&
  590. *pIpsecFilterSpec->pszDestDNSName) {
  591. memcpy(pCurrentPos, pIpsecFilterSpec->pszDestDNSName, dwDestDNSNameLen);
  592. }
  593. pCurrentPos += dwDestDNSNameLen;
  594. memcpy(pCurrentPos, &(dwDescriptionLen), sizeof(DWORD));
  595. pCurrentPos += sizeof(DWORD);
  596. if (pIpsecFilterSpec->pszDescription &&
  597. *pIpsecFilterSpec->pszDescription) {
  598. memcpy(pCurrentPos, pIpsecFilterSpec->pszDescription, dwDescriptionLen);
  599. }
  600. pCurrentPos += dwDescriptionLen;
  601. memcpy(pCurrentPos, &(pIpsecFilterSpec->FilterSpecGUID), sizeof(GUID));
  602. pCurrentPos += sizeof(GUID);
  603. memcpy(pCurrentPos, &(pIpsecFilterSpec->dwMirrorFlag), sizeof(DWORD));
  604. pCurrentPos += sizeof(DWORD);
  605. memcpy(pCurrentPos, &(pIpsecFilterSpec->Filter), sizeof(IPSEC_FILTER));
  606. *ppMem = pMem;
  607. *pdwSize = dwSize;
  608. return(dwError);
  609. error:
  610. *ppMem = NULL;
  611. *pdwSize = 0;
  612. return(dwError);
  613. }
  614. DWORD
  615. RegGetFilterData(
  616. HKEY hRegistryKey,
  617. LPWSTR pszIpsecRootContainer,
  618. GUID FilterGUID,
  619. PIPSEC_FILTER_DATA * ppIpsecFilterData
  620. )
  621. {
  622. DWORD dwError = 0;
  623. PIPSEC_FILTER_OBJECT pIpsecFilterObject = NULL;
  624. PIPSEC_FILTER_DATA pIpsecFilterData = NULL;
  625. WCHAR szIpsecFilterName[MAX_PATH];
  626. LPWSTR pszFilterName = NULL;
  627. szIpsecFilterName[0] = L'\0';
  628. wcscpy(szIpsecFilterName, L"ipsecFilter");
  629. dwError = UuidToString(&FilterGUID, &pszFilterName);
  630. BAIL_ON_WIN32_ERROR(dwError);
  631. wcscat(szIpsecFilterName, L"{");
  632. wcscat(szIpsecFilterName, pszFilterName);
  633. wcscat(szIpsecFilterName, L"}");
  634. dwError =UnMarshallRegistryFilterObject(
  635. hRegistryKey,
  636. pszIpsecRootContainer,
  637. szIpsecFilterName,
  638. REG_RELATIVE_NAME,
  639. &pIpsecFilterObject
  640. );
  641. BAIL_ON_WIN32_ERROR(dwError);
  642. dwError = RegUnmarshallFilterData(
  643. pIpsecFilterObject,
  644. &pIpsecFilterData
  645. );
  646. BAIL_ON_WIN32_ERROR(dwError);
  647. error:
  648. if (pIpsecFilterObject) {
  649. FreeIpsecFilterObject(
  650. pIpsecFilterObject
  651. );
  652. }
  653. if (pszFilterName) {
  654. RpcStringFree(&pszFilterName);
  655. }
  656. *ppIpsecFilterData = pIpsecFilterData;
  657. return(dwError);
  658. }
  659. VOID
  660. FreeSpecBuffer(
  661. PSPEC_BUFFER pSpecBuffer,
  662. DWORD dwNumFilterSpecs
  663. )
  664. {
  665. DWORD i = 0;
  666. if (pSpecBuffer) {
  667. for (i = 0; i < dwNumFilterSpecs; i++) {
  668. if ((pSpecBuffer+i)->pMem) {
  669. FreePolMem((pSpecBuffer+i)->pMem);
  670. }
  671. }
  672. FreePolMem(pSpecBuffer);
  673. }
  674. return;
  675. }