Update.
[glibc.git] / sunrpc / rpc_cmsg.c
blob4cd2a8f35a04fbcdf79b450055f03eff05476e93
1 /* @(#)rpc_callmsg.c 2.1 88/07/29 4.0 RPCSRC */
2 /*
3 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
4 * unrestricted use provided that this legend is included on all tape
5 * media and as a part of the software program in whole or part. Users
6 * may copy or modify Sun RPC without charge, but are not authorized
7 * to license or distribute it to anyone else except as part of a product or
8 * program developed by the user.
10 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
11 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
12 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
14 * Sun RPC is provided with no support and without any obligation on the
15 * part of Sun Microsystems, Inc. to assist in its use, correction,
16 * modification or enhancement.
18 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
19 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
20 * OR ANY PART THEREOF.
22 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
23 * or profits or other special, indirect and consequential damages, even if
24 * Sun has been advised of the possibility of such damages.
26 * Sun Microsystems, Inc.
27 * 2550 Garcia Avenue
28 * Mountain View, California 94043
30 #if !defined(lint) && defined(SCCSIDS)
31 static char sccsid[] = "@(#)rpc_callmsg.c 1.4 87/08/11 Copyr 1984 Sun Micro";
32 #endif
35 * rpc_callmsg.c
37 * Copyright (C) 1984, Sun Microsystems, Inc.
41 #include <string.h>
42 #include <sys/param.h>
43 #include <rpc/rpc.h>
46 * XDR a call message
48 bool_t
49 xdr_callmsg (XDR *xdrs, struct rpc_msg *cmsg)
51 long *buf;
52 struct opaque_auth *oa;
54 if (xdrs->x_op == XDR_ENCODE)
56 if (cmsg->rm_call.cb_cred.oa_length > MAX_AUTH_BYTES)
58 return (FALSE);
60 if (cmsg->rm_call.cb_verf.oa_length > MAX_AUTH_BYTES)
62 return (FALSE);
64 buf = XDR_INLINE (xdrs, 8 * BYTES_PER_XDR_UNIT
65 + RNDUP (cmsg->rm_call.cb_cred.oa_length)
66 + 2 * BYTES_PER_XDR_UNIT
67 + RNDUP (cmsg->rm_call.cb_verf.oa_length));
68 if (buf != NULL)
70 IXDR_PUT_LONG (buf, cmsg->rm_xid);
71 IXDR_PUT_ENUM (buf, cmsg->rm_direction);
72 if (cmsg->rm_direction != CALL)
74 return FALSE;
76 IXDR_PUT_LONG (buf, cmsg->rm_call.cb_rpcvers);
77 if (cmsg->rm_call.cb_rpcvers != RPC_MSG_VERSION)
79 return FALSE;
81 IXDR_PUT_LONG (buf, cmsg->rm_call.cb_prog);
82 IXDR_PUT_LONG (buf, cmsg->rm_call.cb_vers);
83 IXDR_PUT_LONG (buf, cmsg->rm_call.cb_proc);
84 oa = &cmsg->rm_call.cb_cred;
85 IXDR_PUT_ENUM (buf, oa->oa_flavor);
86 IXDR_PUT_LONG (buf, oa->oa_length);
87 if (oa->oa_length)
89 bcopy (oa->oa_base, (caddr_t) buf, oa->oa_length);
90 buf = (long *) ((char *) buf + RNDUP (oa->oa_length));
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)
97 bcopy (oa->oa_base, (caddr_t) buf, oa->oa_length);
98 /* no real need....
99 buf = (long *) ((char *) buf + RNDUP(oa->oa_length));
102 return TRUE;
105 if (xdrs->x_op == XDR_DECODE)
107 buf = XDR_INLINE (xdrs, 8 * BYTES_PER_XDR_UNIT);
108 if (buf != NULL)
110 cmsg->rm_xid = IXDR_GET_LONG (buf);
111 cmsg->rm_direction = IXDR_GET_ENUM (buf, enum msg_type);
112 if (cmsg->rm_direction != CALL)
114 return FALSE;
116 cmsg->rm_call.cb_rpcvers = IXDR_GET_LONG (buf);
117 if (cmsg->rm_call.cb_rpcvers != RPC_MSG_VERSION)
119 return FALSE;
121 cmsg->rm_call.cb_prog = IXDR_GET_LONG (buf);
122 cmsg->rm_call.cb_vers = IXDR_GET_LONG (buf);
123 cmsg->rm_call.cb_proc = IXDR_GET_LONG (buf);
124 oa = &cmsg->rm_call.cb_cred;
125 oa->oa_flavor = IXDR_GET_ENUM (buf, enum_t);
126 oa->oa_length = IXDR_GET_LONG (buf);
127 if (oa->oa_length)
129 if (oa->oa_length > MAX_AUTH_BYTES)
131 return FALSE;
133 if (oa->oa_base == NULL)
135 oa->oa_base = (caddr_t)
136 mem_alloc (oa->oa_length);
138 buf = XDR_INLINE (xdrs, RNDUP (oa->oa_length));
139 if (buf == NULL)
141 if (xdr_opaque (xdrs, oa->oa_base,
142 oa->oa_length) == FALSE)
144 return FALSE;
147 else
149 bcopy ((caddr_t) buf, oa->oa_base,
150 oa->oa_length);
151 /* no real need....
152 buf = (long *) ((char *) buf
153 + RNDUP(oa->oa_length));
157 oa = &cmsg->rm_call.cb_verf;
158 buf = XDR_INLINE (xdrs, 2 * BYTES_PER_XDR_UNIT);
159 if (buf == NULL)
161 if (xdr_enum (xdrs, &oa->oa_flavor) == FALSE ||
162 xdr_u_int (xdrs, &oa->oa_length) == FALSE)
164 return FALSE;
167 else
169 oa->oa_flavor = IXDR_GET_ENUM (buf, enum_t);
170 oa->oa_length = IXDR_GET_LONG (buf);
172 if (oa->oa_length)
174 if (oa->oa_length > MAX_AUTH_BYTES)
176 return FALSE;
178 if (oa->oa_base == NULL)
180 oa->oa_base = (caddr_t)
181 mem_alloc (oa->oa_length);
183 buf = XDR_INLINE (xdrs, RNDUP (oa->oa_length));
184 if (buf == NULL)
186 if (xdr_opaque (xdrs, oa->oa_base,
187 oa->oa_length) == FALSE)
189 return FALSE;
192 else
194 bcopy ((caddr_t) buf, oa->oa_base,
195 oa->oa_length);
196 /* no real need...
197 buf = (long *) ((char *) buf
198 + RNDUP(oa->oa_length));
202 return TRUE;
205 if (
206 xdr_u_long (xdrs, &(cmsg->rm_xid)) &&
207 xdr_enum (xdrs, (enum_t *) & (cmsg->rm_direction)) &&
208 (cmsg->rm_direction == CALL) &&
209 xdr_u_long (xdrs, &(cmsg->rm_call.cb_rpcvers)) &&
210 (cmsg->rm_call.cb_rpcvers == RPC_MSG_VERSION) &&
211 xdr_u_long (xdrs, &(cmsg->rm_call.cb_prog)) &&
212 xdr_u_long (xdrs, &(cmsg->rm_call.cb_vers)) &&
213 xdr_u_long (xdrs, &(cmsg->rm_call.cb_proc)) &&
214 xdr_opaque_auth (xdrs, &(cmsg->rm_call.cb_cred)))
215 return xdr_opaque_auth (xdrs, &(cmsg->rm_call.cb_verf));
216 return FALSE;