1df8bae1dSRodney W. Grimes /* 2df8bae1dSRodney W. Grimes * Copyright (c) 1989, 1993 3df8bae1dSRodney W. Grimes * The Regents of the University of California. All rights reserved. 4df8bae1dSRodney W. Grimes * (c) UNIX System Laboratories, Inc. 5df8bae1dSRodney W. Grimes * All or some portions of this file are derived from material licensed 6df8bae1dSRodney W. Grimes * to the University of California by American Telephone and Telegraph 7df8bae1dSRodney W. Grimes * Co. or Unix System Laboratories, Inc. and are reproduced herein with 8df8bae1dSRodney W. Grimes * the permission of UNIX System Laboratories, Inc. 9df8bae1dSRodney W. Grimes * 10df8bae1dSRodney W. Grimes * Redistribution and use in source and binary forms, with or without 11df8bae1dSRodney W. Grimes * modification, are permitted provided that the following conditions 12df8bae1dSRodney W. Grimes * are met: 13df8bae1dSRodney W. Grimes * 1. Redistributions of source code must retain the above copyright 14df8bae1dSRodney W. Grimes * notice, this list of conditions and the following disclaimer. 15df8bae1dSRodney W. Grimes * 2. Redistributions in binary form must reproduce the above copyright 16df8bae1dSRodney W. Grimes * notice, this list of conditions and the following disclaimer in the 17df8bae1dSRodney W. Grimes * documentation and/or other materials provided with the distribution. 18df8bae1dSRodney W. Grimes * 3. All advertising materials mentioning features or use of this software 19df8bae1dSRodney W. Grimes * must display the following acknowledgement: 20df8bae1dSRodney W. Grimes * This product includes software developed by the University of 21df8bae1dSRodney W. Grimes * California, Berkeley and its contributors. 22df8bae1dSRodney W. Grimes * 4. Neither the name of the University nor the names of its contributors 23df8bae1dSRodney W. Grimes * may be used to endorse or promote products derived from this software 24df8bae1dSRodney W. Grimes * without specific prior written permission. 25df8bae1dSRodney W. Grimes * 26df8bae1dSRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 27df8bae1dSRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28df8bae1dSRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29df8bae1dSRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 30df8bae1dSRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31df8bae1dSRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32df8bae1dSRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33df8bae1dSRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34df8bae1dSRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35df8bae1dSRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36df8bae1dSRodney W. Grimes * SUCH DAMAGE. 37df8bae1dSRodney W. Grimes * 38996c772fSJohn Dyson * @(#)vfs_subr.c 8.31 (Berkeley) 5/26/95 39c3aac50fSPeter Wemm * $FreeBSD$ 40df8bae1dSRodney W. Grimes */ 41df8bae1dSRodney W. Grimes 42df8bae1dSRodney W. Grimes #include <sys/param.h> 43df8bae1dSRodney W. Grimes #include <sys/systm.h> 44986f4ce7SBruce Evans #include <sys/kernel.h> 458ee8b21bSPoul-Henning Kamp #include <sys/socket.h> 46a1c995b6SPoul-Henning Kamp #include <sys/malloc.h> 47bf61e266SKris Kennaway #include <sys/mbuf.h> 48df8bae1dSRodney W. Grimes #include <sys/mount.h> 498ee8b21bSPoul-Henning Kamp #include <net/radix.h> 508ee8b21bSPoul-Henning Kamp #include <sys/domain.h> 518ee8b21bSPoul-Henning Kamp #include <sys/dirent.h> 525e950839SLuoqi Chen #include <sys/vnode.h> 53df8bae1dSRodney W. Grimes 54a1c995b6SPoul-Henning Kamp static MALLOC_DEFINE(M_NETADDR, "Export Host", "Export host address structure"); 5555166637SPoul-Henning Kamp 5698d93822SBruce Evans static void vfs_free_addrlist __P((struct netexport *nep)); 5798d93822SBruce Evans static int vfs_free_netcred __P((struct radix_node *rn, void *w)); 5898d93822SBruce Evans static int vfs_hang_addrlist __P((struct mount *mp, struct netexport *nep, 5998d93822SBruce Evans struct export_args *argp)); 6098d93822SBruce Evans 61df8bae1dSRodney W. Grimes /* 62a13234bbSPoul-Henning Kamp * Network address lookup element 63a13234bbSPoul-Henning Kamp */ 64a13234bbSPoul-Henning Kamp struct netcred { 65a13234bbSPoul-Henning Kamp struct radix_node netc_rnodes[2]; 66a13234bbSPoul-Henning Kamp int netc_exflags; 67a13234bbSPoul-Henning Kamp struct ucred netc_anon; 68a13234bbSPoul-Henning Kamp }; 69a13234bbSPoul-Henning Kamp 70a13234bbSPoul-Henning Kamp /* 71a13234bbSPoul-Henning Kamp * Network export information 72a13234bbSPoul-Henning Kamp */ 73a13234bbSPoul-Henning Kamp struct netexport { 74a13234bbSPoul-Henning Kamp struct netcred ne_defexported; /* Default export */ 75a13234bbSPoul-Henning Kamp struct radix_node_head *ne_rtable[AF_MAX+1]; /* Individual exports */ 76a13234bbSPoul-Henning Kamp }; 77a13234bbSPoul-Henning Kamp 78a13234bbSPoul-Henning Kamp /* 79df8bae1dSRodney W. Grimes * Build hash lists of net addresses and hang them off the mount point. 80df8bae1dSRodney W. Grimes * Called by ufs_mount() to set up the lists of export addresses. 81df8bae1dSRodney W. Grimes */ 82df8bae1dSRodney W. Grimes static int 83514ede09SBruce Evans vfs_hang_addrlist(mp, nep, argp) 84514ede09SBruce Evans struct mount *mp; 85514ede09SBruce Evans struct netexport *nep; 86514ede09SBruce Evans struct export_args *argp; 87df8bae1dSRodney W. Grimes { 88df8bae1dSRodney W. Grimes register struct netcred *np; 89df8bae1dSRodney W. Grimes register struct radix_node_head *rnh; 90df8bae1dSRodney W. Grimes register int i; 91df8bae1dSRodney W. Grimes struct radix_node *rn; 92df8bae1dSRodney W. Grimes struct sockaddr *saddr, *smask = 0; 93df8bae1dSRodney W. Grimes struct domain *dom; 94df8bae1dSRodney W. Grimes int error; 95df8bae1dSRodney W. Grimes 96df8bae1dSRodney W. Grimes if (argp->ex_addrlen == 0) { 97df8bae1dSRodney W. Grimes if (mp->mnt_flag & MNT_DEFEXPORTED) 98df8bae1dSRodney W. Grimes return (EPERM); 99df8bae1dSRodney W. Grimes np = &nep->ne_defexported; 100df8bae1dSRodney W. Grimes np->netc_exflags = argp->ex_flags; 101c0511d3bSBrian Feldman bzero(&np->netc_anon, sizeof(np->netc_anon)); 102c0511d3bSBrian Feldman np->netc_anon.cr_uid = argp->ex_anon.cr_uid; 103c0511d3bSBrian Feldman np->netc_anon.cr_ngroups = argp->ex_anon.cr_ngroups; 104c0511d3bSBrian Feldman bcopy(argp->ex_anon.cr_groups, np->netc_anon.cr_groups, 105c0511d3bSBrian Feldman sizeof(np->netc_anon.cr_groups)); 106df8bae1dSRodney W. Grimes np->netc_anon.cr_ref = 1; 107df8bae1dSRodney W. Grimes mp->mnt_flag |= MNT_DEFEXPORTED; 108df8bae1dSRodney W. Grimes return (0); 109df8bae1dSRodney W. Grimes } 110bf61e266SKris Kennaway 111bf61e266SKris Kennaway if (argp->ex_addrlen > MLEN) 112bf61e266SKris Kennaway return (EINVAL); 113bf61e266SKris Kennaway 114df8bae1dSRodney W. Grimes i = sizeof(struct netcred) + argp->ex_addrlen + argp->ex_masklen; 1157cc0979fSDavid Malone np = (struct netcred *) malloc(i, M_NETADDR, M_WAITOK | M_ZERO); 116df8bae1dSRodney W. Grimes saddr = (struct sockaddr *) (np + 1); 117bb56ec4aSPoul-Henning Kamp if ((error = copyin(argp->ex_addr, (caddr_t) saddr, argp->ex_addrlen))) 118df8bae1dSRodney W. Grimes goto out; 119df8bae1dSRodney W. Grimes if (saddr->sa_len > argp->ex_addrlen) 120df8bae1dSRodney W. Grimes saddr->sa_len = argp->ex_addrlen; 121df8bae1dSRodney W. Grimes if (argp->ex_masklen) { 122df8bae1dSRodney W. Grimes smask = (struct sockaddr *) ((caddr_t) saddr + argp->ex_addrlen); 1235f61c81dSPeter Wemm error = copyin(argp->ex_mask, (caddr_t) smask, argp->ex_masklen); 124df8bae1dSRodney W. Grimes if (error) 125df8bae1dSRodney W. Grimes goto out; 126df8bae1dSRodney W. Grimes if (smask->sa_len > argp->ex_masklen) 127df8bae1dSRodney W. Grimes smask->sa_len = argp->ex_masklen; 128df8bae1dSRodney W. Grimes } 129df8bae1dSRodney W. Grimes i = saddr->sa_family; 130df8bae1dSRodney W. Grimes if ((rnh = nep->ne_rtable[i]) == 0) { 131df8bae1dSRodney W. Grimes /* 1320d94caffSDavid Greenman * Seems silly to initialize every AF when most are not used, 1330d94caffSDavid Greenman * do so on demand here 134df8bae1dSRodney W. Grimes */ 135df8bae1dSRodney W. Grimes for (dom = domains; dom; dom = dom->dom_next) 136df8bae1dSRodney W. Grimes if (dom->dom_family == i && dom->dom_rtattach) { 137df8bae1dSRodney W. Grimes dom->dom_rtattach((void **) &nep->ne_rtable[i], 138df8bae1dSRodney W. Grimes dom->dom_rtoffset); 139df8bae1dSRodney W. Grimes break; 140df8bae1dSRodney W. Grimes } 141df8bae1dSRodney W. Grimes if ((rnh = nep->ne_rtable[i]) == 0) { 142df8bae1dSRodney W. Grimes error = ENOBUFS; 143df8bae1dSRodney W. Grimes goto out; 144df8bae1dSRodney W. Grimes } 145df8bae1dSRodney W. Grimes } 146df8bae1dSRodney W. Grimes rn = (*rnh->rnh_addaddr) ((caddr_t) saddr, (caddr_t) smask, rnh, 147df8bae1dSRodney W. Grimes np->netc_rnodes); 148df8bae1dSRodney W. Grimes if (rn == 0 || np != (struct netcred *) rn) { /* already exists */ 149df8bae1dSRodney W. Grimes error = EPERM; 150df8bae1dSRodney W. Grimes goto out; 151df8bae1dSRodney W. Grimes } 152df8bae1dSRodney W. Grimes np->netc_exflags = argp->ex_flags; 153c0511d3bSBrian Feldman bzero(&np->netc_anon, sizeof(np->netc_anon)); 154c0511d3bSBrian Feldman np->netc_anon.cr_uid = argp->ex_anon.cr_uid; 155c0511d3bSBrian Feldman np->netc_anon.cr_ngroups = argp->ex_anon.cr_ngroups; 156c0511d3bSBrian Feldman bcopy(argp->ex_anon.cr_groups, np->netc_anon.cr_groups, 157c0511d3bSBrian Feldman sizeof(np->netc_anon.cr_groups)); 158df8bae1dSRodney W. Grimes np->netc_anon.cr_ref = 1; 159df8bae1dSRodney W. Grimes return (0); 160df8bae1dSRodney W. Grimes out: 161df8bae1dSRodney W. Grimes free(np, M_NETADDR); 162df8bae1dSRodney W. Grimes return (error); 163df8bae1dSRodney W. Grimes } 164df8bae1dSRodney W. Grimes 165a863c0fbSEivind Eklund /* Helper for vfs_free_addrlist. */ 166df8bae1dSRodney W. Grimes /* ARGSUSED */ 167df8bae1dSRodney W. Grimes static int 168514ede09SBruce Evans vfs_free_netcred(rn, w) 169514ede09SBruce Evans struct radix_node *rn; 170514ede09SBruce Evans void *w; 171df8bae1dSRodney W. Grimes { 172df8bae1dSRodney W. Grimes register struct radix_node_head *rnh = (struct radix_node_head *) w; 173df8bae1dSRodney W. Grimes 174df8bae1dSRodney W. Grimes (*rnh->rnh_deladdr) (rn->rn_key, rn->rn_mask, rnh); 175df8bae1dSRodney W. Grimes free((caddr_t) rn, M_NETADDR); 176df8bae1dSRodney W. Grimes return (0); 177df8bae1dSRodney W. Grimes } 178df8bae1dSRodney W. Grimes 179df8bae1dSRodney W. Grimes /* 180df8bae1dSRodney W. Grimes * Free the net address hash lists that are hanging off the mount points. 181df8bae1dSRodney W. Grimes */ 182df8bae1dSRodney W. Grimes static void 183514ede09SBruce Evans vfs_free_addrlist(nep) 184514ede09SBruce Evans struct netexport *nep; 185df8bae1dSRodney W. Grimes { 186df8bae1dSRodney W. Grimes register int i; 187df8bae1dSRodney W. Grimes register struct radix_node_head *rnh; 188df8bae1dSRodney W. Grimes 189df8bae1dSRodney W. Grimes for (i = 0; i <= AF_MAX; i++) 190bb56ec4aSPoul-Henning Kamp if ((rnh = nep->ne_rtable[i])) { 191df8bae1dSRodney W. Grimes (*rnh->rnh_walktree) (rnh, vfs_free_netcred, 192df8bae1dSRodney W. Grimes (caddr_t) rnh); 193df8bae1dSRodney W. Grimes free((caddr_t) rnh, M_RTABLE); 194df8bae1dSRodney W. Grimes nep->ne_rtable[i] = 0; 195df8bae1dSRodney W. Grimes } 196df8bae1dSRodney W. Grimes } 197df8bae1dSRodney W. Grimes 19821a90397SAlfred Perlstein /* 19921a90397SAlfred Perlstein * High level function to manipulate export options on a mount point 20021a90397SAlfred Perlstein * and the passed in netexport. 20121a90397SAlfred Perlstein * Struct export_args *argp is the variable used to twiddle options, 20221a90397SAlfred Perlstein * the structure is described in sys/mount.h 20321a90397SAlfred Perlstein */ 204df8bae1dSRodney W. Grimes int 205a13234bbSPoul-Henning Kamp vfs_export(mp, argp) 206df8bae1dSRodney W. Grimes struct mount *mp; 207df8bae1dSRodney W. Grimes struct export_args *argp; 208df8bae1dSRodney W. Grimes { 209a13234bbSPoul-Henning Kamp struct netexport *nep; 210df8bae1dSRodney W. Grimes int error; 211df8bae1dSRodney W. Grimes 212a13234bbSPoul-Henning Kamp nep = mp->mnt_export; 213df8bae1dSRodney W. Grimes if (argp->ex_flags & MNT_DELEXPORT) { 214a13234bbSPoul-Henning Kamp if (nep == NULL) 2155f558fa4SIan Dowse return (ENOENT); 216f6b4c285SDoug Rabson if (mp->mnt_flag & MNT_EXPUBLIC) { 217f6b4c285SDoug Rabson vfs_setpublicfs(NULL, NULL, NULL); 218f6b4c285SDoug Rabson mp->mnt_flag &= ~MNT_EXPUBLIC; 219f6b4c285SDoug Rabson } 220df8bae1dSRodney W. Grimes vfs_free_addrlist(nep); 221a13234bbSPoul-Henning Kamp mp->mnt_export = NULL; 222a13234bbSPoul-Henning Kamp free(nep, M_MOUNT); 223df8bae1dSRodney W. Grimes mp->mnt_flag &= ~(MNT_EXPORTED | MNT_DEFEXPORTED); 224df8bae1dSRodney W. Grimes } 225df8bae1dSRodney W. Grimes if (argp->ex_flags & MNT_EXPORTED) { 226a13234bbSPoul-Henning Kamp if (nep == NULL) { 227a13234bbSPoul-Henning Kamp nep = malloc(sizeof(struct netexport), M_MOUNT, M_WAITOK | M_ZERO); 228a13234bbSPoul-Henning Kamp mp->mnt_export = nep; 229a13234bbSPoul-Henning Kamp } 230f6b4c285SDoug Rabson if (argp->ex_flags & MNT_EXPUBLIC) { 231f6b4c285SDoug Rabson if ((error = vfs_setpublicfs(mp, nep, argp)) != 0) 232f6b4c285SDoug Rabson return (error); 233f6b4c285SDoug Rabson mp->mnt_flag |= MNT_EXPUBLIC; 234f6b4c285SDoug Rabson } 235bb56ec4aSPoul-Henning Kamp if ((error = vfs_hang_addrlist(mp, nep, argp))) 236df8bae1dSRodney W. Grimes return (error); 237df8bae1dSRodney W. Grimes mp->mnt_flag |= MNT_EXPORTED; 238df8bae1dSRodney W. Grimes } 239df8bae1dSRodney W. Grimes return (0); 240df8bae1dSRodney W. Grimes } 241df8bae1dSRodney W. Grimes 242f6b4c285SDoug Rabson /* 243f6b4c285SDoug Rabson * Set the publicly exported filesystem (WebNFS). Currently, only 244f6b4c285SDoug Rabson * one public filesystem is possible in the spec (RFC 2054 and 2055) 245f6b4c285SDoug Rabson */ 246f6b4c285SDoug Rabson int 247f6b4c285SDoug Rabson vfs_setpublicfs(mp, nep, argp) 248f6b4c285SDoug Rabson struct mount *mp; 249f6b4c285SDoug Rabson struct netexport *nep; 250f6b4c285SDoug Rabson struct export_args *argp; 251f6b4c285SDoug Rabson { 252f6b4c285SDoug Rabson int error; 253f6b4c285SDoug Rabson struct vnode *rvp; 254f6b4c285SDoug Rabson char *cp; 255f6b4c285SDoug Rabson 256f6b4c285SDoug Rabson /* 257f6b4c285SDoug Rabson * mp == NULL -> invalidate the current info, the FS is 258f6b4c285SDoug Rabson * no longer exported. May be called from either vfs_export 259f6b4c285SDoug Rabson * or unmount, so check if it hasn't already been done. 260f6b4c285SDoug Rabson */ 261f6b4c285SDoug Rabson if (mp == NULL) { 262f6b4c285SDoug Rabson if (nfs_pub.np_valid) { 263f6b4c285SDoug Rabson nfs_pub.np_valid = 0; 264f6b4c285SDoug Rabson if (nfs_pub.np_index != NULL) { 265f6b4c285SDoug Rabson FREE(nfs_pub.np_index, M_TEMP); 266f6b4c285SDoug Rabson nfs_pub.np_index = NULL; 267f6b4c285SDoug Rabson } 268f6b4c285SDoug Rabson } 269f6b4c285SDoug Rabson return (0); 270f6b4c285SDoug Rabson } 271f6b4c285SDoug Rabson 272f6b4c285SDoug Rabson /* 273f6b4c285SDoug Rabson * Only one allowed at a time. 274f6b4c285SDoug Rabson */ 275f6b4c285SDoug Rabson if (nfs_pub.np_valid != 0 && mp != nfs_pub.np_mount) 276f6b4c285SDoug Rabson return (EBUSY); 277f6b4c285SDoug Rabson 278f6b4c285SDoug Rabson /* 279f6b4c285SDoug Rabson * Get real filehandle for root of exported FS. 280f6b4c285SDoug Rabson */ 281f6b4c285SDoug Rabson bzero((caddr_t)&nfs_pub.np_handle, sizeof(nfs_pub.np_handle)); 282f6b4c285SDoug Rabson nfs_pub.np_handle.fh_fsid = mp->mnt_stat.f_fsid; 283f6b4c285SDoug Rabson 284f6b4c285SDoug Rabson if ((error = VFS_ROOT(mp, &rvp))) 285f6b4c285SDoug Rabson return (error); 286f6b4c285SDoug Rabson 287f6b4c285SDoug Rabson if ((error = VFS_VPTOFH(rvp, &nfs_pub.np_handle.fh_fid))) 288f6b4c285SDoug Rabson return (error); 289f6b4c285SDoug Rabson 290f6b4c285SDoug Rabson vput(rvp); 291f6b4c285SDoug Rabson 292f6b4c285SDoug Rabson /* 293f6b4c285SDoug Rabson * If an indexfile was specified, pull it in. 294f6b4c285SDoug Rabson */ 295f6b4c285SDoug Rabson if (argp->ex_indexfile != NULL) { 296f6b4c285SDoug Rabson MALLOC(nfs_pub.np_index, char *, MAXNAMLEN + 1, M_TEMP, 297f6b4c285SDoug Rabson M_WAITOK); 298f6b4c285SDoug Rabson error = copyinstr(argp->ex_indexfile, nfs_pub.np_index, 299f6b4c285SDoug Rabson MAXNAMLEN, (size_t *)0); 300f6b4c285SDoug Rabson if (!error) { 301f6b4c285SDoug Rabson /* 302f6b4c285SDoug Rabson * Check for illegal filenames. 303f6b4c285SDoug Rabson */ 304f6b4c285SDoug Rabson for (cp = nfs_pub.np_index; *cp; cp++) { 305f6b4c285SDoug Rabson if (*cp == '/') { 306f6b4c285SDoug Rabson error = EINVAL; 307f6b4c285SDoug Rabson break; 308f6b4c285SDoug Rabson } 309f6b4c285SDoug Rabson } 310f6b4c285SDoug Rabson } 311f6b4c285SDoug Rabson if (error) { 312f6b4c285SDoug Rabson FREE(nfs_pub.np_index, M_TEMP); 313f6b4c285SDoug Rabson return (error); 314f6b4c285SDoug Rabson } 315f6b4c285SDoug Rabson } 316f6b4c285SDoug Rabson 317f6b4c285SDoug Rabson nfs_pub.np_mount = mp; 318f6b4c285SDoug Rabson nfs_pub.np_valid = 1; 319f6b4c285SDoug Rabson return (0); 320f6b4c285SDoug Rabson } 321f6b4c285SDoug Rabson 32221a90397SAlfred Perlstein /* 32321a90397SAlfred Perlstein * Used by the filesystems to determine if a given network address 32421a90397SAlfred Perlstein * (passed in 'nam') is present in thier exports list, returns a pointer 32521a90397SAlfred Perlstein * to struct netcred so that the filesystem can examine it for 32621a90397SAlfred Perlstein * access rights (read/write/etc). 32721a90397SAlfred Perlstein */ 328df8bae1dSRodney W. Grimes struct netcred * 329a13234bbSPoul-Henning Kamp vfs_export_lookup(mp, nam) 330df8bae1dSRodney W. Grimes register struct mount *mp; 33157bf258eSGarrett Wollman struct sockaddr *nam; 332df8bae1dSRodney W. Grimes { 333a13234bbSPoul-Henning Kamp struct netexport *nep; 334df8bae1dSRodney W. Grimes register struct netcred *np; 335df8bae1dSRodney W. Grimes register struct radix_node_head *rnh; 336df8bae1dSRodney W. Grimes struct sockaddr *saddr; 337df8bae1dSRodney W. Grimes 338a13234bbSPoul-Henning Kamp nep = mp->mnt_export; 339a13234bbSPoul-Henning Kamp if (nep == NULL) 340a13234bbSPoul-Henning Kamp return (NULL); 341df8bae1dSRodney W. Grimes np = NULL; 342df8bae1dSRodney W. Grimes if (mp->mnt_flag & MNT_EXPORTED) { 343df8bae1dSRodney W. Grimes /* 344df8bae1dSRodney W. Grimes * Lookup in the export list first. 345df8bae1dSRodney W. Grimes */ 346df8bae1dSRodney W. Grimes if (nam != NULL) { 34757bf258eSGarrett Wollman saddr = nam; 348df8bae1dSRodney W. Grimes rnh = nep->ne_rtable[saddr->sa_family]; 349df8bae1dSRodney W. Grimes if (rnh != NULL) { 350df8bae1dSRodney W. Grimes np = (struct netcred *) 351df8bae1dSRodney W. Grimes (*rnh->rnh_matchaddr)((caddr_t)saddr, 352df8bae1dSRodney W. Grimes rnh); 353df8bae1dSRodney W. Grimes if (np && np->netc_rnodes->rn_flags & RNF_ROOT) 354df8bae1dSRodney W. Grimes np = NULL; 355df8bae1dSRodney W. Grimes } 356df8bae1dSRodney W. Grimes } 357df8bae1dSRodney W. Grimes /* 358df8bae1dSRodney W. Grimes * If no address match, use the default if it exists. 359df8bae1dSRodney W. Grimes */ 360df8bae1dSRodney W. Grimes if (np == NULL && mp->mnt_flag & MNT_DEFEXPORTED) 361df8bae1dSRodney W. Grimes np = &nep->ne_defexported; 362df8bae1dSRodney W. Grimes } 363df8bae1dSRodney W. Grimes return (np); 364df8bae1dSRodney W. Grimes } 36561f5d510SDavid Greenman 36661f5d510SDavid Greenman /* 367a13234bbSPoul-Henning Kamp * XXX: This comment comes from the deprecated ufs_check_export() 368a13234bbSPoul-Henning Kamp * XXX: and may not entirely apply, but lacking something better: 369a13234bbSPoul-Henning Kamp * This is the generic part of fhtovp called after the underlying 370a13234bbSPoul-Henning Kamp * filesystem has validated the file handle. 371a13234bbSPoul-Henning Kamp * 372a13234bbSPoul-Henning Kamp * Verify that a host should have access to a filesystem. 373a13234bbSPoul-Henning Kamp */ 374a13234bbSPoul-Henning Kamp 375a13234bbSPoul-Henning Kamp int 376a13234bbSPoul-Henning Kamp vfs_stdcheckexp(mp, nam, extflagsp, credanonp) 377a13234bbSPoul-Henning Kamp struct mount *mp; 378a13234bbSPoul-Henning Kamp struct sockaddr *nam; 379a13234bbSPoul-Henning Kamp int *extflagsp; 380a13234bbSPoul-Henning Kamp struct ucred **credanonp; 381a13234bbSPoul-Henning Kamp { 382a13234bbSPoul-Henning Kamp struct netcred *np; 383a13234bbSPoul-Henning Kamp 384a13234bbSPoul-Henning Kamp np = vfs_export_lookup(mp, nam); 385a13234bbSPoul-Henning Kamp if (np == NULL) 386a13234bbSPoul-Henning Kamp return (EACCES); 387a13234bbSPoul-Henning Kamp *extflagsp = np->netc_exflags; 388a13234bbSPoul-Henning Kamp *credanonp = &np->netc_anon; 389a13234bbSPoul-Henning Kamp return (0); 390a13234bbSPoul-Henning Kamp } 391a13234bbSPoul-Henning Kamp 392