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 /*
24*e8031f0aSraf * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
257c478bd9Sstevel@tonic-gate * Use is subject to license terms.
267c478bd9Sstevel@tonic-gate */
27*e8031f0aSraf
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 #pragma ident "%Z%%M% %I% %E% SMI"
377c478bd9Sstevel@tonic-gate
387c478bd9Sstevel@tonic-gate /*
397c478bd9Sstevel@tonic-gate * This set of routines implements the rpc message definition,
407c478bd9Sstevel@tonic-gate * its serializer and some common rpc utility routines.
417c478bd9Sstevel@tonic-gate * The routines are meant for various implementations of rpc -
427c478bd9Sstevel@tonic-gate * they are NOT for the rpc client or rpc service implementations!
437c478bd9Sstevel@tonic-gate * Because authentication stuff is easy and is part of rpc, the opaque
447c478bd9Sstevel@tonic-gate * routines are also in this program.
457c478bd9Sstevel@tonic-gate */
467c478bd9Sstevel@tonic-gate
47*e8031f0aSraf #include "mt.h"
487c478bd9Sstevel@tonic-gate #include <sys/param.h>
497c478bd9Sstevel@tonic-gate #include <syslog.h>
507c478bd9Sstevel@tonic-gate #include <rpc/rpc.h>
517c478bd9Sstevel@tonic-gate #include <malloc.h>
527c478bd9Sstevel@tonic-gate
537c478bd9Sstevel@tonic-gate /* * * * * * * * * * * * * * XDR Authentication * * * * * * * * * * * */
547c478bd9Sstevel@tonic-gate
557c478bd9Sstevel@tonic-gate struct opaque_auth _null_auth;
567c478bd9Sstevel@tonic-gate
577c478bd9Sstevel@tonic-gate /*
587c478bd9Sstevel@tonic-gate * XDR an opaque authentication struct
597c478bd9Sstevel@tonic-gate * (see auth.h)
607c478bd9Sstevel@tonic-gate */
617c478bd9Sstevel@tonic-gate bool_t
xdr_opaque_auth(XDR * xdrs,struct opaque_auth * ap)6261961e0fSrobinson xdr_opaque_auth(XDR *xdrs, struct opaque_auth *ap)
637c478bd9Sstevel@tonic-gate {
6461961e0fSrobinson if (xdr_enum(xdrs, &(ap->oa_flavor)))
6561961e0fSrobinson return (xdr_bytes(xdrs, &ap->oa_base,
6661961e0fSrobinson &ap->oa_length, MAX_AUTH_BYTES));
677c478bd9Sstevel@tonic-gate return (FALSE);
687c478bd9Sstevel@tonic-gate }
697c478bd9Sstevel@tonic-gate
707c478bd9Sstevel@tonic-gate /*
717c478bd9Sstevel@tonic-gate * XDR a DES block
727c478bd9Sstevel@tonic-gate */
737c478bd9Sstevel@tonic-gate bool_t
xdr_des_block(XDR * xdrs,des_block * blkp)7461961e0fSrobinson xdr_des_block(XDR *xdrs, des_block *blkp)
757c478bd9Sstevel@tonic-gate {
7661961e0fSrobinson return (xdr_opaque(xdrs, (caddr_t)blkp, sizeof (des_block)));
777c478bd9Sstevel@tonic-gate }
787c478bd9Sstevel@tonic-gate
797c478bd9Sstevel@tonic-gate /* * * * * * * * * * * * * * XDR RPC MESSAGE * * * * * * * * * * * * * * * */
807c478bd9Sstevel@tonic-gate
817c478bd9Sstevel@tonic-gate /*
827c478bd9Sstevel@tonic-gate * XDR the MSG_ACCEPTED part of a reply message union
837c478bd9Sstevel@tonic-gate */
847c478bd9Sstevel@tonic-gate bool_t
xdr_accepted_reply(XDR * xdrs,struct accepted_reply * ar)8561961e0fSrobinson xdr_accepted_reply(XDR *xdrs, struct accepted_reply *ar)
867c478bd9Sstevel@tonic-gate {
877c478bd9Sstevel@tonic-gate /* personalized union, rather than calling xdr_union */
8861961e0fSrobinson if (!xdr_opaque_auth(xdrs, &(ar->ar_verf)))
897c478bd9Sstevel@tonic-gate return (FALSE);
9061961e0fSrobinson if (!xdr_enum(xdrs, (enum_t *)&(ar->ar_stat)))
917c478bd9Sstevel@tonic-gate return (FALSE);
927c478bd9Sstevel@tonic-gate
937c478bd9Sstevel@tonic-gate switch (ar->ar_stat) {
947c478bd9Sstevel@tonic-gate case SUCCESS:
9561961e0fSrobinson return ((*(ar->ar_results.proc))(xdrs, ar->ar_results.where));
967c478bd9Sstevel@tonic-gate case PROG_MISMATCH:
9761961e0fSrobinson if (!xdr_u_int(xdrs, (uint_t *)&(ar->ar_vers.low)))
987c478bd9Sstevel@tonic-gate return (FALSE);
9961961e0fSrobinson return (xdr_u_int(xdrs, (uint_t *)&(ar->ar_vers.high)));
1007c478bd9Sstevel@tonic-gate }
1017c478bd9Sstevel@tonic-gate return (TRUE); /* TRUE => open ended set of problems */
1027c478bd9Sstevel@tonic-gate }
1037c478bd9Sstevel@tonic-gate
1047c478bd9Sstevel@tonic-gate /*
1057c478bd9Sstevel@tonic-gate * XDR the MSG_DENIED part of a reply message union
1067c478bd9Sstevel@tonic-gate */
1077c478bd9Sstevel@tonic-gate bool_t
xdr_rejected_reply(XDR * xdrs,struct rejected_reply * rr)10861961e0fSrobinson xdr_rejected_reply(XDR *xdrs, struct rejected_reply *rr)
1097c478bd9Sstevel@tonic-gate {
1107c478bd9Sstevel@tonic-gate /* personalized union, rather than calling xdr_union */
11161961e0fSrobinson if (!xdr_enum(xdrs, (enum_t *)&(rr->rj_stat)))
1127c478bd9Sstevel@tonic-gate return (FALSE);
1137c478bd9Sstevel@tonic-gate switch (rr->rj_stat) {
1147c478bd9Sstevel@tonic-gate case RPC_MISMATCH:
11561961e0fSrobinson if (!xdr_u_int(xdrs, (uint_t *)&(rr->rj_vers.low)))
1167c478bd9Sstevel@tonic-gate return (FALSE);
11761961e0fSrobinson return (xdr_u_int(xdrs, (uint_t *)&(rr->rj_vers.high)));
1187c478bd9Sstevel@tonic-gate case AUTH_ERROR:
11961961e0fSrobinson return (xdr_enum(xdrs, (enum_t *)&(rr->rj_why)));
1207c478bd9Sstevel@tonic-gate }
1217c478bd9Sstevel@tonic-gate return (FALSE);
1227c478bd9Sstevel@tonic-gate }
1237c478bd9Sstevel@tonic-gate
1247c478bd9Sstevel@tonic-gate /*
1257c478bd9Sstevel@tonic-gate * XDR a reply message
1267c478bd9Sstevel@tonic-gate */
1277c478bd9Sstevel@tonic-gate bool_t
xdr_replymsg(XDR * xdrs,struct rpc_msg * rmsg)12861961e0fSrobinson xdr_replymsg(XDR *xdrs, struct rpc_msg *rmsg)
1297c478bd9Sstevel@tonic-gate {
1307c478bd9Sstevel@tonic-gate struct xdr_discrim reply_dscrm[3];
13161961e0fSrobinson rpc_inline_t *buf;
13261961e0fSrobinson struct accepted_reply *ar;
13361961e0fSrobinson struct opaque_auth *oa;
13461961e0fSrobinson uint_t rndup;
1357c478bd9Sstevel@tonic-gate
1367c478bd9Sstevel@tonic-gate if (xdrs->x_op == XDR_ENCODE &&
1377c478bd9Sstevel@tonic-gate rmsg->rm_reply.rp_stat == MSG_ACCEPTED &&
1387c478bd9Sstevel@tonic-gate rmsg->rm_direction == REPLY &&
1397c478bd9Sstevel@tonic-gate (buf = XDR_INLINE(xdrs, 6 * BYTES_PER_XDR_UNIT + (rndup =
1407c478bd9Sstevel@tonic-gate RNDUP(rmsg->rm_reply.rp_acpt.ar_verf.oa_length)))) != NULL) {
1417c478bd9Sstevel@tonic-gate IXDR_PUT_INT32(buf, rmsg->rm_xid);
1427c478bd9Sstevel@tonic-gate IXDR_PUT_ENUM(buf, rmsg->rm_direction);
1437c478bd9Sstevel@tonic-gate IXDR_PUT_ENUM(buf, rmsg->rm_reply.rp_stat);
1447c478bd9Sstevel@tonic-gate ar = &rmsg->rm_reply.rp_acpt;
1457c478bd9Sstevel@tonic-gate oa = &ar->ar_verf;
1467c478bd9Sstevel@tonic-gate IXDR_PUT_ENUM(buf, oa->oa_flavor);
1477c478bd9Sstevel@tonic-gate IXDR_PUT_INT32(buf, oa->oa_length);
1487c478bd9Sstevel@tonic-gate if (oa->oa_length) {
14961961e0fSrobinson (void) memcpy(buf, oa->oa_base, oa->oa_length);
1507c478bd9Sstevel@tonic-gate /* LINTED pointer alignment */
1517c478bd9Sstevel@tonic-gate buf = (rpc_inline_t *)(((caddr_t)buf) + oa->oa_length);
1527c478bd9Sstevel@tonic-gate }
1537c478bd9Sstevel@tonic-gate if ((rndup = (rndup - oa->oa_length)) > 0) {
1547c478bd9Sstevel@tonic-gate (void) memset((caddr_t)buf, 0, rndup);
1557c478bd9Sstevel@tonic-gate /* LINTED pointer alignment */
1567c478bd9Sstevel@tonic-gate buf = (rpc_inline_t *)(((caddr_t)buf) + rndup);
1577c478bd9Sstevel@tonic-gate }
1587c478bd9Sstevel@tonic-gate /*
1597c478bd9Sstevel@tonic-gate * stat and rest of reply, copied from xdr_accepted_reply
1607c478bd9Sstevel@tonic-gate */
1617c478bd9Sstevel@tonic-gate IXDR_PUT_ENUM(buf, ar->ar_stat);
1627c478bd9Sstevel@tonic-gate switch (ar->ar_stat) {
1637c478bd9Sstevel@tonic-gate case SUCCESS:
16461961e0fSrobinson return ((*(ar->ar_results.proc))
16561961e0fSrobinson (xdrs, ar->ar_results.where));
1667c478bd9Sstevel@tonic-gate case PROG_MISMATCH:
16761961e0fSrobinson if (!xdr_u_int(xdrs, (uint_t *)&(ar->ar_vers.low)))
1687c478bd9Sstevel@tonic-gate return (FALSE);
16961961e0fSrobinson return (xdr_u_int(xdrs, (uint_t *)&(ar->ar_vers.high)));
1707c478bd9Sstevel@tonic-gate }
1717c478bd9Sstevel@tonic-gate return (TRUE);
1727c478bd9Sstevel@tonic-gate }
1737c478bd9Sstevel@tonic-gate if (xdrs->x_op == XDR_DECODE &&
1747c478bd9Sstevel@tonic-gate (buf = XDR_INLINE(xdrs, 3 * BYTES_PER_XDR_UNIT)) != NULL) {
1757c478bd9Sstevel@tonic-gate rmsg->rm_xid = IXDR_GET_INT32(buf);
1767c478bd9Sstevel@tonic-gate rmsg->rm_direction = IXDR_GET_ENUM(buf, enum msg_type);
17761961e0fSrobinson if (rmsg->rm_direction != REPLY)
1787c478bd9Sstevel@tonic-gate return (FALSE);
1797c478bd9Sstevel@tonic-gate rmsg->rm_reply.rp_stat = IXDR_GET_ENUM(buf, enum reply_stat);
1807c478bd9Sstevel@tonic-gate if (rmsg->rm_reply.rp_stat != MSG_ACCEPTED) {
18161961e0fSrobinson if (rmsg->rm_reply.rp_stat == MSG_DENIED)
18261961e0fSrobinson return (xdr_rejected_reply(xdrs,
18361961e0fSrobinson &rmsg->rm_reply.rp_rjct));
1847c478bd9Sstevel@tonic-gate return (FALSE);
1857c478bd9Sstevel@tonic-gate }
1867c478bd9Sstevel@tonic-gate ar = &rmsg->rm_reply.rp_acpt;
1877c478bd9Sstevel@tonic-gate oa = &ar->ar_verf;
1887c478bd9Sstevel@tonic-gate buf = XDR_INLINE(xdrs, 2 * BYTES_PER_XDR_UNIT);
1897c478bd9Sstevel@tonic-gate if (buf != NULL) {
1907c478bd9Sstevel@tonic-gate oa->oa_flavor = IXDR_GET_ENUM(buf, enum_t);
1917c478bd9Sstevel@tonic-gate oa->oa_length = IXDR_GET_INT32(buf);
1927c478bd9Sstevel@tonic-gate } else {
1937c478bd9Sstevel@tonic-gate if (xdr_enum(xdrs, &oa->oa_flavor) == FALSE ||
19461961e0fSrobinson xdr_u_int(xdrs, &oa->oa_length) == FALSE)
1957c478bd9Sstevel@tonic-gate return (FALSE);
1967c478bd9Sstevel@tonic-gate }
1977c478bd9Sstevel@tonic-gate if (oa->oa_length) {
19861961e0fSrobinson if (oa->oa_length > MAX_AUTH_BYTES)
1997c478bd9Sstevel@tonic-gate return (FALSE);
2007c478bd9Sstevel@tonic-gate if (oa->oa_base == NULL) {
20161961e0fSrobinson oa->oa_base = malloc(oa->oa_length);
2027c478bd9Sstevel@tonic-gate if (oa->oa_base == NULL) {
2037c478bd9Sstevel@tonic-gate syslog(LOG_ERR,
2047c478bd9Sstevel@tonic-gate "xdr_replymsg : "
2057c478bd9Sstevel@tonic-gate "out of memory.");
2067c478bd9Sstevel@tonic-gate rpc_callerr.re_status = RPC_SYSTEMERROR;
2077c478bd9Sstevel@tonic-gate return (FALSE);
2087c478bd9Sstevel@tonic-gate }
2097c478bd9Sstevel@tonic-gate }
2107c478bd9Sstevel@tonic-gate buf = XDR_INLINE(xdrs, RNDUP(oa->oa_length));
2117c478bd9Sstevel@tonic-gate if (buf == NULL) {
2127c478bd9Sstevel@tonic-gate if (xdr_opaque(xdrs, oa->oa_base,
21361961e0fSrobinson oa->oa_length) == FALSE)
2147c478bd9Sstevel@tonic-gate return (FALSE);
2157c478bd9Sstevel@tonic-gate } else {
21661961e0fSrobinson (void) memcpy(oa->oa_base, buf, oa->oa_length);
2177c478bd9Sstevel@tonic-gate }
2187c478bd9Sstevel@tonic-gate }
2197c478bd9Sstevel@tonic-gate /*
2207c478bd9Sstevel@tonic-gate * stat and rest of reply, copied from
2217c478bd9Sstevel@tonic-gate * xdr_accepted_reply
2227c478bd9Sstevel@tonic-gate */
22361961e0fSrobinson if (!xdr_enum(xdrs, (enum_t *)&ar->ar_stat))
2247c478bd9Sstevel@tonic-gate return (FALSE);
2257c478bd9Sstevel@tonic-gate switch (ar->ar_stat) {
2267c478bd9Sstevel@tonic-gate case SUCCESS:
22761961e0fSrobinson return ((*(ar->ar_results.proc))
22861961e0fSrobinson (xdrs, ar->ar_results.where));
2297c478bd9Sstevel@tonic-gate case PROG_MISMATCH:
23061961e0fSrobinson if (!xdr_u_int(xdrs, (uint_t *)&(ar->ar_vers.low)))
2317c478bd9Sstevel@tonic-gate return (FALSE);
23261961e0fSrobinson return (xdr_u_int(xdrs, (uint_t *)&(ar->ar_vers.high)));
2337c478bd9Sstevel@tonic-gate }
2347c478bd9Sstevel@tonic-gate return (TRUE);
2357c478bd9Sstevel@tonic-gate }
2367c478bd9Sstevel@tonic-gate
2377c478bd9Sstevel@tonic-gate reply_dscrm[0].value = (int)MSG_ACCEPTED;
2387c478bd9Sstevel@tonic-gate reply_dscrm[0].proc = (xdrproc_t)xdr_accepted_reply;
2397c478bd9Sstevel@tonic-gate reply_dscrm[1].value = (int)MSG_DENIED;
2407c478bd9Sstevel@tonic-gate reply_dscrm[1].proc = (xdrproc_t)xdr_rejected_reply;
2417c478bd9Sstevel@tonic-gate reply_dscrm[2].value = __dontcare__;
2427c478bd9Sstevel@tonic-gate reply_dscrm[2].proc = NULL_xdrproc_t;
2437c478bd9Sstevel@tonic-gate if (xdr_u_int(xdrs, &(rmsg->rm_xid)) &&
2447c478bd9Sstevel@tonic-gate xdr_enum(xdrs, (enum_t *)&(rmsg->rm_direction)) &&
24561961e0fSrobinson (rmsg->rm_direction == REPLY))
24661961e0fSrobinson return (xdr_union(xdrs, (enum_t *)&(rmsg->rm_reply.rp_stat),
2477c478bd9Sstevel@tonic-gate (caddr_t)&(rmsg->rm_reply.ru),
24861961e0fSrobinson reply_dscrm, NULL_xdrproc_t));
2497c478bd9Sstevel@tonic-gate return (FALSE);
2507c478bd9Sstevel@tonic-gate }
2517c478bd9Sstevel@tonic-gate
2527c478bd9Sstevel@tonic-gate /*
2537c478bd9Sstevel@tonic-gate * Serializes the "static part" of a call message header.
2547c478bd9Sstevel@tonic-gate * The fields include: rm_xid, rm_direction, rpcvers, prog, and vers.
2557c478bd9Sstevel@tonic-gate * The rm_xid is not really static, but the user can easily munge on the fly.
2567c478bd9Sstevel@tonic-gate */
2577c478bd9Sstevel@tonic-gate bool_t
xdr_callhdr(XDR * xdrs,struct rpc_msg * cmsg)25861961e0fSrobinson xdr_callhdr(XDR *xdrs, struct rpc_msg *cmsg)
2597c478bd9Sstevel@tonic-gate {
2607c478bd9Sstevel@tonic-gate cmsg->rm_direction = CALL;
2617c478bd9Sstevel@tonic-gate cmsg->rm_call.cb_rpcvers = RPC_MSG_VERSION;
2627c478bd9Sstevel@tonic-gate if (xdrs->x_op == XDR_ENCODE &&
2637c478bd9Sstevel@tonic-gate xdr_u_int(xdrs, &(cmsg->rm_xid)) &&
2647c478bd9Sstevel@tonic-gate xdr_enum(xdrs, (enum_t *)&(cmsg->rm_direction)) &&
26561961e0fSrobinson xdr_u_int(xdrs, (uint_t *)&(cmsg->rm_call.cb_rpcvers)) &&
26661961e0fSrobinson xdr_u_int(xdrs, (uint_t *)&(cmsg->rm_call.cb_prog))) {
26761961e0fSrobinson return (xdr_u_int(xdrs, (uint_t *)&(cmsg->rm_call.cb_vers)));
2687c478bd9Sstevel@tonic-gate }
2697c478bd9Sstevel@tonic-gate return (FALSE);
2707c478bd9Sstevel@tonic-gate }
2717c478bd9Sstevel@tonic-gate
2727c478bd9Sstevel@tonic-gate /* ************************** Client utility routine ************* */
2737c478bd9Sstevel@tonic-gate
2747c478bd9Sstevel@tonic-gate static void
accepted(enum accept_stat acpt_stat,struct rpc_err * error)27561961e0fSrobinson accepted(enum accept_stat acpt_stat, struct rpc_err *error)
2767c478bd9Sstevel@tonic-gate {
2777c478bd9Sstevel@tonic-gate switch (acpt_stat) {
2787c478bd9Sstevel@tonic-gate
2797c478bd9Sstevel@tonic-gate case PROG_UNAVAIL:
2807c478bd9Sstevel@tonic-gate error->re_status = RPC_PROGUNAVAIL;
2817c478bd9Sstevel@tonic-gate return;
2827c478bd9Sstevel@tonic-gate
2837c478bd9Sstevel@tonic-gate case PROG_MISMATCH:
2847c478bd9Sstevel@tonic-gate error->re_status = RPC_PROGVERSMISMATCH;
2857c478bd9Sstevel@tonic-gate return;
2867c478bd9Sstevel@tonic-gate
2877c478bd9Sstevel@tonic-gate case PROC_UNAVAIL:
2887c478bd9Sstevel@tonic-gate error->re_status = RPC_PROCUNAVAIL;
2897c478bd9Sstevel@tonic-gate return;
2907c478bd9Sstevel@tonic-gate
2917c478bd9Sstevel@tonic-gate case GARBAGE_ARGS:
2927c478bd9Sstevel@tonic-gate error->re_status = RPC_CANTDECODEARGS;
2937c478bd9Sstevel@tonic-gate return;
2947c478bd9Sstevel@tonic-gate
2957c478bd9Sstevel@tonic-gate case SYSTEM_ERR:
2967c478bd9Sstevel@tonic-gate error->re_status = RPC_SYSTEMERROR;
2977c478bd9Sstevel@tonic-gate return;
2987c478bd9Sstevel@tonic-gate
2997c478bd9Sstevel@tonic-gate case SUCCESS:
3007c478bd9Sstevel@tonic-gate error->re_status = RPC_SUCCESS;
3017c478bd9Sstevel@tonic-gate return;
3027c478bd9Sstevel@tonic-gate }
3037c478bd9Sstevel@tonic-gate /* something's wrong, but we don't know what ... */
3047c478bd9Sstevel@tonic-gate error->re_status = RPC_FAILED;
3057c478bd9Sstevel@tonic-gate error->re_lb.s1 = (int32_t)MSG_ACCEPTED;
3067c478bd9Sstevel@tonic-gate error->re_lb.s2 = (int32_t)acpt_stat;
3077c478bd9Sstevel@tonic-gate }
3087c478bd9Sstevel@tonic-gate
3097c478bd9Sstevel@tonic-gate static void
rejected(enum reject_stat rjct_stat,struct rpc_err * error)31061961e0fSrobinson rejected(enum reject_stat rjct_stat, struct rpc_err *error)
3117c478bd9Sstevel@tonic-gate {
3127c478bd9Sstevel@tonic-gate switch (rjct_stat) {
3137c478bd9Sstevel@tonic-gate case RPC_MISMATCH:
3147c478bd9Sstevel@tonic-gate error->re_status = RPC_VERSMISMATCH;
3157c478bd9Sstevel@tonic-gate return;
3167c478bd9Sstevel@tonic-gate
3177c478bd9Sstevel@tonic-gate case AUTH_ERROR:
3187c478bd9Sstevel@tonic-gate error->re_status = RPC_AUTHERROR;
3197c478bd9Sstevel@tonic-gate return;
3207c478bd9Sstevel@tonic-gate }
3217c478bd9Sstevel@tonic-gate /* something's wrong, but we don't know what ... */
3227c478bd9Sstevel@tonic-gate error->re_status = RPC_FAILED;
3237c478bd9Sstevel@tonic-gate error->re_lb.s1 = (int32_t)MSG_DENIED;
3247c478bd9Sstevel@tonic-gate error->re_lb.s2 = (int32_t)rjct_stat;
3257c478bd9Sstevel@tonic-gate }
3267c478bd9Sstevel@tonic-gate
3277c478bd9Sstevel@tonic-gate /*
3287c478bd9Sstevel@tonic-gate * given a reply message, fills in the error
3297c478bd9Sstevel@tonic-gate */
3307c478bd9Sstevel@tonic-gate void
__seterr_reply(struct rpc_msg * msg,struct rpc_err * error)33161961e0fSrobinson __seterr_reply(struct rpc_msg *msg, struct rpc_err *error)
3327c478bd9Sstevel@tonic-gate {
3337c478bd9Sstevel@tonic-gate /* optimized for normal, SUCCESSful case */
3347c478bd9Sstevel@tonic-gate switch (msg->rm_reply.rp_stat) {
3357c478bd9Sstevel@tonic-gate case MSG_ACCEPTED:
3367c478bd9Sstevel@tonic-gate if (msg->acpted_rply.ar_stat == SUCCESS) {
3377c478bd9Sstevel@tonic-gate error->re_status = RPC_SUCCESS;
3387c478bd9Sstevel@tonic-gate return;
3397c478bd9Sstevel@tonic-gate };
3407c478bd9Sstevel@tonic-gate accepted(msg->acpted_rply.ar_stat, error);
3417c478bd9Sstevel@tonic-gate break;
3427c478bd9Sstevel@tonic-gate
3437c478bd9Sstevel@tonic-gate case MSG_DENIED:
3447c478bd9Sstevel@tonic-gate rejected(msg->rjcted_rply.rj_stat, error);
3457c478bd9Sstevel@tonic-gate break;
3467c478bd9Sstevel@tonic-gate
3477c478bd9Sstevel@tonic-gate default:
3487c478bd9Sstevel@tonic-gate error->re_status = RPC_FAILED;
3497c478bd9Sstevel@tonic-gate error->re_lb.s1 = (int32_t)(msg->rm_reply.rp_stat);
3507c478bd9Sstevel@tonic-gate break;
3517c478bd9Sstevel@tonic-gate }
3527c478bd9Sstevel@tonic-gate
3537c478bd9Sstevel@tonic-gate switch (error->re_status) {
3547c478bd9Sstevel@tonic-gate case RPC_VERSMISMATCH:
3557c478bd9Sstevel@tonic-gate error->re_vers.low = msg->rjcted_rply.rj_vers.low;
3567c478bd9Sstevel@tonic-gate error->re_vers.high = msg->rjcted_rply.rj_vers.high;
3577c478bd9Sstevel@tonic-gate break;
3587c478bd9Sstevel@tonic-gate
3597c478bd9Sstevel@tonic-gate case RPC_AUTHERROR:
3607c478bd9Sstevel@tonic-gate error->re_why = msg->rjcted_rply.rj_why;
3617c478bd9Sstevel@tonic-gate break;
3627c478bd9Sstevel@tonic-gate
3637c478bd9Sstevel@tonic-gate case RPC_PROGVERSMISMATCH:
3647c478bd9Sstevel@tonic-gate error->re_vers.low = msg->acpted_rply.ar_vers.low;
3657c478bd9Sstevel@tonic-gate error->re_vers.high = msg->acpted_rply.ar_vers.high;
3667c478bd9Sstevel@tonic-gate break;
3677c478bd9Sstevel@tonic-gate }
3687c478bd9Sstevel@tonic-gate }
369