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.

571 lines
15 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1991 - 1999
  3. Module Name:
  4. osfpcket.hxx
  5. Abstract:
  6. This file contains the packet formats for the OSF Connection Oriented
  7. RPC protocol.
  8. Author:
  9. Michael Montague (mikemon) 23-Jul-1990
  10. Revision History:
  11. 07-Mar-1992 mikemon
  12. Added comments and cleaned it up.
  13. --*/
  14. #ifndef __OSFPCKET_HXX__
  15. #define __OSFPCKET_HXX__
  16. #define OSF_RPC_V20_VERS 5
  17. #define OSF_RPC_V20_VERS_MINOR 0
  18. typedef enum
  19. {
  20. rpc_request = 0,
  21. rpc_response = 2,
  22. rpc_fault = 3,
  23. rpc_bind = 11,
  24. rpc_bind_ack = 12,
  25. rpc_bind_nak = 13,
  26. rpc_alter_context = 14,
  27. rpc_alter_context_resp = 15,
  28. rpc_auth_3 = 16,
  29. rpc_shutdown = 17,
  30. rpc_cancel = 18,
  31. rpc_orphaned = 19,
  32. rpc_rts = 20
  33. } rpc_ptype_t;
  34. #define PFC_FIRST_FRAG 0x01
  35. #define PFC_LAST_FRAG 0x02
  36. #define PFC_PENDING_CANCEL 0x04 // both cancel and support header sign use the same bit
  37. #define PFC_SUPPORT_HEADER_SIGN 0x04 // actual meaning of this bit is inferred from context
  38. // 0x08 reserved
  39. #define PFC_CONC_MPX 0x10
  40. #define PFC_DID_NOT_EXECUTE 0x20
  41. #define PFC_MAYBE 0x40
  42. #define PFC_OBJECT_UUID 0x80
  43. typedef struct
  44. {
  45. unsigned short length;
  46. unsigned char port_spec[1];
  47. } port_any_t;
  48. typedef unsigned short p_context_id_t;
  49. typedef struct
  50. {
  51. GUID if_uuid;
  52. unsigned long if_version;
  53. } p_syntax_id_t;
  54. typedef struct
  55. {
  56. p_context_id_t p_cont_id;
  57. unsigned char n_transfer_syn;
  58. unsigned char reserved;
  59. p_syntax_id_t abstract_syntax;
  60. p_syntax_id_t transfer_syntaxes[1];
  61. } p_cont_elem_t;
  62. // The maximum value of n_context_elem that we expect.
  63. #define MAX_N_CONTEXT_ELEM 20
  64. // There can be at most 20 versions of an interface.
  65. #define MAX_NUM_INTERFACE_VERSIONS 20
  66. // We put a bound on the number of alter-contexts for the same
  67. // interface and presentation context. This is roughly equal
  68. // to the max number of simultaneous async calls we expect.
  69. #define MAX_NUM_IDENTICAL_ALTER_CONTEXTS 100
  70. typedef struct
  71. {
  72. unsigned char n_context_elem;
  73. unsigned char reserved;
  74. unsigned short reserved2;
  75. p_cont_elem_t p_cont_elem[1];
  76. } p_cont_list_t;
  77. typedef unsigned short p_cont_def_result_t;
  78. #define acceptance 0
  79. #define user_rejection 1
  80. #define provider_rejection 2
  81. typedef unsigned short p_provider_reason_t;
  82. #define reason_not_specified 0
  83. #define abstract_syntax_not_supported 1
  84. #define proposed_transfer_syntaxes_not_supported 2
  85. #define local_limit_exceeded 3
  86. typedef unsigned short p_reject_reason_t;
  87. #define reason_not_specified_reject 0
  88. #define temporary_congestion 1
  89. #define local_limit_exceeded_reject 2
  90. #define protocol_version_not_supported 4
  91. #define authentication_type_not_recognized 8
  92. #define invalid_checksum 9
  93. typedef struct
  94. {
  95. p_cont_def_result_t result;
  96. p_provider_reason_t reason;
  97. p_syntax_id_t transfer_syntax;
  98. } p_result_t;
  99. typedef struct
  100. {
  101. unsigned char n_results;
  102. unsigned char reserved;
  103. unsigned short reserved2;
  104. p_result_t p_results[1];
  105. } p_result_list_t;
  106. typedef struct
  107. {
  108. unsigned char major;
  109. unsigned char minor;
  110. } version_t;
  111. typedef version_t p_rt_version_t;
  112. typedef struct
  113. {
  114. // currently, the runtime uses only one version.
  115. // if we change that, we have to change the alignment
  116. // of the members after that so that they are still
  117. // naturally aligned
  118. unsigned char n_protocols;
  119. p_rt_version_t p_protocols[1];
  120. } p_rt_versions_supported_t;
  121. typedef struct
  122. {
  123. unsigned char rpc_vers;
  124. unsigned char rpc_vers_minor;
  125. unsigned char PTYPE;
  126. unsigned char pfc_flags;
  127. unsigned char drep[4];
  128. unsigned short frag_length;
  129. unsigned short auth_length;
  130. unsigned long call_id;
  131. } rpcconn_common;
  132. // RPC can send fragments of at most MAX_USHORT because this is the
  133. // longest length we can represent.
  134. #define MAX_SUPPORTED_FRAG_LENGTH ((unsigned short) -1)
  135. typedef struct
  136. {
  137. rpcconn_common common;
  138. unsigned short max_xmit_frag;
  139. unsigned short max_recv_frag;
  140. unsigned long assoc_group_id;
  141. } rpcconn_bind;
  142. #if defined(WIN32RPC) || defined(MAC)
  143. #pragma pack(2)
  144. #endif // WIN32RPC
  145. typedef struct
  146. {
  147. rpcconn_common common;
  148. unsigned short max_xmit_frag;
  149. unsigned short max_recv_frag;
  150. unsigned long assoc_group_id;
  151. unsigned short sec_addr_length;
  152. } rpcconn_bind_ack;
  153. #if defined(WIN32RPC) || defined(MAC)
  154. #pragma pack()
  155. #endif // WIN32RPC
  156. typedef struct
  157. {
  158. rpcconn_common common;
  159. p_reject_reason_t provider_reject_reason;
  160. p_rt_versions_supported_t versions;
  161. UUID Signature;
  162. #if defined (_WIN64)
  163. // on Win64, we need to align the buffer after
  164. // this to 16 byte boundary. That's why the padding
  165. ULONG Padding[2];
  166. #endif
  167. char buffer[1];
  168. } rpcconn_bind_nak;
  169. const size_t BindNakSizeWithoutEEInfoAndSignature = FIELD_OFFSET(rpcconn_bind_nak, Signature);
  170. const size_t BindNakSizeWithoutEEInfo = FIELD_OFFSET(rpcconn_bind_nak, buffer);
  171. extern const UUID *BindNakEEInfoSignature;
  172. inline size_t GetEEInfoSizeFromBindNakPacket (rpcconn_bind_nak *BindNak)
  173. {
  174. ASSERT (BindNak->common.frag_length > BindNakSizeWithoutEEInfo);
  175. ASSERT (RpcpMemoryCompare(&BindNak->Signature, BindNakEEInfoSignature, sizeof(UUID)) == 0);
  176. return (BindNak->common.frag_length - BindNakSizeWithoutEEInfo);
  177. }
  178. const int MinimumBindNakLength = 21;
  179. typedef struct
  180. {
  181. rpcconn_common common;
  182. unsigned char auth_type;
  183. unsigned char auth_level;
  184. #ifndef WIN32RPC
  185. unsigned short pad;
  186. #endif // WIN32RPC
  187. } rpcconn_auth3;
  188. typedef rpcconn_bind rpcconn_alter_context;
  189. typedef struct
  190. {
  191. rpcconn_common common;
  192. unsigned short max_xmit_frag;
  193. unsigned short max_recv_frag;
  194. unsigned long assoc_group_id;
  195. unsigned short sec_addr_length;
  196. unsigned short pad;
  197. } rpcconn_alter_context_resp;
  198. typedef struct
  199. {
  200. rpcconn_common common;
  201. unsigned long alloc_hint;
  202. p_context_id_t p_cont_id;
  203. unsigned short opnum;
  204. } rpcconn_request;
  205. typedef struct
  206. {
  207. rpcconn_common common;
  208. unsigned long alloc_hint;
  209. p_context_id_t p_cont_id;
  210. unsigned char alert_count;
  211. unsigned char reserved;
  212. } rpcconn_response;
  213. const unsigned char FaultEEInfoPresent = 1;
  214. typedef struct
  215. {
  216. rpcconn_common common;
  217. unsigned long alloc_hint;
  218. p_context_id_t p_cont_id;
  219. unsigned char alert_count;
  220. unsigned char reserved;
  221. unsigned long status;
  222. unsigned long reserved2;
  223. // present only if reserved & FaultEEInfoPresent
  224. // the actual length is alloc_hint - FIELD_OFFSET(rpcconn_fault, buffer)
  225. unsigned char buffer[1];
  226. } rpcconn_fault;
  227. const size_t FaultSizeWithoutEEInfo = FIELD_OFFSET(rpcconn_fault, buffer);
  228. inline size_t GetEEInfoSizeFromFaultPacket (rpcconn_fault *Fault)
  229. {
  230. CORRUPTION_ASSERT (Fault->reserved & FaultEEInfoPresent);
  231. CORRUPTION_ASSERT (Fault->alloc_hint > 0);
  232. return (Fault->alloc_hint - FaultSizeWithoutEEInfo);
  233. }
  234. const ULONG SecurityContextIdWireRep = 1;
  235. typedef struct
  236. {
  237. unsigned char auth_type;
  238. unsigned char auth_level;
  239. unsigned char auth_pad_length;
  240. unsigned char auth_reserved;
  241. unsigned long auth_context_id;
  242. } sec_trailer;
  243. const unsigned char SecVerificationTrailerSignature[] = {0x8a, 0xe3, 0x13, 0x71, 0x02, 0xf4, 0x36, 0x71};
  244. #define SEC_VT_MUST_PROCESS_COMMAND 0x8000
  245. #define SEC_VT_COMMAND_END 0x4000
  246. #define SEC_VT_COMMAND_CODE_MASK 0x3FFF
  247. typedef struct
  248. {
  249. USHORT command; // most significant bit may be SEC_VT_MUST_PROCESS_COMMAND
  250. USHORT length;
  251. // actual data will sit here
  252. } rpc_sec_verification_trailer_command;
  253. typedef struct
  254. {
  255. unsigned char signature[8]; // must be SecVerificationTrailerSignature
  256. } rpc_sec_verification_trailer;
  257. // the verification trailer is always 4 byte aligned. This means the maximum gap is
  258. // 3 bytes
  259. #define MAX_RPC_SEC_VT_ALIGN 3
  260. #define SEC_VT_COMMAND_BITMASK_1 0x0001
  261. #define SEC_VT_COMMAND_PCONTEXT 0x0002
  262. #define SEC_VT_COMMAND_HEADER2 0x0003
  263. #define CLIENT_SUPPORT_HEADER_SIGNING 0x1
  264. typedef struct
  265. {
  266. rpc_sec_verification_trailer_command command_common;
  267. ULONG bits;
  268. } rpc_sec_vt_bitmask;
  269. typedef struct
  270. {
  271. rpc_sec_verification_trailer_command command_common;
  272. RPC_SYNTAX_IDENTIFIER InterfaceId;
  273. RPC_SYNTAX_IDENTIFIER TransferSyntax;
  274. } rpc_sec_vt_pcontext;
  275. typedef struct
  276. {
  277. rpc_sec_verification_trailer_command command_common;
  278. unsigned char PTYPE;
  279. unsigned char Reserved1;
  280. unsigned short Reserved2;
  281. unsigned char drep[4];
  282. unsigned long call_id;
  283. p_context_id_t p_cont_id;
  284. unsigned short opnum;
  285. } rpc_sec_vt_header2;
  286. typedef struct tagChannelSettingCookie
  287. {
  288. char Cookie[16];
  289. } ChannelSettingCookie;
  290. #define COOKIE_SIZE_IN_BYTES 16
  291. #define MAX_IPv4_ADDRESS_SIZE 16 // sizeof(SOCKADDR_IN)
  292. #define MAX_IPv6_ADDRESS_SIZE 28 // sizeof(SOCKADDR_IN6)
  293. #define MAX_ADDRESS_SIZE max(MAX_IPv4_ADDRESS_SIZE, MAX_IPv6_ADDRESS_SIZE)
  294. #define RTS_FLAG_PING 0x1
  295. #define RTS_FLAG_OTHER_CMD 0x2
  296. #define RTS_FLAG_RECYCLE_CHANNEL 0x4
  297. #define RTS_FLAG_IN_CHANNEL 0x8
  298. #define RTS_FLAG_OUT_CHANNEL 0x10
  299. #define RTS_FLAG_EOF 0x20
  300. #define RTS_FLAG_ECHO 0x40
  301. typedef enum tagClientAddressType
  302. {
  303. catIPv4 = 0,
  304. catIPv6
  305. } ClientAddressType;
  306. typedef struct tagChannelSettingClientAddress
  307. {
  308. // provide enough storage for IPv6 address. Declared in this
  309. // form to avoid general runtime dependency on transport headers
  310. // In reality this is SOCKADDR_IN for IPv4 and SOCKADDR_IN6 for
  311. // IPv6
  312. ClientAddressType AddressType;
  313. union
  314. {
  315. /*[case(catIPv4)]*/ char IPv4Address[MAX_IPv4_ADDRESS_SIZE];
  316. /*[case(catIPv6)]*/ char IPv6Address[MAX_IPv6_ADDRESS_SIZE];
  317. } u;
  318. } ChannelSettingClientAddress;
  319. typedef enum tagForwardDestinations
  320. {
  321. fdClient = 0,
  322. fdInProxy,
  323. fdServer,
  324. fdOutProxy
  325. } ForwardDestinations;
  326. typedef struct tagFlowControlAck
  327. {
  328. ULONG BytesReceived;
  329. ULONG AvailableWindow;
  330. ChannelSettingCookie ChannelCookie;
  331. } FlowControlAck;
  332. typedef enum tagTunnelSettingsCommandTypes
  333. {
  334. tsctReceiveWindowSize = 0, // 0
  335. tsctFlowControlAck, // 1
  336. tsctConnectionTimeout, // 2
  337. tsctCookie, // 3
  338. tsctChannelLifetime, // 4
  339. tsctClientKeepalive, // 5
  340. tsctVersion, // 6
  341. tsctEmpty, // 7
  342. tsctPadding, // 8
  343. tsctNANCE, // 9
  344. tsctANCE, // 10
  345. tsctClientAddress, // 11
  346. tsctAssociationGroupId, // 12
  347. tsctDestination, // 13
  348. tsctPingTrafficSentNotify // 14
  349. } TunnelSettingsCommandTypes;
  350. #define LAST_RTS_COMMAND (tsctPingTrafficSentNotify)
  351. extern const int TunnelSettingsCommandTypeSizes[];
  352. typedef struct tagTunnelSettingsCommand
  353. {
  354. unsigned long CommandType;
  355. union
  356. {
  357. /*[case(tsctReceiveWindowSize)]*/ ULONG ReceiveWindowSize;
  358. /*[case(tsctFlowControlAck)]*/ FlowControlAck Ack;
  359. /*[case(tsctConnectionTimeout)]*/ ULONG ConnectionTimeout; // in milliseconds
  360. /*[case(tsctCookie)]*/ ChannelSettingCookie Cookie;
  361. /*[case(tsctChannelLifetime)]*/ ULONG ChannelLifetime;
  362. /*[case(tsctClientKeepalive)]*/ ULONG ClientKeepalive; // in milliseconds
  363. /*[case(tsctVersion)]*/ ULONG Version;
  364. /*[case(tsctEmpty)] ; */ // empty - no operands
  365. /*[case(tsctPadding)] ; */ ULONG ConformanceCount; // in bytes
  366. /*[case(tsctNANCE)] ; */ // NANCE - negative acknowledgement for new channel
  367. // establishment - no operands
  368. /*[case(tsctANCE)] ; */ // ANCE - acknowledge new channel establishment
  369. /*[case(tsctClientAddress)]*/ ChannelSettingClientAddress ClientAddress;
  370. /*[case(tsctAssociationGroupId)]*/ ChannelSettingCookie AssociationGroupId;
  371. /*[case(tsctDestination)]*/ ULONG Destination; // actually one of ForwardDestinations
  372. /*[case(tsctPingTrafficSentNotify)]*/ ULONG PingTrafficSent; // in bytes
  373. } u;
  374. } TunnelSettingsCommand;
  375. typedef struct {
  376. rpcconn_common common;
  377. unsigned short Flags;
  378. unsigned short NumberOfSettingCommands;
  379. TunnelSettingsCommand Cmd[1]; // the actual size depends on NumberOfSettings
  380. } rpcconn_tunnel_settings;
  381. #define SIZE_OF_RTS_CMD_AND_PADDING(Command) \
  382. (TunnelSettingsCommandTypeSizes[Command] \
  383. + ConstPadN(TunnelSettingsCommandTypeSizes[Command], 4))
  384. #define MUST_RECV_FRAG_SIZE 2048
  385. #define NDR_DREP_ASCII 0x00
  386. #define NDR_DREP_EBCDIC 0x01
  387. #define NDR_DREP_CHARACTER_MASK 0x0F
  388. #define NDR_DREP_BIG_ENDIAN 0x00
  389. #define NDR_DREP_LITTLE_ENDIAN 0x10
  390. #define NDR_DREP_ENDIAN_MASK 0xF0
  391. #define NDR_DREP_IEEE 0x00
  392. #define NDR_DREP_VAX 0x01
  393. #define NDR_DREP_CRAY 0x02
  394. #define NDR_DREP_IBM 0x03
  395. #ifdef MAC
  396. #define NDR_LOCAL_CHAR_DREP NDR_DREP_ASCII
  397. #define NDR_LOCAL_INT_DREP NDR_DREP_BIG_ENDIAN
  398. #define NDR_LOCAL_FP_DREP NDR_DREP_IEEE
  399. #else
  400. #define NDR_LOCAL_CHAR_DREP NDR_DREP_ASCII
  401. #define NDR_LOCAL_INT_DREP NDR_DREP_LITTLE_ENDIAN
  402. #define NDR_LOCAL_FP_DREP NDR_DREP_IEEE
  403. #endif
  404. /*++
  405. Routine Description:
  406. This macro determines whether or not we need to do endian data
  407. conversion.
  408. Argument:
  409. drep - Supplies the four byte data representation.
  410. Return Value:
  411. A value of non-zero indicates that endian data conversion needs to
  412. be performed.
  413. --*/
  414. #define DataConvertEndian(drep) \
  415. ( (drep[0] & NDR_DREP_ENDIAN_MASK) != NDR_LOCAL_INT_DREP )
  416. /*++
  417. Routine Description:
  418. This macro determines whether or not we need to do character data
  419. conversion.
  420. Argument:
  421. drep - Supplies the four byte data representation.
  422. Return Value:
  423. A value of non-zero indicates that character data conversion needs to
  424. be performed.
  425. --*/
  426. #define DataConvertCharacter(drep) \
  427. ( (drep[0] & NDR_DREP_CHARACTER_MASK) != NDR_LOCAL_CHAR_DREP)
  428. void
  429. ConstructPacket (
  430. IN OUT rpcconn_common PAPI * Packet,
  431. IN unsigned char PacketType,
  432. IN unsigned int PacketLength
  433. );
  434. RPC_STATUS
  435. ValidatePacket (
  436. IN rpcconn_common PAPI * Packet,
  437. IN unsigned int PacketLength
  438. );
  439. void
  440. ByteSwapSyntaxId (
  441. IN p_syntax_id_t PAPI * SyntaxId
  442. );
  443. #if 0
  444. void
  445. ConvertStringEbcdicToAscii (
  446. IN unsigned char * String
  447. );
  448. #endif
  449. extern unsigned long __RPC_FAR
  450. MapToNcaStatusCode (
  451. IN RPC_STATUS RpcStatus
  452. );
  453. extern RPC_STATUS __RPC_FAR
  454. MapFromNcaStatusCode (
  455. IN unsigned long NcaStatus
  456. );
  457. #if 1
  458. #define CoAllocateBuffer(_x_) RpcAllocateBuffer((_x_))
  459. #define CoFreeBuffer(_x_) RpcFreeBuffer((_x_))
  460. #else
  461. #define CoAllocateBuffer(_x_) RpcpFarAllocate((_x_))
  462. #define CoFreeBuffer(_x_) RpcpFarFree((_x_))
  463. #endif
  464. #endif // __OSFPCKET_HXX__