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.

3372 lines
76 KiB

  1. /*++
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. winipsec.c
  5. Abstract:
  6. Contains IPSec WINAPI calls specific code.
  7. Author:
  8. abhisheV 21-September-1999
  9. Environment:
  10. User Level: Win32
  11. Revision History:
  12. --*/
  13. #include "precomp.h"
  14. DWORD
  15. SPDApiBufferAllocate(
  16. DWORD dwByteCount,
  17. LPVOID * ppBuffer
  18. )
  19. {
  20. DWORD dwError = 0;
  21. if (ppBuffer == NULL) {
  22. dwError = ERROR_INVALID_PARAMETER;
  23. BAIL_ON_WIN32_ERROR(dwError);
  24. }
  25. *ppBuffer = NULL;
  26. *ppBuffer = MIDL_user_allocate(dwByteCount);
  27. if (*ppBuffer == NULL) {
  28. dwError = ERROR_OUTOFMEMORY;
  29. BAIL_ON_WIN32_ERROR(dwError);
  30. }
  31. else {
  32. memset((LPBYTE) *ppBuffer, 0, dwByteCount);
  33. }
  34. error:
  35. return (dwError);
  36. }
  37. VOID
  38. SPDApiBufferFree(
  39. LPVOID pBuffer
  40. )
  41. {
  42. if (pBuffer) {
  43. MIDL_user_free(pBuffer);
  44. }
  45. }
  46. DWORD
  47. AddTransportFilter(
  48. LPWSTR pServerName,
  49. DWORD dwVersion,
  50. DWORD dwFlags,
  51. PTRANSPORT_FILTER pTransportFilter,
  52. LPVOID pvReserved,
  53. PHANDLE phFilter
  54. )
  55. {
  56. DWORD dwError = 0;
  57. TRANSPORT_FILTER_CONTAINER FilterContainer;
  58. PTRANSPORT_FILTER_CONTAINER pFilterContainer = &FilterContainer;
  59. if (dwVersion) {
  60. return (ERROR_NOT_SUPPORTED);
  61. }
  62. if (!phFilter) {
  63. return (ERROR_INVALID_PARAMETER);
  64. }
  65. if (pTransportFilter && (pTransportFilter->IpVersion != IPSEC_PROTOCOL_V4)) {
  66. return (ERROR_INVALID_LEVEL);
  67. }
  68. dwError = ValidateTransportFilter(
  69. pTransportFilter
  70. );
  71. BAIL_ON_WIN32_ERROR(dwError);
  72. pFilterContainer->dwNumFilters = 1;
  73. pFilterContainer->pTransportFilters = pTransportFilter;
  74. RpcTryExcept {
  75. dwError = RpcAddTransportFilter(
  76. pServerName,
  77. dwVersion,
  78. dwFlags,
  79. pFilterContainer,
  80. phFilter
  81. );
  82. BAIL_ON_WIN32_ERROR(dwError);
  83. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  84. dwError = TranslateExceptionCode(RpcExceptionCode());
  85. BAIL_ON_WIN32_ERROR(dwError);
  86. } RpcEndExcept
  87. error:
  88. return (dwError);
  89. }
  90. DWORD
  91. DeleteTransportFilter(
  92. HANDLE hFilter
  93. )
  94. {
  95. DWORD dwError = 0;
  96. if (!hFilter) {
  97. return (ERROR_INVALID_PARAMETER);
  98. }
  99. RpcTryExcept {
  100. dwError = RpcDeleteTransportFilter(
  101. &hFilter
  102. );
  103. BAIL_ON_WIN32_ERROR(dwError);
  104. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  105. dwError = TranslateExceptionCode(RpcExceptionCode());
  106. BAIL_ON_WIN32_ERROR(dwError);
  107. } RpcEndExcept
  108. error:
  109. if (dwError) {
  110. dwError = SPDDestroyClientContextHandle(
  111. dwError,
  112. hFilter
  113. );
  114. }
  115. return (dwError);
  116. }
  117. DWORD
  118. EnumTransportFilters(
  119. LPWSTR pServerName,
  120. DWORD dwVersion,
  121. PTRANSPORT_FILTER pTransportTemplateFilter,
  122. DWORD dwLevel,
  123. GUID gGenericFilterID,
  124. DWORD dwPreferredNumEntries,
  125. PTRANSPORT_FILTER * ppTransportFilters,
  126. LPDWORD pdwNumFilters,
  127. LPDWORD pdwResumeHandle,
  128. LPVOID pvReserved
  129. )
  130. {
  131. DWORD dwError = 0;
  132. TRANSPORT_FILTER_CONTAINER FilterContainer;
  133. PTRANSPORT_FILTER_CONTAINER pFilterContainer = &FilterContainer;
  134. TRANSPORT_FILTER_CONTAINER TemplateFilterContainer;
  135. PTRANSPORT_FILTER_CONTAINER pTemplateFilterContainer = &TemplateFilterContainer;
  136. memset(pFilterContainer, 0, sizeof(TRANSPORT_FILTER_CONTAINER));
  137. if (dwVersion) {
  138. return (ERROR_NOT_SUPPORTED);
  139. }
  140. if (pTransportTemplateFilter) {
  141. return (ERROR_NOT_SUPPORTED);
  142. }
  143. if (!ppTransportFilters || !pdwNumFilters || !pdwResumeHandle) {
  144. return (ERROR_INVALID_PARAMETER);
  145. }
  146. switch (dwLevel) {
  147. case ENUM_GENERIC_FILTERS:
  148. case ENUM_SELECT_SPECIFIC_FILTERS:
  149. case ENUM_SPECIFIC_FILTERS:
  150. break;
  151. default:
  152. dwError = ERROR_INVALID_LEVEL;
  153. BAIL_ON_WIN32_ERROR(dwError);
  154. break;
  155. }
  156. pTemplateFilterContainer->dwNumFilters = 0;
  157. pTemplateFilterContainer->pTransportFilters = NULL;
  158. RpcTryExcept {
  159. dwError = RpcEnumTransportFilters(
  160. pServerName,
  161. dwVersion,
  162. pTemplateFilterContainer,
  163. dwLevel,
  164. gGenericFilterID,
  165. dwPreferredNumEntries,
  166. &pFilterContainer,
  167. pdwResumeHandle
  168. );
  169. BAIL_ON_WIN32_ERROR(dwError);
  170. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  171. dwError = TranslateExceptionCode(RpcExceptionCode());
  172. BAIL_ON_WIN32_ERROR(dwError);
  173. } RpcEndExcept
  174. *ppTransportFilters = pFilterContainer->pTransportFilters;
  175. *pdwNumFilters = pFilterContainer->dwNumFilters;
  176. return (dwError);
  177. error:
  178. *ppTransportFilters = NULL;
  179. *pdwNumFilters = 0;
  180. return (dwError);
  181. }
  182. DWORD
  183. SetTransportFilter(
  184. HANDLE hFilter,
  185. DWORD dwVersion,
  186. PTRANSPORT_FILTER pTransportFilter,
  187. LPVOID pvReserved
  188. )
  189. {
  190. DWORD dwError = 0;
  191. TRANSPORT_FILTER_CONTAINER FilterContainer;
  192. PTRANSPORT_FILTER_CONTAINER pFilterContainer = &FilterContainer;
  193. if (dwVersion) {
  194. return (ERROR_NOT_SUPPORTED);
  195. }
  196. if (!hFilter) {
  197. return (ERROR_INVALID_PARAMETER);
  198. }
  199. if (pTransportFilter && (pTransportFilter->IpVersion != IPSEC_PROTOCOL_V4)) {
  200. return (ERROR_INVALID_LEVEL);
  201. }
  202. dwError = ValidateTransportFilter(
  203. pTransportFilter
  204. );
  205. BAIL_ON_WIN32_ERROR(dwError);
  206. pFilterContainer->dwNumFilters = 1;
  207. pFilterContainer->pTransportFilters = pTransportFilter;
  208. RpcTryExcept {
  209. dwError = RpcSetTransportFilter(
  210. hFilter,
  211. dwVersion,
  212. pFilterContainer
  213. );
  214. BAIL_ON_WIN32_ERROR(dwError);
  215. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  216. dwError = TranslateExceptionCode(RpcExceptionCode());
  217. BAIL_ON_WIN32_ERROR(dwError);
  218. } RpcEndExcept
  219. error:
  220. return (dwError);
  221. }
  222. DWORD
  223. GetTransportFilter(
  224. HANDLE hFilter,
  225. DWORD dwVersion,
  226. PTRANSPORT_FILTER * ppTransportFilter,
  227. LPVOID pvReserved
  228. )
  229. {
  230. DWORD dwError = 0;
  231. TRANSPORT_FILTER_CONTAINER FilterContainer;
  232. PTRANSPORT_FILTER_CONTAINER pFilterContainer = &FilterContainer;
  233. memset(pFilterContainer, 0, sizeof(TRANSPORT_FILTER_CONTAINER));
  234. if (dwVersion) {
  235. return (ERROR_NOT_SUPPORTED);
  236. }
  237. if (!hFilter || !ppTransportFilter) {
  238. return (ERROR_INVALID_PARAMETER);
  239. }
  240. RpcTryExcept {
  241. dwError = RpcGetTransportFilter(
  242. hFilter,
  243. dwVersion,
  244. &pFilterContainer
  245. );
  246. BAIL_ON_WIN32_ERROR(dwError);
  247. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  248. dwError = TranslateExceptionCode(RpcExceptionCode());
  249. BAIL_ON_WIN32_ERROR(dwError);
  250. } RpcEndExcept
  251. *ppTransportFilter = pFilterContainer->pTransportFilters;
  252. return (dwError);
  253. error:
  254. *ppTransportFilter = NULL;
  255. return (dwError);
  256. }
  257. DWORD
  258. AddQMPolicy(
  259. LPWSTR pServerName,
  260. DWORD dwVersion,
  261. DWORD dwFlags,
  262. PIPSEC_QM_POLICY pQMPolicy,
  263. LPVOID pvReserved
  264. )
  265. {
  266. DWORD dwError = 0;
  267. IPSEC_QM_POLICY_CONTAINER QMPolicyContainer;
  268. PIPSEC_QM_POLICY_CONTAINER pQMPolicyContainer = &QMPolicyContainer;
  269. if (dwVersion) {
  270. return (ERROR_NOT_SUPPORTED);
  271. }
  272. dwError = ValidateQMPolicy(
  273. pQMPolicy
  274. );
  275. BAIL_ON_WIN32_ERROR(dwError);
  276. pQMPolicyContainer->dwNumPolicies = 1;
  277. pQMPolicyContainer->pPolicies = pQMPolicy;
  278. RpcTryExcept {
  279. dwError = RpcAddQMPolicy(
  280. pServerName,
  281. dwVersion,
  282. dwFlags,
  283. pQMPolicyContainer
  284. );
  285. BAIL_ON_WIN32_ERROR(dwError);
  286. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  287. dwError = TranslateExceptionCode(RpcExceptionCode());
  288. BAIL_ON_WIN32_ERROR(dwError);
  289. } RpcEndExcept
  290. error:
  291. return (dwError);
  292. }
  293. DWORD
  294. DeleteQMPolicy(
  295. LPWSTR pServerName,
  296. DWORD dwVersion,
  297. LPWSTR pszPolicyName,
  298. LPVOID pvReserved
  299. )
  300. {
  301. DWORD dwError = 0;
  302. if (dwVersion) {
  303. return (ERROR_NOT_SUPPORTED);
  304. }
  305. if (!pszPolicyName || !*pszPolicyName) {
  306. dwError = ERROR_INVALID_PARAMETER;
  307. BAIL_ON_WIN32_ERROR(dwError);
  308. }
  309. RpcTryExcept {
  310. dwError = RpcDeleteQMPolicy(
  311. pServerName,
  312. dwVersion,
  313. pszPolicyName
  314. );
  315. BAIL_ON_WIN32_ERROR(dwError);
  316. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  317. dwError = TranslateExceptionCode(RpcExceptionCode());
  318. BAIL_ON_WIN32_ERROR(dwError);
  319. } RpcEndExcept
  320. error:
  321. return (dwError);
  322. }
  323. DWORD
  324. EnumQMPolicies(
  325. LPWSTR pServerName,
  326. DWORD dwVersion,
  327. PIPSEC_QM_POLICY pQMTemplatePolicy,
  328. DWORD dwFlags,
  329. DWORD dwPreferredNumEntries,
  330. PIPSEC_QM_POLICY * ppQMPolicies,
  331. LPDWORD pdwNumPolicies,
  332. LPDWORD pdwResumeHandle,
  333. LPVOID pvReserved
  334. )
  335. {
  336. DWORD dwError = 0;
  337. IPSEC_QM_POLICY_CONTAINER QMPolicyContainer;
  338. PIPSEC_QM_POLICY_CONTAINER pQMPolicyContainer = &QMPolicyContainer;
  339. IPSEC_QM_POLICY_CONTAINER QMTempPolicyContainer;
  340. PIPSEC_QM_POLICY_CONTAINER pQMTempPolicyContainer = &QMTempPolicyContainer;
  341. memset(pQMPolicyContainer, 0, sizeof(IPSEC_QM_POLICY_CONTAINER));
  342. if (dwVersion) {
  343. return (ERROR_NOT_SUPPORTED);
  344. }
  345. if (pQMTemplatePolicy) {
  346. return (ERROR_NOT_SUPPORTED);
  347. }
  348. if (!ppQMPolicies || !pdwNumPolicies || !pdwResumeHandle) {
  349. //
  350. // Do not bail to error from here.
  351. //
  352. return (ERROR_INVALID_PARAMETER);
  353. }
  354. pQMTempPolicyContainer->dwNumPolicies = 0;
  355. pQMTempPolicyContainer->pPolicies = NULL;
  356. RpcTryExcept {
  357. dwError = RpcEnumQMPolicies(
  358. pServerName,
  359. dwVersion,
  360. pQMTempPolicyContainer,
  361. dwFlags,
  362. dwPreferredNumEntries,
  363. &pQMPolicyContainer,
  364. pdwResumeHandle
  365. );
  366. BAIL_ON_WIN32_ERROR(dwError);
  367. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  368. dwError = TranslateExceptionCode(RpcExceptionCode());
  369. BAIL_ON_WIN32_ERROR(dwError);
  370. } RpcEndExcept
  371. *ppQMPolicies = pQMPolicyContainer->pPolicies;
  372. *pdwNumPolicies = pQMPolicyContainer->dwNumPolicies;
  373. return (dwError);
  374. error:
  375. *ppQMPolicies = NULL;
  376. *pdwNumPolicies = 0;
  377. return (dwError);
  378. }
  379. DWORD
  380. SetQMPolicy(
  381. LPWSTR pServerName,
  382. DWORD dwVersion,
  383. LPWSTR pszPolicyName,
  384. PIPSEC_QM_POLICY pQMPolicy,
  385. LPVOID pvReserved
  386. )
  387. {
  388. DWORD dwError = 0;
  389. IPSEC_QM_POLICY_CONTAINER QMPolicyContainer;
  390. PIPSEC_QM_POLICY_CONTAINER pQMPolicyContainer = &QMPolicyContainer;
  391. if (dwVersion) {
  392. return (ERROR_NOT_SUPPORTED);
  393. }
  394. if (!pszPolicyName || !*pszPolicyName) {
  395. dwError = ERROR_INVALID_PARAMETER;
  396. BAIL_ON_WIN32_ERROR(dwError);
  397. }
  398. dwError = ValidateQMPolicy(
  399. pQMPolicy
  400. );
  401. BAIL_ON_WIN32_ERROR(dwError);
  402. pQMPolicyContainer->dwNumPolicies = 1;
  403. pQMPolicyContainer->pPolicies = pQMPolicy;
  404. RpcTryExcept {
  405. dwError = RpcSetQMPolicy(
  406. pServerName,
  407. dwVersion,
  408. pszPolicyName,
  409. pQMPolicyContainer
  410. );
  411. BAIL_ON_WIN32_ERROR(dwError);
  412. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  413. dwError = TranslateExceptionCode(RpcExceptionCode());
  414. BAIL_ON_WIN32_ERROR(dwError);
  415. } RpcEndExcept
  416. error:
  417. return (dwError);
  418. }
  419. DWORD
  420. GetQMPolicy(
  421. LPWSTR pServerName,
  422. DWORD dwVersion,
  423. LPWSTR pszPolicyName,
  424. DWORD dwFlags,
  425. PIPSEC_QM_POLICY * ppQMPolicy,
  426. LPVOID pvReserved
  427. )
  428. {
  429. DWORD dwError = 0;
  430. IPSEC_QM_POLICY_CONTAINER QMPolicyContainer;
  431. PIPSEC_QM_POLICY_CONTAINER pQMPolicyContainer = &QMPolicyContainer;
  432. memset(pQMPolicyContainer, 0, sizeof(IPSEC_QM_POLICY_CONTAINER));
  433. if (dwVersion) {
  434. return (ERROR_NOT_SUPPORTED);
  435. }
  436. if (!pszPolicyName || !*pszPolicyName || !ppQMPolicy) {
  437. //
  438. // Do not bail to error from here.
  439. //
  440. return (ERROR_INVALID_PARAMETER);
  441. }
  442. RpcTryExcept {
  443. dwError = RpcGetQMPolicy(
  444. pServerName,
  445. dwVersion,
  446. pszPolicyName,
  447. dwFlags,
  448. &pQMPolicyContainer
  449. );
  450. BAIL_ON_WIN32_ERROR(dwError);
  451. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  452. dwError = TranslateExceptionCode(RpcExceptionCode());
  453. BAIL_ON_WIN32_ERROR(dwError);
  454. } RpcEndExcept
  455. *ppQMPolicy = pQMPolicyContainer->pPolicies;
  456. return (dwError);
  457. error:
  458. *ppQMPolicy = NULL;
  459. return (dwError);
  460. }
  461. DWORD
  462. AddMMPolicy(
  463. LPWSTR pServerName,
  464. DWORD dwVersion,
  465. DWORD dwFlags,
  466. PIPSEC_MM_POLICY pMMPolicy,
  467. LPVOID pvReserved
  468. )
  469. {
  470. DWORD dwError = 0;
  471. IPSEC_MM_POLICY_CONTAINER MMPolicyContainer;
  472. PIPSEC_MM_POLICY_CONTAINER pMMPolicyContainer = &MMPolicyContainer;
  473. if (dwVersion) {
  474. return (ERROR_NOT_SUPPORTED);
  475. }
  476. dwError = ValidateMMPolicy(
  477. pMMPolicy
  478. );
  479. BAIL_ON_WIN32_ERROR(dwError);
  480. pMMPolicyContainer->dwNumPolicies = 1;
  481. pMMPolicyContainer->pPolicies = pMMPolicy;
  482. RpcTryExcept {
  483. dwError = RpcAddMMPolicy(
  484. pServerName,
  485. dwVersion,
  486. dwFlags,
  487. pMMPolicyContainer
  488. );
  489. BAIL_ON_WIN32_ERROR(dwError);
  490. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  491. dwError = TranslateExceptionCode(RpcExceptionCode());
  492. BAIL_ON_WIN32_ERROR(dwError);
  493. } RpcEndExcept
  494. error:
  495. return (dwError);
  496. }
  497. DWORD
  498. DeleteMMPolicy(
  499. LPWSTR pServerName,
  500. DWORD dwVersion,
  501. LPWSTR pszPolicyName,
  502. LPVOID pvReserved
  503. )
  504. {
  505. DWORD dwError = 0;
  506. if (dwVersion) {
  507. return (ERROR_NOT_SUPPORTED);
  508. }
  509. if (!pszPolicyName || !*pszPolicyName) {
  510. dwError = ERROR_INVALID_PARAMETER;
  511. BAIL_ON_WIN32_ERROR(dwError);
  512. }
  513. RpcTryExcept {
  514. dwError = RpcDeleteMMPolicy(
  515. pServerName,
  516. dwVersion,
  517. pszPolicyName
  518. );
  519. BAIL_ON_WIN32_ERROR(dwError);
  520. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  521. dwError = TranslateExceptionCode(RpcExceptionCode());
  522. BAIL_ON_WIN32_ERROR(dwError);
  523. } RpcEndExcept
  524. error:
  525. return (dwError);
  526. }
  527. DWORD
  528. EnumMMPolicies(
  529. LPWSTR pServerName,
  530. DWORD dwVersion,
  531. PIPSEC_MM_POLICY pMMTemplatePolicy,
  532. DWORD dwFlags,
  533. DWORD dwPreferredNumEntries,
  534. PIPSEC_MM_POLICY * ppMMPolicies,
  535. LPDWORD pdwNumPolicies,
  536. LPDWORD pdwResumeHandle,
  537. LPVOID pvReserved
  538. )
  539. {
  540. DWORD dwError = 0;
  541. IPSEC_MM_POLICY_CONTAINER MMPolicyContainer;
  542. PIPSEC_MM_POLICY_CONTAINER pMMPolicyContainer = &MMPolicyContainer;
  543. IPSEC_MM_POLICY_CONTAINER MMTempPolicyContainer;
  544. PIPSEC_MM_POLICY_CONTAINER pMMTempPolicyContainer = &MMTempPolicyContainer;
  545. memset(pMMPolicyContainer, 0, sizeof(IPSEC_MM_POLICY_CONTAINER));
  546. if (dwVersion) {
  547. return (ERROR_NOT_SUPPORTED);
  548. }
  549. if (pMMTemplatePolicy) {
  550. return (ERROR_NOT_SUPPORTED);
  551. }
  552. if (!ppMMPolicies || !pdwNumPolicies || !pdwResumeHandle) {
  553. //
  554. // Do not bail to error from here.
  555. //
  556. return (ERROR_INVALID_PARAMETER);
  557. }
  558. pMMTempPolicyContainer->dwNumPolicies = 0;
  559. pMMTempPolicyContainer->pPolicies = NULL;
  560. RpcTryExcept {
  561. dwError = RpcEnumMMPolicies(
  562. pServerName,
  563. dwVersion,
  564. pMMTempPolicyContainer,
  565. dwFlags,
  566. dwPreferredNumEntries,
  567. &pMMPolicyContainer,
  568. pdwResumeHandle
  569. );
  570. BAIL_ON_WIN32_ERROR(dwError);
  571. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  572. dwError = TranslateExceptionCode(RpcExceptionCode());
  573. BAIL_ON_WIN32_ERROR(dwError);
  574. } RpcEndExcept
  575. *ppMMPolicies = pMMPolicyContainer->pPolicies;
  576. *pdwNumPolicies = pMMPolicyContainer->dwNumPolicies;
  577. return (dwError);
  578. error:
  579. *ppMMPolicies = NULL;
  580. *pdwNumPolicies = 0;
  581. return (dwError);
  582. }
  583. DWORD
  584. SetMMPolicy(
  585. LPWSTR pServerName,
  586. DWORD dwVersion,
  587. LPWSTR pszPolicyName,
  588. PIPSEC_MM_POLICY pMMPolicy,
  589. LPVOID pvReserved
  590. )
  591. {
  592. DWORD dwError = 0;
  593. IPSEC_MM_POLICY_CONTAINER MMPolicyContainer;
  594. PIPSEC_MM_POLICY_CONTAINER pMMPolicyContainer = &MMPolicyContainer;
  595. if (dwVersion) {
  596. return (ERROR_NOT_SUPPORTED);
  597. }
  598. if (!pszPolicyName || !*pszPolicyName) {
  599. dwError = ERROR_INVALID_PARAMETER;
  600. BAIL_ON_WIN32_ERROR(dwError);
  601. }
  602. dwError = ValidateMMPolicy(
  603. pMMPolicy
  604. );
  605. BAIL_ON_WIN32_ERROR(dwError);
  606. pMMPolicyContainer->dwNumPolicies = 1;
  607. pMMPolicyContainer->pPolicies = pMMPolicy;
  608. RpcTryExcept {
  609. dwError = RpcSetMMPolicy(
  610. pServerName,
  611. dwVersion,
  612. pszPolicyName,
  613. pMMPolicyContainer
  614. );
  615. BAIL_ON_WIN32_ERROR(dwError);
  616. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  617. dwError = TranslateExceptionCode(RpcExceptionCode());
  618. BAIL_ON_WIN32_ERROR(dwError);
  619. } RpcEndExcept
  620. error:
  621. return (dwError);
  622. }
  623. DWORD
  624. GetMMPolicy(
  625. LPWSTR pServerName,
  626. DWORD dwVersion,
  627. LPWSTR pszPolicyName,
  628. PIPSEC_MM_POLICY * ppMMPolicy,
  629. LPVOID pvReserved
  630. )
  631. {
  632. DWORD dwError = 0;
  633. IPSEC_MM_POLICY_CONTAINER MMPolicyContainer;
  634. PIPSEC_MM_POLICY_CONTAINER pMMPolicyContainer = &MMPolicyContainer;
  635. memset(pMMPolicyContainer, 0, sizeof(IPSEC_MM_POLICY_CONTAINER));
  636. if (dwVersion) {
  637. return (ERROR_NOT_SUPPORTED);
  638. }
  639. if (!pszPolicyName || !*pszPolicyName || !ppMMPolicy) {
  640. //
  641. // Do not bail to error from here.
  642. //
  643. return (ERROR_INVALID_PARAMETER);
  644. }
  645. RpcTryExcept {
  646. dwError = RpcGetMMPolicy(
  647. pServerName,
  648. dwVersion,
  649. pszPolicyName,
  650. &pMMPolicyContainer
  651. );
  652. BAIL_ON_WIN32_ERROR(dwError);
  653. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  654. dwError = TranslateExceptionCode(RpcExceptionCode());
  655. BAIL_ON_WIN32_ERROR(dwError);
  656. } RpcEndExcept
  657. *ppMMPolicy = pMMPolicyContainer->pPolicies;
  658. return (dwError);
  659. error:
  660. *ppMMPolicy = NULL;
  661. return (dwError);
  662. }
  663. DWORD
  664. AddMMFilter(
  665. LPWSTR pServerName,
  666. DWORD dwVersion,
  667. DWORD dwFlags,
  668. PMM_FILTER pMMFilter,
  669. LPVOID pvReserved,
  670. PHANDLE phMMFilter
  671. )
  672. {
  673. DWORD dwError = 0;
  674. MM_FILTER_CONTAINER MMFilterContainer;
  675. PMM_FILTER_CONTAINER pMMFilterContainer = &MMFilterContainer;
  676. if (dwVersion) {
  677. return (ERROR_NOT_SUPPORTED);
  678. }
  679. if (!phMMFilter) {
  680. return (ERROR_INVALID_PARAMETER);
  681. }
  682. if (pMMFilter && (pMMFilter->IpVersion != IPSEC_PROTOCOL_V4)) {
  683. return (ERROR_INVALID_LEVEL);
  684. }
  685. dwError = ValidateMMFilter(
  686. pMMFilter
  687. );
  688. BAIL_ON_WIN32_ERROR(dwError);
  689. pMMFilterContainer->dwNumFilters = 1;
  690. pMMFilterContainer->pMMFilters = pMMFilter;
  691. RpcTryExcept {
  692. dwError = RpcAddMMFilter(
  693. pServerName,
  694. dwVersion,
  695. dwFlags,
  696. pMMFilterContainer,
  697. phMMFilter
  698. );
  699. BAIL_ON_WIN32_ERROR(dwError);
  700. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  701. dwError = TranslateExceptionCode(RpcExceptionCode());
  702. BAIL_ON_WIN32_ERROR(dwError);
  703. } RpcEndExcept
  704. error:
  705. return (dwError);
  706. }
  707. DWORD
  708. DeleteMMFilter(
  709. HANDLE hMMFilter
  710. )
  711. {
  712. DWORD dwError = 0;
  713. if (!hMMFilter) {
  714. return (ERROR_INVALID_PARAMETER);
  715. }
  716. RpcTryExcept {
  717. dwError = RpcDeleteMMFilter(
  718. &hMMFilter
  719. );
  720. BAIL_ON_WIN32_ERROR(dwError);
  721. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  722. dwError = TranslateExceptionCode(RpcExceptionCode());
  723. BAIL_ON_WIN32_ERROR(dwError);
  724. } RpcEndExcept
  725. error:
  726. if (dwError) {
  727. dwError = SPDDestroyClientContextHandle(
  728. dwError,
  729. hMMFilter
  730. );
  731. }
  732. return (dwError);
  733. }
  734. DWORD
  735. EnumMMFilters(
  736. LPWSTR pServerName,
  737. DWORD dwVersion,
  738. PMM_FILTER pMMTemplateFilter,
  739. DWORD dwLevel,
  740. GUID gGenericFilterID,
  741. DWORD dwPreferredNumEntries,
  742. PMM_FILTER * ppMMFilters,
  743. LPDWORD pdwNumMMFilters,
  744. LPDWORD pdwResumeHandle,
  745. LPVOID pvReserved
  746. )
  747. {
  748. DWORD dwError = 0;
  749. MM_FILTER_CONTAINER MMFilterContainer;
  750. PMM_FILTER_CONTAINER pMMFilterContainer = &MMFilterContainer;
  751. MM_FILTER_CONTAINER TemplateFilterContainer;
  752. PMM_FILTER_CONTAINER pTemplateFilterContainer = &TemplateFilterContainer;
  753. memset(pMMFilterContainer, 0, sizeof(MM_FILTER_CONTAINER));
  754. if (dwVersion) {
  755. return (ERROR_NOT_SUPPORTED);
  756. }
  757. if (pMMTemplateFilter) {
  758. return (ERROR_NOT_SUPPORTED);
  759. }
  760. if (!ppMMFilters || !pdwNumMMFilters || !pdwResumeHandle) {
  761. return (ERROR_INVALID_PARAMETER);
  762. }
  763. switch (dwLevel) {
  764. case ENUM_GENERIC_FILTERS:
  765. case ENUM_SELECT_SPECIFIC_FILTERS:
  766. case ENUM_SPECIFIC_FILTERS:
  767. break;
  768. default:
  769. dwError = ERROR_INVALID_LEVEL;
  770. BAIL_ON_WIN32_ERROR(dwError);
  771. break;
  772. }
  773. pTemplateFilterContainer->dwNumFilters = 0;
  774. pTemplateFilterContainer->pMMFilters = NULL;
  775. RpcTryExcept {
  776. dwError = RpcEnumMMFilters(
  777. pServerName,
  778. dwVersion,
  779. pTemplateFilterContainer,
  780. dwLevel,
  781. gGenericFilterID,
  782. dwPreferredNumEntries,
  783. &pMMFilterContainer,
  784. pdwResumeHandle
  785. );
  786. BAIL_ON_WIN32_ERROR(dwError);
  787. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  788. dwError = TranslateExceptionCode(RpcExceptionCode());
  789. BAIL_ON_WIN32_ERROR(dwError);
  790. } RpcEndExcept
  791. *ppMMFilters = pMMFilterContainer->pMMFilters;
  792. *pdwNumMMFilters = pMMFilterContainer->dwNumFilters;
  793. return (dwError);
  794. error:
  795. *ppMMFilters = NULL;
  796. *pdwNumMMFilters = 0;
  797. return (dwError);
  798. }
  799. DWORD
  800. SetMMFilter(
  801. HANDLE hMMFilter,
  802. DWORD dwVersion,
  803. PMM_FILTER pMMFilter,
  804. LPVOID pvReserved
  805. )
  806. {
  807. DWORD dwError = 0;
  808. MM_FILTER_CONTAINER MMFilterContainer;
  809. PMM_FILTER_CONTAINER pMMFilterContainer = &MMFilterContainer;
  810. if (dwVersion) {
  811. return (ERROR_NOT_SUPPORTED);
  812. }
  813. if (!hMMFilter) {
  814. return (ERROR_INVALID_PARAMETER);
  815. }
  816. if (pMMFilter && (pMMFilter->IpVersion != IPSEC_PROTOCOL_V4)) {
  817. return (ERROR_INVALID_LEVEL);
  818. }
  819. dwError = ValidateMMFilter(
  820. pMMFilter
  821. );
  822. BAIL_ON_WIN32_ERROR(dwError);
  823. pMMFilterContainer->dwNumFilters = 1;
  824. pMMFilterContainer->pMMFilters = pMMFilter;
  825. RpcTryExcept {
  826. dwError = RpcSetMMFilter(
  827. hMMFilter,
  828. dwVersion,
  829. pMMFilterContainer
  830. );
  831. BAIL_ON_WIN32_ERROR(dwError);
  832. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  833. dwError = TranslateExceptionCode(RpcExceptionCode());
  834. BAIL_ON_WIN32_ERROR(dwError);
  835. } RpcEndExcept
  836. error:
  837. return (dwError);
  838. }
  839. DWORD
  840. GetMMFilter(
  841. HANDLE hMMFilter,
  842. DWORD dwVersion,
  843. PMM_FILTER * ppMMFilter,
  844. LPVOID pvReserved
  845. )
  846. {
  847. DWORD dwError = 0;
  848. MM_FILTER_CONTAINER MMFilterContainer;
  849. PMM_FILTER_CONTAINER pMMFilterContainer = &MMFilterContainer;
  850. memset(pMMFilterContainer, 0, sizeof(MM_FILTER_CONTAINER));
  851. if (dwVersion) {
  852. return (ERROR_NOT_SUPPORTED);
  853. }
  854. if (!hMMFilter || !ppMMFilter) {
  855. return (ERROR_INVALID_PARAMETER);
  856. }
  857. RpcTryExcept {
  858. dwError = RpcGetMMFilter(
  859. hMMFilter,
  860. dwVersion,
  861. &pMMFilterContainer
  862. );
  863. BAIL_ON_WIN32_ERROR(dwError);
  864. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  865. dwError = TranslateExceptionCode(RpcExceptionCode());
  866. BAIL_ON_WIN32_ERROR(dwError);
  867. } RpcEndExcept
  868. *ppMMFilter = pMMFilterContainer->pMMFilters;
  869. return (dwError);
  870. error:
  871. *ppMMFilter = NULL;
  872. return (dwError);
  873. }
  874. DWORD
  875. MatchMMFilter(
  876. LPWSTR pServerName,
  877. DWORD dwVersion,
  878. PMM_FILTER pMMFilter,
  879. DWORD dwFlags,
  880. DWORD dwPreferredNumEntries,
  881. PMM_FILTER * ppMatchedMMFilters,
  882. PIPSEC_MM_POLICY * ppMatchedMMPolicies,
  883. PMM_AUTH_METHODS * ppMatchedMMAuthMethods,
  884. LPDWORD pdwNumMatches,
  885. LPDWORD pdwResumeHandle,
  886. LPVOID pvReserved
  887. )
  888. {
  889. DWORD dwError = 0;
  890. MM_FILTER_CONTAINER InMMFilterContainer;
  891. PMM_FILTER_CONTAINER pInMMFilterContainer = &InMMFilterContainer;
  892. MM_FILTER_CONTAINER OutMMFilterContainer;
  893. PMM_FILTER_CONTAINER pOutMMFilterContainer = &OutMMFilterContainer;
  894. IPSEC_MM_POLICY_CONTAINER MMPolicyContainer;
  895. PIPSEC_MM_POLICY_CONTAINER pMMPolicyContainer = &MMPolicyContainer;
  896. MM_AUTH_METHODS_CONTAINER MMAuthContainer;
  897. PMM_AUTH_METHODS_CONTAINER pMMAuthContainer = &MMAuthContainer;
  898. if (dwVersion) {
  899. return (ERROR_NOT_SUPPORTED);
  900. }
  901. if (!pMMFilter || !ppMatchedMMFilters || !ppMatchedMMPolicies ||
  902. !ppMatchedMMAuthMethods || !pdwNumMatches || !pdwResumeHandle) {
  903. return (ERROR_INVALID_PARAMETER);
  904. }
  905. if (pMMFilter && (pMMFilter->IpVersion != IPSEC_PROTOCOL_V4)) {
  906. return (ERROR_INVALID_LEVEL);
  907. }
  908. dwError = ValidateMMFilterTemplate(
  909. pMMFilter
  910. );
  911. BAIL_ON_WIN32_ERROR(dwError);
  912. pInMMFilterContainer->dwNumFilters = 1;
  913. pInMMFilterContainer->pMMFilters = pMMFilter;
  914. memset(pOutMMFilterContainer, 0, sizeof(MM_FILTER_CONTAINER));
  915. memset(pMMPolicyContainer, 0, sizeof(IPSEC_MM_POLICY_CONTAINER));
  916. memset(pMMAuthContainer, 0, sizeof(MM_AUTH_METHODS_CONTAINER));
  917. RpcTryExcept {
  918. dwError = RpcMatchMMFilter(
  919. pServerName,
  920. dwVersion,
  921. pInMMFilterContainer,
  922. dwFlags,
  923. dwPreferredNumEntries,
  924. &pOutMMFilterContainer,
  925. &pMMPolicyContainer,
  926. &pMMAuthContainer,
  927. pdwResumeHandle
  928. );
  929. BAIL_ON_WIN32_ERROR(dwError);
  930. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  931. dwError = TranslateExceptionCode(RpcExceptionCode());
  932. BAIL_ON_WIN32_ERROR(dwError);
  933. } RpcEndExcept
  934. *ppMatchedMMFilters = pOutMMFilterContainer->pMMFilters;
  935. *ppMatchedMMPolicies = pMMPolicyContainer->pPolicies;
  936. *ppMatchedMMAuthMethods = pMMAuthContainer->pMMAuthMethods;
  937. *pdwNumMatches = pOutMMFilterContainer->dwNumFilters;
  938. return (dwError);
  939. error:
  940. *ppMatchedMMFilters = NULL;
  941. *ppMatchedMMPolicies = NULL;
  942. *ppMatchedMMAuthMethods = NULL;
  943. *pdwNumMatches = 0;
  944. return (dwError);
  945. }
  946. DWORD
  947. MatchTransportFilter(
  948. LPWSTR pServerName,
  949. DWORD dwVersion,
  950. PTRANSPORT_FILTER pTxFilter,
  951. DWORD dwFlags,
  952. DWORD dwPreferredNumEntries,
  953. PTRANSPORT_FILTER * ppMatchedTxFilters,
  954. PIPSEC_QM_POLICY * ppMatchedQMPolicies,
  955. LPDWORD pdwNumMatches,
  956. LPDWORD pdwResumeHandle,
  957. LPVOID pvReserved
  958. )
  959. {
  960. DWORD dwError = 0;
  961. TRANSPORT_FILTER_CONTAINER InTxFilterContainer;
  962. PTRANSPORT_FILTER_CONTAINER pInTxFilterContainer = &InTxFilterContainer;
  963. TRANSPORT_FILTER_CONTAINER OutTxFilterContainer;
  964. PTRANSPORT_FILTER_CONTAINER pOutTxFilterContainer = &OutTxFilterContainer;
  965. IPSEC_QM_POLICY_CONTAINER QMPolicyContainer;
  966. PIPSEC_QM_POLICY_CONTAINER pQMPolicyContainer = &QMPolicyContainer;
  967. if (dwVersion) {
  968. return (ERROR_NOT_SUPPORTED);
  969. }
  970. if (!pTxFilter || !ppMatchedTxFilters || !ppMatchedQMPolicies ||
  971. !pdwNumMatches || !pdwResumeHandle) {
  972. return (ERROR_INVALID_PARAMETER);
  973. }
  974. if (pTxFilter && (pTxFilter->IpVersion != IPSEC_PROTOCOL_V4)) {
  975. return (ERROR_INVALID_LEVEL);
  976. }
  977. dwError = ValidateTxFilterTemplate(
  978. pTxFilter
  979. );
  980. BAIL_ON_WIN32_ERROR(dwError);
  981. pInTxFilterContainer->dwNumFilters = 1;
  982. pInTxFilterContainer->pTransportFilters = pTxFilter;
  983. memset(pOutTxFilterContainer, 0, sizeof(TRANSPORT_FILTER_CONTAINER));
  984. memset(pQMPolicyContainer, 0, sizeof(IPSEC_QM_POLICY_CONTAINER));
  985. RpcTryExcept {
  986. dwError = RpcMatchTransportFilter(
  987. pServerName,
  988. dwVersion,
  989. pInTxFilterContainer,
  990. dwFlags,
  991. dwPreferredNumEntries,
  992. &pOutTxFilterContainer,
  993. &pQMPolicyContainer,
  994. pdwResumeHandle
  995. );
  996. BAIL_ON_WIN32_ERROR(dwError);
  997. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  998. dwError = TranslateExceptionCode(RpcExceptionCode());
  999. BAIL_ON_WIN32_ERROR(dwError);
  1000. } RpcEndExcept
  1001. *ppMatchedTxFilters = pOutTxFilterContainer->pTransportFilters;
  1002. *ppMatchedQMPolicies = pQMPolicyContainer->pPolicies;
  1003. *pdwNumMatches = pOutTxFilterContainer->dwNumFilters;
  1004. return (dwError);
  1005. error:
  1006. *ppMatchedTxFilters = NULL;
  1007. *ppMatchedQMPolicies = NULL;
  1008. *pdwNumMatches = 0;
  1009. return (dwError);
  1010. }
  1011. DWORD
  1012. GetQMPolicyByID(
  1013. LPWSTR pServerName,
  1014. DWORD dwVersion,
  1015. GUID gQMPolicyID,
  1016. DWORD dwFlags,
  1017. PIPSEC_QM_POLICY * ppQMPolicy,
  1018. LPVOID pvReserved
  1019. )
  1020. {
  1021. DWORD dwError = 0;
  1022. IPSEC_QM_POLICY_CONTAINER QMPolicyContainer;
  1023. PIPSEC_QM_POLICY_CONTAINER pQMPolicyContainer = &QMPolicyContainer;
  1024. memset(pQMPolicyContainer, 0, sizeof(IPSEC_QM_POLICY_CONTAINER));
  1025. if (dwVersion) {
  1026. return (ERROR_NOT_SUPPORTED);
  1027. }
  1028. if (!ppQMPolicy) {
  1029. return (ERROR_INVALID_PARAMETER);
  1030. }
  1031. RpcTryExcept {
  1032. dwError = RpcGetQMPolicyByID(
  1033. pServerName,
  1034. dwVersion,
  1035. gQMPolicyID,
  1036. dwFlags,
  1037. &pQMPolicyContainer
  1038. );
  1039. BAIL_ON_WIN32_ERROR(dwError);
  1040. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  1041. dwError = TranslateExceptionCode(RpcExceptionCode());
  1042. BAIL_ON_WIN32_ERROR(dwError);
  1043. } RpcEndExcept
  1044. *ppQMPolicy = pQMPolicyContainer->pPolicies;
  1045. return (dwError);
  1046. error:
  1047. *ppQMPolicy = NULL;
  1048. return (dwError);
  1049. }
  1050. DWORD
  1051. GetMMPolicyByID(
  1052. LPWSTR pServerName,
  1053. DWORD dwVersion,
  1054. GUID gMMPolicyID,
  1055. PIPSEC_MM_POLICY * ppMMPolicy,
  1056. LPVOID pvReserved
  1057. )
  1058. {
  1059. DWORD dwError = 0;
  1060. IPSEC_MM_POLICY_CONTAINER MMPolicyContainer;
  1061. PIPSEC_MM_POLICY_CONTAINER pMMPolicyContainer = &MMPolicyContainer;
  1062. memset(pMMPolicyContainer, 0, sizeof(IPSEC_MM_POLICY_CONTAINER));
  1063. if (dwVersion) {
  1064. return (ERROR_NOT_SUPPORTED);
  1065. }
  1066. if (!ppMMPolicy) {
  1067. return (ERROR_INVALID_PARAMETER);
  1068. }
  1069. RpcTryExcept {
  1070. dwError = RpcGetMMPolicyByID(
  1071. pServerName,
  1072. dwVersion,
  1073. gMMPolicyID,
  1074. &pMMPolicyContainer
  1075. );
  1076. BAIL_ON_WIN32_ERROR(dwError);
  1077. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  1078. dwError = TranslateExceptionCode(RpcExceptionCode());
  1079. BAIL_ON_WIN32_ERROR(dwError);
  1080. } RpcEndExcept
  1081. *ppMMPolicy = pMMPolicyContainer->pPolicies;
  1082. return (dwError);
  1083. error:
  1084. *ppMMPolicy = NULL;
  1085. return (dwError);
  1086. }
  1087. DWORD
  1088. AddMMAuthMethods(
  1089. LPWSTR pServerName,
  1090. DWORD dwVersion,
  1091. DWORD dwFlags,
  1092. PMM_AUTH_METHODS pMMAuthMethods,
  1093. LPVOID pvReserved
  1094. )
  1095. {
  1096. DWORD dwError = 0;
  1097. MM_AUTH_METHODS_CONTAINER MMAuthContainer;
  1098. PMM_AUTH_METHODS_CONTAINER pMMAuthContainer = &MMAuthContainer;
  1099. if (dwVersion) {
  1100. return (ERROR_NOT_SUPPORTED);
  1101. }
  1102. dwError = ValidateMMAuthMethods(
  1103. pMMAuthMethods
  1104. );
  1105. BAIL_ON_WIN32_ERROR(dwError);
  1106. pMMAuthContainer->dwNumAuthMethods = 1;
  1107. pMMAuthContainer->pMMAuthMethods = pMMAuthMethods;
  1108. RpcTryExcept {
  1109. dwError = RpcAddMMAuthMethods(
  1110. pServerName,
  1111. dwVersion,
  1112. dwFlags,
  1113. pMMAuthContainer
  1114. );
  1115. BAIL_ON_WIN32_ERROR(dwError);
  1116. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  1117. dwError = TranslateExceptionCode(RpcExceptionCode());
  1118. BAIL_ON_WIN32_ERROR(dwError);
  1119. } RpcEndExcept
  1120. error:
  1121. return (dwError);
  1122. }
  1123. DWORD
  1124. DeleteMMAuthMethods(
  1125. LPWSTR pServerName,
  1126. DWORD dwVersion,
  1127. GUID gMMAuthID,
  1128. LPVOID pvReserved
  1129. )
  1130. {
  1131. DWORD dwError = 0;
  1132. if (dwVersion) {
  1133. return (ERROR_NOT_SUPPORTED);
  1134. }
  1135. RpcTryExcept {
  1136. dwError = RpcDeleteMMAuthMethods(
  1137. pServerName,
  1138. dwVersion,
  1139. gMMAuthID
  1140. );
  1141. BAIL_ON_WIN32_ERROR(dwError);
  1142. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  1143. dwError = TranslateExceptionCode(RpcExceptionCode());
  1144. BAIL_ON_WIN32_ERROR(dwError);
  1145. } RpcEndExcept
  1146. error:
  1147. return (dwError);
  1148. }
  1149. DWORD
  1150. EnumMMAuthMethods(
  1151. LPWSTR pServerName,
  1152. DWORD dwVersion,
  1153. PMM_AUTH_METHODS pMMTemplateAuthMethods,
  1154. DWORD dwFlags,
  1155. DWORD dwPreferredNumEntries,
  1156. PMM_AUTH_METHODS * ppMMAuthMethods,
  1157. LPDWORD pdwNumAuthMethods,
  1158. LPDWORD pdwResumeHandle,
  1159. LPVOID pvReserved
  1160. )
  1161. {
  1162. DWORD dwError = 0;
  1163. MM_AUTH_METHODS_CONTAINER MMAuthContainer;
  1164. PMM_AUTH_METHODS_CONTAINER pMMAuthContainer = &MMAuthContainer;
  1165. MM_AUTH_METHODS_CONTAINER MMTempAuthContainer;
  1166. PMM_AUTH_METHODS_CONTAINER pMMTempAuthContainer = &MMTempAuthContainer;
  1167. memset(pMMAuthContainer, 0, sizeof(MM_AUTH_METHODS_CONTAINER));
  1168. if (dwVersion) {
  1169. return (ERROR_NOT_SUPPORTED);
  1170. }
  1171. if (pMMTemplateAuthMethods) {
  1172. return (ERROR_NOT_SUPPORTED);
  1173. }
  1174. if (!ppMMAuthMethods || !pdwNumAuthMethods || !pdwResumeHandle) {
  1175. return (ERROR_INVALID_PARAMETER);
  1176. }
  1177. pMMTempAuthContainer->dwNumAuthMethods = 0;
  1178. pMMTempAuthContainer->pMMAuthMethods = NULL;
  1179. RpcTryExcept {
  1180. dwError = RpcEnumMMAuthMethods(
  1181. pServerName,
  1182. dwVersion,
  1183. pMMTempAuthContainer,
  1184. dwFlags,
  1185. dwPreferredNumEntries,
  1186. &pMMAuthContainer,
  1187. pdwResumeHandle
  1188. );
  1189. BAIL_ON_WIN32_ERROR(dwError);
  1190. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  1191. dwError = TranslateExceptionCode(RpcExceptionCode());
  1192. BAIL_ON_WIN32_ERROR(dwError);
  1193. } RpcEndExcept
  1194. *ppMMAuthMethods = pMMAuthContainer->pMMAuthMethods;
  1195. *pdwNumAuthMethods = pMMAuthContainer->dwNumAuthMethods;
  1196. return (dwError);
  1197. error:
  1198. *ppMMAuthMethods = NULL;
  1199. *pdwNumAuthMethods = 0;
  1200. return (dwError);
  1201. }
  1202. DWORD
  1203. SetMMAuthMethods(
  1204. LPWSTR pServerName,
  1205. DWORD dwVersion,
  1206. GUID gMMAuthID,
  1207. PMM_AUTH_METHODS pMMAuthMethods,
  1208. LPVOID pvReserved
  1209. )
  1210. {
  1211. DWORD dwError = 0;
  1212. MM_AUTH_METHODS_CONTAINER MMAuthContainer;
  1213. PMM_AUTH_METHODS_CONTAINER pMMAuthContainer = &MMAuthContainer;
  1214. if (dwVersion) {
  1215. return (ERROR_NOT_SUPPORTED);
  1216. }
  1217. dwError = ValidateMMAuthMethods(
  1218. pMMAuthMethods
  1219. );
  1220. BAIL_ON_WIN32_ERROR(dwError);
  1221. pMMAuthContainer->dwNumAuthMethods = 1;
  1222. pMMAuthContainer->pMMAuthMethods = pMMAuthMethods;
  1223. RpcTryExcept {
  1224. dwError = RpcSetMMAuthMethods(
  1225. pServerName,
  1226. dwVersion,
  1227. gMMAuthID,
  1228. pMMAuthContainer
  1229. );
  1230. BAIL_ON_WIN32_ERROR(dwError);
  1231. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  1232. dwError = TranslateExceptionCode(RpcExceptionCode());
  1233. BAIL_ON_WIN32_ERROR(dwError);
  1234. } RpcEndExcept
  1235. error:
  1236. return (dwError);
  1237. }
  1238. DWORD
  1239. GetMMAuthMethods(
  1240. LPWSTR pServerName,
  1241. DWORD dwVersion,
  1242. GUID gMMAuthID,
  1243. PMM_AUTH_METHODS * ppMMAuthMethods,
  1244. LPVOID pvReserved
  1245. )
  1246. {
  1247. DWORD dwError = 0;
  1248. MM_AUTH_METHODS_CONTAINER MMAuthContainer;
  1249. PMM_AUTH_METHODS_CONTAINER pMMAuthContainer = &MMAuthContainer;
  1250. memset(pMMAuthContainer, 0, sizeof(MM_AUTH_METHODS_CONTAINER));
  1251. if (dwVersion) {
  1252. return (ERROR_NOT_SUPPORTED);
  1253. }
  1254. if (!ppMMAuthMethods) {
  1255. return (ERROR_INVALID_PARAMETER);
  1256. }
  1257. RpcTryExcept {
  1258. dwError = RpcGetMMAuthMethods(
  1259. pServerName,
  1260. dwVersion,
  1261. gMMAuthID,
  1262. &pMMAuthContainer
  1263. );
  1264. BAIL_ON_WIN32_ERROR(dwError);
  1265. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  1266. dwError = TranslateExceptionCode(RpcExceptionCode());
  1267. BAIL_ON_WIN32_ERROR(dwError);
  1268. } RpcEndExcept
  1269. *ppMMAuthMethods = pMMAuthContainer->pMMAuthMethods;
  1270. return (dwError);
  1271. error:
  1272. *ppMMAuthMethods = NULL;
  1273. return (dwError);
  1274. }
  1275. DWORD
  1276. InitiateIKENegotiation(
  1277. LPWSTR pServerName,
  1278. DWORD dwVersion,
  1279. PIPSEC_QM_FILTER pQMFilter,
  1280. DWORD dwClientProcessId,
  1281. HANDLE hClientEvent,
  1282. DWORD dwFlags,
  1283. IPSEC_UDP_ENCAP_CONTEXT UdpEncapContext,
  1284. LPVOID pvReserved,
  1285. PHANDLE phNegotiation
  1286. )
  1287. {
  1288. DWORD dwError = 0;
  1289. QM_FILTER_CONTAINER FilterContainer;
  1290. PQM_FILTER_CONTAINER pFilterContainer = &FilterContainer;
  1291. ULONG uhClientEvent = 0;
  1292. if (dwVersion) {
  1293. return (ERROR_NOT_SUPPORTED);
  1294. }
  1295. pFilterContainer->dwNumFilters = 1;
  1296. pFilterContainer->pQMFilters = pQMFilter;
  1297. uhClientEvent = HandleToUlong(hClientEvent);
  1298. if (phNegotiation) {
  1299. *phNegotiation = NULL;
  1300. }
  1301. if (pQMFilter && (pQMFilter->IpVersion != IPSEC_PROTOCOL_V4)) {
  1302. return (ERROR_INVALID_LEVEL);
  1303. }
  1304. dwError=ValidateInitiateIKENegotiation(
  1305. pServerName,
  1306. pFilterContainer,
  1307. dwClientProcessId,
  1308. uhClientEvent,
  1309. dwFlags,
  1310. UdpEncapContext,
  1311. phNegotiation
  1312. );
  1313. BAIL_ON_WIN32_ERROR(dwError);
  1314. RpcTryExcept {
  1315. dwError = RpcInitiateIKENegotiation(
  1316. pServerName,
  1317. dwVersion,
  1318. pFilterContainer,
  1319. dwClientProcessId,
  1320. uhClientEvent,
  1321. dwFlags,
  1322. UdpEncapContext,
  1323. phNegotiation
  1324. );
  1325. BAIL_ON_WIN32_ERROR(dwError);
  1326. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  1327. dwError = TranslateExceptionCode(RpcExceptionCode());
  1328. BAIL_ON_WIN32_ERROR(dwError);
  1329. } RpcEndExcept
  1330. error:
  1331. return (dwError);
  1332. }
  1333. DWORD
  1334. QueryIKENegotiationStatus(
  1335. HANDLE hNegotiation,
  1336. DWORD dwVersion,
  1337. PSA_NEGOTIATION_STATUS_INFO pNegotiationStatus,
  1338. LPVOID pvReserved
  1339. )
  1340. {
  1341. DWORD dwError = 0;
  1342. if (dwVersion) {
  1343. return (ERROR_NOT_SUPPORTED);
  1344. }
  1345. dwError = ValidateQueryIKENegotiationStatus(
  1346. hNegotiation,
  1347. pNegotiationStatus
  1348. );
  1349. BAIL_ON_WIN32_ERROR(dwError);
  1350. RpcTryExcept {
  1351. dwError = RpcQueryIKENegotiationStatus(
  1352. hNegotiation,
  1353. dwVersion,
  1354. pNegotiationStatus
  1355. );
  1356. BAIL_ON_WIN32_ERROR(dwError);
  1357. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  1358. dwError = TranslateExceptionCode(RpcExceptionCode());
  1359. BAIL_ON_WIN32_ERROR(dwError);
  1360. } RpcEndExcept
  1361. error:
  1362. return (dwError);
  1363. }
  1364. DWORD
  1365. CloseIKENegotiationHandle(
  1366. HANDLE hNegotiation
  1367. )
  1368. {
  1369. DWORD dwError = 0;
  1370. dwError = ValidateCloseIKENegotiationHandle(hNegotiation);
  1371. BAIL_ON_WIN32_ERROR(dwError);
  1372. RpcTryExcept {
  1373. dwError = RpcCloseIKENegotiationHandle(
  1374. &hNegotiation
  1375. );
  1376. BAIL_ON_WIN32_ERROR(dwError);
  1377. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  1378. dwError = TranslateExceptionCode(RpcExceptionCode());
  1379. BAIL_ON_WIN32_ERROR(dwError);
  1380. } RpcEndExcept
  1381. error:
  1382. return (dwError);
  1383. }
  1384. DWORD
  1385. EnumMMSAs(
  1386. LPWSTR pServerName,
  1387. DWORD dwVersion,
  1388. PIPSEC_MM_SA pMMTemplate,
  1389. DWORD dwFlags,
  1390. DWORD dwPreferredNumEntries,
  1391. PIPSEC_MM_SA * ppMMSAs,
  1392. LPDWORD pdwNumEntries,
  1393. LPDWORD pdwTotalMMsAvailable,
  1394. LPDWORD pdwEnumHandle,
  1395. LPVOID pvReserved
  1396. )
  1397. {
  1398. DWORD dwError = 0;
  1399. MM_SA_CONTAINER MMSAContainer, MMSAContainerTemplate;
  1400. PMM_SA_CONTAINER pContainer = &MMSAContainer;
  1401. if (dwVersion) {
  1402. return (ERROR_NOT_SUPPORTED);
  1403. }
  1404. if (pMMTemplate && (pMMTemplate->IpVersion != IPSEC_PROTOCOL_V4)) {
  1405. return (ERROR_INVALID_LEVEL);
  1406. }
  1407. MMSAContainerTemplate.dwNumMMSAs = 1;
  1408. MMSAContainerTemplate.pMMSAs = pMMTemplate;
  1409. memset(&MMSAContainer, 0, sizeof(MM_SA_CONTAINER));
  1410. if (ppMMSAs == NULL) {
  1411. return (ERROR_INVALID_PARAMETER);
  1412. }
  1413. dwError = ValidateEnumMMSAs(
  1414. pServerName,
  1415. &MMSAContainerTemplate,
  1416. &pContainer,
  1417. pdwNumEntries,
  1418. pdwTotalMMsAvailable,
  1419. pdwEnumHandle,
  1420. dwFlags
  1421. );
  1422. BAIL_ON_WIN32_ERROR(dwError);
  1423. RpcTryExcept {
  1424. dwError = RpcEnumMMSAs(
  1425. pServerName,
  1426. dwVersion,
  1427. &MMSAContainerTemplate,
  1428. dwFlags,
  1429. dwPreferredNumEntries,
  1430. &pContainer,
  1431. pdwNumEntries,
  1432. pdwTotalMMsAvailable,
  1433. pdwEnumHandle
  1434. );
  1435. BAIL_ON_WIN32_ERROR(dwError);
  1436. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  1437. dwError = TranslateExceptionCode(RpcExceptionCode());
  1438. BAIL_ON_WIN32_ERROR(dwError);
  1439. } RpcEndExcept
  1440. *ppMMSAs = pContainer->pMMSAs;
  1441. return (dwError);
  1442. error:
  1443. *ppMMSAs = NULL;
  1444. return (dwError);
  1445. }
  1446. DWORD
  1447. DeleteMMSAs(
  1448. LPWSTR pServerName,
  1449. DWORD dwVersion,
  1450. PIPSEC_MM_SA pMMTemplate,
  1451. DWORD dwFlags,
  1452. LPVOID pvReserved
  1453. )
  1454. {
  1455. DWORD dwError = 0;
  1456. MM_SA_CONTAINER MMSAContainerTemplate;
  1457. if (dwVersion) {
  1458. return (ERROR_NOT_SUPPORTED);
  1459. }
  1460. if (pMMTemplate && (pMMTemplate->IpVersion != IPSEC_PROTOCOL_V4)) {
  1461. return (ERROR_INVALID_LEVEL);
  1462. }
  1463. MMSAContainerTemplate.dwNumMMSAs = 1;
  1464. MMSAContainerTemplate.pMMSAs = pMMTemplate;
  1465. dwError = ValidateDeleteMMSAs(
  1466. pServerName,
  1467. &MMSAContainerTemplate,
  1468. dwFlags
  1469. );
  1470. BAIL_ON_WIN32_ERROR(dwError);
  1471. RpcTryExcept {
  1472. dwError = RpcDeleteMMSAs(
  1473. pServerName,
  1474. dwVersion,
  1475. &MMSAContainerTemplate,
  1476. dwFlags
  1477. );
  1478. BAIL_ON_WIN32_ERROR(dwError);
  1479. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  1480. dwError = TranslateExceptionCode(RpcExceptionCode());
  1481. BAIL_ON_WIN32_ERROR(dwError);
  1482. } RpcEndExcept
  1483. error:
  1484. return (dwError);
  1485. }
  1486. DWORD
  1487. DeleteQMSAs(
  1488. LPWSTR pServerName,
  1489. DWORD dwVersion,
  1490. PIPSEC_QM_SA pIpsecQMSA,
  1491. DWORD dwFlags,
  1492. LPVOID pvReserved
  1493. )
  1494. {
  1495. DWORD dwError = 0;
  1496. QM_SA_CONTAINER QMSATempContainer;
  1497. PQM_SA_CONTAINER pQMSATempContainer = &QMSATempContainer;
  1498. if (dwVersion) {
  1499. return (ERROR_NOT_SUPPORTED);
  1500. }
  1501. if (pIpsecQMSA && (pIpsecQMSA->IpsecQMFilter.IpVersion != IPSEC_PROTOCOL_V4)) {
  1502. return (ERROR_INVALID_LEVEL);
  1503. }
  1504. memset(pQMSATempContainer, 0, sizeof(QM_SA_CONTAINER));
  1505. if (!pIpsecQMSA) {
  1506. dwError = ERROR_INVALID_PARAMETER;
  1507. BAIL_ON_WIN32_ERROR(dwError);
  1508. }
  1509. pQMSATempContainer->dwNumQMSAs = 1;
  1510. pQMSATempContainer->pQMSAs = pIpsecQMSA;
  1511. dwError = ValidateQMFilterAddresses(
  1512. &pQMSATempContainer->pQMSAs->IpsecQMFilter
  1513. );
  1514. BAIL_ON_WIN32_ERROR(dwError);
  1515. RpcTryExcept {
  1516. dwError = RpcDeleteQMSAs(
  1517. pServerName,
  1518. dwVersion,
  1519. pQMSATempContainer,
  1520. dwFlags
  1521. );
  1522. BAIL_ON_WIN32_ERROR(dwError);
  1523. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  1524. dwError = TranslateExceptionCode(RpcExceptionCode());
  1525. BAIL_ON_WIN32_ERROR(dwError);
  1526. } RpcEndExcept
  1527. error:
  1528. return (dwError);
  1529. }
  1530. DWORD
  1531. QueryIKEStatistics(
  1532. LPWSTR pServerName,
  1533. DWORD dwVersion,
  1534. PIKE_STATISTICS pIKEStatistics,
  1535. LPVOID pvReserved
  1536. )
  1537. {
  1538. DWORD dwError = 0;
  1539. if (dwVersion) {
  1540. return (ERROR_NOT_SUPPORTED);
  1541. }
  1542. dwError = ValidateQueryIKEStatistics(
  1543. pServerName,
  1544. pIKEStatistics
  1545. );
  1546. BAIL_ON_WIN32_ERROR(dwError);
  1547. RpcTryExcept {
  1548. dwError = RpcQueryIKEStatistics(
  1549. pServerName,
  1550. dwVersion,
  1551. pIKEStatistics
  1552. );
  1553. BAIL_ON_WIN32_ERROR(dwError);
  1554. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  1555. dwError = TranslateExceptionCode(RpcExceptionCode());
  1556. BAIL_ON_WIN32_ERROR(dwError);
  1557. } RpcEndExcept
  1558. error:
  1559. return (dwError);
  1560. }
  1561. DWORD
  1562. RegisterIKENotifyClient(
  1563. LPWSTR pServerName,
  1564. DWORD dwVersion,
  1565. DWORD dwClientProcessId,
  1566. HANDLE hClientEvent,
  1567. IPSEC_QM_SA QMTemplate,
  1568. DWORD dwFlags,
  1569. LPVOID pvReserved,
  1570. PHANDLE phNotifyHandle
  1571. )
  1572. {
  1573. DWORD dwError = 0;
  1574. ULONG uhClientEvent = 0;
  1575. QM_SA_CONTAINER QMSAContainer;
  1576. PQM_SA_CONTAINER pQMSAContainer = &QMSAContainer;
  1577. if (dwVersion) {
  1578. return (ERROR_NOT_SUPPORTED);
  1579. }
  1580. if (QMTemplate.IpsecQMFilter.IpVersion != IPSEC_PROTOCOL_V4) {
  1581. return (ERROR_INVALID_LEVEL);
  1582. }
  1583. QMSAContainer.dwNumQMSAs = 1;
  1584. QMSAContainer.pQMSAs = &QMTemplate;
  1585. uhClientEvent = HandleToUlong(hClientEvent);
  1586. dwError = ValidateRegisterIKENotifyClient(
  1587. pServerName,
  1588. dwClientProcessId,
  1589. uhClientEvent,
  1590. pQMSAContainer,
  1591. phNotifyHandle,
  1592. dwFlags
  1593. );
  1594. BAIL_ON_WIN32_ERROR(dwError);
  1595. RpcTryExcept {
  1596. dwError = RpcRegisterIKENotifyClient(
  1597. pServerName,
  1598. dwVersion,
  1599. dwClientProcessId,
  1600. uhClientEvent,
  1601. pQMSAContainer,
  1602. dwFlags,
  1603. phNotifyHandle
  1604. );
  1605. BAIL_ON_WIN32_ERROR(dwError);
  1606. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  1607. dwError = TranslateExceptionCode(RpcExceptionCode());
  1608. BAIL_ON_WIN32_ERROR(dwError);
  1609. } RpcEndExcept
  1610. error:
  1611. return (dwError);
  1612. }
  1613. DWORD
  1614. QueryIKENotifyData(
  1615. HANDLE hNotifyHandle,
  1616. DWORD dwVersion,
  1617. DWORD dwFlags,
  1618. PIPSEC_QM_SA * ppQMSAs,
  1619. PDWORD pdwNumEntries,
  1620. LPVOID pvReserved
  1621. )
  1622. {
  1623. DWORD dwError = 0;
  1624. QM_SA_CONTAINER QMSAContainer;
  1625. PQM_SA_CONTAINER pContainer = &QMSAContainer;
  1626. if (dwVersion) {
  1627. return (ERROR_NOT_SUPPORTED);
  1628. }
  1629. memset(&QMSAContainer, 0, sizeof(QM_SA_CONTAINER));
  1630. if ((ppQMSAs == NULL) || (pdwNumEntries == NULL)) {
  1631. return (ERROR_INVALID_PARAMETER);
  1632. }
  1633. dwError = ValidateQueryNotifyData(
  1634. hNotifyHandle,
  1635. pdwNumEntries,
  1636. &pContainer,
  1637. dwFlags
  1638. );
  1639. BAIL_ON_WIN32_ERROR(dwError);
  1640. RpcTryExcept {
  1641. dwError = RpcQueryIKENotifyData(
  1642. hNotifyHandle,
  1643. dwVersion,
  1644. dwFlags,
  1645. &pContainer,
  1646. pdwNumEntries
  1647. );
  1648. if (dwError && dwError != ERROR_MORE_DATA) {
  1649. goto error;
  1650. }
  1651. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  1652. dwError = TranslateExceptionCode(RpcExceptionCode());
  1653. BAIL_ON_WIN32_ERROR(dwError);
  1654. } RpcEndExcept
  1655. *ppQMSAs = pContainer->pQMSAs;
  1656. *pdwNumEntries = pContainer->dwNumQMSAs;
  1657. return (dwError);
  1658. error:
  1659. *ppQMSAs = NULL;
  1660. *pdwNumEntries = 0;
  1661. return (dwError);
  1662. }
  1663. DWORD
  1664. CloseIKENotifyHandle(
  1665. HANDLE hNotifyHandle
  1666. )
  1667. {
  1668. DWORD dwError = 0;
  1669. dwError = ValidateCloseNotifyHandle(hNotifyHandle);
  1670. BAIL_ON_WIN32_ERROR(dwError);
  1671. RpcTryExcept {
  1672. dwError = RpcCloseIKENotifyHandle(
  1673. &hNotifyHandle
  1674. );
  1675. BAIL_ON_WIN32_ERROR(dwError);
  1676. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  1677. dwError = TranslateExceptionCode(RpcExceptionCode());
  1678. BAIL_ON_WIN32_ERROR(dwError);
  1679. } RpcEndExcept
  1680. error:
  1681. return (dwError);
  1682. }
  1683. DWORD
  1684. QueryIPSecStatistics(
  1685. LPWSTR pServerName,
  1686. DWORD dwVersion,
  1687. PIPSEC_STATISTICS * ppIpsecStatistics,
  1688. LPVOID pvReserved
  1689. )
  1690. {
  1691. DWORD dwError = 0;
  1692. IPSEC_STATISTICS_CONTAINER IpsecStatsContainer;
  1693. PIPSEC_STATISTICS_CONTAINER pIpsecStatsContainer = &IpsecStatsContainer;
  1694. memset(pIpsecStatsContainer, 0, sizeof(IPSEC_STATISTICS_CONTAINER));
  1695. if (dwVersion) {
  1696. return (ERROR_NOT_SUPPORTED);
  1697. }
  1698. if (!ppIpsecStatistics) {
  1699. return (ERROR_INVALID_PARAMETER);
  1700. }
  1701. RpcTryExcept {
  1702. dwError = RpcQueryIPSecStatistics(
  1703. pServerName,
  1704. dwVersion,
  1705. &pIpsecStatsContainer
  1706. );
  1707. BAIL_ON_WIN32_ERROR(dwError);
  1708. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  1709. dwError = TranslateExceptionCode(RpcExceptionCode());
  1710. BAIL_ON_WIN32_ERROR(dwError);
  1711. } RpcEndExcept
  1712. *ppIpsecStatistics = pIpsecStatsContainer->pIpsecStatistics;
  1713. return (dwError);
  1714. error:
  1715. return (dwError);
  1716. }
  1717. DWORD
  1718. EnumQMSAs(
  1719. LPWSTR pServerName,
  1720. DWORD dwVersion,
  1721. PIPSEC_QM_SA pQMSATemplate,
  1722. DWORD dwFlags,
  1723. DWORD dwPreferredNumEntries,
  1724. PIPSEC_QM_SA * ppQMSAs,
  1725. LPDWORD pdwNumQMSAs,
  1726. LPDWORD pdwNumTotalQMSAs,
  1727. LPDWORD pdwResumeHandle,
  1728. LPVOID pvReserved
  1729. )
  1730. {
  1731. DWORD dwError = 0;
  1732. QM_SA_CONTAINER QMSATempContainer;
  1733. PQM_SA_CONTAINER pQMSATempContainer = &QMSATempContainer;
  1734. QM_SA_CONTAINER QMSAContainer;
  1735. PQM_SA_CONTAINER pQMSAContainer = &QMSAContainer;
  1736. memset(pQMSAContainer, 0, sizeof(QM_SA_CONTAINER));
  1737. if (dwVersion) {
  1738. return (ERROR_NOT_SUPPORTED);
  1739. }
  1740. if (pQMSATemplate) {
  1741. return (ERROR_NOT_SUPPORTED);
  1742. }
  1743. if (!ppQMSAs || !pdwNumQMSAs ||
  1744. !pdwNumTotalQMSAs || !pdwResumeHandle) {
  1745. return (ERROR_INVALID_PARAMETER);
  1746. }
  1747. pQMSATempContainer->dwNumQMSAs = 0;
  1748. pQMSATempContainer->pQMSAs = NULL;
  1749. RpcTryExcept {
  1750. dwError = RpcEnumQMSAs(
  1751. pServerName,
  1752. dwVersion,
  1753. pQMSATempContainer,
  1754. dwFlags,
  1755. dwPreferredNumEntries,
  1756. &pQMSAContainer,
  1757. pdwNumTotalQMSAs,
  1758. pdwResumeHandle
  1759. );
  1760. BAIL_ON_WIN32_ERROR(dwError);
  1761. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  1762. dwError = TranslateExceptionCode(RpcExceptionCode());
  1763. BAIL_ON_WIN32_ERROR(dwError);
  1764. } RpcEndExcept
  1765. *ppQMSAs = pQMSAContainer->pQMSAs;
  1766. *pdwNumQMSAs = pQMSAContainer->dwNumQMSAs;
  1767. return (dwError);
  1768. error:
  1769. return (dwError);
  1770. }
  1771. DWORD
  1772. AddTunnelFilter(
  1773. LPWSTR pServerName,
  1774. DWORD dwVersion,
  1775. DWORD dwFlags,
  1776. PTUNNEL_FILTER pTunnelFilter,
  1777. LPVOID pvReserved,
  1778. PHANDLE phFilter
  1779. )
  1780. {
  1781. DWORD dwError = 0;
  1782. TUNNEL_FILTER_CONTAINER FilterContainer;
  1783. PTUNNEL_FILTER_CONTAINER pFilterContainer = &FilterContainer;
  1784. if (dwVersion) {
  1785. return (ERROR_NOT_SUPPORTED);
  1786. }
  1787. if (!phFilter) {
  1788. return (ERROR_INVALID_PARAMETER);
  1789. }
  1790. if (pTunnelFilter && (pTunnelFilter->IpVersion != IPSEC_PROTOCOL_V4)) {
  1791. return (ERROR_INVALID_LEVEL);
  1792. }
  1793. dwError = ValidateTunnelFilter(
  1794. pTunnelFilter
  1795. );
  1796. BAIL_ON_WIN32_ERROR(dwError);
  1797. pFilterContainer->dwNumFilters = 1;
  1798. pFilterContainer->pTunnelFilters = pTunnelFilter;
  1799. RpcTryExcept {
  1800. dwError = RpcAddTunnelFilter(
  1801. pServerName,
  1802. dwVersion,
  1803. dwFlags,
  1804. pFilterContainer,
  1805. phFilter
  1806. );
  1807. BAIL_ON_WIN32_ERROR(dwError);
  1808. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  1809. dwError = TranslateExceptionCode(RpcExceptionCode());
  1810. BAIL_ON_WIN32_ERROR(dwError);
  1811. } RpcEndExcept
  1812. error:
  1813. return (dwError);
  1814. }
  1815. DWORD
  1816. DeleteTunnelFilter(
  1817. HANDLE hFilter
  1818. )
  1819. {
  1820. DWORD dwError = 0;
  1821. if (!hFilter) {
  1822. return (ERROR_INVALID_PARAMETER);
  1823. }
  1824. RpcTryExcept {
  1825. dwError = RpcDeleteTunnelFilter(
  1826. &hFilter
  1827. );
  1828. BAIL_ON_WIN32_ERROR(dwError);
  1829. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  1830. dwError = TranslateExceptionCode(RpcExceptionCode());
  1831. BAIL_ON_WIN32_ERROR(dwError);
  1832. } RpcEndExcept
  1833. error:
  1834. if (dwError) {
  1835. dwError = SPDDestroyClientContextHandle(
  1836. dwError,
  1837. hFilter
  1838. );
  1839. }
  1840. return (dwError);
  1841. }
  1842. DWORD
  1843. EnumTunnelFilters(
  1844. LPWSTR pServerName,
  1845. DWORD dwVersion,
  1846. PTUNNEL_FILTER pTunnelTemplateFilter,
  1847. DWORD dwLevel,
  1848. GUID gGenericFilterID,
  1849. DWORD dwPreferredNumEntries,
  1850. PTUNNEL_FILTER * ppTunnelFilters,
  1851. LPDWORD pdwNumFilters,
  1852. LPDWORD pdwResumeHandle,
  1853. LPVOID pvReserved
  1854. )
  1855. {
  1856. DWORD dwError = 0;
  1857. TUNNEL_FILTER_CONTAINER FilterContainer;
  1858. PTUNNEL_FILTER_CONTAINER pFilterContainer = &FilterContainer;
  1859. TUNNEL_FILTER_CONTAINER TemplateFilterContainer;
  1860. PTUNNEL_FILTER_CONTAINER pTemplateFilterContainer = &TemplateFilterContainer;
  1861. memset(pFilterContainer, 0, sizeof(TUNNEL_FILTER_CONTAINER));
  1862. if (dwVersion) {
  1863. return (ERROR_NOT_SUPPORTED);
  1864. }
  1865. if (pTunnelTemplateFilter) {
  1866. return (ERROR_NOT_SUPPORTED);
  1867. }
  1868. if (!ppTunnelFilters || !pdwNumFilters || !pdwResumeHandle) {
  1869. return (ERROR_INVALID_PARAMETER);
  1870. }
  1871. switch (dwLevel) {
  1872. case ENUM_GENERIC_FILTERS:
  1873. case ENUM_SELECT_SPECIFIC_FILTERS:
  1874. case ENUM_SPECIFIC_FILTERS:
  1875. break;
  1876. default:
  1877. dwError = ERROR_INVALID_LEVEL;
  1878. BAIL_ON_WIN32_ERROR(dwError);
  1879. break;
  1880. }
  1881. pTemplateFilterContainer->dwNumFilters = 0;
  1882. pTemplateFilterContainer->pTunnelFilters = NULL;
  1883. RpcTryExcept {
  1884. dwError = RpcEnumTunnelFilters(
  1885. pServerName,
  1886. dwVersion,
  1887. pTemplateFilterContainer,
  1888. dwLevel,
  1889. gGenericFilterID,
  1890. dwPreferredNumEntries,
  1891. &pFilterContainer,
  1892. pdwResumeHandle
  1893. );
  1894. BAIL_ON_WIN32_ERROR(dwError);
  1895. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  1896. dwError = TranslateExceptionCode(RpcExceptionCode());
  1897. BAIL_ON_WIN32_ERROR(dwError);
  1898. } RpcEndExcept
  1899. *ppTunnelFilters = pFilterContainer->pTunnelFilters;
  1900. *pdwNumFilters = pFilterContainer->dwNumFilters;
  1901. return (dwError);
  1902. error:
  1903. *ppTunnelFilters = NULL;
  1904. *pdwNumFilters = 0;
  1905. return (dwError);
  1906. }
  1907. DWORD
  1908. SetTunnelFilter(
  1909. HANDLE hFilter,
  1910. DWORD dwVersion,
  1911. PTUNNEL_FILTER pTunnelFilter,
  1912. LPVOID pvReserved
  1913. )
  1914. {
  1915. DWORD dwError = 0;
  1916. TUNNEL_FILTER_CONTAINER FilterContainer;
  1917. PTUNNEL_FILTER_CONTAINER pFilterContainer = &FilterContainer;
  1918. if (dwVersion) {
  1919. return (ERROR_NOT_SUPPORTED);
  1920. }
  1921. if (!hFilter) {
  1922. return (ERROR_INVALID_PARAMETER);
  1923. }
  1924. if (pTunnelFilter && (pTunnelFilter->IpVersion != IPSEC_PROTOCOL_V4)) {
  1925. return (ERROR_INVALID_LEVEL);
  1926. }
  1927. dwError = ValidateTunnelFilter(
  1928. pTunnelFilter
  1929. );
  1930. BAIL_ON_WIN32_ERROR(dwError);
  1931. pFilterContainer->dwNumFilters = 1;
  1932. pFilterContainer->pTunnelFilters = pTunnelFilter;
  1933. RpcTryExcept {
  1934. dwError = RpcSetTunnelFilter(
  1935. hFilter,
  1936. dwVersion,
  1937. pFilterContainer
  1938. );
  1939. BAIL_ON_WIN32_ERROR(dwError);
  1940. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  1941. dwError = TranslateExceptionCode(RpcExceptionCode());
  1942. BAIL_ON_WIN32_ERROR(dwError);
  1943. } RpcEndExcept
  1944. error:
  1945. return (dwError);
  1946. }
  1947. DWORD
  1948. GetTunnelFilter(
  1949. HANDLE hFilter,
  1950. DWORD dwVersion,
  1951. PTUNNEL_FILTER * ppTunnelFilter,
  1952. LPVOID pvReserved
  1953. )
  1954. {
  1955. DWORD dwError = 0;
  1956. TUNNEL_FILTER_CONTAINER FilterContainer;
  1957. PTUNNEL_FILTER_CONTAINER pFilterContainer = &FilterContainer;
  1958. memset(pFilterContainer, 0, sizeof(TUNNEL_FILTER_CONTAINER));
  1959. if (dwVersion) {
  1960. return (ERROR_NOT_SUPPORTED);
  1961. }
  1962. if (!hFilter || !ppTunnelFilter) {
  1963. return (ERROR_INVALID_PARAMETER);
  1964. }
  1965. RpcTryExcept {
  1966. dwError = RpcGetTunnelFilter(
  1967. hFilter,
  1968. dwVersion,
  1969. &pFilterContainer
  1970. );
  1971. BAIL_ON_WIN32_ERROR(dwError);
  1972. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  1973. dwError = TranslateExceptionCode(RpcExceptionCode());
  1974. BAIL_ON_WIN32_ERROR(dwError);
  1975. } RpcEndExcept
  1976. *ppTunnelFilter = pFilterContainer->pTunnelFilters;
  1977. return (dwError);
  1978. error:
  1979. *ppTunnelFilter = NULL;
  1980. return (dwError);
  1981. }
  1982. DWORD
  1983. MatchTunnelFilter(
  1984. LPWSTR pServerName,
  1985. DWORD dwVersion,
  1986. PTUNNEL_FILTER pTnFilter,
  1987. DWORD dwFlags,
  1988. DWORD dwPreferredNumEntries,
  1989. PTUNNEL_FILTER * ppMatchedTnFilters,
  1990. PIPSEC_QM_POLICY * ppMatchedQMPolicies,
  1991. LPDWORD pdwNumMatches,
  1992. LPDWORD pdwResumeHandle,
  1993. LPVOID pvReserved
  1994. )
  1995. {
  1996. DWORD dwError = 0;
  1997. TUNNEL_FILTER_CONTAINER InTnFilterContainer;
  1998. PTUNNEL_FILTER_CONTAINER pInTnFilterContainer = &InTnFilterContainer;
  1999. TUNNEL_FILTER_CONTAINER OutTnFilterContainer;
  2000. PTUNNEL_FILTER_CONTAINER pOutTnFilterContainer = &OutTnFilterContainer;
  2001. IPSEC_QM_POLICY_CONTAINER QMPolicyContainer;
  2002. PIPSEC_QM_POLICY_CONTAINER pQMPolicyContainer = &QMPolicyContainer;
  2003. if (dwVersion) {
  2004. return (ERROR_NOT_SUPPORTED);
  2005. }
  2006. if (!pTnFilter || !ppMatchedTnFilters || !ppMatchedQMPolicies ||
  2007. !pdwNumMatches || !pdwResumeHandle) {
  2008. return (ERROR_INVALID_PARAMETER);
  2009. }
  2010. if (pTnFilter && (pTnFilter->IpVersion != IPSEC_PROTOCOL_V4)) {
  2011. return (ERROR_INVALID_LEVEL);
  2012. }
  2013. dwError = ValidateTnFilterTemplate(
  2014. pTnFilter
  2015. );
  2016. BAIL_ON_WIN32_ERROR(dwError);
  2017. pInTnFilterContainer->dwNumFilters = 1;
  2018. pInTnFilterContainer->pTunnelFilters = pTnFilter;
  2019. memset(pOutTnFilterContainer, 0, sizeof(TUNNEL_FILTER_CONTAINER));
  2020. memset(pQMPolicyContainer, 0, sizeof(IPSEC_QM_POLICY_CONTAINER));
  2021. RpcTryExcept {
  2022. dwError = RpcMatchTunnelFilter(
  2023. pServerName,
  2024. dwVersion,
  2025. pInTnFilterContainer,
  2026. dwFlags,
  2027. dwPreferredNumEntries,
  2028. &pOutTnFilterContainer,
  2029. &pQMPolicyContainer,
  2030. pdwResumeHandle
  2031. );
  2032. BAIL_ON_WIN32_ERROR(dwError);
  2033. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  2034. dwError = TranslateExceptionCode(RpcExceptionCode());
  2035. BAIL_ON_WIN32_ERROR(dwError);
  2036. } RpcEndExcept
  2037. *ppMatchedTnFilters = pOutTnFilterContainer->pTunnelFilters;
  2038. *ppMatchedQMPolicies = pQMPolicyContainer->pPolicies;
  2039. *pdwNumMatches = pOutTnFilterContainer->dwNumFilters;
  2040. return (dwError);
  2041. error:
  2042. *ppMatchedTnFilters = NULL;
  2043. *ppMatchedQMPolicies = NULL;
  2044. *pdwNumMatches = 0;
  2045. return (dwError);
  2046. }
  2047. DWORD
  2048. OpenMMFilterHandle(
  2049. LPWSTR pServerName,
  2050. DWORD dwVersion,
  2051. PMM_FILTER pMMFilter,
  2052. LPVOID pvReserved,
  2053. PHANDLE phMMFilter
  2054. )
  2055. {
  2056. DWORD dwError = 0;
  2057. MM_FILTER_CONTAINER MMFilterContainer;
  2058. PMM_FILTER_CONTAINER pMMFilterContainer = &MMFilterContainer;
  2059. if (dwVersion) {
  2060. return (ERROR_NOT_SUPPORTED);
  2061. }
  2062. if (!phMMFilter) {
  2063. return (ERROR_INVALID_PARAMETER);
  2064. }
  2065. if (pMMFilter && (pMMFilter->IpVersion != IPSEC_PROTOCOL_V4)) {
  2066. return (ERROR_INVALID_LEVEL);
  2067. }
  2068. dwError = ValidateMMFilter(
  2069. pMMFilter
  2070. );
  2071. BAIL_ON_WIN32_ERROR(dwError);
  2072. pMMFilterContainer->dwNumFilters = 1;
  2073. pMMFilterContainer->pMMFilters = pMMFilter;
  2074. RpcTryExcept {
  2075. dwError = RpcOpenMMFilterHandle(
  2076. pServerName,
  2077. dwVersion,
  2078. pMMFilterContainer,
  2079. phMMFilter
  2080. );
  2081. BAIL_ON_WIN32_ERROR(dwError);
  2082. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  2083. dwError = TranslateExceptionCode(RpcExceptionCode());
  2084. BAIL_ON_WIN32_ERROR(dwError);
  2085. } RpcEndExcept
  2086. error:
  2087. return (dwError);
  2088. }
  2089. DWORD
  2090. CloseMMFilterHandle(
  2091. HANDLE hMMFilter
  2092. )
  2093. {
  2094. DWORD dwError = 0;
  2095. if (!hMMFilter) {
  2096. return (ERROR_INVALID_PARAMETER);
  2097. }
  2098. RpcTryExcept {
  2099. dwError = RpcCloseMMFilterHandle(
  2100. &hMMFilter
  2101. );
  2102. BAIL_ON_WIN32_ERROR(dwError);
  2103. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  2104. dwError = TranslateExceptionCode(RpcExceptionCode());
  2105. BAIL_ON_WIN32_ERROR(dwError);
  2106. } RpcEndExcept
  2107. error:
  2108. if (dwError) {
  2109. dwError = SPDDestroyClientContextHandle(
  2110. dwError,
  2111. hMMFilter
  2112. );
  2113. }
  2114. return (dwError);
  2115. }
  2116. DWORD
  2117. OpenTransportFilterHandle(
  2118. LPWSTR pServerName,
  2119. DWORD dwVersion,
  2120. PTRANSPORT_FILTER pTransportFilter,
  2121. LPVOID pvReserved,
  2122. PHANDLE phTxFilter
  2123. )
  2124. {
  2125. DWORD dwError = 0;
  2126. TRANSPORT_FILTER_CONTAINER FilterContainer;
  2127. PTRANSPORT_FILTER_CONTAINER pFilterContainer = &FilterContainer;
  2128. if (dwVersion) {
  2129. return (ERROR_NOT_SUPPORTED);
  2130. }
  2131. if (!phTxFilter) {
  2132. return (ERROR_INVALID_PARAMETER);
  2133. }
  2134. if (pTransportFilter && (pTransportFilter->IpVersion != IPSEC_PROTOCOL_V4)) {
  2135. return (ERROR_INVALID_LEVEL);
  2136. }
  2137. dwError = ValidateTransportFilter(
  2138. pTransportFilter
  2139. );
  2140. BAIL_ON_WIN32_ERROR(dwError);
  2141. pFilterContainer->dwNumFilters = 1;
  2142. pFilterContainer->pTransportFilters = pTransportFilter;
  2143. RpcTryExcept {
  2144. dwError = RpcOpenTransportFilterHandle(
  2145. pServerName,
  2146. dwVersion,
  2147. pFilterContainer,
  2148. phTxFilter
  2149. );
  2150. BAIL_ON_WIN32_ERROR(dwError);
  2151. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  2152. dwError = TranslateExceptionCode(RpcExceptionCode());
  2153. BAIL_ON_WIN32_ERROR(dwError);
  2154. } RpcEndExcept
  2155. error:
  2156. return (dwError);
  2157. }
  2158. DWORD
  2159. CloseTransportFilterHandle(
  2160. HANDLE hTxFilter
  2161. )
  2162. {
  2163. DWORD dwError = 0;
  2164. if (!hTxFilter) {
  2165. return (ERROR_INVALID_PARAMETER);
  2166. }
  2167. RpcTryExcept {
  2168. dwError = RpcCloseTransportFilterHandle(
  2169. &hTxFilter
  2170. );
  2171. BAIL_ON_WIN32_ERROR(dwError);
  2172. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  2173. dwError = TranslateExceptionCode(RpcExceptionCode());
  2174. BAIL_ON_WIN32_ERROR(dwError);
  2175. } RpcEndExcept
  2176. error:
  2177. if (dwError) {
  2178. dwError = SPDDestroyClientContextHandle(
  2179. dwError,
  2180. hTxFilter
  2181. );
  2182. }
  2183. return (dwError);
  2184. }
  2185. DWORD
  2186. OpenTunnelFilterHandle(
  2187. LPWSTR pServerName,
  2188. DWORD dwVersion,
  2189. PTUNNEL_FILTER pTunnelFilter,
  2190. LPVOID pvReserved,
  2191. PHANDLE phTnFilter
  2192. )
  2193. {
  2194. DWORD dwError = 0;
  2195. TUNNEL_FILTER_CONTAINER FilterContainer;
  2196. PTUNNEL_FILTER_CONTAINER pFilterContainer = &FilterContainer;
  2197. if (dwVersion) {
  2198. return (ERROR_NOT_SUPPORTED);
  2199. }
  2200. if (!phTnFilter) {
  2201. return (ERROR_INVALID_PARAMETER);
  2202. }
  2203. if (pTunnelFilter && (pTunnelFilter->IpVersion != IPSEC_PROTOCOL_V4)) {
  2204. return (ERROR_INVALID_LEVEL);
  2205. }
  2206. dwError = ValidateTunnelFilter(
  2207. pTunnelFilter
  2208. );
  2209. BAIL_ON_WIN32_ERROR(dwError);
  2210. pFilterContainer->dwNumFilters = 1;
  2211. pFilterContainer->pTunnelFilters = pTunnelFilter;
  2212. RpcTryExcept {
  2213. dwError = RpcOpenTunnelFilterHandle(
  2214. pServerName,
  2215. dwVersion,
  2216. pFilterContainer,
  2217. phTnFilter
  2218. );
  2219. BAIL_ON_WIN32_ERROR(dwError);
  2220. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  2221. dwError = TranslateExceptionCode(RpcExceptionCode());
  2222. BAIL_ON_WIN32_ERROR(dwError);
  2223. } RpcEndExcept
  2224. error:
  2225. return (dwError);
  2226. }
  2227. DWORD
  2228. CloseTunnelFilterHandle(
  2229. HANDLE hTnFilter
  2230. )
  2231. {
  2232. DWORD dwError = 0;
  2233. if (!hTnFilter) {
  2234. return (ERROR_INVALID_PARAMETER);
  2235. }
  2236. RpcTryExcept {
  2237. dwError = RpcCloseTunnelFilterHandle(
  2238. &hTnFilter
  2239. );
  2240. BAIL_ON_WIN32_ERROR(dwError);
  2241. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  2242. dwError = TranslateExceptionCode(RpcExceptionCode());
  2243. BAIL_ON_WIN32_ERROR(dwError);
  2244. } RpcEndExcept
  2245. error:
  2246. if (dwError) {
  2247. dwError = SPDDestroyClientContextHandle(
  2248. dwError,
  2249. hTnFilter
  2250. );
  2251. }
  2252. return (dwError);
  2253. }
  2254. DWORD
  2255. EnumIPSecInterfaces(
  2256. LPWSTR pServerName,
  2257. DWORD dwVersion,
  2258. PIPSEC_INTERFACE_INFO pIpsecIfTemplate,
  2259. DWORD dwFlags,
  2260. DWORD dwPreferredNumEntries,
  2261. PIPSEC_INTERFACE_INFO * ppIpsecInterfaces,
  2262. LPDWORD pdwNumInterfaces,
  2263. LPDWORD pdwNumTotalInterfaces,
  2264. LPDWORD pdwResumeHandle,
  2265. LPVOID pvReserved
  2266. )
  2267. {
  2268. DWORD dwError = 0;
  2269. IPSEC_INTERFACE_CONTAINER IpsecIfTempContainer;
  2270. PIPSEC_INTERFACE_CONTAINER pIpsecIfTempContainer = &IpsecIfTempContainer;
  2271. IPSEC_INTERFACE_CONTAINER IpsecIfContainer;
  2272. PIPSEC_INTERFACE_CONTAINER pIpsecIfContainer = &IpsecIfContainer;
  2273. memset(pIpsecIfContainer, 0, sizeof(IPSEC_INTERFACE_CONTAINER));
  2274. if (dwVersion) {
  2275. return (ERROR_NOT_SUPPORTED);
  2276. }
  2277. if (pIpsecIfTemplate) {
  2278. return (ERROR_NOT_SUPPORTED);
  2279. }
  2280. if (!ppIpsecInterfaces || !pdwNumInterfaces ||
  2281. !pdwNumTotalInterfaces || !pdwResumeHandle) {
  2282. return (ERROR_INVALID_PARAMETER);
  2283. }
  2284. pIpsecIfTempContainer->dwNumInterfaces = 0;
  2285. pIpsecIfTempContainer->pIpsecInterfaces = NULL;
  2286. RpcTryExcept {
  2287. dwError = RpcEnumIpsecInterfaces(
  2288. pServerName,
  2289. dwVersion,
  2290. pIpsecIfTempContainer,
  2291. dwFlags,
  2292. dwPreferredNumEntries,
  2293. &pIpsecIfContainer,
  2294. pdwNumTotalInterfaces,
  2295. pdwResumeHandle
  2296. );
  2297. BAIL_ON_WIN32_ERROR(dwError);
  2298. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  2299. dwError = TranslateExceptionCode(RpcExceptionCode());
  2300. BAIL_ON_WIN32_ERROR(dwError);
  2301. } RpcEndExcept
  2302. *ppIpsecInterfaces = pIpsecIfContainer->pIpsecInterfaces;
  2303. *pdwNumInterfaces = pIpsecIfContainer->dwNumInterfaces;
  2304. return (dwError);
  2305. error:
  2306. *ppIpsecInterfaces = NULL;
  2307. *pdwNumInterfaces = 0;
  2308. *pdwNumTotalInterfaces = 0;
  2309. return (dwError);
  2310. }
  2311. DWORD
  2312. AddSAs(
  2313. LPWSTR pServerName,
  2314. DWORD dwVersion,
  2315. IPSEC_SA_DIRECTION SADirection,
  2316. PIPSEC_QM_OFFER pQMOffer,
  2317. PIPSEC_QM_FILTER pQMFilter,
  2318. HANDLE * phLarvalContext,
  2319. DWORD dwInboundKeyMatLen,
  2320. BYTE * pInboundKeyMat,
  2321. DWORD dwOutboundKeyMatLen,
  2322. BYTE * pOutboundKeyMat,
  2323. BYTE * pContextInfo,
  2324. UDP_ENCAP_INFO EncapInfo,
  2325. LPVOID pvReserved,
  2326. DWORD dwFlags
  2327. )
  2328. {
  2329. DWORD dwError = 0;
  2330. QM_FILTER_CONTAINER FilterContainer;
  2331. PQM_FILTER_CONTAINER pFilterContainer = &FilterContainer;
  2332. IPSEC_QM_POLICY_CONTAINER QMPolicyContainer;
  2333. PIPSEC_QM_POLICY_CONTAINER pQMPolicyContainer = &QMPolicyContainer;
  2334. IPSEC_QM_POLICY QMPolicy;
  2335. ULONG uhLarvalContext = 0;
  2336. memset(&QMPolicy, 0, sizeof(IPSEC_QM_POLICY));
  2337. if (dwVersion) {
  2338. return (ERROR_NOT_SUPPORTED);
  2339. }
  2340. if (phLarvalContext == NULL) {
  2341. dwError = ERROR_INVALID_PARAMETER;
  2342. BAIL_ON_WIN32_ERROR(dwError);
  2343. }
  2344. if (pQMFilter && (pQMFilter->IpVersion != IPSEC_PROTOCOL_V4)) {
  2345. return (ERROR_INVALID_LEVEL);
  2346. }
  2347. uhLarvalContext = HandleToUlong(*phLarvalContext);
  2348. pFilterContainer->dwNumFilters = 1;
  2349. pFilterContainer->pQMFilters = pQMFilter;
  2350. pQMPolicyContainer->dwNumPolicies = 1;
  2351. QMPolicy.pOffers = pQMOffer;
  2352. QMPolicy.dwOfferCount = 1;
  2353. pQMPolicyContainer->pPolicies = &QMPolicy;
  2354. dwError=ValidateIPSecAddSA(
  2355. pServerName,
  2356. SADirection,
  2357. pQMPolicyContainer,
  2358. pFilterContainer,
  2359. &uhLarvalContext,
  2360. dwInboundKeyMatLen,
  2361. pInboundKeyMat,
  2362. dwOutboundKeyMatLen,
  2363. pOutboundKeyMat,
  2364. pContextInfo,
  2365. EncapInfo,
  2366. dwFlags);
  2367. BAIL_ON_WIN32_ERROR(dwError);
  2368. RpcTryExcept {
  2369. dwError = RpcAddSAs(
  2370. pServerName,
  2371. dwVersion,
  2372. SADirection,
  2373. pQMPolicyContainer,
  2374. pFilterContainer,
  2375. &uhLarvalContext,
  2376. dwInboundKeyMatLen,
  2377. pInboundKeyMat,
  2378. dwOutboundKeyMatLen,
  2379. pOutboundKeyMat,
  2380. pContextInfo,
  2381. EncapInfo,
  2382. dwFlags);
  2383. BAIL_ON_WIN32_ERROR(dwError);
  2384. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  2385. dwError = TranslateExceptionCode(RpcExceptionCode());
  2386. BAIL_ON_WIN32_ERROR(dwError);
  2387. } RpcEndExcept
  2388. *phLarvalContext = LongToHandle(uhLarvalContext);
  2389. error:
  2390. return (dwError);
  2391. }
  2392. DWORD
  2393. WINAPI
  2394. SetConfigurationVariables(
  2395. LPWSTR pServerName,
  2396. IKE_CONFIG IKEConfig
  2397. )
  2398. {
  2399. DWORD dwError = 0;
  2400. dwError=ValidateSetConfigurationVariables(
  2401. pServerName,
  2402. IKEConfig
  2403. );
  2404. BAIL_ON_WIN32_ERROR(dwError);
  2405. RpcTryExcept {
  2406. dwError = RpcSetConfigurationVariables(
  2407. pServerName,
  2408. IKEConfig
  2409. );
  2410. BAIL_ON_WIN32_ERROR(dwError);
  2411. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  2412. dwError = TranslateExceptionCode(RpcExceptionCode());
  2413. BAIL_ON_WIN32_ERROR(dwError);
  2414. } RpcEndExcept
  2415. error:
  2416. return (dwError);
  2417. }
  2418. DWORD
  2419. WINAPI
  2420. GetConfigurationVariables(
  2421. LPWSTR pServerName,
  2422. PIKE_CONFIG pIKEConfig
  2423. )
  2424. {
  2425. DWORD dwError = 0;
  2426. dwError=ValidateGetConfigurationVariables(
  2427. pServerName,
  2428. pIKEConfig
  2429. );
  2430. BAIL_ON_WIN32_ERROR(dwError);
  2431. RpcTryExcept {
  2432. dwError = RpcGetConfigurationVariables(
  2433. pServerName,
  2434. pIKEConfig
  2435. );
  2436. BAIL_ON_WIN32_ERROR(dwError);
  2437. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  2438. dwError = TranslateExceptionCode(RpcExceptionCode());
  2439. BAIL_ON_WIN32_ERROR(dwError);
  2440. } RpcEndExcept
  2441. error:
  2442. return (dwError);
  2443. }
  2444. DWORD
  2445. WINAPI
  2446. QuerySpdPolicyState(
  2447. LPWSTR pServerName,
  2448. DWORD dwVersion,
  2449. PSPD_POLICY_STATE * ppSpdPolicyState,
  2450. LPVOID pvReserved
  2451. )
  2452. {
  2453. DWORD dwError = 0;
  2454. SPD_POLICY_STATE_CONTAINER SpdPolicyStateContainer;
  2455. PSPD_POLICY_STATE_CONTAINER pSpdPolicyStateContainer = &SpdPolicyStateContainer;
  2456. memset(pSpdPolicyStateContainer, 0, sizeof(SPD_POLICY_STATE_CONTAINER));
  2457. if (dwVersion) {
  2458. return (ERROR_NOT_SUPPORTED);
  2459. }
  2460. if (!ppSpdPolicyState) {
  2461. return (ERROR_INVALID_PARAMETER);
  2462. }
  2463. RpcTryExcept {
  2464. dwError = RpcQuerySpdPolicyState(
  2465. pServerName,
  2466. dwVersion,
  2467. &pSpdPolicyStateContainer
  2468. );
  2469. BAIL_ON_WIN32_ERROR(dwError);
  2470. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  2471. dwError = TranslateExceptionCode(RpcExceptionCode());
  2472. BAIL_ON_WIN32_ERROR(dwError);
  2473. } RpcEndExcept
  2474. *ppSpdPolicyState = pSpdPolicyStateContainer->pSpdPolicyStates;
  2475. return (dwError);
  2476. error:
  2477. *ppSpdPolicyState = NULL;
  2478. return (dwError);
  2479. }