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