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.

601 lines
14 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1991 - 1999
  3. Module Name:
  4. svrbind.cxx
  5. Abstract:
  6. This file contains the implementation of the server binding handle
  7. class, SVR_BINDING_HANDLE.
  8. Author:
  9. Michael Montague (mikemon) 23-Nov-1991
  10. Revision History:
  11. --*/
  12. #include <precomp.hxx>
  13. RPC_STATUS
  14. SVR_BINDING_HANDLE::InsureRealBindingHandle (
  15. )
  16. /*++
  17. Routine Description:
  18. This method is used to insure that we have transformed this binding
  19. handle into a real full fledged binding handle. If we do not
  20. have a real binding handle, then we attempt to create one.
  21. Return Value:
  22. RPC_S_OK will be returned if we successfully obtain a real binding
  23. handle. Otherwise, the result of trying to create a binding handle
  24. will be returned; see DCE_BINDING::CreateBindingHandle for a list
  25. of error codes.
  26. --*/
  27. {
  28. RPC_STATUS Status;
  29. if (RealBindingHandle == 0)
  30. {
  31. RealBindingHandle = DceBinding->CreateBindingHandle(&Status);
  32. if (Status != RPC_S_OK)
  33. {
  34. RealBindingHandle = 0;
  35. return(Status);
  36. }
  37. // This binding needs to transfer its ObjectUuid, if any,
  38. // to the new binding. It is not possible to efficiently add
  39. // the object uuid to the DceBinding first.
  40. if (InqIfNullObjectUuid() == 0)
  41. {
  42. RealBindingHandle->SetObjectUuid(InqPointerAtObjectUuid());
  43. }
  44. DceBinding = 0;
  45. }
  46. return(RPC_S_OK);
  47. }
  48. SVR_BINDING_HANDLE::SVR_BINDING_HANDLE (
  49. IN DCE_BINDING * DceBinding,
  50. IN RPC_CHAR * DynamicEndpoint,
  51. IN OUT RPC_STATUS *Status
  52. ) : BINDING_HANDLE(Status)
  53. /*++
  54. Routine Description:
  55. This constructor is trivial. We just stash the binding information
  56. and dynamic endpoint away for future use.
  57. Arguments:
  58. DceBinding - Supplies the binding information. Ownership of this
  59. object passes to this routine.
  60. DynamicEndpoint - Supplies the dynamic endpoint for the rpc address
  61. corresponding to this binding. Ownership of this object passes
  62. to this routine.
  63. --*/
  64. {
  65. ObjectType = SVR_BINDING_HANDLE_TYPE;
  66. this->DceBinding = DceBinding;
  67. RealBindingHandle = 0;
  68. if( DynamicEndpoint )
  69. {
  70. EndpointIsDynamic = 1;
  71. DceBinding->AddEndpoint(DynamicEndpoint);
  72. }
  73. else
  74. {
  75. EndpointIsDynamic = 0;
  76. }
  77. }
  78. SVR_BINDING_HANDLE::~SVR_BINDING_HANDLE (
  79. )
  80. /*++
  81. Routine Description:
  82. Since ownership of the binding information passed to the constructor
  83. of this instance, we need to delete the binding information now.
  84. Actually, before we can delete the binding information we need to
  85. check to see if ownership has passed to the real binding handle.
  86. --*/
  87. {
  88. if (DceBinding != 0)
  89. delete DceBinding;
  90. }
  91. inline HANDLE_TYPE // Return SVR_BINDING_HANDLE_TYPE.
  92. SVR_BINDING_HANDLE::Type (
  93. )
  94. {
  95. UNUSED(this);
  96. return (SVR_BINDING_HANDLE_TYPE);
  97. }
  98. void
  99. SVR_BINDING_HANDLE::MakePartiallyBound(
  100. )
  101. /*++
  102. Routine Description:
  103. This routine is called by RPC_SERVER::NsBindingsModify(). We just
  104. remove the endpoint information from DceBinding member variable.
  105. --*/
  106. {
  107. if (EndpointIsDynamic)
  108. {
  109. DceBinding->MakePartiallyBound();
  110. }
  111. }
  112. RPC_STATUS
  113. SVR_BINDING_HANDLE::SendReceive (
  114. IN OUT PRPC_MESSAGE Message
  115. )
  116. /*++
  117. Routine Description:
  118. We need to transport the server binding handle into a full fledged
  119. binding handle, and then let the full fledged binding handle take
  120. care of performing the requested operation.
  121. Arguments:
  122. Message - Supplies and returns information describing the remote
  123. procedure call to be sent.
  124. Return Value:
  125. For possible return codes, see DCE_BINDING::CreateBindingHandle and
  126. SendReceive.
  127. --*/
  128. {
  129. RPC_STATUS Status;
  130. Status = InsureRealBindingHandle();
  131. if (Status != RPC_S_OK)
  132. return(Status);
  133. return(RealBindingHandle->SendReceive(Message));
  134. }
  135. RPC_STATUS
  136. SVR_BINDING_HANDLE::NegotiateTransferSyntax (
  137. IN OUT PRPC_MESSAGE Message
  138. )
  139. /*++
  140. Routine Description:
  141. We need to transport the server binding handle into a full fledged
  142. binding handle, and then let the full fledged binding handle take
  143. care of performing the requested operation.
  144. Arguments:
  145. Message - Supplies and returns information describing the buffer
  146. we need to allocate.
  147. Return Value:
  148. For possible return codes, see DCE_BINDING::CreateBindingHandle and
  149. the different flavors of NegotiateTransferSyntax.
  150. --*/
  151. {
  152. RPC_STATUS Status;
  153. Status = InsureRealBindingHandle();
  154. if (Status != RPC_S_OK)
  155. return(Status);
  156. return(RealBindingHandle->NegotiateTransferSyntax(Message));
  157. }
  158. RPC_STATUS
  159. SVR_BINDING_HANDLE::GetBuffer (
  160. IN OUT PRPC_MESSAGE Message,
  161. IN UUID *ObjectUuid
  162. )
  163. /*++
  164. Routine Description:
  165. We need to transport the server binding handle into a full fledged
  166. binding handle, and then let the full fledged binding handle take
  167. care of performing the requested operation.
  168. Arguments:
  169. Message - Supplies and returns information describing the buffer
  170. we need to allocate.
  171. Return Value:
  172. For possible return codes, see DCE_BINDING::CreateBindingHandle and
  173. the different flavors of GetBuffer.
  174. --*/
  175. {
  176. RPC_STATUS Status;
  177. Status = InsureRealBindingHandle();
  178. if (Status != RPC_S_OK)
  179. return(Status);
  180. return(RealBindingHandle->GetBuffer(Message, ObjectUuid));
  181. }
  182. void
  183. SVR_BINDING_HANDLE::FreeBuffer (
  184. IN PRPC_MESSAGE Message
  185. )
  186. /*++
  187. Routine Description:
  188. We need to transport the server binding handle into a full fledged
  189. binding handle, and then let the full fledged binding handle take
  190. care of performing the requested operation.
  191. Arguments:
  192. Message - Supplies the buffer to be freed.
  193. --*/
  194. {
  195. RPC_STATUS Status;
  196. Status = InsureRealBindingHandle();
  197. ASSERT(Status == RPC_S_OK);
  198. RealBindingHandle->FreeBuffer(Message);
  199. }
  200. RPC_STATUS
  201. SVR_BINDING_HANDLE::BindingCopy (
  202. OUT BINDING_HANDLE * PAPI * DestinationBinding,
  203. IN unsigned int MaintainContext
  204. )
  205. /*++
  206. Routine Description:
  207. We need to copy this binding handle. This is relatively easy to
  208. do: we just need to duplicate the binding information and construct
  209. another server binding handle.
  210. Arguments:
  211. DestinationBinding - Returns a copy of this binding handle.
  212. MaintainContext - Supplies a flag that indicates whether or not context
  213. is being maintained over this binding handle. A non-zero value
  214. indicates that context is being maintained.
  215. Return Value:
  216. RPC_S_OUT_OF_MEMORY - This indicates that there is not enough memory
  217. to allocate a new binding handle.
  218. RPC_S_OK - We successfully copied this binding handle.
  219. --*/
  220. {
  221. SVR_BINDING_HANDLE * Binding;
  222. DCE_BINDING * DceBinding;
  223. RPC_STATUS Status;
  224. if (RealBindingHandle != 0)
  225. return(RealBindingHandle->BindingCopy(DestinationBinding,
  226. MaintainContext));
  227. // Even if the binding is really dynamic, the endpoint has
  228. // been added to the DceBinding in the constructor.
  229. DceBinding = this->DceBinding->DuplicateDceBinding();
  230. if (DceBinding == 0)
  231. {
  232. *DestinationBinding = 0;
  233. return(RPC_S_OUT_OF_MEMORY);
  234. }
  235. Binding = new SVR_BINDING_HANDLE(DceBinding,0, &Status);
  236. *DestinationBinding = Binding;
  237. if (Binding == 0)
  238. return(RPC_S_OUT_OF_MEMORY);
  239. return(RPC_S_OK);
  240. }
  241. RPC_STATUS
  242. SVR_BINDING_HANDLE::BindingFree (
  243. )
  244. /*++
  245. Routine Description:
  246. The application wants to free this binding handle. If there is a real
  247. binding handle, we need to invoke BindingFree on it as well; otherwise,
  248. all we have got to do is to delete it.
  249. Return Value:
  250. RPC_S_OK - This value will be returned, unless an error occurs in the
  251. BindingFree operation invoked on the real binding handle.
  252. --*/
  253. {
  254. RPC_STATUS Status;
  255. if (RealBindingHandle != 0)
  256. {
  257. Status = RealBindingHandle->BindingFree();
  258. RealBindingHandle = 0;
  259. if (Status != RPC_S_OK)
  260. return(Status);
  261. }
  262. delete this;
  263. return(RPC_S_OK);
  264. }
  265. RPC_STATUS
  266. SVR_BINDING_HANDLE::ToStringBinding (
  267. OUT RPC_CHAR PAPI * PAPI * StringBinding
  268. )
  269. /*++
  270. Routine Description:
  271. We need to convert the binding handle into a string binding. We
  272. can just use the information in this server binding handle to
  273. create the string binding.
  274. Arguments:
  275. StringBinding - Returns the string representation of the binding
  276. handle.
  277. Return Value:
  278. RPC_S_OK - The operation completed successfully.
  279. RPC_S_OUT_OF_MEMORY - We do not have enough memory available to
  280. allocate space for the string binding.
  281. --*/
  282. {
  283. if (RealBindingHandle != 0)
  284. return(RealBindingHandle->ToStringBinding(StringBinding));
  285. *StringBinding = DceBinding->StringBindingCompose(
  286. InqPointerAtObjectUuid());
  287. if (*StringBinding == 0)
  288. return(RPC_S_OUT_OF_MEMORY);
  289. return(RPC_S_OK);
  290. }
  291. RPC_STATUS
  292. SVR_BINDING_HANDLE::ToStaticStringBinding (
  293. OUT RPC_CHAR PAPI * PAPI * StringBinding
  294. )
  295. /*++
  296. Routine Description:
  297. We need to convert the binding handle into a string binding. We
  298. can just use the information in this server binding handle to
  299. create the string binding.
  300. Arguments:
  301. StringBinding - Returns the string representation of the binding
  302. handle.
  303. Return Value:
  304. RPC_S_OK - The operation completed successfully.
  305. RPC_S_OUT_OF_MEMORY - We do not have enough memory available to
  306. allocate space for the string binding.
  307. --*/
  308. {
  309. RPC_STATUS Status;
  310. RPC_CHAR __RPC_FAR * CopiedStringBinding;
  311. RPC_UUID *MyUuid = 0;
  312. DCE_BINDING *MyDceBinding;
  313. if (RealBindingHandle != 0)
  314. {
  315. Status = RealBindingHandle->ToStringBinding(StringBinding);
  316. if (Status != RPC_S_OK)
  317. {
  318. return Status;
  319. }
  320. if (EndpointIsDynamic == 0)
  321. {
  322. return RPC_S_OK;
  323. }
  324. //
  325. // The endpoint is dynamic, need to strip it out
  326. //
  327. CopiedStringBinding = (RPC_CHAR *)
  328. _alloca( (RpcpStringLength(StringBinding)+1)*(sizeof(RPC_CHAR)) );
  329. if (CopiedStringBinding == 0)
  330. {
  331. return (RPC_S_OUT_OF_MEMORY);
  332. }
  333. RpcpStringCopy(CopiedStringBinding, StringBinding);
  334. MyDceBinding = new DCE_BINDING(CopiedStringBinding,&Status);
  335. if ( MyDceBinding == 0 )
  336. {
  337. return(RPC_S_OUT_OF_MEMORY);
  338. }
  339. if ( Status != RPC_S_OK )
  340. {
  341. delete MyDceBinding;
  342. return(Status);
  343. }
  344. }
  345. else
  346. {
  347. MyUuid = InqPointerAtObjectUuid();
  348. MyDceBinding = DceBinding;
  349. }
  350. *StringBinding = MyDceBinding->StringBindingCompose(
  351. MyUuid,
  352. EndpointIsDynamic);
  353. if (DceBinding != MyDceBinding)
  354. {
  355. delete MyDceBinding;
  356. }
  357. if (*StringBinding == 0)
  358. {
  359. return RPC_S_OUT_OF_MEMORY;
  360. }
  361. return(RPC_S_OK);
  362. }
  363. RPC_STATUS
  364. SVR_BINDING_HANDLE::InquireDynamicEndpoint (
  365. OUT RPC_CHAR PAPI * PAPI * DynamicEndpoint
  366. )
  367. /*++
  368. Routine Description:
  369. This routine is used to obtain the dynamic endpoint from a binding
  370. handle which was created from an rpc address. If there is a dynamic
  371. endpoint, we just need to duplicate it, and return a pointer to it.
  372. Arguments:
  373. DynamicEndpoint - Returns a pointer to the dynamic endpoint, it is
  374. always set to zero.
  375. Return Value:
  376. RPC_S_OK - The operation completed successfully.
  377. RPC_S_OUT_OF_MEMORY - Unable to allocate memory for the endpoint string.
  378. --*/
  379. {
  380. if (EndpointIsDynamic == 1 && DceBinding)
  381. {
  382. *DynamicEndpoint = DuplicateStringPAPI(DceBinding->InqEndpoint());
  383. if (*DynamicEndpoint == 0)
  384. return(RPC_S_OUT_OF_MEMORY);
  385. }
  386. else
  387. {
  388. *DynamicEndpoint = 0;
  389. }
  390. return(RPC_S_OK);
  391. }
  392. RPC_STATUS
  393. SVR_BINDING_HANDLE::PrepareBindingHandle (
  394. IN TRANS_INFO * TransportInterface,
  395. IN DCE_BINDING * DceBinding
  396. )
  397. {
  398. UNUSED(this);
  399. UNUSED(TransportInterface);
  400. UNUSED(DceBinding);
  401. ASSERT( 0 );
  402. return RPC_S_OK;
  403. }
  404. RPC_STATUS
  405. SVR_BINDING_HANDLE::ResolveBinding (
  406. IN PRPC_CLIENT_INTERFACE RpcClientInterface
  407. )
  408. {
  409. RPC_STATUS Status;
  410. Status = InsureRealBindingHandle();
  411. if (Status != RPC_S_OK)
  412. return (Status);
  413. return(RealBindingHandle->ResolveBinding(RpcClientInterface));
  414. }
  415. RPC_STATUS
  416. SVR_BINDING_HANDLE::BindingReset (
  417. )
  418. {
  419. RPC_STATUS Status;
  420. Status = InsureRealBindingHandle();
  421. if (Status != RPC_S_OK)
  422. return(Status);
  423. Status = RealBindingHandle->BindingReset();
  424. if (Status == RPC_S_OK)
  425. {
  426. EndpointIsDynamic = 0;
  427. }
  428. return (Status);
  429. }
  430. RPC_STATUS
  431. SVR_BINDING_HANDLE::InquireTransportType(
  432. OUT unsigned int PAPI *Type
  433. )
  434. {
  435. RPC_STATUS Status;
  436. Status = InsureRealBindingHandle();
  437. if (Status != RPC_S_OK)
  438. return(Status);
  439. return(RealBindingHandle->InquireTransportType(Type));
  440. }