xref: /titanic_50/usr/src/uts/common/rpc/rpcb_prot.c (revision 1fd2cb30ed9441dcd42f7250881c1f8d075723a9)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate  * Copyright 1997 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate /*	Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T	*/
287c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate /*
317c478bd9Sstevel@tonic-gate  * Portions of this source code were derived from Berkeley 4.3 BSD
327c478bd9Sstevel@tonic-gate  * under license from the Regents of the University of California.
337c478bd9Sstevel@tonic-gate  */
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate /*
367c478bd9Sstevel@tonic-gate  * rpcb_prot.c
377c478bd9Sstevel@tonic-gate  * XDR routines for the rpcbinder version 3.
387c478bd9Sstevel@tonic-gate  */
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate #include <rpc/rpc.h>
417c478bd9Sstevel@tonic-gate #include <rpc/types.h>
427c478bd9Sstevel@tonic-gate #include <rpc/xdr.h>
437c478bd9Sstevel@tonic-gate #include <rpc/rpcb_prot.h>
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate bool_t
xdr_rpcb(XDR * xdrs,RPCB * objp)477c478bd9Sstevel@tonic-gate xdr_rpcb(XDR *xdrs, RPCB *objp)
487c478bd9Sstevel@tonic-gate {
497c478bd9Sstevel@tonic-gate 	if (!xdr_rpcprog(xdrs, &objp->r_prog))
507c478bd9Sstevel@tonic-gate 		return (FALSE);
517c478bd9Sstevel@tonic-gate 	if (!xdr_rpcvers(xdrs, &objp->r_vers))
527c478bd9Sstevel@tonic-gate 		return (FALSE);
537c478bd9Sstevel@tonic-gate 	if (!xdr_string(xdrs, &objp->r_netid, ~0))
547c478bd9Sstevel@tonic-gate 		return (FALSE);
557c478bd9Sstevel@tonic-gate 	if (!xdr_string(xdrs, &objp->r_addr, ~0))
567c478bd9Sstevel@tonic-gate 		return (FALSE);
577c478bd9Sstevel@tonic-gate 	if (!xdr_string(xdrs, &objp->r_owner, ~0))
587c478bd9Sstevel@tonic-gate 		return (FALSE);
597c478bd9Sstevel@tonic-gate 	return (TRUE);
607c478bd9Sstevel@tonic-gate }
617c478bd9Sstevel@tonic-gate 
627c478bd9Sstevel@tonic-gate /*
637c478bd9Sstevel@tonic-gate  * XDR remote call arguments
647c478bd9Sstevel@tonic-gate  * written for XDR_ENCODE direction only
657c478bd9Sstevel@tonic-gate  */
667c478bd9Sstevel@tonic-gate bool_t
xdr_rpcb_rmtcallargs(XDR * xdrs,struct rpcb_rmtcallargs * objp)677c478bd9Sstevel@tonic-gate xdr_rpcb_rmtcallargs(XDR *xdrs, struct rpcb_rmtcallargs *objp)
687c478bd9Sstevel@tonic-gate {
69*1fd2cb30SMarcel Telka 	uint_t lenposition, argposition, position;
707c478bd9Sstevel@tonic-gate 
717c478bd9Sstevel@tonic-gate 	if (!xdr_rpcprog(xdrs, &objp->prog))
727c478bd9Sstevel@tonic-gate 		return (FALSE);
737c478bd9Sstevel@tonic-gate 	if (!xdr_rpcvers(xdrs, &objp->vers))
747c478bd9Sstevel@tonic-gate 		return (FALSE);
757c478bd9Sstevel@tonic-gate 	if (!xdr_rpcproc(xdrs, &objp->proc))
767c478bd9Sstevel@tonic-gate 		return (FALSE);
777c478bd9Sstevel@tonic-gate 	/*
787c478bd9Sstevel@tonic-gate 	 * All the jugglery for just getting the size of the arguments
797c478bd9Sstevel@tonic-gate 	 */
807c478bd9Sstevel@tonic-gate 	lenposition = XDR_GETPOS(xdrs);
817c478bd9Sstevel@tonic-gate 	if (!xdr_u_int(xdrs, &(objp->arglen)))
827c478bd9Sstevel@tonic-gate 		return (FALSE);
837c478bd9Sstevel@tonic-gate 	argposition = XDR_GETPOS(xdrs);
847c478bd9Sstevel@tonic-gate 	if (!(*(objp->xdr_args))(xdrs, objp->args_ptr))
857c478bd9Sstevel@tonic-gate 		return (FALSE);
867c478bd9Sstevel@tonic-gate 	position = XDR_GETPOS(xdrs);
87*1fd2cb30SMarcel Telka 	objp->arglen = position - argposition;
887c478bd9Sstevel@tonic-gate 	XDR_SETPOS(xdrs, lenposition);
897c478bd9Sstevel@tonic-gate 	if (!xdr_u_int(xdrs, &(objp->arglen)))
907c478bd9Sstevel@tonic-gate 		return (FALSE);
917c478bd9Sstevel@tonic-gate 	XDR_SETPOS(xdrs, position);
927c478bd9Sstevel@tonic-gate 	return (TRUE);
937c478bd9Sstevel@tonic-gate }
947c478bd9Sstevel@tonic-gate 
957c478bd9Sstevel@tonic-gate /*
967c478bd9Sstevel@tonic-gate  * XDR remote call results
977c478bd9Sstevel@tonic-gate  * written for XDR_DECODE direction only
987c478bd9Sstevel@tonic-gate  */
997c478bd9Sstevel@tonic-gate bool_t
xdr_rpcb_rmtcallres(XDR * xdrs,struct rpcb_rmtcallres * objp)1007c478bd9Sstevel@tonic-gate xdr_rpcb_rmtcallres(XDR *xdrs, struct rpcb_rmtcallres *objp)
1017c478bd9Sstevel@tonic-gate {
1027c478bd9Sstevel@tonic-gate 	if (!xdr_string(xdrs, &objp->addr_ptr, ~0))
1037c478bd9Sstevel@tonic-gate 		return (FALSE);
1047c478bd9Sstevel@tonic-gate 	if (!xdr_u_int(xdrs, &objp->resultslen))
1057c478bd9Sstevel@tonic-gate 		return (FALSE);
1067c478bd9Sstevel@tonic-gate 	return ((*(objp->xdr_results))(xdrs, objp->results_ptr));
1077c478bd9Sstevel@tonic-gate }
1087c478bd9Sstevel@tonic-gate 
1097c478bd9Sstevel@tonic-gate bool_t
xdr_netbuf(XDR * xdrs,struct netbuf * objp)1107c478bd9Sstevel@tonic-gate xdr_netbuf(XDR *xdrs, struct netbuf *objp)
1117c478bd9Sstevel@tonic-gate {
112*1fd2cb30SMarcel Telka 	bool_t res;
1137c478bd9Sstevel@tonic-gate 
114*1fd2cb30SMarcel Telka 	/*
115*1fd2cb30SMarcel Telka 	 * Save the passed in maxlen value and buf pointer.  We might
116*1fd2cb30SMarcel Telka 	 * need them later.
117*1fd2cb30SMarcel Telka 	 */
118*1fd2cb30SMarcel Telka 	uint_t maxlen_save = objp->maxlen;
119*1fd2cb30SMarcel Telka 	void *buf_save = objp->buf;
120*1fd2cb30SMarcel Telka 
121*1fd2cb30SMarcel Telka 	if (!xdr_u_int(xdrs, &objp->maxlen))
1227c478bd9Sstevel@tonic-gate 		return (FALSE);
123*1fd2cb30SMarcel Telka 
124*1fd2cb30SMarcel Telka 	/*
125*1fd2cb30SMarcel Telka 	 * We need to free maxlen, not len, so do it explicitly now.
126*1fd2cb30SMarcel Telka 	 */
127*1fd2cb30SMarcel Telka 	if (xdrs->x_op == XDR_FREE)
128*1fd2cb30SMarcel Telka 		return (xdr_bytes(xdrs, &objp->buf, &objp->maxlen,
129*1fd2cb30SMarcel Telka 		    objp->maxlen));
130*1fd2cb30SMarcel Telka 
131*1fd2cb30SMarcel Telka 	/*
132*1fd2cb30SMarcel Telka 	 * If we're decoding and the caller has already allocated a
133*1fd2cb30SMarcel Telka 	 * buffer restore the maxlen value since the decoded value
134*1fd2cb30SMarcel Telka 	 * doesn't apply to the caller's buffer.  xdr_bytes() will
135*1fd2cb30SMarcel Telka 	 * return an error if the buffer isn't big enough.
136*1fd2cb30SMarcel Telka 	 */
137*1fd2cb30SMarcel Telka 	if (xdrs->x_op == XDR_DECODE && objp->buf != NULL)
138*1fd2cb30SMarcel Telka 		objp->maxlen = maxlen_save;
139*1fd2cb30SMarcel Telka 
140*1fd2cb30SMarcel Telka 	res = xdr_bytes(xdrs, &objp->buf, &objp->len, objp->maxlen);
141*1fd2cb30SMarcel Telka 
142*1fd2cb30SMarcel Telka 	/*
143*1fd2cb30SMarcel Telka 	 * If we are decoding and the buffer was allocated in the
144*1fd2cb30SMarcel Telka 	 * xdr_bytes() function we need to set maxlen properly to
145*1fd2cb30SMarcel Telka 	 * follow the netbuf semantics.
146*1fd2cb30SMarcel Telka 	 */
147*1fd2cb30SMarcel Telka 	if (xdrs->x_op == XDR_DECODE && objp->buf != buf_save)
148*1fd2cb30SMarcel Telka 		objp->maxlen = objp->len;
149*1fd2cb30SMarcel Telka 
150*1fd2cb30SMarcel Telka 	return (res);
1517c478bd9Sstevel@tonic-gate }
152