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.

356 lines
8.6 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1992 - 1999
  3. Module Name:
  4. wmsgpack.hxx
  5. Abstract:
  6. This file contains the definitions of the packet formats used by
  7. RPC on LPC.
  8. Author:
  9. Steven Zeck (stevez) 11/12/91
  10. Revision History:
  11. 15-Dec-1992 mikemon
  12. Rewrote the majority of the code.
  13. ... implemented WMSG protocol
  14. 05-15-96 merged LRPC / WMSG into a single protocol
  15. Kamen Moutafov (KamenM) Mar-2000 Support for extended error info
  16. --*/
  17. #ifndef __LPCPACK_HXX__
  18. #define __LPCPACK_HXX__
  19. #define LRPC_DIRECTORY_NAME L##"\\RPC Control\\"
  20. #define MINIMUM_PARTIAL_BUFFLEN 10240
  21. #define PORT_NAME_LEN 64
  22. #define BIND_BACK_PORT_NAME_LEN 128
  23. #define LRPC_TIMEOUT 100
  24. #define LRPC_THRESHOLD_SIZE (MINIMUM_PARTIAL_BUFFLEN * 3)
  25. #define BIND_BACK_FLAG 1
  26. #define NEW_SECURITY_CONTEXT_FLAG 2
  27. #define NEW_PRESENTATION_CONTEXT_FLAG 4
  28. #define EXTENDED_ERROR_INFO_PRESENT 8
  29. #define DEFAULT_LOGONID_FLAG (0x10)
  30. #define SERVER_BIND_EXCH_RESP (0x20)
  31. #define TS_NDR20_FLAG 1
  32. #define TS_NDR64_FLAG 2
  33. #define TS_NDRTEST_FLAG 4
  34. typedef struct _LRPC_BIND_EXCHANGE
  35. {
  36. INT ConnectType ;
  37. DWORD AssocKey ;
  38. RPC_SYNTAX_IDENTIFIER InterfaceId;
  39. // can be any of TS_NDR20_FLAG, TS_NDR64_FLAG
  40. unsigned int TransferSyntaxSet;
  41. RPC_STATUS RpcStatus;
  42. // can be: BIND_BACK_FLAG, NEW_SECURITY_CONTEXT_FLAG, NEW_PRESENTATION_CONTEXT_FLAG
  43. // EXTENDED_ERROR_INFO_PRESENT, SERVER_BIND_EXCH_RESP on return from the server
  44. unsigned short Flags;
  45. // the first is always the presentation context id for NDR20,
  46. // and the second is for NDR64. The third can be NDRTest - that's
  47. // why the + 1
  48. unsigned short PresentationContext[MaximumNumberOfTransferSyntaxes + 1];
  49. unsigned long SecurityContextId;
  50. union
  51. {
  52. char szPortName[PORT_NAME_LEN] ;
  53. struct
  54. {
  55. // provide 8 byte alignment
  56. unsigned char Pad2[4];
  57. unsigned char Buffer[4];
  58. };
  59. };
  60. } LRPC_BIND_EXCHANGE;
  61. // message types
  62. #define LRPC_MSG_BIND 0
  63. #define LRPC_MSG_REQUEST 1
  64. #define LRPC_MSG_RESPONSE 2
  65. #define LRPC_MSG_CALLBACK 3
  66. #define LRPC_MSG_FAULT 4
  67. #define LRPC_MSG_CLOSE 5
  68. #define LRPC_MSG_ACK 6
  69. #define LRPC_BIND_ACK 7
  70. #define LRPC_MSG_COPY 8
  71. #define LRPC_MSG_PUSH 9
  72. #define LRPC_MSG_CANCEL 10
  73. #define LRPC_MSG_BIND_BACK 11
  74. #define LRPC_ASYNC_REQUEST 12
  75. #define LRPC_PARTIAL_REQUEST 13
  76. #define LRPC_CLIENT_SEND_MORE 14
  77. #define LRPC_SERVER_SEND_MORE 15
  78. #define LRPC_MSG_FAULT2 16
  79. #define MAX_LRPC_MSG 16
  80. // connect types
  81. #define LRPC_CONNECT_REQUEST 0
  82. #define LRPC_CONNECT_RESPONSE 1
  83. #define LRPC_CONNECT_TICKLE 2
  84. #define MAX_LRPC_CONTEXTS ((PORT_MAXIMUM_MESSAGE_LENGTH - sizeof(LRPC_BIND_MESSAGE)) / sizeof(DWORD))
  85. typedef struct _OLD_SECURITY_CONTEXTS
  86. {
  87. DWORD NumContexts;
  88. DWORD SecurityContextId[1];
  89. } OLD_SECURITY_CONTEXTS;
  90. #define BIND_NAK_PICKLE_BUFFER_OFFSET (FIELD_OFFSET(LRPC_BIND_EXCHANGE, Buffer) \
  91. + FIELD_OFFSET(LRPC_BIND_MESSAGE, BindExchange))
  92. #define MAX_BIND_NAK (PORT_MAXIMUM_MESSAGE_LENGTH - BIND_NAK_PICKLE_BUFFER_OFFSET)
  93. typedef struct _LRPC_BIND_MESSAGE
  94. {
  95. PORT_MESSAGE LpcHeader;
  96. unsigned char MessageType;
  97. unsigned char Pad[3];
  98. LRPC_BIND_EXCHANGE BindExchange;
  99. OLD_SECURITY_CONTEXTS OldSecurityContexts;
  100. } LRPC_BIND_MESSAGE;
  101. typedef struct _LRPC_BIND_BACK_MESSAGE
  102. {
  103. PORT_MESSAGE LpcHeader;
  104. unsigned char MessageType;
  105. unsigned char Pad[3];
  106. DWORD AssocKey ;
  107. char szPortName[BIND_BACK_PORT_NAME_LEN] ;
  108. } LRPC_BIND_BACK_MESSAGE;
  109. // buffer flags
  110. #define LRPC_BUFFER_IMMEDIATE 0x0001
  111. #define LRPC_BUFFER_REQUEST 0x0002
  112. #define LRPC_BUFFER_SERVER 0x0004
  113. // misc flags
  114. #define LRPC_SYNC_CLIENT 0x0040
  115. #define LRPC_BUFFER_PARTIAL 0x0080
  116. #define LRPC_OBJECT_UUID 0x0100
  117. #define LRPC_NON_PIPE 0x0200
  118. #define LRPC_CAUSAL 0x0400
  119. #define LRPC_EEINFO_PRESENT 0x0800
  120. typedef struct _LRPC_RPC_HEADER
  121. {
  122. unsigned char MessageType;
  123. unsigned short PresentContext;
  124. unsigned short Flags ;
  125. unsigned short ProcedureNumber;
  126. UUID ObjectUuid;
  127. unsigned long SecurityContextId;
  128. unsigned long CallId;
  129. } LRPC_RPC_HEADER;
  130. typedef struct _LRPC_SERVER_BUFFER
  131. {
  132. unsigned int Length;
  133. LPC_PVOID Buffer;
  134. } LRPC_SERVER_BUFFER;
  135. #define MAXIMUM_MESSAGE_BUFFER \
  136. (PORT_MAXIMUM_MESSAGE_LENGTH - sizeof(PORT_MESSAGE) \
  137. - sizeof(LRPC_RPC_HEADER))
  138. typedef struct _LRPC_CONNECT_MESSAGE
  139. {
  140. PORT_MESSAGE LpcHeader;
  141. LRPC_BIND_EXCHANGE BindExchange;
  142. } LRPC_CONNECT_MESSAGE;
  143. typedef struct _LRPC_RPC_MESSAGE
  144. {
  145. PORT_MESSAGE LpcHeader;
  146. LRPC_RPC_HEADER RpcHeader;
  147. union
  148. {
  149. unsigned char Buffer[MAXIMUM_MESSAGE_BUFFER];
  150. PORT_DATA_INFORMATION Request;
  151. LRPC_SERVER_BUFFER Server;
  152. };
  153. } LRPC_RPC_MESSAGE;
  154. typedef struct _LRPC_FAULT_MESSAGE
  155. {
  156. PORT_MESSAGE LpcHeader;
  157. LRPC_RPC_HEADER RpcHeader ;
  158. RPC_STATUS RpcStatus;
  159. // align the Buffer on 8 bytes - required for pickling
  160. DWORD Padding1;
  161. // the actual length has to be retrieved
  162. // from LpcHeader.u1.s1.DataLength/TotalLength
  163. unsigned char Buffer[4];
  164. } LRPC_FAULT_MESSAGE;
  165. #define MAXIMUM_FAULT_MESSAGE \
  166. (PORT_MAXIMUM_MESSAGE_LENGTH - sizeof(LRPC_FAULT_MESSAGE))
  167. // N.B. The layout of fault2 must match the layout of
  168. // LRPC_RPC_MESSAGE up to and including the union of
  169. // Request/Server. This is so because many code paths
  170. // will operate on both, and having the same layout
  171. // allows us to avoid special casing those
  172. typedef struct _LRPC_FAULT2_MESSAGE
  173. {
  174. PORT_MESSAGE LpcHeader;
  175. LRPC_RPC_HEADER RpcHeader ;
  176. union
  177. {
  178. PORT_DATA_INFORMATION Request;
  179. LRPC_SERVER_BUFFER Server;
  180. };
  181. RPC_STATUS RpcStatus;
  182. } LRPC_FAULT2_MESSAGE;
  183. typedef struct _LRPC_CLOSE_MESSAGE
  184. {
  185. PORT_MESSAGE LpcHeader;
  186. unsigned char MessageType;
  187. unsigned char Pad[3];
  188. } LRPC_CLOSE_MESSAGE;
  189. typedef struct _LRPC_PUSH_MESSAGE
  190. {
  191. PORT_MESSAGE LpcHeader;
  192. LRPC_RPC_HEADER RpcHeader;
  193. PORT_DATA_INFORMATION Response;
  194. RPC_STATUS RpcStatus;
  195. } LRPC_PUSH_MESSAGE;
  196. #define ACK_BUFFER_COMPLETE 0x01
  197. typedef struct _LRPC_ACK_MESSAGE
  198. {
  199. PORT_MESSAGE LpcHeader;
  200. unsigned char MessageType;
  201. unsigned char Pad ;
  202. short Shutup ;
  203. RPC_STATUS RpcStatus;
  204. int ValidDataSize ;
  205. int Flags ;
  206. } LRPC_ACK_MESSAGE;
  207. typedef struct _LRPC_COPY_MESSAGE
  208. {
  209. PORT_MESSAGE LpcHeader;
  210. LRPC_RPC_HEADER RpcHeader ;
  211. PORT_DATA_INFORMATION Request;
  212. LRPC_SERVER_BUFFER Server;
  213. RPC_STATUS RpcStatus;
  214. int IsPartial ;
  215. } LRPC_COPY_MESSAGE;
  216. typedef struct _LRPC_PARTIAL_MESSAGE
  217. {
  218. PORT_MESSAGE LpcHeader;
  219. LRPC_RPC_HEADER RpcHeader ;
  220. PORT_DATA_INFORMATION Request;
  221. RPC_STATUS RpcStatus;
  222. int IsPartial ;
  223. } LRPC_PARTIAL_MESSAGE;
  224. typedef union _LRPC_MESSAGE
  225. {
  226. LRPC_CONNECT_MESSAGE Connect;
  227. LRPC_BIND_MESSAGE Bind;
  228. LRPC_RPC_MESSAGE Rpc;
  229. LRPC_FAULT_MESSAGE Fault;
  230. LRPC_FAULT2_MESSAGE Fault2;
  231. LRPC_CLOSE_MESSAGE Close;
  232. PORT_MESSAGE LpcHeader;
  233. LRPC_ACK_MESSAGE Ack ;
  234. LRPC_PUSH_MESSAGE Push ;
  235. LRPC_BIND_BACK_MESSAGE BindBack ;
  236. LRPC_PARTIAL_MESSAGE Partial ;
  237. } LRPC_MESSAGE;
  238. //
  239. // Conversion functions to use the 64bit LPC structures when built 32bit on 64bit NT(wow64).
  240. #if defined(BUILD_WOW6432)
  241. inline
  242. CLIENT_ID
  243. MsgClientIdToClientId(const CLIENT_ID64 & s) {
  244. CLIENT_ID d;
  245. d.UniqueProcess = (HANDLE)s.UniqueProcess;
  246. d.UniqueThread = (HANDLE)s.UniqueThread;
  247. return d;
  248. }
  249. inline
  250. CLIENT_ID64
  251. ClientIdToMsgClientId(const CLIENT_ID & s) {
  252. CLIENT_ID64 d;
  253. d.UniqueProcess = (ULONGLONG)s.UniqueProcess;
  254. d.UniqueThread = (ULONGLONG)s.UniqueThread;
  255. return d;
  256. }
  257. inline
  258. ULONGLONG
  259. PtrToMsgPtr(void * s) {
  260. return (ULONGLONG)s;
  261. }
  262. inline
  263. void *
  264. MsgPtrToPtr(ULONGLONG s) {
  265. return (void *)s;
  266. }
  267. #else
  268. inline
  269. CLIENT_ID
  270. MsgClientIdToClientId(const CLIENT_ID & s) {
  271. return s;
  272. }
  273. inline
  274. CLIENT_ID
  275. ClientIdToMsgClientId(const CLIENT_ID s) {
  276. return s;
  277. }
  278. inline
  279. PVOID
  280. PtrToMsgPtr(PVOID s) {
  281. return s;
  282. }
  283. inline
  284. void *
  285. MsgPtrToPtr(void *s) {
  286. return s;
  287. }
  288. #endif
  289. RPC_STATUS
  290. LrpcMapRpcStatus (
  291. IN RPC_STATUS RpcStatus
  292. );
  293. void
  294. ShutdownLrpcClient (
  295. ) ;
  296. #endif // __LPCPACK_HXX__