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.

488 lines
11 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. NULL, // Null for dynamic endpoint
  82. gpszStrBindingOptions,
  83. &pszStringBinding
  84. );
  85. }
  86. else {
  87. RpcStatus = RpcStringBindingComposeW(
  88. 0,
  89. L"ncacn_np",
  90. lpStr,
  91. NULL, // Null for dynamic endpoint
  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 = RpcEpResolveBinding(
  108. hBinding,
  109. winipsec_ClientIfHandle
  110. );
  111. if (RpcStatus != RPC_S_OK) {
  112. return NULL;
  113. }
  114. RpcStatus = RpcBindingSetOption(
  115. hBinding,
  116. RPC_C_OPT_UNIQUE_BINDING,
  117. (ULONG_PTR) 1
  118. );
  119. if (RpcStatus != RPC_S_OK) {
  120. STRING_HANDLE_unbind(lpStr, hBinding);
  121. return NULL;
  122. }
  123. RpcStatus = RpcMgmtInqServerPrincName(
  124. hBinding,
  125. RPC_C_AUTHN_GSS_NEGOTIATE,
  126. &pszServerPrincipalName
  127. );
  128. if (RpcStatus != RPC_S_OK) {
  129. STRING_HANDLE_unbind(lpStr, hBinding);
  130. RpcRaiseException(RpcStatus);
  131. }
  132. if (!lpStr || !*lpStr) {
  133. RpcStatus = RpcBindingSetAuthInfoW(
  134. hBinding,
  135. pszServerPrincipalName,
  136. RPC_C_PROTECT_LEVEL_PKT_PRIVACY,
  137. RPC_C_AUTHN_WINNT,
  138. NULL,
  139. RPC_C_AUTHZ_NONE
  140. );
  141. }
  142. else {
  143. RpcStatus = RpcBindingSetAuthInfoW(
  144. hBinding,
  145. pszServerPrincipalName,
  146. RPC_C_PROTECT_LEVEL_PKT_PRIVACY,
  147. RPC_C_AUTHN_GSS_NEGOTIATE,
  148. NULL,
  149. RPC_C_AUTHZ_NONE
  150. );
  151. }
  152. if (pszServerPrincipalName) {
  153. RpcStringFree(&pszServerPrincipalName);
  154. }
  155. if (RpcStatus != RPC_S_OK) {
  156. STRING_HANDLE_unbind(lpStr, hBinding);
  157. return NULL;
  158. }
  159. ASSERT(RpcStatus == RPC_S_OK);
  160. return (hBinding);
  161. }
  162. VOID
  163. STRING_HANDLE_unbind(
  164. STRING_HANDLE lpStr,
  165. handle_t hBinding
  166. )
  167. {
  168. RPC_STATUS RpcStatus = 0;
  169. RpcStatus = RpcBindingFree(&hBinding);
  170. ASSERT(RpcStatus == RPC_S_OK);
  171. return;
  172. }
  173. handle_t
  174. MMFILTER_HANDLE_bind(
  175. MMFILTER_HANDLE hFilter,
  176. STRING_HANDLE lpStr
  177. )
  178. {
  179. RPC_STATUS RpcStatus = 0;
  180. LPWSTR pszStrBinding = NULL;
  181. handle_t hBinding = NULL;
  182. if (!lpStr || !*lpStr) {
  183. RpcStatus = RpcStringBindingComposeW(
  184. 0,
  185. L"ncalrpc",
  186. 0,
  187. L"ipsec",
  188. gpszStrBindingOptions,
  189. &pszStrBinding
  190. );
  191. }
  192. else {
  193. RpcStatus = RpcStringBindingComposeW(
  194. 0,
  195. L"ncacn_np",
  196. lpStr,
  197. L"\\pipe\\ipsec",
  198. gpszStrBindingOptions,
  199. &pszStrBinding
  200. );
  201. }
  202. if (RpcStatus != RPC_S_OK) {
  203. return NULL;
  204. }
  205. RpcStatus = RpcBindingFromStringBindingW(
  206. pszStrBinding,
  207. &hBinding
  208. );
  209. RpcStringFreeW(&pszStrBinding);
  210. if (RpcStatus != RPC_S_OK) {
  211. return NULL;
  212. }
  213. return (hBinding);
  214. }
  215. VOID
  216. MMFILTER_HANDLE_unbind(
  217. MMFILTER_HANDLE hFilter,
  218. handle_t hBinding
  219. )
  220. {
  221. RPC_STATUS RpcStatus = 0;
  222. RpcStatus = RpcBindingFree(&hBinding);
  223. ASSERT(RpcStatus == RPC_S_OK);
  224. return;
  225. }
  226. handle_t
  227. IKENEGOTIATION_HANDLE_bind(
  228. IKENEGOTIATION_HANDLE hIKENegotiation,
  229. STRING_HANDLE lpStr
  230. )
  231. {
  232. RPC_STATUS RpcStatus = 0;
  233. LPWSTR pszStrBinding = NULL;
  234. handle_t hBinding = NULL;
  235. if (!lpStr || !*lpStr) {
  236. RpcStatus = RpcStringBindingComposeW(
  237. 0,
  238. L"ncalrpc",
  239. 0,
  240. L"ipsec",
  241. gpszStrBindingOptions,
  242. &pszStrBinding
  243. );
  244. }
  245. else {
  246. RpcStatus = RpcStringBindingComposeW(
  247. 0,
  248. L"ncacn_np",
  249. lpStr,
  250. L"\\pipe\\ipsec",
  251. gpszStrBindingOptions,
  252. &pszStrBinding
  253. );
  254. }
  255. if (RpcStatus != RPC_S_OK) {
  256. return NULL;
  257. }
  258. RpcStatus = RpcBindingFromStringBindingW(
  259. pszStrBinding,
  260. &hBinding
  261. );
  262. RpcStringFreeW(&pszStrBinding);
  263. if (RpcStatus != RPC_S_OK) {
  264. return NULL;
  265. }
  266. return (hBinding);
  267. }
  268. VOID
  269. IKENEGOTIATION_HANDLE_unbind(
  270. IKENEGOTIATION_HANDLE hIKENegotiation,
  271. handle_t hBinding
  272. )
  273. {
  274. RPC_STATUS RpcStatus = 0;
  275. RpcStatus = RpcBindingFree(&hBinding);
  276. ASSERT(RpcStatus == RPC_S_OK);
  277. return;
  278. }
  279. handle_t
  280. IKENOTIFY_HANDLE_bind(
  281. IKENOTIFY_HANDLE hIKENegotiation,
  282. STRING_HANDLE lpStr
  283. )
  284. {
  285. RPC_STATUS RpcStatus = 0;
  286. LPWSTR pszStrBinding = NULL;
  287. handle_t hBinding = NULL;
  288. if (!lpStr || !*lpStr) {
  289. RpcStatus = RpcStringBindingComposeW(
  290. 0,
  291. L"ncalrpc",
  292. 0,
  293. L"ipsec",
  294. gpszStrBindingOptions,
  295. &pszStrBinding
  296. );
  297. }
  298. else {
  299. RpcStatus = RpcStringBindingComposeW(
  300. 0,
  301. L"ncacn_np",
  302. lpStr,
  303. L"\\pipe\\ipsec",
  304. gpszStrBindingOptions,
  305. &pszStrBinding
  306. );
  307. }
  308. if (RpcStatus != RPC_S_OK) {
  309. return NULL;
  310. }
  311. RpcStatus = RpcBindingFromStringBindingW(
  312. pszStrBinding,
  313. &hBinding
  314. );
  315. RpcStringFreeW(&pszStrBinding);
  316. if (RpcStatus != RPC_S_OK) {
  317. return NULL;
  318. }
  319. return (hBinding);
  320. }
  321. VOID
  322. IKENOTIFY_HANDLE_unbind(
  323. IKENOTIFY_HANDLE hIKENegotiation,
  324. handle_t hBinding
  325. )
  326. {
  327. RPC_STATUS RpcStatus = 0;
  328. RpcStatus = RpcBindingFree(&hBinding);
  329. ASSERT(RpcStatus == RPC_S_OK);
  330. return;
  331. }
  332. handle_t
  333. TUNNELFILTER_HANDLE_bind(
  334. TUNNELFILTER_HANDLE hFilter,
  335. STRING_HANDLE lpStr
  336. )
  337. {
  338. RPC_STATUS RpcStatus = 0;
  339. LPWSTR pszStrBinding = NULL;
  340. handle_t hBinding = NULL;
  341. if (!lpStr || !*lpStr) {
  342. RpcStatus = RpcStringBindingComposeW(
  343. 0,
  344. L"ncalrpc",
  345. 0,
  346. L"ipsec",
  347. gpszStrBindingOptions,
  348. &pszStrBinding
  349. );
  350. }
  351. else {
  352. RpcStatus = RpcStringBindingComposeW(
  353. 0,
  354. L"ncacn_np",
  355. lpStr,
  356. L"\\pipe\\ipsec",
  357. gpszStrBindingOptions,
  358. &pszStrBinding
  359. );
  360. }
  361. if (RpcStatus != RPC_S_OK) {
  362. return NULL;
  363. }
  364. RpcStatus = RpcBindingFromStringBindingW(
  365. pszStrBinding,
  366. &hBinding
  367. );
  368. RpcStringFreeW(&pszStrBinding);
  369. if (RpcStatus != RPC_S_OK) {
  370. return NULL;
  371. }
  372. return (hBinding);
  373. }
  374. VOID
  375. TUNNELFILTER_HANDLE_unbind(
  376. TUNNELFILTER_HANDLE hFilter,
  377. handle_t hBinding
  378. )
  379. {
  380. RPC_STATUS RpcStatus = 0;
  381. RpcStatus = RpcBindingFree(&hBinding);
  382. ASSERT(RpcStatus == RPC_S_OK);
  383. return;
  384. }