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.

2757 lines
66 KiB

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