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.

286 lines
6.4 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1991 - 1999
  3. Module Name:
  4. osfpcket.cxx
  5. Abstract:
  6. This file provides helper routines for dealing with packets for the
  7. OSF Connection Oriented RPC protocol.
  8. Author:
  9. Michael Montague (mikemon) 23-Jul-1990
  10. Revision History:
  11. 30-Apr-1991 o-decjt
  12. Initialized the drep[4] fields to reflect integer, character,
  13. and floating point format.
  14. --*/
  15. #include <precomp.hxx>
  16. #include <osfpcket.hxx>
  17. void
  18. ConstructPacket (
  19. IN OUT rpcconn_common PAPI * Packet,
  20. IN unsigned char PacketType,
  21. IN unsigned int PacketLength
  22. )
  23. /*++
  24. Routine Description:
  25. This routine fills in the common fields of a packet, except for the
  26. call_id.
  27. Arguments:
  28. Packet - Supplies the packet for which we want to fill in the common
  29. fields; returns the filled in packet.
  30. PacketType - Supplies the type of the packet; this is one of the values
  31. in the rpc_ptype_t enumeration.
  32. PacketLength - Supplies the total length of the packet in bytes.
  33. --*/
  34. {
  35. Packet->rpc_vers = OSF_RPC_V20_VERS;
  36. Packet->rpc_vers_minor = OSF_RPC_V20_VERS_MINOR;
  37. Packet->PTYPE = PacketType;
  38. Packet->pfc_flags = 0;
  39. Packet->drep[0] = NDR_LOCAL_CHAR_DREP | NDR_LOCAL_INT_DREP;
  40. Packet->drep[1] = NDR_LOCAL_FP_DREP;
  41. Packet->drep[2] = 0;
  42. Packet->drep[3] = 0;
  43. Packet->frag_length = (unsigned short) PacketLength;
  44. Packet->auth_length = 0;
  45. }
  46. unsigned int PacketSizes[] =
  47. {
  48. sizeof(rpc_request), // = 0
  49. 0, // = 1
  50. sizeof(rpc_response),// = 2
  51. sizeof(rpc_fault),// = 3
  52. 0,// = 4
  53. 0,// = 5
  54. 0,// = 6
  55. 0,// = 7
  56. 0,// = 8
  57. 0,// = 9
  58. 0,// = 10
  59. sizeof(rpc_bind),// = 11,
  60. sizeof(rpc_bind_ack),// = 12,
  61. sizeof(rpc_bind_nak),// = 13,
  62. sizeof(rpc_alter_context),// = 14,
  63. sizeof(rpc_alter_context_resp),// = 15,
  64. sizeof(rpc_auth_3),// = 16,
  65. sizeof(rpc_shutdown),// = 17,
  66. sizeof(rpc_cancel),// = 18,
  67. sizeof(rpc_orphaned) // = 19
  68. };
  69. unsigned int
  70. MinPacketLength (
  71. IN rpcconn_common PAPI *Packet
  72. )
  73. {
  74. unsigned int Size;
  75. if (Packet->PTYPE > rpc_orphaned)
  76. {
  77. return 0;
  78. }
  79. Size = PacketSizes[Packet->PTYPE];
  80. if (Size == 0)
  81. {
  82. return 0;
  83. }
  84. if (Packet->pfc_flags & PFC_OBJECT_UUID)
  85. {
  86. Size += sizeof(UUID);
  87. }
  88. if (Packet->auth_length)
  89. {
  90. Size += Packet->auth_length+sizeof(sec_trailer);
  91. if (Size > Packet->frag_length)
  92. {
  93. return 0;
  94. }
  95. sec_trailer * SecurityTrailer = (sec_trailer *) (((unsigned char *) Packet)
  96. + Packet->frag_length - Packet->auth_length - sizeof(sec_trailer));
  97. Size += SecurityTrailer->auth_pad_length;
  98. }
  99. return Size;
  100. }
  101. RPC_STATUS
  102. ValidatePacket (
  103. IN rpcconn_common PAPI * Packet,
  104. IN unsigned int PacketLength
  105. )
  106. /*++
  107. Routine Description:
  108. This is the routine used to validate a packet and perform data
  109. conversion, if necessary of the common part of a packet. In addition,
  110. to data converting the common part of a packet, we data convert the
  111. rest of the headers of rpc_request, rpc_response, and rpc_fault packets.
  112. Arguments:
  113. Packet - Supplies the packet to validate and data convert (if
  114. necessary).
  115. PacketLength - Supplies the length of the packet as reported by the
  116. transport.
  117. Return Value:
  118. RPC_S_OK - The packet has been successfully validated and the data
  119. converted (if necessary).
  120. RPC_S_PROTOCOL_ERROR - The supplied packet does not contain an rpc
  121. protocol version which we recognize.
  122. --*/
  123. {
  124. if ( DataConvertEndian(Packet->drep) != 0 )
  125. {
  126. // We need to data convert the packet.
  127. Packet->frag_length = RpcpByteSwapShort(Packet->frag_length);
  128. Packet->auth_length = RpcpByteSwapShort(Packet->auth_length);
  129. Packet->call_id = RpcpByteSwapLong(Packet->call_id);
  130. if ( (Packet->PTYPE == rpc_request)
  131. || (Packet->PTYPE == rpc_response)
  132. || (Packet->PTYPE == rpc_fault))
  133. {
  134. ((rpcconn_request PAPI *) Packet)->alloc_hint =
  135. RpcpByteSwapLong(((rpcconn_request PAPI *) Packet)->alloc_hint);
  136. ((rpcconn_request PAPI *) Packet)->p_cont_id
  137. = RpcpByteSwapShort(((rpcconn_request PAPI *) Packet)->p_cont_id);
  138. if ( Packet->PTYPE == rpc_request )
  139. {
  140. ((rpcconn_request PAPI *) Packet)->opnum =
  141. RpcpByteSwapShort(((rpcconn_request PAPI *) Packet)->opnum);
  142. }
  143. }
  144. }
  145. else if ( (Packet->drep[0] & NDR_DREP_ENDIAN_MASK) != NDR_LOCAL_INT_DREP )
  146. {
  147. return(RPC_S_PROTOCOL_ERROR);
  148. }
  149. if (Packet->frag_length != (unsigned short) PacketLength)
  150. {
  151. ASSERT(0);
  152. return (RPC_S_PROTOCOL_ERROR);
  153. }
  154. unsigned int MinLength = MinPacketLength(Packet);
  155. if (MinLength == 0 || MinLength > PacketLength)
  156. {
  157. return (RPC_S_PROTOCOL_ERROR);
  158. }
  159. if ( (Packet->rpc_vers != OSF_RPC_V20_VERS)
  160. || (Packet->rpc_vers_minor > OSF_RPC_V20_VERS_MINOR))
  161. {
  162. return(RPC_S_PROTOCOL_ERROR);
  163. }
  164. return(RPC_S_OK);
  165. }
  166. void
  167. ByteSwapSyntaxId (
  168. IN p_syntax_id_t PAPI * SyntaxId
  169. )
  170. /*++
  171. Routine Description:
  172. This routine is used to perform data conversion in a syntax identifier
  173. if necessary.
  174. Arguments:
  175. SyntaxId - Supplies the syntax identifier to be byte swapped.
  176. --*/
  177. {
  178. ByteSwapUuid((RPC_UUID *)&SyntaxId->if_uuid);
  179. SyntaxId->if_version = RpcpByteSwapLong(SyntaxId->if_version);
  180. }
  181. #if 0
  182. void
  183. ConvertStringEbcdicToAscii (
  184. IN unsigned char * String
  185. )
  186. /*++
  187. Routine Description:
  188. We will convert a zero terminated character string from EBCDIC to
  189. ASCII. The conversion will be done in place.
  190. Arguments:
  191. String - Supplies the string to be converted.
  192. --*/
  193. {
  194. UNUSED(String);
  195. ASSERT(!RPC_S_CANNOT_SUPPORT);
  196. }
  197. #endif
  198. void
  199. UnpickleEEInfoFromBuffer (
  200. IN PVOID Buffer,
  201. IN size_t SizeOfPickledData
  202. )
  203. {
  204. RPC_STATUS RpcStatus;
  205. ExtendedErrorInfo *EEInfo;
  206. ASSERT(IsBufferAligned(Buffer));
  207. ASSERT(RpcpGetEEInfo() == NULL);
  208. RpcStatus = UnpickleEEInfo((unsigned char *)Buffer,
  209. SizeOfPickledData,
  210. &EEInfo);
  211. if (RpcStatus == RPC_S_OK)
  212. {
  213. StripComputerNameIfRedundant(EEInfo);
  214. RpcpSetEEInfo(EEInfo);
  215. }
  216. }