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 | |
34 | #include <string.h> |
35 | #include <sys/param.h> |
36 | #include <rpc/rpc.h> |
37 | |
38 | /* |
39 | * XDR a call message |
40 | */ |
41 | bool_t |
42 | xdr_callmsg (XDR *xdrs, struct rpc_msg *cmsg) |
43 | { |
44 | int32_t *buf; |
45 | struct opaque_auth *oa; |
46 | |
47 | if (xdrs->x_op == XDR_ENCODE) |
48 | { |
49 | if (cmsg->rm_call.cb_cred.oa_length > MAX_AUTH_BYTES) |
50 | { |
51 | return (FALSE); |
52 | } |
53 | if (cmsg->rm_call.cb_verf.oa_length > MAX_AUTH_BYTES) |
54 | { |
55 | return (FALSE); |
56 | } |
57 | buf = XDR_INLINE (xdrs, 8 * BYTES_PER_XDR_UNIT |
58 | + RNDUP (cmsg->rm_call.cb_cred.oa_length) |
59 | + 2 * BYTES_PER_XDR_UNIT |
60 | + RNDUP (cmsg->rm_call.cb_verf.oa_length)); |
61 | if (buf != NULL) |
62 | { |
63 | (void) IXDR_PUT_LONG (buf, cmsg->rm_xid); |
64 | (void) IXDR_PUT_ENUM (buf, cmsg->rm_direction); |
65 | if (cmsg->rm_direction != CALL) |
66 | return FALSE; |
67 | (void) IXDR_PUT_LONG (buf, cmsg->rm_call.cb_rpcvers); |
68 | if (cmsg->rm_call.cb_rpcvers != RPC_MSG_VERSION) |
69 | return FALSE; |
70 | (void) IXDR_PUT_LONG (buf, cmsg->rm_call.cb_prog); |
71 | (void) IXDR_PUT_LONG (buf, cmsg->rm_call.cb_vers); |
72 | (void) IXDR_PUT_LONG (buf, cmsg->rm_call.cb_proc); |
73 | oa = &cmsg->rm_call.cb_cred; |
74 | (void) IXDR_PUT_ENUM (buf, oa->oa_flavor); |
75 | (void) IXDR_PUT_INT32 (buf, oa->oa_length); |
76 | if (oa->oa_length) |
77 | { |
78 | memcpy ((caddr_t) buf, oa->oa_base, oa->oa_length); |
79 | buf = (int32_t *) ((char *) buf + RNDUP (oa->oa_length)); |
80 | } |
81 | oa = &cmsg->rm_call.cb_verf; |
82 | (void) IXDR_PUT_ENUM (buf, oa->oa_flavor); |
83 | (void) IXDR_PUT_INT32 (buf, oa->oa_length); |
84 | if (oa->oa_length) |
85 | { |
86 | memcpy ((caddr_t) buf, oa->oa_base, oa->oa_length); |
87 | /* no real need.... |
88 | buf = (long *) ((char *) buf + RNDUP(oa->oa_length)); |
89 | */ |
90 | } |
91 | return TRUE; |
92 | } |
93 | } |
94 | if (xdrs->x_op == XDR_DECODE) |
95 | { |
96 | buf = XDR_INLINE (xdrs, 8 * BYTES_PER_XDR_UNIT); |
97 | if (buf != NULL) |
98 | { |
99 | cmsg->rm_xid = IXDR_GET_LONG (buf); |
100 | cmsg->rm_direction = IXDR_GET_ENUM (buf, enum msg_type); |
101 | if (cmsg->rm_direction != CALL) |
102 | { |
103 | return FALSE; |
104 | } |
105 | cmsg->rm_call.cb_rpcvers = IXDR_GET_LONG (buf); |
106 | if (cmsg->rm_call.cb_rpcvers != RPC_MSG_VERSION) |
107 | { |
108 | return FALSE; |
109 | } |
110 | cmsg->rm_call.cb_prog = IXDR_GET_LONG (buf); |
111 | cmsg->rm_call.cb_vers = IXDR_GET_LONG (buf); |
112 | cmsg->rm_call.cb_proc = IXDR_GET_LONG (buf); |
113 | oa = &cmsg->rm_call.cb_cred; |
114 | oa->oa_flavor = IXDR_GET_ENUM (buf, enum_t); |
115 | oa->oa_length = IXDR_GET_INT32 (buf); |
116 | if (oa->oa_length) |
117 | { |
118 | if (oa->oa_length > MAX_AUTH_BYTES) |
119 | return FALSE; |
120 | if (oa->oa_base == NULL) |
121 | { |
122 | oa->oa_base = (caddr_t) |
123 | mem_alloc (oa->oa_length); |
124 | } |
125 | buf = XDR_INLINE (xdrs, RNDUP (oa->oa_length)); |
126 | if (buf == NULL) |
127 | { |
128 | if (xdr_opaque (xdrs, oa->oa_base, |
129 | oa->oa_length) == FALSE) |
130 | return FALSE; |
131 | } |
132 | else |
133 | { |
134 | memcpy (oa->oa_base, (caddr_t) buf, oa->oa_length); |
135 | /* no real need.... |
136 | buf = (long *) ((char *) buf |
137 | + RNDUP(oa->oa_length)); |
138 | */ |
139 | } |
140 | } |
141 | oa = &cmsg->rm_call.cb_verf; |
142 | buf = XDR_INLINE (xdrs, 2 * BYTES_PER_XDR_UNIT); |
143 | if (buf == NULL) |
144 | { |
145 | if (xdr_enum (xdrs, &oa->oa_flavor) == FALSE || |
146 | xdr_u_int (xdrs, &oa->oa_length) == FALSE) |
147 | { |
148 | return FALSE; |
149 | } |
150 | } |
151 | else |
152 | { |
153 | oa->oa_flavor = IXDR_GET_ENUM (buf, enum_t); |
154 | oa->oa_length = IXDR_GET_INT32 (buf); |
155 | } |
156 | if (oa->oa_length) |
157 | { |
158 | if (oa->oa_length > MAX_AUTH_BYTES) |
159 | return FALSE; |
160 | if (oa->oa_base == NULL) |
161 | { |
162 | oa->oa_base = (caddr_t) |
163 | mem_alloc (oa->oa_length); |
164 | } |
165 | buf = XDR_INLINE (xdrs, RNDUP (oa->oa_length)); |
166 | if (buf == NULL) |
167 | { |
168 | if (xdr_opaque (xdrs, oa->oa_base, |
169 | oa->oa_length) == FALSE) |
170 | return FALSE; |
171 | } |
172 | else |
173 | { |
174 | memcpy (oa->oa_base, (caddr_t) buf, oa->oa_length); |
175 | /* no real need... |
176 | buf = (long *) ((char *) buf |
177 | + RNDUP(oa->oa_length)); |
178 | */ |
179 | } |
180 | } |
181 | return TRUE; |
182 | } |
183 | } |
184 | if ( |
185 | xdr_u_long (xdrs, &(cmsg->rm_xid)) && |
186 | xdr_enum (xdrs, (enum_t *) & (cmsg->rm_direction)) && |
187 | (cmsg->rm_direction == CALL) && |
188 | xdr_u_long (xdrs, &(cmsg->rm_call.cb_rpcvers)) && |
189 | (cmsg->rm_call.cb_rpcvers == RPC_MSG_VERSION) && |
190 | xdr_u_long (xdrs, &(cmsg->rm_call.cb_prog)) && |
191 | xdr_u_long (xdrs, &(cmsg->rm_call.cb_vers)) && |
192 | xdr_u_long (xdrs, &(cmsg->rm_call.cb_proc)) && |
193 | xdr_opaque_auth (xdrs, &(cmsg->rm_call.cb_cred))) |
194 | return xdr_opaque_auth (xdrs, &(cmsg->rm_call.cb_verf)); |
195 | return FALSE; |
196 | } |
197 | libc_hidden_nolink_sunrpc (xdr_callmsg, GLIBC_2_0) |
198 | |