1 /* $NetBSD: rpcb_prot.c,v 1.3 2000/07/14 08:40:42 fvdl Exp $ */
4 * Copyright (c) 2009, Sun Microsystems, Inc.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 * - Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
14 * - Neither the name of Sun Microsystems, Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived
16 * from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
31 * Copyright (c) 1986-1991 by Sun Microsystems Inc.
34 /* #ident "@(#)rpcb_prot.c 1.13 94/04/24 SMI" */
36 #if defined(LIBC_SCCS) && !defined(lint)
37 static char sccsid[] = "@(#)rpcb_prot.c 1.9 89/04/21 Copyr 1984 Sun Micro";
39 #include <sys/cdefs.h>
40 __FBSDID("$FreeBSD$");
44 * XDR routines for the rpcbinder version 3.
46 * Copyright (C) 1984, 1988, Sun Microsystems, Inc.
49 #include "namespace.h"
51 #include <rpc/types.h>
53 #include <rpc/rpcb_prot.h>
54 #include "un-namespace.h"
61 if (!xdr_u_int32_t(xdrs, &objp->r_prog)) {
64 if (!xdr_u_int32_t(xdrs, &objp->r_vers)) {
67 if (!xdr_string(xdrs, &objp->r_netid, (u_int)~0)) {
70 if (!xdr_string(xdrs, &objp->r_addr, (u_int)~0)) {
73 if (!xdr_string(xdrs, &objp->r_owner, (u_int)~0)) {
80 * rpcblist_ptr implements a linked list. The RPCL definition from
85 * struct rpcblist *rpcb_next;
87 * typedef rpcblist *rpcblist_ptr;
89 * Recall that "pointers" in XDR are encoded as a boolean, indicating whether
90 * there's any data behind the pointer, followed by the data (if any exists).
91 * The boolean can be interpreted as ``more data follows me''; if FALSE then
92 * nothing follows the boolean; if TRUE then the boolean is followed by an
93 * actual struct rpcb, and another rpcblist_ptr (declared in RPCL as "struct
96 * This could be implemented via the xdr_pointer type, though this would
97 * result in one recursive call per element in the list. Rather than do that
98 * we can ``unwind'' the recursion into a while loop and use xdr_reference to
99 * serialize the rpcb elements.
103 xdr_rpcblist_ptr(xdrs, rp)
108 * more_elements is pre-computed in case the direction is
109 * XDR_ENCODE or XDR_FREE. more_elements is overwritten by
110 * xdr_bool when the direction is XDR_DECODE.
112 bool_t more_elements;
113 int freeing = (xdrs->x_op == XDR_FREE);
115 rpcblist_ptr next_copy;
119 more_elements = (bool_t)(*rp != NULL);
120 if (! xdr_bool(xdrs, &more_elements)) {
123 if (! more_elements) {
124 return (TRUE); /* we are done */
127 * the unfortunate side effect of non-recursion is that in
128 * the case of freeing we must remember the next object
129 * before we free the current object ...
132 next = (*rp)->rpcb_next;
133 if (! xdr_reference(xdrs, (caddr_t *)rp,
134 (u_int)sizeof (rpcblist), (xdrproc_t)xdr_rpcb)) {
141 * Note that in the subsequent iteration, next_copy
142 * gets nulled out by the xdr_reference
143 * but next itself survives.
146 rp = &((*rp)->rpcb_next);
153 * xdr_rpcblist() is specified to take a RPCBLIST **, but is identical in
154 * functionality to xdr_rpcblist_ptr().
157 xdr_rpcblist(xdrs, rp)
163 dummy = xdr_rpcblist_ptr(xdrs, (rpcblist_ptr *)rp);
169 xdr_rpcb_entry(xdrs, objp)
173 if (!xdr_string(xdrs, &objp->r_maddr, (u_int)~0)) {
176 if (!xdr_string(xdrs, &objp->r_nc_netid, (u_int)~0)) {
179 if (!xdr_u_int32_t(xdrs, &objp->r_nc_semantics)) {
182 if (!xdr_string(xdrs, &objp->r_nc_protofmly, (u_int)~0)) {
185 if (!xdr_string(xdrs, &objp->r_nc_proto, (u_int)~0)) {
192 xdr_rpcb_entry_list_ptr(xdrs, rp)
194 rpcb_entry_list_ptr *rp;
197 * more_elements is pre-computed in case the direction is
198 * XDR_ENCODE or XDR_FREE. more_elements is overwritten by
199 * xdr_bool when the direction is XDR_DECODE.
201 bool_t more_elements;
202 int freeing = (xdrs->x_op == XDR_FREE);
203 rpcb_entry_list_ptr next;
204 rpcb_entry_list_ptr next_copy;
208 more_elements = (bool_t)(*rp != NULL);
209 if (! xdr_bool(xdrs, &more_elements)) {
212 if (! more_elements) {
213 return (TRUE); /* we are done */
216 * the unfortunate side effect of non-recursion is that in
217 * the case of freeing we must remember the next object
218 * before we free the current object ...
221 next = (*rp)->rpcb_entry_next;
222 if (! xdr_reference(xdrs, (caddr_t *)rp,
223 (u_int)sizeof (rpcb_entry_list),
224 (xdrproc_t)xdr_rpcb_entry)) {
231 * Note that in the subsequent iteration, next_copy
232 * gets nulled out by the xdr_reference
233 * but next itself survives.
236 rp = &((*rp)->rpcb_entry_next);
243 * XDR remote call arguments
244 * written for XDR_ENCODE direction only
247 xdr_rpcb_rmtcallargs(xdrs, p)
249 struct rpcb_rmtcallargs *p;
251 struct r_rpcb_rmtcallargs *objp =
252 (struct r_rpcb_rmtcallargs *)(void *)p;
253 u_int lenposition, argposition, position;
256 buf = XDR_INLINE(xdrs, 3 * BYTES_PER_XDR_UNIT);
258 if (!xdr_u_int32_t(xdrs, &objp->prog)) {
261 if (!xdr_u_int32_t(xdrs, &objp->vers)) {
264 if (!xdr_u_int32_t(xdrs, &objp->proc)) {
268 IXDR_PUT_U_INT32(buf, objp->prog);
269 IXDR_PUT_U_INT32(buf, objp->vers);
270 IXDR_PUT_U_INT32(buf, objp->proc);
274 * All the jugglery for just getting the size of the arguments
276 lenposition = XDR_GETPOS(xdrs);
277 if (! xdr_u_int(xdrs, &(objp->args.args_len))) {
280 argposition = XDR_GETPOS(xdrs);
281 if (! (*objp->xdr_args)(xdrs, objp->args.args_val)) {
284 position = XDR_GETPOS(xdrs);
285 objp->args.args_len = (u_int)((u_long)position - (u_long)argposition);
286 XDR_SETPOS(xdrs, lenposition);
287 if (! xdr_u_int(xdrs, &(objp->args.args_len))) {
290 XDR_SETPOS(xdrs, position);
295 * XDR remote call results
296 * written for XDR_DECODE direction only
299 xdr_rpcb_rmtcallres(xdrs, p)
301 struct rpcb_rmtcallres *p;
304 struct r_rpcb_rmtcallres *objp = (struct r_rpcb_rmtcallres *)(void *)p;
306 if (!xdr_string(xdrs, &objp->addr, (u_int)~0)) {
309 if (!xdr_u_int(xdrs, &objp->results.results_len)) {
312 dummy = (*(objp->xdr_res))(xdrs, objp->results.results_val);
317 xdr_netbuf(xdrs, objp)
324 if (!xdr_u_int32_t(xdrs, (u_int32_t *) &objp->maxlen)) {
328 dummy = xdr_bytes(xdrs, (char **) pp,
329 (u_int *)&(objp->len), objp->maxlen);