1999-12-19 06:08:07 +00:00
|
|
|
/*-
|
2004-02-22 00:33:12 +00:00
|
|
|
* Copyright (c) 1999-2003 Robert N. M. Watson
|
1999-12-19 06:08:07 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
2001-11-01 21:37:07 +00:00
|
|
|
* This software was developed by Robert Watson for the TrustedBSD Project.
|
|
|
|
*
|
1999-12-19 06:08:07 +00:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
/*
|
2001-03-06 17:28:24 +00:00
|
|
|
* Developed by the TrustedBSD Project.
|
|
|
|
* Support for POSIX.1e access control lists.
|
1999-12-19 06:08:07 +00:00
|
|
|
*/
|
|
|
|
|
2003-06-11 00:56:59 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2002-08-01 01:04:16 +00:00
|
|
|
#include "opt_mac.h"
|
|
|
|
|
1999-12-19 06:08:07 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/sysproto.h>
|
|
|
|
#include <sys/kernel.h>
|
2002-08-01 01:04:16 +00:00
|
|
|
#include <sys/mac.h>
|
1999-12-19 06:08:07 +00:00
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/vnode.h>
|
|
|
|
#include <sys/lock.h>
|
2001-09-01 04:33:22 +00:00
|
|
|
#include <sys/mutex.h>
|
1999-12-19 06:08:07 +00:00
|
|
|
#include <sys/namei.h>
|
|
|
|
#include <sys/file.h>
|
2003-01-01 01:56:19 +00:00
|
|
|
#include <sys/filedesc.h>
|
1999-12-19 06:08:07 +00:00
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/sysent.h>
|
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/acl.h>
|
|
|
|
|
2001-03-06 17:28:24 +00:00
|
|
|
MALLOC_DEFINE(M_ACL, "acl", "access control list");
|
1999-12-19 06:08:07 +00:00
|
|
|
|
2002-06-27 19:30:11 +00:00
|
|
|
static int vacl_set_acl(struct thread *td, struct vnode *vp,
|
|
|
|
acl_type_t type, struct acl *aclp);
|
|
|
|
static int vacl_get_acl(struct thread *td, struct vnode *vp,
|
|
|
|
acl_type_t type, struct acl *aclp);
|
2001-10-27 05:45:42 +00:00
|
|
|
static int vacl_aclcheck(struct thread *td, struct vnode *vp,
|
2002-06-27 19:30:11 +00:00
|
|
|
acl_type_t type, struct acl *aclp);
|
1999-12-19 06:08:07 +00:00
|
|
|
|
2001-03-06 17:28:24 +00:00
|
|
|
/*
|
|
|
|
* Implement a version of vaccess() that understands POSIX.1e ACL semantics.
|
|
|
|
* Return 0 on success, else an errno value. Should be merged into
|
|
|
|
* vaccess() eventually.
|
|
|
|
*/
|
|
|
|
int
|
In my first reading of POSIX.1e, I misinterpreted handling of the
ACL_USER_OBJ and ACL_GROUP_OBJ fields, believing that modification of the
access ACL could be used by privileged processes to change file/directory
ownership. In fact, this is incorrect; ACL_*_OBJ (+ ACL_MASK and
ACL_OTHER) should have undefined ae_id fields; this commit attempts
to correct that misunderstanding.
o Modify arguments to vaccess_acl_posix1e() to accept the uid and gid
associated with the vnode, as those can no longer be extracted from
the ACL passed as an argument. Perform all comparisons against
the passed arguments. This actually has the effect of simplifying
a number of components of this call, as well as reducing the indent
level, but now seperates handling of ACL_GROUP_OBJ from ACL_GROUP.
o Modify acl_posix1e_check() to return EINVAL if the ae_id field of
any of the ACL_{USER_OBJ,GROUP_OBJ,MASK,OTHER} entries is a value
other than ACL_UNDEFINED_ID. As a temporary work-around to allow
clean upgrades, set the ae_id field to ACL_UNDEFINED_ID before
each check so that this cannot cause a failure in the short term
(this work-around will be removed when the userland libraries and
utilities are updated to take this change into account).
o Modify ufs_sync_acl_from_inode() so that it forces
ACL_{USER_OBJ,GROUP_OBJ,MASK,OTHER} ae_id fields to ACL_UNDEFINED_ID
when synchronizing the ACL from the inode.
o Modify ufs_sync_inode_from_acl to not propagate uid and gid
information to the inode from the ACL during ACL update. Also
modify the masking of permission bits that may be set from
ALLPERMS to (S_IRWXU|S_IRWXG|S_IRWXO), as ACLs currently do not
carry none-ACCESSPERMS (S_ISUID, S_ISGID, S_ISTXT).
o Modify ufs_getacl() so that when it emulates an access ACL from
the inode, it initializes the ae_id fields to ACL_UNDEFINED_ID.
o Clean up ufs_setacl() substantially since it is no longer possible
to perform chown/chgrp operations using vop_setacl(), so all the
access control for that can be eliminated.
o Modify ufs_access() so that it passes owner uid and gid information
into vaccess_acl_posix1e().
Pointed out by: jedger
Obtained from: TrustedBSD Project
2001-04-17 04:33:34 +00:00
|
|
|
vaccess_acl_posix1e(enum vtype type, uid_t file_uid, gid_t file_gid,
|
|
|
|
struct acl *acl, mode_t acc_mode, struct ucred *cred, int *privused)
|
2001-03-06 17:28:24 +00:00
|
|
|
{
|
|
|
|
struct acl_entry *acl_other, *acl_mask;
|
|
|
|
mode_t dac_granted;
|
|
|
|
mode_t cap_granted;
|
|
|
|
mode_t acl_mask_granted;
|
|
|
|
int group_matched, i;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Look for a normal, non-privileged way to access the file/directory
|
|
|
|
* as requested. If it exists, go with that. Otherwise, attempt
|
|
|
|
* to use privileges granted via cap_granted. In some cases,
|
|
|
|
* which privileges to use may be ambiguous due to "best match",
|
|
|
|
* in which case fall back on first match for the time being.
|
|
|
|
*/
|
|
|
|
if (privused != NULL)
|
|
|
|
*privused = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Determine privileges now, but don't apply until we've found
|
2001-08-24 01:41:42 +00:00
|
|
|
* a DAC entry that matches but has failed to allow access.
|
2001-03-06 17:28:24 +00:00
|
|
|
*/
|
|
|
|
#ifndef CAPABILITIES
|
2004-07-26 07:24:04 +00:00
|
|
|
if (suser_cred(cred, SUSER_ALLOWJAIL) == 0)
|
2002-07-22 03:57:07 +00:00
|
|
|
cap_granted = VALLPERM;
|
2001-03-06 17:28:24 +00:00
|
|
|
else
|
|
|
|
cap_granted = 0;
|
|
|
|
#else
|
|
|
|
cap_granted = 0;
|
|
|
|
|
|
|
|
if (type == VDIR) {
|
|
|
|
if ((acc_mode & VEXEC) && !cap_check(cred, NULL,
|
2004-07-26 07:24:04 +00:00
|
|
|
CAP_DAC_READ_SEARCH, SUSER_ALLOWJAIL))
|
2001-03-06 17:28:24 +00:00
|
|
|
cap_granted |= VEXEC;
|
|
|
|
} else {
|
|
|
|
if ((acc_mode & VEXEC) && !cap_check(cred, NULL,
|
2004-07-26 07:24:04 +00:00
|
|
|
CAP_DAC_EXECUTE, SUSER_ALLOWJAIL))
|
2001-03-06 17:28:24 +00:00
|
|
|
cap_granted |= VEXEC;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((acc_mode & VREAD) && !cap_check(cred, NULL, CAP_DAC_READ_SEARCH,
|
2004-07-26 07:24:04 +00:00
|
|
|
SUSER_ALLOWJAIL))
|
2001-03-06 17:28:24 +00:00
|
|
|
cap_granted |= VREAD;
|
|
|
|
|
2002-07-22 03:57:07 +00:00
|
|
|
if (((acc_mode & VWRITE) || (acc_mode & VAPPEND)) &&
|
2004-07-26 07:24:04 +00:00
|
|
|
!cap_check(cred, NULL, CAP_DAC_WRITE, SUSER_ALLOWJAIL))
|
2002-07-22 03:57:07 +00:00
|
|
|
cap_granted |= (VWRITE | VAPPEND);
|
2001-03-06 17:28:24 +00:00
|
|
|
|
|
|
|
if ((acc_mode & VADMIN) && !cap_check(cred, NULL, CAP_FOWNER,
|
2004-07-26 07:24:04 +00:00
|
|
|
SUSER_ALLOWJAIL))
|
2001-03-06 17:28:24 +00:00
|
|
|
cap_granted |= VADMIN;
|
|
|
|
#endif /* CAPABILITIES */
|
|
|
|
|
|
|
|
/*
|
2001-08-24 01:41:42 +00:00
|
|
|
* The owner matches if the effective uid associated with the
|
|
|
|
* credential matches that of the ACL_USER_OBJ entry. While we're
|
|
|
|
* doing the first scan, also cache the location of the ACL_MASK
|
|
|
|
* and ACL_OTHER entries, preventing some future iterations.
|
2001-03-06 17:28:24 +00:00
|
|
|
*/
|
|
|
|
acl_mask = acl_other = NULL;
|
|
|
|
for (i = 0; i < acl->acl_cnt; i++) {
|
|
|
|
switch (acl->acl_entry[i].ae_tag) {
|
|
|
|
case ACL_USER_OBJ:
|
In my first reading of POSIX.1e, I misinterpreted handling of the
ACL_USER_OBJ and ACL_GROUP_OBJ fields, believing that modification of the
access ACL could be used by privileged processes to change file/directory
ownership. In fact, this is incorrect; ACL_*_OBJ (+ ACL_MASK and
ACL_OTHER) should have undefined ae_id fields; this commit attempts
to correct that misunderstanding.
o Modify arguments to vaccess_acl_posix1e() to accept the uid and gid
associated with the vnode, as those can no longer be extracted from
the ACL passed as an argument. Perform all comparisons against
the passed arguments. This actually has the effect of simplifying
a number of components of this call, as well as reducing the indent
level, but now seperates handling of ACL_GROUP_OBJ from ACL_GROUP.
o Modify acl_posix1e_check() to return EINVAL if the ae_id field of
any of the ACL_{USER_OBJ,GROUP_OBJ,MASK,OTHER} entries is a value
other than ACL_UNDEFINED_ID. As a temporary work-around to allow
clean upgrades, set the ae_id field to ACL_UNDEFINED_ID before
each check so that this cannot cause a failure in the short term
(this work-around will be removed when the userland libraries and
utilities are updated to take this change into account).
o Modify ufs_sync_acl_from_inode() so that it forces
ACL_{USER_OBJ,GROUP_OBJ,MASK,OTHER} ae_id fields to ACL_UNDEFINED_ID
when synchronizing the ACL from the inode.
o Modify ufs_sync_inode_from_acl to not propagate uid and gid
information to the inode from the ACL during ACL update. Also
modify the masking of permission bits that may be set from
ALLPERMS to (S_IRWXU|S_IRWXG|S_IRWXO), as ACLs currently do not
carry none-ACCESSPERMS (S_ISUID, S_ISGID, S_ISTXT).
o Modify ufs_getacl() so that when it emulates an access ACL from
the inode, it initializes the ae_id fields to ACL_UNDEFINED_ID.
o Clean up ufs_setacl() substantially since it is no longer possible
to perform chown/chgrp operations using vop_setacl(), so all the
access control for that can be eliminated.
o Modify ufs_access() so that it passes owner uid and gid information
into vaccess_acl_posix1e().
Pointed out by: jedger
Obtained from: TrustedBSD Project
2001-04-17 04:33:34 +00:00
|
|
|
if (file_uid != cred->cr_uid)
|
2001-03-06 17:28:24 +00:00
|
|
|
break;
|
|
|
|
dac_granted = 0;
|
|
|
|
dac_granted |= VADMIN;
|
2001-04-11 02:19:01 +00:00
|
|
|
if (acl->acl_entry[i].ae_perm & ACL_EXECUTE)
|
2001-03-06 17:28:24 +00:00
|
|
|
dac_granted |= VEXEC;
|
2001-04-11 02:19:01 +00:00
|
|
|
if (acl->acl_entry[i].ae_perm & ACL_READ)
|
2001-03-06 17:28:24 +00:00
|
|
|
dac_granted |= VREAD;
|
2001-04-11 02:19:01 +00:00
|
|
|
if (acl->acl_entry[i].ae_perm & ACL_WRITE)
|
2002-07-22 03:57:07 +00:00
|
|
|
dac_granted |= (VWRITE | VAPPEND);
|
2001-03-06 17:28:24 +00:00
|
|
|
if ((acc_mode & dac_granted) == acc_mode)
|
|
|
|
return (0);
|
|
|
|
if ((acc_mode & (dac_granted | cap_granted)) ==
|
|
|
|
acc_mode) {
|
|
|
|
if (privused != NULL)
|
|
|
|
*privused = 1;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
case ACL_MASK:
|
|
|
|
acl_mask = &acl->acl_entry[i];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ACL_OTHER:
|
|
|
|
acl_other = &acl->acl_entry[i];
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2002-03-19 11:02:06 +00:00
|
|
|
break;
|
2001-03-06 17:28:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-08-24 01:41:42 +00:00
|
|
|
* An ACL_OTHER entry should always exist in a valid access
|
|
|
|
* ACL. If it doesn't, then generate a serious failure. For now,
|
|
|
|
* this means a debugging message and EPERM, but in the future
|
|
|
|
* should probably be a panic.
|
2001-03-06 17:28:24 +00:00
|
|
|
*/
|
|
|
|
if (acl_other == NULL) {
|
|
|
|
/*
|
2001-08-24 01:41:42 +00:00
|
|
|
* XXX This should never happen
|
2001-03-06 17:28:24 +00:00
|
|
|
*/
|
|
|
|
printf("vaccess_acl_posix1e: ACL_OTHER missing\n");
|
|
|
|
return (EPERM);
|
|
|
|
}
|
2001-08-24 01:41:42 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Checks against ACL_USER, ACL_GROUP_OBJ, and ACL_GROUP fields
|
|
|
|
* are masked by an ACL_MASK entry, if any. As such, first identify
|
|
|
|
* the ACL_MASK field, then iterate through identifying potential
|
|
|
|
* user matches, then group matches. If there is no ACL_MASK,
|
|
|
|
* assume that the mask allows all requests to succeed.
|
|
|
|
*/
|
2001-03-06 17:28:24 +00:00
|
|
|
if (acl_mask != NULL) {
|
|
|
|
acl_mask_granted = 0;
|
2001-04-11 02:19:01 +00:00
|
|
|
if (acl_mask->ae_perm & ACL_EXECUTE)
|
2001-03-06 17:28:24 +00:00
|
|
|
acl_mask_granted |= VEXEC;
|
2001-04-11 02:19:01 +00:00
|
|
|
if (acl_mask->ae_perm & ACL_READ)
|
2001-03-06 17:28:24 +00:00
|
|
|
acl_mask_granted |= VREAD;
|
2001-04-11 02:19:01 +00:00
|
|
|
if (acl_mask->ae_perm & ACL_WRITE)
|
2002-07-22 03:57:07 +00:00
|
|
|
acl_mask_granted |= (VWRITE | VAPPEND);
|
2001-03-06 17:28:24 +00:00
|
|
|
} else
|
2002-07-22 03:57:07 +00:00
|
|
|
acl_mask_granted = VEXEC | VREAD | VWRITE | VAPPEND;
|
2001-03-06 17:28:24 +00:00
|
|
|
|
|
|
|
/*
|
2001-08-24 01:41:42 +00:00
|
|
|
* Iterate through user ACL entries. Do checks twice, first
|
|
|
|
* without privilege, and then if a match is found but failed,
|
|
|
|
* a second time with privilege.
|
2001-03-06 17:28:24 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check ACL_USER ACL entries.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < acl->acl_cnt; i++) {
|
|
|
|
switch (acl->acl_entry[i].ae_tag) {
|
|
|
|
case ACL_USER:
|
|
|
|
if (acl->acl_entry[i].ae_id != cred->cr_uid)
|
|
|
|
break;
|
|
|
|
dac_granted = 0;
|
2001-04-11 02:19:01 +00:00
|
|
|
if (acl->acl_entry[i].ae_perm & ACL_EXECUTE)
|
2001-03-06 17:28:24 +00:00
|
|
|
dac_granted |= VEXEC;
|
2001-04-11 02:19:01 +00:00
|
|
|
if (acl->acl_entry[i].ae_perm & ACL_READ)
|
2001-03-06 17:28:24 +00:00
|
|
|
dac_granted |= VREAD;
|
2001-04-11 02:19:01 +00:00
|
|
|
if (acl->acl_entry[i].ae_perm & ACL_WRITE)
|
2002-07-22 03:57:07 +00:00
|
|
|
dac_granted |= (VWRITE | VAPPEND);
|
2001-03-06 17:28:24 +00:00
|
|
|
dac_granted &= acl_mask_granted;
|
|
|
|
if ((acc_mode & dac_granted) == acc_mode)
|
|
|
|
return (0);
|
In my first reading of POSIX.1e, I misinterpreted handling of the
ACL_USER_OBJ and ACL_GROUP_OBJ fields, believing that modification of the
access ACL could be used by privileged processes to change file/directory
ownership. In fact, this is incorrect; ACL_*_OBJ (+ ACL_MASK and
ACL_OTHER) should have undefined ae_id fields; this commit attempts
to correct that misunderstanding.
o Modify arguments to vaccess_acl_posix1e() to accept the uid and gid
associated with the vnode, as those can no longer be extracted from
the ACL passed as an argument. Perform all comparisons against
the passed arguments. This actually has the effect of simplifying
a number of components of this call, as well as reducing the indent
level, but now seperates handling of ACL_GROUP_OBJ from ACL_GROUP.
o Modify acl_posix1e_check() to return EINVAL if the ae_id field of
any of the ACL_{USER_OBJ,GROUP_OBJ,MASK,OTHER} entries is a value
other than ACL_UNDEFINED_ID. As a temporary work-around to allow
clean upgrades, set the ae_id field to ACL_UNDEFINED_ID before
each check so that this cannot cause a failure in the short term
(this work-around will be removed when the userland libraries and
utilities are updated to take this change into account).
o Modify ufs_sync_acl_from_inode() so that it forces
ACL_{USER_OBJ,GROUP_OBJ,MASK,OTHER} ae_id fields to ACL_UNDEFINED_ID
when synchronizing the ACL from the inode.
o Modify ufs_sync_inode_from_acl to not propagate uid and gid
information to the inode from the ACL during ACL update. Also
modify the masking of permission bits that may be set from
ALLPERMS to (S_IRWXU|S_IRWXG|S_IRWXO), as ACLs currently do not
carry none-ACCESSPERMS (S_ISUID, S_ISGID, S_ISTXT).
o Modify ufs_getacl() so that when it emulates an access ACL from
the inode, it initializes the ae_id fields to ACL_UNDEFINED_ID.
o Clean up ufs_setacl() substantially since it is no longer possible
to perform chown/chgrp operations using vop_setacl(), so all the
access control for that can be eliminated.
o Modify ufs_access() so that it passes owner uid and gid information
into vaccess_acl_posix1e().
Pointed out by: jedger
Obtained from: TrustedBSD Project
2001-04-17 04:33:34 +00:00
|
|
|
if ((acc_mode & (dac_granted | cap_granted)) !=
|
|
|
|
acc_mode)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (privused != NULL)
|
|
|
|
*privused = 1;
|
|
|
|
return (0);
|
2001-03-06 17:28:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Group match is best-match, not first-match, so find a
|
|
|
|
* "best" match. Iterate across, testing each potential group
|
|
|
|
* match. Make sure we keep track of whether we found a match
|
2001-08-24 01:41:42 +00:00
|
|
|
* or not, so that we know if we should try again with any
|
|
|
|
* available privilege, or if we should move on to ACL_OTHER.
|
2001-03-06 17:28:24 +00:00
|
|
|
*/
|
|
|
|
group_matched = 0;
|
|
|
|
for (i = 0; i < acl->acl_cnt; i++) {
|
|
|
|
switch (acl->acl_entry[i].ae_tag) {
|
|
|
|
case ACL_GROUP_OBJ:
|
2001-04-23 22:52:26 +00:00
|
|
|
if (!groupmember(file_gid, cred))
|
In my first reading of POSIX.1e, I misinterpreted handling of the
ACL_USER_OBJ and ACL_GROUP_OBJ fields, believing that modification of the
access ACL could be used by privileged processes to change file/directory
ownership. In fact, this is incorrect; ACL_*_OBJ (+ ACL_MASK and
ACL_OTHER) should have undefined ae_id fields; this commit attempts
to correct that misunderstanding.
o Modify arguments to vaccess_acl_posix1e() to accept the uid and gid
associated with the vnode, as those can no longer be extracted from
the ACL passed as an argument. Perform all comparisons against
the passed arguments. This actually has the effect of simplifying
a number of components of this call, as well as reducing the indent
level, but now seperates handling of ACL_GROUP_OBJ from ACL_GROUP.
o Modify acl_posix1e_check() to return EINVAL if the ae_id field of
any of the ACL_{USER_OBJ,GROUP_OBJ,MASK,OTHER} entries is a value
other than ACL_UNDEFINED_ID. As a temporary work-around to allow
clean upgrades, set the ae_id field to ACL_UNDEFINED_ID before
each check so that this cannot cause a failure in the short term
(this work-around will be removed when the userland libraries and
utilities are updated to take this change into account).
o Modify ufs_sync_acl_from_inode() so that it forces
ACL_{USER_OBJ,GROUP_OBJ,MASK,OTHER} ae_id fields to ACL_UNDEFINED_ID
when synchronizing the ACL from the inode.
o Modify ufs_sync_inode_from_acl to not propagate uid and gid
information to the inode from the ACL during ACL update. Also
modify the masking of permission bits that may be set from
ALLPERMS to (S_IRWXU|S_IRWXG|S_IRWXO), as ACLs currently do not
carry none-ACCESSPERMS (S_ISUID, S_ISGID, S_ISTXT).
o Modify ufs_getacl() so that when it emulates an access ACL from
the inode, it initializes the ae_id fields to ACL_UNDEFINED_ID.
o Clean up ufs_setacl() substantially since it is no longer possible
to perform chown/chgrp operations using vop_setacl(), so all the
access control for that can be eliminated.
o Modify ufs_access() so that it passes owner uid and gid information
into vaccess_acl_posix1e().
Pointed out by: jedger
Obtained from: TrustedBSD Project
2001-04-17 04:33:34 +00:00
|
|
|
break;
|
|
|
|
dac_granted = 0;
|
|
|
|
if (acl->acl_entry[i].ae_perm & ACL_EXECUTE)
|
|
|
|
dac_granted |= VEXEC;
|
|
|
|
if (acl->acl_entry[i].ae_perm & ACL_READ)
|
|
|
|
dac_granted |= VREAD;
|
|
|
|
if (acl->acl_entry[i].ae_perm & ACL_WRITE)
|
2002-07-22 03:57:07 +00:00
|
|
|
dac_granted |= (VWRITE | VAPPEND);
|
In my first reading of POSIX.1e, I misinterpreted handling of the
ACL_USER_OBJ and ACL_GROUP_OBJ fields, believing that modification of the
access ACL could be used by privileged processes to change file/directory
ownership. In fact, this is incorrect; ACL_*_OBJ (+ ACL_MASK and
ACL_OTHER) should have undefined ae_id fields; this commit attempts
to correct that misunderstanding.
o Modify arguments to vaccess_acl_posix1e() to accept the uid and gid
associated with the vnode, as those can no longer be extracted from
the ACL passed as an argument. Perform all comparisons against
the passed arguments. This actually has the effect of simplifying
a number of components of this call, as well as reducing the indent
level, but now seperates handling of ACL_GROUP_OBJ from ACL_GROUP.
o Modify acl_posix1e_check() to return EINVAL if the ae_id field of
any of the ACL_{USER_OBJ,GROUP_OBJ,MASK,OTHER} entries is a value
other than ACL_UNDEFINED_ID. As a temporary work-around to allow
clean upgrades, set the ae_id field to ACL_UNDEFINED_ID before
each check so that this cannot cause a failure in the short term
(this work-around will be removed when the userland libraries and
utilities are updated to take this change into account).
o Modify ufs_sync_acl_from_inode() so that it forces
ACL_{USER_OBJ,GROUP_OBJ,MASK,OTHER} ae_id fields to ACL_UNDEFINED_ID
when synchronizing the ACL from the inode.
o Modify ufs_sync_inode_from_acl to not propagate uid and gid
information to the inode from the ACL during ACL update. Also
modify the masking of permission bits that may be set from
ALLPERMS to (S_IRWXU|S_IRWXG|S_IRWXO), as ACLs currently do not
carry none-ACCESSPERMS (S_ISUID, S_ISGID, S_ISTXT).
o Modify ufs_getacl() so that when it emulates an access ACL from
the inode, it initializes the ae_id fields to ACL_UNDEFINED_ID.
o Clean up ufs_setacl() substantially since it is no longer possible
to perform chown/chgrp operations using vop_setacl(), so all the
access control for that can be eliminated.
o Modify ufs_access() so that it passes owner uid and gid information
into vaccess_acl_posix1e().
Pointed out by: jedger
Obtained from: TrustedBSD Project
2001-04-17 04:33:34 +00:00
|
|
|
dac_granted &= acl_mask_granted;
|
|
|
|
|
|
|
|
if ((acc_mode & dac_granted) == acc_mode)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
group_matched = 1;
|
|
|
|
break;
|
|
|
|
|
2001-03-06 17:28:24 +00:00
|
|
|
case ACL_GROUP:
|
In my first reading of POSIX.1e, I misinterpreted handling of the
ACL_USER_OBJ and ACL_GROUP_OBJ fields, believing that modification of the
access ACL could be used by privileged processes to change file/directory
ownership. In fact, this is incorrect; ACL_*_OBJ (+ ACL_MASK and
ACL_OTHER) should have undefined ae_id fields; this commit attempts
to correct that misunderstanding.
o Modify arguments to vaccess_acl_posix1e() to accept the uid and gid
associated with the vnode, as those can no longer be extracted from
the ACL passed as an argument. Perform all comparisons against
the passed arguments. This actually has the effect of simplifying
a number of components of this call, as well as reducing the indent
level, but now seperates handling of ACL_GROUP_OBJ from ACL_GROUP.
o Modify acl_posix1e_check() to return EINVAL if the ae_id field of
any of the ACL_{USER_OBJ,GROUP_OBJ,MASK,OTHER} entries is a value
other than ACL_UNDEFINED_ID. As a temporary work-around to allow
clean upgrades, set the ae_id field to ACL_UNDEFINED_ID before
each check so that this cannot cause a failure in the short term
(this work-around will be removed when the userland libraries and
utilities are updated to take this change into account).
o Modify ufs_sync_acl_from_inode() so that it forces
ACL_{USER_OBJ,GROUP_OBJ,MASK,OTHER} ae_id fields to ACL_UNDEFINED_ID
when synchronizing the ACL from the inode.
o Modify ufs_sync_inode_from_acl to not propagate uid and gid
information to the inode from the ACL during ACL update. Also
modify the masking of permission bits that may be set from
ALLPERMS to (S_IRWXU|S_IRWXG|S_IRWXO), as ACLs currently do not
carry none-ACCESSPERMS (S_ISUID, S_ISGID, S_ISTXT).
o Modify ufs_getacl() so that when it emulates an access ACL from
the inode, it initializes the ae_id fields to ACL_UNDEFINED_ID.
o Clean up ufs_setacl() substantially since it is no longer possible
to perform chown/chgrp operations using vop_setacl(), so all the
access control for that can be eliminated.
o Modify ufs_access() so that it passes owner uid and gid information
into vaccess_acl_posix1e().
Pointed out by: jedger
Obtained from: TrustedBSD Project
2001-04-17 04:33:34 +00:00
|
|
|
if (!groupmember(acl->acl_entry[i].ae_id, cred))
|
|
|
|
break;
|
|
|
|
dac_granted = 0;
|
|
|
|
if (acl->acl_entry[i].ae_perm & ACL_EXECUTE)
|
|
|
|
dac_granted |= VEXEC;
|
|
|
|
if (acl->acl_entry[i].ae_perm & ACL_READ)
|
|
|
|
dac_granted |= VREAD;
|
|
|
|
if (acl->acl_entry[i].ae_perm & ACL_WRITE)
|
2002-07-22 03:57:07 +00:00
|
|
|
dac_granted |= (VWRITE | VAPPEND);
|
In my first reading of POSIX.1e, I misinterpreted handling of the
ACL_USER_OBJ and ACL_GROUP_OBJ fields, believing that modification of the
access ACL could be used by privileged processes to change file/directory
ownership. In fact, this is incorrect; ACL_*_OBJ (+ ACL_MASK and
ACL_OTHER) should have undefined ae_id fields; this commit attempts
to correct that misunderstanding.
o Modify arguments to vaccess_acl_posix1e() to accept the uid and gid
associated with the vnode, as those can no longer be extracted from
the ACL passed as an argument. Perform all comparisons against
the passed arguments. This actually has the effect of simplifying
a number of components of this call, as well as reducing the indent
level, but now seperates handling of ACL_GROUP_OBJ from ACL_GROUP.
o Modify acl_posix1e_check() to return EINVAL if the ae_id field of
any of the ACL_{USER_OBJ,GROUP_OBJ,MASK,OTHER} entries is a value
other than ACL_UNDEFINED_ID. As a temporary work-around to allow
clean upgrades, set the ae_id field to ACL_UNDEFINED_ID before
each check so that this cannot cause a failure in the short term
(this work-around will be removed when the userland libraries and
utilities are updated to take this change into account).
o Modify ufs_sync_acl_from_inode() so that it forces
ACL_{USER_OBJ,GROUP_OBJ,MASK,OTHER} ae_id fields to ACL_UNDEFINED_ID
when synchronizing the ACL from the inode.
o Modify ufs_sync_inode_from_acl to not propagate uid and gid
information to the inode from the ACL during ACL update. Also
modify the masking of permission bits that may be set from
ALLPERMS to (S_IRWXU|S_IRWXG|S_IRWXO), as ACLs currently do not
carry none-ACCESSPERMS (S_ISUID, S_ISGID, S_ISTXT).
o Modify ufs_getacl() so that when it emulates an access ACL from
the inode, it initializes the ae_id fields to ACL_UNDEFINED_ID.
o Clean up ufs_setacl() substantially since it is no longer possible
to perform chown/chgrp operations using vop_setacl(), so all the
access control for that can be eliminated.
o Modify ufs_access() so that it passes owner uid and gid information
into vaccess_acl_posix1e().
Pointed out by: jedger
Obtained from: TrustedBSD Project
2001-04-17 04:33:34 +00:00
|
|
|
dac_granted &= acl_mask_granted;
|
2001-03-06 17:28:24 +00:00
|
|
|
|
In my first reading of POSIX.1e, I misinterpreted handling of the
ACL_USER_OBJ and ACL_GROUP_OBJ fields, believing that modification of the
access ACL could be used by privileged processes to change file/directory
ownership. In fact, this is incorrect; ACL_*_OBJ (+ ACL_MASK and
ACL_OTHER) should have undefined ae_id fields; this commit attempts
to correct that misunderstanding.
o Modify arguments to vaccess_acl_posix1e() to accept the uid and gid
associated with the vnode, as those can no longer be extracted from
the ACL passed as an argument. Perform all comparisons against
the passed arguments. This actually has the effect of simplifying
a number of components of this call, as well as reducing the indent
level, but now seperates handling of ACL_GROUP_OBJ from ACL_GROUP.
o Modify acl_posix1e_check() to return EINVAL if the ae_id field of
any of the ACL_{USER_OBJ,GROUP_OBJ,MASK,OTHER} entries is a value
other than ACL_UNDEFINED_ID. As a temporary work-around to allow
clean upgrades, set the ae_id field to ACL_UNDEFINED_ID before
each check so that this cannot cause a failure in the short term
(this work-around will be removed when the userland libraries and
utilities are updated to take this change into account).
o Modify ufs_sync_acl_from_inode() so that it forces
ACL_{USER_OBJ,GROUP_OBJ,MASK,OTHER} ae_id fields to ACL_UNDEFINED_ID
when synchronizing the ACL from the inode.
o Modify ufs_sync_inode_from_acl to not propagate uid and gid
information to the inode from the ACL during ACL update. Also
modify the masking of permission bits that may be set from
ALLPERMS to (S_IRWXU|S_IRWXG|S_IRWXO), as ACLs currently do not
carry none-ACCESSPERMS (S_ISUID, S_ISGID, S_ISTXT).
o Modify ufs_getacl() so that when it emulates an access ACL from
the inode, it initializes the ae_id fields to ACL_UNDEFINED_ID.
o Clean up ufs_setacl() substantially since it is no longer possible
to perform chown/chgrp operations using vop_setacl(), so all the
access control for that can be eliminated.
o Modify ufs_access() so that it passes owner uid and gid information
into vaccess_acl_posix1e().
Pointed out by: jedger
Obtained from: TrustedBSD Project
2001-04-17 04:33:34 +00:00
|
|
|
if ((acc_mode & dac_granted) == acc_mode)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
group_matched = 1;
|
|
|
|
break;
|
2001-03-06 17:28:24 +00:00
|
|
|
|
|
|
|
default:
|
2002-03-19 11:02:06 +00:00
|
|
|
break;
|
2001-03-06 17:28:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (group_matched == 1) {
|
|
|
|
/*
|
|
|
|
* There was a match, but it did not grant rights via
|
|
|
|
* pure DAC. Try again, this time with privilege.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < acl->acl_cnt; i++) {
|
|
|
|
switch (acl->acl_entry[i].ae_tag) {
|
|
|
|
case ACL_GROUP_OBJ:
|
2001-04-29 19:53:50 +00:00
|
|
|
if (!groupmember(file_gid, cred))
|
In my first reading of POSIX.1e, I misinterpreted handling of the
ACL_USER_OBJ and ACL_GROUP_OBJ fields, believing that modification of the
access ACL could be used by privileged processes to change file/directory
ownership. In fact, this is incorrect; ACL_*_OBJ (+ ACL_MASK and
ACL_OTHER) should have undefined ae_id fields; this commit attempts
to correct that misunderstanding.
o Modify arguments to vaccess_acl_posix1e() to accept the uid and gid
associated with the vnode, as those can no longer be extracted from
the ACL passed as an argument. Perform all comparisons against
the passed arguments. This actually has the effect of simplifying
a number of components of this call, as well as reducing the indent
level, but now seperates handling of ACL_GROUP_OBJ from ACL_GROUP.
o Modify acl_posix1e_check() to return EINVAL if the ae_id field of
any of the ACL_{USER_OBJ,GROUP_OBJ,MASK,OTHER} entries is a value
other than ACL_UNDEFINED_ID. As a temporary work-around to allow
clean upgrades, set the ae_id field to ACL_UNDEFINED_ID before
each check so that this cannot cause a failure in the short term
(this work-around will be removed when the userland libraries and
utilities are updated to take this change into account).
o Modify ufs_sync_acl_from_inode() so that it forces
ACL_{USER_OBJ,GROUP_OBJ,MASK,OTHER} ae_id fields to ACL_UNDEFINED_ID
when synchronizing the ACL from the inode.
o Modify ufs_sync_inode_from_acl to not propagate uid and gid
information to the inode from the ACL during ACL update. Also
modify the masking of permission bits that may be set from
ALLPERMS to (S_IRWXU|S_IRWXG|S_IRWXO), as ACLs currently do not
carry none-ACCESSPERMS (S_ISUID, S_ISGID, S_ISTXT).
o Modify ufs_getacl() so that when it emulates an access ACL from
the inode, it initializes the ae_id fields to ACL_UNDEFINED_ID.
o Clean up ufs_setacl() substantially since it is no longer possible
to perform chown/chgrp operations using vop_setacl(), so all the
access control for that can be eliminated.
o Modify ufs_access() so that it passes owner uid and gid information
into vaccess_acl_posix1e().
Pointed out by: jedger
Obtained from: TrustedBSD Project
2001-04-17 04:33:34 +00:00
|
|
|
break;
|
|
|
|
dac_granted = 0;
|
|
|
|
if (acl->acl_entry[i].ae_perm & ACL_EXECUTE)
|
2001-03-06 17:28:24 +00:00
|
|
|
dac_granted |= VEXEC;
|
In my first reading of POSIX.1e, I misinterpreted handling of the
ACL_USER_OBJ and ACL_GROUP_OBJ fields, believing that modification of the
access ACL could be used by privileged processes to change file/directory
ownership. In fact, this is incorrect; ACL_*_OBJ (+ ACL_MASK and
ACL_OTHER) should have undefined ae_id fields; this commit attempts
to correct that misunderstanding.
o Modify arguments to vaccess_acl_posix1e() to accept the uid and gid
associated with the vnode, as those can no longer be extracted from
the ACL passed as an argument. Perform all comparisons against
the passed arguments. This actually has the effect of simplifying
a number of components of this call, as well as reducing the indent
level, but now seperates handling of ACL_GROUP_OBJ from ACL_GROUP.
o Modify acl_posix1e_check() to return EINVAL if the ae_id field of
any of the ACL_{USER_OBJ,GROUP_OBJ,MASK,OTHER} entries is a value
other than ACL_UNDEFINED_ID. As a temporary work-around to allow
clean upgrades, set the ae_id field to ACL_UNDEFINED_ID before
each check so that this cannot cause a failure in the short term
(this work-around will be removed when the userland libraries and
utilities are updated to take this change into account).
o Modify ufs_sync_acl_from_inode() so that it forces
ACL_{USER_OBJ,GROUP_OBJ,MASK,OTHER} ae_id fields to ACL_UNDEFINED_ID
when synchronizing the ACL from the inode.
o Modify ufs_sync_inode_from_acl to not propagate uid and gid
information to the inode from the ACL during ACL update. Also
modify the masking of permission bits that may be set from
ALLPERMS to (S_IRWXU|S_IRWXG|S_IRWXO), as ACLs currently do not
carry none-ACCESSPERMS (S_ISUID, S_ISGID, S_ISTXT).
o Modify ufs_getacl() so that when it emulates an access ACL from
the inode, it initializes the ae_id fields to ACL_UNDEFINED_ID.
o Clean up ufs_setacl() substantially since it is no longer possible
to perform chown/chgrp operations using vop_setacl(), so all the
access control for that can be eliminated.
o Modify ufs_access() so that it passes owner uid and gid information
into vaccess_acl_posix1e().
Pointed out by: jedger
Obtained from: TrustedBSD Project
2001-04-17 04:33:34 +00:00
|
|
|
if (acl->acl_entry[i].ae_perm & ACL_READ)
|
|
|
|
dac_granted |= VREAD;
|
|
|
|
if (acl->acl_entry[i].ae_perm & ACL_WRITE)
|
2002-07-22 03:57:07 +00:00
|
|
|
dac_granted |= (VWRITE | VAPPEND);
|
In my first reading of POSIX.1e, I misinterpreted handling of the
ACL_USER_OBJ and ACL_GROUP_OBJ fields, believing that modification of the
access ACL could be used by privileged processes to change file/directory
ownership. In fact, this is incorrect; ACL_*_OBJ (+ ACL_MASK and
ACL_OTHER) should have undefined ae_id fields; this commit attempts
to correct that misunderstanding.
o Modify arguments to vaccess_acl_posix1e() to accept the uid and gid
associated with the vnode, as those can no longer be extracted from
the ACL passed as an argument. Perform all comparisons against
the passed arguments. This actually has the effect of simplifying
a number of components of this call, as well as reducing the indent
level, but now seperates handling of ACL_GROUP_OBJ from ACL_GROUP.
o Modify acl_posix1e_check() to return EINVAL if the ae_id field of
any of the ACL_{USER_OBJ,GROUP_OBJ,MASK,OTHER} entries is a value
other than ACL_UNDEFINED_ID. As a temporary work-around to allow
clean upgrades, set the ae_id field to ACL_UNDEFINED_ID before
each check so that this cannot cause a failure in the short term
(this work-around will be removed when the userland libraries and
utilities are updated to take this change into account).
o Modify ufs_sync_acl_from_inode() so that it forces
ACL_{USER_OBJ,GROUP_OBJ,MASK,OTHER} ae_id fields to ACL_UNDEFINED_ID
when synchronizing the ACL from the inode.
o Modify ufs_sync_inode_from_acl to not propagate uid and gid
information to the inode from the ACL during ACL update. Also
modify the masking of permission bits that may be set from
ALLPERMS to (S_IRWXU|S_IRWXG|S_IRWXO), as ACLs currently do not
carry none-ACCESSPERMS (S_ISUID, S_ISGID, S_ISTXT).
o Modify ufs_getacl() so that when it emulates an access ACL from
the inode, it initializes the ae_id fields to ACL_UNDEFINED_ID.
o Clean up ufs_setacl() substantially since it is no longer possible
to perform chown/chgrp operations using vop_setacl(), so all the
access control for that can be eliminated.
o Modify ufs_access() so that it passes owner uid and gid information
into vaccess_acl_posix1e().
Pointed out by: jedger
Obtained from: TrustedBSD Project
2001-04-17 04:33:34 +00:00
|
|
|
dac_granted &= acl_mask_granted;
|
|
|
|
|
|
|
|
if ((acc_mode & (dac_granted | cap_granted)) !=
|
|
|
|
acc_mode)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (privused != NULL)
|
|
|
|
*privused = 1;
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
case ACL_GROUP:
|
|
|
|
if (!groupmember(acl->acl_entry[i].ae_id,
|
|
|
|
cred))
|
|
|
|
break;
|
|
|
|
dac_granted = 0;
|
|
|
|
if (acl->acl_entry[i].ae_perm & ACL_EXECUTE)
|
|
|
|
dac_granted |= VEXEC;
|
|
|
|
if (acl->acl_entry[i].ae_perm & ACL_READ)
|
|
|
|
dac_granted |= VREAD;
|
|
|
|
if (acl->acl_entry[i].ae_perm & ACL_WRITE)
|
2002-07-22 03:57:07 +00:00
|
|
|
dac_granted |= (VWRITE | VAPPEND);
|
In my first reading of POSIX.1e, I misinterpreted handling of the
ACL_USER_OBJ and ACL_GROUP_OBJ fields, believing that modification of the
access ACL could be used by privileged processes to change file/directory
ownership. In fact, this is incorrect; ACL_*_OBJ (+ ACL_MASK and
ACL_OTHER) should have undefined ae_id fields; this commit attempts
to correct that misunderstanding.
o Modify arguments to vaccess_acl_posix1e() to accept the uid and gid
associated with the vnode, as those can no longer be extracted from
the ACL passed as an argument. Perform all comparisons against
the passed arguments. This actually has the effect of simplifying
a number of components of this call, as well as reducing the indent
level, but now seperates handling of ACL_GROUP_OBJ from ACL_GROUP.
o Modify acl_posix1e_check() to return EINVAL if the ae_id field of
any of the ACL_{USER_OBJ,GROUP_OBJ,MASK,OTHER} entries is a value
other than ACL_UNDEFINED_ID. As a temporary work-around to allow
clean upgrades, set the ae_id field to ACL_UNDEFINED_ID before
each check so that this cannot cause a failure in the short term
(this work-around will be removed when the userland libraries and
utilities are updated to take this change into account).
o Modify ufs_sync_acl_from_inode() so that it forces
ACL_{USER_OBJ,GROUP_OBJ,MASK,OTHER} ae_id fields to ACL_UNDEFINED_ID
when synchronizing the ACL from the inode.
o Modify ufs_sync_inode_from_acl to not propagate uid and gid
information to the inode from the ACL during ACL update. Also
modify the masking of permission bits that may be set from
ALLPERMS to (S_IRWXU|S_IRWXG|S_IRWXO), as ACLs currently do not
carry none-ACCESSPERMS (S_ISUID, S_ISGID, S_ISTXT).
o Modify ufs_getacl() so that when it emulates an access ACL from
the inode, it initializes the ae_id fields to ACL_UNDEFINED_ID.
o Clean up ufs_setacl() substantially since it is no longer possible
to perform chown/chgrp operations using vop_setacl(), so all the
access control for that can be eliminated.
o Modify ufs_access() so that it passes owner uid and gid information
into vaccess_acl_posix1e().
Pointed out by: jedger
Obtained from: TrustedBSD Project
2001-04-17 04:33:34 +00:00
|
|
|
dac_granted &= acl_mask_granted;
|
|
|
|
|
|
|
|
if ((acc_mode & (dac_granted | cap_granted)) !=
|
|
|
|
acc_mode)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (privused != NULL)
|
|
|
|
*privused = 1;
|
|
|
|
return (0);
|
|
|
|
|
2001-03-06 17:28:24 +00:00
|
|
|
default:
|
2002-03-19 11:02:06 +00:00
|
|
|
break;
|
2001-03-06 17:28:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Even with privilege, group membership was not sufficient.
|
|
|
|
* Return failure.
|
|
|
|
*/
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Fall back on ACL_OTHER. ACL_MASK is not applied to ACL_OTHER.
|
|
|
|
*/
|
|
|
|
dac_granted = 0;
|
2001-04-11 02:19:01 +00:00
|
|
|
if (acl_other->ae_perm & ACL_EXECUTE)
|
2001-03-06 17:28:24 +00:00
|
|
|
dac_granted |= VEXEC;
|
2001-04-11 02:19:01 +00:00
|
|
|
if (acl_other->ae_perm & ACL_READ)
|
2001-03-06 17:28:24 +00:00
|
|
|
dac_granted |= VREAD;
|
2001-04-11 02:19:01 +00:00
|
|
|
if (acl_other->ae_perm & ACL_WRITE)
|
2002-07-22 03:57:07 +00:00
|
|
|
dac_granted |= (VWRITE | VAPPEND);
|
2001-03-06 17:28:24 +00:00
|
|
|
|
|
|
|
if ((acc_mode & dac_granted) == acc_mode)
|
|
|
|
return (0);
|
|
|
|
if ((acc_mode & (dac_granted | cap_granted)) == acc_mode) {
|
|
|
|
if (privused != NULL)
|
|
|
|
*privused = 1;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
error:
|
|
|
|
return ((acc_mode & VADMIN) ? EPERM : EACCES);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2002-05-16 21:28:32 +00:00
|
|
|
* For the purposes of filesystems maintaining the _OBJ entries in an
|
2001-03-06 17:28:24 +00:00
|
|
|
* inode with a mode_t field, this routine converts a mode_t entry
|
|
|
|
* to an acl_perm_t.
|
|
|
|
*/
|
|
|
|
acl_perm_t
|
|
|
|
acl_posix1e_mode_to_perm(acl_tag_t tag, mode_t mode)
|
|
|
|
{
|
|
|
|
acl_perm_t perm = 0;
|
|
|
|
|
|
|
|
switch(tag) {
|
|
|
|
case ACL_USER_OBJ:
|
|
|
|
if (mode & S_IXUSR)
|
2001-04-11 02:19:01 +00:00
|
|
|
perm |= ACL_EXECUTE;
|
2001-03-06 17:28:24 +00:00
|
|
|
if (mode & S_IRUSR)
|
2001-04-11 02:19:01 +00:00
|
|
|
perm |= ACL_READ;
|
2001-03-06 17:28:24 +00:00
|
|
|
if (mode & S_IWUSR)
|
2001-04-11 02:19:01 +00:00
|
|
|
perm |= ACL_WRITE;
|
2001-03-06 17:28:24 +00:00
|
|
|
return (perm);
|
|
|
|
|
|
|
|
case ACL_GROUP_OBJ:
|
|
|
|
if (mode & S_IXGRP)
|
2001-04-11 02:19:01 +00:00
|
|
|
perm |= ACL_EXECUTE;
|
2001-03-06 17:28:24 +00:00
|
|
|
if (mode & S_IRGRP)
|
2001-04-11 02:19:01 +00:00
|
|
|
perm |= ACL_READ;
|
2001-03-06 17:28:24 +00:00
|
|
|
if (mode & S_IWGRP)
|
2001-04-11 02:19:01 +00:00
|
|
|
perm |= ACL_WRITE;
|
2001-03-06 17:28:24 +00:00
|
|
|
return (perm);
|
|
|
|
|
|
|
|
case ACL_OTHER:
|
|
|
|
if (mode & S_IXOTH)
|
2001-04-11 02:19:01 +00:00
|
|
|
perm |= ACL_EXECUTE;
|
2001-03-06 17:28:24 +00:00
|
|
|
if (mode & S_IROTH)
|
2001-04-11 02:19:01 +00:00
|
|
|
perm |= ACL_READ;
|
2001-03-06 17:28:24 +00:00
|
|
|
if (mode & S_IWOTH)
|
2001-04-11 02:19:01 +00:00
|
|
|
perm |= ACL_WRITE;
|
2001-03-06 17:28:24 +00:00
|
|
|
return (perm);
|
|
|
|
|
|
|
|
default:
|
|
|
|
printf("acl_posix1e_mode_to_perm: invalid tag (%d)\n", tag);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Given inode information (uid, gid, mode), return an acl entry of the
|
|
|
|
* appropriate type.
|
|
|
|
*/
|
|
|
|
struct acl_entry
|
|
|
|
acl_posix1e_mode_to_entry(acl_tag_t tag, uid_t uid, gid_t gid, mode_t mode)
|
|
|
|
{
|
|
|
|
struct acl_entry acl_entry;
|
|
|
|
|
|
|
|
acl_entry.ae_tag = tag;
|
|
|
|
acl_entry.ae_perm = acl_posix1e_mode_to_perm(tag, mode);
|
|
|
|
switch(tag) {
|
|
|
|
case ACL_USER_OBJ:
|
|
|
|
acl_entry.ae_id = uid;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ACL_GROUP_OBJ:
|
|
|
|
acl_entry.ae_id = gid;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ACL_OTHER:
|
2001-09-01 23:16:02 +00:00
|
|
|
acl_entry.ae_id = ACL_UNDEFINED_ID;
|
2001-03-06 17:28:24 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2001-09-01 23:16:02 +00:00
|
|
|
acl_entry.ae_id = ACL_UNDEFINED_ID;
|
2001-03-06 17:28:24 +00:00
|
|
|
printf("acl_posix1e_mode_to_entry: invalid tag (%d)\n", tag);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (acl_entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Utility function to generate a file mode given appropriate ACL entries.
|
|
|
|
*/
|
|
|
|
mode_t
|
|
|
|
acl_posix1e_perms_to_mode(struct acl_entry *acl_user_obj_entry,
|
|
|
|
struct acl_entry *acl_group_obj_entry, struct acl_entry *acl_other_entry)
|
|
|
|
{
|
|
|
|
mode_t mode;
|
|
|
|
|
|
|
|
mode = 0;
|
2001-04-11 02:19:01 +00:00
|
|
|
if (acl_user_obj_entry->ae_perm & ACL_EXECUTE)
|
2001-03-06 17:28:24 +00:00
|
|
|
mode |= S_IXUSR;
|
2001-04-11 02:19:01 +00:00
|
|
|
if (acl_user_obj_entry->ae_perm & ACL_READ)
|
2001-03-06 17:28:24 +00:00
|
|
|
mode |= S_IRUSR;
|
2001-04-11 02:19:01 +00:00
|
|
|
if (acl_user_obj_entry->ae_perm & ACL_WRITE)
|
2001-03-06 17:28:24 +00:00
|
|
|
mode |= S_IWUSR;
|
2001-04-11 02:19:01 +00:00
|
|
|
if (acl_group_obj_entry->ae_perm & ACL_EXECUTE)
|
2001-03-06 17:28:24 +00:00
|
|
|
mode |= S_IXGRP;
|
2001-04-11 02:19:01 +00:00
|
|
|
if (acl_group_obj_entry->ae_perm & ACL_READ)
|
2001-03-06 17:28:24 +00:00
|
|
|
mode |= S_IRGRP;
|
2001-04-11 02:19:01 +00:00
|
|
|
if (acl_group_obj_entry->ae_perm & ACL_WRITE)
|
2001-03-06 17:28:24 +00:00
|
|
|
mode |= S_IWGRP;
|
2001-04-11 02:19:01 +00:00
|
|
|
if (acl_other_entry->ae_perm & ACL_EXECUTE)
|
2001-03-06 17:28:24 +00:00
|
|
|
mode |= S_IXOTH;
|
2001-04-11 02:19:01 +00:00
|
|
|
if (acl_other_entry->ae_perm & ACL_READ)
|
2001-03-06 17:28:24 +00:00
|
|
|
mode |= S_IROTH;
|
2001-04-11 02:19:01 +00:00
|
|
|
if (acl_other_entry->ae_perm & ACL_WRITE)
|
2001-03-06 17:28:24 +00:00
|
|
|
mode |= S_IWOTH;
|
|
|
|
|
|
|
|
return (mode);
|
|
|
|
}
|
|
|
|
|
2003-08-04 02:13:05 +00:00
|
|
|
/*
|
|
|
|
* Utility function to generate a file mode given a complete POSIX.1e
|
|
|
|
* access ACL. Note that if the ACL is improperly formed, this may
|
|
|
|
* result in a panic.
|
|
|
|
*/
|
|
|
|
mode_t
|
|
|
|
acl_posix1e_acl_to_mode(struct acl *acl)
|
|
|
|
{
|
|
|
|
struct acl_entry *acl_mask, *acl_user_obj, *acl_group_obj, *acl_other;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find the ACL entries relevant to a POSIX permission mode.
|
|
|
|
*/
|
|
|
|
acl_user_obj = acl_group_obj = acl_other = acl_mask = NULL;
|
|
|
|
for (i = 0; i < acl->acl_cnt; i++) {
|
|
|
|
switch (acl->acl_entry[i].ae_tag) {
|
|
|
|
case ACL_USER_OBJ:
|
|
|
|
acl_user_obj = &acl->acl_entry[i];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ACL_GROUP_OBJ:
|
|
|
|
acl_group_obj = &acl->acl_entry[i];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ACL_OTHER:
|
|
|
|
acl_other = &acl->acl_entry[i];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ACL_MASK:
|
|
|
|
acl_mask = &acl->acl_entry[i];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ACL_USER:
|
|
|
|
case ACL_GROUP:
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
panic("acl_posix1e_acl_to_mode: bad ae_tag");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (acl_user_obj == NULL || acl_group_obj == NULL || acl_other == NULL)
|
|
|
|
panic("acl_posix1e_acl_to_mode: missing base ae_tags");
|
|
|
|
|
|
|
|
/*
|
|
|
|
* POSIX.1e specifies that if there is an ACL_MASK entry, we replace
|
|
|
|
* the mode "group" bits with its permissions. If there isn't, we
|
|
|
|
* use the ACL_GROUP_OBJ permissions.
|
|
|
|
*/
|
|
|
|
if (acl_mask != NULL)
|
|
|
|
return (acl_posix1e_perms_to_mode(acl_user_obj, acl_mask,
|
|
|
|
acl_other));
|
|
|
|
else
|
|
|
|
return (acl_posix1e_perms_to_mode(acl_user_obj, acl_group_obj,
|
|
|
|
acl_other));
|
|
|
|
}
|
|
|
|
|
2001-03-06 17:28:24 +00:00
|
|
|
/*
|
|
|
|
* Perform a syntactic check of the ACL, sufficient to allow an
|
2002-05-16 21:28:32 +00:00
|
|
|
* implementing filesystem to determine if it should accept this and
|
2001-03-06 17:28:24 +00:00
|
|
|
* rely on the POSIX.1e ACL properties.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
acl_posix1e_check(struct acl *acl)
|
|
|
|
{
|
|
|
|
int num_acl_user_obj, num_acl_user, num_acl_group_obj, num_acl_group;
|
|
|
|
int num_acl_mask, num_acl_other, i;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Verify that the number of entries does not exceed the maximum
|
|
|
|
* defined for acl_t.
|
|
|
|
* Verify that the correct number of various sorts of ae_tags are
|
|
|
|
* present:
|
|
|
|
* Exactly one ACL_USER_OBJ
|
|
|
|
* Exactly one ACL_GROUP_OBJ
|
|
|
|
* Exactly one ACL_OTHER
|
|
|
|
* If any ACL_USER or ACL_GROUP entries appear, then exactly one
|
|
|
|
* ACL_MASK entry must also appear.
|
|
|
|
* Verify that all ae_perm entries are in ACL_PERM_BITS.
|
|
|
|
* Verify all ae_tag entries are understood by this implementation.
|
|
|
|
* Note: Does not check for uniqueness of qualifier (ae_id) field.
|
|
|
|
*/
|
|
|
|
num_acl_user_obj = num_acl_user = num_acl_group_obj = num_acl_group =
|
|
|
|
num_acl_mask = num_acl_other = 0;
|
|
|
|
if (acl->acl_cnt > ACL_MAX_ENTRIES || acl->acl_cnt < 0)
|
|
|
|
return (EINVAL);
|
|
|
|
for (i = 0; i < acl->acl_cnt; i++) {
|
|
|
|
/*
|
|
|
|
* Check for a valid tag.
|
|
|
|
*/
|
|
|
|
switch(acl->acl_entry[i].ae_tag) {
|
|
|
|
case ACL_USER_OBJ:
|
In my first reading of POSIX.1e, I misinterpreted handling of the
ACL_USER_OBJ and ACL_GROUP_OBJ fields, believing that modification of the
access ACL could be used by privileged processes to change file/directory
ownership. In fact, this is incorrect; ACL_*_OBJ (+ ACL_MASK and
ACL_OTHER) should have undefined ae_id fields; this commit attempts
to correct that misunderstanding.
o Modify arguments to vaccess_acl_posix1e() to accept the uid and gid
associated with the vnode, as those can no longer be extracted from
the ACL passed as an argument. Perform all comparisons against
the passed arguments. This actually has the effect of simplifying
a number of components of this call, as well as reducing the indent
level, but now seperates handling of ACL_GROUP_OBJ from ACL_GROUP.
o Modify acl_posix1e_check() to return EINVAL if the ae_id field of
any of the ACL_{USER_OBJ,GROUP_OBJ,MASK,OTHER} entries is a value
other than ACL_UNDEFINED_ID. As a temporary work-around to allow
clean upgrades, set the ae_id field to ACL_UNDEFINED_ID before
each check so that this cannot cause a failure in the short term
(this work-around will be removed when the userland libraries and
utilities are updated to take this change into account).
o Modify ufs_sync_acl_from_inode() so that it forces
ACL_{USER_OBJ,GROUP_OBJ,MASK,OTHER} ae_id fields to ACL_UNDEFINED_ID
when synchronizing the ACL from the inode.
o Modify ufs_sync_inode_from_acl to not propagate uid and gid
information to the inode from the ACL during ACL update. Also
modify the masking of permission bits that may be set from
ALLPERMS to (S_IRWXU|S_IRWXG|S_IRWXO), as ACLs currently do not
carry none-ACCESSPERMS (S_ISUID, S_ISGID, S_ISTXT).
o Modify ufs_getacl() so that when it emulates an access ACL from
the inode, it initializes the ae_id fields to ACL_UNDEFINED_ID.
o Clean up ufs_setacl() substantially since it is no longer possible
to perform chown/chgrp operations using vop_setacl(), so all the
access control for that can be eliminated.
o Modify ufs_access() so that it passes owner uid and gid information
into vaccess_acl_posix1e().
Pointed out by: jedger
Obtained from: TrustedBSD Project
2001-04-17 04:33:34 +00:00
|
|
|
acl->acl_entry[i].ae_id = ACL_UNDEFINED_ID; /* XXX */
|
|
|
|
if (acl->acl_entry[i].ae_id != ACL_UNDEFINED_ID)
|
|
|
|
return (EINVAL);
|
2001-03-06 17:28:24 +00:00
|
|
|
num_acl_user_obj++;
|
|
|
|
break;
|
|
|
|
case ACL_GROUP_OBJ:
|
In my first reading of POSIX.1e, I misinterpreted handling of the
ACL_USER_OBJ and ACL_GROUP_OBJ fields, believing that modification of the
access ACL could be used by privileged processes to change file/directory
ownership. In fact, this is incorrect; ACL_*_OBJ (+ ACL_MASK and
ACL_OTHER) should have undefined ae_id fields; this commit attempts
to correct that misunderstanding.
o Modify arguments to vaccess_acl_posix1e() to accept the uid and gid
associated with the vnode, as those can no longer be extracted from
the ACL passed as an argument. Perform all comparisons against
the passed arguments. This actually has the effect of simplifying
a number of components of this call, as well as reducing the indent
level, but now seperates handling of ACL_GROUP_OBJ from ACL_GROUP.
o Modify acl_posix1e_check() to return EINVAL if the ae_id field of
any of the ACL_{USER_OBJ,GROUP_OBJ,MASK,OTHER} entries is a value
other than ACL_UNDEFINED_ID. As a temporary work-around to allow
clean upgrades, set the ae_id field to ACL_UNDEFINED_ID before
each check so that this cannot cause a failure in the short term
(this work-around will be removed when the userland libraries and
utilities are updated to take this change into account).
o Modify ufs_sync_acl_from_inode() so that it forces
ACL_{USER_OBJ,GROUP_OBJ,MASK,OTHER} ae_id fields to ACL_UNDEFINED_ID
when synchronizing the ACL from the inode.
o Modify ufs_sync_inode_from_acl to not propagate uid and gid
information to the inode from the ACL during ACL update. Also
modify the masking of permission bits that may be set from
ALLPERMS to (S_IRWXU|S_IRWXG|S_IRWXO), as ACLs currently do not
carry none-ACCESSPERMS (S_ISUID, S_ISGID, S_ISTXT).
o Modify ufs_getacl() so that when it emulates an access ACL from
the inode, it initializes the ae_id fields to ACL_UNDEFINED_ID.
o Clean up ufs_setacl() substantially since it is no longer possible
to perform chown/chgrp operations using vop_setacl(), so all the
access control for that can be eliminated.
o Modify ufs_access() so that it passes owner uid and gid information
into vaccess_acl_posix1e().
Pointed out by: jedger
Obtained from: TrustedBSD Project
2001-04-17 04:33:34 +00:00
|
|
|
acl->acl_entry[i].ae_id = ACL_UNDEFINED_ID; /* XXX */
|
|
|
|
if (acl->acl_entry[i].ae_id != ACL_UNDEFINED_ID)
|
|
|
|
return (EINVAL);
|
2001-03-06 17:28:24 +00:00
|
|
|
num_acl_group_obj++;
|
|
|
|
break;
|
|
|
|
case ACL_USER:
|
In my first reading of POSIX.1e, I misinterpreted handling of the
ACL_USER_OBJ and ACL_GROUP_OBJ fields, believing that modification of the
access ACL could be used by privileged processes to change file/directory
ownership. In fact, this is incorrect; ACL_*_OBJ (+ ACL_MASK and
ACL_OTHER) should have undefined ae_id fields; this commit attempts
to correct that misunderstanding.
o Modify arguments to vaccess_acl_posix1e() to accept the uid and gid
associated with the vnode, as those can no longer be extracted from
the ACL passed as an argument. Perform all comparisons against
the passed arguments. This actually has the effect of simplifying
a number of components of this call, as well as reducing the indent
level, but now seperates handling of ACL_GROUP_OBJ from ACL_GROUP.
o Modify acl_posix1e_check() to return EINVAL if the ae_id field of
any of the ACL_{USER_OBJ,GROUP_OBJ,MASK,OTHER} entries is a value
other than ACL_UNDEFINED_ID. As a temporary work-around to allow
clean upgrades, set the ae_id field to ACL_UNDEFINED_ID before
each check so that this cannot cause a failure in the short term
(this work-around will be removed when the userland libraries and
utilities are updated to take this change into account).
o Modify ufs_sync_acl_from_inode() so that it forces
ACL_{USER_OBJ,GROUP_OBJ,MASK,OTHER} ae_id fields to ACL_UNDEFINED_ID
when synchronizing the ACL from the inode.
o Modify ufs_sync_inode_from_acl to not propagate uid and gid
information to the inode from the ACL during ACL update. Also
modify the masking of permission bits that may be set from
ALLPERMS to (S_IRWXU|S_IRWXG|S_IRWXO), as ACLs currently do not
carry none-ACCESSPERMS (S_ISUID, S_ISGID, S_ISTXT).
o Modify ufs_getacl() so that when it emulates an access ACL from
the inode, it initializes the ae_id fields to ACL_UNDEFINED_ID.
o Clean up ufs_setacl() substantially since it is no longer possible
to perform chown/chgrp operations using vop_setacl(), so all the
access control for that can be eliminated.
o Modify ufs_access() so that it passes owner uid and gid information
into vaccess_acl_posix1e().
Pointed out by: jedger
Obtained from: TrustedBSD Project
2001-04-17 04:33:34 +00:00
|
|
|
if (acl->acl_entry[i].ae_id == ACL_UNDEFINED_ID)
|
|
|
|
return (EINVAL);
|
2001-03-06 17:28:24 +00:00
|
|
|
num_acl_user++;
|
|
|
|
break;
|
|
|
|
case ACL_GROUP:
|
In my first reading of POSIX.1e, I misinterpreted handling of the
ACL_USER_OBJ and ACL_GROUP_OBJ fields, believing that modification of the
access ACL could be used by privileged processes to change file/directory
ownership. In fact, this is incorrect; ACL_*_OBJ (+ ACL_MASK and
ACL_OTHER) should have undefined ae_id fields; this commit attempts
to correct that misunderstanding.
o Modify arguments to vaccess_acl_posix1e() to accept the uid and gid
associated with the vnode, as those can no longer be extracted from
the ACL passed as an argument. Perform all comparisons against
the passed arguments. This actually has the effect of simplifying
a number of components of this call, as well as reducing the indent
level, but now seperates handling of ACL_GROUP_OBJ from ACL_GROUP.
o Modify acl_posix1e_check() to return EINVAL if the ae_id field of
any of the ACL_{USER_OBJ,GROUP_OBJ,MASK,OTHER} entries is a value
other than ACL_UNDEFINED_ID. As a temporary work-around to allow
clean upgrades, set the ae_id field to ACL_UNDEFINED_ID before
each check so that this cannot cause a failure in the short term
(this work-around will be removed when the userland libraries and
utilities are updated to take this change into account).
o Modify ufs_sync_acl_from_inode() so that it forces
ACL_{USER_OBJ,GROUP_OBJ,MASK,OTHER} ae_id fields to ACL_UNDEFINED_ID
when synchronizing the ACL from the inode.
o Modify ufs_sync_inode_from_acl to not propagate uid and gid
information to the inode from the ACL during ACL update. Also
modify the masking of permission bits that may be set from
ALLPERMS to (S_IRWXU|S_IRWXG|S_IRWXO), as ACLs currently do not
carry none-ACCESSPERMS (S_ISUID, S_ISGID, S_ISTXT).
o Modify ufs_getacl() so that when it emulates an access ACL from
the inode, it initializes the ae_id fields to ACL_UNDEFINED_ID.
o Clean up ufs_setacl() substantially since it is no longer possible
to perform chown/chgrp operations using vop_setacl(), so all the
access control for that can be eliminated.
o Modify ufs_access() so that it passes owner uid and gid information
into vaccess_acl_posix1e().
Pointed out by: jedger
Obtained from: TrustedBSD Project
2001-04-17 04:33:34 +00:00
|
|
|
if (acl->acl_entry[i].ae_id == ACL_UNDEFINED_ID)
|
|
|
|
return (EINVAL);
|
2001-03-06 17:28:24 +00:00
|
|
|
num_acl_group++;
|
|
|
|
break;
|
|
|
|
case ACL_OTHER:
|
In my first reading of POSIX.1e, I misinterpreted handling of the
ACL_USER_OBJ and ACL_GROUP_OBJ fields, believing that modification of the
access ACL could be used by privileged processes to change file/directory
ownership. In fact, this is incorrect; ACL_*_OBJ (+ ACL_MASK and
ACL_OTHER) should have undefined ae_id fields; this commit attempts
to correct that misunderstanding.
o Modify arguments to vaccess_acl_posix1e() to accept the uid and gid
associated with the vnode, as those can no longer be extracted from
the ACL passed as an argument. Perform all comparisons against
the passed arguments. This actually has the effect of simplifying
a number of components of this call, as well as reducing the indent
level, but now seperates handling of ACL_GROUP_OBJ from ACL_GROUP.
o Modify acl_posix1e_check() to return EINVAL if the ae_id field of
any of the ACL_{USER_OBJ,GROUP_OBJ,MASK,OTHER} entries is a value
other than ACL_UNDEFINED_ID. As a temporary work-around to allow
clean upgrades, set the ae_id field to ACL_UNDEFINED_ID before
each check so that this cannot cause a failure in the short term
(this work-around will be removed when the userland libraries and
utilities are updated to take this change into account).
o Modify ufs_sync_acl_from_inode() so that it forces
ACL_{USER_OBJ,GROUP_OBJ,MASK,OTHER} ae_id fields to ACL_UNDEFINED_ID
when synchronizing the ACL from the inode.
o Modify ufs_sync_inode_from_acl to not propagate uid and gid
information to the inode from the ACL during ACL update. Also
modify the masking of permission bits that may be set from
ALLPERMS to (S_IRWXU|S_IRWXG|S_IRWXO), as ACLs currently do not
carry none-ACCESSPERMS (S_ISUID, S_ISGID, S_ISTXT).
o Modify ufs_getacl() so that when it emulates an access ACL from
the inode, it initializes the ae_id fields to ACL_UNDEFINED_ID.
o Clean up ufs_setacl() substantially since it is no longer possible
to perform chown/chgrp operations using vop_setacl(), so all the
access control for that can be eliminated.
o Modify ufs_access() so that it passes owner uid and gid information
into vaccess_acl_posix1e().
Pointed out by: jedger
Obtained from: TrustedBSD Project
2001-04-17 04:33:34 +00:00
|
|
|
acl->acl_entry[i].ae_id = ACL_UNDEFINED_ID; /* XXX */
|
|
|
|
if (acl->acl_entry[i].ae_id != ACL_UNDEFINED_ID)
|
|
|
|
return (EINVAL);
|
2001-03-06 17:28:24 +00:00
|
|
|
num_acl_other++;
|
|
|
|
break;
|
|
|
|
case ACL_MASK:
|
In my first reading of POSIX.1e, I misinterpreted handling of the
ACL_USER_OBJ and ACL_GROUP_OBJ fields, believing that modification of the
access ACL could be used by privileged processes to change file/directory
ownership. In fact, this is incorrect; ACL_*_OBJ (+ ACL_MASK and
ACL_OTHER) should have undefined ae_id fields; this commit attempts
to correct that misunderstanding.
o Modify arguments to vaccess_acl_posix1e() to accept the uid and gid
associated with the vnode, as those can no longer be extracted from
the ACL passed as an argument. Perform all comparisons against
the passed arguments. This actually has the effect of simplifying
a number of components of this call, as well as reducing the indent
level, but now seperates handling of ACL_GROUP_OBJ from ACL_GROUP.
o Modify acl_posix1e_check() to return EINVAL if the ae_id field of
any of the ACL_{USER_OBJ,GROUP_OBJ,MASK,OTHER} entries is a value
other than ACL_UNDEFINED_ID. As a temporary work-around to allow
clean upgrades, set the ae_id field to ACL_UNDEFINED_ID before
each check so that this cannot cause a failure in the short term
(this work-around will be removed when the userland libraries and
utilities are updated to take this change into account).
o Modify ufs_sync_acl_from_inode() so that it forces
ACL_{USER_OBJ,GROUP_OBJ,MASK,OTHER} ae_id fields to ACL_UNDEFINED_ID
when synchronizing the ACL from the inode.
o Modify ufs_sync_inode_from_acl to not propagate uid and gid
information to the inode from the ACL during ACL update. Also
modify the masking of permission bits that may be set from
ALLPERMS to (S_IRWXU|S_IRWXG|S_IRWXO), as ACLs currently do not
carry none-ACCESSPERMS (S_ISUID, S_ISGID, S_ISTXT).
o Modify ufs_getacl() so that when it emulates an access ACL from
the inode, it initializes the ae_id fields to ACL_UNDEFINED_ID.
o Clean up ufs_setacl() substantially since it is no longer possible
to perform chown/chgrp operations using vop_setacl(), so all the
access control for that can be eliminated.
o Modify ufs_access() so that it passes owner uid and gid information
into vaccess_acl_posix1e().
Pointed out by: jedger
Obtained from: TrustedBSD Project
2001-04-17 04:33:34 +00:00
|
|
|
acl->acl_entry[i].ae_id = ACL_UNDEFINED_ID; /* XXX */
|
|
|
|
if (acl->acl_entry[i].ae_id != ACL_UNDEFINED_ID)
|
|
|
|
return (EINVAL);
|
2001-03-06 17:28:24 +00:00
|
|
|
num_acl_mask++;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Check for valid perm entries.
|
|
|
|
*/
|
|
|
|
if ((acl->acl_entry[i].ae_perm | ACL_PERM_BITS) !=
|
|
|
|
ACL_PERM_BITS)
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
if ((num_acl_user_obj != 1) || (num_acl_group_obj != 1) ||
|
|
|
|
(num_acl_other != 1) || (num_acl_mask != 0 && num_acl_mask != 1))
|
|
|
|
return (EINVAL);
|
|
|
|
if (((num_acl_group != 0) || (num_acl_user != 0)) &&
|
|
|
|
(num_acl_mask != 1))
|
|
|
|
return (EINVAL);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2003-08-04 02:13:05 +00:00
|
|
|
/*
|
|
|
|
* Given a requested mode for a new object, and a default ACL, combine
|
|
|
|
* the two to produce a new mode. Be careful not to clear any bits that
|
|
|
|
* aren't intended to be affected by the POSIX.1e ACL. Eventually,
|
|
|
|
* this might also take the cmask as an argument, if we push that down
|
|
|
|
* into per-filesystem-code.
|
|
|
|
*/
|
|
|
|
mode_t
|
|
|
|
acl_posix1e_newfilemode(mode_t cmode, struct acl *dacl)
|
|
|
|
{
|
|
|
|
mode_t mode;
|
|
|
|
|
|
|
|
mode = cmode;
|
|
|
|
/*
|
|
|
|
* The current composition policy is that a permission bit must
|
|
|
|
* be set in *both* the ACL and the requested creation mode for
|
|
|
|
* it to appear in the resulting mode/ACL. First clear any
|
|
|
|
* possibly effected bits, then reconstruct.
|
|
|
|
*/
|
|
|
|
mode &= ACL_PRESERVE_MASK;
|
|
|
|
mode |= (ACL_OVERRIDE_MASK & cmode & acl_posix1e_acl_to_mode(dacl));
|
|
|
|
|
|
|
|
return (mode);
|
|
|
|
}
|
|
|
|
|
1999-12-19 06:08:07 +00:00
|
|
|
/*
|
|
|
|
* These calls wrap the real vnode operations, and are called by the
|
|
|
|
* syscall code once the syscall has converted the path or file
|
|
|
|
* descriptor to a vnode (unlocked). The aclp pointer is assumed
|
|
|
|
* still to point to userland, so this should not be consumed within
|
|
|
|
* the kernel except by syscall code. Other code should directly
|
|
|
|
* invoke VOP_{SET,GET}ACL.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Given a vnode, set its ACL.
|
|
|
|
*/
|
|
|
|
static int
|
2001-10-27 05:45:42 +00:00
|
|
|
vacl_set_acl(struct thread *td, struct vnode *vp, acl_type_t type,
|
2000-01-19 06:07:34 +00:00
|
|
|
struct acl *aclp)
|
1999-12-19 06:08:07 +00:00
|
|
|
{
|
|
|
|
struct acl inkernacl;
|
2002-02-04 17:58:15 +00:00
|
|
|
struct mount *mp;
|
1999-12-19 06:08:07 +00:00
|
|
|
int error;
|
|
|
|
|
|
|
|
error = copyin(aclp, &inkernacl, sizeof(struct acl));
|
|
|
|
if (error)
|
|
|
|
return(error);
|
2002-02-04 17:58:15 +00:00
|
|
|
error = vn_start_write(vp, &mp, V_WAIT | PCATCH);
|
|
|
|
if (error != 0)
|
|
|
|
return (error);
|
2002-02-27 18:32:23 +00:00
|
|
|
VOP_LEASE(vp, td, td->td_ucred, LEASE_WRITE);
|
2001-09-12 08:38:13 +00:00
|
|
|
vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
|
2002-08-01 01:04:16 +00:00
|
|
|
#ifdef MAC
|
|
|
|
error = mac_check_vnode_setacl(td->td_ucred, vp, type, &inkernacl);
|
|
|
|
if (error != 0)
|
|
|
|
goto out;
|
|
|
|
#endif
|
2002-02-27 18:32:23 +00:00
|
|
|
error = VOP_SETACL(vp, type, &inkernacl, td->td_ucred, td);
|
2002-08-01 01:04:16 +00:00
|
|
|
#ifdef MAC
|
|
|
|
out:
|
|
|
|
#endif
|
2001-09-12 08:38:13 +00:00
|
|
|
VOP_UNLOCK(vp, 0, td);
|
2002-02-04 17:58:15 +00:00
|
|
|
vn_finished_write(mp);
|
2001-01-27 00:01:31 +00:00
|
|
|
return(error);
|
1999-12-19 06:08:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Given a vnode, get its ACL.
|
|
|
|
*/
|
|
|
|
static int
|
2001-10-27 05:45:42 +00:00
|
|
|
vacl_get_acl(struct thread *td, struct vnode *vp, acl_type_t type,
|
1999-12-19 06:08:07 +00:00
|
|
|
struct acl *aclp)
|
|
|
|
{
|
|
|
|
struct acl inkernelacl;
|
|
|
|
int error;
|
|
|
|
|
2002-02-27 18:32:23 +00:00
|
|
|
VOP_LEASE(vp, td, td->td_ucred, LEASE_WRITE);
|
2001-09-12 08:38:13 +00:00
|
|
|
vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
|
2002-08-01 01:04:16 +00:00
|
|
|
#ifdef MAC
|
|
|
|
error = mac_check_vnode_getacl(td->td_ucred, vp, type);
|
|
|
|
if (error != 0)
|
|
|
|
goto out;
|
|
|
|
#endif
|
2002-02-27 18:32:23 +00:00
|
|
|
error = VOP_GETACL(vp, type, &inkernelacl, td->td_ucred, td);
|
2002-08-01 01:04:16 +00:00
|
|
|
#ifdef MAC
|
|
|
|
out:
|
|
|
|
#endif
|
2001-09-12 08:38:13 +00:00
|
|
|
VOP_UNLOCK(vp, 0, td);
|
1999-12-19 06:08:07 +00:00
|
|
|
if (error == 0)
|
|
|
|
error = copyout(&inkernelacl, aclp, sizeof(struct acl));
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Given a vnode, delete its ACL.
|
|
|
|
*/
|
|
|
|
static int
|
2001-10-27 05:45:42 +00:00
|
|
|
vacl_delete(struct thread *td, struct vnode *vp, acl_type_t type)
|
1999-12-19 06:08:07 +00:00
|
|
|
{
|
2002-02-04 17:58:15 +00:00
|
|
|
struct mount *mp;
|
1999-12-19 06:08:07 +00:00
|
|
|
int error;
|
|
|
|
|
2002-02-04 17:58:15 +00:00
|
|
|
error = vn_start_write(vp, &mp, V_WAIT | PCATCH);
|
|
|
|
if (error)
|
|
|
|
return (error);
|
2002-02-27 18:32:23 +00:00
|
|
|
VOP_LEASE(vp, td, td->td_ucred, LEASE_WRITE);
|
2001-09-12 08:38:13 +00:00
|
|
|
vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
|
2002-08-01 01:04:16 +00:00
|
|
|
#ifdef MAC
|
|
|
|
error = mac_check_vnode_deleteacl(td->td_ucred, vp, type);
|
|
|
|
if (error)
|
|
|
|
goto out;
|
|
|
|
#endif
|
|
|
|
error = VOP_SETACL(vp, type, 0, td->td_ucred, td);
|
|
|
|
#ifdef MAC
|
|
|
|
out:
|
|
|
|
#endif
|
2001-09-12 08:38:13 +00:00
|
|
|
VOP_UNLOCK(vp, 0, td);
|
2002-02-04 17:58:15 +00:00
|
|
|
vn_finished_write(mp);
|
1999-12-19 06:08:07 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Given a vnode, check whether an ACL is appropriate for it
|
|
|
|
*/
|
|
|
|
static int
|
2001-10-27 05:45:42 +00:00
|
|
|
vacl_aclcheck(struct thread *td, struct vnode *vp, acl_type_t type,
|
1999-12-19 06:08:07 +00:00
|
|
|
struct acl *aclp)
|
|
|
|
{
|
|
|
|
struct acl inkernelacl;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
error = copyin(aclp, &inkernelacl, sizeof(struct acl));
|
|
|
|
if (error)
|
|
|
|
return(error);
|
2002-02-27 18:32:23 +00:00
|
|
|
error = VOP_ACLCHECK(vp, type, &inkernelacl, td->td_ucred, td);
|
1999-12-19 06:08:07 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* syscalls -- convert the path/fd to a vnode, and call vacl_whatever.
|
|
|
|
* Don't need to lock, as the vacl_ code will get/release any locks
|
|
|
|
* required.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Given a file path, get an ACL for it
|
2001-09-01 04:33:22 +00:00
|
|
|
*
|
|
|
|
* MPSAFE
|
1999-12-19 06:08:07 +00:00
|
|
|
*/
|
|
|
|
int
|
2001-10-27 05:45:42 +00:00
|
|
|
__acl_get_file(struct thread *td, struct __acl_get_file_args *uap)
|
1999-12-19 06:08:07 +00:00
|
|
|
{
|
|
|
|
struct nameidata nd;
|
|
|
|
int error;
|
|
|
|
|
2001-09-01 04:33:22 +00:00
|
|
|
mtx_lock(&Giant);
|
2002-12-14 01:56:26 +00:00
|
|
|
NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, uap->path, td);
|
1999-12-19 06:08:07 +00:00
|
|
|
error = namei(&nd);
|
2001-09-01 04:33:22 +00:00
|
|
|
if (error == 0) {
|
2002-12-14 08:18:06 +00:00
|
|
|
error = vacl_get_acl(td, nd.ni_vp, uap->type, uap->aclp);
|
2001-09-01 04:33:22 +00:00
|
|
|
NDFREE(&nd, 0);
|
|
|
|
}
|
|
|
|
mtx_unlock(&Giant);
|
1999-12-19 06:08:07 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2002-12-29 20:28:44 +00:00
|
|
|
/*
|
|
|
|
* Given a file path, get an ACL for it; don't follow links.
|
|
|
|
*
|
|
|
|
* MPSAFE
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
__acl_get_link(struct thread *td, struct __acl_get_link_args *uap)
|
|
|
|
{
|
|
|
|
struct nameidata nd;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
mtx_lock(&Giant);
|
|
|
|
NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_USERSPACE, uap->path, td);
|
|
|
|
error = namei(&nd);
|
|
|
|
if (error == 0) {
|
|
|
|
error = vacl_get_acl(td, nd.ni_vp, uap->type, uap->aclp);
|
|
|
|
NDFREE(&nd, 0);
|
|
|
|
}
|
|
|
|
mtx_unlock(&Giant);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
1999-12-19 06:08:07 +00:00
|
|
|
/*
|
|
|
|
* Given a file path, set an ACL for it
|
2001-09-01 04:33:22 +00:00
|
|
|
*
|
|
|
|
* MPSAFE
|
1999-12-19 06:08:07 +00:00
|
|
|
*/
|
|
|
|
int
|
2001-10-27 05:45:42 +00:00
|
|
|
__acl_set_file(struct thread *td, struct __acl_set_file_args *uap)
|
1999-12-19 06:08:07 +00:00
|
|
|
{
|
|
|
|
struct nameidata nd;
|
|
|
|
int error;
|
|
|
|
|
2001-09-01 04:33:22 +00:00
|
|
|
mtx_lock(&Giant);
|
2002-12-14 01:56:26 +00:00
|
|
|
NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, uap->path, td);
|
1999-12-19 06:08:07 +00:00
|
|
|
error = namei(&nd);
|
2001-09-01 04:33:22 +00:00
|
|
|
if (error == 0) {
|
2002-12-14 08:18:06 +00:00
|
|
|
error = vacl_set_acl(td, nd.ni_vp, uap->type, uap->aclp);
|
2001-09-01 04:33:22 +00:00
|
|
|
NDFREE(&nd, 0);
|
|
|
|
}
|
|
|
|
mtx_unlock(&Giant);
|
1999-12-19 06:08:07 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2002-12-29 20:28:44 +00:00
|
|
|
/*
|
|
|
|
* Given a file path, set an ACL for it; don't follow links.
|
|
|
|
*
|
|
|
|
* MPSAFE
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
__acl_set_link(struct thread *td, struct __acl_set_link_args *uap)
|
|
|
|
{
|
|
|
|
struct nameidata nd;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
mtx_lock(&Giant);
|
|
|
|
NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_USERSPACE, uap->path, td);
|
|
|
|
error = namei(&nd);
|
|
|
|
if (error == 0) {
|
|
|
|
error = vacl_set_acl(td, nd.ni_vp, uap->type, uap->aclp);
|
|
|
|
NDFREE(&nd, 0);
|
|
|
|
}
|
|
|
|
mtx_unlock(&Giant);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
1999-12-19 06:08:07 +00:00
|
|
|
/*
|
|
|
|
* Given a file descriptor, get an ACL for it
|
2001-09-01 04:33:22 +00:00
|
|
|
*
|
|
|
|
* MPSAFE
|
1999-12-19 06:08:07 +00:00
|
|
|
*/
|
|
|
|
int
|
2001-10-27 05:45:42 +00:00
|
|
|
__acl_get_fd(struct thread *td, struct __acl_get_fd_args *uap)
|
1999-12-19 06:08:07 +00:00
|
|
|
{
|
|
|
|
struct file *fp;
|
|
|
|
int error;
|
|
|
|
|
2001-09-01 04:33:22 +00:00
|
|
|
mtx_lock(&Giant);
|
2002-12-14 01:56:26 +00:00
|
|
|
error = getvnode(td->td_proc->p_fd, uap->filedes, &fp);
|
2001-09-01 04:33:22 +00:00
|
|
|
if (error == 0) {
|
2003-06-22 08:41:43 +00:00
|
|
|
error = vacl_get_acl(td, fp->f_vnode, uap->type, uap->aclp);
|
2002-01-13 11:58:06 +00:00
|
|
|
fdrop(fp, td);
|
2001-09-01 04:33:22 +00:00
|
|
|
}
|
|
|
|
mtx_unlock(&Giant);
|
|
|
|
return (error);
|
1999-12-19 06:08:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Given a file descriptor, set an ACL for it
|
2001-09-01 04:33:22 +00:00
|
|
|
*
|
|
|
|
* MPSAFE
|
1999-12-19 06:08:07 +00:00
|
|
|
*/
|
|
|
|
int
|
2001-10-27 05:45:42 +00:00
|
|
|
__acl_set_fd(struct thread *td, struct __acl_set_fd_args *uap)
|
1999-12-19 06:08:07 +00:00
|
|
|
{
|
|
|
|
struct file *fp;
|
|
|
|
int error;
|
|
|
|
|
2001-09-01 04:33:22 +00:00
|
|
|
mtx_lock(&Giant);
|
2002-12-14 01:56:26 +00:00
|
|
|
error = getvnode(td->td_proc->p_fd, uap->filedes, &fp);
|
2001-09-01 04:33:22 +00:00
|
|
|
if (error == 0) {
|
2003-06-22 08:41:43 +00:00
|
|
|
error = vacl_set_acl(td, fp->f_vnode, uap->type, uap->aclp);
|
2002-01-13 11:58:06 +00:00
|
|
|
fdrop(fp, td);
|
2001-09-01 04:33:22 +00:00
|
|
|
}
|
|
|
|
mtx_unlock(&Giant);
|
|
|
|
return (error);
|
1999-12-19 06:08:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Given a file path, delete an ACL from it.
|
2001-09-01 04:33:22 +00:00
|
|
|
*
|
|
|
|
* MPSAFE
|
1999-12-19 06:08:07 +00:00
|
|
|
*/
|
|
|
|
int
|
2001-10-27 05:45:42 +00:00
|
|
|
__acl_delete_file(struct thread *td, struct __acl_delete_file_args *uap)
|
1999-12-19 06:08:07 +00:00
|
|
|
{
|
|
|
|
struct nameidata nd;
|
|
|
|
int error;
|
|
|
|
|
2001-09-01 04:33:22 +00:00
|
|
|
mtx_lock(&Giant);
|
2002-12-14 01:56:26 +00:00
|
|
|
NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, uap->path, td);
|
1999-12-19 06:08:07 +00:00
|
|
|
error = namei(&nd);
|
2001-09-01 04:33:22 +00:00
|
|
|
if (error == 0) {
|
2002-12-14 01:56:26 +00:00
|
|
|
error = vacl_delete(td, nd.ni_vp, uap->type);
|
2001-09-01 04:33:22 +00:00
|
|
|
NDFREE(&nd, 0);
|
|
|
|
}
|
|
|
|
mtx_unlock(&Giant);
|
1999-12-19 06:08:07 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2002-12-29 20:28:44 +00:00
|
|
|
/*
|
|
|
|
* Given a file path, delete an ACL from it; don't follow links.
|
|
|
|
*
|
|
|
|
* MPSAFE
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
__acl_delete_link(struct thread *td, struct __acl_delete_link_args *uap)
|
|
|
|
{
|
|
|
|
struct nameidata nd;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
mtx_lock(&Giant);
|
|
|
|
NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_USERSPACE, uap->path, td);
|
|
|
|
error = namei(&nd);
|
|
|
|
if (error == 0) {
|
|
|
|
error = vacl_delete(td, nd.ni_vp, uap->type);
|
|
|
|
NDFREE(&nd, 0);
|
|
|
|
}
|
|
|
|
mtx_unlock(&Giant);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
1999-12-19 06:08:07 +00:00
|
|
|
/*
|
|
|
|
* Given a file path, delete an ACL from it.
|
2001-09-01 04:33:22 +00:00
|
|
|
*
|
|
|
|
* MPSAFE
|
1999-12-19 06:08:07 +00:00
|
|
|
*/
|
|
|
|
int
|
2001-10-27 05:45:42 +00:00
|
|
|
__acl_delete_fd(struct thread *td, struct __acl_delete_fd_args *uap)
|
1999-12-19 06:08:07 +00:00
|
|
|
{
|
|
|
|
struct file *fp;
|
|
|
|
int error;
|
|
|
|
|
2001-09-01 04:33:22 +00:00
|
|
|
mtx_lock(&Giant);
|
2002-12-14 01:56:26 +00:00
|
|
|
error = getvnode(td->td_proc->p_fd, uap->filedes, &fp);
|
2001-09-01 04:33:22 +00:00
|
|
|
if (error == 0) {
|
2003-06-22 08:41:43 +00:00
|
|
|
error = vacl_delete(td, fp->f_vnode, uap->type);
|
2002-01-13 11:58:06 +00:00
|
|
|
fdrop(fp, td);
|
2001-09-01 04:33:22 +00:00
|
|
|
}
|
|
|
|
mtx_unlock(&Giant);
|
1999-12-19 06:08:07 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Given a file path, check an ACL for it
|
2001-09-01 04:33:22 +00:00
|
|
|
*
|
|
|
|
* MPSAFE
|
1999-12-19 06:08:07 +00:00
|
|
|
*/
|
|
|
|
int
|
2001-10-27 05:45:42 +00:00
|
|
|
__acl_aclcheck_file(struct thread *td, struct __acl_aclcheck_file_args *uap)
|
1999-12-19 06:08:07 +00:00
|
|
|
{
|
|
|
|
struct nameidata nd;
|
|
|
|
int error;
|
|
|
|
|
2001-09-01 04:33:22 +00:00
|
|
|
mtx_lock(&Giant);
|
2002-12-14 01:56:26 +00:00
|
|
|
NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, uap->path, td);
|
1999-12-19 06:08:07 +00:00
|
|
|
error = namei(&nd);
|
2001-09-01 04:33:22 +00:00
|
|
|
if (error == 0) {
|
2002-12-14 08:18:06 +00:00
|
|
|
error = vacl_aclcheck(td, nd.ni_vp, uap->type, uap->aclp);
|
2001-09-01 04:33:22 +00:00
|
|
|
NDFREE(&nd, 0);
|
|
|
|
}
|
|
|
|
mtx_unlock(&Giant);
|
1999-12-19 06:08:07 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2002-12-29 20:28:44 +00:00
|
|
|
/*
|
|
|
|
* Given a file path, check an ACL for it; don't follow links.
|
|
|
|
*
|
|
|
|
* MPSAFE
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
__acl_aclcheck_link(struct thread *td, struct __acl_aclcheck_link_args *uap)
|
|
|
|
{
|
|
|
|
struct nameidata nd;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
mtx_lock(&Giant);
|
|
|
|
NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_USERSPACE, uap->path, td);
|
|
|
|
error = namei(&nd);
|
|
|
|
if (error == 0) {
|
|
|
|
error = vacl_aclcheck(td, nd.ni_vp, uap->type, uap->aclp);
|
|
|
|
NDFREE(&nd, 0);
|
|
|
|
}
|
|
|
|
mtx_unlock(&Giant);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
1999-12-19 06:08:07 +00:00
|
|
|
/*
|
|
|
|
* Given a file descriptor, check an ACL for it
|
2001-09-01 04:33:22 +00:00
|
|
|
*
|
|
|
|
* MPSAFE
|
1999-12-19 06:08:07 +00:00
|
|
|
*/
|
|
|
|
int
|
2001-10-27 05:45:42 +00:00
|
|
|
__acl_aclcheck_fd(struct thread *td, struct __acl_aclcheck_fd_args *uap)
|
1999-12-19 06:08:07 +00:00
|
|
|
{
|
|
|
|
struct file *fp;
|
|
|
|
int error;
|
|
|
|
|
2001-09-01 04:33:22 +00:00
|
|
|
mtx_lock(&Giant);
|
2002-12-14 01:56:26 +00:00
|
|
|
error = getvnode(td->td_proc->p_fd, uap->filedes, &fp);
|
2001-09-01 04:33:22 +00:00
|
|
|
if (error == 0) {
|
2003-06-22 08:41:43 +00:00
|
|
|
error = vacl_aclcheck(td, fp->f_vnode, uap->type, uap->aclp);
|
2002-01-13 11:58:06 +00:00
|
|
|
fdrop(fp, td);
|
2001-09-01 04:33:22 +00:00
|
|
|
}
|
|
|
|
mtx_unlock(&Giant);
|
|
|
|
return (error);
|
1999-12-19 06:08:07 +00:00
|
|
|
}
|