17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 52879e8a4Sprabahar * Common Development and Distribution License (the "License"). 62879e8a4Sprabahar * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 22*134a1f4eSCasper H.S. Dik * Copyright (c) 1993, 2010, Oracle and/or its affiliates. All rights reserved. 237c478bd9Sstevel@tonic-gate */ 247c478bd9Sstevel@tonic-gate 257c478bd9Sstevel@tonic-gate #ifndef _SYS_FS_UFS_ACL_H 267c478bd9Sstevel@tonic-gate #define _SYS_FS_UFS_ACL_H 277c478bd9Sstevel@tonic-gate 287c478bd9Sstevel@tonic-gate #include <sys/types.h> 297c478bd9Sstevel@tonic-gate #include <sys/cred.h> 307c478bd9Sstevel@tonic-gate #include <sys/vfs.h> 317c478bd9Sstevel@tonic-gate #include <sys/acl.h> 327c478bd9Sstevel@tonic-gate #include <sys/fs/ufs_fs.h> 337c478bd9Sstevel@tonic-gate 347c478bd9Sstevel@tonic-gate #ifdef __cplusplus 357c478bd9Sstevel@tonic-gate extern "C" { 367c478bd9Sstevel@tonic-gate #endif 377c478bd9Sstevel@tonic-gate 387c478bd9Sstevel@tonic-gate /* 397c478bd9Sstevel@tonic-gate * On-disk UFS ACL structure 407c478bd9Sstevel@tonic-gate */ 417c478bd9Sstevel@tonic-gate 427c478bd9Sstevel@tonic-gate typedef struct ufs_acl { 437c478bd9Sstevel@tonic-gate union { 447c478bd9Sstevel@tonic-gate uint32_t acl_next; /* Pad for old structure */ 457c478bd9Sstevel@tonic-gate ushort_t acl_tag; /* Entry type */ 467c478bd9Sstevel@tonic-gate } acl_un; 477c478bd9Sstevel@tonic-gate o_mode_t acl_perm; /* Permission bits */ 487c478bd9Sstevel@tonic-gate uid_t acl_who; /* User or group ID */ 497c478bd9Sstevel@tonic-gate } ufs_acl_t; 507c478bd9Sstevel@tonic-gate 517c478bd9Sstevel@tonic-gate #define acl_tag acl_un.acl_tag 527c478bd9Sstevel@tonic-gate #define acl_next acl_un.acl_next 537c478bd9Sstevel@tonic-gate 547c478bd9Sstevel@tonic-gate /* 557c478bd9Sstevel@tonic-gate * In-core UFS ACL structure 567c478bd9Sstevel@tonic-gate */ 577c478bd9Sstevel@tonic-gate 587c478bd9Sstevel@tonic-gate typedef struct ufs_ic_acl { 597c478bd9Sstevel@tonic-gate struct ufs_ic_acl *acl_ic_next; /* Next ACL for this inode */ 607c478bd9Sstevel@tonic-gate o_mode_t acl_ic_perm; /* Permission bits */ 617c478bd9Sstevel@tonic-gate uid_t acl_ic_who; /* User or group ID */ 627c478bd9Sstevel@tonic-gate } ufs_ic_acl_t; 637c478bd9Sstevel@tonic-gate 647c478bd9Sstevel@tonic-gate /* 657c478bd9Sstevel@tonic-gate * In-core ACL mask 667c478bd9Sstevel@tonic-gate */ 677c478bd9Sstevel@tonic-gate typedef struct ufs_aclmask { 687c478bd9Sstevel@tonic-gate short acl_ismask; /* Is mask defined? */ 697c478bd9Sstevel@tonic-gate o_mode_t acl_maskbits; /* Permission mask */ 707c478bd9Sstevel@tonic-gate } ufs_aclmask_t; 717c478bd9Sstevel@tonic-gate 727c478bd9Sstevel@tonic-gate /* 737c478bd9Sstevel@tonic-gate * full acl 747c478bd9Sstevel@tonic-gate */ 757c478bd9Sstevel@tonic-gate typedef struct ic_acl { 767c478bd9Sstevel@tonic-gate ufs_ic_acl_t *owner; /* owner object */ 777c478bd9Sstevel@tonic-gate ufs_ic_acl_t *group; /* group object */ 787c478bd9Sstevel@tonic-gate ufs_ic_acl_t *other; /* other object */ 797c478bd9Sstevel@tonic-gate ufs_ic_acl_t *users; /* list of users */ 807c478bd9Sstevel@tonic-gate ufs_ic_acl_t *groups; /* list of groups */ 817c478bd9Sstevel@tonic-gate ufs_aclmask_t mask; /* mask */ 827c478bd9Sstevel@tonic-gate } ic_acl_t; 837c478bd9Sstevel@tonic-gate 847c478bd9Sstevel@tonic-gate /* 857c478bd9Sstevel@tonic-gate * In-core shadow inode 867c478bd9Sstevel@tonic-gate */ 877c478bd9Sstevel@tonic-gate typedef struct si { 887c478bd9Sstevel@tonic-gate struct si *s_next; /* signature hash next */ 897c478bd9Sstevel@tonic-gate struct si *s_forw; /* inode hash next */ 907c478bd9Sstevel@tonic-gate struct si *s_fore; /* unref'd list next */ 917c478bd9Sstevel@tonic-gate 927c478bd9Sstevel@tonic-gate int s_flags; /* see below */ 937c478bd9Sstevel@tonic-gate ino_t s_shadow; /* shadow inode number */ 947c478bd9Sstevel@tonic-gate dev_t s_dev; /* device (major,minor) */ 957c478bd9Sstevel@tonic-gate int s_signature; /* signature for all ACLs */ 967c478bd9Sstevel@tonic-gate int s_use; /* on disk use count */ 977c478bd9Sstevel@tonic-gate int s_ref; /* in core reference count */ 987c478bd9Sstevel@tonic-gate krwlock_t s_lock; /* lock for this structure */ 997c478bd9Sstevel@tonic-gate 1007c478bd9Sstevel@tonic-gate ic_acl_t s_a; /* acls */ 1017c478bd9Sstevel@tonic-gate ic_acl_t s_d; /* def acls */ 1027c478bd9Sstevel@tonic-gate } si_t; 1037c478bd9Sstevel@tonic-gate 1047c478bd9Sstevel@tonic-gate #define aowner s_a.owner 1057c478bd9Sstevel@tonic-gate #define agroup s_a.group 1067c478bd9Sstevel@tonic-gate #define aother s_a.other 1077c478bd9Sstevel@tonic-gate #define ausers s_a.users 1087c478bd9Sstevel@tonic-gate #define agroups s_a.groups 1097c478bd9Sstevel@tonic-gate #define aclass s_a.mask 1107c478bd9Sstevel@tonic-gate 1117c478bd9Sstevel@tonic-gate #define downer s_d.owner 1127c478bd9Sstevel@tonic-gate #define dgroup s_d.group 1137c478bd9Sstevel@tonic-gate #define dother s_d.other 1147c478bd9Sstevel@tonic-gate #define dusers s_d.users 1157c478bd9Sstevel@tonic-gate #define dgroups s_d.groups 1167c478bd9Sstevel@tonic-gate #define dclass s_d.mask 1177c478bd9Sstevel@tonic-gate 1187c478bd9Sstevel@tonic-gate #define s_prev s_forw 1197c478bd9Sstevel@tonic-gate 1207c478bd9Sstevel@tonic-gate /* 1217c478bd9Sstevel@tonic-gate * s_flags 1227c478bd9Sstevel@tonic-gate */ 1237c478bd9Sstevel@tonic-gate #define SI_CACHED 0x0001 /* Is in si_cache */ 1247c478bd9Sstevel@tonic-gate 1257c478bd9Sstevel@tonic-gate /* 1267c478bd9Sstevel@tonic-gate * Header to identify data on disk 1277c478bd9Sstevel@tonic-gate */ 1287c478bd9Sstevel@tonic-gate typedef struct ufs_fsd { 1297c478bd9Sstevel@tonic-gate int fsd_type; /* type of data */ 1307c478bd9Sstevel@tonic-gate int fsd_size; /* size in bytes of ufs_fsd and data */ 1317c478bd9Sstevel@tonic-gate char fsd_data[1]; /* data */ 1327c478bd9Sstevel@tonic-gate } ufs_fsd_t; 1337c478bd9Sstevel@tonic-gate 1347c478bd9Sstevel@tonic-gate /* 1357c478bd9Sstevel@tonic-gate * Data types (fsd_type) 1367c478bd9Sstevel@tonic-gate */ 1377c478bd9Sstevel@tonic-gate #define FSD_FREE (0) /* Free entry */ 1387c478bd9Sstevel@tonic-gate #define FSD_ACL (1) /* Access Control Lists */ 1397c478bd9Sstevel@tonic-gate #define FSD_DFACL (2) /* reserved for future use */ 1407c478bd9Sstevel@tonic-gate #define FSD_RESERVED3 (3) /* reserved for future use */ 1417c478bd9Sstevel@tonic-gate #define FSD_RESERVED4 (4) /* reserved for future use */ 1427c478bd9Sstevel@tonic-gate #define FSD_RESERVED5 (5) /* reserved for future use */ 1437c478bd9Sstevel@tonic-gate #define FSD_RESERVED6 (6) /* reserved for future use */ 1447c478bd9Sstevel@tonic-gate #define FSD_RESERVED7 (7) /* reserved for future use */ 1457c478bd9Sstevel@tonic-gate 1467c478bd9Sstevel@tonic-gate /* 1477c478bd9Sstevel@tonic-gate * FSD manipulation macros 1487c478bd9Sstevel@tonic-gate * The FSD macros are aligned on integer boundary even if the preceeding 1497c478bd9Sstevel@tonic-gate * record had a byte aligned length. So the record length is always 1507c478bd9Sstevel@tonic-gate * integer length. All increments of the data pointers must use the 1517c478bd9Sstevel@tonic-gate * FSD_RECSZ macro. 1527c478bd9Sstevel@tonic-gate */ 1537c478bd9Sstevel@tonic-gate #define FSD_TPSZ(fsdp) (sizeof (fsdp->fsd_type)) 1547c478bd9Sstevel@tonic-gate #define FSD_TPMSK(fsdp) (FSD_TPSZ(fsdp) - 1) 1557c478bd9Sstevel@tonic-gate #define FSD_RECSZ(fsdp, size) ((size + FSD_TPMSK(fsdp)) & ~FSD_TPMSK(fsdp)) 1567c478bd9Sstevel@tonic-gate /* 1577c478bd9Sstevel@tonic-gate * flags for acl_validate 1587c478bd9Sstevel@tonic-gate */ 1597c478bd9Sstevel@tonic-gate #define ACL_CHECK 0x01 1607c478bd9Sstevel@tonic-gate #define DEF_ACL_CHECK 0x02 1617c478bd9Sstevel@tonic-gate 162*134a1f4eSCasper H.S. Dik #define MODE_CHECK(O, M, PERM, C, I) \ 163*134a1f4eSCasper H.S. Dik secpolicy_vnode_access2(C, ITOV(I), O, (PERM), M) 1647c478bd9Sstevel@tonic-gate 1657c478bd9Sstevel@tonic-gate /* 1667c478bd9Sstevel@tonic-gate * Check that the file type is one that accepts ACLs 1677c478bd9Sstevel@tonic-gate */ 1687c478bd9Sstevel@tonic-gate #define CHECK_ACL_ALLOWED(MODE) (((MODE) == IFDIR) || ((MODE) == IFREG) || \ 1697c478bd9Sstevel@tonic-gate ((MODE) == IFIFO) || ((MODE) == IFCHR) || \ 1707c478bd9Sstevel@tonic-gate ((MODE) == IFBLK) || ((MODE) == IFATTRDIR)) 1717c478bd9Sstevel@tonic-gate 1722879e8a4Sprabahar /* 1732879e8a4Sprabahar * Get ACL group permissions if the mask is not present, and the ACL 1742879e8a4Sprabahar * group permission intersected with the mask if the mask is present 1752879e8a4Sprabahar */ 1762879e8a4Sprabahar #define MASK2MODE(ACL) \ 1772879e8a4Sprabahar ((ACL)->aclass.acl_ismask ? \ 1782879e8a4Sprabahar ((((ACL)->aclass.acl_maskbits & \ 1792879e8a4Sprabahar (ACL)->agroup->acl_ic_perm) & 07) << 3) : \ 1802879e8a4Sprabahar (((ACL)->agroup->acl_ic_perm & 07) << 3)) 1812879e8a4Sprabahar 1827c478bd9Sstevel@tonic-gate #define MODE2ACL(P, MODE, CRED) \ 1837c478bd9Sstevel@tonic-gate ASSERT((P)); \ 1847c478bd9Sstevel@tonic-gate (P)->acl_ic_next = NULL; \ 1857c478bd9Sstevel@tonic-gate (P)->acl_ic_perm &= ((MODE) & 7); \ 1867c478bd9Sstevel@tonic-gate (P)->acl_ic_who = (CRED); 1877c478bd9Sstevel@tonic-gate 1887c478bd9Sstevel@tonic-gate #define ACL_MOVE(P, T, B) \ 1897c478bd9Sstevel@tonic-gate { \ 1907c478bd9Sstevel@tonic-gate ufs_ic_acl_t *acl; \ 1917c478bd9Sstevel@tonic-gate for (acl = (P); acl; acl = acl->acl_ic_next) { \ 1927c478bd9Sstevel@tonic-gate (B)->acl_tag = (T); \ 1937c478bd9Sstevel@tonic-gate (B)->acl_perm = acl->acl_ic_perm; \ 1947c478bd9Sstevel@tonic-gate (B)->acl_who = acl->acl_ic_who; \ 1957c478bd9Sstevel@tonic-gate (B)++; \ 1967c478bd9Sstevel@tonic-gate } \ 1977c478bd9Sstevel@tonic-gate } 1987c478bd9Sstevel@tonic-gate 1997c478bd9Sstevel@tonic-gate #ifdef __cplusplus 2007c478bd9Sstevel@tonic-gate } 2017c478bd9Sstevel@tonic-gate #endif 2027c478bd9Sstevel@tonic-gate 2037c478bd9Sstevel@tonic-gate #endif /* _SYS_FS_UFS_ACL_H */ 204