xref: /illumos-gate/usr/src/lib/libnsl/rpc/rpc_prot.c (revision 37972848)
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
2161961e0fSrobinson  */
2261961e0fSrobinson 
2361961e0fSrobinson /*
24e8031f0aSraf  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
257c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
267c478bd9Sstevel@tonic-gate  */
27e8031f0aSraf 
287c478bd9Sstevel@tonic-gate /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
297c478bd9Sstevel@tonic-gate /* All Rights Reserved */
307c478bd9Sstevel@tonic-gate /*
317c478bd9Sstevel@tonic-gate  * Portions of this source code were derived from Berkeley
327c478bd9Sstevel@tonic-gate  * 4.3 BSD under license from the Regents of the University of
337c478bd9Sstevel@tonic-gate  * California.
347c478bd9Sstevel@tonic-gate  */
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate /*
377c478bd9Sstevel@tonic-gate  * This set of routines implements the rpc message definition,
387c478bd9Sstevel@tonic-gate  * its serializer and some common rpc utility routines.
397c478bd9Sstevel@tonic-gate  * The routines are meant for various implementations of rpc -
407c478bd9Sstevel@tonic-gate  * they are NOT for the rpc client or rpc service implementations!
417c478bd9Sstevel@tonic-gate  * Because authentication stuff is easy and is part of rpc, the opaque
427c478bd9Sstevel@tonic-gate  * routines are also in this program.
437c478bd9Sstevel@tonic-gate  */
447c478bd9Sstevel@tonic-gate 
45e8031f0aSraf #include "mt.h"
467c478bd9Sstevel@tonic-gate #include <sys/param.h>
477c478bd9Sstevel@tonic-gate #include <syslog.h>
487c478bd9Sstevel@tonic-gate #include <rpc/rpc.h>
497c478bd9Sstevel@tonic-gate #include <malloc.h>
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate /* * * * * * * * * * * * * * XDR Authentication * * * * * * * * * * * */
527c478bd9Sstevel@tonic-gate 
537c478bd9Sstevel@tonic-gate /*
547c478bd9Sstevel@tonic-gate  * XDR an opaque authentication struct
557c478bd9Sstevel@tonic-gate  * (see auth.h)
567c478bd9Sstevel@tonic-gate  */
577c478bd9Sstevel@tonic-gate bool_t
xdr_opaque_auth(XDR * xdrs,struct opaque_auth * ap)5861961e0fSrobinson xdr_opaque_auth(XDR *xdrs, struct opaque_auth *ap)
597c478bd9Sstevel@tonic-gate {
6061961e0fSrobinson 	if (xdr_enum(xdrs, &(ap->oa_flavor)))
6161961e0fSrobinson 		return (xdr_bytes(xdrs, &ap->oa_base,
62*37972848SToomas Soome 		    &ap->oa_length, MAX_AUTH_BYTES));
637c478bd9Sstevel@tonic-gate 	return (FALSE);
647c478bd9Sstevel@tonic-gate }
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate /*
677c478bd9Sstevel@tonic-gate  * XDR a DES block
687c478bd9Sstevel@tonic-gate  */
697c478bd9Sstevel@tonic-gate bool_t
xdr_des_block(XDR * xdrs,des_block * blkp)7061961e0fSrobinson xdr_des_block(XDR *xdrs, des_block *blkp)
717c478bd9Sstevel@tonic-gate {
7261961e0fSrobinson 	return (xdr_opaque(xdrs, (caddr_t)blkp, sizeof (des_block)));
737c478bd9Sstevel@tonic-gate }
747c478bd9Sstevel@tonic-gate 
757c478bd9Sstevel@tonic-gate /* * * * * * * * * * * * * * XDR RPC MESSAGE * * * * * * * * * * * * * * * */
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate /*
787c478bd9Sstevel@tonic-gate  * XDR the MSG_ACCEPTED part of a reply message union
797c478bd9Sstevel@tonic-gate  */
807c478bd9Sstevel@tonic-gate bool_t
xdr_accepted_reply(XDR * xdrs,struct accepted_reply * ar)8161961e0fSrobinson xdr_accepted_reply(XDR *xdrs, struct accepted_reply *ar)
827c478bd9Sstevel@tonic-gate {
837c478bd9Sstevel@tonic-gate 	/* personalized union, rather than calling xdr_union */
8461961e0fSrobinson 	if (!xdr_opaque_auth(xdrs, &(ar->ar_verf)))
857c478bd9Sstevel@tonic-gate 		return (FALSE);
8661961e0fSrobinson 	if (!xdr_enum(xdrs, (enum_t *)&(ar->ar_stat)))
877c478bd9Sstevel@tonic-gate 		return (FALSE);
887c478bd9Sstevel@tonic-gate 
897c478bd9Sstevel@tonic-gate 	switch (ar->ar_stat) {
907c478bd9Sstevel@tonic-gate 	case SUCCESS:
9161961e0fSrobinson 		return ((*(ar->ar_results.proc))(xdrs, ar->ar_results.where));
927c478bd9Sstevel@tonic-gate 	case PROG_MISMATCH:
9361961e0fSrobinson 		if (!xdr_u_int(xdrs, (uint_t *)&(ar->ar_vers.low)))
947c478bd9Sstevel@tonic-gate 			return (FALSE);
9561961e0fSrobinson 		return (xdr_u_int(xdrs, (uint_t *)&(ar->ar_vers.high)));
967c478bd9Sstevel@tonic-gate 	}
977c478bd9Sstevel@tonic-gate 	return (TRUE);  /* TRUE => open ended set of problems */
987c478bd9Sstevel@tonic-gate }
997c478bd9Sstevel@tonic-gate 
1007c478bd9Sstevel@tonic-gate /*
1017c478bd9Sstevel@tonic-gate  * XDR the MSG_DENIED part of a reply message union
1027c478bd9Sstevel@tonic-gate  */
1037c478bd9Sstevel@tonic-gate bool_t
xdr_rejected_reply(XDR * xdrs,struct rejected_reply * rr)10461961e0fSrobinson xdr_rejected_reply(XDR *xdrs, struct rejected_reply *rr)
1057c478bd9Sstevel@tonic-gate {
1067c478bd9Sstevel@tonic-gate 	/* personalized union, rather than calling xdr_union */
10761961e0fSrobinson 	if (!xdr_enum(xdrs, (enum_t *)&(rr->rj_stat)))
1087c478bd9Sstevel@tonic-gate 		return (FALSE);
1097c478bd9Sstevel@tonic-gate 	switch (rr->rj_stat) {
1107c478bd9Sstevel@tonic-gate 	case RPC_MISMATCH:
11161961e0fSrobinson 		if (!xdr_u_int(xdrs, (uint_t *)&(rr->rj_vers.low)))
1127c478bd9Sstevel@tonic-gate 			return (FALSE);
11361961e0fSrobinson 		return (xdr_u_int(xdrs, (uint_t *)&(rr->rj_vers.high)));
1147c478bd9Sstevel@tonic-gate 	case AUTH_ERROR:
11561961e0fSrobinson 		return (xdr_enum(xdrs, (enum_t *)&(rr->rj_why)));
1167c478bd9Sstevel@tonic-gate 	}
1177c478bd9Sstevel@tonic-gate 	return (FALSE);
1187c478bd9Sstevel@tonic-gate }
1197c478bd9Sstevel@tonic-gate 
1207c478bd9Sstevel@tonic-gate /*
1217c478bd9Sstevel@tonic-gate  * XDR a reply message
1227c478bd9Sstevel@tonic-gate  */
1237c478bd9Sstevel@tonic-gate bool_t
xdr_replymsg(XDR * xdrs,struct rpc_msg * rmsg)12461961e0fSrobinson xdr_replymsg(XDR *xdrs, struct rpc_msg *rmsg)
1257c478bd9Sstevel@tonic-gate {
1267c478bd9Sstevel@tonic-gate 	struct xdr_discrim reply_dscrm[3];
12761961e0fSrobinson 	rpc_inline_t *buf;
12861961e0fSrobinson 	struct accepted_reply *ar;
12961961e0fSrobinson 	struct opaque_auth *oa;
13061961e0fSrobinson 	uint_t rndup;
1317c478bd9Sstevel@tonic-gate 
1327c478bd9Sstevel@tonic-gate 	if (xdrs->x_op == XDR_ENCODE &&
1337c478bd9Sstevel@tonic-gate 	    rmsg->rm_reply.rp_stat == MSG_ACCEPTED &&
1347c478bd9Sstevel@tonic-gate 	    rmsg->rm_direction == REPLY &&
1357c478bd9Sstevel@tonic-gate 	    (buf = XDR_INLINE(xdrs, 6 * BYTES_PER_XDR_UNIT + (rndup =
136*37972848SToomas Soome 	    RNDUP(rmsg->rm_reply.rp_acpt.ar_verf.oa_length)))) != NULL) {
1377c478bd9Sstevel@tonic-gate 		IXDR_PUT_INT32(buf, rmsg->rm_xid);
1387c478bd9Sstevel@tonic-gate 		IXDR_PUT_ENUM(buf, rmsg->rm_direction);
1397c478bd9Sstevel@tonic-gate 		IXDR_PUT_ENUM(buf, rmsg->rm_reply.rp_stat);
1407c478bd9Sstevel@tonic-gate 		ar = &rmsg->rm_reply.rp_acpt;
1417c478bd9Sstevel@tonic-gate 		oa = &ar->ar_verf;
1427c478bd9Sstevel@tonic-gate 		IXDR_PUT_ENUM(buf, oa->oa_flavor);
1437c478bd9Sstevel@tonic-gate 		IXDR_PUT_INT32(buf, oa->oa_length);
1447c478bd9Sstevel@tonic-gate 		if (oa->oa_length) {
14561961e0fSrobinson 			(void) memcpy(buf, oa->oa_base, oa->oa_length);
1467c478bd9Sstevel@tonic-gate /* LINTED pointer alignment */
1477c478bd9Sstevel@tonic-gate 			buf = (rpc_inline_t *)(((caddr_t)buf) + oa->oa_length);
1487c478bd9Sstevel@tonic-gate 		}
1497c478bd9Sstevel@tonic-gate 		if ((rndup = (rndup - oa->oa_length)) > 0) {
1507c478bd9Sstevel@tonic-gate 			(void) memset((caddr_t)buf, 0, rndup);
1517c478bd9Sstevel@tonic-gate /* LINTED pointer alignment */
1527c478bd9Sstevel@tonic-gate 			buf = (rpc_inline_t *)(((caddr_t)buf) + rndup);
1537c478bd9Sstevel@tonic-gate 		}
1547c478bd9Sstevel@tonic-gate 		/*
1557c478bd9Sstevel@tonic-gate 		 * stat and rest of reply, copied from xdr_accepted_reply
1567c478bd9Sstevel@tonic-gate 		 */
1577c478bd9Sstevel@tonic-gate 		IXDR_PUT_ENUM(buf, ar->ar_stat);
1587c478bd9Sstevel@tonic-gate 		switch (ar->ar_stat) {
1597c478bd9Sstevel@tonic-gate 		case SUCCESS:
16061961e0fSrobinson 			return ((*(ar->ar_results.proc))
161*37972848SToomas Soome 			    (xdrs, ar->ar_results.where));
1627c478bd9Sstevel@tonic-gate 		case PROG_MISMATCH:
16361961e0fSrobinson 			if (!xdr_u_int(xdrs, (uint_t *)&(ar->ar_vers.low)))
1647c478bd9Sstevel@tonic-gate 				return (FALSE);
16561961e0fSrobinson 			return (xdr_u_int(xdrs, (uint_t *)&(ar->ar_vers.high)));
1667c478bd9Sstevel@tonic-gate 		}
1677c478bd9Sstevel@tonic-gate 		return (TRUE);
1687c478bd9Sstevel@tonic-gate 	}
1697c478bd9Sstevel@tonic-gate 	if (xdrs->x_op == XDR_DECODE &&
1707c478bd9Sstevel@tonic-gate 	    (buf = XDR_INLINE(xdrs, 3 * BYTES_PER_XDR_UNIT)) != NULL) {
1717c478bd9Sstevel@tonic-gate 		rmsg->rm_xid = IXDR_GET_INT32(buf);
1727c478bd9Sstevel@tonic-gate 		rmsg->rm_direction = IXDR_GET_ENUM(buf, enum msg_type);
17361961e0fSrobinson 		if (rmsg->rm_direction != REPLY)
1747c478bd9Sstevel@tonic-gate 			return (FALSE);
1757c478bd9Sstevel@tonic-gate 		rmsg->rm_reply.rp_stat = IXDR_GET_ENUM(buf, enum reply_stat);
1767c478bd9Sstevel@tonic-gate 		if (rmsg->rm_reply.rp_stat != MSG_ACCEPTED) {
17761961e0fSrobinson 			if (rmsg->rm_reply.rp_stat == MSG_DENIED)
17861961e0fSrobinson 				return (xdr_rejected_reply(xdrs,
179*37972848SToomas Soome 				    &rmsg->rm_reply.rp_rjct));
1807c478bd9Sstevel@tonic-gate 			return (FALSE);
1817c478bd9Sstevel@tonic-gate 		}
1827c478bd9Sstevel@tonic-gate 		ar = &rmsg->rm_reply.rp_acpt;
1837c478bd9Sstevel@tonic-gate 		oa = &ar->ar_verf;
1847c478bd9Sstevel@tonic-gate 		buf = XDR_INLINE(xdrs, 2 * BYTES_PER_XDR_UNIT);
1857c478bd9Sstevel@tonic-gate 		if (buf != NULL) {
1867c478bd9Sstevel@tonic-gate 			oa->oa_flavor = IXDR_GET_ENUM(buf, enum_t);
1877c478bd9Sstevel@tonic-gate 			oa->oa_length = IXDR_GET_INT32(buf);
1887c478bd9Sstevel@tonic-gate 		} else {
1897c478bd9Sstevel@tonic-gate 			if (xdr_enum(xdrs, &oa->oa_flavor) == FALSE ||
19061961e0fSrobinson 			    xdr_u_int(xdrs, &oa->oa_length) == FALSE)
1917c478bd9Sstevel@tonic-gate 				return (FALSE);
1927c478bd9Sstevel@tonic-gate 		}
1937c478bd9Sstevel@tonic-gate 		if (oa->oa_length) {
19461961e0fSrobinson 			if (oa->oa_length > MAX_AUTH_BYTES)
1957c478bd9Sstevel@tonic-gate 				return (FALSE);
1967c478bd9Sstevel@tonic-gate 			if (oa->oa_base == NULL) {
19761961e0fSrobinson 				oa->oa_base = malloc(oa->oa_length);
1987c478bd9Sstevel@tonic-gate 				if (oa->oa_base == NULL) {
1997c478bd9Sstevel@tonic-gate 					syslog(LOG_ERR,
200*37972848SToomas Soome 					    "xdr_replymsg : out of memory.");
2017c478bd9Sstevel@tonic-gate 					rpc_callerr.re_status = RPC_SYSTEMERROR;
2027c478bd9Sstevel@tonic-gate 					return (FALSE);
2037c478bd9Sstevel@tonic-gate 				}
2047c478bd9Sstevel@tonic-gate 			}
2057c478bd9Sstevel@tonic-gate 			buf = XDR_INLINE(xdrs, RNDUP(oa->oa_length));
2067c478bd9Sstevel@tonic-gate 			if (buf == NULL) {
2077c478bd9Sstevel@tonic-gate 				if (xdr_opaque(xdrs, oa->oa_base,
20861961e0fSrobinson 				    oa->oa_length) == FALSE)
2097c478bd9Sstevel@tonic-gate 					return (FALSE);
2107c478bd9Sstevel@tonic-gate 			} else {
21161961e0fSrobinson 				(void) memcpy(oa->oa_base, buf, oa->oa_length);
2127c478bd9Sstevel@tonic-gate 			}
2137c478bd9Sstevel@tonic-gate 		}
2147c478bd9Sstevel@tonic-gate 		/*
2157c478bd9Sstevel@tonic-gate 		 * stat and rest of reply, copied from
2167c478bd9Sstevel@tonic-gate 		 * xdr_accepted_reply
2177c478bd9Sstevel@tonic-gate 		 */
21861961e0fSrobinson 		if (!xdr_enum(xdrs, (enum_t *)&ar->ar_stat))
2197c478bd9Sstevel@tonic-gate 			return (FALSE);
2207c478bd9Sstevel@tonic-gate 		switch (ar->ar_stat) {
2217c478bd9Sstevel@tonic-gate 		case SUCCESS:
22261961e0fSrobinson 			return ((*(ar->ar_results.proc))
223*37972848SToomas Soome 			    (xdrs, ar->ar_results.where));
2247c478bd9Sstevel@tonic-gate 		case PROG_MISMATCH:
22561961e0fSrobinson 			if (!xdr_u_int(xdrs, (uint_t *)&(ar->ar_vers.low)))
2267c478bd9Sstevel@tonic-gate 				return (FALSE);
22761961e0fSrobinson 			return (xdr_u_int(xdrs, (uint_t *)&(ar->ar_vers.high)));
2287c478bd9Sstevel@tonic-gate 		}
2297c478bd9Sstevel@tonic-gate 		return (TRUE);
2307c478bd9Sstevel@tonic-gate 	}
2317c478bd9Sstevel@tonic-gate 
2327c478bd9Sstevel@tonic-gate 	reply_dscrm[0].value = (int)MSG_ACCEPTED;
23361961e0fSrobinson 	reply_dscrm[0].proc = (xdrproc_t)xdr_accepted_reply;
2347c478bd9Sstevel@tonic-gate 	reply_dscrm[1].value = (int)MSG_DENIED;
23561961e0fSrobinson 	reply_dscrm[1].proc =  (xdrproc_t)xdr_rejected_reply;
2367c478bd9Sstevel@tonic-gate 	reply_dscrm[2].value = __dontcare__;
2377c478bd9Sstevel@tonic-gate 	reply_dscrm[2].proc = NULL_xdrproc_t;
2387c478bd9Sstevel@tonic-gate 	if (xdr_u_int(xdrs, &(rmsg->rm_xid)) &&
2397c478bd9Sstevel@tonic-gate 	    xdr_enum(xdrs, (enum_t *)&(rmsg->rm_direction)) &&
24061961e0fSrobinson 	    (rmsg->rm_direction == REPLY))
24161961e0fSrobinson 		return (xdr_union(xdrs, (enum_t *)&(rmsg->rm_reply.rp_stat),
242*37972848SToomas Soome 		    (caddr_t)&(rmsg->rm_reply.ru),
243*37972848SToomas Soome 		    reply_dscrm, NULL_xdrproc_t));
2447c478bd9Sstevel@tonic-gate 	return (FALSE);
2457c478bd9Sstevel@tonic-gate }
2467c478bd9Sstevel@tonic-gate 
2477c478bd9Sstevel@tonic-gate /*
2487c478bd9Sstevel@tonic-gate  * Serializes the "static part" of a call message header.
2497c478bd9Sstevel@tonic-gate  * The fields include: rm_xid, rm_direction, rpcvers, prog, and vers.
2507c478bd9Sstevel@tonic-gate  * The rm_xid is not really static, but the user can easily munge on the fly.
2517c478bd9Sstevel@tonic-gate  */
2527c478bd9Sstevel@tonic-gate bool_t
xdr_callhdr(XDR * xdrs,struct rpc_msg * cmsg)25361961e0fSrobinson xdr_callhdr(XDR *xdrs, struct rpc_msg *cmsg)
2547c478bd9Sstevel@tonic-gate {
2557c478bd9Sstevel@tonic-gate 	cmsg->rm_direction = CALL;
2567c478bd9Sstevel@tonic-gate 	cmsg->rm_call.cb_rpcvers = RPC_MSG_VERSION;
2577c478bd9Sstevel@tonic-gate 	if (xdrs->x_op == XDR_ENCODE &&
2587c478bd9Sstevel@tonic-gate 	    xdr_u_int(xdrs, &(cmsg->rm_xid)) &&
2597c478bd9Sstevel@tonic-gate 	    xdr_enum(xdrs, (enum_t *)&(cmsg->rm_direction)) &&
26061961e0fSrobinson 	    xdr_u_int(xdrs, (uint_t *)&(cmsg->rm_call.cb_rpcvers)) &&
26161961e0fSrobinson 	    xdr_u_int(xdrs, (uint_t *)&(cmsg->rm_call.cb_prog))) {
262*37972848SToomas Soome 		return (xdr_u_int(xdrs, (uint_t *)&(cmsg->rm_call.cb_vers)));
2637c478bd9Sstevel@tonic-gate 	}
2647c478bd9Sstevel@tonic-gate 	return (FALSE);
2657c478bd9Sstevel@tonic-gate }
2667c478bd9Sstevel@tonic-gate 
2677c478bd9Sstevel@tonic-gate /* ************************** Client utility routine ************* */
2687c478bd9Sstevel@tonic-gate 
2697c478bd9Sstevel@tonic-gate static void
accepted(enum accept_stat acpt_stat,struct rpc_err * error)27061961e0fSrobinson accepted(enum accept_stat acpt_stat, struct rpc_err *error)
2717c478bd9Sstevel@tonic-gate {
2727c478bd9Sstevel@tonic-gate 	switch (acpt_stat) {
2737c478bd9Sstevel@tonic-gate 
2747c478bd9Sstevel@tonic-gate 	case PROG_UNAVAIL:
2757c478bd9Sstevel@tonic-gate 		error->re_status = RPC_PROGUNAVAIL;
2767c478bd9Sstevel@tonic-gate 		return;
2777c478bd9Sstevel@tonic-gate 
2787c478bd9Sstevel@tonic-gate 	case PROG_MISMATCH:
2797c478bd9Sstevel@tonic-gate 		error->re_status = RPC_PROGVERSMISMATCH;
2807c478bd9Sstevel@tonic-gate 		return;
2817c478bd9Sstevel@tonic-gate 
2827c478bd9Sstevel@tonic-gate 	case PROC_UNAVAIL:
2837c478bd9Sstevel@tonic-gate 		error->re_status = RPC_PROCUNAVAIL;
2847c478bd9Sstevel@tonic-gate 		return;
2857c478bd9Sstevel@tonic-gate 
2867c478bd9Sstevel@tonic-gate 	case GARBAGE_ARGS:
2877c478bd9Sstevel@tonic-gate 		error->re_status = RPC_CANTDECODEARGS;
2887c478bd9Sstevel@tonic-gate 		return;
2897c478bd9Sstevel@tonic-gate 
2907c478bd9Sstevel@tonic-gate 	case SYSTEM_ERR:
2917c478bd9Sstevel@tonic-gate 		error->re_status = RPC_SYSTEMERROR;
2927c478bd9Sstevel@tonic-gate 		return;
2937c478bd9Sstevel@tonic-gate 
2947c478bd9Sstevel@tonic-gate 	case SUCCESS:
2957c478bd9Sstevel@tonic-gate 		error->re_status = RPC_SUCCESS;
2967c478bd9Sstevel@tonic-gate 		return;
2977c478bd9Sstevel@tonic-gate 	}
2987c478bd9Sstevel@tonic-gate 	/* something's wrong, but we don't know what ... */
2997c478bd9Sstevel@tonic-gate 	error->re_status = RPC_FAILED;
3007c478bd9Sstevel@tonic-gate 	error->re_lb.s1 = (int32_t)MSG_ACCEPTED;
3017c478bd9Sstevel@tonic-gate 	error->re_lb.s2 = (int32_t)acpt_stat;
3027c478bd9Sstevel@tonic-gate }
3037c478bd9Sstevel@tonic-gate 
3047c478bd9Sstevel@tonic-gate static void
rejected(enum reject_stat rjct_stat,struct rpc_err * error)30561961e0fSrobinson rejected(enum reject_stat rjct_stat, struct rpc_err *error)
3067c478bd9Sstevel@tonic-gate {
3077c478bd9Sstevel@tonic-gate 	switch (rjct_stat) {
3087c478bd9Sstevel@tonic-gate 	case RPC_MISMATCH:
3097c478bd9Sstevel@tonic-gate 		error->re_status = RPC_VERSMISMATCH;
3107c478bd9Sstevel@tonic-gate 		return;
3117c478bd9Sstevel@tonic-gate 
3127c478bd9Sstevel@tonic-gate 	case AUTH_ERROR:
3137c478bd9Sstevel@tonic-gate 		error->re_status = RPC_AUTHERROR;
3147c478bd9Sstevel@tonic-gate 		return;
3157c478bd9Sstevel@tonic-gate 	}
3167c478bd9Sstevel@tonic-gate 	/* something's wrong, but we don't know what ... */
3177c478bd9Sstevel@tonic-gate 	error->re_status = RPC_FAILED;
3187c478bd9Sstevel@tonic-gate 	error->re_lb.s1 = (int32_t)MSG_DENIED;
3197c478bd9Sstevel@tonic-gate 	error->re_lb.s2 = (int32_t)rjct_stat;
3207c478bd9Sstevel@tonic-gate }
3217c478bd9Sstevel@tonic-gate 
3227c478bd9Sstevel@tonic-gate /*
3237c478bd9Sstevel@tonic-gate  * given a reply message, fills in the error
3247c478bd9Sstevel@tonic-gate  */
3257c478bd9Sstevel@tonic-gate void
__seterr_reply(struct rpc_msg * msg,struct rpc_err * error)32661961e0fSrobinson __seterr_reply(struct rpc_msg *msg, struct rpc_err *error)
3277c478bd9Sstevel@tonic-gate {
3287c478bd9Sstevel@tonic-gate 	/* optimized for normal, SUCCESSful case */
3297c478bd9Sstevel@tonic-gate 	switch (msg->rm_reply.rp_stat) {
3307c478bd9Sstevel@tonic-gate 	case MSG_ACCEPTED:
3317c478bd9Sstevel@tonic-gate 		if (msg->acpted_rply.ar_stat == SUCCESS) {
3327c478bd9Sstevel@tonic-gate 			error->re_status = RPC_SUCCESS;
3337c478bd9Sstevel@tonic-gate 			return;
3347c478bd9Sstevel@tonic-gate 		};
3357c478bd9Sstevel@tonic-gate 		accepted(msg->acpted_rply.ar_stat, error);
3367c478bd9Sstevel@tonic-gate 		break;
3377c478bd9Sstevel@tonic-gate 
3387c478bd9Sstevel@tonic-gate 	case MSG_DENIED:
3397c478bd9Sstevel@tonic-gate 		rejected(msg->rjcted_rply.rj_stat, error);
3407c478bd9Sstevel@tonic-gate 		break;
3417c478bd9Sstevel@tonic-gate 
3427c478bd9Sstevel@tonic-gate 	default:
3437c478bd9Sstevel@tonic-gate 		error->re_status = RPC_FAILED;
3447c478bd9Sstevel@tonic-gate 		error->re_lb.s1 = (int32_t)(msg->rm_reply.rp_stat);
3457c478bd9Sstevel@tonic-gate 		break;
3467c478bd9Sstevel@tonic-gate 	}
3477c478bd9Sstevel@tonic-gate 
3487c478bd9Sstevel@tonic-gate 	switch (error->re_status) {
3497c478bd9Sstevel@tonic-gate 	case RPC_VERSMISMATCH:
3507c478bd9Sstevel@tonic-gate 		error->re_vers.low = msg->rjcted_rply.rj_vers.low;
3517c478bd9Sstevel@tonic-gate 		error->re_vers.high = msg->rjcted_rply.rj_vers.high;
3527c478bd9Sstevel@tonic-gate 		break;
3537c478bd9Sstevel@tonic-gate 
3547c478bd9Sstevel@tonic-gate 	case RPC_AUTHERROR:
3557c478bd9Sstevel@tonic-gate 		error->re_why = msg->rjcted_rply.rj_why;
3567c478bd9Sstevel@tonic-gate 		break;
3577c478bd9Sstevel@tonic-gate 
3587c478bd9Sstevel@tonic-gate 	case RPC_PROGVERSMISMATCH:
3597c478bd9Sstevel@tonic-gate 		error->re_vers.low = msg->acpted_rply.ar_vers.low;
3607c478bd9Sstevel@tonic-gate 		error->re_vers.high = msg->acpted_rply.ar_vers.high;
3617c478bd9Sstevel@tonic-gate 		break;
3627c478bd9Sstevel@tonic-gate 	}
3637c478bd9Sstevel@tonic-gate }
364