1168404Spjd/* 2168404Spjd * CDDL HEADER START 3168404Spjd * 4168404Spjd * The contents of this file are subject to the terms of the 5168404Spjd * Common Development and Distribution License (the "License"). 6168404Spjd * You may not use this file except in compliance with the License. 7168404Spjd * 8168404Spjd * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9168404Spjd * or http://www.opensolaris.org/os/licensing. 10168404Spjd * See the License for the specific language governing permissions 11168404Spjd * and limitations under the License. 12168404Spjd * 13168404Spjd * When distributing Covered Code, include this CDDL HEADER in each 14168404Spjd * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15168404Spjd * If applicable, add the following below this CDDL HEADER, with the 16168404Spjd * fields enclosed by brackets "[]" replaced with your own identifying 17168404Spjd * information: Portions Copyright [yyyy] [name of copyright owner] 18168404Spjd * 19168404Spjd * CDDL HEADER END 20168404Spjd */ 21168404Spjd/* 22219089Spjd * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. 23168404Spjd */ 24168404Spjd 25168404Spjd#ifndef _SYS_FS_ZFS_ACL_H 26168404Spjd#define _SYS_FS_ZFS_ACL_H 27168404Spjd 28168404Spjd#ifdef _KERNEL 29168404Spjd#include <sys/cred.h> 30168404Spjd#endif 31168404Spjd#include <sys/acl.h> 32168404Spjd#include <sys/dmu.h> 33185029Spjd#include <sys/zfs_fuid.h> 34219089Spjd#include <sys/sa.h> 35168404Spjd 36168404Spjd#ifdef __cplusplus 37168404Spjdextern "C" { 38168404Spjd#endif 39168404Spjd 40168404Spjdstruct znode_phys; 41168404Spjd 42168404Spjd#define ACE_SLOT_CNT 6 43185029Spjd#define ZFS_ACL_VERSION_INITIAL 0ULL 44185029Spjd#define ZFS_ACL_VERSION_FUID 1ULL 45185029Spjd#define ZFS_ACL_VERSION ZFS_ACL_VERSION_FUID 46168404Spjd 47185029Spjd/* 48251631Sdelphij * ZFS ACLs (Access Control Lists) are stored in various forms. 49251631Sdelphij * 50185029Spjd * Files created with ACL version ZFS_ACL_VERSION_INITIAL 51185029Spjd * will all be created with fixed length ACEs of type 52185029Spjd * zfs_oldace_t. 53185029Spjd * 54185029Spjd * Files with ACL version ZFS_ACL_VERSION_FUID will be created 55185029Spjd * with various sized ACEs. The abstraction entries will utilize 56185029Spjd * zfs_ace_hdr_t, normal user/group entries will use zfs_ace_t 57185029Spjd * and some specialized CIFS ACEs will use zfs_object_ace_t. 58185029Spjd */ 59185029Spjd 60185029Spjd/* 61185029Spjd * All ACEs have a common hdr. For 62185029Spjd * owner@, group@, and everyone@ this is all 63185029Spjd * thats needed. 64185029Spjd */ 65185029Spjdtypedef struct zfs_ace_hdr { 66185029Spjd uint16_t z_type; 67185029Spjd uint16_t z_flags; 68185029Spjd uint32_t z_access_mask; 69185029Spjd} zfs_ace_hdr_t; 70185029Spjd 71185029Spjdtypedef zfs_ace_hdr_t zfs_ace_abstract_t; 72185029Spjd 73185029Spjd/* 74185029Spjd * Standard ACE 75185029Spjd */ 76185029Spjdtypedef struct zfs_ace { 77185029Spjd zfs_ace_hdr_t z_hdr; 78185029Spjd uint64_t z_fuid; 79185029Spjd} zfs_ace_t; 80185029Spjd 81185029Spjd/* 82185029Spjd * The following type only applies to ACE_ACCESS_ALLOWED|DENIED_OBJECT_ACE_TYPE 83185029Spjd * and will only be set/retrieved in a CIFS context. 84185029Spjd */ 85185029Spjd 86185029Spjdtypedef struct zfs_object_ace { 87185029Spjd zfs_ace_t z_ace; 88185029Spjd uint8_t z_object_type[16]; /* object type */ 89185029Spjd uint8_t z_inherit_type[16]; /* inherited object type */ 90185029Spjd} zfs_object_ace_t; 91185029Spjd 92185029Spjdtypedef struct zfs_oldace { 93185029Spjd uint32_t z_fuid; /* "who" */ 94185029Spjd uint32_t z_access_mask; /* access mask */ 95185029Spjd uint16_t z_flags; /* flags, i.e inheritance */ 96185029Spjd uint16_t z_type; /* type of entry allow/deny */ 97185029Spjd} zfs_oldace_t; 98185029Spjd 99185029Spjdtypedef struct zfs_acl_phys_v0 { 100185029Spjd uint64_t z_acl_extern_obj; /* ext acl pieces */ 101185029Spjd uint32_t z_acl_count; /* Number of ACEs */ 102185029Spjd uint16_t z_acl_version; /* acl version */ 103185029Spjd uint16_t z_acl_pad; /* pad */ 104185029Spjd zfs_oldace_t z_ace_data[ACE_SLOT_CNT]; /* 6 standard ACEs */ 105185029Spjd} zfs_acl_phys_v0_t; 106185029Spjd 107185029Spjd#define ZFS_ACE_SPACE (sizeof (zfs_oldace_t) * ACE_SLOT_CNT) 108185029Spjd 109219089Spjd/* 110219089Spjd * Size of ACL count is always 2 bytes. 111219089Spjd * Necessary to for dealing with both V0 ACL and V1 ACL layout 112219089Spjd */ 113219089Spjd#define ZFS_ACL_COUNT_SIZE (sizeof (uint16_t)) 114219089Spjd 115185029Spjdtypedef struct zfs_acl_phys { 116168404Spjd uint64_t z_acl_extern_obj; /* ext acl pieces */ 117185029Spjd uint32_t z_acl_size; /* Number of bytes in ACL */ 118168404Spjd uint16_t z_acl_version; /* acl version */ 119185029Spjd uint16_t z_acl_count; /* ace count */ 120219089Spjd uint8_t z_ace_data[ZFS_ACE_SPACE]; /* space for embedded ACEs */ 121185029Spjd} zfs_acl_phys_t; 122168404Spjd 123185029Spjdtypedef struct acl_ops { 124185029Spjd uint32_t (*ace_mask_get) (void *acep); /* get access mask */ 125185029Spjd void (*ace_mask_set) (void *acep, 126185029Spjd uint32_t mask); /* set access mask */ 127185029Spjd uint16_t (*ace_flags_get) (void *acep); /* get flags */ 128185029Spjd void (*ace_flags_set) (void *acep, 129185029Spjd uint16_t flags); /* set flags */ 130185029Spjd uint16_t (*ace_type_get)(void *acep); /* get type */ 131185029Spjd void (*ace_type_set)(void *acep, 132185029Spjd uint16_t type); /* set type */ 133185029Spjd uint64_t (*ace_who_get)(void *acep); /* get who/fuid */ 134185029Spjd void (*ace_who_set)(void *acep, 135185029Spjd uint64_t who); /* set who/fuid */ 136185029Spjd size_t (*ace_size)(void *acep); /* how big is this ace */ 137185029Spjd size_t (*ace_abstract_size)(void); /* sizeof abstract entry */ 138185029Spjd int (*ace_mask_off)(void); /* off of access mask in ace */ 139251631Sdelphij /* ptr to data if any */ 140185029Spjd int (*ace_data)(void *acep, void **datap); 141185029Spjd} acl_ops_t; 142185029Spjd 143168404Spjd/* 144185029Spjd * A zfs_acl_t structure is composed of a list of zfs_acl_node_t's. 145185029Spjd * Each node will have one or more ACEs associated with it. You will 146185029Spjd * only have multiple nodes during a chmod operation. Normally only 147185029Spjd * one node is required. 148168404Spjd */ 149185029Spjdtypedef struct zfs_acl_node { 150185029Spjd list_node_t z_next; /* Next chunk of ACEs */ 151185029Spjd void *z_acldata; /* pointer into actual ACE(s) */ 152185029Spjd void *z_allocdata; /* pointer to kmem allocated memory */ 153185029Spjd size_t z_allocsize; /* Size of blob in bytes */ 154185029Spjd size_t z_size; /* length of ACL data */ 155219089Spjd uint64_t z_ace_count; /* number of ACEs in this acl node */ 156185029Spjd int z_ace_idx; /* ace iterator positioned on */ 157185029Spjd} zfs_acl_node_t; 158168404Spjd 159168404Spjdtypedef struct zfs_acl { 160219089Spjd uint64_t z_acl_count; /* Number of ACEs */ 161185029Spjd size_t z_acl_bytes; /* Number of bytes in ACL */ 162185029Spjd uint_t z_version; /* version of ACL */ 163185029Spjd void *z_next_ace; /* pointer to next ACE */ 164219089Spjd uint64_t z_hints; /* ACL hints (ZFS_INHERIT_ACE ...) */ 165185029Spjd zfs_acl_node_t *z_curr_node; /* current node iterator is handling */ 166185029Spjd list_t z_acl; /* chunks of ACE data */ 167185029Spjd acl_ops_t z_ops; /* ACL operations */ 168168404Spjd} zfs_acl_t; 169168404Spjd 170219089Spjdtypedef struct acl_locator_cb { 171219089Spjd zfs_acl_t *cb_aclp; 172219089Spjd zfs_acl_node_t *cb_acl_node; 173219089Spjd} zfs_acl_locator_cb_t; 174219089Spjd 175185029Spjd#define ACL_DATA_ALLOCED 0x1 176168404Spjd#define ZFS_ACL_SIZE(aclcnt) (sizeof (ace_t) * (aclcnt)) 177168404Spjd 178209962Smmstruct zfs_fuid_info; 179209962Smm 180209962Smmtypedef struct zfs_acl_ids { 181209962Smm uint64_t z_fuid; /* file owner fuid */ 182209962Smm uint64_t z_fgid; /* file group owner fuid */ 183209962Smm uint64_t z_mode; /* mode to set on create */ 184209962Smm zfs_acl_t *z_aclp; /* ACL to create with file */ 185209962Smm struct zfs_fuid_info *z_fuidp; /* for tracking fuids for log */ 186209962Smm} zfs_acl_ids_t; 187209962Smm 188168404Spjd/* 189168404Spjd * Property values for acl_mode and acl_inherit. 190168404Spjd * 191168404Spjd * acl_mode can take discard, noallow, groupmask and passthrough. 192168404Spjd * whereas acl_inherit has secure instead of groupmask. 193168404Spjd */ 194168404Spjd 195168404Spjd#define ZFS_ACL_DISCARD 0 196168404Spjd#define ZFS_ACL_NOALLOW 1 197168404Spjd#define ZFS_ACL_GROUPMASK 2 198168404Spjd#define ZFS_ACL_PASSTHROUGH 3 199185029Spjd#define ZFS_ACL_RESTRICTED 4 200201143Sdelphij#define ZFS_ACL_PASSTHROUGH_X 5 201168404Spjd 202168404Spjdstruct znode; 203185029Spjdstruct zfsvfs; 204168404Spjd 205168404Spjd#ifdef _KERNEL 206209962Smmint zfs_acl_ids_create(struct znode *, int, vattr_t *, 207209962Smm cred_t *, vsecattr_t *, zfs_acl_ids_t *); 208209962Smmvoid zfs_acl_ids_free(zfs_acl_ids_t *); 209209962Smmboolean_t zfs_acl_ids_overquota(struct zfsvfs *, zfs_acl_ids_t *); 210185029Spjdint zfs_getacl(struct znode *, vsecattr_t *, boolean_t, cred_t *); 211185029Spjdint zfs_setacl(struct znode *, vsecattr_t *, boolean_t, cred_t *); 212168404Spjdvoid zfs_acl_rele(void *); 213185029Spjdvoid zfs_oldace_byteswap(ace_t *, int); 214185029Spjdvoid zfs_ace_byteswap(void *, size_t, boolean_t); 215211932Smmextern boolean_t zfs_has_access(struct znode *zp, cred_t *cr); 216185029Spjdextern int zfs_zaccess(struct znode *, int, int, boolean_t, cred_t *); 217211932Smmint zfs_fastaccesschk_execute(struct znode *, cred_t *); 218185029Spjdextern int zfs_zaccess_rwx(struct znode *, mode_t, int, cred_t *); 219185029Spjdextern int zfs_zaccess_unix(struct znode *, mode_t, cred_t *); 220168404Spjdextern int zfs_acl_access(struct znode *, int, cred_t *); 221224174Smmint zfs_acl_chmod_setattr(struct znode *, zfs_acl_t **, uint64_t); 222168404Spjdint zfs_zaccess_delete(struct znode *, struct znode *, cred_t *); 223168404Spjdint zfs_zaccess_rename(struct znode *, struct znode *, 224168404Spjd struct znode *, struct znode *, cred_t *cr); 225168404Spjdvoid zfs_acl_free(zfs_acl_t *); 226209962Smmint zfs_vsec_2_aclp(struct zfsvfs *, vtype_t, vsecattr_t *, cred_t *, 227209962Smm struct zfs_fuid_info **, zfs_acl_t **); 228209962Smmint zfs_aclset_common(struct znode *, zfs_acl_t *, cred_t *, dmu_tx_t *); 229219089Spjduint64_t zfs_external_acl(struct znode *); 230219089Spjdint zfs_znode_acl_version(struct znode *); 231219089Spjdint zfs_acl_size(struct znode *, int *); 232219089Spjdzfs_acl_t *zfs_acl_alloc(int); 233219089Spjdzfs_acl_node_t *zfs_acl_node_alloc(size_t); 234219089Spjdvoid zfs_acl_xform(struct znode *, zfs_acl_t *, cred_t *); 235219089Spjdvoid zfs_acl_data_locator(void **, uint32_t *, uint32_t, boolean_t, void *); 236219089Spjduint64_t zfs_mode_compute(uint64_t, zfs_acl_t *, 237219089Spjd uint64_t *, uint64_t, uint64_t); 238219089Spjdint zfs_acl_chown_setattr(struct znode *); 239168404Spjd 240168404Spjd#endif 241168404Spjd 242168404Spjd#ifdef __cplusplus 243168404Spjd} 244168404Spjd#endif 245219089Spjd#endif /* _SYS_FS_ZFS_ACL_H */ 246