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