1fa9e4066Sahrens /* 2fa9e4066Sahrens * CDDL HEADER START 3fa9e4066Sahrens * 4fa9e4066Sahrens * The contents of this file are subject to the terms of the 5ea8dc4b6Seschrock * Common Development and Distribution License (the "License"). 6ea8dc4b6Seschrock * You may not use this file except in compliance with the License. 7fa9e4066Sahrens * 8fa9e4066Sahrens * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9fa9e4066Sahrens * or http://www.opensolaris.org/os/licensing. 10fa9e4066Sahrens * See the License for the specific language governing permissions 11fa9e4066Sahrens * and limitations under the License. 12fa9e4066Sahrens * 13fa9e4066Sahrens * When distributing Covered Code, include this CDDL HEADER in each 14fa9e4066Sahrens * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15fa9e4066Sahrens * If applicable, add the following below this CDDL HEADER, with the 16fa9e4066Sahrens * fields enclosed by brackets "[]" replaced with your own identifying 17fa9e4066Sahrens * information: Portions Copyright [yyyy] [name of copyright owner] 18fa9e4066Sahrens * 19fa9e4066Sahrens * CDDL HEADER END 20fa9e4066Sahrens */ 21fa9e4066Sahrens /* 22bda89588Sjp * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 23fa9e4066Sahrens * Use is subject to license terms. 24fa9e4066Sahrens */ 25fa9e4066Sahrens 26fa9e4066Sahrens #ifndef _SYS_FS_ZFS_ACL_H 27fa9e4066Sahrens #define _SYS_FS_ZFS_ACL_H 28fa9e4066Sahrens 29fa9e4066Sahrens #ifdef _KERNEL 30fa9e4066Sahrens #include <sys/isa_defs.h> 31fa9e4066Sahrens #include <sys/types32.h> 32fa9e4066Sahrens #endif 33fa9e4066Sahrens #include <sys/acl.h> 34fa9e4066Sahrens #include <sys/dmu.h> 35da6c28aaSamw #include <sys/zfs_fuid.h> 36fa9e4066Sahrens 37fa9e4066Sahrens #ifdef __cplusplus 38fa9e4066Sahrens extern "C" { 39fa9e4066Sahrens #endif 40fa9e4066Sahrens 41fa9e4066Sahrens struct znode_phys; 42fa9e4066Sahrens 43fa9e4066Sahrens #define ACE_SLOT_CNT 6 44da6c28aaSamw #define ZFS_ACL_VERSION_INITIAL 0ULL 45da6c28aaSamw #define ZFS_ACL_VERSION_FUID 1ULL 46da6c28aaSamw #define ZFS_ACL_VERSION ZFS_ACL_VERSION_FUID 47fa9e4066Sahrens 48da6c28aaSamw /* 49da6c28aaSamw * ZFS ACLs are store in various forms. 50da6c28aaSamw * Files created with ACL version ZFS_ACL_VERSION_INITIAL 51da6c28aaSamw * will all be created with fixed length ACEs of type 52da6c28aaSamw * zfs_oldace_t. 53da6c28aaSamw * 54da6c28aaSamw * Files with ACL version ZFS_ACL_VERSION_FUID will be created 55da6c28aaSamw * with various sized ACEs. The abstraction entries will utilize 56da6c28aaSamw * zfs_ace_hdr_t, normal user/group entries will use zfs_ace_t 57da6c28aaSamw * and some specialized CIFS ACEs will use zfs_object_ace_t. 58da6c28aaSamw */ 59da6c28aaSamw 60da6c28aaSamw /* 61da6c28aaSamw * All ACEs have a common hdr. For 62da6c28aaSamw * owner@, group@, and everyone@ this is all 63da6c28aaSamw * thats needed. 64da6c28aaSamw */ 65da6c28aaSamw typedef struct zfs_ace_hdr { 66da6c28aaSamw uint16_t z_type; 67da6c28aaSamw uint16_t z_flags; 68da6c28aaSamw uint32_t z_access_mask; 69da6c28aaSamw } zfs_ace_hdr_t; 70da6c28aaSamw 71da6c28aaSamw typedef zfs_ace_hdr_t zfs_ace_abstract_t; 72da6c28aaSamw 73da6c28aaSamw /* 74da6c28aaSamw * Standard ACE 75da6c28aaSamw */ 76da6c28aaSamw typedef struct zfs_ace { 77da6c28aaSamw zfs_ace_hdr_t z_hdr; 78da6c28aaSamw uint64_t z_fuid; 79da6c28aaSamw } zfs_ace_t; 80da6c28aaSamw 81da6c28aaSamw /* 82da6c28aaSamw * The following type only applies to ACE_ACCESS_ALLOWED|DENIED_OBJECT_ACE_TYPE 83da6c28aaSamw * and will only be set/retrieved in a CIFS context. 84da6c28aaSamw */ 85da6c28aaSamw 86da6c28aaSamw typedef struct zfs_object_ace { 87da6c28aaSamw zfs_ace_t z_ace; 88da6c28aaSamw uint8_t z_object_type[16]; /* object type */ 89da6c28aaSamw uint8_t z_inherit_type[16]; /* inherited object type */ 90da6c28aaSamw } zfs_object_ace_t; 91da6c28aaSamw 92da6c28aaSamw typedef struct zfs_oldace { 93da6c28aaSamw uint32_t z_fuid; /* "who" */ 94da6c28aaSamw uint32_t z_access_mask; /* access mask */ 95da6c28aaSamw uint16_t z_flags; /* flags, i.e inheritance */ 96da6c28aaSamw uint16_t z_type; /* type of entry allow/deny */ 97da6c28aaSamw } zfs_oldace_t; 98da6c28aaSamw 99da6c28aaSamw typedef struct zfs_acl_phys_v0 { 100da6c28aaSamw uint64_t z_acl_extern_obj; /* ext acl pieces */ 101da6c28aaSamw uint32_t z_acl_count; /* Number of ACEs */ 102da6c28aaSamw uint16_t z_acl_version; /* acl version */ 103da6c28aaSamw uint16_t z_acl_pad; /* pad */ 104da6c28aaSamw zfs_oldace_t z_ace_data[ACE_SLOT_CNT]; /* 6 standard ACEs */ 105da6c28aaSamw } zfs_acl_phys_v0_t; 106da6c28aaSamw 107da6c28aaSamw #define ZFS_ACE_SPACE (sizeof (zfs_oldace_t) * ACE_SLOT_CNT) 108da6c28aaSamw 109da6c28aaSamw typedef struct zfs_acl_phys { 110fa9e4066Sahrens uint64_t z_acl_extern_obj; /* ext acl pieces */ 111da6c28aaSamw uint32_t z_acl_size; /* Number of bytes in ACL */ 112fa9e4066Sahrens uint16_t z_acl_version; /* acl version */ 113da6c28aaSamw uint16_t z_acl_count; /* ace count */ 114da6c28aaSamw uint8_t z_ace_data[ZFS_ACE_SPACE]; /* space for embedded ACEs */ 115da6c28aaSamw } zfs_acl_phys_t; 116da6c28aaSamw 117da6c28aaSamw 118da6c28aaSamw 119da6c28aaSamw typedef struct acl_ops { 120da6c28aaSamw uint32_t (*ace_mask_get) (void *acep); /* get access mask */ 121da6c28aaSamw void (*ace_mask_set) (void *acep, 122da6c28aaSamw uint32_t mask); /* set access mask */ 123da6c28aaSamw uint16_t (*ace_flags_get) (void *acep); /* get flags */ 124da6c28aaSamw void (*ace_flags_set) (void *acep, 125da6c28aaSamw uint16_t flags); /* set flags */ 126da6c28aaSamw uint16_t (*ace_type_get)(void *acep); /* get type */ 127da6c28aaSamw void (*ace_type_set)(void *acep, 128da6c28aaSamw uint16_t type); /* set type */ 129da6c28aaSamw uint64_t (*ace_who_get)(void *acep); /* get who/fuid */ 130da6c28aaSamw void (*ace_who_set)(void *acep, 131da6c28aaSamw uint64_t who); /* set who/fuid */ 132da6c28aaSamw size_t (*ace_size)(void *acep); /* how big is this ace */ 133da6c28aaSamw size_t (*ace_abstract_size)(void); /* sizeof abstract entry */ 134da6c28aaSamw int (*ace_mask_off)(void); /* off of access mask in ace */ 135da6c28aaSamw int (*ace_data)(void *acep, void **datap); 136da6c28aaSamw /* ptr to data if any */ 137da6c28aaSamw } acl_ops_t; 138fa9e4066Sahrens 139fa9e4066Sahrens /* 140da6c28aaSamw * A zfs_acl_t structure is composed of a list of zfs_acl_node_t's. 141da6c28aaSamw * Each node will have one or more ACEs associated with it. You will 142da6c28aaSamw * only have multiple nodes during a chmod operation. Normally only 143da6c28aaSamw * one node is required. 144fa9e4066Sahrens */ 145da6c28aaSamw typedef struct zfs_acl_node { 146da6c28aaSamw list_node_t z_next; /* Next chunk of ACEs */ 147da6c28aaSamw void *z_acldata; /* pointer into actual ACE(s) */ 148da6c28aaSamw void *z_allocdata; /* pointer to kmem allocated memory */ 149da6c28aaSamw size_t z_allocsize; /* Size of blob in bytes */ 150da6c28aaSamw size_t z_size; /* length of ACL data */ 151da6c28aaSamw int z_ace_count; /* number of ACEs in this acl node */ 152da6c28aaSamw int z_ace_idx; /* ace iterator positioned on */ 153da6c28aaSamw } zfs_acl_node_t; 154fa9e4066Sahrens 155fa9e4066Sahrens typedef struct zfs_acl { 156da6c28aaSamw int z_acl_count; /* Number of ACEs */ 157da6c28aaSamw size_t z_acl_bytes; /* Number of bytes in ACL */ 158da6c28aaSamw uint_t z_version; /* version of ACL */ 159da6c28aaSamw void *z_next_ace; /* pointer to next ACE */ 160da6c28aaSamw int z_hints; /* ACL hints (ZFS_INHERIT_ACE ...) */ 161da6c28aaSamw zfs_acl_node_t *z_curr_node; /* current node iterator is handling */ 162da6c28aaSamw list_t z_acl; /* chunks of ACE data */ 163da6c28aaSamw acl_ops_t z_ops; /* ACL operations */ 1644c841f60Smarks boolean_t z_has_fuids; /* FUIDs present in ACL? */ 165fa9e4066Sahrens } zfs_acl_t; 166fa9e4066Sahrens 167da6c28aaSamw #define ACL_DATA_ALLOCED 0x1 168fa9e4066Sahrens #define ZFS_ACL_SIZE(aclcnt) (sizeof (ace_t) * (aclcnt)) 169fa9e4066Sahrens 170fa9e4066Sahrens /* 171fa9e4066Sahrens * Property values for acl_mode and acl_inherit. 172fa9e4066Sahrens * 173fa9e4066Sahrens * acl_mode can take discard, noallow, groupmask and passthrough. 174fa9e4066Sahrens * whereas acl_inherit has secure instead of groupmask. 175fa9e4066Sahrens */ 176fa9e4066Sahrens 177e9dbad6fSeschrock #define ZFS_ACL_DISCARD 0 178e9dbad6fSeschrock #define ZFS_ACL_NOALLOW 1 179e9dbad6fSeschrock #define ZFS_ACL_GROUPMASK 2 180e9dbad6fSeschrock #define ZFS_ACL_PASSTHROUGH 3 181b3d141f8Smarks #define ZFS_ACL_RESTRICTED 4 182*d0f3f37eSMark Shellenbaum #define ZFS_ACL_PASSTHROUGH_X 5 183fa9e4066Sahrens 184fa9e4066Sahrens struct znode; 185da6c28aaSamw struct zfsvfs; 1864c841f60Smarks struct zfs_fuid_info; 187fa9e4066Sahrens 188fa9e4066Sahrens #ifdef _KERNEL 189fa9e4066Sahrens void zfs_perm_init(struct znode *, struct znode *, int, vattr_t *, 190da6c28aaSamw dmu_tx_t *, cred_t *, zfs_acl_t *, zfs_fuid_info_t **); 191da6c28aaSamw int zfs_getacl(struct znode *, vsecattr_t *, boolean_t, cred_t *); 192da6c28aaSamw int zfs_setacl(struct znode *, vsecattr_t *, boolean_t, cred_t *); 193fa9e4066Sahrens void zfs_acl_rele(void *); 194da6c28aaSamw void zfs_oldace_byteswap(ace_t *, int); 195da6c28aaSamw void zfs_ace_byteswap(void *, size_t, boolean_t); 196da6c28aaSamw extern int zfs_zaccess(struct znode *, int, int, boolean_t, cred_t *); 197da6c28aaSamw extern int zfs_zaccess_rwx(struct znode *, mode_t, int, cred_t *); 198da6c28aaSamw extern int zfs_zaccess_unix(struct znode *, mode_t, cred_t *); 199fa9e4066Sahrens extern int zfs_acl_access(struct znode *, int, cred_t *); 2004c841f60Smarks int zfs_acl_chmod_setattr(struct znode *, zfs_acl_t **, uint64_t); 201fa9e4066Sahrens int zfs_zaccess_delete(struct znode *, struct znode *, cred_t *); 202fa9e4066Sahrens int zfs_zaccess_rename(struct znode *, struct znode *, 203fa9e4066Sahrens struct znode *, struct znode *, cred_t *cr); 204fa9e4066Sahrens void zfs_acl_free(zfs_acl_t *); 205da6c28aaSamw int zfs_vsec_2_aclp(struct zfsvfs *, vtype_t, vsecattr_t *, zfs_acl_t **); 2064c841f60Smarks int zfs_aclset_common(struct znode *, zfs_acl_t *, cred_t *, 2074c841f60Smarks struct zfs_fuid_info **, dmu_tx_t *); 208fa9e4066Sahrens 209fa9e4066Sahrens #endif 210fa9e4066Sahrens 211fa9e4066Sahrens #ifdef __cplusplus 212fa9e4066Sahrens } 213fa9e4066Sahrens #endif 214fa9e4066Sahrens #endif /* _SYS_FS_ZFS_ACL_H */ 215