#include <sys/types.h>
#include <sys/stat.h>
#include <sys/errno.h>
#include <sys/kmem.h>
#include <sys/t_lock.h>
#include <sys/ksynch.h>
#include <sys/buf.h>
#include <sys/vfs.h>
#include <sys/vnode.h>
#include <sys/mode.h>
#include <sys/systm.h>
#include <vm/seg.h>
#include <sys/file.h>
#include <sys/acl.h>
#include <sys/fs/ufs_inode.h>
#include <sys/fs/ufs_acl.h>
#include <sys/fs/ufs_quota.h>
#include <sys/sysmacros.h>
#include <sys/debug.h>
#include <sys/policy.h>
static int si_signature(si_t *);
static int si_cachei_get(struct inode *, si_t **);
static int si_cachea_get(struct inode *, si_t *, si_t **);
static int si_cmp(si_t *, si_t *);
static void si_cache_put(si_t *);
void si_cache_del(si_t *, int);
void si_cache_init(void);
static void ufs_si_free_mem(si_t *);
static int ufs_si_store(struct inode *, si_t *, int, cred_t *);
static si_t *ufs_acl_cp(si_t *);
static int ufs_sectobuf(si_t *, caddr_t *, size_t *);
static int acl_count(ufs_ic_acl_t *);
static int acl_validate(aclent_t *, int, int);
static int vsecattr2aclentry(vsecattr_t *, si_t **);
static int aclentry2vsecattr(si_t *, vsecattr_t *);
krwlock_t si_cache_lock;
int si_cachecnt = 64;
si_t **si_cachea;
si_t **si_cachei;
long si_cachehit = 0;
long si_cachemiss = 0;
#define SI_HASH(S) ((int)(S) & (si_cachecnt - 1))
static int
ufs_si_store(struct inode *ip, si_t *sp, int puship, cred_t *cr)
{
struct vfs *vfsp;
struct inode *sip;
si_t *oldsp;
si_t *csp;
caddr_t acldata;
ino_t oldshadow;
size_t acldatalen;
off_t offset;
int shadow;
int err;
int refcnt;
int usecnt;
int signature;
int resid;
struct ufsvfs *ufsvfsp = ip->i_ufsvfs;
struct fs *fs = ufsvfsp->vfs_fs;
ASSERT(RW_WRITE_HELD(&ip->i_contents));
ASSERT(ip->i_ufs_acl != sp);
if (!CHECK_ACL_ALLOWED(ip->i_mode & IFMT))
return (ENOSYS);
if (!sp->ausers &&
!sp->agroups &&
!sp->downer &&
!sp->dgroup &&
!sp->dother &&
sp->dclass.acl_ismask == 0 &&
!sp->dusers &&
!sp->dgroups) {
if (ip->i_ufs_acl)
err = ufs_si_free(ip->i_ufs_acl, ITOV(ip)->v_vfsp, cr);
ip->i_ufs_acl = NULL;
ip->i_shadow = 0;
ip->i_flag |= IMOD | IACC;
ip->i_mode = (ip->i_smode & ~0777) |
((sp->aowner->acl_ic_perm & 07) << 6) |
(MASK2MODE(sp)) |
(sp->aother->acl_ic_perm & 07);
TRANS_INODE(ip->i_ufsvfs, ip);
ufs_iupdat(ip, 1);
ufs_si_free_mem(sp);
return (0);
}
loop:
if (si_cachea_get(ip, sp, &csp) == 0) {
ASSERT(RW_WRITE_HELD(&csp->s_lock));
if (ip->i_ufs_acl == csp) {
rw_exit(&csp->s_lock);
(void) ufs_si_free_mem(sp);
return (0);
}
vfsp = ITOV(ip)->v_vfsp;
ASSERT(csp->s_shadow <= INT_MAX);
shadow = (int)csp->s_shadow;
rw_exit(&csp->s_lock);
if ((err = ufs_iget(vfsp, shadow, &sip, cr)) != 0) {
(void) ufs_si_free_mem(sp);
return (EIO);
}
rw_enter(&sip->i_contents, RW_WRITER);
if ((sip->i_mode & IFMT) != IFSHAD || sip->i_nlink <= 0) {
rw_exit(&sip->i_contents);
VN_RELE(ITOV(sip));
goto loop;
}
if (si_cachea_get(ip, sp, &csp) != 0) {
rw_exit(&sip->i_contents);
VN_RELE(ITOV(sip));
goto loop;
}
ASSERT(RW_WRITE_HELD(&csp->s_lock));
if (csp->s_shadow != shadow) {
rw_exit(&csp->s_lock);
rw_exit(&sip->i_contents);
VN_RELE(ITOV(sip));
goto loop;
}
ASSERT(RW_WRITE_HELD(&sip->i_contents));
ASSERT(sip->i_dquot == 0);
ASSERT(sip->i_nlink > 0);
sip->i_nlink++;
TRANS_INODE(ufsvfsp, sip);
csp->s_use = sip->i_nlink;
csp->s_ref++;
ASSERT(sp->s_ref >= 0 && sp->s_ref <= sp->s_use);
sip->i_flag |= ICHG | IMOD;
sip->i_seq++;
ITIMES_NOLOCK(sip);
rw_exit(&csp->s_lock);
rw_exit(&sip->i_contents);
VN_RELE(ITOV(sip));
(void) ufs_si_free_mem(sp);
sp = csp;
si_cachehit++;
goto switchshadows;
}
err = ufs_ialloc(ip, ip->i_number, (mode_t)IFSHAD, &sip, cr);
if (err) {
(void) ufs_si_free_mem(sp);
return (err);
}
rw_enter(&sip->i_contents, RW_WRITER);
sip->i_flag |= IACC | IUPD | ICHG;
sip->i_seq++;
sip->i_mode = (o_mode_t)IFSHAD;
ITOV(sip)->v_type = VREG;
ufs_reset_vnode(ITOV(sip));
sip->i_nlink = 1;
sip->i_uid = crgetuid(cr);
sip->i_suid = (ulong_t)sip->i_uid > (ulong_t)USHRT_MAX ?
UID_LONG : sip->i_uid;
sip->i_gid = crgetgid(cr);
sip->i_sgid = (ulong_t)sip->i_gid > (ulong_t)USHRT_MAX ?
GID_LONG : sip->i_gid;
sip->i_shadow = 0;
TRANS_INODE(ufsvfsp, sip);
sip->i_ufs_acl = NULL;
ASSERT(sip->i_size == 0);
sp->s_shadow = sip->i_number;
if ((err = ufs_sectobuf(sp, &acldata, &acldatalen)) != 0)
goto errout;
offset = 0;
resid = 0;
if (((err = ufs_rdwri(UIO_WRITE, FWRITE|FSYNC, sip, acldata,
acldatalen, (offset_t)0, UIO_SYSSPACE, &resid, cr)) != 0) ||
(resid != 0)) {
kmem_free(acldata, acldatalen);
if ((resid != 0) && (err == 0))
err = ENOSPC;
goto errout;
}
offset += acldatalen;
if ((acldatalen + fs->fs_bsize) > ufsvfsp->vfs_maxacl)
ufsvfsp->vfs_maxacl = acldatalen + fs->fs_bsize;
kmem_free(acldata, acldatalen);
ufs_iupdat(sip, 1);
rw_exit(&sip->i_contents);
VN_RELE(ITOV(sip));
sp->s_use = 1;
sp->s_ref = 1;
si_cache_put(sp);
si_cachemiss++;
switchshadows:
ASSERT(RW_WRITE_HELD(&ip->i_contents));
rw_enter(&sp->s_lock, RW_READER);
oldsp = ip->i_ufs_acl;
oldshadow = ip->i_shadow;
ip->i_ufs_acl = sp;
ASSERT(sp->s_shadow <= INT_MAX);
ip->i_shadow = (int32_t)sp->s_shadow;
ASSERT(oldsp != sp);
ASSERT(oldshadow != ip->i_number);
ASSERT(ip->i_number != ip->i_shadow);
if (sp->aowner) {
ip->i_mode &= ~0700;
ip->i_mode |= (sp->aowner->acl_ic_perm & 07) << 6;
ip->i_uid = sp->aowner->acl_ic_who;
}
if (sp->agroup) {
ip->i_mode &= ~0070;
ip->i_mode |= MASK2MODE(sp);
ip->i_gid = sp->agroup->acl_ic_who;
}
if (sp->aother) {
ip->i_mode &= ~0007;
ip->i_mode |= (sp->aother->acl_ic_perm & 07);
}
if (sp->aclass.acl_ismask)
ip->i_mode = (ip->i_mode & ~070) |
(((sp->aclass.acl_maskbits & 07) << 3) &
ip->i_mode);
TRANS_INODE(ufsvfsp, ip);
rw_exit(&sp->s_lock);
ip->i_flag |= ICHG;
ip->i_seq++;
if (puship == 1)
ufs_iupdat(ip, 1);
if (oldshadow) {
ASSERT(RW_WRITE_HELD(&ip->i_contents));
vfsp = ITOV(ip)->v_vfsp;
if ((err = ufs_iget_alloced(vfsp, oldshadow, &sip, cr)) != 0) {
return (EIO);
}
rw_enter(&sip->i_contents, RW_WRITER);
if (oldsp)
rw_enter(&oldsp->s_lock, RW_WRITER);
ASSERT(sip->i_dquot == 0);
ASSERT(sip->i_nlink > 0);
usecnt = --sip->i_nlink;
ufs_setreclaim(sip);
TRANS_INODE(ufsvfsp, sip);
sip->i_flag |= ICHG | IMOD;
sip->i_seq++;
ITIMES_NOLOCK(sip);
if (oldsp) {
oldsp->s_use = usecnt;
refcnt = --oldsp->s_ref;
signature = oldsp->s_signature;
rw_exit(&oldsp->s_lock);
}
rw_exit(&sip->i_contents);
VN_RELE(ITOV(sip));
if (oldsp && (refcnt == 0))
si_cache_del(oldsp, signature);
}
return (0);
errout:
sip->i_nlink = 0;
ufs_setreclaim(sip);
TRANS_INODE(ufsvfsp, sip);
ITIMES_NOLOCK(sip);
rw_exit(&sip->i_contents);
VN_RELE(ITOV(sip));
ASSERT(!sp->s_use && !sp->s_ref && !(sp->s_flags & SI_CACHED));
(void) ufs_si_free_mem(sp);
return (err);
}
int
ufs_si_load(struct inode *ip, cred_t *cr)
{
struct vfs *vfsp;
struct inode *sip;
ufs_fsd_t *fsdp;
si_t *sp;
vsecattr_t vsecattr = { 0, 0, NULL, 0, NULL};
aclent_t *aclp;
ufs_acl_t *ufsaclp;
caddr_t acldata = NULL;
ino_t maxino;
int err;
size_t acldatalen;
int numacls;
int shadow;
int usecnt;
struct ufsvfs *ufsvfsp = ip->i_ufsvfs;
struct fs *fs = ufsvfsp->vfs_fs;
ASSERT(ip != NULL);
ASSERT(RW_WRITE_HELD(&ip->i_contents));
ASSERT(ip->i_shadow && ip->i_ufs_acl == NULL);
ASSERT((ip->i_mode & IFMT) != IFSHAD);
if (!CHECK_ACL_ALLOWED(ip->i_mode & IFMT))
return (ENOSYS);
if (ip->i_shadow == ip->i_number)
return (EIO);
maxino = (ino_t)(ITOF(ip)->fs_ncg * ITOF(ip)->fs_ipg);
if (ip->i_shadow < UFSROOTINO || ip->i_shadow > maxino)
return (EIO);
if (si_cachei_get(ip, &sp) == 0) {
ASSERT(RW_WRITE_HELD(&sp->s_lock));
ip->i_ufs_acl = sp;
sp->s_ref++;
ASSERT(sp->s_ref >= 0 && sp->s_ref <= sp->s_use);
rw_exit(&sp->s_lock);
si_cachehit++;
return (0);
}
vfsp = ITOV(ip)->v_vfsp;
shadow = ip->i_shadow;
if ((err = ufs_iget_alloced(vfsp, shadow, &sip, cr)) != 0) {
return (err);
}
rw_enter(&sip->i_contents, RW_WRITER);
if ((sip->i_mode & IFMT) != IFSHAD) {
rw_exit(&sip->i_contents);
err = EINVAL;
goto alldone;
}
ASSERT(sip->i_dquot == 0);
usecnt = sip->i_nlink;
if ((!ULOCKFS_IS_NOIACC(&ufsvfsp->vfs_ulockfs)) &&
(!(sip)->i_ufsvfs->vfs_noatime)) {
sip->i_flag |= IACC;
}
rw_downgrade(&sip->i_contents);
ASSERT(sip->i_size <= MAXOFF_T);
acldata = kmem_zalloc((size_t)sip->i_size, KM_SLEEP);
acldatalen = sip->i_size;
err = ufs_rdwri(UIO_READ, FREAD, sip, acldata, acldatalen, (offset_t)0,
UIO_SYSSPACE, (int *)0, cr);
rw_exit(&sip->i_contents);
if (err)
goto alldone;
bzero((caddr_t)&vsecattr, sizeof (vsecattr_t));
for (fsdp = (ufs_fsd_t *)acldata;
fsdp < (ufs_fsd_t *)(acldata + acldatalen);
fsdp = (ufs_fsd_t *)((caddr_t)fsdp +
FSD_RECSZ(fsdp, fsdp->fsd_size))) {
if (fsdp->fsd_size <= 0)
break;
switch (fsdp->fsd_type) {
case FSD_ACL:
numacls = vsecattr.vsa_aclcnt =
(int)((fsdp->fsd_size -
2 * sizeof (int)) / sizeof (ufs_acl_t));
aclp = vsecattr.vsa_aclentp =
kmem_zalloc(numacls * sizeof (aclent_t), KM_SLEEP);
for (ufsaclp = (ufs_acl_t *)fsdp->fsd_data;
numacls; ufsaclp++) {
aclp->a_type = ufsaclp->acl_tag;
aclp->a_id = ufsaclp->acl_who;
aclp->a_perm = ufsaclp->acl_perm;
aclp++;
numacls--;
}
break;
case FSD_DFACL:
numacls = vsecattr.vsa_dfaclcnt =
(int)((fsdp->fsd_size -
2 * sizeof (int)) / sizeof (ufs_acl_t));
aclp = vsecattr.vsa_dfaclentp =
kmem_zalloc(numacls * sizeof (aclent_t), KM_SLEEP);
for (ufsaclp = (ufs_acl_t *)fsdp->fsd_data;
numacls; ufsaclp++) {
aclp->a_type = ufsaclp->acl_tag;
aclp->a_id = ufsaclp->acl_who;
aclp->a_perm = ufsaclp->acl_perm;
aclp++;
numacls--;
}
break;
}
}
if (vsecattr.vsa_aclentp) {
ksort((caddr_t)vsecattr.vsa_aclentp, vsecattr.vsa_aclcnt,
sizeof (aclent_t), cmp2acls);
if ((err = acl_validate(vsecattr.vsa_aclentp,
vsecattr.vsa_aclcnt, ACL_CHECK)) != 0) {
goto alldone;
}
}
if (vsecattr.vsa_dfaclentp) {
ksort((caddr_t)vsecattr.vsa_dfaclentp, vsecattr.vsa_dfaclcnt,
sizeof (aclent_t), cmp2acls);
if ((err = acl_validate(vsecattr.vsa_dfaclentp,
vsecattr.vsa_dfaclcnt, DEF_ACL_CHECK)) != 0) {
goto alldone;
}
}
if (!vsecattr.vsa_aclentp && !vsecattr.vsa_dfaclentp) {
err = 0;
goto alldone;
}
if ((err = vsecattr2aclentry(&vsecattr, &sp)) != 0) {
goto alldone;
}
sp->s_shadow = ip->i_shadow;
sp->s_dev = ip->i_dev;
sp->s_use = usecnt;
sp->s_ref = 1;
ASSERT(sp->s_ref >= 0 && sp->s_ref <= sp->s_use);
si_cache_put(sp);
ip->i_ufs_acl = sp;
err = 0;
si_cachemiss++;
if ((acldatalen + fs->fs_bsize) > ufsvfsp->vfs_maxacl)
ufsvfsp->vfs_maxacl = acldatalen + fs->fs_bsize;
alldone:
if (err) {
rw_enter(&sip->i_contents, RW_READER);
mutex_enter(&sip->i_tlock);
sip->i_flag |= ISTALE;
mutex_exit(&sip->i_tlock);
rw_exit(&sip->i_contents);
}
VN_RELE(ITOV(sip));
if (acldata)
kmem_free(acldata, acldatalen);
if (vsecattr.vsa_aclentp)
kmem_free(vsecattr.vsa_aclentp,
vsecattr.vsa_aclcnt * sizeof (aclent_t));
if (vsecattr.vsa_dfaclentp)
kmem_free(vsecattr.vsa_dfaclentp,
vsecattr.vsa_dfaclcnt * sizeof (aclent_t));
return (err);
}
int
ufs_acl_access(struct inode *ip, int mode, cred_t *cr)
{
ufs_ic_acl_t *acl;
int ismask, mask = 0;
int gperm = 0;
int ngroup = 0;
si_t *sp = NULL;
uid_t uid = crgetuid(cr);
uid_t owner;
ASSERT(ip->i_ufs_acl != NULL);
ASSERT(RW_LOCK_HELD(&ip->i_contents));
sp = ip->i_ufs_acl;
ismask = sp->aclass.acl_ismask ?
sp->aclass.acl_ismask : 0;
if (ismask)
mask = sp->aclass.acl_maskbits;
else
mask = -1;
owner = sp->aowner->acl_ic_who;
if (uid == owner) {
return (MODE_CHECK(owner, mode, (sp->aowner->acl_ic_perm << 6),
cr, ip));
}
if (sp->ausers)
for (acl = sp->ausers; acl != NULL; acl = acl->acl_ic_next) {
if (acl->acl_ic_who == uid) {
return (MODE_CHECK(owner, mode,
(mask & acl->acl_ic_perm) << 6, cr, ip));
}
}
if (groupmember((uid_t)sp->agroup->acl_ic_who, cr)) {
ngroup++;
gperm = (sp->agroup->acl_ic_perm);
if (!ismask)
return (MODE_CHECK(owner, mode, (gperm << 6), cr, ip));
}
if (sp->agroups)
for (acl = sp->agroups; acl != NULL; acl = acl->acl_ic_next) {
if (groupmember(acl->acl_ic_who, cr)) {
ngroup++;
gperm |= acl->acl_ic_perm;
}
}
if (ngroup != 0)
return (MODE_CHECK(owner, mode, ((gperm & mask) << 6), cr, ip));
return (MODE_CHECK(owner, mode, sp->aother->acl_ic_perm << 6, cr, ip));
}
int
ufs_acl_get(struct inode *ip, vsecattr_t *vsap, int flag, cred_t *cr)
{
aclent_t *aclentp;
ASSERT(RW_LOCK_HELD(&ip->i_contents));
if (ip->i_ufs_acl)
return (aclentry2vsecattr(ip->i_ufs_acl, vsap));
vsap->vsa_aclcnt = 0;
vsap->vsa_aclentp = NULL;
vsap->vsa_dfaclcnt = 0;
vsap->vsa_dfaclentp = NULL;
if (vsap->vsa_mask & (VSA_ACLCNT | VSA_ACL))
vsap->vsa_aclcnt = 4;
if (vsap->vsa_mask & VSA_ACL) {
vsap->vsa_aclentp = kmem_zalloc(4 * sizeof (aclent_t),
KM_SLEEP);
if (vsap->vsa_aclentp == NULL)
return (ENOMEM);
aclentp = vsap->vsa_aclentp;
aclentp->a_type = USER_OBJ;
aclentp->a_perm = ((ushort_t)(ip->i_mode & 0700)) >> 6;
aclentp->a_id = ip->i_uid;
aclentp++;
aclentp->a_type = GROUP_OBJ;
aclentp->a_perm = ((ushort_t)(ip->i_mode & 0070)) >> 3;
aclentp->a_id = ip->i_gid;
aclentp++;
aclentp->a_type = OTHER_OBJ;
aclentp->a_perm = ip->i_mode & 0007;
aclentp->a_id = 0;
aclentp++;
aclentp->a_type = CLASS_OBJ;
aclentp->a_perm = ((ushort_t)(ip->i_mode & 0070)) >> 3;
aclentp->a_id = 0;
ksort((caddr_t)vsap->vsa_aclentp, vsap->vsa_aclcnt,
sizeof (aclent_t), cmp2acls);
}
return (0);
}
int
ufs_acl_set(struct inode *ip, vsecattr_t *vsap, int flag, cred_t *cr)
{
si_t *sp;
int err;
ASSERT(RW_WRITE_HELD(&ip->i_contents));
if (!CHECK_ACL_ALLOWED(ip->i_mode & IFMT))
return (ENOSYS);
if (secpolicy_vnode_setdac(cr, ip->i_uid) != 0)
return (EPERM);
if ((err = vsecattr2aclentry(vsap, &sp)) != 0)
return (err);
sp->s_dev = ip->i_dev;
#ifdef DEBUG
if (vsap->vsa_mask == VSA_ACL) {
ASSERT(sp->aowner);
ASSERT(sp->agroup);
ASSERT(sp->aother);
}
#endif
if (sp->aowner)
sp->aowner->acl_ic_who = ip->i_uid;
if (sp->agroup)
sp->agroup->acl_ic_who = ip->i_gid;
err = ufs_si_store(ip, sp, 1, cr);
return (err);
}
static int
acl_validate(aclent_t *aclentp, int nentries, int flag)
{
int i;
int nuser_objs = 0;
int ngroup_objs = 0;
int nother_objs = 0;
int nclass_objs = 0;
int ndef_user_objs = 0;
int ndef_group_objs = 0;
int ndef_other_objs = 0;
int ndef_class_objs = 0;
int nusers = 0;
int ngroups = 0;
int ndef_users = 0;
int ndef_groups = 0;
int numdefs = 0;
if (aclentp == NULL)
return (0);
if (nentries <= 0)
return (EINVAL);
for (i = 1; i < nentries; i++) {
if (((aclentp[i - 1].a_type == aclentp[i].a_type) &&
(aclentp[i - 1].a_id == aclentp[i].a_id)) ||
(aclentp[i - 1].a_perm > 07)) {
return (EINVAL);
}
}
if (flag == 0 || (flag != ACL_CHECK && flag != DEF_ACL_CHECK))
return (EINVAL);
for (i = 0; i < nentries; i++) {
switch (aclentp[i].a_type) {
case USER_OBJ:
nuser_objs++;
break;
case GROUP_OBJ:
ngroup_objs++;
break;
case OTHER_OBJ:
nother_objs++;
break;
case CLASS_OBJ:
nclass_objs++;
break;
case DEF_USER_OBJ:
ndef_user_objs++;
break;
case DEF_GROUP_OBJ:
ndef_group_objs++;
break;
case DEF_OTHER_OBJ:
ndef_other_objs++;
break;
case DEF_CLASS_OBJ:
ndef_class_objs++;
break;
case USER:
nusers++;
break;
case GROUP:
ngroups++;
break;
case DEF_USER:
ndef_users++;
break;
case DEF_GROUP:
ndef_groups++;
break;
default:
return (EINVAL);
}
}
if (flag & ACL_CHECK) {
if (nuser_objs != 1 || ngroup_objs != 1 ||
nother_objs != 1 || nclass_objs > 1) {
return (EINVAL);
}
if (ngroups && !nclass_objs) {
return (EINVAL);
}
if (nuser_objs + ngroup_objs + nother_objs + nclass_objs +
ngroups + nusers > MAX_ACL_ENTRIES)
return (EINVAL);
}
if (flag & DEF_ACL_CHECK) {
if (ndef_other_objs > 1 || ndef_user_objs > 1 ||
ndef_group_objs > 1 || ndef_class_objs > 1) {
return (EINVAL);
}
numdefs = ndef_other_objs + ndef_user_objs + ndef_group_objs;
if (numdefs != 0 && numdefs != 3) {
return (EINVAL);
}
if (ndef_groups && !ndef_class_objs) {
return (EINVAL);
}
if ((ndef_users || ndef_groups) &&
((numdefs != 3) && !ndef_class_objs)) {
return (EINVAL);
}
if (ndef_user_objs + ndef_group_objs + ndef_other_objs +
ndef_class_objs + ndef_users + ndef_groups >
MAX_ACL_ENTRIES)
return (EINVAL);
}
return (0);
}
static int
formacl(ufs_ic_acl_t **aclpp, aclent_t *aclentp)
{
ufs_ic_acl_t *uaclp;
uaclp = kmem_alloc(sizeof (ufs_ic_acl_t), KM_SLEEP);
uaclp->acl_ic_perm = aclentp->a_perm;
uaclp->acl_ic_who = aclentp->a_id;
uaclp->acl_ic_next = *aclpp;
*aclpp = uaclp;
return (0);
}
static int
vsecattr2aclentry(vsecattr_t *vsap, si_t **spp)
{
aclent_t *aclentp, *aclp;
si_t *sp;
int err;
int i;
ksort((caddr_t)vsap->vsa_aclentp, vsap->vsa_aclcnt,
sizeof (aclent_t), cmp2acls);
ksort((caddr_t)vsap->vsa_dfaclentp, vsap->vsa_dfaclcnt,
sizeof (aclent_t), cmp2acls);
if ((err = acl_validate(vsap->vsa_aclentp,
vsap->vsa_aclcnt, ACL_CHECK)) != 0)
return (err);
if ((err = acl_validate(vsap->vsa_dfaclentp,
vsap->vsa_dfaclcnt, DEF_ACL_CHECK)) != 0)
return (err);
sp = kmem_zalloc(sizeof (si_t), KM_SLEEP);
rw_init(&sp->s_lock, NULL, RW_DEFAULT, NULL);
aclp = (aclent_t *)vsap->vsa_aclentp;
aclentp = aclp + vsap->vsa_aclcnt - 1;
for (i = 0; i < vsap->vsa_aclcnt; i++) {
switch (aclentp->a_type) {
case USER_OBJ:
if (err = formacl(&sp->aowner, aclentp))
goto error;
break;
case GROUP_OBJ:
if (err = formacl(&sp->agroup, aclentp))
goto error;
break;
case OTHER_OBJ:
if (err = formacl(&sp->aother, aclentp))
goto error;
break;
case USER:
if (err = formacl(&sp->ausers, aclentp))
goto error;
break;
case CLASS_OBJ:
sp->aclass.acl_ismask = 1;
sp->aclass.acl_maskbits = aclentp->a_perm;
break;
case GROUP:
if (err = formacl(&sp->agroups, aclentp))
goto error;
break;
default:
break;
}
aclentp--;
}
aclp = (aclent_t *)vsap->vsa_dfaclentp;
aclentp = aclp + vsap->vsa_dfaclcnt - 1;
for (i = 0; i < vsap->vsa_dfaclcnt; i++) {
switch (aclentp->a_type) {
case DEF_USER_OBJ:
if (err = formacl(&sp->downer, aclentp))
goto error;
break;
case DEF_GROUP_OBJ:
if (err = formacl(&sp->dgroup, aclentp))
goto error;
break;
case DEF_OTHER_OBJ:
if (err = formacl(&sp->dother, aclentp))
goto error;
break;
case DEF_USER:
if (err = formacl(&sp->dusers, aclentp))
goto error;
break;
case DEF_CLASS_OBJ:
sp->dclass.acl_ismask = 1;
sp->dclass.acl_maskbits = aclentp->a_perm;
break;
case DEF_GROUP:
if (err = formacl(&sp->dgroups, aclentp))
goto error;
break;
default:
break;
}
aclentp--;
}
*spp = sp;
return (0);
error:
ufs_si_free_mem(sp);
return (err);
}
void
formvsec(int obj_type, ufs_ic_acl_t *aclp, aclent_t **aclentpp)
{
for (; aclp; aclp = aclp->acl_ic_next) {
(*aclentpp)->a_type = obj_type;
(*aclentpp)->a_perm = aclp->acl_ic_perm;
(*aclentpp)->a_id = aclp->acl_ic_who;
(*aclentpp)++;
}
}
static int
aclentry2vsecattr(si_t *sp, vsecattr_t *vsap)
{
aclent_t *aclentp;
int numacls = 0;
int err;
vsap->vsa_aclentp = vsap->vsa_dfaclentp = NULL;
numacls = acl_count(sp->aowner) +
acl_count(sp->agroup) +
acl_count(sp->aother) +
acl_count(sp->ausers) +
acl_count(sp->agroups);
if (sp->aclass.acl_ismask)
numacls++;
if (vsap->vsa_mask & (VSA_ACLCNT | VSA_ACL))
vsap->vsa_aclcnt = numacls;
if (numacls == 0)
goto do_defaults;
if (vsap->vsa_mask & VSA_ACL) {
vsap->vsa_aclentp = kmem_zalloc(numacls * sizeof (aclent_t),
KM_SLEEP);
aclentp = vsap->vsa_aclentp;
formvsec(USER_OBJ, sp->aowner, &aclentp);
formvsec(USER, sp->ausers, &aclentp);
formvsec(GROUP_OBJ, sp->agroup, &aclentp);
formvsec(GROUP, sp->agroups, &aclentp);
formvsec(OTHER_OBJ, sp->aother, &aclentp);
if (sp->aclass.acl_ismask) {
aclentp->a_type = CLASS_OBJ;
aclentp->a_perm = sp->aclass.acl_maskbits;
aclentp->a_id = 0;
aclentp++;
}
ksort((caddr_t)vsap->vsa_aclentp, vsap->vsa_aclcnt,
sizeof (aclent_t), cmp2acls);
if ((err = acl_validate(vsap->vsa_aclentp,
vsap->vsa_aclcnt, ACL_CHECK)) != 0) {
kmem_free(vsap->vsa_aclentp,
numacls * sizeof (aclent_t));
vsap->vsa_aclentp = NULL;
return (err);
}
}
do_defaults:
numacls = acl_count(sp->downer) +
acl_count(sp->dgroup) +
acl_count(sp->dother) +
acl_count(sp->dusers) +
acl_count(sp->dgroups);
if (sp->dclass.acl_ismask)
numacls++;
if (vsap->vsa_mask & (VSA_DFACLCNT | VSA_DFACL))
vsap->vsa_dfaclcnt = numacls;
if (numacls == 0)
goto do_others;
if (vsap->vsa_mask & VSA_DFACL) {
vsap->vsa_dfaclentp =
kmem_zalloc(numacls * sizeof (aclent_t), KM_SLEEP);
aclentp = vsap->vsa_dfaclentp;
formvsec(DEF_USER_OBJ, sp->downer, &aclentp);
formvsec(DEF_USER, sp->dusers, &aclentp);
formvsec(DEF_GROUP_OBJ, sp->dgroup, &aclentp);
formvsec(DEF_GROUP, sp->dgroups, &aclentp);
formvsec(DEF_OTHER_OBJ, sp->dother, &aclentp);
if (sp->dclass.acl_ismask) {
aclentp->a_type = DEF_CLASS_OBJ;
aclentp->a_perm = sp->dclass.acl_maskbits;
aclentp->a_id = 0;
aclentp++;
}
ksort((caddr_t)vsap->vsa_dfaclentp, vsap->vsa_dfaclcnt,
sizeof (aclent_t), cmp2acls);
if ((err = acl_validate(vsap->vsa_dfaclentp,
vsap->vsa_dfaclcnt, DEF_ACL_CHECK)) != 0) {
if (vsap->vsa_aclentp != NULL)
kmem_free(vsap->vsa_aclentp,
vsap->vsa_aclcnt * sizeof (aclent_t));
kmem_free(vsap->vsa_dfaclentp,
vsap->vsa_dfaclcnt * sizeof (aclent_t));
vsap->vsa_aclentp = vsap->vsa_dfaclentp = NULL;
return (err);
}
}
do_others:
return (0);
}
static void
acl_free(ufs_ic_acl_t *aclp)
{
while (aclp != NULL) {
ufs_ic_acl_t *nextaclp = aclp->acl_ic_next;
kmem_free(aclp, sizeof (ufs_ic_acl_t));
aclp = nextaclp;
}
}
static void
ufs_si_free_mem(si_t *sp)
{
ASSERT(!(sp->s_flags & SI_CACHED));
ASSERT(!RW_LOCK_HELD(&sp->s_lock));
acl_free(sp->aowner);
acl_free(sp->agroup);
acl_free(sp->aother);
acl_free(sp->ausers);
acl_free(sp->agroups);
acl_free(sp->downer);
acl_free(sp->dgroup);
acl_free(sp->dother);
acl_free(sp->dusers);
acl_free(sp->dgroups);
rw_destroy(&sp->s_lock);
kmem_free(sp, sizeof (si_t));
}
void
acl_cpy(ufs_ic_acl_t *saclp, ufs_ic_acl_t *daclp)
{
ufs_ic_acl_t *aclp, *prev_aclp = NULL, *aclp1;
if (saclp == NULL) {
daclp = NULL;
return;
}
prev_aclp = daclp;
for (aclp = saclp; aclp != NULL; aclp = aclp->acl_ic_next) {
aclp1 = kmem_alloc(sizeof (ufs_ic_acl_t), KM_SLEEP);
aclp1->acl_ic_next = NULL;
aclp1->acl_ic_who = aclp->acl_ic_who;
aclp1->acl_ic_perm = aclp->acl_ic_perm;
prev_aclp->acl_ic_next = aclp1;
prev_aclp = (ufs_ic_acl_t *)&aclp1->acl_ic_next;
}
}
int
ufs_si_inherit(struct inode *ip, struct inode *tdp, o_mode_t mode, cred_t *cr)
{
si_t *tsp, *sp = tdp->i_ufs_acl;
int error;
o_mode_t old_modes, old_uid, old_gid;
int mask;
ASSERT(RW_WRITE_HELD(&ip->i_contents));
ASSERT(RW_WRITE_HELD(&tdp->i_rwlock));
ASSERT(RW_WRITE_HELD(&tdp->i_contents));
if (!CHECK_ACL_ALLOWED(ip->i_mode & IFMT))
return (0);
rw_enter(&sp->s_lock, RW_READER);
ASSERT(((tdp->i_mode & IFMT) == IFDIR) ||
((tdp->i_mode & IFMT) == IFATTRDIR));
mask = ((sp->downer != NULL) ? 1 : 0) |
((sp->dgroup != NULL) ? 2 : 0) |
((sp->dother != NULL) ? 4 : 0);
if (mask == 0) {
rw_exit(&sp->s_lock);
return (0);
}
if (mask != 7) {
rw_exit(&sp->s_lock);
return (EINVAL);
}
tsp = kmem_zalloc(sizeof (si_t), KM_SLEEP);
rw_init(&tsp->s_lock, NULL, RW_DEFAULT, NULL);
ASSERT(RW_READ_HELD(&sp->s_lock));
acl_cpy(sp->downer, (ufs_ic_acl_t *)&tsp->aowner);
acl_cpy(sp->dgroup, (ufs_ic_acl_t *)&tsp->agroup);
acl_cpy(sp->dother, (ufs_ic_acl_t *)&tsp->aother);
acl_cpy(sp->dusers, (ufs_ic_acl_t *)&tsp->ausers);
acl_cpy(sp->dgroups, (ufs_ic_acl_t *)&tsp->agroups);
tsp->aclass.acl_ismask = sp->dclass.acl_ismask;
tsp->aclass.acl_maskbits = sp->dclass.acl_maskbits;
MODE2ACL(tsp->aowner, (mode >> 6), ip->i_uid);
MODE2ACL(tsp->agroup, (mode >> 3), ip->i_gid);
MODE2ACL(tsp->aother, (mode), 0);
if (tsp->aclass.acl_ismask) {
tsp->aclass.acl_maskbits &= mode >> 3;
}
if (((ip->i_mode & IFMT) == IFDIR) ||
((ip->i_mode & IFMT) == IFATTRDIR)) {
acl_cpy(sp->downer, (ufs_ic_acl_t *)&tsp->downer);
acl_cpy(sp->dgroup, (ufs_ic_acl_t *)&tsp->dgroup);
acl_cpy(sp->dother, (ufs_ic_acl_t *)&tsp->dother);
acl_cpy(sp->dusers, (ufs_ic_acl_t *)&tsp->dusers);
acl_cpy(sp->dgroups, (ufs_ic_acl_t *)&tsp->dgroups);
tsp->dclass.acl_ismask = sp->dclass.acl_ismask;
tsp->dclass.acl_maskbits = sp->dclass.acl_maskbits;
}
old_modes = ip->i_mode;
old_uid = ip->i_uid;
old_gid = ip->i_gid;
rw_exit(&sp->s_lock);
rw_enter(&ip->i_rwlock, RW_WRITER);
ip->i_flag |= tdp->i_flag & IQUIET;
if ((error = ufs_si_store(ip, tsp, 0, cr)) != 0) {
ip->i_mode = old_modes;
ip->i_uid = old_uid;
ip->i_gid = old_gid;
}
ip->i_flag &= ~IQUIET;
rw_exit(&ip->i_rwlock);
return (error);
}
si_t *
ufs_acl_cp(si_t *sp)
{
si_t *dsp;
ASSERT(RW_READ_HELD(&sp->s_lock));
ASSERT(sp->s_ref && sp->s_use);
dsp = kmem_zalloc(sizeof (si_t), KM_SLEEP);
rw_init(&dsp->s_lock, NULL, RW_DEFAULT, NULL);
acl_cpy(sp->aowner, (ufs_ic_acl_t *)&dsp->aowner);
acl_cpy(sp->agroup, (ufs_ic_acl_t *)&dsp->agroup);
acl_cpy(sp->aother, (ufs_ic_acl_t *)&dsp->aother);
acl_cpy(sp->ausers, (ufs_ic_acl_t *)&dsp->ausers);
acl_cpy(sp->agroups, (ufs_ic_acl_t *)&dsp->agroups);
dsp->aclass.acl_ismask = sp->aclass.acl_ismask;
dsp->aclass.acl_maskbits = sp->aclass.acl_maskbits;
acl_cpy(sp->downer, (ufs_ic_acl_t *)&dsp->downer);
acl_cpy(sp->dgroup, (ufs_ic_acl_t *)&dsp->dgroup);
acl_cpy(sp->dother, (ufs_ic_acl_t *)&dsp->dother);
acl_cpy(sp->dusers, (ufs_ic_acl_t *)&dsp->dusers);
acl_cpy(sp->dgroups, (ufs_ic_acl_t *)&dsp->dgroups);
dsp->dclass.acl_ismask = sp->dclass.acl_ismask;
dsp->dclass.acl_maskbits = sp->dclass.acl_maskbits;
return (dsp);
}
int
ufs_acl_setattr(struct inode *ip, struct vattr *vap, cred_t *cr)
{
si_t *sp;
int mask = vap->va_mask;
int error = 0;
ASSERT(RW_WRITE_HELD(&ip->i_contents));
if (!(mask & (AT_MODE|AT_UID|AT_GID)))
return (0);
if (!(ip->i_ufs_acl) || !(ip->i_ufs_acl->aowner))
return (0);
rw_enter(&ip->i_ufs_acl->s_lock, RW_READER);
sp = ufs_acl_cp(ip->i_ufs_acl);
ASSERT(sp != ip->i_ufs_acl);
if (mask & AT_MODE) {
sp->aowner->acl_ic_perm = (o_mode_t)(ip->i_mode & 0700) >> 6;
if (sp->aclass.acl_ismask)
sp->aclass.acl_maskbits =
(o_mode_t)(ip->i_mode & 070) >> 3;
else
sp->agroup->acl_ic_perm =
(o_mode_t)(ip->i_mode & 070) >> 3;
sp->aother->acl_ic_perm = (o_mode_t)(ip->i_mode & 07);
}
if (mask & AT_UID) {
sp->aowner->acl_ic_who = ip->i_uid;
}
if (mask & AT_GID) {
sp->agroup->acl_ic_who = ip->i_gid;
}
rw_exit(&ip->i_ufs_acl->s_lock);
error = ufs_si_store(ip, sp, 0, cr);
return (error);
}
static int
acl_count(ufs_ic_acl_t *p)
{
ufs_ic_acl_t *acl;
int count;
for (count = 0, acl = p; acl; acl = acl->acl_ic_next, count++)
;
return (count);
}
static int
ufs_sectobuf(si_t *sp, caddr_t *buf, size_t *len)
{
size_t acl_size;
size_t def_acl_size;
caddr_t buffer;
struct ufs_fsd *fsdp;
ufs_acl_t *bufaclp;
acl_size = acl_count(sp->aowner) +
acl_count(sp->agroup) +
acl_count(sp->aother) +
acl_count(sp->ausers) +
acl_count(sp->agroups);
if (sp->aclass.acl_ismask)
acl_size++;
acl_size *= sizeof (ufs_acl_t);
if (acl_size)
acl_size += 2 * sizeof (int);
def_acl_size =
acl_count(sp->downer) +
acl_count(sp->dgroup) +
acl_count(sp->dother) +
acl_count(sp->dusers) +
acl_count(sp->dgroups);
if (sp->dclass.acl_ismask)
def_acl_size++;
def_acl_size *= sizeof (ufs_acl_t);
if (def_acl_size)
def_acl_size += 2 * sizeof (int);
if (acl_size + def_acl_size == 0)
return (0);
buffer = kmem_zalloc((acl_size + def_acl_size), KM_SLEEP);
bufaclp = (ufs_acl_t *)buffer;
if (acl_size == 0)
goto wrtdefs;
fsdp = (struct ufs_fsd *)bufaclp;
fsdp->fsd_type = FSD_ACL;
bufaclp = (ufs_acl_t *)&fsdp->fsd_data[0];
ACL_MOVE(sp->aowner, USER_OBJ, bufaclp);
ACL_MOVE(sp->agroup, GROUP_OBJ, bufaclp);
ACL_MOVE(sp->aother, OTHER_OBJ, bufaclp);
ACL_MOVE(sp->ausers, USER, bufaclp);
ACL_MOVE(sp->agroups, GROUP, bufaclp);
if (sp->aclass.acl_ismask) {
bufaclp->acl_tag = CLASS_OBJ;
bufaclp->acl_who = (uid_t)sp->aclass.acl_ismask;
bufaclp->acl_perm = (o_mode_t)sp->aclass.acl_maskbits;
bufaclp++;
}
ASSERT(acl_size <= INT_MAX);
fsdp->fsd_size = (int)acl_size;
wrtdefs:
if (def_acl_size == 0)
goto alldone;
fsdp = (struct ufs_fsd *)bufaclp;
fsdp->fsd_type = FSD_DFACL;
bufaclp = (ufs_acl_t *)&fsdp->fsd_data[0];
ACL_MOVE(sp->downer, DEF_USER_OBJ, bufaclp);
ACL_MOVE(sp->dgroup, DEF_GROUP_OBJ, bufaclp);
ACL_MOVE(sp->dother, DEF_OTHER_OBJ, bufaclp);
ACL_MOVE(sp->dusers, DEF_USER, bufaclp);
ACL_MOVE(sp->dgroups, DEF_GROUP, bufaclp);
if (sp->dclass.acl_ismask) {
bufaclp->acl_tag = DEF_CLASS_OBJ;
bufaclp->acl_who = (uid_t)sp->dclass.acl_ismask;
bufaclp->acl_perm = (o_mode_t)sp->dclass.acl_maskbits;
bufaclp++;
}
ASSERT(def_acl_size <= INT_MAX);
fsdp->fsd_size = (int)def_acl_size;
alldone:
*buf = buffer;
*len = acl_size + def_acl_size;
return (0);
}
int
ufs_si_free(si_t *sp, struct vfs *vfsp, cred_t *cr)
{
struct inode *sip;
int shadow;
int err = 0;
int refcnt;
int signature;
ASSERT(vfsp);
ASSERT(sp);
rw_enter(&sp->s_lock, RW_READER);
ASSERT(sp->s_shadow <= INT_MAX);
shadow = (int)sp->s_shadow;
ASSERT(sp->s_ref);
rw_exit(&sp->s_lock);
if ((err = ufs_iget_alloced(vfsp, shadow, &sip, cr)) == 0) {
rw_enter(&sip->i_contents, RW_WRITER);
rw_enter(&sp->s_lock, RW_WRITER);
ASSERT(sp->s_shadow == shadow);
ASSERT(sip->i_dquot == 0);
ASSERT(sip->i_nlink > 0);
sp->s_use = --sip->i_nlink;
ufs_setreclaim(sip);
TRANS_INODE(sip->i_ufsvfs, sip);
sip->i_flag |= ICHG | IMOD;
sip->i_seq++;
ITIMES_NOLOCK(sip);
refcnt = --sp->s_ref;
signature = sp->s_signature;
ASSERT(sp->s_ref >= 0 && sp->s_ref <= sp->s_use);
rw_exit(&sp->s_lock);
rw_exit(&sip->i_contents);
VN_RELE(ITOV(sip));
} else {
rw_enter(&sp->s_lock, RW_WRITER);
refcnt = --sp->s_ref;
signature = sp->s_signature;
ASSERT(sp->s_ref >= 0 && sp->s_ref <= sp->s_use);
rw_exit(&sp->s_lock);
}
if (refcnt == 0)
si_cache_del(sp, signature);
return (err);
}
static int
si_cachei_get(struct inode *ip, si_t **spp)
{
si_t *sp;
rw_enter(&si_cache_lock, RW_READER);
for (sp = si_cachei[SI_HASH(ip->i_shadow)]; sp; sp = sp->s_forw)
if (sp->s_shadow == ip->i_shadow && sp->s_dev == ip->i_dev)
break;
if (sp == NULL) {
rw_exit(&si_cache_lock);
return (1);
}
rw_enter(&sp->s_lock, RW_WRITER);
rw_exit(&si_cache_lock);
*spp = sp;
return (0);
}
static int
si_cachea_get(struct inode *ip, si_t *spi, si_t **spp)
{
si_t *sp;
spi->s_dev = ip->i_dev;
spi->s_signature = si_signature(spi);
rw_enter(&si_cache_lock, RW_READER);
for (sp = si_cachea[SI_HASH(spi->s_signature)]; sp; sp = sp->s_next) {
if (sp->s_signature == spi->s_signature &&
sp->s_dev == spi->s_dev &&
sp->s_use > 0 &&
sp->s_use <= (MAXLINK - 1) &&
!si_cmp(sp, spi))
break;
}
if (sp == NULL) {
rw_exit(&si_cache_lock);
return (1);
}
rw_enter(&sp->s_lock, RW_WRITER);
spi->s_shadow = sp->s_shadow;
rw_exit(&si_cache_lock);
*spp = sp;
return (0);
}
static void
si_cache_put(si_t *sp)
{
si_t **tspp;
ASSERT(sp->s_fore == NULL);
rw_enter(&si_cache_lock, RW_WRITER);
if (!sp->s_signature)
sp->s_signature = si_signature(sp);
sp->s_flags |= SI_CACHED;
sp->s_fore = NULL;
tspp = &si_cachea[SI_HASH(sp->s_signature)];
sp->s_next = *tspp;
*tspp = sp;
tspp = &si_cachei[SI_HASH(sp->s_shadow)];
sp->s_forw = *tspp;
*tspp = sp;
rw_exit(&si_cache_lock);
}
void
si_cache_del(si_t *sp, int signature)
{
si_t **tspp;
int hash;
int foundacl = 0;
rw_enter(&si_cache_lock, RW_WRITER);
hash = SI_HASH(signature);
for (tspp = &si_cachea[hash]; *tspp; tspp = &(*tspp)->s_next) {
if (*tspp == sp) {
rw_enter(&sp->s_lock, RW_WRITER);
if (sp->s_ref) {
rw_exit(&sp->s_lock);
rw_exit(&si_cache_lock);
return;
}
ASSERT(sp->s_fore == NULL);
ASSERT(sp->s_flags & SI_CACHED);
foundacl = 1;
*tspp = sp->s_next;
break;
}
}
if (foundacl == 0) {
rw_exit(&si_cache_lock);
return;
}
hash = SI_HASH(sp->s_shadow);
for (tspp = &si_cachei[hash]; *tspp; tspp = &(*tspp)->s_forw) {
if (*tspp == sp) {
*tspp = sp->s_forw;
break;
}
}
rw_exit(&sp->s_lock);
rw_exit(&si_cache_lock);
sp->s_flags &= ~SI_CACHED;
(void) ufs_si_free_mem(sp);
}
void
si_cache_init(void)
{
rw_init(&si_cache_lock, NULL, RW_DEFAULT, NULL);
si_cachea = kmem_zalloc(si_cachecnt * sizeof (si_t *), KM_SLEEP);
si_cachei = kmem_zalloc(si_cachecnt * sizeof (si_t *), KM_SLEEP);
}
static int
aclcksum(ufs_ic_acl_t *s_aclp)
{
ufs_ic_acl_t *aclp;
int signature = 0;
for (aclp = s_aclp; aclp; aclp = aclp->acl_ic_next) {
signature += aclp->acl_ic_perm;
signature += aclp->acl_ic_who;
}
return (signature);
}
static int
si_signature(si_t *sp)
{
int signature = sp->s_dev;
signature += aclcksum(sp->aowner) + aclcksum(sp->agroup) +
aclcksum(sp->aother) + aclcksum(sp->ausers) +
aclcksum(sp->agroups) + aclcksum(sp->downer) +
aclcksum(sp->dgroup) + aclcksum(sp->dother) +
aclcksum(sp->dusers) + aclcksum(sp->dgroups);
if (sp->aclass.acl_ismask)
signature += sp->aclass.acl_maskbits;
if (sp->dclass.acl_ismask)
signature += sp->dclass.acl_maskbits;
return (signature);
}
static int
aclcmp(ufs_ic_acl_t *aclin1p, ufs_ic_acl_t *aclin2p)
{
ufs_ic_acl_t *aclp1;
ufs_ic_acl_t *aclp2;
if (aclin1p == aclin2p)
return (0);
for (aclp1 = aclin1p, aclp2 = aclin2p; aclp1 && aclp2;
aclp1 = aclp1->acl_ic_next, aclp2 = aclp2->acl_ic_next) {
if (aclp1->acl_ic_perm != aclp2->acl_ic_perm ||
aclp1->acl_ic_who != aclp2->acl_ic_who)
return (1);
}
if (aclp1 || aclp2)
return (1);
return (0);
}
static int
si_cmp(si_t *sp1, si_t *sp2)
{
if (sp1->s_dev != sp2->s_dev)
return (1);
if (aclcmp(sp1->aowner, sp2->aowner) ||
aclcmp(sp1->agroup, sp2->agroup) ||
aclcmp(sp1->aother, sp2->aother) ||
aclcmp(sp1->ausers, sp2->ausers) ||
aclcmp(sp1->agroups, sp2->agroups) ||
aclcmp(sp1->downer, sp2->downer) ||
aclcmp(sp1->dgroup, sp2->dgroup) ||
aclcmp(sp1->dother, sp2->dother) ||
aclcmp(sp1->dusers, sp2->dusers) ||
aclcmp(sp1->dgroups, sp2->dgroups))
return (1);
if (sp1->aclass.acl_ismask != sp2->aclass.acl_ismask)
return (1);
if (sp1->dclass.acl_ismask != sp2->dclass.acl_ismask)
return (1);
if (sp1->aclass.acl_ismask &&
sp1->aclass.acl_maskbits != sp2->aclass.acl_maskbits)
return (1);
if (sp1->dclass.acl_ismask &&
sp1->dclass.acl_maskbits != sp2->dclass.acl_maskbits)
return (1);
return (0);
}
void
ufs_si_cache_flush(dev_t dev)
{
si_t *tsp, **tspp;
int i;
rw_enter(&si_cache_lock, RW_WRITER);
for (i = 0; i < si_cachecnt; i++) {
tspp = &si_cachea[i];
while (*tspp) {
if ((*tspp)->s_dev == dev) {
*tspp = (*tspp)->s_next;
} else {
tspp = &(*tspp)->s_next;
}
}
}
for (i = 0; i < si_cachecnt; i++) {
tspp = &si_cachei[i];
while (*tspp) {
if ((*tspp)->s_dev == dev) {
tsp = *tspp;
*tspp = (*tspp)->s_forw;
tsp->s_flags &= ~SI_CACHED;
ufs_si_free_mem(tsp);
} else {
tspp = &(*tspp)->s_forw;
}
}
}
rw_exit(&si_cache_lock);
}
void
ufs_si_del(struct inode *ip)
{
si_t *sp = ip->i_ufs_acl;
int refcnt;
int signature;
if (sp) {
rw_enter(&sp->s_lock, RW_WRITER);
refcnt = --sp->s_ref;
signature = sp->s_signature;
ASSERT(sp->s_ref >= 0 && sp->s_ref <= sp->s_use);
rw_exit(&sp->s_lock);
if (refcnt == 0)
si_cache_del(sp, signature);
ip->i_ufs_acl = NULL;
}
}