1999-12-19 06:08:07 +00:00
|
|
|
/*-
|
2006-07-06 23:37:39 +00:00
|
|
|
* Copyright (c) 1999-2006 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.
|
2006-07-06 23:37:39 +00:00
|
|
|
*
|
|
|
|
* ACL system calls and other functions common across different ACL types.
|
|
|
|
* Type-specific routines go into subr_acl_<type>.c.
|
1999-12-19 06:08:07 +00:00
|
|
|
*/
|
|
|
|
|
2003-06-11 00:56:59 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
1999-12-19 06:08:07 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/sysproto.h>
|
2011-08-11 12:30:23 +00:00
|
|
|
#include <sys/capability.h>
|
2008-03-31 12:01:21 +00:00
|
|
|
#include <sys/fcntl.h>
|
1999-12-19 06:08:07 +00:00
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/malloc.h>
|
2005-09-17 22:01:14 +00:00
|
|
|
#include <sys/mount.h>
|
1999-12-19 06:08:07 +00:00
|
|
|
#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/acl.h>
|
|
|
|
|
2006-10-22 11:52:19 +00:00
|
|
|
#include <security/mac/mac_framework.h>
|
|
|
|
|
2009-05-22 15:56:43 +00:00
|
|
|
CTASSERT(ACL_MAX_ENTRIES >= OLDACL_MAX_ENTRIES);
|
|
|
|
|
|
|
|
MALLOC_DEFINE(M_ACL, "acl", "Access Control Lists");
|
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
|
|
|
|
2009-05-22 15:56:43 +00:00
|
|
|
int
|
|
|
|
acl_copy_oldacl_into_acl(const struct oldacl *source, struct acl *dest)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (source->acl_cnt < 0 || source->acl_cnt > OLDACL_MAX_ENTRIES)
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
bzero(dest, sizeof(*dest));
|
|
|
|
|
|
|
|
dest->acl_cnt = source->acl_cnt;
|
|
|
|
dest->acl_maxcnt = ACL_MAX_ENTRIES;
|
|
|
|
|
|
|
|
for (i = 0; i < dest->acl_cnt; i++) {
|
|
|
|
dest->acl_entry[i].ae_tag = source->acl_entry[i].ae_tag;
|
|
|
|
dest->acl_entry[i].ae_id = source->acl_entry[i].ae_id;
|
|
|
|
dest->acl_entry[i].ae_perm = source->acl_entry[i].ae_perm;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
acl_copy_acl_into_oldacl(const struct acl *source, struct oldacl *dest)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2010-06-03 13:45:27 +00:00
|
|
|
if (source->acl_cnt > OLDACL_MAX_ENTRIES)
|
2009-05-22 15:56:43 +00:00
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
bzero(dest, sizeof(*dest));
|
|
|
|
|
|
|
|
dest->acl_cnt = source->acl_cnt;
|
|
|
|
|
|
|
|
for (i = 0; i < dest->acl_cnt; i++) {
|
|
|
|
dest->acl_entry[i].ae_tag = source->acl_entry[i].ae_tag;
|
|
|
|
dest->acl_entry[i].ae_id = source->acl_entry[i].ae_id;
|
|
|
|
dest->acl_entry[i].ae_perm = source->acl_entry[i].ae_perm;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* At one time, "struct ACL" was extended in order to add support for NFSv4
|
|
|
|
* ACLs. Instead of creating compatibility versions of all the ACL-related
|
|
|
|
* syscalls, they were left intact. It's possible to find out what the code
|
|
|
|
* calling these syscalls (libc) expects basing on "type" argument - if it's
|
|
|
|
* either ACL_TYPE_ACCESS_OLD or ACL_TYPE_DEFAULT_OLD (which previously were
|
|
|
|
* known as ACL_TYPE_ACCESS and ACL_TYPE_DEFAULT), then it's the "struct
|
|
|
|
* oldacl". If it's something else, then it's the new "struct acl". In the
|
|
|
|
* latter case, the routines below just copyin/copyout the contents. In the
|
|
|
|
* former case, they copyin the "struct oldacl" and convert it to the new
|
|
|
|
* format.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
acl_copyin(void *user_acl, struct acl *kernel_acl, acl_type_t type)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
struct oldacl old;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case ACL_TYPE_ACCESS_OLD:
|
|
|
|
case ACL_TYPE_DEFAULT_OLD:
|
|
|
|
error = copyin(user_acl, &old, sizeof(old));
|
|
|
|
if (error != 0)
|
|
|
|
break;
|
|
|
|
acl_copy_oldacl_into_acl(&old, kernel_acl);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
error = copyin(user_acl, kernel_acl, sizeof(*kernel_acl));
|
|
|
|
if (kernel_acl->acl_maxcnt != ACL_MAX_ENTRIES)
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
acl_copyout(struct acl *kernel_acl, void *user_acl, acl_type_t type)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
struct oldacl old;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case ACL_TYPE_ACCESS_OLD:
|
|
|
|
case ACL_TYPE_DEFAULT_OLD:
|
|
|
|
error = acl_copy_acl_into_oldacl(kernel_acl, &old);
|
|
|
|
if (error != 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
error = copyout(&old, user_acl, sizeof(old));
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2009-10-05 19:56:56 +00:00
|
|
|
if (fuword32((char *)user_acl +
|
2009-05-22 15:56:43 +00:00
|
|
|
offsetof(struct acl, acl_maxcnt)) != ACL_MAX_ENTRIES)
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
error = copyout(kernel_acl, user_acl, sizeof(*kernel_acl));
|
|
|
|
}
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Convert "old" type - ACL_TYPE_{ACCESS,DEFAULT}_OLD - into its "new"
|
2009-12-03 13:29:24 +00:00
|
|
|
* counterpart. It's required for old (pre-NFSv4 ACLs) libc to work
|
2009-05-22 15:56:43 +00:00
|
|
|
* with new kernel. Fixing 'type' for old binaries with new libc
|
|
|
|
* is being done in lib/libc/posix1e/acl_support.c:_acl_type_unold().
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
acl_type_unold(int type)
|
|
|
|
{
|
|
|
|
switch (type) {
|
|
|
|
case ACL_TYPE_ACCESS_OLD:
|
|
|
|
return (ACL_TYPE_ACCESS);
|
|
|
|
|
|
|
|
case ACL_TYPE_DEFAULT_OLD:
|
|
|
|
return (ACL_TYPE_DEFAULT);
|
|
|
|
|
|
|
|
default:
|
|
|
|
return (type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-12-19 06:08:07 +00:00
|
|
|
/*
|
2007-01-12 22:01:03 +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.
|
1999-12-19 06:08:07 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
|
|
{
|
2009-04-18 16:47:33 +00:00
|
|
|
struct acl *inkernelacl;
|
2002-02-04 17:58:15 +00:00
|
|
|
struct mount *mp;
|
1999-12-19 06:08:07 +00:00
|
|
|
int error;
|
|
|
|
|
2009-04-18 16:47:33 +00:00
|
|
|
inkernelacl = acl_alloc(M_WAITOK);
|
2009-05-22 15:56:43 +00:00
|
|
|
error = acl_copyin(aclp, inkernelacl, type);
|
2009-11-04 07:04:15 +00:00
|
|
|
if (error != 0)
|
2009-04-18 16:47:33 +00:00
|
|
|
goto out;
|
2002-02-04 17:58:15 +00:00
|
|
|
error = vn_start_write(vp, &mp, V_WAIT | PCATCH);
|
|
|
|
if (error != 0)
|
2009-04-18 16:47:33 +00:00
|
|
|
goto out;
|
2008-01-10 01:10:58 +00:00
|
|
|
vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
|
2002-08-01 01:04:16 +00:00
|
|
|
#ifdef MAC
|
2009-04-18 16:47:33 +00:00
|
|
|
error = mac_vnode_check_setacl(td->td_ucred, vp, type, inkernelacl);
|
2002-08-01 01:04:16 +00:00
|
|
|
if (error != 0)
|
2009-04-18 16:47:33 +00:00
|
|
|
goto out_unlock;
|
2002-08-01 01:04:16 +00:00
|
|
|
#endif
|
2009-05-22 15:56:43 +00:00
|
|
|
error = VOP_SETACL(vp, acl_type_unold(type), inkernelacl,
|
|
|
|
td->td_ucred, td);
|
2002-08-01 01:04:16 +00:00
|
|
|
#ifdef MAC
|
2009-04-18 16:47:33 +00:00
|
|
|
out_unlock:
|
2002-08-01 01:04:16 +00:00
|
|
|
#endif
|
2008-01-13 14:44:15 +00:00
|
|
|
VOP_UNLOCK(vp, 0);
|
2002-02-04 17:58:15 +00:00
|
|
|
vn_finished_write(mp);
|
2009-04-18 16:47:33 +00:00
|
|
|
out:
|
|
|
|
acl_free(inkernelacl);
|
2009-11-04 07:04:15 +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)
|
|
|
|
{
|
2009-04-18 16:47:33 +00:00
|
|
|
struct acl *inkernelacl;
|
1999-12-19 06:08:07 +00:00
|
|
|
int error;
|
|
|
|
|
2009-04-18 16:47:33 +00:00
|
|
|
inkernelacl = acl_alloc(M_WAITOK);
|
2008-01-10 01:10:58 +00:00
|
|
|
vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
|
2002-08-01 01:04:16 +00:00
|
|
|
#ifdef MAC
|
2007-10-24 19:04:04 +00:00
|
|
|
error = mac_vnode_check_getacl(td->td_ucred, vp, type);
|
2002-08-01 01:04:16 +00:00
|
|
|
if (error != 0)
|
|
|
|
goto out;
|
|
|
|
#endif
|
2009-05-22 15:56:43 +00:00
|
|
|
error = VOP_GETACL(vp, acl_type_unold(type), inkernelacl,
|
|
|
|
td->td_ucred, td);
|
|
|
|
|
2002-08-01 01:04:16 +00:00
|
|
|
#ifdef MAC
|
|
|
|
out:
|
|
|
|
#endif
|
2008-01-13 14:44:15 +00:00
|
|
|
VOP_UNLOCK(vp, 0);
|
1999-12-19 06:08:07 +00:00
|
|
|
if (error == 0)
|
2009-05-22 15:56:43 +00:00
|
|
|
error = acl_copyout(inkernelacl, aclp, type);
|
2009-04-18 16:47:33 +00:00
|
|
|
acl_free(inkernelacl);
|
1999-12-19 06:08:07 +00:00
|
|
|
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);
|
2009-11-04 07:04:15 +00:00
|
|
|
if (error != 0)
|
2002-02-04 17:58:15 +00:00
|
|
|
return (error);
|
2008-01-10 01:10:58 +00:00
|
|
|
vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
|
2002-08-01 01:04:16 +00:00
|
|
|
#ifdef MAC
|
2007-10-24 19:04:04 +00:00
|
|
|
error = mac_vnode_check_deleteacl(td->td_ucred, vp, type);
|
2009-11-04 07:04:15 +00:00
|
|
|
if (error != 0)
|
2002-08-01 01:04:16 +00:00
|
|
|
goto out;
|
|
|
|
#endif
|
2009-05-22 15:56:43 +00:00
|
|
|
error = VOP_SETACL(vp, acl_type_unold(type), 0, td->td_ucred, td);
|
2002-08-01 01:04:16 +00:00
|
|
|
#ifdef MAC
|
|
|
|
out:
|
|
|
|
#endif
|
2008-01-13 14:44:15 +00:00
|
|
|
VOP_UNLOCK(vp, 0);
|
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)
|
|
|
|
{
|
2009-04-18 16:47:33 +00:00
|
|
|
struct acl *inkernelacl;
|
1999-12-19 06:08:07 +00:00
|
|
|
int error;
|
|
|
|
|
2009-04-18 16:47:33 +00:00
|
|
|
inkernelacl = acl_alloc(M_WAITOK);
|
2009-05-22 15:56:43 +00:00
|
|
|
error = acl_copyin(aclp, inkernelacl, type);
|
2009-11-04 07:04:15 +00:00
|
|
|
if (error != 0)
|
2009-04-18 16:47:33 +00:00
|
|
|
goto out;
|
2009-12-03 13:29:24 +00:00
|
|
|
error = VOP_ACLCHECK(vp, acl_type_unold(type), inkernelacl,
|
|
|
|
td->td_ucred, td);
|
2009-04-18 16:47:33 +00:00
|
|
|
out:
|
|
|
|
acl_free(inkernelacl);
|
1999-12-19 06:08:07 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2007-01-12 22:01:03 +00:00
|
|
|
* 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.
|
1999-12-19 06:08:07 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Given a file path, get an ACL for it
|
|
|
|
*/
|
|
|
|
int
|
2011-09-16 13:58:51 +00:00
|
|
|
sys___acl_get_file(struct thread *td, struct __acl_get_file_args *uap)
|
1999-12-19 06:08:07 +00:00
|
|
|
{
|
|
|
|
struct nameidata nd;
|
2012-10-22 17:50:54 +00:00
|
|
|
int error;
|
1999-12-19 06:08:07 +00:00
|
|
|
|
2012-10-22 17:50:54 +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);
|
|
|
|
}
|
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.
|
|
|
|
*/
|
|
|
|
int
|
2011-09-16 13:58:51 +00:00
|
|
|
sys___acl_get_link(struct thread *td, struct __acl_get_link_args *uap)
|
2002-12-29 20:28:44 +00:00
|
|
|
{
|
|
|
|
struct nameidata nd;
|
2012-10-22 17:50:54 +00:00
|
|
|
int error;
|
2002-12-29 20:28:44 +00:00
|
|
|
|
2012-10-22 17:50:54 +00:00
|
|
|
NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_USERSPACE, uap->path, td);
|
2002-12-29 20:28:44 +00:00
|
|
|
error = namei(&nd);
|
|
|
|
if (error == 0) {
|
|
|
|
error = vacl_get_acl(td, nd.ni_vp, uap->type, uap->aclp);
|
|
|
|
NDFREE(&nd, 0);
|
|
|
|
}
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
1999-12-19 06:08:07 +00:00
|
|
|
/*
|
2007-03-04 22:36:48 +00:00
|
|
|
* Given a file path, set an ACL for it.
|
1999-12-19 06:08:07 +00:00
|
|
|
*/
|
|
|
|
int
|
2011-09-16 13:58:51 +00:00
|
|
|
sys___acl_set_file(struct thread *td, struct __acl_set_file_args *uap)
|
1999-12-19 06:08:07 +00:00
|
|
|
{
|
|
|
|
struct nameidata nd;
|
2012-10-22 17:50:54 +00:00
|
|
|
int error;
|
1999-12-19 06:08:07 +00:00
|
|
|
|
2012-10-22 17:50:54 +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);
|
|
|
|
}
|
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.
|
|
|
|
*/
|
|
|
|
int
|
2011-09-16 13:58:51 +00:00
|
|
|
sys___acl_set_link(struct thread *td, struct __acl_set_link_args *uap)
|
2002-12-29 20:28:44 +00:00
|
|
|
{
|
|
|
|
struct nameidata nd;
|
2012-10-22 17:50:54 +00:00
|
|
|
int error;
|
2002-12-29 20:28:44 +00:00
|
|
|
|
2012-10-22 17:50:54 +00:00
|
|
|
NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_USERSPACE, uap->path, td);
|
2002-12-29 20:28:44 +00:00
|
|
|
error = namei(&nd);
|
|
|
|
if (error == 0) {
|
|
|
|
error = vacl_set_acl(td, nd.ni_vp, uap->type, uap->aclp);
|
|
|
|
NDFREE(&nd, 0);
|
|
|
|
}
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
1999-12-19 06:08:07 +00:00
|
|
|
/*
|
2007-03-05 13:26:07 +00:00
|
|
|
* Given a file descriptor, get an ACL for it.
|
1999-12-19 06:08:07 +00:00
|
|
|
*/
|
|
|
|
int
|
2011-09-16 13:58:51 +00:00
|
|
|
sys___acl_get_fd(struct thread *td, struct __acl_get_fd_args *uap)
|
1999-12-19 06:08:07 +00:00
|
|
|
{
|
|
|
|
struct file *fp;
|
2012-10-22 17:50:54 +00:00
|
|
|
int error;
|
1999-12-19 06:08:07 +00:00
|
|
|
|
2011-08-11 12:30:23 +00:00
|
|
|
error = getvnode(td->td_proc->p_fd, uap->filedes, CAP_ACL_GET, &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
|
|
|
}
|
|
|
|
return (error);
|
1999-12-19 06:08:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2007-03-05 13:26:07 +00:00
|
|
|
* Given a file descriptor, set an ACL for it.
|
1999-12-19 06:08:07 +00:00
|
|
|
*/
|
|
|
|
int
|
2011-09-16 13:58:51 +00:00
|
|
|
sys___acl_set_fd(struct thread *td, struct __acl_set_fd_args *uap)
|
1999-12-19 06:08:07 +00:00
|
|
|
{
|
|
|
|
struct file *fp;
|
2012-10-22 17:50:54 +00:00
|
|
|
int error;
|
1999-12-19 06:08:07 +00:00
|
|
|
|
2011-08-11 12:30:23 +00:00
|
|
|
error = getvnode(td->td_proc->p_fd, uap->filedes, CAP_ACL_SET, &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
|
|
|
}
|
|
|
|
return (error);
|
1999-12-19 06:08:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Given a file path, delete an ACL from it.
|
|
|
|
*/
|
|
|
|
int
|
2011-09-16 13:58:51 +00:00
|
|
|
sys___acl_delete_file(struct thread *td, struct __acl_delete_file_args *uap)
|
1999-12-19 06:08:07 +00:00
|
|
|
{
|
|
|
|
struct nameidata nd;
|
2012-10-22 17:50:54 +00:00
|
|
|
int error;
|
1999-12-19 06:08:07 +00:00
|
|
|
|
2012-10-22 17:50:54 +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);
|
|
|
|
}
|
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.
|
|
|
|
*/
|
|
|
|
int
|
2011-09-16 13:58:51 +00:00
|
|
|
sys___acl_delete_link(struct thread *td, struct __acl_delete_link_args *uap)
|
2002-12-29 20:28:44 +00:00
|
|
|
{
|
|
|
|
struct nameidata nd;
|
2012-10-22 17:50:54 +00:00
|
|
|
int error;
|
2002-12-29 20:28:44 +00:00
|
|
|
|
2012-10-22 17:50:54 +00:00
|
|
|
NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_USERSPACE, uap->path, td);
|
2002-12-29 20:28:44 +00:00
|
|
|
error = namei(&nd);
|
|
|
|
if (error == 0) {
|
|
|
|
error = vacl_delete(td, nd.ni_vp, uap->type);
|
|
|
|
NDFREE(&nd, 0);
|
|
|
|
}
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
1999-12-19 06:08:07 +00:00
|
|
|
/*
|
|
|
|
* Given a file path, delete an ACL from it.
|
|
|
|
*/
|
|
|
|
int
|
2011-09-16 13:58:51 +00:00
|
|
|
sys___acl_delete_fd(struct thread *td, struct __acl_delete_fd_args *uap)
|
1999-12-19 06:08:07 +00:00
|
|
|
{
|
|
|
|
struct file *fp;
|
2012-10-22 17:50:54 +00:00
|
|
|
int error;
|
1999-12-19 06:08:07 +00:00
|
|
|
|
2011-08-11 12:30:23 +00:00
|
|
|
error = getvnode(td->td_proc->p_fd, uap->filedes, CAP_ACL_DELETE,
|
|
|
|
&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
|
|
|
}
|
1999-12-19 06:08:07 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2007-03-04 22:36:48 +00:00
|
|
|
* Given a file path, check an ACL for it.
|
1999-12-19 06:08:07 +00:00
|
|
|
*/
|
|
|
|
int
|
2011-09-16 13:58:51 +00:00
|
|
|
sys___acl_aclcheck_file(struct thread *td, struct __acl_aclcheck_file_args *uap)
|
1999-12-19 06:08:07 +00:00
|
|
|
{
|
2009-11-04 07:04:15 +00:00
|
|
|
struct nameidata nd;
|
2012-10-22 17:50:54 +00:00
|
|
|
int error;
|
1999-12-19 06:08:07 +00:00
|
|
|
|
2012-10-22 17:50:54 +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);
|
|
|
|
}
|
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.
|
|
|
|
*/
|
|
|
|
int
|
2011-09-16 13:58:51 +00:00
|
|
|
sys___acl_aclcheck_link(struct thread *td, struct __acl_aclcheck_link_args *uap)
|
2002-12-29 20:28:44 +00:00
|
|
|
{
|
2009-11-04 08:25:58 +00:00
|
|
|
struct nameidata nd;
|
2012-10-22 17:50:54 +00:00
|
|
|
int error;
|
2002-12-29 20:28:44 +00:00
|
|
|
|
2012-10-22 17:50:54 +00:00
|
|
|
NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_USERSPACE, uap->path, td);
|
2002-12-29 20:28:44 +00:00
|
|
|
error = namei(&nd);
|
|
|
|
if (error == 0) {
|
|
|
|
error = vacl_aclcheck(td, nd.ni_vp, uap->type, uap->aclp);
|
|
|
|
NDFREE(&nd, 0);
|
|
|
|
}
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
1999-12-19 06:08:07 +00:00
|
|
|
/*
|
2007-03-04 22:36:48 +00:00
|
|
|
* Given a file descriptor, check an ACL for it.
|
1999-12-19 06:08:07 +00:00
|
|
|
*/
|
|
|
|
int
|
2011-09-16 13:58:51 +00:00
|
|
|
sys___acl_aclcheck_fd(struct thread *td, struct __acl_aclcheck_fd_args *uap)
|
1999-12-19 06:08:07 +00:00
|
|
|
{
|
|
|
|
struct file *fp;
|
2012-10-22 17:50:54 +00:00
|
|
|
int error;
|
1999-12-19 06:08:07 +00:00
|
|
|
|
2011-08-11 12:30:23 +00:00
|
|
|
error = getvnode(td->td_proc->p_fd, uap->filedes, CAP_ACL_CHECK,
|
|
|
|
&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
|
|
|
}
|
|
|
|
return (error);
|
1999-12-19 06:08:07 +00:00
|
|
|
}
|
2005-09-06 00:06:30 +00:00
|
|
|
|
2009-04-18 16:47:33 +00:00
|
|
|
struct acl *
|
|
|
|
acl_alloc(int flags)
|
|
|
|
{
|
|
|
|
struct acl *aclp;
|
|
|
|
|
2009-04-19 09:56:30 +00:00
|
|
|
aclp = malloc(sizeof(*aclp), M_ACL, flags);
|
2009-05-22 15:56:43 +00:00
|
|
|
aclp->acl_maxcnt = ACL_MAX_ENTRIES;
|
2009-04-18 16:47:33 +00:00
|
|
|
|
|
|
|
return (aclp);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
acl_free(struct acl *aclp)
|
|
|
|
{
|
|
|
|
|
2009-04-19 09:56:30 +00:00
|
|
|
free(aclp, M_ACL);
|
2009-04-18 16:47:33 +00:00
|
|
|
}
|