rpc_callmsg.c revision 1.4 1 /* $NetBSD: rpc_callmsg.c,v 1.4 1995/04/29 05:26:31 cgd 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 1995/04/29 05:26:31 cgd Exp $";
36 #endif
37
38 /*
39 * rpc_callmsg.c
40 *
41 * Copyright (C) 1984, Sun Microsystems, Inc.
42 *
43 */
44
45 #include <stdlib.h>
46 #include <sys/param.h>
47
48 #include <rpc/rpc.h>
49
50 /*
51 * XDR a call message
52 */
53 bool_t
54 xdr_callmsg(xdrs, cmsg)
55 register XDR *xdrs;
56 register struct rpc_msg *cmsg;
57 {
58 register int32_t *buf;
59 register struct opaque_auth *oa;
60
61 if (xdrs->x_op == XDR_ENCODE) {
62 if (cmsg->rm_call.cb_cred.oa_length > MAX_AUTH_BYTES) {
63 return (FALSE);
64 }
65 if (cmsg->rm_call.cb_verf.oa_length > MAX_AUTH_BYTES) {
66 return (FALSE);
67 }
68 buf = XDR_INLINE(xdrs, 8 * BYTES_PER_XDR_UNIT
69 + RNDUP(cmsg->rm_call.cb_cred.oa_length)
70 + 2 * BYTES_PER_XDR_UNIT
71 + RNDUP(cmsg->rm_call.cb_verf.oa_length));
72 if (buf != NULL) {
73 IXDR_PUT_LONG(buf, cmsg->rm_xid);
74 IXDR_PUT_ENUM(buf, cmsg->rm_direction);
75 if (cmsg->rm_direction != CALL) {
76 return (FALSE);
77 }
78 IXDR_PUT_LONG(buf, cmsg->rm_call.cb_rpcvers);
79 if (cmsg->rm_call.cb_rpcvers != RPC_MSG_VERSION) {
80 return (FALSE);
81 }
82 IXDR_PUT_LONG(buf, cmsg->rm_call.cb_prog);
83 IXDR_PUT_LONG(buf, cmsg->rm_call.cb_vers);
84 IXDR_PUT_LONG(buf, cmsg->rm_call.cb_proc);
85 oa = &cmsg->rm_call.cb_cred;
86 IXDR_PUT_ENUM(buf, oa->oa_flavor);
87 IXDR_PUT_LONG(buf, oa->oa_length);
88 if (oa->oa_length) {
89 bcopy(oa->oa_base, (caddr_t)buf, oa->oa_length);
90 buf += RNDUP(oa->oa_length) / sizeof (int32_t);
91 }
92 oa = &cmsg->rm_call.cb_verf;
93 IXDR_PUT_ENUM(buf, oa->oa_flavor);
94 IXDR_PUT_LONG(buf, oa->oa_length);
95 if (oa->oa_length) {
96 bcopy(oa->oa_base, (caddr_t)buf, oa->oa_length);
97 /* no real need....
98 buf += RNDUP(oa->oa_length) / sizeof (int32_t);
99 */
100 }
101 return (TRUE);
102 }
103 }
104 if (xdrs->x_op == XDR_DECODE) {
105 buf = XDR_INLINE(xdrs, 8 * BYTES_PER_XDR_UNIT);
106 if (buf != NULL) {
107 cmsg->rm_xid = IXDR_GET_LONG(buf);
108 cmsg->rm_direction = IXDR_GET_ENUM(buf, enum msg_type);
109 if (cmsg->rm_direction != CALL) {
110 return (FALSE);
111 }
112 cmsg->rm_call.cb_rpcvers = IXDR_GET_LONG(buf);
113 if (cmsg->rm_call.cb_rpcvers != RPC_MSG_VERSION) {
114 return (FALSE);
115 }
116 cmsg->rm_call.cb_prog = IXDR_GET_LONG(buf);
117 cmsg->rm_call.cb_vers = IXDR_GET_LONG(buf);
118 cmsg->rm_call.cb_proc = IXDR_GET_LONG(buf);
119 oa = &cmsg->rm_call.cb_cred;
120 oa->oa_flavor = IXDR_GET_ENUM(buf, enum_t);
121 oa->oa_length = IXDR_GET_LONG(buf);
122 if (oa->oa_length) {
123 if (oa->oa_length > MAX_AUTH_BYTES) {
124 return (FALSE);
125 }
126 if (oa->oa_base == NULL) {
127 oa->oa_base = (caddr_t)
128 mem_alloc(oa->oa_length);
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 bcopy((caddr_t)buf, oa->oa_base,
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 = IXDR_GET_LONG(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 }
164 buf = XDR_INLINE(xdrs, RNDUP(oa->oa_length));
165 if (buf == NULL) {
166 if (xdr_opaque(xdrs, oa->oa_base,
167 oa->oa_length) == FALSE) {
168 return (FALSE);
169 }
170 } else {
171 bcopy((caddr_t)buf, oa->oa_base,
172 oa->oa_length);
173 /* no real need...
174 buf += RNDUP(oa->oa_length) /
175 sizeof (int32_t);
176 */
177 }
178 }
179 return (TRUE);
180 }
181 }
182 if (
183 xdr_u_int32_t(xdrs, &(cmsg->rm_xid)) &&
184 xdr_enum(xdrs, (enum_t *)&(cmsg->rm_direction)) &&
185 (cmsg->rm_direction == CALL) &&
186 xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_rpcvers)) &&
187 (cmsg->rm_call.cb_rpcvers == RPC_MSG_VERSION) &&
188 xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_prog)) &&
189 xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_vers)) &&
190 xdr_u_int32_t(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
196