rpc_callmsg.c revision 1.7 1 /* $NetBSD: rpc_callmsg.c,v 1.7 1997/07/21 14:08:35 jtc Exp $ */
2
3 /*
4 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
5 * unrestricted use provided that this legend is included on all tape
6 * media and as a part of the software program in whole or part. Users
7 * may copy or modify Sun RPC without charge, but are not authorized
8 * to license or distribute it to anyone else except as part of a product or
9 * program developed by the user.
10 *
11 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
12 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
13 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
14 *
15 * Sun RPC is provided with no support and without any obligation on the
16 * part of Sun Microsystems, Inc. to assist in its use, correction,
17 * modification or enhancement.
18 *
19 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
20 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
21 * OR ANY PART THEREOF.
22 *
23 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
24 * or profits or other special, indirect and consequential damages, even if
25 * Sun has been advised of the possibility of such damages.
26 *
27 * Sun Microsystems, Inc.
28 * 2550 Garcia Avenue
29 * Mountain View, California 94043
30 */
31
32 #include <sys/cdefs.h>
33 #if defined(LIBC_SCCS) && !defined(lint)
34 #if 0
35 static char *sccsid = "@(#)rpc_callmsg.c 1.4 87/08/11 Copyr 1984 Sun Micro";
36 static char *sccsid = "@(#)rpc_callmsg.c 2.1 88/07/29 4.0 RPCSRC";
37 #else
38 __RCSID("$NetBSD: rpc_callmsg.c,v 1.7 1997/07/21 14:08:35 jtc Exp $");
39 #endif
40 #endif
41
42 /*
43 * rpc_callmsg.c
44 *
45 * Copyright (C) 1984, Sun Microsystems, Inc.
46 *
47 */
48
49 #include "namespace.h"
50 #include <stdlib.h>
51 #include <string.h>
52 #include <sys/param.h>
53 #include <rpc/rpc.h>
54
55 #ifdef __weak_alias
56 __weak_alias(xdr_callmsg,_xdr_callmsg);
57 #endif
58
59 /*
60 * XDR a call message
61 */
62 bool_t
63 xdr_callmsg(xdrs, cmsg)
64 register XDR *xdrs;
65 register struct rpc_msg *cmsg;
66 {
67 register int32_t *buf;
68 register struct opaque_auth *oa;
69
70 if (xdrs->x_op == XDR_ENCODE) {
71 if (cmsg->rm_call.cb_cred.oa_length > MAX_AUTH_BYTES) {
72 return (FALSE);
73 }
74 if (cmsg->rm_call.cb_verf.oa_length > MAX_AUTH_BYTES) {
75 return (FALSE);
76 }
77 buf = XDR_INLINE(xdrs, 8 * BYTES_PER_XDR_UNIT
78 + RNDUP(cmsg->rm_call.cb_cred.oa_length)
79 + 2 * BYTES_PER_XDR_UNIT
80 + RNDUP(cmsg->rm_call.cb_verf.oa_length));
81 if (buf != NULL) {
82 IXDR_PUT_LONG(buf, cmsg->rm_xid);
83 IXDR_PUT_ENUM(buf, cmsg->rm_direction);
84 if (cmsg->rm_direction != CALL) {
85 return (FALSE);
86 }
87 IXDR_PUT_LONG(buf, cmsg->rm_call.cb_rpcvers);
88 if (cmsg->rm_call.cb_rpcvers != RPC_MSG_VERSION) {
89 return (FALSE);
90 }
91 IXDR_PUT_LONG(buf, cmsg->rm_call.cb_prog);
92 IXDR_PUT_LONG(buf, cmsg->rm_call.cb_vers);
93 IXDR_PUT_LONG(buf, cmsg->rm_call.cb_proc);
94 oa = &cmsg->rm_call.cb_cred;
95 IXDR_PUT_ENUM(buf, oa->oa_flavor);
96 IXDR_PUT_LONG(buf, oa->oa_length);
97 if (oa->oa_length) {
98 bcopy(oa->oa_base, (caddr_t)buf, oa->oa_length);
99 buf += RNDUP(oa->oa_length) / sizeof (int32_t);
100 }
101 oa = &cmsg->rm_call.cb_verf;
102 IXDR_PUT_ENUM(buf, oa->oa_flavor);
103 IXDR_PUT_LONG(buf, oa->oa_length);
104 if (oa->oa_length) {
105 bcopy(oa->oa_base, (caddr_t)buf, oa->oa_length);
106 /* no real need....
107 buf += RNDUP(oa->oa_length) / sizeof (int32_t);
108 */
109 }
110 return (TRUE);
111 }
112 }
113 if (xdrs->x_op == XDR_DECODE) {
114 buf = XDR_INLINE(xdrs, 8 * BYTES_PER_XDR_UNIT);
115 if (buf != NULL) {
116 cmsg->rm_xid = IXDR_GET_LONG(buf);
117 cmsg->rm_direction = IXDR_GET_ENUM(buf, enum msg_type);
118 if (cmsg->rm_direction != CALL) {
119 return (FALSE);
120 }
121 cmsg->rm_call.cb_rpcvers = IXDR_GET_LONG(buf);
122 if (cmsg->rm_call.cb_rpcvers != RPC_MSG_VERSION) {
123 return (FALSE);
124 }
125 cmsg->rm_call.cb_prog = IXDR_GET_LONG(buf);
126 cmsg->rm_call.cb_vers = IXDR_GET_LONG(buf);
127 cmsg->rm_call.cb_proc = IXDR_GET_LONG(buf);
128 oa = &cmsg->rm_call.cb_cred;
129 oa->oa_flavor = IXDR_GET_ENUM(buf, enum_t);
130 oa->oa_length = IXDR_GET_LONG(buf);
131 if (oa->oa_length) {
132 if (oa->oa_length > MAX_AUTH_BYTES) {
133 return (FALSE);
134 }
135 if (oa->oa_base == NULL) {
136 oa->oa_base = (caddr_t)
137 mem_alloc(oa->oa_length);
138 }
139 buf = XDR_INLINE(xdrs, RNDUP(oa->oa_length));
140 if (buf == NULL) {
141 if (xdr_opaque(xdrs, oa->oa_base,
142 oa->oa_length) == FALSE) {
143 return (FALSE);
144 }
145 } else {
146 bcopy((caddr_t)buf, oa->oa_base,
147 oa->oa_length);
148 /* no real need....
149 buf += RNDUP(oa->oa_length) /
150 sizeof (int32_t);
151 */
152 }
153 }
154 oa = &cmsg->rm_call.cb_verf;
155 buf = XDR_INLINE(xdrs, 2 * BYTES_PER_XDR_UNIT);
156 if (buf == NULL) {
157 if (xdr_enum(xdrs, &oa->oa_flavor) == FALSE ||
158 xdr_u_int(xdrs, &oa->oa_length) == FALSE) {
159 return (FALSE);
160 }
161 } else {
162 oa->oa_flavor = IXDR_GET_ENUM(buf, enum_t);
163 oa->oa_length = IXDR_GET_LONG(buf);
164 }
165 if (oa->oa_length) {
166 if (oa->oa_length > MAX_AUTH_BYTES) {
167 return (FALSE);
168 }
169 if (oa->oa_base == NULL) {
170 oa->oa_base = (caddr_t)
171 mem_alloc(oa->oa_length);
172 }
173 buf = XDR_INLINE(xdrs, RNDUP(oa->oa_length));
174 if (buf == NULL) {
175 if (xdr_opaque(xdrs, oa->oa_base,
176 oa->oa_length) == FALSE) {
177 return (FALSE);
178 }
179 } else {
180 bcopy((caddr_t)buf, oa->oa_base,
181 oa->oa_length);
182 /* no real need...
183 buf += RNDUP(oa->oa_length) /
184 sizeof (int32_t);
185 */
186 }
187 }
188 return (TRUE);
189 }
190 }
191 if (
192 xdr_u_int32_t(xdrs, &(cmsg->rm_xid)) &&
193 xdr_enum(xdrs, (enum_t *)&(cmsg->rm_direction)) &&
194 (cmsg->rm_direction == CALL) &&
195 xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_rpcvers)) &&
196 (cmsg->rm_call.cb_rpcvers == RPC_MSG_VERSION) &&
197 xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_prog)) &&
198 xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_vers)) &&
199 xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_proc)) &&
200 xdr_opaque_auth(xdrs, &(cmsg->rm_call.cb_cred)) )
201 return (xdr_opaque_auth(xdrs, &(cmsg->rm_call.cb_verf)));
202 return (FALSE);
203 }
204
205