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 * xdr.c, generic XDR routines implementation. 367c478bd9Sstevel@tonic-gate * These are the "generic" xdr routines used to serialize and de-serialize 377c478bd9Sstevel@tonic-gate * most common data items. See xdr.h for more info on the interface to 387c478bd9Sstevel@tonic-gate * xdr. 397c478bd9Sstevel@tonic-gate */ 407c478bd9Sstevel@tonic-gate 417c478bd9Sstevel@tonic-gate #include <sys/param.h> 427c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h> 437c478bd9Sstevel@tonic-gate #include <sys/types.h> 447c478bd9Sstevel@tonic-gate #include <sys/systm.h> 457c478bd9Sstevel@tonic-gate 467c478bd9Sstevel@tonic-gate #include <rpc/types.h> 477c478bd9Sstevel@tonic-gate #include <rpc/xdr.h> 487c478bd9Sstevel@tonic-gate #include <sys/isa_defs.h> 497c478bd9Sstevel@tonic-gate 507c478bd9Sstevel@tonic-gate #pragma weak xdr_int32_t = xdr_int 517c478bd9Sstevel@tonic-gate #pragma weak xdr_uint32_t = xdr_u_int 527c478bd9Sstevel@tonic-gate #pragma weak xdr_int64_t = xdr_longlong_t 537c478bd9Sstevel@tonic-gate #pragma weak xdr_uint64_t = xdr_u_longlong_t 547c478bd9Sstevel@tonic-gate 557c478bd9Sstevel@tonic-gate #if !defined(_BIG_ENDIAN) && !defined(_LITTLE_ENDIAN) 567c478bd9Sstevel@tonic-gate #error "Exactly one of _BIG_ENDIAN or _LITTLE_ENDIAN must be defined" 577c478bd9Sstevel@tonic-gate #elif defined(_BIG_ENDIAN) && defined(_LITTLE_ENDIAN) 587c478bd9Sstevel@tonic-gate #error "Only one of _BIG_ENDIAN or _LITTLE_ENDIAN may be defined" 597c478bd9Sstevel@tonic-gate #endif 607c478bd9Sstevel@tonic-gate 617c478bd9Sstevel@tonic-gate /* 627c478bd9Sstevel@tonic-gate * constants specific to the xdr "protocol" 637c478bd9Sstevel@tonic-gate */ 647c478bd9Sstevel@tonic-gate #define XDR_FALSE ((int32_t)0) 657c478bd9Sstevel@tonic-gate #define XDR_TRUE ((int32_t)1) 667c478bd9Sstevel@tonic-gate #define LASTUNSIGNED ((uint_t)0-1) 677c478bd9Sstevel@tonic-gate 687c478bd9Sstevel@tonic-gate /* 697c478bd9Sstevel@tonic-gate * for unit alignment 707c478bd9Sstevel@tonic-gate */ 717c478bd9Sstevel@tonic-gate static char xdr_zero[BYTES_PER_XDR_UNIT] = { 0, 0, 0, 0 }; 727c478bd9Sstevel@tonic-gate 737c478bd9Sstevel@tonic-gate /* 747c478bd9Sstevel@tonic-gate * Free a data structure using XDR 757c478bd9Sstevel@tonic-gate * Not a filter, but a convenient utility nonetheless 767c478bd9Sstevel@tonic-gate */ 777c478bd9Sstevel@tonic-gate void 787c478bd9Sstevel@tonic-gate xdr_free(xdrproc_t proc, char *objp) 797c478bd9Sstevel@tonic-gate { 807c478bd9Sstevel@tonic-gate XDR x; 817c478bd9Sstevel@tonic-gate 827c478bd9Sstevel@tonic-gate x.x_op = XDR_FREE; 837c478bd9Sstevel@tonic-gate (*proc)(&x, objp); 847c478bd9Sstevel@tonic-gate } 857c478bd9Sstevel@tonic-gate 867c478bd9Sstevel@tonic-gate /* 877c478bd9Sstevel@tonic-gate * XDR nothing 887c478bd9Sstevel@tonic-gate */ 897c478bd9Sstevel@tonic-gate bool_t 907c478bd9Sstevel@tonic-gate xdr_void(void) 917c478bd9Sstevel@tonic-gate { 927c478bd9Sstevel@tonic-gate return (TRUE); 937c478bd9Sstevel@tonic-gate } 947c478bd9Sstevel@tonic-gate 957c478bd9Sstevel@tonic-gate /* 967c478bd9Sstevel@tonic-gate * XDR integers 977c478bd9Sstevel@tonic-gate * 987c478bd9Sstevel@tonic-gate * PSARC 2003/523 Contract Private Interface 997c478bd9Sstevel@tonic-gate * xdr_int 1007c478bd9Sstevel@tonic-gate * Changes must be reviewed by Solaris File Sharing 1017c478bd9Sstevel@tonic-gate * Changes must be communicated to contract-2003-523@sun.com 1027c478bd9Sstevel@tonic-gate */ 1037c478bd9Sstevel@tonic-gate bool_t 1047c478bd9Sstevel@tonic-gate xdr_int(XDR *xdrs, int *ip) 1057c478bd9Sstevel@tonic-gate { 1067c478bd9Sstevel@tonic-gate if (xdrs->x_op == XDR_ENCODE) 1077c478bd9Sstevel@tonic-gate return (XDR_PUTINT32(xdrs, ip)); 1087c478bd9Sstevel@tonic-gate 1097c478bd9Sstevel@tonic-gate if (xdrs->x_op == XDR_DECODE) 1107c478bd9Sstevel@tonic-gate return (XDR_GETINT32(xdrs, ip)); 1117c478bd9Sstevel@tonic-gate 1127c478bd9Sstevel@tonic-gate if (xdrs->x_op == XDR_FREE) 1137c478bd9Sstevel@tonic-gate return (TRUE); 1147c478bd9Sstevel@tonic-gate 1157c478bd9Sstevel@tonic-gate return (FALSE); 1167c478bd9Sstevel@tonic-gate } 1177c478bd9Sstevel@tonic-gate 1187c478bd9Sstevel@tonic-gate /* 1197c478bd9Sstevel@tonic-gate * XDR unsigned integers 1207c478bd9Sstevel@tonic-gate * 1217c478bd9Sstevel@tonic-gate * PSARC 2003/523 Contract Private Interface 1227c478bd9Sstevel@tonic-gate * xdr_u_int 1237c478bd9Sstevel@tonic-gate * Changes must be reviewed by Solaris File Sharing 1247c478bd9Sstevel@tonic-gate * Changes must be communicated to contract-2003-523@sun.com 1257c478bd9Sstevel@tonic-gate */ 1267c478bd9Sstevel@tonic-gate bool_t 1277c478bd9Sstevel@tonic-gate xdr_u_int(XDR *xdrs, uint_t *up) 1287c478bd9Sstevel@tonic-gate { 1297c478bd9Sstevel@tonic-gate if (xdrs->x_op == XDR_ENCODE) 1307c478bd9Sstevel@tonic-gate return (XDR_PUTINT32(xdrs, (int32_t *)up)); 1317c478bd9Sstevel@tonic-gate 1327c478bd9Sstevel@tonic-gate if (xdrs->x_op == XDR_DECODE) 1337c478bd9Sstevel@tonic-gate return (XDR_GETINT32(xdrs, (int32_t *)up)); 1347c478bd9Sstevel@tonic-gate 1357c478bd9Sstevel@tonic-gate if (xdrs->x_op == XDR_FREE) 1367c478bd9Sstevel@tonic-gate return (TRUE); 1377c478bd9Sstevel@tonic-gate 1387c478bd9Sstevel@tonic-gate return (FALSE); 1397c478bd9Sstevel@tonic-gate } 1407c478bd9Sstevel@tonic-gate 1417c478bd9Sstevel@tonic-gate 1427c478bd9Sstevel@tonic-gate #if defined(_ILP32) 1437c478bd9Sstevel@tonic-gate /* 1447c478bd9Sstevel@tonic-gate * xdr_long and xdr_u_long for binary compatability on ILP32 kernels. 1457c478bd9Sstevel@tonic-gate * 1467c478bd9Sstevel@tonic-gate * No prototypes since new code should not be using these interfaces. 1477c478bd9Sstevel@tonic-gate */ 1487c478bd9Sstevel@tonic-gate bool_t 1497c478bd9Sstevel@tonic-gate xdr_long(XDR *xdrs, long *ip) 1507c478bd9Sstevel@tonic-gate { 1517c478bd9Sstevel@tonic-gate return (xdr_int(xdrs, (int *)ip)); 1527c478bd9Sstevel@tonic-gate } 1537c478bd9Sstevel@tonic-gate 1547c478bd9Sstevel@tonic-gate bool_t 1557c478bd9Sstevel@tonic-gate xdr_u_long(XDR *xdrs, unsigned long *up) 1567c478bd9Sstevel@tonic-gate { 1577c478bd9Sstevel@tonic-gate return (xdr_u_int(xdrs, (uint_t *)up)); 1587c478bd9Sstevel@tonic-gate } 1597c478bd9Sstevel@tonic-gate #endif /* _ILP32 */ 1607c478bd9Sstevel@tonic-gate 1617c478bd9Sstevel@tonic-gate 1627c478bd9Sstevel@tonic-gate /* 1637c478bd9Sstevel@tonic-gate * XDR long long integers 1647c478bd9Sstevel@tonic-gate */ 1657c478bd9Sstevel@tonic-gate bool_t 1667c478bd9Sstevel@tonic-gate xdr_longlong_t(XDR *xdrs, longlong_t *hp) 1677c478bd9Sstevel@tonic-gate { 1687c478bd9Sstevel@tonic-gate if (xdrs->x_op == XDR_ENCODE) { 1697c478bd9Sstevel@tonic-gate #if defined(_LITTLE_ENDIAN) 1707c478bd9Sstevel@tonic-gate if (XDR_PUTINT32(xdrs, (int32_t *)((char *)hp + 1717c478bd9Sstevel@tonic-gate BYTES_PER_XDR_UNIT)) == TRUE) { 1727c478bd9Sstevel@tonic-gate return (XDR_PUTINT32(xdrs, (int32_t *)hp)); 1737c478bd9Sstevel@tonic-gate } 1747c478bd9Sstevel@tonic-gate #elif defined(_BIG_ENDIAN) 1757c478bd9Sstevel@tonic-gate if (XDR_PUTINT32(xdrs, (int32_t *)hp) == TRUE) { 1767c478bd9Sstevel@tonic-gate return (XDR_PUTINT32(xdrs, (int32_t *)((char *)hp + 1777c478bd9Sstevel@tonic-gate BYTES_PER_XDR_UNIT))); 1787c478bd9Sstevel@tonic-gate } 1797c478bd9Sstevel@tonic-gate #endif 1807c478bd9Sstevel@tonic-gate return (FALSE); 1817c478bd9Sstevel@tonic-gate 1827c478bd9Sstevel@tonic-gate } 1837c478bd9Sstevel@tonic-gate if (xdrs->x_op == XDR_DECODE) { 1847c478bd9Sstevel@tonic-gate #if defined(_LITTLE_ENDIAN) 1857c478bd9Sstevel@tonic-gate if (XDR_GETINT32(xdrs, (int32_t *)((char *)hp + 1867c478bd9Sstevel@tonic-gate BYTES_PER_XDR_UNIT)) == TRUE) { 1877c478bd9Sstevel@tonic-gate return (XDR_GETINT32(xdrs, (int32_t *)hp)); 1887c478bd9Sstevel@tonic-gate } 1897c478bd9Sstevel@tonic-gate #elif defined(_BIG_ENDIAN) 1907c478bd9Sstevel@tonic-gate if (XDR_GETINT32(xdrs, (int32_t *)hp) == TRUE) { 1917c478bd9Sstevel@tonic-gate return (XDR_GETINT32(xdrs, (int32_t *)((char *)hp + 1927c478bd9Sstevel@tonic-gate BYTES_PER_XDR_UNIT))); 1937c478bd9Sstevel@tonic-gate } 1947c478bd9Sstevel@tonic-gate #endif 1957c478bd9Sstevel@tonic-gate return (FALSE); 1967c478bd9Sstevel@tonic-gate } 1977c478bd9Sstevel@tonic-gate return (TRUE); 1987c478bd9Sstevel@tonic-gate } 1997c478bd9Sstevel@tonic-gate 2007c478bd9Sstevel@tonic-gate /* 2017c478bd9Sstevel@tonic-gate * XDR unsigned long long integers 2027c478bd9Sstevel@tonic-gate */ 2037c478bd9Sstevel@tonic-gate bool_t 2047c478bd9Sstevel@tonic-gate xdr_u_longlong_t(XDR *xdrs, u_longlong_t *hp) 2057c478bd9Sstevel@tonic-gate { 2067c478bd9Sstevel@tonic-gate 2077c478bd9Sstevel@tonic-gate if (xdrs->x_op == XDR_ENCODE) { 2087c478bd9Sstevel@tonic-gate #if defined(_LITTLE_ENDIAN) 2097c478bd9Sstevel@tonic-gate if (XDR_PUTINT32(xdrs, (int32_t *)((char *)hp + 2107c478bd9Sstevel@tonic-gate BYTES_PER_XDR_UNIT)) == TRUE) { 2117c478bd9Sstevel@tonic-gate return (XDR_PUTINT32(xdrs, (int32_t *)hp)); 2127c478bd9Sstevel@tonic-gate } 2137c478bd9Sstevel@tonic-gate #elif defined(_BIG_ENDIAN) 2147c478bd9Sstevel@tonic-gate if (XDR_PUTINT32(xdrs, (int32_t *)hp) == TRUE) { 2157c478bd9Sstevel@tonic-gate return (XDR_PUTINT32(xdrs, (int32_t *)((char *)hp + 2167c478bd9Sstevel@tonic-gate BYTES_PER_XDR_UNIT))); 2177c478bd9Sstevel@tonic-gate } 2187c478bd9Sstevel@tonic-gate #endif 2197c478bd9Sstevel@tonic-gate return (FALSE); 2207c478bd9Sstevel@tonic-gate 2217c478bd9Sstevel@tonic-gate } 2227c478bd9Sstevel@tonic-gate if (xdrs->x_op == XDR_DECODE) { 2237c478bd9Sstevel@tonic-gate #if defined(_LITTLE_ENDIAN) 2247c478bd9Sstevel@tonic-gate if (XDR_GETINT32(xdrs, (int32_t *)((char *)hp + 2257c478bd9Sstevel@tonic-gate BYTES_PER_XDR_UNIT)) == TRUE) { 2267c478bd9Sstevel@tonic-gate return (XDR_GETINT32(xdrs, (int32_t *)hp)); 2277c478bd9Sstevel@tonic-gate } 2287c478bd9Sstevel@tonic-gate #elif defined(_BIG_ENDIAN) 2297c478bd9Sstevel@tonic-gate if (XDR_GETINT32(xdrs, (int32_t *)hp) == TRUE) { 2307c478bd9Sstevel@tonic-gate return (XDR_GETINT32(xdrs, (int32_t *)((char *)hp + 2317c478bd9Sstevel@tonic-gate BYTES_PER_XDR_UNIT))); 2327c478bd9Sstevel@tonic-gate } 2337c478bd9Sstevel@tonic-gate #endif 2347c478bd9Sstevel@tonic-gate return (FALSE); 2357c478bd9Sstevel@tonic-gate } 2367c478bd9Sstevel@tonic-gate return (TRUE); 2377c478bd9Sstevel@tonic-gate } 2387c478bd9Sstevel@tonic-gate 2397c478bd9Sstevel@tonic-gate /* 2407c478bd9Sstevel@tonic-gate * XDR short integers 2417c478bd9Sstevel@tonic-gate */ 2427c478bd9Sstevel@tonic-gate bool_t 2437c478bd9Sstevel@tonic-gate xdr_short(XDR *xdrs, short *sp) 2447c478bd9Sstevel@tonic-gate { 2457c478bd9Sstevel@tonic-gate int32_t l; 2467c478bd9Sstevel@tonic-gate 2477c478bd9Sstevel@tonic-gate switch (xdrs->x_op) { 2487c478bd9Sstevel@tonic-gate 2497c478bd9Sstevel@tonic-gate case XDR_ENCODE: 2507c478bd9Sstevel@tonic-gate l = (int32_t)*sp; 2517c478bd9Sstevel@tonic-gate return (XDR_PUTINT32(xdrs, &l)); 2527c478bd9Sstevel@tonic-gate 2537c478bd9Sstevel@tonic-gate case XDR_DECODE: 2547c478bd9Sstevel@tonic-gate if (!XDR_GETINT32(xdrs, &l)) 2557c478bd9Sstevel@tonic-gate return (FALSE); 2567c478bd9Sstevel@tonic-gate *sp = (short)l; 2577c478bd9Sstevel@tonic-gate return (TRUE); 2587c478bd9Sstevel@tonic-gate 2597c478bd9Sstevel@tonic-gate case XDR_FREE: 2607c478bd9Sstevel@tonic-gate return (TRUE); 2617c478bd9Sstevel@tonic-gate } 2627c478bd9Sstevel@tonic-gate return (FALSE); 2637c478bd9Sstevel@tonic-gate } 2647c478bd9Sstevel@tonic-gate 2657c478bd9Sstevel@tonic-gate /* 2667c478bd9Sstevel@tonic-gate * XDR unsigned short integers 2677c478bd9Sstevel@tonic-gate */ 2687c478bd9Sstevel@tonic-gate bool_t 2697c478bd9Sstevel@tonic-gate xdr_u_short(XDR *xdrs, ushort_t *usp) 2707c478bd9Sstevel@tonic-gate { 2717c478bd9Sstevel@tonic-gate uint32_t l; 2727c478bd9Sstevel@tonic-gate 2737c478bd9Sstevel@tonic-gate switch (xdrs->x_op) { 2747c478bd9Sstevel@tonic-gate 2757c478bd9Sstevel@tonic-gate case XDR_ENCODE: 2767c478bd9Sstevel@tonic-gate l = (uint32_t)*usp; 2777c478bd9Sstevel@tonic-gate return (XDR_PUTINT32(xdrs, (int32_t *)&l)); 2787c478bd9Sstevel@tonic-gate 2797c478bd9Sstevel@tonic-gate case XDR_DECODE: 2807c478bd9Sstevel@tonic-gate if (!XDR_GETINT32(xdrs, (int32_t *)&l)) { 2817c478bd9Sstevel@tonic-gate return (FALSE); 2827c478bd9Sstevel@tonic-gate } 2837c478bd9Sstevel@tonic-gate *usp = (ushort_t)l; 2847c478bd9Sstevel@tonic-gate return (TRUE); 2857c478bd9Sstevel@tonic-gate 2867c478bd9Sstevel@tonic-gate case XDR_FREE: 2877c478bd9Sstevel@tonic-gate return (TRUE); 2887c478bd9Sstevel@tonic-gate } 2897c478bd9Sstevel@tonic-gate return (FALSE); 2907c478bd9Sstevel@tonic-gate } 2917c478bd9Sstevel@tonic-gate 2927c478bd9Sstevel@tonic-gate 2937c478bd9Sstevel@tonic-gate /* 2947c478bd9Sstevel@tonic-gate * XDR a char 2957c478bd9Sstevel@tonic-gate */ 2967c478bd9Sstevel@tonic-gate bool_t 2977c478bd9Sstevel@tonic-gate xdr_char(XDR *xdrs, char *cp) 2987c478bd9Sstevel@tonic-gate { 2997c478bd9Sstevel@tonic-gate int i; 3007c478bd9Sstevel@tonic-gate 3017c478bd9Sstevel@tonic-gate i = (*cp); 3027c478bd9Sstevel@tonic-gate if (!xdr_int(xdrs, &i)) { 3037c478bd9Sstevel@tonic-gate return (FALSE); 3047c478bd9Sstevel@tonic-gate } 3057c478bd9Sstevel@tonic-gate *cp = (char)i; 3067c478bd9Sstevel@tonic-gate return (TRUE); 3077c478bd9Sstevel@tonic-gate } 3087c478bd9Sstevel@tonic-gate 3097c478bd9Sstevel@tonic-gate /* 3107c478bd9Sstevel@tonic-gate * XDR booleans 3117c478bd9Sstevel@tonic-gate * 3127c478bd9Sstevel@tonic-gate * PSARC 2003/523 Contract Private Interface 3137c478bd9Sstevel@tonic-gate * xdr_bool 3147c478bd9Sstevel@tonic-gate * Changes must be reviewed by Solaris File Sharing 3157c478bd9Sstevel@tonic-gate * Changes must be communicated to contract-2003-523@sun.com 3167c478bd9Sstevel@tonic-gate */ 3177c478bd9Sstevel@tonic-gate bool_t 3187c478bd9Sstevel@tonic-gate xdr_bool(XDR *xdrs, bool_t *bp) 3197c478bd9Sstevel@tonic-gate { 3207c478bd9Sstevel@tonic-gate int32_t i32b; 3217c478bd9Sstevel@tonic-gate 3227c478bd9Sstevel@tonic-gate switch (xdrs->x_op) { 3237c478bd9Sstevel@tonic-gate 3247c478bd9Sstevel@tonic-gate case XDR_ENCODE: 3257c478bd9Sstevel@tonic-gate i32b = *bp ? XDR_TRUE : XDR_FALSE; 3267c478bd9Sstevel@tonic-gate return (XDR_PUTINT32(xdrs, &i32b)); 3277c478bd9Sstevel@tonic-gate 3287c478bd9Sstevel@tonic-gate case XDR_DECODE: 3297c478bd9Sstevel@tonic-gate if (!XDR_GETINT32(xdrs, &i32b)) { 3307c478bd9Sstevel@tonic-gate return (FALSE); 3317c478bd9Sstevel@tonic-gate } 3327c478bd9Sstevel@tonic-gate *bp = (i32b == XDR_FALSE) ? FALSE : TRUE; 3337c478bd9Sstevel@tonic-gate return (TRUE); 3347c478bd9Sstevel@tonic-gate 3357c478bd9Sstevel@tonic-gate case XDR_FREE: 3367c478bd9Sstevel@tonic-gate return (TRUE); 3377c478bd9Sstevel@tonic-gate } 3387c478bd9Sstevel@tonic-gate return (FALSE); 3397c478bd9Sstevel@tonic-gate } 3407c478bd9Sstevel@tonic-gate 3417c478bd9Sstevel@tonic-gate /* 3427c478bd9Sstevel@tonic-gate * XDR enumerations 3437c478bd9Sstevel@tonic-gate * 3447c478bd9Sstevel@tonic-gate * PSARC 2003/523 Contract Private Interface 3457c478bd9Sstevel@tonic-gate * xdr_enum 3467c478bd9Sstevel@tonic-gate * Changes must be reviewed by Solaris File Sharing 3477c478bd9Sstevel@tonic-gate * Changes must be communicated to contract-2003-523@sun.com 3487c478bd9Sstevel@tonic-gate */ 3497c478bd9Sstevel@tonic-gate #ifndef lint 3507c478bd9Sstevel@tonic-gate enum sizecheck { SIZEVAL } sizecheckvar; /* used to find the size of */ 3517c478bd9Sstevel@tonic-gate /* an enum */ 3527c478bd9Sstevel@tonic-gate #endif 3537c478bd9Sstevel@tonic-gate bool_t 3547c478bd9Sstevel@tonic-gate xdr_enum(XDR *xdrs, enum_t *ep) 3557c478bd9Sstevel@tonic-gate { 3567c478bd9Sstevel@tonic-gate #ifndef lint 3577c478bd9Sstevel@tonic-gate /* 3587c478bd9Sstevel@tonic-gate * enums are treated as ints 3597c478bd9Sstevel@tonic-gate */ 3607c478bd9Sstevel@tonic-gate if (sizeof (sizecheckvar) == sizeof (int32_t)) { 3617c478bd9Sstevel@tonic-gate return (xdr_int(xdrs, (int32_t *)ep)); 3627c478bd9Sstevel@tonic-gate } else if (sizeof (sizecheckvar) == sizeof (short)) { 3637c478bd9Sstevel@tonic-gate return (xdr_short(xdrs, (short *)ep)); 3647c478bd9Sstevel@tonic-gate } else { 3657c478bd9Sstevel@tonic-gate return (FALSE); 3667c478bd9Sstevel@tonic-gate } 3677c478bd9Sstevel@tonic-gate #else 3687c478bd9Sstevel@tonic-gate (void) (xdr_short(xdrs, (short *)ep)); 3697c478bd9Sstevel@tonic-gate return (xdr_int(xdrs, (int32_t *)ep)); 3707c478bd9Sstevel@tonic-gate #endif 3717c478bd9Sstevel@tonic-gate } 3727c478bd9Sstevel@tonic-gate 3737c478bd9Sstevel@tonic-gate /* 3747c478bd9Sstevel@tonic-gate * XDR opaque data 3757c478bd9Sstevel@tonic-gate * Allows the specification of a fixed size sequence of opaque bytes. 3767c478bd9Sstevel@tonic-gate * cp points to the opaque object and cnt gives the byte length. 3777c478bd9Sstevel@tonic-gate * 3787c478bd9Sstevel@tonic-gate * PSARC 2003/523 Contract Private Interface 3797c478bd9Sstevel@tonic-gate * xdr_opaque 3807c478bd9Sstevel@tonic-gate * Changes must be reviewed by Solaris File Sharing 3817c478bd9Sstevel@tonic-gate * Changes must be communicated to contract-2003-523@sun.com 3827c478bd9Sstevel@tonic-gate */ 3837c478bd9Sstevel@tonic-gate bool_t 3847c478bd9Sstevel@tonic-gate xdr_opaque(XDR *xdrs, caddr_t cp, const uint_t cnt) 3857c478bd9Sstevel@tonic-gate { 3867c478bd9Sstevel@tonic-gate uint_t rndup; 3877c478bd9Sstevel@tonic-gate static char crud[BYTES_PER_XDR_UNIT]; 3887c478bd9Sstevel@tonic-gate 3897c478bd9Sstevel@tonic-gate /* 3907c478bd9Sstevel@tonic-gate * if no data we are done 3917c478bd9Sstevel@tonic-gate */ 3927c478bd9Sstevel@tonic-gate if (cnt == 0) 3937c478bd9Sstevel@tonic-gate return (TRUE); 3947c478bd9Sstevel@tonic-gate 3957c478bd9Sstevel@tonic-gate /* 3967c478bd9Sstevel@tonic-gate * round byte count to full xdr units 3977c478bd9Sstevel@tonic-gate */ 3987c478bd9Sstevel@tonic-gate rndup = cnt % BYTES_PER_XDR_UNIT; 3997c478bd9Sstevel@tonic-gate if (rndup != 0) 4007c478bd9Sstevel@tonic-gate rndup = BYTES_PER_XDR_UNIT - rndup; 4017c478bd9Sstevel@tonic-gate 4027c478bd9Sstevel@tonic-gate if (xdrs->x_op == XDR_DECODE) { 4037c478bd9Sstevel@tonic-gate if (!XDR_GETBYTES(xdrs, cp, cnt)) { 4047c478bd9Sstevel@tonic-gate return (FALSE); 4057c478bd9Sstevel@tonic-gate } 4067c478bd9Sstevel@tonic-gate if (rndup == 0) 4077c478bd9Sstevel@tonic-gate return (TRUE); 4087c478bd9Sstevel@tonic-gate return (XDR_GETBYTES(xdrs, (caddr_t)crud, rndup)); 4097c478bd9Sstevel@tonic-gate } 4107c478bd9Sstevel@tonic-gate 4117c478bd9Sstevel@tonic-gate if (xdrs->x_op == XDR_ENCODE) { 4127c478bd9Sstevel@tonic-gate if (!XDR_PUTBYTES(xdrs, cp, cnt)) { 4137c478bd9Sstevel@tonic-gate return (FALSE); 4147c478bd9Sstevel@tonic-gate } 4157c478bd9Sstevel@tonic-gate if (rndup == 0) 4167c478bd9Sstevel@tonic-gate return (TRUE); 4177c478bd9Sstevel@tonic-gate return (XDR_PUTBYTES(xdrs, xdr_zero, rndup)); 4187c478bd9Sstevel@tonic-gate } 4197c478bd9Sstevel@tonic-gate 4207c478bd9Sstevel@tonic-gate if (xdrs->x_op == XDR_FREE) 4217c478bd9Sstevel@tonic-gate return (TRUE); 4227c478bd9Sstevel@tonic-gate 4237c478bd9Sstevel@tonic-gate return (FALSE); 4247c478bd9Sstevel@tonic-gate } 4257c478bd9Sstevel@tonic-gate 4267c478bd9Sstevel@tonic-gate /* 4277c478bd9Sstevel@tonic-gate * XDR counted bytes 4287c478bd9Sstevel@tonic-gate * *cpp is a pointer to the bytes, *sizep is the count. 4297c478bd9Sstevel@tonic-gate * If *cpp is NULL maxsize bytes are allocated 4307c478bd9Sstevel@tonic-gate * 4317c478bd9Sstevel@tonic-gate * PSARC 2003/523 Contract Private Interface 4327c478bd9Sstevel@tonic-gate * xdr_bytes 4337c478bd9Sstevel@tonic-gate * Changes must be reviewed by Solaris File Sharing 4347c478bd9Sstevel@tonic-gate * Changes must be communicated to contract-2003-523@sun.com 4357c478bd9Sstevel@tonic-gate */ 4367c478bd9Sstevel@tonic-gate bool_t 4377c478bd9Sstevel@tonic-gate xdr_bytes(XDR *xdrs, char **cpp, uint_t *sizep, const uint_t maxsize) 4387c478bd9Sstevel@tonic-gate { 4397c478bd9Sstevel@tonic-gate char *sp = *cpp; /* sp is the actual string pointer */ 4407c478bd9Sstevel@tonic-gate uint_t nodesize; 4417c478bd9Sstevel@tonic-gate 4427c478bd9Sstevel@tonic-gate /* 4437c478bd9Sstevel@tonic-gate * first deal with the length since xdr bytes are counted 4447c478bd9Sstevel@tonic-gate */ 4457c478bd9Sstevel@tonic-gate if (!xdr_u_int(xdrs, sizep)) { 4467c478bd9Sstevel@tonic-gate return (FALSE); 4477c478bd9Sstevel@tonic-gate } 4487c478bd9Sstevel@tonic-gate nodesize = *sizep; 4497c478bd9Sstevel@tonic-gate if ((nodesize > maxsize) && (xdrs->x_op != XDR_FREE)) { 4507c478bd9Sstevel@tonic-gate return (FALSE); 4517c478bd9Sstevel@tonic-gate } 4527c478bd9Sstevel@tonic-gate 4537c478bd9Sstevel@tonic-gate /* 4547c478bd9Sstevel@tonic-gate * now deal with the actual bytes 4557c478bd9Sstevel@tonic-gate */ 4567c478bd9Sstevel@tonic-gate switch (xdrs->x_op) { 4577c478bd9Sstevel@tonic-gate case XDR_DECODE: 4587c478bd9Sstevel@tonic-gate if (nodesize == 0) 4597c478bd9Sstevel@tonic-gate return (TRUE); 4607c478bd9Sstevel@tonic-gate if (sp == NULL) 4617c478bd9Sstevel@tonic-gate *cpp = sp = (char *)mem_alloc(nodesize); 4627c478bd9Sstevel@tonic-gate /* FALLTHROUGH */ 4637c478bd9Sstevel@tonic-gate 4647c478bd9Sstevel@tonic-gate case XDR_ENCODE: 4657c478bd9Sstevel@tonic-gate return (xdr_opaque(xdrs, sp, nodesize)); 4667c478bd9Sstevel@tonic-gate 4677c478bd9Sstevel@tonic-gate case XDR_FREE: 4687c478bd9Sstevel@tonic-gate if (sp != NULL) { 4697c478bd9Sstevel@tonic-gate mem_free(sp, nodesize); 4707c478bd9Sstevel@tonic-gate *cpp = NULL; 4717c478bd9Sstevel@tonic-gate } 4727c478bd9Sstevel@tonic-gate return (TRUE); 4737c478bd9Sstevel@tonic-gate } 4747c478bd9Sstevel@tonic-gate return (FALSE); 4757c478bd9Sstevel@tonic-gate } 4767c478bd9Sstevel@tonic-gate 4777c478bd9Sstevel@tonic-gate /* 4787c478bd9Sstevel@tonic-gate * Implemented here due to commonality of the object. 4797c478bd9Sstevel@tonic-gate */ 4807c478bd9Sstevel@tonic-gate bool_t 4817c478bd9Sstevel@tonic-gate xdr_netobj(XDR *xdrs, struct netobj *np) 4827c478bd9Sstevel@tonic-gate { 4837c478bd9Sstevel@tonic-gate return (xdr_bytes(xdrs, &np->n_bytes, &np->n_len, MAX_NETOBJ_SZ)); 4847c478bd9Sstevel@tonic-gate } 4857c478bd9Sstevel@tonic-gate 4867c478bd9Sstevel@tonic-gate /* 4877c478bd9Sstevel@tonic-gate * XDR a descriminated union 4887c478bd9Sstevel@tonic-gate * Support routine for discriminated unions. 4897c478bd9Sstevel@tonic-gate * You create an array of xdrdiscrim structures, terminated with 4907c478bd9Sstevel@tonic-gate * an entry with a null procedure pointer. The routine gets 4917c478bd9Sstevel@tonic-gate * the discriminant value and then searches the array of xdrdiscrims 4927c478bd9Sstevel@tonic-gate * looking for that value. It calls the procedure given in the xdrdiscrim 4937c478bd9Sstevel@tonic-gate * to handle the discriminant. If there is no specific routine a default 4947c478bd9Sstevel@tonic-gate * routine may be called. 4957c478bd9Sstevel@tonic-gate * If there is no specific or default routine an error is returned. 4967c478bd9Sstevel@tonic-gate */ 4977c478bd9Sstevel@tonic-gate bool_t 4987c478bd9Sstevel@tonic-gate xdr_union(XDR *xdrs, enum_t *dscmp, char *unp, 4997c478bd9Sstevel@tonic-gate const struct xdr_discrim *choices, const xdrproc_t dfault) 5007c478bd9Sstevel@tonic-gate { 5017c478bd9Sstevel@tonic-gate enum_t dscm; 5027c478bd9Sstevel@tonic-gate 5037c478bd9Sstevel@tonic-gate /* 5047c478bd9Sstevel@tonic-gate * we deal with the discriminator; it's an enum 5057c478bd9Sstevel@tonic-gate */ 5067c478bd9Sstevel@tonic-gate if (!xdr_enum(xdrs, dscmp)) { 5077c478bd9Sstevel@tonic-gate return (FALSE); 5087c478bd9Sstevel@tonic-gate } 5097c478bd9Sstevel@tonic-gate dscm = *dscmp; 5107c478bd9Sstevel@tonic-gate 5117c478bd9Sstevel@tonic-gate /* 5127c478bd9Sstevel@tonic-gate * search choices for a value that matches the discriminator. 5137c478bd9Sstevel@tonic-gate * if we find one, execute the xdr routine for that value. 5147c478bd9Sstevel@tonic-gate */ 5157c478bd9Sstevel@tonic-gate for (; choices->proc != NULL_xdrproc_t; choices++) { 5167c478bd9Sstevel@tonic-gate if (choices->value == dscm) 5177c478bd9Sstevel@tonic-gate return ((*(choices->proc))(xdrs, unp, LASTUNSIGNED)); 5187c478bd9Sstevel@tonic-gate } 5197c478bd9Sstevel@tonic-gate 5207c478bd9Sstevel@tonic-gate /* 5217c478bd9Sstevel@tonic-gate * no match - execute the default xdr routine if there is one 5227c478bd9Sstevel@tonic-gate */ 5237c478bd9Sstevel@tonic-gate return ((dfault == NULL_xdrproc_t) ? FALSE : 5247c478bd9Sstevel@tonic-gate (*dfault)(xdrs, unp, LASTUNSIGNED)); 5257c478bd9Sstevel@tonic-gate } 5267c478bd9Sstevel@tonic-gate 5277c478bd9Sstevel@tonic-gate 5287c478bd9Sstevel@tonic-gate /* 5297c478bd9Sstevel@tonic-gate * Non-portable xdr primitives. 5307c478bd9Sstevel@tonic-gate * Care should be taken when moving these routines to new architectures. 5317c478bd9Sstevel@tonic-gate */ 5327c478bd9Sstevel@tonic-gate 5337c478bd9Sstevel@tonic-gate 5347c478bd9Sstevel@tonic-gate /* 5357c478bd9Sstevel@tonic-gate * XDR null terminated ASCII strings 5367c478bd9Sstevel@tonic-gate * xdr_string deals with "C strings" - arrays of bytes that are 5377c478bd9Sstevel@tonic-gate * terminated by a NULL character. The parameter cpp references a 5387c478bd9Sstevel@tonic-gate * pointer to storage; If the pointer is null, then the necessary 5397c478bd9Sstevel@tonic-gate * storage is allocated. The last parameter is the max allowed length 5407c478bd9Sstevel@tonic-gate * of the string as specified by a protocol. 5417c478bd9Sstevel@tonic-gate */ 5427c478bd9Sstevel@tonic-gate bool_t 5437c478bd9Sstevel@tonic-gate xdr_string(XDR *xdrs, char **cpp, const uint_t maxsize) 5447c478bd9Sstevel@tonic-gate { 5457c478bd9Sstevel@tonic-gate char *sp = *cpp; /* sp is the actual string pointer */ 5467c478bd9Sstevel@tonic-gate uint_t size; 5477c478bd9Sstevel@tonic-gate uint_t nodesize; 5487c478bd9Sstevel@tonic-gate 5497c478bd9Sstevel@tonic-gate /* 5507c478bd9Sstevel@tonic-gate * first deal with the length since xdr strings are counted-strings 5517c478bd9Sstevel@tonic-gate */ 5527c478bd9Sstevel@tonic-gate switch (xdrs->x_op) { 5537c478bd9Sstevel@tonic-gate case XDR_FREE: 5547c478bd9Sstevel@tonic-gate if (sp == NULL) 5557c478bd9Sstevel@tonic-gate return (TRUE); /* already free */ 5567c478bd9Sstevel@tonic-gate /* FALLTHROUGH */ 5577c478bd9Sstevel@tonic-gate case XDR_ENCODE: 5587c478bd9Sstevel@tonic-gate size = (sp != NULL) ? (uint_t)strlen(sp) : 0; 5597c478bd9Sstevel@tonic-gate break; 5607c478bd9Sstevel@tonic-gate case XDR_DECODE: 5617c478bd9Sstevel@tonic-gate break; 5627c478bd9Sstevel@tonic-gate } 5637c478bd9Sstevel@tonic-gate if (!xdr_u_int(xdrs, &size)) { 5647c478bd9Sstevel@tonic-gate return (FALSE); 5657c478bd9Sstevel@tonic-gate } 5667c478bd9Sstevel@tonic-gate if (size > maxsize) { 5677c478bd9Sstevel@tonic-gate return (FALSE); 5687c478bd9Sstevel@tonic-gate } 5697c478bd9Sstevel@tonic-gate nodesize = size + 1; 5707c478bd9Sstevel@tonic-gate 5717c478bd9Sstevel@tonic-gate /* 5727c478bd9Sstevel@tonic-gate * now deal with the actual bytes 5737c478bd9Sstevel@tonic-gate */ 5747c478bd9Sstevel@tonic-gate switch (xdrs->x_op) { 5757c478bd9Sstevel@tonic-gate case XDR_DECODE: 5767c478bd9Sstevel@tonic-gate if (nodesize == 0) 5777c478bd9Sstevel@tonic-gate return (TRUE); 5787c478bd9Sstevel@tonic-gate if (sp == NULL) 5797c478bd9Sstevel@tonic-gate sp = (char *)mem_alloc(nodesize); 5807c478bd9Sstevel@tonic-gate sp[size] = 0; 5817c478bd9Sstevel@tonic-gate if (!xdr_opaque(xdrs, sp, size)) { 5827c478bd9Sstevel@tonic-gate /* 5837c478bd9Sstevel@tonic-gate * free up memory if allocated here 5847c478bd9Sstevel@tonic-gate */ 5857c478bd9Sstevel@tonic-gate if (*cpp == NULL) { 5867c478bd9Sstevel@tonic-gate mem_free(sp, nodesize); 5877c478bd9Sstevel@tonic-gate } 5887c478bd9Sstevel@tonic-gate return (FALSE); 5897c478bd9Sstevel@tonic-gate } 5907c478bd9Sstevel@tonic-gate if (strlen(sp) != size) { 5917c478bd9Sstevel@tonic-gate if (*cpp == NULL) { 5927c478bd9Sstevel@tonic-gate mem_free(sp, nodesize); 5937c478bd9Sstevel@tonic-gate } 5947c478bd9Sstevel@tonic-gate return (FALSE); 5957c478bd9Sstevel@tonic-gate } 5967c478bd9Sstevel@tonic-gate *cpp = sp; 5977c478bd9Sstevel@tonic-gate return (TRUE); 5987c478bd9Sstevel@tonic-gate 5997c478bd9Sstevel@tonic-gate case XDR_ENCODE: 6007c478bd9Sstevel@tonic-gate return (xdr_opaque(xdrs, sp, size)); 6017c478bd9Sstevel@tonic-gate 6027c478bd9Sstevel@tonic-gate case XDR_FREE: 6037c478bd9Sstevel@tonic-gate mem_free(sp, nodesize); 6047c478bd9Sstevel@tonic-gate *cpp = NULL; 6057c478bd9Sstevel@tonic-gate return (TRUE); 6067c478bd9Sstevel@tonic-gate } 6077c478bd9Sstevel@tonic-gate return (FALSE); 6087c478bd9Sstevel@tonic-gate } 6097c478bd9Sstevel@tonic-gate 6107c478bd9Sstevel@tonic-gate /* 6117c478bd9Sstevel@tonic-gate * Wrapper for xdr_string that can be called directly from 6127c478bd9Sstevel@tonic-gate * routines like clnt_call 6137c478bd9Sstevel@tonic-gate */ 6147c478bd9Sstevel@tonic-gate bool_t 6157c478bd9Sstevel@tonic-gate xdr_wrapstring(XDR *xdrs, char **cpp) 6167c478bd9Sstevel@tonic-gate { 6177c478bd9Sstevel@tonic-gate if (xdr_string(xdrs, cpp, LASTUNSIGNED)) 6187c478bd9Sstevel@tonic-gate return (TRUE); 6197c478bd9Sstevel@tonic-gate return (FALSE); 6207c478bd9Sstevel@tonic-gate } 621