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.

420 lines
10 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1991 - 1999
  3. Module Name:
  4. dcecmisc.cxx
  5. Abstract:
  6. This module contains the code implementing miscellaneous DCE RPC
  7. runtime APIs. In particular, this includes the following APIs:
  8. RpcIfInqId, RpcNetworkIsProtseqValid, RpcMgmtInqComTimeout,
  9. RpcMgmtSetComTimeout, RpcMgmtSetCancelTimeout, and DceErrorInqText.
  10. Author:
  11. Michael Montague (mikemon) 11-Nov-1991
  12. Revision History:
  13. --*/
  14. #include <precomp.hxx>
  15. #if !defined(_M_IA64)
  16. unsigned long RecvWindow = 0;
  17. unsigned long SendWindow = 0;
  18. #endif
  19. RPC_STATUS RPC_ENTRY
  20. RpcIfInqId (
  21. IN RPC_IF_HANDLE RpcIfHandle,
  22. OUT RPC_IF_ID PAPI * RpcIfId
  23. )
  24. /*++
  25. Routine Description:
  26. The routine is used by an application to obtain the interface
  27. identification part of an interface specification. This is a really
  28. simple API since the RpcIfHandle points to the interface information,
  29. so all we have got to do is cast RpcIfHandle and copy some stuff.
  30. Arguments:
  31. RpcIfHandle - Supplies a handle to the interface specification.
  32. RpcIfId - Returns the interface identification part of the interface
  33. specification.
  34. Return Value:
  35. RPC_S_OK - The operation completed successfully.
  36. --*/
  37. {
  38. RPC_CLIENT_INTERFACE PAPI * RpcInterfaceInformation;
  39. InitializeIfNecessary();
  40. RpcInterfaceInformation = (RPC_CLIENT_INTERFACE PAPI *) RpcIfHandle;
  41. RpcpMemoryCopy(&(RpcIfId->Uuid),
  42. &(RpcInterfaceInformation->InterfaceId.SyntaxGUID),sizeof(UUID));
  43. RpcIfId->VersMajor =
  44. RpcInterfaceInformation->InterfaceId.SyntaxVersion.MajorVersion;
  45. RpcIfId->VersMinor =
  46. RpcInterfaceInformation->InterfaceId.SyntaxVersion.MinorVersion;
  47. return(RPC_S_OK);
  48. }
  49. RPC_STATUS RPC_ENTRY
  50. RpcNetworkIsProtseqValid (
  51. IN unsigned short PAPI * Protseq
  52. )
  53. /*++
  54. Routine Description:
  55. An application program will use this API to determine if an rpc
  56. protocol sequence is supported by the current system.
  57. Arguments:
  58. Protseq - Supplies an rpc protocol sequence to be check to see if
  59. it is supported.
  60. Return Value:
  61. RPC_S_OK - The specified rpc protocol sequence is support.
  62. RPC_S_PROTSEQ_NOT_SUPPORTED - The specified rpc protocol sequence
  63. is not supported (but it appears to be valid).
  64. RPC_S_INVALID_RPC_PROTSEQ - The specified rpc protocol sequence is
  65. invalid.
  66. --*/
  67. {
  68. InitializeIfNecessary();
  69. return(IsRpcProtocolSequenceSupported(Protseq));
  70. }
  71. RPC_STATUS RPC_ENTRY
  72. RpcMgmtInqComTimeout (
  73. IN RPC_BINDING_HANDLE Binding,
  74. OUT unsigned int PAPI * Timeout
  75. )
  76. /*++
  77. Routine Description:
  78. This routine is used to obtain the communications timeout from a
  79. binding handle.
  80. Arguments:
  81. Binding - Supplies a binding handle from which to inquire the
  82. communication timeout.
  83. Timeout - Returns the communications timeout in the binding handle.
  84. Return Value:
  85. RPC_S_OK - The operation completed successfully.
  86. RPC_S_INVALID_BINDING - The specified binding is not a client side
  87. binding handle.
  88. --*/
  89. {
  90. BINDING_HANDLE * BindingHandle;
  91. InitializeIfNecessary();
  92. BindingHandle = (BINDING_HANDLE *) Binding;
  93. if (BindingHandle->InvalidHandle(BINDING_HANDLE_TYPE))
  94. return(RPC_S_INVALID_BINDING);
  95. *Timeout = BindingHandle->InqComTimeout();
  96. return(RPC_S_OK);
  97. }
  98. RPC_STATUS RPC_ENTRY
  99. RpcMgmtSetComTimeout (
  100. IN RPC_BINDING_HANDLE Binding,
  101. IN unsigned int Timeout
  102. )
  103. /*++
  104. Routine Description:
  105. An application will use this routine to set the communications
  106. timeout for a binding handle. The timeout value specifies the
  107. relative amount of time that should be spent to establish a binding
  108. to the server before giving up.
  109. Arguments:
  110. Binding - Supplies the binding handle for which the communications
  111. timeout value will be set.
  112. Timeout - Supplies the communications timeout value to set in the
  113. binding handle.
  114. Return Value:
  115. RPC_S_OK - The operation completed successfully.
  116. RPC_S_INVALID_BINDING - The specified binding is not a client side
  117. binding handle.
  118. RPC_S_INVALID_TIMEOUT - The specified timeout value is invalid.
  119. --*/
  120. {
  121. BINDING_HANDLE * BindingHandle;
  122. InitializeIfNecessary();
  123. BindingHandle = (BINDING_HANDLE *) Binding;
  124. if (BindingHandle->InvalidHandle(BINDING_HANDLE_TYPE))
  125. return(RPC_S_INVALID_BINDING);
  126. return(BindingHandle->SetComTimeout(Timeout));
  127. }
  128. RPC_STATUS RPC_ENTRY
  129. I_RpcIfInqTransferSyntaxes (
  130. IN RPC_IF_HANDLE RpcIfHandle,
  131. OUT RPC_TRANSFER_SYNTAX PAPI * TransferSyntaxes,
  132. IN unsigned int TransferSyntaxSize,
  133. OUT unsigned int PAPI * TransferSyntaxCount
  134. )
  135. /*++
  136. Routine Description:
  137. This routine will be used to obtain the transfer syntaxes support
  138. by an interface. A description of the interface is supplied via
  139. the interface handle.
  140. Arguments:
  141. RpcIfHandle - Supplies a reference to the interface from which we
  142. want to inquire the transfer syntaxes.
  143. TransferSyntaxes - Returns a copy of the transfer syntaxes support
  144. by the interface.
  145. TransferSyntaxSize - Supplies the number of RPC_TRANSFER_SYNTAX records
  146. which can fit in the transfer syntaxes buffer.
  147. TransferSyntaxCount - Returns the number of transfer syntaxes supported
  148. by the interface. This value will always be returned, whether or
  149. not an error occurs.
  150. Return Value:
  151. RPC_S_OK - We copied the transfer syntaxes into the buffer successfully.
  152. RPC_S_BUFFER_TOO_SMALL - The supplies transfer syntaxes buffer is too
  153. small; the transfer syntax count parameter will return the minimum
  154. size required.
  155. --*/
  156. {
  157. RPC_CLIENT_INTERFACE PAPI * RpcInterfaceInformation;
  158. *TransferSyntaxCount = 1;
  159. if (TransferSyntaxSize < 1)
  160. return(RPC_S_BUFFER_TOO_SMALL);
  161. RpcInterfaceInformation = (RPC_CLIENT_INTERFACE PAPI *) RpcIfHandle;
  162. RpcpMemoryCopy(&(TransferSyntaxes->Uuid),
  163. &(RpcInterfaceInformation->TransferSyntax.SyntaxGUID),
  164. sizeof(UUID));
  165. TransferSyntaxes->VersMajor =
  166. RpcInterfaceInformation->TransferSyntax.SyntaxVersion.MajorVersion;
  167. TransferSyntaxes->VersMinor =
  168. RpcInterfaceInformation->TransferSyntax.SyntaxVersion.MinorVersion;
  169. return(RPC_S_OK);
  170. }
  171. RPC_STATUS RPC_ENTRY
  172. RpcMgmtEnableIdleCleanup (
  173. void
  174. )
  175. /*++
  176. Routine Description:
  177. An application will use this routine to enable cleanup of idle resources.
  178. For the connection oriented protocol module, a connection must be idle
  179. for five minutes before it is cleaned up.
  180. Return Value:
  181. RPC_S_OK - Cleanup of idle resources has been enabled.
  182. RPC_S_OUT_OF_THREADS - Insufficient threads are available to be able
  183. to perform this operation.
  184. RPC_S_OUT_OF_RESOURCES - Insufficient resources are available to be
  185. able to perform this operation.
  186. RPC_S_OUT_OF_MEMORY - Insufficient memory is available to be able to
  187. perform this operation.
  188. --*/
  189. {
  190. InitializeIfNecessary();
  191. return(EnableIdleConnectionCleanup());
  192. }
  193. RPC_STATUS RPC_ENTRY
  194. DceErrorInqTextA (
  195. IN RPC_STATUS RpcStatus,
  196. OUT unsigned char __RPC_FAR * ErrorText
  197. )
  198. /*++
  199. Routine Description:
  200. The supplied status code is converted into a text message if possible.
  201. Arguments:
  202. RpcStatus - Supplies the status code to convert.
  203. ErrorText - Returns a character string containing the text message
  204. for the status code.
  205. Return Value:
  206. RPC_S_OK - The supplied status codes has successfully been converted
  207. into a text message.
  208. RPC_S_INVALID_ARG - The supplied value is not a valid status code.
  209. --*/
  210. {
  211. if ( FormatMessageA(FORMAT_MESSAGE_IGNORE_INSERTS
  212. | FORMAT_MESSAGE_FROM_SYSTEM, 0, RpcStatus, 0, (char *)ErrorText,
  213. DCE_C_ERROR_STRING_LEN, 0) == 0 )
  214. {
  215. if ( FormatMessageA( FORMAT_MESSAGE_IGNORE_INSERTS |
  216. FORMAT_MESSAGE_FROM_SYSTEM, 0, RPC_S_NOT_RPC_ERROR,
  217. 0, (char *)ErrorText, DCE_C_ERROR_STRING_LEN, 0 ) == 0 )
  218. {
  219. *ErrorText = '\0';
  220. return(RPC_S_INVALID_ARG);
  221. }
  222. }
  223. return(RPC_S_OK);
  224. }
  225. RPC_STATUS RPC_ENTRY
  226. DceErrorInqTextW (
  227. IN RPC_STATUS RpcStatus,
  228. OUT unsigned short __RPC_FAR * ErrorText
  229. )
  230. /*++
  231. Routine Description:
  232. The supplied status code is converted into a text message if possible.
  233. Arguments:
  234. RpcStatus - Supplies the status code to convert.
  235. ErrorText - Returns a character string containing the text message
  236. for the status code.
  237. Return Value:
  238. RPC_S_OK - The supplied status codes has successfully been converted
  239. into a text message.
  240. RPC_S_INVALID_ARG - The supplied value is not a valid status code.
  241. --*/
  242. {
  243. if ( FormatMessageW(FORMAT_MESSAGE_IGNORE_INSERTS
  244. | FORMAT_MESSAGE_FROM_SYSTEM, 0, RpcStatus, 0, ErrorText,
  245. DCE_C_ERROR_STRING_LEN * sizeof(RPC_CHAR), 0) == 0 )
  246. {
  247. if ( FormatMessageW( FORMAT_MESSAGE_IGNORE_INSERTS |
  248. FORMAT_MESSAGE_FROM_SYSTEM, 0, RPC_S_NOT_RPC_ERROR, 0,
  249. ErrorText, DCE_C_ERROR_STRING_LEN * sizeof(RPC_CHAR),0 ) == 0 )
  250. {
  251. *ErrorText = 0;
  252. return(RPC_S_INVALID_ARG);
  253. }
  254. }
  255. return(RPC_S_OK);
  256. }
  257. #if !defined(_M_IA64)
  258. RPC_STATUS RPC_ENTRY
  259. I_RpcConnectionInqSockBuffSize(
  260. OUT unsigned long __RPC_FAR * RecvBuffSize,
  261. OUT unsigned long __RPC_FAR * SendBuffSize
  262. )
  263. {
  264. RequestGlobalMutex();
  265. *RecvBuffSize = RecvWindow;
  266. *SendBuffSize = SendWindow;
  267. ClearGlobalMutex();
  268. return (RPC_S_OK);
  269. }
  270. RPC_STATUS RPC_ENTRY
  271. I_RpcConnectionSetSockBuffSize(
  272. IN unsigned long RecvBuffSize,
  273. IN unsigned long SendBuffSize
  274. )
  275. {
  276. if (RecvBuffSize > 0xFFFF)
  277. {
  278. RecvBuffSize = 0xFFFF;
  279. }
  280. if (SendBuffSize > 0xFFFF)
  281. {
  282. SendBuffSize = 0xFFFF;
  283. }
  284. RequestGlobalMutex();
  285. RecvWindow = RecvBuffSize;
  286. SendWindow = SendBuffSize;
  287. ClearGlobalMutex();
  288. return (RPC_S_OK);
  289. }
  290. void RPC_ENTRY
  291. I_RpcConnectionInqSockBuffSize2(
  292. OUT unsigned long __RPC_FAR * RecvWindowSize
  293. )
  294. {
  295. *RecvWindowSize = RecvWindow;
  296. }
  297. #endif