]> git.ipfire.org Git - thirdparty/glibc.git/blob - sunrpc/rpc_cmsg.c
Update.
[thirdparty/glibc.git] / sunrpc / rpc_cmsg.c
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.
9 *
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.
13 *
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.
17 *
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.
21 *
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.
25 *
26 * Sun Microsystems, Inc.
27 * 2550 Garcia Avenue
28 * Mountain View, California 94043
29 */
30 #if !defined(lint) && defined(SCCSIDS)
31 static char sccsid[] = "@(#)rpc_callmsg.c 1.4 87/08/11 Copyr 1984 Sun Micro";
32 #endif
33
34 /*
35 * rpc_callmsg.c
36 *
37 * Copyright (C) 1984, Sun Microsystems, Inc.
38 *
39 */
40
41 #include <string.h>
42 #include <sys/param.h>
43 #include <rpc/rpc.h>
44
45 extern bool_t xdr_opaque_auth (XDR *, struct opaque_auth *);
46
47 /*
48 * XDR a call message
49 */
50 bool_t
51 xdr_callmsg (XDR *xdrs, struct rpc_msg *cmsg)
52 {
53 long *buf;
54 struct opaque_auth *oa;
55
56 if (xdrs->x_op == XDR_ENCODE)
57 {
58 if (cmsg->rm_call.cb_cred.oa_length > MAX_AUTH_BYTES)
59 {
60 return (FALSE);
61 }
62 if (cmsg->rm_call.cb_verf.oa_length > MAX_AUTH_BYTES)
63 {
64 return (FALSE);
65 }
66 buf = XDR_INLINE (xdrs, 8 * BYTES_PER_XDR_UNIT
67 + RNDUP (cmsg->rm_call.cb_cred.oa_length)
68 + 2 * BYTES_PER_XDR_UNIT
69 + RNDUP (cmsg->rm_call.cb_verf.oa_length));
70 if (buf != NULL)
71 {
72 IXDR_PUT_LONG (buf, cmsg->rm_xid);
73 IXDR_PUT_ENUM (buf, cmsg->rm_direction);
74 if (cmsg->rm_direction != CALL)
75 {
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 {
81 return FALSE;
82 }
83 IXDR_PUT_LONG (buf, cmsg->rm_call.cb_prog);
84 IXDR_PUT_LONG (buf, cmsg->rm_call.cb_vers);
85 IXDR_PUT_LONG (buf, cmsg->rm_call.cb_proc);
86 oa = &cmsg->rm_call.cb_cred;
87 IXDR_PUT_ENUM (buf, oa->oa_flavor);
88 IXDR_PUT_LONG (buf, oa->oa_length);
89 if (oa->oa_length)
90 {
91 bcopy (oa->oa_base, (caddr_t) buf, oa->oa_length);
92 buf = (long *) ((char *) buf + RNDUP (oa->oa_length));
93 }
94 oa = &cmsg->rm_call.cb_verf;
95 IXDR_PUT_ENUM (buf, oa->oa_flavor);
96 IXDR_PUT_LONG (buf, oa->oa_length);
97 if (oa->oa_length)
98 {
99 bcopy (oa->oa_base, (caddr_t) buf, oa->oa_length);
100 /* no real need....
101 buf = (long *) ((char *) buf + RNDUP(oa->oa_length));
102 */
103 }
104 return TRUE;
105 }
106 }
107 if (xdrs->x_op == XDR_DECODE)
108 {
109 buf = XDR_INLINE (xdrs, 8 * BYTES_PER_XDR_UNIT);
110 if (buf != NULL)
111 {
112 cmsg->rm_xid = IXDR_GET_LONG (buf);
113 cmsg->rm_direction = IXDR_GET_ENUM (buf, enum msg_type);
114 if (cmsg->rm_direction != CALL)
115 {
116 return FALSE;
117 }
118 cmsg->rm_call.cb_rpcvers = IXDR_GET_LONG (buf);
119 if (cmsg->rm_call.cb_rpcvers != RPC_MSG_VERSION)
120 {
121 return FALSE;
122 }
123 cmsg->rm_call.cb_prog = IXDR_GET_LONG (buf);
124 cmsg->rm_call.cb_vers = IXDR_GET_LONG (buf);
125 cmsg->rm_call.cb_proc = IXDR_GET_LONG (buf);
126 oa = &cmsg->rm_call.cb_cred;
127 oa->oa_flavor = IXDR_GET_ENUM (buf, enum_t);
128 oa->oa_length = IXDR_GET_LONG (buf);
129 if (oa->oa_length)
130 {
131 if (oa->oa_length > MAX_AUTH_BYTES)
132 {
133 return FALSE;
134 }
135 if (oa->oa_base == NULL)
136 {
137 oa->oa_base = (caddr_t)
138 mem_alloc (oa->oa_length);
139 }
140 buf = XDR_INLINE (xdrs, RNDUP (oa->oa_length));
141 if (buf == NULL)
142 {
143 if (xdr_opaque (xdrs, oa->oa_base,
144 oa->oa_length) == FALSE)
145 {
146 return FALSE;
147 }
148 }
149 else
150 {
151 bcopy ((caddr_t) buf, oa->oa_base,
152 oa->oa_length);
153 /* no real need....
154 buf = (long *) ((char *) buf
155 + RNDUP(oa->oa_length));
156 */
157 }
158 }
159 oa = &cmsg->rm_call.cb_verf;
160 buf = XDR_INLINE (xdrs, 2 * BYTES_PER_XDR_UNIT);
161 if (buf == NULL)
162 {
163 if (xdr_enum (xdrs, &oa->oa_flavor) == FALSE ||
164 xdr_u_int (xdrs, &oa->oa_length) == FALSE)
165 {
166 return FALSE;
167 }
168 }
169 else
170 {
171 oa->oa_flavor = IXDR_GET_ENUM (buf, enum_t);
172 oa->oa_length = IXDR_GET_LONG (buf);
173 }
174 if (oa->oa_length)
175 {
176 if (oa->oa_length > MAX_AUTH_BYTES)
177 {
178 return FALSE;
179 }
180 if (oa->oa_base == NULL)
181 {
182 oa->oa_base = (caddr_t)
183 mem_alloc (oa->oa_length);
184 }
185 buf = XDR_INLINE (xdrs, RNDUP (oa->oa_length));
186 if (buf == NULL)
187 {
188 if (xdr_opaque (xdrs, oa->oa_base,
189 oa->oa_length) == FALSE)
190 {
191 return FALSE;
192 }
193 }
194 else
195 {
196 bcopy ((caddr_t) buf, oa->oa_base,
197 oa->oa_length);
198 /* no real need...
199 buf = (long *) ((char *) buf
200 + RNDUP(oa->oa_length));
201 */
202 }
203 }
204 return TRUE;
205 }
206 }
207 if (
208 xdr_u_long (xdrs, &(cmsg->rm_xid)) &&
209 xdr_enum (xdrs, (enum_t *) & (cmsg->rm_direction)) &&
210 (cmsg->rm_direction == CALL) &&
211 xdr_u_long (xdrs, &(cmsg->rm_call.cb_rpcvers)) &&
212 (cmsg->rm_call.cb_rpcvers == RPC_MSG_VERSION) &&
213 xdr_u_long (xdrs, &(cmsg->rm_call.cb_prog)) &&
214 xdr_u_long (xdrs, &(cmsg->rm_call.cb_vers)) &&
215 xdr_u_long (xdrs, &(cmsg->rm_call.cb_proc)) &&
216 xdr_opaque_auth (xdrs, &(cmsg->rm_call.cb_cred)))
217 return xdr_opaque_auth (xdrs, &(cmsg->rm_call.cb_verf));
218 return FALSE;
219 }