-
-/*
- * Check mode permission on inode pointer. Mode is READ, WRITE or EXEC.
- * The mode is shifted to select the owner/group/other fields. The
- * super user is granted all permissions.
- *
- * NB: Called from vnode op table. It seems this could all be done
- * using vattr's but...
- */
-iaccess(ip, mode, cred)
- register struct inode *ip;
- register int mode;
- struct ucred *cred;
-{
- register gid_t *gp;
- int i;
-
- /*
- * If you're the super-user, you always get access.
- */
- if (cred->cr_uid == 0)
- return (0);
- /*
- * Access check is based on only one of owner, group, public.
- * If not owner, then check group. If not a member of the
- * group, then check public access.
- */
- if (cred->cr_uid != ip->i_uid) {
- mode >>= 3;
- gp = cred->cr_groups;
- for (i = 0; i < cred->cr_ngroups; i++, gp++)
- if (ip->i_gid == *gp)
- goto found;
- mode >>= 3;
-found:
- ;
- }
- if ((ip->i_mode & mode) != 0)
- return (0);
- return (EACCES);
-}