rpc_cmsg.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /*
  2. * rpc_callmsg.c
  3. *
  4. * Copyright (c) 2010, Oracle America, Inc.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions are
  8. * met:
  9. *
  10. * * Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * * Redistributions in binary form must reproduce the above
  13. * copyright notice, this list of conditions and the following
  14. * disclaimer in the documentation and/or other materials
  15. * provided with the distribution.
  16. * * Neither the name of the "Oracle America, Inc." nor the names of its
  17. * contributors may be used to endorse or promote products derived
  18. * from this software without specific prior written permission.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  23. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  24. * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  25. * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  26. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  27. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  28. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  29. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  30. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. */
  33. #include <string.h>
  34. #include <sys/param.h>
  35. #include <rpc/rpc.h>
  36. #include <shlib-compat.h>
  37. /*
  38. * XDR a call message
  39. */
  40. bool_t
  41. xdr_callmsg (XDR *xdrs, struct rpc_msg *cmsg)
  42. {
  43. int32_t *buf;
  44. struct opaque_auth *oa;
  45. if (xdrs->x_op == XDR_ENCODE)
  46. {
  47. if (cmsg->rm_call.cb_cred.oa_length > MAX_AUTH_BYTES)
  48. {
  49. return (FALSE);
  50. }
  51. if (cmsg->rm_call.cb_verf.oa_length > MAX_AUTH_BYTES)
  52. {
  53. return (FALSE);
  54. }
  55. buf = XDR_INLINE (xdrs, 8 * BYTES_PER_XDR_UNIT
  56. + RNDUP (cmsg->rm_call.cb_cred.oa_length)
  57. + 2 * BYTES_PER_XDR_UNIT
  58. + RNDUP (cmsg->rm_call.cb_verf.oa_length));
  59. if (buf != NULL)
  60. {
  61. (void) IXDR_PUT_LONG (buf, cmsg->rm_xid);
  62. (void) IXDR_PUT_ENUM (buf, cmsg->rm_direction);
  63. if (cmsg->rm_direction != CALL)
  64. return FALSE;
  65. (void) IXDR_PUT_LONG (buf, cmsg->rm_call.cb_rpcvers);
  66. if (cmsg->rm_call.cb_rpcvers != RPC_MSG_VERSION)
  67. return FALSE;
  68. (void) IXDR_PUT_LONG (buf, cmsg->rm_call.cb_prog);
  69. (void) IXDR_PUT_LONG (buf, cmsg->rm_call.cb_vers);
  70. (void) IXDR_PUT_LONG (buf, cmsg->rm_call.cb_proc);
  71. oa = &cmsg->rm_call.cb_cred;
  72. (void) IXDR_PUT_ENUM (buf, oa->oa_flavor);
  73. (void) IXDR_PUT_INT32 (buf, oa->oa_length);
  74. if (oa->oa_length)
  75. {
  76. memcpy ((caddr_t) buf, oa->oa_base, oa->oa_length);
  77. buf = (int32_t *) ((char *) buf + RNDUP (oa->oa_length));
  78. }
  79. oa = &cmsg->rm_call.cb_verf;
  80. (void) IXDR_PUT_ENUM (buf, oa->oa_flavor);
  81. (void) IXDR_PUT_INT32 (buf, oa->oa_length);
  82. if (oa->oa_length)
  83. {
  84. memcpy ((caddr_t) buf, oa->oa_base, oa->oa_length);
  85. /* no real need....
  86. buf = (long *) ((char *) buf + RNDUP(oa->oa_length));
  87. */
  88. }
  89. return TRUE;
  90. }
  91. }
  92. if (xdrs->x_op == XDR_DECODE)
  93. {
  94. buf = XDR_INLINE (xdrs, 8 * BYTES_PER_XDR_UNIT);
  95. if (buf != NULL)
  96. {
  97. cmsg->rm_xid = IXDR_GET_LONG (buf);
  98. cmsg->rm_direction = IXDR_GET_ENUM (buf, enum msg_type);
  99. if (cmsg->rm_direction != CALL)
  100. {
  101. return FALSE;
  102. }
  103. cmsg->rm_call.cb_rpcvers = IXDR_GET_LONG (buf);
  104. if (cmsg->rm_call.cb_rpcvers != RPC_MSG_VERSION)
  105. {
  106. return FALSE;
  107. }
  108. cmsg->rm_call.cb_prog = IXDR_GET_LONG (buf);
  109. cmsg->rm_call.cb_vers = IXDR_GET_LONG (buf);
  110. cmsg->rm_call.cb_proc = IXDR_GET_LONG (buf);
  111. oa = &cmsg->rm_call.cb_cred;
  112. oa->oa_flavor = IXDR_GET_ENUM (buf, enum_t);
  113. oa->oa_length = IXDR_GET_INT32 (buf);
  114. if (oa->oa_length)
  115. {
  116. if (oa->oa_length > MAX_AUTH_BYTES)
  117. return FALSE;
  118. if (oa->oa_base == NULL)
  119. {
  120. oa->oa_base = (caddr_t)
  121. mem_alloc (oa->oa_length);
  122. }
  123. buf = XDR_INLINE (xdrs, RNDUP (oa->oa_length));
  124. if (buf == NULL)
  125. {
  126. if (xdr_opaque (xdrs, oa->oa_base,
  127. oa->oa_length) == FALSE)
  128. return FALSE;
  129. }
  130. else
  131. {
  132. memcpy (oa->oa_base, (caddr_t) buf, oa->oa_length);
  133. /* no real need....
  134. buf = (long *) ((char *) buf
  135. + RNDUP(oa->oa_length));
  136. */
  137. }
  138. }
  139. oa = &cmsg->rm_call.cb_verf;
  140. buf = XDR_INLINE (xdrs, 2 * BYTES_PER_XDR_UNIT);
  141. if (buf == NULL)
  142. {
  143. if (xdr_enum (xdrs, &oa->oa_flavor) == FALSE ||
  144. xdr_u_int (xdrs, &oa->oa_length) == FALSE)
  145. {
  146. return FALSE;
  147. }
  148. }
  149. else
  150. {
  151. oa->oa_flavor = IXDR_GET_ENUM (buf, enum_t);
  152. oa->oa_length = IXDR_GET_INT32 (buf);
  153. }
  154. if (oa->oa_length)
  155. {
  156. if (oa->oa_length > MAX_AUTH_BYTES)
  157. return FALSE;
  158. if (oa->oa_base == NULL)
  159. {
  160. oa->oa_base = (caddr_t)
  161. mem_alloc (oa->oa_length);
  162. }
  163. buf = XDR_INLINE (xdrs, RNDUP (oa->oa_length));
  164. if (buf == NULL)
  165. {
  166. if (xdr_opaque (xdrs, oa->oa_base,
  167. oa->oa_length) == FALSE)
  168. return FALSE;
  169. }
  170. else
  171. {
  172. memcpy (oa->oa_base, (caddr_t) buf, oa->oa_length);
  173. /* no real need...
  174. buf = (long *) ((char *) buf
  175. + RNDUP(oa->oa_length));
  176. */
  177. }
  178. }
  179. return TRUE;
  180. }
  181. }
  182. if (
  183. xdr_u_long (xdrs, &(cmsg->rm_xid)) &&
  184. xdr_enum (xdrs, (enum_t *) & (cmsg->rm_direction)) &&
  185. (cmsg->rm_direction == CALL) &&
  186. xdr_u_long (xdrs, &(cmsg->rm_call.cb_rpcvers)) &&
  187. (cmsg->rm_call.cb_rpcvers == RPC_MSG_VERSION) &&
  188. xdr_u_long (xdrs, &(cmsg->rm_call.cb_prog)) &&
  189. xdr_u_long (xdrs, &(cmsg->rm_call.cb_vers)) &&
  190. xdr_u_long (xdrs, &(cmsg->rm_call.cb_proc)) &&
  191. xdr_opaque_auth (xdrs, &(cmsg->rm_call.cb_cred)))
  192. return xdr_opaque_auth (xdrs, &(cmsg->rm_call.cb_verf));
  193. return FALSE;
  194. }
  195. libc_hidden_nolink_sunrpc (xdr_callmsg, GLIBC_2_0)