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