xref: /titanic_50/usr/src/uts/common/rpc/rpcb_prot.c (revision 8cfa78e6de0de88f6a15cd29ee5f6a8a1bfe7c20)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 1997 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*	Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T	*/
28 /*	  All Rights Reserved  	*/
29 
30 /*
31  * Portions of this source code were derived from Berkeley 4.3 BSD
32  * under license from the Regents of the University of California.
33  */
34 
35 /*
36  * rpcb_prot.c
37  * XDR routines for the rpcbinder version 3.
38  */
39 
40 #include <rpc/rpc.h>
41 #include <rpc/types.h>
42 #include <rpc/xdr.h>
43 #include <rpc/rpcb_prot.h>
44 
45 
46 bool_t
47 xdr_rpcb(XDR *xdrs, RPCB *objp)
48 {
49 	if (!xdr_rpcprog(xdrs, &objp->r_prog))
50 		return (FALSE);
51 	if (!xdr_rpcvers(xdrs, &objp->r_vers))
52 		return (FALSE);
53 	if (!xdr_string(xdrs, &objp->r_netid, ~0))
54 		return (FALSE);
55 	if (!xdr_string(xdrs, &objp->r_addr, ~0))
56 		return (FALSE);
57 	if (!xdr_string(xdrs, &objp->r_owner, ~0))
58 		return (FALSE);
59 	return (TRUE);
60 }
61 
62 /*
63  * XDR remote call arguments
64  * written for XDR_ENCODE direction only
65  */
66 bool_t
67 xdr_rpcb_rmtcallargs(XDR *xdrs, struct rpcb_rmtcallargs *objp)
68 {
69 	uint_t lenposition, argposition, position;
70 
71 	if (!xdr_rpcprog(xdrs, &objp->prog))
72 		return (FALSE);
73 	if (!xdr_rpcvers(xdrs, &objp->vers))
74 		return (FALSE);
75 	if (!xdr_rpcproc(xdrs, &objp->proc))
76 		return (FALSE);
77 	/*
78 	 * All the jugglery for just getting the size of the arguments
79 	 */
80 	lenposition = XDR_GETPOS(xdrs);
81 	if (!xdr_u_int(xdrs, &(objp->arglen)))
82 		return (FALSE);
83 	argposition = XDR_GETPOS(xdrs);
84 	if (!(*(objp->xdr_args))(xdrs, objp->args_ptr))
85 		return (FALSE);
86 	position = XDR_GETPOS(xdrs);
87 	objp->arglen = position - argposition;
88 	XDR_SETPOS(xdrs, lenposition);
89 	if (!xdr_u_int(xdrs, &(objp->arglen)))
90 		return (FALSE);
91 	XDR_SETPOS(xdrs, position);
92 	return (TRUE);
93 }
94 
95 /*
96  * XDR remote call results
97  * written for XDR_DECODE direction only
98  */
99 bool_t
100 xdr_rpcb_rmtcallres(XDR *xdrs, struct rpcb_rmtcallres *objp)
101 {
102 	if (!xdr_string(xdrs, &objp->addr_ptr, ~0))
103 		return (FALSE);
104 	if (!xdr_u_int(xdrs, &objp->resultslen))
105 		return (FALSE);
106 	return ((*(objp->xdr_results))(xdrs, objp->results_ptr));
107 }
108 
109 bool_t
110 xdr_netbuf(XDR *xdrs, struct netbuf *objp)
111 {
112 	bool_t res;
113 
114 	/*
115 	 * Save the passed in maxlen value and buf pointer.  We might
116 	 * need them later.
117 	 */
118 	uint_t maxlen_save = objp->maxlen;
119 	void *buf_save = objp->buf;
120 
121 	if (!xdr_u_int(xdrs, &objp->maxlen))
122 		return (FALSE);
123 
124 	/*
125 	 * We need to free maxlen, not len, so do it explicitly now.
126 	 */
127 	if (xdrs->x_op == XDR_FREE)
128 		return (xdr_bytes(xdrs, &objp->buf, &objp->maxlen,
129 		    objp->maxlen));
130 
131 	/*
132 	 * If we're decoding and the caller has already allocated a
133 	 * buffer restore the maxlen value since the decoded value
134 	 * doesn't apply to the caller's buffer.  xdr_bytes() will
135 	 * return an error if the buffer isn't big enough.
136 	 */
137 	if (xdrs->x_op == XDR_DECODE && objp->buf != NULL)
138 		objp->maxlen = maxlen_save;
139 
140 	res = xdr_bytes(xdrs, &objp->buf, &objp->len, objp->maxlen);
141 
142 	/*
143 	 * If we are decoding and the buffer was allocated in the
144 	 * xdr_bytes() function we need to set maxlen properly to
145 	 * follow the netbuf semantics.
146 	 */
147 	if (xdrs->x_op == XDR_DECODE && objp->buf != buf_save)
148 		objp->maxlen = objp->len;
149 
150 	return (res);
151 }
152