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.

2739 lines
59 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 = MIDL_user_allocate(dwByteCount);
  26. if (*ppBuffer == NULL) {
  27. dwError = ERROR_OUTOFMEMORY;
  28. BAIL_ON_WIN32_ERROR(dwError);
  29. }
  30. error:
  31. return (dwError);
  32. }
  33. VOID
  34. SPDApiBufferFree(
  35. LPVOID pBuffer
  36. )
  37. {
  38. if (pBuffer) {
  39. MIDL_user_free(pBuffer);
  40. }
  41. }
  42. DWORD
  43. AddTransportFilter(
  44. LPWSTR pServerName,
  45. DWORD dwFlags,
  46. PTRANSPORT_FILTER pTransportFilter,
  47. PHANDLE phFilter
  48. )
  49. {
  50. DWORD dwError = 0;
  51. TRANSPORT_FILTER_CONTAINER FilterContainer;
  52. PTRANSPORT_FILTER_CONTAINER pFilterContainer = &FilterContainer;
  53. if (!phFilter) {
  54. return (ERROR_INVALID_PARAMETER);
  55. }
  56. dwError = ValidateTransportFilter(
  57. pTransportFilter
  58. );
  59. BAIL_ON_WIN32_ERROR(dwError);
  60. pFilterContainer->dwNumFilters = 1;
  61. pFilterContainer->pTransportFilters = pTransportFilter;
  62. RpcTryExcept {
  63. dwError = RpcAddTransportFilter(
  64. pServerName,
  65. dwFlags,
  66. pFilterContainer,
  67. phFilter
  68. );
  69. BAIL_ON_WIN32_ERROR(dwError);
  70. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  71. dwError = TranslateExceptionCode(RpcExceptionCode());
  72. BAIL_ON_WIN32_ERROR(dwError);
  73. } RpcEndExcept
  74. error:
  75. return (dwError);
  76. }
  77. DWORD
  78. DeleteTransportFilter(
  79. HANDLE hFilter
  80. )
  81. {
  82. DWORD dwError = 0;
  83. if (!hFilter) {
  84. return (ERROR_INVALID_PARAMETER);
  85. }
  86. RpcTryExcept {
  87. dwError = RpcDeleteTransportFilter(
  88. &hFilter
  89. );
  90. BAIL_ON_WIN32_ERROR(dwError);
  91. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  92. dwError = TranslateExceptionCode(RpcExceptionCode());
  93. BAIL_ON_WIN32_ERROR(dwError);
  94. } RpcEndExcept
  95. error:
  96. if (dwError) {
  97. dwError = SPDDestroyClientContextHandle(
  98. dwError,
  99. hFilter
  100. );
  101. }
  102. return (dwError);
  103. }
  104. DWORD
  105. EnumTransportFilters(
  106. LPWSTR pServerName,
  107. DWORD dwLevel,
  108. GUID gGenericFilterID,
  109. PTRANSPORT_FILTER * ppTransportFilters,
  110. DWORD dwPreferredNumEntries,
  111. LPDWORD pdwNumFilters,
  112. LPDWORD pdwResumeHandle
  113. )
  114. {
  115. DWORD dwError = 0;
  116. TRANSPORT_FILTER_CONTAINER FilterContainer;
  117. PTRANSPORT_FILTER_CONTAINER pFilterContainer = &FilterContainer;
  118. memset(pFilterContainer, 0, sizeof(TRANSPORT_FILTER_CONTAINER));
  119. if (!ppTransportFilters || !pdwNumFilters || !pdwResumeHandle) {
  120. return (ERROR_INVALID_PARAMETER);
  121. }
  122. switch (dwLevel) {
  123. case ENUM_GENERIC_FILTERS:
  124. case ENUM_SELECT_SPECIFIC_FILTERS:
  125. case ENUM_SPECIFIC_FILTERS:
  126. break;
  127. default:
  128. dwError = ERROR_INVALID_LEVEL;
  129. BAIL_ON_WIN32_ERROR(dwError);
  130. break;
  131. }
  132. RpcTryExcept {
  133. dwError = RpcEnumTransportFilters(
  134. pServerName,
  135. dwLevel,
  136. gGenericFilterID,
  137. &pFilterContainer,
  138. dwPreferredNumEntries,
  139. pdwResumeHandle
  140. );
  141. BAIL_ON_WIN32_ERROR(dwError);
  142. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  143. dwError = TranslateExceptionCode(RpcExceptionCode());
  144. BAIL_ON_WIN32_ERROR(dwError);
  145. } RpcEndExcept
  146. *ppTransportFilters = pFilterContainer->pTransportFilters;
  147. *pdwNumFilters = pFilterContainer->dwNumFilters;
  148. return (dwError);
  149. error:
  150. *ppTransportFilters = NULL;
  151. *pdwNumFilters = 0;
  152. return (dwError);
  153. }
  154. DWORD
  155. SetTransportFilter(
  156. HANDLE hFilter,
  157. PTRANSPORT_FILTER pTransportFilter
  158. )
  159. {
  160. DWORD dwError = 0;
  161. TRANSPORT_FILTER_CONTAINER FilterContainer;
  162. PTRANSPORT_FILTER_CONTAINER pFilterContainer = &FilterContainer;
  163. if (!hFilter) {
  164. return (ERROR_INVALID_PARAMETER);
  165. }
  166. dwError = ValidateTransportFilter(
  167. pTransportFilter
  168. );
  169. BAIL_ON_WIN32_ERROR(dwError);
  170. pFilterContainer->dwNumFilters = 1;
  171. pFilterContainer->pTransportFilters = pTransportFilter;
  172. RpcTryExcept {
  173. dwError = RpcSetTransportFilter(
  174. hFilter,
  175. pFilterContainer
  176. );
  177. BAIL_ON_WIN32_ERROR(dwError);
  178. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  179. dwError = TranslateExceptionCode(RpcExceptionCode());
  180. BAIL_ON_WIN32_ERROR(dwError);
  181. } RpcEndExcept
  182. error:
  183. return (dwError);
  184. }
  185. DWORD
  186. GetTransportFilter(
  187. HANDLE hFilter,
  188. PTRANSPORT_FILTER * ppTransportFilter
  189. )
  190. {
  191. DWORD dwError = 0;
  192. TRANSPORT_FILTER_CONTAINER FilterContainer;
  193. PTRANSPORT_FILTER_CONTAINER pFilterContainer = &FilterContainer;
  194. memset(pFilterContainer, 0, sizeof(TRANSPORT_FILTER_CONTAINER));
  195. if (!hFilter || !ppTransportFilter) {
  196. return (ERROR_INVALID_PARAMETER);
  197. }
  198. RpcTryExcept {
  199. dwError = RpcGetTransportFilter(
  200. hFilter,
  201. &pFilterContainer
  202. );
  203. BAIL_ON_WIN32_ERROR(dwError);
  204. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  205. dwError = TranslateExceptionCode(RpcExceptionCode());
  206. BAIL_ON_WIN32_ERROR(dwError);
  207. } RpcEndExcept
  208. *ppTransportFilter = pFilterContainer->pTransportFilters;
  209. return (dwError);
  210. error:
  211. *ppTransportFilter = NULL;
  212. return (dwError);
  213. }
  214. DWORD
  215. AddQMPolicy(
  216. LPWSTR pServerName,
  217. DWORD dwFlags,
  218. PIPSEC_QM_POLICY pQMPolicy
  219. )
  220. {
  221. DWORD dwError = 0;
  222. IPSEC_QM_POLICY_CONTAINER QMPolicyContainer;
  223. PIPSEC_QM_POLICY_CONTAINER pQMPolicyContainer = &QMPolicyContainer;
  224. dwError = ValidateQMPolicy(
  225. pQMPolicy
  226. );
  227. BAIL_ON_WIN32_ERROR(dwError);
  228. pQMPolicyContainer->dwNumPolicies = 1;
  229. pQMPolicyContainer->pPolicies = pQMPolicy;
  230. RpcTryExcept {
  231. dwError = RpcAddQMPolicy(
  232. pServerName,
  233. dwFlags,
  234. pQMPolicyContainer
  235. );
  236. BAIL_ON_WIN32_ERROR(dwError);
  237. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  238. dwError = TranslateExceptionCode(RpcExceptionCode());
  239. BAIL_ON_WIN32_ERROR(dwError);
  240. } RpcEndExcept
  241. error:
  242. return (dwError);
  243. }
  244. DWORD
  245. DeleteQMPolicy(
  246. LPWSTR pServerName,
  247. LPWSTR pszPolicyName
  248. )
  249. {
  250. DWORD dwError = 0;
  251. if (!pszPolicyName || !*pszPolicyName) {
  252. dwError = ERROR_INVALID_PARAMETER;
  253. BAIL_ON_WIN32_ERROR(dwError);
  254. }
  255. RpcTryExcept {
  256. dwError = RpcDeleteQMPolicy(
  257. pServerName,
  258. pszPolicyName
  259. );
  260. BAIL_ON_WIN32_ERROR(dwError);
  261. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  262. dwError = TranslateExceptionCode(RpcExceptionCode());
  263. BAIL_ON_WIN32_ERROR(dwError);
  264. } RpcEndExcept
  265. error:
  266. return (dwError);
  267. }
  268. DWORD
  269. EnumQMPolicies(
  270. LPWSTR pServerName,
  271. PIPSEC_QM_POLICY * ppQMPolicies,
  272. DWORD dwPreferredNumEntries,
  273. LPDWORD pdwNumPolicies,
  274. LPDWORD pdwResumeHandle
  275. )
  276. {
  277. DWORD dwError = 0;
  278. IPSEC_QM_POLICY_CONTAINER QMPolicyContainer;
  279. PIPSEC_QM_POLICY_CONTAINER pQMPolicyContainer = &QMPolicyContainer;
  280. memset(pQMPolicyContainer, 0, sizeof(IPSEC_QM_POLICY_CONTAINER));
  281. if (!ppQMPolicies || !pdwNumPolicies || !pdwResumeHandle) {
  282. //
  283. // Do not bail to error from here.
  284. //
  285. return (ERROR_INVALID_PARAMETER);
  286. }
  287. RpcTryExcept {
  288. dwError = RpcEnumQMPolicies(
  289. pServerName,
  290. &pQMPolicyContainer,
  291. dwPreferredNumEntries,
  292. pdwResumeHandle
  293. );
  294. BAIL_ON_WIN32_ERROR(dwError);
  295. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  296. dwError = TranslateExceptionCode(RpcExceptionCode());
  297. BAIL_ON_WIN32_ERROR(dwError);
  298. } RpcEndExcept
  299. *ppQMPolicies = pQMPolicyContainer->pPolicies;
  300. *pdwNumPolicies = pQMPolicyContainer->dwNumPolicies;
  301. return (dwError);
  302. error:
  303. *ppQMPolicies = NULL;
  304. *pdwNumPolicies = 0;
  305. return (dwError);
  306. }
  307. DWORD
  308. SetQMPolicy(
  309. LPWSTR pServerName,
  310. LPWSTR pszPolicyName,
  311. PIPSEC_QM_POLICY pQMPolicy
  312. )
  313. {
  314. DWORD dwError = 0;
  315. IPSEC_QM_POLICY_CONTAINER QMPolicyContainer;
  316. PIPSEC_QM_POLICY_CONTAINER pQMPolicyContainer = &QMPolicyContainer;
  317. if (!pszPolicyName || !*pszPolicyName) {
  318. dwError = ERROR_INVALID_PARAMETER;
  319. BAIL_ON_WIN32_ERROR(dwError);
  320. }
  321. dwError = ValidateQMPolicy(
  322. pQMPolicy
  323. );
  324. BAIL_ON_WIN32_ERROR(dwError);
  325. pQMPolicyContainer->dwNumPolicies = 1;
  326. pQMPolicyContainer->pPolicies = pQMPolicy;
  327. RpcTryExcept {
  328. dwError = RpcSetQMPolicy(
  329. pServerName,
  330. pszPolicyName,
  331. pQMPolicyContainer
  332. );
  333. BAIL_ON_WIN32_ERROR(dwError);
  334. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  335. dwError = TranslateExceptionCode(RpcExceptionCode());
  336. BAIL_ON_WIN32_ERROR(dwError);
  337. } RpcEndExcept
  338. error:
  339. return (dwError);
  340. }
  341. DWORD
  342. GetQMPolicy(
  343. LPWSTR pServerName,
  344. LPWSTR pszPolicyName,
  345. PIPSEC_QM_POLICY * ppQMPolicy
  346. )
  347. {
  348. DWORD dwError = 0;
  349. IPSEC_QM_POLICY_CONTAINER QMPolicyContainer;
  350. PIPSEC_QM_POLICY_CONTAINER pQMPolicyContainer = &QMPolicyContainer;
  351. memset(pQMPolicyContainer, 0, sizeof(IPSEC_QM_POLICY_CONTAINER));
  352. if (!pszPolicyName || !*pszPolicyName || !ppQMPolicy) {
  353. //
  354. // Do not bail to error from here.
  355. //
  356. return (ERROR_INVALID_PARAMETER);
  357. }
  358. RpcTryExcept {
  359. dwError = RpcGetQMPolicy(
  360. pServerName,
  361. pszPolicyName,
  362. &pQMPolicyContainer
  363. );
  364. BAIL_ON_WIN32_ERROR(dwError);
  365. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  366. dwError = TranslateExceptionCode(RpcExceptionCode());
  367. BAIL_ON_WIN32_ERROR(dwError);
  368. } RpcEndExcept
  369. *ppQMPolicy = pQMPolicyContainer->pPolicies;
  370. return (dwError);
  371. error:
  372. *ppQMPolicy = NULL;
  373. return (dwError);
  374. }
  375. DWORD
  376. AddMMPolicy(
  377. LPWSTR pServerName,
  378. DWORD dwFlags,
  379. PIPSEC_MM_POLICY pMMPolicy
  380. )
  381. {
  382. DWORD dwError = 0;
  383. IPSEC_MM_POLICY_CONTAINER MMPolicyContainer;
  384. PIPSEC_MM_POLICY_CONTAINER pMMPolicyContainer = &MMPolicyContainer;
  385. dwError = ValidateMMPolicy(
  386. pMMPolicy
  387. );
  388. BAIL_ON_WIN32_ERROR(dwError);
  389. pMMPolicyContainer->dwNumPolicies = 1;
  390. pMMPolicyContainer->pPolicies = pMMPolicy;
  391. RpcTryExcept {
  392. dwError = RpcAddMMPolicy(
  393. pServerName,
  394. dwFlags,
  395. pMMPolicyContainer
  396. );
  397. BAIL_ON_WIN32_ERROR(dwError);
  398. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  399. dwError = TranslateExceptionCode(RpcExceptionCode());
  400. BAIL_ON_WIN32_ERROR(dwError);
  401. } RpcEndExcept
  402. error:
  403. return (dwError);
  404. }
  405. DWORD
  406. DeleteMMPolicy(
  407. LPWSTR pServerName,
  408. LPWSTR pszPolicyName
  409. )
  410. {
  411. DWORD dwError = 0;
  412. if (!pszPolicyName || !*pszPolicyName) {
  413. dwError = ERROR_INVALID_PARAMETER;
  414. BAIL_ON_WIN32_ERROR(dwError);
  415. }
  416. RpcTryExcept {
  417. dwError = RpcDeleteMMPolicy(
  418. pServerName,
  419. pszPolicyName
  420. );
  421. BAIL_ON_WIN32_ERROR(dwError);
  422. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  423. dwError = TranslateExceptionCode(RpcExceptionCode());
  424. BAIL_ON_WIN32_ERROR(dwError);
  425. } RpcEndExcept
  426. error:
  427. return (dwError);
  428. }
  429. DWORD
  430. EnumMMPolicies(
  431. LPWSTR pServerName,
  432. PIPSEC_MM_POLICY * ppMMPolicies,
  433. DWORD dwPreferredNumEntries,
  434. LPDWORD pdwNumPolicies,
  435. LPDWORD pdwResumeHandle
  436. )
  437. {
  438. DWORD dwError = 0;
  439. IPSEC_MM_POLICY_CONTAINER MMPolicyContainer;
  440. PIPSEC_MM_POLICY_CONTAINER pMMPolicyContainer = &MMPolicyContainer;
  441. memset(pMMPolicyContainer, 0, sizeof(IPSEC_MM_POLICY_CONTAINER));
  442. if (!ppMMPolicies || !pdwNumPolicies || !pdwResumeHandle) {
  443. //
  444. // Do not bail to error from here.
  445. //
  446. return (ERROR_INVALID_PARAMETER);
  447. }
  448. RpcTryExcept {
  449. dwError = RpcEnumMMPolicies(
  450. pServerName,
  451. &pMMPolicyContainer,
  452. dwPreferredNumEntries,
  453. pdwResumeHandle
  454. );
  455. BAIL_ON_WIN32_ERROR(dwError);
  456. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  457. dwError = TranslateExceptionCode(RpcExceptionCode());
  458. BAIL_ON_WIN32_ERROR(dwError);
  459. } RpcEndExcept
  460. *ppMMPolicies = pMMPolicyContainer->pPolicies;
  461. *pdwNumPolicies = pMMPolicyContainer->dwNumPolicies;
  462. return (dwError);
  463. error:
  464. *ppMMPolicies = NULL;
  465. *pdwNumPolicies = 0;
  466. return (dwError);
  467. }
  468. DWORD
  469. SetMMPolicy(
  470. LPWSTR pServerName,
  471. LPWSTR pszPolicyName,
  472. PIPSEC_MM_POLICY pMMPolicy
  473. )
  474. {
  475. DWORD dwError = 0;
  476. IPSEC_MM_POLICY_CONTAINER MMPolicyContainer;
  477. PIPSEC_MM_POLICY_CONTAINER pMMPolicyContainer = &MMPolicyContainer;
  478. if (!pszPolicyName || !*pszPolicyName) {
  479. dwError = ERROR_INVALID_PARAMETER;
  480. BAIL_ON_WIN32_ERROR(dwError);
  481. }
  482. dwError = ValidateMMPolicy(
  483. pMMPolicy
  484. );
  485. BAIL_ON_WIN32_ERROR(dwError);
  486. pMMPolicyContainer->dwNumPolicies = 1;
  487. pMMPolicyContainer->pPolicies = pMMPolicy;
  488. RpcTryExcept {
  489. dwError = RpcSetMMPolicy(
  490. pServerName,
  491. pszPolicyName,
  492. pMMPolicyContainer
  493. );
  494. BAIL_ON_WIN32_ERROR(dwError);
  495. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  496. dwError = TranslateExceptionCode(RpcExceptionCode());
  497. BAIL_ON_WIN32_ERROR(dwError);
  498. } RpcEndExcept
  499. error:
  500. return (dwError);
  501. }
  502. DWORD
  503. GetMMPolicy(
  504. LPWSTR pServerName,
  505. LPWSTR pszPolicyName,
  506. PIPSEC_MM_POLICY * ppMMPolicy
  507. )
  508. {
  509. DWORD dwError = 0;
  510. IPSEC_MM_POLICY_CONTAINER MMPolicyContainer;
  511. PIPSEC_MM_POLICY_CONTAINER pMMPolicyContainer = &MMPolicyContainer;
  512. memset(pMMPolicyContainer, 0, sizeof(IPSEC_MM_POLICY_CONTAINER));
  513. if (!pszPolicyName || !*pszPolicyName || !ppMMPolicy) {
  514. //
  515. // Do not bail to error from here.
  516. //
  517. return (ERROR_INVALID_PARAMETER);
  518. }
  519. RpcTryExcept {
  520. dwError = RpcGetMMPolicy(
  521. pServerName,
  522. pszPolicyName,
  523. &pMMPolicyContainer
  524. );
  525. BAIL_ON_WIN32_ERROR(dwError);
  526. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  527. dwError = TranslateExceptionCode(RpcExceptionCode());
  528. BAIL_ON_WIN32_ERROR(dwError);
  529. } RpcEndExcept
  530. *ppMMPolicy = pMMPolicyContainer->pPolicies;
  531. return (dwError);
  532. error:
  533. *ppMMPolicy = NULL;
  534. return (dwError);
  535. }
  536. DWORD
  537. AddMMFilter(
  538. LPWSTR pServerName,
  539. DWORD dwFlags,
  540. PMM_FILTER pMMFilter,
  541. PHANDLE phMMFilter
  542. )
  543. {
  544. DWORD dwError = 0;
  545. MM_FILTER_CONTAINER MMFilterContainer;
  546. PMM_FILTER_CONTAINER pMMFilterContainer = &MMFilterContainer;
  547. if (!phMMFilter) {
  548. return (ERROR_INVALID_PARAMETER);
  549. }
  550. dwError = ValidateMMFilter(
  551. pMMFilter
  552. );
  553. BAIL_ON_WIN32_ERROR(dwError);
  554. pMMFilterContainer->dwNumFilters = 1;
  555. pMMFilterContainer->pMMFilters = pMMFilter;
  556. RpcTryExcept {
  557. dwError = RpcAddMMFilter(
  558. pServerName,
  559. dwFlags,
  560. pMMFilterContainer,
  561. phMMFilter
  562. );
  563. BAIL_ON_WIN32_ERROR(dwError);
  564. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  565. dwError = TranslateExceptionCode(RpcExceptionCode());
  566. BAIL_ON_WIN32_ERROR(dwError);
  567. } RpcEndExcept
  568. error:
  569. return (dwError);
  570. }
  571. DWORD
  572. DeleteMMFilter(
  573. HANDLE hMMFilter
  574. )
  575. {
  576. DWORD dwError = 0;
  577. if (!hMMFilter) {
  578. return (ERROR_INVALID_PARAMETER);
  579. }
  580. RpcTryExcept {
  581. dwError = RpcDeleteMMFilter(
  582. &hMMFilter
  583. );
  584. BAIL_ON_WIN32_ERROR(dwError);
  585. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  586. dwError = TranslateExceptionCode(RpcExceptionCode());
  587. BAIL_ON_WIN32_ERROR(dwError);
  588. } RpcEndExcept
  589. error:
  590. if (dwError) {
  591. dwError = SPDDestroyClientContextHandle(
  592. dwError,
  593. hMMFilter
  594. );
  595. }
  596. return (dwError);
  597. }
  598. DWORD
  599. EnumMMFilters(
  600. LPWSTR pServerName,
  601. DWORD dwLevel,
  602. GUID gGenericFilterID,
  603. PMM_FILTER * ppMMFilters,
  604. DWORD dwPreferredNumEntries,
  605. LPDWORD pdwNumMMFilters,
  606. LPDWORD pdwResumeHandle
  607. )
  608. {
  609. DWORD dwError = 0;
  610. MM_FILTER_CONTAINER MMFilterContainer;
  611. PMM_FILTER_CONTAINER pMMFilterContainer = &MMFilterContainer;
  612. memset(pMMFilterContainer, 0, sizeof(MM_FILTER_CONTAINER));
  613. if (!ppMMFilters || !pdwNumMMFilters || !pdwResumeHandle) {
  614. return (ERROR_INVALID_PARAMETER);
  615. }
  616. switch (dwLevel) {
  617. case ENUM_GENERIC_FILTERS:
  618. case ENUM_SELECT_SPECIFIC_FILTERS:
  619. case ENUM_SPECIFIC_FILTERS:
  620. break;
  621. default:
  622. dwError = ERROR_INVALID_LEVEL;
  623. BAIL_ON_WIN32_ERROR(dwError);
  624. break;
  625. }
  626. RpcTryExcept {
  627. dwError = RpcEnumMMFilters(
  628. pServerName,
  629. dwLevel,
  630. gGenericFilterID,
  631. &pMMFilterContainer,
  632. dwPreferredNumEntries,
  633. pdwResumeHandle
  634. );
  635. BAIL_ON_WIN32_ERROR(dwError);
  636. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  637. dwError = TranslateExceptionCode(RpcExceptionCode());
  638. BAIL_ON_WIN32_ERROR(dwError);
  639. } RpcEndExcept
  640. *ppMMFilters = pMMFilterContainer->pMMFilters;
  641. *pdwNumMMFilters = pMMFilterContainer->dwNumFilters;
  642. return (dwError);
  643. error:
  644. *ppMMFilters = NULL;
  645. *pdwNumMMFilters = 0;
  646. return (dwError);
  647. }
  648. DWORD
  649. SetMMFilter(
  650. HANDLE hMMFilter,
  651. PMM_FILTER pMMFilter
  652. )
  653. {
  654. DWORD dwError = 0;
  655. MM_FILTER_CONTAINER MMFilterContainer;
  656. PMM_FILTER_CONTAINER pMMFilterContainer = &MMFilterContainer;
  657. if (!hMMFilter) {
  658. return (ERROR_INVALID_PARAMETER);
  659. }
  660. dwError = ValidateMMFilter(
  661. pMMFilter
  662. );
  663. BAIL_ON_WIN32_ERROR(dwError);
  664. pMMFilterContainer->dwNumFilters = 1;
  665. pMMFilterContainer->pMMFilters = pMMFilter;
  666. RpcTryExcept {
  667. dwError = RpcSetMMFilter(
  668. hMMFilter,
  669. pMMFilterContainer
  670. );
  671. BAIL_ON_WIN32_ERROR(dwError);
  672. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  673. dwError = TranslateExceptionCode(RpcExceptionCode());
  674. BAIL_ON_WIN32_ERROR(dwError);
  675. } RpcEndExcept
  676. error:
  677. return (dwError);
  678. }
  679. DWORD
  680. GetMMFilter(
  681. HANDLE hMMFilter,
  682. PMM_FILTER * ppMMFilter
  683. )
  684. {
  685. DWORD dwError = 0;
  686. MM_FILTER_CONTAINER MMFilterContainer;
  687. PMM_FILTER_CONTAINER pMMFilterContainer = &MMFilterContainer;
  688. memset(pMMFilterContainer, 0, sizeof(MM_FILTER_CONTAINER));
  689. if (!hMMFilter || !ppMMFilter) {
  690. return (ERROR_INVALID_PARAMETER);
  691. }
  692. RpcTryExcept {
  693. dwError = RpcGetMMFilter(
  694. hMMFilter,
  695. &pMMFilterContainer
  696. );
  697. BAIL_ON_WIN32_ERROR(dwError);
  698. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  699. dwError = TranslateExceptionCode(RpcExceptionCode());
  700. BAIL_ON_WIN32_ERROR(dwError);
  701. } RpcEndExcept
  702. *ppMMFilter = pMMFilterContainer->pMMFilters;
  703. return (dwError);
  704. error:
  705. *ppMMFilter = NULL;
  706. return (dwError);
  707. }
  708. DWORD
  709. MatchMMFilter(
  710. LPWSTR pServerName,
  711. PMM_FILTER pMMFilter,
  712. DWORD dwFlags,
  713. PMM_FILTER * ppMatchedMMFilters,
  714. PIPSEC_MM_POLICY * ppMatchedMMPolicies,
  715. PMM_AUTH_METHODS * ppMatchedMMAuthMethods,
  716. DWORD dwPreferredNumEntries,
  717. LPDWORD pdwNumMatches,
  718. LPDWORD pdwResumeHandle
  719. )
  720. {
  721. DWORD dwError = 0;
  722. MM_FILTER_CONTAINER InMMFilterContainer;
  723. PMM_FILTER_CONTAINER pInMMFilterContainer = &InMMFilterContainer;
  724. MM_FILTER_CONTAINER OutMMFilterContainer;
  725. PMM_FILTER_CONTAINER pOutMMFilterContainer = &OutMMFilterContainer;
  726. IPSEC_MM_POLICY_CONTAINER MMPolicyContainer;
  727. PIPSEC_MM_POLICY_CONTAINER pMMPolicyContainer = &MMPolicyContainer;
  728. MM_AUTH_METHODS_CONTAINER MMAuthContainer;
  729. PMM_AUTH_METHODS_CONTAINER pMMAuthContainer = &MMAuthContainer;
  730. if (!pMMFilter || !ppMatchedMMFilters || !ppMatchedMMPolicies ||
  731. !ppMatchedMMAuthMethods || !pdwNumMatches || !pdwResumeHandle) {
  732. return (ERROR_INVALID_PARAMETER);
  733. }
  734. dwError = ValidateMMFilterTemplate(
  735. pMMFilter
  736. );
  737. BAIL_ON_WIN32_ERROR(dwError);
  738. pInMMFilterContainer->dwNumFilters = 1;
  739. pInMMFilterContainer->pMMFilters = pMMFilter;
  740. memset(pOutMMFilterContainer, 0, sizeof(MM_FILTER_CONTAINER));
  741. memset(pMMPolicyContainer, 0, sizeof(IPSEC_MM_POLICY_CONTAINER));
  742. memset(pMMAuthContainer, 0, sizeof(MM_AUTH_METHODS_CONTAINER));
  743. RpcTryExcept {
  744. dwError = RpcMatchMMFilter(
  745. pServerName,
  746. pInMMFilterContainer,
  747. dwFlags,
  748. &pOutMMFilterContainer,
  749. &pMMPolicyContainer,
  750. &pMMAuthContainer,
  751. dwPreferredNumEntries,
  752. pdwResumeHandle
  753. );
  754. BAIL_ON_WIN32_ERROR(dwError);
  755. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  756. dwError = TranslateExceptionCode(RpcExceptionCode());
  757. BAIL_ON_WIN32_ERROR(dwError);
  758. } RpcEndExcept
  759. *ppMatchedMMFilters = pOutMMFilterContainer->pMMFilters;
  760. *ppMatchedMMPolicies = pMMPolicyContainer->pPolicies;
  761. *ppMatchedMMAuthMethods = pMMAuthContainer->pMMAuthMethods;
  762. *pdwNumMatches = pOutMMFilterContainer->dwNumFilters;
  763. return (dwError);
  764. error:
  765. *ppMatchedMMFilters = NULL;
  766. *ppMatchedMMPolicies = NULL;
  767. *ppMatchedMMAuthMethods = NULL;
  768. *pdwNumMatches = 0;
  769. return (dwError);
  770. }
  771. DWORD
  772. MatchTransportFilter(
  773. LPWSTR pServerName,
  774. PTRANSPORT_FILTER pTxFilter,
  775. DWORD dwFlags,
  776. PTRANSPORT_FILTER * ppMatchedTxFilters,
  777. PIPSEC_QM_POLICY * ppMatchedQMPolicies,
  778. DWORD dwPreferredNumEntries,
  779. LPDWORD pdwNumMatches,
  780. LPDWORD pdwResumeHandle
  781. )
  782. {
  783. DWORD dwError = 0;
  784. TRANSPORT_FILTER_CONTAINER InTxFilterContainer;
  785. PTRANSPORT_FILTER_CONTAINER pInTxFilterContainer = &InTxFilterContainer;
  786. TRANSPORT_FILTER_CONTAINER OutTxFilterContainer;
  787. PTRANSPORT_FILTER_CONTAINER pOutTxFilterContainer = &OutTxFilterContainer;
  788. IPSEC_QM_POLICY_CONTAINER QMPolicyContainer;
  789. PIPSEC_QM_POLICY_CONTAINER pQMPolicyContainer = &QMPolicyContainer;
  790. if (!pTxFilter || !ppMatchedTxFilters || !ppMatchedQMPolicies ||
  791. !pdwNumMatches || !pdwResumeHandle) {
  792. return (ERROR_INVALID_PARAMETER);
  793. }
  794. dwError = ValidateTxFilterTemplate(
  795. pTxFilter
  796. );
  797. BAIL_ON_WIN32_ERROR(dwError);
  798. pInTxFilterContainer->dwNumFilters = 1;
  799. pInTxFilterContainer->pTransportFilters = pTxFilter;
  800. memset(pOutTxFilterContainer, 0, sizeof(TRANSPORT_FILTER_CONTAINER));
  801. memset(pQMPolicyContainer, 0, sizeof(IPSEC_QM_POLICY_CONTAINER));
  802. RpcTryExcept {
  803. dwError = RpcMatchTransportFilter(
  804. pServerName,
  805. pInTxFilterContainer,
  806. dwFlags,
  807. &pOutTxFilterContainer,
  808. &pQMPolicyContainer,
  809. dwPreferredNumEntries,
  810. pdwResumeHandle
  811. );
  812. BAIL_ON_WIN32_ERROR(dwError);
  813. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  814. dwError = TranslateExceptionCode(RpcExceptionCode());
  815. BAIL_ON_WIN32_ERROR(dwError);
  816. } RpcEndExcept
  817. *ppMatchedTxFilters = pOutTxFilterContainer->pTransportFilters;
  818. *ppMatchedQMPolicies = pQMPolicyContainer->pPolicies;
  819. *pdwNumMatches = pOutTxFilterContainer->dwNumFilters;
  820. return (dwError);
  821. error:
  822. *ppMatchedTxFilters = NULL;
  823. *ppMatchedQMPolicies = NULL;
  824. *pdwNumMatches = 0;
  825. return (dwError);
  826. }
  827. DWORD
  828. GetQMPolicyByID(
  829. LPWSTR pServerName,
  830. GUID gQMPolicyID,
  831. PIPSEC_QM_POLICY * ppQMPolicy
  832. )
  833. {
  834. DWORD dwError = 0;
  835. IPSEC_QM_POLICY_CONTAINER QMPolicyContainer;
  836. PIPSEC_QM_POLICY_CONTAINER pQMPolicyContainer = &QMPolicyContainer;
  837. memset(pQMPolicyContainer, 0, sizeof(IPSEC_QM_POLICY_CONTAINER));
  838. if (!ppQMPolicy) {
  839. return (ERROR_INVALID_PARAMETER);
  840. }
  841. RpcTryExcept {
  842. dwError = RpcGetQMPolicyByID(
  843. pServerName,
  844. gQMPolicyID,
  845. &pQMPolicyContainer
  846. );
  847. BAIL_ON_WIN32_ERROR(dwError);
  848. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  849. dwError = TranslateExceptionCode(RpcExceptionCode());
  850. BAIL_ON_WIN32_ERROR(dwError);
  851. } RpcEndExcept
  852. *ppQMPolicy = pQMPolicyContainer->pPolicies;
  853. return (dwError);
  854. error:
  855. *ppQMPolicy = NULL;
  856. return (dwError);
  857. }
  858. DWORD
  859. GetMMPolicyByID(
  860. LPWSTR pServerName,
  861. GUID gMMPolicyID,
  862. PIPSEC_MM_POLICY * ppMMPolicy
  863. )
  864. {
  865. DWORD dwError = 0;
  866. IPSEC_MM_POLICY_CONTAINER MMPolicyContainer;
  867. PIPSEC_MM_POLICY_CONTAINER pMMPolicyContainer = &MMPolicyContainer;
  868. memset(pMMPolicyContainer, 0, sizeof(IPSEC_MM_POLICY_CONTAINER));
  869. if (!ppMMPolicy) {
  870. return (ERROR_INVALID_PARAMETER);
  871. }
  872. RpcTryExcept {
  873. dwError = RpcGetMMPolicyByID(
  874. pServerName,
  875. gMMPolicyID,
  876. &pMMPolicyContainer
  877. );
  878. BAIL_ON_WIN32_ERROR(dwError);
  879. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  880. dwError = TranslateExceptionCode(RpcExceptionCode());
  881. BAIL_ON_WIN32_ERROR(dwError);
  882. } RpcEndExcept
  883. *ppMMPolicy = pMMPolicyContainer->pPolicies;
  884. return (dwError);
  885. error:
  886. *ppMMPolicy = NULL;
  887. return (dwError);
  888. }
  889. DWORD
  890. AddMMAuthMethods(
  891. LPWSTR pServerName,
  892. DWORD dwFlags,
  893. PMM_AUTH_METHODS pMMAuthMethods
  894. )
  895. {
  896. DWORD dwError = 0;
  897. MM_AUTH_METHODS_CONTAINER MMAuthContainer;
  898. PMM_AUTH_METHODS_CONTAINER pMMAuthContainer = &MMAuthContainer;
  899. dwError = ValidateMMAuthMethods(
  900. pMMAuthMethods
  901. );
  902. BAIL_ON_WIN32_ERROR(dwError);
  903. pMMAuthContainer->dwNumAuthMethods = 1;
  904. pMMAuthContainer->pMMAuthMethods = pMMAuthMethods;
  905. RpcTryExcept {
  906. dwError = RpcAddMMAuthMethods(
  907. pServerName,
  908. dwFlags,
  909. pMMAuthContainer
  910. );
  911. BAIL_ON_WIN32_ERROR(dwError);
  912. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  913. dwError = TranslateExceptionCode(RpcExceptionCode());
  914. BAIL_ON_WIN32_ERROR(dwError);
  915. } RpcEndExcept
  916. error:
  917. return (dwError);
  918. }
  919. DWORD
  920. DeleteMMAuthMethods(
  921. LPWSTR pServerName,
  922. GUID gMMAuthID
  923. )
  924. {
  925. DWORD dwError = 0;
  926. RpcTryExcept {
  927. dwError = RpcDeleteMMAuthMethods(
  928. pServerName,
  929. gMMAuthID
  930. );
  931. BAIL_ON_WIN32_ERROR(dwError);
  932. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  933. dwError = TranslateExceptionCode(RpcExceptionCode());
  934. BAIL_ON_WIN32_ERROR(dwError);
  935. } RpcEndExcept
  936. error:
  937. return (dwError);
  938. }
  939. DWORD
  940. EnumMMAuthMethods(
  941. LPWSTR pServerName,
  942. PMM_AUTH_METHODS * ppMMAuthMethods,
  943. DWORD dwPreferredNumEntries,
  944. LPDWORD pdwNumAuthMethods,
  945. LPDWORD pdwResumeHandle
  946. )
  947. {
  948. DWORD dwError = 0;
  949. MM_AUTH_METHODS_CONTAINER MMAuthContainer;
  950. PMM_AUTH_METHODS_CONTAINER pMMAuthContainer = &MMAuthContainer;
  951. memset(pMMAuthContainer, 0, sizeof(MM_AUTH_METHODS_CONTAINER));
  952. if (!ppMMAuthMethods || !pdwNumAuthMethods || !pdwResumeHandle) {
  953. return (ERROR_INVALID_PARAMETER);
  954. }
  955. RpcTryExcept {
  956. dwError = RpcEnumMMAuthMethods(
  957. pServerName,
  958. &pMMAuthContainer,
  959. dwPreferredNumEntries,
  960. pdwResumeHandle
  961. );
  962. BAIL_ON_WIN32_ERROR(dwError);
  963. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  964. dwError = TranslateExceptionCode(RpcExceptionCode());
  965. BAIL_ON_WIN32_ERROR(dwError);
  966. } RpcEndExcept
  967. *ppMMAuthMethods = pMMAuthContainer->pMMAuthMethods;
  968. *pdwNumAuthMethods = pMMAuthContainer->dwNumAuthMethods;
  969. return (dwError);
  970. error:
  971. *ppMMAuthMethods = NULL;
  972. *pdwNumAuthMethods = 0;
  973. return (dwError);
  974. }
  975. DWORD
  976. SetMMAuthMethods(
  977. LPWSTR pServerName,
  978. GUID gMMAuthID,
  979. PMM_AUTH_METHODS pMMAuthMethods
  980. )
  981. {
  982. DWORD dwError = 0;
  983. MM_AUTH_METHODS_CONTAINER MMAuthContainer;
  984. PMM_AUTH_METHODS_CONTAINER pMMAuthContainer = &MMAuthContainer;
  985. dwError = ValidateMMAuthMethods(
  986. pMMAuthMethods
  987. );
  988. BAIL_ON_WIN32_ERROR(dwError);
  989. pMMAuthContainer->dwNumAuthMethods = 1;
  990. pMMAuthContainer->pMMAuthMethods = pMMAuthMethods;
  991. RpcTryExcept {
  992. dwError = RpcSetMMAuthMethods(
  993. pServerName,
  994. gMMAuthID,
  995. pMMAuthContainer
  996. );
  997. BAIL_ON_WIN32_ERROR(dwError);
  998. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  999. dwError = TranslateExceptionCode(RpcExceptionCode());
  1000. BAIL_ON_WIN32_ERROR(dwError);
  1001. } RpcEndExcept
  1002. error:
  1003. return (dwError);
  1004. }
  1005. DWORD
  1006. GetMMAuthMethods(
  1007. LPWSTR pServerName,
  1008. GUID gMMAuthID,
  1009. PMM_AUTH_METHODS * ppMMAuthMethods
  1010. )
  1011. {
  1012. DWORD dwError = 0;
  1013. MM_AUTH_METHODS_CONTAINER MMAuthContainer;
  1014. PMM_AUTH_METHODS_CONTAINER pMMAuthContainer = &MMAuthContainer;
  1015. memset(pMMAuthContainer, 0, sizeof(MM_AUTH_METHODS_CONTAINER));
  1016. if (!ppMMAuthMethods) {
  1017. return (ERROR_INVALID_PARAMETER);
  1018. }
  1019. RpcTryExcept {
  1020. dwError = RpcGetMMAuthMethods(
  1021. pServerName,
  1022. gMMAuthID,
  1023. &pMMAuthContainer
  1024. );
  1025. BAIL_ON_WIN32_ERROR(dwError);
  1026. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  1027. dwError = TranslateExceptionCode(RpcExceptionCode());
  1028. BAIL_ON_WIN32_ERROR(dwError);
  1029. } RpcEndExcept
  1030. *ppMMAuthMethods = pMMAuthContainer->pMMAuthMethods;
  1031. return (dwError);
  1032. error:
  1033. *ppMMAuthMethods = NULL;
  1034. return (dwError);
  1035. }
  1036. DWORD
  1037. IPSecInitiateIKENegotiation(
  1038. LPWSTR pServerName,
  1039. PIPSEC_QM_FILTER pQMFilter,
  1040. DWORD dwClientProcessId,
  1041. HANDLE hClientEvent,
  1042. DWORD dwFlags,
  1043. PHANDLE phNegotiation
  1044. )
  1045. {
  1046. DWORD dwError = 0;
  1047. QM_FILTER_CONTAINER FilterContainer;
  1048. PQM_FILTER_CONTAINER pFilterContainer = &FilterContainer;
  1049. ULONG uhClientEvent = 0;
  1050. pFilterContainer->dwNumFilters = 1;
  1051. pFilterContainer->pQMFilters = pQMFilter;
  1052. uhClientEvent = HandleToUlong(hClientEvent);
  1053. if (phNegotiation) {
  1054. *phNegotiation=NULL;
  1055. }
  1056. dwError=ValidateInitiateIKENegotiation(
  1057. pServerName,
  1058. pFilterContainer,
  1059. dwClientProcessId,
  1060. uhClientEvent,
  1061. dwFlags,
  1062. phNegotiation
  1063. );
  1064. BAIL_ON_WIN32_ERROR(dwError);
  1065. RpcTryExcept {
  1066. dwError = RpcInitiateIKENegotiation(
  1067. pServerName,
  1068. pFilterContainer,
  1069. dwClientProcessId,
  1070. uhClientEvent,
  1071. dwFlags,
  1072. phNegotiation
  1073. );
  1074. BAIL_ON_WIN32_ERROR(dwError);
  1075. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  1076. dwError = TranslateExceptionCode(RpcExceptionCode());
  1077. BAIL_ON_WIN32_ERROR(dwError);
  1078. } RpcEndExcept
  1079. error:
  1080. return (dwError);
  1081. }
  1082. DWORD
  1083. IPSecQueryIKENegotiationStatus(
  1084. HANDLE hNegotiation,
  1085. PSA_NEGOTIATION_STATUS_INFO pNegotiationStatus
  1086. )
  1087. {
  1088. DWORD dwError = 0;
  1089. dwError=ValidateQueryIKENegotiationStatus(
  1090. hNegotiation,
  1091. pNegotiationStatus
  1092. );
  1093. BAIL_ON_WIN32_ERROR(dwError);
  1094. RpcTryExcept {
  1095. dwError = RpcQueryIKENegotiationStatus(
  1096. hNegotiation,
  1097. pNegotiationStatus
  1098. );
  1099. BAIL_ON_WIN32_ERROR(dwError);
  1100. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  1101. dwError = TranslateExceptionCode(RpcExceptionCode());
  1102. BAIL_ON_WIN32_ERROR(dwError);
  1103. } RpcEndExcept
  1104. error:
  1105. return (dwError);
  1106. }
  1107. DWORD
  1108. IPSecCloseIKENegotiationHandle(
  1109. HANDLE hNegotiation
  1110. )
  1111. {
  1112. DWORD dwError = 0;
  1113. dwError=ValidateCloseIKENegotiationHandle(hNegotiation);
  1114. BAIL_ON_WIN32_ERROR(dwError);
  1115. RpcTryExcept {
  1116. dwError = RpcCloseIKENegotiationHandle(
  1117. &hNegotiation
  1118. );
  1119. BAIL_ON_WIN32_ERROR(dwError);
  1120. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  1121. dwError = TranslateExceptionCode(RpcExceptionCode());
  1122. BAIL_ON_WIN32_ERROR(dwError);
  1123. } RpcEndExcept
  1124. error:
  1125. return (dwError);
  1126. }
  1127. DWORD
  1128. IPSecEnumMMSAs(
  1129. LPWSTR pServerName,
  1130. PIPSEC_MM_SA pMMTemplate,
  1131. PIPSEC_MM_SA * ppMMSAs,
  1132. LPDWORD pdwNumEntries,
  1133. LPDWORD pdwTotalMMsAvailable,
  1134. LPDWORD pdwEnumHandle,
  1135. DWORD dwFlags
  1136. )
  1137. {
  1138. DWORD dwError = 0;
  1139. MM_SA_CONTAINER MMSAContainer, MMSAContainerTemplate;
  1140. PMM_SA_CONTAINER pContainer = &MMSAContainer;
  1141. MMSAContainerTemplate.dwNumMMSAs = 1;
  1142. MMSAContainerTemplate.pMMSAs = pMMTemplate;
  1143. memset(&MMSAContainer, 0, sizeof(MM_SA_CONTAINER));
  1144. if (ppMMSAs == NULL) {
  1145. return ERROR_INVALID_PARAMETER;
  1146. }
  1147. dwError=ValidateEnumMMSAs(
  1148. pServerName,
  1149. &MMSAContainerTemplate,
  1150. &pContainer,
  1151. pdwNumEntries,
  1152. pdwTotalMMsAvailable,
  1153. pdwEnumHandle,
  1154. dwFlags
  1155. );
  1156. BAIL_ON_WIN32_ERROR(dwError);
  1157. RpcTryExcept {
  1158. dwError = RpcEnumMMSAs(
  1159. pServerName,
  1160. &MMSAContainerTemplate,
  1161. &pContainer,
  1162. pdwNumEntries,
  1163. pdwTotalMMsAvailable,
  1164. pdwEnumHandle,
  1165. dwFlags
  1166. );
  1167. BAIL_ON_WIN32_ERROR(dwError);
  1168. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  1169. dwError = TranslateExceptionCode(RpcExceptionCode());
  1170. BAIL_ON_WIN32_ERROR(dwError);
  1171. } RpcEndExcept
  1172. *ppMMSAs = pContainer->pMMSAs;
  1173. return (dwError);
  1174. error:
  1175. return (dwError);
  1176. }
  1177. DWORD
  1178. IPSecDeleteMMSAs(
  1179. LPWSTR pServerName,
  1180. PIPSEC_MM_SA pMMTemplate,
  1181. DWORD dwFlags
  1182. )
  1183. {
  1184. DWORD dwError = 0;
  1185. MM_SA_CONTAINER MMSAContainerTemplate;
  1186. MMSAContainerTemplate.dwNumMMSAs = 1;
  1187. MMSAContainerTemplate.pMMSAs = pMMTemplate;
  1188. dwError=ValidateDeleteMMSAs(
  1189. pServerName,
  1190. &MMSAContainerTemplate,
  1191. dwFlags
  1192. );
  1193. BAIL_ON_WIN32_ERROR(dwError);
  1194. RpcTryExcept {
  1195. dwError = RpcDeleteMMSAs(
  1196. pServerName,
  1197. &MMSAContainerTemplate,
  1198. dwFlags
  1199. );
  1200. BAIL_ON_WIN32_ERROR(dwError);
  1201. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  1202. dwError = TranslateExceptionCode(RpcExceptionCode());
  1203. BAIL_ON_WIN32_ERROR(dwError);
  1204. } RpcEndExcept
  1205. error:
  1206. return (dwError);
  1207. }
  1208. DWORD
  1209. IPSecDeleteQMSAs(
  1210. LPWSTR pServerName,
  1211. PIPSEC_QM_SA pIpsecQMSA,
  1212. DWORD dwFlags
  1213. )
  1214. {
  1215. DWORD dwError = 0;
  1216. QM_SA_CONTAINER QMSATempContainer;
  1217. PQM_SA_CONTAINER pQMSATempContainer = &QMSATempContainer;
  1218. memset(pQMSATempContainer, 0, sizeof(QM_SA_CONTAINER));
  1219. if (!pIpsecQMSA) {
  1220. dwError = ERROR_INVALID_PARAMETER;
  1221. BAIL_ON_WIN32_ERROR(dwError);
  1222. }
  1223. pQMSATempContainer->dwNumQMSAs = 1;
  1224. pQMSATempContainer->pQMSAs = pIpsecQMSA;
  1225. RpcTryExcept {
  1226. dwError = RpcDeleteQMSAs(
  1227. pServerName,
  1228. pQMSATempContainer,
  1229. dwFlags
  1230. );
  1231. BAIL_ON_WIN32_ERROR(dwError);
  1232. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  1233. dwError = TranslateExceptionCode(RpcExceptionCode());
  1234. BAIL_ON_WIN32_ERROR(dwError);
  1235. } RpcEndExcept
  1236. error:
  1237. return (dwError);
  1238. }
  1239. DWORD
  1240. IPSecQueryIKEStatistics(
  1241. LPWSTR pServerName,
  1242. PIKE_STATISTICS pIKEStatistics
  1243. )
  1244. {
  1245. DWORD dwError = 0;
  1246. dwError=ValidateQueryIKEStatistics(
  1247. pServerName,
  1248. pIKEStatistics
  1249. );
  1250. BAIL_ON_WIN32_ERROR(dwError);
  1251. RpcTryExcept {
  1252. dwError = RpcQueryIKEStatistics(
  1253. pServerName,
  1254. pIKEStatistics
  1255. );
  1256. BAIL_ON_WIN32_ERROR(dwError);
  1257. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  1258. dwError = TranslateExceptionCode(RpcExceptionCode());
  1259. BAIL_ON_WIN32_ERROR(dwError);
  1260. } RpcEndExcept
  1261. error:
  1262. return (dwError);
  1263. }
  1264. DWORD
  1265. IPSecRegisterIKENotifyClient(
  1266. LPWSTR pServerName,
  1267. DWORD dwClientProcessId,
  1268. HANDLE hClientEvent,
  1269. IPSEC_QM_SA QMTemplate,
  1270. PHANDLE phNotifyHandle,
  1271. DWORD dwFlags
  1272. )
  1273. {
  1274. DWORD dwError = 0;
  1275. ULONG uhClientEvent = 0;
  1276. QM_SA_CONTAINER QMSAContainer;
  1277. PQM_SA_CONTAINER pQMSAContainer = &QMSAContainer;
  1278. QMSAContainer.dwNumQMSAs=1;
  1279. QMSAContainer.pQMSAs=&QMTemplate;
  1280. uhClientEvent = HandleToUlong(hClientEvent);
  1281. dwError=ValidateRegisterIKENotifyClient(
  1282. pServerName,
  1283. dwClientProcessId,
  1284. uhClientEvent,
  1285. pQMSAContainer,
  1286. phNotifyHandle,
  1287. dwFlags
  1288. );
  1289. BAIL_ON_WIN32_ERROR(dwError);
  1290. RpcTryExcept {
  1291. dwError = RpcRegisterIKENotifyClient(
  1292. pServerName,
  1293. dwClientProcessId,
  1294. uhClientEvent,
  1295. pQMSAContainer,
  1296. phNotifyHandle,
  1297. dwFlags
  1298. );
  1299. BAIL_ON_WIN32_ERROR(dwError);
  1300. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  1301. dwError = TranslateExceptionCode(RpcExceptionCode());
  1302. BAIL_ON_WIN32_ERROR(dwError);
  1303. } RpcEndExcept
  1304. error:
  1305. return (dwError);
  1306. }
  1307. DWORD IPSecQueryNotifyData(
  1308. HANDLE hNotifyHandle,
  1309. PDWORD pdwNumEntries,
  1310. PIPSEC_QM_SA *ppQMSAs,
  1311. DWORD dwFlags
  1312. )
  1313. {
  1314. DWORD dwError = 0;
  1315. QM_SA_CONTAINER QMSAContainer;
  1316. PQM_SA_CONTAINER pContainer = &QMSAContainer;
  1317. memset(&QMSAContainer, 0, sizeof(QM_SA_CONTAINER));
  1318. if (ppQMSAs == NULL) {
  1319. return ERROR_INVALID_PARAMETER;
  1320. }
  1321. dwError=ValidateQueryNotifyData(
  1322. hNotifyHandle,
  1323. pdwNumEntries,
  1324. &pContainer,
  1325. dwFlags
  1326. );
  1327. BAIL_ON_WIN32_ERROR(dwError);
  1328. RpcTryExcept {
  1329. dwError = RpcQueryNotifyData(
  1330. hNotifyHandle,
  1331. pdwNumEntries,
  1332. &pContainer,
  1333. dwFlags
  1334. );
  1335. if (dwError && dwError != ERROR_MORE_DATA) {
  1336. goto error;
  1337. }
  1338. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  1339. dwError = TranslateExceptionCode(RpcExceptionCode());
  1340. BAIL_ON_WIN32_ERROR(dwError);
  1341. } RpcEndExcept
  1342. *ppQMSAs = pContainer->pQMSAs;
  1343. *pdwNumEntries = pContainer->dwNumQMSAs;
  1344. return (dwError);
  1345. error:
  1346. return (dwError);
  1347. }
  1348. DWORD IPSecCloseNotifyHandle(
  1349. HANDLE hNotifyHandle
  1350. )
  1351. {
  1352. DWORD dwError = 0;
  1353. dwError=ValidateCloseNotifyHandle(hNotifyHandle);
  1354. BAIL_ON_WIN32_ERROR(dwError);
  1355. RpcTryExcept {
  1356. dwError = RpcCloseNotifyHandle(
  1357. &hNotifyHandle
  1358. );
  1359. BAIL_ON_WIN32_ERROR(dwError);
  1360. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  1361. dwError = TranslateExceptionCode(RpcExceptionCode());
  1362. BAIL_ON_WIN32_ERROR(dwError);
  1363. } RpcEndExcept
  1364. error:
  1365. return (dwError);
  1366. }
  1367. DWORD
  1368. QueryIPSecStatistics(
  1369. LPWSTR pServerName,
  1370. PIPSEC_STATISTICS * ppIpsecStatistics
  1371. )
  1372. {
  1373. DWORD dwError = 0;
  1374. IPSEC_STATISTICS_CONTAINER IpsecStatsContainer;
  1375. PIPSEC_STATISTICS_CONTAINER pIpsecStatsContainer = &IpsecStatsContainer;
  1376. memset(pIpsecStatsContainer, 0, sizeof(IPSEC_STATISTICS_CONTAINER));
  1377. if (!ppIpsecStatistics) {
  1378. return (ERROR_INVALID_PARAMETER);
  1379. }
  1380. RpcTryExcept {
  1381. dwError = RpcQueryIPSecStatistics(
  1382. pServerName,
  1383. &pIpsecStatsContainer
  1384. );
  1385. BAIL_ON_WIN32_ERROR(dwError);
  1386. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  1387. dwError = TranslateExceptionCode(RpcExceptionCode());
  1388. BAIL_ON_WIN32_ERROR(dwError);
  1389. } RpcEndExcept
  1390. *ppIpsecStatistics = pIpsecStatsContainer->pIpsecStatistics;
  1391. return (dwError);
  1392. error:
  1393. return (dwError);
  1394. }
  1395. DWORD
  1396. EnumQMSAs(
  1397. LPWSTR pServerName,
  1398. PIPSEC_QM_SA pQMSATemplate,
  1399. PIPSEC_QM_SA * ppQMSAs,
  1400. DWORD dwPreferredNumEntries,
  1401. LPDWORD pdwNumQMSAs,
  1402. LPDWORD pdwNumTotalQMSAs,
  1403. LPDWORD pdwResumeHandle,
  1404. DWORD dwFlags
  1405. )
  1406. {
  1407. DWORD dwError = 0;
  1408. QM_SA_CONTAINER QMSATempContainer;
  1409. PQM_SA_CONTAINER pQMSATempContainer = &QMSATempContainer;
  1410. QM_SA_CONTAINER QMSAContainer;
  1411. PQM_SA_CONTAINER pQMSAContainer = &QMSAContainer;
  1412. memset(pQMSAContainer, 0, sizeof(QM_SA_CONTAINER));
  1413. if (!ppQMSAs || !pdwNumQMSAs ||
  1414. !pdwNumTotalQMSAs || !pdwResumeHandle) {
  1415. return (ERROR_INVALID_PARAMETER);
  1416. }
  1417. if (pQMSATemplate) {
  1418. pQMSATempContainer->dwNumQMSAs = 1;
  1419. pQMSATempContainer->pQMSAs = pQMSATemplate;
  1420. }
  1421. else {
  1422. pQMSATempContainer->dwNumQMSAs = 0;
  1423. pQMSATempContainer->pQMSAs = NULL;
  1424. }
  1425. RpcTryExcept {
  1426. dwError = RpcEnumQMSAs(
  1427. pServerName,
  1428. pQMSATempContainer,
  1429. &pQMSAContainer,
  1430. dwPreferredNumEntries,
  1431. pdwNumTotalQMSAs,
  1432. pdwResumeHandle,
  1433. dwFlags
  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. *ppQMSAs = pQMSAContainer->pQMSAs;
  1441. *pdwNumQMSAs = pQMSAContainer->dwNumQMSAs;
  1442. return (dwError);
  1443. error:
  1444. return (dwError);
  1445. }
  1446. DWORD
  1447. AddTunnelFilter(
  1448. LPWSTR pServerName,
  1449. DWORD dwFlags,
  1450. PTUNNEL_FILTER pTunnelFilter,
  1451. PHANDLE phFilter
  1452. )
  1453. {
  1454. DWORD dwError = 0;
  1455. TUNNEL_FILTER_CONTAINER FilterContainer;
  1456. PTUNNEL_FILTER_CONTAINER pFilterContainer = &FilterContainer;
  1457. if (!phFilter) {
  1458. return (ERROR_INVALID_PARAMETER);
  1459. }
  1460. dwError = ValidateTunnelFilter(
  1461. pTunnelFilter
  1462. );
  1463. BAIL_ON_WIN32_ERROR(dwError);
  1464. pFilterContainer->dwNumFilters = 1;
  1465. pFilterContainer->pTunnelFilters = pTunnelFilter;
  1466. RpcTryExcept {
  1467. dwError = RpcAddTunnelFilter(
  1468. pServerName,
  1469. dwFlags,
  1470. pFilterContainer,
  1471. phFilter
  1472. );
  1473. BAIL_ON_WIN32_ERROR(dwError);
  1474. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  1475. dwError = TranslateExceptionCode(RpcExceptionCode());
  1476. BAIL_ON_WIN32_ERROR(dwError);
  1477. } RpcEndExcept
  1478. error:
  1479. return (dwError);
  1480. }
  1481. DWORD
  1482. DeleteTunnelFilter(
  1483. HANDLE hFilter
  1484. )
  1485. {
  1486. DWORD dwError = 0;
  1487. if (!hFilter) {
  1488. return (ERROR_INVALID_PARAMETER);
  1489. }
  1490. RpcTryExcept {
  1491. dwError = RpcDeleteTunnelFilter(
  1492. &hFilter
  1493. );
  1494. BAIL_ON_WIN32_ERROR(dwError);
  1495. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  1496. dwError = TranslateExceptionCode(RpcExceptionCode());
  1497. BAIL_ON_WIN32_ERROR(dwError);
  1498. } RpcEndExcept
  1499. error:
  1500. if (dwError) {
  1501. dwError = SPDDestroyClientContextHandle(
  1502. dwError,
  1503. hFilter
  1504. );
  1505. }
  1506. return (dwError);
  1507. }
  1508. DWORD
  1509. EnumTunnelFilters(
  1510. LPWSTR pServerName,
  1511. DWORD dwLevel,
  1512. GUID gGenericFilterID,
  1513. PTUNNEL_FILTER * ppTunnelFilters,
  1514. DWORD dwPreferredNumEntries,
  1515. LPDWORD pdwNumFilters,
  1516. LPDWORD pdwResumeHandle
  1517. )
  1518. {
  1519. DWORD dwError = 0;
  1520. TUNNEL_FILTER_CONTAINER FilterContainer;
  1521. PTUNNEL_FILTER_CONTAINER pFilterContainer = &FilterContainer;
  1522. memset(pFilterContainer, 0, sizeof(TUNNEL_FILTER_CONTAINER));
  1523. if (!ppTunnelFilters || !pdwNumFilters || !pdwResumeHandle) {
  1524. return (ERROR_INVALID_PARAMETER);
  1525. }
  1526. switch (dwLevel) {
  1527. case ENUM_GENERIC_FILTERS:
  1528. case ENUM_SELECT_SPECIFIC_FILTERS:
  1529. case ENUM_SPECIFIC_FILTERS:
  1530. break;
  1531. default:
  1532. dwError = ERROR_INVALID_LEVEL;
  1533. BAIL_ON_WIN32_ERROR(dwError);
  1534. break;
  1535. }
  1536. RpcTryExcept {
  1537. dwError = RpcEnumTunnelFilters(
  1538. pServerName,
  1539. dwLevel,
  1540. gGenericFilterID,
  1541. &pFilterContainer,
  1542. dwPreferredNumEntries,
  1543. pdwResumeHandle
  1544. );
  1545. BAIL_ON_WIN32_ERROR(dwError);
  1546. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  1547. dwError = TranslateExceptionCode(RpcExceptionCode());
  1548. BAIL_ON_WIN32_ERROR(dwError);
  1549. } RpcEndExcept
  1550. *ppTunnelFilters = pFilterContainer->pTunnelFilters;
  1551. *pdwNumFilters = pFilterContainer->dwNumFilters;
  1552. return (dwError);
  1553. error:
  1554. *ppTunnelFilters = NULL;
  1555. *pdwNumFilters = 0;
  1556. return (dwError);
  1557. }
  1558. DWORD
  1559. SetTunnelFilter(
  1560. HANDLE hFilter,
  1561. PTUNNEL_FILTER pTunnelFilter
  1562. )
  1563. {
  1564. DWORD dwError = 0;
  1565. TUNNEL_FILTER_CONTAINER FilterContainer;
  1566. PTUNNEL_FILTER_CONTAINER pFilterContainer = &FilterContainer;
  1567. if (!hFilter) {
  1568. return (ERROR_INVALID_PARAMETER);
  1569. }
  1570. dwError = ValidateTunnelFilter(
  1571. pTunnelFilter
  1572. );
  1573. BAIL_ON_WIN32_ERROR(dwError);
  1574. pFilterContainer->dwNumFilters = 1;
  1575. pFilterContainer->pTunnelFilters = pTunnelFilter;
  1576. RpcTryExcept {
  1577. dwError = RpcSetTunnelFilter(
  1578. hFilter,
  1579. pFilterContainer
  1580. );
  1581. BAIL_ON_WIN32_ERROR(dwError);
  1582. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  1583. dwError = TranslateExceptionCode(RpcExceptionCode());
  1584. BAIL_ON_WIN32_ERROR(dwError);
  1585. } RpcEndExcept
  1586. error:
  1587. return (dwError);
  1588. }
  1589. DWORD
  1590. GetTunnelFilter(
  1591. HANDLE hFilter,
  1592. PTUNNEL_FILTER * ppTunnelFilter
  1593. )
  1594. {
  1595. DWORD dwError = 0;
  1596. TUNNEL_FILTER_CONTAINER FilterContainer;
  1597. PTUNNEL_FILTER_CONTAINER pFilterContainer = &FilterContainer;
  1598. memset(pFilterContainer, 0, sizeof(TUNNEL_FILTER_CONTAINER));
  1599. if (!hFilter || !ppTunnelFilter) {
  1600. return (ERROR_INVALID_PARAMETER);
  1601. }
  1602. RpcTryExcept {
  1603. dwError = RpcGetTunnelFilter(
  1604. hFilter,
  1605. &pFilterContainer
  1606. );
  1607. BAIL_ON_WIN32_ERROR(dwError);
  1608. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  1609. dwError = TranslateExceptionCode(RpcExceptionCode());
  1610. BAIL_ON_WIN32_ERROR(dwError);
  1611. } RpcEndExcept
  1612. *ppTunnelFilter = pFilterContainer->pTunnelFilters;
  1613. return (dwError);
  1614. error:
  1615. *ppTunnelFilter = NULL;
  1616. return (dwError);
  1617. }
  1618. DWORD
  1619. MatchTunnelFilter(
  1620. LPWSTR pServerName,
  1621. PTUNNEL_FILTER pTnFilter,
  1622. DWORD dwFlags,
  1623. PTUNNEL_FILTER * ppMatchedTnFilters,
  1624. PIPSEC_QM_POLICY * ppMatchedQMPolicies,
  1625. DWORD dwPreferredNumEntries,
  1626. LPDWORD pdwNumMatches,
  1627. LPDWORD pdwResumeHandle
  1628. )
  1629. {
  1630. DWORD dwError = 0;
  1631. TUNNEL_FILTER_CONTAINER InTnFilterContainer;
  1632. PTUNNEL_FILTER_CONTAINER pInTnFilterContainer = &InTnFilterContainer;
  1633. TUNNEL_FILTER_CONTAINER OutTnFilterContainer;
  1634. PTUNNEL_FILTER_CONTAINER pOutTnFilterContainer = &OutTnFilterContainer;
  1635. IPSEC_QM_POLICY_CONTAINER QMPolicyContainer;
  1636. PIPSEC_QM_POLICY_CONTAINER pQMPolicyContainer = &QMPolicyContainer;
  1637. if (!pTnFilter || !ppMatchedTnFilters || !ppMatchedQMPolicies ||
  1638. !pdwNumMatches || !pdwResumeHandle) {
  1639. return (ERROR_INVALID_PARAMETER);
  1640. }
  1641. dwError = ValidateTnFilterTemplate(
  1642. pTnFilter
  1643. );
  1644. BAIL_ON_WIN32_ERROR(dwError);
  1645. pInTnFilterContainer->dwNumFilters = 1;
  1646. pInTnFilterContainer->pTunnelFilters = pTnFilter;
  1647. memset(pOutTnFilterContainer, 0, sizeof(TUNNEL_FILTER_CONTAINER));
  1648. memset(pQMPolicyContainer, 0, sizeof(IPSEC_QM_POLICY_CONTAINER));
  1649. RpcTryExcept {
  1650. dwError = RpcMatchTunnelFilter(
  1651. pServerName,
  1652. pInTnFilterContainer,
  1653. dwFlags,
  1654. &pOutTnFilterContainer,
  1655. &pQMPolicyContainer,
  1656. dwPreferredNumEntries,
  1657. pdwResumeHandle
  1658. );
  1659. BAIL_ON_WIN32_ERROR(dwError);
  1660. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  1661. dwError = TranslateExceptionCode(RpcExceptionCode());
  1662. BAIL_ON_WIN32_ERROR(dwError);
  1663. } RpcEndExcept
  1664. *ppMatchedTnFilters = pOutTnFilterContainer->pTunnelFilters;
  1665. *ppMatchedQMPolicies = pQMPolicyContainer->pPolicies;
  1666. *pdwNumMatches = pOutTnFilterContainer->dwNumFilters;
  1667. return (dwError);
  1668. error:
  1669. *ppMatchedTnFilters = NULL;
  1670. *ppMatchedQMPolicies = NULL;
  1671. *pdwNumMatches = 0;
  1672. return (dwError);
  1673. }
  1674. DWORD
  1675. OpenMMFilterHandle(
  1676. LPWSTR pServerName,
  1677. PMM_FILTER pMMFilter,
  1678. PHANDLE phMMFilter
  1679. )
  1680. {
  1681. DWORD dwError = 0;
  1682. MM_FILTER_CONTAINER MMFilterContainer;
  1683. PMM_FILTER_CONTAINER pMMFilterContainer = &MMFilterContainer;
  1684. if (!phMMFilter) {
  1685. return (ERROR_INVALID_PARAMETER);
  1686. }
  1687. dwError = ValidateMMFilter(
  1688. pMMFilter
  1689. );
  1690. BAIL_ON_WIN32_ERROR(dwError);
  1691. pMMFilterContainer->dwNumFilters = 1;
  1692. pMMFilterContainer->pMMFilters = pMMFilter;
  1693. RpcTryExcept {
  1694. dwError = RpcOpenMMFilterHandle(
  1695. pServerName,
  1696. pMMFilterContainer,
  1697. phMMFilter
  1698. );
  1699. BAIL_ON_WIN32_ERROR(dwError);
  1700. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  1701. dwError = TranslateExceptionCode(RpcExceptionCode());
  1702. BAIL_ON_WIN32_ERROR(dwError);
  1703. } RpcEndExcept
  1704. error:
  1705. return (dwError);
  1706. }
  1707. DWORD
  1708. CloseMMFilterHandle(
  1709. HANDLE hMMFilter
  1710. )
  1711. {
  1712. DWORD dwError = 0;
  1713. if (!hMMFilter) {
  1714. return (ERROR_INVALID_PARAMETER);
  1715. }
  1716. RpcTryExcept {
  1717. dwError = RpcCloseMMFilterHandle(
  1718. &hMMFilter
  1719. );
  1720. BAIL_ON_WIN32_ERROR(dwError);
  1721. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  1722. dwError = TranslateExceptionCode(RpcExceptionCode());
  1723. BAIL_ON_WIN32_ERROR(dwError);
  1724. } RpcEndExcept
  1725. error:
  1726. if (dwError) {
  1727. dwError = SPDDestroyClientContextHandle(
  1728. dwError,
  1729. hMMFilter
  1730. );
  1731. }
  1732. return (dwError);
  1733. }
  1734. DWORD
  1735. OpenTransportFilterHandle(
  1736. LPWSTR pServerName,
  1737. PTRANSPORT_FILTER pTransportFilter,
  1738. PHANDLE phTxFilter
  1739. )
  1740. {
  1741. DWORD dwError = 0;
  1742. TRANSPORT_FILTER_CONTAINER FilterContainer;
  1743. PTRANSPORT_FILTER_CONTAINER pFilterContainer = &FilterContainer;
  1744. if (!phTxFilter) {
  1745. return (ERROR_INVALID_PARAMETER);
  1746. }
  1747. dwError = ValidateTransportFilter(
  1748. pTransportFilter
  1749. );
  1750. BAIL_ON_WIN32_ERROR(dwError);
  1751. pFilterContainer->dwNumFilters = 1;
  1752. pFilterContainer->pTransportFilters = pTransportFilter;
  1753. RpcTryExcept {
  1754. dwError = RpcOpenTransportFilterHandle(
  1755. pServerName,
  1756. pFilterContainer,
  1757. phTxFilter
  1758. );
  1759. BAIL_ON_WIN32_ERROR(dwError);
  1760. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  1761. dwError = TranslateExceptionCode(RpcExceptionCode());
  1762. BAIL_ON_WIN32_ERROR(dwError);
  1763. } RpcEndExcept
  1764. error:
  1765. return (dwError);
  1766. }
  1767. DWORD
  1768. CloseTransportFilterHandle(
  1769. HANDLE hTxFilter
  1770. )
  1771. {
  1772. DWORD dwError = 0;
  1773. if (!hTxFilter) {
  1774. return (ERROR_INVALID_PARAMETER);
  1775. }
  1776. RpcTryExcept {
  1777. dwError = RpcCloseTransportFilterHandle(
  1778. &hTxFilter
  1779. );
  1780. BAIL_ON_WIN32_ERROR(dwError);
  1781. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  1782. dwError = TranslateExceptionCode(RpcExceptionCode());
  1783. BAIL_ON_WIN32_ERROR(dwError);
  1784. } RpcEndExcept
  1785. error:
  1786. if (dwError) {
  1787. dwError = SPDDestroyClientContextHandle(
  1788. dwError,
  1789. hTxFilter
  1790. );
  1791. }
  1792. return (dwError);
  1793. }
  1794. DWORD
  1795. OpenTunnelFilterHandle(
  1796. LPWSTR pServerName,
  1797. PTUNNEL_FILTER pTunnelFilter,
  1798. PHANDLE phTnFilter
  1799. )
  1800. {
  1801. DWORD dwError = 0;
  1802. TUNNEL_FILTER_CONTAINER FilterContainer;
  1803. PTUNNEL_FILTER_CONTAINER pFilterContainer = &FilterContainer;
  1804. if (!phTnFilter) {
  1805. return (ERROR_INVALID_PARAMETER);
  1806. }
  1807. dwError = ValidateTunnelFilter(
  1808. pTunnelFilter
  1809. );
  1810. BAIL_ON_WIN32_ERROR(dwError);
  1811. pFilterContainer->dwNumFilters = 1;
  1812. pFilterContainer->pTunnelFilters = pTunnelFilter;
  1813. RpcTryExcept {
  1814. dwError = RpcOpenTunnelFilterHandle(
  1815. pServerName,
  1816. pFilterContainer,
  1817. phTnFilter
  1818. );
  1819. BAIL_ON_WIN32_ERROR(dwError);
  1820. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  1821. dwError = TranslateExceptionCode(RpcExceptionCode());
  1822. BAIL_ON_WIN32_ERROR(dwError);
  1823. } RpcEndExcept
  1824. error:
  1825. return (dwError);
  1826. }
  1827. DWORD
  1828. CloseTunnelFilterHandle(
  1829. HANDLE hTnFilter
  1830. )
  1831. {
  1832. DWORD dwError = 0;
  1833. if (!hTnFilter) {
  1834. return (ERROR_INVALID_PARAMETER);
  1835. }
  1836. RpcTryExcept {
  1837. dwError = RpcCloseTunnelFilterHandle(
  1838. &hTnFilter
  1839. );
  1840. BAIL_ON_WIN32_ERROR(dwError);
  1841. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  1842. dwError = TranslateExceptionCode(RpcExceptionCode());
  1843. BAIL_ON_WIN32_ERROR(dwError);
  1844. } RpcEndExcept
  1845. error:
  1846. if (dwError) {
  1847. dwError = SPDDestroyClientContextHandle(
  1848. dwError,
  1849. hTnFilter
  1850. );
  1851. }
  1852. return (dwError);
  1853. }
  1854. DWORD
  1855. EnumIPSecInterfaces(
  1856. LPWSTR pServerName,
  1857. PIPSEC_INTERFACE_INFO pIpsecIfTemplate,
  1858. PIPSEC_INTERFACE_INFO * ppIpsecInterfaces,
  1859. DWORD dwPreferredNumEntries,
  1860. LPDWORD pdwNumInterfaces,
  1861. LPDWORD pdwNumTotalInterfaces,
  1862. LPDWORD pdwResumeHandle,
  1863. DWORD dwFlags
  1864. )
  1865. {
  1866. DWORD dwError = 0;
  1867. IPSEC_INTERFACE_CONTAINER IpsecIfTempContainer;
  1868. PIPSEC_INTERFACE_CONTAINER pIpsecIfTempContainer = &IpsecIfTempContainer;
  1869. IPSEC_INTERFACE_CONTAINER IpsecIfContainer;
  1870. PIPSEC_INTERFACE_CONTAINER pIpsecIfContainer = &IpsecIfContainer;
  1871. memset(pIpsecIfContainer, 0, sizeof(IPSEC_INTERFACE_CONTAINER));
  1872. if (!ppIpsecInterfaces || !pdwNumInterfaces ||
  1873. !pdwNumTotalInterfaces || !pdwResumeHandle) {
  1874. return (ERROR_INVALID_PARAMETER);
  1875. }
  1876. if (pIpsecIfTemplate) {
  1877. pIpsecIfTempContainer->dwNumInterfaces = 1;
  1878. pIpsecIfTempContainer->pIpsecInterfaces = pIpsecIfTemplate;
  1879. }
  1880. else {
  1881. pIpsecIfTempContainer->dwNumInterfaces = 0;
  1882. pIpsecIfTempContainer->pIpsecInterfaces = NULL;
  1883. }
  1884. RpcTryExcept {
  1885. dwError = RpcEnumIpsecInterfaces(
  1886. pServerName,
  1887. pIpsecIfTempContainer,
  1888. &pIpsecIfContainer,
  1889. dwPreferredNumEntries,
  1890. pdwNumTotalInterfaces,
  1891. pdwResumeHandle,
  1892. dwFlags
  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. *ppIpsecInterfaces = pIpsecIfContainer->pIpsecInterfaces;
  1900. *pdwNumInterfaces = pIpsecIfContainer->dwNumInterfaces;
  1901. return (dwError);
  1902. error:
  1903. *ppIpsecInterfaces = NULL;
  1904. *pdwNumInterfaces = 0;
  1905. *pdwNumTotalInterfaces = 0;
  1906. return (dwError);
  1907. }
  1908. DWORD IPSecAddSAs(
  1909. LPWSTR pServerName,
  1910. PIPSEC_QM_OFFER pQMOffer,
  1911. PIPSEC_QM_FILTER pQMFilter,
  1912. HANDLE *hLarvalContext,
  1913. DWORD dwInboundKeyMatLen,
  1914. BYTE *pInboundKeyMat,
  1915. DWORD dwOutboundKeyMatLen,
  1916. BYTE *pOutboundKeyMat,
  1917. BYTE *pContextInfo,
  1918. DWORD dwFlags)
  1919. {
  1920. DWORD dwError = 0;
  1921. QM_FILTER_CONTAINER FilterContainer;
  1922. PQM_FILTER_CONTAINER pFilterContainer = &FilterContainer;
  1923. ULONG uhClientEvent = 0;
  1924. IPSEC_QM_POLICY_CONTAINER QMPolicyContainer;
  1925. PIPSEC_QM_POLICY_CONTAINER pQMPolicyContainer = &QMPolicyContainer;
  1926. IPSEC_QM_POLICY QMPolicy;
  1927. DWORD uhLarvalContext=0;
  1928. memset(&QMPolicy,0,sizeof(IPSEC_QM_POLICY));
  1929. if (hLarvalContext == NULL) {
  1930. dwError=ERROR_INVALID_PARAMETER;
  1931. }
  1932. BAIL_ON_WIN32_ERROR(dwError);
  1933. uhLarvalContext=HandleToUlong(*hLarvalContext);
  1934. pFilterContainer->dwNumFilters = 1;
  1935. pFilterContainer->pQMFilters = pQMFilter;
  1936. pQMPolicyContainer->dwNumPolicies=1;
  1937. QMPolicy.pOffers=pQMOffer;
  1938. QMPolicy.dwOfferCount=1;
  1939. pQMPolicyContainer->pPolicies=&QMPolicy;
  1940. dwError=ValidateIPSecAddSA(
  1941. pServerName,
  1942. pQMPolicyContainer,
  1943. pFilterContainer,
  1944. &uhLarvalContext,
  1945. dwInboundKeyMatLen,
  1946. pInboundKeyMat,
  1947. dwOutboundKeyMatLen,
  1948. pOutboundKeyMat,
  1949. pContextInfo,
  1950. dwFlags);
  1951. BAIL_ON_WIN32_ERROR(dwError);
  1952. dwError = RpcIPSecAddSA(
  1953. pServerName,
  1954. pQMPolicyContainer,
  1955. pFilterContainer,
  1956. &uhLarvalContext,
  1957. dwInboundKeyMatLen,
  1958. pInboundKeyMat,
  1959. dwOutboundKeyMatLen,
  1960. pOutboundKeyMat,
  1961. pContextInfo,
  1962. dwFlags);
  1963. BAIL_ON_WIN32_ERROR(dwError);
  1964. *hLarvalContext=LongToHandle(uhLarvalContext);
  1965. error:
  1966. return dwError;
  1967. }