zfs_acl.h revision 9396:f41cf682d0d3
164562Sgshapiro/* 2132943Sgshapiro * CDDL HEADER START 364562Sgshapiro * 464562Sgshapiro * The contents of this file are subject to the terms of the 564562Sgshapiro * Common Development and Distribution License (the "License"). 664562Sgshapiro * You may not use this file except in compliance with the License. 764562Sgshapiro * 864562Sgshapiro * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 964562Sgshapiro * or http://www.opensolaris.org/os/licensing. 1064562Sgshapiro * See the License for the specific language governing permissions 1190792Sgshapiro * and limitations under the License. 12141858Sgshapiro * 1364562Sgshapiro * When distributing Covered Code, include this CDDL HEADER in each 1464562Sgshapiro * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 1590792Sgshapiro * If applicable, add the following below this CDDL HEADER, with the 16132943Sgshapiro * fields enclosed by brackets "[]" replaced with your own identifying 1764562Sgshapiro * information: Portions Copyright [yyyy] [name of copyright owner] 18141858Sgshapiro * 19132943Sgshapiro * CDDL HEADER END 20132943Sgshapiro */ 21132943Sgshapiro/* 2264562Sgshapiro * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 23132943Sgshapiro * Use is subject to license terms. 24132943Sgshapiro */ 25132943Sgshapiro 26132943Sgshapiro#ifndef _SYS_FS_ZFS_ACL_H 27132943Sgshapiro#define _SYS_FS_ZFS_ACL_H 28132943Sgshapiro 29132943Sgshapiro#ifdef _KERNEL 30132943Sgshapiro#include <sys/isa_defs.h> 31132943Sgshapiro#include <sys/types32.h> 32132943Sgshapiro#endif 33132943Sgshapiro#include <sys/acl.h> 34132943Sgshapiro#include <sys/dmu.h> 35132943Sgshapiro#include <sys/zfs_fuid.h> 36132943Sgshapiro 37132943Sgshapiro#ifdef __cplusplus 38132943Sgshapiroextern "C" { 39132943Sgshapiro#endif 40132943Sgshapiro 41132943Sgshapirostruct znode_phys; 42132943Sgshapiro 43132943Sgshapiro#define ACE_SLOT_CNT 6 44132943Sgshapiro#define ZFS_ACL_VERSION_INITIAL 0ULL 4564562Sgshapiro#define ZFS_ACL_VERSION_FUID 1ULL 4664562Sgshapiro#define ZFS_ACL_VERSION ZFS_ACL_VERSION_FUID 4764562Sgshapiro 4864562Sgshapiro/* 4964562Sgshapiro * ZFS ACLs are store in various forms. 5064562Sgshapiro * Files created with ACL version ZFS_ACL_VERSION_INITIAL 5164562Sgshapiro * will all be created with fixed length ACEs of type 5264562Sgshapiro * zfs_oldace_t. 5364562Sgshapiro * 5464562Sgshapiro * Files with ACL version ZFS_ACL_VERSION_FUID will be created 5564562Sgshapiro * with various sized ACEs. The abstraction entries will utilize 5664562Sgshapiro * zfs_ace_hdr_t, normal user/group entries will use zfs_ace_t 5764562Sgshapiro * and some specialized CIFS ACEs will use zfs_object_ace_t. 5864562Sgshapiro */ 5964562Sgshapiro 6064562Sgshapiro/* 6164562Sgshapiro * All ACEs have a common hdr. For 6264562Sgshapiro * owner@, group@, and everyone@ this is all 6364562Sgshapiro * thats needed. 6464562Sgshapiro */ 6564562Sgshapirotypedef struct zfs_ace_hdr { 6664562Sgshapiro uint16_t z_type; 6764562Sgshapiro uint16_t z_flags; 6864562Sgshapiro uint32_t z_access_mask; 6964562Sgshapiro} zfs_ace_hdr_t; 7064562Sgshapiro 71111823Sgshapirotypedef zfs_ace_hdr_t zfs_ace_abstract_t; 7264562Sgshapiro 7364562Sgshapiro/* 7464562Sgshapiro * Standard ACE 7564562Sgshapiro */ 7664562Sgshapirotypedef struct zfs_ace { 7764562Sgshapiro zfs_ace_hdr_t z_hdr; 7864562Sgshapiro uint64_t z_fuid; 7971345Sgshapiro} zfs_ace_t; 8064562Sgshapiro 81102528Sgshapiro/* 8264562Sgshapiro * The following type only applies to ACE_ACCESS_ALLOWED|DENIED_OBJECT_ACE_TYPE 83111823Sgshapiro * and will only be set/retrieved in a CIFS context. 84111823Sgshapiro */ 85102528Sgshapiro 86102528Sgshapirotypedef struct zfs_object_ace { 87102528Sgshapiro zfs_ace_t z_ace; 88102528Sgshapiro uint8_t z_object_type[16]; /* object type */ 89102528Sgshapiro uint8_t z_inherit_type[16]; /* inherited object type */ 90102528Sgshapiro} zfs_object_ace_t; 91102528Sgshapiro 92102528Sgshapirotypedef struct zfs_oldace { 93111823Sgshapiro uint32_t z_fuid; /* "who" */ 9464562Sgshapiro uint32_t z_access_mask; /* access mask */ 9564562Sgshapiro uint16_t z_flags; /* flags, i.e inheritance */ 9664562Sgshapiro uint16_t z_type; /* type of entry allow/deny */ 9764562Sgshapiro} zfs_oldace_t; 9890792Sgshapiro 9990792Sgshapirotypedef struct zfs_acl_phys_v0 { 10090792Sgshapiro uint64_t z_acl_extern_obj; /* ext acl pieces */ 10164562Sgshapiro uint32_t z_acl_count; /* Number of ACEs */ 10264562Sgshapiro uint16_t z_acl_version; /* acl version */ 10364562Sgshapiro uint16_t z_acl_pad; /* pad */ 104110560Sgshapiro zfs_oldace_t z_ace_data[ACE_SLOT_CNT]; /* 6 standard ACEs */ 10564562Sgshapiro} zfs_acl_phys_v0_t; 10664562Sgshapiro 10764562Sgshapiro#define ZFS_ACE_SPACE (sizeof (zfs_oldace_t) * ACE_SLOT_CNT) 10864562Sgshapiro 10964562Sgshapirotypedef struct zfs_acl_phys { 11064562Sgshapiro uint64_t z_acl_extern_obj; /* ext acl pieces */ 11164562Sgshapiro uint32_t z_acl_size; /* Number of bytes in ACL */ 11264562Sgshapiro uint16_t z_acl_version; /* acl version */ 11364562Sgshapiro uint16_t z_acl_count; /* ace count */ 11464562Sgshapiro uint8_t z_ace_data[ZFS_ACE_SPACE]; /* space for embedded ACEs */ 11564562Sgshapiro} zfs_acl_phys_t; 11664562Sgshapiro 11764562Sgshapirotypedef struct acl_ops { 11864562Sgshapiro uint32_t (*ace_mask_get) (void *acep); /* get access mask */ 11964562Sgshapiro void (*ace_mask_set) (void *acep, 12064562Sgshapiro uint32_t mask); /* set access mask */ 12164562Sgshapiro uint16_t (*ace_flags_get) (void *acep); /* get flags */ 12264562Sgshapiro void (*ace_flags_set) (void *acep, 12364562Sgshapiro uint16_t flags); /* set flags */ 12464562Sgshapiro uint16_t (*ace_type_get)(void *acep); /* get type */ 12564562Sgshapiro void (*ace_type_set)(void *acep, 12690792Sgshapiro uint16_t type); /* set type */ 12764562Sgshapiro uint64_t (*ace_who_get)(void *acep); /* get who/fuid */ 12864562Sgshapiro void (*ace_who_set)(void *acep, 12964562Sgshapiro uint64_t who); /* set who/fuid */ 13064562Sgshapiro size_t (*ace_size)(void *acep); /* how big is this ace */ 13164562Sgshapiro size_t (*ace_abstract_size)(void); /* sizeof abstract entry */ 13264562Sgshapiro int (*ace_mask_off)(void); /* off of access mask in ace */ 13364562Sgshapiro int (*ace_data)(void *acep, void **datap); 13464562Sgshapiro /* ptr to data if any */ 13564562Sgshapiro} acl_ops_t; 13664562Sgshapiro 137132943Sgshapiro/* 13864562Sgshapiro * A zfs_acl_t structure is composed of a list of zfs_acl_node_t's. 13964562Sgshapiro * Each node will have one or more ACEs associated with it. You will 14064562Sgshapiro * only have multiple nodes during a chmod operation. Normally only 14164562Sgshapiro * one node is required. 14290792Sgshapiro */ 14390792Sgshapirotypedef struct zfs_acl_node { 14490792Sgshapiro list_node_t z_next; /* Next chunk of ACEs */ 14564562Sgshapiro void *z_acldata; /* pointer into actual ACE(s) */ 14690792Sgshapiro void *z_allocdata; /* pointer to kmem allocated memory */ 14764562Sgshapiro size_t z_allocsize; /* Size of blob in bytes */ 14864562Sgshapiro size_t z_size; /* length of ACL data */ 14964562Sgshapiro int z_ace_count; /* number of ACEs in this acl node */ 15064562Sgshapiro int z_ace_idx; /* ace iterator positioned on */ 15164562Sgshapiro} zfs_acl_node_t; 15264562Sgshapiro 15364562Sgshapirotypedef struct zfs_acl { 154102528Sgshapiro int z_acl_count; /* Number of ACEs */ 15564562Sgshapiro size_t z_acl_bytes; /* Number of bytes in ACL */ 156111823Sgshapiro uint_t z_version; /* version of ACL */ 157111823Sgshapiro void *z_next_ace; /* pointer to next ACE */ 158102528Sgshapiro int z_hints; /* ACL hints (ZFS_INHERIT_ACE ...) */ 159102528Sgshapiro zfs_acl_node_t *z_curr_node; /* current node iterator is handling */ 160102528Sgshapiro list_t z_acl; /* chunks of ACE data */ 161102528Sgshapiro acl_ops_t z_ops; /* ACL operations */ 162102528Sgshapiro} zfs_acl_t; 163102528Sgshapiro 164102528Sgshapiro#define ACL_DATA_ALLOCED 0x1 165102528Sgshapiro#define ZFS_ACL_SIZE(aclcnt) (sizeof (ace_t) * (aclcnt)) 166111823Sgshapiro 16764562Sgshapirostruct zfs_fuid_info; 16864562Sgshapiro 16964562Sgshapirotypedef struct zfs_acl_ids { 17064562Sgshapiro uint64_t z_fuid; /* file owner fuid */ 17164562Sgshapiro uint64_t z_fgid; /* file group owner fuid */ 17290792Sgshapiro uint64_t z_mode; /* mode to set on create */ 17390792Sgshapiro zfs_acl_t *z_aclp; /* ACL to create with file */ 17464562Sgshapiro struct zfs_fuid_info *z_fuidp; /* for tracking fuids for log */ 17564562Sgshapiro} zfs_acl_ids_t; 17664562Sgshapiro 177110560Sgshapiro/* 17864562Sgshapiro * Property values for acl_mode and acl_inherit. 17964562Sgshapiro * 18064562Sgshapiro * acl_mode can take discard, noallow, groupmask and passthrough. 18164562Sgshapiro * whereas acl_inherit has secure instead of groupmask. 18264562Sgshapiro */ 18364562Sgshapiro 18464562Sgshapiro#define ZFS_ACL_DISCARD 0 18564562Sgshapiro#define ZFS_ACL_NOALLOW 1 18664562Sgshapiro#define ZFS_ACL_GROUPMASK 2 18764562Sgshapiro#define ZFS_ACL_PASSTHROUGH 3 18864562Sgshapiro#define ZFS_ACL_RESTRICTED 4 18964562Sgshapiro#define ZFS_ACL_PASSTHROUGH_X 5 19064562Sgshapiro 19164562Sgshapirostruct znode; 19264562Sgshapirostruct zfsvfs; 19364562Sgshapiro 19464562Sgshapiro#ifdef _KERNEL 19564562Sgshapiroint zfs_acl_ids_create(struct znode *, int, vattr_t *, 19690792Sgshapiro cred_t *, vsecattr_t *, zfs_acl_ids_t *); 19790792Sgshapirovoid zfs_acl_ids_free(zfs_acl_ids_t *); 19890792Sgshapiroboolean_t zfs_acl_ids_overquota(struct zfsvfs *, zfs_acl_ids_t *); 19990792Sgshapiroint zfs_getacl(struct znode *, vsecattr_t *, boolean_t, cred_t *); 20064562Sgshapiroint zfs_setacl(struct znode *, vsecattr_t *, boolean_t, cred_t *); 20164562Sgshapirovoid zfs_acl_rele(void *); 20264562Sgshapirovoid zfs_oldace_byteswap(ace_t *, int); 20364562Sgshapirovoid zfs_ace_byteswap(void *, size_t, boolean_t); 20464562Sgshapiroextern int zfs_zaccess(struct znode *, int, int, boolean_t, cred_t *); 20564562Sgshapiroextern int zfs_zaccess_rwx(struct znode *, mode_t, int, cred_t *); 20664562Sgshapiroextern int zfs_zaccess_unix(struct znode *, mode_t, cred_t *); 20764562Sgshapiroextern int zfs_acl_access(struct znode *, int, cred_t *); 20864562Sgshapiroint zfs_acl_chmod_setattr(struct znode *, zfs_acl_t **, uint64_t); 20964562Sgshapiroint zfs_zaccess_delete(struct znode *, struct znode *, cred_t *); 21064562Sgshapiroint zfs_zaccess_rename(struct znode *, struct znode *, 21164562Sgshapiro struct znode *, struct znode *, cred_t *cr); 21264562Sgshapirovoid zfs_acl_free(zfs_acl_t *); 21364562Sgshapiroint zfs_vsec_2_aclp(struct zfsvfs *, vtype_t, vsecattr_t *, cred_t *, 21464562Sgshapiro struct zfs_fuid_info **, zfs_acl_t **); 21564562Sgshapiroint zfs_aclset_common(struct znode *, zfs_acl_t *, cred_t *, dmu_tx_t *); 21664562Sgshapiro 21764562Sgshapiro#endif 21890792Sgshapiro 21964562Sgshapiro#ifdef __cplusplus 22064562Sgshapiro} 22164562Sgshapiro#endif 22264562Sgshapiro#endif /* _SYS_FS_ZFS_ACL_H */ 22364562Sgshapiro