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