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.

480 lines
9.8 KiB

  1. /*++
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. bind.c
  5. Abstract:
  6. Contains the RPC bind and un-bind routines.
  7. Author:
  8. abhisheV 21-September-1999
  9. Environment:
  10. User Level: Win32
  11. Revision History:
  12. --*/
  13. #include "precomp.h"
  14. handle_t
  15. TRANSPORTFILTER_HANDLE_bind(
  16. TRANSPORTFILTER_HANDLE hFilter,
  17. STRING_HANDLE lpStr
  18. )
  19. {
  20. RPC_STATUS RpcStatus = 0;
  21. LPWSTR pszStrBinding = NULL;
  22. handle_t hBinding = NULL;
  23. if (!lpStr || !*lpStr) {
  24. RpcStatus = RpcStringBindingComposeW(
  25. 0,
  26. L"ncalrpc",
  27. 0,
  28. L"ipsec",
  29. gpszStrBindingOptions,
  30. &pszStrBinding
  31. );
  32. }
  33. else {
  34. RpcStatus = RpcStringBindingComposeW(
  35. 0,
  36. L"ncacn_np",
  37. lpStr,
  38. L"\\pipe\\ipsec",
  39. gpszStrBindingOptions,
  40. &pszStrBinding
  41. );
  42. }
  43. if (RpcStatus != RPC_S_OK) {
  44. return NULL;
  45. }
  46. RpcStatus = RpcBindingFromStringBindingW(
  47. pszStrBinding,
  48. &hBinding
  49. );
  50. RpcStringFreeW(&pszStrBinding);
  51. if (RpcStatus != RPC_S_OK) {
  52. return NULL;
  53. }
  54. return (hBinding);
  55. }
  56. VOID
  57. TRANSPORTFILTER_HANDLE_unbind(
  58. TRANSPORTFILTER_HANDLE hFilter,
  59. handle_t hBinding
  60. )
  61. {
  62. RPC_STATUS RpcStatus = 0;
  63. RpcStatus = RpcBindingFree(&hBinding);
  64. ASSERT(RpcStatus == RPC_S_OK);
  65. return;
  66. }
  67. handle_t
  68. STRING_HANDLE_bind(
  69. STRING_HANDLE lpStr
  70. )
  71. {
  72. RPC_STATUS RpcStatus = 0;
  73. LPWSTR pszStringBinding = NULL;
  74. handle_t hBinding = NULL;
  75. LPWSTR pszServerPrincipalName = NULL;
  76. if (!lpStr || !*lpStr) {
  77. RpcStatus = RpcStringBindingComposeW(
  78. 0,
  79. L"ncalrpc",
  80. 0,
  81. L"ipsec",
  82. gpszStrBindingOptions,
  83. &pszStringBinding
  84. );
  85. }
  86. else {
  87. RpcStatus = RpcStringBindingComposeW(
  88. 0,
  89. L"ncacn_np",
  90. lpStr,
  91. L"\\pipe\\ipsec",
  92. gpszStrBindingOptions,
  93. &pszStringBinding
  94. );
  95. }
  96. if (RpcStatus != RPC_S_OK) {
  97. return NULL;
  98. }
  99. RpcStatus = RpcBindingFromStringBindingW(
  100. pszStringBinding,
  101. &hBinding
  102. );
  103. RpcStringFreeW(&pszStringBinding);
  104. if (RpcStatus != RPC_S_OK) {
  105. return NULL;
  106. }
  107. RpcStatus = RpcBindingSetOption(
  108. hBinding,
  109. RPC_C_OPT_UNIQUE_BINDING,
  110. (ULONG_PTR) 1
  111. );
  112. if (RpcStatus != RPC_S_OK) {
  113. STRING_HANDLE_unbind(lpStr, hBinding);
  114. return NULL;
  115. }
  116. RpcStatus = RpcMgmtInqServerPrincName(
  117. hBinding,
  118. RPC_C_AUTHN_WINNT,
  119. &pszServerPrincipalName
  120. );
  121. if (RpcStatus != RPC_S_OK) {
  122. STRING_HANDLE_unbind(lpStr, hBinding);
  123. RpcRaiseException(RpcStatus);
  124. }
  125. if (!lpStr || !*lpStr) {
  126. RpcStatus = RpcBindingSetAuthInfoW(
  127. hBinding,
  128. pszServerPrincipalName,
  129. RPC_C_PROTECT_LEVEL_PKT_PRIVACY,
  130. RPC_C_AUTHN_WINNT,
  131. NULL,
  132. RPC_C_AUTHZ_NONE
  133. );
  134. }
  135. else {
  136. RpcStatus = RpcBindingSetAuthInfoW(
  137. hBinding,
  138. pszServerPrincipalName,
  139. RPC_C_PROTECT_LEVEL_PKT_PRIVACY,
  140. RPC_C_AUTHN_GSS_NEGOTIATE,
  141. NULL,
  142. RPC_C_AUTHZ_NONE
  143. );
  144. }
  145. if (pszServerPrincipalName) {
  146. RpcStringFree(&pszServerPrincipalName);
  147. }
  148. if (RpcStatus != RPC_S_OK) {
  149. STRING_HANDLE_unbind(lpStr, hBinding);
  150. return NULL;
  151. }
  152. ASSERT(RpcStatus == RPC_S_OK);
  153. return (hBinding);
  154. }
  155. VOID
  156. STRING_HANDLE_unbind(
  157. STRING_HANDLE lpStr,
  158. handle_t hBinding
  159. )
  160. {
  161. RPC_STATUS RpcStatus = 0;
  162. RpcStatus = RpcBindingFree(&hBinding);
  163. ASSERT(RpcStatus == RPC_S_OK);
  164. return;
  165. }
  166. handle_t
  167. MMFILTER_HANDLE_bind(
  168. MMFILTER_HANDLE hFilter,
  169. STRING_HANDLE lpStr
  170. )
  171. {
  172. RPC_STATUS RpcStatus = 0;
  173. LPWSTR pszStrBinding = NULL;
  174. handle_t hBinding = NULL;
  175. if (!lpStr || !*lpStr) {
  176. RpcStatus = RpcStringBindingComposeW(
  177. 0,
  178. L"ncalrpc",
  179. 0,
  180. L"ipsec",
  181. gpszStrBindingOptions,
  182. &pszStrBinding
  183. );
  184. }
  185. else {
  186. RpcStatus = RpcStringBindingComposeW(
  187. 0,
  188. L"ncacn_np",
  189. lpStr,
  190. L"\\pipe\\ipsec",
  191. gpszStrBindingOptions,
  192. &pszStrBinding
  193. );
  194. }
  195. if (RpcStatus != RPC_S_OK) {
  196. return NULL;
  197. }
  198. RpcStatus = RpcBindingFromStringBindingW(
  199. pszStrBinding,
  200. &hBinding
  201. );
  202. RpcStringFreeW(&pszStrBinding);
  203. if (RpcStatus != RPC_S_OK) {
  204. return NULL;
  205. }
  206. return (hBinding);
  207. }
  208. VOID
  209. MMFILTER_HANDLE_unbind(
  210. MMFILTER_HANDLE hFilter,
  211. handle_t hBinding
  212. )
  213. {
  214. RPC_STATUS RpcStatus = 0;
  215. RpcStatus = RpcBindingFree(&hBinding);
  216. ASSERT(RpcStatus == RPC_S_OK);
  217. return;
  218. }
  219. handle_t
  220. IKENEGOTIATION_HANDLE_bind(
  221. IKENEGOTIATION_HANDLE hIKENegotiation,
  222. STRING_HANDLE lpStr
  223. )
  224. {
  225. RPC_STATUS RpcStatus = 0;
  226. LPWSTR pszStrBinding = NULL;
  227. handle_t hBinding = NULL;
  228. if (!lpStr || !*lpStr) {
  229. RpcStatus = RpcStringBindingComposeW(
  230. 0,
  231. L"ncalrpc",
  232. 0,
  233. L"ipsec",
  234. gpszStrBindingOptions,
  235. &pszStrBinding
  236. );
  237. }
  238. else {
  239. RpcStatus = RpcStringBindingComposeW(
  240. 0,
  241. L"ncacn_np",
  242. lpStr,
  243. L"\\pipe\\ipsec",
  244. gpszStrBindingOptions,
  245. &pszStrBinding
  246. );
  247. }
  248. if (RpcStatus != RPC_S_OK) {
  249. return NULL;
  250. }
  251. RpcStatus = RpcBindingFromStringBindingW(
  252. pszStrBinding,
  253. &hBinding
  254. );
  255. RpcStringFreeW(&pszStrBinding);
  256. if (RpcStatus != RPC_S_OK) {
  257. return NULL;
  258. }
  259. return (hBinding);
  260. }
  261. VOID
  262. IKENEGOTIATION_HANDLE_unbind(
  263. IKENEGOTIATION_HANDLE hIKENegotiation,
  264. handle_t hBinding
  265. )
  266. {
  267. RPC_STATUS RpcStatus = 0;
  268. RpcStatus = RpcBindingFree(&hBinding);
  269. ASSERT(RpcStatus == RPC_S_OK);
  270. return;
  271. }
  272. handle_t
  273. IKENOTIFY_HANDLE_bind(
  274. IKENOTIFY_HANDLE hIKENegotiation,
  275. STRING_HANDLE lpStr
  276. )
  277. {
  278. RPC_STATUS RpcStatus = 0;
  279. LPWSTR pszStrBinding = NULL;
  280. handle_t hBinding = NULL;
  281. if (!lpStr || !*lpStr) {
  282. RpcStatus = RpcStringBindingComposeW(
  283. 0,
  284. L"ncalrpc",
  285. 0,
  286. L"ipsec",
  287. gpszStrBindingOptions,
  288. &pszStrBinding
  289. );
  290. }
  291. else {
  292. RpcStatus = RpcStringBindingComposeW(
  293. 0,
  294. L"ncacn_np",
  295. lpStr,
  296. L"\\pipe\\ipsec",
  297. gpszStrBindingOptions,
  298. &pszStrBinding
  299. );
  300. }
  301. if (RpcStatus != RPC_S_OK) {
  302. return NULL;
  303. }
  304. RpcStatus = RpcBindingFromStringBindingW(
  305. pszStrBinding,
  306. &hBinding
  307. );
  308. RpcStringFreeW(&pszStrBinding);
  309. if (RpcStatus != RPC_S_OK) {
  310. return NULL;
  311. }
  312. return (hBinding);
  313. }
  314. VOID
  315. IKENOTIFY_HANDLE_unbind(
  316. IKENOTIFY_HANDLE hIKENegotiation,
  317. handle_t hBinding
  318. )
  319. {
  320. RPC_STATUS RpcStatus = 0;
  321. RpcStatus = RpcBindingFree(&hBinding);
  322. ASSERT(RpcStatus == RPC_S_OK);
  323. return;
  324. }
  325. handle_t
  326. TUNNELFILTER_HANDLE_bind(
  327. TUNNELFILTER_HANDLE hFilter,
  328. STRING_HANDLE lpStr
  329. )
  330. {
  331. RPC_STATUS RpcStatus = 0;
  332. LPWSTR pszStrBinding = NULL;
  333. handle_t hBinding = NULL;
  334. if (!lpStr || !*lpStr) {
  335. RpcStatus = RpcStringBindingComposeW(
  336. 0,
  337. L"ncalrpc",
  338. 0,
  339. L"ipsec",
  340. gpszStrBindingOptions,
  341. &pszStrBinding
  342. );
  343. }
  344. else {
  345. RpcStatus = RpcStringBindingComposeW(
  346. 0,
  347. L"ncacn_np",
  348. lpStr,
  349. L"\\pipe\\ipsec",
  350. gpszStrBindingOptions,
  351. &pszStrBinding
  352. );
  353. }
  354. if (RpcStatus != RPC_S_OK) {
  355. return NULL;
  356. }
  357. RpcStatus = RpcBindingFromStringBindingW(
  358. pszStrBinding,
  359. &hBinding
  360. );
  361. RpcStringFreeW(&pszStrBinding);
  362. if (RpcStatus != RPC_S_OK) {
  363. return NULL;
  364. }
  365. return (hBinding);
  366. }
  367. VOID
  368. TUNNELFILTER_HANDLE_unbind(
  369. TUNNELFILTER_HANDLE hFilter,
  370. handle_t hBinding
  371. )
  372. {
  373. RPC_STATUS RpcStatus = 0;
  374. RpcStatus = RpcBindingFree(&hBinding);
  375. ASSERT(RpcStatus == RPC_S_OK);
  376. return;
  377. }