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