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.

2864 lines
75 KiB

  1. #include "precomp.h"
  2. DWORD
  3. ProcessNFAs(
  4. PIPSEC_POLICY_OBJECT pIpsecPolicyObject,
  5. DWORD dwStoreType,
  6. PDWORD pdwSlientErrorCode,
  7. PIPSEC_POLICY_DATA * ppIpsecPolicyData
  8. )
  9. {
  10. DWORD dwError = 0;
  11. DWORD i = 0;
  12. DWORD NumberofRules = 0;
  13. PIPSEC_NFA_OBJECT * ppIpsecNFAObjects = NULL;
  14. PIPSEC_FILTER_OBJECT * ppIpsecFilterObjects = NULL;
  15. PIPSEC_NEGPOL_OBJECT * ppIpsecNegPolObjects = NULL;
  16. DWORD dwNumFilterObjects = 0;
  17. DWORD dwNumNegPolObjects = 0;
  18. PIPSEC_NFA_OBJECT pIpsecNFAObject = NULL;
  19. PIPSEC_NFA_DATA * ppIpsecNFAData = NULL;
  20. PIPSEC_NFA_DATA pIpsecNFAData = NULL;
  21. PIPSEC_POLICY_DATA pIpsecPolicyData = NULL;
  22. DWORD dwNumNFACount = 0;
  23. NumberofRules = pIpsecPolicyObject->NumberofRulesReturned;
  24. ppIpsecNFAObjects = pIpsecPolicyObject->ppIpsecNFAObjects;
  25. ppIpsecFilterObjects = pIpsecPolicyObject->ppIpsecFilterObjects;
  26. ppIpsecNegPolObjects = pIpsecPolicyObject->ppIpsecNegPolObjects;
  27. dwNumFilterObjects = pIpsecPolicyObject->NumberofFilters;
  28. dwNumNegPolObjects = pIpsecPolicyObject->NumberofNegPols;
  29. __try {
  30. dwError = UnmarshallPolicyObject(
  31. pIpsecPolicyObject,
  32. dwStoreType,
  33. &pIpsecPolicyData
  34. );
  35. } __except(EXCEPTION_EXECUTE_HANDLER) {
  36. dwError = ERROR_INVALID_DATA;
  37. }
  38. BAIL_ON_WIN32_ERROR(dwError);
  39. __try {
  40. dwError = UnmarshallISAKMPObject(
  41. *(pIpsecPolicyObject->ppIpsecISAKMPObjects),
  42. &pIpsecPolicyData->pIpsecISAKMPData
  43. );
  44. } __except(EXCEPTION_EXECUTE_HANDLER) {
  45. dwError = ERROR_INVALID_DATA;
  46. }
  47. BAIL_ON_WIN32_ERROR(dwError);
  48. ppIpsecNFAData = (PIPSEC_NFA_DATA *)AllocPolMem(
  49. sizeof(PIPSEC_NFA_DATA)* NumberofRules
  50. );
  51. if (!ppIpsecNFAData) {
  52. dwError = ERROR_OUTOFMEMORY;
  53. BAIL_ON_WIN32_ERROR(dwError);
  54. }
  55. for (i = 0; i < NumberofRules; i++) {
  56. pIpsecNFAObject = *(ppIpsecNFAObjects + i);
  57. dwError = ProcessNFA(
  58. pIpsecNFAObject,
  59. dwStoreType,
  60. ppIpsecFilterObjects,
  61. dwNumFilterObjects,
  62. ppIpsecNegPolObjects,
  63. dwNumNegPolObjects,
  64. &pIpsecNFAData
  65. );
  66. if (dwError == ERROR_SUCCESS) {
  67. if (pIpsecNFAData->dwActiveFlag != 0) {
  68. *(ppIpsecNFAData + dwNumNFACount) = pIpsecNFAData;
  69. dwNumNFACount++;
  70. }
  71. else {
  72. FreeIpsecNFAData(pIpsecNFAData);
  73. }
  74. }
  75. else {
  76. *pdwSlientErrorCode = dwError;
  77. }
  78. }
  79. pIpsecPolicyData->ppIpsecNFAData = ppIpsecNFAData;
  80. pIpsecPolicyData->dwNumNFACount = dwNumNFACount;
  81. *ppIpsecPolicyData = pIpsecPolicyData;
  82. return(dwError);
  83. error:
  84. if (pIpsecPolicyData) {
  85. FreeIpsecPolicyData(
  86. pIpsecPolicyData
  87. );
  88. }
  89. *ppIpsecPolicyData = NULL;
  90. return(dwError);
  91. }
  92. DWORD
  93. ProcessNFA(
  94. PIPSEC_NFA_OBJECT pIpsecNFAObject,
  95. DWORD dwStoreType,
  96. PIPSEC_FILTER_OBJECT * ppIpsecFilterObjects,
  97. DWORD dwNumFilterObjects,
  98. PIPSEC_NEGPOL_OBJECT * ppIpsecNegPolObjects,
  99. DWORD dwNumNegPolObjects,
  100. PIPSEC_NFA_DATA * ppIpsecNFAData
  101. )
  102. {
  103. DWORD dwError = 0;
  104. PIPSEC_FILTER_OBJECT pIpsecFilterObject = NULL;
  105. PIPSEC_NEGPOL_OBJECT pIpsecNegPolObject = NULL;
  106. PIPSEC_NFA_DATA pIpsecNFAData = NULL;
  107. __try {
  108. dwError = UnmarshallNFAObject(
  109. pIpsecNFAObject,
  110. dwStoreType,
  111. &pIpsecNFAData
  112. );
  113. } __except(EXCEPTION_EXECUTE_HANDLER) {
  114. dwError = ERROR_INVALID_DATA;
  115. }
  116. BAIL_ON_WIN32_ERROR(dwError);
  117. if (pIpsecNFAObject->pszIpsecFilterReference &&
  118. *pIpsecNFAObject->pszIpsecFilterReference) {
  119. dwError = FindIpsecFilterObject(
  120. pIpsecNFAObject,
  121. ppIpsecFilterObjects,
  122. dwNumFilterObjects,
  123. &pIpsecFilterObject
  124. );
  125. BAIL_ON_WIN32_ERROR(dwError);
  126. __try {
  127. dwError = UnmarshallFilterObject(
  128. pIpsecFilterObject,
  129. &pIpsecNFAData->pIpsecFilterData
  130. );
  131. } __except(EXCEPTION_EXECUTE_HANDLER) {
  132. dwError = ERROR_INVALID_DATA;
  133. }
  134. BAIL_ON_WIN32_ERROR(dwError);
  135. } else {
  136. //
  137. // We've received a NULL FilterReference or a NULL string FilterReference
  138. //
  139. //
  140. // This is acceptable - implies there is no filter associated
  141. //
  142. pIpsecNFAData->pIpsecFilterData = NULL;
  143. }
  144. dwError = FindIpsecNegPolObject(
  145. pIpsecNFAObject,
  146. ppIpsecNegPolObjects,
  147. dwNumNegPolObjects,
  148. &pIpsecNegPolObject
  149. );
  150. BAIL_ON_WIN32_ERROR(dwError);
  151. __try {
  152. dwError = UnmarshallNegPolObject(
  153. pIpsecNegPolObject,
  154. &pIpsecNFAData->pIpsecNegPolData
  155. );
  156. } __except(EXCEPTION_EXECUTE_HANDLER) {
  157. dwError = ERROR_INVALID_DATA;
  158. }
  159. BAIL_ON_WIN32_ERROR(dwError);
  160. *ppIpsecNFAData = pIpsecNFAData;
  161. return(dwError);
  162. error:
  163. if (pIpsecNFAData) {
  164. FreeIpsecNFAData(
  165. pIpsecNFAData
  166. );
  167. }
  168. return(dwError);
  169. }
  170. DWORD
  171. DeepCpyRsopInfo(
  172. PRSOP_INFO pDestRsop,
  173. PRSOP_INFO pSrcRsop
  174. )
  175. {
  176. DWORD dwError = ERROR_SUCCESS;
  177. if (!pDestRsop || !pSrcRsop) {
  178. dwError = ERROR_INVALID_PARAMETER;
  179. BAIL_ON_WIN32_ERROR(dwError);
  180. }
  181. memset(pDestRsop, 0, sizeof(RSOP_INFO));
  182. if (pSrcRsop->pszCreationtime && *pSrcRsop->pszCreationtime) {
  183. pDestRsop->pszCreationtime = AllocPolStr(
  184. pSrcRsop->pszCreationtime
  185. );
  186. if (!pDestRsop->pszCreationtime) {
  187. dwError = ERROR_OUTOFMEMORY;
  188. BAIL_ON_WIN32_ERROR(dwError);
  189. }
  190. }
  191. if (pSrcRsop->pszID && *pSrcRsop->pszID) {
  192. pDestRsop->pszID = AllocPolStr(
  193. pSrcRsop->pszID
  194. );
  195. if (!pDestRsop->pszID) {
  196. dwError = ERROR_OUTOFMEMORY;
  197. BAIL_ON_WIN32_ERROR(dwError);
  198. }
  199. }
  200. if (pSrcRsop->pszName && *pSrcRsop->pszName) {
  201. pDestRsop->pszName = AllocPolStr(
  202. pSrcRsop->pszName
  203. );
  204. if (!pDestRsop->pszName) {
  205. dwError = ERROR_OUTOFMEMORY;
  206. BAIL_ON_WIN32_ERROR(dwError);
  207. }
  208. }
  209. pDestRsop->uiPrecedence = pSrcRsop->uiPrecedence;
  210. if (pSrcRsop->pszGPOID && *pSrcRsop->pszGPOID) {
  211. pDestRsop->pszGPOID= AllocPolStr(
  212. pSrcRsop->pszGPOID
  213. );
  214. if (!pDestRsop->pszGPOID) {
  215. dwError = ERROR_OUTOFMEMORY;
  216. BAIL_ON_WIN32_ERROR(dwError);
  217. }
  218. }
  219. if (pSrcRsop->pszSOMID && *pSrcRsop->pszSOMID) {
  220. pDestRsop->pszSOMID = AllocPolStr(
  221. pSrcRsop->pszSOMID
  222. );
  223. if (!pDestRsop->pszSOMID) {
  224. dwError = ERROR_OUTOFMEMORY;
  225. BAIL_ON_WIN32_ERROR(dwError);
  226. }
  227. }
  228. error:
  229. return dwError;
  230. }
  231. DWORD SetPolstoreFlag(
  232. LPBYTE pCur,
  233. LPBYTE pStart,
  234. DWORD dwLength,
  235. DWORD LastError,
  236. DWORD * pdwFlags
  237. )
  238. {
  239. DWORD dwFlags = 0;
  240. LPBYTE pEnd;
  241. //
  242. // End of data is at end of buffer minus the NULL character
  243. //
  244. pEnd = pStart + dwLength - 1;
  245. if (LastError == ERROR_SUCCESS) {
  246. if (pCur + sizeof(GUID) >= pEnd) {
  247. dwFlags = POLSTORE_READWRITE;
  248. }
  249. else {
  250. dwFlags = POLSTORE_READONLY | POLSTORE_NEW_VER;
  251. }
  252. } else {
  253. dwFlags = POLSTORE_READONLY | POLSTORE_PARTIAL;
  254. }
  255. *pdwFlags = dwFlags;
  256. return ERROR_SUCCESS;
  257. }
  258. DWORD
  259. UnmarshallPolicyObject(
  260. PIPSEC_POLICY_OBJECT pIpsecPolicyObject,
  261. DWORD dwStoreType,
  262. PIPSEC_POLICY_DATA * ppIpsecPolicyData
  263. )
  264. {
  265. LPBYTE pMem = NULL;
  266. LPWSTR pszIpsecISAKMPReference = NULL;
  267. PIPSEC_POLICY_DATA pIpsecPolicyData = NULL;
  268. DWORD dwPollingInterval = 0;
  269. DWORD dwFlags = 0;
  270. DWORD dwError = 0;
  271. DWORD dwSkipSize = 0;
  272. // {6A1F5C6F-72B7-11d2-ACF0-0060B0ECCA17}
  273. GUID GUID_POLSTORE_VERSION_INFO =
  274. { 0x6a1f5c6f, 0x72b7, 0x11d2, { 0xac, 0xf0, 0x0, 0x60, 0xb0, 0xec, 0xca, 0x17 } };
  275. // {22202163-4F4C-11d1-863B-00A0248D3021}
  276. static const GUID GUID_IPSEC_POLICY_DATA_BLOB =
  277. { 0x22202163, 0x4f4c, 0x11d1, { 0x86, 0x3b, 0x0, 0xa0, 0x24, 0x8d, 0x30, 0x21 } };
  278. pMem = pIpsecPolicyObject->pIpsecData;
  279. //
  280. // Check if the first blob is the version.
  281. //
  282. if (!memcmp(pMem, &(GUID_POLSTORE_VERSION_INFO), sizeof(GUID))) {
  283. pMem += sizeof(GUID);
  284. memcpy(&dwSkipSize, pMem, sizeof(DWORD));
  285. pMem += sizeof(DWORD);
  286. pMem += dwSkipSize;
  287. }
  288. pMem += sizeof(GUID);
  289. pMem += sizeof(DWORD);
  290. memcpy((LPBYTE)&dwPollingInterval, pMem, sizeof(DWORD));
  291. pMem += sizeof(DWORD);
  292. (VOID) SetPolstoreFlag(
  293. pMem,
  294. pIpsecPolicyObject->pIpsecData,
  295. pIpsecPolicyObject->dwIpsecDataLen,
  296. ERROR_SUCCESS,
  297. &dwFlags
  298. );
  299. pIpsecPolicyData = (PIPSEC_POLICY_DATA)AllocPolMem(
  300. sizeof(IPSEC_POLICY_DATA)
  301. );
  302. if (!pIpsecPolicyData) {
  303. dwError = ERROR_OUTOFMEMORY;
  304. BAIL_ON_WIN32_ERROR(dwError);
  305. }
  306. if (pIpsecPolicyObject->pszIpsecName && *(pIpsecPolicyObject->pszIpsecName)) {
  307. pIpsecPolicyData->pszIpsecName = AllocPolStr(
  308. pIpsecPolicyObject->pszIpsecName
  309. );
  310. if (!pIpsecPolicyData->pszIpsecName) {
  311. dwError = ERROR_OUTOFMEMORY;
  312. BAIL_ON_WIN32_ERROR(dwError);
  313. }
  314. }
  315. if (pIpsecPolicyObject->pszDescription && *(pIpsecPolicyObject->pszDescription)){
  316. pIpsecPolicyData->pszDescription = AllocPolStr(
  317. pIpsecPolicyObject->pszDescription
  318. );
  319. if (!pIpsecPolicyData->pszDescription) {
  320. dwError = ERROR_OUTOFMEMORY;
  321. BAIL_ON_WIN32_ERROR(dwError);
  322. }
  323. }
  324. wGUIDFromString(pIpsecPolicyObject->pszIpsecID,
  325. &pIpsecPolicyData->PolicyIdentifier
  326. );
  327. switch(dwStoreType) {
  328. case IPSEC_WMI_PROVIDER:
  329. pIpsecPolicyData->pRsopInfo = (PRSOP_INFO)AllocPolMem(
  330. sizeof(RSOP_INFO)
  331. );
  332. if (!pIpsecPolicyData->pRsopInfo) {
  333. dwError = ERROR_OUTOFMEMORY;
  334. BAIL_ON_WIN32_ERROR(dwError);
  335. }
  336. dwError = DeepCpyRsopInfo(
  337. pIpsecPolicyData->pRsopInfo,
  338. pIpsecPolicyObject->pRsopInfo
  339. );
  340. BAIL_ON_WIN32_ERROR(dwError);
  341. // no "break"; do everything we'd do for IPSEC_REGISTRY_PROVIDER as well.
  342. case IPSEC_REGISTRY_PROVIDER:
  343. dwError = GenGUIDFromRegISAKMPReference(
  344. pIpsecPolicyObject->pszIpsecISAKMPReference,
  345. &pIpsecPolicyData->ISAKMPIdentifier
  346. );
  347. BAIL_ON_WIN32_ERROR(dwError);
  348. break;
  349. case IPSEC_DIRECTORY_PROVIDER:
  350. dwError = CopyISAKMPDSToFQRegString(
  351. pIpsecPolicyObject->pszIpsecISAKMPReference,
  352. &pszIpsecISAKMPReference
  353. );
  354. BAIL_ON_WIN32_ERROR(dwError);
  355. dwError = GenGUIDFromRegISAKMPReference(
  356. pszIpsecISAKMPReference,
  357. &pIpsecPolicyData->ISAKMPIdentifier
  358. );
  359. BAIL_ON_WIN32_ERROR(dwError);
  360. break;
  361. default:
  362. dwError = ERROR_INVALID_PARAMETER;
  363. BAIL_ON_WIN32_ERROR(dwError);
  364. }
  365. pIpsecPolicyData->dwWhenChanged = pIpsecPolicyObject->dwWhenChanged;
  366. pIpsecPolicyData->dwPollingInterval = dwPollingInterval;
  367. pIpsecPolicyData->dwFlags = dwFlags;
  368. *ppIpsecPolicyData = pIpsecPolicyData;
  369. if (pszIpsecISAKMPReference) {
  370. FreePolStr(pszIpsecISAKMPReference);
  371. }
  372. return(0);
  373. error:
  374. if (pIpsecPolicyData) {
  375. FreeIpsecPolicyData(pIpsecPolicyData);
  376. }
  377. if (pszIpsecISAKMPReference) {
  378. FreePolStr(pszIpsecISAKMPReference);
  379. }
  380. *ppIpsecPolicyData = NULL;
  381. return(dwError);
  382. }
  383. DWORD
  384. UnmarshallNFAObject(
  385. PIPSEC_NFA_OBJECT pIpsecNFAObject,
  386. DWORD dwStoreType,
  387. PIPSEC_NFA_DATA * ppIpsecNFAData
  388. )
  389. {
  390. LPBYTE pMem = NULL;
  391. DWORD dwNumAuthMethods = 0;
  392. PIPSEC_AUTH_METHOD * ppIpsecAuthMethods = NULL;
  393. DWORD dwFlags = 0;
  394. DWORD dwError = 0;
  395. DWORD i = 0;
  396. PIPSEC_AUTH_METHOD pIpsecAuthMethod = NULL;
  397. DWORD dwInterfaceType = 0;
  398. DWORD dwInterfaceNameLen = 0;
  399. LPWSTR pszInterfaceName = NULL;
  400. DWORD dwTunnelIpAddr = 0;
  401. DWORD dwTunnelFlags = 0;
  402. DWORD dwActiveFlag = 0;
  403. DWORD dwEndPointNameLen = 0;
  404. LPWSTR pszEndPointName = NULL;
  405. DWORD dwNumBytesAdvanced = 0;
  406. PIPSEC_NFA_DATA pIpsecNFAData = NULL;
  407. LPWSTR pszIpsecFilterReference = NULL;
  408. LPWSTR pszIpsecNegPolReference = NULL;
  409. // {11BBAC00-498D-11d1-8639-00A0248D3021}
  410. static const GUID GUID_IPSEC_NFA_BLOB =
  411. { 0x11bbac00, 0x498d, 0x11d1, { 0x86, 0x39, 0x0, 0xa0, 0x24, 0x8d, 0x30, 0x21 } };
  412. DWORD dwReadBytes = 0;
  413. GUID TmpGuid;
  414. DWORD dwNumAltAuthMethods = 0;
  415. pMem = pIpsecNFAObject->pIpsecData;
  416. pMem += sizeof(GUID); // for the GUID
  417. pMem += sizeof(DWORD); // for the size
  418. memcpy((LPBYTE)&dwNumAuthMethods, pMem, sizeof(DWORD));
  419. pIpsecNFAData = (PIPSEC_NFA_DATA)AllocPolMem(
  420. sizeof(IPSEC_NFA_DATA)
  421. );
  422. if (!pIpsecNFAData) {
  423. dwError = ERROR_OUTOFMEMORY;
  424. BAIL_ON_WIN32_ERROR(dwError);
  425. }
  426. if (dwNumAuthMethods) {
  427. ppIpsecAuthMethods = (PIPSEC_AUTH_METHOD *) AllocPolMem(
  428. sizeof(PIPSEC_AUTH_METHOD)*dwNumAuthMethods
  429. );
  430. if (!ppIpsecAuthMethods) {
  431. dwError = ERROR_OUTOFMEMORY;
  432. BAIL_ON_WIN32_ERROR(dwError);
  433. }
  434. }
  435. pMem += sizeof(DWORD);
  436. for (i = 0; i < dwNumAuthMethods;i++){
  437. __try {
  438. dwError = UnmarshallAuthMethods(
  439. pMem,
  440. &pIpsecAuthMethod,
  441. &dwNumBytesAdvanced
  442. );
  443. } __except(EXCEPTION_EXECUTE_HANDLER) {
  444. dwError = ERROR_INVALID_DATA;
  445. }
  446. if (dwError) {
  447. pIpsecNFAData->dwAuthMethodCount = i;
  448. pIpsecNFAData->ppAuthMethods = ppIpsecAuthMethods;
  449. BAIL_ON_WIN32_ERROR(dwError);
  450. }
  451. pMem += dwNumBytesAdvanced;
  452. *(ppIpsecAuthMethods + i) = pIpsecAuthMethod;
  453. }
  454. pIpsecNFAData->dwAuthMethodCount = dwNumAuthMethods;
  455. pIpsecNFAData->ppAuthMethods = ppIpsecAuthMethods;
  456. memcpy((LPBYTE)&dwInterfaceType, pMem, sizeof(DWORD));
  457. pIpsecNFAData->dwInterfaceType = dwInterfaceType;
  458. pMem += sizeof(DWORD);
  459. memcpy((LPBYTE)&dwInterfaceNameLen, pMem, sizeof(DWORD));
  460. pMem += sizeof(DWORD);
  461. if (dwInterfaceNameLen) {
  462. pszInterfaceName = AllocPolStr((LPWSTR)pMem);
  463. if (!pszInterfaceName) {
  464. dwError = ERROR_OUTOFMEMORY;
  465. BAIL_ON_WIN32_ERROR(dwError);
  466. }
  467. }
  468. pIpsecNFAData->pszInterfaceName = pszInterfaceName;
  469. pMem += dwInterfaceNameLen;
  470. memcpy((LPBYTE)&dwTunnelIpAddr, pMem, sizeof(DWORD));
  471. pIpsecNFAData->dwTunnelIpAddr = dwTunnelIpAddr;
  472. pMem += sizeof(DWORD);
  473. memcpy((LPBYTE)&dwTunnelFlags, pMem, sizeof(DWORD));
  474. pIpsecNFAData->dwTunnelFlags = dwTunnelFlags;
  475. pMem += sizeof(DWORD);
  476. memcpy((LPBYTE)&dwActiveFlag, pMem, sizeof(DWORD));
  477. pIpsecNFAData->dwActiveFlag = dwActiveFlag;
  478. pMem += sizeof(DWORD);
  479. memcpy((LPBYTE)&dwEndPointNameLen, pMem, sizeof(DWORD));
  480. pMem += sizeof(DWORD);
  481. if (dwEndPointNameLen) {
  482. pszEndPointName = AllocPolStr((LPWSTR)pMem);
  483. if (!pszEndPointName) {
  484. dwError = ERROR_OUTOFMEMORY;
  485. BAIL_ON_WIN32_ERROR(dwError);
  486. }
  487. }
  488. pIpsecNFAData->pszEndPointName = pszEndPointName;
  489. pMem += dwEndPointNameLen;
  490. __try {
  491. dwReadBytes = (DWORD) ((BYTE *) pMem - (BYTE *) pIpsecNFAObject->pIpsecData);
  492. if ((dwReadBytes < pIpsecNFAObject->dwIpsecDataLen) &&
  493. ((pIpsecNFAObject->dwIpsecDataLen - dwReadBytes) > sizeof(GUID))) {
  494. memset(&TmpGuid, 1, sizeof(GUID));
  495. if (memcmp(pMem, &TmpGuid, sizeof(GUID)) == 0) {
  496. pMem += sizeof(GUID);
  497. memcpy(&dwNumAltAuthMethods, pMem, sizeof(DWORD));
  498. pMem += sizeof(DWORD);
  499. if (dwNumAltAuthMethods == dwNumAuthMethods) {
  500. for (i = 0; i < dwNumAuthMethods; i++) {
  501. dwError = UnmarshallAltAuthMethods(
  502. pMem,
  503. ppIpsecAuthMethods[i],
  504. &dwNumBytesAdvanced
  505. );
  506. if (dwError) {
  507. break;
  508. }
  509. pMem += dwNumBytesAdvanced;
  510. }
  511. }
  512. }
  513. dwReadBytes = (DWORD) ((BYTE *) pMem - (BYTE *) pIpsecNFAObject->pIpsecData);
  514. if ((dwReadBytes < pIpsecNFAObject->dwIpsecDataLen) &&
  515. ((pIpsecNFAObject->dwIpsecDataLen - dwReadBytes) > sizeof(GUID))) {
  516. // Have V3 data
  517. pMem += sizeof(GUID);
  518. pMem += sizeof(DWORD);
  519. for (i=0; i < dwNumAuthMethods; i++) {
  520. memcpy(&((*ppIpsecAuthMethods[i]).dwAuthFlags),
  521. pMem,
  522. sizeof(DWORD));
  523. pMem += sizeof(DWORD);
  524. }
  525. }
  526. }
  527. } __except(EXCEPTION_EXECUTE_HANDLER) {
  528. }
  529. (VOID) SetPolstoreFlag(
  530. pMem,
  531. pIpsecNFAObject->pIpsecData,
  532. pIpsecNFAObject->dwIpsecDataLen,
  533. dwError,
  534. &dwFlags
  535. );
  536. dwError = ERROR_SUCCESS;
  537. //
  538. // Convert the ipsecID to its GUID format
  539. //
  540. wGUIDFromString(pIpsecNFAObject->pszIpsecID,
  541. &pIpsecNFAData->NFAIdentifier
  542. );
  543. if (pIpsecNFAObject->pszIpsecName && *(pIpsecNFAObject->pszIpsecName)) {
  544. pIpsecNFAData->pszIpsecName = AllocPolStr(
  545. pIpsecNFAObject->pszIpsecName
  546. );
  547. if (!pIpsecNFAData->pszIpsecName) {
  548. dwError = ERROR_OUTOFMEMORY;
  549. BAIL_ON_WIN32_ERROR(dwError);
  550. }
  551. }
  552. if (pIpsecNFAObject->pszDescription && *(pIpsecNFAObject->pszDescription)) {
  553. pIpsecNFAData->pszDescription = AllocPolStr(
  554. pIpsecNFAObject->pszDescription
  555. );
  556. if (!pIpsecNFAData->pszDescription) {
  557. dwError = ERROR_OUTOFMEMORY;
  558. BAIL_ON_WIN32_ERROR(dwError);
  559. }
  560. }
  561. switch(dwStoreType) {
  562. case IPSEC_WMI_PROVIDER:
  563. case IPSEC_REGISTRY_PROVIDER:
  564. dwError = GenGUIDFromRegFilterReference(
  565. pIpsecNFAObject->pszIpsecFilterReference,
  566. &pIpsecNFAData->FilterIdentifier
  567. );
  568. BAIL_ON_WIN32_ERROR(dwError);
  569. dwError = GenGUIDFromRegNegPolReference(
  570. pIpsecNFAObject->pszIpsecNegPolReference,
  571. &pIpsecNFAData->NegPolIdentifier
  572. );
  573. BAIL_ON_WIN32_ERROR(dwError);
  574. break;
  575. case IPSEC_DIRECTORY_PROVIDER:
  576. if (pIpsecNFAObject->pszIpsecFilterReference &&
  577. *pIpsecNFAObject->pszIpsecFilterReference) {
  578. dwError = CopyFilterDSToFQRegString(
  579. pIpsecNFAObject->pszIpsecFilterReference,
  580. &pszIpsecFilterReference
  581. );
  582. BAIL_ON_WIN32_ERROR(dwError);
  583. dwError = GenGUIDFromRegFilterReference(
  584. pszIpsecFilterReference,
  585. &pIpsecNFAData->FilterIdentifier
  586. );
  587. BAIL_ON_WIN32_ERROR(dwError);
  588. }
  589. dwError = CopyNegPolDSToFQRegString(
  590. pIpsecNFAObject->pszIpsecNegPolReference,
  591. &pszIpsecNegPolReference
  592. );
  593. BAIL_ON_WIN32_ERROR(dwError);
  594. dwError = GenGUIDFromRegNegPolReference(
  595. pszIpsecNegPolReference,
  596. &pIpsecNFAData->NegPolIdentifier
  597. );
  598. BAIL_ON_WIN32_ERROR(dwError);
  599. break;
  600. default:
  601. dwError = ERROR_INVALID_PARAMETER;
  602. BAIL_ON_WIN32_ERROR(dwError);
  603. }
  604. pIpsecNFAData->dwWhenChanged = pIpsecNFAObject->dwWhenChanged;
  605. pIpsecNFAData->dwFlags = dwFlags;
  606. *ppIpsecNFAData = pIpsecNFAData;
  607. if (pszIpsecFilterReference) {
  608. FreePolStr(pszIpsecFilterReference);
  609. }
  610. if (pszIpsecNegPolReference) {
  611. FreePolStr(pszIpsecNegPolReference);
  612. }
  613. return(0);
  614. error:
  615. if (pIpsecNFAData) {
  616. FreeIpsecNFAData(pIpsecNFAData);
  617. }
  618. if (pszIpsecFilterReference) {
  619. FreePolStr(pszIpsecFilterReference);
  620. }
  621. if (pszIpsecNegPolReference) {
  622. FreePolStr(pszIpsecNegPolReference);
  623. }
  624. *ppIpsecNFAData = NULL;
  625. return(dwError);
  626. }
  627. DWORD
  628. UnmarshallFilterObject(
  629. PIPSEC_FILTER_OBJECT pIpsecFilterObject,
  630. PIPSEC_FILTER_DATA * ppIpsecFilterData
  631. )
  632. {
  633. LPBYTE pMem = NULL;
  634. DWORD dwNumFilterSpecs = 0;
  635. PIPSEC_FILTER_SPEC * ppIpsecFilterSpecs = NULL;
  636. PIPSEC_FILTER_SPEC pIpsecFilterSpec = NULL;
  637. DWORD i = 0;
  638. DWORD dwNumBytesAdvanced = 0;
  639. DWORD dwFlags = 0;
  640. PIPSEC_FILTER_DATA pIpsecFilterData = NULL;
  641. DWORD dwError = 0;
  642. // {80DC20B5-2EC8-11d1-A89E-00A0248D3021}
  643. static const GUID GUID_IPSEC_FILTER_BLOB =
  644. { 0x80dc20b5, 0x2ec8, 0x11d1, { 0xa8, 0x9e, 0x0, 0xa0, 0x24, 0x8d, 0x30, 0x21 } };
  645. pIpsecFilterData = (PIPSEC_FILTER_DATA)AllocPolMem(
  646. sizeof(IPSEC_FILTER_DATA)
  647. );
  648. if (!pIpsecFilterData) {
  649. dwError = ERROR_OUTOFMEMORY;
  650. BAIL_ON_WIN32_ERROR(dwError);
  651. }
  652. pMem = pIpsecFilterObject->pIpsecData;
  653. pMem += sizeof(GUID);
  654. pMem += sizeof(DWORD);
  655. memcpy((LPBYTE)&dwNumFilterSpecs, pMem, sizeof(DWORD));
  656. if (dwNumFilterSpecs) {
  657. ppIpsecFilterSpecs = (PIPSEC_FILTER_SPEC *)AllocPolMem(
  658. sizeof(PIPSEC_FILTER_SPEC)*dwNumFilterSpecs
  659. );
  660. if (!ppIpsecFilterSpecs) {
  661. dwError = ERROR_OUTOFMEMORY;
  662. BAIL_ON_WIN32_ERROR(dwError);
  663. }
  664. }
  665. pMem += sizeof(DWORD);
  666. for (i = 0; i < dwNumFilterSpecs;i++){
  667. __try {
  668. dwError = UnmarshallFilterSpec(
  669. pMem,
  670. &pIpsecFilterSpec,
  671. &dwNumBytesAdvanced
  672. );
  673. } __except(EXCEPTION_EXECUTE_HANDLER) {
  674. dwError = ERROR_INVALID_DATA;
  675. }
  676. if (dwError) {
  677. pIpsecFilterData->dwNumFilterSpecs = i;
  678. pIpsecFilterData->ppFilterSpecs = ppIpsecFilterSpecs;
  679. BAIL_ON_WIN32_ERROR(dwError);
  680. }
  681. pMem += dwNumBytesAdvanced;
  682. *(ppIpsecFilterSpecs + i) = pIpsecFilterSpec;
  683. }
  684. pIpsecFilterData->dwNumFilterSpecs = dwNumFilterSpecs;
  685. pIpsecFilterData->ppFilterSpecs = ppIpsecFilterSpecs;
  686. (VOID) SetPolstoreFlag(
  687. pMem,
  688. pIpsecFilterObject->pIpsecData,
  689. pIpsecFilterObject->dwIpsecDataLen,
  690. ERROR_SUCCESS,
  691. &dwFlags
  692. );
  693. //
  694. // Convert the ipsecID to its GUID format
  695. //
  696. if (pIpsecFilterObject->pszIpsecName && *(pIpsecFilterObject->pszIpsecName)) {
  697. pIpsecFilterData->pszIpsecName = AllocPolStr(
  698. pIpsecFilterObject->pszIpsecName
  699. );
  700. if (!pIpsecFilterData->pszIpsecName) {
  701. dwError = ERROR_OUTOFMEMORY;
  702. BAIL_ON_WIN32_ERROR(dwError);
  703. }
  704. }
  705. if (pIpsecFilterObject->pszDescription && *(pIpsecFilterObject->pszDescription)) {
  706. pIpsecFilterData->pszDescription = AllocPolStr(
  707. pIpsecFilterObject->pszDescription
  708. );
  709. if (!pIpsecFilterData->pszDescription) {
  710. dwError = ERROR_OUTOFMEMORY;
  711. BAIL_ON_WIN32_ERROR(dwError);
  712. }
  713. }
  714. wGUIDFromString(pIpsecFilterObject->pszIpsecID,
  715. &pIpsecFilterData->FilterIdentifier
  716. );
  717. pIpsecFilterData->dwWhenChanged = pIpsecFilterObject->dwWhenChanged;
  718. pIpsecFilterData->dwFlags = dwFlags;
  719. *ppIpsecFilterData = pIpsecFilterData;
  720. return(dwError);
  721. error:
  722. if (pIpsecFilterData) {
  723. FreeIpsecFilterData(pIpsecFilterData);
  724. }
  725. *ppIpsecFilterData = NULL;
  726. return(dwError);
  727. }
  728. DWORD
  729. UnmarshallNegPolObject(
  730. PIPSEC_NEGPOL_OBJECT pIpsecNegPolObject,
  731. PIPSEC_NEGPOL_DATA * ppIpsecNegPolData
  732. )
  733. {
  734. LPBYTE pMem = NULL;
  735. DWORD dwNumSecurityOffers = 0;
  736. PIPSEC_SECURITY_METHOD pIpsecOffer = NULL;
  737. PIPSEC_NEGPOL_DATA pIpsecNegPolData = NULL;
  738. DWORD dwFlags = 0;
  739. DWORD dwError = 0;
  740. // {80DC20B9-2EC8-11d1-A89E-00A0248D3021}
  741. static const GUID GUID_IPSEC_NEGPOLICY_BLOB =
  742. { 0x80dc20b9, 0x2ec8, 0x11d1, { 0xa8, 0x9e, 0x0, 0xa0, 0x24, 0x8d, 0x30, 0x21 } };
  743. pMem = pIpsecNegPolObject->pIpsecData;
  744. pIpsecNegPolData = (PIPSEC_NEGPOL_DATA)AllocPolMem(
  745. sizeof(IPSEC_NEGPOL_DATA)
  746. );
  747. if (!pIpsecNegPolData) {
  748. dwError = ERROR_OUTOFMEMORY;
  749. BAIL_ON_WIN32_ERROR(dwError);
  750. }
  751. pMem += sizeof(GUID);
  752. pMem += sizeof(DWORD);
  753. memcpy((LPBYTE)&dwNumSecurityOffers, pMem, sizeof(DWORD));
  754. pMem += sizeof(DWORD);
  755. if (dwNumSecurityOffers) {
  756. pIpsecOffer = (PIPSEC_SECURITY_METHOD)AllocPolMem(
  757. sizeof(IPSEC_SECURITY_METHOD)*dwNumSecurityOffers
  758. );
  759. if (!pIpsecOffer) {
  760. dwError = ERROR_OUTOFMEMORY;
  761. BAIL_ON_WIN32_ERROR(dwError);
  762. }
  763. memcpy((LPBYTE)pIpsecOffer, pMem,
  764. sizeof(IPSEC_SECURITY_METHOD)*dwNumSecurityOffers);
  765. pMem += sizeof(IPSEC_SECURITY_METHOD)*dwNumSecurityOffers;
  766. }
  767. (VOID) SetPolstoreFlag(
  768. pMem,
  769. pIpsecNegPolObject->pIpsecData,
  770. pIpsecNegPolObject->dwIpsecDataLen,
  771. ERROR_SUCCESS,
  772. &dwFlags
  773. );
  774. //
  775. // Convert the ipsecID to its GUID format
  776. //
  777. if (pIpsecNegPolObject->pszIpsecName && *(pIpsecNegPolObject->pszIpsecName)) {
  778. pIpsecNegPolData->pszIpsecName = AllocPolStr(
  779. pIpsecNegPolObject->pszIpsecName
  780. );
  781. if (!pIpsecNegPolData->pszIpsecName) {
  782. dwError = ERROR_OUTOFMEMORY;
  783. BAIL_ON_WIN32_ERROR(dwError);
  784. }
  785. }
  786. if (pIpsecNegPolObject->pszDescription && *(pIpsecNegPolObject->pszDescription)){
  787. pIpsecNegPolData->pszDescription = AllocPolStr(
  788. pIpsecNegPolObject->pszDescription
  789. );
  790. if (!pIpsecNegPolData->pszDescription) {
  791. dwError = ERROR_OUTOFMEMORY;
  792. BAIL_ON_WIN32_ERROR(dwError);
  793. }
  794. }
  795. wGUIDFromString(pIpsecNegPolObject->pszIpsecID,
  796. &pIpsecNegPolData->NegPolIdentifier
  797. );
  798. wGUIDFromString(pIpsecNegPolObject->pszIpsecNegPolAction,
  799. &pIpsecNegPolData->NegPolAction
  800. );
  801. wGUIDFromString(pIpsecNegPolObject->pszIpsecNegPolType,
  802. &pIpsecNegPolData->NegPolType
  803. );
  804. pIpsecNegPolData->dwSecurityMethodCount = dwNumSecurityOffers;
  805. pIpsecNegPolData->pIpsecSecurityMethods = pIpsecOffer;
  806. pIpsecNegPolData->dwWhenChanged = pIpsecNegPolObject->dwWhenChanged;
  807. pIpsecNegPolData->dwFlags = dwFlags;
  808. *ppIpsecNegPolData = pIpsecNegPolData;
  809. return(0);
  810. error:
  811. if (pIpsecOffer) {
  812. FreePolMem(pIpsecOffer);
  813. }
  814. if (pIpsecNegPolData) {
  815. FreeIpsecNegPolData(pIpsecNegPolData);
  816. }
  817. *ppIpsecNegPolData = NULL;
  818. return(dwError);
  819. }
  820. DWORD
  821. ConvertBundleFlagToBundle(BYTE bBundleFlag,
  822. PISAKMP_POLICY pIsakmpPolicy,
  823. CRYPTO_BUNDLE *pBundle)
  824. {
  825. if (bBundleFlag == BYTE_DES_MD5_2048) {
  826. pBundle->EncryptionAlgorithm.AlgorithmIdentifier = IPSEC_ESP_DES;
  827. pBundle->HashAlgorithm.AlgorithmIdentifier = IPSEC_AH_MD5;
  828. pBundle->OakleyGroup=DH_GROUP_2048;
  829. }
  830. if (bBundleFlag == BYTE_DES_SHA_2048) {
  831. pBundle->EncryptionAlgorithm.AlgorithmIdentifier = IPSEC_ESP_DES;
  832. pBundle->HashAlgorithm.AlgorithmIdentifier = IPSEC_AH_SHA;
  833. pBundle->OakleyGroup=DH_GROUP_2048;
  834. }
  835. if (bBundleFlag == BYTE_3DES_MD5_2048) {
  836. pBundle->EncryptionAlgorithm.AlgorithmIdentifier = IPSEC_ESP_3_DES;
  837. pBundle->HashAlgorithm.AlgorithmIdentifier = IPSEC_AH_MD5;
  838. pBundle->OakleyGroup=DH_GROUP_2048;
  839. }
  840. if (bBundleFlag == BYTE_3DES_SHA_2048) {
  841. pBundle->EncryptionAlgorithm.AlgorithmIdentifier = IPSEC_ESP_3_DES;
  842. pBundle->HashAlgorithm.AlgorithmIdentifier = IPSEC_AH_SHA;
  843. pBundle->OakleyGroup=DH_GROUP_2048;
  844. }
  845. pBundle->QuickModeLimit = pIsakmpPolicy->dwQMLimit;
  846. if (pBundle->QuickModeLimit == 1) {
  847. pBundle->PfsIdentityRequired = TRUE;
  848. }
  849. pBundle->Lifetime.Seconds = pIsakmpPolicy->dwLifetimeSec;
  850. return ERROR_SUCCESS;
  851. }
  852. DWORD
  853. UnmarshallISAKMPObject(
  854. PIPSEC_ISAKMP_OBJECT pIpsecISAKMPObject,
  855. PIPSEC_ISAKMP_DATA * ppIpsecISAKMPData
  856. )
  857. {
  858. LPBYTE pMem = NULL;
  859. PIPSEC_ISAKMP_DATA pIpsecISAKMPData = NULL;
  860. DWORD dwNumISAKMPSecurityMethods = 0;
  861. PCRYPTO_BUNDLE pSecurityMethods = NULL;
  862. PCRYPTO_BUNDLE pSecurityMethod = NULL;
  863. DWORD dwFlags = 0;
  864. DWORD i = 0;
  865. DWORD dwError = 0;
  866. DWORD dwNumLeadingBundles = 0;
  867. BYTE *pbLeadingBundleFlags = NULL;
  868. // {80DC20B8-2EC8-11d1-A89E-00A0248D3021}
  869. static const GUID GUID_IPSEC_ISAKMP_POLICY_BLOB =
  870. { 0x80dc20b8, 0x2ec8, 0x11d1, { 0xa8, 0x9e, 0x0, 0xa0, 0x24, 0x8d, 0x30, 0x21 } };
  871. // CHECK THIS PART
  872. pMem = pIpsecISAKMPObject->pIpsecData;
  873. pIpsecISAKMPData = (PIPSEC_ISAKMP_DATA) AllocPolMem(
  874. sizeof(IPSEC_ISAKMP_DATA)
  875. );
  876. if (!pIpsecISAKMPData) {
  877. dwError = ERROR_OUTOFMEMORY;
  878. BAIL_ON_WIN32_ERROR(dwError);
  879. }
  880. pMem += sizeof(GUID);
  881. pMem += sizeof(DWORD);
  882. memcpy((LPBYTE)&pIpsecISAKMPData->ISAKMPPolicy, pMem, sizeof(ISAKMP_POLICY));
  883. pMem += sizeof(ISAKMP_POLICY);
  884. memcpy((LPBYTE)&dwNumISAKMPSecurityMethods, pMem, sizeof(DWORD));
  885. pMem += sizeof(DWORD);
  886. pbLeadingBundleFlags = pIpsecISAKMPData->ISAKMPPolicy.bLeadingBundleFlags;
  887. for (i=0; i < 4; i++) {
  888. if (pbLeadingBundleFlags[i] != 0) {
  889. dwNumLeadingBundles++;
  890. }
  891. }
  892. if (!dwNumISAKMPSecurityMethods && !dwNumLeadingBundles) {
  893. dwError = ERROR_INVALID_DATA;
  894. BAIL_ON_WIN32_ERROR(dwError);
  895. }
  896. pSecurityMethods = (PCRYPTO_BUNDLE) AllocPolMem(
  897. sizeof(CRYPTO_BUNDLE)*(dwNumISAKMPSecurityMethods+dwNumLeadingBundles)
  898. );
  899. if (!pSecurityMethods) {
  900. dwError = ERROR_OUTOFMEMORY;
  901. BAIL_ON_WIN32_ERROR(dwError);
  902. }
  903. for (i = 0; i < dwNumLeadingBundles; i++) {
  904. pSecurityMethod = pSecurityMethods + i;
  905. ConvertBundleFlagToBundle(pbLeadingBundleFlags[i],
  906. &pIpsecISAKMPData->ISAKMPPolicy,
  907. pSecurityMethod);
  908. }
  909. for (i = 0; i < dwNumISAKMPSecurityMethods; i++) {
  910. pSecurityMethod = pSecurityMethods + (i + dwNumLeadingBundles);
  911. memcpy(pSecurityMethod, pMem, sizeof(CRYPTO_BUNDLE));
  912. if (pSecurityMethod->PseudoRandomFunction.Rounds) {
  913. ConvertBundleFlagToBundle((BYTE)pSecurityMethod->PseudoRandomFunction.Rounds,
  914. &pIpsecISAKMPData->ISAKMPPolicy,
  915. pSecurityMethod);
  916. pSecurityMethod->PseudoRandomFunction.Rounds = 0;
  917. }
  918. pMem += sizeof(CRYPTO_BUNDLE);
  919. }
  920. pIpsecISAKMPData->dwNumISAKMPSecurityMethods = dwNumISAKMPSecurityMethods + dwNumLeadingBundles;
  921. pIpsecISAKMPData->pSecurityMethods = pSecurityMethods;
  922. (VOID) SetPolstoreFlag(
  923. pMem,
  924. pIpsecISAKMPObject->pIpsecData,
  925. pIpsecISAKMPObject->dwIpsecDataLen,
  926. ERROR_SUCCESS,
  927. &dwFlags
  928. );
  929. //
  930. // Convert the ipsecID to its GUID format
  931. //
  932. wGUIDFromString(pIpsecISAKMPObject->pszIpsecID,
  933. &pIpsecISAKMPData->ISAKMPIdentifier
  934. );
  935. pIpsecISAKMPData->dwWhenChanged = pIpsecISAKMPObject->dwWhenChanged;
  936. pIpsecISAKMPData->dwFlags = dwFlags;
  937. *ppIpsecISAKMPData = pIpsecISAKMPData;
  938. return(0);
  939. error:
  940. if (pIpsecISAKMPData) {
  941. FreeIpsecISAKMPData(pIpsecISAKMPData);
  942. }
  943. *ppIpsecISAKMPData = NULL;
  944. return(dwError);
  945. }
  946. DWORD
  947. FindIpsecFilterObject(
  948. PIPSEC_NFA_OBJECT pIpsecNFAObject,
  949. PIPSEC_FILTER_OBJECT * ppIpsecFilterObjects,
  950. DWORD dwNumFilterObjects,
  951. PIPSEC_FILTER_OBJECT * ppIpsecFilterObject
  952. )
  953. {
  954. DWORD i = 0;
  955. PIPSEC_FILTER_OBJECT pIpsecFilterObject = NULL;
  956. for (i = 0; i < dwNumFilterObjects; i++) {
  957. pIpsecFilterObject = *(ppIpsecFilterObjects + i);
  958. if (!_wcsicmp(pIpsecFilterObject->pszDistinguishedName,
  959. pIpsecNFAObject->pszIpsecFilterReference)) {
  960. *ppIpsecFilterObject = pIpsecFilterObject;
  961. return(0);
  962. }
  963. }
  964. *ppIpsecFilterObject = NULL;
  965. return(ERROR_NOT_FOUND);
  966. }
  967. DWORD
  968. FindIpsecNegPolObject(
  969. PIPSEC_NFA_OBJECT pIpsecNFAObject,
  970. PIPSEC_NEGPOL_OBJECT * ppIpsecNegPolObjects,
  971. DWORD dwNumNegPolObjects,
  972. PIPSEC_NEGPOL_OBJECT * ppIpsecNegPolObject
  973. )
  974. {
  975. DWORD i = 0;
  976. PIPSEC_NEGPOL_OBJECT pIpsecNegPolObject = NULL;
  977. for (i = 0; i < dwNumNegPolObjects; i++) {
  978. pIpsecNegPolObject = *(ppIpsecNegPolObjects + i);
  979. if (!_wcsicmp(pIpsecNegPolObject->pszDistinguishedName,
  980. pIpsecNFAObject->pszIpsecNegPolReference)) {
  981. *ppIpsecNegPolObject = pIpsecNegPolObject;
  982. return(0);
  983. }
  984. }
  985. *ppIpsecNegPolObject = NULL;
  986. return(ERROR_NOT_FOUND);
  987. }
  988. void
  989. FreeIpsecFilterData(
  990. PIPSEC_FILTER_DATA pIpsecFilterData
  991. )
  992. {
  993. DWORD dwNumFilterSpecs = 0;
  994. PIPSEC_FILTER_SPEC * ppIpsecFilterSpecs = NULL;
  995. DWORD i = 0;
  996. PIPSEC_FILTER_SPEC pIpsecFilterSpec = NULL;
  997. dwNumFilterSpecs = pIpsecFilterData->dwNumFilterSpecs;
  998. ppIpsecFilterSpecs = pIpsecFilterData->ppFilterSpecs;
  999. for (i = 0; i < dwNumFilterSpecs; i++) {
  1000. pIpsecFilterSpec = *(ppIpsecFilterSpecs + i);
  1001. if (pIpsecFilterSpec) {
  1002. if (pIpsecFilterSpec->pszSrcDNSName){
  1003. FreePolStr(pIpsecFilterSpec->pszSrcDNSName);
  1004. }
  1005. if (pIpsecFilterSpec->pszDestDNSName){
  1006. FreePolStr(pIpsecFilterSpec->pszDestDNSName);
  1007. }
  1008. if (pIpsecFilterSpec->pszDescription){
  1009. FreePolStr(pIpsecFilterSpec->pszDescription);
  1010. }
  1011. FreePolMem(pIpsecFilterSpec);
  1012. }
  1013. }
  1014. FreePolMem(ppIpsecFilterSpecs);
  1015. if (pIpsecFilterData->pszIpsecName) {
  1016. FreePolStr(pIpsecFilterData->pszIpsecName);
  1017. }
  1018. if (pIpsecFilterData->pszDescription) {
  1019. FreePolStr(pIpsecFilterData->pszDescription);
  1020. }
  1021. FreePolMem(pIpsecFilterData);
  1022. return;
  1023. }
  1024. void
  1025. FreeIpsecISAKMPData(
  1026. PIPSEC_ISAKMP_DATA pIpsecISAKMPData
  1027. )
  1028. {
  1029. if (pIpsecISAKMPData->pSecurityMethods) {
  1030. FreePolMem(pIpsecISAKMPData->pSecurityMethods);
  1031. }
  1032. FreePolMem(pIpsecISAKMPData);
  1033. return;
  1034. }
  1035. void
  1036. FreeIpsecNegPolData(
  1037. PIPSEC_NEGPOL_DATA pIpsecNegPolData
  1038. )
  1039. {
  1040. if (pIpsecNegPolData->pIpsecSecurityMethods){
  1041. FreePolMem(pIpsecNegPolData->pIpsecSecurityMethods);
  1042. }
  1043. if (pIpsecNegPolData->pszIpsecName) {
  1044. FreePolStr(pIpsecNegPolData->pszIpsecName);
  1045. }
  1046. if (pIpsecNegPolData->pszDescription) {
  1047. FreePolStr(pIpsecNegPolData->pszDescription);
  1048. }
  1049. FreePolMem(pIpsecNegPolData);
  1050. return;
  1051. }
  1052. void
  1053. FreeIpsecNFAData(
  1054. PIPSEC_NFA_DATA pIpsecNFAData
  1055. )
  1056. {
  1057. DWORD dwNumAuthMethods = 0;
  1058. PIPSEC_AUTH_METHOD * ppIpsecAuthMethods = NULL;
  1059. DWORD i = 0;
  1060. PIPSEC_AUTH_METHOD pIpsecAuthMethod = NULL;
  1061. ppIpsecAuthMethods = pIpsecNFAData->ppAuthMethods;
  1062. dwNumAuthMethods = pIpsecNFAData->dwAuthMethodCount;
  1063. for (i = 0; i < dwNumAuthMethods; i++) {
  1064. pIpsecAuthMethod = *(ppIpsecAuthMethods + i);
  1065. if (pIpsecAuthMethod) {
  1066. if (pIpsecAuthMethod->pszAuthMethod) {
  1067. FreePolStr(pIpsecAuthMethod->pszAuthMethod);
  1068. }
  1069. if (pIpsecAuthMethod->pAltAuthMethod) {
  1070. FreePolMem(pIpsecAuthMethod->pAltAuthMethod);
  1071. }
  1072. FreePolMem(pIpsecAuthMethod);
  1073. }
  1074. }
  1075. if (pIpsecNFAData->ppAuthMethods) {
  1076. FreePolMem(pIpsecNFAData->ppAuthMethods);
  1077. }
  1078. if (pIpsecNFAData->pszInterfaceName) {
  1079. FreePolStr(pIpsecNFAData->pszInterfaceName);
  1080. }
  1081. if (pIpsecNFAData->pszEndPointName) {
  1082. FreePolStr(pIpsecNFAData->pszEndPointName);
  1083. }
  1084. if (pIpsecNFAData->pIpsecFilterData) {
  1085. FreeIpsecFilterData(pIpsecNFAData->pIpsecFilterData);
  1086. }
  1087. if (pIpsecNFAData->pIpsecNegPolData) {
  1088. FreeIpsecNegPolData(pIpsecNFAData->pIpsecNegPolData);
  1089. }
  1090. if (pIpsecNFAData->pszIpsecName) {
  1091. FreePolStr(pIpsecNFAData->pszIpsecName);
  1092. }
  1093. if (pIpsecNFAData->pszDescription) {
  1094. FreePolStr(pIpsecNFAData->pszDescription);
  1095. }
  1096. FreePolMem(pIpsecNFAData);
  1097. }
  1098. void
  1099. FreeIpsecPolicyData(
  1100. PIPSEC_POLICY_DATA pIpsecPolicyData
  1101. )
  1102. {
  1103. DWORD i = 0;
  1104. DWORD dwNumNFACount = 0;
  1105. PIPSEC_NFA_DATA * ppIpsecNFAData = NULL;
  1106. PIPSEC_NFA_DATA pIpsecNFAData = NULL;
  1107. PIPSEC_ISAKMP_DATA pIpsecISAKMPData = NULL;
  1108. dwNumNFACount = pIpsecPolicyData->dwNumNFACount;
  1109. ppIpsecNFAData = pIpsecPolicyData->ppIpsecNFAData;
  1110. pIpsecISAKMPData = pIpsecPolicyData->pIpsecISAKMPData;
  1111. if (pIpsecISAKMPData) {
  1112. FreeIpsecISAKMPData(
  1113. pIpsecISAKMPData
  1114. );
  1115. }
  1116. for (i = 0; i < dwNumNFACount; i++) {
  1117. pIpsecNFAData = *(ppIpsecNFAData + i);
  1118. if (pIpsecNFAData) {
  1119. FreeIpsecNFAData(
  1120. pIpsecNFAData
  1121. );
  1122. }
  1123. }
  1124. if (pIpsecPolicyData->ppIpsecNFAData) {
  1125. FreePolMem(pIpsecPolicyData->ppIpsecNFAData);
  1126. }
  1127. if (pIpsecPolicyData->pszIpsecName) {
  1128. FreePolStr(pIpsecPolicyData->pszIpsecName);
  1129. }
  1130. if (pIpsecPolicyData->pszDescription) {
  1131. FreePolStr(pIpsecPolicyData->pszDescription);
  1132. }
  1133. if (pIpsecPolicyData->pRsopInfo) {
  1134. FreeRsopInfo(
  1135. pIpsecPolicyData->pRsopInfo
  1136. );
  1137. }
  1138. if (pIpsecPolicyData) {
  1139. FreePolMem(pIpsecPolicyData);
  1140. }
  1141. }
  1142. DWORD
  1143. CopyIpsecPolicyData(
  1144. PIPSEC_POLICY_DATA pIpsecPolicyData,
  1145. PIPSEC_POLICY_DATA * ppIpsecPolicyData
  1146. )
  1147. {
  1148. DWORD dwError = 0;
  1149. PIPSEC_POLICY_DATA pNewIpsecPolicyData = NULL;
  1150. DWORD dwNumberofRules = 0;
  1151. PIPSEC_NFA_DATA * ppIpsecNFAData = NULL;
  1152. PIPSEC_NFA_DATA pIpsecNFAData = NULL;
  1153. PIPSEC_NFA_DATA pNewIpsecNFAData = NULL;
  1154. PIPSEC_NFA_DATA * ppNewIpsecNFAData = NULL;
  1155. DWORD i = 0;
  1156. *ppIpsecPolicyData = NULL;
  1157. pNewIpsecPolicyData = (PIPSEC_POLICY_DATA) AllocPolMem(
  1158. sizeof(IPSEC_POLICY_DATA)
  1159. );
  1160. if (!pNewIpsecPolicyData) {
  1161. dwError = ERROR_OUTOFMEMORY;
  1162. BAIL_ON_WIN32_ERROR(dwError);
  1163. }
  1164. dwNumberofRules = pIpsecPolicyData->dwNumNFACount;
  1165. ppIpsecNFAData = pIpsecPolicyData->ppIpsecNFAData;
  1166. if (dwNumberofRules) {
  1167. ppNewIpsecNFAData = (PIPSEC_NFA_DATA *) AllocPolMem(
  1168. sizeof(PIPSEC_NFA_DATA)*
  1169. dwNumberofRules
  1170. );
  1171. if (!ppNewIpsecNFAData) {
  1172. dwError = ERROR_OUTOFMEMORY;
  1173. BAIL_ON_WIN32_ERROR(dwError);
  1174. }
  1175. }
  1176. for (i = 0; i < dwNumberofRules; i++) {
  1177. pIpsecNFAData = *(ppIpsecNFAData + i);
  1178. dwError = CopyIpsecNFAData(
  1179. pIpsecNFAData,
  1180. &pNewIpsecNFAData
  1181. );
  1182. if (dwError) {
  1183. pNewIpsecPolicyData->ppIpsecNFAData = ppNewIpsecNFAData;
  1184. pNewIpsecPolicyData->dwNumNFACount = i;
  1185. BAIL_ON_WIN32_ERROR(dwError);
  1186. }
  1187. *(ppNewIpsecNFAData + i) = pNewIpsecNFAData;
  1188. }
  1189. pNewIpsecPolicyData->ppIpsecNFAData = ppNewIpsecNFAData;
  1190. pNewIpsecPolicyData->dwNumNFACount = dwNumberofRules;
  1191. if (pIpsecPolicyData->pIpsecISAKMPData) {
  1192. dwError = CopyIpsecISAKMPData(
  1193. pIpsecPolicyData->pIpsecISAKMPData,
  1194. &pNewIpsecPolicyData->pIpsecISAKMPData
  1195. );
  1196. BAIL_ON_WIN32_ERROR(dwError);
  1197. }
  1198. pNewIpsecPolicyData->dwPollingInterval = pIpsecPolicyData->dwPollingInterval;
  1199. pNewIpsecPolicyData->dwWhenChanged = pIpsecPolicyData->dwWhenChanged;
  1200. pNewIpsecPolicyData->dwFlags = pIpsecPolicyData->dwFlags;
  1201. memcpy(
  1202. &(pNewIpsecPolicyData->PolicyIdentifier),
  1203. &(pIpsecPolicyData->PolicyIdentifier),
  1204. sizeof(GUID)
  1205. );
  1206. memcpy(
  1207. &(pNewIpsecPolicyData->ISAKMPIdentifier),
  1208. &(pIpsecPolicyData->ISAKMPIdentifier),
  1209. sizeof(GUID)
  1210. );
  1211. if (pIpsecPolicyData->pszIpsecName &&
  1212. *pIpsecPolicyData->pszIpsecName) {
  1213. pNewIpsecPolicyData->pszIpsecName = AllocPolStr(
  1214. pIpsecPolicyData->pszIpsecName
  1215. );
  1216. if (!pNewIpsecPolicyData->pszIpsecName) {
  1217. dwError = ERROR_OUTOFMEMORY;
  1218. BAIL_ON_WIN32_ERROR(dwError);
  1219. }
  1220. }
  1221. if (pIpsecPolicyData->pszDescription &&
  1222. *pIpsecPolicyData->pszDescription) {
  1223. pNewIpsecPolicyData->pszDescription = AllocPolStr(
  1224. pIpsecPolicyData->pszDescription
  1225. );
  1226. if (!pNewIpsecPolicyData->pszDescription) {
  1227. dwError = ERROR_OUTOFMEMORY;
  1228. BAIL_ON_WIN32_ERROR(dwError);
  1229. }
  1230. }
  1231. if (pIpsecPolicyData->pRsopInfo) {
  1232. pNewIpsecPolicyData->pRsopInfo = (PRSOP_INFO)AllocPolMem(
  1233. sizeof(RSOP_INFO)
  1234. );
  1235. if (!pNewIpsecPolicyData->pRsopInfo) {
  1236. dwError = ERROR_OUTOFMEMORY;
  1237. BAIL_ON_WIN32_ERROR(dwError);
  1238. }
  1239. dwError = DeepCpyRsopInfo(
  1240. pNewIpsecPolicyData->pRsopInfo,
  1241. pIpsecPolicyData->pRsopInfo
  1242. );
  1243. BAIL_ON_WIN32_ERROR(dwError);
  1244. }
  1245. *ppIpsecPolicyData = pNewIpsecPolicyData;
  1246. return (dwError);
  1247. error:
  1248. if (pNewIpsecPolicyData) {
  1249. FreeIpsecPolicyData(pNewIpsecPolicyData);
  1250. }
  1251. *ppIpsecPolicyData = NULL;
  1252. return (dwError);
  1253. }
  1254. DWORD
  1255. CopyIpsecNFAData(
  1256. PIPSEC_NFA_DATA pIpsecNFAData,
  1257. PIPSEC_NFA_DATA * ppIpsecNFAData
  1258. )
  1259. {
  1260. PIPSEC_NFA_DATA pNewIpsecNFAData = NULL;
  1261. DWORD dwError = 0;
  1262. DWORD i = 0;
  1263. DWORD dwAuthMethodCount = 0;
  1264. PIPSEC_AUTH_METHOD * ppAuthMethods = NULL;
  1265. PIPSEC_AUTH_METHOD * ppNewAuthMethods = NULL;
  1266. PIPSEC_AUTH_METHOD pAuthMethod = NULL;
  1267. PIPSEC_AUTH_METHOD pNewAuthMethod = NULL;
  1268. pNewIpsecNFAData = (PIPSEC_NFA_DATA) AllocPolMem(
  1269. sizeof(IPSEC_NFA_DATA)
  1270. );
  1271. if (!pNewIpsecNFAData) {
  1272. dwError = ERROR_OUTOFMEMORY;
  1273. BAIL_ON_WIN32_ERROR(dwError);
  1274. }
  1275. dwAuthMethodCount = pIpsecNFAData->dwAuthMethodCount;
  1276. ppAuthMethods = pIpsecNFAData->ppAuthMethods;
  1277. if (dwAuthMethodCount) {
  1278. ppNewAuthMethods = (PIPSEC_AUTH_METHOD *) AllocPolMem(
  1279. sizeof(PIPSEC_AUTH_METHOD)*
  1280. dwAuthMethodCount
  1281. );
  1282. if (!ppNewAuthMethods) {
  1283. dwError = ERROR_OUTOFMEMORY;
  1284. BAIL_ON_WIN32_ERROR(dwError);
  1285. }
  1286. }
  1287. for (i = 0; i < dwAuthMethodCount; i++) {
  1288. pAuthMethod = *(ppAuthMethods + i);
  1289. dwError = CopyIpsecAuthMethod(
  1290. pAuthMethod,
  1291. &pNewAuthMethod
  1292. );
  1293. if (dwError) {
  1294. pNewIpsecNFAData->ppAuthMethods = ppNewAuthMethods;
  1295. pNewIpsecNFAData->dwAuthMethodCount = i;
  1296. BAIL_ON_WIN32_ERROR(dwError);
  1297. }
  1298. *(ppNewAuthMethods + i) = pNewAuthMethod;
  1299. }
  1300. pNewIpsecNFAData->ppAuthMethods = ppNewAuthMethods;
  1301. pNewIpsecNFAData->dwAuthMethodCount = dwAuthMethodCount;
  1302. if (pIpsecNFAData->pszIpsecName && *pIpsecNFAData->pszIpsecName) {
  1303. pNewIpsecNFAData->pszIpsecName = AllocPolStr(
  1304. pIpsecNFAData->pszIpsecName
  1305. );
  1306. if (!(pNewIpsecNFAData->pszIpsecName)) {
  1307. dwError = ERROR_OUTOFMEMORY;
  1308. BAIL_ON_WIN32_ERROR(dwError);
  1309. }
  1310. }
  1311. if (pIpsecNFAData->pszDescription && *pIpsecNFAData->pszDescription) {
  1312. pNewIpsecNFAData->pszDescription = AllocPolStr(
  1313. pIpsecNFAData->pszDescription
  1314. );
  1315. if (!(pNewIpsecNFAData->pszDescription)) {
  1316. dwError = ERROR_OUTOFMEMORY;
  1317. BAIL_ON_WIN32_ERROR(dwError);
  1318. }
  1319. }
  1320. memcpy(
  1321. &(pNewIpsecNFAData->NFAIdentifier),
  1322. &(pIpsecNFAData->NFAIdentifier),
  1323. sizeof(GUID)
  1324. );
  1325. memcpy(
  1326. &(pNewIpsecNFAData->FilterIdentifier),
  1327. &(pIpsecNFAData->FilterIdentifier),
  1328. sizeof(GUID)
  1329. );
  1330. memcpy(
  1331. &(pNewIpsecNFAData->NegPolIdentifier),
  1332. &(pIpsecNFAData->NegPolIdentifier),
  1333. sizeof(GUID)
  1334. );
  1335. pNewIpsecNFAData->dwInterfaceType = pIpsecNFAData->dwInterfaceType;
  1336. if (pIpsecNFAData->pszInterfaceName && *pIpsecNFAData->pszInterfaceName) {
  1337. pNewIpsecNFAData->pszInterfaceName = AllocPolStr(
  1338. pIpsecNFAData->pszInterfaceName
  1339. );
  1340. if (!(pNewIpsecNFAData->pszInterfaceName)) {
  1341. dwError = ERROR_OUTOFMEMORY;
  1342. BAIL_ON_WIN32_ERROR(dwError);
  1343. }
  1344. }
  1345. pNewIpsecNFAData->dwTunnelIpAddr = pIpsecNFAData->dwTunnelIpAddr;
  1346. pNewIpsecNFAData->dwTunnelFlags = pIpsecNFAData->dwTunnelFlags;
  1347. pNewIpsecNFAData->dwActiveFlag = pIpsecNFAData->dwActiveFlag;
  1348. if (pIpsecNFAData->pszEndPointName && *pIpsecNFAData->pszEndPointName) {
  1349. pNewIpsecNFAData->pszEndPointName = AllocPolStr(
  1350. pIpsecNFAData->pszEndPointName
  1351. );
  1352. if (!(pNewIpsecNFAData->pszEndPointName)) {
  1353. dwError = ERROR_OUTOFMEMORY;
  1354. BAIL_ON_WIN32_ERROR(dwError);
  1355. }
  1356. }
  1357. if (pIpsecNFAData->pIpsecFilterData) {
  1358. dwError = CopyIpsecFilterData(
  1359. pIpsecNFAData->pIpsecFilterData,
  1360. &pNewIpsecNFAData->pIpsecFilterData
  1361. );
  1362. BAIL_ON_WIN32_ERROR(dwError);
  1363. }
  1364. if (pIpsecNFAData->pIpsecNegPolData) {
  1365. dwError = CopyIpsecNegPolData(
  1366. pIpsecNFAData->pIpsecNegPolData,
  1367. &pNewIpsecNFAData->pIpsecNegPolData
  1368. );
  1369. BAIL_ON_WIN32_ERROR(dwError);
  1370. }
  1371. pNewIpsecNFAData->dwWhenChanged = pIpsecNFAData->dwWhenChanged;
  1372. pNewIpsecNFAData->dwFlags = pIpsecNFAData->dwFlags;
  1373. *ppIpsecNFAData = pNewIpsecNFAData;
  1374. return(ERROR_SUCCESS);
  1375. error:
  1376. if (pNewIpsecNFAData) {
  1377. FreeIpsecNFAData(pNewIpsecNFAData);
  1378. }
  1379. *ppIpsecNFAData = NULL;
  1380. return (dwError);
  1381. }
  1382. DWORD
  1383. CopyIpsecAuthMethod(
  1384. PIPSEC_AUTH_METHOD pAuthMethod,
  1385. PIPSEC_AUTH_METHOD * ppAuthMethod
  1386. )
  1387. {
  1388. DWORD dwError = 0;
  1389. PIPSEC_AUTH_METHOD pNewAuthMethod = NULL;
  1390. pNewAuthMethod = (PIPSEC_AUTH_METHOD) AllocPolMem(
  1391. sizeof(IPSEC_AUTH_METHOD)
  1392. );
  1393. if (!pNewAuthMethod) {
  1394. dwError = ERROR_OUTOFMEMORY;
  1395. BAIL_ON_WIN32_ERROR(dwError);
  1396. }
  1397. pNewAuthMethod->dwAuthType = pAuthMethod->dwAuthType;
  1398. pNewAuthMethod->dwAuthLen = pAuthMethod->dwAuthLen;
  1399. if (pAuthMethod->pszAuthMethod) {
  1400. pNewAuthMethod->pszAuthMethod = AllocPolStr(
  1401. pAuthMethod->pszAuthMethod
  1402. );
  1403. if (!(pNewAuthMethod->pszAuthMethod)) {
  1404. dwError = ERROR_OUTOFMEMORY;
  1405. BAIL_ON_WIN32_ERROR(dwError);
  1406. }
  1407. }
  1408. pNewAuthMethod->dwAltAuthLen = 0;
  1409. pNewAuthMethod->pAltAuthMethod = NULL;
  1410. if (pAuthMethod->dwAltAuthLen && pAuthMethod->pAltAuthMethod) {
  1411. pNewAuthMethod->pAltAuthMethod = AllocPolMem(
  1412. pAuthMethod->dwAltAuthLen
  1413. );
  1414. if (!(pNewAuthMethod->pAltAuthMethod)) {
  1415. dwError = ERROR_OUTOFMEMORY;
  1416. BAIL_ON_WIN32_ERROR(dwError);
  1417. }
  1418. memcpy(
  1419. pNewAuthMethod->pAltAuthMethod,
  1420. pAuthMethod->pAltAuthMethod,
  1421. pAuthMethod->dwAltAuthLen
  1422. );
  1423. pNewAuthMethod->dwAltAuthLen = pAuthMethod->dwAltAuthLen;
  1424. }
  1425. pNewAuthMethod->dwAuthFlags = pAuthMethod->dwAuthFlags;
  1426. *ppAuthMethod = pNewAuthMethod;
  1427. return (ERROR_SUCCESS);
  1428. error:
  1429. if (pNewAuthMethod) {
  1430. if (pNewAuthMethod->pszAuthMethod) {
  1431. FreePolStr(pNewAuthMethod->pszAuthMethod);
  1432. }
  1433. if (pNewAuthMethod->pAltAuthMethod) {
  1434. FreePolMem(pNewAuthMethod->pAltAuthMethod);
  1435. }
  1436. FreePolMem(pNewAuthMethod);
  1437. }
  1438. *ppAuthMethod = NULL;
  1439. return (dwError);
  1440. }
  1441. DWORD
  1442. CopyIpsecISAKMPData(
  1443. PIPSEC_ISAKMP_DATA pIpsecISAKMPData,
  1444. PIPSEC_ISAKMP_DATA * ppIpsecISAKMPData
  1445. )
  1446. {
  1447. DWORD dwError = 0;
  1448. PIPSEC_ISAKMP_DATA pNewIpsecISAKMPData = NULL;
  1449. DWORD dwNumISAKMPSecurityMethods = 0;
  1450. pNewIpsecISAKMPData = (PIPSEC_ISAKMP_DATA) AllocPolMem(
  1451. sizeof(IPSEC_ISAKMP_DATA)
  1452. );
  1453. if (!pNewIpsecISAKMPData) {
  1454. dwError = ERROR_OUTOFMEMORY;
  1455. BAIL_ON_WIN32_ERROR(dwError);
  1456. }
  1457. memcpy(
  1458. &(pNewIpsecISAKMPData->ISAKMPIdentifier),
  1459. &(pIpsecISAKMPData->ISAKMPIdentifier),
  1460. sizeof(GUID)
  1461. );
  1462. memcpy(
  1463. &(pNewIpsecISAKMPData->ISAKMPPolicy),
  1464. &(pIpsecISAKMPData->ISAKMPPolicy),
  1465. sizeof(ISAKMP_POLICY)
  1466. );
  1467. dwNumISAKMPSecurityMethods =
  1468. pIpsecISAKMPData->dwNumISAKMPSecurityMethods;
  1469. pNewIpsecISAKMPData->dwWhenChanged =
  1470. pIpsecISAKMPData->dwWhenChanged;
  1471. pNewIpsecISAKMPData->dwFlags =
  1472. pIpsecISAKMPData->dwFlags;
  1473. if (pIpsecISAKMPData->pSecurityMethods) {
  1474. pNewIpsecISAKMPData->pSecurityMethods = (PCRYPTO_BUNDLE) AllocPolMem(
  1475. sizeof(CRYPTO_BUNDLE) *
  1476. dwNumISAKMPSecurityMethods
  1477. );
  1478. if (!(pNewIpsecISAKMPData->pSecurityMethods)) {
  1479. dwError = ERROR_OUTOFMEMORY;
  1480. BAIL_ON_WIN32_ERROR(dwError);
  1481. }
  1482. memcpy(
  1483. pNewIpsecISAKMPData->pSecurityMethods,
  1484. pIpsecISAKMPData->pSecurityMethods,
  1485. sizeof(CRYPTO_BUNDLE)*dwNumISAKMPSecurityMethods
  1486. );
  1487. pNewIpsecISAKMPData->dwNumISAKMPSecurityMethods =
  1488. pIpsecISAKMPData->dwNumISAKMPSecurityMethods;
  1489. }
  1490. else {
  1491. pNewIpsecISAKMPData->pSecurityMethods = NULL;
  1492. pNewIpsecISAKMPData->dwNumISAKMPSecurityMethods = 0;
  1493. }
  1494. *ppIpsecISAKMPData = pNewIpsecISAKMPData;
  1495. return(ERROR_SUCCESS);
  1496. error:
  1497. *ppIpsecISAKMPData = NULL;
  1498. return (dwError);
  1499. }
  1500. DWORD
  1501. CopyIpsecFilterData(
  1502. PIPSEC_FILTER_DATA pIpsecFilterData,
  1503. PIPSEC_FILTER_DATA * ppIpsecFilterData
  1504. )
  1505. {
  1506. DWORD dwError = 0;
  1507. DWORD i = 0;
  1508. PIPSEC_FILTER_DATA pNewIpsecFilterData = NULL;
  1509. DWORD dwNumFilterSpecs = 0;
  1510. PIPSEC_FILTER_SPEC * ppFilterSpecs = NULL;
  1511. PIPSEC_FILTER_SPEC * ppNewFilterSpecs = NULL;
  1512. PIPSEC_FILTER_SPEC pFilterSpecs = NULL;
  1513. PIPSEC_FILTER_SPEC pNewFilterSpecs = NULL;
  1514. pNewIpsecFilterData = (PIPSEC_FILTER_DATA) AllocPolMem(
  1515. sizeof(IPSEC_FILTER_DATA)
  1516. );
  1517. if (!pNewIpsecFilterData) {
  1518. dwError = ERROR_OUTOFMEMORY;
  1519. BAIL_ON_WIN32_ERROR(dwError);
  1520. }
  1521. dwNumFilterSpecs = pIpsecFilterData->dwNumFilterSpecs;
  1522. ppFilterSpecs = pIpsecFilterData->ppFilterSpecs;
  1523. if (dwNumFilterSpecs) {
  1524. ppNewFilterSpecs = (PIPSEC_FILTER_SPEC *) AllocPolMem(
  1525. sizeof(PIPSEC_FILTER_SPEC)*
  1526. dwNumFilterSpecs
  1527. );
  1528. if (!ppNewFilterSpecs) {
  1529. dwError = ERROR_OUTOFMEMORY;
  1530. BAIL_ON_WIN32_ERROR(dwError);
  1531. }
  1532. }
  1533. for (i = 0; i < dwNumFilterSpecs; i++) {
  1534. pFilterSpecs = *(ppFilterSpecs + i);
  1535. dwError = CopyIpsecFilterSpec(
  1536. pFilterSpecs,
  1537. &pNewFilterSpecs
  1538. );
  1539. if (dwError) {
  1540. pNewIpsecFilterData->ppFilterSpecs = ppNewFilterSpecs;
  1541. pNewIpsecFilterData->dwNumFilterSpecs = i;
  1542. BAIL_ON_WIN32_ERROR(dwError);
  1543. }
  1544. *(ppNewFilterSpecs + i) = pNewFilterSpecs;
  1545. }
  1546. pNewIpsecFilterData->ppFilterSpecs = ppNewFilterSpecs;
  1547. pNewIpsecFilterData->dwNumFilterSpecs = dwNumFilterSpecs;
  1548. if (pIpsecFilterData->pszIpsecName && *pIpsecFilterData->pszIpsecName) {
  1549. pNewIpsecFilterData->pszIpsecName = AllocPolStr(
  1550. pIpsecFilterData->pszIpsecName
  1551. );
  1552. if (!(pNewIpsecFilterData->pszIpsecName)) {
  1553. dwError = ERROR_OUTOFMEMORY;
  1554. BAIL_ON_WIN32_ERROR(dwError);
  1555. }
  1556. }
  1557. if (pIpsecFilterData->pszDescription && *pIpsecFilterData->pszDescription) {
  1558. pNewIpsecFilterData->pszDescription = AllocPolStr(
  1559. pIpsecFilterData->pszDescription
  1560. );
  1561. if (!(pNewIpsecFilterData->pszDescription)) {
  1562. dwError = ERROR_OUTOFMEMORY;
  1563. BAIL_ON_WIN32_ERROR(dwError);
  1564. }
  1565. }
  1566. memcpy(
  1567. &(pNewIpsecFilterData->FilterIdentifier),
  1568. &(pIpsecFilterData->FilterIdentifier),
  1569. sizeof(GUID)
  1570. );
  1571. pNewIpsecFilterData->dwWhenChanged = pIpsecFilterData->dwWhenChanged;
  1572. pNewIpsecFilterData->dwFlags = pIpsecFilterData->dwFlags;
  1573. *ppIpsecFilterData = pNewIpsecFilterData;
  1574. return(ERROR_SUCCESS);
  1575. error:
  1576. if (pNewIpsecFilterData) {
  1577. FreeIpsecFilterData(pNewIpsecFilterData);
  1578. }
  1579. *ppIpsecFilterData = NULL;
  1580. return (dwError);
  1581. }
  1582. DWORD
  1583. CopyIpsecFilterSpec(
  1584. PIPSEC_FILTER_SPEC pFilterSpecs,
  1585. PIPSEC_FILTER_SPEC * ppFilterSpecs
  1586. )
  1587. {
  1588. DWORD dwError = 0;
  1589. PIPSEC_FILTER_SPEC pNewFilterSpecs = NULL;
  1590. pNewFilterSpecs = (PIPSEC_FILTER_SPEC) AllocPolMem(
  1591. sizeof(IPSEC_FILTER_SPEC)
  1592. );
  1593. if (!pNewFilterSpecs) {
  1594. dwError = ERROR_OUTOFMEMORY;
  1595. BAIL_ON_WIN32_ERROR(dwError);
  1596. }
  1597. if (pFilterSpecs->pszSrcDNSName) {
  1598. pNewFilterSpecs->pszSrcDNSName = AllocPolStr(
  1599. pFilterSpecs->pszSrcDNSName
  1600. );
  1601. if (!(pNewFilterSpecs->pszSrcDNSName)) {
  1602. dwError = ERROR_OUTOFMEMORY;
  1603. BAIL_ON_WIN32_ERROR(dwError);
  1604. }
  1605. }
  1606. if (pFilterSpecs->pszDestDNSName) {
  1607. pNewFilterSpecs->pszDestDNSName = AllocPolStr(
  1608. pFilterSpecs->pszDestDNSName
  1609. );
  1610. if (!(pNewFilterSpecs->pszDestDNSName)) {
  1611. dwError = ERROR_OUTOFMEMORY;
  1612. BAIL_ON_WIN32_ERROR(dwError);
  1613. }
  1614. }
  1615. if (pFilterSpecs->pszDescription) {
  1616. pNewFilterSpecs->pszDescription = AllocPolStr(
  1617. pFilterSpecs->pszDescription
  1618. );
  1619. if (!(pNewFilterSpecs->pszDescription)) {
  1620. dwError = ERROR_OUTOFMEMORY;
  1621. BAIL_ON_WIN32_ERROR(dwError);
  1622. }
  1623. }
  1624. memcpy(
  1625. &(pNewFilterSpecs->FilterSpecGUID),
  1626. &(pFilterSpecs->FilterSpecGUID),
  1627. sizeof(GUID)
  1628. );
  1629. pNewFilterSpecs->dwMirrorFlag = pFilterSpecs->dwMirrorFlag;
  1630. memcpy(
  1631. &(pNewFilterSpecs->Filter),
  1632. &(pFilterSpecs->Filter),
  1633. sizeof(IPSEC_FILTER)
  1634. );
  1635. *ppFilterSpecs = pNewFilterSpecs;
  1636. return(ERROR_SUCCESS);
  1637. error:
  1638. if (pNewFilterSpecs) {
  1639. if (pNewFilterSpecs->pszSrcDNSName){
  1640. FreePolStr(pNewFilterSpecs->pszSrcDNSName);
  1641. }
  1642. if (pNewFilterSpecs->pszDestDNSName){
  1643. FreePolStr(pNewFilterSpecs->pszDestDNSName);
  1644. }
  1645. if (pNewFilterSpecs->pszDescription){
  1646. FreePolStr(pNewFilterSpecs->pszDescription);
  1647. }
  1648. FreePolMem(pNewFilterSpecs);
  1649. }
  1650. *ppFilterSpecs = NULL;
  1651. return (dwError);
  1652. }
  1653. DWORD
  1654. CopyIpsecNegPolData(
  1655. PIPSEC_NEGPOL_DATA pIpsecNegPolData,
  1656. PIPSEC_NEGPOL_DATA * ppIpsecNegPolData
  1657. )
  1658. {
  1659. DWORD dwNumSecurityOffers = 0;
  1660. PIPSEC_NEGPOL_DATA pNewIpsecNegPolData = NULL;
  1661. DWORD dwError = 0;
  1662. pNewIpsecNegPolData = (PIPSEC_NEGPOL_DATA) AllocPolMem(
  1663. sizeof(IPSEC_NEGPOL_DATA)
  1664. );
  1665. if (!pNewIpsecNegPolData) {
  1666. dwError = ERROR_OUTOFMEMORY;
  1667. BAIL_ON_WIN32_ERROR(dwError);
  1668. }
  1669. dwNumSecurityOffers = pIpsecNegPolData->dwSecurityMethodCount;
  1670. if (dwNumSecurityOffers) {
  1671. pNewIpsecNegPolData->pIpsecSecurityMethods = (PIPSEC_SECURITY_METHOD) AllocPolMem(
  1672. sizeof(IPSEC_SECURITY_METHOD)*dwNumSecurityOffers
  1673. );
  1674. if (!(pNewIpsecNegPolData->pIpsecSecurityMethods)) {
  1675. dwError = ERROR_OUTOFMEMORY;
  1676. BAIL_ON_WIN32_ERROR(dwError);
  1677. }
  1678. memcpy(
  1679. (pNewIpsecNegPolData->pIpsecSecurityMethods),
  1680. (pIpsecNegPolData->pIpsecSecurityMethods),
  1681. sizeof(IPSEC_SECURITY_METHOD)*dwNumSecurityOffers
  1682. );
  1683. pNewIpsecNegPolData->dwSecurityMethodCount = dwNumSecurityOffers;
  1684. }
  1685. else {
  1686. pNewIpsecNegPolData->dwSecurityMethodCount = 0;
  1687. pNewIpsecNegPolData->pIpsecSecurityMethods = NULL;
  1688. }
  1689. if (pIpsecNegPolData->pszIpsecName && *pIpsecNegPolData->pszIpsecName) {
  1690. pNewIpsecNegPolData->pszIpsecName = AllocPolStr(
  1691. pIpsecNegPolData->pszIpsecName
  1692. );
  1693. if (!(pNewIpsecNegPolData->pszIpsecName)) {
  1694. dwError = ERROR_OUTOFMEMORY;
  1695. BAIL_ON_WIN32_ERROR(dwError);
  1696. }
  1697. }
  1698. if (pIpsecNegPolData->pszDescription && *pIpsecNegPolData->pszDescription) {
  1699. pNewIpsecNegPolData->pszDescription = AllocPolStr(
  1700. pIpsecNegPolData->pszDescription
  1701. );
  1702. if (!(pNewIpsecNegPolData->pszDescription)) {
  1703. dwError = ERROR_OUTOFMEMORY;
  1704. BAIL_ON_WIN32_ERROR(dwError);
  1705. }
  1706. }
  1707. //
  1708. // Convert the ipsecID to its GUID format
  1709. //
  1710. memcpy(
  1711. &(pNewIpsecNegPolData->NegPolIdentifier),
  1712. &(pIpsecNegPolData->NegPolIdentifier),
  1713. sizeof(GUID)
  1714. );
  1715. memcpy(
  1716. &(pNewIpsecNegPolData->NegPolAction),
  1717. &(pIpsecNegPolData->NegPolAction),
  1718. sizeof(GUID)
  1719. );
  1720. memcpy(
  1721. &(pNewIpsecNegPolData->NegPolType),
  1722. &(pIpsecNegPolData->NegPolType),
  1723. sizeof(GUID)
  1724. );
  1725. pNewIpsecNegPolData->dwWhenChanged = pIpsecNegPolData->dwWhenChanged;
  1726. pNewIpsecNegPolData->dwFlags = pIpsecNegPolData->dwFlags;
  1727. *ppIpsecNegPolData = pNewIpsecNegPolData;
  1728. return (0);
  1729. error:
  1730. if (pNewIpsecNegPolData) {
  1731. FreeIpsecNegPolData(pNewIpsecNegPolData);
  1732. }
  1733. *ppIpsecNegPolData = NULL;
  1734. return(dwError);
  1735. }
  1736. DWORD
  1737. UnmarshallFilterSpec(
  1738. LPBYTE pMem,
  1739. PIPSEC_FILTER_SPEC * ppIpsecFilterSpec,
  1740. PDWORD pdwNumBytesAdvanced
  1741. )
  1742. {
  1743. DWORD dwSrcDNSNameLen = 0;
  1744. LPWSTR pszSrcDNSName = NULL;
  1745. DWORD dwDestDNSNameLen = 0;
  1746. LPWSTR pszDestDNSName = NULL;
  1747. DWORD dwDescriptionLen = 0;
  1748. LPWSTR pszDescription = NULL;
  1749. GUID FilterSpecGUID;
  1750. DWORD dwMirrorFlag = 0;
  1751. IPSEC_FILTER ipsecFilter;
  1752. PIPSEC_FILTER_SPEC pIpsecFilterSpec = NULL;
  1753. DWORD dwNumBytesAdvanced = 0;
  1754. DWORD dwError = 0;
  1755. *ppIpsecFilterSpec = NULL;
  1756. *pdwNumBytesAdvanced = 0;
  1757. memcpy((LPBYTE)&dwSrcDNSNameLen, pMem, sizeof(DWORD));
  1758. pMem += sizeof(DWORD);
  1759. dwNumBytesAdvanced += sizeof(DWORD);
  1760. if (dwSrcDNSNameLen) {
  1761. pszSrcDNSName = AllocPolStr((LPWSTR)pMem);
  1762. if (!pszSrcDNSName) {
  1763. dwError = ERROR_OUTOFMEMORY;
  1764. BAIL_ON_WIN32_ERROR(dwError);
  1765. }
  1766. }
  1767. pMem += dwSrcDNSNameLen;
  1768. dwNumBytesAdvanced += dwSrcDNSNameLen;
  1769. memcpy((LPBYTE)&dwDestDNSNameLen, pMem, sizeof(DWORD));
  1770. pMem += sizeof(DWORD);
  1771. dwNumBytesAdvanced += sizeof(DWORD);
  1772. if (dwDestDNSNameLen) {
  1773. pszDestDNSName = AllocPolStr((LPWSTR)pMem);
  1774. if (!pszDestDNSName) {
  1775. dwError = ERROR_OUTOFMEMORY;
  1776. BAIL_ON_WIN32_ERROR(dwError);
  1777. }
  1778. }
  1779. pMem += dwDestDNSNameLen;
  1780. dwNumBytesAdvanced += dwDestDNSNameLen;
  1781. memcpy((LPBYTE)&dwDescriptionLen, pMem, sizeof(DWORD));
  1782. pMem += sizeof(DWORD);
  1783. dwNumBytesAdvanced += sizeof(DWORD);
  1784. if (dwDescriptionLen) {
  1785. pszDescription = AllocPolStr((LPWSTR)pMem);
  1786. if (!pszDescription) {
  1787. dwError = ERROR_OUTOFMEMORY;
  1788. BAIL_ON_WIN32_ERROR(dwError);
  1789. }
  1790. }
  1791. pMem += dwDescriptionLen;
  1792. dwNumBytesAdvanced += dwDescriptionLen;
  1793. memcpy((LPBYTE)&FilterSpecGUID, pMem, sizeof(GUID));
  1794. pMem += sizeof(GUID);
  1795. dwNumBytesAdvanced += sizeof(GUID);
  1796. memcpy((LPBYTE)&dwMirrorFlag, pMem, sizeof(DWORD));
  1797. pMem += sizeof(DWORD);
  1798. dwNumBytesAdvanced += sizeof(DWORD);
  1799. memcpy((LPBYTE)&ipsecFilter, pMem, sizeof(IPSEC_FILTER));
  1800. pIpsecFilterSpec = (PIPSEC_FILTER_SPEC)AllocPolMem(
  1801. sizeof(IPSEC_FILTER_SPEC)
  1802. );
  1803. if (!pIpsecFilterSpec) {
  1804. dwError = ERROR_OUTOFMEMORY;
  1805. BAIL_ON_WIN32_ERROR(dwError);
  1806. }
  1807. pMem += sizeof(IPSEC_FILTER);
  1808. dwNumBytesAdvanced += sizeof(IPSEC_FILTER);
  1809. pIpsecFilterSpec->pszSrcDNSName = pszSrcDNSName;
  1810. pIpsecFilterSpec->pszDestDNSName = pszDestDNSName;
  1811. pIpsecFilterSpec->pszDescription = pszDescription;
  1812. pIpsecFilterSpec->dwMirrorFlag = dwMirrorFlag;
  1813. memcpy((LPBYTE)&pIpsecFilterSpec->FilterSpecGUID, &FilterSpecGUID, sizeof(GUID));
  1814. memcpy((LPBYTE)&pIpsecFilterSpec->Filter, &ipsecFilter, sizeof(IPSEC_FILTER));
  1815. *ppIpsecFilterSpec = pIpsecFilterSpec;
  1816. *pdwNumBytesAdvanced = dwNumBytesAdvanced;
  1817. return(dwError);
  1818. error:
  1819. if (pszSrcDNSName) {
  1820. FreePolStr(pszSrcDNSName);
  1821. }
  1822. if (pszDestDNSName) {
  1823. FreePolStr(pszDestDNSName);
  1824. }
  1825. if (pszDescription) {
  1826. FreePolStr(pszDescription);
  1827. }
  1828. *ppIpsecFilterSpec = NULL;
  1829. *pdwNumBytesAdvanced = 0;
  1830. return(dwError);
  1831. }
  1832. DWORD
  1833. UnmarshallAuthMethods(
  1834. LPBYTE pMem,
  1835. PIPSEC_AUTH_METHOD * ppIpsecAuthMethod,
  1836. PDWORD pdwNumBytesAdvanced
  1837. )
  1838. {
  1839. DWORD dwError = 0;
  1840. DWORD dwAuthType = 0;
  1841. DWORD dwAuthLen = 0;
  1842. LPWSTR pszAuthMethod = NULL;
  1843. PIPSEC_AUTH_METHOD pIpsecAuthMethod = NULL;
  1844. DWORD dwNumBytesAdvanced = 0;
  1845. pIpsecAuthMethod = (PIPSEC_AUTH_METHOD)AllocPolMem(
  1846. sizeof(IPSEC_AUTH_METHOD)
  1847. );
  1848. if (!pIpsecAuthMethod) {
  1849. dwError = ERROR_OUTOFMEMORY;
  1850. BAIL_ON_WIN32_ERROR(dwError);
  1851. }
  1852. memcpy((LPBYTE)&dwAuthType, pMem, sizeof(DWORD));
  1853. pMem += sizeof(DWORD);
  1854. dwNumBytesAdvanced += sizeof(DWORD);
  1855. memcpy((LPBYTE)&dwAuthLen, pMem, sizeof(DWORD));
  1856. pMem += sizeof(DWORD);
  1857. dwNumBytesAdvanced += sizeof(DWORD);
  1858. if (dwAuthLen) {
  1859. pszAuthMethod = AllocPolStr((LPWSTR)pMem);
  1860. if (!pszAuthMethod) {
  1861. dwError = ERROR_OUTOFMEMORY;
  1862. BAIL_ON_WIN32_ERROR(dwError);
  1863. }
  1864. }
  1865. pMem += dwAuthLen;
  1866. dwNumBytesAdvanced += dwAuthLen;
  1867. //
  1868. // Unmarshall parameters.
  1869. //
  1870. pIpsecAuthMethod->dwAuthType = dwAuthType;
  1871. pIpsecAuthMethod->dwAuthLen = (dwAuthLen - 2)/2;
  1872. pIpsecAuthMethod->pszAuthMethod = pszAuthMethod;
  1873. pIpsecAuthMethod->dwAltAuthLen = 0;
  1874. pIpsecAuthMethod->pAltAuthMethod = NULL;
  1875. *ppIpsecAuthMethod = pIpsecAuthMethod;
  1876. *pdwNumBytesAdvanced = dwNumBytesAdvanced;
  1877. return (dwError);
  1878. error:
  1879. if (pszAuthMethod) {
  1880. FreePolStr(pszAuthMethod);
  1881. }
  1882. if (pIpsecAuthMethod) {
  1883. FreePolMem(pIpsecAuthMethod);
  1884. }
  1885. *ppIpsecAuthMethod = NULL;
  1886. *pdwNumBytesAdvanced = 0;
  1887. return (dwError);
  1888. }
  1889. DWORD
  1890. UnmarshallAltAuthMethods(
  1891. LPBYTE pMem,
  1892. PIPSEC_AUTH_METHOD pIpsecAuthMethod,
  1893. PDWORD pdwNumBytesAdvanced
  1894. )
  1895. {
  1896. DWORD dwError = 0;
  1897. DWORD dwAuthType = 0;
  1898. DWORD dwAuthLen = 0;
  1899. PBYTE pAltAuthMethod = NULL;
  1900. DWORD dwNumBytesAdvanced = 0;
  1901. memcpy((LPBYTE)&dwAuthType, pMem, sizeof(DWORD));
  1902. pMem += sizeof(DWORD);
  1903. dwNumBytesAdvanced += sizeof(DWORD);
  1904. memcpy((LPBYTE)&dwAuthLen, pMem, sizeof(DWORD));
  1905. pMem += sizeof(DWORD);
  1906. dwNumBytesAdvanced += sizeof(DWORD);
  1907. if (dwAuthLen) {
  1908. pAltAuthMethod = (PBYTE) AllocPolMem(dwAuthLen);
  1909. if (!pAltAuthMethod) {
  1910. dwError = ERROR_OUTOFMEMORY;
  1911. BAIL_ON_WIN32_ERROR(dwError);
  1912. }
  1913. memcpy(pAltAuthMethod, pMem, dwAuthLen);
  1914. }
  1915. pMem += dwAuthLen;
  1916. dwNumBytesAdvanced += dwAuthLen;
  1917. pIpsecAuthMethod->dwAltAuthLen = dwAuthLen;
  1918. pIpsecAuthMethod->pAltAuthMethod = pAltAuthMethod;
  1919. *pdwNumBytesAdvanced = dwNumBytesAdvanced;
  1920. return (dwError);
  1921. error:
  1922. if (pAltAuthMethod) {
  1923. FreePolMem(pAltAuthMethod);
  1924. }
  1925. pIpsecAuthMethod->dwAltAuthLen = 0;
  1926. pIpsecAuthMethod->pAltAuthMethod = NULL;
  1927. *pdwNumBytesAdvanced = 0;
  1928. return (dwError);
  1929. }
  1930. void
  1931. FreeRsopInfo(
  1932. PRSOP_INFO pRsopInfo
  1933. )
  1934. {
  1935. if (pRsopInfo) {
  1936. FreePolStr(pRsopInfo->pszCreationtime);
  1937. FreePolStr(pRsopInfo->pszID);
  1938. FreePolStr(pRsopInfo->pszName);
  1939. FreePolStr(pRsopInfo->pszGPOID);
  1940. FreePolStr(pRsopInfo->pszSOMID);
  1941. }
  1942. }
  1943. void
  1944. FreeMulIpsecFilterData(
  1945. PIPSEC_FILTER_DATA * ppIpsecFilterData,
  1946. DWORD dwNumFilterObjects
  1947. )
  1948. {
  1949. DWORD i = 0;
  1950. PIPSEC_FILTER_DATA pIpsecFilterData = NULL;
  1951. if (!ppIpsecFilterData) {
  1952. return;
  1953. }
  1954. for (i = 0; i < dwNumFilterObjects; i++) {
  1955. pIpsecFilterData = *(ppIpsecFilterData + i);
  1956. if (pIpsecFilterData) {
  1957. FreeIpsecFilterData(pIpsecFilterData);
  1958. }
  1959. }
  1960. FreePolMem(ppIpsecFilterData);
  1961. return;
  1962. }
  1963. void
  1964. FreeMulIpsecNegPolData(
  1965. PIPSEC_NEGPOL_DATA * ppIpsecNegPolData,
  1966. DWORD dwNumNegPolObjects
  1967. )
  1968. {
  1969. DWORD i = 0;
  1970. PIPSEC_NEGPOL_DATA pIpsecNegPolData = NULL;
  1971. if (!ppIpsecNegPolData) {
  1972. return;
  1973. }
  1974. for (i = 0; i < dwNumNegPolObjects; i++) {
  1975. pIpsecNegPolData = *(ppIpsecNegPolData + i);
  1976. if (pIpsecNegPolData) {
  1977. FreeIpsecNegPolData(pIpsecNegPolData);
  1978. }
  1979. }
  1980. FreePolMem(ppIpsecNegPolData);
  1981. return;
  1982. }
  1983. void
  1984. FreeMulIpsecPolicyData(
  1985. PIPSEC_POLICY_DATA * ppIpsecPolicyData,
  1986. DWORD dwNumPolicyObjects
  1987. )
  1988. {
  1989. DWORD i = 0;
  1990. PIPSEC_POLICY_DATA pIpsecPolicyData = NULL;
  1991. if (!ppIpsecPolicyData) {
  1992. return;
  1993. }
  1994. for (i = 0; i < dwNumPolicyObjects; i++) {
  1995. pIpsecPolicyData = *(ppIpsecPolicyData + i);
  1996. if (pIpsecPolicyData) {
  1997. FreeIpsecPolicyData(pIpsecPolicyData);
  1998. }
  1999. }
  2000. FreePolMem(ppIpsecPolicyData);
  2001. return;
  2002. }
  2003. void
  2004. FreeMulIpsecNFAData(
  2005. PIPSEC_NFA_DATA * ppIpsecNFAData,
  2006. DWORD dwNumNFAObjects
  2007. )
  2008. {
  2009. DWORD i = 0;
  2010. PIPSEC_NFA_DATA pIpsecNFAData = NULL;
  2011. if (!ppIpsecNFAData) {
  2012. return;
  2013. }
  2014. for (i = 0; i < dwNumNFAObjects; i++) {
  2015. pIpsecNFAData = *(ppIpsecNFAData + i);
  2016. if (pIpsecNFAData) {
  2017. FreeIpsecNFAData(pIpsecNFAData);
  2018. }
  2019. }
  2020. FreePolMem(ppIpsecNFAData);
  2021. return;
  2022. }
  2023. DWORD
  2024. GenGUIDFromRegFilterReference(
  2025. LPWSTR pszIpsecFilterReference,
  2026. GUID * FilterIdentifier
  2027. )
  2028. {
  2029. DWORD dwError = 0;
  2030. LPWSTR pszGuid = NULL;
  2031. if (pszIpsecFilterReference) {
  2032. pszGuid = wcschr(pszIpsecFilterReference, L'{');
  2033. if (!pszGuid) {
  2034. dwError = ERROR_INVALID_DATA;
  2035. return (dwError);
  2036. }
  2037. wGUIDFromString(pszGuid, FilterIdentifier);
  2038. }else {
  2039. memset(FilterIdentifier, 0, sizeof(GUID));
  2040. }
  2041. return(dwError);
  2042. }
  2043. DWORD
  2044. GenGUIDFromRegNegPolReference(
  2045. LPWSTR pszIpsecNegPolReference,
  2046. GUID * NegPolIdentifier
  2047. )
  2048. {
  2049. DWORD dwError = 0;
  2050. LPWSTR pszGuid = NULL;
  2051. if (pszIpsecNegPolReference) {
  2052. pszGuid = wcschr(pszIpsecNegPolReference, L'{');
  2053. if (!pszGuid) {
  2054. dwError = ERROR_INVALID_DATA;
  2055. return (dwError);
  2056. }
  2057. wGUIDFromString(pszGuid, NegPolIdentifier);
  2058. }else {
  2059. memset(NegPolIdentifier, 0, sizeof(GUID));
  2060. }
  2061. return(dwError);
  2062. }
  2063. DWORD
  2064. GenGUIDFromRegISAKMPReference(
  2065. LPWSTR pszIpsecISAKMPReference,
  2066. GUID * ISAKMPIdentifier
  2067. )
  2068. {
  2069. DWORD dwError = 0;
  2070. LPWSTR pszGuid = NULL;
  2071. if (pszIpsecISAKMPReference) {
  2072. pszGuid = wcschr(pszIpsecISAKMPReference, L'{');
  2073. if (!pszGuid) {
  2074. dwError = ERROR_INVALID_DATA;
  2075. return (dwError);
  2076. }
  2077. wGUIDFromString(pszGuid, ISAKMPIdentifier);
  2078. }else {
  2079. memset(ISAKMPIdentifier, 0, sizeof(GUID));
  2080. }
  2081. return(dwError);
  2082. }
  2083. void
  2084. FreeIpsecFilterSpecs(
  2085. PIPSEC_FILTER_SPEC * ppIpsecFilterSpecs,
  2086. DWORD dwNumFilterSpecs
  2087. )
  2088. {
  2089. DWORD i = 0;
  2090. PIPSEC_FILTER_SPEC pIpsecFilterSpec = NULL;
  2091. for (i = 0; i < dwNumFilterSpecs; i++) {
  2092. pIpsecFilterSpec = *(ppIpsecFilterSpecs + i);
  2093. if (pIpsecFilterSpec) {
  2094. FreeIpsecFilterSpec(pIpsecFilterSpec);
  2095. }
  2096. }
  2097. FreePolMem(ppIpsecFilterSpecs);
  2098. }
  2099. void
  2100. FreeIpsecFilterSpec(
  2101. PIPSEC_FILTER_SPEC pIpsecFilterSpec
  2102. )
  2103. {
  2104. if (pIpsecFilterSpec->pszSrcDNSName){
  2105. FreePolStr(pIpsecFilterSpec->pszSrcDNSName);
  2106. }
  2107. if (pIpsecFilterSpec->pszDestDNSName){
  2108. FreePolStr(pIpsecFilterSpec->pszDestDNSName);
  2109. }
  2110. if (pIpsecFilterSpec->pszDescription){
  2111. FreePolStr(pIpsecFilterSpec->pszDescription);
  2112. }
  2113. FreePolMem(pIpsecFilterSpec);
  2114. return;
  2115. }
  2116. void
  2117. FreeMulIpsecISAKMPData(
  2118. PIPSEC_ISAKMP_DATA * ppIpsecISAKMPData,
  2119. DWORD dwNumISAKMPObjects
  2120. )
  2121. {
  2122. DWORD i = 0;
  2123. PIPSEC_ISAKMP_DATA pIpsecISAKMPData = NULL;
  2124. if (!ppIpsecISAKMPData) {
  2125. return;
  2126. }
  2127. for (i = 0; i < dwNumISAKMPObjects; i++) {
  2128. pIpsecISAKMPData = *(ppIpsecISAKMPData + i);
  2129. if (pIpsecISAKMPData) {
  2130. FreeIpsecISAKMPData(pIpsecISAKMPData);
  2131. }
  2132. }
  2133. FreePolMem(ppIpsecISAKMPData);
  2134. return;
  2135. }