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 5*0a701b1eSRobert Gordon * Common Development and Distribution License (the "License"). 6*0a701b1eSRobert Gordon * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 22*0a701b1eSRobert Gordon * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ 277c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate /* 307c478bd9Sstevel@tonic-gate * Portions of this source code were derived from Berkeley 4.3 BSD 317c478bd9Sstevel@tonic-gate * under license from the Regents of the University of California. 327c478bd9Sstevel@tonic-gate */ 337c478bd9Sstevel@tonic-gate 347c478bd9Sstevel@tonic-gate /* 357c478bd9Sstevel@tonic-gate * rpc_prot.c 367c478bd9Sstevel@tonic-gate * This set of routines implements the rpc message definition, 377c478bd9Sstevel@tonic-gate * its serializer and some common rpc utility routines. 387c478bd9Sstevel@tonic-gate * The routines are meant for various implementations of rpc - 397c478bd9Sstevel@tonic-gate * they are NOT for the rpc client or rpc service implementations! 407c478bd9Sstevel@tonic-gate * Because authentication stuff is easy and is part of rpc, the opaque 417c478bd9Sstevel@tonic-gate * routines are also in this program. 427c478bd9Sstevel@tonic-gate */ 437c478bd9Sstevel@tonic-gate 447c478bd9Sstevel@tonic-gate #include <sys/param.h> 457c478bd9Sstevel@tonic-gate 467c478bd9Sstevel@tonic-gate #include <sys/types.h> 477c478bd9Sstevel@tonic-gate #include <sys/t_lock.h> 487c478bd9Sstevel@tonic-gate #include <sys/systm.h> 497c478bd9Sstevel@tonic-gate 507c478bd9Sstevel@tonic-gate #include <rpc/types.h> 517c478bd9Sstevel@tonic-gate #include <rpc/xdr.h> 527c478bd9Sstevel@tonic-gate #include <rpc/auth.h> 537c478bd9Sstevel@tonic-gate #include <rpc/clnt.h> 547c478bd9Sstevel@tonic-gate #include <rpc/rpc_msg.h> 557c478bd9Sstevel@tonic-gate 567c478bd9Sstevel@tonic-gate /* * * * * * * * * * * * * * XDR Authentication * * * * * * * * * * * */ 577c478bd9Sstevel@tonic-gate 587c478bd9Sstevel@tonic-gate struct opaque_auth _null_auth; 597c478bd9Sstevel@tonic-gate 607c478bd9Sstevel@tonic-gate /* 617c478bd9Sstevel@tonic-gate * XDR an opaque authentication struct 627c478bd9Sstevel@tonic-gate * (see auth.h) 637c478bd9Sstevel@tonic-gate */ 647c478bd9Sstevel@tonic-gate bool_t 657c478bd9Sstevel@tonic-gate xdr_opaque_auth(XDR *xdrs, struct opaque_auth *ap) 667c478bd9Sstevel@tonic-gate { 677c478bd9Sstevel@tonic-gate if (xdr_enum(xdrs, &(ap->oa_flavor))) { 687c478bd9Sstevel@tonic-gate return (xdr_bytes(xdrs, &ap->oa_base, 697c478bd9Sstevel@tonic-gate &ap->oa_length, MAX_AUTH_BYTES)); 707c478bd9Sstevel@tonic-gate } 717c478bd9Sstevel@tonic-gate return (FALSE); 727c478bd9Sstevel@tonic-gate } 737c478bd9Sstevel@tonic-gate 747c478bd9Sstevel@tonic-gate /* 757c478bd9Sstevel@tonic-gate * XDR a DES block 767c478bd9Sstevel@tonic-gate */ 777c478bd9Sstevel@tonic-gate bool_t 787c478bd9Sstevel@tonic-gate xdr_des_block(XDR *xdrs, des_block *blkp) 797c478bd9Sstevel@tonic-gate { 807c478bd9Sstevel@tonic-gate return (xdr_opaque(xdrs, (caddr_t)blkp, sizeof (des_block))); 817c478bd9Sstevel@tonic-gate } 827c478bd9Sstevel@tonic-gate 837c478bd9Sstevel@tonic-gate /* * * * * * * * * * * * * * XDR RPC MESSAGE * * * * * * * * * * * * * * * */ 847c478bd9Sstevel@tonic-gate 857c478bd9Sstevel@tonic-gate /* 867c478bd9Sstevel@tonic-gate * XDR the MSG_ACCEPTED part of a reply message union 877c478bd9Sstevel@tonic-gate */ 887c478bd9Sstevel@tonic-gate bool_t 897c478bd9Sstevel@tonic-gate xdr_accepted_reply(XDR *xdrs, struct accepted_reply *ar) 907c478bd9Sstevel@tonic-gate { 917c478bd9Sstevel@tonic-gate /* personalized union, rather than calling xdr_union */ 927c478bd9Sstevel@tonic-gate if (!xdr_opaque_auth(xdrs, &(ar->ar_verf))) 937c478bd9Sstevel@tonic-gate return (FALSE); 947c478bd9Sstevel@tonic-gate if (!xdr_enum(xdrs, (enum_t *)&(ar->ar_stat))) 957c478bd9Sstevel@tonic-gate return (FALSE); 967c478bd9Sstevel@tonic-gate 977c478bd9Sstevel@tonic-gate switch (ar->ar_stat) { 987c478bd9Sstevel@tonic-gate case SUCCESS: 997c478bd9Sstevel@tonic-gate return ((*(ar->ar_results.proc))(xdrs, ar->ar_results.where)); 1007c478bd9Sstevel@tonic-gate 1017c478bd9Sstevel@tonic-gate case PROG_MISMATCH: 1027c478bd9Sstevel@tonic-gate if (!xdr_rpcvers(xdrs, &(ar->ar_vers.low))) 1037c478bd9Sstevel@tonic-gate return (FALSE); 1047c478bd9Sstevel@tonic-gate return (xdr_rpcvers(xdrs, &(ar->ar_vers.high))); 1057c478bd9Sstevel@tonic-gate } 1067c478bd9Sstevel@tonic-gate return (TRUE); /* TRUE => open ended set of problems */ 1077c478bd9Sstevel@tonic-gate } 1087c478bd9Sstevel@tonic-gate 1097c478bd9Sstevel@tonic-gate /* 1107c478bd9Sstevel@tonic-gate * XDR the MSG_DENIED part of a reply message union 1117c478bd9Sstevel@tonic-gate */ 1127c478bd9Sstevel@tonic-gate bool_t 1137c478bd9Sstevel@tonic-gate xdr_rejected_reply(XDR *xdrs, struct rejected_reply *rr) 1147c478bd9Sstevel@tonic-gate { 1157c478bd9Sstevel@tonic-gate /* personalized union, rather than calling xdr_union */ 1167c478bd9Sstevel@tonic-gate if (!xdr_enum(xdrs, (enum_t *)&(rr->rj_stat))) 1177c478bd9Sstevel@tonic-gate return (FALSE); 1187c478bd9Sstevel@tonic-gate switch (rr->rj_stat) { 1197c478bd9Sstevel@tonic-gate 1207c478bd9Sstevel@tonic-gate case RPC_MISMATCH: 1217c478bd9Sstevel@tonic-gate if (!xdr_rpcvers(xdrs, &(rr->rj_vers.low))) 1227c478bd9Sstevel@tonic-gate return (FALSE); 1237c478bd9Sstevel@tonic-gate return (xdr_rpcvers(xdrs, &(rr->rj_vers.high))); 1247c478bd9Sstevel@tonic-gate 1257c478bd9Sstevel@tonic-gate case AUTH_ERROR: 1267c478bd9Sstevel@tonic-gate return (xdr_enum(xdrs, (enum_t *)&(rr->rj_why))); 1277c478bd9Sstevel@tonic-gate } 1287c478bd9Sstevel@tonic-gate return (FALSE); 1297c478bd9Sstevel@tonic-gate } 1307c478bd9Sstevel@tonic-gate 1317c478bd9Sstevel@tonic-gate static struct xdr_discrim reply_dscrm[3] = { 1327c478bd9Sstevel@tonic-gate { MSG_ACCEPTED, xdr_accepted_reply }, 1337c478bd9Sstevel@tonic-gate { MSG_DENIED, xdr_rejected_reply }, 1347c478bd9Sstevel@tonic-gate { __dontcare__, NULL_xdrproc_t } 1357c478bd9Sstevel@tonic-gate }; 1367c478bd9Sstevel@tonic-gate 1377c478bd9Sstevel@tonic-gate /* 1387c478bd9Sstevel@tonic-gate * XDR a reply message 1397c478bd9Sstevel@tonic-gate */ 1407c478bd9Sstevel@tonic-gate bool_t 1417c478bd9Sstevel@tonic-gate xdr_replymsg(XDR *xdrs, struct rpc_msg *rmsg) 1427c478bd9Sstevel@tonic-gate { 1437c478bd9Sstevel@tonic-gate int32_t *buf; 1447c478bd9Sstevel@tonic-gate struct accepted_reply *ar; 1457c478bd9Sstevel@tonic-gate struct opaque_auth *oa; 1467c478bd9Sstevel@tonic-gate uint_t rndup; 1477c478bd9Sstevel@tonic-gate 1487c478bd9Sstevel@tonic-gate if (xdrs->x_op == XDR_ENCODE && 1497c478bd9Sstevel@tonic-gate rmsg->rm_reply.rp_stat == MSG_ACCEPTED && 1507c478bd9Sstevel@tonic-gate rmsg->rm_direction == REPLY && 1517c478bd9Sstevel@tonic-gate (buf = XDR_INLINE(xdrs, 6 * BYTES_PER_XDR_UNIT + (rndup = 1527c478bd9Sstevel@tonic-gate RNDUP(rmsg->rm_reply.rp_acpt.ar_verf.oa_length)))) != NULL) { 1537c478bd9Sstevel@tonic-gate IXDR_PUT_INT32(buf, rmsg->rm_xid); 1547c478bd9Sstevel@tonic-gate IXDR_PUT_ENUM(buf, rmsg->rm_direction); 1557c478bd9Sstevel@tonic-gate IXDR_PUT_ENUM(buf, rmsg->rm_reply.rp_stat); 1567c478bd9Sstevel@tonic-gate ar = &rmsg->rm_reply.rp_acpt; 1577c478bd9Sstevel@tonic-gate oa = &ar->ar_verf; 1587c478bd9Sstevel@tonic-gate IXDR_PUT_ENUM(buf, oa->oa_flavor); 1597c478bd9Sstevel@tonic-gate IXDR_PUT_INT32(buf, oa->oa_length); 1607c478bd9Sstevel@tonic-gate if (oa->oa_length) { 1617c478bd9Sstevel@tonic-gate bcopy(oa->oa_base, buf, oa->oa_length); 1627c478bd9Sstevel@tonic-gate buf = (int32_t *)(((caddr_t)buf) + oa->oa_length); 1637c478bd9Sstevel@tonic-gate if ((rndup = (rndup - oa->oa_length)) > 0) { 1647c478bd9Sstevel@tonic-gate bzero(buf, rndup); 1657c478bd9Sstevel@tonic-gate buf = (int32_t *)(((caddr_t)buf) + rndup); 1667c478bd9Sstevel@tonic-gate } 1677c478bd9Sstevel@tonic-gate } 1687c478bd9Sstevel@tonic-gate /* 1697c478bd9Sstevel@tonic-gate * stat and rest of reply, copied from xdr_accepted_reply 1707c478bd9Sstevel@tonic-gate */ 1717c478bd9Sstevel@tonic-gate IXDR_PUT_ENUM(buf, ar->ar_stat); 1727c478bd9Sstevel@tonic-gate switch (ar->ar_stat) { 1737c478bd9Sstevel@tonic-gate case SUCCESS: 1747c478bd9Sstevel@tonic-gate return ((*(ar->ar_results.proc))(xdrs, 1757c478bd9Sstevel@tonic-gate ar->ar_results.where)); 1767c478bd9Sstevel@tonic-gate 1777c478bd9Sstevel@tonic-gate case PROG_MISMATCH: 1787c478bd9Sstevel@tonic-gate if (!xdr_rpcvers(xdrs, &(ar->ar_vers.low))) 1797c478bd9Sstevel@tonic-gate return (FALSE); 1807c478bd9Sstevel@tonic-gate return (xdr_rpcvers(xdrs, &(ar->ar_vers.high))); 1817c478bd9Sstevel@tonic-gate } 1827c478bd9Sstevel@tonic-gate return (TRUE); 1837c478bd9Sstevel@tonic-gate } 1847c478bd9Sstevel@tonic-gate if (xdrs->x_op == XDR_DECODE && 1857c478bd9Sstevel@tonic-gate (buf = XDR_INLINE(xdrs, 3 * BYTES_PER_XDR_UNIT)) != NULL) { 1867c478bd9Sstevel@tonic-gate rmsg->rm_xid = IXDR_GET_INT32(buf); 1877c478bd9Sstevel@tonic-gate rmsg->rm_direction = IXDR_GET_ENUM(buf, enum msg_type); 1887c478bd9Sstevel@tonic-gate if (rmsg->rm_direction != REPLY) 1897c478bd9Sstevel@tonic-gate return (FALSE); 1907c478bd9Sstevel@tonic-gate rmsg->rm_reply.rp_stat = IXDR_GET_ENUM(buf, enum reply_stat); 1917c478bd9Sstevel@tonic-gate if (rmsg->rm_reply.rp_stat != MSG_ACCEPTED) { 1927c478bd9Sstevel@tonic-gate if (rmsg->rm_reply.rp_stat == MSG_DENIED) 1937c478bd9Sstevel@tonic-gate return (xdr_rejected_reply(xdrs, 1947c478bd9Sstevel@tonic-gate &rmsg->rm_reply.rp_rjct)); 1957c478bd9Sstevel@tonic-gate return (FALSE); 1967c478bd9Sstevel@tonic-gate } 1977c478bd9Sstevel@tonic-gate ar = &rmsg->rm_reply.rp_acpt; 1987c478bd9Sstevel@tonic-gate oa = &ar->ar_verf; 1997c478bd9Sstevel@tonic-gate buf = XDR_INLINE(xdrs, 2 * BYTES_PER_XDR_UNIT); 2007c478bd9Sstevel@tonic-gate if (buf != NULL) { 2017c478bd9Sstevel@tonic-gate oa->oa_flavor = IXDR_GET_ENUM(buf, enum_t); 2027c478bd9Sstevel@tonic-gate oa->oa_length = IXDR_GET_INT32(buf); 2037c478bd9Sstevel@tonic-gate } else { 2047c478bd9Sstevel@tonic-gate if (xdr_enum(xdrs, &oa->oa_flavor) == FALSE || 2057c478bd9Sstevel@tonic-gate xdr_u_int(xdrs, &oa->oa_length) == FALSE) 2067c478bd9Sstevel@tonic-gate return (FALSE); 2077c478bd9Sstevel@tonic-gate } 2087c478bd9Sstevel@tonic-gate if (oa->oa_length) { 2097c478bd9Sstevel@tonic-gate if (oa->oa_length > MAX_AUTH_BYTES) 2107c478bd9Sstevel@tonic-gate return (FALSE); 2117c478bd9Sstevel@tonic-gate if (oa->oa_base == NULL) { 2127c478bd9Sstevel@tonic-gate oa->oa_base = (caddr_t) 2137c478bd9Sstevel@tonic-gate mem_alloc(oa->oa_length); 2147c478bd9Sstevel@tonic-gate } 2157c478bd9Sstevel@tonic-gate buf = XDR_INLINE(xdrs, RNDUP(oa->oa_length)); 2167c478bd9Sstevel@tonic-gate if (buf == NULL) { 2177c478bd9Sstevel@tonic-gate if (xdr_opaque(xdrs, oa->oa_base, 2187c478bd9Sstevel@tonic-gate oa->oa_length) == FALSE) 2197c478bd9Sstevel@tonic-gate return (FALSE); 2207c478bd9Sstevel@tonic-gate } else { 2217c478bd9Sstevel@tonic-gate bcopy(buf, oa->oa_base, oa->oa_length); 2227c478bd9Sstevel@tonic-gate } 2237c478bd9Sstevel@tonic-gate } 2247c478bd9Sstevel@tonic-gate /* 2257c478bd9Sstevel@tonic-gate * stat and rest of reply, copied from 2267c478bd9Sstevel@tonic-gate * xdr_accepted_reply 2277c478bd9Sstevel@tonic-gate */ 2287c478bd9Sstevel@tonic-gate if (!xdr_enum(xdrs, (enum_t *)&ar->ar_stat)) 2297c478bd9Sstevel@tonic-gate return (FALSE); 2307c478bd9Sstevel@tonic-gate switch (ar->ar_stat) { 2317c478bd9Sstevel@tonic-gate case SUCCESS: 2327c478bd9Sstevel@tonic-gate return ((*(ar->ar_results.proc))(xdrs, 2337c478bd9Sstevel@tonic-gate ar->ar_results.where)); 2347c478bd9Sstevel@tonic-gate 2357c478bd9Sstevel@tonic-gate case PROG_MISMATCH: 2367c478bd9Sstevel@tonic-gate if (!xdr_rpcvers(xdrs, &ar->ar_vers.low)) 2377c478bd9Sstevel@tonic-gate return (FALSE); 2387c478bd9Sstevel@tonic-gate return (xdr_rpcvers(xdrs, &ar->ar_vers.high)); 2397c478bd9Sstevel@tonic-gate } 2407c478bd9Sstevel@tonic-gate return (TRUE); 2417c478bd9Sstevel@tonic-gate } 2427c478bd9Sstevel@tonic-gate 2437c478bd9Sstevel@tonic-gate if (xdr_u_int(xdrs, &(rmsg->rm_xid)) && 2447c478bd9Sstevel@tonic-gate xdr_enum(xdrs, (enum_t *)&(rmsg->rm_direction)) && 2457c478bd9Sstevel@tonic-gate (rmsg->rm_direction == REPLY)) 2467c478bd9Sstevel@tonic-gate return (xdr_union(xdrs, (enum_t *)&(rmsg->rm_reply.rp_stat), 2477c478bd9Sstevel@tonic-gate (caddr_t)&(rmsg->rm_reply.ru), reply_dscrm, 2487c478bd9Sstevel@tonic-gate NULL_xdrproc_t)); 2497c478bd9Sstevel@tonic-gate return (FALSE); 2507c478bd9Sstevel@tonic-gate } 2517c478bd9Sstevel@tonic-gate 2527c478bd9Sstevel@tonic-gate /* 2537c478bd9Sstevel@tonic-gate * XDR a reply message header (encode only) 2547c478bd9Sstevel@tonic-gate */ 2557c478bd9Sstevel@tonic-gate bool_t 2567c478bd9Sstevel@tonic-gate xdr_replymsg_hdr(XDR *xdrs, struct rpc_msg *rmsg) 2577c478bd9Sstevel@tonic-gate { 2587c478bd9Sstevel@tonic-gate int32_t *buf; 2597c478bd9Sstevel@tonic-gate struct accepted_reply *ar; 2607c478bd9Sstevel@tonic-gate struct opaque_auth *oa; 2617c478bd9Sstevel@tonic-gate uint_t rndup; 2627c478bd9Sstevel@tonic-gate 2637c478bd9Sstevel@tonic-gate if (xdrs->x_op != XDR_ENCODE || 2647c478bd9Sstevel@tonic-gate rmsg->rm_reply.rp_stat != MSG_ACCEPTED || 2657c478bd9Sstevel@tonic-gate rmsg->rm_direction != REPLY) 2667c478bd9Sstevel@tonic-gate return (FALSE); 2677c478bd9Sstevel@tonic-gate 2687c478bd9Sstevel@tonic-gate if ((buf = XDR_INLINE(xdrs, 6 * BYTES_PER_XDR_UNIT + (rndup = 2697c478bd9Sstevel@tonic-gate RNDUP(rmsg->rm_reply.rp_acpt.ar_verf.oa_length)))) != NULL) { 2707c478bd9Sstevel@tonic-gate IXDR_PUT_INT32(buf, rmsg->rm_xid); 2717c478bd9Sstevel@tonic-gate IXDR_PUT_ENUM(buf, rmsg->rm_direction); 2727c478bd9Sstevel@tonic-gate IXDR_PUT_ENUM(buf, rmsg->rm_reply.rp_stat); 2737c478bd9Sstevel@tonic-gate ar = &rmsg->rm_reply.rp_acpt; 2747c478bd9Sstevel@tonic-gate oa = &ar->ar_verf; 2757c478bd9Sstevel@tonic-gate IXDR_PUT_ENUM(buf, oa->oa_flavor); 2767c478bd9Sstevel@tonic-gate IXDR_PUT_INT32(buf, oa->oa_length); 2777c478bd9Sstevel@tonic-gate if (oa->oa_length) { 2787c478bd9Sstevel@tonic-gate bcopy(oa->oa_base, buf, oa->oa_length); 2797c478bd9Sstevel@tonic-gate buf = (int32_t *)(((caddr_t)buf) + oa->oa_length); 2807c478bd9Sstevel@tonic-gate if ((rndup = (rndup - oa->oa_length)) > 0) { 2817c478bd9Sstevel@tonic-gate bzero(buf, rndup); 2827c478bd9Sstevel@tonic-gate buf = (int32_t *)(((caddr_t)buf) + rndup); 2837c478bd9Sstevel@tonic-gate } 2847c478bd9Sstevel@tonic-gate } 2857c478bd9Sstevel@tonic-gate /* 2867c478bd9Sstevel@tonic-gate * stat and rest of reply, copied from xdr_accepted_reply 2877c478bd9Sstevel@tonic-gate */ 2887c478bd9Sstevel@tonic-gate IXDR_PUT_ENUM(buf, ar->ar_stat); 2897c478bd9Sstevel@tonic-gate return (TRUE); 2907c478bd9Sstevel@tonic-gate } 2917c478bd9Sstevel@tonic-gate 2927c478bd9Sstevel@tonic-gate if (xdr_u_int(xdrs, &(rmsg->rm_xid)) && 2937c478bd9Sstevel@tonic-gate xdr_enum(xdrs, (enum_t *)&(rmsg->rm_direction)) && 2947c478bd9Sstevel@tonic-gate xdr_enum(xdrs, (enum_t *)&(rmsg->rm_reply.rp_stat)) && 2957c478bd9Sstevel@tonic-gate xdr_opaque_auth(xdrs, &rmsg->rm_reply.rp_acpt.ar_verf) && 2967c478bd9Sstevel@tonic-gate xdr_enum(xdrs, (enum_t *)&(rmsg->rm_reply.rp_acpt.ar_stat))) 2977c478bd9Sstevel@tonic-gate return (TRUE); 2987c478bd9Sstevel@tonic-gate return (FALSE); 2997c478bd9Sstevel@tonic-gate } 3007c478bd9Sstevel@tonic-gate 3017c478bd9Sstevel@tonic-gate /* 3027c478bd9Sstevel@tonic-gate * XDR a reply message body (encode only) 3037c478bd9Sstevel@tonic-gate */ 3047c478bd9Sstevel@tonic-gate bool_t 3057c478bd9Sstevel@tonic-gate xdr_replymsg_body(XDR *xdrs, struct rpc_msg *rmsg) 3067c478bd9Sstevel@tonic-gate { 3077c478bd9Sstevel@tonic-gate struct accepted_reply *ar; 3087c478bd9Sstevel@tonic-gate 3097c478bd9Sstevel@tonic-gate if (xdrs->x_op != XDR_ENCODE) 3107c478bd9Sstevel@tonic-gate return (FALSE); 3117c478bd9Sstevel@tonic-gate 3127c478bd9Sstevel@tonic-gate ar = &rmsg->rm_reply.rp_acpt; 3137c478bd9Sstevel@tonic-gate 3147c478bd9Sstevel@tonic-gate if (ar->ar_results.proc == NULL) 3157c478bd9Sstevel@tonic-gate return (TRUE); 3167c478bd9Sstevel@tonic-gate return ((*(ar->ar_results.proc))(xdrs, ar->ar_results.where)); 3177c478bd9Sstevel@tonic-gate } 3187c478bd9Sstevel@tonic-gate 3197c478bd9Sstevel@tonic-gate /* 3207c478bd9Sstevel@tonic-gate * Serializes the "static part" of a call message header. 3217c478bd9Sstevel@tonic-gate * The fields include: rm_xid, rm_direction, rpcvers, prog, and vers. 3227c478bd9Sstevel@tonic-gate * The rm_xid is not really static, but the user can easily munge on the fly. 3237c478bd9Sstevel@tonic-gate */ 3247c478bd9Sstevel@tonic-gate bool_t 3257c478bd9Sstevel@tonic-gate xdr_callhdr(XDR *xdrs, struct rpc_msg *cmsg) 3267c478bd9Sstevel@tonic-gate { 3277c478bd9Sstevel@tonic-gate cmsg->rm_direction = CALL; 3287c478bd9Sstevel@tonic-gate cmsg->rm_call.cb_rpcvers = RPC_MSG_VERSION; 3297c478bd9Sstevel@tonic-gate if (xdrs->x_op == XDR_ENCODE && 3307c478bd9Sstevel@tonic-gate xdr_u_int(xdrs, &(cmsg->rm_xid)) && 3317c478bd9Sstevel@tonic-gate xdr_enum(xdrs, (enum_t *)&(cmsg->rm_direction)) && 3327c478bd9Sstevel@tonic-gate xdr_rpcvers(xdrs, &(cmsg->rm_call.cb_rpcvers)) && 3337c478bd9Sstevel@tonic-gate xdr_rpcprog(xdrs, &(cmsg->rm_call.cb_prog))) 3347c478bd9Sstevel@tonic-gate return (xdr_rpcvers(xdrs, &(cmsg->rm_call.cb_vers))); 3357c478bd9Sstevel@tonic-gate return (FALSE); 3367c478bd9Sstevel@tonic-gate } 3377c478bd9Sstevel@tonic-gate 3387c478bd9Sstevel@tonic-gate /* ************************** Client utility routine ************* */ 3397c478bd9Sstevel@tonic-gate 3407c478bd9Sstevel@tonic-gate static void 3417c478bd9Sstevel@tonic-gate accepted(enum accept_stat acpt_stat, struct rpc_err *error) 3427c478bd9Sstevel@tonic-gate { 3437c478bd9Sstevel@tonic-gate switch (acpt_stat) { 3447c478bd9Sstevel@tonic-gate case PROG_UNAVAIL: 3457c478bd9Sstevel@tonic-gate error->re_status = RPC_PROGUNAVAIL; 3467c478bd9Sstevel@tonic-gate return; 3477c478bd9Sstevel@tonic-gate 3487c478bd9Sstevel@tonic-gate case PROG_MISMATCH: 3497c478bd9Sstevel@tonic-gate error->re_status = RPC_PROGVERSMISMATCH; 3507c478bd9Sstevel@tonic-gate return; 3517c478bd9Sstevel@tonic-gate 3527c478bd9Sstevel@tonic-gate case PROC_UNAVAIL: 3537c478bd9Sstevel@tonic-gate error->re_status = RPC_PROCUNAVAIL; 3547c478bd9Sstevel@tonic-gate return; 3557c478bd9Sstevel@tonic-gate 3567c478bd9Sstevel@tonic-gate case GARBAGE_ARGS: 3577c478bd9Sstevel@tonic-gate error->re_status = RPC_CANTDECODEARGS; 3587c478bd9Sstevel@tonic-gate return; 3597c478bd9Sstevel@tonic-gate 3607c478bd9Sstevel@tonic-gate case SYSTEM_ERR: 3617c478bd9Sstevel@tonic-gate error->re_status = RPC_SYSTEMERROR; 3627c478bd9Sstevel@tonic-gate return; 3637c478bd9Sstevel@tonic-gate 3647c478bd9Sstevel@tonic-gate case SUCCESS: 3657c478bd9Sstevel@tonic-gate error->re_status = RPC_SUCCESS; 3667c478bd9Sstevel@tonic-gate return; 3677c478bd9Sstevel@tonic-gate } 3687c478bd9Sstevel@tonic-gate /* something's wrong, but we don't know what ... */ 3697c478bd9Sstevel@tonic-gate error->re_status = RPC_FAILED; 3707c478bd9Sstevel@tonic-gate error->re_lb.s1 = (int32_t)MSG_ACCEPTED; 3717c478bd9Sstevel@tonic-gate error->re_lb.s2 = (int32_t)acpt_stat; 3727c478bd9Sstevel@tonic-gate } 3737c478bd9Sstevel@tonic-gate 3747c478bd9Sstevel@tonic-gate static void 3757c478bd9Sstevel@tonic-gate rejected(enum reject_stat rjct_stat, struct rpc_err *error) 3767c478bd9Sstevel@tonic-gate { 3777c478bd9Sstevel@tonic-gate switch (rjct_stat) { 3787c478bd9Sstevel@tonic-gate case RPC_VERSMISMATCH: 3797c478bd9Sstevel@tonic-gate error->re_status = RPC_VERSMISMATCH; 3807c478bd9Sstevel@tonic-gate return; 3817c478bd9Sstevel@tonic-gate 3827c478bd9Sstevel@tonic-gate case AUTH_ERROR: 3837c478bd9Sstevel@tonic-gate error->re_status = RPC_AUTHERROR; 3847c478bd9Sstevel@tonic-gate return; 3857c478bd9Sstevel@tonic-gate } 3867c478bd9Sstevel@tonic-gate /* something's wrong, but we don't know what ... */ 3877c478bd9Sstevel@tonic-gate error->re_status = RPC_FAILED; 3887c478bd9Sstevel@tonic-gate error->re_lb.s1 = (int32_t)MSG_DENIED; 3897c478bd9Sstevel@tonic-gate error->re_lb.s2 = (int32_t)rjct_stat; 3907c478bd9Sstevel@tonic-gate } 3917c478bd9Sstevel@tonic-gate 3927c478bd9Sstevel@tonic-gate /* 3937c478bd9Sstevel@tonic-gate * given a reply message, fills in the error 3947c478bd9Sstevel@tonic-gate */ 3957c478bd9Sstevel@tonic-gate void 3967c478bd9Sstevel@tonic-gate _seterr_reply(struct rpc_msg *msg, struct rpc_err *error) 3977c478bd9Sstevel@tonic-gate { 3987c478bd9Sstevel@tonic-gate /* optimized for normal, SUCCESSful case */ 3997c478bd9Sstevel@tonic-gate switch (msg->rm_reply.rp_stat) { 4007c478bd9Sstevel@tonic-gate case MSG_ACCEPTED: 4017c478bd9Sstevel@tonic-gate if (msg->acpted_rply.ar_stat == SUCCESS) { 4027c478bd9Sstevel@tonic-gate error->re_status = RPC_SUCCESS; 4037c478bd9Sstevel@tonic-gate return; 4047c478bd9Sstevel@tonic-gate }; 4057c478bd9Sstevel@tonic-gate accepted(msg->acpted_rply.ar_stat, error); 4067c478bd9Sstevel@tonic-gate break; 4077c478bd9Sstevel@tonic-gate 4087c478bd9Sstevel@tonic-gate case MSG_DENIED: 4097c478bd9Sstevel@tonic-gate rejected(msg->rjcted_rply.rj_stat, error); 4107c478bd9Sstevel@tonic-gate break; 4117c478bd9Sstevel@tonic-gate 4127c478bd9Sstevel@tonic-gate default: 4137c478bd9Sstevel@tonic-gate error->re_status = RPC_FAILED; 4147c478bd9Sstevel@tonic-gate error->re_lb.s1 = (int32_t)(msg->rm_reply.rp_stat); 4157c478bd9Sstevel@tonic-gate break; 4167c478bd9Sstevel@tonic-gate } 4177c478bd9Sstevel@tonic-gate 4187c478bd9Sstevel@tonic-gate switch (error->re_status) { 4197c478bd9Sstevel@tonic-gate case RPC_VERSMISMATCH: 4207c478bd9Sstevel@tonic-gate error->re_vers.low = msg->rjcted_rply.rj_vers.low; 4217c478bd9Sstevel@tonic-gate error->re_vers.high = msg->rjcted_rply.rj_vers.high; 4227c478bd9Sstevel@tonic-gate break; 4237c478bd9Sstevel@tonic-gate 4247c478bd9Sstevel@tonic-gate case RPC_AUTHERROR: 4257c478bd9Sstevel@tonic-gate error->re_why = msg->rjcted_rply.rj_why; 4267c478bd9Sstevel@tonic-gate break; 4277c478bd9Sstevel@tonic-gate 4287c478bd9Sstevel@tonic-gate case RPC_PROGVERSMISMATCH: 4297c478bd9Sstevel@tonic-gate error->re_vers.low = msg->acpted_rply.ar_vers.low; 4307c478bd9Sstevel@tonic-gate error->re_vers.high = msg->acpted_rply.ar_vers.high; 4317c478bd9Sstevel@tonic-gate break; 4327c478bd9Sstevel@tonic-gate } 4337c478bd9Sstevel@tonic-gate } 4347c478bd9Sstevel@tonic-gate 4357c478bd9Sstevel@tonic-gate /* 4367c478bd9Sstevel@tonic-gate * given a reply message, frees the accepted verifier 4377c478bd9Sstevel@tonic-gate */ 4387c478bd9Sstevel@tonic-gate bool_t 4397c478bd9Sstevel@tonic-gate xdr_rpc_free_verifier(XDR *xdrs, struct rpc_msg *msg) 4407c478bd9Sstevel@tonic-gate { 4417c478bd9Sstevel@tonic-gate if (msg->rm_direction == REPLY && 4427c478bd9Sstevel@tonic-gate msg->rm_reply.rp_stat == MSG_ACCEPTED && 4437c478bd9Sstevel@tonic-gate msg->acpted_rply.ar_verf.oa_base != NULL) { 4447c478bd9Sstevel@tonic-gate xdrs->x_op = XDR_FREE; 4457c478bd9Sstevel@tonic-gate return (xdr_opaque_auth(xdrs, &(msg->acpted_rply.ar_verf))); 4467c478bd9Sstevel@tonic-gate } 4477c478bd9Sstevel@tonic-gate return (TRUE); 4487c478bd9Sstevel@tonic-gate } 449