1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* 23*0Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 24*0Sstevel@tonic-gate * Use is subject to license terms. 25*0Sstevel@tonic-gate */ 26*0Sstevel@tonic-gate 27*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 28*0Sstevel@tonic-gate 29*0Sstevel@tonic-gate /* 30*0Sstevel@tonic-gate * This file can not be automatically generated by rpcgen from 31*0Sstevel@tonic-gate * autofs_prot.x because of the xdr routines that provide readdir 32*0Sstevel@tonic-gate * support, its own implementation of xdr_autofs_netbuf(). rpcgen will 33*0Sstevel@tonic-gate * also generate xdr routines with recursion which should not be used 34*0Sstevel@tonic-gate * in the kernel. 35*0Sstevel@tonic-gate */ 36*0Sstevel@tonic-gate 37*0Sstevel@tonic-gate #include <sys/param.h> 38*0Sstevel@tonic-gate #include <sys/kmem.h> 39*0Sstevel@tonic-gate #include <sys/errno.h> 40*0Sstevel@tonic-gate #include <sys/proc.h> 41*0Sstevel@tonic-gate #include <sys/vfs.h> 42*0Sstevel@tonic-gate #include <sys/vnode.h> 43*0Sstevel@tonic-gate #include <sys/pathname.h> 44*0Sstevel@tonic-gate #include <sys/cred.h> 45*0Sstevel@tonic-gate #include <sys/mount.h> 46*0Sstevel@tonic-gate #include <sys/cmn_err.h> 47*0Sstevel@tonic-gate #include <sys/debug.h> 48*0Sstevel@tonic-gate #include <sys/systm.h> 49*0Sstevel@tonic-gate #include <rpc/types.h> 50*0Sstevel@tonic-gate #include <rpc/xdr.h> 51*0Sstevel@tonic-gate #include <rpc/auth.h> 52*0Sstevel@tonic-gate #include <rpc/clnt.h> 53*0Sstevel@tonic-gate #include <sys/ticotsord.h> 54*0Sstevel@tonic-gate #include <sys/dirent.h> 55*0Sstevel@tonic-gate #include <sys/sysmacros.h> /* includes roundup() */ 56*0Sstevel@tonic-gate #include <fs/fs_subr.h> 57*0Sstevel@tonic-gate #include <rpcsvc/autofs_prot.h> 58*0Sstevel@tonic-gate #include <sys/fs/autofs.h> 59*0Sstevel@tonic-gate 60*0Sstevel@tonic-gate bool_t xdr_autofs_netbuf(XDR *, struct netbuf *); 61*0Sstevel@tonic-gate bool_t xdr_mounta(XDR *, struct mounta *); 62*0Sstevel@tonic-gate 63*0Sstevel@tonic-gate bool_t 64*0Sstevel@tonic-gate xdr_umntrequest(XDR *xdrs, umntrequest *objp) 65*0Sstevel@tonic-gate { 66*0Sstevel@tonic-gate bool_t more_data; 67*0Sstevel@tonic-gate 68*0Sstevel@tonic-gate ASSERT(xdrs->x_op == XDR_ENCODE); 69*0Sstevel@tonic-gate 70*0Sstevel@tonic-gate for (; objp != NULL; objp = objp->next) { 71*0Sstevel@tonic-gate if (!xdr_bool_t(xdrs, &objp->isdirect)) 72*0Sstevel@tonic-gate return (FALSE); 73*0Sstevel@tonic-gate if (!xdr_string(xdrs, &objp->mntresource, AUTOFS_MAXPATHLEN)) 74*0Sstevel@tonic-gate return (FALSE); 75*0Sstevel@tonic-gate if (!xdr_string(xdrs, &objp->mntpnt, AUTOFS_MAXPATHLEN)) 76*0Sstevel@tonic-gate return (FALSE); 77*0Sstevel@tonic-gate if (!xdr_string(xdrs, &objp->fstype, AUTOFS_MAXCOMPONENTLEN)) 78*0Sstevel@tonic-gate return (FALSE); 79*0Sstevel@tonic-gate if (!xdr_string(xdrs, &objp->mntopts, AUTOFS_MAXOPTSLEN)) 80*0Sstevel@tonic-gate return (FALSE); 81*0Sstevel@tonic-gate 82*0Sstevel@tonic-gate if (objp->next != NULL) 83*0Sstevel@tonic-gate more_data = TRUE; 84*0Sstevel@tonic-gate else 85*0Sstevel@tonic-gate more_data = FALSE; 86*0Sstevel@tonic-gate 87*0Sstevel@tonic-gate if (!xdr_bool(xdrs, &more_data)) 88*0Sstevel@tonic-gate return (FALSE); 89*0Sstevel@tonic-gate } 90*0Sstevel@tonic-gate return (TRUE); 91*0Sstevel@tonic-gate } 92*0Sstevel@tonic-gate 93*0Sstevel@tonic-gate bool_t 94*0Sstevel@tonic-gate xdr_umntres(XDR *xdrs, umntres *objp) 95*0Sstevel@tonic-gate { 96*0Sstevel@tonic-gate return (xdr_int(xdrs, &objp->status)); 97*0Sstevel@tonic-gate } 98*0Sstevel@tonic-gate 99*0Sstevel@tonic-gate bool_t 100*0Sstevel@tonic-gate xdr_autofs_stat(XDR *xdrs, autofs_stat *objp) 101*0Sstevel@tonic-gate { 102*0Sstevel@tonic-gate if (!xdr_enum(xdrs, (enum_t *)objp)) 103*0Sstevel@tonic-gate return (FALSE); 104*0Sstevel@tonic-gate return (TRUE); 105*0Sstevel@tonic-gate } 106*0Sstevel@tonic-gate 107*0Sstevel@tonic-gate bool_t 108*0Sstevel@tonic-gate xdr_autofs_action(XDR *xdrs, autofs_action *objp) 109*0Sstevel@tonic-gate { 110*0Sstevel@tonic-gate if (!xdr_enum(xdrs, (enum_t *)objp)) 111*0Sstevel@tonic-gate return (FALSE); 112*0Sstevel@tonic-gate return (TRUE); 113*0Sstevel@tonic-gate } 114*0Sstevel@tonic-gate 115*0Sstevel@tonic-gate bool_t 116*0Sstevel@tonic-gate xdr_linka(XDR *xdrs, linka *objp) 117*0Sstevel@tonic-gate { 118*0Sstevel@tonic-gate if (!xdr_string(xdrs, &objp->dir, AUTOFS_MAXPATHLEN)) 119*0Sstevel@tonic-gate return (FALSE); 120*0Sstevel@tonic-gate if (!xdr_string(xdrs, &objp->link, AUTOFS_MAXPATHLEN)) 121*0Sstevel@tonic-gate return (FALSE); 122*0Sstevel@tonic-gate return (TRUE); 123*0Sstevel@tonic-gate } 124*0Sstevel@tonic-gate 125*0Sstevel@tonic-gate bool_t 126*0Sstevel@tonic-gate xdr_autofs_args(XDR *xdrs, autofs_args *objp) 127*0Sstevel@tonic-gate { 128*0Sstevel@tonic-gate if (!xdr_autofs_netbuf(xdrs, &objp->addr)) 129*0Sstevel@tonic-gate return (FALSE); 130*0Sstevel@tonic-gate if (!xdr_string(xdrs, &objp->path, AUTOFS_MAXPATHLEN)) 131*0Sstevel@tonic-gate return (FALSE); 132*0Sstevel@tonic-gate if (!xdr_string(xdrs, &objp->opts, AUTOFS_MAXOPTSLEN)) 133*0Sstevel@tonic-gate return (FALSE); 134*0Sstevel@tonic-gate if (!xdr_string(xdrs, &objp->map, AUTOFS_MAXPATHLEN)) 135*0Sstevel@tonic-gate return (FALSE); 136*0Sstevel@tonic-gate if (!xdr_string(xdrs, &objp->subdir, AUTOFS_MAXPATHLEN)) 137*0Sstevel@tonic-gate return (FALSE); 138*0Sstevel@tonic-gate if (!xdr_string(xdrs, &objp->key, AUTOFS_MAXCOMPONENTLEN)) 139*0Sstevel@tonic-gate return (FALSE); 140*0Sstevel@tonic-gate if (!xdr_int(xdrs, &objp->mount_to)) 141*0Sstevel@tonic-gate return (FALSE); 142*0Sstevel@tonic-gate if (!xdr_int(xdrs, &objp->rpc_to)) 143*0Sstevel@tonic-gate return (FALSE); 144*0Sstevel@tonic-gate if (!xdr_int(xdrs, &objp->direct)) 145*0Sstevel@tonic-gate return (FALSE); 146*0Sstevel@tonic-gate return (TRUE); 147*0Sstevel@tonic-gate } 148*0Sstevel@tonic-gate 149*0Sstevel@tonic-gate bool_t 150*0Sstevel@tonic-gate xdr_action_list_entry(XDR *xdrs, action_list_entry *objp) 151*0Sstevel@tonic-gate { 152*0Sstevel@tonic-gate if (!xdr_autofs_action(xdrs, &objp->action)) 153*0Sstevel@tonic-gate return (FALSE); 154*0Sstevel@tonic-gate switch (objp->action) { 155*0Sstevel@tonic-gate case AUTOFS_MOUNT_RQ: 156*0Sstevel@tonic-gate if (!xdr_mounta(xdrs, &objp->action_list_entry_u.mounta)) 157*0Sstevel@tonic-gate return (FALSE); 158*0Sstevel@tonic-gate break; 159*0Sstevel@tonic-gate case AUTOFS_LINK_RQ: 160*0Sstevel@tonic-gate if (!xdr_linka(xdrs, &objp->action_list_entry_u.linka)) 161*0Sstevel@tonic-gate return (FALSE); 162*0Sstevel@tonic-gate break; 163*0Sstevel@tonic-gate default: 164*0Sstevel@tonic-gate break; 165*0Sstevel@tonic-gate } 166*0Sstevel@tonic-gate return (TRUE); 167*0Sstevel@tonic-gate } 168*0Sstevel@tonic-gate 169*0Sstevel@tonic-gate bool_t 170*0Sstevel@tonic-gate xdr_action_list(XDR *xdrs, action_list *objp) 171*0Sstevel@tonic-gate { 172*0Sstevel@tonic-gate bool_t more_data = TRUE; 173*0Sstevel@tonic-gate bool_t status = TRUE; 174*0Sstevel@tonic-gate action_list *p; 175*0Sstevel@tonic-gate 176*0Sstevel@tonic-gate ASSERT((xdrs->x_op == XDR_DECODE) || (xdrs->x_op == XDR_FREE)); 177*0Sstevel@tonic-gate 178*0Sstevel@tonic-gate more_data = (objp != NULL); 179*0Sstevel@tonic-gate p = objp; 180*0Sstevel@tonic-gate 181*0Sstevel@tonic-gate if (xdrs->x_op == XDR_FREE) 182*0Sstevel@tonic-gate goto free; 183*0Sstevel@tonic-gate 184*0Sstevel@tonic-gate while (more_data) { 185*0Sstevel@tonic-gate if (!xdr_action_list_entry(xdrs, &p->action)) 186*0Sstevel@tonic-gate goto free; 187*0Sstevel@tonic-gate 188*0Sstevel@tonic-gate if (!xdr_bool(xdrs, &more_data)) 189*0Sstevel@tonic-gate goto free; 190*0Sstevel@tonic-gate 191*0Sstevel@tonic-gate if (more_data) { 192*0Sstevel@tonic-gate p->next = kmem_zalloc(sizeof (action_list), KM_SLEEP); 193*0Sstevel@tonic-gate p = p->next; 194*0Sstevel@tonic-gate if (p == NULL) { 195*0Sstevel@tonic-gate status = FALSE; 196*0Sstevel@tonic-gate goto free; 197*0Sstevel@tonic-gate } 198*0Sstevel@tonic-gate } else 199*0Sstevel@tonic-gate p->next = NULL; 200*0Sstevel@tonic-gate } 201*0Sstevel@tonic-gate return (TRUE); 202*0Sstevel@tonic-gate 203*0Sstevel@tonic-gate free: 204*0Sstevel@tonic-gate for (p = objp; p != NULL; ) { 205*0Sstevel@tonic-gate if (!xdr_action_list_entry(xdrs, &objp->action)) 206*0Sstevel@tonic-gate cmn_err(CE_WARN, "xdr_action_list: " 207*0Sstevel@tonic-gate "action_list_entry free failed %p\n", 208*0Sstevel@tonic-gate (void *)&objp->action); 209*0Sstevel@tonic-gate p = p->next; 210*0Sstevel@tonic-gate kmem_free(objp, sizeof (*objp)); 211*0Sstevel@tonic-gate objp = p; 212*0Sstevel@tonic-gate } 213*0Sstevel@tonic-gate objp = NULL; 214*0Sstevel@tonic-gate 215*0Sstevel@tonic-gate return (status); 216*0Sstevel@tonic-gate } 217*0Sstevel@tonic-gate 218*0Sstevel@tonic-gate bool_t 219*0Sstevel@tonic-gate xdr_autofs_netbuf(XDR *xdrs, struct netbuf *objp) 220*0Sstevel@tonic-gate { 221*0Sstevel@tonic-gate bool_t dummy; 222*0Sstevel@tonic-gate 223*0Sstevel@tonic-gate if (!xdr_u_int(xdrs, (uint_t *)&objp->maxlen)) 224*0Sstevel@tonic-gate return (FALSE); 225*0Sstevel@tonic-gate dummy = xdr_bytes(xdrs, (char **)&(objp->buf), 226*0Sstevel@tonic-gate (uint_t *)&(objp->len), objp->maxlen); 227*0Sstevel@tonic-gate return (dummy); 228*0Sstevel@tonic-gate } 229*0Sstevel@tonic-gate 230*0Sstevel@tonic-gate bool_t 231*0Sstevel@tonic-gate xdr_mounta(XDR *xdrs, struct mounta *objp) 232*0Sstevel@tonic-gate { 233*0Sstevel@tonic-gate if (!xdr_string(xdrs, &objp->spec, AUTOFS_MAXPATHLEN)) 234*0Sstevel@tonic-gate return (FALSE); 235*0Sstevel@tonic-gate if (!xdr_string(xdrs, &objp->dir, AUTOFS_MAXPATHLEN)) 236*0Sstevel@tonic-gate return (FALSE); 237*0Sstevel@tonic-gate if (!xdr_int(xdrs, &objp->flags)) 238*0Sstevel@tonic-gate return (FALSE); 239*0Sstevel@tonic-gate if (!xdr_string(xdrs, &objp->fstype, AUTOFS_MAXCOMPONENTLEN)) 240*0Sstevel@tonic-gate return (FALSE); 241*0Sstevel@tonic-gate if (!xdr_pointer(xdrs, (char **)&objp->dataptr, sizeof (autofs_args), 242*0Sstevel@tonic-gate (xdrproc_t)xdr_autofs_args)) 243*0Sstevel@tonic-gate return (FALSE); 244*0Sstevel@tonic-gate /* 245*0Sstevel@tonic-gate * The length is the original user-land length, not the 246*0Sstevel@tonic-gate * length of the native kernel autofs_args structure provided 247*0Sstevel@tonic-gate * after we decode the xdr buffer. So passing the user's idea of 248*0Sstevel@tonic-gate * the length is wrong and we need to stuff the length field with 249*0Sstevel@tonic-gate * the length of the native structure. 250*0Sstevel@tonic-gate */ 251*0Sstevel@tonic-gate if (!xdr_int(xdrs, &objp->datalen)) 252*0Sstevel@tonic-gate return (FALSE); 253*0Sstevel@tonic-gate if (xdrs->x_op == XDR_DECODE) 254*0Sstevel@tonic-gate objp->datalen = sizeof (struct autofs_args); 255*0Sstevel@tonic-gate if (!xdr_string(xdrs, &objp->optptr, AUTOFS_MAXOPTSLEN)) 256*0Sstevel@tonic-gate return (FALSE); 257*0Sstevel@tonic-gate if (!xdr_int(xdrs, &objp->optlen)) 258*0Sstevel@tonic-gate return (FALSE); 259*0Sstevel@tonic-gate ASSERT((xdrs->x_op == XDR_DECODE) || (xdrs->x_op == XDR_FREE)); 260*0Sstevel@tonic-gate return (TRUE); 261*0Sstevel@tonic-gate } 262*0Sstevel@tonic-gate 263*0Sstevel@tonic-gate bool_t 264*0Sstevel@tonic-gate xdr_autofs_res(XDR *xdrs, autofs_res *objp) 265*0Sstevel@tonic-gate { 266*0Sstevel@tonic-gate if (!xdr_enum(xdrs, (enum_t *)objp)) 267*0Sstevel@tonic-gate return (FALSE); 268*0Sstevel@tonic-gate return (TRUE); 269*0Sstevel@tonic-gate } 270*0Sstevel@tonic-gate 271*0Sstevel@tonic-gate bool_t 272*0Sstevel@tonic-gate xdr_autofs_lookupargs(XDR *xdrs, autofs_lookupargs *objp) 273*0Sstevel@tonic-gate { 274*0Sstevel@tonic-gate if (!xdr_string(xdrs, &objp->map, AUTOFS_MAXPATHLEN)) 275*0Sstevel@tonic-gate return (FALSE); 276*0Sstevel@tonic-gate if (!xdr_string(xdrs, &objp->path, AUTOFS_MAXPATHLEN)) 277*0Sstevel@tonic-gate return (FALSE); 278*0Sstevel@tonic-gate if (!xdr_string(xdrs, &objp->name, AUTOFS_MAXCOMPONENTLEN)) 279*0Sstevel@tonic-gate return (FALSE); 280*0Sstevel@tonic-gate if (!xdr_string(xdrs, &objp->subdir, AUTOFS_MAXPATHLEN)) 281*0Sstevel@tonic-gate return (FALSE); 282*0Sstevel@tonic-gate if (!xdr_string(xdrs, &objp->opts, AUTOFS_MAXOPTSLEN)) 283*0Sstevel@tonic-gate return (FALSE); 284*0Sstevel@tonic-gate if (!xdr_bool_t(xdrs, &objp->isdirect)) 285*0Sstevel@tonic-gate return (FALSE); 286*0Sstevel@tonic-gate return (TRUE); 287*0Sstevel@tonic-gate } 288*0Sstevel@tonic-gate 289*0Sstevel@tonic-gate bool_t 290*0Sstevel@tonic-gate xdr_mount_result_type(XDR *xdrs, mount_result_type *objp) 291*0Sstevel@tonic-gate { 292*0Sstevel@tonic-gate if (!xdr_autofs_stat(xdrs, &objp->status)) 293*0Sstevel@tonic-gate return (FALSE); 294*0Sstevel@tonic-gate switch (objp->status) { 295*0Sstevel@tonic-gate case AUTOFS_ACTION: 296*0Sstevel@tonic-gate if (!xdr_pointer(xdrs, 297*0Sstevel@tonic-gate (char **)&objp->mount_result_type_u.list, 298*0Sstevel@tonic-gate sizeof (action_list), (xdrproc_t)xdr_action_list)) 299*0Sstevel@tonic-gate return (FALSE); 300*0Sstevel@tonic-gate break; 301*0Sstevel@tonic-gate case AUTOFS_DONE: 302*0Sstevel@tonic-gate if (!xdr_int(xdrs, &objp->mount_result_type_u.error)) 303*0Sstevel@tonic-gate return (FALSE); 304*0Sstevel@tonic-gate break; 305*0Sstevel@tonic-gate } 306*0Sstevel@tonic-gate return (TRUE); 307*0Sstevel@tonic-gate } 308*0Sstevel@tonic-gate 309*0Sstevel@tonic-gate bool_t 310*0Sstevel@tonic-gate xdr_autofs_mountres(XDR *xdrs, autofs_mountres *objp) 311*0Sstevel@tonic-gate { 312*0Sstevel@tonic-gate if (!xdr_mount_result_type(xdrs, &objp->mr_type)) 313*0Sstevel@tonic-gate return (FALSE); 314*0Sstevel@tonic-gate if (!xdr_int(xdrs, &objp->mr_verbose)) 315*0Sstevel@tonic-gate return (FALSE); 316*0Sstevel@tonic-gate return (TRUE); 317*0Sstevel@tonic-gate } 318*0Sstevel@tonic-gate 319*0Sstevel@tonic-gate bool_t 320*0Sstevel@tonic-gate xdr_lookup_result_type(XDR *xdrs, lookup_result_type *objp) 321*0Sstevel@tonic-gate { 322*0Sstevel@tonic-gate if (!xdr_autofs_action(xdrs, &objp->action)) 323*0Sstevel@tonic-gate return (FALSE); 324*0Sstevel@tonic-gate switch (objp->action) { 325*0Sstevel@tonic-gate case AUTOFS_LINK_RQ: 326*0Sstevel@tonic-gate if (!xdr_linka(xdrs, &objp->lookup_result_type_u.lt_linka)) 327*0Sstevel@tonic-gate return (FALSE); 328*0Sstevel@tonic-gate break; 329*0Sstevel@tonic-gate default: 330*0Sstevel@tonic-gate break; 331*0Sstevel@tonic-gate } 332*0Sstevel@tonic-gate return (TRUE); 333*0Sstevel@tonic-gate } 334*0Sstevel@tonic-gate 335*0Sstevel@tonic-gate bool_t 336*0Sstevel@tonic-gate xdr_autofs_lookupres(XDR *xdrs, autofs_lookupres *objp) 337*0Sstevel@tonic-gate { 338*0Sstevel@tonic-gate if (!xdr_autofs_res(xdrs, &objp->lu_res)) 339*0Sstevel@tonic-gate return (FALSE); 340*0Sstevel@tonic-gate if (!xdr_lookup_result_type(xdrs, &objp->lu_type)) 341*0Sstevel@tonic-gate return (FALSE); 342*0Sstevel@tonic-gate if (!xdr_int(xdrs, &objp->lu_verbose)) 343*0Sstevel@tonic-gate return (FALSE); 344*0Sstevel@tonic-gate return (TRUE); 345*0Sstevel@tonic-gate } 346*0Sstevel@tonic-gate 347*0Sstevel@tonic-gate bool_t 348*0Sstevel@tonic-gate xdr_autofs_rddirargs(XDR *xdrs, autofs_rddirargs *objp) 349*0Sstevel@tonic-gate { 350*0Sstevel@tonic-gate if (!xdr_string(xdrs, &objp->rda_map, AUTOFS_MAXPATHLEN)) 351*0Sstevel@tonic-gate return (FALSE); 352*0Sstevel@tonic-gate if (!xdr_u_int(xdrs, &objp->rda_offset)) 353*0Sstevel@tonic-gate return (FALSE); 354*0Sstevel@tonic-gate if (!xdr_u_int(xdrs, &objp->rda_count)) 355*0Sstevel@tonic-gate return (FALSE); 356*0Sstevel@tonic-gate return (TRUE); 357*0Sstevel@tonic-gate } 358*0Sstevel@tonic-gate 359*0Sstevel@tonic-gate /* 360*0Sstevel@tonic-gate * Directory read reply: 361*0Sstevel@tonic-gate * union (enum autofs_res) { 362*0Sstevel@tonic-gate * AUTOFS_OK: entlist; 363*0Sstevel@tonic-gate * boolean eof; 364*0Sstevel@tonic-gate * default: 365*0Sstevel@tonic-gate * } 366*0Sstevel@tonic-gate * 367*0Sstevel@tonic-gate * Directory entries 368*0Sstevel@tonic-gate * struct direct { 369*0Sstevel@tonic-gate * off_t d_off; * offset of next entry * 370*0Sstevel@tonic-gate * u_long d_fileno; * inode number of entry * 371*0Sstevel@tonic-gate * ushort_t d_reclen; * length of this record * 372*0Sstevel@tonic-gate * ushort_t d_namlen; * length of string in d_name * 373*0Sstevel@tonic-gate * char d_name[MAXNAMLEN + 1]; * name no longer than this * 374*0Sstevel@tonic-gate * }; 375*0Sstevel@tonic-gate * are on the wire as: 376*0Sstevel@tonic-gate * union entlist (boolean valid) { 377*0Sstevel@tonic-gate * TRUE: struct otw_dirent; 378*0Sstevel@tonic-gate * uint_t nxtoffset; 379*0Sstevel@tonic-gate * union entlist; 380*0Sstevel@tonic-gate * FALSE: 381*0Sstevel@tonic-gate * } 382*0Sstevel@tonic-gate * where otw_dirent is: 383*0Sstevel@tonic-gate * struct dirent { 384*0Sstevel@tonic-gate * uint_t de_fid; 385*0Sstevel@tonic-gate * string de_name<AUTOFS_MAXPATHLEN>; 386*0Sstevel@tonic-gate * } 387*0Sstevel@tonic-gate */ 388*0Sstevel@tonic-gate 389*0Sstevel@tonic-gate #ifdef nextdp 390*0Sstevel@tonic-gate #undef nextdp 391*0Sstevel@tonic-gate #endif 392*0Sstevel@tonic-gate #define nextdp(dp) ((struct dirent64 *)((char *)(dp) + (dp)->d_reclen)) 393*0Sstevel@tonic-gate 394*0Sstevel@tonic-gate /* 395*0Sstevel@tonic-gate * ENCODE ONLY 396*0Sstevel@tonic-gate */ 397*0Sstevel@tonic-gate bool_t 398*0Sstevel@tonic-gate xdr_autofs_putrddirres(XDR *xdrs, struct autofsrddir *rddir, uint_t reqsize) 399*0Sstevel@tonic-gate { 400*0Sstevel@tonic-gate struct dirent64 *dp; 401*0Sstevel@tonic-gate char *name; 402*0Sstevel@tonic-gate int size; 403*0Sstevel@tonic-gate uint_t namlen; 404*0Sstevel@tonic-gate bool_t true = TRUE; 405*0Sstevel@tonic-gate bool_t false = FALSE; 406*0Sstevel@tonic-gate int entrysz; 407*0Sstevel@tonic-gate int tofit; 408*0Sstevel@tonic-gate int bufsize; 409*0Sstevel@tonic-gate uint_t ino, off; 410*0Sstevel@tonic-gate 411*0Sstevel@tonic-gate bufsize = 1 * BYTES_PER_XDR_UNIT; 412*0Sstevel@tonic-gate for (size = rddir->rddir_size, dp = rddir->rddir_entries; 413*0Sstevel@tonic-gate size > 0; 414*0Sstevel@tonic-gate /* LINTED pointer alignment */ 415*0Sstevel@tonic-gate size -= dp->d_reclen, dp = nextdp(dp)) { 416*0Sstevel@tonic-gate if (dp->d_reclen == 0 /* || DIRSIZ(dp) > dp->d_reclen */) 417*0Sstevel@tonic-gate return (FALSE); 418*0Sstevel@tonic-gate if (dp->d_ino == 0) 419*0Sstevel@tonic-gate continue; 420*0Sstevel@tonic-gate name = dp->d_name; 421*0Sstevel@tonic-gate namlen = (uint_t)strlen(name); 422*0Sstevel@tonic-gate ino = (uint_t)dp->d_ino; 423*0Sstevel@tonic-gate off = (uint_t)dp->d_off; 424*0Sstevel@tonic-gate entrysz = (1 + 1 + 1 + 1) * BYTES_PER_XDR_UNIT + 425*0Sstevel@tonic-gate roundup(namlen, BYTES_PER_XDR_UNIT); 426*0Sstevel@tonic-gate tofit = entrysz + 2 * BYTES_PER_XDR_UNIT; 427*0Sstevel@tonic-gate if (bufsize + tofit > reqsize) { 428*0Sstevel@tonic-gate rddir->rddir_eof = FALSE; 429*0Sstevel@tonic-gate break; 430*0Sstevel@tonic-gate } 431*0Sstevel@tonic-gate if (!xdr_bool(xdrs, &true) || 432*0Sstevel@tonic-gate !xdr_u_int(xdrs, &ino) || 433*0Sstevel@tonic-gate !xdr_bytes(xdrs, &name, &namlen, AUTOFS_MAXPATHLEN) || 434*0Sstevel@tonic-gate !xdr_u_int(xdrs, &off)) { 435*0Sstevel@tonic-gate return (FALSE); 436*0Sstevel@tonic-gate } 437*0Sstevel@tonic-gate bufsize += entrysz; 438*0Sstevel@tonic-gate } 439*0Sstevel@tonic-gate if (!xdr_bool(xdrs, &false)) 440*0Sstevel@tonic-gate return (FALSE); 441*0Sstevel@tonic-gate if (!xdr_bool(xdrs, &rddir->rddir_eof)) 442*0Sstevel@tonic-gate return (FALSE); 443*0Sstevel@tonic-gate return (TRUE); 444*0Sstevel@tonic-gate } 445*0Sstevel@tonic-gate 446*0Sstevel@tonic-gate 447*0Sstevel@tonic-gate /* 448*0Sstevel@tonic-gate * DECODE ONLY 449*0Sstevel@tonic-gate */ 450*0Sstevel@tonic-gate bool_t 451*0Sstevel@tonic-gate xdr_autofs_getrddirres(XDR *xdrs, struct autofsrddir *rddir) 452*0Sstevel@tonic-gate { 453*0Sstevel@tonic-gate struct dirent64 *dp; 454*0Sstevel@tonic-gate uint_t namlen; 455*0Sstevel@tonic-gate int size; 456*0Sstevel@tonic-gate bool_t valid; 457*0Sstevel@tonic-gate uint_t offset; 458*0Sstevel@tonic-gate uint_t fileid; 459*0Sstevel@tonic-gate 460*0Sstevel@tonic-gate offset = (uint_t)-1; 461*0Sstevel@tonic-gate 462*0Sstevel@tonic-gate size = rddir->rddir_size; 463*0Sstevel@tonic-gate dp = rddir->rddir_entries; 464*0Sstevel@tonic-gate for (;;) { 465*0Sstevel@tonic-gate if (!xdr_bool(xdrs, &valid)) 466*0Sstevel@tonic-gate return (FALSE); 467*0Sstevel@tonic-gate if (!valid) 468*0Sstevel@tonic-gate break; 469*0Sstevel@tonic-gate if (!xdr_u_int(xdrs, &fileid) || 470*0Sstevel@tonic-gate !xdr_u_int(xdrs, &namlen)) 471*0Sstevel@tonic-gate return (FALSE); 472*0Sstevel@tonic-gate if (DIRENT64_RECLEN(namlen) > size) { 473*0Sstevel@tonic-gate rddir->rddir_eof = FALSE; 474*0Sstevel@tonic-gate goto bufovflw; 475*0Sstevel@tonic-gate } 476*0Sstevel@tonic-gate if (!xdr_opaque(xdrs, dp->d_name, namlen)|| 477*0Sstevel@tonic-gate !xdr_u_int(xdrs, &offset)) 478*0Sstevel@tonic-gate return (FALSE); 479*0Sstevel@tonic-gate dp->d_ino = fileid; 480*0Sstevel@tonic-gate dp->d_reclen = (ushort_t)DIRENT64_RECLEN(namlen); 481*0Sstevel@tonic-gate bzero(&dp->d_name[namlen], 482*0Sstevel@tonic-gate DIRENT64_NAMELEN(dp->d_reclen) - namlen); 483*0Sstevel@tonic-gate dp->d_off = offset; 484*0Sstevel@tonic-gate size -= dp->d_reclen; 485*0Sstevel@tonic-gate /* LINTED pointer alignment */ 486*0Sstevel@tonic-gate dp = nextdp(dp); 487*0Sstevel@tonic-gate } 488*0Sstevel@tonic-gate if (!xdr_bool(xdrs, &rddir->rddir_eof)) 489*0Sstevel@tonic-gate return (FALSE); 490*0Sstevel@tonic-gate bufovflw: 491*0Sstevel@tonic-gate rddir->rddir_size = (uint_t)((char *)dp - (char *)rddir->rddir_entries); 492*0Sstevel@tonic-gate rddir->rddir_offset = offset; 493*0Sstevel@tonic-gate return (TRUE); 494*0Sstevel@tonic-gate } 495*0Sstevel@tonic-gate 496*0Sstevel@tonic-gate bool_t 497*0Sstevel@tonic-gate xdr_autofs_rddirres(XDR *xdrs, autofs_rddirres *objp) 498*0Sstevel@tonic-gate { 499*0Sstevel@tonic-gate if (!xdr_enum(xdrs, (enum_t *)&objp->rd_status)) 500*0Sstevel@tonic-gate return (FALSE); 501*0Sstevel@tonic-gate if (objp->rd_status != AUTOFS_OK) 502*0Sstevel@tonic-gate return (TRUE); 503*0Sstevel@tonic-gate if (xdrs->x_op == XDR_ENCODE) 504*0Sstevel@tonic-gate return (xdr_autofs_putrddirres(xdrs, 505*0Sstevel@tonic-gate (struct autofsrddir *)&objp->rd_rddir, objp->rd_bufsize)); 506*0Sstevel@tonic-gate else if (xdrs->x_op == XDR_DECODE) 507*0Sstevel@tonic-gate return (xdr_autofs_getrddirres(xdrs, 508*0Sstevel@tonic-gate (struct autofsrddir *)&objp->rd_rddir)); 509*0Sstevel@tonic-gate return (FALSE); 510*0Sstevel@tonic-gate } 511