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$");
|
|
|
|
|
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>
|
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>
|
|
|
|
|
2005-09-06 00:06:30 +00:00
|
|
|
#include <vm/uma.h>
|
1999-12-19 06:08:07 +00:00
|
|
|
|
2005-09-06 00:06:30 +00:00
|
|
|
uma_zone_t acl_zone;
|
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
|
|
|
|
|
|
|
/*
|
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);
|
|
|
|
error = copyin(aclp, inkernelacl, sizeof(struct acl));
|
1999-12-19 06:08:07 +00:00
|
|
|
if (error)
|
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-04-18 16:47:33 +00:00
|
|
|
error = VOP_SETACL(vp, 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);
|
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)
|
|
|
|
{
|
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-04-18 16:47:33 +00:00
|
|
|
error = VOP_GETACL(vp, 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-04-18 16:47:33 +00:00
|
|
|
error = copyout(inkernelacl, aclp, sizeof(struct acl));
|
|
|
|
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);
|
|
|
|
if (error)
|
|
|
|
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);
|
2002-08-01 01:04:16 +00:00
|
|
|
if (error)
|
|
|
|
goto out;
|
|
|
|
#endif
|
|
|
|
error = VOP_SETACL(vp, type, 0, td->td_ucred, td);
|
|
|
|
#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);
|
|
|
|
error = copyin(aclp, inkernelacl, sizeof(struct acl));
|
1999-12-19 06:08:07 +00:00
|
|
|
if (error)
|
2009-04-18 16:47:33 +00:00
|
|
|
goto out;
|
|
|
|
error = VOP_ACLCHECK(vp, type, inkernelacl, td->td_ucred, td);
|
|
|
|
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
|
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;
|
2005-09-17 22:01:14 +00:00
|
|
|
int vfslocked, error;
|
1999-12-19 06:08:07 +00:00
|
|
|
|
2005-09-17 22:01:14 +00:00
|
|
|
NDINIT(&nd, LOOKUP, MPSAFE|FOLLOW, UIO_USERSPACE, uap->path, td);
|
1999-12-19 06:08:07 +00:00
|
|
|
error = namei(&nd);
|
2005-09-17 22:01:14 +00:00
|
|
|
vfslocked = NDHASGIANT(&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);
|
|
|
|
}
|
2005-09-17 22:01:14 +00:00
|
|
|
VFS_UNLOCK_GIANT(vfslocked);
|
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
|
|
|
|
__acl_get_link(struct thread *td, struct __acl_get_link_args *uap)
|
|
|
|
{
|
|
|
|
struct nameidata nd;
|
2005-09-17 22:01:14 +00:00
|
|
|
int vfslocked, error;
|
2002-12-29 20:28:44 +00:00
|
|
|
|
2005-09-17 22:01:14 +00:00
|
|
|
NDINIT(&nd, LOOKUP, MPSAFE|NOFOLLOW, UIO_USERSPACE, uap->path, td);
|
2002-12-29 20:28:44 +00:00
|
|
|
error = namei(&nd);
|
2005-09-17 22:01:14 +00:00
|
|
|
vfslocked = NDHASGIANT(&nd);
|
2002-12-29 20:28:44 +00:00
|
|
|
if (error == 0) {
|
|
|
|
error = vacl_get_acl(td, nd.ni_vp, uap->type, uap->aclp);
|
|
|
|
NDFREE(&nd, 0);
|
|
|
|
}
|
2005-09-17 22:01:14 +00:00
|
|
|
VFS_UNLOCK_GIANT(vfslocked);
|
2002-12-29 20:28:44 +00:00
|
|
|
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
|
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;
|
2005-09-17 22:01:14 +00:00
|
|
|
int vfslocked, error;
|
1999-12-19 06:08:07 +00:00
|
|
|
|
2005-09-17 22:01:14 +00:00
|
|
|
NDINIT(&nd, LOOKUP, MPSAFE|FOLLOW, UIO_USERSPACE, uap->path, td);
|
1999-12-19 06:08:07 +00:00
|
|
|
error = namei(&nd);
|
2005-09-17 22:01:14 +00:00
|
|
|
vfslocked = NDHASGIANT(&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);
|
|
|
|
}
|
2005-09-17 22:01:14 +00:00
|
|
|
VFS_UNLOCK_GIANT(vfslocked);
|
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
|
|
|
|
__acl_set_link(struct thread *td, struct __acl_set_link_args *uap)
|
|
|
|
{
|
|
|
|
struct nameidata nd;
|
2005-09-17 22:01:14 +00:00
|
|
|
int vfslocked, error;
|
2002-12-29 20:28:44 +00:00
|
|
|
|
2005-09-17 22:01:14 +00:00
|
|
|
NDINIT(&nd, LOOKUP, MPSAFE|NOFOLLOW, UIO_USERSPACE, uap->path, td);
|
2002-12-29 20:28:44 +00:00
|
|
|
error = namei(&nd);
|
2005-09-17 22:01:14 +00:00
|
|
|
vfslocked = NDHASGIANT(&nd);
|
2002-12-29 20:28:44 +00:00
|
|
|
if (error == 0) {
|
|
|
|
error = vacl_set_acl(td, nd.ni_vp, uap->type, uap->aclp);
|
|
|
|
NDFREE(&nd, 0);
|
|
|
|
}
|
2005-09-17 22:01:14 +00:00
|
|
|
VFS_UNLOCK_GIANT(vfslocked);
|
2002-12-29 20:28:44 +00:00
|
|
|
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
|
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;
|
2005-09-17 22:01:14 +00:00
|
|
|
int vfslocked, error;
|
1999-12-19 06:08:07 +00:00
|
|
|
|
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) {
|
2005-09-17 22:01:14 +00:00
|
|
|
vfslocked = VFS_LOCK_GIANT(fp->f_vnode->v_mount);
|
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);
|
2005-09-17 22:01:14 +00:00
|
|
|
VFS_UNLOCK_GIANT(vfslocked);
|
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
|
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;
|
2005-09-17 22:01:14 +00:00
|
|
|
int vfslocked, error;
|
1999-12-19 06:08:07 +00:00
|
|
|
|
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) {
|
2005-09-17 22:01:14 +00:00
|
|
|
vfslocked = VFS_LOCK_GIANT(fp->f_vnode->v_mount);
|
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);
|
2005-09-17 22:01:14 +00:00
|
|
|
VFS_UNLOCK_GIANT(vfslocked);
|
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
|
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;
|
2005-09-17 22:01:14 +00:00
|
|
|
int vfslocked, error;
|
1999-12-19 06:08:07 +00:00
|
|
|
|
2005-09-17 22:01:14 +00:00
|
|
|
NDINIT(&nd, LOOKUP, MPSAFE|FOLLOW, UIO_USERSPACE, uap->path, td);
|
1999-12-19 06:08:07 +00:00
|
|
|
error = namei(&nd);
|
2005-09-17 22:01:14 +00:00
|
|
|
vfslocked = NDHASGIANT(&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);
|
|
|
|
}
|
2005-09-17 22:01:14 +00:00
|
|
|
VFS_UNLOCK_GIANT(vfslocked);
|
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
|
|
|
|
__acl_delete_link(struct thread *td, struct __acl_delete_link_args *uap)
|
|
|
|
{
|
|
|
|
struct nameidata nd;
|
2005-09-17 22:01:14 +00:00
|
|
|
int vfslocked, error;
|
2002-12-29 20:28:44 +00:00
|
|
|
|
2005-09-17 22:01:14 +00:00
|
|
|
NDINIT(&nd, LOOKUP, MPSAFE|NOFOLLOW, UIO_USERSPACE, uap->path, td);
|
2002-12-29 20:28:44 +00:00
|
|
|
error = namei(&nd);
|
2005-09-17 22:01:14 +00:00
|
|
|
vfslocked = NDHASGIANT(&nd);
|
2002-12-29 20:28:44 +00:00
|
|
|
if (error == 0) {
|
|
|
|
error = vacl_delete(td, nd.ni_vp, uap->type);
|
|
|
|
NDFREE(&nd, 0);
|
|
|
|
}
|
2005-09-17 22:01:14 +00:00
|
|
|
VFS_UNLOCK_GIANT(vfslocked);
|
2002-12-29 20:28:44 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
1999-12-19 06:08:07 +00:00
|
|
|
/*
|
|
|
|
* Given a file path, delete an ACL from it.
|
|
|
|
*/
|
|
|
|
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;
|
2005-09-17 22:01:14 +00:00
|
|
|
int vfslocked, error;
|
1999-12-19 06:08:07 +00:00
|
|
|
|
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) {
|
2005-09-17 22:01:14 +00:00
|
|
|
vfslocked = VFS_LOCK_GIANT(fp->f_vnode->v_mount);
|
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);
|
2005-09-17 22:01:14 +00:00
|
|
|
VFS_UNLOCK_GIANT(vfslocked);
|
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
|
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;
|
2005-09-17 22:01:14 +00:00
|
|
|
int vfslocked, error;
|
1999-12-19 06:08:07 +00:00
|
|
|
|
2005-09-17 22:01:14 +00:00
|
|
|
NDINIT(&nd, LOOKUP, MPSAFE|FOLLOW, UIO_USERSPACE, uap->path, td);
|
1999-12-19 06:08:07 +00:00
|
|
|
error = namei(&nd);
|
2005-09-17 22:01:14 +00:00
|
|
|
vfslocked = NDHASGIANT(&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);
|
|
|
|
}
|
2005-09-17 22:01:14 +00:00
|
|
|
VFS_UNLOCK_GIANT(vfslocked);
|
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
|
|
|
|
__acl_aclcheck_link(struct thread *td, struct __acl_aclcheck_link_args *uap)
|
|
|
|
{
|
|
|
|
struct nameidata nd;
|
2005-09-17 22:01:14 +00:00
|
|
|
int vfslocked, error;
|
2002-12-29 20:28:44 +00:00
|
|
|
|
2005-09-17 22:01:14 +00:00
|
|
|
NDINIT(&nd, LOOKUP, MPSAFE|NOFOLLOW, UIO_USERSPACE, uap->path, td);
|
2002-12-29 20:28:44 +00:00
|
|
|
error = namei(&nd);
|
2005-09-17 22:01:14 +00:00
|
|
|
vfslocked = NDHASGIANT(&nd);
|
2002-12-29 20:28:44 +00:00
|
|
|
if (error == 0) {
|
|
|
|
error = vacl_aclcheck(td, nd.ni_vp, uap->type, uap->aclp);
|
|
|
|
NDFREE(&nd, 0);
|
|
|
|
}
|
2005-09-17 22:01:14 +00:00
|
|
|
VFS_UNLOCK_GIANT(vfslocked);
|
2002-12-29 20:28:44 +00:00
|
|
|
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
|
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;
|
2005-09-17 22:01:14 +00:00
|
|
|
int vfslocked, error;
|
1999-12-19 06:08:07 +00:00
|
|
|
|
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) {
|
2005-09-17 22:01:14 +00:00
|
|
|
vfslocked = VFS_LOCK_GIANT(fp->f_vnode->v_mount);
|
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);
|
2005-09-17 22:01:14 +00:00
|
|
|
VFS_UNLOCK_GIANT(vfslocked);
|
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;
|
|
|
|
|
|
|
|
aclp = uma_zalloc(acl_zone, flags);
|
|
|
|
|
|
|
|
return (aclp);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
acl_free(struct acl *aclp)
|
|
|
|
{
|
|
|
|
|
|
|
|
uma_zfree(acl_zone, aclp);
|
|
|
|
}
|
|
|
|
|
2005-09-06 00:06:30 +00:00
|
|
|
/* ARGUSED */
|
|
|
|
|
|
|
|
static void
|
|
|
|
aclinit(void *dummy __unused)
|
|
|
|
{
|
|
|
|
|
|
|
|
acl_zone = uma_zcreate("ACL UMA zone", sizeof(struct acl),
|
|
|
|
NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, 0);
|
|
|
|
}
|
2008-03-16 10:58:09 +00:00
|
|
|
SYSINIT(acls, SI_SUB_ACL, SI_ORDER_FIRST, aclinit, NULL);
|