acl.h revision 74667
1/*- 2 * Copyright (c) 1999, 2000, 2001 Robert N. M. Watson 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * 26 * $FreeBSD: head/sys/sys/acl.h 74667 2001-03-22 22:31:01Z jedgar $ 27 */ 28/* 29 * Developed by the TrustedBSD Project. 30 * Support for POSIX.1e access control lists. 31 */ 32 33#ifndef _SYS_ACL_H 34#define _SYS_ACL_H 35 36/* 37 * POSIX.1e ACL types and related constants. 38 */ 39 40#define POSIX1E_ACL_ACCESS_EXTATTR_NAMESPACE EXTATTR_NAMESPACE_SYSTEM 41#define POSIX1E_ACL_ACCESS_EXTATTR_NAME "posix1e.acl_access" 42#define POSIX1E_ACL_DEFAULT_EXTATTR_NAMESPACE EXTATTR_NAMESPACE_SYSTEM 43#define POSIX1E_ACL_DEFAULT_EXTATTR_NAME "posix1e.acl_default" 44#define ACL_MAX_ENTRIES 32 /* maximum entries in an ACL */ 45#define _POSIX_ACL_PATH_MAX ACL_MAX_ENTRIES 46 47typedef int acl_type_t; 48typedef int acl_tag_t; 49typedef mode_t acl_perm_t; 50typedef mode_t *acl_permset_t; 51 52struct acl_entry { 53 acl_tag_t ae_tag; 54 uid_t ae_id; 55 acl_perm_t ae_perm; 56}; 57typedef struct acl_entry *acl_entry_t; 58 59struct acl { 60 int acl_cnt; 61 struct acl_entry acl_entry[ACL_MAX_ENTRIES]; 62}; 63typedef struct acl *acl_t; 64 65/* 66 * Possible valid values for ae_tag field. 67 */ 68#define ACL_USER_OBJ 0x00000001 69#define ACL_USER 0x00000002 70#define ACL_GROUP_OBJ 0x00000004 71#define ACL_GROUP 0x00000008 72#define ACL_MASK 0x00000010 73#define ACL_OTHER 0x00000020 74#define ACL_OTHER_OBJ ACL_OTHER 75 76/* 77 * Possible valid values for acl_type_t arguments. 78 */ 79#define ACL_TYPE_ACCESS 0x00000000 80#define ACL_TYPE_DEFAULT 0x00000001 81#define ACL_TYPE_AFS 0x00000002 82#define ACL_TYPE_CODA 0x00000003 83#define ACL_TYPE_NTFS 0x00000004 84#define ACL_TYPE_NWFS 0x00000005 85 86/* 87 * Possible flags in ae_perm field. 88 */ 89#define ACL_PERM_EXEC 0x0001 90#define ACL_PERM_WRITE 0x0002 91#define ACL_PERM_READ 0x0004 92#define ACL_PERM_NONE 0x0000 93#define ACL_PERM_BITS (ACL_PERM_EXEC | ACL_PERM_WRITE | ACL_PERM_READ) 94#define ACL_POSIX1E_BITS (ACL_PERM_EXEC | ACL_PERM_WRITE | ACL_PERM_READ) 95 96#ifdef _KERNEL 97 98/* 99 * Storage for ACLs and support structures. 100 */ 101#ifdef MALLOC_DECLARE 102MALLOC_DECLARE(M_ACL); 103#endif 104 105acl_perm_t acl_posix1e_mode_to_perm __P((acl_tag_t tag, mode_t mode)); 106struct acl_entry acl_posix1e_mode_to_entry __P((acl_tag_t tag, uid_t uid, 107 gid_t gid, mode_t mode)); 108mode_t acl_posix1e_perms_to_mode __P((struct acl_entry *acl_user_obj_entry, 109 struct acl_entry *acl_group_obj_entry, struct acl_entry *acl_other_entry)); 110int acl_posix1e_check(struct acl *acl); 111 112#else /* !_KERNEL */ 113 114/* 115 * Syscall interface -- use the library calls instead as the syscalls 116 * have strict acl entry ordering requirements. 117 */ 118__BEGIN_DECLS 119int __acl_aclcheck_fd(int _filedes, acl_type_t _type, struct acl *_aclp); 120int __acl_aclcheck_file(const char *_path, acl_type_t _type, 121 struct acl *_aclp); 122int __acl_delete_fd(int _filedes, acl_type_t _type); 123int __acl_delete_file(const char *_path_p, acl_type_t _type); 124int __acl_get_fd(int _filedes, acl_type_t _type, struct acl *_aclp); 125int __acl_get_file(const char *_path, acl_type_t _type, struct acl *_aclp); 126int __acl_set_fd(int _filedes, acl_type_t _type, struct acl *_aclp); 127int __acl_set_file(const char *_path, acl_type_t _type, struct acl *_aclp); 128__END_DECLS 129 130/* 131 * Supported POSIX.1e ACL manipulation and assignment/retrieval API 132 * _np calls are local extensions that reflect an environment capable of 133 * opening file descriptors of directories, and allowing additional 134 * ACL type for different file systems (i.e., AFS). 135 */ 136__BEGIN_DECLS 137int acl_add_perm(acl_permset_t _permset_d, acl_perm_t _perm); 138int acl_calc_mask(acl_t *acl_p); 139int acl_clear_perms(acl_permset_t _permset_d); 140int acl_copy_entry(acl_entry_t _dest_d, acl_entry_t _src_d); 141ssize_t acl_copy_ext(void *_buf_p, acl_t _acl, ssize_t _size); 142acl_t acl_copy_int(const void *_buf_p); 143int acl_create_entry(acl_t *_acl_p, acl_entry_t *_entry_p); 144int acl_delete_fd_np(int _filedes, acl_type_t _type); 145int acl_delete_entry(acl_t acl, acl_entry_t entry_d); 146int acl_delete_file_np(const char *_path_p, acl_type_t _type); 147int acl_delete_def_file(const char *_path_p); 148int acl_delete_perm(acl_permset_t _permset_d, acl_perm_t _perm); 149acl_t acl_dup(acl_t _acl); 150int acl_free(void *_obj_p); 151acl_t acl_from_text(const char *_buf_p); 152int acl_get_entry(acl_t _acl, int _entry_id, acl_entry_t *_entry_p); 153acl_t acl_get_fd(int _fd); 154acl_t acl_get_fd_np(int fd, acl_type_t _type); 155acl_t acl_get_file(const char *_path_p, acl_type_t _type); 156void *acl_get_qualifier(acl_entry_t _entry_d); 157int acl_get_permset(acl_entry_t _entry_d, acl_permset_t *_permset_p); 158int acl_get_tag_type(acl_entry_t _entry_d, acl_tag_t *_tag_type_p); 159acl_t acl_init(int _count); 160int acl_set_fd(int _fd, acl_t _acl); 161int acl_set_fd_np(int _fd, acl_t _acl, acl_type_t _type); 162int acl_set_file(const char *_path_p, acl_type_t _type, acl_t _acl); 163int acl_set_permset(acl_entry_t _entry_d, acl_permset_t _permset_d); 164int acl_set_qualifier(acl_entry_t _entry_d, const void *_tag_qualifier_p); 165int acl_set_tag_type(acl_entry_t _entry_d, acl_tag_t _tag_type); 166ssize_t acl_size(acl_t _acl); 167char *acl_to_text(acl_t _acl, ssize_t *_len_p); 168int acl_valid(acl_t _acl); 169int acl_valid_fd_np(int _fd, acl_type_t _type, acl_t _acl); 170int acl_valid_file_np(const char *_path_p, acl_type_t _type, acl_t _acl); 171__END_DECLS 172 173#endif /* !_KERNEL */ 174 175#endif /* !_SYS_ACL_H */ 176