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.

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