xref: /titanic_44/usr/src/uts/common/rpc/rpcb_prot.c (revision bf97644ef2e3bacba45a487ed02f388753d08502)
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*bf97644eSMarcel 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*bf97644eSMarcel 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*bf97644eSMarcel Telka 	bool_t res;
1137c478bd9Sstevel@tonic-gate 
114*bf97644eSMarcel Telka 	/*
115*bf97644eSMarcel Telka 	 * Save the passed in maxlen value and buf pointer.  We might
116*bf97644eSMarcel Telka 	 * need them later.
117*bf97644eSMarcel Telka 	 */
118*bf97644eSMarcel Telka 	uint_t maxlen_save = objp->maxlen;
119*bf97644eSMarcel Telka 	void *buf_save = objp->buf;
120*bf97644eSMarcel Telka 
121*bf97644eSMarcel Telka 	if (!xdr_u_int(xdrs, &objp->maxlen))
1227c478bd9Sstevel@tonic-gate 		return (FALSE);
123*bf97644eSMarcel Telka 
124*bf97644eSMarcel Telka 	/*
125*bf97644eSMarcel Telka 	 * We need to free maxlen, not len, so do it explicitly now.
126*bf97644eSMarcel Telka 	 */
127*bf97644eSMarcel Telka 	if (xdrs->x_op == XDR_FREE)
128*bf97644eSMarcel Telka 		return (xdr_bytes(xdrs, &objp->buf, &objp->maxlen,
129*bf97644eSMarcel Telka 		    objp->maxlen));
130*bf97644eSMarcel Telka 
131*bf97644eSMarcel Telka 	/*
132*bf97644eSMarcel Telka 	 * If we're decoding and the caller has already allocated a
133*bf97644eSMarcel Telka 	 * buffer restore the maxlen value since the decoded value
134*bf97644eSMarcel Telka 	 * doesn't apply to the caller's buffer.  xdr_bytes() will
135*bf97644eSMarcel Telka 	 * return an error if the buffer isn't big enough.
136*bf97644eSMarcel Telka 	 */
137*bf97644eSMarcel Telka 	if (xdrs->x_op == XDR_DECODE && objp->buf != NULL)
138*bf97644eSMarcel Telka 		objp->maxlen = maxlen_save;
139*bf97644eSMarcel Telka 
140*bf97644eSMarcel Telka 	res = xdr_bytes(xdrs, &objp->buf, &objp->len, objp->maxlen);
141*bf97644eSMarcel Telka 
142*bf97644eSMarcel Telka 	/*
143*bf97644eSMarcel Telka 	 * If we are decoding and the buffer was allocated in the
144*bf97644eSMarcel Telka 	 * xdr_bytes() function we need to set maxlen properly to
145*bf97644eSMarcel Telka 	 * follow the netbuf semantics.
146*bf97644eSMarcel Telka 	 */
147*bf97644eSMarcel Telka 	if (xdrs->x_op == XDR_DECODE && objp->buf != buf_save)
148*bf97644eSMarcel Telka 		objp->maxlen = objp->len;
149*bf97644eSMarcel Telka 
150*bf97644eSMarcel Telka 	return (res);
1517c478bd9Sstevel@tonic-gate }
152