xref: /onnv-gate/usr/src/cmd/fs.d/autofs/autod_xdr.c (revision 11291:80bdcd03e626)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
52170Sevanl  * Common Development and Distribution License (the "License").
62170Sevanl  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
222170Sevanl  * autod_xdr.c
230Sstevel@tonic-gate  *
24*11291SRobert.Thurlow@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
252170Sevanl  * Use is subject to license terms.
260Sstevel@tonic-gate  */
270Sstevel@tonic-gate 
280Sstevel@tonic-gate /*
290Sstevel@tonic-gate  * This file can not be automatically generated by rpcgen from
300Sstevel@tonic-gate  * autofs_prot.x because of the xdr routines that provide readdir
310Sstevel@tonic-gate  * support, and my own implementation of xdr_autofs_netbuf().
320Sstevel@tonic-gate  */
330Sstevel@tonic-gate 
340Sstevel@tonic-gate #include <sys/vfs.h>
350Sstevel@tonic-gate #include <sys/sysmacros.h>		/* includes roundup() */
360Sstevel@tonic-gate #include <string.h>
370Sstevel@tonic-gate #include <rpcsvc/autofs_prot.h>
38*11291SRobert.Thurlow@Sun.COM #include <nfs/nfs4.h>
39*11291SRobert.Thurlow@Sun.COM #include <rpcsvc/nfs4_prot.h>
400Sstevel@tonic-gate #include <rpc/xdr.h>
415047Spf199842 #include <stdlib.h>
425047Spf199842 #include <strings.h>
430Sstevel@tonic-gate 
440Sstevel@tonic-gate bool_t
xdr_autofs_stat(register XDR * xdrs,autofs_stat * objp)450Sstevel@tonic-gate xdr_autofs_stat(register XDR *xdrs, autofs_stat *objp)
460Sstevel@tonic-gate {
470Sstevel@tonic-gate 	if (!xdr_enum(xdrs, (enum_t *)objp))
480Sstevel@tonic-gate 		return (FALSE);
490Sstevel@tonic-gate 	return (TRUE);
500Sstevel@tonic-gate }
510Sstevel@tonic-gate 
520Sstevel@tonic-gate bool_t
xdr_autofs_action(register XDR * xdrs,autofs_action * objp)530Sstevel@tonic-gate xdr_autofs_action(register XDR *xdrs, autofs_action *objp)
540Sstevel@tonic-gate {
550Sstevel@tonic-gate 	if (!xdr_enum(xdrs, (enum_t *)objp))
560Sstevel@tonic-gate 		return (FALSE);
570Sstevel@tonic-gate 	return (TRUE);
580Sstevel@tonic-gate }
590Sstevel@tonic-gate 
600Sstevel@tonic-gate bool_t
xdr_linka(register XDR * xdrs,linka * objp)610Sstevel@tonic-gate xdr_linka(register XDR *xdrs, linka *objp)
620Sstevel@tonic-gate {
630Sstevel@tonic-gate 	if (!xdr_string(xdrs, &objp->dir, AUTOFS_MAXPATHLEN))
640Sstevel@tonic-gate 		return (FALSE);
650Sstevel@tonic-gate 	if (!xdr_string(xdrs, &objp->link, AUTOFS_MAXPATHLEN))
660Sstevel@tonic-gate 		return (FALSE);
670Sstevel@tonic-gate 	return (TRUE);
680Sstevel@tonic-gate }
690Sstevel@tonic-gate 
700Sstevel@tonic-gate bool_t
xdr_autofs_netbuf(xdrs,objp)710Sstevel@tonic-gate xdr_autofs_netbuf(xdrs, objp)
720Sstevel@tonic-gate 	XDR *xdrs;
730Sstevel@tonic-gate 	struct netbuf *objp;
740Sstevel@tonic-gate {
750Sstevel@tonic-gate 	bool_t dummy;
760Sstevel@tonic-gate 
770Sstevel@tonic-gate 	if (!xdr_u_int(xdrs, &objp->maxlen)) {
780Sstevel@tonic-gate 		return (FALSE);
790Sstevel@tonic-gate 	}
800Sstevel@tonic-gate 	dummy = xdr_bytes(xdrs, (char **)&(objp->buf),
812170Sevanl 			(uint_t *)&(objp->len), objp->maxlen);
820Sstevel@tonic-gate 	return (dummy);
830Sstevel@tonic-gate }
840Sstevel@tonic-gate 
850Sstevel@tonic-gate bool_t
xdr_autofs_args(register XDR * xdrs,autofs_args * objp)860Sstevel@tonic-gate xdr_autofs_args(register XDR *xdrs, autofs_args *objp)
870Sstevel@tonic-gate {
880Sstevel@tonic-gate 	if (!xdr_autofs_netbuf(xdrs, &objp->addr))
890Sstevel@tonic-gate 		return (FALSE);
900Sstevel@tonic-gate 	if (!xdr_string(xdrs, &objp->path, AUTOFS_MAXPATHLEN))
910Sstevel@tonic-gate 		return (FALSE);
920Sstevel@tonic-gate 	if (!xdr_string(xdrs, &objp->opts, AUTOFS_MAXOPTSLEN))
930Sstevel@tonic-gate 		return (FALSE);
940Sstevel@tonic-gate 	if (!xdr_string(xdrs, &objp->map, AUTOFS_MAXPATHLEN))
950Sstevel@tonic-gate 		return (FALSE);
960Sstevel@tonic-gate 	if (!xdr_string(xdrs, &objp->subdir, AUTOFS_MAXPATHLEN))
970Sstevel@tonic-gate 		return (FALSE);
980Sstevel@tonic-gate 	if (!xdr_string(xdrs, &objp->key, AUTOFS_MAXCOMPONENTLEN))
990Sstevel@tonic-gate 		return (FALSE);
1000Sstevel@tonic-gate 	if (!xdr_int(xdrs, &objp->mount_to))
1010Sstevel@tonic-gate 		return (FALSE);
1020Sstevel@tonic-gate 	if (!xdr_int(xdrs, &objp->rpc_to))
1030Sstevel@tonic-gate 		return (FALSE);
1040Sstevel@tonic-gate 	if (!xdr_int(xdrs, &objp->direct))
1050Sstevel@tonic-gate 		return (FALSE);
1060Sstevel@tonic-gate 	return (TRUE);
1070Sstevel@tonic-gate }
1080Sstevel@tonic-gate 
1090Sstevel@tonic-gate bool_t
xdr_mounta(register XDR * xdrs,struct mounta * objp)1100Sstevel@tonic-gate xdr_mounta(register XDR *xdrs, struct mounta *objp)
1110Sstevel@tonic-gate {
1120Sstevel@tonic-gate 	if (!xdr_string(xdrs, &objp->spec, AUTOFS_MAXPATHLEN))
1130Sstevel@tonic-gate 		return (FALSE);
1140Sstevel@tonic-gate 	if (!xdr_string(xdrs, &objp->dir, AUTOFS_MAXPATHLEN))
1150Sstevel@tonic-gate 		return (FALSE);
1160Sstevel@tonic-gate 	if (!xdr_int(xdrs, &objp->flags))
1170Sstevel@tonic-gate 		return (FALSE);
1180Sstevel@tonic-gate 	if (!xdr_string(xdrs, &objp->fstype, AUTOFS_MAXCOMPONENTLEN))
1190Sstevel@tonic-gate 		return (FALSE);
1204068Sdm120769 	if (!xdr_pointer(xdrs, (char **)&objp->dataptr, sizeof (autofs_args),
1214068Sdm120769 	    (xdrproc_t)xdr_autofs_args))
1224068Sdm120769 		return (FALSE);
1230Sstevel@tonic-gate 	if (!xdr_int(xdrs, &objp->datalen))
1240Sstevel@tonic-gate 		return (FALSE);
1250Sstevel@tonic-gate 	if (!xdr_string(xdrs, &objp->optptr, AUTOFS_MAXOPTSLEN))
1260Sstevel@tonic-gate 		return (FALSE);
1270Sstevel@tonic-gate 	if (!xdr_int(xdrs, &objp->optlen))
1280Sstevel@tonic-gate 		return (FALSE);
1290Sstevel@tonic-gate 	return (TRUE);
1300Sstevel@tonic-gate }
1310Sstevel@tonic-gate 
1320Sstevel@tonic-gate bool_t
xdr_action_list_entry(register XDR * xdrs,action_list_entry * objp)1330Sstevel@tonic-gate xdr_action_list_entry(register XDR *xdrs, action_list_entry *objp)
1340Sstevel@tonic-gate {
1350Sstevel@tonic-gate 	if (!xdr_autofs_action(xdrs, &objp->action))
1360Sstevel@tonic-gate 		return (FALSE);
1370Sstevel@tonic-gate 	switch (objp->action) {
1380Sstevel@tonic-gate 	case AUTOFS_MOUNT_RQ:
1390Sstevel@tonic-gate 		if (!xdr_mounta(xdrs, &objp->action_list_entry_u.mounta))
1400Sstevel@tonic-gate 			return (FALSE);
1410Sstevel@tonic-gate 		break;
1420Sstevel@tonic-gate 	case AUTOFS_LINK_RQ:
1430Sstevel@tonic-gate 		if (!xdr_linka(xdrs, &objp->action_list_entry_u.linka))
1440Sstevel@tonic-gate 			return (FALSE);
1450Sstevel@tonic-gate 		break;
1460Sstevel@tonic-gate 	}
1470Sstevel@tonic-gate 	return (TRUE);
1480Sstevel@tonic-gate }
1490Sstevel@tonic-gate 
1500Sstevel@tonic-gate bool_t
xdr_action_list(XDR * xdrs,action_list * objp)1515047Spf199842 xdr_action_list(XDR *xdrs, action_list *objp)
1520Sstevel@tonic-gate {
1535047Spf199842 	action_list *tmp_action_list;
1545047Spf199842 	bool_t more_data = TRUE;
1555047Spf199842 	bool_t first_objp = TRUE;
1565047Spf199842 
1575047Spf199842 	if (xdrs->x_op == XDR_DECODE) {
1585047Spf199842 		while (more_data) {
1595047Spf199842 			if (!xdr_action_list_entry(xdrs, &objp->action))
1605047Spf199842 				return (FALSE);
1615047Spf199842 			if (!xdr_bool(xdrs, &more_data))
1625047Spf199842 				return (FALSE);
1635047Spf199842 			if (!more_data) {
1645047Spf199842 				objp->next = NULL;
1655047Spf199842 				break;
1665047Spf199842 			}
1675047Spf199842 			if (objp->next == NULL) {
1685047Spf199842 				objp->next = (action_list *)
1695047Spf199842 				    mem_alloc(sizeof (action_list));
1705047Spf199842 				if (objp->next == NULL)
1715047Spf199842 					return (FALSE);
1725047Spf199842 				bzero(objp->next, sizeof (action_list));
1735047Spf199842 			}
1745047Spf199842 			objp = objp->next;
1755047Spf199842 		}
1765047Spf199842 	} else if (xdrs->x_op == XDR_ENCODE) {
1775047Spf199842 		while (more_data) {
1785047Spf199842 			if (!xdr_action_list_entry(xdrs, &objp->action))
1795047Spf199842 				return (FALSE);
1805047Spf199842 			objp = objp->next;
1815047Spf199842 			if (objp == NULL)
1825047Spf199842 				more_data = FALSE;
1835047Spf199842 			if (!xdr_bool(xdrs, &more_data))
1845047Spf199842 				return (FALSE);
1855047Spf199842 		}
1865047Spf199842 	} else {
1875047Spf199842 		while (more_data) {
1885047Spf199842 			if (!xdr_action_list_entry(xdrs, &objp->action))
1895047Spf199842 				return (FALSE);
1905047Spf199842 			tmp_action_list = objp;
1915047Spf199842 			objp = objp->next;
1925047Spf199842 			if (objp == NULL)
1935047Spf199842 				more_data = FALSE;
1945047Spf199842 			if (!first_objp)
1955047Spf199842 				mem_free(tmp_action_list, sizeof (action_list));
1965047Spf199842 			else
1975047Spf199842 				first_objp = FALSE;
1985047Spf199842 		}
1995047Spf199842 	}
2000Sstevel@tonic-gate 	return (TRUE);
2010Sstevel@tonic-gate }
2020Sstevel@tonic-gate 
2030Sstevel@tonic-gate bool_t
xdr_umntrequest(register XDR * xdrs,umntrequest * objp)2040Sstevel@tonic-gate xdr_umntrequest(register XDR *xdrs, umntrequest *objp)
2050Sstevel@tonic-gate {
2060Sstevel@tonic-gate 	if (!xdr_bool_t(xdrs, &objp->isdirect))
2070Sstevel@tonic-gate 		return (FALSE);
2080Sstevel@tonic-gate 	if (!xdr_string(xdrs, &objp->mntresource, AUTOFS_MAXPATHLEN))
2090Sstevel@tonic-gate 		return (FALSE);
2100Sstevel@tonic-gate 	if (!xdr_string(xdrs, &objp->mntpnt, AUTOFS_MAXPATHLEN))
2110Sstevel@tonic-gate 		return (FALSE);
2120Sstevel@tonic-gate 	if (!xdr_string(xdrs, &objp->fstype, AUTOFS_MAXCOMPONENTLEN))
2130Sstevel@tonic-gate 		return (FALSE);
2140Sstevel@tonic-gate 	if (!xdr_string(xdrs, &objp->mntopts, AUTOFS_MAXOPTSLEN))
2150Sstevel@tonic-gate 		return (FALSE);
2160Sstevel@tonic-gate 	if (!xdr_pointer(xdrs, (char **)&objp->next, sizeof (umntrequest),
2175047Spf199842 	    (xdrproc_t)xdr_umntrequest))
2180Sstevel@tonic-gate 		return (FALSE);
2190Sstevel@tonic-gate 	return (TRUE);
2200Sstevel@tonic-gate }
2210Sstevel@tonic-gate 
2220Sstevel@tonic-gate bool_t
xdr_umntres(register XDR * xdrs,umntres * objp)2230Sstevel@tonic-gate xdr_umntres(register XDR *xdrs, umntres *objp)
2240Sstevel@tonic-gate {
2250Sstevel@tonic-gate 	if (!xdr_int(xdrs, &objp->status))
2260Sstevel@tonic-gate 		return (FALSE);
2270Sstevel@tonic-gate 	return (TRUE);
2280Sstevel@tonic-gate }
2290Sstevel@tonic-gate 
2300Sstevel@tonic-gate bool_t
xdr_autofs_res(xdrs,objp)2310Sstevel@tonic-gate xdr_autofs_res(xdrs, objp)
2320Sstevel@tonic-gate 	register XDR *xdrs;
2330Sstevel@tonic-gate 	autofs_res *objp;
2340Sstevel@tonic-gate {
2350Sstevel@tonic-gate 	if (!xdr_enum(xdrs, (enum_t *)objp))
2360Sstevel@tonic-gate 		return (FALSE);
2370Sstevel@tonic-gate 	return (TRUE);
2380Sstevel@tonic-gate }
2390Sstevel@tonic-gate 
2400Sstevel@tonic-gate bool_t
xdr_autofs_lookupargs(xdrs,objp)2410Sstevel@tonic-gate xdr_autofs_lookupargs(xdrs, objp)
2420Sstevel@tonic-gate 	register XDR *xdrs;
2430Sstevel@tonic-gate 	autofs_lookupargs *objp;
2440Sstevel@tonic-gate {
2450Sstevel@tonic-gate 	if (!xdr_string(xdrs, &objp->map, AUTOFS_MAXPATHLEN))
2460Sstevel@tonic-gate 		return (FALSE);
2470Sstevel@tonic-gate 	if (!xdr_string(xdrs, &objp->path, AUTOFS_MAXPATHLEN))
2480Sstevel@tonic-gate 		return (FALSE);
2490Sstevel@tonic-gate 	if (!xdr_string(xdrs, &objp->name, AUTOFS_MAXCOMPONENTLEN))
2500Sstevel@tonic-gate 		return (FALSE);
2510Sstevel@tonic-gate 	if (!xdr_string(xdrs, &objp->subdir, AUTOFS_MAXPATHLEN))
2520Sstevel@tonic-gate 		return (FALSE);
2530Sstevel@tonic-gate 	if (!xdr_string(xdrs, &objp->opts, AUTOFS_MAXOPTSLEN))
2540Sstevel@tonic-gate 		return (FALSE);
2550Sstevel@tonic-gate 	if (!xdr_bool_t(xdrs, &objp->isdirect))
2560Sstevel@tonic-gate 		return (FALSE);
2573391Ssemery 	if (!xdr_u_int(xdrs, (uint_t *)&objp->uid))
2583391Ssemery 		return (FALSE);
2590Sstevel@tonic-gate 	return (TRUE);
2600Sstevel@tonic-gate }
2610Sstevel@tonic-gate 
2620Sstevel@tonic-gate bool_t
xdr_mount_result_type(xdrs,objp)2630Sstevel@tonic-gate xdr_mount_result_type(xdrs, objp)
2640Sstevel@tonic-gate 	register XDR *xdrs;
2650Sstevel@tonic-gate 	mount_result_type *objp;
2660Sstevel@tonic-gate {
2670Sstevel@tonic-gate 	if (!xdr_autofs_stat(xdrs, &objp->status))
2680Sstevel@tonic-gate 		return (FALSE);
2690Sstevel@tonic-gate 	switch (objp->status) {
2700Sstevel@tonic-gate 	case AUTOFS_ACTION:
2710Sstevel@tonic-gate 		if (!xdr_pointer(xdrs,
2720Sstevel@tonic-gate 		    (char **)&objp->mount_result_type_u.list,
2732170Sevanl 		    sizeof (action_list), (xdrproc_t)xdr_action_list))
2740Sstevel@tonic-gate 			return (FALSE);
2750Sstevel@tonic-gate 		break;
2760Sstevel@tonic-gate 	case AUTOFS_DONE:
2770Sstevel@tonic-gate 		if (!xdr_int(xdrs, &objp->mount_result_type_u.error))
2780Sstevel@tonic-gate 			return (FALSE);
2790Sstevel@tonic-gate 		break;
2800Sstevel@tonic-gate 	}
2810Sstevel@tonic-gate 	return (TRUE);
2820Sstevel@tonic-gate }
2830Sstevel@tonic-gate 
2840Sstevel@tonic-gate bool_t
xdr_autofs_mountres(xdrs,objp)2850Sstevel@tonic-gate xdr_autofs_mountres(xdrs, objp)
2860Sstevel@tonic-gate 	register XDR *xdrs;
2870Sstevel@tonic-gate 	autofs_mountres *objp;
2880Sstevel@tonic-gate {
2890Sstevel@tonic-gate 	if (!xdr_mount_result_type(xdrs, &objp->mr_type))
2900Sstevel@tonic-gate 		return (FALSE);
2910Sstevel@tonic-gate 	if (!xdr_int(xdrs, &objp->mr_verbose))
2920Sstevel@tonic-gate 		return (FALSE);
2930Sstevel@tonic-gate 	return (TRUE);
2940Sstevel@tonic-gate }
2950Sstevel@tonic-gate bool_t
xdr_lookup_result_type(xdrs,objp)2960Sstevel@tonic-gate xdr_lookup_result_type(xdrs, objp)
2970Sstevel@tonic-gate 	register XDR *xdrs;
2980Sstevel@tonic-gate 	lookup_result_type *objp;
2990Sstevel@tonic-gate {
3000Sstevel@tonic-gate 	if (!xdr_autofs_action(xdrs, &objp->action))
3010Sstevel@tonic-gate 		return (FALSE);
3020Sstevel@tonic-gate 	switch (objp->action) {
3030Sstevel@tonic-gate 	case AUTOFS_LINK_RQ:
3040Sstevel@tonic-gate 		if (!xdr_linka(xdrs, &objp->lookup_result_type_u.lt_linka))
3050Sstevel@tonic-gate 			return (FALSE);
3060Sstevel@tonic-gate 		break;
3070Sstevel@tonic-gate 	}
3080Sstevel@tonic-gate 	return (TRUE);
3090Sstevel@tonic-gate }
3100Sstevel@tonic-gate 
3110Sstevel@tonic-gate bool_t
xdr_autofs_lookupres(xdrs,objp)3120Sstevel@tonic-gate xdr_autofs_lookupres(xdrs, objp)
3130Sstevel@tonic-gate 	register XDR *xdrs;
3140Sstevel@tonic-gate 	autofs_lookupres *objp;
3150Sstevel@tonic-gate {
3160Sstevel@tonic-gate 	if (!xdr_autofs_res(xdrs, &objp->lu_res))
3170Sstevel@tonic-gate 		return (FALSE);
3180Sstevel@tonic-gate 	if (!xdr_lookup_result_type(xdrs, &objp->lu_type))
3190Sstevel@tonic-gate 		return (FALSE);
3200Sstevel@tonic-gate 	if (!xdr_int(xdrs, &objp->lu_verbose))
3210Sstevel@tonic-gate 		return (FALSE);
3220Sstevel@tonic-gate 	return (TRUE);
3230Sstevel@tonic-gate }
3240Sstevel@tonic-gate 
3250Sstevel@tonic-gate /*
3260Sstevel@tonic-gate  * ******************************************************
3270Sstevel@tonic-gate  * Readdir XDR support
3280Sstevel@tonic-gate  * ******************************************************
3290Sstevel@tonic-gate  */
3300Sstevel@tonic-gate 
3310Sstevel@tonic-gate bool_t
xdr_autofs_rddirargs(xdrs,objp)3320Sstevel@tonic-gate xdr_autofs_rddirargs(xdrs, objp)
3330Sstevel@tonic-gate 	register XDR *xdrs;
3340Sstevel@tonic-gate 	autofs_rddirargs *objp;
3350Sstevel@tonic-gate {
3360Sstevel@tonic-gate 	if (!xdr_string(xdrs, &objp->rda_map, AUTOFS_MAXPATHLEN))
3370Sstevel@tonic-gate 		return (FALSE);
3380Sstevel@tonic-gate 	if (!xdr_u_int(xdrs, &objp->rda_offset))
3390Sstevel@tonic-gate 		return (FALSE);
3400Sstevel@tonic-gate 	if (!xdr_u_int(xdrs, &objp->rda_count))
3410Sstevel@tonic-gate 		return (FALSE);
3423391Ssemery 	if (!xdr_u_int(xdrs, (uint_t *)&objp->uid))
3433391Ssemery 		return (FALSE);
3440Sstevel@tonic-gate 	return (TRUE);
3450Sstevel@tonic-gate }
3460Sstevel@tonic-gate 
3470Sstevel@tonic-gate /*
3480Sstevel@tonic-gate  * Directory read reply:
3490Sstevel@tonic-gate  * union (enum autofs_res) {
3500Sstevel@tonic-gate  *	AUTOFS_OK: entlist;
3510Sstevel@tonic-gate  *		 boolean eof;
3520Sstevel@tonic-gate  *	default:
3530Sstevel@tonic-gate  * }
3540Sstevel@tonic-gate  *
3550Sstevel@tonic-gate  * Directory entries
3560Sstevel@tonic-gate  *	struct  direct {
3570Sstevel@tonic-gate  *		off_t   d_off;			* offset of next entry *
3580Sstevel@tonic-gate  *		u_long  d_fileno;		* inode number of entry *
3590Sstevel@tonic-gate  *		u_short d_reclen;		* length of this record *
3600Sstevel@tonic-gate  *		u_short d_namlen;		* length of string in d_name *
3610Sstevel@tonic-gate  *		char    d_name[MAXNAMLEN + 1];	* name no longer than this *
3620Sstevel@tonic-gate  *	};
3630Sstevel@tonic-gate  * are on the wire as:
3640Sstevel@tonic-gate  * union entlist (boolean valid) {
3650Sstevel@tonic-gate  * 	TRUE:	struct otw_dirent;
3660Sstevel@tonic-gate  *		u_long nxtoffset;
3670Sstevel@tonic-gate  *		union entlist;
3680Sstevel@tonic-gate  *	FALSE:
3690Sstevel@tonic-gate  * }
3700Sstevel@tonic-gate  * where otw_dirent is:
3710Sstevel@tonic-gate  * 	struct dirent {
3720Sstevel@tonic-gate  *		u_long	de_fid;
3730Sstevel@tonic-gate  *		string	de_name<AUTOFS_MAXPATHLEN>;
3740Sstevel@tonic-gate  *	}
3750Sstevel@tonic-gate  */
3760Sstevel@tonic-gate 
3770Sstevel@tonic-gate #ifdef nextdp
3780Sstevel@tonic-gate #undef nextdp
3790Sstevel@tonic-gate #endif
3800Sstevel@tonic-gate #define	nextdp(dp)	((struct dirent64 *)((char *)(dp) + (dp)->d_reclen))
3810Sstevel@tonic-gate 
3820Sstevel@tonic-gate /*
3830Sstevel@tonic-gate  * ENCODE ONLY
3840Sstevel@tonic-gate  */
3850Sstevel@tonic-gate bool_t
xdr_autofs_putrddirres(xdrs,rddir,reqsize)3860Sstevel@tonic-gate xdr_autofs_putrddirres(xdrs, rddir, reqsize)
3870Sstevel@tonic-gate 	XDR *xdrs;
3880Sstevel@tonic-gate 	struct autofsrddir *rddir;
3890Sstevel@tonic-gate 	uint_t reqsize;			/* requested size */
3900Sstevel@tonic-gate {
3910Sstevel@tonic-gate 	struct dirent64 *dp;
3920Sstevel@tonic-gate 	char *name;
3930Sstevel@tonic-gate 	int size;
3942170Sevanl 	uint_t namlen;
3950Sstevel@tonic-gate 	bool_t true = TRUE;
3960Sstevel@tonic-gate 	bool_t false = FALSE;
3970Sstevel@tonic-gate 	int entrysz;
3980Sstevel@tonic-gate 	int tofit;
3990Sstevel@tonic-gate 	int bufsize;
4000Sstevel@tonic-gate 	uint_t ino, off;
4010Sstevel@tonic-gate 
4020Sstevel@tonic-gate 	bufsize = 1 * BYTES_PER_XDR_UNIT;
4030Sstevel@tonic-gate 	for (size = rddir->rddir_size, dp = rddir->rddir_entries;
4040Sstevel@tonic-gate 		size > 0;
4050Sstevel@tonic-gate 		/* LINTED pointer alignment */
4060Sstevel@tonic-gate 		size -= dp->d_reclen, dp = nextdp(dp)) {
4070Sstevel@tonic-gate 		if (dp->d_reclen == 0 /* || DIRSIZ(dp) > dp->d_reclen */) {
4080Sstevel@tonic-gate 			return (FALSE);
4090Sstevel@tonic-gate 		}
4100Sstevel@tonic-gate 		if (dp->d_ino == 0) {
4110Sstevel@tonic-gate 			continue;
4120Sstevel@tonic-gate 		}
4130Sstevel@tonic-gate 		name = dp->d_name;
4140Sstevel@tonic-gate 		namlen = strlen(name);
4152170Sevanl 		ino = (uint_t)dp->d_ino;
4162170Sevanl 		off = (uint_t)dp->d_off;
4170Sstevel@tonic-gate 		entrysz = (1 + 1 + 1 + 1) * BYTES_PER_XDR_UNIT +
4180Sstevel@tonic-gate 		    roundup(namlen, BYTES_PER_XDR_UNIT);
4190Sstevel@tonic-gate 		tofit = entrysz + 2 * BYTES_PER_XDR_UNIT;
4200Sstevel@tonic-gate 		if (bufsize + tofit > reqsize) {
4210Sstevel@tonic-gate 			rddir->rddir_eof = FALSE;
4220Sstevel@tonic-gate 			break;
4230Sstevel@tonic-gate 		}
4240Sstevel@tonic-gate 		if (!xdr_bool(xdrs, &true) ||
4250Sstevel@tonic-gate 		    !xdr_u_int(xdrs, &ino) ||
4260Sstevel@tonic-gate 		    !xdr_bytes(xdrs, &name, &namlen, AUTOFS_MAXPATHLEN) ||
4270Sstevel@tonic-gate 		    !xdr_u_int(xdrs, &off)) {
4280Sstevel@tonic-gate 			return (FALSE);
4290Sstevel@tonic-gate 		}
4300Sstevel@tonic-gate 		bufsize += entrysz;
4310Sstevel@tonic-gate 	}
4320Sstevel@tonic-gate 	if (!xdr_bool(xdrs, &false)) {
4330Sstevel@tonic-gate 		return (FALSE);
4340Sstevel@tonic-gate 	}
4350Sstevel@tonic-gate 	if (!xdr_bool(xdrs, &rddir->rddir_eof)) {
4360Sstevel@tonic-gate 		return (FALSE);
4370Sstevel@tonic-gate 	}
4380Sstevel@tonic-gate 	return (TRUE);
4390Sstevel@tonic-gate }
4400Sstevel@tonic-gate 
4410Sstevel@tonic-gate #define	DIRENT64_RECLEN(namelen)	\
4420Sstevel@tonic-gate 	(((int)(((dirent64_t *)0)->d_name) + 1 + (namelen) + 7) & ~ 7)
4430Sstevel@tonic-gate #define	reclen(namlen)	DIRENT64_RECLEN((namlen))
4440Sstevel@tonic-gate 
4450Sstevel@tonic-gate /*
4460Sstevel@tonic-gate  * DECODE ONLY
4470Sstevel@tonic-gate  */
4480Sstevel@tonic-gate bool_t
xdr_autofs_getrddirres(xdrs,rddir)4490Sstevel@tonic-gate xdr_autofs_getrddirres(xdrs, rddir)
4500Sstevel@tonic-gate 	XDR *xdrs;
4510Sstevel@tonic-gate 	struct autofsrddir *rddir;
4520Sstevel@tonic-gate {
4530Sstevel@tonic-gate 	struct dirent64 *dp;
4542170Sevanl 	uint_t namlen;
4550Sstevel@tonic-gate 	int size;
4560Sstevel@tonic-gate 	bool_t valid;
4570Sstevel@tonic-gate 	int offset = -1;
4580Sstevel@tonic-gate 	uint_t fileid;
4590Sstevel@tonic-gate 
4600Sstevel@tonic-gate 	size = rddir->rddir_size;
4610Sstevel@tonic-gate 	dp = rddir->rddir_entries;
4620Sstevel@tonic-gate 	for (;;) {
4630Sstevel@tonic-gate 		if (!xdr_bool(xdrs, &valid)) {
4640Sstevel@tonic-gate 			return (FALSE);
4650Sstevel@tonic-gate 		}
4660Sstevel@tonic-gate 		if (!valid) {
4670Sstevel@tonic-gate 			break;
4680Sstevel@tonic-gate 		}
4690Sstevel@tonic-gate 		if (!xdr_u_int(xdrs, &fileid) ||
4700Sstevel@tonic-gate 		    !xdr_u_int(xdrs, &namlen)) {
4710Sstevel@tonic-gate 			return (FALSE);
4720Sstevel@tonic-gate 		}
4730Sstevel@tonic-gate 		if (reclen(namlen) > size) {
4740Sstevel@tonic-gate 			rddir->rddir_eof = FALSE;
4750Sstevel@tonic-gate 			goto bufovflw;
4760Sstevel@tonic-gate 		}
4770Sstevel@tonic-gate 		if (!xdr_opaque(xdrs, dp->d_name, namlen)||
4780Sstevel@tonic-gate 		    !xdr_int(xdrs, &offset)) {
4790Sstevel@tonic-gate 			return (FALSE);
4800Sstevel@tonic-gate 		}
4810Sstevel@tonic-gate 		dp->d_ino = fileid;
4820Sstevel@tonic-gate 		dp->d_reclen = reclen(namlen);
4830Sstevel@tonic-gate 		dp->d_name[namlen] = '\0';
4840Sstevel@tonic-gate 		dp->d_off = offset;
4850Sstevel@tonic-gate 		size -= dp->d_reclen;
4860Sstevel@tonic-gate 		/* LINTED pointer alignment */
4870Sstevel@tonic-gate 		dp = nextdp(dp);
4880Sstevel@tonic-gate 	}
4890Sstevel@tonic-gate 	if (!xdr_bool(xdrs, &rddir->rddir_eof)) {
4900Sstevel@tonic-gate 		return (FALSE);
4910Sstevel@tonic-gate 	}
4920Sstevel@tonic-gate bufovflw:
4930Sstevel@tonic-gate 	rddir->rddir_size = (char *)dp - (char *)(rddir->rddir_entries);
4940Sstevel@tonic-gate 	rddir->rddir_offset = offset;
4950Sstevel@tonic-gate 	return (TRUE);
4960Sstevel@tonic-gate }
4970Sstevel@tonic-gate 
4980Sstevel@tonic-gate bool_t
xdr_autofs_rddirres(register XDR * xdrs,autofs_rddirres * objp)4990Sstevel@tonic-gate xdr_autofs_rddirres(register XDR *xdrs, autofs_rddirres *objp)
5000Sstevel@tonic-gate {
5010Sstevel@tonic-gate 	if (!xdr_enum(xdrs, (enum_t *)&objp->rd_status))
5020Sstevel@tonic-gate 		return (FALSE);
5030Sstevel@tonic-gate 	if (objp->rd_status != AUTOFS_OK)
5040Sstevel@tonic-gate 		return (TRUE);
5050Sstevel@tonic-gate 	if (xdrs->x_op == XDR_ENCODE)
5060Sstevel@tonic-gate 		return (xdr_autofs_putrddirres(
5075047Spf199842 		    xdrs, (struct autofsrddir *)&objp->rd_rddir,
5085047Spf199842 		    objp->rd_bufsize));
5090Sstevel@tonic-gate 	else if (xdrs->x_op == XDR_DECODE)
5100Sstevel@tonic-gate 		return (xdr_autofs_getrddirres(xdrs,
5115047Spf199842 		    (struct autofsrddir *)&objp->rd_rddir));
5120Sstevel@tonic-gate 	else return (FALSE);
5130Sstevel@tonic-gate }
514