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