1 /* $NetBSD: rpcb_prot.c,v 1.11 2013/03/11 20:19:29 tron Exp $ */
4 * Copyright (c) 2010, Oracle America, Inc.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following
14 * disclaimer in the documentation and/or other materials
15 * provided with the distribution.
16 * * Neither the name of the "Oracle America, Inc." nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
25 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
27 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 * Copyright (c) 1986-1991 by Sun Microsystems Inc.
37 /* #ident "@(#)rpcb_prot.c 1.13 94/04/24 SMI" */
39 #include <sys/cdefs.h>
40 #if defined(LIBC_SCCS) && !defined(lint)
42 static char sccsid
[] = "@(#)rpcb_prot.c 1.9 89/04/21 Copyr 1984 Sun Micro";
44 __RCSID("$NetBSD: rpcb_prot.c,v 1.11 2013/03/11 20:19:29 tron Exp $");
50 * XDR routines for the rpcbinder version 3.
52 * Copyright (C) 1984, 1988, Sun Microsystems, Inc.
55 #include "namespace.h"
58 #include <rpc/types.h>
60 #include <rpc/rpcb_prot.h>
65 __weak_alias(xdr_rpcb
,_xdr_rpcb
)
66 __weak_alias(xdr_rpcblist_ptr
,_xdr_rpcblist_ptr
)
67 __weak_alias(xdr_rpcblist
,_xdr_rpcblist
)
68 __weak_alias(xdr_rpcb_entry
,_xdr_rpcb_entry
)
69 __weak_alias(xdr_rpcb_entry_list_ptr
,_xdr_rpcb_entry_list_ptr
)
70 __weak_alias(xdr_rpcb_rmtcallargs
,_xdr_rpcb_rmtcallargs
)
71 __weak_alias(xdr_rpcb_rmtcallres
,_xdr_rpcb_rmtcallres
)
72 __weak_alias(xdr_netbuf
,_xdr_netbuf
)
77 xdr_rpcb(XDR
*xdrs
, RPCB
*objp
)
80 _DIAGASSERT(objp
!= NULL
);
82 if (!xdr_u_int32_t(xdrs
, &objp
->r_prog
)) {
85 if (!xdr_u_int32_t(xdrs
, &objp
->r_vers
)) {
88 if (!xdr_string(xdrs
, &objp
->r_netid
, (u_int
)~0)) {
91 if (!xdr_string(xdrs
, &objp
->r_addr
, (u_int
)~0)) {
94 if (!xdr_string(xdrs
, &objp
->r_owner
, (u_int
)~0)) {
101 * rpcblist_ptr implements a linked list. The RPCL definition from
106 * struct rpcblist *rpcb_next;
108 * typedef rpcblist *rpcblist_ptr;
110 * Recall that "pointers" in XDR are encoded as a boolean, indicating whether
111 * there's any data behind the pointer, followed by the data (if any exists).
112 * The boolean can be interpreted as ``more data follows me''; if FALSE then
113 * nothing follows the boolean; if TRUE then the boolean is followed by an
114 * actual struct rpcb, and another rpcblist_ptr (declared in RPCL as "struct
117 * This could be implemented via the xdr_pointer type, though this would
118 * result in one recursive call per element in the list. Rather than do that
119 * we can ``unwind'' the recursion into a while loop and use xdr_reference to
120 * serialize the rpcb elements.
124 xdr_rpcblist_ptr(XDR
*xdrs
, rpcblist_ptr
*rp
)
127 * more_elements is pre-computed in case the direction is
128 * XDR_ENCODE or XDR_FREE. more_elements is overwritten by
129 * xdr_bool when the direction is XDR_DECODE.
131 bool_t more_elements
;
134 rpcblist_ptr next_copy
;
136 _DIAGASSERT(xdrs
!= NULL
);
137 /* XXX: rp may be NULL ??? */
139 freeing
= (xdrs
->x_op
== XDR_FREE
);
143 more_elements
= (bool_t
)(*rp
!= NULL
);
144 if (! xdr_bool(xdrs
, &more_elements
)) {
147 if (! more_elements
) {
148 return (TRUE
); /* we are done */
151 * the unfortunate side effect of non-recursion is that in
152 * the case of freeing we must remember the next object
153 * before we free the current object ...
156 next
= (*rp
)->rpcb_next
;
157 if (! xdr_reference(xdrs
, (caddr_t
*)rp
,
158 (u_int
)sizeof (rpcblist
), (xdrproc_t
)xdr_rpcb
)) {
165 * Note that in the subsequent iteration, next_copy
166 * gets nulled out by the xdr_reference
167 * but next itself survives.
170 rp
= &((*rp
)->rpcb_next
);
177 * xdr_rpcblist() is specified to take a RPCBLIST **, but is identical in
178 * functionality to xdr_rpcblist_ptr().
181 xdr_rpcblist(XDR
*xdrs
, RPCBLIST
**rp
)
185 dummy
= xdr_rpcblist_ptr(xdrs
, (rpcblist_ptr
*)rp
);
191 xdr_rpcb_entry(XDR
*xdrs
, rpcb_entry
*objp
)
194 _DIAGASSERT(objp
!= NULL
);
196 if (!xdr_string(xdrs
, &objp
->r_maddr
, (u_int
)~0)) {
199 if (!xdr_string(xdrs
, &objp
->r_nc_netid
, (u_int
)~0)) {
202 if (!xdr_u_int32_t(xdrs
, &objp
->r_nc_semantics
)) {
205 if (!xdr_string(xdrs
, &objp
->r_nc_protofmly
, (u_int
)~0)) {
208 if (!xdr_string(xdrs
, &objp
->r_nc_proto
, (u_int
)~0)) {
215 xdr_rpcb_entry_list_ptr(XDR
*xdrs
, rpcb_entry_list_ptr
*rp
)
218 * more_elements is pre-computed in case the direction is
219 * XDR_ENCODE or XDR_FREE. more_elements is overwritten by
220 * xdr_bool when the direction is XDR_DECODE.
222 bool_t more_elements
;
224 rpcb_entry_list_ptr next
;
225 rpcb_entry_list_ptr next_copy
;
227 _DIAGASSERT(xdrs
!= NULL
);
228 /* XXX: rp is allowed to be NULL ??? */
230 freeing
= (xdrs
->x_op
== XDR_FREE
);
234 more_elements
= (bool_t
)(*rp
!= NULL
);
235 if (! xdr_bool(xdrs
, &more_elements
)) {
238 if (! more_elements
) {
239 return (TRUE
); /* we are done */
242 * the unfortunate side effect of non-recursion is that in
243 * the case of freeing we must remember the next object
244 * before we free the current object ...
247 next
= (*rp
)->rpcb_entry_next
;
248 if (! xdr_reference(xdrs
, (caddr_t
*)rp
,
249 (u_int
)sizeof (rpcb_entry_list
),
250 (xdrproc_t
)xdr_rpcb_entry
)) {
257 * Note that in the subsequent iteration, next_copy
258 * gets nulled out by the xdr_reference
259 * but next itself survives.
262 rp
= &((*rp
)->rpcb_entry_next
);
269 * XDR remote call arguments
270 * written for XDR_ENCODE direction only
273 xdr_rpcb_rmtcallargs(XDR
*xdrs
, struct rpcb_rmtcallargs
*p
)
275 struct r_rpcb_rmtcallargs
*objp
=
276 (struct r_rpcb_rmtcallargs
*)(void *)p
;
277 u_int lenposition
, argposition
, position
;
280 _DIAGASSERT(p
!= NULL
);
282 buf
= XDR_INLINE(xdrs
, 3 * BYTES_PER_XDR_UNIT
);
284 if (!xdr_u_int32_t(xdrs
, &objp
->prog
)) {
287 if (!xdr_u_int32_t(xdrs
, &objp
->vers
)) {
290 if (!xdr_u_int32_t(xdrs
, &objp
->proc
)) {
294 IXDR_PUT_U_INT32(buf
, objp
->prog
);
295 IXDR_PUT_U_INT32(buf
, objp
->vers
);
296 IXDR_PUT_U_INT32(buf
, objp
->proc
);
300 * All the jugglery for just getting the size of the arguments
302 lenposition
= XDR_GETPOS(xdrs
);
303 if (! xdr_u_int(xdrs
, &(objp
->args
.args_len
))) {
306 argposition
= XDR_GETPOS(xdrs
);
307 if (! (*objp
->xdr_args
)(xdrs
, objp
->args
.args_val
)) {
310 position
= XDR_GETPOS(xdrs
);
311 objp
->args
.args_len
= (u_int
)((u_long
)position
- (u_long
)argposition
);
312 XDR_SETPOS(xdrs
, lenposition
);
313 if (! xdr_u_int(xdrs
, &(objp
->args
.args_len
))) {
316 XDR_SETPOS(xdrs
, position
);
321 * XDR remote call results
322 * written for XDR_DECODE direction only
325 xdr_rpcb_rmtcallres(XDR
*xdrs
, struct rpcb_rmtcallres
*p
)
328 struct r_rpcb_rmtcallres
*objp
= (struct r_rpcb_rmtcallres
*)(void *)p
;
330 _DIAGASSERT(p
!= NULL
);
332 if (!xdr_string(xdrs
, &objp
->addr
, (u_int
)~0)) {
335 if (!xdr_u_int(xdrs
, &objp
->results
.results_len
)) {
338 dummy
= (*(objp
->xdr_res
))(xdrs
, objp
->results
.results_val
);
343 xdr_netbuf(XDR
*xdrs
, struct netbuf
*objp
)
347 _DIAGASSERT(objp
!= NULL
);
349 if (!xdr_u_int32_t(xdrs
, (u_int32_t
*) &objp
->maxlen
)) {
352 dummy
= xdr_bytes(xdrs
, (char **)(void *)&(objp
->buf
),
353 (u_int
*)&(objp
->len
), objp
->maxlen
);