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.

585 lines
13 KiB

  1. /*++
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. ikerpc.c
  5. Abstract:
  6. This module contains all of the code to service the
  7. RPC calls made to the SPD that are serviced in IKE.
  8. Author:
  9. abhisheV 30-September-1999
  10. Environment
  11. User Level: Win32
  12. Revision History:
  13. --*/
  14. #include "precomp.h"
  15. VOID
  16. IKENEGOTIATION_HANDLE_rundown(
  17. IKENEGOTIATION_HANDLE hIKENegotiation
  18. )
  19. {
  20. if (!gbIsIKEUp) {
  21. return;
  22. }
  23. if (hIKENegotiation) {
  24. (VOID) IKECloseIKENegotiationHandle(
  25. hIKENegotiation
  26. );
  27. }
  28. }
  29. VOID
  30. IKENOTIFY_HANDLE_rundown(
  31. IKENOTIFY_HANDLE hIKENotifyHandle
  32. )
  33. {
  34. if (!gbIsIKEUp) {
  35. return;
  36. }
  37. if (hIKENotifyHandle) {
  38. (VOID) IKECloseIKENotifyHandle(
  39. hIKENotifyHandle
  40. );
  41. }
  42. }
  43. DWORD
  44. RpcInitiateIKENegotiation(
  45. STRING_HANDLE pServerName,
  46. PQM_FILTER_CONTAINER pQMFilterContainer,
  47. DWORD dwClientProcessId,
  48. ULONG uhClientEvent,
  49. DWORD dwFlags,
  50. IKENEGOTIATION_HANDLE * phIKENegotiation
  51. )
  52. {
  53. DWORD dwError = 0;
  54. HANDLE hClientEvent = NULL;
  55. PIPSEC_QM_FILTER pQMFilter = NULL;
  56. BOOL bImpersonating = FALSE;
  57. dwError = SPDImpersonateClient(
  58. &bImpersonating
  59. );
  60. BAIL_ON_WIN32_ERROR(dwError);
  61. ENTER_SPD_SECTION();
  62. dwError = ValidateSecurity(
  63. SPD_OBJECT_SERVER,
  64. SERVER_ACCESS_ADMINISTER,
  65. NULL,
  66. NULL
  67. );
  68. LEAVE_SPD_SECTION();
  69. BAIL_ON_WIN32_ERROR(dwError);
  70. dwError = ValidateInitiateIKENegotiation(pServerName,
  71. pQMFilterContainer,
  72. dwClientProcessId,
  73. uhClientEvent,
  74. dwFlags,
  75. phIKENegotiation);
  76. BAIL_ON_WIN32_ERROR(dwError);
  77. hClientEvent = LongToHandle(uhClientEvent);
  78. pQMFilter = pQMFilterContainer->pQMFilters;
  79. dwError = IKEInitiateIKENegotiation(
  80. pQMFilter,
  81. dwClientProcessId,
  82. hClientEvent,
  83. dwFlags,
  84. phIKENegotiation
  85. );
  86. BAIL_ON_WIN32_ERROR(dwError);
  87. error:
  88. SPDRevertToSelf(bImpersonating);
  89. return (dwError);
  90. }
  91. DWORD
  92. RpcQueryIKENegotiationStatus(
  93. IKENEGOTIATION_HANDLE hIKENegotiation,
  94. SA_NEGOTIATION_STATUS_INFO *NegotiationStatus
  95. )
  96. {
  97. DWORD dwError = 0;
  98. DWORD dwFlags=0;
  99. BOOL bImpersonating = FALSE;
  100. dwError = SPDImpersonateClient(
  101. &bImpersonating
  102. );
  103. BAIL_ON_WIN32_ERROR(dwError);
  104. ENTER_SPD_SECTION();
  105. dwError = ValidateSecurity(
  106. SPD_OBJECT_SERVER,
  107. SERVER_ACCESS_ADMINISTER,
  108. NULL,
  109. NULL
  110. );
  111. LEAVE_SPD_SECTION();
  112. BAIL_ON_WIN32_ERROR(dwError);
  113. dwError=ValidateQueryIKENegotiationStatus(hIKENegotiation,
  114. NegotiationStatus);
  115. BAIL_ON_WIN32_ERROR(dwError);
  116. dwError = IKEQueryIKENegotiationStatus(
  117. hIKENegotiation,
  118. NegotiationStatus,
  119. dwFlags
  120. );
  121. BAIL_ON_WIN32_ERROR(dwError);
  122. error:
  123. SPDRevertToSelf(bImpersonating);
  124. return (dwError);
  125. }
  126. DWORD
  127. RpcCloseIKENegotiationHandle(
  128. IKENEGOTIATION_HANDLE * phIKENegotiation
  129. )
  130. {
  131. DWORD dwError = 0;
  132. BOOL bImpersonating = FALSE;
  133. dwError = SPDImpersonateClient(
  134. &bImpersonating
  135. );
  136. BAIL_ON_WIN32_ERROR(dwError);
  137. ENTER_SPD_SECTION();
  138. dwError = ValidateSecurity(
  139. SPD_OBJECT_SERVER,
  140. SERVER_ACCESS_ADMINISTER,
  141. NULL,
  142. NULL
  143. );
  144. LEAVE_SPD_SECTION();
  145. BAIL_ON_WIN32_ERROR(dwError);
  146. dwError=ValidateCloseIKENegotiationHandle(phIKENegotiation);
  147. BAIL_ON_WIN32_ERROR(dwError);
  148. dwError = IKECloseIKENegotiationHandle(
  149. *phIKENegotiation
  150. );
  151. BAIL_ON_WIN32_ERROR(dwError);
  152. *phIKENegotiation = NULL;
  153. error:
  154. SPDRevertToSelf(bImpersonating);
  155. return (dwError);
  156. }
  157. DWORD
  158. RpcEnumMMSAs(
  159. STRING_HANDLE pServerName,
  160. PMM_SA_CONTAINER pMMTemplate,
  161. PMM_SA_CONTAINER *ppMMSAContainer,
  162. LPDWORD pdwNumEntries,
  163. LPDWORD pdwTotalMMsAvailable,
  164. LPDWORD pdwEnumHandle,
  165. DWORD dwFlags
  166. )
  167. {
  168. DWORD dwError = 0;
  169. PIPSEC_MM_SA pMMSAs=NULL;
  170. BOOL bImpersonating = FALSE;
  171. dwError = SPDImpersonateClient(
  172. &bImpersonating
  173. );
  174. BAIL_ON_WIN32_ERROR(dwError);
  175. ENTER_SPD_SECTION();
  176. dwError = ValidateSecurity(
  177. SPD_OBJECT_SERVER,
  178. SERVER_ACCESS_ADMINISTER,
  179. NULL,
  180. NULL
  181. );
  182. LEAVE_SPD_SECTION();
  183. BAIL_ON_WIN32_ERROR(dwError);
  184. dwError=ValidateEnumMMSAs(pServerName,
  185. pMMTemplate,
  186. ppMMSAContainer,
  187. pdwNumEntries,
  188. pdwTotalMMsAvailable,
  189. pdwEnumHandle,
  190. dwFlags);
  191. BAIL_ON_WIN32_ERROR(dwError);
  192. dwError= IKEEnumMMs(
  193. pMMTemplate->pMMSAs,
  194. &pMMSAs,
  195. pdwNumEntries,
  196. pdwTotalMMsAvailable,
  197. pdwEnumHandle,
  198. dwFlags
  199. );
  200. BAIL_ON_WIN32_ERROR(dwError);
  201. (*ppMMSAContainer)->pMMSAs=pMMSAs;
  202. (*ppMMSAContainer)->dwNumMMSAs=*pdwNumEntries;
  203. error:
  204. if (dwError != ERROR_SUCCESS) {
  205. if (ppMMSAContainer && *ppMMSAContainer) {
  206. (*ppMMSAContainer)->pMMSAs=NULL;
  207. (*ppMMSAContainer)->dwNumMMSAs=0;
  208. }
  209. }
  210. SPDRevertToSelf(bImpersonating);
  211. return dwError;
  212. }
  213. DWORD
  214. RpcDeleteMMSAs(
  215. STRING_HANDLE pServerName,
  216. PMM_SA_CONTAINER pMMTemplate,
  217. DWORD dwFlags
  218. )
  219. {
  220. DWORD dwError = 0;
  221. BOOL bImpersonating = FALSE;
  222. dwError = SPDImpersonateClient(
  223. &bImpersonating
  224. );
  225. BAIL_ON_WIN32_ERROR(dwError);
  226. ENTER_SPD_SECTION();
  227. dwError = ValidateSecurity(
  228. SPD_OBJECT_SERVER,
  229. SERVER_ACCESS_ADMINISTER,
  230. NULL,
  231. NULL
  232. );
  233. LEAVE_SPD_SECTION();
  234. BAIL_ON_WIN32_ERROR(dwError);
  235. dwError=ValidateDeleteMMSAs(pServerName,
  236. pMMTemplate,
  237. dwFlags);
  238. BAIL_ON_WIN32_ERROR(dwError);
  239. dwError= IKEDeleteAssociation(
  240. pMMTemplate->pMMSAs,
  241. dwFlags);
  242. BAIL_ON_WIN32_ERROR(dwError);
  243. error:
  244. SPDRevertToSelf(bImpersonating);
  245. return dwError;
  246. }
  247. DWORD
  248. RpcQueryIKEStatistics(
  249. STRING_HANDLE pServerName,
  250. IKE_STATISTICS *pIKEStatistics
  251. )
  252. {
  253. DWORD dwError = 0;
  254. BOOL bImpersonating = FALSE;
  255. dwError = SPDImpersonateClient(
  256. &bImpersonating
  257. );
  258. BAIL_ON_WIN32_ERROR(dwError);
  259. ENTER_SPD_SECTION();
  260. dwError = ValidateSecurity(
  261. SPD_OBJECT_SERVER,
  262. SERVER_ACCESS_ADMINISTER,
  263. NULL,
  264. NULL
  265. );
  266. LEAVE_SPD_SECTION();
  267. BAIL_ON_WIN32_ERROR(dwError);
  268. dwError=ValidateQueryIKEStatistics(pServerName,
  269. pIKEStatistics);
  270. BAIL_ON_WIN32_ERROR(dwError);
  271. dwError = IKEQueryStatistics(pIKEStatistics);
  272. BAIL_ON_WIN32_ERROR(dwError);
  273. error:
  274. SPDRevertToSelf(bImpersonating);
  275. return dwError;
  276. }
  277. DWORD
  278. RpcRegisterIKENotifyClient(
  279. STRING_HANDLE pServerName,
  280. DWORD dwClientProcessId,
  281. ULONG uhClientEvent,
  282. PQM_SA_CONTAINER pQMSATemplateContainer,
  283. IKENOTIFY_HANDLE *phNotifyHandle,
  284. DWORD dwFlags
  285. )
  286. {
  287. DWORD dwError = 0;
  288. HANDLE hClientEvent = LongToHandle(uhClientEvent);
  289. BOOL bImpersonating = FALSE;
  290. dwError = SPDImpersonateClient(
  291. &bImpersonating
  292. );
  293. BAIL_ON_WIN32_ERROR(dwError);
  294. ENTER_SPD_SECTION();
  295. dwError = ValidateSecurity(
  296. SPD_OBJECT_SERVER,
  297. SERVER_ACCESS_ADMINISTER,
  298. NULL,
  299. NULL
  300. );
  301. LEAVE_SPD_SECTION();
  302. BAIL_ON_WIN32_ERROR(dwError);
  303. dwError=ValidateRegisterIKENotifyClient(pServerName,
  304. dwClientProcessId,
  305. uhClientEvent,
  306. pQMSATemplateContainer,
  307. phNotifyHandle,
  308. dwFlags);
  309. BAIL_ON_WIN32_ERROR(dwError);
  310. dwError= IKERegisterNotifyClient(
  311. dwClientProcessId,
  312. hClientEvent,
  313. *pQMSATemplateContainer->pQMSAs,
  314. phNotifyHandle);
  315. BAIL_ON_WIN32_ERROR(dwError);
  316. error:
  317. SPDRevertToSelf(bImpersonating);
  318. return dwError;
  319. }
  320. DWORD RpcQueryNotifyData(
  321. IKENOTIFY_HANDLE uhNotifyHandle,
  322. PDWORD pdwNumEntries,
  323. PQM_SA_CONTAINER *ppQMSAContainer,
  324. DWORD dwFlags
  325. )
  326. {
  327. DWORD dwError = 0;
  328. PIPSEC_QM_SA pQMSAs=NULL;
  329. BOOL bImpersonating = FALSE;
  330. dwError = SPDImpersonateClient(
  331. &bImpersonating
  332. );
  333. BAIL_ON_WIN32_ERROR(dwError);
  334. ENTER_SPD_SECTION();
  335. dwError = ValidateSecurity(
  336. SPD_OBJECT_SERVER,
  337. SERVER_ACCESS_ADMINISTER,
  338. NULL,
  339. NULL
  340. );
  341. LEAVE_SPD_SECTION();
  342. BAIL_ON_WIN32_ERROR(dwError);
  343. dwError=ValidateQueryNotifyData(uhNotifyHandle,
  344. pdwNumEntries,
  345. ppQMSAContainer,
  346. dwFlags);
  347. BAIL_ON_WIN32_ERROR(dwError);
  348. dwError= IKEQuerySpiChange(
  349. uhNotifyHandle,
  350. pdwNumEntries,
  351. &pQMSAs);
  352. if ((dwError == ERROR_SUCCESS) ||
  353. (dwError == ERROR_MORE_DATA)) {
  354. (*ppQMSAContainer)->pQMSAs=pQMSAs;
  355. (*ppQMSAContainer)->dwNumQMSAs=*pdwNumEntries;
  356. SPDRevertToSelf(bImpersonating);
  357. return dwError;
  358. }
  359. error:
  360. if (ppQMSAContainer && *ppQMSAContainer) {
  361. (*ppQMSAContainer)->pQMSAs=NULL;
  362. (*ppQMSAContainer)->dwNumQMSAs=0;
  363. }
  364. if (pdwNumEntries) {
  365. *pdwNumEntries=0;
  366. }
  367. SPDRevertToSelf(bImpersonating);
  368. return dwError;
  369. }
  370. DWORD RpcCloseNotifyHandle(
  371. IKENOTIFY_HANDLE *phHandle
  372. )
  373. {
  374. DWORD dwError =0;
  375. BOOL bImpersonating = FALSE;
  376. dwError = SPDImpersonateClient(
  377. &bImpersonating
  378. );
  379. BAIL_ON_WIN32_ERROR(dwError);
  380. ENTER_SPD_SECTION();
  381. dwError = ValidateSecurity(
  382. SPD_OBJECT_SERVER,
  383. SERVER_ACCESS_ADMINISTER,
  384. NULL,
  385. NULL
  386. );
  387. LEAVE_SPD_SECTION();
  388. BAIL_ON_WIN32_ERROR(dwError);
  389. dwError=ValidateCloseNotifyHandle(phHandle);
  390. BAIL_ON_WIN32_ERROR(dwError);
  391. dwError = IKECloseIKENotifyHandle(*phHandle);
  392. BAIL_ON_WIN32_ERROR(dwError);
  393. *phHandle = NULL;
  394. error:
  395. SPDRevertToSelf(bImpersonating);
  396. return dwError;
  397. }
  398. DWORD RpcIPSecAddSA(
  399. STRING_HANDLE pServerName,
  400. PIPSEC_QM_POLICY_CONTAINER pQMPolicyContainer,
  401. PQM_FILTER_CONTAINER pQMFilterContainer,
  402. DWORD *uhLarvalContext,
  403. DWORD dwInboundKeyMatLen,
  404. BYTE *pInboundKeyMat,
  405. DWORD dwOutboundKeyMatLen,
  406. BYTE *pOutboundKeyMat,
  407. BYTE *pContextInfo,
  408. DWORD dwFlags)
  409. {
  410. DWORD dwError = 0;
  411. HANDLE hLarvalContext = NULL;
  412. PIPSEC_QM_FILTER pQMFilter = NULL;
  413. PIPSEC_QM_OFFER pQMOffer = NULL;
  414. BOOL bImpersonating = FALSE;
  415. dwError = SPDImpersonateClient(
  416. &bImpersonating
  417. );
  418. BAIL_ON_WIN32_ERROR(dwError);
  419. ENTER_SPD_SECTION();
  420. dwError = ValidateSecurity(
  421. SPD_OBJECT_SERVER,
  422. SERVER_ACCESS_ADMINISTER,
  423. NULL,
  424. NULL
  425. );
  426. LEAVE_SPD_SECTION();
  427. BAIL_ON_WIN32_ERROR(dwError);
  428. dwError=ValidateIPSecAddSA(pServerName,
  429. pQMPolicyContainer,
  430. pQMFilterContainer,
  431. uhLarvalContext,
  432. dwInboundKeyMatLen,
  433. pInboundKeyMat,
  434. dwOutboundKeyMatLen,
  435. pOutboundKeyMat,
  436. pContextInfo,
  437. dwFlags);
  438. BAIL_ON_WIN32_ERROR(dwError);
  439. hLarvalContext = LongToHandle(*uhLarvalContext);
  440. pQMFilter = pQMFilterContainer->pQMFilters;
  441. pQMOffer = pQMPolicyContainer->pPolicies->pOffers;
  442. dwError=IKEAddSAs(
  443. pQMOffer,
  444. pQMFilter,
  445. &hLarvalContext,
  446. dwInboundKeyMatLen,
  447. pInboundKeyMat,
  448. dwOutboundKeyMatLen,
  449. pOutboundKeyMat,
  450. pContextInfo,
  451. dwFlags);
  452. BAIL_ON_WIN32_ERROR(dwError);
  453. *uhLarvalContext = HandleToLong(hLarvalContext);
  454. error:
  455. SPDRevertToSelf(bImpersonating);
  456. return (dwError);
  457. }