diff options
author | phk <phk@FreeBSD.org> | 2000-08-20 08:36:26 +0000 |
---|---|---|
committer | phk <phk@FreeBSD.org> | 2000-08-20 08:36:26 +0000 |
commit | 3d2aecdc81ed97cfbe436b52fc98b64db180e3ba (patch) | |
tree | 55c272da20b4e053d7634d0f42eb73a594cf619e /sys/fs | |
parent | 936d03c5051b75e93717f207de0e6a3764c41cd7 (diff) | |
download | FreeBSD-src-3d2aecdc81ed97cfbe436b52fc98b64db180e3ba.zip FreeBSD-src-3d2aecdc81ed97cfbe436b52fc98b64db180e3ba.tar.gz |
Centralize the canonical vop_access user/group/other check in vaccess().
Discussed with: bde
Diffstat (limited to 'sys/fs')
-rw-r--r-- | sys/fs/cd9660/cd9660_vnops.c | 45 | ||||
-rw-r--r-- | sys/fs/hpfs/hpfs_vnops.c | 44 | ||||
-rw-r--r-- | sys/fs/msdosfs/msdosfs_vnops.c | 44 | ||||
-rw-r--r-- | sys/fs/ntfs/ntfs_vnops.c | 46 |
4 files changed, 13 insertions, 166 deletions
diff --git a/sys/fs/cd9660/cd9660_vnops.c b/sys/fs/cd9660/cd9660_vnops.c index e4c6909..b4e06fb 100644 --- a/sys/fs/cd9660/cd9660_vnops.c +++ b/sys/fs/cd9660/cd9660_vnops.c @@ -135,10 +135,7 @@ cd9660_access(ap) { struct vnode *vp = ap->a_vp; struct iso_node *ip = VTOI(vp); - struct ucred *cred = ap->a_cred; - mode_t mask, mode = ap->a_mode; - gid_t *gp; - int i; + mode_t mode = ap->a_mode; /* * Disallow write attempts unless the file is a socket, @@ -157,44 +154,8 @@ cd9660_access(ap) } } - /* User id 0 always gets access. */ - if (cred->cr_uid == 0) - return (0); - - mask = 0; - - /* Otherwise, check the owner. */ - if (cred->cr_uid == ip->inode.iso_uid) { - if (mode & VEXEC) - mask |= S_IXUSR; - if (mode & VREAD) - mask |= S_IRUSR; - if (mode & VWRITE) - mask |= S_IWUSR; - return ((ip->inode.iso_mode & mask) == mask ? 0 : EACCES); - } - - /* Otherwise, check the groups. */ - for (i = 0, gp = cred->cr_groups; i < cred->cr_ngroups; i++, gp++) - if (ip->inode.iso_gid == *gp) { - if (mode & VEXEC) - mask |= S_IXGRP; - if (mode & VREAD) - mask |= S_IRGRP; - if (mode & VWRITE) - mask |= S_IWGRP; - return ((ip->inode.iso_mode & mask) == mask ? - 0 : EACCES); - } - - /* Otherwise, check everyone else. */ - if (mode & VEXEC) - mask |= S_IXOTH; - if (mode & VREAD) - mask |= S_IROTH; - if (mode & VWRITE) - mask |= S_IWOTH; - return ((ip->inode.iso_mode & mask) == mask ? 0 : EACCES); + return (vaccess(vp->v_type, ip->inode.iso_mode, ip->inode.iso_uid, + ip->inode.iso_gid, ap->a_mode, ap->a_cred)); } static int diff --git a/sys/fs/hpfs/hpfs_vnops.c b/sys/fs/hpfs/hpfs_vnops.c index 4ab248c..4f5a735 100644 --- a/sys/fs/hpfs/hpfs_vnops.c +++ b/sys/fs/hpfs/hpfs_vnops.c @@ -777,10 +777,7 @@ hpfs_access(ap) { struct vnode *vp = ap->a_vp; struct hpfsnode *hp = VTOHP(vp); - struct ucred *cred = ap->a_cred; - mode_t mask, mode = ap->a_mode; - register gid_t *gp; - int i; + mode_t mode = ap->a_mode; dprintf(("hpfs_access(0x%x):\n", hp->h_no)); @@ -800,43 +797,8 @@ hpfs_access(ap) } } - /* Otherwise, user id 0 always gets access. */ - if (cred->cr_uid == 0) - return (0); - - mask = 0; - - /* Otherwise, check the owner. */ - if (cred->cr_uid == hp->h_uid) { - if (mode & VEXEC) - mask |= S_IXUSR; - if (mode & VREAD) - mask |= S_IRUSR; - if (mode & VWRITE) - mask |= S_IWUSR; - return ((hp->h_mode & mask) == mask ? 0 : EACCES); - } - - /* Otherwise, check the groups. */ - for (i = 0, gp = cred->cr_groups; i < cred->cr_ngroups; i++, gp++) - if (hp->h_gid == *gp) { - if (mode & VEXEC) - mask |= S_IXGRP; - if (mode & VREAD) - mask |= S_IRGRP; - if (mode & VWRITE) - mask |= S_IWGRP; - return ((hp->h_mode & mask) == mask ? 0 : EACCES); - } - - /* Otherwise, check everyone else. */ - if (mode & VEXEC) - mask |= S_IXOTH; - if (mode & VREAD) - mask |= S_IROTH; - if (mode & VWRITE) - mask |= S_IWOTH; - return ((hp->h_mode & mask) == mask ? 0 : EACCES); + return (vaccess(vp->v_type, hp->h_mode, hp->h_uid, hp->h_gid, + ap->a_mode, ap->a_cred)); } /* diff --git a/sys/fs/msdosfs/msdosfs_vnops.c b/sys/fs/msdosfs/msdosfs_vnops.c index 10ebaf8..09f99e3 100644 --- a/sys/fs/msdosfs/msdosfs_vnops.c +++ b/sys/fs/msdosfs/msdosfs_vnops.c @@ -252,10 +252,7 @@ msdosfs_access(ap) struct vnode *vp = ap->a_vp; struct denode *dep = VTODE(ap->a_vp); struct msdosfsmount *pmp = dep->de_pmp; - struct ucred *cred = ap->a_cred; - mode_t mask, file_mode, mode = ap->a_mode; - register gid_t *gp; - int i; + mode_t file_mode, mode = ap->a_mode; file_mode = (S_IXUSR|S_IXGRP|S_IXOTH) | (S_IRUSR|S_IRGRP|S_IROTH) | ((dep->de_Attributes & ATTR_READONLY) ? 0 : (S_IWUSR|S_IWGRP|S_IWOTH)); @@ -279,43 +276,8 @@ msdosfs_access(ap) } } - /* User id 0 always gets access. */ - if (cred->cr_uid == 0) - return 0; - - mask = 0; - - /* Otherwise, check the owner. */ - if (cred->cr_uid == pmp->pm_uid) { - if (mode & VEXEC) - mask |= S_IXUSR; - if (mode & VREAD) - mask |= S_IRUSR; - if (mode & VWRITE) - mask |= S_IWUSR; - return (file_mode & mask) == mask ? 0 : EACCES; - } - - /* Otherwise, check the groups. */ - for (i = 0, gp = cred->cr_groups; i < cred->cr_ngroups; i++, gp++) - if (pmp->pm_gid == *gp) { - if (mode & VEXEC) - mask |= S_IXGRP; - if (mode & VREAD) - mask |= S_IRGRP; - if (mode & VWRITE) - mask |= S_IWGRP; - return (file_mode & mask) == mask ? 0 : EACCES; - } - - /* Otherwise, check everyone else. */ - if (mode & VEXEC) - mask |= S_IXOTH; - if (mode & VREAD) - mask |= S_IROTH; - if (mode & VWRITE) - mask |= S_IWOTH; - return (file_mode & mask) == mask ? 0 : EACCES; + return (vaccess(vp->v_type, file_mode, pmp->pm_uid, pmp->pm_gid, + ap->a_mode, ap->a_cred)); } static int diff --git a/sys/fs/ntfs/ntfs_vnops.c b/sys/fs/ntfs/ntfs_vnops.c index e3db31f..06dab1c 100644 --- a/sys/fs/ntfs/ntfs_vnops.c +++ b/sys/fs/ntfs/ntfs_vnops.c @@ -450,10 +450,7 @@ ntfs_access(ap) { struct vnode *vp = ap->a_vp; struct ntnode *ip = VTONT(vp); - struct ucred *cred = ap->a_cred; - mode_t mask, mode = ap->a_mode; - register gid_t *gp; - int i; + mode_t mode = ap->a_mode; #ifdef QUOTA int error; #endif @@ -480,44 +477,9 @@ ntfs_access(ap) } } - /* Otherwise, user id 0 always gets access. */ - if (cred->cr_uid == 0) - return (0); - - mask = 0; - - /* Otherwise, check the owner. */ - if (cred->cr_uid == ip->i_mp->ntm_uid) { - if (mode & VEXEC) - mask |= S_IXUSR; - if (mode & VREAD) - mask |= S_IRUSR; - if (mode & VWRITE) - mask |= S_IWUSR; - return ((ip->i_mp->ntm_mode & mask) == mask ? 0 : EACCES); - } - - /* Otherwise, check the groups. */ - for (i = 0, gp = cred->cr_groups; i < cred->cr_ngroups; i++, gp++) - if (ip->i_mp->ntm_gid == *gp) { - if (mode & VEXEC) - mask |= S_IXGRP; - if (mode & VREAD) - mask |= S_IRGRP; - if (mode & VWRITE) - mask |= S_IWGRP; - return ((ip->i_mp->ntm_mode&mask) == mask ? 0 : EACCES); - } - - /* Otherwise, check everyone else. */ - if (mode & VEXEC) - mask |= S_IXOTH; - if (mode & VREAD) - mask |= S_IROTH; - if (mode & VWRITE) - mask |= S_IWOTH; - return ((ip->i_mp->ntm_mode & mask) == mask ? 0 : EACCES); -} + return (vaccess(vp->v_type, ip->i_mp->ntm_mode, ip->i_mp->ntm_uid, + ip->i_mp->ntm_gid, ap->a_mode, ap->a_cred)); +} /* * Open called. |