From a13234bb35c2671d47ec5b12eb613bb5d62121f2 Mon Sep 17 00:00:00 2001 From: Poul-Henning Kamp Date: Wed, 25 Apr 2001 07:07:52 +0000 Subject: [PATCH] Move the netexport structure from the fs-specific mountstructure to struct mount. This makes the "struct netexport *" paramter to the vfs_export and vfs_checkexport interface unneeded. Consequently that all non-stacking filesystems can use vfs_stdcheckexp(). At the same time, make it a pointer to a struct netexport in struct mount, so that we can remove the bogus AF_MAX and #include from --- sys/fs/cd9660/cd9660_vfsops.c | 30 +-------------- sys/fs/cd9660/iso.h | 1 - sys/fs/hpfs/hpfs.h | 2 + sys/fs/hpfs/hpfs_vfsops.c | 17 ++++---- sys/fs/msdosfs/msdosfs_vfsops.c | 24 +----------- sys/fs/msdosfs/msdosfsmount.h | 1 - sys/fs/ntfs/ntfs.h | 2 + sys/fs/ntfs/ntfs_vfsops.c | 18 ++++----- sys/gnu/ext2fs/ext2_mount.h | 2 - sys/gnu/ext2fs/ext2_vfsops.c | 4 +- sys/gnu/fs/ext2fs/ext2_mount.h | 2 - sys/gnu/fs/ext2fs/ext2_vfsops.c | 4 +- sys/isofs/cd9660/cd9660_vfsops.c | 30 +-------------- sys/isofs/cd9660/iso.h | 1 - sys/kern/vfs_default.c | 10 ----- sys/kern/vfs_export.c | 66 +++++++++++++++++++++++++++++--- sys/kern/vfs_subr.c | 66 +++++++++++++++++++++++++++++--- sys/msdosfs/msdosfs_vfsops.c | 24 +----------- sys/msdosfs/msdosfsmount.h | 1 - sys/ntfs/ntfs.h | 2 + sys/ntfs/ntfs_vfsops.c | 18 ++++----- sys/sys/mount.h | 31 ++++----------- sys/ufs/ffs/ffs_vfsops.c | 4 +- sys/ufs/ifs/ifs_vfsops.c | 2 +- sys/ufs/mfs/mfs_vfsops.c | 4 +- sys/ufs/ufs/ufs_extern.h | 3 +- sys/ufs/ufs/ufs_vfsops.c | 29 -------------- sys/ufs/ufs/ufsmount.h | 2 - 28 files changed, 174 insertions(+), 226 deletions(-) diff --git a/sys/fs/cd9660/cd9660_vfsops.c b/sys/fs/cd9660/cd9660_vfsops.c index 0228988cb988..276718f21695 100644 --- a/sys/fs/cd9660/cd9660_vfsops.c +++ b/sys/fs/cd9660/cd9660_vfsops.c @@ -73,8 +73,6 @@ static int cd9660_root __P((struct mount *, struct vnode **)); static int cd9660_statfs __P((struct mount *, struct statfs *, struct proc *)); static int cd9660_vget __P((struct mount *, ino_t, struct vnode **)); static int cd9660_fhtovp __P((struct mount *, struct fid *, struct vnode **)); -static int cd9660_checkexp __P((struct mount *, struct sockaddr *, - int *, struct ucred **)); static int cd9660_vptofh __P((struct vnode *, struct fid *)); static struct vfsops cd9660_vfsops = { @@ -87,7 +85,7 @@ static struct vfsops cd9660_vfsops = { vfs_stdsync, cd9660_vget, cd9660_fhtovp, - cd9660_checkexp, + vfs_stdcheckexp, cd9660_vptofh, cd9660_init, cd9660_uninit, @@ -207,7 +205,7 @@ cd9660_mount(mp, path, data, ndp, p) if (mp->mnt_flag & MNT_UPDATE) { imp = VFSTOISOFS(mp); if (args.fspec == 0) - return (vfs_export(mp, &imp->im_export, &args.export)); + return (vfs_export(mp, &args.export)); } /* * Not an update, or updating the name: look up the name @@ -652,30 +650,6 @@ cd9660_fhtovp(mp, fhp, vpp) return (0); } -int -cd9660_checkexp(mp, nam, exflagsp, credanonp) - struct mount *mp; - struct sockaddr *nam; - int *exflagsp; - struct ucred **credanonp; -{ - register struct netcred *np; - register struct iso_mnt *imp; - - imp = VFSTOISOFS(mp); - - /* - * Get the export permission structure for this tuple. - */ - np = vfs_export_lookup(mp, &imp->im_export, nam); - if (np == NULL) - return (EACCES); - - *exflagsp = np->netc_exflags; - *credanonp = &np->netc_anon; - return (0); -} - int cd9660_vget(mp, ino, vpp) struct mount *mp; diff --git a/sys/fs/cd9660/iso.h b/sys/fs/cd9660/iso.h index 2da3d82d1476..b62c723dcde8 100644 --- a/sys/fs/cd9660/iso.h +++ b/sys/fs/cd9660/iso.h @@ -235,7 +235,6 @@ struct iso_mnt { int im_bmask; int volume_space_size; - struct netexport im_export; char root[ISODCL (157, 190)]; int root_extent; diff --git a/sys/fs/hpfs/hpfs.h b/sys/fs/hpfs/hpfs.h index 0f07880711f7..f354b6bb7b49 100644 --- a/sys/fs/hpfs/hpfs.h +++ b/sys/fs/hpfs/hpfs.h @@ -310,7 +310,9 @@ struct cpisec { struct hpfsmount { struct sublock hpm_su; struct spblock hpm_sp; +#if !defined(__FreeBSD__) struct netexport hpm_export; +#endif struct mount * hpm_mp; struct vnode * hpm_devvp; dev_t hpm_dev; diff --git a/sys/fs/hpfs/hpfs_vfsops.c b/sys/fs/hpfs/hpfs_vfsops.c index 2d40b2da1253..ec68f86dce44 100644 --- a/sys/fs/hpfs/hpfs_vfsops.c +++ b/sys/fs/hpfs/hpfs_vfsops.c @@ -88,8 +88,6 @@ static int hpfs_mount __P((struct mount *, char *, caddr_t, struct nameidata *, struct proc *)); static int hpfs_init __P((struct vfsconf *)); static int hpfs_uninit __P((struct vfsconf *)); -static int hpfs_checkexp __P((struct mount *, struct sockaddr *, - int *, struct ucred **)); #else /* defined(__NetBSD__) */ static int hpfs_mount __P((struct mount *, const char *, void *, struct nameidata *, struct proc *)); @@ -101,20 +99,14 @@ static int hpfs_checkexp __P((struct mount *, struct mbuf *, int *, struct ucred **)); #endif +#if !defined(__FreeBSD__) /*ARGSUSED*/ static int hpfs_checkexp(mp, nam, exflagsp, credanonp) -#if defined(__FreeBSD__) - register struct mount *mp; - struct sockaddr *nam; - int *exflagsp; - struct ucred **credanonp; -#else /* defined(__NetBSD__) */ register struct mount *mp; struct mbuf *nam; int *exflagsp; struct ucred **credanonp; -#endif { register struct netcred *np; register struct hpfsmount *hpm = VFSTOHPFS(mp); @@ -130,6 +122,7 @@ hpfs_checkexp(mp, nam, exflagsp, credanonp) *credanonp = &np->netc_anon; return (0); } +#endif #if !defined(__FreeBSD__) /*ARGSUSED*/ @@ -222,7 +215,11 @@ hpfs_mount ( if (args.fspec == 0) { dprintf(("export 0x%x\n",args.export.ex_flags)); +#if defined(__FreeBSD__) + err = vfs_export(mp, &args.export); +#else /* defined(__NetBSD__) */ err = vfs_export(mp, &hpmp->hpm_export, &args.export); +#endif if (err) { printf("hpfs_mount: vfs_export failed %d\n", err); @@ -741,7 +738,7 @@ static struct vfsops hpfs_vfsops = { vfs_stdsync, hpfs_vget, hpfs_fhtovp, - hpfs_checkexp, + vfs_stdcheckexp, hpfs_vptofh, hpfs_init, hpfs_uninit, diff --git a/sys/fs/msdosfs/msdosfs_vfsops.c b/sys/fs/msdosfs/msdosfs_vfsops.c index 6cda3bd12872..2f04def7495d 100644 --- a/sys/fs/msdosfs/msdosfs_vfsops.c +++ b/sys/fs/msdosfs/msdosfs_vfsops.c @@ -93,8 +93,6 @@ static int mountmsdosfs __P((struct vnode *devvp, struct mount *mp, struct proc *p, struct msdosfs_args *argp)); static int msdosfs_fhtovp __P((struct mount *, struct fid *, struct vnode **)); -static int msdosfs_checkexp __P((struct mount *, struct sockaddr *, - int *, struct ucred **)); static int msdosfs_mount __P((struct mount *, char *, caddr_t, struct nameidata *, struct proc *)); static int msdosfs_root __P((struct mount *, struct vnode **)); @@ -292,7 +290,7 @@ msdosfs_mount(mp, path, data, ndp, p) /* * Process export requests. */ - return (vfs_export(mp, &pmp->pm_export, &args.export)); + return (vfs_export(mp, &args.export)); } } /* @@ -931,24 +929,6 @@ msdosfs_fhtovp(mp, fhp, vpp) return (0); } -static int -msdosfs_checkexp(mp, nam, exflagsp, credanonp) - struct mount *mp; - struct sockaddr *nam; - int *exflagsp; - struct ucred **credanonp; -{ - struct msdosfsmount *pmp = VFSTOMSDOSFS(mp); - struct netcred *np; - - np = vfs_export_lookup(mp, &pmp->pm_export, nam); - if (np == NULL) - return (EACCES); - *exflagsp = np->netc_exflags; - *credanonp = &np->netc_anon; - return (0); -} - static int msdosfs_vptofh(vp, fhp) struct vnode *vp; @@ -976,7 +956,7 @@ static struct vfsops msdosfs_vfsops = { msdosfs_sync, vfs_stdvget, msdosfs_fhtovp, - msdosfs_checkexp, + vfs_stdcheckexp, msdosfs_vptofh, msdosfs_init, msdosfs_uninit, diff --git a/sys/fs/msdosfs/msdosfsmount.h b/sys/fs/msdosfs/msdosfsmount.h index da4919040725..1c9a890e98ba 100644 --- a/sys/fs/msdosfs/msdosfsmount.h +++ b/sys/fs/msdosfs/msdosfsmount.h @@ -92,7 +92,6 @@ struct msdosfsmount { u_int pm_curfat; /* current fat for FAT32 (0 otherwise) */ u_int *pm_inusemap; /* ptr to bitmap of in-use clusters */ u_int pm_flags; /* see below */ - struct netexport pm_export; /* export information */ u_int16_t pm_u2w[128]; /* Local->Unicode table */ u_int8_t pm_ul[128]; /* Local upper->lower table */ u_int8_t pm_lu[128]; /* Local lower->upper table */ diff --git a/sys/fs/ntfs/ntfs.h b/sys/fs/ntfs/ntfs.h index 9bf77518f855..d74fe6fbb584 100644 --- a/sys/fs/ntfs/ntfs.h +++ b/sys/fs/ntfs/ntfs.h @@ -255,7 +255,9 @@ struct ntfsmount { cn_t ntm_cfree; struct ntvattrdef *ntm_ad; int ntm_adnum; +#if !defined(__FreeBSD__) struct netexport ntm_export; /* export information */ +#endif }; #define ntm_mftcn ntm_bootfile.bf_mftcn diff --git a/sys/fs/ntfs/ntfs_vfsops.c b/sys/fs/ntfs/ntfs_vfsops.c index 89a7dd7bc0f4..b6fde8ed6436 100644 --- a/sys/fs/ntfs/ntfs_vfsops.c +++ b/sys/fs/ntfs/ntfs_vfsops.c @@ -99,8 +99,6 @@ struct sockaddr; static int ntfs_mount __P((struct mount *, char *, caddr_t, struct nameidata *, struct proc *)); static int ntfs_init __P((struct vfsconf *)); -static int ntfs_checkexp __P((struct mount *, struct sockaddr *, - int *, struct ucred **)); #elif defined(__NetBSD__) static int ntfs_mount __P((struct mount *, const char *, void *, struct nameidata *, struct proc *)); @@ -116,19 +114,13 @@ static int ntfs_checkexp __P((struct mount *, struct mbuf *, * Verify a remote client has export rights and return these rights via. * exflagsp and credanonp. */ +#if !defined(__FreeBSD__) static int ntfs_checkexp(mp, nam, exflagsp, credanonp) -#if defined(__FreeBSD__) - register struct mount *mp; - struct sockaddr *nam; - int *exflagsp; - struct ucred **credanonp; -#else /* defined(__NetBSD__) */ register struct mount *mp; struct mbuf *nam; int *exflagsp; struct ucred **credanonp; -#endif { register struct netcred *np; register struct ntfsmount *ntm = VFSTONTFS(mp); @@ -139,11 +131,11 @@ ntfs_checkexp(mp, nam, exflagsp, credanonp) np = vfs_export_lookup(mp, &ntm->ntm_export, nam); if (np == NULL) return (EACCES); - *exflagsp = np->netc_exflags; *credanonp = &np->netc_anon; return (0); } +#endif #if defined(__NetBSD__) /*ARGSUSED*/ @@ -306,8 +298,12 @@ ntfs_mount ( * Process export requests. Jumping to "success" * will return the vfs_export() error code. */ +#if defined(__FreeBSD__) + err = vfs_export(mp, &args.export); +#else /* defined(__NetBSD__) */ struct ntfsmount *ntm = VFSTONTFS(mp); err = vfs_export(mp, &ntm->ntm_export, &args.export); +#endif goto success; } @@ -1007,7 +1003,7 @@ static struct vfsops ntfs_vfsops = { vfs_stdsync, ntfs_vget, ntfs_fhtovp, - ntfs_checkexp, + vfs_stdcheckexp, ntfs_vptofh, ntfs_init, ntfs_uninit, diff --git a/sys/gnu/ext2fs/ext2_mount.h b/sys/gnu/ext2fs/ext2_mount.h index 900c81e61307..f5b93f57caa1 100644 --- a/sys/gnu/ext2fs/ext2_mount.h +++ b/sys/gnu/ext2fs/ext2_mount.h @@ -68,7 +68,6 @@ struct timeval; struct ucred; struct uio; struct vnode; -struct netexport; struct ufs_extattr_per_mount; /* This structure describes the UFS specific mount structure data. */ @@ -94,7 +93,6 @@ struct ufsmount { time_t um_btime[MAXQUOTAS]; /* block quota time limit */ time_t um_itime[MAXQUOTAS]; /* inode quota time limit */ char um_qflags[MAXQUOTAS]; /* quota specific flags */ - struct netexport um_export; /* export information */ int64_t um_savedmaxfilesize; /* XXX - limit maxfilesize */ struct malloc_type *um_malloctype; /* The inodes malloctype */ int um_i_effnlink_valid; /* i_effnlink valid? */ diff --git a/sys/gnu/ext2fs/ext2_vfsops.c b/sys/gnu/ext2fs/ext2_vfsops.c index 263db6dcf090..5f7118eb85c0 100644 --- a/sys/gnu/ext2fs/ext2_vfsops.c +++ b/sys/gnu/ext2fs/ext2_vfsops.c @@ -96,7 +96,7 @@ static struct vfsops ext2fs_vfsops = { ext2_sync, ext2_vget, ext2_fhtovp, - ufs_check_export, + vfs_stdcheckexp, ext2_vptofh, ext2_init, vfs_stduninit, @@ -264,7 +264,7 @@ ext2_mount(mp, path, data, ndp, p) /* * Process export requests. */ - return (vfs_export(mp, &ump->um_export, &args.export)); + return (vfs_export(mp, &args.export)); } } /* diff --git a/sys/gnu/fs/ext2fs/ext2_mount.h b/sys/gnu/fs/ext2fs/ext2_mount.h index 900c81e61307..f5b93f57caa1 100644 --- a/sys/gnu/fs/ext2fs/ext2_mount.h +++ b/sys/gnu/fs/ext2fs/ext2_mount.h @@ -68,7 +68,6 @@ struct timeval; struct ucred; struct uio; struct vnode; -struct netexport; struct ufs_extattr_per_mount; /* This structure describes the UFS specific mount structure data. */ @@ -94,7 +93,6 @@ struct ufsmount { time_t um_btime[MAXQUOTAS]; /* block quota time limit */ time_t um_itime[MAXQUOTAS]; /* inode quota time limit */ char um_qflags[MAXQUOTAS]; /* quota specific flags */ - struct netexport um_export; /* export information */ int64_t um_savedmaxfilesize; /* XXX - limit maxfilesize */ struct malloc_type *um_malloctype; /* The inodes malloctype */ int um_i_effnlink_valid; /* i_effnlink valid? */ diff --git a/sys/gnu/fs/ext2fs/ext2_vfsops.c b/sys/gnu/fs/ext2fs/ext2_vfsops.c index 263db6dcf090..5f7118eb85c0 100644 --- a/sys/gnu/fs/ext2fs/ext2_vfsops.c +++ b/sys/gnu/fs/ext2fs/ext2_vfsops.c @@ -96,7 +96,7 @@ static struct vfsops ext2fs_vfsops = { ext2_sync, ext2_vget, ext2_fhtovp, - ufs_check_export, + vfs_stdcheckexp, ext2_vptofh, ext2_init, vfs_stduninit, @@ -264,7 +264,7 @@ ext2_mount(mp, path, data, ndp, p) /* * Process export requests. */ - return (vfs_export(mp, &ump->um_export, &args.export)); + return (vfs_export(mp, &args.export)); } } /* diff --git a/sys/isofs/cd9660/cd9660_vfsops.c b/sys/isofs/cd9660/cd9660_vfsops.c index 0228988cb988..276718f21695 100644 --- a/sys/isofs/cd9660/cd9660_vfsops.c +++ b/sys/isofs/cd9660/cd9660_vfsops.c @@ -73,8 +73,6 @@ static int cd9660_root __P((struct mount *, struct vnode **)); static int cd9660_statfs __P((struct mount *, struct statfs *, struct proc *)); static int cd9660_vget __P((struct mount *, ino_t, struct vnode **)); static int cd9660_fhtovp __P((struct mount *, struct fid *, struct vnode **)); -static int cd9660_checkexp __P((struct mount *, struct sockaddr *, - int *, struct ucred **)); static int cd9660_vptofh __P((struct vnode *, struct fid *)); static struct vfsops cd9660_vfsops = { @@ -87,7 +85,7 @@ static struct vfsops cd9660_vfsops = { vfs_stdsync, cd9660_vget, cd9660_fhtovp, - cd9660_checkexp, + vfs_stdcheckexp, cd9660_vptofh, cd9660_init, cd9660_uninit, @@ -207,7 +205,7 @@ cd9660_mount(mp, path, data, ndp, p) if (mp->mnt_flag & MNT_UPDATE) { imp = VFSTOISOFS(mp); if (args.fspec == 0) - return (vfs_export(mp, &imp->im_export, &args.export)); + return (vfs_export(mp, &args.export)); } /* * Not an update, or updating the name: look up the name @@ -652,30 +650,6 @@ cd9660_fhtovp(mp, fhp, vpp) return (0); } -int -cd9660_checkexp(mp, nam, exflagsp, credanonp) - struct mount *mp; - struct sockaddr *nam; - int *exflagsp; - struct ucred **credanonp; -{ - register struct netcred *np; - register struct iso_mnt *imp; - - imp = VFSTOISOFS(mp); - - /* - * Get the export permission structure for this tuple. - */ - np = vfs_export_lookup(mp, &imp->im_export, nam); - if (np == NULL) - return (EACCES); - - *exflagsp = np->netc_exflags; - *credanonp = &np->netc_anon; - return (0); -} - int cd9660_vget(mp, ino, vpp) struct mount *mp; diff --git a/sys/isofs/cd9660/iso.h b/sys/isofs/cd9660/iso.h index 2da3d82d1476..b62c723dcde8 100644 --- a/sys/isofs/cd9660/iso.h +++ b/sys/isofs/cd9660/iso.h @@ -235,7 +235,6 @@ struct iso_mnt { int im_bmask; int volume_space_size; - struct netexport im_export; char root[ISODCL (157, 190)]; int root_extent; diff --git a/sys/kern/vfs_default.c b/sys/kern/vfs_default.c index 13411298d80f..f1dd5e9e48d8 100644 --- a/sys/kern/vfs_default.c +++ b/sys/kern/vfs_default.c @@ -708,16 +708,6 @@ vfs_stdfhtovp (mp, fhp, vpp) return (EOPNOTSUPP); } -int -vfs_stdcheckexp (mp, nam, extflagsp, credanonp) - struct mount *mp; - struct sockaddr *nam; - int *extflagsp; - struct ucred **credanonp; -{ - return (EOPNOTSUPP); -} - int vfs_stdinit (vfsp) struct vfsconf *vfsp; diff --git a/sys/kern/vfs_export.c b/sys/kern/vfs_export.c index 352b83e56aea..4bb58fe98054 100644 --- a/sys/kern/vfs_export.c +++ b/sys/kern/vfs_export.c @@ -73,7 +73,7 @@ #include #include - +#include #include #include #include @@ -258,6 +258,23 @@ static int vfs_free_netcred __P((struct radix_node *rn, void *w)); static int vfs_hang_addrlist __P((struct mount *mp, struct netexport *nep, struct export_args *argp)); +/* + * Network address lookup element + */ +struct netcred { + struct radix_node netc_rnodes[2]; + int netc_exflags; + struct ucred netc_anon; +}; + +/* + * Network export information + */ +struct netexport { + struct netcred ne_defexported; /* Default export */ + struct radix_node_head *ne_rtable[AF_MAX+1]; /* Individual exports */ +}; + /* * Initialize the vnode management data structures. */ @@ -2448,22 +2465,31 @@ vfs_free_addrlist(nep) * the structure is described in sys/mount.h */ int -vfs_export(mp, nep, argp) +vfs_export(mp, argp) struct mount *mp; - struct netexport *nep; struct export_args *argp; { + struct netexport *nep; int error; + nep = mp->mnt_export; if (argp->ex_flags & MNT_DELEXPORT) { + if (nep == NULL) + return (EINVAL); if (mp->mnt_flag & MNT_EXPUBLIC) { vfs_setpublicfs(NULL, NULL, NULL); mp->mnt_flag &= ~MNT_EXPUBLIC; } vfs_free_addrlist(nep); + mp->mnt_export = NULL; + free(nep, M_MOUNT); mp->mnt_flag &= ~(MNT_EXPORTED | MNT_DEFEXPORTED); } if (argp->ex_flags & MNT_EXPORTED) { + if (nep == NULL) { + nep = malloc(sizeof(struct netexport), M_MOUNT, M_WAITOK | M_ZERO); + mp->mnt_export = nep; + } if (argp->ex_flags & MNT_EXPUBLIC) { if ((error = vfs_setpublicfs(mp, nep, argp)) != 0) return (error); @@ -2563,15 +2589,18 @@ vfs_setpublicfs(mp, nep, argp) * access rights (read/write/etc). */ struct netcred * -vfs_export_lookup(mp, nep, nam) +vfs_export_lookup(mp, nam) register struct mount *mp; - struct netexport *nep; struct sockaddr *nam; { + struct netexport *nep; register struct netcred *np; register struct radix_node_head *rnh; struct sockaddr *saddr; + nep = mp->mnt_export; + if (nep == NULL) + return (NULL); np = NULL; if (mp->mnt_flag & MNT_EXPORTED) { /* @@ -3176,3 +3205,30 @@ vaccess(type, file_mode, file_uid, file_gid, acc_mode, cred, privused) return ((acc_mode & VADMIN) ? EPERM : EACCES); } + +/* + * XXX: This comment comes from the deprecated ufs_check_export() + * XXX: and may not entirely apply, but lacking something better: + * This is the generic part of fhtovp called after the underlying + * filesystem has validated the file handle. + * + * Verify that a host should have access to a filesystem. + */ + +int +vfs_stdcheckexp(mp, nam, extflagsp, credanonp) + struct mount *mp; + struct sockaddr *nam; + int *extflagsp; + struct ucred **credanonp; +{ + struct netcred *np; + + np = vfs_export_lookup(mp, nam); + if (np == NULL) + return (EACCES); + *extflagsp = np->netc_exflags; + *credanonp = &np->netc_anon; + return (0); +} + diff --git a/sys/kern/vfs_subr.c b/sys/kern/vfs_subr.c index 352b83e56aea..4bb58fe98054 100644 --- a/sys/kern/vfs_subr.c +++ b/sys/kern/vfs_subr.c @@ -73,7 +73,7 @@ #include #include - +#include #include #include #include @@ -258,6 +258,23 @@ static int vfs_free_netcred __P((struct radix_node *rn, void *w)); static int vfs_hang_addrlist __P((struct mount *mp, struct netexport *nep, struct export_args *argp)); +/* + * Network address lookup element + */ +struct netcred { + struct radix_node netc_rnodes[2]; + int netc_exflags; + struct ucred netc_anon; +}; + +/* + * Network export information + */ +struct netexport { + struct netcred ne_defexported; /* Default export */ + struct radix_node_head *ne_rtable[AF_MAX+1]; /* Individual exports */ +}; + /* * Initialize the vnode management data structures. */ @@ -2448,22 +2465,31 @@ vfs_free_addrlist(nep) * the structure is described in sys/mount.h */ int -vfs_export(mp, nep, argp) +vfs_export(mp, argp) struct mount *mp; - struct netexport *nep; struct export_args *argp; { + struct netexport *nep; int error; + nep = mp->mnt_export; if (argp->ex_flags & MNT_DELEXPORT) { + if (nep == NULL) + return (EINVAL); if (mp->mnt_flag & MNT_EXPUBLIC) { vfs_setpublicfs(NULL, NULL, NULL); mp->mnt_flag &= ~MNT_EXPUBLIC; } vfs_free_addrlist(nep); + mp->mnt_export = NULL; + free(nep, M_MOUNT); mp->mnt_flag &= ~(MNT_EXPORTED | MNT_DEFEXPORTED); } if (argp->ex_flags & MNT_EXPORTED) { + if (nep == NULL) { + nep = malloc(sizeof(struct netexport), M_MOUNT, M_WAITOK | M_ZERO); + mp->mnt_export = nep; + } if (argp->ex_flags & MNT_EXPUBLIC) { if ((error = vfs_setpublicfs(mp, nep, argp)) != 0) return (error); @@ -2563,15 +2589,18 @@ vfs_setpublicfs(mp, nep, argp) * access rights (read/write/etc). */ struct netcred * -vfs_export_lookup(mp, nep, nam) +vfs_export_lookup(mp, nam) register struct mount *mp; - struct netexport *nep; struct sockaddr *nam; { + struct netexport *nep; register struct netcred *np; register struct radix_node_head *rnh; struct sockaddr *saddr; + nep = mp->mnt_export; + if (nep == NULL) + return (NULL); np = NULL; if (mp->mnt_flag & MNT_EXPORTED) { /* @@ -3176,3 +3205,30 @@ vaccess(type, file_mode, file_uid, file_gid, acc_mode, cred, privused) return ((acc_mode & VADMIN) ? EPERM : EACCES); } + +/* + * XXX: This comment comes from the deprecated ufs_check_export() + * XXX: and may not entirely apply, but lacking something better: + * This is the generic part of fhtovp called after the underlying + * filesystem has validated the file handle. + * + * Verify that a host should have access to a filesystem. + */ + +int +vfs_stdcheckexp(mp, nam, extflagsp, credanonp) + struct mount *mp; + struct sockaddr *nam; + int *extflagsp; + struct ucred **credanonp; +{ + struct netcred *np; + + np = vfs_export_lookup(mp, nam); + if (np == NULL) + return (EACCES); + *extflagsp = np->netc_exflags; + *credanonp = &np->netc_anon; + return (0); +} + diff --git a/sys/msdosfs/msdosfs_vfsops.c b/sys/msdosfs/msdosfs_vfsops.c index 6cda3bd12872..2f04def7495d 100644 --- a/sys/msdosfs/msdosfs_vfsops.c +++ b/sys/msdosfs/msdosfs_vfsops.c @@ -93,8 +93,6 @@ static int mountmsdosfs __P((struct vnode *devvp, struct mount *mp, struct proc *p, struct msdosfs_args *argp)); static int msdosfs_fhtovp __P((struct mount *, struct fid *, struct vnode **)); -static int msdosfs_checkexp __P((struct mount *, struct sockaddr *, - int *, struct ucred **)); static int msdosfs_mount __P((struct mount *, char *, caddr_t, struct nameidata *, struct proc *)); static int msdosfs_root __P((struct mount *, struct vnode **)); @@ -292,7 +290,7 @@ msdosfs_mount(mp, path, data, ndp, p) /* * Process export requests. */ - return (vfs_export(mp, &pmp->pm_export, &args.export)); + return (vfs_export(mp, &args.export)); } } /* @@ -931,24 +929,6 @@ msdosfs_fhtovp(mp, fhp, vpp) return (0); } -static int -msdosfs_checkexp(mp, nam, exflagsp, credanonp) - struct mount *mp; - struct sockaddr *nam; - int *exflagsp; - struct ucred **credanonp; -{ - struct msdosfsmount *pmp = VFSTOMSDOSFS(mp); - struct netcred *np; - - np = vfs_export_lookup(mp, &pmp->pm_export, nam); - if (np == NULL) - return (EACCES); - *exflagsp = np->netc_exflags; - *credanonp = &np->netc_anon; - return (0); -} - static int msdosfs_vptofh(vp, fhp) struct vnode *vp; @@ -976,7 +956,7 @@ static struct vfsops msdosfs_vfsops = { msdosfs_sync, vfs_stdvget, msdosfs_fhtovp, - msdosfs_checkexp, + vfs_stdcheckexp, msdosfs_vptofh, msdosfs_init, msdosfs_uninit, diff --git a/sys/msdosfs/msdosfsmount.h b/sys/msdosfs/msdosfsmount.h index da4919040725..1c9a890e98ba 100644 --- a/sys/msdosfs/msdosfsmount.h +++ b/sys/msdosfs/msdosfsmount.h @@ -92,7 +92,6 @@ struct msdosfsmount { u_int pm_curfat; /* current fat for FAT32 (0 otherwise) */ u_int *pm_inusemap; /* ptr to bitmap of in-use clusters */ u_int pm_flags; /* see below */ - struct netexport pm_export; /* export information */ u_int16_t pm_u2w[128]; /* Local->Unicode table */ u_int8_t pm_ul[128]; /* Local upper->lower table */ u_int8_t pm_lu[128]; /* Local lower->upper table */ diff --git a/sys/ntfs/ntfs.h b/sys/ntfs/ntfs.h index 9bf77518f855..d74fe6fbb584 100644 --- a/sys/ntfs/ntfs.h +++ b/sys/ntfs/ntfs.h @@ -255,7 +255,9 @@ struct ntfsmount { cn_t ntm_cfree; struct ntvattrdef *ntm_ad; int ntm_adnum; +#if !defined(__FreeBSD__) struct netexport ntm_export; /* export information */ +#endif }; #define ntm_mftcn ntm_bootfile.bf_mftcn diff --git a/sys/ntfs/ntfs_vfsops.c b/sys/ntfs/ntfs_vfsops.c index 89a7dd7bc0f4..b6fde8ed6436 100644 --- a/sys/ntfs/ntfs_vfsops.c +++ b/sys/ntfs/ntfs_vfsops.c @@ -99,8 +99,6 @@ struct sockaddr; static int ntfs_mount __P((struct mount *, char *, caddr_t, struct nameidata *, struct proc *)); static int ntfs_init __P((struct vfsconf *)); -static int ntfs_checkexp __P((struct mount *, struct sockaddr *, - int *, struct ucred **)); #elif defined(__NetBSD__) static int ntfs_mount __P((struct mount *, const char *, void *, struct nameidata *, struct proc *)); @@ -116,19 +114,13 @@ static int ntfs_checkexp __P((struct mount *, struct mbuf *, * Verify a remote client has export rights and return these rights via. * exflagsp and credanonp. */ +#if !defined(__FreeBSD__) static int ntfs_checkexp(mp, nam, exflagsp, credanonp) -#if defined(__FreeBSD__) - register struct mount *mp; - struct sockaddr *nam; - int *exflagsp; - struct ucred **credanonp; -#else /* defined(__NetBSD__) */ register struct mount *mp; struct mbuf *nam; int *exflagsp; struct ucred **credanonp; -#endif { register struct netcred *np; register struct ntfsmount *ntm = VFSTONTFS(mp); @@ -139,11 +131,11 @@ ntfs_checkexp(mp, nam, exflagsp, credanonp) np = vfs_export_lookup(mp, &ntm->ntm_export, nam); if (np == NULL) return (EACCES); - *exflagsp = np->netc_exflags; *credanonp = &np->netc_anon; return (0); } +#endif #if defined(__NetBSD__) /*ARGSUSED*/ @@ -306,8 +298,12 @@ ntfs_mount ( * Process export requests. Jumping to "success" * will return the vfs_export() error code. */ +#if defined(__FreeBSD__) + err = vfs_export(mp, &args.export); +#else /* defined(__NetBSD__) */ struct ntfsmount *ntm = VFSTONTFS(mp); err = vfs_export(mp, &ntm->ntm_export, &args.export); +#endif goto success; } @@ -1007,7 +1003,7 @@ static struct vfsops ntfs_vfsops = { vfs_stdsync, ntfs_vget, ntfs_fhtovp, - ntfs_checkexp, + vfs_stdcheckexp, ntfs_vptofh, ntfs_init, ntfs_uninit, diff --git a/sys/sys/mount.h b/sys/sys/mount.h index c522c1831d4f..aef5ac5b9b7b 100644 --- a/sys/sys/mount.h +++ b/sys/sys/mount.h @@ -43,6 +43,9 @@ #include #endif +struct netcred; +struct netexport; + typedef struct fsid { int32_t val[2]; } fsid_t; /* file system id type */ /* @@ -118,6 +121,7 @@ struct mount { qaddr_t mnt_data; /* private data */ time_t mnt_time; /* last time written*/ u_int mnt_iosize_max; /* max IO request size */ + struct netexport *mnt_export; /* export list */ }; #endif /* _KERNEL */ @@ -378,27 +382,6 @@ struct vfsops { }; \ DECLARE_MODULE(fsname, fsname ## _mod, SI_SUB_VFS, SI_ORDER_MIDDLE) -#include - -#define AF_MAX 35 /* XXX */ - -/* - * Network address lookup element - */ -struct netcred { - struct radix_node netc_rnodes[2]; - int netc_exflags; - struct ucred netc_anon; -}; - -/* - * Network export information - */ -struct netexport { - struct netcred ne_defexported; /* Default export */ - struct radix_node_head *ne_rtable[AF_MAX+1]; /* Individual exports */ -}; - extern char *mountrootfsname; /* @@ -413,10 +396,10 @@ int vfs_lock __P((struct mount *)); /* lock a vfs */ void vfs_msync __P((struct mount *, int)); void vfs_unlock __P((struct mount *)); /* unlock a vfs */ int vfs_busy __P((struct mount *, int, struct mtx *, struct proc *)); -int vfs_export /* process mount export info */ - __P((struct mount *, struct netexport *, struct export_args *)); +int vfs_export /* process mount export info */ + __P((struct mount *, struct export_args *)); struct netcred *vfs_export_lookup /* lookup host in fs export list */ - __P((struct mount *, struct netexport *, struct sockaddr *)); + __P((struct mount *, struct sockaddr *)); int vfs_allocate_syncvnode __P((struct mount *)); void vfs_getnewfsid __P((struct mount *)); dev_t vfs_getrootfsid __P((struct mount *)); diff --git a/sys/ufs/ffs/ffs_vfsops.c b/sys/ufs/ffs/ffs_vfsops.c index 58a2dfcf4408..7d48fdb6e36e 100644 --- a/sys/ufs/ffs/ffs_vfsops.c +++ b/sys/ufs/ffs/ffs_vfsops.c @@ -83,7 +83,7 @@ static struct vfsops ufs_vfsops = { ffs_sync, ffs_vget, ffs_fhtovp, - ufs_check_export, + vfs_stdcheckexp, ffs_vptofh, ffs_init, vfs_stduninit, @@ -268,7 +268,7 @@ ffs_mount(mp, path, data, ndp, p) * If not updating name, process export requests. */ if (args.fspec == 0) - return (vfs_export(mp, &ump->um_export, &args.export)); + return (vfs_export(mp, &args.export)); /* * If this is a snapshot request, take the snapshot. */ diff --git a/sys/ufs/ifs/ifs_vfsops.c b/sys/ufs/ifs/ifs_vfsops.c index f0e2e8ca679c..41b1d5f2b5ed 100644 --- a/sys/ufs/ifs/ifs_vfsops.c +++ b/sys/ufs/ifs/ifs_vfsops.c @@ -85,7 +85,7 @@ static struct vfsops ifs_vfsops = { ffs_sync, ifs_vget, ffs_fhtovp, - ufs_check_export, + vfs_stdcheckexp, ffs_vptofh, ifs_init, vfs_stduninit, diff --git a/sys/ufs/mfs/mfs_vfsops.c b/sys/ufs/mfs/mfs_vfsops.c index 2f56b1a366ac..4ac0002a93a0 100644 --- a/sys/ufs/mfs/mfs_vfsops.c +++ b/sys/ufs/mfs/mfs_vfsops.c @@ -109,7 +109,7 @@ static struct vfsops mfs_vfsops = { ffs_sync, ffs_vget, ffs_fhtovp, - ufs_check_export, + vfs_stdcheckexp, ffs_vptofh, mfs_init, vfs_stduninit, @@ -230,7 +230,7 @@ mfs_mount(mp, path, data, ndp, p) * Process export requests. Jumping to "success" * will return the vfs_export() error code. */ - err = vfs_export(mp, &ump->um_export, &args.export); + err = vfs_export(mp, &args.export); goto success; } diff --git a/sys/ufs/ufs/ufs_extern.h b/sys/ufs/ufs/ufs_extern.h index 82704b61410a..251d4a01471f 100644 --- a/sys/ufs/ufs/ufs_extern.h +++ b/sys/ufs/ufs/ufs_extern.h @@ -42,6 +42,7 @@ struct direct; struct indir; struct inode; struct mount; +struct netcred; struct proc; struct sockaddr; struct ucred; @@ -61,8 +62,6 @@ int ufs_vnoperatespec __P((struct vop_generic_args *)); int ufs_bmap __P((struct vop_bmap_args *)); int ufs_bmaparray __P((struct vnode *, daddr_t, daddr_t *, struct indir *, int *, int *, int *)); -int ufs_check_export __P((struct mount *, struct sockaddr *, - int *, struct ucred **)); int ufs_fhtovp(register struct mount *, struct ufid *, struct vnode **); int ufs_checkpath __P((struct inode *, struct inode *, struct ucred *)); void ufs_dirbad __P((struct inode *, doff_t, char *)); diff --git a/sys/ufs/ufs/ufs_vfsops.c b/sys/ufs/ufs/ufs_vfsops.c index 33346cf66a2d..73f8237af8d3 100644 --- a/sys/ufs/ufs/ufs_vfsops.c +++ b/sys/ufs/ufs/ufs_vfsops.c @@ -214,32 +214,3 @@ ufs_fhtovp(mp, ufhp, vpp) return (0); } - -/* - * This is the generic part of fhtovp called after the underlying - * filesystem has validated the file handle. - * - * Verify that a host should have access to a filesystem. - */ -int -ufs_check_export(mp, nam, exflagsp, credanonp) - register struct mount *mp; - struct sockaddr *nam; - int *exflagsp; - struct ucred **credanonp; -{ - register struct netcred *np; - register struct ufsmount *ump;; - - ump = VFSTOUFS(mp); - /* - * Get the export permission structure for this tuple. - */ - np = vfs_export_lookup(mp, &ump->um_export, nam); - if (np == NULL) - return (EACCES); - - *exflagsp = np->netc_exflags; - *credanonp = &np->netc_anon; - return (0); -} diff --git a/sys/ufs/ufs/ufsmount.h b/sys/ufs/ufs/ufsmount.h index 900c81e61307..f5b93f57caa1 100644 --- a/sys/ufs/ufs/ufsmount.h +++ b/sys/ufs/ufs/ufsmount.h @@ -68,7 +68,6 @@ struct timeval; struct ucred; struct uio; struct vnode; -struct netexport; struct ufs_extattr_per_mount; /* This structure describes the UFS specific mount structure data. */ @@ -94,7 +93,6 @@ struct ufsmount { time_t um_btime[MAXQUOTAS]; /* block quota time limit */ time_t um_itime[MAXQUOTAS]; /* inode quota time limit */ char um_qflags[MAXQUOTAS]; /* quota specific flags */ - struct netexport um_export; /* export information */ int64_t um_savedmaxfilesize; /* XXX - limit maxfilesize */ struct malloc_type *um_malloctype; /* The inodes malloctype */ int um_i_effnlink_valid; /* i_effnlink valid? */