Debian Codegraph @

extra/tirpc/libtirpc-1.3.5/src/rpc_callmsg.c

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