Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2146 lines
50 KiB

  1. #include "precomp.h"
  2. DWORD
  3. PADeleteObseleteISAKMPData(
  4. PIPSEC_ISAKMP_DATA * ppOldIpsecISAKMPData,
  5. DWORD dwNumOldPolicies,
  6. PIPSEC_NFA_DATA * ppOldIpsecNFAData,
  7. DWORD dwNumOldNFACount,
  8. PIPSEC_ISAKMP_DATA * ppNewIpsecISAKMPData,
  9. DWORD dwNumNewPolicies
  10. )
  11. {
  12. DWORD dwError = 0;
  13. DWORD i = 0;
  14. PIPSEC_ISAKMP_DATA pOldIpsecISAKMPData = NULL;
  15. PIPSEC_ISAKMP_DATA pFoundISAKMPData = NULL;
  16. for (i = 0; i < dwNumOldPolicies; i++) {
  17. pOldIpsecISAKMPData = *(ppOldIpsecISAKMPData + i);
  18. pFoundISAKMPData = FindISAKMPData(
  19. pOldIpsecISAKMPData,
  20. ppNewIpsecISAKMPData,
  21. dwNumNewPolicies
  22. );
  23. if (!pFoundISAKMPData) {
  24. dwError = PADeleteMMFilters(
  25. pOldIpsecISAKMPData,
  26. ppOldIpsecNFAData,
  27. dwNumOldNFACount
  28. );
  29. dwError = PADeleteMMPolicy(
  30. pOldIpsecISAKMPData->ISAKMPIdentifier
  31. );
  32. }
  33. }
  34. return (dwError);
  35. }
  36. PIPSEC_ISAKMP_DATA
  37. FindISAKMPData(
  38. PIPSEC_ISAKMP_DATA pIpsecISAKMPData,
  39. PIPSEC_ISAKMP_DATA * ppIpsecISAKMPData,
  40. DWORD dwNumPolicies
  41. )
  42. {
  43. DWORD i = 0;
  44. PIPSEC_ISAKMP_DATA pTemp = NULL;
  45. for (i = 0; i < dwNumPolicies; i++) {
  46. pTemp = *(ppIpsecISAKMPData + i);
  47. if (!memcmp(
  48. &(pIpsecISAKMPData->ISAKMPIdentifier),
  49. &(pTemp->ISAKMPIdentifier),
  50. sizeof(GUID))) {
  51. return (pTemp);
  52. }
  53. }
  54. return (NULL);
  55. }
  56. DWORD
  57. PADeleteObseleteNFAData(
  58. PIPSEC_ISAKMP_DATA pNewIpsecISAKMPData,
  59. PIPSEC_NFA_DATA * ppOldIpsecNFAData,
  60. DWORD dwNumOldNFACount,
  61. PIPSEC_NFA_DATA * ppNewIpsecNFAData,
  62. DWORD dwNumNewNFACount
  63. )
  64. {
  65. DWORD dwError = 0;
  66. DWORD i = 0;
  67. PIPSEC_NFA_DATA pOldIpsecNFAData = NULL;
  68. PIPSEC_NFA_DATA pFoundNFAData = NULL;
  69. for (i = 0; i < dwNumOldNFACount; i++) {
  70. pOldIpsecNFAData = *(ppOldIpsecNFAData + i);
  71. pFoundNFAData = FindNFAData(
  72. pOldIpsecNFAData,
  73. ppNewIpsecNFAData,
  74. dwNumNewNFACount
  75. );
  76. if (!pFoundNFAData) {
  77. dwError = PADeleteMMFilterSpecs(
  78. pNewIpsecISAKMPData,
  79. pOldIpsecNFAData
  80. );
  81. dwError = PADeleteMMAuthMethod(
  82. pOldIpsecNFAData->NFAIdentifier
  83. );
  84. dwError = PADeleteQMInfoForNFA(
  85. pOldIpsecNFAData
  86. );
  87. }
  88. }
  89. return (dwError);
  90. }
  91. PIPSEC_NFA_DATA
  92. FindNFAData(
  93. PIPSEC_NFA_DATA pIpsecNFAData,
  94. PIPSEC_NFA_DATA * ppIpsecNFAData,
  95. DWORD dwNumNFACount
  96. )
  97. {
  98. DWORD i = 0;
  99. PIPSEC_NFA_DATA pTemp = NULL;
  100. for (i = 0; i < dwNumNFACount; i++) {
  101. pTemp = *(ppIpsecNFAData + i);
  102. if (!memcmp(
  103. &(pIpsecNFAData->NFAIdentifier),
  104. &(pTemp->NFAIdentifier),
  105. sizeof(GUID))) {
  106. return (pTemp);
  107. }
  108. }
  109. return (NULL);
  110. }
  111. DWORD
  112. PAUpdateISAKMPData(
  113. PIPSEC_ISAKMP_DATA * ppNewIpsecISAKMPData,
  114. DWORD dwNumNewPolicies,
  115. PIPSEC_NFA_DATA * ppOldIpsecNFAData,
  116. DWORD dwNumOldNFACount,
  117. PIPSEC_ISAKMP_DATA * ppOldIpsecISAKMPData,
  118. DWORD dwNumOldPolicies
  119. )
  120. {
  121. DWORD dwError = 0;
  122. DWORD i = 0;
  123. PIPSEC_ISAKMP_DATA pNewIpsecISAKMPData = NULL;
  124. PIPSEC_ISAKMP_DATA pFoundISAKMPData = NULL;
  125. for (i = 0; i < dwNumNewPolicies; i++) {
  126. pNewIpsecISAKMPData = *(ppNewIpsecISAKMPData + i);
  127. pFoundISAKMPData = FindISAKMPData(
  128. pNewIpsecISAKMPData,
  129. ppOldIpsecISAKMPData,
  130. dwNumOldPolicies
  131. );
  132. if (!pFoundISAKMPData) {
  133. dwError = PAAddMMPolicies(
  134. &pNewIpsecISAKMPData,
  135. 1
  136. );
  137. dwError = PAAddMMFilters(
  138. pNewIpsecISAKMPData,
  139. ppOldIpsecNFAData,
  140. dwNumOldNFACount
  141. );
  142. }
  143. else {
  144. dwError = PAProcessISAKMPUpdate(
  145. pFoundISAKMPData,
  146. ppOldIpsecNFAData,
  147. dwNumOldNFACount,
  148. pNewIpsecISAKMPData
  149. );
  150. }
  151. }
  152. return (dwError);
  153. }
  154. DWORD
  155. PAUpdateNFAData(
  156. PIPSEC_ISAKMP_DATA pNewIpsecISAKMPData,
  157. PIPSEC_NFA_DATA * ppNewIpsecNFAData,
  158. DWORD dwNumNewNFACount,
  159. PIPSEC_NFA_DATA * ppOldIpsecNFAData,
  160. DWORD dwNumOldNFACount
  161. )
  162. {
  163. DWORD dwError = 0;
  164. DWORD i = 0;
  165. PIPSEC_NFA_DATA pNewIpsecNFAData = NULL;
  166. PIPSEC_NFA_DATA pFoundNFAData = NULL;
  167. for (i = 0; i < dwNumNewNFACount; i++) {
  168. pNewIpsecNFAData = *(ppNewIpsecNFAData + i);
  169. pFoundNFAData = FindNFAData(
  170. pNewIpsecNFAData,
  171. ppOldIpsecNFAData,
  172. dwNumOldNFACount
  173. );
  174. if (!pFoundNFAData) {
  175. dwError = PAAddMMAuthMethods(
  176. &pNewIpsecNFAData,
  177. 1
  178. );
  179. dwError = PAAddMMFilterSpecs(
  180. pNewIpsecISAKMPData,
  181. pNewIpsecNFAData
  182. );
  183. dwError = PAAddQMInfoForNFA(
  184. pNewIpsecNFAData
  185. );
  186. }
  187. else {
  188. dwError = PAProcessNFAUpdate(
  189. pNewIpsecISAKMPData,
  190. pFoundNFAData,
  191. pNewIpsecNFAData
  192. );
  193. }
  194. }
  195. return (dwError);
  196. }
  197. DWORD
  198. PAProcessISAKMPUpdate(
  199. PIPSEC_ISAKMP_DATA pOldIpsecISAKMPData,
  200. PIPSEC_NFA_DATA * ppOldIpsecNFAData,
  201. DWORD dwNumOldNFACount,
  202. PIPSEC_ISAKMP_DATA pNewIpsecISAKMPData
  203. )
  204. {
  205. DWORD dwError = 0;
  206. PMMPOLICYSTATE pMMPolicyState = NULL;
  207. BOOL bEqual = FALSE;
  208. PIPSEC_MM_POLICY pSPDMMPolicy = NULL;
  209. LPWSTR pServerName = NULL;
  210. pMMPolicyState = FindMMPolicyState(
  211. pOldIpsecISAKMPData->ISAKMPIdentifier
  212. );
  213. if (!pMMPolicyState) {
  214. dwError = PAAddMMPolicies(
  215. &pNewIpsecISAKMPData,
  216. 1
  217. );
  218. dwError = PAAddMMFilters(
  219. pNewIpsecISAKMPData,
  220. ppOldIpsecNFAData,
  221. dwNumOldNFACount
  222. );
  223. return (dwError);
  224. }
  225. if (!(pMMPolicyState->bInSPD)) {
  226. PADeleteMMPolicyState(pMMPolicyState);
  227. dwError = PAAddMMPolicies(
  228. &pNewIpsecISAKMPData,
  229. 1
  230. );
  231. dwError = PAAddMMFilters(
  232. pNewIpsecISAKMPData,
  233. ppOldIpsecNFAData,
  234. dwNumOldNFACount
  235. );
  236. return (dwError);
  237. }
  238. bEqual = EqualISAKMPData(
  239. pOldIpsecISAKMPData,
  240. pNewIpsecISAKMPData
  241. );
  242. if (bEqual) {
  243. dwError = ERROR_SUCCESS;
  244. return (dwError);
  245. }
  246. dwError = PACreateMMPolicy(
  247. pNewIpsecISAKMPData,
  248. pMMPolicyState,
  249. &pSPDMMPolicy
  250. );
  251. BAIL_ON_WIN32_ERROR(dwError);
  252. dwError = SetMMPolicy(
  253. pServerName,
  254. pMMPolicyState->pszPolicyName,
  255. pSPDMMPolicy
  256. );
  257. BAIL_ON_WIN32_ERROR(dwError);
  258. error:
  259. if (pSPDMMPolicy) {
  260. PAFreeMMPolicy(pSPDMMPolicy);
  261. }
  262. return (dwError);
  263. }
  264. BOOL
  265. EqualISAKMPData(
  266. PIPSEC_ISAKMP_DATA pOldIpsecISAKMPData,
  267. PIPSEC_ISAKMP_DATA pNewIpsecISAKMPData
  268. )
  269. {
  270. BOOL bEqual = FALSE;
  271. DWORD dwOldCnt = 0;
  272. PCRYPTO_BUNDLE pOldSecurityMethods = NULL;
  273. DWORD dwNewCnt = 0;
  274. PCRYPTO_BUNDLE pNewSecurityMethods = NULL;
  275. DWORD i = 0;
  276. PCRYPTO_BUNDLE pNewTemp = NULL;
  277. PCRYPTO_BUNDLE pOldTemp = NULL;
  278. //
  279. // At this point, pszPolicyName and ISAKMPIdentifier are same and
  280. // dwWhenChanged is different.
  281. //
  282. dwOldCnt = pOldIpsecISAKMPData->dwNumISAKMPSecurityMethods;
  283. pOldSecurityMethods = pOldIpsecISAKMPData->pSecurityMethods;
  284. dwNewCnt = pNewIpsecISAKMPData->dwNumISAKMPSecurityMethods;
  285. pNewSecurityMethods = pNewIpsecISAKMPData->pSecurityMethods;
  286. //
  287. // At this point, dwOldCnt >= 1 and pOldSecurityMethods != NULL.
  288. //
  289. if (!dwNewCnt || !pNewSecurityMethods) {
  290. return (FALSE);
  291. }
  292. if (dwOldCnt != dwNewCnt) {
  293. return (FALSE);
  294. }
  295. pNewTemp = pNewSecurityMethods;
  296. pOldTemp = pOldSecurityMethods;
  297. for (i = 0; i < dwNewCnt; i++) {
  298. bEqual = FALSE;
  299. bEqual = EqualCryptoBundle(
  300. pOldTemp,
  301. pNewTemp
  302. );
  303. if (!bEqual) {
  304. break;
  305. }
  306. pOldTemp++;
  307. pNewTemp++;
  308. }
  309. return (bEqual);
  310. }
  311. BOOL
  312. EqualCryptoBundle(
  313. PCRYPTO_BUNDLE pOldBundle,
  314. PCRYPTO_BUNDLE pNewBundle
  315. )
  316. {
  317. if (memcmp(
  318. &(pOldBundle->Lifetime),
  319. &(pNewBundle->Lifetime),
  320. sizeof(OAKLEY_LIFETIME))) {
  321. return (FALSE);
  322. }
  323. if (pOldBundle->QuickModeLimit != pNewBundle->QuickModeLimit) {
  324. return (FALSE);
  325. }
  326. if (pOldBundle->OakleyGroup != pNewBundle->OakleyGroup) {
  327. return (FALSE);
  328. }
  329. if (memcmp(
  330. &(pOldBundle->EncryptionAlgorithm),
  331. &(pNewBundle->EncryptionAlgorithm),
  332. sizeof(OAKLEY_ALGORITHM))) {
  333. return (FALSE);
  334. }
  335. if (memcmp(
  336. &(pOldBundle->HashAlgorithm),
  337. &(pNewBundle->HashAlgorithm),
  338. sizeof(OAKLEY_ALGORITHM))) {
  339. return (FALSE);
  340. }
  341. return (TRUE);
  342. }
  343. DWORD
  344. PAProcessNFAUpdate(
  345. PIPSEC_ISAKMP_DATA pNewIpsecISAKMPData,
  346. PIPSEC_NFA_DATA pOldIpsecNFAData,
  347. PIPSEC_NFA_DATA pNewIpsecNFAData
  348. )
  349. {
  350. DWORD dwError = 0;
  351. BOOL bAddedMMFilters = FALSE;
  352. dwError = PAUpdateAuthMethod(
  353. pNewIpsecISAKMPData,
  354. pOldIpsecNFAData,
  355. pNewIpsecNFAData,
  356. &bAddedMMFilters
  357. );
  358. if (!bAddedMMFilters) {
  359. dwError = PAUpdateMMFilters(
  360. pNewIpsecISAKMPData,
  361. pOldIpsecNFAData,
  362. pNewIpsecNFAData
  363. );
  364. }
  365. dwError = PAProcessQMNFAUpdate(
  366. pOldIpsecNFAData,
  367. pNewIpsecNFAData
  368. );
  369. return (dwError);
  370. }
  371. DWORD
  372. PAUpdateAuthMethod(
  373. PIPSEC_ISAKMP_DATA pNewIpsecISAKMPData,
  374. PIPSEC_NFA_DATA pOldIpsecNFAData,
  375. PIPSEC_NFA_DATA pNewIpsecNFAData,
  376. PBOOL pbAddedMMFilters
  377. )
  378. {
  379. DWORD dwError = 0;
  380. PMMAUTHSTATE pMMAuthState = NULL;
  381. BOOL bEqual = FALSE;
  382. PMM_AUTH_METHODS pSPDMMAuthMethods = NULL;
  383. LPWSTR pServerName = NULL;
  384. *pbAddedMMFilters = FALSE;
  385. pMMAuthState = FindMMAuthState(
  386. pOldIpsecNFAData->NFAIdentifier
  387. );
  388. if (!pMMAuthState) {
  389. dwError = PAAddMMAuthMethods(
  390. &pNewIpsecNFAData,
  391. 1
  392. );
  393. dwError = PAAddMMFilterSpecs(
  394. pNewIpsecISAKMPData,
  395. pNewIpsecNFAData
  396. );
  397. *pbAddedMMFilters = TRUE;
  398. return (dwError);
  399. }
  400. if (!(pMMAuthState->bInSPD)) {
  401. PADeleteMMAuthState(pMMAuthState);
  402. dwError = PAAddMMAuthMethods(
  403. &pNewIpsecNFAData,
  404. 1
  405. );
  406. dwError = PAAddMMFilterSpecs(
  407. pNewIpsecISAKMPData,
  408. pNewIpsecNFAData
  409. );
  410. *pbAddedMMFilters = TRUE;
  411. return (dwError);
  412. }
  413. bEqual = EqualAuthMethodData(
  414. pOldIpsecNFAData,
  415. pNewIpsecNFAData
  416. );
  417. if (bEqual) {
  418. dwError = ERROR_SUCCESS;
  419. return (dwError);
  420. }
  421. dwError = PACreateMMAuthMethods(
  422. pNewIpsecNFAData,
  423. &pSPDMMAuthMethods
  424. );
  425. BAIL_ON_WIN32_ERROR(dwError);
  426. dwError = SetMMAuthMethods(
  427. pServerName,
  428. pMMAuthState->gMMAuthID,
  429. pSPDMMAuthMethods
  430. );
  431. BAIL_ON_WIN32_ERROR(dwError);
  432. error:
  433. if (pSPDMMAuthMethods) {
  434. PAFreeMMAuthMethods(pSPDMMAuthMethods);
  435. }
  436. return (dwError);
  437. }
  438. BOOL
  439. EqualAuthMethodData(
  440. PIPSEC_NFA_DATA pOldIpsecNFAData,
  441. PIPSEC_NFA_DATA pNewIpsecNFAData
  442. )
  443. {
  444. BOOL bEqual = FALSE;
  445. DWORD dwOldCnt = 0;
  446. PIPSEC_AUTH_METHOD * ppOldAuthMethods = NULL;
  447. DWORD dwNewCnt = 0;
  448. PIPSEC_AUTH_METHOD * ppNewAuthMethods = NULL;
  449. DWORD i = 0;
  450. PIPSEC_AUTH_METHOD pNewAuthMethod = NULL;
  451. PIPSEC_AUTH_METHOD pOldAuthMethod = NULL;
  452. //
  453. // At this point, NFAIdentifier is same and
  454. // dwWhenChanged is different.
  455. //
  456. dwOldCnt = pOldIpsecNFAData->dwAuthMethodCount;
  457. ppOldAuthMethods = pOldIpsecNFAData->ppAuthMethods;
  458. dwNewCnt = pNewIpsecNFAData->dwAuthMethodCount;
  459. ppNewAuthMethods = pNewIpsecNFAData->ppAuthMethods;
  460. //
  461. // At this point, dwOldCnt >= 1 and ppOldAuthMethods != NULL.
  462. //
  463. if (!dwNewCnt || !ppNewAuthMethods) {
  464. return (FALSE);
  465. }
  466. if (dwOldCnt != dwNewCnt) {
  467. return (FALSE);
  468. }
  469. for (i = 0; i < dwNewCnt; i++) {
  470. pNewAuthMethod = *(ppNewAuthMethods + i);
  471. pOldAuthMethod = *(ppOldAuthMethods + i);
  472. bEqual = FALSE;
  473. bEqual = EqualAuthBundle(
  474. pOldAuthMethod,
  475. pNewAuthMethod
  476. );
  477. if (!bEqual) {
  478. break;
  479. }
  480. }
  481. return (bEqual);
  482. }
  483. BOOL
  484. EqualAuthBundle(
  485. PIPSEC_AUTH_METHOD pOldAuthMethod,
  486. PIPSEC_AUTH_METHOD pNewAuthMethod
  487. )
  488. {
  489. BOOL bEqual = FALSE;
  490. DWORD dwOldAuthLen = 0;
  491. DWORD dwNewAuthLen = 0;
  492. if (pOldAuthMethod->dwAuthType != pNewAuthMethod->dwAuthType) {
  493. return (FALSE);
  494. }
  495. switch (pNewAuthMethod->dwAuthType) {
  496. case OAK_SSPI:
  497. bEqual = TRUE;
  498. break;
  499. default:
  500. //
  501. // Since auth version 2 also has auth version 1 fields filled in it, so
  502. // there is no need to explicitly compare exclusive auth version 2 fields.
  503. //
  504. dwOldAuthLen = pOldAuthMethod->dwAuthLen;
  505. dwNewAuthLen = pNewAuthMethod->dwAuthLen;
  506. if (!dwNewAuthLen || !(pNewAuthMethod->pszAuthMethod)) {
  507. bEqual = FALSE;
  508. break;
  509. }
  510. if (dwOldAuthLen != dwNewAuthLen) {
  511. bEqual = FALSE;
  512. break;
  513. }
  514. if (!memcmp(
  515. (LPBYTE) pNewAuthMethod->pszAuthMethod,
  516. (LPBYTE) pOldAuthMethod->pszAuthMethod,
  517. (dwNewAuthLen*sizeof(WCHAR)))) {
  518. bEqual = TRUE;
  519. break;
  520. }
  521. break;
  522. }
  523. return (bEqual);
  524. }
  525. DWORD
  526. PAProcessQMNFAUpdate(
  527. PIPSEC_NFA_DATA pOldIpsecNFAData,
  528. PIPSEC_NFA_DATA pNewIpsecNFAData
  529. )
  530. {
  531. DWORD dwError = 0;
  532. PIPSEC_NEGPOL_DATA pOldIpsecNegPolData = NULL;
  533. PIPSEC_NEGPOL_DATA pNewIpsecNegPolData = NULL;
  534. BOOL bAddedQMFilters = FALSE;
  535. pOldIpsecNegPolData = pOldIpsecNFAData->pIpsecNegPolData;
  536. pNewIpsecNegPolData = pNewIpsecNFAData->pIpsecNegPolData;
  537. if (memcmp(
  538. &(pOldIpsecNegPolData->NegPolIdentifier),
  539. &(pNewIpsecNegPolData->NegPolIdentifier),
  540. sizeof(GUID))) {
  541. dwError = PADeleteQMInfoForNFA(pOldIpsecNFAData);
  542. dwError = PAAddQMInfoForNFA(pNewIpsecNFAData);
  543. }
  544. else {
  545. dwError = PAProcessNegPolUpdate(
  546. pOldIpsecNFAData,
  547. pNewIpsecNFAData,
  548. &bAddedQMFilters
  549. );
  550. if (!bAddedQMFilters) {
  551. dwError = PAUpdateQMFilters(
  552. pOldIpsecNFAData,
  553. pNewIpsecNFAData
  554. );
  555. }
  556. }
  557. return (dwError);
  558. }
  559. DWORD
  560. PADeleteQMInfoForNFA(
  561. PIPSEC_NFA_DATA pOldIpsecNFAData
  562. )
  563. {
  564. DWORD dwError = 0;
  565. PIPSEC_NEGPOL_DATA pOldIpsecNegPolData = NULL;
  566. dwError = PADeleteQMFilterSpecs(
  567. pOldIpsecNFAData
  568. );
  569. pOldIpsecNegPolData = pOldIpsecNFAData->pIpsecNegPolData;
  570. dwError = PADeleteQMPolicy(
  571. pOldIpsecNegPolData->NegPolIdentifier
  572. );
  573. return (dwError);
  574. }
  575. DWORD
  576. PAAddQMInfoForNFA(
  577. PIPSEC_NFA_DATA pNewIpsecNFAData
  578. )
  579. {
  580. DWORD dwError = 0;
  581. dwError = PAAddQMPolicies(
  582. &pNewIpsecNFAData,
  583. 1
  584. );
  585. dwError = PAAddQMFilterSpecs(
  586. pNewIpsecNFAData
  587. );
  588. return (dwError);
  589. }
  590. DWORD
  591. PAProcessNegPolUpdate(
  592. PIPSEC_NFA_DATA pOldIpsecNFAData,
  593. PIPSEC_NFA_DATA pNewIpsecNFAData,
  594. PBOOL pbAddedQMFilters
  595. )
  596. {
  597. DWORD dwError = 0;
  598. PIPSEC_NEGPOL_DATA pOldIpsecNegPolData = NULL;
  599. PIPSEC_NEGPOL_DATA pNewIpsecNegPolData = NULL;
  600. PQMPOLICYSTATE pQMPolicyState = NULL;
  601. BOOL bEqual = FALSE;
  602. PIPSEC_QM_POLICY pSPDQMPolicy = NULL;
  603. LPWSTR pServerName = NULL;
  604. *pbAddedQMFilters = FALSE;
  605. pOldIpsecNegPolData = pOldIpsecNFAData->pIpsecNegPolData;
  606. pNewIpsecNegPolData = pNewIpsecNFAData->pIpsecNegPolData;
  607. pQMPolicyState = FindQMPolicyState(
  608. pOldIpsecNegPolData->NegPolIdentifier
  609. );
  610. if (!pQMPolicyState) {
  611. dwError = PAAddQMInfoForNFA(pNewIpsecNFAData);
  612. *pbAddedQMFilters = TRUE;
  613. return (dwError);
  614. }
  615. if (IsClearOnly(pQMPolicyState->gNegPolAction)) {
  616. if (IsClearOnly(pNewIpsecNegPolData->NegPolAction)) {
  617. dwError = ERROR_SUCCESS;
  618. return (dwError);
  619. }
  620. else {
  621. dwError = PADeleteQMInfoForNFA(pOldIpsecNFAData);
  622. dwError = PAAddQMInfoForNFA(pNewIpsecNFAData);
  623. *pbAddedQMFilters = TRUE;
  624. return (dwError);
  625. }
  626. }
  627. if (IsBlocking(pQMPolicyState->gNegPolAction)) {
  628. if (IsBlocking(pNewIpsecNegPolData->NegPolAction)) {
  629. dwError = ERROR_SUCCESS;
  630. return (dwError);
  631. }
  632. else {
  633. dwError = PADeleteQMInfoForNFA(pOldIpsecNFAData);
  634. dwError = PAAddQMInfoForNFA(pNewIpsecNFAData);
  635. *pbAddedQMFilters = TRUE;
  636. return (dwError);
  637. }
  638. }
  639. if (IsClearOnly(pNewIpsecNegPolData->NegPolAction)) {
  640. if (IsClearOnly(pQMPolicyState->gNegPolAction)) {
  641. dwError = ERROR_SUCCESS;
  642. return (dwError);
  643. }
  644. else {
  645. dwError = PADeleteQMInfoForNFA(pOldIpsecNFAData);
  646. dwError = PAAddQMInfoForNFA(pNewIpsecNFAData);
  647. *pbAddedQMFilters = TRUE;
  648. return (dwError);
  649. }
  650. }
  651. if (IsBlocking(pNewIpsecNegPolData->NegPolAction)) {
  652. if (IsBlocking(pQMPolicyState->gNegPolAction)) {
  653. dwError = ERROR_SUCCESS;
  654. return (dwError);
  655. }
  656. else {
  657. dwError = PADeleteQMInfoForNFA(pOldIpsecNFAData);
  658. dwError = PAAddQMInfoForNFA(pNewIpsecNFAData);
  659. *pbAddedQMFilters = TRUE;
  660. return (dwError);
  661. }
  662. }
  663. if (!(pQMPolicyState->bInSPD)) {
  664. PADeleteQMPolicy(pQMPolicyState->gPolicyID);
  665. dwError = PAAddQMInfoForNFA(pNewIpsecNFAData);
  666. *pbAddedQMFilters = TRUE;
  667. return (dwError);
  668. }
  669. bEqual = EqualNegPolData(
  670. pOldIpsecNegPolData,
  671. pNewIpsecNegPolData
  672. );
  673. if (bEqual) {
  674. dwError = ERROR_SUCCESS;
  675. return (dwError);
  676. }
  677. memcpy(
  678. &(pQMPolicyState->gNegPolType),
  679. &(pNewIpsecNegPolData->NegPolType),
  680. sizeof(GUID)
  681. );
  682. memcpy(
  683. &(pQMPolicyState->gNegPolAction),
  684. &(pNewIpsecNegPolData->NegPolAction),
  685. sizeof(GUID)
  686. );
  687. dwError = PACreateQMPolicy(
  688. pNewIpsecNFAData,
  689. pQMPolicyState,
  690. &pSPDQMPolicy
  691. );
  692. BAIL_ON_WIN32_ERROR(dwError);
  693. dwError = SetQMPolicy(
  694. pServerName,
  695. pQMPolicyState->pszPolicyName,
  696. pSPDQMPolicy
  697. );
  698. BAIL_ON_WIN32_ERROR(dwError);
  699. error:
  700. if (pSPDQMPolicy) {
  701. PAFreeQMPolicy(pSPDQMPolicy);
  702. }
  703. return (dwError);
  704. }
  705. BOOL
  706. EqualNegPolData(
  707. PIPSEC_NEGPOL_DATA pOldIpsecNegPolData,
  708. PIPSEC_NEGPOL_DATA pNewIpsecNegPolData
  709. )
  710. {
  711. BOOL bEqual = FALSE;
  712. DWORD dwOldCnt = 0;
  713. PIPSEC_SECURITY_METHOD pOldSecurityMethods = NULL;
  714. DWORD dwNewCnt = 0;
  715. PIPSEC_SECURITY_METHOD pNewSecurityMethods = NULL;
  716. DWORD i = 0;
  717. PIPSEC_SECURITY_METHOD pNewTemp = NULL;
  718. PIPSEC_SECURITY_METHOD pOldTemp = NULL;
  719. //
  720. // At this point, pszPolicyName and NegPolIdentifier are same and
  721. // dwWhenChanged is different.
  722. //
  723. if (memcmp(
  724. &(pOldIpsecNegPolData->NegPolAction),
  725. &(pNewIpsecNegPolData->NegPolAction),
  726. sizeof(GUID))) {
  727. return (FALSE);
  728. }
  729. if (memcmp(
  730. &(pOldIpsecNegPolData->NegPolType),
  731. &(pNewIpsecNegPolData->NegPolType),
  732. sizeof(GUID))) {
  733. return (FALSE);
  734. }
  735. dwOldCnt = pOldIpsecNegPolData->dwSecurityMethodCount;
  736. pOldSecurityMethods = pOldIpsecNegPolData->pIpsecSecurityMethods;
  737. dwNewCnt = pNewIpsecNegPolData->dwSecurityMethodCount;
  738. pNewSecurityMethods = pNewIpsecNegPolData->pIpsecSecurityMethods;
  739. //
  740. // At this point, dwOldCnt >= 1 and pOldSecurityMethods != NULL.
  741. //
  742. if (!dwNewCnt || !pNewSecurityMethods) {
  743. return (FALSE);
  744. }
  745. if (dwOldCnt != dwNewCnt) {
  746. return (FALSE);
  747. }
  748. pNewTemp = pNewSecurityMethods;
  749. pOldTemp = pOldSecurityMethods;
  750. for (i = 0; i < dwNewCnt; i++) {
  751. bEqual = FALSE;
  752. bEqual = EqualSecurityMethod(
  753. pOldTemp,
  754. pNewTemp
  755. );
  756. if (!bEqual) {
  757. break;
  758. }
  759. pOldTemp++;
  760. pNewTemp++;
  761. }
  762. return (bEqual);
  763. }
  764. BOOL
  765. EqualSecurityMethod(
  766. PIPSEC_SECURITY_METHOD pOldBundle,
  767. PIPSEC_SECURITY_METHOD pNewBundle
  768. )
  769. {
  770. DWORD i = 0;
  771. if (memcmp(
  772. &(pOldBundle->Lifetime),
  773. &(pNewBundle->Lifetime),
  774. sizeof(LIFETIME))) {
  775. return (FALSE);
  776. }
  777. if (pOldBundle->Flags != pNewBundle->Flags) {
  778. return (FALSE);
  779. }
  780. if (pOldBundle->PfsQMRequired != pNewBundle->PfsQMRequired) {
  781. return (FALSE);
  782. }
  783. if (pOldBundle->Count != pNewBundle->Count) {
  784. return (FALSE);
  785. }
  786. if (pNewBundle->Count == 0) {
  787. return (TRUE);
  788. }
  789. for (i = 0; i < (pNewBundle->Count); i++) {
  790. if (memcmp(
  791. &(pOldBundle->Algos[i]),
  792. &(pNewBundle->Algos[i]),
  793. sizeof(IPSEC_ALGO_INFO))) {
  794. return (FALSE);
  795. }
  796. }
  797. return (TRUE);
  798. }
  799. DWORD
  800. PAUpdateMMFilters(
  801. PIPSEC_ISAKMP_DATA pNewIpsecISAKMPData,
  802. PIPSEC_NFA_DATA pOldIpsecNFAData,
  803. PIPSEC_NFA_DATA pNewIpsecNFAData
  804. )
  805. {
  806. DWORD dwError = 0;
  807. BOOL bEqual = FALSE;
  808. PIPSEC_NEGPOL_DATA pOldIpsecNegPolData = NULL;
  809. PIPSEC_NEGPOL_DATA pNewIpsecNegPolData = NULL;
  810. pOldIpsecNegPolData = pOldIpsecNFAData->pIpsecNegPolData;
  811. pNewIpsecNegPolData = pNewIpsecNFAData->pIpsecNegPolData;
  812. bEqual = EqualFilterKeysInNegPols(
  813. pOldIpsecNegPolData,
  814. pNewIpsecNegPolData
  815. );
  816. if (!bEqual) {
  817. dwError = PADeleteMMFilterSpecs(
  818. pNewIpsecISAKMPData,
  819. pOldIpsecNFAData
  820. );
  821. dwError = PAAddMMFilterSpecs(
  822. pNewIpsecISAKMPData,
  823. pNewIpsecNFAData
  824. );
  825. return (dwError);
  826. }
  827. bEqual = EqualFilterKeysInNFAs(
  828. pOldIpsecNFAData,
  829. pNewIpsecNFAData
  830. );
  831. if (!bEqual) {
  832. dwError = PADeleteMMFilterSpecs(
  833. pNewIpsecISAKMPData,
  834. pOldIpsecNFAData
  835. );
  836. dwError = PAAddMMFilterSpecs(
  837. pNewIpsecISAKMPData,
  838. pNewIpsecNFAData
  839. );
  840. return (dwError);
  841. }
  842. if (!memcmp(
  843. &(pNewIpsecNegPolData->NegPolType),
  844. &(GUID_NEGOTIATION_TYPE_DEFAULT),
  845. sizeof(GUID))) {
  846. dwError = ERROR_SUCCESS;
  847. return (dwError);
  848. }
  849. if (IsClearOnly(pNewIpsecNegPolData->NegPolAction) ||
  850. IsBlocking(pNewIpsecNegPolData->NegPolAction)) {
  851. dwError = ERROR_SUCCESS;
  852. return (dwError);
  853. }
  854. dwError = PAProcessMMFilterDataForNFAs(
  855. pNewIpsecISAKMPData,
  856. pOldIpsecNFAData,
  857. pNewIpsecNFAData
  858. );
  859. return (dwError);
  860. }
  861. BOOL
  862. EqualFilterKeysInNegPols(
  863. PIPSEC_NEGPOL_DATA pOldIpsecNegPolData,
  864. PIPSEC_NEGPOL_DATA pNewIpsecNegPolData
  865. )
  866. {
  867. BOOL bOldAllowsSoft = FALSE;
  868. BOOL bNewAllowsSoft = FALSE;
  869. if (memcmp(
  870. &(pOldIpsecNegPolData->NegPolType),
  871. &(pNewIpsecNegPolData->NegPolType),
  872. sizeof(GUID))) {
  873. return (FALSE);
  874. }
  875. if (memcmp(
  876. &(pOldIpsecNegPolData->NegPolAction),
  877. &(pNewIpsecNegPolData->NegPolAction),
  878. sizeof(GUID))) {
  879. return (FALSE);
  880. }
  881. bOldAllowsSoft = AllowsSoft(
  882. pOldIpsecNegPolData->dwSecurityMethodCount,
  883. pOldIpsecNegPolData->pIpsecSecurityMethods
  884. );
  885. bNewAllowsSoft = AllowsSoft(
  886. pNewIpsecNegPolData->dwSecurityMethodCount,
  887. pNewIpsecNegPolData->pIpsecSecurityMethods
  888. );
  889. if (bOldAllowsSoft != bNewAllowsSoft) {
  890. return (FALSE);
  891. }
  892. return (TRUE);
  893. }
  894. BOOL
  895. EqualFilterKeysInNFAs(
  896. PIPSEC_NFA_DATA pOldIpsecNFAData,
  897. PIPSEC_NFA_DATA pNewIpsecNFAData
  898. )
  899. {
  900. if (pOldIpsecNFAData->dwInterfaceType !=
  901. pNewIpsecNFAData->dwInterfaceType) {
  902. return (FALSE);
  903. }
  904. if (pOldIpsecNFAData->dwTunnelFlags !=
  905. pNewIpsecNFAData->dwTunnelFlags) {
  906. return (FALSE);
  907. }
  908. if (pOldIpsecNFAData->dwTunnelIpAddr !=
  909. pNewIpsecNFAData->dwTunnelIpAddr) {
  910. return (FALSE);
  911. }
  912. return (TRUE);
  913. }
  914. DWORD
  915. PAProcessMMFilterDataForNFAs(
  916. PIPSEC_ISAKMP_DATA pNewIpsecISAKMPData,
  917. PIPSEC_NFA_DATA pOldIpsecNFAData,
  918. PIPSEC_NFA_DATA pNewIpsecNFAData
  919. )
  920. {
  921. DWORD dwError = 0;
  922. PIPSEC_FILTER_DATA pOldIpsecFilterData = NULL;
  923. PIPSEC_FILTER_DATA pNewIpsecFilterData = NULL;
  924. DWORD dwNumOldFilterSpecs = 0;
  925. PIPSEC_FILTER_SPEC * ppOldFilterSpecs = NULL;
  926. DWORD dwNumNewFilterSpecs = 0;
  927. PIPSEC_FILTER_SPEC * ppNewFilterSpecs = NULL;
  928. pOldIpsecFilterData = pOldIpsecNFAData->pIpsecFilterData;
  929. pNewIpsecFilterData = pNewIpsecNFAData->pIpsecFilterData;
  930. if (!pOldIpsecFilterData) {
  931. if (!pNewIpsecFilterData) {
  932. dwError = ERROR_SUCCESS;
  933. return (dwError);
  934. }
  935. else {
  936. dwError = PAAddMMFilterSpecs(
  937. pNewIpsecISAKMPData,
  938. pNewIpsecNFAData
  939. );
  940. return (dwError);
  941. }
  942. }
  943. if (!pNewIpsecFilterData) {
  944. dwError = PADeleteMMFilterSpecs(
  945. pNewIpsecISAKMPData,
  946. pOldIpsecNFAData
  947. );
  948. return (dwError);
  949. }
  950. if (memcmp(
  951. &(pOldIpsecFilterData->FilterIdentifier),
  952. &(pNewIpsecFilterData->FilterIdentifier),
  953. sizeof(GUID))) {
  954. dwError = PADeleteMMFilterSpecs(
  955. pNewIpsecISAKMPData,
  956. pOldIpsecNFAData
  957. );
  958. dwError = PAAddMMFilterSpecs(
  959. pNewIpsecISAKMPData,
  960. pNewIpsecNFAData
  961. );
  962. return (dwError);
  963. }
  964. dwNumOldFilterSpecs = pOldIpsecFilterData->dwNumFilterSpecs;
  965. ppOldFilterSpecs = pOldIpsecFilterData->ppFilterSpecs;
  966. dwNumNewFilterSpecs = pNewIpsecFilterData->dwNumFilterSpecs;
  967. ppNewFilterSpecs = pNewIpsecFilterData->ppFilterSpecs;
  968. dwError = PADeleteObseleteMMFilterSpecs(
  969. pNewIpsecISAKMPData,
  970. pOldIpsecNFAData,
  971. dwNumOldFilterSpecs,
  972. ppOldFilterSpecs,
  973. pNewIpsecNFAData,
  974. dwNumNewFilterSpecs,
  975. ppNewFilterSpecs
  976. );
  977. dwError = PAUpdateMMFilterSpecs(
  978. pNewIpsecISAKMPData,
  979. pOldIpsecNFAData,
  980. dwNumOldFilterSpecs,
  981. ppOldFilterSpecs,
  982. pNewIpsecNFAData,
  983. dwNumNewFilterSpecs,
  984. ppNewFilterSpecs
  985. );
  986. return (dwError);
  987. }
  988. DWORD
  989. PADeleteObseleteMMFilterSpecs(
  990. PIPSEC_ISAKMP_DATA pNewIpsecISAKMPData,
  991. PIPSEC_NFA_DATA pOldIpsecNFAData,
  992. DWORD dwNumOldFilterSpecs,
  993. PIPSEC_FILTER_SPEC * ppOldFilterSpecs,
  994. PIPSEC_NFA_DATA pNewIpsecNFAData,
  995. DWORD dwNumNewFilterSpecs,
  996. PIPSEC_FILTER_SPEC * ppNewFilterSpecs
  997. )
  998. {
  999. DWORD dwError = 0;
  1000. DWORD i = 0;
  1001. PIPSEC_FILTER_SPEC pOldFilterSpec = NULL;
  1002. PIPSEC_FILTER_SPEC pFoundFilterSpec = NULL;
  1003. for (i = 0; i < dwNumOldFilterSpecs; i++) {
  1004. pOldFilterSpec = *(ppOldFilterSpecs + i);
  1005. pFoundFilterSpec = FindFilterSpec(
  1006. pOldFilterSpec,
  1007. ppNewFilterSpecs,
  1008. dwNumNewFilterSpecs
  1009. );
  1010. if (!pFoundFilterSpec) {
  1011. dwError = PADeleteMMFilter(
  1012. pOldFilterSpec->FilterSpecGUID
  1013. );
  1014. }
  1015. }
  1016. return (dwError);
  1017. }
  1018. PIPSEC_FILTER_SPEC
  1019. FindFilterSpec(
  1020. PIPSEC_FILTER_SPEC pFilterSpec,
  1021. PIPSEC_FILTER_SPEC * ppFilterSpecs,
  1022. DWORD dwNumFilterSpecs
  1023. )
  1024. {
  1025. DWORD i = 0;
  1026. PIPSEC_FILTER_SPEC pTemp = NULL;
  1027. for (i = 0; i < dwNumFilterSpecs; i++) {
  1028. pTemp = *(ppFilterSpecs + i);
  1029. if (!memcmp(
  1030. &(pFilterSpec->FilterSpecGUID),
  1031. &(pTemp->FilterSpecGUID),
  1032. sizeof(GUID))) {
  1033. return (pTemp);
  1034. }
  1035. }
  1036. return (NULL);
  1037. }
  1038. DWORD
  1039. PAUpdateMMFilterSpecs(
  1040. PIPSEC_ISAKMP_DATA pNewIpsecISAKMPData,
  1041. PIPSEC_NFA_DATA pOldIpsecNFAData,
  1042. DWORD dwNumOldFilterSpecs,
  1043. PIPSEC_FILTER_SPEC * ppOldFilterSpecs,
  1044. PIPSEC_NFA_DATA pNewIpsecNFAData,
  1045. DWORD dwNumNewFilterSpecs,
  1046. PIPSEC_FILTER_SPEC * ppNewFilterSpecs
  1047. )
  1048. {
  1049. DWORD dwError = 0;
  1050. PMMPOLICYSTATE pMMPolicyState = NULL;
  1051. PMMAUTHSTATE pMMAuthState = NULL;
  1052. DWORD i = 0;
  1053. PIPSEC_FILTER_SPEC pNewFilterSpec = NULL;
  1054. PIPSEC_FILTER_SPEC pFoundFilterSpec = NULL;
  1055. BOOL bEqual = FALSE;
  1056. PMMFILTERSTATE pMMFilterState = NULL;
  1057. pMMPolicyState = FindMMPolicyState(
  1058. pNewIpsecISAKMPData->ISAKMPIdentifier
  1059. );
  1060. if (!pMMPolicyState || !(pMMPolicyState->bInSPD)) {
  1061. dwError = ERROR_INVALID_PARAMETER;
  1062. return (dwError);
  1063. }
  1064. pMMAuthState = FindMMAuthState(
  1065. pNewIpsecNFAData->NFAIdentifier
  1066. );
  1067. if (!pMMAuthState || !(pMMAuthState->bInSPD)) {
  1068. dwError = ERROR_INVALID_PARAMETER;
  1069. return (dwError);
  1070. }
  1071. for (i = 0; i < dwNumNewFilterSpecs; i++) {
  1072. pNewFilterSpec = *(ppNewFilterSpecs + i);
  1073. pFoundFilterSpec = FindFilterSpec(
  1074. pNewFilterSpec,
  1075. ppOldFilterSpecs,
  1076. dwNumOldFilterSpecs
  1077. );
  1078. if (!pFoundFilterSpec) {
  1079. dwError = PAAddMMFilterSpec(
  1080. pNewIpsecISAKMPData,
  1081. pNewIpsecNFAData,
  1082. pNewFilterSpec
  1083. );
  1084. }
  1085. else {
  1086. bEqual = FALSE;
  1087. bEqual = EqualFilterSpecs(
  1088. pFoundFilterSpec,
  1089. pNewFilterSpec
  1090. );
  1091. if (!bEqual) {
  1092. dwError = PADeleteMMFilter(
  1093. pFoundFilterSpec->FilterSpecGUID
  1094. );
  1095. dwError = PAAddMMFilterSpec(
  1096. pNewIpsecISAKMPData,
  1097. pNewIpsecNFAData,
  1098. pNewFilterSpec
  1099. );
  1100. }
  1101. else {
  1102. pMMFilterState = FindMMFilterState(
  1103. pFoundFilterSpec->FilterSpecGUID
  1104. );
  1105. if (!pMMFilterState) {
  1106. dwError = PAAddMMFilterSpec(
  1107. pNewIpsecISAKMPData,
  1108. pNewIpsecNFAData,
  1109. pNewFilterSpec
  1110. );
  1111. }
  1112. else {
  1113. if (!pMMFilterState->hMMFilter) {
  1114. PADeleteMMFilterState(pMMFilterState);
  1115. dwError = PAAddMMFilterSpec(
  1116. pNewIpsecISAKMPData,
  1117. pNewIpsecNFAData,
  1118. pNewFilterSpec
  1119. );
  1120. }
  1121. }
  1122. }
  1123. }
  1124. }
  1125. return (dwError);
  1126. }
  1127. DWORD
  1128. PAAddMMFilterSpec(
  1129. PIPSEC_ISAKMP_DATA pIpsecISAKMPData,
  1130. PIPSEC_NFA_DATA pIpsecNFAData,
  1131. PIPSEC_FILTER_SPEC pFilterSpec
  1132. )
  1133. {
  1134. DWORD dwError = 0;
  1135. PMMFILTERSTATE pMMFilterState = NULL;
  1136. PMM_FILTER pSPDMMFilter = NULL;
  1137. LPWSTR pServerName = NULL;
  1138. DWORD dwPersist = 0;
  1139. dwError = PACreateMMFilterState(
  1140. pIpsecISAKMPData,
  1141. pIpsecNFAData,
  1142. pFilterSpec,
  1143. &pMMFilterState
  1144. );
  1145. if (dwError) {
  1146. return (dwError);
  1147. }
  1148. dwError = PACreateMMFilter(
  1149. pIpsecISAKMPData,
  1150. pIpsecNFAData,
  1151. pFilterSpec,
  1152. &pSPDMMFilter
  1153. );
  1154. if (dwError) {
  1155. pMMFilterState->hMMFilter = NULL;
  1156. pMMFilterState->pNext = gpMMFilterState;
  1157. gpMMFilterState = pMMFilterState;
  1158. return (dwError);
  1159. }
  1160. dwError = AddMMFilter(
  1161. pServerName,
  1162. dwPersist,
  1163. pSPDMMFilter,
  1164. &(pMMFilterState->hMMFilter)
  1165. );
  1166. pMMFilterState->pNext = gpMMFilterState;
  1167. gpMMFilterState = pMMFilterState;
  1168. PAFreeMMFilter(pSPDMMFilter);
  1169. return (dwError);
  1170. }
  1171. BOOL
  1172. EqualFilterSpecs(
  1173. PIPSEC_FILTER_SPEC pOldFilterSpec,
  1174. PIPSEC_FILTER_SPEC pNewFilterSpec
  1175. )
  1176. {
  1177. BOOL bEqual = FALSE;
  1178. //
  1179. // At this point, FilterSpecGUID is same.
  1180. //
  1181. bEqual = AreNamesEqual(
  1182. pOldFilterSpec->pszDescription,
  1183. pNewFilterSpec->pszDescription
  1184. );
  1185. if (!bEqual) {
  1186. return (FALSE);
  1187. }
  1188. if (pOldFilterSpec->dwMirrorFlag !=
  1189. pNewFilterSpec->dwMirrorFlag) {
  1190. return (FALSE);
  1191. }
  1192. if (memcmp(
  1193. &(pOldFilterSpec->Filter),
  1194. &(pNewFilterSpec->Filter),
  1195. sizeof(IPSEC_FILTER))) {
  1196. return (FALSE);
  1197. }
  1198. return (TRUE);
  1199. }
  1200. DWORD
  1201. PAUpdateQMFilters(
  1202. PIPSEC_NFA_DATA pOldIpsecNFAData,
  1203. PIPSEC_NFA_DATA pNewIpsecNFAData
  1204. )
  1205. {
  1206. DWORD dwError = 0;
  1207. BOOL bEqual = FALSE;
  1208. PIPSEC_NEGPOL_DATA pOldIpsecNegPolData = NULL;
  1209. PIPSEC_NEGPOL_DATA pNewIpsecNegPolData = NULL;
  1210. pOldIpsecNegPolData = pOldIpsecNFAData->pIpsecNegPolData;
  1211. pNewIpsecNegPolData = pNewIpsecNFAData->pIpsecNegPolData;
  1212. bEqual = EqualFilterKeysInNegPols(
  1213. pOldIpsecNegPolData,
  1214. pNewIpsecNegPolData
  1215. );
  1216. if (!bEqual) {
  1217. dwError = PADeleteQMFilterSpecs(
  1218. pOldIpsecNFAData
  1219. );
  1220. dwError = PAAddQMFilterSpecs(
  1221. pNewIpsecNFAData
  1222. );
  1223. return (dwError);
  1224. }
  1225. bEqual = EqualFilterKeysInNFAs(
  1226. pOldIpsecNFAData,
  1227. pNewIpsecNFAData
  1228. );
  1229. if (!bEqual) {
  1230. dwError = PADeleteQMFilterSpecs(
  1231. pOldIpsecNFAData
  1232. );
  1233. dwError = PAAddQMFilterSpecs(
  1234. pNewIpsecNFAData
  1235. );
  1236. return (dwError);
  1237. }
  1238. if (!memcmp(
  1239. &(pNewIpsecNegPolData->NegPolType),
  1240. &(GUID_NEGOTIATION_TYPE_DEFAULT),
  1241. sizeof(GUID))) {
  1242. dwError = ERROR_SUCCESS;
  1243. return (dwError);
  1244. }
  1245. dwError = PAProcessQMFilterDataForNFAs(
  1246. pOldIpsecNFAData,
  1247. pNewIpsecNFAData
  1248. );
  1249. return (dwError);
  1250. }
  1251. DWORD
  1252. PAAddQMFilterSpecs(
  1253. PIPSEC_NFA_DATA pNewIpsecNFAData
  1254. )
  1255. {
  1256. DWORD dwError = 0;
  1257. if (!(pNewIpsecNFAData->dwTunnelFlags)) {
  1258. dwError = PAAddTxFilterSpecs(
  1259. pNewIpsecNFAData
  1260. );
  1261. }
  1262. else {
  1263. dwError = PAAddTnFilterSpecs(
  1264. pNewIpsecNFAData
  1265. );
  1266. }
  1267. return (dwError);
  1268. }
  1269. DWORD
  1270. PADeleteQMFilterSpecs(
  1271. PIPSEC_NFA_DATA pOldIpsecNFAData
  1272. )
  1273. {
  1274. DWORD dwError = 0;
  1275. if (!(pOldIpsecNFAData->dwTunnelFlags)) {
  1276. dwError = PADeleteTxFilterSpecs(
  1277. pOldIpsecNFAData
  1278. );
  1279. }
  1280. else {
  1281. dwError = PADeleteTnFilterSpecs(
  1282. pOldIpsecNFAData
  1283. );
  1284. }
  1285. return (dwError);
  1286. }
  1287. DWORD
  1288. PAProcessQMFilterDataForNFAs(
  1289. PIPSEC_NFA_DATA pOldIpsecNFAData,
  1290. PIPSEC_NFA_DATA pNewIpsecNFAData
  1291. )
  1292. {
  1293. DWORD dwError = 0;
  1294. PIPSEC_FILTER_DATA pOldIpsecFilterData = NULL;
  1295. PIPSEC_FILTER_DATA pNewIpsecFilterData = NULL;
  1296. DWORD dwNumOldFilterSpecs = 0;
  1297. PIPSEC_FILTER_SPEC * ppOldFilterSpecs = NULL;
  1298. DWORD dwNumNewFilterSpecs = 0;
  1299. PIPSEC_FILTER_SPEC * ppNewFilterSpecs = NULL;
  1300. pOldIpsecFilterData = pOldIpsecNFAData->pIpsecFilterData;
  1301. pNewIpsecFilterData = pNewIpsecNFAData->pIpsecFilterData;
  1302. if (!pOldIpsecFilterData) {
  1303. if (!pNewIpsecFilterData) {
  1304. dwError = ERROR_SUCCESS;
  1305. return (dwError);
  1306. }
  1307. else {
  1308. dwError = PAAddQMFilterSpecs(
  1309. pNewIpsecNFAData
  1310. );
  1311. return (dwError);
  1312. }
  1313. }
  1314. if (!pNewIpsecFilterData) {
  1315. dwError = PADeleteQMFilterSpecs(
  1316. pOldIpsecNFAData
  1317. );
  1318. return (dwError);
  1319. }
  1320. if (memcmp(
  1321. &(pOldIpsecFilterData->FilterIdentifier),
  1322. &(pNewIpsecFilterData->FilterIdentifier),
  1323. sizeof(GUID))) {
  1324. dwError = PADeleteQMFilterSpecs(
  1325. pOldIpsecNFAData
  1326. );
  1327. dwError = PAAddQMFilterSpecs(
  1328. pNewIpsecNFAData
  1329. );
  1330. return (dwError);
  1331. }
  1332. dwNumOldFilterSpecs = pOldIpsecFilterData->dwNumFilterSpecs;
  1333. ppOldFilterSpecs = pOldIpsecFilterData->ppFilterSpecs;
  1334. dwNumNewFilterSpecs = pNewIpsecFilterData->dwNumFilterSpecs;
  1335. ppNewFilterSpecs = pNewIpsecFilterData->ppFilterSpecs;
  1336. dwError = PADeleteObseleteQMFilterSpecs(
  1337. pOldIpsecNFAData,
  1338. dwNumOldFilterSpecs,
  1339. ppOldFilterSpecs,
  1340. pNewIpsecNFAData,
  1341. dwNumNewFilterSpecs,
  1342. ppNewFilterSpecs
  1343. );
  1344. dwError = PAUpdateQMFilterSpecs(
  1345. pOldIpsecNFAData,
  1346. dwNumOldFilterSpecs,
  1347. ppOldFilterSpecs,
  1348. pNewIpsecNFAData,
  1349. dwNumNewFilterSpecs,
  1350. ppNewFilterSpecs
  1351. );
  1352. return (dwError);
  1353. }
  1354. DWORD
  1355. PADeleteObseleteQMFilterSpecs(
  1356. PIPSEC_NFA_DATA pOldIpsecNFAData,
  1357. DWORD dwNumOldFilterSpecs,
  1358. PIPSEC_FILTER_SPEC * ppOldFilterSpecs,
  1359. PIPSEC_NFA_DATA pNewIpsecNFAData,
  1360. DWORD dwNumNewFilterSpecs,
  1361. PIPSEC_FILTER_SPEC * ppNewFilterSpecs
  1362. )
  1363. {
  1364. DWORD dwError = 0;
  1365. DWORD i = 0;
  1366. PIPSEC_FILTER_SPEC pOldFilterSpec = NULL;
  1367. PIPSEC_FILTER_SPEC pFoundFilterSpec = NULL;
  1368. for (i = 0; i < dwNumOldFilterSpecs; i++) {
  1369. pOldFilterSpec = *(ppOldFilterSpecs + i);
  1370. pFoundFilterSpec = FindFilterSpec(
  1371. pOldFilterSpec,
  1372. ppNewFilterSpecs,
  1373. dwNumNewFilterSpecs
  1374. );
  1375. if (!pFoundFilterSpec) {
  1376. dwError = PADeleteQMFilter(
  1377. pOldIpsecNFAData,
  1378. pOldFilterSpec->FilterSpecGUID
  1379. );
  1380. }
  1381. }
  1382. return (dwError);
  1383. }
  1384. DWORD
  1385. PAUpdateQMFilterSpecs(
  1386. PIPSEC_NFA_DATA pOldIpsecNFAData,
  1387. DWORD dwNumOldFilterSpecs,
  1388. PIPSEC_FILTER_SPEC * ppOldFilterSpecs,
  1389. PIPSEC_NFA_DATA pNewIpsecNFAData,
  1390. DWORD dwNumNewFilterSpecs,
  1391. PIPSEC_FILTER_SPEC * ppNewFilterSpecs
  1392. )
  1393. {
  1394. DWORD dwError = 0;
  1395. PIPSEC_NEGPOL_DATA pNewIpsecNegPolData = NULL;
  1396. PQMPOLICYSTATE pQMPolicyState = NULL;
  1397. DWORD i = 0;
  1398. PIPSEC_FILTER_SPEC pNewFilterSpec = NULL;
  1399. PIPSEC_FILTER_SPEC pFoundFilterSpec = NULL;
  1400. BOOL bEqual = FALSE;
  1401. pNewIpsecNegPolData = pNewIpsecNFAData->pIpsecNegPolData;
  1402. pQMPolicyState = FindQMPolicyState(
  1403. pNewIpsecNegPolData->NegPolIdentifier
  1404. );
  1405. if (!pQMPolicyState) {
  1406. dwError = ERROR_INVALID_PARAMETER;
  1407. return (dwError);
  1408. }
  1409. if (!IsClearOnly(pQMPolicyState->gNegPolAction) &&
  1410. !IsBlocking(pQMPolicyState->gNegPolAction) &&
  1411. !(pQMPolicyState->bInSPD)) {
  1412. dwError = ERROR_INVALID_PARAMETER;
  1413. return (dwError);
  1414. }
  1415. for (i = 0; i < dwNumNewFilterSpecs; i++) {
  1416. pNewFilterSpec = *(ppNewFilterSpecs + i);
  1417. pFoundFilterSpec = FindFilterSpec(
  1418. pNewFilterSpec,
  1419. ppOldFilterSpecs,
  1420. dwNumOldFilterSpecs
  1421. );
  1422. if (!pFoundFilterSpec) {
  1423. dwError = PAAddQMFilterSpec(
  1424. pNewIpsecNFAData,
  1425. pQMPolicyState,
  1426. pNewFilterSpec
  1427. );
  1428. }
  1429. else {
  1430. bEqual = FALSE;
  1431. bEqual = EqualFilterSpecs(
  1432. pFoundFilterSpec,
  1433. pNewFilterSpec
  1434. );
  1435. if (!bEqual) {
  1436. dwError = PADeleteQMFilter(
  1437. pOldIpsecNFAData,
  1438. pFoundFilterSpec->FilterSpecGUID
  1439. );
  1440. dwError = PAAddQMFilterSpec(
  1441. pNewIpsecNFAData,
  1442. pQMPolicyState,
  1443. pNewFilterSpec
  1444. );
  1445. }
  1446. else {
  1447. dwError = PAUpdateQMFilterSpec(
  1448. pNewIpsecNFAData,
  1449. pQMPolicyState,
  1450. pNewFilterSpec
  1451. );
  1452. }
  1453. }
  1454. }
  1455. return (dwError);
  1456. }
  1457. DWORD
  1458. PADeleteQMFilter(
  1459. PIPSEC_NFA_DATA pIpsecNFAData,
  1460. GUID FilterSpecGUID
  1461. )
  1462. {
  1463. DWORD dwError = 0;
  1464. if (!(pIpsecNFAData->dwTunnelFlags)) {
  1465. dwError = PADeleteTxFilter(
  1466. FilterSpecGUID
  1467. );
  1468. }
  1469. else {
  1470. dwError = PADeleteTnFilter(
  1471. FilterSpecGUID
  1472. );
  1473. }
  1474. return (dwError);
  1475. }
  1476. DWORD
  1477. PAAddQMFilterSpec(
  1478. PIPSEC_NFA_DATA pIpsecNFAData,
  1479. PQMPOLICYSTATE pQMPolicyState,
  1480. PIPSEC_FILTER_SPEC pFilterSpec
  1481. )
  1482. {
  1483. DWORD dwError = 0;
  1484. if (!(pIpsecNFAData->dwTunnelFlags)) {
  1485. dwError = PAAddTxFilterSpec(
  1486. pIpsecNFAData,
  1487. pQMPolicyState,
  1488. pFilterSpec
  1489. );
  1490. }
  1491. else {
  1492. dwError = PAAddTnFilterSpec(
  1493. pIpsecNFAData,
  1494. pQMPolicyState,
  1495. pFilterSpec
  1496. );
  1497. }
  1498. return (dwError);
  1499. }
  1500. DWORD
  1501. PAAddTxFilterSpec(
  1502. PIPSEC_NFA_DATA pIpsecNFAData,
  1503. PQMPOLICYSTATE pQMPolicyState,
  1504. PIPSEC_FILTER_SPEC pFilterSpec
  1505. )
  1506. {
  1507. DWORD dwError = 0;
  1508. PIPSEC_NEGPOL_DATA pIpsecNegPolData = NULL;
  1509. PTXFILTERSTATE pTxFilterState = NULL;
  1510. PTRANSPORT_FILTER pSPDTxFilter = NULL;
  1511. LPWSTR pServerName = NULL;
  1512. DWORD dwPersist = 0;
  1513. pIpsecNegPolData = pIpsecNFAData->pIpsecNegPolData;
  1514. dwError = PACreateTxFilterState(
  1515. pIpsecNegPolData,
  1516. pIpsecNFAData,
  1517. pFilterSpec,
  1518. &pTxFilterState
  1519. );
  1520. if (dwError) {
  1521. return (dwError);
  1522. }
  1523. dwError = PACreateTxFilter(
  1524. pIpsecNegPolData,
  1525. pIpsecNFAData,
  1526. pFilterSpec,
  1527. pQMPolicyState,
  1528. &pSPDTxFilter
  1529. );
  1530. if (dwError) {
  1531. pTxFilterState->hTxFilter = NULL;
  1532. pTxFilterState->pNext = gpTxFilterState;
  1533. gpTxFilterState = pTxFilterState;
  1534. return (dwError);
  1535. }
  1536. dwError = AddTransportFilter(
  1537. pServerName,
  1538. dwPersist,
  1539. pSPDTxFilter,
  1540. &(pTxFilterState->hTxFilter)
  1541. );
  1542. pTxFilterState->pNext = gpTxFilterState;
  1543. gpTxFilterState = pTxFilterState;
  1544. PAFreeTxFilter(pSPDTxFilter);
  1545. return (dwError);
  1546. }
  1547. DWORD
  1548. PAAddTnFilterSpec(
  1549. PIPSEC_NFA_DATA pIpsecNFAData,
  1550. PQMPOLICYSTATE pQMPolicyState,
  1551. PIPSEC_FILTER_SPEC pFilterSpec
  1552. )
  1553. {
  1554. DWORD dwError = 0;
  1555. PIPSEC_NEGPOL_DATA pIpsecNegPolData = NULL;
  1556. PTNFILTERSTATE pTnFilterState = NULL;
  1557. PTUNNEL_FILTER pSPDTnFilter = NULL;
  1558. LPWSTR pServerName = NULL;
  1559. DWORD dwPersist = 0;
  1560. pIpsecNegPolData = pIpsecNFAData->pIpsecNegPolData;
  1561. dwError = PACreateTnFilterState(
  1562. pIpsecNegPolData,
  1563. pIpsecNFAData,
  1564. pFilterSpec,
  1565. &pTnFilterState
  1566. );
  1567. if (dwError) {
  1568. return (dwError);
  1569. }
  1570. dwError = PACreateTnFilter(
  1571. pIpsecNegPolData,
  1572. pIpsecNFAData,
  1573. pFilterSpec,
  1574. pQMPolicyState,
  1575. &pSPDTnFilter
  1576. );
  1577. if (dwError) {
  1578. pTnFilterState->hTnFilter = NULL;
  1579. pTnFilterState->pNext = gpTnFilterState;
  1580. gpTnFilterState = pTnFilterState;
  1581. return (dwError);
  1582. }
  1583. dwError = AddTunnelFilter(
  1584. pServerName,
  1585. dwPersist,
  1586. pSPDTnFilter,
  1587. &(pTnFilterState->hTnFilter)
  1588. );
  1589. pTnFilterState->pNext = gpTnFilterState;
  1590. gpTnFilterState = pTnFilterState;
  1591. PAFreeTnFilter(pSPDTnFilter);
  1592. return (dwError);
  1593. }
  1594. BOOL
  1595. AllowsSoft(
  1596. DWORD dwSecurityMethodCount,
  1597. PIPSEC_SECURITY_METHOD pIpsecSecurityMethods
  1598. )
  1599. {
  1600. DWORD dwTempOfferCount = 0;
  1601. PIPSEC_SECURITY_METHOD pTempMethod = NULL;
  1602. BOOL bAllowsSoft = FALSE;
  1603. DWORD i = 0;
  1604. if (!dwSecurityMethodCount || !pIpsecSecurityMethods) {
  1605. return (FALSE);
  1606. }
  1607. if (dwSecurityMethodCount > IPSEC_MAX_QM_OFFERS) {
  1608. dwTempOfferCount = IPSEC_MAX_QM_OFFERS;
  1609. }
  1610. else {
  1611. dwTempOfferCount = dwSecurityMethodCount;
  1612. }
  1613. pTempMethod = pIpsecSecurityMethods;
  1614. for (i = 0; i < dwTempOfferCount; i++) {
  1615. if (pTempMethod->Count == 0) {
  1616. bAllowsSoft = TRUE;
  1617. break;
  1618. }
  1619. pTempMethod++;
  1620. }
  1621. return (bAllowsSoft);
  1622. }
  1623. DWORD
  1624. PAUpdateQMFilterSpec(
  1625. PIPSEC_NFA_DATA pIpsecNFAData,
  1626. PQMPOLICYSTATE pQMPolicyState,
  1627. PIPSEC_FILTER_SPEC pFilterSpec
  1628. )
  1629. {
  1630. DWORD dwError = 0;
  1631. if (!(pIpsecNFAData->dwTunnelFlags)) {
  1632. dwError = PAUpdateTxFilterSpec(
  1633. pIpsecNFAData,
  1634. pQMPolicyState,
  1635. pFilterSpec
  1636. );
  1637. }
  1638. else {
  1639. dwError = PAUpdateTnFilterSpec(
  1640. pIpsecNFAData,
  1641. pQMPolicyState,
  1642. pFilterSpec
  1643. );
  1644. }
  1645. return (dwError);
  1646. }
  1647. DWORD
  1648. PAUpdateTxFilterSpec(
  1649. PIPSEC_NFA_DATA pIpsecNFAData,
  1650. PQMPOLICYSTATE pQMPolicyState,
  1651. PIPSEC_FILTER_SPEC pFilterSpec
  1652. )
  1653. {
  1654. DWORD dwError = 0;
  1655. PTXFILTERSTATE pTxFilterState = NULL;
  1656. pTxFilterState = FindTxFilterState(
  1657. pFilterSpec->FilterSpecGUID
  1658. );
  1659. if (!pTxFilterState) {
  1660. dwError = PAAddTxFilterSpec(
  1661. pIpsecNFAData,
  1662. pQMPolicyState,
  1663. pFilterSpec
  1664. );
  1665. }
  1666. else {
  1667. if (!pTxFilterState->hTxFilter) {
  1668. PADeleteTxFilterState(pTxFilterState);
  1669. dwError = PAAddTxFilterSpec(
  1670. pIpsecNFAData,
  1671. pQMPolicyState,
  1672. pFilterSpec
  1673. );
  1674. }
  1675. }
  1676. return (dwError);
  1677. }
  1678. DWORD
  1679. PAUpdateTnFilterSpec(
  1680. PIPSEC_NFA_DATA pIpsecNFAData,
  1681. PQMPOLICYSTATE pQMPolicyState,
  1682. PIPSEC_FILTER_SPEC pFilterSpec
  1683. )
  1684. {
  1685. DWORD dwError = 0;
  1686. PTNFILTERSTATE pTnFilterState = NULL;
  1687. pTnFilterState = FindTnFilterState(
  1688. pFilterSpec->FilterSpecGUID
  1689. );
  1690. if (!pTnFilterState) {
  1691. dwError = PAAddTnFilterSpec(
  1692. pIpsecNFAData,
  1693. pQMPolicyState,
  1694. pFilterSpec
  1695. );
  1696. }
  1697. else {
  1698. if (!pTnFilterState->hTnFilter) {
  1699. PADeleteTnFilterState(pTnFilterState);
  1700. dwError = PAAddTnFilterSpec(
  1701. pIpsecNFAData,
  1702. pQMPolicyState,
  1703. pFilterSpec
  1704. );
  1705. }
  1706. }
  1707. return (dwError);
  1708. }